import {z} from 'zod' export type GetApiV1CustomersCustomerIdArgs = {customer_id: unknown}; export type GetApiV1CustomersCustomerIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const individualCurrencyExtra = z.object({country_of_birth: z.string().min(2).max(2), country_of_issuance: z.string().min(2).max(2), currency: z.literal("usd"), id_number: z.string().min(1).max(100), ip_address: z.string().min(2).max(45).optional(), occupation_code: z.string().min(6).max(6)}); export const gender = z.enum(["male", "female", "undefined"]); export const individualIdentification = z.union([z.object({country_of_issuance: z.string().min(2).max(2), expiry_date: z.string(), number: z.string().min(1).max(100), type: z.literal("passport")}), z.object({country_of_issuance: z.string().min(2).max(2), expiry_date: z.string(), number: z.string().min(1).max(100), type: z.literal("national_id")})]); export const address = z.object({country_code: z.string().min(2).max(2), line_1: z.string().max(50), line_2: z.string().max(50).nullable().optional(), line_3: z.string().max(50).nullable().optional(), line_4: z.string().max(50).nullable().optional()}); export const approvalStatus = z.enum(["auto_approved", "pending", "approved", "rejected"]); export const documentType = z.enum(["passport", "visa", "national_id", "trade_licence", "commercial_licence", "identity_verification_biometrics", "incorporation_cert", "incumbency_cert", "memorandum_articles", "bank_statement", "photo", "proof_of_address", "regulatory_license", "articles_of_association", "source_of_funds", "aml_cft_sanctions_ind_audit", "aml_cft_sanctions_policy", "compliance_officer_resume", "financial_statements", "share_certificate", "corporate_resolution", "wolfsberg_gcbddq", "edd_concentration_form", "other"]); export const documentSummary = z.object({document_type: documentType, id: z.string(), reference: z.string().max(35)}); export const rejectionReason = z.enum(["prohibited", "sanction", "pep", "financial_crimes", "other"]); export const customerRelationshipType = z.union([z.literal("direct"), z.object({indirect: z.object({parent_customer_id: z.string()})})]); export const aedLicenseIssuer = z.enum(["mainland", "freezone", "international"]); export const businessCurrencyExtra = z.union([z.object({currency: z.literal("usd"), industry_code: z.string().min(6).max(6), ip_address: z.string().min(2).max(45).optional(), tax_number: z.string().min(1).max(100)}), z.object({currency: z.literal("aed"), license_issuer: aedLicenseIssuer, trade_license_expiry: z.string().nullable().optional()})]); export const regulatoryLicenseType = z.enum(["banking", "card_acquiring", "card_issuer", "crypto_asset", "electronic_money", "forex", "payments", "none", "other", "trading"]); export const getCustomerResponse = z.union([z.object({individual: z.object({currency_extra: z.array(individualCurrencyExtra), date_of_birth: z.string(), first_name: z.string(), gender: gender, identification: individualIdentification.nullable().optional(), last_name: z.string(), middle_name: z.string().nullable().optional(), nationality: z.string().min(2).max(2)}), address: address, approval_status: approvalStatus, display_name: z.string(), documents: z.array(documentSummary), id: z.string(), reference: z.string().max(36), rejection_reason: rejectionReason.nullable().optional(), relationship_type: customerRelationshipType}), z.object({business: z.object({business_name: z.string(), country_of_issuance: z.string().min(2).max(2), currency_extra: z.array(businessCurrencyExtra), issuance_authority: z.string().nullable().optional(), registration_date: z.string().nullable().optional(), registration_number: z.string(), regulatory_licenses: z.array(regulatoryLicenseType)}), address: address, approval_status: approvalStatus, display_name: z.string(), documents: z.array(documentSummary), id: z.string(), reference: z.string().max(36), rejection_reason: rejectionReason.nullable().optional(), relationship_type: customerRelationshipType})]); 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 * * GET /v1/customers/{customer_id} */ export const getApiV1CustomersCustomerId = async (args: GetApiV1CustomersCustomerIdArgs, options?: GetApiV1CustomersCustomerIdOptions) => { const {baseUrl = "https://auth-sandbox.fuse.me", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customer_id))}${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(getCustomerResponse, await res.json()) };