import {z} from 'zod' export type DocumentType = 'OTHER_DOCUMENTS' | 'APPLICATION' | 'ORGANIZATIONAL_DOCUMENTS' | 'CERTIFICATE_OF_GOOD_STANDING' | 'TAX_IDENTIFICATION' | 'IDENTITY_VERIFICATION' | 'PROOF_OF_RESIDENCY' | 'PROOF_OF_FUNDS' | 'SAMPLE_INVOICE' | 'OPERATING_AGREEMENT' | 'TRUST_DOCUMENTS' | 'MONEY_SERVICE_DOCUMENTS' | 'INVESTMENT_DOCUMENTS' | 'CURP' | 'AML_DOCUMENTS' | 'FUND_STRUCTURE_CHART' | 'FUND_MANAGER_REGISTRATION' | 'MEMORANDUM_OF_ASSOCIATION' | 'ORGANIZATIONAL_CHART' | 'FOUNDATION_BY_LAWS' | 'APPOINTMENT_OF_GUARDIAN_EVIDENCE' | 'LEGAL_DOMICILE_OF_BENEFICIAL_OWNERS' | 'GOVERNING_BODY_MEMBER_NAMES' | 'INDEPENDENT_AUDIT'; export type IdentityPublicDocumentUploadBody = {name: string, document_types?: Array | undefined}; export type UpdateApiIdentityIdentitiesIdentityIdDocumentsArgs = {identity_id: string, body: IdentityPublicDocumentUploadBody}; export type UpdateApiIdentityIdentitiesIdentityIdDocumentsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const documentUploadResponse = z.object({file_id: z.string().optional(), name: z.string().optional(), upload_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 }; /** * Document Upload * * PUT /identity/identities/{identity_id}/documents */ export const updateApiIdentityIdentitiesIdentityIdDocuments = async (args: UpdateApiIdentityIdentitiesIdentityIdDocumentsArgs, options?: UpdateApiIdentityIdentitiesIdentityIdDocumentsOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/identity/identities/${encodeURIComponent(String(args.identity_id))}/documents${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(documentUploadResponse, await res.json()) };