import {z} from 'zod' export type GetApiV1OrgsOrgIdClusteringStatsArgs = {org_id: string, query?: string | undefined, summary?: boolean | undefined, limit?: string | undefined, lookback?: string | undefined, from?: string | undefined, to?: string | undefined, groupby?: string | undefined, volatility?: string | undefined, offset?: string | undefined, window?: string | undefined, negative?: boolean | undefined}; export type GetApiV1OrgsOrgIdClusteringStatsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const coreClusterStat = z.object({anomaly: z.number().optional(), count: z.number().int().optional(), delta: z.number().optional(), offset_counts: z.array(z.number().int()).optional(), offset_deltas: z.array(z.number()).optional(), offset_proportions: z.array(z.number()).optional(), past_count: z.number().int().optional(), past_proportion: z.number().optional(), pattern: z.string().optional(), proportion: z.number().optional(), sentiment: z.number().optional()}); export const coreClusterStatResponse = z.object({stats: z.array(coreClusterStat).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 }; /** * Returns top log patterns (signatures of log messages) and their stats; count, proportion, sentiment and delta. * * GET /v1/orgs/{org_id}/clustering/stats */ export const getApiV1OrgsOrgIdClusteringStats = async (args: GetApiV1OrgsOrgIdClusteringStatsArgs, options?: GetApiV1OrgsOrgIdClusteringStatsOptions) => { const {baseUrl = "https://api.edgedelta.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.query != null) query.append("query", String(args.query)) if (args.summary != null) query.append("summary", String(args.summary)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.lookback != null) query.append("lookback", String(args.lookback)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.groupby != null) query.append("groupby", String(args.groupby)) if (args.volatility != null) query.append("volatility", String(args.volatility)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.window != null) query.append("window", String(args.window)) if (args.negative != null) query.append("negative", String(args.negative)) if (ApiKeyAuth !== undefined) headers.set("X-ED-API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/orgs/${encodeURIComponent(String(args.org_id))}/clustering/stats${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(coreClusterStatResponse, await res.json()) };