import {z} from 'zod' export type GetApiAccountsAccountIdAchScheduledArgs = {account_id: string, limit?: number | undefined, offset?: (string | null) | undefined, 'x-entity-id'?: string | undefined}; export type GetApiAccountsAccountIdAchScheduledOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pageMetadata = z.object({nextOffset: z.string().nullable().optional()}); export const transferStatus = z.enum(["pending", "pending_approval", "canceled", "processing", "error", "sent", "returned", "void"]); export const timestamp = z.string(); export const transferMethod = z.enum(["book", "usdc", "usdt", "pyusd", "cash", "usdg", "path_usd", "ach", "wire", "international"]); export const scheduledAchTransfer = z.object({id: z.string(), status: transferStatus, amount: z.string(), description: z.string().nullable().optional(), schedule_description: z.string().nullable().optional(), counterparty_id: z.string(), rrule: z.string().min(1).max(120), first_occurrence: timestamp, transfer_type: transferMethod, metadata: z.record(z.string(), z.string().max(200)).nullable().optional()}); export const scheduledAchTransfers = z.object({page: pageMetadata.nullable().optional(), scheduled_ach_transfers: z.array(scheduledAchTransfer)}); 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 Scheduled ACH Transfers * * GET /accounts/{account_id}/ach/scheduled */ export const getApiAccountsAccountIdAchScheduled = async (args: GetApiAccountsAccountIdAchScheduledArgs, options?: GetApiAccountsAccountIdAchScheduledOptions) => { const {baseUrl = "https://api.meow.com/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args['x-entity-id'] != null) headers.set("x-entity-id", String(args['x-entity-id'])) if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.account_id))}/ach/scheduled${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(scheduledAchTransfers, await res.json()) };