| |
|
|
| 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 { |
| ListInvoicesRequest, |
| ListInvoicesResponse, |
| GetInvoiceRequest, |
| GetInvoiceResponse, |
| UpdateInvoiceRequest, |
| UpdateInvoiceResponse, |
| DeleteInvoiceRequest, |
| DeleteInvoiceResponse, |
| AdvanceInvoiceRequest, |
| AdvanceInvoiceResponse, |
| ApproveInvoiceRequest, |
| ApproveInvoiceResponse, |
| RetryInvoiceRequest, |
| RetryInvoiceResponse, |
| SnapshotQuantitiesInvoiceRequest, |
| SnapshotQuantitiesInvoiceResponse, |
| } from '../models/operations/invoices.js' |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function listInvoices( |
| client: Client, |
| req: ListInvoicesRequest = {}, |
| options?: RequestOptions, |
| ): Promise<Result<ListInvoicesResponse>> { |
| return request(() => { |
| if (client._options.validate && req.sort !== undefined) { |
| assertValid(schemas.listInvoicesQueryParams.shape.sort, req.sort) |
| } |
| const query = toWire( |
| { |
| page: req.page, |
| sort: encodeSort(req.sort, toSnakeCase), |
| filter: req.filter, |
| }, |
| schemas.listInvoicesQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listInvoicesQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get('openmeter/billing/invoices', { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listInvoicesResponseWire, data) |
| } |
| return fromWire(data, schemas.listInvoicesResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function getInvoice( |
| client: Client, |
| req: GetInvoiceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<GetInvoiceResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| invoiceId: req.invoiceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.getInvoicePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.getInvoicePathParamsWire, pathParams) |
| } |
| const path = `openmeter/billing/invoices/${(() => { |
| if (pathParams.invoiceId === undefined) { |
| throw new Error('missing path parameter: invoiceId') |
| } |
| return encodeURIComponent(String(pathParams.invoiceId)) |
| })()}` |
| return http(client) |
| .get(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.getInvoiceResponseWire, data) |
| } |
| return fromWire(data, schemas.getInvoiceResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function updateInvoice( |
| client: Client, |
| req: UpdateInvoiceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<UpdateInvoiceResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| invoiceId: req.invoiceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.updateInvoicePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.updateInvoicePathParamsWire, pathParams) |
| } |
| const path = `openmeter/billing/invoices/${(() => { |
| if (pathParams.invoiceId === undefined) { |
| throw new Error('missing path parameter: invoiceId') |
| } |
| return encodeURIComponent(String(pathParams.invoiceId)) |
| })()}` |
| const body = toWire(req.body, schemas.updateInvoiceBody) |
| if (client._options.validate) { |
| assertValid(schemas.updateInvoiceBodyWire, body) |
| } |
| return http(client) |
| .put(path, { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.updateInvoiceResponseWire, data) |
| } |
| return fromWire(data, schemas.updateInvoiceResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function deleteInvoice( |
| client: Client, |
| req: DeleteInvoiceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<DeleteInvoiceResponse>> { |
| return request(async () => { |
| const pathParamsInput = { |
| invoiceId: req.invoiceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.deleteInvoicePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.deleteInvoicePathParamsWire, pathParams) |
| } |
| const path = `openmeter/billing/invoices/${(() => { |
| if (pathParams.invoiceId === undefined) { |
| throw new Error('missing path parameter: invoiceId') |
| } |
| return encodeURIComponent(String(pathParams.invoiceId)) |
| })()}` |
| await http(client).delete(path, options) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function advanceInvoice( |
| client: Client, |
| req: AdvanceInvoiceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<AdvanceInvoiceResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| invoiceId: req.invoiceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.advanceInvoicePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.advanceInvoicePathParamsWire, pathParams) |
| } |
| const path = `openmeter/billing/invoices/${(() => { |
| if (pathParams.invoiceId === undefined) { |
| throw new Error('missing path parameter: invoiceId') |
| } |
| return encodeURIComponent(String(pathParams.invoiceId)) |
| })()}/advance` |
| return http(client) |
| .post(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.advanceInvoiceResponseWire, data) |
| } |
| return fromWire(data, schemas.advanceInvoiceResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function approveInvoice( |
| client: Client, |
| req: ApproveInvoiceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<ApproveInvoiceResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| invoiceId: req.invoiceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.approveInvoicePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.approveInvoicePathParamsWire, pathParams) |
| } |
| const path = `openmeter/billing/invoices/${(() => { |
| if (pathParams.invoiceId === undefined) { |
| throw new Error('missing path parameter: invoiceId') |
| } |
| return encodeURIComponent(String(pathParams.invoiceId)) |
| })()}/approve` |
| return http(client) |
| .post(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.approveInvoiceResponseWire, data) |
| } |
| return fromWire(data, schemas.approveInvoiceResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function retryInvoice( |
| client: Client, |
| req: RetryInvoiceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<RetryInvoiceResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| invoiceId: req.invoiceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.retryInvoicePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.retryInvoicePathParamsWire, pathParams) |
| } |
| const path = `openmeter/billing/invoices/${(() => { |
| if (pathParams.invoiceId === undefined) { |
| throw new Error('missing path parameter: invoiceId') |
| } |
| return encodeURIComponent(String(pathParams.invoiceId)) |
| })()}/retry` |
| return http(client) |
| .post(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.retryInvoiceResponseWire, data) |
| } |
| return fromWire(data, schemas.retryInvoiceResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function snapshotQuantitiesInvoice( |
| client: Client, |
| req: SnapshotQuantitiesInvoiceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<SnapshotQuantitiesInvoiceResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| invoiceId: req.invoiceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.snapshotQuantitiesInvoicePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.snapshotQuantitiesInvoicePathParamsWire, pathParams) |
| } |
| const path = `openmeter/billing/invoices/${(() => { |
| if (pathParams.invoiceId === undefined) { |
| throw new Error('missing path parameter: invoiceId') |
| } |
| return encodeURIComponent(String(pathParams.invoiceId)) |
| })()}/snapshot-quantities` |
| return http(client) |
| .post(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.snapshotQuantitiesInvoiceResponseWire, data) |
| } |
| return fromWire(data, schemas.snapshotQuantitiesInvoiceResponse) |
| }) |
| }) |
| } |
|
|