// 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 } from '../lib/encodings.js' import { toWire, toPathWire, fromWire, assertValid } from '../lib/wire.js' import * as schemas from '../models/schemas.js' import type { CreateTaxCodeRequest, CreateTaxCodeResponse, GetTaxCodeRequest, GetTaxCodeResponse, ListTaxCodesRequest, ListTaxCodesResponse, UpsertTaxCodeRequest, UpsertTaxCodeResponse, DeleteTaxCodeRequest, DeleteTaxCodeResponse, } from '../models/operations/tax.js' /** * Create tax code * * POST /openmeter/tax-codes */ export function createTaxCode( client: Client, req: CreateTaxCodeRequest, options?: RequestOptions, ): Promise> { return request(() => { const body = toWire(req, schemas.createTaxCodeBody) if (client._options.validate) { assertValid(schemas.createTaxCodeBodyWire, body) } return http(client) .post('openmeter/tax-codes', { ...options, json: body }) .json() .then((data) => { if (client._options.validate) { assertValid(schemas.createTaxCodeResponseWire, data) } return fromWire(data, schemas.createTaxCodeResponse) }) }) } /** * Get tax code * * GET /openmeter/tax-codes/{taxCodeId} */ export function getTaxCode( client: Client, req: GetTaxCodeRequest, options?: RequestOptions, ): Promise> { return request(() => { const pathParamsInput = { taxCodeId: req.taxCodeId, } const pathParams = client._options.validate ? toPathWire(pathParamsInput, schemas.getTaxCodePathParams) : pathParamsInput if (client._options.validate) { assertValid(schemas.getTaxCodePathParamsWire, pathParams) } const path = `openmeter/tax-codes/${(() => { if (pathParams.taxCodeId === undefined) { throw new Error('missing path parameter: taxCodeId') } return encodeURIComponent(String(pathParams.taxCodeId)) })()}` return http(client) .get(path, options) .json() .then((data) => { if (client._options.validate) { assertValid(schemas.getTaxCodeResponseWire, data) } return fromWire(data, schemas.getTaxCodeResponse) }) }) } /** * List tax codes * * GET /openmeter/tax-codes */ export function listTaxCodes( client: Client, req: ListTaxCodesRequest = {}, options?: RequestOptions, ): Promise> { return request(() => { const query = toWire( { page: req.page, includeDeleted: req.includeDeleted, }, schemas.listTaxCodesQueryParams, ) if (client._options.validate) { assertValid(schemas.listTaxCodesQueryParamsWire, query) } const searchParams = toURLSearchParams(query) return http(client) .get('openmeter/tax-codes', { ...options, searchParams }) .json() .then((data) => { if (client._options.validate) { assertValid(schemas.listTaxCodesResponseWire, data) } return fromWire(data, schemas.listTaxCodesResponse) }) }) } /** * Upsert tax code * * PUT /openmeter/tax-codes/{taxCodeId} */ export function upsertTaxCode( client: Client, req: UpsertTaxCodeRequest, options?: RequestOptions, ): Promise> { return request(() => { const pathParamsInput = { taxCodeId: req.taxCodeId, } const pathParams = client._options.validate ? toPathWire(pathParamsInput, schemas.upsertTaxCodePathParams) : pathParamsInput if (client._options.validate) { assertValid(schemas.upsertTaxCodePathParamsWire, pathParams) } const path = `openmeter/tax-codes/${(() => { if (pathParams.taxCodeId === undefined) { throw new Error('missing path parameter: taxCodeId') } return encodeURIComponent(String(pathParams.taxCodeId)) })()}` const body = toWire(req.body, schemas.upsertTaxCodeBody) if (client._options.validate) { assertValid(schemas.upsertTaxCodeBodyWire, body) } return http(client) .put(path, { ...options, json: body }) .json() .then((data) => { if (client._options.validate) { assertValid(schemas.upsertTaxCodeResponseWire, data) } return fromWire(data, schemas.upsertTaxCodeResponse) }) }) } /** * Delete tax code * * DELETE /openmeter/tax-codes/{taxCodeId} */ export function deleteTaxCode( client: Client, req: DeleteTaxCodeRequest, options?: RequestOptions, ): Promise> { return request(async () => { const pathParamsInput = { taxCodeId: req.taxCodeId, } const pathParams = client._options.validate ? toPathWire(pathParamsInput, schemas.deleteTaxCodePathParams) : pathParamsInput if (client._options.validate) { assertValid(schemas.deleteTaxCodePathParamsWire, pathParams) } const path = `openmeter/tax-codes/${(() => { if (pathParams.taxCodeId === undefined) { throw new Error('missing path parameter: taxCodeId') } return encodeURIComponent(String(pathParams.taxCodeId)) })()}` await http(client).delete(path, options) }) }