import {z} from 'zod' export type Edge = {id: string, source: string, source_handle?: (string | null) | undefined, target: string}; export type PipelineKind = 'user' | 'evaluation'; export type Position = {x: number, y: number}; export type NodeStyle = {backgroundColor?: (string | null) | undefined}; export type Node = {data: Record, id: string, io_type: string, is_disabled?: boolean | undefined, meta?: ({[key: string]: string} | null) | undefined, position: Position, style?: (NodeStyle | null) | undefined}; export type StreamType = 'logs' | 'metrics' | 'traces' | 'profiles' | 'service_graph' | 'enrichment_tables' | 'file_list' | 'metadata' | 'index'; export type AggFunction = 'avg' | 'min' | 'max' | 'sum' | 'count' | 'median' | 'p50' | 'p75' | 'p90' | 'p95' | 'p99'; export type Operator = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'contains' | 'not_contains' | 'is_null' | 'is_not_null' | 'is_empty' | 'is_not_empty'; export type Condition = {column: string, ignore_case?: boolean | undefined, operator: Operator, value: Record}; export type Aggregation = {function: AggFunction, group_by?: (Array | null) | undefined, having: Condition, multi_alert?: boolean | undefined, warning_value?: (number | null) | undefined}; export type CompareHistoricData = {offSet: string}; export type SearchEventType = 'ui' | 'dashboards' | 'reports' | 'alerts' | 'values' | 'other' | 'rum' | 'derivedstream' | 'searchjob' | 'download' | 'insights' | 'public_dashboard'; export type SloAlertKind = 'error_budget' | 'burn_rate'; export type SloCondition = {critical: number, kind: SloAlertKind, long_window_secs?: (number | null) | undefined, multi_alert?: boolean | undefined, operator: Operator, short_window_secs?: (number | null) | undefined, slo_id: string, warning?: (number | null) | undefined}; export type QueryType = 'custom' | 'sql' | 'promql' | 'slo'; export type QueryCondition = {aggregation?: (Aggregation | null) | undefined, conditions?: (Record | null) | undefined, multi_time_range?: (Array | null) | undefined, promql?: (string | null) | undefined, promql_condition?: (Condition | null) | undefined, promql_multi_alert?: boolean | undefined, promql_rule_mode?: boolean | undefined, promql_warning_value?: (number | null) | undefined, search_event_type?: (SearchEventType | null) | undefined, slo_condition?: (SloCondition | null) | undefined, sql?: (string | null) | undefined, type?: QueryType | undefined, vrl_function?: (string | null) | undefined}; export type FrequencyType = 'cron' | 'minutes'; export type TriggerCondition = {align_time?: boolean | undefined, cron?: string | undefined, frequency?: number | undefined, frequency_type?: FrequencyType | undefined, notify_on_warning?: (boolean | null) | undefined, operator?: Operator | undefined, period?: number | undefined, silence?: number | undefined, threshold?: number | undefined, timezone?: (string | null) | undefined, tolerance_in_secs?: (number | null) | undefined, warning_threshold?: (number | null) | undefined}; export type PipelineSource = {org_id?: string | undefined, stream_name?: string | undefined, stream_type?: StreamType | undefined, source_type: 'realtime'} | {delay?: (number | null) | undefined, org_id?: string | undefined, query_condition?: QueryCondition | undefined, start_at?: (number | null) | undefined, stream_type?: StreamType | undefined, trigger_condition?: TriggerCondition | undefined, tz_offset?: number | undefined, source_type: 'scheduled'}; export type UpdateApiApiOrgIdPipelinesArgs = {org_id: string, body: {description?: string | undefined, edges: Array, enabled?: boolean | undefined, kind?: PipelineKind | undefined, name: string, nodes: Array, org?: string | undefined, pipeline_id?: string | undefined, source?: PipelineSource | undefined, version?: number | undefined}}; export type UpdateApiApiOrgIdPipelinesOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const httpResponse = z.object({code: z.number().int().gte(0), error_detail: z.string().nullable().optional(), hint: z.string().nullable().optional(), id: z.string().nullable().optional(), message: z.string(), name: z.string().nullable().optional(), suggestions: z.array(z.string()).nullable().optional(), trace_id: z.string().nullable().optional(), warnings: z.array(z.string()).nullable().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 }; /** * Update pipeline * * PUT /api/{org_id}/pipelines */ export const updateApiApiOrgIdPipelines = async (args: UpdateApiApiOrgIdPipelinesArgs, options: UpdateApiApiOrgIdPipelinesOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/pipelines${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(httpResponse, await res.json()) };