import {z} from 'zod' export type GetApiV1BatchesBatchUuidBanktransfersArgs = {batchUuid: string, offset?: number | undefined, limit?: number | undefined}; export type GetApiV1BatchesBatchUuidBanktransfersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const batchItemBankTransfer = z.object({batchItemUuid: z.string().optional(), status: z.enum(["Submitted", "Removed", "Suceeded", "Failed"]).optional(), result: z.object({code: z.number().int().optional(), message: z.string().optional()}).optional(), dateCreated: z.string().optional(), lastUpdated: z.string().optional(), icanFrom: z.number().int().optional(), amount: z.number().int().optional(), myRef: z.string().optional(), yourRef: z.string().optional(), refId: z.number().int().optional(), payeeType: z.enum(["ACCOUNT_DETAILS", "PAYEE_ID"]).optional(), payeeId: z.number().int().optional(), destIban: z.string().optional(), destAccountHolderName: z.string().optional(), payeeCheckStatus: z.enum(["FULL_MATCH", "PARTIAL_MATCH", "NO_MATCH", "UNABLE_TO_MATCH"]).optional(), payeeCheckPartialMatchName: z.string().optional()}); export const getApiV1BatchesBatchUuidBanktransfersResponse = z.object({total: z.number().int().optional(), items: z.array(batchItemBankTransfer).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 }; /** * List items for a bank transfer batch * * GET /v1/batches/{batchUuid}/banktransfers */ export const getApiV1BatchesBatchUuidBanktransfers = async (args: GetApiV1BatchesBatchUuidBanktransfersArgs, options?: GetApiV1BatchesBatchUuidBanktransfersOptions) => { const {baseUrl = "https://api.fire.com/business", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/batches/${encodeURIComponent(String(args.batchUuid))}/banktransfers${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(getApiV1BatchesBatchUuidBanktransfersResponse, await res.json()) };