import {z} from 'zod' export type TransliteratedAddressDto = {addressLine1?: string | undefined, addressLine2?: string | undefined, city?: string | undefined, state?: string | undefined}; export type AddressDto = {addressLine1: string, addressLine2?: string | undefined, city: string, state?: string | undefined, postalCode: string, country: string, transliterated?: TransliteratedAddressDto | undefined}; export type DocumentUploadDto = {requirementId?: string | undefined, type?: ('IDENTITY' | 'LIVENESS_CHECK' | 'PROOF_OF_ADDRESS' | 'INVOICE' | 'CONTRACT' | 'BANK_STATEMENT' | 'BUSINESS_LICENSE' | 'ARTICLES_OF_INCORPORATION' | 'ARTICLES_OF_ASSOCIATION' | 'CERTIFICATE_OF_FORMATION' | 'CERTIFICATE_OF_INCUMBENCY' | 'OPERATING_AGREEMENT' | 'PARTNERSHIP_AGREEMENT' | 'OWNERSHIP_STRUCTURE' | 'SHAREHOLDER_AGREEMENT' | 'STOCK_CERTIFICATE' | 'TAX_RETURN' | 'FINANCIAL_STATEMENT' | 'MARKETING_MATERIALS' | 'DOMAIN_OWNERSHIP_PROOF' | 'BUSINESS_PLAN' | 'BILL_OF_LADING' | 'AML_POLICY' | 'AML_COMFORT_LETTER' | 'FUNDS_FLOW_DIAGRAM' | 'GOOD_STANDING_CERTIFICATE' | 'TIN_VERIFICATION' | 'MSB_LICENSE' | 'DIRECTORS_REGISTRY' | 'OWNERSHIP_CHART' | 'PROOF_OF_SIGNATORY_AUTHORITY' | 'PROOF_OF_SOURCE_OF_FUNDS' | 'PROOF_OF_ENTITY_NAME_CHANGE' | 'REMOTE_ADDRESS_ATTESTATION' | 'E_SIGNATURE_CERTIFICATE' | 'COMPLIANCE_NOTES' | 'PROOF_OF_SOURCE_OF_WEALTH' | 'TAX_EXEMPT_ENTITY_CONFIRMATION' | 'OTHER') | undefined, subtype?: ('GOVERNMENT_ID_FRONT' | 'GOVERNMENT_ID_BACK' | 'SELFIE' | 'UTILITY_BILL' | 'LEASE_AGREEMENT') | undefined, description?: string | undefined, remarks?: string | undefined, file: string}; export type UpdateAssociatedBusinessDto = {parentEntityId?: (string | null) | undefined, countryCode?: string | undefined, email?: string | undefined, phone?: string | undefined, address?: AddressDto | undefined, hasOwnership?: boolean | undefined, hasControl?: boolean | undefined, ownershipPercentage?: number | undefined, isSigner?: boolean | undefined, isDirector?: boolean | undefined, role?: ('CEO' | 'CFO' | 'COO' | 'PRESIDENT' | 'GENERAL_COUNSEL' | 'MANAGING_MEMBER' | 'TREASURER' | 'OTHER') | undefined, supportingDocuments?: Array | undefined, attestedOwnershipStructureAt?: string | undefined, relationshipDate?: string | undefined, businessName?: string | undefined, registrationNumber?: string | undefined, dateOfIncorporation?: string | undefined, businessAddress?: AddressDto | undefined}; export type PatchApiV1CustomersCustomerIdAssociatedBusinessesIdArgs = {'X-API-Key'?: string | undefined, customerId: string, id: string, body: UpdateAssociatedBusinessDto}; export type PatchApiV1CustomersCustomerIdAssociatedBusinessesIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const individualEntityDetailsDto = z.object({firstName: z.string().optional(), nickname: z.string().optional(), lastName: z.string().optional(), middleName: z.string().optional(), dateOfBirth: z.string().optional(), taxResidenceCountry: z.string().optional(), transliteratedFirstName: z.string().optional(), transliteratedMiddleName: z.string().optional(), transliteratedLastName: z.string().optional(), taxIdentificationDocumentType: z.string().optional()}); export const transliteratedAddressDto = z.object({addressLine1: z.string().min(1).max(1024).optional(), addressLine2: z.string().min(1).max(1024).optional(), city: z.string().min(1).max(256).optional(), state: z.string().min(1).max(256).optional()}); export const addressDto = z.object({addressLine1: z.string().min(1).max(1024), addressLine2: z.string().min(1).max(1024).optional(), city: z.string().min(1).max(256), state: z.string().min(1).max(256).optional(), postalCode: z.string().min(1).max(50), country: z.string().min(2).max(2), transliterated: transliteratedAddressDto.optional()}); export const businessEntityDetailsDto = z.object({businessName: z.string().optional(), registrationNumber: z.string().optional(), dateOfIncorporation: z.string().optional(), businessAddress: addressDto.optional()}); export const verificationLinkDto = z.object({sessionId: z.string(), verificationUrl: z.string(), expiresAt: z.string(), status: z.enum(["PENDING", "ACTIVE", "IN_PROGRESS", "COMPLETED", "EXPIRED", "CANCELLED", "SUBMITTED"])}); export const associatedEntityResponseDto = z.object({id: z.string(), createdAt: z.string(), updatedAt: z.string(), entityType: z.enum(["INDIVIDUAL", "BUSINESS"]), parentEntityId: z.string().optional(), details: z.union([individualEntityDetailsDto, businessEntityDetailsDto]).optional(), countryCode: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), address: addressDto.optional(), hasOwnership: z.boolean(), hasControl: z.boolean(), ownershipPercentage: z.number().optional(), isSigner: z.boolean().optional(), isDirector: z.boolean().optional(), role: z.enum(["CEO", "CFO", "COO", "PRESIDENT", "GENERAL_COUNSEL", "MANAGING_MEMBER", "TREASURER", "OTHER"]).optional(), title: z.string().optional(), documents: z.array(z.string()).optional(), attestedOwnershipStructureAt: z.string().optional(), displayName: z.string().optional(), verificationLink: verificationLinkDto.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 an associated business * * PATCH /v1/customers/{customerId}/associated_businesses/{id} */ export const patchApiV1CustomersCustomerIdAssociatedBusinessesId = async (args: PatchApiV1CustomersCustomerIdAssociatedBusinessesIdArgs, options?: PatchApiV1CustomersCustomerIdAssociatedBusinessesIdOptions) => { const {baseUrl = "https://sandbox.api.infinite.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customerId))}/associated_businesses/${encodeURIComponent(String(args.id))}${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(associatedEntityResponseDto, await res.json()) };