import {z} from 'zod' export type GetApiApiTaxStatusArgs = {link?: string | undefined, page_size?: number | undefined, page?: number | undefined, omit?: string | undefined, fields?: string | undefined, link__in?: Array | undefined, id?: string | undefined, id__in?: Array | undefined, created_at?: string | undefined, created_at__gt?: string | undefined, created_at__gte?: string | undefined, created_at__lt?: string | undefined, created_at__lte?: string | undefined, created_at__range?: Array | undefined}; export type GetApiApiTaxStatusOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const id = z.string(); export const link = z.string().nullable(); export const collectedAt = z.string(); export const createdAt = z.string(); export const taxStatusTaxPayerInformationSat = z.object({rfc: z.string().nullable(), curp: z.string().nullable().optional(), name: z.string().nullable().optional(), first_last_name: z.string().nullable().optional(), second_last_name: z.string().nullable().optional(), start_operations_date: z.string().nullable(), status_padron: z.string().nullable(), last_status_change_date: z.string().nullable(), commercial_name: z.string().nullable().optional(), social_name: z.string().nullable().optional(), email: z.string().nullable().optional(), phone: z.string().nullable().optional()}).nullable(); export const taxStatusAddressBetweenStreetSat = z.object({street_one: z.string().nullable().optional(), street_two: z.string().nullable().optional()}); export const taxStatusAddressSat = z.object({postal_code: z.string().nullable(), street_type: z.string().nullable().optional(), street: z.string().nullable().optional(), exterior_number: z.string().nullable().optional(), interior_number: z.string().nullable().optional(), suburb: z.string().nullable().optional(), locality: z.string().nullable().optional(), municipality: z.string().nullable().optional(), state: z.string().nullable().optional(), between_street: z.array(taxStatusAddressBetweenStreetSat).nullable().optional()}).nullable(); export const taxStatusEconomicActivitySat = z.object({economic_activity: z.string().nullable().optional(), initial_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), order: z.string().nullable().optional(), percentage: z.string().nullable().optional()}); export const taxStatusRegimensSat = z.object({end_date: z.string().nullable(), initial_date: z.string().nullable(), regimen: z.string().nullable()}); export const taxStatusObligationsSat = z.object({obligation: z.string().nullable().optional(), expiration: z.string().nullable().optional(), initial_date: z.string().nullable().optional(), end_date: z.string().nullable().optional()}); export const taxStatusSat = z.object({id: id, link: link, collected_at: collectedAt, created_at: createdAt, place_and_date_of_issuance: z.string().nullable(), official_name: z.string().nullable(), id_cif: z.string().nullable(), tax_payer_information: taxStatusTaxPayerInformationSat, address: taxStatusAddressSat, economic_activity: z.array(taxStatusEconomicActivitySat).nullable(), regimes: z.array(taxStatusRegimensSat).nullable(), obligations: z.array(taxStatusObligationsSat).nullable(), digital_stamp: z.string().nullable(), digital_stamp_chain: z.string().nullable(), pdf: z.string().nullable()}); export const getApiApiTaxStatusResponse = z.object({count: z.number().int().optional(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(taxStatusSat).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 }; /** * List tax statuses * * GET /api/tax-status/ */ export const getApiApiTaxStatus = async (args: GetApiApiTaxStatusArgs, options?: GetApiApiTaxStatusOptions) => { const {baseUrl = "https://sandbox.belvo.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.link != null) query.append("link", String(args.link)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page != null) query.append("page", String(args.page)) if (args.omit != null) query.append("omit", String(args.omit)) if (args.fields != null) query.append("fields", String(args.fields)) if (args.link__in != null) query.append("link__in", args.link__in.join(',')) if (args.id != null) query.append("id", String(args.id)) if (args.id__in != null) query.append("id__in", args.id__in.join(',')) if (args.created_at != null) query.append("created_at", String(args.created_at)) if (args.created_at__gt != null) query.append("created_at__gt", String(args.created_at__gt)) if (args.created_at__gte != null) query.append("created_at__gte", String(args.created_at__gte)) if (args.created_at__lt != null) query.append("created_at__lt", String(args.created_at__lt)) if (args.created_at__lte != null) query.append("created_at__lte", String(args.created_at__lte)) if (args.created_at__range != null) query.append("created_at__range", args.created_at__range.join(',')) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/tax-status/${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(getApiApiTaxStatusResponse, await res.json()) };