import {z} from 'zod' export type V2FormationDocumentItem = {type?: ('REGISTRATION_DOCUMENT' | 'CONSTITUTIONAL_DOCUMENT' | 'FORMATION_DOCUMENT' | 'PROOF_OF_TAX_IDENTIFICATION' | 'EVIDENCE_OF_DIRECTORS_AND_CONTROLLERS') | undefined, description?: string | undefined, files: Array<{uri: string}>}; export type V2OwnershipDocumentItem = {type?: ('OWNERSHIP_INFORMATION' | 'OWNERSHIP_CHART' | 'PROOF_OF_SIGNATORY_AUTHORITY') | undefined, description?: string | undefined, files: Array<{uri: string}>}; export type V2SupportingDocumentItem = {type?: ('SHAREHOLDER_REGISTER' | 'PROOF_OF_NATURE_OF_BUSINESS' | 'PROOF_OF_ENTITY_NAME_CHANGE' | 'CERT_OF_INCUMBENCY' | 'PROOF_OF_SOURCE_OF_FUNDS' | 'PROOF_OF_SOURCE_OF_WEALTH' | 'AML_COMFORT_LETTER' | 'MARKETING_MATERIALS' | 'TAX_EXEMPT_ENTITY_CONFIRMATION' | 'E_SIGNATURE_CERTIFICATE' | 'FLOW_OF_FUNDS' | 'PROOF_OF_NATURE_OF_BUSINESS_LICENSE' | 'PROOF_OF_NATURE_OF_BUSINESS_AML_POLICY' | 'EVIDENCE_OF_GOOD_STANDING' | 'PROOF_OF_ACCOUNT_PURPOSE' | 'PROOF_OF_ADDRESS' | 'OTHER') | undefined, description?: string | undefined, files: Array<{uri: string}>}; export type AttachDocumentsToBusinessCustomerV2Input = {formation_documents?: Array | undefined, ownership_documents?: Array | undefined, supporting_documents?: Array | undefined, tos_policies_value: string}; export type CreateApiV2CustomersCustomerIdBusinessAttachArgs = {customer_id: string, body: AttachDocumentsToBusinessCustomerV2Input}; export type CreateApiV2CustomersCustomerIdBusinessAttachOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2CustomersCustomerIdBusinessAttachResponse = z.object({data: z.object({}).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 }; /** * Attach Documents to Business Customer V2 * * POST /v2/customers/{customer_id}/business/attach */ export const createApiV2CustomersCustomerIdBusinessAttach = async (args: CreateApiV2CustomersCustomerIdBusinessAttachArgs, options?: CreateApiV2CustomersCustomerIdBusinessAttachOptions) => { const {baseUrl = "https://sandbox.api.fin.com", 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(/\/+$/, '')}/v2/customers/${encodeURIComponent(String(args.customer_id))}/business/attach${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(createApiV2CustomersCustomerIdBusinessAttachResponse, await res.json()) };