@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
@@ -7,7 +7,7 @@
7
7
  * with no cycle. `shield.module.ts` re-exports these for the public barrel.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.FileShareError = exports.FILE_SHARE_ERROR_CODES = exports.SHIELD_FILE_SHARE = exports.SHIELD_AGENT_CLIENT_DATA_PROFILES = exports.SHIELD_AGENT_CLIENT_DATA_DISCLOSURE = exports.SHIELD_AGENT_TASK_CALLS = exports.SHIELD_PROPOSAL_READER = exports.SHIELD_PROPOSAL_PORT = exports.SHIELD_AGENT_FILE_READER = exports.SHIELD_FILE_INGEST = exports.SHIELD_OBJECT_STORE = exports.SHIELD_RECORD_AUTHORIZATION = exports.SHIELD_DECISION_AUTHORITY = void 0;
10
+ exports.FileShareError = exports.FILE_SHARE_ERROR_CODES = exports.SHIELD_FILE_SHARE = exports.SHIELD_AGENT_CLIENT_DATA_PROFILES = exports.SHIELD_AGENT_CLIENT_DATA_DISCLOSURE = exports.SHIELD_AGENT_AUDIT_LINKS = exports.SHIELD_AGENT_TASK_CALLS = exports.SHIELD_PROPOSAL_READER = exports.SHIELD_PROPOSAL_PORT = exports.SHIELD_AGENT_FILE_READER = exports.SHIELD_FILE_INGEST = exports.SHIELD_OBJECT_STORE = exports.SHIELD_RECORD_AUTHORIZATION = exports.SHIELD_DECISION_AUTHORITY = void 0;
11
11
  /**
12
12
  * The Core decision authority (`@astram/core`'s `DecisionAuthority`) — the single
13
13
  * ADR-0001 decision entry both the global enforcement guard and the engine's
@@ -66,6 +66,13 @@ exports.SHIELD_PROPOSAL_PORT = Symbol('SHIELD_PROPOSAL_PORT');
66
66
  exports.SHIELD_PROPOSAL_READER = Symbol('SHIELD_PROPOSAL_READER');
67
67
  /** Token of {@link AgentTaskCalls} (plan D-6). */
68
68
  exports.SHIELD_AGENT_TASK_CALLS = Symbol('SHIELD_AGENT_TASK_CALLS');
69
+ /**
70
+ * {@link AgentAuditLinks} (SPEC §5, §6), bound by `@astram/identity`'s `IdentityFeatureModule` in
71
+ * the framework module that binds {@link SHIELD_AGENT_FILE_READER} (request-scoped), injected by
72
+ * `@astram/agent`'s audit controller. Guard never imports identity: this token is the seam.
73
+ * Unbound without identity (the audit routes then answer 503).
74
+ */
75
+ exports.SHIELD_AGENT_AUDIT_LINKS = Symbol('SHIELD_AGENT_AUDIT_LINKS');
69
76
  /** Token of {@link AgentClientDataDisclosurePort} (provided by identity, consumed by the agent). */
70
77
  exports.SHIELD_AGENT_CLIENT_DATA_DISCLOSURE = Symbol('SHIELD_AGENT_CLIENT_DATA_DISCLOSURE');
71
78
  /** Token of {@link AgentClientDataProfiles} (SPEC v7 §5 D). */
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Framework authz migration — policy subject role sets on `<authz>.record_permission_rule`
3
+ * (department-scoped policies; spec `docs/features/department-scoped-policies/SPEC.md` v2 §4; id 141
4
+ * per `docs/migrations/RESERVATIONS.md`).
5
+ *
6
+ * Adds `rpr_subject_role_uuids JSON NULL` after `rpr_subject_value`: a JSON array of 1–16 distinct
7
+ * role uuids when `rpr_subject_kind` is `roles` or `except_roles`, NULL otherwise. Every row of one
8
+ * policy (`rpr_policy_uuid` group) carries the same kind and array. `rpr_subject_kind VARCHAR(16)`
9
+ * already fits the new kinds; no other DDL. No data change: existing rows keep NULL (their kinds
10
+ * `everyone` / legacy `role` do not read the column). No ids hard-coded.
11
+ *
12
+ * Idempotent: the column is added only when `information_schema.COLUMNS` shows it absent; a re-run
13
+ * issues no DDL.
14
+ *
15
+ * `down` refuses (throws a fixed message, changes nothing) while any row has kind `roles` or
16
+ * `except_roles`: without the column those rows would never match, so an `except_roles` deny would
17
+ * silently stop applying. Otherwise it drops the column, only when present. It never deletes rules.
18
+ *
19
+ * Database name from `ctx.schemas` (`frameworkSchemasForMigration(...).authz`), so the four-database,
20
+ * namespace and single layouts all work. Sorts after `...009` (creates `record_permission_rule`) and
21
+ * above every published id (132).
22
+ */
23
+
24
+ const { frameworkSchemasForMigration } = require('@astram/core');
25
+
26
+ const MIGRATION = '1710000000141-AddRecordRuleSubjectRoles';
27
+ const TABLE = 'record_permission_rule';
28
+ const COLUMN = 'rpr_subject_role_uuids';
29
+
30
+ const DOWN_REFUSED =
31
+ `${MIGRATION}: refusing to roll back: record_permission_rule holds policies with a role subject ` +
32
+ "(rpr_subject_kind 'roles' or 'except_roles'). Delete or re-author them first; nothing was changed.";
33
+
34
+ async function exists(query, sql, params) {
35
+ const rows = await query(sql, params);
36
+ return Array.isArray(rows) && rows.length > 0;
37
+ }
38
+
39
+ const tableExists = (query, schema) =>
40
+ exists(
41
+ query,
42
+ `SELECT 1 AS n FROM information_schema.TABLES
43
+ WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? LIMIT 1`,
44
+ [schema, TABLE],
45
+ );
46
+
47
+ const columnExists = (query, schema) =>
48
+ exists(
49
+ query,
50
+ `SELECT 1 AS n FROM information_schema.COLUMNS
51
+ WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ? LIMIT 1`,
52
+ [schema, TABLE, COLUMN],
53
+ );
54
+
55
+ const tbl = (schema) => `\`${schema}\`.\`${TABLE}\``;
56
+
57
+ async function up(ctx) {
58
+ const { query } = ctx;
59
+ const AUTHZ = frameworkSchemasForMigration(ctx, process.env).authz;
60
+
61
+ if (!(await tableExists(query, AUTHZ))) {
62
+ throw new Error(
63
+ `${MIGRATION}: ${AUTHZ}.${TABLE} does not exist; run 1710000000009-CreateRecordPermissionRule first.`,
64
+ );
65
+ }
66
+
67
+ if (!(await columnExists(query, AUTHZ))) {
68
+ await query(
69
+ `ALTER TABLE ${tbl(AUTHZ)} ADD COLUMN IF NOT EXISTS ${COLUMN} JSON NULL AFTER rpr_subject_value`,
70
+ );
71
+ }
72
+ }
73
+
74
+ async function down(ctx) {
75
+ const { query } = ctx;
76
+ const AUTHZ = frameworkSchemasForMigration(ctx, process.env).authz;
77
+
78
+ if (!(await tableExists(query, AUTHZ))) return;
79
+ if (!(await columnExists(query, AUTHZ))) return;
80
+
81
+ // Refuse before any change while a role-subject policy exists (never drop a live deny).
82
+ if (
83
+ await exists(
84
+ query,
85
+ `SELECT 1 AS n FROM ${tbl(AUTHZ)} WHERE rpr_subject_kind IN (?, ?) LIMIT 1`,
86
+ ['roles', 'except_roles'],
87
+ )
88
+ ) {
89
+ throw new Error(DOWN_REFUSED);
90
+ }
91
+
92
+ await query(`ALTER TABLE ${tbl(AUTHZ)} DROP COLUMN IF EXISTS ${COLUMN}`);
93
+ }
94
+
95
+ module.exports = { up, down };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Framework authz migration — permission groups (docs/features/permission-groups/SPEC.md §4).
3
+ *
4
+ * Adds to `permission` the display-only group of the key's object type, declared in code by
5
+ * `@ObjectType({ group })` and written by the catalog reconcile: `perm_group_key`,
6
+ * `perm_group_label` and `perm_group_order` (the effective sort order). NULL = no group. Grants,
7
+ * wildcards, bundles and decide() never read these columns.
8
+ *
9
+ * No backfill: existing rows stay NULL until the first reconcile after upgrade writes them.
10
+ * `down` drops the columns with no refusal: the data is derived from code and rewritten by the
11
+ * reconcile after a re-`up`.
12
+ *
13
+ * Idempotent: `ADD COLUMN IF NOT EXISTS` / `DROP COLUMN IF EXISTS`. Literal column names; run by
14
+ * the DDL account.
15
+ */
16
+
17
+ const { frameworkSchemasForMigration } = require('@astram/core');
18
+
19
+ const COLUMNS = [
20
+ ['perm_group_key', 'VARCHAR(32) NULL DEFAULT NULL'],
21
+ ['perm_group_label', 'VARCHAR(40) NULL DEFAULT NULL'],
22
+ ['perm_group_order', 'INT NULL DEFAULT NULL'],
23
+ ];
24
+
25
+ async function up(ctx) {
26
+ const { query } = ctx;
27
+ const SCHEMA = frameworkSchemasForMigration(ctx, process.env).authz;
28
+ for (const [name, type] of COLUMNS) {
29
+ await query(`ALTER TABLE \`${SCHEMA}\`.\`permission\` ADD COLUMN IF NOT EXISTS ${name} ${type}`);
30
+ }
31
+ }
32
+
33
+ async function down(ctx) {
34
+ const { query } = ctx;
35
+ const SCHEMA = frameworkSchemasForMigration(ctx, process.env).authz;
36
+ for (const [name] of [...COLUMNS].reverse()) {
37
+ await query(`ALTER TABLE \`${SCHEMA}\`.\`permission\` DROP COLUMN IF EXISTS ${name}`);
38
+ }
39
+ }
40
+
41
+ module.exports = { up, down };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astram/guard",
3
- "version": "0.36.0",
3
+ "version": "0.39.0",
4
4
  "license": "MIT",
5
5
  "description": "Astram framework — the enforcement guard + real-world adapters (the 'hands'). One global deny-by-default gate every request passes through (ADR-0002), classification decorators, boot-pool assertion (ADR-0018), the forRoot() registration seam, and the DB/Redis/crypto adapters that connect the sealed core to a real backend. Depends on @astram/core (ADR-0003, ADR-0023).",
6
6
  "type": "commonjs",
@@ -36,8 +36,8 @@
36
36
  "argon2": "^0.41.1",
37
37
  "ioredis": "^5.4.1",
38
38
  "mariadb": "^3.5.4",
39
- "@astram/core": "1.20.0",
40
- "@astram/engine": "0.22.0"
39
+ "@astram/core": "1.21.0",
40
+ "@astram/engine": "0.23.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@nestjs/common": "^11",
@@ -45,7 +45,7 @@
45
45
  "@nestjs/platform-express": "^11",
46
46
  "reflect-metadata": "^0.2",
47
47
  "rxjs": "^7",
48
- "@astram/messaging": "^0.1.27"
48
+ "@astram/messaging": "^0.1.30"
49
49
  },
50
50
  "peerDependenciesMeta": {
51
51
  "@astram/messaging": {
@@ -68,7 +68,7 @@
68
68
  "typescript": "^5.7.0",
69
69
  "unplugin-swc": "^1.5.1",
70
70
  "vitest": "^2.1.8",
71
- "@astram/messaging": "0.1.27"
71
+ "@astram/messaging": "0.1.30"
72
72
  },
73
73
  "repository": {
74
74
  "type": "git",