import {z} from 'zod' export type GetApiSettlementQueueEntriesArgs = {'Finix-Version'?: string | undefined, after_cursor?: string | undefined, before_cursor?: string | undefined, application_id?: string | undefined, 'created_at.gte'?: string | undefined, 'created_at.lte'?: string | undefined, entity_id?: string | undefined, entity_type?: ('ADJUSTMENT' | 'DISPUTE_TRANSFER' | 'FEE' | 'REVERSE' | 'SPLIT_TRANSFER' | 'TRANSFER') | undefined, limit?: number | undefined, merchant_id?: string | undefined, 'ready_to_settle_after.gte'?: string | undefined, 'ready_to_settle_after.lte'?: string | undefined, state?: ('AWAITING_SETTLEMENT_TIME' | 'PENDING' | 'RELEASED') | undefined, 'updated_at.gte'?: string | undefined, 'updated_at.lte'?: string | undefined}; export type GetApiSettlementQueueEntriesOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const page = z.object({limit: z.number().int().optional(), next_cursor: z.string().nullable().optional()}); export const id = z.string().min(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const applicationId = z.string().min(1); export const settlementQueueEntry = z.object({id: id.optional(), created_at: createdAt.optional(), updated_at: updatedAt.optional(), application_id: applicationId.optional(), entity_id: z.string().optional(), entity_type: z.enum(["ADJUSTMENT", "DISPUTE_TRANSFER", "FEE", "TRANSFER", "REVERSE", "SPLIT_TRANSFER"]).optional(), merchant_id: z.string().optional(), platform_id: z.string().optional(), ready_to_settle_after: z.string().nullable().optional(), state: z.enum(["AWAITING_SETTLEMENT_TIME", "PENDING", "RELEASED"]).optional(), _links: z.object({self: z.object({href: z.string().optional()}).optional()}).optional()}); export const self = z.object({href: z.string().min(1).optional()}); export const next = z.object({href: z.string().optional()}); export const getApiSettlementQueueEntriesResponse = z.object({page: page.optional(), _embedded: z.object({settlement_queue_entries: z.array(settlementQueueEntry).optional()}).optional(), _links: z.object({self: self.optional(), next: next.optional()}).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 Settlement Queue Entries * * GET /settlement_queue_entries */ export const getApiSettlementQueueEntries = async (args: GetApiSettlementQueueEntriesArgs, options?: GetApiSettlementQueueEntriesOptions) => { const {baseUrl = "https://finix.sandbox-payments-api.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Finix-Version'] != null) headers.set("Finix-Version", String(args['Finix-Version'])) if (args.after_cursor != null) query.append("after_cursor", String(args.after_cursor)) if (args.before_cursor != null) query.append("before_cursor", String(args.before_cursor)) if (args.application_id != null) query.append("application_id", String(args.application_id)) if (args['created_at.gte'] != null) query.append("created_at.gte", String(args['created_at.gte'])) if (args['created_at.lte'] != null) query.append("created_at.lte", String(args['created_at.lte'])) if (args.entity_id != null) query.append("entity_id", String(args.entity_id)) if (args.entity_type != null) query.append("entity_type", String(args.entity_type)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.merchant_id != null) query.append("merchant_id", String(args.merchant_id)) if (args['ready_to_settle_after.gte'] != null) query.append("ready_to_settle_after.gte", String(args['ready_to_settle_after.gte'])) if (args['ready_to_settle_after.lte'] != null) query.append("ready_to_settle_after.lte", String(args['ready_to_settle_after.lte'])) if (args.state != null) query.append("state", String(args.state)) if (args['updated_at.gte'] != null) query.append("updated_at.gte", String(args['updated_at.gte'])) if (args['updated_at.lte'] != null) query.append("updated_at.lte", String(args['updated_at.lte'])) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/settlement_queue_entries${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(getApiSettlementQueueEntriesResponse, await res.json()) };