export type CloseAlertsParams = {type: 'error' | 'metric', attrs?: {[key: string]: string} | undefined}; export type AnnotationCreateRequest = {name: string, description?: string | undefined, color?: string | undefined, attrs?: {[key: string]: string} | undefined, fingerprint?: string | undefined, time?: string | undefined, closeAlerts?: CloseAlertsParams | undefined}; export type CreateApiApiV1AnnotationsArgs = {body: AnnotationCreateRequest}; export type CreateApiApiV1AnnotationsOptions = {baseUrl?: string | undefined, uptraceDSNHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create annotation * * POST /api/v1/annotations * * Also accepts auth: dsnQuery */ export const createApiApiV1Annotations = async (args: CreateApiApiV1AnnotationsArgs, options?: CreateApiApiV1AnnotationsOptions) => { const {baseUrl = "https://api.uptrace.dev", fetch: fetchFn = fetch, uptraceDSNHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (uptraceDSNHeader !== undefined) headers.set("uptrace-dsn", uptraceDSNHeader) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/annotations${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 };