import {z} from 'zod' export type ResidentialAddress = {line1?: string | undefined, line2?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, zipCode?: string | undefined}; export type IdentificationDocument = {type: 'ssn' | 'itin' | 'driversLicense' | 'passport', issuingCountry: string, number: string}; export type CustomerUpdate = {firstName?: string | undefined, middleName?: string | undefined, lastName?: string | undefined, email?: string | undefined, phone?: string | undefined, birthDate?: string | undefined, nationality?: string | undefined, ipAddress?: string | undefined, externalId?: string | undefined, signedAgreement?: boolean | undefined, residentialAddress?: ResidentialAddress | undefined, identifyingInformation?: Array | undefined, endorsements?: (Array<'basic' | 'cryptoCustody' | 'usd'>) | undefined, metadata?: {[key: string]: string} | undefined}; export type PatchApiCustomersCustomerIdArgs = {customerId: string, body: CustomerUpdate}; export type PatchApiCustomersCustomerIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customer = z.object({id: z.string().optional(), object: z.string().optional(), type: z.literal("individual").optional(), firstName: z.string().nullable().optional(), middleName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional(), phone: z.string().nullable().optional(), nationality: z.string().nullable().optional(), externalId: z.string().nullable().optional(), status: z.enum(["active", "inactive"]).optional(), signedAgreement: z.boolean().optional(), signedAgreementAt: z.string().nullable().optional(), wallets: z.array(z.object({id: z.string().optional(), type: z.string().optional(), address: z.string().optional(), network: z.string().optional(), asset: z.string().optional(), balance: z.string().optional(), estimatedValueUsd: z.string().optional(), createdAt: z.string().optional()})).optional(), endorsements: z.array(z.object({name: z.enum(["basic", "cryptoCustody", "usd"]).optional(), status: z.enum(["INACTIVE", "PENDING", "ISSUES", "ACTIVE", "REJECTED", "REVOKED_ISSUES", "OFFBOARDED"]).optional(), rejectionReasons: z.array(z.object({developerReason: z.string().optional(), reason: z.string().optional()})).optional(), requirements: z.object({complete: z.array(z.string()).optional(), pending: z.array(z.string()).optional(), missing: z.array(z.string()).nullable().optional(), issues: z.array(z.string()).optional()}).optional()})).optional(), metadata: z.record(z.string(), z.string()).nullable().optional(), createdAt: z.string().optional(), updatedAt: 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 a customer * * PATCH /customers/{customerId} */ export const patchApiCustomersCustomerId = async (args: PatchApiCustomersCustomerIdArgs, options?: PatchApiCustomersCustomerIdOptions) => { const {baseUrl = "https://sandbox-api.polygon.technology/v0.10", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/customers/${encodeURIComponent(String(args.customerId))}${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(customer, await res.json()) };