import {z} from 'zod' export type GetApiV1TransactionsBatchesBatchIdArgs = {batch_id: string}; export type GetApiV1TransactionsBatchesBatchIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const beneficiaryType = z.enum(["individual", "business"]); export const purposeCode = z.enum(["charity", "commercial_investment", "corporate_card", "credit_card", "dividend", "family", "financial_services", "goods_sold", "goods_bought", "government", "insurance", "intergroup_transfer", "intra_group_dividends", "information_technology", "leasing", "loan_charges", "merchant_settlement", "mobile_wallet", "non_resident_transfer_between_accounts", "none", "pension", "personal_expenses", "prepaid_cards", "professional", "rental", "resident_transfer_between_accounts", "salaries", "tax", "telecommunications", "travel", "utility_bill"]); export const localPaymentRecord = z.object({beneficiary_account_number: z.string().max(27).nullable().optional(), beneficiary_address_country: z.string().nullable().optional(), beneficiary_address_line1: z.string().max(50), beneficiary_address_line2: z.string().max(50).nullable().optional(), beneficiary_address_line3: z.string().max(50).nullable().optional(), beneficiary_address_line4: z.string().max(50).nullable().optional(), beneficiary_bank_branch: z.string().nullable().optional(), beneficiary_bic: z.string().min(8), beneficiary_date_of_birth: z.string().nullable().optional(), beneficiary_email: z.string().nullable().optional(), beneficiary_iban: z.string().nullable().optional(), beneficiary_id_number: z.string().nullable().optional(), beneficiary_id_type: z.string().nullable().optional(), beneficiary_name: z.string().max(140), beneficiary_nationality: z.string().nullable().optional(), beneficiary_phone: z.string().nullable().optional(), beneficiary_sort_code: z.string().max(6).nullable().optional(), beneficiary_type: beneficiaryType.optional(), beneficiary_wire_routing_number: z.string().max(12).nullable().optional(), external_reference: z.string().min(100), instructed_amount: z.number().int().gte(0), purpose: purposeCode, sequence_no: z.number().int().gte(0), source_account_id: z.string()}); export const batchStatus = z.enum(["Created", "Processed"]); export const batch = z.object({batch_id: z.string(), created_at: z.string(), file_name: z.string(), record_count: z.number().int().gte(0), records: z.array(localPaymentRecord), status: batchStatus, total_instructed_amount: z.number().int().gte(0)}); 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 a single batch * * GET /v1/transactions/batches/{batch_id} */ export const getApiV1TransactionsBatchesBatchId = async (args: GetApiV1TransactionsBatchesBatchIdArgs, options?: GetApiV1TransactionsBatchesBatchIdOptions) => { 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/transactions/batches/${encodeURIComponent(String(args.batch_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(batch, await res.json()) };