@astram/guard 0.36.0 → 0.39.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 (48) hide show
  1. package/dist/auth/auth.controller.d.ts.map +1 -1
  2. package/dist/auth/auth.controller.js +5 -1
  3. package/dist/auth/dto.d.ts +2 -0
  4. package/dist/auth/dto.d.ts.map +1 -1
  5. package/dist/authz/list-scope-sql.d.ts +21 -0
  6. package/dist/authz/list-scope-sql.d.ts.map +1 -1
  7. package/dist/authz/list-scope-sql.js +45 -2
  8. package/dist/authz/mariadb-list-scope-adapter.d.ts.map +1 -1
  9. package/dist/authz/mariadb-list-scope-adapter.js +10 -25
  10. package/dist/authz/mariadb-policy-store.d.ts +45 -7
  11. package/dist/authz/mariadb-policy-store.d.ts.map +1 -1
  12. package/dist/authz/mariadb-policy-store.js +112 -13
  13. package/dist/authz/mariadb-record-rule-adapter.d.ts +19 -1
  14. package/dist/authz/mariadb-record-rule-adapter.d.ts.map +1 -1
  15. package/dist/authz/mariadb-record-rule-adapter.js +65 -14
  16. package/dist/authz/rule-subject.d.ts +32 -0
  17. package/dist/authz/rule-subject.d.ts.map +1 -0
  18. package/dist/authz/rule-subject.js +71 -0
  19. package/dist/authz/viewer-departments.d.ts +14 -0
  20. package/dist/authz/viewer-departments.d.ts.map +1 -0
  21. package/dist/authz/viewer-departments.js +61 -0
  22. package/dist/authz/wire-record-authorization.d.ts.map +1 -1
  23. package/dist/authz/wire-record-authorization.js +25 -2
  24. package/dist/completeness/catalog-reconciler.d.ts +10 -1
  25. package/dist/completeness/catalog-reconciler.d.ts.map +1 -1
  26. package/dist/completeness/catalog-reconciler.js +23 -4
  27. package/dist/completeness/ports/catalog-store.d.ts +19 -2
  28. package/dist/completeness/ports/catalog-store.d.ts.map +1 -1
  29. package/dist/identity/auth-facts.controller.d.ts.map +1 -1
  30. package/dist/identity/auth-facts.controller.js +5 -1
  31. package/dist/identity/identity-actions.d.ts +8 -0
  32. package/dist/identity/identity-actions.d.ts.map +1 -1
  33. package/dist/identity/identity-actions.js +8 -1
  34. package/dist/identity/module-registry.bridge.d.ts +16 -0
  35. package/dist/identity/module-registry.bridge.d.ts.map +1 -1
  36. package/dist/identity/module-registry.bridge.js +45 -0
  37. package/dist/identity/permission-facts.adapter.d.ts +41 -1
  38. package/dist/identity/permission-facts.adapter.d.ts.map +1 -1
  39. package/dist/identity/permission-facts.adapter.js +98 -1
  40. package/dist/index.d.ts +8 -6
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +21 -6
  43. package/dist/module/shield-tokens.d.ts +27 -0
  44. package/dist/module/shield-tokens.d.ts.map +1 -1
  45. package/dist/module/shield-tokens.js +8 -1
  46. package/migrations/1710000000141-AddRecordRuleSubjectRoles.cjs +95 -0
  47. package/migrations/1710000000143-AddPermissionGroup.cjs +41 -0
  48. package/package.json +5 -5
@@ -39,7 +39,9 @@
39
39
  * 14-operator {@link import('@astram/core').PolicyOperator} model (unified with
40
40
  * the guided policy builder, Task 0.2): `eq/ne` (dual-accept legacy
41
41
  * `equals`/`not_equals`), `in/not_in`, `gt/lt/gte/lte`, `contains/not_contains`,
42
- * `is_null/is_not_null`, `is_owner/is_not_owner`. An unknown operator makes the
42
+ * `is_null/is_not_null`, `is_owner/is_not_owner`, plus the principal-relative
43
+ * `in_my_departments/not_in_my_departments` (department-scoped policies: the viewer's
44
+ * department codes, read lazily once per evaluate). An unknown operator makes the
43
45
  * rule NOT match (fail-closed, never a spurious allow) — see `conditionHolds`
44
46
  * below for the exact per-operator semantics and the documented edge-case choices.
45
47
  */
@@ -47,18 +49,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
47
49
  exports.MariaDbRecordPermissionRuleAdapter = exports.SHIELD_RECORD_RULE_PORT = void 0;
48
50
  const core_1 = require("@astram/core");
49
51
  const framework_schema_names_js_1 = require("../config/framework-schema-names.js");
52
+ const rule_subject_js_1 = require("./rule-subject.js");
53
+ const viewer_departments_js_1 = require("./viewer-departments.js");
50
54
  /** The DI token the adapter is bound under (parity with the session store token). */
51
55
  exports.SHIELD_RECORD_RULE_PORT = Symbol('SHIELD_RECORD_RULE_PORT');
52
- /** Whether the rule's subject matches this principal (role membership / everyone). */
53
- function subjectMatches(row, input) {
54
- const kind = row.rpr_subject_kind;
55
- if (kind === 'everyone')
56
- return true;
57
- if (kind === 'role') {
58
- return (row.rpr_subject_value !== null && input.principal.roleIds.includes(row.rpr_subject_value));
59
- }
60
- // Unknown subject kind → does NOT match (fail-closed).
61
- return false;
56
+ /** The department operators (department-scoped policies, spec §5 C). */
57
+ const DEPARTMENT_OPERATORS = new Set([
58
+ 'in_my_departments',
59
+ 'not_in_my_departments',
60
+ ]);
61
+ /**
62
+ * `in_my_departments`: the attribute is a non-empty string AND is (exactly, `===`) one of the
63
+ * viewer's department codes `D`. `not_in_my_departments` is its plain negation, so it holds on
64
+ * an absent / null / empty attribute and on every row when `D` is empty (deny-only, D2).
65
+ */
66
+ function inDepartments(actual, departments) {
67
+ return typeof actual === 'string' && actual !== '' && departments.includes(actual);
62
68
  }
63
69
  /** Resolve a rule value token against the request (e.g. `$actor.id`) or use the literal. */
64
70
  function resolveValue(raw, input) {
@@ -140,7 +146,7 @@ function orderedCompare(actual, expected) {
140
146
  * → does NOT hold for either (fail-closed — no owner to compare, and an
141
147
  * empty attribute must never "match" an empty `principal.id`).
142
148
  */
143
- function conditionHolds(row, input) {
149
+ function conditionHolds(row, input, departments) {
144
150
  if (row.rpr_field === null)
145
151
  return true; // unconditional
146
152
  const actual = fieldValue(row.rpr_field, input);
@@ -208,6 +214,15 @@ function conditionHolds(row, input) {
208
214
  // absent OR empty-string → does NOT hold (fail-closed; same hardening,
209
215
  // mirrored for the negative ownership operator).
210
216
  return isPresent(actual) && actual !== '' && actual !== input.principal.id;
217
+ case 'in_my_departments':
218
+ // `departments` is loaded by `evaluate` before any group with a department operator is
219
+ // evaluated; `null` here would be a wiring bug → the condition does not hold (and for
220
+ // the negative operator see below).
221
+ return departments !== null && inDepartments(actual, departments);
222
+ case 'not_in_my_departments':
223
+ // NOT `in_my_departments` (deny-only, D2). An unloaded set (`null`, a wiring bug) is
224
+ // treated as the empty set: the condition holds, so a deny applies (fail closed).
225
+ return departments === null || !inDepartments(actual, departments);
211
226
  default:
212
227
  return false; // unknown operator → fail-closed (rule does not apply)
213
228
  }
@@ -219,11 +234,36 @@ function conditionHolds(row, input) {
219
234
  class MariaDbRecordPermissionRuleAdapter {
220
235
  db;
221
236
  schema;
237
+ appSchema;
238
+ now;
222
239
  constructor(db, opts = {}) {
223
240
  this.db = db;
224
241
  // The `record_permission_rule` database: `opts.schema` (checked), else the resolved authz
225
242
  // name (configurable-framework-db), fixed at construction.
226
243
  this.schema = (0, framework_schema_names_js_1.authzSchemaAtConstruction)(opts.schema);
244
+ this.appSchema =
245
+ opts.appSchema !== undefined
246
+ ? (0, core_1.assertSchemaName)(opts.appSchema, 'opts.appSchema')
247
+ : (0, core_1.resolveFrameworkSchemas)(process.env).app;
248
+ this.now = opts.now ?? Date.now;
249
+ }
250
+ /**
251
+ * The viewer department set `D` for this evaluation (spec §5 C, D3):
252
+ * - root and a record reached outside the principal's subtree (cross-tenant grant) ⇒ empty;
253
+ * - otherwise the codes of the principal's in-effect postings in `principal.tenantId`.
254
+ * A reader failure throws {@link AuthorizationUnavailableError} (fail closed).
255
+ */
256
+ async departmentsFor(input) {
257
+ const { principal, resource } = input;
258
+ if (principal.isRoot)
259
+ return [];
260
+ const recordTenant = resource.tenantId;
261
+ if (recordTenant !== undefined &&
262
+ recordTenant !== null &&
263
+ !principal.scopeSubtreeNodeIds.includes(recordTenant)) {
264
+ return [];
265
+ }
266
+ return (0, viewer_departments_js_1.readViewerDepartmentCodes)(this.db, this.appSchema, principal.id, principal.tenantId, this.now());
227
267
  }
228
268
  async evaluate(input) {
229
269
  // tenant scoping: match rows for the resource's tenant OR the global/system baseline
@@ -231,7 +271,7 @@ class MariaDbRecordPermissionRuleAdapter {
231
271
  const tenantId = input.resource.tenantId ?? input.principal.tenantId;
232
272
  let rows;
233
273
  try {
234
- rows = (await this.db.query(`SELECT rpr_policy_uuid, rpr_effect, rpr_subject_kind, rpr_subject_value, rpr_field, rpr_operator, rpr_value
274
+ rows = (await this.db.query(`SELECT rpr_policy_uuid, rpr_effect, rpr_subject_kind, rpr_subject_value, rpr_subject_role_uuids, rpr_field, rpr_operator, rpr_value
235
275
  FROM \`${this.schema}\`.\`record_permission_rule\`
236
276
  WHERE rpr_type_key = ?
237
277
  AND (rpr_tenant_uuid = ? OR rpr_tenant_uuid IS NULL)
@@ -266,6 +306,10 @@ class MariaDbRecordPermissionRuleAdapter {
266
306
  }
267
307
  let allow = false;
268
308
  let explicitDeny = false;
309
+ // The viewer department set, read LAZILY: at most once per evaluate, and only when a
310
+ // subject-matching group uses a department operator (a request without such a policy
311
+ // pays no extra query — spec §5 B, §12 case 11).
312
+ let departments = null;
269
313
  for (const groupRows of groups.values()) {
270
314
  const head = groupRows[0];
271
315
  if (head === undefined)
@@ -274,7 +318,14 @@ class MariaDbRecordPermissionRuleAdapter {
274
318
  // Its effect is consistent across rows (the store writes one effect per policy);
275
319
  // we take the group's effect from its first row and ignore any anomalous mix
276
320
  // fail-closed (a non-'allow'/'deny' effect contributes nothing).
277
- const applies = groupRows.every((row) => subjectMatches(row, input) && conditionHolds(row, input));
321
+ if (!groupRows.every((row) => (0, rule_subject_js_1.subjectMatches)(row, input.principal.roleIds)))
322
+ continue;
323
+ if (departments === null &&
324
+ groupRows.some((row) => row.rpr_field !== null && DEPARTMENT_OPERATORS.has(row.rpr_operator ?? ''))) {
325
+ departments = await this.departmentsFor(input); // throws on outage (fail closed)
326
+ }
327
+ const set = departments;
328
+ const applies = groupRows.every((row) => conditionHolds(row, input, set));
278
329
  if (!applies)
279
330
  continue;
280
331
  const effect = head.rpr_effect;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * One subject matcher for `record_permission_rule` rows, shared by the single-record adapter
3
+ * (`decide()` / get) and the list-scope adapter (list / aggregate) so the two paths can never
4
+ * disagree on who a rule applies to (department-scoped policies, spec §5 C/D, D4; Shield #8).
5
+ *
6
+ * Kinds (fixed list, spec §10):
7
+ * - `everyone` — every principal (the pre-existing default);
8
+ * - `role` — LEGACY single-role row: `rpr_subject_value` is one role uuid;
9
+ * - `roles` — the principal holds at least one role of `rpr_subject_role_uuids`;
10
+ * - `except_roles` — the principal holds none of them.
11
+ *
12
+ * FAIL CLOSED (Shield #1): an unknown kind, or a `roles` / `except_roles` row whose JSON is
13
+ * malformed, empty, not an array or holds a non-string / empty entry, never matches. For an
14
+ * `except_roles` deny this loses the deny for that group; that is reachable only by a direct DB
15
+ * write (the store never writes it) and is pinned by a unit test (spec §13).
16
+ */
17
+ /** The subject columns of a rule row. The JSON column may arrive as a string or parsed. */
18
+ export interface RuleSubjectColumns {
19
+ readonly rpr_subject_kind: string;
20
+ readonly rpr_subject_value: string | null;
21
+ readonly rpr_subject_role_uuids?: unknown;
22
+ }
23
+ /**
24
+ * The role ids of a `roles` / `except_roles` row, or `null` when the stored value is not a
25
+ * non-empty array of non-empty strings. The `mariadb` driver returns a JSON column either as
26
+ * its text or as the parsed value (depending on server type info / `autoJsonMap`), so both are
27
+ * accepted.
28
+ */
29
+ export declare function parseSubjectRoleIds(raw: unknown): readonly string[] | null;
30
+ /** Whether the rule's subject applies to a principal holding `roleIds`. */
31
+ export declare function subjectMatches(row: RuleSubjectColumns, roleIds: readonly string[]): boolean;
32
+ //# sourceMappingURL=rule-subject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-subject.d.ts","sourceRoot":"","sources":["../../src/authz/rule-subject.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,2FAA2F;AAC3F,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI,CAoB1E;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAiB3F"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * One subject matcher for `record_permission_rule` rows, shared by the single-record adapter
4
+ * (`decide()` / get) and the list-scope adapter (list / aggregate) so the two paths can never
5
+ * disagree on who a rule applies to (department-scoped policies, spec §5 C/D, D4; Shield #8).
6
+ *
7
+ * Kinds (fixed list, spec §10):
8
+ * - `everyone` — every principal (the pre-existing default);
9
+ * - `role` — LEGACY single-role row: `rpr_subject_value` is one role uuid;
10
+ * - `roles` — the principal holds at least one role of `rpr_subject_role_uuids`;
11
+ * - `except_roles` — the principal holds none of them.
12
+ *
13
+ * FAIL CLOSED (Shield #1): an unknown kind, or a `roles` / `except_roles` row whose JSON is
14
+ * malformed, empty, not an array or holds a non-string / empty entry, never matches. For an
15
+ * `except_roles` deny this loses the deny for that group; that is reachable only by a direct DB
16
+ * write (the store never writes it) and is pinned by a unit test (spec §13).
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.parseSubjectRoleIds = parseSubjectRoleIds;
20
+ exports.subjectMatches = subjectMatches;
21
+ /**
22
+ * The role ids of a `roles` / `except_roles` row, or `null` when the stored value is not a
23
+ * non-empty array of non-empty strings. The `mariadb` driver returns a JSON column either as
24
+ * its text or as the parsed value (depending on server type info / `autoJsonMap`), so both are
25
+ * accepted.
26
+ */
27
+ function parseSubjectRoleIds(raw) {
28
+ let value = raw;
29
+ if (typeof value === 'string') {
30
+ try {
31
+ value = JSON.parse(value);
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ }
37
+ else if (value instanceof Uint8Array) {
38
+ try {
39
+ value = JSON.parse(Buffer.from(value).toString('utf8'));
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ if (!Array.isArray(value) || value.length === 0)
46
+ return null;
47
+ for (const id of value) {
48
+ if (typeof id !== 'string' || id.length === 0)
49
+ return null;
50
+ }
51
+ return value;
52
+ }
53
+ /** Whether the rule's subject applies to a principal holding `roleIds`. */
54
+ function subjectMatches(row, roleIds) {
55
+ switch (row.rpr_subject_kind) {
56
+ case 'everyone':
57
+ return true;
58
+ case 'role':
59
+ return row.rpr_subject_value !== null && roleIds.includes(row.rpr_subject_value);
60
+ case 'roles': {
61
+ const listed = parseSubjectRoleIds(row.rpr_subject_role_uuids);
62
+ return listed !== null && listed.some((id) => roleIds.includes(id));
63
+ }
64
+ case 'except_roles': {
65
+ const listed = parseSubjectRoleIds(row.rpr_subject_role_uuids);
66
+ return listed !== null && !listed.some((id) => roleIds.includes(id));
67
+ }
68
+ default:
69
+ return false; // unknown subject kind → does NOT match (fail-closed)
70
+ }
71
+ }
@@ -0,0 +1,14 @@
1
+ /** Department code shape (spec §10): 1–32 of `A–Z`, `0–9`, `_`, case-sensitive. */
2
+ export declare const DEPARTMENT_CODE_PATTERN: RegExp;
3
+ /** The minimal query surface (a `mariadb` Pool or connection satisfies it). */
4
+ export interface DepartmentQueryable {
5
+ query(sql: string, params?: readonly unknown[]): Promise<unknown>;
6
+ }
7
+ /**
8
+ * Read the viewer's department codes. `appSchema` is the org (`<app>`) database name, already
9
+ * checked at construction by the caller (`schemaNamesAtConstruction`); it is the only text
10
+ * interpolated into the SQL.
11
+ * @throws AuthorizationUnavailableError when the read fails.
12
+ */
13
+ export declare function readViewerDepartmentCodes(q: DepartmentQueryable, appSchema: string, userUuid: string, companyUuid: string, nowMs: number): Promise<readonly string[]>;
14
+ //# sourceMappingURL=viewer-departments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewer-departments.d.ts","sourceRoot":"","sources":["../../src/authz/viewer-departments.ts"],"names":[],"mappings":"AAmBA,mFAAmF;AACnF,eAAO,MAAM,uBAAuB,QAAsB,CAAC;AAE3D,+EAA+E;AAC/E,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnE;AAMD;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,CAAC,EAAE,mBAAmB,EACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAiC5B"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEPARTMENT_CODE_PATTERN = void 0;
4
+ exports.readViewerDepartmentCodes = readViewerDepartmentCodes;
5
+ /**
6
+ * The viewer's department CODES for the principal-relative department operators
7
+ * (`in_my_departments` / `not_in_my_departments`; department-scoped policies, spec §5 B, D1, D3).
8
+ *
9
+ * The set is the distinct non-NULL `d_code` of the departments on the user's IN-EFFECT postings
10
+ * of their ACTIVE membership in `companyUuid` (the principal's active company), with the user
11
+ * `active` — the same membership/posting predicate as `readRoleIdsForTenant` in
12
+ * `identity/permission-facts.adapter.ts`, so roles and departments come from the same postings.
13
+ *
14
+ * ── Read lazily, at gate 6 (which already reads MariaDB), and only when a subject-matching rule
15
+ * group uses a department operator; the session hot path is untouched (Shield #12).
16
+ * ── FAIL CLOSED: a query failure THROWS {@link AuthorizationUnavailableError} (503), never an
17
+ * empty set that could read as "no departments" and never a widened list. A department
18
+ * without a code contributes nothing; only codes matching {@link DEPARTMENT_CODE_PATTERN}
19
+ * are returned (defence against a direct DB write). Every value is bound (`?`).
20
+ * ── Root and non-user principals (service accounts) have no membership: the set is empty.
21
+ */
22
+ const core_1 = require("@astram/core");
23
+ /** Department code shape (spec §10): 1–32 of `A–Z`, `0–9`, `_`, case-sensitive. */
24
+ exports.DEPARTMENT_CODE_PATTERN = /^[A-Z0-9_]{1,32}$/;
25
+ /**
26
+ * Read the viewer's department codes. `appSchema` is the org (`<app>`) database name, already
27
+ * checked at construction by the caller (`schemaNamesAtConstruction`); it is the only text
28
+ * interpolated into the SQL.
29
+ * @throws AuthorizationUnavailableError when the read fails.
30
+ */
31
+ async function readViewerDepartmentCodes(q, appSchema, userUuid, companyUuid, nowMs) {
32
+ let rows;
33
+ try {
34
+ rows = (await q.query(`SELECT DISTINCT d.d_code AS d_code
35
+ FROM \`${appSchema}\`.\`company_membership\` cm
36
+ JOIN \`${appSchema}\`.\`users\` u ON u.u_uuid = cm.cm_user_uuid AND u.u_status = 'active'
37
+ JOIN \`${appSchema}\`.\`membership_posting\` mp ON mp.mp_membership_uuid = cm.cm_uuid
38
+ JOIN \`${appSchema}\`.\`departments\` d ON d.d_uuid = mp.mp_department_uuid
39
+ JOIN \`${appSchema}\`.\`company_departments\` cd
40
+ ON cd.cd_department_uuid = d.d_uuid AND cd.cd_company_uuid = cm.cm_company_uuid
41
+ WHERE cm.cm_user_uuid = ? AND cm.cm_company_uuid = ? AND cm.cm_is_active = 1
42
+ AND mp.mp_department_uuid IS NOT NULL
43
+ AND d.d_code IS NOT NULL
44
+ AND (mp.mp_effective_from_ms IS NULL OR mp.mp_effective_from_ms <= ?)
45
+ AND (mp.mp_effective_until_ms IS NULL OR mp.mp_effective_until_ms > ?)`, [userUuid, companyUuid, nowMs, nowMs]));
46
+ }
47
+ catch (err) {
48
+ // No department code or user id in the message (spec §11 rule 9).
49
+ throw new core_1.AuthorizationUnavailableError(`department store unavailable: ${err.message}`);
50
+ }
51
+ if (!Array.isArray(rows)) {
52
+ throw new core_1.AuthorizationUnavailableError('department store returned an unexpected result');
53
+ }
54
+ const codes = new Set();
55
+ for (const row of rows) {
56
+ const code = row?.d_code;
57
+ if (typeof code === 'string' && exports.DEPARTMENT_CODE_PATTERN.test(code))
58
+ codes.add(code);
59
+ }
60
+ return [...codes];
61
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"wire-record-authorization.d.ts","sourceRoot":"","sources":["../../src/authz/wire-record-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EACV,iBAAiB,EAEjB,cAAc,EAEd,mBAAmB,EACnB,SAAS,EAET,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAMtB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,kCAAkC,CAAC;AAO1C,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,2CAA2C,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,eAAe,EAAE,mBAAmB,CAAC;IAC9C,6FAA6F;IAC7F,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAAC;IAC1C,6GAA6G;IAC7G,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC/D;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CACzC;AAOD;;;;;GAKG;AACH;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,mBAAmB,EACzB,KAAK,EAAE,uBAAuB,GAC7B,mBAAmB,CA2BrB;AAED,6EAA6E;AAC7E,MAAM,WAAW,+BAA+B;IAC9C;;;;OA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kBAAkB,CAAC;IAC1C,6GAA6G;IAC7G,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC/D;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CACzC;AAYD;;;;;GAKG;AACH;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,mBAAmB,EACzB,KAAK,EAAE,uBAAuB,GAC7B,mBAAmB,CA2BrB;AAED,6EAA6E;AAC7E,MAAM,WAAW,+BAA+B;IAC9C;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,uBAAuB,CAAC;CACjD;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,yBAAyB,EACjC,OAAO,GAAE,+BAAoC,GAC5C,iBAAiB,CAoCnB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,KACX,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,yBAAyB,GAAG,WAAW,CAmH/E"}
@@ -12,6 +12,7 @@ const mariadb_cross_tenant_grant_adapter_js_1 = require("./mariadb-cross-tenant-
12
12
  const mariadb_list_scope_adapter_js_1 = require("./mariadb-list-scope-adapter.js");
13
13
  const operation_marker_check_js_1 = require("./operation-marker-check.js");
14
14
  const list_scope_sql_js_1 = require("./list-scope-sql.js");
15
+ const viewer_departments_js_1 = require("./viewer-departments.js");
15
16
  const session_facts_als_js_1 = require("../request-auth/session-facts-als.js");
16
17
  const framework_schema_names_js_1 = require("../config/framework-schema-names.js");
17
18
  const manifest_operation_authority_adapter_js_1 = require("./manifest-operation-authority-adapter.js");
@@ -19,6 +20,10 @@ const manifest_operation_authority_adapter_js_1 = require("./manifest-operation-
19
20
  function authzSchemaOf(inputs) {
20
21
  return (0, framework_schema_names_js_1.schemaNamesAtConstruction)(inputs.schemas).authz;
21
22
  }
23
+ /** The org (`<app>`) database the viewer-department reader joins: `inputs.schemas`, else now. */
24
+ function appSchemaOf(inputs) {
25
+ return (0, framework_schema_names_js_1.schemaNamesAtConstruction)(inputs.schemas).app;
26
+ }
22
27
  /**
23
28
  * Construct the four framework-owned record-tier adapters over the supplied pool +
24
29
  * manifest, and return the fully-wired core {@link DecisionAuthority}. Behavior-identical
@@ -74,6 +79,7 @@ function buildRecordAuthorization(inputs, options = {}) {
74
79
  ? withRedisPermissionVersion(inputs.permissionFacts, options.versionCache)
75
80
  : inputs.permissionFacts;
76
81
  const schema = authzSchemaOf(inputs);
82
+ const appSchema = appSchemaOf(inputs);
77
83
  // Delegation / trusted-operation authority over the DECLARED manifest (no DB). Empty ⇒
78
84
  // pass-through. The app supplies the entries; the framework owns the adapter. The marker check
79
85
  // also uses it (plan D-5): a principal bound to an undeclared step is denied outright.
@@ -89,7 +95,9 @@ function buildRecordAuthorization(inputs, options = {}) {
89
95
  // ── The FOUR framework-owned record-tier adapters — constructed HERE, and ONLY here.
90
96
  // Record-permit ADMIN rules over `shield_authz.record_permission_rule` (widen the
91
97
  // core-owned owner baseline, deny-wins). Empty table ⇒ owner-only (NOT a lockout).
92
- recordRule: new mariadb_record_rule_adapter_js_1.MariaDbRecordPermissionRuleAdapter(inputs.pool, { schema }),
98
+ // The department operators read the viewer's department codes from `<app>` on the same
99
+ // pool, lazily (department-scoped policies, spec §5 C).
100
+ recordRule: new mariadb_record_rule_adapter_js_1.MariaDbRecordPermissionRuleAdapter(inputs.pool, { schema, appSchema }),
93
101
  // Per-record SHARE source over `shield_authz.record_share` (widening permit, union
94
102
  // with baseline under deny-wins). No share ⇒ false (baseline still governs).
95
103
  recordShare: new mariadb_record_share_adapter_js_1.MariaDbRecordShareAdapter(inputs.pool, { schema }),
@@ -120,6 +128,7 @@ function buildRecordAuthorization(inputs, options = {}) {
120
128
  function buildListScopeFn(inputs) {
121
129
  // The authz database, resolved ONCE here (build time) and captured by the per-request fn.
122
130
  const schema = authzSchemaOf(inputs);
131
+ const appSchema = appSchemaOf(inputs);
123
132
  // Framework-constructed over `inputs.pool` — UN-overridable (not a field of the inputs).
124
133
  const listScopePort = new mariadb_list_scope_adapter_js_1.MariaDbListScopeAdapter(inputs.pool, { schema });
125
134
  // The cross-tenant grant adapter — reused HERE to resolve the OWNING tenants a grantee
@@ -183,9 +192,23 @@ function buildListScopeFn(inputs) {
183
192
  owningTenantDeny = owningPolicy.deny; // ONLY the deny — the GRANT is the permit source
184
193
  }
185
194
  }
195
+ // ── Viewer department codes (department-scoped policies, spec §5 D, D3) ───────────────
196
+ // Loaded ONLY when a group the translator will see uses a department operator (no extra
197
+ // query otherwise). Same-tenant set: the actor's in-effect postings in `actor.tenantId`,
198
+ // exactly the set decide() reads for a record in the actor's subtree. Root has no
199
+ // membership (empty set, as decide()). The owning-tenant deny branch (`owningTenantDeny`)
200
+ // is always translated with an EMPTY set by the translator itself, so it needs no read.
201
+ // A reader outage throws (fail closed).
202
+ let departmentCodes = null;
203
+ if ((0, list_scope_sql_js_1.groupsUseDepartmentOperator)(spec.policyAllow) ||
204
+ (0, list_scope_sql_js_1.groupsUseDepartmentOperator)(spec.policyDeny)) {
205
+ departmentCodes = actor.isRoot
206
+ ? []
207
+ : await (0, viewer_departments_js_1.readViewerDepartmentCodes)(inputs.pool, appSchema, actor.id, actor.tenantId, Date.now());
208
+ }
186
209
  // Translate the abstract spec → SAFE parameterized WHERE fragment. An unknown-field
187
210
  // rejection here also PROPAGATES (fail-closed).
188
- const translated = (0, list_scope_sql_js_1.translateListScope)(spec, reg, { principalId: actor.id, principalTenantId: actor.tenantId }, { owningTenantDeny, schema });
211
+ const translated = (0, list_scope_sql_js_1.translateListScope)(spec, reg, { principalId: actor.id, principalTenantId: actor.tenantId, departmentCodes }, { owningTenantDeny, schema });
189
212
  return { sql: translated.sql, params: translated.params };
190
213
  };
191
214
  }
@@ -1,6 +1,6 @@
1
1
  import type { OperationInventory, ModuleRegistry } from '@astram/core';
2
2
  import type { PermissionText } from '@astram/engine';
3
- import type { CatalogStore, ReconcileReport } from './ports/catalog-store.js';
3
+ import type { CatalogPermissionGroup, CatalogStore, ReconcileReport } from './ports/catalog-store.js';
4
4
  /** A @Classified route could not be gated (stranded or key-not-registered). Boot must
5
5
  * abort — an ungatable route may never serve traffic (ADR-0002 fail-closed). */
6
6
  export declare class CatalogGatabilityError extends Error {
@@ -23,6 +23,10 @@ export declare class CatalogReconciler {
23
23
  * a reactivation stamps `lastActivatedAt` only. First-seen fields are never sent anywhere
24
24
  * but the insert (spec §11, §13). A registered row whose text differs from `opts.text` is
25
25
  * rewritten through ONE `store.updateText` call (skipped when the store lacks it).
26
+ *
27
+ * Permission groups (SPEC §5): with `opts.groups`, an insert writes the key's group and a
28
+ * registered row whose stored group differs is queued in the same `updateText` call (listed in
29
+ * `relabelled`); without it, groups are never touched.
26
30
  */
27
31
  reconcile(registry: ModuleRegistry, store: CatalogStore, nowIso: string, opts?: ReconcileOptions): Promise<ReconcileReport>;
28
32
  }
@@ -32,5 +36,10 @@ export interface ReconcileOptions {
32
36
  readonly text?: ReadonlyMap<string, PermissionText>;
33
37
  /** The app release (`APP_RELEASE`) stamped as `firstSeenVersion` on insert; absent ⇒ null. */
34
38
  readonly release?: string | null;
39
+ /**
40
+ * Permission groups (SPEC §5): permission key → display-only group (`permissionGroupByKey`).
41
+ * A key missing from the map has no group (written as null). Absent ⇒ groups never touched.
42
+ */
43
+ readonly groups?: ReadonlyMap<string, CatalogPermissionGroup>;
35
44
  }
36
45
  //# sourceMappingURL=catalog-reconciler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"catalog-reconciler.d.ts","sourceRoot":"","sources":["../../src/completeness/catalog-reconciler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,KAAK,EAEV,YAAY,EAEZ,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC;iFACiF;AACjF,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,iBAAiB;IAC5B;;;OAGG;IACH,aAAa,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI;IAgB5E;;;;;;;;;;;OAWG;IACG,SAAS,CACb,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,gBAAgB,GACtB,OAAO,CAAC,eAAe,CAAC;CA2D5B;AAED,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,iGAAiG;IACjG,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACpD,8FAA8F;IAC9F,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC"}
1
+ {"version":3,"file":"catalog-reconciler.d.ts","sourceRoot":"","sources":["../../src/completeness/catalog-reconciler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,KAAK,EACV,sBAAsB,EAEtB,YAAY,EAEZ,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC;iFACiF;AACjF,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,iBAAiB;IAC5B;;;OAGG;IACH,aAAa,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI;IAgB5E;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CACb,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,gBAAgB,GACtB,OAAO,CAAC,eAAe,CAAC;CAmE5B;AAED,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,iGAAiG;IACjG,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACpD,8FAA8F;IAC9F,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;CAC/D"}
@@ -41,9 +41,14 @@ class CatalogReconciler {
41
41
  * a reactivation stamps `lastActivatedAt` only. First-seen fields are never sent anywhere
42
42
  * but the insert (spec §11, §13). A registered row whose text differs from `opts.text` is
43
43
  * rewritten through ONE `store.updateText` call (skipped when the store lacks it).
44
+ *
45
+ * Permission groups (SPEC §5): with `opts.groups`, an insert writes the key's group and a
46
+ * registered row whose stored group differs is queued in the same `updateText` call (listed in
47
+ * `relabelled`); without it, groups are never touched.
44
48
  */
45
49
  async reconcile(registry, store, nowIso, opts) {
46
50
  const text = opts?.text;
51
+ const groups = opts?.groups;
47
52
  const release = opts?.release ?? null;
48
53
  const stored = await store.listPermissions();
49
54
  const storedByKey = new Map(stored.map((r) => [r.permissionKey, r]));
@@ -70,6 +75,7 @@ class CatalogReconciler {
70
75
  firstSeenAt: nowIso,
71
76
  firstSeenVersion: release,
72
77
  lastActivatedAt: nowIso,
78
+ ...(groups !== undefined ? { group: groups.get(key) ?? null } : {}),
73
79
  });
74
80
  if (inserted)
75
81
  added.push(key);
@@ -78,12 +84,18 @@ class CatalogReconciler {
78
84
  if (existing.status === 'orphaned')
79
85
  reactivated.push(key);
80
86
  const t = text?.get(key);
81
- if (t && textDiffers(existing, t)) {
87
+ const textChanged = t !== undefined && textDiffers(existing, t);
88
+ // Permission groups (SPEC §5): only with `opts.groups`; a key missing from it has no group.
89
+ const codeGroup = groups !== undefined ? (groups.get(key) ?? null) : undefined;
90
+ const groupChanged = codeGroup !== undefined && groupDiffers(existing.group, codeGroup);
91
+ if (textChanged || groupChanged) {
92
+ const base = textChanged ? t : existing;
82
93
  textUpdates.push({
83
94
  permissionKey: key,
84
- label: t.label,
85
- description: t.description,
86
- caution: t.caution,
95
+ label: base.label,
96
+ description: base.description ?? null,
97
+ caution: base.caution ?? null,
98
+ ...(codeGroup !== undefined ? { group: codeGroup } : {}),
87
99
  });
88
100
  }
89
101
  }
@@ -104,6 +116,13 @@ class CatalogReconciler {
104
116
  }
105
117
  }
106
118
  exports.CatalogReconciler = CatalogReconciler;
119
+ /** Stored vs code group; an absent stored group counts as null. */
120
+ function groupDiffers(stored, code) {
121
+ const s = stored ?? null;
122
+ if (s === null || code === null)
123
+ return s !== code;
124
+ return s.key !== code.key || s.label !== code.label || s.order !== code.order;
125
+ }
107
126
  /** Stored vs code text, with absent/undefined normalised to null. */
108
127
  function textDiffers(row, t) {
109
128
  return (row.label !== t.label ||
@@ -28,13 +28,29 @@ export interface CatalogPermissionRow {
28
28
  readonly firstSeenVersion?: string | null;
29
29
  /** When the key last became active (insert or orphaned → active), ISO. */
30
30
  readonly lastActivatedAt?: string | null;
31
+ /**
32
+ * Permission groups (SPEC §5): the display-only group of the key's type, `null` = none.
33
+ * OPTIONAL and additive; never read by grants, wildcards or decide().
34
+ */
35
+ readonly group?: CatalogPermissionGroup | null;
36
+ }
37
+ /** A stored permission group: key, label and the effective sort order. */
38
+ export interface CatalogPermissionGroup {
39
+ readonly key: string;
40
+ readonly label: string;
41
+ readonly order: number;
31
42
  }
32
- /** One text rewrite the reconciler asks for (code text replaces stored text, G-027). */
43
+ /**
44
+ * One text rewrite the reconciler asks for (code text replaces stored text, G-027). With
45
+ * `group` present (permission groups), the store also writes the group (`null` clears it);
46
+ * absent ⇒ the stored group is left alone.
47
+ */
33
48
  export interface CatalogTextUpdate {
34
49
  readonly permissionKey: string;
35
50
  readonly label: string;
36
51
  readonly description: string | null;
37
52
  readonly caution: string | null;
53
+ readonly group?: CatalogPermissionGroup | null;
38
54
  }
39
55
  /** The result of one mutating reconcile pass — surfaced via /health/catalog + logged. */
40
56
  export interface ReconcileReport {
@@ -61,7 +77,8 @@ export interface CatalogStore {
61
77
  markActive(keys: readonly string[], nowIso?: string): Promise<void>;
62
78
  /**
63
79
  * OPTIONAL (G-027): rewrite label/description/caution of existing rows to the code's text.
64
- * Writes only those three fields. A store without it still reconciles (no relabelling).
80
+ * Writes only those three fields, plus the group when the row carries `group`. A store
81
+ * without it still reconciles (no relabelling).
65
82
  */
66
83
  updateText?(rows: readonly CatalogTextUpdate[]): Promise<void>;
67
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"catalog-store.d.ts","sourceRoot":"","sources":["../../../src/completeness/ports/catalog-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;IACvC,iEAAiE;IACjE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAA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oot":"","sources":["../../src/identity/auth-facts.controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAGlF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAiB,KAAK,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,6BAA6B,EACnC,MAAM,+BAA+B,CAAC;AAEvC,+FAA+F;AAC/F,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAC;CAC/C;AAED,qBACa,mBAAmB;IAI5B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAG5B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAItB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAPf,WAAW,EAAE,kBAAkB,GAAG,SAAS,EAG3C,KAAK,EAAE,6BAA6B,GAAG,SAAS,EAIhD,cAAc,CAAC,GAAE,qBAAqB,GAAG,IAAI,aAAA;IAGhE;;;;;OAKG;IAGG,YAAY,CACU,aAAa,CAAC,EAAE,MAAM,GAC/C,OAAO,CAAC,kBAAkB,GAAG,4BAA4B,CAAC;IA8B7D;;;;;OAKG;IAGG,qBAAqB,CACC,aAAa,CAAC,EAAE,MAAM,GAC/C,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,UAAU,EAAE,wBAAwB,CAAA;KAAE,CAAC;IA0B1E,oGAAoG;YACtF,sBAAsB;CAerC"}
1
+ {"version":3,"file":"auth-facts.controller.d.ts","sourceRoot":"","sources":["../../src/identity/auth-facts.controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAGlF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAiB,KAAK,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,6BAA6B,EACnC,MAAM,+BAA+B,CAAC;AAEvC,+FAA+F;AAC/F,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAC;CAC/C;AAED,qBACa,mBAAmB;IAI5B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAG5B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAItB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAPf,WAAW,EAAE,kBAAkB,GAAG,SAAS,EAG3C,KAAK,EAAE,6BAA6B,GAAG,SAAS,EAIhD,cAAc,CAAC,GAAE,qBAAqB,GAAG,IAAI,aAAA;IAGhE;;;;;OAKG;IAGG,YAAY,CACU,aAAa,CAAC,EAAE,MAAM,GAC/C,OAAO,CAAC,kBAAkB,GAAG,4BAA4B,CAAC;IAkC7D;;;;;OAKG;IAGG,qBAAqB,CACC,aAAa,CAAC,EAAE,MAAM,GAC/C,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,UAAU,EAAE,wBAAwB,CAAA;KAAE,CAAC;IA0B1E,oGAAoG;YACtF,sBAAsB;CAerC"}
@@ -64,7 +64,11 @@ let AuthFactsController = class AuthFactsController {
64
64
  throw new common_1.HttpException({ error: 'authorization_unavailable' }, common_1.HttpStatus.SERVICE_UNAVAILABLE);
65
65
  }
66
66
  try {
67
- return await this.facts.projectFor(principal.id, principal.tenantId, principal.isRoot);
67
+ // Department scope fact: the session's kind, from the bound session only, never the
68
+ // request (the node set is the active company, `principal.tenantId`).
69
+ return await this.facts.projectFor(principal.id, principal.tenantId, principal.isRoot, {
70
+ kind: principal.kind,
71
+ });
68
72
  }
69
73
  catch (err) {
70
74
  if (err instanceof permission_facts_adapter_js_1.AuthorizationUnavailableError) {
@@ -41,6 +41,14 @@ export type ServiceAccountAction = (typeof SERVICE_ACCOUNT_ACTIONS)[number];
41
41
  */
42
42
  export declare const AGENT_ACTIONS: readonly ["chat", "propose", "restricted_data", "client_data_approve"];
43
43
  export type AgentAction = (typeof AGENT_ACTIONS)[number];
44
+ /**
45
+ * `agent_audit`'s action vocabulary (agent-activity-audit SPEC v1 §5, §10): `read` only, the key
46
+ * `identity:agent_audit:read` that gates the tenant admin's read of the assistant's task and
47
+ * action records (`GET /agent/audit/…`). A separate authority-only type on purpose: the key is
48
+ * NOT covered by `identity:agent:*` (supervisor decision (a)).
49
+ */
50
+ export declare const AGENT_AUDIT_ACTIONS: readonly ["read"];
51
+ export type AgentAuditAction = (typeof AGENT_AUDIT_ACTIONS)[number];
44
52
  /**
45
53
  * The per-tenant agent modes stored in `agent_tenant_setting.ats_mode` (agent-read-capabilities
46
54
  * SPEC §5 H, §11 D-3; model-provider-client-data SPEC v7 §4 B). `off` is the default when no row
@@ -1 +1 @@
1
- {"version":3,"file":"identity-actions.d.ts","sourceRoot":"","sources":["../../src/identity/identity-actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,eAAO,MAAM,UAAU,aAAa,CAAC;AACrC,eAAO,MAAM,gBAAgB,iDAAkD,CAAC;AAChF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,wCAAyC,CAAC;AACjF,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjF;;;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