import {z} from 'zod' export type GetApiV1KnowledgeGapsClustersClusterIdLifecycleEventsArgs = {cluster_id: string, limit?: number | undefined, offset?: number | undefined}; export type GetApiV1KnowledgeGapsClustersClusterIdLifecycleEventsOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const lifecycleEventRow = z.object({id: z.string(), gap_cluster_id: z.string(), from_status: z.string().nullable(), to_status: z.string(), actor_user_id: z.string().nullable(), actor_type: z.string(), reason: z.string().nullable(), note: z.string().nullable(), created_at: z.string()}); export const lifecycleEventsResponse = z.object({items: z.array(lifecycleEventRow), total: z.number().int()}); 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 }; /** * Audit-trail of lifecycle transitions for a cluster * * GET /v1/knowledge-gaps/clusters/{cluster_id}/lifecycle-events */ export const getApiV1KnowledgeGapsClustersClusterIdLifecycleEvents = async (args: GetApiV1KnowledgeGapsClustersClusterIdLifecycleEventsArgs, options: GetApiV1KnowledgeGapsClustersClusterIdLifecycleEventsOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = 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 (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/knowledge-gaps/clusters/${encodeURIComponent(String(args.cluster_id))}/lifecycle-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(lifecycleEventsResponse, await res.json()) };