import {z} from 'zod' export type GetApiNotificationsChannelsIdArgs = {id: string}; export type GetApiNotificationsChannelsIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudNotificationsEmailRecipientConfigRole = z.object({objectId: z.string().optional(), roleObjectId: z.string().optional()}); export const jumpcloudNotificationsEmailRecipientConfigUser = z.object({address: z.string().optional(), name: z.string().optional(), objectId: z.string().optional()}); export const jumpcloudNotificationsEmailRecipientConfig = z.object({role: z.array(jumpcloudNotificationsEmailRecipientConfigRole).optional(), user: z.array(jumpcloudNotificationsEmailRecipientConfigUser).optional()}); export const jumpcloudNotificationsSlackChannelConfig = z.object({objectId: z.string().optional(), slackChannelId: z.string().optional(), slackTeamId: z.string().optional(), slackWorkspaceName: z.string().optional()}); export const jumpcloudNotificationsSlackConfig = z.object({slackChannel: z.array(jumpcloudNotificationsSlackChannelConfig).optional()}); export const jumpcloudNotificationsWebhookAuthType = z.enum(["WEBHOOK_AUTH_TYPE_UNSPECIFIED", "WEBHOOK_AUTH_TYPE_BASIC", "WEBHOOK_AUTH_TYPE_BEARER"]); export const jumpcloudNotificationsCustomHeaders = z.object({key: z.string().optional(), masked: z.boolean().optional(), objectId: z.string().optional(), value: z.string().optional()}); export const jumpcloudNotificationsMaskedURLPortion = z.object({key: z.string().optional(), objectId: z.string().optional(), value: z.string().optional()}); export const jumpcloudNotificationsWebhookConfig = z.object({authPassword: z.string().optional(), authToken: z.string().optional(), authType: jumpcloudNotificationsWebhookAuthType.optional(), authUsername: z.string().optional(), customHeaders: z.array(jumpcloudNotificationsCustomHeaders).optional(), maskedUrlPortion: z.array(jumpcloudNotificationsMaskedURLPortion).optional(), objectId: z.string().optional(), sslVerification: z.boolean().optional(), url: z.string().optional(), urlMasked: z.boolean().optional()}); export const jumpcloudNotificationsChannelTypeConfig = z.object({email: jumpcloudNotificationsEmailRecipientConfig.optional(), slack: jumpcloudNotificationsSlackConfig.optional(), webhook: jumpcloudNotificationsWebhookConfig.optional()}); export const jumpcloudNotificationsChannelType = z.enum(["CHANNEL_TYPE_UNSPECIFIED", "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_WEBHOOK", "CHANNEL_TYPE_SLACK"]); export const jumpcloudNotificationsChannel = z.object({config: jumpcloudNotificationsChannelTypeConfig.optional(), createdAt: z.string().optional(), createdBy: z.string().optional(), description: z.string().optional(), enabled: z.boolean().optional(), name: z.string().optional(), objectId: z.string().optional(), organizationObjectId: z.string().optional(), type: jumpcloudNotificationsChannelType.optional(), updatedAt: z.string().optional(), updatedBy: z.string().optional()}); export const jumpcloudNotificationsGetChannelResponse = z.object({channel: jumpcloudNotificationsChannel.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 }; /** * This endpoint is used for getting a notification channel. * * GET /notifications/channels/{id} */ export const getApiNotificationsChannelsId = async (args: GetApiNotificationsChannelsIdArgs, options?: GetApiNotificationsChannelsIdOptions) => { const {baseUrl = "https://console.jumpcloud.com/api/v2", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/notifications/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(jumpcloudNotificationsGetChannelResponse, await res.json()) };