import {z} from 'zod' export type PatchApiCardCardIdSecureSettingsArgs = {card_id: string, body: {mobile?: string | undefined, pin?: string | undefined}}; export type PatchApiCardCardIdSecureSettingsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiCardCardIdSecureSettingsResponse = z.object({data: z.object({id: z.string().optional(), holder_id: z.string().optional(), holder_type: z.string().optional(), balance: z.number().int().optional(), currency: z.string().optional(), brand: z.string().optional(), label: z.string().optional(), cardholder_name: z.string().optional(), number_masked: z.string().optional(), number: z.string().optional(), exp_month: z.string().optional(), exp_year: z.string().optional(), cvv: z.string().optional(), pin: z.string().optional(), billing_address: z.object({line1: z.string().optional(), line2: z.unknown(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), postal_code: z.string().optional()}).optional(), platform_managed: z.boolean().optional(), migration_meta: z.object({previous: z.unknown(), next: z.unknown(), balance_brought: z.unknown(), balance_carried: z.unknown(), balance_refunded: z.unknown()}).optional(), is_deleted: z.boolean().optional(), status: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), message: z.string().optional(), meta: z.unknown(), status: 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 }; /** * Update Secure Settings * * PATCH /card/{card_id}/secure_settings */ export const patchApiCardCardIdSecureSettings = async (args: PatchApiCardCardIdSecureSettingsArgs, options?: PatchApiCardCardIdSecureSettingsOptions) => { const {baseUrl = "https://api.useoval.com", 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", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/card/${encodeURIComponent(String(args.card_id))}/secure_settings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiCardCardIdSecureSettingsResponse, await res.json()) };