import {z} from 'zod' export type IdempotencyKey = 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 CreateIndividualWithVerificationLink = {external_customer_id?: string | undefined, customer_type: 'individual', email?: string | undefined, phone?: unknown | undefined, entitlements?: (Array<'base_payout' | 'virtual_account'>) | 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, ttl_in_secs?: number | undefined, redirect?: ({success_url?: string | undefined, reject_url?: string | undefined, sign_key?: string | undefined, allowed_query_params?: Array | undefined}) | undefined}; 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 CreateBusinessWithVerificationLink = {external_customer_id?: string | undefined, customer_type: 'business', email?: string | undefined, phone?: unknown | undefined, entitlements?: (Array<'base_payout' | 'virtual_account'>) | undefined, metadata?: Metadata | 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, id_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, ttl_in_secs?: number | undefined, redirect?: ({success_url?: string | undefined, reject_url?: string | undefined, sign_key?: string | undefined, allowed_query_params?: Array | undefined}) | undefined}; export type CreateApiApiV1CustomerVerificationLinkArgs = {'idempotency-key': IdempotencyKey, body: CreateIndividualWithVerificationLink | CreateBusinessWithVerificationLink}; export type CreateApiApiV1CustomerVerificationLinkOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerId = z.string(); export const generateVerificationLinkResponse = z.object({customer_id: customerId, kyc_link: z.string()}); 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 }; /** * Create customer with entitlements and generate KYC verification link * * POST /api/v1/customer/verification/link * * Also accepts auth: apiKeyAuth */ export const createApiApiV1CustomerVerificationLink = async (args: CreateApiApiV1CustomerVerificationLinkArgs, options?: CreateApiApiV1CustomerVerificationLinkOptions) => { 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 (args['idempotency-key'] != null) headers.set("idempotency-key", String(args['idempotency-key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/customer/verification/link${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(generateVerificationLinkResponse, await res.json()) };