export type AlertScopeSpec = {type?: (string | null) | undefined, symbols?: (Array | null) | undefined}; export type FilterNode = {op?: (string | null) | undefined, conditions?: (Array | null) | undefined, field?: (string | null) | undefined, formula?: (string | null) | undefined, operator?: (string | null) | undefined, value: unknown}; export type FormulaField = {alias?: (string | null) | undefined, expression?: (string | null) | undefined}; export type AlertRuleRequest = {name?: (string | null) | undefined, templateKey?: (string | null) | undefined, templateParams?: ({[key: string]: number | null} | null) | undefined, scope?: AlertScopeSpec | undefined, condition?: FilterNode | undefined, formulas?: (Array | null) | undefined, emailEnabled?: boolean | undefined, emailTo?: (string | null) | undefined, webhookUrl?: (string | null) | undefined, cooldownMinutes?: (number | null) | undefined}; export type CreateApiV1AlertsArgs = {body: AlertRuleRequest}; export type CreateApiV1AlertsOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST /v1/alerts */ export const createApiV1Alerts = async (args: CreateApiV1AlertsArgs, options: CreateApiV1AlertsOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ApiKey !== undefined) headers.set("X-Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/alerts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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 undefined };