import {z} from 'zod' export type AlarmTriggerCondition = {operator: 'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'neq', value: number}; export type AlarmTriggerConfig = {type: 'alert_result_count', config: AlarmTriggerCondition}; export type AlarmUpdateInput = {name?: string | undefined, description?: (string | null) | undefined, query?: string | undefined, stream_ids?: (Array | null) | undefined, evaluation_period?: string | undefined, lookback_lag?: string | undefined, trigger_config?: AlarmTriggerConfig | undefined}; export type PatchApiProjectsProjectIdAlarmsAlarmIdArgs = {project_id: string, alarm_id: string, body: AlarmUpdateInput}; export type PatchApiProjectsProjectIdAlarmsAlarmIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const alarmTriggerCondition = z.object({operator: z.enum(["gt", "gte", "lt", "lte", "eq", "neq"]), value: z.number()}); export const alarmTriggerConfig = z.object({type: z.literal("alert_result_count"), config: alarmTriggerCondition}); export const webLinks = z.object({web: z.string()}); export const alarm = z.object({id: z.string(), project_id: z.string(), name: z.string(), description: z.string().nullable(), state: z.enum(["initial", "alarm", "ok"]), query: z.string().nullable(), stream_ids: z.array(z.string()).nullable(), evaluation_period: z.string().nullable(), lookback_lag: z.string().nullable(), trigger_config: alarmTriggerConfig.nullable(), error: z.string().nullable(), last_checked_at: z.string().nullable(), next_check_at: z.string().nullable(), created_at: z.string(), updated_at: z.string(), links: webLinks}); export const responseMeta = z.object({request_id: z.string().optional()}); export const patchApiProjectsProjectIdAlarmsAlarmIdResponse = z.object({data: alarm, meta: responseMeta.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 an alarm * * PATCH /projects/{project_id}/alarms/{alarm_id} */ export const patchApiProjectsProjectIdAlarmsAlarmId = async (args: PatchApiProjectsProjectIdAlarmsAlarmIdArgs, options?: PatchApiProjectsProjectIdAlarmsAlarmIdOptions) => { const {baseUrl = "https://app.honeybadger.io/v3", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/alarms/${encodeURIComponent(String(args.alarm_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiProjectsProjectIdAlarmsAlarmIdResponse, await res.json()) };