import {z} from 'zod' export type GetApiV1ChargesIdTaxDetailsArgs = {id: number}; export type GetApiV1ChargesIdTaxDetailsOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const revAppComponentsLink = z.object({rel: z.string().optional(), href: z.string().optional()}); export const revAppModelsInvoiceTaxValue = z.object({invoice_tax_id: z.number().int().optional(), description: z.string().optional(), amount: z.number().optional(), tax_authority: z.string().optional(), links: z.array(revAppComponentsLink).optional()}); export const revAppModelsChargeTaxDetails = z.object({charge_id: z.number().int().optional(), tax_amount: z.number().optional(), tax_details: z.array(revAppModelsInvoiceTaxValue).optional(), links: z.array(revAppComponentsLink).optional()}); export const getApiV1ChargesIdTaxDetailsResponse = z.array(revAppModelsChargeTaxDetails); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * View the tax details of a specified charge. * * GET /v1/Charges/{id}/TaxDetails */ export const getApiV1ChargesIdTaxDetails = async (args: GetApiV1ChargesIdTaxDetailsArgs, options?: GetApiV1ChargesIdTaxDetailsOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Charges/${encodeURIComponent(String(args.id))}/TaxDetails${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1ChargesIdTaxDetailsResponse, await res.json()) };