import {z} from 'zod' export type CustomerId = string; export type Metadata = {[key: string]: string}; export type SubmitVerificationAddressRequest = {line1?: string | undefined, line2?: string | undefined, city?: string | undefined, state?: string | undefined, postal_code?: string | undefined, country?: string | undefined}; export type SubmitProofOfAddressDocumentRequest = {document_type: 'UTILITY_BILL' | 'OTHER', front_image_data: string, back_image_data?: string | undefined, country: string}; export type SubmitSourceOfWealthDocumentRequest = {front_image_data: string, back_image_data?: string | undefined, country: string}; export type SubmitIndividualIdVerificationDocumentRequest = {document_type: 'PASSPORT' | 'DRIVERS_LICENSE' | 'NATIONAL_ID' | 'RESIDENCE_PERMIT', front_image_data: string, back_image_data?: string | undefined, country: string}; export type SubmitSelfiePhotoRequest = {data: string}; export type CompanyBeneficiary = {category: 'ubos' | 'shareholders' | 'directors', can_skip?: boolean | undefined, share_size?: number | undefined, individual?: ({first_name: string, last_name: string, middle_name?: string | undefined, dob?: string | undefined, email?: string | undefined, phone?: unknown | undefined, tax_residence_country?: string | undefined, share_size?: number | undefined, address?: SubmitVerificationAddressRequest | undefined, nationality?: string | undefined, id_documents?: Array | undefined, proof_of_address_documents?: Array | undefined, selfie_photo?: SubmitSelfiePhotoRequest | undefined}) | undefined, company?: ({company_name: string, country: string, registration_number?: string | undefined, legal_address?: SubmitVerificationAddressRequest | undefined, share_size?: number | undefined}) | undefined}; export type SubmitCompanyRegistrationDocumentRequest = {document_type: 'COMPANY_DOC', id_doc_sub_type: 'INFORMATION_STATEMENT' | 'INCORPORATION_CERT', front_image_data: string, back_image_data?: string | undefined, country: string}; export type UpdateCustomerRequest = {entitlements?: (Array<'base_payout' | 'virtual_account'>) | undefined, email?: string | undefined, phone?: unknown | undefined, metadata?: Metadata | undefined, first_name?: string | undefined, last_name?: string | undefined, middle_name?: string | undefined, dob?: string | undefined, nationality?: string | undefined, tax_id_number?: string | undefined, address?: SubmitVerificationAddressRequest | undefined, proof_of_address_documents?: Array | undefined, source_of_wealth_documents?: Array | undefined, id_documents?: Array | undefined, selfie_photo?: SubmitSelfiePhotoRequest | undefined, company_name?: string | undefined, country?: string | undefined, registration_number?: string | undefined, legal_address?: SubmitVerificationAddressRequest | undefined, incorporated_on?: string | undefined, type?: string | undefined, tax_id?: string | undefined, registration_location?: string | undefined, website?: string | undefined, postal_address?: SubmitVerificationAddressRequest | undefined, alternative_names?: Array | undefined, beneficiaries?: Array | undefined, company_registration_documents?: Array | undefined, describe_business?: string | undefined, conduct_money_services?: boolean | undefined, describe_compliance_controls?: string | undefined, main_source_of_funds?: ('BUSINESS_LOANS' | 'GRANTS' | 'INTER_COMPANY_FUNDS' | 'INVESTMENT_PROCEEDS' | 'LEGAL_SETTLEMENT' | 'OWNERS_CAPITAL' | 'PENSION_RETIREMENT' | 'SALE_OF_ASSETS' | 'SALES_OF_GOODS_AND_SERVICES' | 'THIRD_PARTY_FUNDS' | 'TREASURY_RESERVES') | undefined, how_did_you_come_across_stables?: string | undefined, describe_money_services?: string | undefined, account_purpose?: ('CHARITABLE_DONATIONS' | 'ECOMMERCE_RETAIL_PAYMENTS' | 'INVESTMENT_PURPOSES' | 'PAYMENTS_TO_FRIENDS_OR_FAMILY_ABROAD' | 'PAYROLL' | 'PERSONAL_OR_LIVING_EXPENSES' | 'PROTECT_WEALTH' | 'PURCHASE_GOODS_AND_SERVICES' | 'RECEIVE_PAYMENTS_FOR_GOODS_AND_SERVICES' | 'TAX_OPTIMIZATION' | 'THIRD_PARTY_MONEY_TRANSMISSION' | 'TREASURY_MANAGEMENT' | 'OTHER') | undefined, account_purpose_other?: string | undefined, is_dao?: boolean | undefined, industry_selection?: string | undefined, expected_annual_revenue?: ('0_99999' | '100000_999999' | '1000000_9999999' | '10000000_49999999' | '50000000_249999999' | '250000000_plus') | undefined, expected_monthly_payments?: string | undefined, source_of_funds?: ('BUSINESS_LOANS' | 'GRANTS' | 'INTER_COMPANY_FUNDS' | 'INVESTMENT_PROCEEDS' | 'LEGAL_SETTLEMENT' | 'OWNERS_CAPITAL' | 'PENSION_RETIREMENT' | 'SALE_OF_ASSETS' | 'SALES_OF_GOODS_AND_SERVICES' | 'THIRD_PARTY_FUNDS' | 'TREASURY_RESERVES') | undefined, source_of_funds_description?: string | undefined, operate_in_prohibited_country?: boolean | undefined, does_your_business_engage_in_high_risk_activities?: ('yes' | 'no') | undefined, high_risk_activities?: (Array<'ADULT_ENTERTAINMENT' | 'GAMBLING' | 'HOLD_CLIENT_FUNDS' | 'INVESTMENT_SERVICES' | 'LENDING_BANKING' | 'MARIJUANA_OR_RELATED_SERVICES' | 'MONEY_SERVICES' | 'NICOTINE_TOBACCO_OR_RELATED_SERVICES' | 'OPERATE_FOREIGN_EXCHANGE_VIRTUAL_CURRENCIES_BROKERAGE_OTC' | 'PHARMACEUTICALS' | 'PRECIOUS_METALS_PRECIOUS_STONES_JEWELRY' | 'SAFE_DEPOSIT_BOX_RENTALS' | 'THIRD_PARTY_PAYMENT_PROCESSING' | 'WEAPONS_FIREARMS_AND_EXPLOSIVES'>) | undefined, accept_terms?: boolean | undefined, bank_statement_file_data?: string | undefined, flow_of_funds_file_data?: string | undefined}; export type PatchApiApiV1CustomerCustomerIdArgs = {customerId: CustomerId, body: UpdateCustomerRequest}; export type PatchApiApiV1CustomerCustomerIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerId = z.string(); export const metadata = z.record(z.string(), z.string()); export const verificationLevelResponse = z.object({level: z.enum(["kyc_level_0", "kyc_level_1", "kyc_level_2", "base_business", "individual_base", "business_base", "individual_enhanced"]), status: z.enum(["in_progress", "approved", "rejected", "requires_action"]), sub_status: z.array(z.enum(["BAD_PROOF_OF_IDENTITY", "BAD_PROOF_OF_ADDRESS", "DOCUMENT_PAGE_MISSING", "OTHER", "FILE_CORRUPTED", "FILE_EMPTY", "FILE_TOO_LARGE", "FILE_UNSUPPORTED_TYPE", "FAILED_TO_SUBMIT", "FAILED_TO_SUBMIT_BENEFICIARY"])).optional()}); export const getCustomerResponse = z.object({customer_id: customerId, external_customer_id: z.string().nullable(), customer_type: z.enum(["individual", "business"]), email: z.string(), phone: z.string().optional(), entitlements: z.array(z.object({name: z.string(), status: z.enum(["submitted", "in_progress", "approved", "rejected"])})).optional(), first_name: z.string().optional(), last_name: z.string().optional(), company_name: z.string().optional(), created_at: z.string(), updated_at: z.string(), metadata: metadata.optional(), verification_levels: z.array(verificationLevelResponse), status: z.string().optional(), compliance_lock: z.object({locked_at: z.string(), locked_by_user_id: z.string(), locked_by_user_name: z.string().nullable().optional(), locked_by_user_email: z.string().nullable().optional(), lock_reason: 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 }; /** * Update customer key details and entitlements * * PATCH /api/v1/customer/{customerId} * * Also accepts auth: apiKeyAuth */ export const patchApiApiV1CustomerCustomerId = async (args: PatchApiApiV1CustomerCustomerIdArgs, options?: PatchApiApiV1CustomerCustomerIdOptions) => { const {baseUrl = "https://api.stables.money", 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(/\/+$/, '')}/api/v1/customer/${encodeURIComponent(String(args.customerId))}${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(getCustomerResponse, await res.json()) };