import {z} from 'zod' export type GetApiV1CustomersIdComplianceArgs = {'X-API-Key'?: string | undefined, id: string, includeHostedProgress?: boolean | undefined, forSessionId?: string | undefined}; export type GetApiV1CustomersIdComplianceOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const missingComplianceRequirementDto = z.object({requirementType: z.enum(["FIELD", "DOCUMENT"]), key: z.string(), displayName: z.string(), entityId: z.string().optional(), entityDisplayName: z.string().optional()}); export const selectOption = z.object({group: z.string().nullable().optional(), value: z.string(), label: z.string(), description: z.string().optional(), disabled: z.boolean().optional(), isExclusive: z.boolean().optional()}); export const fieldDependency = z.object({fieldPath: z.string(), value: z.union([z.boolean(), z.string(), z.number(), z.array(z.string())]).nullable().optional(), hasValue: z.boolean().nullable().optional()}); export const requiredField = z.object({fieldPath: z.string(), displayName: z.string(), dataType: z.string(), required: z.boolean(), validationPattern: z.string().nullable(), validationMessage: z.string().nullable(), allowedValues: z.array(z.string()).nullable(), exampleValue: z.string().nullable().optional(), uiTag: z.string().nullable().optional(), infoBox: z.string().nullable().optional(), link: z.string().nullable().optional(), options: z.array(selectOption).nullable().optional(), isMultiSelect: z.boolean().nullable().optional(), stepId: z.string().nullable().optional(), position: z.number().nullable().optional(), subject: z.string().nullable().optional(), entityScope: z.string().nullable().optional(), countryCode: z.string().nullable().optional(), allowNoTinPlaceholder: z.boolean().optional(), sourcePackage: z.string().nullable().optional(), dependsOn: fieldDependency.nullable().optional(), minLength: z.number().nullable().optional(), maxLength: z.number().nullable().optional()}); export const requiredDocument = z.object({requirementId: z.string().nullable().optional(), documentType: z.enum(["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"]), documentSubtype: z.enum(["GOVERNMENT_ID_FRONT", "GOVERNMENT_ID_BACK", "SELFIE", "UTILITY_BILL", "LEASE_AGREEMENT"]).nullable().optional(), displayName: z.string(), required: z.boolean(), acceptedFormats: z.array(z.string()), requiredSides: z.array(z.string()), maxSizeBytes: z.number(), infoBox: z.string().nullable().optional(), stepId: z.string(), position: z.number().nullable().optional(), subject: z.string().nullable().optional(), entityScope: z.string().nullable().optional(), documentFieldPath: z.string().nullable().optional(), minimumFileCount: z.number().nullable().optional(), sourcePackage: z.string().nullable().optional(), dependsOn: fieldDependency.nullable().optional()}); export const enhancedDiligenceComplianceDto = z.object({requiredFields: z.array(requiredField), requiredDocuments: z.array(requiredDocument), missingRequirements: z.array(missingComplianceRequirementDto)}); export const customerComplianceResponseDto = z.object({customerId: z.string(), updatedAt: z.string(), missingRequirements: z.array(missingComplianceRequirementDto), enhancedDiligence: enhancedDiligenceComplianceDto, validationErrors: z.array(z.string()), hasOpenHostedDraft: z.boolean().optional(), hostedProgressAppliesToSession: z.boolean().optional(), hostedProgressUpdatedAt: z.string().nullable().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 }; /** * Get customer compliance requirements * * GET /v1/customers/{id}/compliance */ export const getApiV1CustomersIdCompliance = async (args: GetApiV1CustomersIdComplianceArgs, options?: GetApiV1CustomersIdComplianceOptions) => { const {baseUrl = "https://sandbox.api.infinite.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (args.includeHostedProgress != null) query.append("includeHostedProgress", String(args.includeHostedProgress)) if (args.forSessionId != null) query.append("forSessionId", String(args.forSessionId)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.id))}/compliance${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(customerComplianceResponseDto, await res.json()) };