import {z} from 'zod' export type GetApiV1BatchesBatchUuidInternaltransfersArgs = {batchUuid: string, offset?: number | undefined, limit?: number | undefined}; export type GetApiV1BatchesBatchUuidInternaltransfersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const batchItemInternalTransfer = z.object({batchItemUuid: z.string().optional(), status: z.enum(["SUBMITTED", "REMOVED", "SUCCEEDED", "FAILED"]).optional(), result: z.object({code: z.number().int().optional(), message: z.string().optional()}).optional(), dateCreated: z.string().optional(), lastUpdated: z.string().optional(), feeAmount: z.number().int().optional(), taxAmount: z.number().int().optional(), amountAfterCharges: z.number().int().optional(), icanFrom: z.number().int().optional(), icanTo: z.number().int().optional(), amount: z.number().int().optional(), ref: z.string().optional(), refId: z.number().int().optional()}); export const getApiV1BatchesBatchUuidInternaltransfersResponse = z.object({total: z.number().int().optional(), items: z.array(batchItemInternalTransfer).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 an internal transfer batch * * GET /v1/batches/{batchUuid}/internaltransfers */ export const getApiV1BatchesBatchUuidInternaltransfers = async (args: GetApiV1BatchesBatchUuidInternaltransfersArgs, options?: GetApiV1BatchesBatchUuidInternaltransfersOptions) => { 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))}/internaltransfers${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(getApiV1BatchesBatchUuidInternaltransfersResponse, await res.json()) };