import {z} from 'zod' export type GetApiApiV2AlertsIdArgs = {id: string}; export type GetApiApiV2AlertsIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudAlertsAlertCategory = z.enum(["ALERT_CATEGORY_UNSPECIFIED", "ALERT_CATEGORY_DIRECTORY", "ALERT_CATEGORY_SYSTEM", "ALERT_CATEGORY_ADMIN", "ALERT_CATEGORY_ACCESS", "ALERT_CATEGORY_GENERAL", "ALERT_CATEGORY_CUSTOM"]); export const jumpcloudAlertsAlertSeverity = z.enum(["ALERT_SEVERITY_UNSPECIFIED", "ALERT_SEVERITY_LOW", "ALERT_SEVERITY_MEDIUM", "ALERT_SEVERITY_HIGH"]); export const jumpcloudAlertsAlertSourceType = z.enum(["ALERT_SOURCE_TYPE_UNSPECIFIED", "ALERT_SOURCE_TYPE_USER", "ALERT_SOURCE_TYPE_ADMIN", "ALERT_SOURCE_TYPE_DEVICE", "ALERT_SOURCE_TYPE_USER_GROUP", "ALERT_SOURCE_TYPE_DEVICES", "ALERT_SOURCE_TYPE_ACCESS_REQUEST", "ALERT_SOURCE_TYPE_SAAS_APPLICATION", "ALERT_SOURCE_TYPE_CUSTOM", "ALERT_SOURCE_TYPE_COMMAND", "ALERT_SOURCE_TYPE_POLICY", "ALERT_SOURCE_TYPE_APPLICATION", "ALERT_SOURCE_TYPE_IPLIST", "ALERT_SOURCE_TYPE_SOFTWARE", "ALERT_SOURCE_TYPE_ACCESSORY", "ALERT_SOURCE_TYPE_LOCATION"]); export const jumpcloudAlertsAlertStatus = z.enum(["ALERT_STATUS_UNSPECIFIED", "ALERT_STATUS_OPEN", "ALERT_STATUS_ACKNOWLEDGED", "ALERT_STATUS_RESOLVED", "ALERT_STATUS_AUTO_RESOLVED", "ALERT_STATUS_DELETED"]); export const jumpcloudAlertsAlert = z.object({acknowledgedAt: z.string().optional(), category: jumpcloudAlertsAlertCategory.optional(), createdAt: z.string().optional(), description: z.string().optional(), firstOccurredAt: z.string().optional(), frequency: z.number().int().optional(), lastOccurredAt: z.string().optional(), lastOccurrenceContext: z.object({}).optional(), objectId: z.string().optional(), occurrencesCount: z.number().int().optional(), organizationObjectId: z.string().optional(), referenceId: z.string().optional(), remark: z.string().optional(), resolvedAt: z.string().optional(), severity: jumpcloudAlertsAlertSeverity.optional(), sourceId: z.string().optional(), sourceName: z.string().optional(), sourceType: jumpcloudAlertsAlertSourceType.optional(), status: jumpcloudAlertsAlertStatus.optional(), title: z.string().optional(), updatedAt: z.string().optional()}); export const jumpcloudAlertsGetAlertResponse = z.object({alert: jumpcloudAlertsAlert.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 provides details of an alert. * * GET /api/v2/alerts/{id} */ export const getApiApiV2AlertsId = async (args: GetApiApiV2AlertsIdArgs, options?: GetApiApiV2AlertsIdOptions) => { const {baseUrl = "https://console.jumpcloud.com", 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(/\/+$/, '')}/api/v2/alerts/${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(jumpcloudAlertsGetAlertResponse, await res.json()) };