import {z} from 'zod' export type CreateApiTransactionsTransactionIdUndoArgs = {force?: boolean | undefined, 'Idempotency-Key'?: string | undefined}; export type CreateApiTransactionsTransactionIdUndoOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionStatus = z.enum(["committed", "undone"]); export const transaction = z.object({id: z.string(), organizationId: z.string(), actorId: z.string(), description: z.string(), method: z.string(), endpoint: z.string(), status: transactionStatus, idempotencyKey: z.string().optional(), undoOfTransactionId: z.string().optional(), undoneByTransactionId: z.string().optional(), createdAt: z.number()}); export const createApiTransactionsTransactionIdUndoResponse = z.object({data: transaction, transactionId: z.string()}); 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 }; /** * Undo transaction * * POST /transactions/{transactionId}/undo * * Also accepts auth: ApiKeyAuth */ export const createApiTransactionsTransactionIdUndo = async (args: CreateApiTransactionsTransactionIdUndoArgs, options: CreateApiTransactionsTransactionIdUndoOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.force != null) query.append("force", String(args.force)) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/transactions/${encodeURIComponent(String(args.transactionId))}/undo${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiTransactionsTransactionIdUndoResponse, await res.json()) };