import {z} from 'zod' export type GetApiNetworkNotificationsV1NotificationRulesIdArgs = {id: string}; export type GetApiNetworkNotificationsV1NotificationRulesIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const notificationRuleSourceAlerts = z.object({enabled: z.boolean().optional(), alertNames: z.array(z.string().max(256)).optional(), minAlertSeverity: z.enum(["CRITICAL", "MAJOR", "MINOR", "INFO"]).optional()}); export const notificationRuleSource = z.object({alerts: notificationRuleSourceAlerts.optional()}); export const notificationRuleDestinationEmail = z.object({enabled: z.boolean().optional(), emailIds: z.array(z.string().max(256)).optional()}); export const notificationRuleDestinationWebhook = z.object({enabled: z.boolean().optional(), webhookIds: z.array(z.string().max(512)).optional()}); export const notificationRuleDestinationSyslog = z.object({enabled: z.boolean().optional(), serverIds: z.array(z.string().max(256)).optional()}); export const notificationRuleDestination = z.object({email: notificationRuleDestinationEmail.optional(), webhook: notificationRuleDestinationWebhook.optional(), syslog: notificationRuleDestinationSyslog.optional()}); export const notificationRule = z.object({id: z.string().max(128), type: z.string(), name: z.string().max(128), description: z.string().max(512).optional(), enabled: z.boolean().optional(), sourceTypes: z.array(z.literal("ALERTS")).optional(), source: notificationRuleSource.optional(), destination: notificationRuleDestination.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 a notification rule by its ID * * GET /network-notifications/v1/notification-rules/{id} */ export const getApiNetworkNotificationsV1NotificationRulesId = async (args: GetApiNetworkNotificationsV1NotificationRulesIdArgs, options?: GetApiNetworkNotificationsV1NotificationRulesIdOptions) => { const {baseUrl = "https://sso.common.cloud.hpe.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-notifications/v1/notification-rules/${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(notificationRule, await res.json()) };