import {z} from 'zod' export type GetApiClusterClusterIdEventsArgs = {clusterId: string, from_date_time: string, to_date_time: string, node_name?: string | undefined, pod_name?: string | undefined, reporting_component?: string | undefined}; export type GetApiClusterClusterIdEventsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiClusterClusterIdEventsResponse = z.object({results: z.array(z.object({created_at: z.string().optional(), kind: z.string().optional(), namespace: z.string().optional(), name: z.string().optional(), reason: z.string().optional(), message: z.string().optional(), type: z.string().optional(), reporting_component: z.string().optional(), count: z.number().int().optional(), first_occurrence: z.string().optional(), last_occurrence: z.string().optional()})).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 }; /** * List Cluster Kubernetes Events * * GET /cluster/{clusterId}/events * * Also accepts auth: bearerAuth */ export const getApiClusterClusterIdEvents = async (args: GetApiClusterClusterIdEventsArgs, options?: GetApiClusterClusterIdEventsOptions) => { const {baseUrl = "https://api.qovery.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from_date_time != null) query.append("from_date_time", String(args.from_date_time)) if (args.to_date_time != null) query.append("to_date_time", String(args.to_date_time)) if (args.node_name != null) query.append("node_name", String(args.node_name)) if (args.pod_name != null) query.append("pod_name", String(args.pod_name)) if (args.reporting_component != null) query.append("reporting_component", String(args.reporting_component)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/cluster/${encodeURIComponent(String(args.clusterId))}/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(getApiClusterClusterIdEventsResponse, await res.json()) };