import {z} from 'zod' export type JumpcloudHealthmonitoringMonitoringWindow = {unit?: string | undefined, value?: number | undefined}; export type JumpcloudHealthmonitoringAlertFrequencySettings = {countPerResource?: boolean | undefined, enabled?: boolean | undefined, eventThresholdCount?: number | undefined, monitoringWindow?: JumpcloudHealthmonitoringMonitoringWindow | undefined}; export type JumpcloudHealthmonitoringRuleCategory = 'RULE_CATEGORY_UNSPECIFIED' | 'RULE_CATEGORY_DIRECTORY' | 'RULE_CATEGORY_SYSTEM' | 'RULE_CATEGORY_ADMIN' | 'RULE_CATEGORY_ACCESS' | 'RULE_CATEGORY_GENERAL' | 'RULE_CATEGORY_CUSTOM'; export type JumpcloudHealthmonitoringRuleCondition = {eventType?: string | undefined, filters?: Record | undefined, objectId?: string | undefined}; export type JumpcloudHealthmonitoringLogicalOperator = 'LOGICAL_OPERATOR_UNSPECIFIED' | 'LOGICAL_OPERATOR_AND' | 'LOGICAL_OPERATOR_OR'; export type JumpcloudHealthmonitoringFilterSource = 'FILTER_SOURCE_UNSPECIFIED' | 'FILTER_SOURCE_UI_BUILDER' | 'FILTER_SOURCE_EXPR_BUILDER'; export type JumpcloudHealthmonitoringRuleEventFilter = {createdAt?: string | undefined, eventTypes?: Array | undefined, filterSource?: JumpcloudHealthmonitoringFilterSource | undefined, objectId?: string | undefined, referenceFields?: Array | undefined, resolutionCondition?: string | undefined, updatedAt?: string | undefined, violationCondition?: string | undefined}; export type JumpcloudHealthmonitoringRuleLabel = 'RULE_LABEL_UNSPECIFIED' | 'RULE_LABEL_ADMIN' | 'RULE_LABEL_WORKFLOW'; export type JumpcloudHealthmonitoringRuleOsFamily = 'RULE_OS_FAMILY_UNSPECIFIED' | 'RULE_OS_FAMILY_ALL' | 'RULE_OS_FAMILY_WINDOWS' | 'RULE_OS_FAMILY_DARWIN' | 'RULE_OS_FAMILY_LINUX'; export type JumpcloudHealthmonitoringPollRuleCondition = {enabled?: boolean | undefined, objectId?: string | undefined, thresholdValue?: number | undefined}; export type JumpcloudHealthmonitoringRuleType = 'RULE_TYPE_UNSPECIFIED' | 'RULE_TYPE_TEMPLATE_BASED' | 'RULE_TYPE_EVENT_FILTER_BASED' | 'RULE_TYPE_POLL_BASED'; export type JumpcloudHealthmonitoringRuleSeverity = 'RULE_SEVERITY_UNSPECIFIED' | 'RULE_SEVERITY_LOW' | 'RULE_SEVERITY_MEDIUM' | 'RULE_SEVERITY_HIGH' | 'RULE_SEVERITY_CRITICAL'; export type JumpcloudHealthmonitoringRuleStatus = 'RULE_STATUS_UNSPECIFIED' | 'RULE_STATUS_ENABLED' | 'RULE_STATUS_DISABLED'; export type JumpcloudHealthmonitoringRule = {alertFrequencySettings?: JumpcloudHealthmonitoringAlertFrequencySettings | undefined, alertsEnabled?: boolean | undefined, category?: JumpcloudHealthmonitoringRuleCategory | undefined, conditions?: Array | undefined, conditionsRelation?: JumpcloudHealthmonitoringLogicalOperator | undefined, createdAt?: string | undefined, createdBy?: string | undefined, createdByObjectId?: string | undefined, description?: string | undefined, detectPreExistingAnamolies?: boolean | undefined, eventFilters?: Array | undefined, eventType?: string | undefined, excludeSuspendedUsers?: boolean | undefined, groupObjectIds?: Array | undefined, labels?: JumpcloudHealthmonitoringRuleLabel | undefined, lastUpdatedAt?: string | undefined, lastUpdatedBy?: string | undefined, name?: string | undefined, notificationChannelObjectIds?: Array | undefined, notifyOnAcknowledgement?: boolean | undefined, notifyOnResolution?: boolean | undefined, notifyOnViolation?: boolean | undefined, notifyPrimaryUserOfDevice?: boolean | undefined, objectId?: string | undefined, organizationObjectId?: string | undefined, osFamily?: JumpcloudHealthmonitoringRuleOsFamily | undefined, pollConditions?: Array | undefined, postExpiryEnabled?: boolean | undefined, ruleSubtype?: string | undefined, ruleType?: JumpcloudHealthmonitoringRuleType | undefined, scopeType?: string | undefined, selectedScopeValues?: Array | undefined, severity?: JumpcloudHealthmonitoringRuleSeverity | undefined, status?: JumpcloudHealthmonitoringRuleStatus | undefined, templateObjectId?: string | undefined}; export type JumpcloudHealthmonitoringCreateRuleRequest = {rule?: JumpcloudHealthmonitoringRule | undefined}; export type CreateApiHealthmonitoringRulesArgs = {body: JumpcloudHealthmonitoringCreateRuleRequest}; export type CreateApiHealthmonitoringRulesOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudHealthmonitoringMonitoringWindow = z.object({unit: z.string().optional(), value: z.number().int().optional()}); export const jumpcloudHealthmonitoringAlertFrequencySettings = z.object({countPerResource: z.boolean().optional(), enabled: z.boolean().optional(), eventThresholdCount: z.number().int().optional(), monitoringWindow: jumpcloudHealthmonitoringMonitoringWindow.optional()}); export const jumpcloudHealthmonitoringRuleCategory = z.enum(["RULE_CATEGORY_UNSPECIFIED", "RULE_CATEGORY_DIRECTORY", "RULE_CATEGORY_SYSTEM", "RULE_CATEGORY_ADMIN", "RULE_CATEGORY_ACCESS", "RULE_CATEGORY_GENERAL", "RULE_CATEGORY_CUSTOM"]); export const jumpcloudHealthmonitoringRuleCondition = z.object({eventType: z.string().optional(), filters: z.object({}).optional(), objectId: z.string().optional()}); export const jumpcloudHealthmonitoringLogicalOperator = z.enum(["LOGICAL_OPERATOR_UNSPECIFIED", "LOGICAL_OPERATOR_AND", "LOGICAL_OPERATOR_OR"]); export const jumpcloudHealthmonitoringFilterSource = z.enum(["FILTER_SOURCE_UNSPECIFIED", "FILTER_SOURCE_UI_BUILDER", "FILTER_SOURCE_EXPR_BUILDER"]); export const jumpcloudHealthmonitoringRuleEventFilter = z.object({createdAt: z.string().optional(), eventTypes: z.array(z.string()).optional(), filterSource: jumpcloudHealthmonitoringFilterSource.optional(), objectId: z.string().optional(), referenceFields: z.array(z.string()).optional(), resolutionCondition: z.string().optional(), updatedAt: z.string().optional(), violationCondition: z.string().optional()}); export const jumpcloudHealthmonitoringRuleLabel = z.enum(["RULE_LABEL_UNSPECIFIED", "RULE_LABEL_ADMIN", "RULE_LABEL_WORKFLOW"]); export const jumpcloudHealthmonitoringRuleOsFamily = z.enum(["RULE_OS_FAMILY_UNSPECIFIED", "RULE_OS_FAMILY_ALL", "RULE_OS_FAMILY_WINDOWS", "RULE_OS_FAMILY_DARWIN", "RULE_OS_FAMILY_LINUX"]); export const jumpcloudHealthmonitoringPollRuleCondition = z.object({enabled: z.boolean().optional(), objectId: z.string().optional(), thresholdValue: z.number().int().optional()}); export const jumpcloudHealthmonitoringRuleType = z.enum(["RULE_TYPE_UNSPECIFIED", "RULE_TYPE_TEMPLATE_BASED", "RULE_TYPE_EVENT_FILTER_BASED", "RULE_TYPE_POLL_BASED"]); export const jumpcloudHealthmonitoringRuleSeverity = z.enum(["RULE_SEVERITY_UNSPECIFIED", "RULE_SEVERITY_LOW", "RULE_SEVERITY_MEDIUM", "RULE_SEVERITY_HIGH", "RULE_SEVERITY_CRITICAL"]); export const jumpcloudHealthmonitoringRuleStatus = z.enum(["RULE_STATUS_UNSPECIFIED", "RULE_STATUS_ENABLED", "RULE_STATUS_DISABLED"]); export const jumpcloudHealthmonitoringRule = z.object({alertFrequencySettings: jumpcloudHealthmonitoringAlertFrequencySettings.optional(), alertsEnabled: z.boolean().optional(), category: jumpcloudHealthmonitoringRuleCategory.optional(), conditions: z.array(jumpcloudHealthmonitoringRuleCondition).optional(), conditionsRelation: jumpcloudHealthmonitoringLogicalOperator.optional(), createdAt: z.string().optional(), createdBy: z.string().optional(), createdByObjectId: z.string().optional(), description: z.string().optional(), detectPreExistingAnamolies: z.boolean().optional(), eventFilters: z.array(jumpcloudHealthmonitoringRuleEventFilter).optional(), eventType: z.string().optional(), excludeSuspendedUsers: z.boolean().optional(), groupObjectIds: z.array(z.string()).optional(), labels: jumpcloudHealthmonitoringRuleLabel.optional(), lastUpdatedAt: z.string().optional(), lastUpdatedBy: z.string().optional(), name: z.string().optional(), notificationChannelObjectIds: z.array(z.string()).optional(), notifyOnAcknowledgement: z.boolean().optional(), notifyOnResolution: z.boolean().optional(), notifyOnViolation: z.boolean().optional(), notifyPrimaryUserOfDevice: z.boolean().optional(), objectId: z.string().optional(), organizationObjectId: z.string().optional(), osFamily: jumpcloudHealthmonitoringRuleOsFamily.optional(), pollConditions: z.array(jumpcloudHealthmonitoringPollRuleCondition).optional(), postExpiryEnabled: z.boolean().optional(), ruleSubtype: z.string().optional(), ruleType: jumpcloudHealthmonitoringRuleType.optional(), scopeType: z.string().optional(), selectedScopeValues: z.array(z.string()).optional(), severity: jumpcloudHealthmonitoringRuleSeverity.optional(), status: jumpcloudHealthmonitoringRuleStatus.optional(), templateObjectId: z.string().optional()}); export const jumpcloudHealthmonitoringCreateRuleResponse = z.object({rule: jumpcloudHealthmonitoringRule.optional(), warning: z.string().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 creating the rules. * * POST /healthmonitoring/rules */ export const createApiHealthmonitoringRules = async (args: CreateApiHealthmonitoringRulesArgs, options?: CreateApiHealthmonitoringRulesOptions) => { 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(/\/+$/, '')}/healthmonitoring/rules${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(jumpcloudHealthmonitoringCreateRuleResponse, await res.json()) };