import {z} from 'zod' export type NotificationSeverity = 'ALERT' | 'ERROR' | 'WARNING' | 'INFO' | 'ADMIN'; export type NotificationCategory = 'Snapshots & Sync' | 'Restore & Recovery' | 'Cyber Resilience' | 'Encryption Keys' | 'Volume Management' | 'Cloud & Credentials' | 'Remote Access & GFL' | 'Hardware' | 'Network' | 'System Health & Performance' | 'Cache Management' | 'Software & Firmware Updates' | 'Licensing' | 'Directory Services' | 'Appliance Lifecycle' | 'Security & Access' | 'File IQ & Auditing'; export type NotificationSubCategory = 'Snapshot' | 'Sync' | 'Snapshot Retention' | 'Success' | 'Errors' | 'User Actions' | 'Disaster Recovery' | 'Ransomware' | 'Antivirus' | 'Escrow' | 'Generation' | 'Account' | 'Remote Access' | 'Backup' | 'Delete' | 'Safe Delete' | 'UniFSCK' | 'Multiprotocol' | 'Sharing' | 'GFL' | 'Lock Arbiter' | 'GFA' | 'RAID' | 'Encryption' | 'Exception' | 'Firmware' | 'UPS' | 'Unreachable' | 'Configuration' | 'Health Monitor' | 'NOC' | 'Limits' | 'Resources' | 'Cache Disk' | 'Metrics' | 'Config Backup' | 'Unsupported' | 'OS Disk' | 'Time' | 'Resize' | 'Eviction' | 'Autocache' | 'Pinning' | 'Sideload' | 'Power' | 'New' | 'Offline' | 'NMC' | 'SSO' | 'SSL Certificates' | 'EULA' | 'Remote Support' | 'File IQ' | 'AMQP' | 'Syslog'; export type NotificationColumns = 'generated_at' | 'severity' | 'category' | 'appliance_name' | 'volume_name'; export type NotificationSortDirection = 'asc' | 'desc'; export type GetApiNotificationsArgs = {start_date?: (string | null) | undefined, end_date?: (string | null) | undefined, severity?: (Array | null) | undefined, category?: (Array | null) | undefined, sub_category?: (Array | null) | undefined, appliance_name?: (Array | null) | undefined, volume_name?: (Array | null) | undefined, search?: (string | null) | undefined, limit?: number | undefined, iterator_id?: (string | null) | undefined, page?: (number | null) | undefined, sort_by?: NotificationColumns | undefined, sort_direction?: NotificationSortDirection | undefined, include_count?: boolean | undefined}; export type GetApiNotificationsOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const notificationSeverity = z.enum(["ALERT", "ERROR", "WARNING", "INFO", "ADMIN"]); export const notificationCategory = z.enum(["Snapshots & Sync", "Restore & Recovery", "Cyber Resilience", "Encryption Keys", "Volume Management", "Cloud & Credentials", "Remote Access & GFL", "Hardware", "Network", "System Health & Performance", "Cache Management", "Software & Firmware Updates", "Licensing", "Directory Services", "Appliance Lifecycle", "Security & Access", "File IQ & Auditing"]); export const notificationOriginType = z.enum(["SYSTEM_GENERATED", "CUSTOMER_DEFINED"]); export const notificationSubCategory = z.enum(["Snapshot", "Sync", "Snapshot Retention", "Success", "Errors", "User Actions", "Disaster Recovery", "Ransomware", "Antivirus", "Escrow", "Generation", "Account", "Remote Access", "Backup", "Delete", "Safe Delete", "UniFSCK", "Multiprotocol", "Sharing", "GFL", "Lock Arbiter", "GFA", "RAID", "Encryption", "Exception", "Firmware", "UPS", "Unreachable", "Configuration", "Health Monitor", "NOC", "Limits", "Resources", "Cache Disk", "Metrics", "Config Backup", "Unsupported", "OS Disk", "Time", "Resize", "Eviction", "Autocache", "Pinning", "Sideload", "Power", "New", "Offline", "NMC", "SSO", "SSL Certificates", "EULA", "Remote Support", "File IQ", "AMQP", "Syslog"]); export const notificationDto = z.object({id: z.string(), account_id: z.string(), severity: notificationSeverity, category: notificationCategory.nullable().optional(), code_name: z.string(), message: z.string(), source: notificationOriginType.nullable().optional(), created_at: z.string(), generated_at: z.string(), sub_category: notificationSubCategory.nullable().optional(), appliance_name: z.string().nullable().optional(), appliance_serial: z.string().nullable().optional(), volume_name: z.string().nullable().optional(), volume_id: z.string().nullable().optional(), arguments: z.record(z.string(), z.unknown()).nullable().optional(), linked_doc: z.string().nullable().optional()}); export const notificationPaginationMetadataDto = z.object({iterator_id: z.string().nullable().optional(), page_size: z.number().int().optional(), total_pages: z.number().int().nullable().optional(), total_items: z.number().int(), page: z.number().int().nullable().optional()}); export const notificationsDto = z.object({items: z.array(notificationDto).optional(), metadata: notificationPaginationMetadataDto}); 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 }; /** * Get All Notifications * * GET /notifications */ export const getApiNotifications = async (args: GetApiNotificationsArgs, options?: GetApiNotificationsOptions) => { const {baseUrl = "https://am1.portal.api.nasuni.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) for (const item of args.severity ?? []) query.append("severity", String(item)) for (const item of args.category ?? []) query.append("category", String(item)) for (const item of args.sub_category ?? []) query.append("sub_category", String(item)) for (const item of args.appliance_name ?? []) query.append("appliance_name", String(item)) for (const item of args.volume_name ?? []) query.append("volume_name", String(item)) if (args.search != null) query.append("search", String(args.search)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.iterator_id != null) query.append("iterator_id", String(args.iterator_id)) if (args.page != null) query.append("page", String(args.page)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_direction != null) query.append("sort_direction", String(args.sort_direction)) if (args.include_count != null) query.append("include_count", String(args.include_count)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/notifications${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(notificationsDto, await res.json()) };