import {z} from 'zod' export type GetApiPipelinesPipelineIdLagArgs = {pipeline_id: string, at?: (string | null) | undefined, topic_name?: (string | null) | undefined, sort?: ('lag' | 'name' | 'latency') | undefined, sort_dir?: ('asc' | 'desc') | undefined, page?: number | undefined, page_size?: number | undefined, include_partitions?: boolean | undefined}; export type GetApiPipelinesPipelineIdLagOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const lagOverallRes = z.object({lag: z.number().int(), latency_ms: z.number().int().nullable().optional(), topic_count: z.number().int(), topics_with_lag: z.number().int()}).and(z.record(z.string(), z.unknown())); export const lagPartitionRes = z.object({partition: z.string(), lag: z.number().int(), latency_ms: z.number().int().nullable().optional()}).and(z.record(z.string(), z.unknown())); export const lagTopicRes = z.object({topic: z.string(), topic_id: z.string().nullable().optional(), kafka_topic: z.string(), producer_type: z.string().nullable().optional(), lag: z.number().int(), share: z.number(), partition_count: z.number().int(), max_partition_lag: z.number().int(), latency_ms: z.number().int().nullable().optional(), partitions: z.array(lagPartitionRes).nullable().optional()}).and(z.record(z.string(), z.unknown())); export const entityLagRes = z.object({entity_type: z.string(), entity_id: z.string(), connector_name: z.string(), supported: z.boolean(), mode: z.enum(["current", "historical"]), requested_at: z.string().nullable().optional(), as_of: z.string().nullable().optional(), resolution: z.enum(["raw", "minute", "hour"]).nullable().optional(), stale: z.boolean(), message: z.string().nullable().optional(), overall: lagOverallRes, topics: z.array(lagTopicRes), total: z.number().int(), page: z.number().int(), page_size: z.number().int()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Per-topic consumer lag for a pipeline * * GET /pipelines/{pipeline_id}/lag */ export const getApiPipelinesPipelineIdLag = async (args: GetApiPipelinesPipelineIdLagArgs, options?: GetApiPipelinesPipelineIdLagOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.at != null) query.append("at", String(args.at)) if (args.topic_name != null) query.append("topic_name", String(args.topic_name)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.sort_dir != null) query.append("sort_dir", String(args.sort_dir)) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.include_partitions != null) query.append("include_partitions", String(args.include_partitions)) if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/pipelines/${encodeURIComponent(String(args.pipeline_id))}/lag${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(entityLagRes, await res.json()) };