import {z} from 'zod' export type GetApiV1AlertChannelsIdArgs = {'x-checkly-account'?: string | undefined, id: number}; export type GetApiV1AlertChannelsIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const type = z.enum(["EMAIL", "SLACK", "SLACK_APP", "WEBHOOK", "SMS", "PAGERDUTY", "OPSGENIE", "CALL"]); export const alertChannelConfig = z.object({}); export const alertChanelSubscription = z.object({id: z.number().optional(), checkId: z.string().nullable().optional(), groupId: z.number().nullable().optional(), activated: z.boolean()}); export const alertChanelSubscriptionList = z.array(alertChanelSubscription); export const bindingProjectV1 = z.object({id: z.string(), logicalId: z.string(), name: z.string()}); export const projectBindingDetailsV1 = z.object({logicalId: z.string(), pending: z.boolean(), sourceFile: z.string().nullable().optional()}); export const projectBindingOwnerV1 = z.object({project: bindingProjectV1, binding: projectBindingDetailsV1}).nullable(); export const projectBindingV1 = z.object({project: bindingProjectV1, binding: projectBindingDetailsV1}); export const projectBindingReferencesV1 = z.array(projectBindingV1); export const projectBindingsV1 = z.object({owner: projectBindingOwnerV1, references: projectBindingReferencesV1}); export const alertChannelRead = z.object({id: z.number(), type: type, config: alertChannelConfig, subscriptions: alertChanelSubscriptionList.optional(), sendRecovery: z.boolean().optional(), sendFailure: z.boolean().optional(), sendDegraded: z.boolean().optional(), sslExpiry: z.boolean().optional(), sslExpiryThreshold: z.number().int().gte(1).lte(30).optional(), autoSubscribe: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().nullable().optional(), projectBindings: projectBindingsV1.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 }; /** * Retrieve an alert channel * * GET /v1/alert-channels/{id} */ export const getApiV1AlertChannelsId = async (args: GetApiV1AlertChannelsIdArgs, options?: GetApiV1AlertChannelsIdOptions) => { const {baseUrl = "https://api.checklyhq.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-checkly-account'] != null) headers.set("x-checkly-account", String(args['x-checkly-account'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/alert-channels/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(alertChannelRead, await res.json()) };