import {z} from 'zod' export type GetApiInternalV1ProjectsProjectIdNotificationChannelsArgs = {project_id: number}; export type GetApiInternalV1ProjectsProjectIdNotificationChannelsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const slackParams = z.object({webhookUrl: z.string().optional(), token: z.string().optional(), channel: z.string().optional(), authMethod: z.enum(["webhook", "token"]).optional()}); export const googleChatParams = z.object({webhookUrl: z.string()}); export const mattermostParams = z.object({webhookUrl: z.string()}); export const pagerdutyParams = z.object({routingKey: z.string(), severity: z.enum(["critical", "error", "warning", "info"])}); export const servicenowParams = z.object({url: z.string(), username: z.string(), password: z.string(), category: z.string().optional(), subcategory: z.string().optional(), impact: z.enum(["1", "2", "3"]).optional(), urgency: z.enum(["1", "2", "3"]).optional(), severity: z.enum(["1", "2", "3", "4", "5"]).optional(), callerId: z.string().optional(), group: z.string().optional(), assignedTo: z.string().optional(), openedBy: z.string().optional(), notify: z.enum(["1", "2"]).optional(), dueDate: z.string().optional()}); export const opsgenieParams = z.object({apiKey: z.string(), priority: z.enum(["P1", "P2", "P3", "P4", "P5"])}); export const telegramParams = z.object({chatId: z.number().int()}); export const teamsParams = z.object({webhookUrl: z.string()}); export const pushoverParams = z.object({token: z.string(), userKey: z.string(), priority: z.number().int().optional(), sound: z.string().optional()}); export const webhookParams = z.object({url: z.string(), payload: z.record(z.string(), z.unknown()).optional()}); export const alertmanagerParams = z.object({url: z.string(), authMethod: z.enum(["none", "basic_auth", "bearer"]).optional(), username: z.string().optional(), password: z.string().optional(), token: z.string().optional()}); export const incidentioParams = z.object({url: z.string(), apiKey: z.string()}); export const notificationChannel = z.object({id: z.number().int(), projectId: z.number().int(), name: z.string(), type: z.enum(["slack", "google_chat", "mattermost", "pagerduty", "servicenow", "opsgenie", "telegram", "teams", "pushover", "webhook", "alertmanager", "incidentio"]), status: z.enum(["draft", "delivering", "paused", "disabled"]), error: z.string().optional(), matchAll: z.boolean().optional(), condition: z.string().optional(), priorities: z.array(z.enum(["info", "low", "medium", "high"])).optional(), params: z.union([slackParams, googleChatParams, mattermostParams, pagerdutyParams, servicenowParams, opsgenieParams, telegramParams, teamsParams, pushoverParams, webhookParams, alertmanagerParams, incidentioParams]), monitorIds: z.array(z.number().int()).optional(), monitorCount: z.number().int().optional(), sentCount: z.number().int().optional(), lastSentAt: z.string().optional()}); export const getApiInternalV1ProjectsProjectIdNotificationChannelsResponse = z.object({channels: z.array(notificationChannel)}); 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 }; /** * List notification channels * * GET /internal/v1/projects/{project_id}/notification-channels * * Also accepts auth: authTokenQuery */ export const getApiInternalV1ProjectsProjectIdNotificationChannels = async (args: GetApiInternalV1ProjectsProjectIdNotificationChannelsArgs, options?: GetApiInternalV1ProjectsProjectIdNotificationChannelsOptions) => { const {baseUrl = "https://api.uptrace.dev", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/internal/v1/projects/${encodeURIComponent(String(args.project_id))}/notification-channels${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(getApiInternalV1ProjectsProjectIdNotificationChannelsResponse, await res.json()) };