import {z} from 'zod' export type GetApiV4OrchestrationPaymentArgs = {page?: number | undefined, size?: number | undefined, sort_field?: ('CREATED_AT' | 'MODIFIED_AT') | undefined, sort_direction?: ('ASC' | 'DESC') | undefined, unique_reference_number?: string | undefined, orchestration_status?: ('INITIAL' | 'RUNNING' | 'COMPLETED' | 'PAUSED' | 'FAILURE' | 'DECLINED' | 'RETRY') | undefined, range_field?: string | undefined, before?: string | undefined, after?: string | undefined}; export type GetApiV4OrchestrationPaymentOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const sort = z.object({direction: z.string().optional(), property: z.string().optional(), ignoreCase: z.boolean().optional(), nullHandling: z.string().optional(), ascending: z.boolean().optional(), descending: z.boolean().optional()}); export const orchestrationPaymentResponse = z.object({uuid: z.string().optional(), unique_reference_number: z.string().optional(), sender_end_to_end_id: z.string().optional(), payment_type: z.enum(["REGULAR", "RETURN", "REVERSAL"]).optional(), connector_role: z.enum(["SENDING", "RECEIVING", "INTERMEDIARY"]).optional(), payment_id: z.string().optional(), payment_status: z.string().optional(), previous_payment_status: z.string().optional(), orchestration_template: z.string().optional(), orchestration_status: z.string().optional(), current_activity: z.string().optional(), current_activity_status: z.string().optional(), initial_context: z.object({}).optional(), current_context: z.object({}).optional(), error_message: z.object({}).optional(), activity_list: z.object({}).optional(), created_at: z.string().optional(), modified_at: z.string().optional()}); export const orchestrationPayments = z.object({first: z.boolean().optional(), last: z.boolean().optional(), number: z.number().int().optional(), numberOfElements: z.number().int().optional(), size: z.number().int().optional(), totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), sort: z.array(sort).optional(), content: z.array(orchestrationPaymentResponse).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 }; /** * Get orchestration payments * * GET /v4/orchestration/payment */ export const getApiV4OrchestrationPayment = async (args: GetApiV4OrchestrationPaymentArgs, options: GetApiV4OrchestrationPaymentOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.sort_field != null) query.append("sort_field", String(args.sort_field)) if (args.sort_direction != null) query.append("sort_direction", String(args.sort_direction)) if (args.unique_reference_number != null) query.append("unique_reference_number", String(args.unique_reference_number)) if (args.orchestration_status != null) query.append("orchestration_status", String(args.orchestration_status)) if (args.range_field != null) query.append("range_field", String(args.range_field)) if (args.before != null) query.append("before", String(args.before)) if (args.after != null) query.append("after", String(args.after)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/v4/orchestration/payment${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(orchestrationPayments, await res.json()) };