import {z} from 'zod' export type CreateApiCustomersCustomerIdCardsArgs = {customer_id: string, body: {number: string, holder_name?: string | undefined, holder_document?: string | undefined, exp_month: number, exp_year: number, cvv?: string | undefined, brand?: string | undefined, label?: string | undefined, billing_address_id?: string | undefined, billing_address?: Record | undefined, options?: Record | undefined, metadata?: Record | undefined, token?: string | undefined}}; export type CreateApiCustomersCustomerIdCardsOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiCustomersCustomerIdCardsResponse = z.object({id: z.string().optional(), first_six_digits: z.string().optional(), last_four_digits: z.string().optional(), brand: z.string().optional(), holder_name: z.string().optional(), holder_document: z.string().optional(), exp_month: z.number().int().optional(), exp_year: z.number().int().optional(), status: z.string().optional(), label: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), billing_address: z.object({zip_code: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), line_1: z.string().optional(), line_2: z.string().optional()}).optional(), customer: z.object({id: z.string().optional(), name: z.string().optional(), email: z.string().optional(), document: z.string().optional(), type: z.string().optional(), delinquent: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), phones: z.object({home_phone: z.object({country_code: z.string().optional(), number: z.string().optional(), area_code: z.string().optional()}).optional(), mobile_phone: z.object({country_code: z.string().optional(), number: z.string().optional(), area_code: z.string().optional()}).optional()}).optional(), metadata: z.object({company: z.string().optional()}).optional()}).optional(), type: 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 }; /** * Criar cartão * * POST /customers/{customer_id}/cards */ export const createApiCustomersCustomerIdCards = async (args: CreateApiCustomersCustomerIdCardsArgs, options?: CreateApiCustomersCustomerIdCardsOptions) => { const {baseUrl = "https://api.mundipagg.com/core/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/customers/${encodeURIComponent(String(args.customer_id))}/cards${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(createApiCustomersCustomerIdCardsResponse, await res.json()) };