import {z} from 'zod' export type PaymentMethodId = string; export type TransactionRequirementRequest = {external_account_id: PaymentMethodId, source_asset?: (string | null) | undefined, currency?: (string | null) | undefined, purpose_code?: (string | null) | undefined}; export type CreateApiV1CustomersCustomerIdTransactionRequirementArgs = {customer_id: string, body: TransactionRequirementRequest}; export type CreateApiV1CustomersCustomerIdTransactionRequirementOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const rfiRequirementType = z.enum(["FILE", "TEXT"]); export const rfiDocumentType = z.enum(["INVOICE", "CONTRACT_AGREEMENT", "CONTRACT", "SETTLEMENT_STATEMENT", "STATEMENT_OF_ACCOUNT", "PURCHASE_ORDER", "PAYMENT_ORDER_INSTRUCTION", "BENEFICIARY_BANK_DETAILS", "WIRE_INSTRUCTIONS", "COUNTERPARTY_KYC_DOCUMENT", "PROOF_OF_RELATIONSHIP", "COUNTERPARTY_EVIDENCE", "BANK_STATEMENT", "TRADING_INVESTMENT_STATEMENT", "CAPITAL_CONTRIBUTION_EVIDENCE", "DISTRIBUTION_REPAYMENT_EVIDENCE", "SOURCE_OF_FUNDS_EXPLANATION", "WALLET_OWNERSHIP_EVIDENCE", "TRANSACTION_HASH", "EXCHANGE_STATEMENT", "STABLECOIN_MINT_REDEMPTION_EVIDENCE", "BLOCKCHAIN_TRANSACTION_SUPPORT", "REVISED_INVOICE_AGREEMENT", "EXPLANATION_LETTER", "DISCREPANCY_EXPLANATION", "UPDATED_PAYMENT_REFERENCE", "OTHER_SUPPORTING_DOCUMENT", "DELIVERY_SLIP", "CUSTOMS_DECLARATION", "BILL_OF_LADING", "IDENTIFICATION_DOCUMENTS", "PROOF_OF_ADDRESS", "REGISTRATION_DOCUMENTS", "INVOICE_FOR_FLIGHT_TICKET", "VISA", "HOTEL_BOOKING", "DELIVERY_SLIP-LOGISTIC_BILL", "DELIVERY_SLIP-CUSTOMS_DECLARATION", "DELIVERY_SLIP-BILL_OF_LADING", "PURCHASE_ORDER-FLIGHT_TICKET", "TRAVEL_DOCUMENT", "PURCHASE_ORDER-HOTEL_BOOKING", "STANDARD_RECIPIENT_INFORMATION", "RECIPIENT_BUSINESS_DETAILS", "RECIPIENT_ADDRESS_REGISTRATION", "RECIPIENT_CONTACT_DETAILS"]); export const transactionRequirementView = z.object({type: rfiRequirementType, accepted_document_types: z.array(rfiDocumentType), note: z.string()}); export const transactionRequirementResponse = z.object({required: z.boolean(), requirements: z.array(transactionRequirementView)}); 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 }; /** * POST /v1/customers/{customer_id}/transaction/requirement */ export const createApiV1CustomersCustomerIdTransactionRequirement = async (args: CreateApiV1CustomersCustomerIdTransactionRequirementArgs, options?: CreateApiV1CustomersCustomerIdTransactionRequirementOptions) => { const {baseUrl = "https://api.1money.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customer_id))}/transaction/requirement${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(transactionRequirementResponse, await res.json()) };