import {z} from 'zod' export type CustomerShippingContactsRequestAddress = {street1: string, street2?: string | undefined, postal_code: string, city?: string | undefined, state?: string | undefined, country: string, residential?: (boolean | null) | undefined}; export type CustomerShippingContactsRequest = {phone?: string | undefined, receiver?: string | undefined, between_streets?: string | undefined, address: CustomerShippingContactsRequestAddress, parent_id?: string | undefined, default?: (boolean | null) | undefined, deleted?: (boolean | null) | undefined, metadata?: {[key: string]: unknown} | undefined}; export type CreateApiCustomersIdShippingContactsArgs = {id: string, 'Accept-Language'?: ('es' | 'en') | undefined, 'X-Child-Company-Id'?: string | undefined, body: CustomerShippingContactsRequest}; export type CreateApiCustomersIdShippingContactsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerShippingContactsAddress = z.object({object: z.string().optional(), street1: z.string().optional(), street2: z.string().optional(), postal_code: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), residential: z.boolean().nullable().optional()}); export const customerShippingContactsResponse = z.object({phone: z.string().optional(), receiver: z.string().optional(), between_streets: z.string().nullable().optional(), address: customerShippingContactsAddress.optional(), parent_id: z.string().optional(), default: z.boolean().optional(), id: z.string().optional(), created_at: z.number().int().optional(), metadata: z.record(z.string(), z.unknown()).optional(), object: z.string().optional(), deleted: z.boolean().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 }; /** * Create a shipping contacts * * POST /customers/{id}/shipping_contacts */ export const createApiCustomersIdShippingContacts = async (args: CreateApiCustomersIdShippingContactsArgs, options?: CreateApiCustomersIdShippingContactsOptions) => { const {baseUrl = "https://api.conekta.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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(/\/+$/, '')}/customers/${encodeURIComponent(String(args.id))}/shipping_contacts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(customerShippingContactsResponse, await res.json()) };