import {z} from 'zod' export type GetApiCompaniesCurrentArgs = {'Accept-Language'?: ('es' | 'en') | undefined}; export type GetApiCompaniesCurrentOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const companyDocumentResponse = z.object({file_classification: z.enum(["id_legal_representative", "id_legal_representative_back", "cfdi", "constitutive_act_basic", "proof_of_address", "power_of_attonery", "deposit_account_cover", "permit_casino", "license_sanitation", "registration_tourism"]).optional(), status: z.string().optional(), file_name: z.string().nullable().optional()}); export const companyResponse = z.object({id: z.string(), name: z.string(), active: z.boolean(), account_status: z.string(), card_payments_enabled: z.boolean().optional(), parent_company_id: z.string().nullable().optional(), onboarding_status: z.string(), documents: z.array(companyDocumentResponse), created_at: z.number().int(), object: z.string(), three_ds_enabled: z.boolean().optional(), three_ds_mode: z.enum(["smart", "strict"]).nullable().optional(), onboarding_url: 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 }; /** * Get Current Company * * GET /companies/current */ export const getApiCompaniesCurrent = async (args: GetApiCompaniesCurrentArgs, options?: GetApiCompaniesCurrentOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/current${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(companyResponse, await res.json()) };