@astram/identity 0.15.0 → 0.16.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.
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework audit migration — the durable hash chain over `audit_log` (audit-chain-store SPEC §4.A,
|
|
3
|
+
* §4.B; Layer 9 reopened, STATUS G3). Both tables live in the audit database (`<ns>_audit`, default
|
|
4
|
+
* `shield_audit`), created by 1710000000010; this migration owns only the two tables.
|
|
5
|
+
* `audit_log` is NOT altered.
|
|
6
|
+
*
|
|
7
|
+
* `audit_chain` — one row per sealed `audit_log` row: per-tenant dense `ac_sequence` from 0, the
|
|
8
|
+
* row's content hash, the previous entry hash (`GENESIS` or the prior `ac_entry_hash`) and its own
|
|
9
|
+
* entry hash. `ac_occurred_at_ms` is an unhashed copy of `al_occurred_at_ms` (sealer window, prune
|
|
10
|
+
* prefix; `audit:verify` checks it); `ac_sealed_at_ms` is the sealer clock. PK (tenant, sequence) is
|
|
11
|
+
* the Layer-9 unique key; UNIQUE `ac_al_uuid` seals a row at most once; `idx_ac_occurred` serves the
|
|
12
|
+
* sealer's window start.
|
|
13
|
+
*
|
|
14
|
+
* `audit_chain_checkpoint` — one row per pruned batch (written only by `prune_audit`): the last
|
|
15
|
+
* pruned sequence and its entry hash, so verification can anchor after a prune.
|
|
16
|
+
*
|
|
17
|
+
* Collation: every tenant and uuid column is `utf8mb4_nopad_bin` (binary AND no pad), so `T1`, `t1`
|
|
18
|
+
* and `T1 ` are three tenants, exactly as in Node and `verifyChain`. Never `utf8mb4_bin` (PAD SPACE).
|
|
19
|
+
* Hash and run-id columns are `ascii_bin`. The table default collation is also `utf8mb4_nopad_bin`,
|
|
20
|
+
* so a character column added later without an explicit COLLATE keeps exact-byte semantics instead
|
|
21
|
+
* of silently folding case or trailing spaces. Comparisons against `audit_log`
|
|
22
|
+
* (`utf8mb4_unicode_ci`) must write `COLLATE utf8mb4_nopad_bin` on the `audit_log` side.
|
|
23
|
+
*
|
|
24
|
+
* Append-only: no code path UPDATEs or DELETEs these tables except `prune_audit` (definer).
|
|
25
|
+
* Idempotent (CREATE TABLE IF NOT EXISTS); `down` drops both (DROP TABLE IF EXISTS). No FK to
|
|
26
|
+
* `audit_log` (prune deletes rows in both under its own rules; a chain row whose `audit_log` row is
|
|
27
|
+
* gone is evidence for `audit:verify`). No seed, no hard-coded ids.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const { frameworkSchemasForMigration } = require('@astram/core');
|
|
31
|
+
|
|
32
|
+
// Database names come from `ctx.schemas` (SHIELD_DB_NAMESPACE, ADR-0037); under an older
|
|
33
|
+
// @astram/migrate without it, the default names apply only while the namespace is unset.
|
|
34
|
+
|
|
35
|
+
async function up(ctx) {
|
|
36
|
+
const { query } = ctx;
|
|
37
|
+
const SCHEMA = frameworkSchemasForMigration(ctx, process.env).audit;
|
|
38
|
+
|
|
39
|
+
await query(`CREATE TABLE IF NOT EXISTS \`${SCHEMA}\`.\`audit_chain\` (
|
|
40
|
+
ac_tenant_id VARCHAR(64) COLLATE utf8mb4_nopad_bin NOT NULL,
|
|
41
|
+
ac_sequence BIGINT UNSIGNED NOT NULL,
|
|
42
|
+
ac_al_uuid VARCHAR(36) COLLATE utf8mb4_nopad_bin NOT NULL,
|
|
43
|
+
ac_content_hash CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
44
|
+
ac_prev_hash VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
45
|
+
ac_entry_hash CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
46
|
+
ac_occurred_at_ms BIGINT NOT NULL,
|
|
47
|
+
ac_sealed_at_ms BIGINT NOT NULL,
|
|
48
|
+
PRIMARY KEY (ac_tenant_id, ac_sequence),
|
|
49
|
+
UNIQUE KEY uq_ac_al_uuid (ac_al_uuid),
|
|
50
|
+
INDEX idx_ac_occurred (ac_occurred_at_ms)
|
|
51
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_nopad_bin`);
|
|
52
|
+
|
|
53
|
+
await query(`CREATE TABLE IF NOT EXISTS \`${SCHEMA}\`.\`audit_chain_checkpoint\` (
|
|
54
|
+
acc_tenant_id VARCHAR(64) COLLATE utf8mb4_nopad_bin NOT NULL,
|
|
55
|
+
acc_sequence BIGINT UNSIGNED NOT NULL,
|
|
56
|
+
acc_entry_hash CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
57
|
+
acc_pruned_at_ms BIGINT NOT NULL,
|
|
58
|
+
acc_run_id VARCHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
59
|
+
acc_acknowledged_sequence BIGINT UNSIGNED NULL,
|
|
60
|
+
PRIMARY KEY (acc_tenant_id, acc_sequence)
|
|
61
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_nopad_bin`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function down(ctx) {
|
|
65
|
+
const { query } = ctx;
|
|
66
|
+
const SCHEMA = frameworkSchemasForMigration(ctx, process.env).audit;
|
|
67
|
+
await query(`DROP TABLE IF EXISTS \`${SCHEMA}\`.\`audit_chain_checkpoint\``);
|
|
68
|
+
await query(`DROP TABLE IF EXISTS \`${SCHEMA}\`.\`audit_chain\``);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = { up, down };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astram/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Astram framework — the framework-owned identity + tenancy model. Hosts the identity @ObjectType classes (user, company, membership, posting), framework-authored identity migrations, and the identity resolver. Top of the dependency graph: depends on @astram/engine (for @ObjectType/@Field decorators) + @astram/guard / @astram/core (for the auth ports).",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"mariadb": "^3.5.4",
|
|
39
|
-
"@astram/core": "1.
|
|
40
|
-
"@astram/
|
|
41
|
-
"@astram/
|
|
39
|
+
"@astram/core": "1.10.0",
|
|
40
|
+
"@astram/engine": "0.10.2",
|
|
41
|
+
"@astram/guard": "0.19.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@nestjs/common": "^11",
|
|
@@ -61,6 +61,11 @@
|
|
|
61
61
|
"unplugin-swc": "^1.5.1",
|
|
62
62
|
"vitest": "^2.1.8"
|
|
63
63
|
},
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "git+https://github.com/ASTRAM-2-0/astram-framework.git",
|
|
67
|
+
"directory": "packages/identity"
|
|
68
|
+
},
|
|
64
69
|
"scripts": {
|
|
65
70
|
"build": "tsc -p tsconfig.build.json",
|
|
66
71
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|