import {z} from 'zod' export type GetApiApiV1DataEventsArgs = {happened_after?: string | undefined, happened_before?: string | undefined, query?: string | undefined, 'page.max_size'?: number | undefined, 'page.token'?: string | undefined}; export type GetApiApiV1DataEventsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const datav1Event = z.object({category: z.string().optional(), happened_at: z.string().optional(), id: z.string().optional(), labels: z.record(z.string(), z.string()).optional(), payload_json: z.string().optional(), payload_object: z.object({}).optional(), source: z.string().optional(), title: z.string().optional(), type: z.string().optional()}); export const configv1PageResult = z.object({next_token: z.string().optional()}); export const datav1ListEventsResponse = z.object({events: z.array(datav1Event).optional(), page: configv1PageResult.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 }; /** * GET /api/v1/data/events */ export const getApiApiV1DataEvents = async (args: GetApiApiV1DataEventsArgs, options?: GetApiApiV1DataEventsOptions) => { const {baseUrl = "https://tenant.chronosphere.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.happened_after != null) query.append("happened_after", String(args.happened_after)) if (args.happened_before != null) query.append("happened_before", String(args.happened_before)) if (args.query != null) query.append("query", String(args.query)) if (args['page.max_size'] != null) query.append("page.max_size", String(args['page.max_size'])) if (args['page.token'] != null) query.append("page.token", String(args['page.token'])) if (ApiKeyAuth !== undefined) headers.set("API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/data/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(datav1ListEventsResponse, await res.json()) };