import {z} from 'zod' export type GetApiV2StorageBranchBranchIdBucketsBucketIdEventsArgs = {bucketId: string, limit?: number | undefined, offset?: number | undefined, maxId?: string | undefined, sinceId?: string | undefined, component?: string | undefined, configurationId?: string | undefined, runId?: string | undefined, q?: string | undefined, query?: string | undefined, sortOrder?: ('asc' | 'desc') | undefined, branchId: string}; export type GetApiV2StorageBranchBranchIdBucketsBucketIdEventsOptions = {baseUrl?: string | undefined, StorageKey?: string | undefined, fetch?: typeof fetch | undefined}; export const bucketEventAttachmentResponse = 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 bucketEventResponse = z.object({uuid: z.string(), event: z.string(), message: z.string(), description: z.string(), type: z.enum(["info", "success", "warn", "error"]), component: z.string(), runId: z.string().nullable(), configurationId: z.string().nullable(), objectId: z.string(), objectName: z.string(), objectType: z.string(), idBranch: z.number().int().nullable(), token: z.object({id: z.number().int(), name: z.string().nullable()}), context: z.union([z.object({httpUserAgent: z.string().nullable().optional(), authorization: z.string().optional(), httpUserAgentOriginal: z.string().nullable().optional(), httpReferer: z.string().nullable().optional(), remoteAddr: z.string().nullable().optional(), apiVersion: z.string().optional(), userAgent: z.string().optional(), async: z.boolean().optional(), networkPolicy: z.string().nullable().optional(), workspaceUsageType: z.string().nullable().optional(), schemaName: z.string().nullable().optional()}), z.array(z.unknown())]), created: z.string(), uri: z.string(), params: z.object({}), results: z.object({}), performance: z.object({}), attachments: z.array(bucketEventAttachmentResponse)}); export const bucketEventsListResponse = z.array(bucketEventResponse); 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 }; /** * List events for a bucket * * GET /v2/storage/branch/{branchId}/buckets/{bucketId}/events * * Also accepts auth: ManageKey, BearerAuth */ export const getApiV2StorageBranchBranchIdBucketsBucketIdEvents = async (args: GetApiV2StorageBranchBranchIdBucketsBucketIdEventsArgs, options?: GetApiV2StorageBranchBranchIdBucketsBucketIdEventsOptions) => { 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 (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.maxId != null) query.append("maxId", String(args.maxId)) if (args.sinceId != null) query.append("sinceId", String(args.sinceId)) if (args.component != null) query.append("component", String(args.component)) if (args.configurationId != null) query.append("configurationId", String(args.configurationId)) if (args.runId != null) query.append("runId", String(args.runId)) if (args.q != null) query.append("q", String(args.q)) if (args.query != null) query.append("query", String(args.query)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (StorageKey !== undefined) headers.set("X-StorageApi-Token", StorageKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/storage/branch/${encodeURIComponent(String(args.branchId))}/buckets/${encodeURIComponent(String(args.bucketId))}/events${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(bucketEventsListResponse, await res.json()) };