import {z} from 'zod' export type RfiTextSubmissionType = 'TEXT'; export type RfiTextSubmissionRequest = {type: RfiTextSubmissionType, text: string}; export type CreateApiV1CustomersCustomerIdRfiCasesCaseIdSubmissionsArgs = {customer_id: string, case_id: string, 'Idempotency-Key': string, 'X-OM-Content-SHA256'?: (string | null) | undefined, body: RfiTextSubmissionRequest}; export type CreateApiV1CustomersCustomerIdRfiCasesCaseIdSubmissionsOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const rfiSubmissionId = z.string(); export const rfiCaseId = z.string(); export const rfiRequirementId = z.string(); export const rfiSubmissionType = z.enum(["FILE", "TEXT"]); export const rfiSubmissionResponse = z.object({submission_id: rfiSubmissionId, case_id: rfiCaseId, requirement_id: rfiRequirementId, type: rfiSubmissionType, document_type: 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", "null"]).nullable().optional(), text: z.string().nullable().optional(), note: z.string().nullable().optional(), file_name: z.string().nullable().optional(), submitted_at: 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 }; /** * POST /v1/customers/{customer_id}/rfi-cases/{case_id}/submissions */ export const createApiV1CustomersCustomerIdRfiCasesCaseIdSubmissions = async (args: CreateApiV1CustomersCustomerIdRfiCasesCaseIdSubmissionsArgs, options?: CreateApiV1CustomersCustomerIdRfiCasesCaseIdSubmissionsOptions) => { 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 (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args['X-OM-Content-SHA256'] != null) headers.set("X-OM-Content-SHA256", String(args['X-OM-Content-SHA256'])) if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customer_id))}/rfi-cases/${encodeURIComponent(String(args.case_id))}/submissions${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(rfiSubmissionResponse, await res.json()) };