import {z} from 'zod' export type GetApiPaymentsV2betaDirectDebitBatchesIdApprovalTasksTaskIdArgs = {id: string, taskId: string}; export type GetApiPaymentsV2betaDirectDebitBatchesIdApprovalTasksTaskIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const resourceID = z.string().min(32).max(64); export const taskStatus = z.enum(["CREATED", "PROCESSING_STARTED", "COMPLETED", "CANCELLING", "CANCELLED"]); export const errorDetails = z.object({code: z.string().optional(), error: z.string().optional(), field: z.string().optional(), metadata: z.record(z.string(), z.string().max(256)).optional()}); export const createdTimestamp = z.string(); export const updatedTimestamp = z.string(); export const resourceVersion = z.number().int().gte(1); export const approvalAction = z.enum(["APPROVE", "REJECT"]); export const approvalTaskApprover = z.object({userId: resourceID, roleId: z.string(), username: z.string(), name: z.string().optional()}); export const paymentApprovalTaskInput = z.object({batchId: resourceID, action: approvalAction, approver: approvalTaskApprover, reason: z.string().max(255).optional(), allowDateChange: z.boolean().optional()}); export const paymentApprovalTask = z.object({id: resourceID, organizationId: resourceID, status: taskStatus, timeout: z.number().int().gte(0), runtimeMs: z.number().int().gte(0), processed: z.number().int().gte(0), starterUserId: resourceID, starterRoleId: resourceID, errors: z.array(errorDetails).optional(), created: createdTimestamp, updated: updatedTimestamp, version: resourceVersion, input: paymentApprovalTaskInput}); 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 direct debit batch approval task * * GET /payments/v2beta/direct-debit-batches/{id}/approval-tasks/{taskId} */ export const getApiPaymentsV2betaDirectDebitBatchesIdApprovalTasksTaskId = async (args: GetApiPaymentsV2betaDirectDebitBatchesIdApprovalTasksTaskIdArgs, options?: GetApiPaymentsV2betaDirectDebitBatchesIdApprovalTasksTaskIdOptions) => { const {baseUrl = "https://api.atlar.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/payments/v2beta/direct-debit-batches/${encodeURIComponent(String(args.id))}/approval-tasks/${encodeURIComponent(String(args.taskId))}${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(paymentApprovalTask, await res.json()) };