@owlmeans/iam 0.1.18-rc.2 → 0.1.18-rc.21

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 (48) hide show
  1. package/README.md +2 -2
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/iam/SKILL.md +193 -56
  4. package/build/consts.d.ts +91 -0
  5. package/build/consts.d.ts.map +1 -1
  6. package/build/consts.js +97 -0
  7. package/build/consts.js.map +1 -1
  8. package/build/errors.d.ts +13 -0
  9. package/build/errors.d.ts.map +1 -1
  10. package/build/errors.js +17 -0
  11. package/build/errors.js.map +1 -1
  12. package/build/gate/index.d.ts +4 -0
  13. package/build/gate/index.d.ts.map +1 -0
  14. package/build/gate/index.js +4 -0
  15. package/build/gate/index.js.map +1 -0
  16. package/build/gate/param.d.ts +31 -0
  17. package/build/gate/param.d.ts.map +1 -0
  18. package/build/gate/param.js +99 -0
  19. package/build/gate/param.js.map +1 -0
  20. package/build/gate/resolve.d.ts +10 -0
  21. package/build/gate/resolve.d.ts.map +1 -0
  22. package/build/gate/resolve.js +93 -0
  23. package/build/gate/resolve.js.map +1 -0
  24. package/build/gate/validate.d.ts +15 -0
  25. package/build/gate/validate.d.ts.map +1 -0
  26. package/build/gate/validate.js +107 -0
  27. package/build/gate/validate.js.map +1 -0
  28. package/build/index.d.ts +2 -0
  29. package/build/index.d.ts.map +1 -1
  30. package/build/index.js +2 -0
  31. package/build/index.js.map +1 -1
  32. package/build/permission.d.ts +21 -0
  33. package/build/permission.d.ts.map +1 -0
  34. package/build/permission.js +39 -0
  35. package/build/permission.js.map +1 -0
  36. package/build/types.d.ts +251 -6
  37. package/build/types.d.ts.map +1 -1
  38. package/package.json +7 -6
  39. package/src/consts.ts +105 -0
  40. package/src/errors.ts +19 -0
  41. package/src/gate/index.ts +3 -0
  42. package/src/gate/param.ts +122 -0
  43. package/src/gate/resolve.ts +114 -0
  44. package/src/gate/validate.ts +132 -0
  45. package/src/index.ts +2 -0
  46. package/src/permission.ts +48 -0
  47. package/src/types.ts +283 -6
  48. package/tests/gate-param.spec.ts +234 -0
package/build/errors.js CHANGED
@@ -27,6 +27,22 @@ export class IamGrantError extends IamError {
27
27
  this.type = IamGrantError.typeName;
28
28
  }
29
29
  }
30
+ /**
31
+ * A refusal about a permission DEFINITION, as opposed to a grant.
32
+ *
33
+ * Separate from `IamGrantError`, which means a grant's subject is missing or its entity does not
34
+ * match — reusing it for a definition-level refusal is a category error the next reader has to unpick.
35
+ *
36
+ * Codes: `permission:held:<name>` (still granted to someone, under a policy that refuses),
37
+ * `permission:managed:<name>` (platform-owned, deleted only with an explicit second key).
38
+ */
39
+ export class IamPermissionError extends IamError {
40
+ static typeName = `IamPermission${ResilientError.typeName}`;
41
+ constructor(message = 'error') {
42
+ super(`permission:${message}`);
43
+ this.type = IamPermissionError.typeName;
44
+ }
45
+ }
30
46
  export class IamUnsupported extends IamError {
31
47
  static typeName = `IamUnsupported${ResilientError.typeName}`;
32
48
  constructor(message = 'error') {
@@ -45,6 +61,7 @@ ResilientError.registerErrorClass(IamError);
45
61
  ResilientError.registerErrorClass(IamClientError);
46
62
  ResilientError.registerErrorClass(IamResourceError);
47
63
  ResilientError.registerErrorClass(IamGrantError);
64
+ ResilientError.registerErrorClass(IamPermissionError);
48
65
  ResilientError.registerErrorClass(IamUnsupported);
49
66
  ResilientError.registerErrorClass(IamUserError);
50
67
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,OAAO,QAAS,SAAQ,cAAc;IACnC,MAAM,CAAU,QAAQ,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE,CAAA;IAEjE,YAAY,OAAO,GAAG,OAAO;QAC3B,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,OAAO,EAAE,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AAED,cAAc,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;AAC3C,cAAc,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAA;AACjD,cAAc,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAA;AACnD,cAAc,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;AAChD,cAAc,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAA;AACrD,cAAc,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAA;AACjD,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './param.js';
2
+ export * from './resolve.js';
3
+ export * from './validate.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gate/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './param.js';
2
+ export * from './resolve.js';
3
+ export * from './validate.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gate/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { GateParamSource } from '../consts.js';
2
+ import type { GateResourceSelector, GateParamProblem, ParsedGateParam } from '../types.js';
3
+ /**
4
+ * Read the `@…` half of a gate param.
5
+ *
6
+ * Two forms, and the difference between them is deliberate:
7
+ *
8
+ * `@enquiryId` — bare. A FLAT key, searched in `params` then `query`. It is never split on
9
+ * a dot, because a query key legally contains one and splitting it would
10
+ * change the meaning of selectors already deployed.
11
+ * `@body:order.id` — qualified. An explicit source and a nested path.
12
+ *
13
+ * The rule worth remembering: the bare form is lenient and flat, the qualified form is strict and
14
+ * nested.
15
+ */
16
+ export declare const parseGateSelector: (selector: string) => GateResourceSelector | GateParamProblem;
17
+ /**
18
+ * Split a gate param into the permission it checks and where the resource id comes from.
19
+ *
20
+ * Splits at the FIRST `@`. Everything before it is the permission name looked up in the subject's
21
+ * grants; everything after says where to read the resource id at request time. The suffix is the
22
+ * gate's syntax and nothing else's — a permission stored or granted under a name containing one is a
23
+ * key nothing ever looks up.
24
+ */
25
+ export declare const parseGateParam: (param: string) => ParsedGateParam;
26
+ /** Compose a gate param. The inverse of `parseGateParam` for every selector it accepts. */
27
+ export declare const formatGateParam: (permission: string, selector?: string | {
28
+ source?: GateParamSource;
29
+ path: string[];
30
+ }) => string;
31
+ //# sourceMappingURL=param.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"param.d.ts","sourceRoot":"","sources":["../../src/gate/param.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAChB,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAI1F;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,aAAc,MAAM,KAAG,oBAAoB,GAAG,gBA6C3E,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,UAAW,MAAM,KAAG,eAoB9C,CAAA;AAED,2FAA2F;AAC3F,eAAO,MAAM,eAAe,eACd,MAAM,aACP,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,KAC/D,MAmBF,CAAA"}
@@ -0,0 +1,99 @@
1
+ import { RESOURCE_PARAM_SEPARATOR, RESOURCE_SOURCE_SEPARATOR, RESOURCE_PATH_SEPARATOR, GateParamSource, GateParamErrorCode, DEFAULT_GATE_PARAM_SOURCES } from '../consts.js';
2
+ const SOURCES = Object.values(GateParamSource);
3
+ /**
4
+ * Read the `@…` half of a gate param.
5
+ *
6
+ * Two forms, and the difference between them is deliberate:
7
+ *
8
+ * `@enquiryId` — bare. A FLAT key, searched in `params` then `query`. It is never split on
9
+ * a dot, because a query key legally contains one and splitting it would
10
+ * change the meaning of selectors already deployed.
11
+ * `@body:order.id` — qualified. An explicit source and a nested path.
12
+ *
13
+ * The rule worth remembering: the bare form is lenient and flat, the qualified form is strict and
14
+ * nested.
15
+ */
16
+ export const parseGateSelector = (selector) => {
17
+ if (selector === '') {
18
+ return { code: GateParamErrorCode.EmptySelector, detail: 'the selector after "@" is empty' };
19
+ }
20
+ const idx = selector.indexOf(RESOURCE_SOURCE_SEPARATOR);
21
+ if (idx < 0) {
22
+ return {
23
+ selector,
24
+ path: [selector],
25
+ sources: DEFAULT_GATE_PARAM_SOURCES
26
+ };
27
+ }
28
+ const source = selector.slice(0, idx);
29
+ const rest = selector.slice(idx + 1);
30
+ if (!SOURCES.includes(source)) {
31
+ return {
32
+ code: GateParamErrorCode.UnknownSource,
33
+ detail: `"${source}" is not one of ${SOURCES.join(', ')}`
34
+ };
35
+ }
36
+ if (rest === '') {
37
+ return {
38
+ code: GateParamErrorCode.EmptySelector,
39
+ detail: `"${source}:" names no path`
40
+ };
41
+ }
42
+ const path = rest.split(RESOURCE_PATH_SEPARATOR);
43
+ if (path.some(segment => segment === '')) {
44
+ return {
45
+ code: GateParamErrorCode.EmptySegment,
46
+ detail: `"${rest}" has an empty path segment`
47
+ };
48
+ }
49
+ return {
50
+ selector,
51
+ source: source,
52
+ path,
53
+ sources: [source]
54
+ };
55
+ };
56
+ /**
57
+ * Split a gate param into the permission it checks and where the resource id comes from.
58
+ *
59
+ * Splits at the FIRST `@`. Everything before it is the permission name looked up in the subject's
60
+ * grants; everything after says where to read the resource id at request time. The suffix is the
61
+ * gate's syntax and nothing else's — a permission stored or granted under a name containing one is a
62
+ * key nothing ever looks up.
63
+ */
64
+ export const parseGateParam = (param) => {
65
+ const idx = param.indexOf(RESOURCE_PARAM_SEPARATOR);
66
+ if (idx < 0) {
67
+ return { permission: param };
68
+ }
69
+ const permission = param.slice(0, idx);
70
+ const selector = param.slice(idx + 1);
71
+ const parsed = parseGateSelector(selector);
72
+ if ('code' in parsed) {
73
+ return { permission, resourceParam: selector, error: parsed };
74
+ }
75
+ return {
76
+ permission,
77
+ // Kept for readers written against the flat form. Only meaningful when the form IS flat.
78
+ ...(parsed.source == null ? { resourceParam: selector } : {}),
79
+ resource: parsed
80
+ };
81
+ };
82
+ /** Compose a gate param. The inverse of `parseGateParam` for every selector it accepts. */
83
+ export const formatGateParam = (permission, selector) => {
84
+ if (selector == null) {
85
+ return permission;
86
+ }
87
+ if (typeof selector === 'string') {
88
+ return selector === '' ? permission : `${permission}${RESOURCE_PARAM_SEPARATOR}${selector}`;
89
+ }
90
+ if (selector.path.length < 1) {
91
+ return permission;
92
+ }
93
+ const path = selector.path.join(RESOURCE_PATH_SEPARATOR);
94
+ const tail = selector.source == null
95
+ ? path
96
+ : `${selector.source}${RESOURCE_SOURCE_SEPARATOR}${path}`;
97
+ return `${permission}${RESOURCE_PARAM_SEPARATOR}${tail}`;
98
+ };
99
+ //# sourceMappingURL=param.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"param.js","sourceRoot":"","sources":["../../src/gate/param.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EAAE,yBAAyB,EAAE,uBAAuB,EAC5E,eAAe,EAAE,kBAAkB,EAAE,0BAA0B,EAChE,MAAM,cAAc,CAAA;AAGrB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAa,CAAA;AAE1D;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAA2C,EAAE;IAC7F,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,EAAE,IAAI,EAAE,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,iCAAiC,EAAE,CAAA;IAC9F,CAAC;IAED,MAA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C,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA;IACxD,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,IAAI,IAAI;QAClC,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,yBAAyB,GAAG,IAAI,EAAE,CAAA;IAE3D,OAAO,GAAG,UAAU,GAAG,wBAAwB,GAAG,IAAI,EAAE,CAAA;AAC1D,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { GateRequestLike, GateResourceSelector, GateResourceResolution } from '../types.js';
2
+ /**
3
+ * Resolve the resource id a selector points at.
4
+ *
5
+ * Sources are tried in the selector's own order — for the bare form, route params before the query —
6
+ * and the first that yields a value wins. When none does, the reason travels back so the caller can
7
+ * tell a MISCONFIGURED gate (the request never carried that key) from a legitimately DENIED one.
8
+ */
9
+ export declare const resolveGateResource: (req: GateRequestLike, selector: GateResourceSelector) => GateResourceResolution;
10
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/gate/resolve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AA4EhG;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,QACzB,eAAe,YAAY,oBAAoB,KACnD,sBA2BF,CAAA"}
@@ -0,0 +1,93 @@
1
+ import { GateParamSource, GateResolutionFailure } from '../consts.js';
2
+ const isRecord = (value) => value != null && typeof value === 'object';
3
+ /**
4
+ * A resource id is a scalar. Anything else is refused rather than coerced.
5
+ *
6
+ * Stringifying an object would produce `"[object Object]"`, which then either matches nothing or —
7
+ * far worse — matches another record that stringified the same way.
8
+ */
9
+ const scalar = (value) => {
10
+ switch (typeof value) {
11
+ case 'string':
12
+ return value;
13
+ case 'number':
14
+ case 'boolean':
15
+ case 'bigint':
16
+ return `${value}`;
17
+ default:
18
+ return null;
19
+ }
20
+ };
21
+ const sourceOf = (req, source) => {
22
+ switch (source) {
23
+ case GateParamSource.Params: return req.params;
24
+ case GateParamSource.Query: return req.query;
25
+ case GateParamSource.Body: return req.body;
26
+ case GateParamSource.Headers: return req.headers;
27
+ case GateParamSource.Auth: return req.auth;
28
+ }
29
+ };
30
+ /**
31
+ * Walk one source for the selector's path.
32
+ *
33
+ * Headers get two adjustments they need and nothing else does: the first segment is lowercased,
34
+ * because HTTP header names are case-insensitive and every server normalises them differently; and a
35
+ * single-element array unwraps, because a repeated header arrives as an array and silently picking
36
+ * one of several values would be an authorization decision made by accident.
37
+ */
38
+ const walk = (container, path, source) => {
39
+ if (!isRecord(container)) {
40
+ return { reason: GateResolutionFailure.SourceMissing };
41
+ }
42
+ let cursor = container;
43
+ for (const [index, rawSegment] of path.entries()) {
44
+ if (!isRecord(cursor)) {
45
+ return { reason: GateResolutionFailure.NotProvided };
46
+ }
47
+ const segment = source === GateParamSource.Headers && index === 0
48
+ ? rawSegment.toLowerCase()
49
+ : rawSegment;
50
+ cursor = cursor[segment];
51
+ }
52
+ if (source === GateParamSource.Headers && Array.isArray(cursor)) {
53
+ if (cursor.length !== 1) {
54
+ return { reason: GateResolutionFailure.NotScalar };
55
+ }
56
+ cursor = cursor[0];
57
+ }
58
+ if (cursor == null) {
59
+ return { reason: GateResolutionFailure.NotProvided };
60
+ }
61
+ return { value: cursor };
62
+ };
63
+ /**
64
+ * Resolve the resource id a selector points at.
65
+ *
66
+ * Sources are tried in the selector's own order — for the bare form, route params before the query —
67
+ * and the first that yields a value wins. When none does, the reason travels back so the caller can
68
+ * tell a MISCONFIGURED gate (the request never carried that key) from a legitimately DENIED one.
69
+ */
70
+ export const resolveGateResource = (req, selector) => {
71
+ let reason = GateResolutionFailure.SourceMissing;
72
+ for (const source of selector.sources) {
73
+ const result = walk(sourceOf(req, source), selector.path, source);
74
+ if (result.reason != null) {
75
+ // A hard refusal is more informative than "keep looking" — report it rather than letting a
76
+ // later, emptier source overwrite it with a vaguer reason.
77
+ if (result.reason === GateResolutionFailure.NotScalar) {
78
+ return { reason: result.reason, from: source };
79
+ }
80
+ if (reason === GateResolutionFailure.SourceMissing) {
81
+ reason = result.reason;
82
+ }
83
+ continue;
84
+ }
85
+ const value = scalar(result.value);
86
+ if (value == null) {
87
+ return { reason: GateResolutionFailure.NotScalar, from: source };
88
+ }
89
+ return { id: value, from: source };
90
+ }
91
+ return { reason };
92
+ };
93
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/gate/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAGrE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAA;AAE5C;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE;IAC/C,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,KAAK,CAAA;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,GAAG,KAAK,EAAE,CAAA;QACnB;YACE,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,GAAoB,EAAE,MAAuB,EAAW,EAAE;IAC1E,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,CAAC,MAAM,CAAA;QAC9C,KAAK,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,KAAK,CAAA;QAC5C,KAAK,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,CAAC,IAAI,CAAA;QAC1C,KAAK,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,CAAC,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AE,CAAA;AAC1B,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,GAAoB,EAAE,QAA8B,EAC5B,EAAE;IAC1B,IAAI,MAAM,GAA0B,qBAAqB,CAAC,aAAa,CAAA;IAEvE,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAEjE,IAAI,MAAM,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YAC1B,2FAA2F;YAC3F,2DAA2D;YAC3D,IAAI,MAAM,CAAC,MAAM,KAAK,qBAAqB,CAAC,SAAS,EAAE,CAAC;gBACtD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;YAChD,CAAC;YACD,IAAI,MAAM,KAAK,qBAAqB,CAAC,aAAa,EAAE,CAAC;gBACnD,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;YACxB,CAAC;YACD,SAAQ;QACV,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAClC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,EAAE,MAAM,EAAE,qBAAqB,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;QAClE,CAAC;QAED,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACpC,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,CAAA;AACnB,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ import type { GateParamAudit, GateParamIssue } from '../types.js';
2
+ /** The `:name` segments of a route template. */
3
+ export declare const routeParamsOf: (path: string) => string[];
4
+ /**
5
+ * Check gate params against what their entrypoint declares.
6
+ *
7
+ * Reports only what is provable from the declaration itself. Anything that would need a guess is
8
+ * left alone: a check that fires on correct code stops being read.
9
+ *
10
+ * Meant to run where a mistake can still be fixed — while code is being generated, or once per alias
11
+ * as a diagnostic. It must never decide a request: with `some()` semantics across params, one
12
+ * malformed sibling must not be able to refuse a legitimately passing one.
13
+ */
14
+ export declare const validateGateParams: (params: string[], audit?: GateParamAudit) => GateParamIssue[];
15
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/gate/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAwB,MAAM,aAAa,CAAA;AAGvF,gDAAgD;AAChD,eAAO,MAAM,aAAa,SAAU,MAAM,KAAG,MAAM,EAGH,CAAA;AA0FhD;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,WAAY,MAAM,EAAE,UAAU,cAAc,KAAG,cAAc,EAsB3F,CAAA"}
@@ -0,0 +1,107 @@
1
+ import { normalizePath, SEP, PARAM } from '@owlmeans/route';
2
+ import { GateParamSource, GateParamErrorCode } from '../consts.js';
3
+ import { parseGateParam } from './param.js';
4
+ /** The `:name` segments of a route template. */
5
+ export const routeParamsOf = (path) => normalizePath(path).split(SEP)
6
+ .filter(segment => segment.startsWith(PARAM))
7
+ .map(segment => segment.slice(PARAM.length));
8
+ /**
9
+ * Whether a key can survive validation to reach the gate.
10
+ *
11
+ * The server compiles entrypoint filters with AJV's `removeAdditional`, which strips an undeclared
12
+ * key BEFORE the handler — and therefore before the gate — runs. So a selector naming a key the
13
+ * filter does not declare denies every request, with a clean build and nothing logged.
14
+ *
15
+ * The `additionalProperties === false` qualifier is what makes this check usable rather than noise:
16
+ * AJV only strips when a schema says so. An entrypoint that declares no filter for a source strips
17
+ * nothing, and reporting those would fire on nearly every endpoint and be ignored within a week.
18
+ */
19
+ const unreachable = (schema, key) => {
20
+ if (schema == null) {
21
+ return false;
22
+ }
23
+ const { properties, additionalProperties } = schema;
24
+ if (additionalProperties !== false) {
25
+ return false;
26
+ }
27
+ return properties == null || !(key in properties);
28
+ };
29
+ const filterFor = (audit, source) => {
30
+ switch (source) {
31
+ case GateParamSource.Query: return audit.filter?.query;
32
+ case GateParamSource.Body: return audit.filter?.body;
33
+ case GateParamSource.Headers: return audit.filter?.headers;
34
+ case GateParamSource.Params: return audit.filter?.params;
35
+ case GateParamSource.Auth: return undefined;
36
+ }
37
+ };
38
+ const auditSelector = (audit, selector) => {
39
+ const key = selector.path[0];
40
+ if (key == null) {
41
+ return null;
42
+ }
43
+ // The bare form searches route params first and the query second, so it is only provably wrong
44
+ // when BOTH are impossible. A declared route param settles it; otherwise fall through to the
45
+ // query check below, which only fires on an explicitly closed schema.
46
+ const routeParams = audit.routeParams
47
+ ?? (audit.routePath != null ? routeParamsOf(audit.routePath) : undefined);
48
+ if (selector.source == null) {
49
+ if (routeParams?.includes(key) === true) {
50
+ return null;
51
+ }
52
+ if (unreachable(audit.filter?.query, key) && unreachable(audit.filter?.params, key)) {
53
+ return {
54
+ code: GateParamErrorCode.UnknownRouteParam,
55
+ detail: `"${key}" is not a route param of "${audit.routePath ?? '?'}"`
56
+ + ' and is declared by neither the params nor the query filter'
57
+ };
58
+ }
59
+ return null;
60
+ }
61
+ if (selector.source === GateParamSource.Params) {
62
+ if (routeParams != null && !routeParams.includes(key) && unreachable(audit.filter?.params, key)) {
63
+ return {
64
+ code: GateParamErrorCode.UnknownRouteParam,
65
+ detail: `"${key}" is not a route param of "${audit.routePath ?? '?'}"`
66
+ };
67
+ }
68
+ return null;
69
+ }
70
+ if (unreachable(filterFor(audit, selector.source), key)) {
71
+ return {
72
+ code: GateParamErrorCode.UnreachableKey,
73
+ detail: `the ${selector.source} filter declares no "${key}" and forbids additional properties,`
74
+ + ' so it is removed by validation before the gate can read it'
75
+ };
76
+ }
77
+ return null;
78
+ };
79
+ /**
80
+ * Check gate params against what their entrypoint declares.
81
+ *
82
+ * Reports only what is provable from the declaration itself. Anything that would need a guess is
83
+ * left alone: a check that fires on correct code stops being read.
84
+ *
85
+ * Meant to run where a mistake can still be fixed — while code is being generated, or once per alias
86
+ * as a diagnostic. It must never decide a request: with `some()` semantics across params, one
87
+ * malformed sibling must not be able to refuse a legitimately passing one.
88
+ */
89
+ export const validateGateParams = (params, audit) => {
90
+ const issues = [];
91
+ for (const param of params) {
92
+ const parsed = parseGateParam(param);
93
+ if (parsed.error != null) {
94
+ issues.push({ param, code: parsed.error.code, detail: parsed.error.detail });
95
+ continue;
96
+ }
97
+ if (parsed.resource == null || audit == null) {
98
+ continue;
99
+ }
100
+ const issue = auditSelector(audit, parsed.resource);
101
+ if (issue != null) {
102
+ issues.push({ param, ...issue });
103
+ }
104
+ }
105
+ return issues;
106
+ };
107
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/gate/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,gDAAgD;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAY,EAAE,CACtD,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC;KAC3B,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;KAC5C,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;AAOhD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,GAAG,CAAC,MAA0B,EAAE,GAAW,EAAW,EAAE;IACvE,IAAI,MAAM,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AM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAgB,EAAE,KAAsB,EAAoB,EAAE;IAC/F,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QAEpC,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;YAC5E,SAAQ;QACV,CAAC;QAED,IAAI,MAAM,CAAC,QAAQ,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAC7C,SAAQ;QACV,CAAC;QAED,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;QACnD,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
package/build/index.d.ts CHANGED
@@ -2,4 +2,6 @@ export type * from './types.js';
2
2
  export * from './consts.js';
3
3
  export * from './errors.js';
4
4
  export * from './utils.js';
5
+ export * from './gate/index.js';
6
+ export * from './permission.js';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA"}
package/build/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './consts.js';
2
2
  export * from './errors.js';
3
3
  export * from './utils.js';
4
+ export * from './gate/index.js';
5
+ export * from './permission.js';
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,21 @@
1
+ import type { ParsedPermissionName } from './types.js';
2
+ /**
3
+ * Read a permission NAME.
4
+ *
5
+ * The name is `<resource>--<action>`, with TWO hyphens. One hyphen is not a separator: `enquiry-view`
6
+ * is a resource called `enquiry-view` carrying no action, and it must keep parsing that way — a name
7
+ * already granted somewhere cannot be re-interpreted without orphaning the grant.
8
+ *
9
+ * A name never carries a gate selector. `@` is the gate's syntax, and a name containing one is
10
+ * exactly the corruption this function exists to make visible, so it is reported through `problem`
11
+ * rather than quietly split.
12
+ */
13
+ export declare const parsePermissionName: (name: string) => ParsedPermissionName;
14
+ /** Compose a permission name. The inverse of `parsePermissionName`. */
15
+ export declare const composePermissionName: (parts: {
16
+ resource: string;
17
+ action?: string;
18
+ }) => string;
19
+ /** True when the value is a usable permission name — well-formed and carrying no gate selector. */
20
+ export declare const isPermissionName: (value: string) => boolean;
21
+ //# sourceMappingURL=permission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,SAAU,MAAM,KAAG,oBAsBlD,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,qBAAqB,UACzB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC3C,MAEiE,CAAA;AAEpE,mGAAmG;AACnG,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,OACU,CAAA"}
@@ -0,0 +1,39 @@
1
+ import { PERMISSION_ACTION_SEPARATOR, RESOURCE_PARAM_SEPARATOR, GateParamErrorCode } from './consts.js';
2
+ /**
3
+ * Read a permission NAME.
4
+ *
5
+ * The name is `<resource>--<action>`, with TWO hyphens. One hyphen is not a separator: `enquiry-view`
6
+ * is a resource called `enquiry-view` carrying no action, and it must keep parsing that way — a name
7
+ * already granted somewhere cannot be re-interpreted without orphaning the grant.
8
+ *
9
+ * A name never carries a gate selector. `@` is the gate's syntax, and a name containing one is
10
+ * exactly the corruption this function exists to make visible, so it is reported through `problem`
11
+ * rather than quietly split.
12
+ */
13
+ export const parsePermissionName = (name) => {
14
+ const problem = name.includes(RESOURCE_PARAM_SEPARATOR)
15
+ ? {
16
+ code: GateParamErrorCode.UnreachableKey,
17
+ detail: `"${name}" carries a gate selector; "${RESOURCE_PARAM_SEPARATOR}" is never part of a`
18
+ + ' permission name, and nothing ever looks up a name that contains one'
19
+ }
20
+ : undefined;
21
+ const idx = name.indexOf(PERMISSION_ACTION_SEPARATOR);
22
+ if (idx < 0) {
23
+ return { name, resource: name, ...(problem != null ? { problem } : {}) };
24
+ }
25
+ const action = name.slice(idx + PERMISSION_ACTION_SEPARATOR.length);
26
+ return {
27
+ name,
28
+ resource: name.slice(0, idx),
29
+ ...(action !== '' ? { action } : {}),
30
+ ...(problem != null ? { problem } : {})
31
+ };
32
+ };
33
+ /** Compose a permission name. The inverse of `parsePermissionName`. */
34
+ export const composePermissionName = (parts) => parts.action == null || parts.action === ''
35
+ ? parts.resource
36
+ : `${parts.resource}${PERMISSION_ACTION_SEPARATOR}${parts.action}`;
37
+ /** True when the value is a usable permission name — well-formed and carrying no gate selector. */
38
+ export const isPermissionName = (value) => value !== '' && !value.includes(RESOURCE_PARAM_SEPARATOR);
39
+ //# sourceMappingURL=permission.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission.js","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGvG;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAwB,EAAE;IACxE,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC;QACrD,CAAC,CAAC;YACA,IAAI,EAAE,kBAAkB,CAAC,cAAc;YACvC,MAAM,EAAE,IAAI,IAAI,+BAA+B,wBAAwB,sBAAsB;kBACzF,sEAAsE;SAC3E;QACD,CAAC,CAAC,SAAS,CAAA;IAEb,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAA;IACrD,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACZ,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;IAC1E,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,2BAA2B,CAAC,MAAM,CAAC,CAAA;IAEnE,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE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