| |
|
|
| import { type Client, http } from '../core.js' |
| import { type Result, type RequestOptions } from '../lib/types.js' |
| import { request } from '../lib/request.js' |
| import { toURLSearchParams, encodeSort } from '../lib/encodings.js' |
| import { |
| toWire, |
| toPathWire, |
| fromWire, |
| assertValid, |
| toSnakeCase, |
| } from '../lib/wire.js' |
| import * as schemas from '../models/schemas.js' |
| import type { |
| CreateCustomerRequest, |
| CreateCustomerResponse, |
| GetCustomerRequest, |
| GetCustomerResponse, |
| ListCustomersRequest, |
| ListCustomersResponse, |
| UpsertCustomerRequest, |
| UpsertCustomerResponse, |
| DeleteCustomerRequest, |
| DeleteCustomerResponse, |
| GetCustomerBillingRequest, |
| GetCustomerBillingResponse, |
| UpdateCustomerBillingRequest, |
| UpdateCustomerBillingResponse, |
| UpdateCustomerBillingAppDataRequest, |
| UpdateCustomerBillingAppDataResponse, |
| CreateCustomerStripeCheckoutSessionRequest, |
| CreateCustomerStripeCheckoutSessionResponse, |
| CreateCustomerStripePortalSessionRequest, |
| CreateCustomerStripePortalSessionResponse, |
| CreateCreditGrantRequest, |
| CreateCreditGrantResponse, |
| GetCreditGrantRequest, |
| GetCreditGrantResponse, |
| ListCreditGrantsRequest, |
| ListCreditGrantsResponse, |
| GetCustomerCreditBalanceRequest, |
| GetCustomerCreditBalanceResponse, |
| CreateCreditAdjustmentRequest, |
| CreateCreditAdjustmentResponse, |
| VoidCreditGrantRequest, |
| VoidCreditGrantResponse, |
| UpdateCreditGrantExternalSettlementRequest, |
| UpdateCreditGrantExternalSettlementResponse, |
| ListCreditTransactionsRequest, |
| ListCreditTransactionsResponse, |
| ListCustomerChargesRequest, |
| ListCustomerChargesResponse, |
| CreateCustomerChargesRequest, |
| CreateCustomerChargesResponse, |
| } from '../models/operations/customers.js' |
|
|
| |
| |
| |
| |
| |
| export function createCustomer( |
| client: Client, |
| req: CreateCustomerRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateCustomerResponse>> { |
| return request(() => { |
| const body = toWire(req, schemas.createCustomerBody) |
| if (client._options.validate) { |
| assertValid(schemas.createCustomerBodyWire, body) |
| } |
| return http(client) |
| .post('openmeter/customers', { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.createCustomerResponseWire, data) |
| } |
| return fromWire(data, schemas.createCustomerResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function getCustomer( |
| client: Client, |
| req: GetCustomerRequest, |
| options?: RequestOptions, |
| ): Promise<Result<GetCustomerResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.getCustomerPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.getCustomerPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}` |
| return http(client) |
| .get(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.getCustomerResponseWire, data) |
| } |
| return fromWire(data, schemas.getCustomerResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function listCustomers( |
| client: Client, |
| req: ListCustomersRequest = {}, |
| options?: RequestOptions, |
| ): Promise<Result<ListCustomersResponse>> { |
| return request(() => { |
| if (client._options.validate && req.sort !== undefined) { |
| assertValid(schemas.listCustomersQueryParams.shape.sort, req.sort) |
| } |
| const query = toWire( |
| { |
| page: req.page, |
| sort: encodeSort(req.sort, toSnakeCase), |
| filter: req.filter, |
| }, |
| schemas.listCustomersQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listCustomersQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get('openmeter/customers', { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listCustomersResponseWire, data) |
| } |
| return fromWire(data, schemas.listCustomersResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function upsertCustomer( |
| client: Client, |
| req: UpsertCustomerRequest, |
| options?: RequestOptions, |
| ): Promise<Result<UpsertCustomerResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.upsertCustomerPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.upsertCustomerPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}` |
| const body = toWire(req.body, schemas.upsertCustomerBody) |
| if (client._options.validate) { |
| assertValid(schemas.upsertCustomerBodyWire, body) |
| } |
| return http(client) |
| .put(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.upsertCustomerResponseWire, data) |
| } |
| return fromWire(data, schemas.upsertCustomerResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function deleteCustomer( |
| client: Client, |
| req: DeleteCustomerRequest, |
| options?: RequestOptions, |
| ): Promise<Result<DeleteCustomerResponse>> { |
| return request(async () => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.deleteCustomerPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.deleteCustomerPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}` |
| await http(client).delete(path, options) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function getCustomerBilling( |
| client: Client, |
| req: GetCustomerBillingRequest, |
| options?: RequestOptions, |
| ): Promise<Result<GetCustomerBillingResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.getCustomerBillingPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.getCustomerBillingPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/billing` |
| return http(client) |
| .get(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.getCustomerBillingResponseWire, data) |
| } |
| return fromWire(data, schemas.getCustomerBillingResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function updateCustomerBilling( |
| client: Client, |
| req: UpdateCustomerBillingRequest, |
| options?: RequestOptions, |
| ): Promise<Result<UpdateCustomerBillingResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.updateCustomerBillingPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.updateCustomerBillingPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/billing` |
| const body = toWire(req.body, schemas.updateCustomerBillingBody) |
| if (client._options.validate) { |
| assertValid(schemas.updateCustomerBillingBodyWire, body) |
| } |
| return http(client) |
| .put(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.updateCustomerBillingResponseWire, data) |
| } |
| return fromWire(data, schemas.updateCustomerBillingResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| export function updateCustomerBillingAppData( |
| client: Client, |
| req: UpdateCustomerBillingAppDataRequest, |
| options?: RequestOptions, |
| ): Promise<Result<UpdateCustomerBillingAppDataResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire( |
| pathParamsInput, |
| schemas.updateCustomerBillingAppDataPathParams, |
| ) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid( |
| schemas.updateCustomerBillingAppDataPathParamsWire, |
| pathParams, |
| ) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/billing/app-data` |
| const body = toWire(req.body, schemas.updateCustomerBillingAppDataBody) |
| if (client._options.validate) { |
| assertValid(schemas.updateCustomerBillingAppDataBodyWire, body) |
| } |
| return http(client) |
| .put(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.updateCustomerBillingAppDataResponseWire, data) |
| } |
| return fromWire(data, schemas.updateCustomerBillingAppDataResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function createCustomerStripeCheckoutSession( |
| client: Client, |
| req: CreateCustomerStripeCheckoutSessionRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateCustomerStripeCheckoutSessionResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire( |
| pathParamsInput, |
| schemas.createCustomerStripeCheckoutSessionPathParams, |
| ) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid( |
| schemas.createCustomerStripeCheckoutSessionPathParamsWire, |
| pathParams, |
| ) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/billing/stripe/checkout-sessions` |
| const body = toWire( |
| req.body, |
| schemas.createCustomerStripeCheckoutSessionBody, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.createCustomerStripeCheckoutSessionBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid( |
| schemas.createCustomerStripeCheckoutSessionResponseWire, |
| data, |
| ) |
| } |
| return fromWire( |
| data, |
| schemas.createCustomerStripeCheckoutSessionResponse, |
| ) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function createCustomerStripePortalSession( |
| client: Client, |
| req: CreateCustomerStripePortalSessionRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateCustomerStripePortalSessionResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire( |
| pathParamsInput, |
| schemas.createCustomerStripePortalSessionPathParams, |
| ) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid( |
| schemas.createCustomerStripePortalSessionPathParamsWire, |
| pathParams, |
| ) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/billing/stripe/portal-sessions` |
| const body = toWire(req.body, schemas.createCustomerStripePortalSessionBody) |
| if (client._options.validate) { |
| assertValid(schemas.createCustomerStripePortalSessionBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid( |
| schemas.createCustomerStripePortalSessionResponseWire, |
| data, |
| ) |
| } |
| return fromWire(data, schemas.createCustomerStripePortalSessionResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function createCreditGrant( |
| client: Client, |
| req: CreateCreditGrantRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateCreditGrantResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.createCreditGrantPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.createCreditGrantPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/credits/grants` |
| const body = toWire(req.body, schemas.createCreditGrantBody) |
| if (client._options.validate) { |
| assertValid(schemas.createCreditGrantBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.createCreditGrantResponseWire, data) |
| } |
| return fromWire(data, schemas.createCreditGrantResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function getCreditGrant( |
| client: Client, |
| req: GetCreditGrantRequest, |
| options?: RequestOptions, |
| ): Promise<Result<GetCreditGrantResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| creditGrantId: req.creditGrantId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.getCreditGrantPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.getCreditGrantPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/credits/grants/${(() => { |
| if (pathParams.creditGrantId === undefined) { |
| throw new Error('missing path parameter: creditGrantId') |
| } |
| return encodeURIComponent(String(pathParams.creditGrantId)) |
| })()}` |
| return http(client) |
| .get(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.getCreditGrantResponseWire, data) |
| } |
| return fromWire(data, schemas.getCreditGrantResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function listCreditGrants( |
| client: Client, |
| req: ListCreditGrantsRequest, |
| options?: RequestOptions, |
| ): Promise<Result<ListCreditGrantsResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.listCreditGrantsPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.listCreditGrantsPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/credits/grants` |
| const query = toWire( |
| { |
| page: req.page, |
| filter: req.filter, |
| }, |
| schemas.listCreditGrantsQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listCreditGrantsQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get(path, { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listCreditGrantsResponseWire, data) |
| } |
| return fromWire(data, schemas.listCreditGrantsResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function getCustomerCreditBalance( |
| client: Client, |
| req: GetCustomerCreditBalanceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<GetCustomerCreditBalanceResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.getCustomerCreditBalancePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.getCustomerCreditBalancePathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/credits/balance` |
| const query = toWire( |
| { |
| timestamp: req.timestamp, |
| filter: req.filter, |
| }, |
| schemas.getCustomerCreditBalanceQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.getCustomerCreditBalanceQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get(path, { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.getCustomerCreditBalanceResponseWire, data) |
| } |
| return fromWire(data, schemas.getCustomerCreditBalanceResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function createCreditAdjustment( |
| client: Client, |
| req: CreateCreditAdjustmentRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateCreditAdjustmentResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.createCreditAdjustmentPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.createCreditAdjustmentPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/credits/adjustments` |
| const body = toWire(req.body, schemas.createCreditAdjustmentBody) |
| if (client._options.validate) { |
| assertValid(schemas.createCreditAdjustmentBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.createCreditAdjustmentResponseWire, data) |
| } |
| return fromWire(data, schemas.createCreditAdjustmentResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function voidCreditGrant( |
| client: Client, |
| req: VoidCreditGrantRequest, |
| options?: RequestOptions, |
| ): Promise<Result<VoidCreditGrantResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| creditGrantId: req.creditGrantId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.voidCreditGrantPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.voidCreditGrantPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/credits/grants/${(() => { |
| if (pathParams.creditGrantId === undefined) { |
| throw new Error('missing path parameter: creditGrantId') |
| } |
| return encodeURIComponent(String(pathParams.creditGrantId)) |
| })()}/void` |
| const body = toWire(req.body, schemas.voidCreditGrantBody) |
| if (client._options.validate) { |
| assertValid(schemas.voidCreditGrantBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.voidCreditGrantResponseWire, data) |
| } |
| return fromWire(data, schemas.voidCreditGrantResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function updateCreditGrantExternalSettlement( |
| client: Client, |
| req: UpdateCreditGrantExternalSettlementRequest, |
| options?: RequestOptions, |
| ): Promise<Result<UpdateCreditGrantExternalSettlementResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| creditGrantId: req.creditGrantId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire( |
| pathParamsInput, |
| schemas.updateCreditGrantExternalSettlementPathParams, |
| ) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid( |
| schemas.updateCreditGrantExternalSettlementPathParamsWire, |
| pathParams, |
| ) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/credits/grants/${(() => { |
| if (pathParams.creditGrantId === undefined) { |
| throw new Error('missing path parameter: creditGrantId') |
| } |
| return encodeURIComponent(String(pathParams.creditGrantId)) |
| })()}/settlement/external` |
| const body = toWire( |
| req.body, |
| schemas.updateCreditGrantExternalSettlementBody, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.updateCreditGrantExternalSettlementBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid( |
| schemas.updateCreditGrantExternalSettlementResponseWire, |
| data, |
| ) |
| } |
| return fromWire( |
| data, |
| schemas.updateCreditGrantExternalSettlementResponse, |
| ) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function listCreditTransactions( |
| client: Client, |
| req: ListCreditTransactionsRequest, |
| options?: RequestOptions, |
| ): Promise<Result<ListCreditTransactionsResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.listCreditTransactionsPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.listCreditTransactionsPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/credits/transactions` |
| const query = toWire( |
| { |
| page: req.page, |
| filter: req.filter, |
| }, |
| schemas.listCreditTransactionsQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listCreditTransactionsQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get(path, { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listCreditTransactionsResponseWire, data) |
| } |
| return fromWire(data, schemas.listCreditTransactionsResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function listCustomerCharges( |
| client: Client, |
| req: ListCustomerChargesRequest, |
| options?: RequestOptions, |
| ): Promise<Result<ListCustomerChargesResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.listCustomerChargesPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.listCustomerChargesPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/charges` |
| if (client._options.validate && req.sort !== undefined) { |
| assertValid(schemas.listCustomerChargesQueryParams.shape.sort, req.sort) |
| } |
| const query = toWire( |
| { |
| page: req.page, |
| sort: encodeSort(req.sort, toSnakeCase), |
| filter: req.filter, |
| expand: req.expand, |
| }, |
| schemas.listCustomerChargesQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listCustomerChargesQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get(path, { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listCustomerChargesResponseWire, data) |
| } |
| return fromWire(data, schemas.listCustomerChargesResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function createCustomerCharges( |
| client: Client, |
| req: CreateCustomerChargesRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateCustomerChargesResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| customerId: req.customerId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.createCustomerChargesPathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.createCustomerChargesPathParamsWire, pathParams) |
| } |
| const path = `openmeter/customers/${(() => { |
| if (pathParams.customerId === undefined) { |
| throw new Error('missing path parameter: customerId') |
| } |
| return encodeURIComponent(String(pathParams.customerId)) |
| })()}/charges` |
| const body = toWire(req.body, schemas.createCustomerChargesBody) |
| if (client._options.validate) { |
| assertValid(schemas.createCustomerChargesBodyWire, body) |
| } |
| return http(client) |
| .post(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.createCustomerChargesResponseWire, data) |
| } |
| return fromWire(data, schemas.createCustomerChargesResponse) |
| }) |
| }) |
| } |
|
|