Skip to content

Commit

Permalink
Cleanup alert-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Jan 10, 2025
1 parent cd1fafd commit 497d499
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/utils/alert-rules.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isObject } from '@socketsecurity/registry/lib/objects'

import type { SocketSdkResultType } from '@socketsecurity/sdk'

//#region UX Constants
Expand Down Expand Up @@ -43,13 +45,17 @@ type NonNormalizedResolvedRule =
/**
* Iterates over all entries with ordered issue rule for deferral. Iterates over
* all issue rules and finds the first defined value that does not defer otherwise
* uses the defaultValue. Takes the value and converts into a UX workflow
* uses the defaultValue. Takes the value and converts into a UX workflow.
*/
function resolveAlertRuleUX(
orderedRulesCollection: Iterable<Iterable<NonNormalizedRule>>,
defaultValue: NonNormalizedResolvedRule
): RuleActionUX {
if (defaultValue === true || defaultValue == null) {
if (
defaultValue === true ||
defaultValue === null ||
defaultValue === undefined
) {
defaultValue = { action: 'error' }
} else if (defaultValue === false) {
defaultValue = { action: 'ignore' }
Expand Down Expand Up @@ -80,14 +86,15 @@ function resolveAlertRuleUX(
}

/**
* Negative form because it is narrowing the type
* Negative form because it is narrowing the type.
*/
function ruleValueDoesNotDefer(
rule: NonNormalizedRule
): rule is NonNormalizedResolvedRule {
if (rule === undefined) {
return false
} else if (rule !== null && typeof rule === 'object') {
}
if (isObject(rule)) {
const { action } = rule
if (action === undefined || action === 'defer') {
return false
Expand All @@ -97,7 +104,7 @@ function ruleValueDoesNotDefer(
}

/**
* Handles booleans for backwards compatibility
* Handles booleans for backwards compatibility.
*/
function uxForDefinedNonDeferValue(
ruleValue: NonNormalizedResolvedRule
Expand Down

0 comments on commit 497d499

Please sign in to comment.