import {z} from 'zod' export type DeleteApiTerminalSessionCommandsRandomIdArgs = {random_id: string}; export type DeleteApiTerminalSessionCommandsRandomIdOptions = {baseUrl?: string | undefined, secretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const terminalSessionCommandStatus = z.enum(["pending", "dispatched", "cancel_requested", "canceled", "superseded", "consumed", "failed"]); export const terminalSessionCommandCurrency = z.enum(["GTQ", "USD"]); export const terminalSessionCommandTerminalAvailability = z.enum(["available", "unavailable"]); export const terminalSessionCommandCheckoutStatus = z.enum(["unpaid", "paid", "failed", "payment_in_progress", "needs_verification", "no_payment_required", "verification_failed", "needs_payer_authentication"]); export const terminalSessionCommand = z.object({id: z.string().optional(), external_id: z.string().optional(), status: terminalSessionCommandStatus.optional(), final: z.boolean().optional(), terminal_id: z.string().optional(), amount_in_cents: z.number().int().optional(), currency: terminalSessionCommandCurrency.optional(), installments: z.number().int().nullable().optional(), description: z.string().nullable().optional(), show_post_payment_screens: z.boolean().optional(), print_receipt: z.boolean().optional(), tax_id: z.string().nullable().optional(), terminal_availability: terminalSessionCommandTerminalAvailability.optional(), checkout_id: z.string().optional(), checkout_url: z.string().optional(), checkout_status: terminalSessionCommandCheckoutStatus.optional(), cancellation_requested_at: z.string().nullable().optional(), canceled_at: z.string().nullable().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 }; /** * Cancelar un comando de terminal * * DELETE /terminal_session_commands/{random_id} */ export const deleteApiTerminalSessionCommandsRandomId = async (args: DeleteApiTerminalSessionCommandsRandomIdArgs, options?: DeleteApiTerminalSessionCommandsRandomIdOptions) => { const {baseUrl = "https://app.recurrente.com/api", fetch: fetchFn = fetch, secretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (secretKey !== undefined) headers.set("X-SECRET-KEY", secretKey) const url = `${baseUrl.replace(/\/+$/, '')}/terminal_session_commands/${encodeURIComponent(String(args.random_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(terminalSessionCommand, await res.json()) };