import {z} from 'zod' export type GetApiPayeeVerificationRequestsArgs = {limit?: number | undefined, starting_after?: string | undefined, sort_order?: ('asc' | 'desc') | undefined, start_date?: string | undefined, end_date?: string | undefined, status?: ('created' | 'completed' | 'failed' | 'received') | undefined, direction?: ('outgoing' | 'incoming') | undefined, scheme?: 'vop' | undefined, payee_identification_type?: string | undefined, payee_identification?: string | undefined, payee_account_number?: string | undefined, requesting_agent_bank_code?: string | undefined, responding_agent_bank_code?: string | undefined, matching_result?: ('match' | 'close_match' | 'no_match' | 'impossible_match') | undefined, internal_account_id?: string | undefined}; export type GetApiPayeeVerificationRequestsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const commonMetadata = z.object({}); export const vopRequestDetails = z.object({id: z.string(), idempotency_key: z.string().optional(), object: z.literal("payee_verification_request"), status: z.enum(["created", "received", "completed", "failed"]), status_details: z.string(), failure_code: z.enum(["business_error", "technical_error", "psp_technical_error"]).nullable().optional(), direction: z.enum(["outgoing", "incoming"]), scheme: z.literal("vop"), request: z.object({payee_identification_type: z.string().optional(), payee_identification: z.string().optional(), sent_identification: z.string().nullable().optional(), payee_account_number: z.string().optional(), additional_information: z.string().optional(), requesting_agent_bank_code: z.string().optional(), responding_agent_bank_code: z.string().optional()}), matching_result: z.enum(["match", "close_match", "no_match", "impossible_match"]), payee_suggested_name: z.string().nullable(), matching_details: z.object({cleaned_identification: z.string().optional(), retrieved_identification: z.string().nullable().optional(), retrieved_identifications: z.array(z.string()).nullable().optional(), internal_account_id: z.string().optional(), matching_score: z.number().int().gte(0).lte(100).optional(), distance: z.enum(["levenshtein", "jarowinkler"]).nullable().optional(), match_threshold: z.number().int().gte(0).lte(100).nullable().optional(), close_match_threshold: z.number().int().gte(0).lte(100).nullable().optional()}).nullable(), scheme_data: z.object({scheme_request_id: z.string().optional(), request_timestamp: z.string().optional(), response_timestamp: z.string().optional()}).nullable(), response_received_at: z.string().nullable().optional(), initiated_at: z.string().nullable().optional(), metadata: commonMetadata.optional(), created_at: z.string()}); export const getApiPayeeVerificationRequestsResponse = z.object({records: z.array(vopRequestDetails)}); 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 payee verification requests * * GET /payee_verification_requests */ export const getApiPayeeVerificationRequests = async (args: GetApiPayeeVerificationRequestsArgs, options?: GetApiPayeeVerificationRequestsOptions) => { const {baseUrl = "https://sandbox.numeral.io/v1", fetch: fetchFn = fetch, sec0} = 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.starting_after != null) query.append("starting_after", String(args.starting_after)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.status != null) query.append("status", String(args.status)) if (args.direction != null) query.append("direction", String(args.direction)) if (args.scheme != null) query.append("scheme", String(args.scheme)) if (args.payee_identification_type != null) query.append("payee_identification_type", String(args.payee_identification_type)) if (args.payee_identification != null) query.append("payee_identification", String(args.payee_identification)) if (args.payee_account_number != null) query.append("payee_account_number", String(args.payee_account_number)) if (args.requesting_agent_bank_code != null) query.append("requesting_agent_bank_code", String(args.requesting_agent_bank_code)) if (args.responding_agent_bank_code != null) query.append("responding_agent_bank_code", String(args.responding_agent_bank_code)) if (args.matching_result != null) query.append("matching_result", String(args.matching_result)) if (args.internal_account_id != null) query.append("internal_account_id", String(args.internal_account_id)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/payee_verification_requests${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(getApiPayeeVerificationRequestsResponse, await res.json()) };