import {z} from 'zod' export type DeleteApiOrdersIdTaxLinesTaxIdArgs = {id: string, tax_id: string, 'Accept-Language'?: ('es' | 'en') | undefined, 'X-Child-Company-Id'?: string | undefined}; export type DeleteApiOrdersIdTaxLinesTaxIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const orderTaxRequestMetadataValue = z.union([z.string().max(249), z.number().int(), z.number(), z.boolean()]); export const orderTaxResponse = z.object({amount: z.number().int().gte(0), description: z.string().min(3), metadata: z.record(z.string(), orderTaxRequestMetadataValue).optional(), id: z.string(), object: z.string().optional(), parent_id: z.string().optional()}); 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 }; /** * Delete Tax * * DELETE /orders/{id}/tax_lines/{tax_id} */ export const deleteApiOrdersIdTaxLinesTaxId = async (args: DeleteApiOrdersIdTaxLinesTaxIdArgs, options?: DeleteApiOrdersIdTaxLinesTaxIdOptions) => { const {baseUrl = "https://api.conekta.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.conekta-v2.3.0+json") if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args['X-Child-Company-Id'] != null) headers.set("X-Child-Company-Id", String(args['X-Child-Company-Id'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/orders/${encodeURIComponent(String(args.id))}/tax_lines/${encodeURIComponent(String(args.tax_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(orderTaxResponse, await res.json()) };