Leon4gr45's picture
Upload folder using huggingface_hub (part 2)
1477a90 verified
Raw
History Blame Contribute Delete
31.9 kB
// Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
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'
/**
* Create customer
*
* POST /openmeter/customers
*/
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)
})
})
}
/**
* Get customer
*
* GET /openmeter/customers/{customerId}
*/
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)
})
})
}
/**
* List customers
*
* GET /openmeter/customers
*/
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)
})
})
}
/**
* Upsert customer
*
* PUT /openmeter/customers/{customerId}
*/
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)
})
})
}
/**
* Delete customer
*
* DELETE /openmeter/customers/{customerId}
*/
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)
})
}
/**
* Get customer billing data
*
* GET /openmeter/customers/{customerId}/billing
*/
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)
})
})
}
/**
* Update customer billing data
*
* PUT /openmeter/customers/{customerId}/billing
*/
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)
})
})
}
/**
* Update customer billing app data
*
* PUT /openmeter/customers/{customerId}/billing/app-data
*/
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)
})
})
}
/**
* Create Stripe Checkout Session
*
* Create a [Stripe Checkout Session](https://docs.stripe.com/payments/checkout)
* for the customer.
*
* Creates a Checkout Session for collecting payment method information from
* customers. The session operates in "setup" mode, which collects payment details
* without charging the customer immediately. The collected payment method can be
* used for future subscription billing.
*
* For hosted checkout sessions, redirect customers to the returned URL. For
* embedded sessions, use the client_secret to initialize Stripe.js in your
* application.
*
* POST /openmeter/customers/{customerId}/billing/stripe/checkout-sessions
*/
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,
)
})
})
}
/**
* Create Stripe customer portal session
*
* Create Stripe Customer Portal Session.
*
* Useful to redirect the customer to the Stripe Customer Portal to manage their
* payment methods, change their billing address and access their invoice history.
* Only returns URL if the customer billing profile is linked to a stripe app and
* customer.
*
* POST /openmeter/customers/{customerId}/billing/stripe/portal-sessions
*/
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)
})
})
}
/**
* Create a new credit grant
*
* Create a new credit grant. A credit grant represents an allocation of prepaid
* credits to a customer.
*
* POST /openmeter/customers/{customerId}/credits/grants
*/
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)
})
})
}
/**
* Get a credit grant
*
* Get a credit grant.
*
* GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}
*/
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)
})
})
}
/**
* List credit grants
*
* List credit grants.
*
* GET /openmeter/customers/{customerId}/credits/grants
*/
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)
})
})
}
/**
* Get a customer's credit balance
*
* Get a credit balance.
*
* GET /openmeter/customers/{customerId}/credits/balance
*/
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)
})
})
}
/**
* Create a credit adjustment
*
* A credit adjustment can be used to make manual adjustments to a customer's
* credit balance.
*
* Supported use-cases:
*
* - Usage correction
*
* POST /openmeter/customers/{customerId}/credits/adjustments
*/
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)
})
})
}
/**
* Void credit grant
*
* Void a credit grant, forfeiting the remaining unused balance.
*
* Voiding is a forward-looking, irreversible operation. Credits already consumed
* by usage remain unaffected — only the remaining balance is forfeited. The grant
* reads as `voided` status afterwards. Payment state is not adjusted when
* `payment_adjustment` is `none`, so invoice-backed or externally collected
* payments may still collect the original amount. Only `active` grants can be
* voided; voiding a pending, expired, or fully consumed grant returns a conflict.
* Retrying a successful void is an idempotent success.
*
* POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/void
*/
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)
})
})
}
/**
* Update credit grant external settlement status
*
* Update the payment settlement status of an externally funded credit grant.
*
* Use this endpoint to synchronize the payment state of an external payment with
* the system so that revenue recognition and credit availability work as expected.
*
* POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/settlement/external
*/
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,
)
})
})
}
/**
* List credit transactions
*
* List credit transactions for a customer.
*
* Returns an immutable, chronological record of credit movements: funded credits
* and consumed credits. Transactions are returned in reverse chronological order
* by default.
*
* GET /openmeter/customers/{customerId}/credits/transactions
*/
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)
})
})
}
/**
* List customer charges
*
* List customer charges.
*
* Returns the customer's charges that are represented as either flat fee or
* usage-based charges.
*
* GET /openmeter/customers/{customerId}/charges
*/
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)
})
})
}
/**
* Create customer charge
*
* Create customer charge.
*
* POST /openmeter/customers/{customerId}/charges
*/
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)
})
})
}