@o3co/auth.policy-verifier.builtins 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.ja.md +101 -0
  2. package/README.md +101 -0
  3. package/dist/__tests__/rules/AttrLiteralCompare.test.d.mts +2 -0
  4. package/dist/__tests__/rules/AttrLiteralCompare.test.d.mts.map +1 -0
  5. package/dist/__tests__/rules/AttrLiteralCompare.test.mjs +253 -0
  6. package/dist/__tests__/rules/AttrLiteralEqual.test.d.mts +2 -0
  7. package/dist/__tests__/rules/AttrLiteralEqual.test.d.mts.map +1 -0
  8. package/dist/__tests__/rules/AttrLiteralEqual.test.mjs +138 -0
  9. package/dist/__tests__/rules/AttrLiteralIn.test.d.mts +2 -0
  10. package/dist/__tests__/rules/AttrLiteralIn.test.d.mts.map +1 -0
  11. package/dist/__tests__/rules/AttrLiteralIn.test.mjs +160 -0
  12. package/dist/__tests__/rules/AttrLiteralNotEqual.test.d.mts +2 -0
  13. package/dist/__tests__/rules/AttrLiteralNotEqual.test.d.mts.map +1 -0
  14. package/dist/__tests__/rules/AttrLiteralNotEqual.test.mjs +157 -0
  15. package/dist/__tests__/rules/AttrLiteralNotIn.test.d.mts +2 -0
  16. package/dist/__tests__/rules/AttrLiteralNotIn.test.d.mts.map +1 -0
  17. package/dist/__tests__/rules/AttrLiteralNotIn.test.mjs +168 -0
  18. package/dist/__tests__/rules/AttrMatchRule.test.mjs +8 -0
  19. package/dist/__tests__/rules/AttrPairCompare.test.d.mts +2 -0
  20. package/dist/__tests__/rules/AttrPairCompare.test.d.mts.map +1 -0
  21. package/dist/__tests__/rules/AttrPairCompare.test.mjs +319 -0
  22. package/dist/__tests__/rules/AttrPairEqual.test.d.mts +2 -0
  23. package/dist/__tests__/rules/AttrPairEqual.test.d.mts.map +1 -0
  24. package/dist/__tests__/rules/AttrPairEqual.test.mjs +155 -0
  25. package/dist/__tests__/rules/AttrPairNotEqual.test.d.mts +2 -0
  26. package/dist/__tests__/rules/AttrPairNotEqual.test.d.mts.map +1 -0
  27. package/dist/__tests__/rules/AttrPairNotEqual.test.mjs +155 -0
  28. package/dist/__tests__/rules/_sharedValidation.test.d.mts +2 -0
  29. package/dist/__tests__/rules/_sharedValidation.test.d.mts.map +1 -0
  30. package/dist/__tests__/rules/_sharedValidation.test.mjs +325 -0
  31. package/dist/index.d.mts +8 -0
  32. package/dist/index.d.mts.map +1 -1
  33. package/dist/index.mjs +8 -0
  34. package/dist/rules/AttrLiteralCompare.d.mts +31 -0
  35. package/dist/rules/AttrLiteralCompare.d.mts.map +1 -0
  36. package/dist/rules/AttrLiteralCompare.mjs +36 -0
  37. package/dist/rules/AttrLiteralEqual.d.mts +37 -0
  38. package/dist/rules/AttrLiteralEqual.d.mts.map +1 -0
  39. package/dist/rules/AttrLiteralEqual.mjs +43 -0
  40. package/dist/rules/AttrLiteralIn.d.mts +38 -0
  41. package/dist/rules/AttrLiteralIn.d.mts.map +1 -0
  42. package/dist/rules/AttrLiteralIn.mjs +46 -0
  43. package/dist/rules/AttrLiteralNotEqual.d.mts +36 -0
  44. package/dist/rules/AttrLiteralNotEqual.d.mts.map +1 -0
  45. package/dist/rules/AttrLiteralNotEqual.mjs +42 -0
  46. package/dist/rules/AttrLiteralNotIn.d.mts +33 -0
  47. package/dist/rules/AttrLiteralNotIn.d.mts.map +1 -0
  48. package/dist/rules/AttrLiteralNotIn.mjs +41 -0
  49. package/dist/rules/AttrMatchRule.d.mts +7 -34
  50. package/dist/rules/AttrMatchRule.d.mts.map +1 -1
  51. package/dist/rules/AttrMatchRule.mjs +7 -32
  52. package/dist/rules/AttrPairCompare.d.mts +35 -0
  53. package/dist/rules/AttrPairCompare.d.mts.map +1 -0
  54. package/dist/rules/AttrPairCompare.mjs +43 -0
  55. package/dist/rules/AttrPairEqual.d.mts +35 -0
  56. package/dist/rules/AttrPairEqual.d.mts.map +1 -0
  57. package/dist/rules/AttrPairEqual.mjs +44 -0
  58. package/dist/rules/AttrPairNotEqual.d.mts +34 -0
  59. package/dist/rules/AttrPairNotEqual.d.mts.map +1 -0
  60. package/dist/rules/AttrPairNotEqual.mjs +43 -0
  61. package/dist/rules/_sharedValidation.d.mts +87 -0
  62. package/dist/rules/_sharedValidation.d.mts.map +1 -0
  63. package/dist/rules/_sharedValidation.mjs +189 -0
  64. package/package.json +5 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttrLiteralNotEqual.d.mts","sourceRoot":"","sources":["../../src/rules/AttrLiteralNotEqual.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EACN,KAAK,YAAY,EAIjB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,yBAAyB;IACzC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,YAAY,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,mBAAoB,YAAW,IAAI;IAKnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEI,MAAM,EAAE,yBAAyB;IAU9D,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;CAKlC"}
@@ -0,0 +1,42 @@
1
+ import { requireAttrName, requireLiteralValue, requireOptionalGroup, } from "./_sharedValidation.mjs";
2
+ /**
3
+ * Rule that passes when a named attribute is present, matches the type of the
4
+ * configured literal value, and is strictly NOT equal to it. No type coercion
5
+ * is performed. If the attribute is missing, null, or of the wrong type the
6
+ * rule returns false (safe-deny).
7
+ *
8
+ * ## Grouping and the default ruleType
9
+ *
10
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
11
+ * across groups. The default `ruleType` is derived from `a`, `typeof v`, and
12
+ * `String(v)`:
13
+ * `attr_literal_not_equal:{a}:{typeof v}:{String(v)}`
14
+ *
15
+ * The `typeof v` segment prevents silent `ruleType` collisions between
16
+ * different-type literals that stringify the same way (e.g. `1` vs `"1"`),
17
+ * which would otherwise be OR-combined by the evaluator against the intent
18
+ * of two independent constraints. See AttrLiteralEqual for the same rationale.
19
+ *
20
+ * Pass a shared `group` string to two instances to opt into OR semantics.
21
+ */
22
+ export class AttrLiteralNotEqual {
23
+ config;
24
+ ruleType;
25
+ code = "attr_equal";
26
+ message;
27
+ constructor(config) {
28
+ this.config = config;
29
+ requireAttrName("AttrLiteralNotEqual", "a", config.a);
30
+ requireLiteralValue("AttrLiteralNotEqual", "v", config.v);
31
+ const group = requireOptionalGroup("AttrLiteralNotEqual", config.group);
32
+ this.ruleType =
33
+ group ?? `attr_literal_not_equal:${config.a}:${typeof config.v}:${String(config.v)}`;
34
+ this.message = `Attribute constraint not satisfied: ${config.a} must not equal ${String(config.v)}.`;
35
+ }
36
+ verify(attrs) {
37
+ const x = attrs.get(this.config.a);
38
+ if (typeof x !== typeof this.config.v)
39
+ return false;
40
+ return x !== this.config.v;
41
+ }
42
+ }
@@ -0,0 +1,33 @@
1
+ import type { Attributes, Rule } from "@o3co/auth.policy-verifier.core";
2
+ import { type LiteralValue } from "./_sharedValidation.mjs";
3
+ export interface AttrLiteralNotInConfig {
4
+ a: string;
5
+ values: LiteralValue[];
6
+ group?: string;
7
+ }
8
+ /**
9
+ * Rule that passes when a named attribute is present, matches the element type
10
+ * of the configured values array, and is NOT included in that array. No type
11
+ * coercion is performed. If the attribute is missing, null, or of the wrong
12
+ * type the rule returns false (safe-deny).
13
+ *
14
+ * ## Grouping and the default ruleType
15
+ *
16
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
17
+ * across groups. The default `ruleType` is derived from `a` and a stable
18
+ * content-hash key over the values array:
19
+ * `attr_literal_not_in:{a}:{valuesKey}`
20
+ *
21
+ * Pass an explicit `group` string to override the default ruleType entirely.
22
+ */
23
+ export declare class AttrLiteralNotIn implements Rule {
24
+ private readonly config;
25
+ readonly ruleType: string;
26
+ readonly code = "attr_in_set";
27
+ readonly message: string;
28
+ private readonly elementType;
29
+ private readonly valuesSet;
30
+ constructor(config: AttrLiteralNotInConfig);
31
+ verify(attrs: Attributes): boolean;
32
+ }
33
+ //# sourceMappingURL=AttrLiteralNotIn.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttrLiteralNotIn.d.mts","sourceRoot":"","sources":["../../src/rules/AttrLiteralNotIn.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAEN,KAAK,YAAY,EAIjB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,sBAAsB;IACtC,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,gBAAiB,YAAW,IAAI;IAQhC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,iBAAiB;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;gBAEjB,MAAM,EAAE,sBAAsB;IAa3D,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;CAKlC"}
@@ -0,0 +1,41 @@
1
+ import { computeValuesKey, requireAttrName, requireHomogeneousLiteralArray, requireOptionalGroup, } from "./_sharedValidation.mjs";
2
+ /**
3
+ * Rule that passes when a named attribute is present, matches the element type
4
+ * of the configured values array, and is NOT included in that array. No type
5
+ * coercion is performed. If the attribute is missing, null, or of the wrong
6
+ * type the rule returns false (safe-deny).
7
+ *
8
+ * ## Grouping and the default ruleType
9
+ *
10
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
11
+ * across groups. The default `ruleType` is derived from `a` and a stable
12
+ * content-hash key over the values array:
13
+ * `attr_literal_not_in:{a}:{valuesKey}`
14
+ *
15
+ * Pass an explicit `group` string to override the default ruleType entirely.
16
+ */
17
+ export class AttrLiteralNotIn {
18
+ config;
19
+ ruleType;
20
+ code = "attr_in_set";
21
+ message;
22
+ elementType;
23
+ valuesSet;
24
+ constructor(config) {
25
+ this.config = config;
26
+ requireAttrName("AttrLiteralNotIn", "a", config.a);
27
+ const values = requireHomogeneousLiteralArray("AttrLiteralNotIn", config.values);
28
+ const group = requireOptionalGroup("AttrLiteralNotIn", config.group);
29
+ this.elementType = typeof values[0];
30
+ this.valuesSet = new Set(values);
31
+ const valuesKey = computeValuesKey(values);
32
+ this.ruleType = group ?? `attr_literal_not_in:${config.a}:${valuesKey}`;
33
+ this.message = `Attribute constraint not satisfied: ${config.a} must not be one of [${values.map(String).join(", ")}].`;
34
+ }
35
+ verify(attrs) {
36
+ const x = attrs.get(this.config.a);
37
+ if (typeof x !== this.elementType)
38
+ return false;
39
+ return !this.valuesSet.has(x);
40
+ }
41
+ }
@@ -1,42 +1,15 @@
1
- import type { Attributes, Rule } from "@o3co/auth.policy-verifier.core";
2
- export interface AttrMatchRuleConfig {
3
- a: string;
4
- b: string;
5
- /**
6
- * Optional grouping key used as `ruleType`. See the class comment for
7
- * how this interacts with the evaluator's OR-within-group /
8
- * AND-across-groups semantics.
9
- */
10
- group?: string;
11
- }
1
+ import { AttrPairEqual, type AttrPairEqualConfig } from "./AttrPairEqual.mjs";
2
+ export type AttrMatchRuleConfig = AttrPairEqualConfig;
12
3
  /**
13
- * Rule that passes when two named attributes are present, are non-empty
14
- * strings, and are equal. A pure predicate over the attributes map —
15
- * `verify(attrs)` does not touch `CollectorContext` and does not close
16
- * over request state.
17
- *
18
- * ## Grouping and the default ruleType
19
- *
20
- * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
21
- * across groups. If every `AttrMatchRule` shared one fixed `ruleType`,
22
- * two instances collected for different comparisons (e.g. subject vs.
23
- * subscriber AND tenant vs. request-tenant) would be OR'd together and
24
- * authorization would weaken silently.
25
- *
26
- * To default to the safe reading of "each distinct pair of attributes
27
- * is a separate AND-combined requirement", `ruleType` is derived from
28
- * `a` and `b` when `group` is not given: `attr_match:{a}:{b}`.
4
+ * @deprecated Use {@link AttrPairEqual}. Scheduled for removal in a future major version.
29
5
  *
30
- * When callers actually want two comparisons to be OR-combined
31
- * (alternative identities, for example), they opt in explicitly by
32
- * passing the same `group` to both rule instances.
6
+ * Kept as a thin wrapper that preserves the legacy `ruleType` (`attr_match:{a}:{b}`)
7
+ * and legacy `message` wording. `verify()` semantics are inherited unchanged from
8
+ * `AttrPairEqual`: both named attributes must be non-empty strings and equal.
33
9
  */
34
- export declare class AttrMatchRule implements Rule {
35
- private readonly config;
10
+ export declare class AttrMatchRule extends AttrPairEqual {
36
11
  readonly ruleType: string;
37
- readonly code = "attr_mismatch";
38
12
  readonly message: string;
39
13
  constructor(config: AttrMatchRuleConfig);
40
- verify(attrs: Attributes): boolean;
41
14
  }
42
15
  //# sourceMappingURL=AttrMatchRule.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AttrMatchRule.d.mts","sourceRoot":"","sources":["../../src/rules/AttrMatchRule.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAExE,MAAM,WAAW,mBAAmB;IACnC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,aAAc,YAAW,IAAI;IAK7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,mBAAmB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEI,MAAM,EAAE,mBAAmB;IAKxD,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;CAOlC"}
1
+ {"version":3,"file":"AttrMatchRule.d.mts","sourceRoot":"","sources":["../../src/rules/AttrMatchRule.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEtD;;;;;;GAMG;AACH,qBAAa,aAAc,SAAQ,aAAa;IAC/C,SAAkB,QAAQ,EAAE,MAAM,CAAC;IACnC,SAAkB,OAAO,EAAE,MAAM,CAAC;gBAEtB,MAAM,EAAE,mBAAmB;CAKvC"}
@@ -1,42 +1,17 @@
1
+ import { AttrPairEqual } from "./AttrPairEqual.mjs";
1
2
  /**
2
- * Rule that passes when two named attributes are present, are non-empty
3
- * strings, and are equal. A pure predicate over the attributes map —
4
- * `verify(attrs)` does not touch `CollectorContext` and does not close
5
- * over request state.
3
+ * @deprecated Use {@link AttrPairEqual}. Scheduled for removal in a future major version.
6
4
  *
7
- * ## Grouping and the default ruleType
8
- *
9
- * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
10
- * across groups. If every `AttrMatchRule` shared one fixed `ruleType`,
11
- * two instances collected for different comparisons (e.g. subject vs.
12
- * subscriber AND tenant vs. request-tenant) would be OR'd together and
13
- * authorization would weaken silently.
14
- *
15
- * To default to the safe reading of "each distinct pair of attributes
16
- * is a separate AND-combined requirement", `ruleType` is derived from
17
- * `a` and `b` when `group` is not given: `attr_match:{a}:{b}`.
18
- *
19
- * When callers actually want two comparisons to be OR-combined
20
- * (alternative identities, for example), they opt in explicitly by
21
- * passing the same `group` to both rule instances.
5
+ * Kept as a thin wrapper that preserves the legacy `ruleType` (`attr_match:{a}:{b}`)
6
+ * and legacy `message` wording. `verify()` semantics are inherited unchanged from
7
+ * `AttrPairEqual`: both named attributes must be non-empty strings and equal.
22
8
  */
23
- export class AttrMatchRule {
24
- config;
9
+ export class AttrMatchRule extends AttrPairEqual {
25
10
  ruleType;
26
- code = "attr_mismatch";
27
11
  message;
28
12
  constructor(config) {
29
- this.config = config;
13
+ super(config);
30
14
  this.ruleType = config.group ?? `attr_match:${config.a}:${config.b}`;
31
15
  this.message = `Attribute constraint not satisfied: ${config.a} and ${config.b} must both be non-empty strings and equal.`;
32
16
  }
33
- verify(attrs) {
34
- const a = attrs.get(this.config.a);
35
- const b = attrs.get(this.config.b);
36
- if (typeof a !== "string" || a.length === 0)
37
- return false;
38
- if (typeof b !== "string" || b.length === 0)
39
- return false;
40
- return a === b;
41
- }
42
17
  }
@@ -0,0 +1,35 @@
1
+ import type { Attributes, Rule } from "@o3co/auth.policy-verifier.core";
2
+ import { type CompareOp } from "./_sharedValidation.mjs";
3
+ export interface AttrPairCompareConfig {
4
+ a: string;
5
+ op: CompareOp;
6
+ b: string;
7
+ group?: string;
8
+ }
9
+ /**
10
+ * Rule that passes when two named attributes are present, are both numbers,
11
+ * and satisfy the configured comparison operator. NaN on either side always
12
+ * returns false (JS native comparison semantics). Missing, null, or non-number
13
+ * attributes return false (safe-deny).
14
+ *
15
+ * Unlike AttrLiteralCompare, the right-hand side comes from the attributes map
16
+ * at evaluation time rather than from a static config value — so NaN is not
17
+ * rejected at construction time.
18
+ *
19
+ * ## Grouping and the default ruleType
20
+ *
21
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
22
+ * across groups. The default `ruleType` is derived from `a`, `op`, and `b`:
23
+ * `attr_pair_compare:{a}:{op}:{b}`
24
+ *
25
+ * Pass an explicit `group` string to override the default ruleType entirely.
26
+ */
27
+ export declare class AttrPairCompare implements Rule {
28
+ private readonly config;
29
+ readonly ruleType: string;
30
+ readonly code = "attr_compare_violated";
31
+ readonly message: string;
32
+ constructor(config: AttrPairCompareConfig);
33
+ verify(attrs: Attributes): boolean;
34
+ }
35
+ //# sourceMappingURL=AttrPairCompare.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttrPairCompare.d.mts","sourceRoot":"","sources":["../../src/rules/AttrPairCompare.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAEN,KAAK,SAAS,EAId,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,qBAAqB;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,SAAS,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,eAAgB,YAAW,IAAI;IAK/B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,2BAA2B;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEI,MAAM,EAAE,qBAAqB;IAU1D,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;CAOlC"}
@@ -0,0 +1,43 @@
1
+ import { applyCompare, requireAttrName, requireCompareOp, requireOptionalGroup, } from "./_sharedValidation.mjs";
2
+ /**
3
+ * Rule that passes when two named attributes are present, are both numbers,
4
+ * and satisfy the configured comparison operator. NaN on either side always
5
+ * returns false (JS native comparison semantics). Missing, null, or non-number
6
+ * attributes return false (safe-deny).
7
+ *
8
+ * Unlike AttrLiteralCompare, the right-hand side comes from the attributes map
9
+ * at evaluation time rather than from a static config value — so NaN is not
10
+ * rejected at construction time.
11
+ *
12
+ * ## Grouping and the default ruleType
13
+ *
14
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
15
+ * across groups. The default `ruleType` is derived from `a`, `op`, and `b`:
16
+ * `attr_pair_compare:{a}:{op}:{b}`
17
+ *
18
+ * Pass an explicit `group` string to override the default ruleType entirely.
19
+ */
20
+ export class AttrPairCompare {
21
+ config;
22
+ ruleType;
23
+ code = "attr_compare_violated";
24
+ message;
25
+ constructor(config) {
26
+ this.config = config;
27
+ requireAttrName("AttrPairCompare", "a", config.a);
28
+ requireAttrName("AttrPairCompare", "b", config.b);
29
+ requireCompareOp("AttrPairCompare", config.op);
30
+ const group = requireOptionalGroup("AttrPairCompare", config.group);
31
+ this.ruleType = group ?? `attr_pair_compare:${config.a}:${config.op}:${config.b}`;
32
+ this.message = `Attribute constraint not satisfied: ${config.a} must be ${config.op} ${config.b}.`;
33
+ }
34
+ verify(attrs) {
35
+ const a = attrs.get(this.config.a);
36
+ const b = attrs.get(this.config.b);
37
+ if (typeof a !== "number")
38
+ return false;
39
+ if (typeof b !== "number")
40
+ return false;
41
+ return applyCompare(this.config.op, a, b);
42
+ }
43
+ }
@@ -0,0 +1,35 @@
1
+ import type { Attributes, Rule } from "@o3co/auth.policy-verifier.core";
2
+ export interface AttrPairEqualConfig {
3
+ a: string;
4
+ b: string;
5
+ group?: string;
6
+ }
7
+ /**
8
+ * Rule that passes when two named attributes are present, are non-empty
9
+ * strings, and are strictly equal. No type coercion is performed: both
10
+ * attribute values must be non-empty strings.
11
+ *
12
+ * ## Backward compatibility
13
+ *
14
+ * AttrPairEqual deliberately retains the string-only semantic of the legacy
15
+ * AttrMatchRule. Do not widen verify() to accept numbers or booleans — the
16
+ * Phase 4 AttrMatchRule alias depends on this invariant.
17
+ *
18
+ * ## Grouping and the default ruleType
19
+ *
20
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
21
+ * across groups. The default `ruleType` is derived from `a` and `b` so that
22
+ * distinct pair requirements are AND-combined by default:
23
+ * `attr_pair_equal:{a}:{b}`
24
+ *
25
+ * Pass a shared `group` string to two instances to opt into OR semantics.
26
+ */
27
+ export declare class AttrPairEqual implements Rule {
28
+ private readonly config;
29
+ readonly ruleType: string;
30
+ readonly code = "attr_mismatch";
31
+ readonly message: string;
32
+ constructor(config: AttrPairEqualConfig);
33
+ verify(attrs: Attributes): boolean;
34
+ }
35
+ //# sourceMappingURL=AttrPairEqual.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttrPairEqual.d.mts","sourceRoot":"","sources":["../../src/rules/AttrPairEqual.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAGxE,MAAM,WAAW,mBAAmB;IACnC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,aAAc,YAAW,IAAI;IAK7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,mBAAmB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEI,MAAM,EAAE,mBAAmB;IASxD,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;CAOlC"}
@@ -0,0 +1,44 @@
1
+ import { requireAttrName, requireOptionalGroup } from "./_sharedValidation.mjs";
2
+ /**
3
+ * Rule that passes when two named attributes are present, are non-empty
4
+ * strings, and are strictly equal. No type coercion is performed: both
5
+ * attribute values must be non-empty strings.
6
+ *
7
+ * ## Backward compatibility
8
+ *
9
+ * AttrPairEqual deliberately retains the string-only semantic of the legacy
10
+ * AttrMatchRule. Do not widen verify() to accept numbers or booleans — the
11
+ * Phase 4 AttrMatchRule alias depends on this invariant.
12
+ *
13
+ * ## Grouping and the default ruleType
14
+ *
15
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
16
+ * across groups. The default `ruleType` is derived from `a` and `b` so that
17
+ * distinct pair requirements are AND-combined by default:
18
+ * `attr_pair_equal:{a}:{b}`
19
+ *
20
+ * Pass a shared `group` string to two instances to opt into OR semantics.
21
+ */
22
+ export class AttrPairEqual {
23
+ config;
24
+ ruleType;
25
+ code = "attr_mismatch";
26
+ message;
27
+ constructor(config) {
28
+ this.config = config;
29
+ requireAttrName("AttrPairEqual", "a", config.a);
30
+ requireAttrName("AttrPairEqual", "b", config.b);
31
+ const group = requireOptionalGroup("AttrPairEqual", config.group);
32
+ this.ruleType = group ?? `attr_pair_equal:${config.a}:${config.b}`;
33
+ this.message = `Attribute constraint not satisfied: ${config.a} must equal ${config.b}.`;
34
+ }
35
+ verify(attrs) {
36
+ const a = attrs.get(this.config.a);
37
+ const b = attrs.get(this.config.b);
38
+ if (typeof a !== "string" || a.length === 0)
39
+ return false;
40
+ if (typeof b !== "string" || b.length === 0)
41
+ return false;
42
+ return a === b;
43
+ }
44
+ }
@@ -0,0 +1,34 @@
1
+ import type { Attributes, Rule } from "@o3co/auth.policy-verifier.core";
2
+ export interface AttrPairNotEqualConfig {
3
+ a: string;
4
+ b: string;
5
+ group?: string;
6
+ }
7
+ /**
8
+ * Rule that passes when two named attributes are present, are non-empty
9
+ * strings, and are strictly NOT equal. No type coercion is performed: both
10
+ * attribute values must be non-empty strings. Missing, null, empty, or
11
+ * non-string attributes return false (safe-deny).
12
+ *
13
+ * ## Denial code
14
+ *
15
+ * The denial code is "attr_match": the rule failed because the pair matched
16
+ * when it was required to differ.
17
+ *
18
+ * ## Grouping and the default ruleType
19
+ *
20
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
21
+ * across groups. The default `ruleType` is derived from `a` and `b`:
22
+ * `attr_pair_not_equal:{a}:{b}`
23
+ *
24
+ * Pass a shared `group` string to two instances to opt into OR semantics.
25
+ */
26
+ export declare class AttrPairNotEqual implements Rule {
27
+ private readonly config;
28
+ readonly ruleType: string;
29
+ readonly code = "attr_match";
30
+ readonly message: string;
31
+ constructor(config: AttrPairNotEqualConfig);
32
+ verify(attrs: Attributes): boolean;
33
+ }
34
+ //# sourceMappingURL=AttrPairNotEqual.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttrPairNotEqual.d.mts","sourceRoot":"","sources":["../../src/rules/AttrPairNotEqual.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAGxE,MAAM,WAAW,sBAAsB;IACtC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,gBAAiB,YAAW,IAAI;IAKhC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEI,MAAM,EAAE,sBAAsB;IAS3D,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;CAOlC"}
@@ -0,0 +1,43 @@
1
+ import { requireAttrName, requireOptionalGroup } from "./_sharedValidation.mjs";
2
+ /**
3
+ * Rule that passes when two named attributes are present, are non-empty
4
+ * strings, and are strictly NOT equal. No type coercion is performed: both
5
+ * attribute values must be non-empty strings. Missing, null, empty, or
6
+ * non-string attributes return false (safe-deny).
7
+ *
8
+ * ## Denial code
9
+ *
10
+ * The denial code is "attr_match": the rule failed because the pair matched
11
+ * when it was required to differ.
12
+ *
13
+ * ## Grouping and the default ruleType
14
+ *
15
+ * The evaluator groups rules by `ruleType`, ORs within a group, and ANDs
16
+ * across groups. The default `ruleType` is derived from `a` and `b`:
17
+ * `attr_pair_not_equal:{a}:{b}`
18
+ *
19
+ * Pass a shared `group` string to two instances to opt into OR semantics.
20
+ */
21
+ export class AttrPairNotEqual {
22
+ config;
23
+ ruleType;
24
+ code = "attr_match";
25
+ message;
26
+ constructor(config) {
27
+ this.config = config;
28
+ requireAttrName("AttrPairNotEqual", "a", config.a);
29
+ requireAttrName("AttrPairNotEqual", "b", config.b);
30
+ const group = requireOptionalGroup("AttrPairNotEqual", config.group);
31
+ this.ruleType = group ?? `attr_pair_not_equal:${config.a}:${config.b}`;
32
+ this.message = `Attribute constraint not satisfied: ${config.a} must not equal ${config.b}.`;
33
+ }
34
+ verify(attrs) {
35
+ const a = attrs.get(this.config.a);
36
+ const b = attrs.get(this.config.b);
37
+ if (typeof a !== "string" || a.length === 0)
38
+ return false;
39
+ if (typeof b !== "string" || b.length === 0)
40
+ return false;
41
+ return a !== b;
42
+ }
43
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Shared validation helpers for attribute-based rule constructors.
3
+ */
4
+ export type LiteralValue = string | number | boolean;
5
+ export type CompareOp = "lt" | "le" | "gt" | "ge";
6
+ export declare const COMPARE_OPS: readonly CompareOp[];
7
+ /**
8
+ * Validates that a config field used as an attribute name is a non-empty string
9
+ * that does not contain the `:` separator character used in derived `ruleType`
10
+ * strings. Allowing `:` would let distinct configs collide on the same
11
+ * `ruleType` (e.g. `(a="x:y", b="z")` and `(a="x", b="y:z")` both produce
12
+ * `attr_pair_equal:x:y:z`), which the evaluator would silently OR together
13
+ * and weaken authorization.
14
+ * @param className - The rule class name, used in error messages.
15
+ * @param fieldName - The config field name ("a" or "b"), used in error messages.
16
+ * @param value - The raw value to validate.
17
+ * @returns The validated non-empty string.
18
+ * @throws {Error} If value is not a non-empty string, or contains `:`.
19
+ */
20
+ export declare function requireAttrName(className: string, fieldName: "a" | "b", value: unknown): string;
21
+ /**
22
+ * Validates that a config field used as a literal comparison value is a
23
+ * string, number, or boolean (i.e. a LiteralValue). NaN is rejected because
24
+ * its comparison semantics (`NaN !== NaN` is always true, `NaN === NaN` is
25
+ * always false) would silently invert Equal/NotEqual rules — a NotEqual(v=NaN)
26
+ * would always pass against any numeric attribute, weakening authorization.
27
+ * @param className - The rule class name, used in error messages.
28
+ * @param fieldName - The config field name ("v"), used in error messages.
29
+ * @param value - The raw value to validate.
30
+ * @returns The validated LiteralValue.
31
+ * @throws {Error} If value is null, undefined, of any other type, or NaN.
32
+ */
33
+ export declare function requireLiteralValue(className: string, fieldName: "v", value: unknown): LiteralValue;
34
+ /**
35
+ * Validates a numeric comparison value. Rejects NaN; accepts Infinity/-Infinity.
36
+ * @param className - The rule class name, used in error messages.
37
+ * @param fieldName - The config field name ("v"), used in error messages.
38
+ * @param value - The raw value to validate.
39
+ * @returns The validated number.
40
+ * @throws {Error} If value is not a number, or if value is NaN.
41
+ */
42
+ export declare function requireNumber(className: string, fieldName: "v", value: unknown): number;
43
+ /**
44
+ * Validates that a value is a non-empty, homogeneous array of LiteralValues
45
+ * (no null/undefined elements, no NaN elements, all elements the same typeof).
46
+ * @param className - The rule class name, used in error messages.
47
+ * @param value - The raw value to validate.
48
+ * @returns The validated LiteralValue array.
49
+ * @throws {Error} If not an array, empty, contains invalid elements, has mixed types, or contains NaN.
50
+ */
51
+ export declare function requireHomogeneousLiteralArray(className: string, value: unknown): LiteralValue[];
52
+ /**
53
+ * Validates that a value is one of the allowed CompareOp strings.
54
+ * @param className - The rule class name, used in error messages.
55
+ * @param value - The raw value to validate.
56
+ * @returns The validated CompareOp.
57
+ * @throws {Error} If value is not a string or not one of the allowed operators.
58
+ */
59
+ export declare function requireCompareOp(className: string, value: unknown): CompareOp;
60
+ /**
61
+ * Validates an optional group string. Returns undefined when value is undefined;
62
+ * throws when value is a non-string or an empty string; otherwise returns the
63
+ * non-empty string.
64
+ * @param className - The rule class name, used in error messages.
65
+ * @param value - The raw value to validate.
66
+ * @returns The validated non-empty string, or undefined.
67
+ * @throws {Error} If value is a non-string or an empty string.
68
+ */
69
+ export declare function requireOptionalGroup(className: string, value: unknown): string | undefined;
70
+ /**
71
+ * Computes a stable cache/dedup key for an array of LiteralValues.
72
+ * Format: `{type}:{count}:{hashPrefix}` — SHA-256 over a canonical serialization
73
+ * of `values`. The canonical form first deduplicates `values` (to mirror the
74
+ * Set-based semantics of AttrLiteralIn / AttrLiteralNotIn — duplicates do not
75
+ * change the rule's behavior, so they must not change its `ruleType`), then
76
+ * applies `JSON.stringify(String(v))` to each remaining element before sorting
77
+ * and joining with `,`. The per-element quoting prevents separator collisions
78
+ * across different arrays (e.g. `["a,b", "c"]` vs `["a", "b,c"]`).
79
+ * The `{count}` segment reflects the post-dedup element count.
80
+ * Caller must guarantee values is a non-empty homogeneous LiteralValue[].
81
+ */
82
+ export declare function computeValuesKey(values: LiteralValue[]): string;
83
+ /**
84
+ * Applies a numeric comparison operator between left and right.
85
+ */
86
+ export declare function applyCompare<T extends number>(op: CompareOp, left: T, right: T): boolean;
87
+ //# sourceMappingURL=_sharedValidation.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_sharedValidation.d.mts","sourceRoot":"","sources":["../../src/rules/_sharedValidation.mts"],"names":[],"mappings":"AAEA;;GAEG;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAarD,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,EAA6B,CAAC;AAE1E;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,GAAG,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAe/F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,GAAG,EACd,KAAK,EAAE,OAAO,GACZ,YAAY,CAad;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAQvF;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,YAAY,EAAE,CAkChG;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS,CAU7E;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAe1F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAS/D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAWxF"}