import {z} from 'zod' export type JumpcloudAlertsAlertCategory = 'ALERT_CATEGORY_UNSPECIFIED' | 'ALERT_CATEGORY_DIRECTORY' | 'ALERT_CATEGORY_SYSTEM' | 'ALERT_CATEGORY_ADMIN' | 'ALERT_CATEGORY_ACCESS' | 'ALERT_CATEGORY_GENERAL' | 'ALERT_CATEGORY_CUSTOM'; export type JumpcloudAlertsAlertSeverity = 'ALERT_SEVERITY_UNSPECIFIED' | 'ALERT_SEVERITY_LOW' | 'ALERT_SEVERITY_MEDIUM' | 'ALERT_SEVERITY_HIGH'; export type JumpcloudAlertsAlertSourceType = '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 type JumpcloudAlertsAlertStatus = 'ALERT_STATUS_UNSPECIFIED' | 'ALERT_STATUS_OPEN' | 'ALERT_STATUS_ACKNOWLEDGED' | 'ALERT_STATUS_RESOLVED' | 'ALERT_STATUS_AUTO_RESOLVED' | 'ALERT_STATUS_DELETED'; export type JumpcloudAlertsFilterCriteria = {category?: Array | undefined, existingCondition?: string | undefined, lastOccurredAtAfter?: string | undefined, lastOccurredAtBefore?: string | undefined, severity?: Array | undefined, sourceId?: Array | undefined, sourceType?: Array | undefined, status?: Array | undefined, title?: string | undefined}; export type JumpcloudAlertsBulkDeleteRequest = {excludeIds?: Array | undefined, filter?: JumpcloudAlertsFilterCriteria | undefined}; export type CreateApiAlertsBulkDeleteArgs = {body: JumpcloudAlertsBulkDeleteRequest}; export type CreateApiAlertsBulkDeleteOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudAlertsBulkDeleteResponse = z.object({affectedCount: z.number().int().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 performing bulk delete operations on alerts. * * POST /alerts/bulk-delete */ export const createApiAlertsBulkDelete = async (args: CreateApiAlertsBulkDeleteArgs, options?: CreateApiAlertsBulkDeleteOptions) => { 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(/\/+$/, '')}/alerts/bulk-delete${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(jumpcloudAlertsBulkDeleteResponse, await res.json()) };