import {z} from 'zod' export type PatchApiApiV2OrgIdAlertsAlertIdEnableArgs = {org_id: string, alert_id: string, value: boolean, folder?: string | undefined}; export type PatchApiApiV2OrgIdAlertsAlertIdEnableOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const enableAlertResponseBody = z.object({enabled: z.boolean()}); 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 }; /** * Enable or disable alert * * PATCH /api/v2/{org_id}/alerts/{alert_id}/enable */ export const patchApiApiV2OrgIdAlertsAlertIdEnable = async (args: PatchApiApiV2OrgIdAlertsAlertIdEnableArgs, options: PatchApiApiV2OrgIdAlertsAlertIdEnableOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.value != null) query.append("value", String(args.value)) if (args.folder != null) query.append("folder", String(args.folder)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/${encodeURIComponent(String(args.org_id))}/alerts/${encodeURIComponent(String(args.alert_id))}/enable${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(enableAlertResponseBody, await res.json()) };