import {z} from 'zod' export type JumpcloudNotificationsEmailRecipientConfigRole = {objectId?: string | undefined, roleObjectId?: string | undefined}; export type JumpcloudNotificationsEmailRecipientConfigUser = {address?: string | undefined, name?: string | undefined, objectId?: string | undefined}; export type JumpcloudNotificationsEmailRecipientConfig = {role?: Array | undefined, user?: Array | undefined}; export type JumpcloudNotificationsSlackChannelConfig = {objectId?: string | undefined, slackChannelId?: string | undefined, slackTeamId?: string | undefined, slackWorkspaceName?: string | undefined}; export type JumpcloudNotificationsSlackConfig = {slackChannel?: Array | undefined}; export type JumpcloudNotificationsWebhookAuthType = 'WEBHOOK_AUTH_TYPE_UNSPECIFIED' | 'WEBHOOK_AUTH_TYPE_BASIC' | 'WEBHOOK_AUTH_TYPE_BEARER'; export type JumpcloudNotificationsCustomHeaders = {key?: string | undefined, masked?: boolean | undefined, objectId?: string | undefined, value?: string | undefined}; export type JumpcloudNotificationsMaskedURLPortion = {key?: string | undefined, objectId?: string | undefined, value?: string | undefined}; export type JumpcloudNotificationsWebhookConfig = {authPassword?: string | undefined, authToken?: string | undefined, authType?: JumpcloudNotificationsWebhookAuthType | undefined, authUsername?: string | undefined, customHeaders?: Array | undefined, maskedUrlPortion?: Array | undefined, objectId?: string | undefined, sslVerification?: boolean | undefined, url?: string | undefined, urlMasked?: boolean | undefined}; export type JumpcloudNotificationsChannelTypeConfig = {email?: JumpcloudNotificationsEmailRecipientConfig | undefined, slack?: JumpcloudNotificationsSlackConfig | undefined, webhook?: JumpcloudNotificationsWebhookConfig | undefined}; export type JumpcloudNotificationsChannelType = 'CHANNEL_TYPE_UNSPECIFIED' | 'CHANNEL_TYPE_EMAIL' | 'CHANNEL_TYPE_WEBHOOK' | 'CHANNEL_TYPE_SLACK'; export type JumpcloudNotificationsChannel = {config?: JumpcloudNotificationsChannelTypeConfig | undefined, createdAt?: string | undefined, createdBy?: string | undefined, description?: string | undefined, enabled?: boolean | undefined, name?: string | undefined, objectId?: string | undefined, organizationObjectId?: string | undefined, type?: JumpcloudNotificationsChannelType | undefined, updatedAt?: string | undefined, updatedBy?: string | undefined}; export type PatchApiNotificationsChannelsIdArgs = {id: string, body: {channel?: JumpcloudNotificationsChannel | undefined}}; export type PatchApiNotificationsChannelsIdOptions = {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 jumpcloudNotificationsUpdateChannelResponse = 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 updating the channels. * * PATCH /notifications/channels/{id} */ export const patchApiNotificationsChannelsId = async (args: PatchApiNotificationsChannelsIdArgs, options?: PatchApiNotificationsChannelsIdOptions) => { const {baseUrl = "https://console.jumpcloud.com/api/v2", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "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(jumpcloudNotificationsUpdateChannelResponse, await res.json()) };