import {z} from 'zod' export type GetApiV2StorageBranchBranchIdEventsEventIdArgs = {eventId: string, branchId: string}; export type GetApiV2StorageBranchBranchIdEventsEventIdOptions = {baseUrl?: string | undefined, StorageKey?: string | undefined, fetch?: typeof fetch | undefined}; export const eventAttachmentResponse = z.object({id: z.number().int(), isSliced: z.boolean(), uploadType: z.string(), isExpired: z.boolean(), created: z.string(), name: z.string(), url: z.string(), sizeBytes: z.number().int().nullable()}); export const eventResponse = z.object({uuid: z.string(), event: z.string(), component: z.string(), message: z.string(), description: z.string(), type: z.enum(["info", "success", "warn", "error"]), runId: z.string().nullable(), created: z.string(), configurationId: z.string().nullable(), objectId: z.union([z.string(), z.number().int()]), objectName: z.string(), objectType: z.string(), context: z.union([z.object({remoteAddr: z.string().nullable().optional(), httpReferer: z.string().nullable().optional(), httpUserAgent: z.string().nullable().optional(), httpUserAgentOriginal: z.string().nullable().optional(), authorization: z.string().nullable().optional(), apiVersion: z.string().nullable().optional()}), z.array(z.unknown())]), params: z.record(z.string(), z.unknown()), results: z.record(z.string(), z.unknown()), performance: z.record(z.string(), z.unknown()), token: z.object({id: z.number().int(), name: z.string().nullable()}), idBranch: z.number().int().nullable(), uri: z.string(), attachments: z.array(eventAttachmentResponse)}); 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 }; /** * Event detail * * GET /v2/storage/branch/{branchId}/events/{eventId} * * Also accepts auth: ManageKey, BearerAuth */ export const getApiV2StorageBranchBranchIdEventsEventId = async (args: GetApiV2StorageBranchBranchIdEventsEventIdArgs, options?: GetApiV2StorageBranchBranchIdEventsEventIdOptions) => { const {baseUrl = "https://connection.keboola.com", fetch: fetchFn = fetch, StorageKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (StorageKey !== undefined) headers.set("X-StorageApi-Token", StorageKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/storage/branch/${encodeURIComponent(String(args.branchId))}/events/${encodeURIComponent(String(args.eventId))}${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(eventResponse, await res.json()) };