import {z} from 'zod' export type LimitParam = number; export type OffsetParam = number; export type GetApiNetworkNotificationsV1NotificationRulesArgs = {limit?: LimitParam | undefined, offset?: OffsetParam | undefined}; export type GetApiNetworkNotificationsV1NotificationRulesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const notificationRuleSourceAlertsSummary = z.object({enabled: z.boolean().optional(), alertCount: z.number().int().gte(1).lte(300).optional(), minAlertSeverity: z.enum(["CRITICAL", "MAJOR", "MINOR", "INFO"]).optional()}); export const notificationRuleSourceSummary = z.object({alerts: notificationRuleSourceAlertsSummary.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 notificationRuleSummary = 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: notificationRuleSourceSummary.optional(), destination: notificationRuleDestination.optional()}); export const notificationRules = z.object({items: z.array(notificationRuleSummary), offset: z.number().int().gte(0).lte(2147483647).optional(), count: z.number().int().gte(0).lte(2147483647), total: z.number().int().gte(0).lte(9223372036854776000).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 }; /** * List all notification rules * * GET /network-notifications/v1/notification-rules */ export const getApiNetworkNotificationsV1NotificationRules = async (args: GetApiNetworkNotificationsV1NotificationRulesArgs, options?: GetApiNetworkNotificationsV1NotificationRulesOptions) => { 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 (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-notifications/v1/notification-rules${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(notificationRules, await res.json()) };