@astram/core 1.8.0 → 1.10.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.
- package/dist/audit/audit-recorder.d.ts +38 -2
- package/dist/audit/audit-recorder.d.ts.map +1 -1
- package/dist/audit/audit-recorder.js +39 -12
- package/dist/audit/audit-recorder.js.map +1 -1
- package/dist/audit/audit-row.d.ts +63 -0
- package/dist/audit/audit-row.d.ts.map +1 -0
- package/dist/audit/audit-row.js +99 -0
- package/dist/audit/audit-row.js.map +1 -0
- package/dist/audit/errors.d.ts +22 -0
- package/dist/audit/errors.d.ts.map +1 -1
- package/dist/audit/errors.js +18 -0
- package/dist/audit/errors.js.map +1 -1
- package/dist/audit/index.d.ts +1 -0
- package/dist/audit/index.d.ts.map +1 -1
- package/dist/audit/index.js +3 -0
- package/dist/audit/index.js.map +1 -1
- package/dist/audit/ports.d.ts +13 -8
- package/dist/audit/ports.d.ts.map +1 -1
- package/dist/audit/ports.js +7 -5
- package/dist/audit/ports.js.map +1 -1
- package/dist/database/framework-tables.js +1 -1
- package/dist/database/framework-tables.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/messaging/index.d.ts +11 -0
- package/dist/messaging/index.d.ts.map +1 -0
- package/dist/messaging/index.js +10 -0
- package/dist/messaging/index.js.map +1 -0
- package/dist/messaging/ports.d.ts +84 -0
- package/dist/messaging/ports.d.ts.map +1 -0
- package/dist/messaging/ports.js +39 -0
- package/dist/messaging/ports.js.map +1 -0
- package/dist-cjs/audit/audit-recorder.js +40 -12
- package/dist-cjs/audit/audit-row.js +102 -0
- package/dist-cjs/audit/errors.js +20 -1
- package/dist-cjs/audit/index.js +3 -0
- package/dist-cjs/audit/ports.js +7 -5
- package/dist-cjs/database/framework-tables.js +1 -1
- package/dist-cjs/index.js +2 -0
- package/dist-cjs/messaging/index.js +15 -0
- package/dist-cjs/messaging/ports.js +43 -0
- package/package.json +6 -1
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
*
|
|
41
41
|
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
42
42
|
*/
|
|
43
|
-
import type { AuditSink } from './index.js';
|
|
43
|
+
import type { AuditEvent, AuditSink } from './index.js';
|
|
44
44
|
import type { AuditEventStore, Clock, HashFunction, StoredAuditRecord } from './ports.js';
|
|
45
45
|
/**
|
|
46
46
|
* The fixed genesis `prevHash` for the FIRST record of every tenant's chain
|
|
@@ -50,6 +50,35 @@ import type { AuditEventStore, Clock, HashFunction, StoredAuditRecord } from './
|
|
|
50
50
|
* `entryHash` and lets the scheme version later without ambiguity.
|
|
51
51
|
*/
|
|
52
52
|
export declare const GENESIS = "shield:audit:genesis:v1";
|
|
53
|
+
/**
|
|
54
|
+
* The position a tenant's chain continues from: the last linked (or last pruned)
|
|
55
|
+
* record's tenant, sequence and entry hash. Passed to {@link linkEntry} as `prev` and
|
|
56
|
+
* to {@link verifyChain} as `anchor` (a pruned chain's checkpoint, or the tail of the
|
|
57
|
+
* previous page when a verifier pages a long chain).
|
|
58
|
+
*/
|
|
59
|
+
export interface ChainAnchor {
|
|
60
|
+
readonly tenantId: string;
|
|
61
|
+
readonly sequenceNumber: number;
|
|
62
|
+
readonly entryHash: string;
|
|
63
|
+
}
|
|
64
|
+
/** The chain fields {@link linkEntry} computes for one event. */
|
|
65
|
+
export interface ChainLink {
|
|
66
|
+
readonly sequenceNumber: number;
|
|
67
|
+
readonly contentHash: string;
|
|
68
|
+
readonly prevHash: string;
|
|
69
|
+
readonly entryHash: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The pure chain math for ONE event (§3): `contentHash = H(canonicalize(content))`,
|
|
73
|
+
* `sequenceNumber = prev.sequenceNumber + 1` (or `0`), `prevHash = prev.entryHash`
|
|
74
|
+
* (or {@link GENESIS}), `entryHash = H(contentHash ‖ prevHash ‖ sequenceNumber)`.
|
|
75
|
+
*
|
|
76
|
+
* `content` is hashed exactly as given: the caller passes the already-cleaned event
|
|
77
|
+
* (the recorder strips secrets first; the sealer builds it from the stored row with
|
|
78
|
+
* `auditEventFromRow`). Equal inputs give equal outputs. `prev.tenantId` is not read
|
|
79
|
+
* here; the caller keeps chains per tenant.
|
|
80
|
+
*/
|
|
81
|
+
export declare function linkEntry(content: AuditEvent, prev: ChainAnchor | undefined, hash: HashFunction): ChainLink;
|
|
53
82
|
/** Injected capabilities for {@link createAuditRecorder}. */
|
|
54
83
|
export interface AuditRecorderDeps {
|
|
55
84
|
/** Append-only record store PORT (MariaDB adapter in `@astram/guard`). */
|
|
@@ -122,8 +151,15 @@ export type ChainVerification = {
|
|
|
122
151
|
* - `content_mismatch` — the recomputed `contentHash`/`entryHash` ≠ the stored
|
|
123
152
|
* ones: a field of the record was mutated.
|
|
124
153
|
*
|
|
154
|
+
* With an `anchor` (a pruned chain's checkpoint, or the last record of the previous
|
|
155
|
+
* page), the chain is expected to continue from it: the expected tenant is
|
|
156
|
+
* `anchor.tenantId` (a foreign first record is reported at index 0), the first
|
|
157
|
+
* sequence `anchor.sequenceNumber + 1` and the first `prevHash` `anchor.entryHash`.
|
|
158
|
+
* Without one, the chain must start at sequence 0 from {@link GENESIS}.
|
|
159
|
+
*
|
|
125
160
|
* @param records An ordered, single-tenant chain (sequence ascending).
|
|
126
161
|
* @param hash The SAME deterministic hash used to write the chain.
|
|
162
|
+
* @param anchor Optional position the records continue from.
|
|
127
163
|
*/
|
|
128
|
-
export declare function verifyChain(records: readonly StoredAuditRecord[], hash: HashFunction): ChainVerification;
|
|
164
|
+
export declare function verifyChain(records: readonly StoredAuditRecord[], hash: HashFunction, anchor?: ChainAnchor): ChainVerification;
|
|
129
165
|
//# sourceMappingURL=audit-recorder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-recorder.d.ts","sourceRoot":"","sources":["../../src/audit/audit-recorder.ts"],"names":[],"mappings":"AAA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,CAAC,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAChD;AAUD,uFAAuF;AACvF,MAAM,MAAM,0BAA0B,GAAG,iBAAiB,CAAC;AAE3D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,SAAS,CAsGtE;AAED,sDAAsD;AACtD,MAAM,MAAM,gBAAgB,GAC1B,kBAAkB,GAAG,eAAe,GAAG,cAAc,GAAG,iBAAiB,CAAC;AAE5E,sFAAsF;AACtF,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAEhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,SAAS,iBAAiB,EAAE,EACrC,IAAI,EAAE,YAAY,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,iBAAiB,CAoEnB"}
|
|
@@ -61,6 +61,23 @@ const CHAIN_SEP = '|';
|
|
|
61
61
|
function entryPreimage(contentHash, prevHash, sequenceNumber) {
|
|
62
62
|
return `${contentHash}${CHAIN_SEP}${prevHash}${CHAIN_SEP}${sequenceNumber}`;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* The pure chain math for ONE event (§3): `contentHash = H(canonicalize(content))`,
|
|
66
|
+
* `sequenceNumber = prev.sequenceNumber + 1` (or `0`), `prevHash = prev.entryHash`
|
|
67
|
+
* (or {@link GENESIS}), `entryHash = H(contentHash ‖ prevHash ‖ sequenceNumber)`.
|
|
68
|
+
*
|
|
69
|
+
* `content` is hashed exactly as given: the caller passes the already-cleaned event
|
|
70
|
+
* (the recorder strips secrets first; the sealer builds it from the stored row with
|
|
71
|
+
* `auditEventFromRow`). Equal inputs give equal outputs. `prev.tenantId` is not read
|
|
72
|
+
* here; the caller keeps chains per tenant.
|
|
73
|
+
*/
|
|
74
|
+
export function linkEntry(content, prev, hash) {
|
|
75
|
+
const sequenceNumber = prev !== undefined ? prev.sequenceNumber + 1 : 0;
|
|
76
|
+
const prevHash = prev !== undefined ? prev.entryHash : GENESIS;
|
|
77
|
+
const contentHash = hash.hash(canonicalizeEvent(content));
|
|
78
|
+
const entryHash = hash.hash(entryPreimage(contentHash, prevHash, sequenceNumber));
|
|
79
|
+
return { sequenceNumber, contentHash, prevHash, entryHash };
|
|
80
|
+
}
|
|
64
81
|
/**
|
|
65
82
|
* A non-blank string guard — an actor/tenant id must be a present, non-whitespace
|
|
66
83
|
* string. (`.trim()` catches `' '`, which a bare `length === 0` would miss.)
|
|
@@ -129,10 +146,13 @@ export function createAuditRecorder(deps) {
|
|
|
129
146
|
// prevHash from it. Per-tenant: `readChain` only returns THIS tenant's records.
|
|
130
147
|
const chain = await store.readChain(event.tenantId);
|
|
131
148
|
const tail = chain.length > 0 ? chain[chain.length - 1] : undefined;
|
|
132
|
-
const sequenceNumber
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
const { sequenceNumber, contentHash, prevHash, entryHash } = linkEntry(cleanEvent, tail !== undefined
|
|
150
|
+
? {
|
|
151
|
+
tenantId: tail.tenantId,
|
|
152
|
+
sequenceNumber: tail.sequenceNumber,
|
|
153
|
+
entryHash: tail.entryHash,
|
|
154
|
+
}
|
|
155
|
+
: undefined, hash);
|
|
136
156
|
// ── (4) STAMP (AC-9). The engine's own clock — distinct from occurredAtMs.
|
|
137
157
|
const recordedAtMs = clock.nowMs();
|
|
138
158
|
const stored = {
|
|
@@ -200,17 +220,24 @@ export function createAuditRecorder(deps) {
|
|
|
200
220
|
* - `content_mismatch` — the recomputed `contentHash`/`entryHash` ≠ the stored
|
|
201
221
|
* ones: a field of the record was mutated.
|
|
202
222
|
*
|
|
223
|
+
* With an `anchor` (a pruned chain's checkpoint, or the last record of the previous
|
|
224
|
+
* page), the chain is expected to continue from it: the expected tenant is
|
|
225
|
+
* `anchor.tenantId` (a foreign first record is reported at index 0), the first
|
|
226
|
+
* sequence `anchor.sequenceNumber + 1` and the first `prevHash` `anchor.entryHash`.
|
|
227
|
+
* Without one, the chain must start at sequence 0 from {@link GENESIS}.
|
|
228
|
+
*
|
|
203
229
|
* @param records An ordered, single-tenant chain (sequence ascending).
|
|
204
230
|
* @param hash The SAME deterministic hash used to write the chain.
|
|
231
|
+
* @param anchor Optional position the records continue from.
|
|
205
232
|
*/
|
|
206
|
-
export function verifyChain(records, hash) {
|
|
207
|
-
let expectedPrevHash = GENESIS;
|
|
208
|
-
let expectedSequence = 0;
|
|
209
|
-
// The chain is contractually SINGLE-tenant. Pin the expected tenant to the
|
|
210
|
-
// record's; any
|
|
211
|
-
// (a foreign record chained on at the right sequence can self-verify) and MUST
|
|
212
|
-
// rejected. An empty array
|
|
213
|
-
const expectedTenantId = records.length > 0 ? records[0]?.tenantId : undefined;
|
|
233
|
+
export function verifyChain(records, hash, anchor) {
|
|
234
|
+
let expectedPrevHash = anchor !== undefined ? anchor.entryHash : GENESIS;
|
|
235
|
+
let expectedSequence = anchor !== undefined ? anchor.sequenceNumber + 1 : 0;
|
|
236
|
+
// The chain is contractually SINGLE-tenant. Pin the expected tenant to the anchor's
|
|
237
|
+
// (else the first record's); any record with a different `tenantId` is a cross-tenant
|
|
238
|
+
// splice (a foreign record chained on at the right sequence can self-verify) and MUST
|
|
239
|
+
// be rejected. An empty array is vacuously intact (loop does not run).
|
|
240
|
+
const expectedTenantId = anchor !== undefined ? anchor.tenantId : records.length > 0 ? records[0]?.tenantId : undefined;
|
|
214
241
|
for (let i = 0; i < records.length; i++) {
|
|
215
242
|
const record = records[i];
|
|
216
243
|
if (record === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-recorder.js","source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AAE,CAAC;QACvE,CAAC;QAED,4EAA4E;QAC5E,gBAAgB,GAAG,mBAAmB,CAAC;QACvC,gBAAgB,GAAG,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stored-row mapping for the durable audit chain (audit-chain-store SPEC §5.D).
|
|
3
|
+
*
|
|
4
|
+
* `auditEventFromRow` is THE one mapping from an `audit_log` row back to the
|
|
5
|
+
* {@link AuditEvent} whose canonical form is hashed into the chain. The sealer (guard)
|
|
6
|
+
* and the verifier (`astram-migrate audit:verify`) both use it, so the content they
|
|
7
|
+
* hash is built the same way from the same stored columns. It is the inverse of the
|
|
8
|
+
* one INSERT shape (`@astram/engine` `MariaDbAuditSink.record`):
|
|
9
|
+
* - `al_type`, `al_actor_id`, `al_tenant_id` ⇒ `type`, `actorId`, `tenantId`;
|
|
10
|
+
* - `al_occurred_at_ms` (BIGINT) ⇒ `occurredAtMs` via {@link toSafeInteger};
|
|
11
|
+
* - `al_action_key` ⇒ `action: { key }`;
|
|
12
|
+
* - `al_resource_json`, `al_decision_json`, `al_attributes_json` ⇒ the parsed value
|
|
13
|
+
* (the driver may return JSON text or an already-parsed value);
|
|
14
|
+
* - SQL NULL ⇒ the field is absent (never `undefined`-valued, never `null`);
|
|
15
|
+
* - `al_uuid` is the row key, not content: it is never part of the event.
|
|
16
|
+
*
|
|
17
|
+
* BIGINT values never reach the hashed content as `bigint` (`canonicalizeEvent`
|
|
18
|
+
* rejects them): they are converted to a safe `number` or the row is rejected with a
|
|
19
|
+
* typed {@link AuditRowError}. A JSON column whose text does not parse is also rejected
|
|
20
|
+
* typed (`invalid_json`), so the sealer can tell a repeating row problem from a
|
|
21
|
+
* transient database error.
|
|
22
|
+
*
|
|
23
|
+
* Kept in its own file (not `audit-recorder.ts`): it is row/driver shape knowledge,
|
|
24
|
+
* not chain math, and the recorder stays independent of any storage layout.
|
|
25
|
+
*
|
|
26
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
27
|
+
*/
|
|
28
|
+
import type { AuditEvent } from './index.js';
|
|
29
|
+
/** A BIGINT column value as a MariaDB driver may return it. */
|
|
30
|
+
export type BigIntColumnValue = number | bigint | string;
|
|
31
|
+
/**
|
|
32
|
+
* One `audit_log` row as read back from the database (column names of identity
|
|
33
|
+
* migration `1710000000010-CreateAuditLog`). JSON columns may be text or parsed;
|
|
34
|
+
* nullable columns may be `null`. `al_uuid` is accepted but never mapped.
|
|
35
|
+
*/
|
|
36
|
+
export interface AuditLogRow {
|
|
37
|
+
readonly al_uuid?: string;
|
|
38
|
+
readonly al_type: string;
|
|
39
|
+
readonly al_occurred_at_ms: BigIntColumnValue;
|
|
40
|
+
readonly al_actor_id: string;
|
|
41
|
+
readonly al_tenant_id: string;
|
|
42
|
+
readonly al_action_key?: string | null;
|
|
43
|
+
readonly al_resource_json?: unknown;
|
|
44
|
+
readonly al_decision_json?: unknown;
|
|
45
|
+
readonly al_attributes_json?: unknown;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Convert a BIGINT column value (`number`, `bigint`, or decimal-integer string) to a
|
|
49
|
+
* JS `number`, refusing anything that is not exactly representable: a non-integer, a
|
|
50
|
+
* value outside `Number.MIN_SAFE_INTEGER..MAX_SAFE_INTEGER`, `NaN`/`±Infinity`, an
|
|
51
|
+
* empty or non-decimal string, `null`, `undefined` or any other type ⇒
|
|
52
|
+
* `AuditRowError('unsafe_integer')` (the value is never put in the message).
|
|
53
|
+
*
|
|
54
|
+
* Used for `al_occurred_at_ms`, `ac_sequence` and `acc_sequence`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function toSafeInteger(value: BigIntColumnValue): number;
|
|
57
|
+
/**
|
|
58
|
+
* Map one stored `audit_log` row to the {@link AuditEvent} that is hashed into the
|
|
59
|
+
* chain (see the file header for the column mapping). Throws {@link AuditRowError}
|
|
60
|
+
* for an unsafe BIGINT or unparseable JSON text.
|
|
61
|
+
*/
|
|
62
|
+
export declare function auditEventFromRow(row: AuditLogRow): AuditEvent;
|
|
63
|
+
//# sourceMappingURL=audit-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-row.d.ts","sourceRoot":"","sources":["../../src/audit/audit-row.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,YAAY,CAAC;AAE7D,+DAA+D;AAC/D,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CACvC;AAQD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAc9D;AAeD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,UAAU,CAsB9D"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stored-row mapping for the durable audit chain (audit-chain-store SPEC §5.D).
|
|
3
|
+
*
|
|
4
|
+
* `auditEventFromRow` is THE one mapping from an `audit_log` row back to the
|
|
5
|
+
* {@link AuditEvent} whose canonical form is hashed into the chain. The sealer (guard)
|
|
6
|
+
* and the verifier (`astram-migrate audit:verify`) both use it, so the content they
|
|
7
|
+
* hash is built the same way from the same stored columns. It is the inverse of the
|
|
8
|
+
* one INSERT shape (`@astram/engine` `MariaDbAuditSink.record`):
|
|
9
|
+
* - `al_type`, `al_actor_id`, `al_tenant_id` ⇒ `type`, `actorId`, `tenantId`;
|
|
10
|
+
* - `al_occurred_at_ms` (BIGINT) ⇒ `occurredAtMs` via {@link toSafeInteger};
|
|
11
|
+
* - `al_action_key` ⇒ `action: { key }`;
|
|
12
|
+
* - `al_resource_json`, `al_decision_json`, `al_attributes_json` ⇒ the parsed value
|
|
13
|
+
* (the driver may return JSON text or an already-parsed value);
|
|
14
|
+
* - SQL NULL ⇒ the field is absent (never `undefined`-valued, never `null`);
|
|
15
|
+
* - `al_uuid` is the row key, not content: it is never part of the event.
|
|
16
|
+
*
|
|
17
|
+
* BIGINT values never reach the hashed content as `bigint` (`canonicalizeEvent`
|
|
18
|
+
* rejects them): they are converted to a safe `number` or the row is rejected with a
|
|
19
|
+
* typed {@link AuditRowError}. A JSON column whose text does not parse is also rejected
|
|
20
|
+
* typed (`invalid_json`), so the sealer can tell a repeating row problem from a
|
|
21
|
+
* transient database error.
|
|
22
|
+
*
|
|
23
|
+
* Kept in its own file (not `audit-recorder.ts`): it is row/driver shape knowledge,
|
|
24
|
+
* not chain math, and the recorder stays independent of any storage layout.
|
|
25
|
+
*
|
|
26
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
27
|
+
*/
|
|
28
|
+
import { AuditRowError } from './errors.js';
|
|
29
|
+
const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
|
|
30
|
+
const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
|
|
31
|
+
/** Optional sign, then decimal digits only; 17 digits already exceed the safe range. */
|
|
32
|
+
const DECIMAL_INTEGER = /^-?[0-9]{1,20}$/;
|
|
33
|
+
/**
|
|
34
|
+
* Convert a BIGINT column value (`number`, `bigint`, or decimal-integer string) to a
|
|
35
|
+
* JS `number`, refusing anything that is not exactly representable: a non-integer, a
|
|
36
|
+
* value outside `Number.MIN_SAFE_INTEGER..MAX_SAFE_INTEGER`, `NaN`/`±Infinity`, an
|
|
37
|
+
* empty or non-decimal string, `null`, `undefined` or any other type ⇒
|
|
38
|
+
* `AuditRowError('unsafe_integer')` (the value is never put in the message).
|
|
39
|
+
*
|
|
40
|
+
* Used for `al_occurred_at_ms`, `ac_sequence` and `acc_sequence`.
|
|
41
|
+
*/
|
|
42
|
+
export function toSafeInteger(value) {
|
|
43
|
+
const v = value;
|
|
44
|
+
if (typeof v === 'number') {
|
|
45
|
+
if (!Number.isSafeInteger(v))
|
|
46
|
+
throw new AuditRowError('unsafe_integer');
|
|
47
|
+
return v === 0 ? 0 : v; // normalize -0
|
|
48
|
+
}
|
|
49
|
+
if (typeof v === 'bigint') {
|
|
50
|
+
if (v > MAX_SAFE || v < MIN_SAFE)
|
|
51
|
+
throw new AuditRowError('unsafe_integer');
|
|
52
|
+
return Number(v);
|
|
53
|
+
}
|
|
54
|
+
if (typeof v === 'string' && DECIMAL_INTEGER.test(v)) {
|
|
55
|
+
return toSafeInteger(BigInt(v));
|
|
56
|
+
}
|
|
57
|
+
throw new AuditRowError('unsafe_integer');
|
|
58
|
+
}
|
|
59
|
+
/** A JSON column: SQL NULL (or a parsed JSON null) ⇒ absent; text ⇒ parsed; else as given. */
|
|
60
|
+
function jsonColumn(value) {
|
|
61
|
+
if (value === null || value === undefined)
|
|
62
|
+
return undefined;
|
|
63
|
+
if (typeof value !== 'string')
|
|
64
|
+
return value;
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = JSON.parse(value);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new AuditRowError('invalid_json');
|
|
71
|
+
}
|
|
72
|
+
return parsed === null ? undefined : parsed;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Map one stored `audit_log` row to the {@link AuditEvent} that is hashed into the
|
|
76
|
+
* chain (see the file header for the column mapping). Throws {@link AuditRowError}
|
|
77
|
+
* for an unsafe BIGINT or unparseable JSON text.
|
|
78
|
+
*/
|
|
79
|
+
export function auditEventFromRow(row) {
|
|
80
|
+
const occurredAtMs = toSafeInteger(row.al_occurred_at_ms);
|
|
81
|
+
const actionKey = row.al_action_key;
|
|
82
|
+
const resource = jsonColumn(row.al_resource_json);
|
|
83
|
+
const decision = jsonColumn(row.al_decision_json);
|
|
84
|
+
const attributes = jsonColumn(row.al_attributes_json);
|
|
85
|
+
const action = actionKey !== null && actionKey !== undefined ? { key: actionKey } : undefined;
|
|
86
|
+
return {
|
|
87
|
+
type: row.al_type,
|
|
88
|
+
occurredAtMs,
|
|
89
|
+
actorId: row.al_actor_id,
|
|
90
|
+
tenantId: row.al_tenant_id,
|
|
91
|
+
...(action !== undefined ? { action } : {}),
|
|
92
|
+
...(resource !== undefined ? { resource: resource } : {}),
|
|
93
|
+
...(decision !== undefined ? { decision: decision } : {}),
|
|
94
|
+
...(attributes !== undefined
|
|
95
|
+
? { attributes: attributes }
|
|
96
|
+
: {}),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=audit-row.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-row.js","sourceRoot":"","sources":["../../src/audit/audit-row.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAuB5C,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACjD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEjD,wFAAwF;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.ts
CHANGED
|
@@ -53,4 +53,26 @@ export declare class AuditValidationError extends Error {
|
|
|
53
53
|
readonly reason: AuditValidationReason;
|
|
54
54
|
constructor(reason: AuditValidationReason);
|
|
55
55
|
}
|
|
56
|
+
/** Why a stored `audit_log` / chain row could not be mapped back to its hashed content. */
|
|
57
|
+
export type AuditRowRejectionReason =
|
|
58
|
+
/**
|
|
59
|
+
* A BIGINT column (`al_occurred_at_ms`, `ac_sequence`, `acc_sequence`) is not a
|
|
60
|
+
* safe integer (or not an integer, or not a number/bigint/decimal string), so it
|
|
61
|
+
* cannot become a JS `number` without losing precision.
|
|
62
|
+
*/
|
|
63
|
+
'unsafe_integer'
|
|
64
|
+
/** A JSON column holds text that does not parse as JSON. */
|
|
65
|
+
| 'invalid_json';
|
|
66
|
+
/**
|
|
67
|
+
* Thrown by `auditEventFromRow` / `toSafeInteger` (`./audit-row.ts`) when a STORED
|
|
68
|
+
* row cannot be turned back into the exact `AuditEvent` that is hashed. A repeating
|
|
69
|
+
* error: the same row fails the same way on every retry, so the sealer parks that
|
|
70
|
+
* tenant until the next sweep (SPEC §5.G). Names the reason only; NEVER carries the
|
|
71
|
+
* offending value (it comes from the database and could be anything).
|
|
72
|
+
*/
|
|
73
|
+
export declare class AuditRowError extends Error {
|
|
74
|
+
/** The specific row problem. */
|
|
75
|
+
readonly reason: AuditRowRejectionReason;
|
|
76
|
+
constructor(reason: AuditRowRejectionReason);
|
|
77
|
+
}
|
|
56
78
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/audit/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,wFAAwF;AACxF,MAAM,MAAM,qBAAqB,GAC7B,eAAe,GACf,gBAAgB,GAChB,qBAAqB;AACvB;;;;;;;GAOG;GACD,0BAA0B;AAC5B;;;;;;;;GAQG;GACD,kBAAkB,CAAC;AAEvB;;;;;;;;;;GAUG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;gBAE3B,MAAM,EAAE,qBAAqB;CAO1C"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/audit/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,wFAAwF;AACxF,MAAM,MAAM,qBAAqB,GAC7B,eAAe,GACf,gBAAgB,GAChB,qBAAqB;AACvB;;;;;;;GAOG;GACD,0BAA0B;AAC5B;;;;;;;;GAQG;GACD,kBAAkB,CAAC;AAEvB;;;;;;;;;;GAUG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;gBAE3B,MAAM,EAAE,qBAAqB;CAO1C;AAED,2FAA2F;AAC3F,MAAM,MAAM,uBAAuB;AACjC;;;;GAIG;AACD,gBAAgB;AAClB,4DAA4D;GAC1D,cAAc,CAAC;AAEnB;;;;;;GAMG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;gBAE7B,MAAM,EAAE,uBAAuB;CAO5C"}
|
package/dist/audit/errors.js
CHANGED
|
@@ -38,4 +38,22 @@ export class AuditValidationError extends Error {
|
|
|
38
38
|
Object.setPrototypeOf(this, AuditValidationError.prototype);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown by `auditEventFromRow` / `toSafeInteger` (`./audit-row.ts`) when a STORED
|
|
43
|
+
* row cannot be turned back into the exact `AuditEvent` that is hashed. A repeating
|
|
44
|
+
* error: the same row fails the same way on every retry, so the sealer parks that
|
|
45
|
+
* tenant until the next sweep (SPEC §5.G). Names the reason only; NEVER carries the
|
|
46
|
+
* offending value (it comes from the database and could be anything).
|
|
47
|
+
*/
|
|
48
|
+
export class AuditRowError extends Error {
|
|
49
|
+
/** The specific row problem. */
|
|
50
|
+
reason;
|
|
51
|
+
constructor(reason) {
|
|
52
|
+
super(`audit_row_rejected:${reason}`);
|
|
53
|
+
this.name = 'AuditRowError';
|
|
54
|
+
this.reason = reason;
|
|
55
|
+
// Preserve the prototype chain when compiled down-level so `instanceof` works.
|
|
56
|
+
Object.setPrototypeOf(this, AuditRowError.prototype);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
41
59
|
//# sourceMappingURL=errors.js.map
|
package/dist/audit/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/audit/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA2BH;;;;;;;;;;GAUG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,4EAA4E;IACnE,MAAM,CAAwB;IAEvC,YAAY,MAA6B;QACvC,KAAK,CAAC,wBAAwB,MAAM,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,+EAA+E;QAC/E,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/audit/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA2BH;;;;;;;;;;GAUG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,4EAA4E;IACnE,MAAM,CAAwB;IAEvC,YAAY,MAA6B;QACvC,KAAK,CAAC,wBAAwB,MAAM,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAC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AGG;AACH,MAAM,WAAW,SAAS;IACxB,0EAA0E;IAC1E,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAMD,cAAc,YAAY,CAAC;AAE3B,cAAc,mBAAmB,CAAC;AAElC,cAAc,gBAAgB,CAAC;AAE/B,cAAc,aAAa,CAAC;AAG5B,cAAc,qBAAqB,CAAC;AAGpC,cAAc,gBAAgB,CAAC"}
|
package/dist/audit/index.js
CHANGED
|
@@ -21,4 +21,7 @@ export * from './errors.js';
|
|
|
21
21
|
// - the tamper-evident recorder `createAuditRecorder` (IS an AuditSink) + the pure
|
|
22
22
|
// `verifyChain` primitive + the GENESIS chain constant:
|
|
23
23
|
export * from './audit-recorder.js';
|
|
24
|
+
// - the stored-row mapping for the durable chain (`auditEventFromRow`, `toSafeInteger`,
|
|
25
|
+
// `AuditLogRow`); `linkEntry` / `ChainAnchor` come from `./audit-recorder.js` above:
|
|
26
|
+
export * from './audit-row.js';
|
|
24
27
|
//# sourceMappingURL=index.js.map
|
package/dist/audit/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/audit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0CH,iFAAiF;AACjF,2EAA2E;AAC3E,yEAAyE;AACzE,0FAA0F;AAC1F,cAAc,YAAY,CAAC;AAC3B,qFAAqF;AACrF,cAAc,mBAAmB,CAAC;AAClC,wEAAwE;AACxE,cAAc,gBAAgB,CAAC;AAC/B,+EAA+E;AAC/E,cAAc,aAAa,CAAC;AAC5B,qFAAqF;AACrF,4DAA4D;AAC5D,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/audit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0CH,iFAAiF;AACjF,2EAA2E;AAC3E,yEAAyE;AACzE,0FAA0F;AAC1F,cAAc,YAAY,CAAC;AAC3B,qFAAqF;AACrF,cAAc,mBAAmB,CAAC;AAClC,wEAAwE;AACxE,cAAc,gBAAgB,CAAC;AAC/B,+EAA+E;AAC/E,cAAc,aAAa,CAAC;AAC5B,qFAAqF;AACrF,4DAA4D;AAC5D,cAAc,qBAAqB,CAAC;AACpC,0FAA0F;AAC1F,yFAAyF;AACzF,cAAc,gBAAgB,CAAC"}
|
package/dist/audit/ports.d.ts
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* knowing which crypto / DB backs them.
|
|
6
6
|
*
|
|
7
7
|
* ADR-0003 (zero-dep Core): every concrete adapter (`node:crypto` SHA-256, the
|
|
8
|
-
* append-only MariaDB `
|
|
9
|
-
* CANNOT live here. The Core defines only these interfaces
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* append-only MariaDB `<ns>_audit` tables) is a real runtime dependency and
|
|
9
|
+
* CANNOT live here. The Core defines only these interfaces. `@astram/guard` ships
|
|
10
|
+
* the SHA-256 `HashFunction` and the deferred sealer (`AuditChainSealer`,
|
|
11
|
+
* audit-chain-store SPEC §5.G), which chains committed `audit_log` rows with
|
|
12
|
+
* `linkEntry` instead of injecting a store into `createAuditRecorder(...)`. This
|
|
13
|
+
* keeps `@astram/core` at ZERO runtime dependencies (the load-bearing invariant)
|
|
14
|
+
* while the substrate stays swappable.
|
|
13
15
|
*
|
|
14
16
|
* ⛔ SECURITY — the audit engine records for INTEGRITY, not confidentiality. It
|
|
15
17
|
* NEVER persists a secret value (a denylist strips secret-bearing keys before a
|
|
@@ -93,9 +95,12 @@ export interface StoredAuditRecord {
|
|
|
93
95
|
readonly entryHash: string;
|
|
94
96
|
}
|
|
95
97
|
/**
|
|
96
|
-
* The **append-only audit record store** PORT
|
|
97
|
-
* Written ONCE per event and read back ordered for verification.
|
|
98
|
-
* `
|
|
98
|
+
* The **append-only audit record store** PORT used by `createAuditRecorder`
|
|
99
|
+
* (inline chaining). Written ONCE per event and read back ordered for verification.
|
|
100
|
+
* No framework concrete ships for it: framework writers append plain `audit_log`
|
|
101
|
+
* rows and the guard's deferred sealer (`AuditChainSealer`, audit-chain-store SPEC
|
|
102
|
+
* §5.G) chains them into `<ns>_audit.audit_chain` with `linkEntry` /
|
|
103
|
+
* `auditEventFromRow`.
|
|
99
104
|
*
|
|
100
105
|
* ⛔ APPEND-ONLY IS STRUCTURAL: this port intentionally exposes NO update / delete
|
|
101
106
|
* method — the adapter's table forbids UPDATE/DELETE (Infra, ADR-0014). Even the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/audit/ports.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/audit/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAO7C,YAAY,EAAE,KAAK,EAAE,CAAC;AAMtB;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,YAAY;IAC3B,2FAA2F;IAC3F,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B;AAMD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB;IAEhC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAClC,0FAA0F;IAC1F,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IAC3C,iFAAiF;IACjF,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxD,oFAAoF;IACpF,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAG1C;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,kFAAkF;IAClF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAAC;CACpE"}
|
package/dist/audit/ports.js
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* knowing which crypto / DB backs them.
|
|
6
6
|
*
|
|
7
7
|
* ADR-0003 (zero-dep Core): every concrete adapter (`node:crypto` SHA-256, the
|
|
8
|
-
* append-only MariaDB `
|
|
9
|
-
* CANNOT live here. The Core defines only these interfaces
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* append-only MariaDB `<ns>_audit` tables) is a real runtime dependency and
|
|
9
|
+
* CANNOT live here. The Core defines only these interfaces. `@astram/guard` ships
|
|
10
|
+
* the SHA-256 `HashFunction` and the deferred sealer (`AuditChainSealer`,
|
|
11
|
+
* audit-chain-store SPEC §5.G), which chains committed `audit_log` rows with
|
|
12
|
+
* `linkEntry` instead of injecting a store into `createAuditRecorder(...)`. This
|
|
13
|
+
* keeps `@astram/core` at ZERO runtime dependencies (the load-bearing invariant)
|
|
14
|
+
* while the substrate stays swappable.
|
|
13
15
|
*
|
|
14
16
|
* ⛔ SECURITY — the audit engine records for INTEGRITY, not confidentiality. It
|
|
15
17
|
* NEVER persists a secret value (a denylist strips secret-bearing keys before a
|
package/dist/audit/ports.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/audit/ports.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/audit/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;AAwIH,yEAAyE;AACzE,+EAA+E;AAC/E,4EAA4E;AAC5E,2DAA2D"}
|
|
@@ -43,7 +43,7 @@ export const FRAMEWORK_TABLES = Object.freeze({
|
|
|
43
43
|
'service_account_key',
|
|
44
44
|
'cross_tenant_grant',
|
|
45
45
|
]),
|
|
46
|
-
audit: Object.freeze(['audit_log']),
|
|
46
|
+
audit: Object.freeze(['audit_log', 'audit_chain', 'audit_chain_checkpoint']),
|
|
47
47
|
});
|
|
48
48
|
/** Framework stored routines. */
|
|
49
49
|
export const FRAMEWORK_ROUTINES = Object.freeze(['prune_audit']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-tables.js","sourceRoot":"","sources":["../../src/database/framework-tables.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE,yGAAyG;AACzG,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC;QACjB,WAAW;QACX,OAAO;QACP,OAAO;QACP,aAAa;QACb,UAAU;QACV,oBAAoB;QACpB,oBAAoB;QACpB,qBAAqB;QACrB,kBAAkB;QAClB,iBAAiB;QACjB,iBAAiB;QACjB,aAAa;KACd,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;QACtB,qBAAqB;QACrB,SAAS;QACT,eAAe;QACf,YAAY;QACZ,sBAAsB;QACtB,mBAAmB;QACnB,oBAAoB;KACrB,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QACnB,YAAY;QACZ,iBAAiB;QACjB,0BAA0B;QAC1B,eAAe;QACf,0BAA0B;QAC1B,wBAAwB;QACxB,cAAc;QACd,eAAe;QACf,qBAAqB;QACrB,oBAAoB;KACrB,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"framework-tables.js","sourceRoot":"","sources":["../../src/database/framework-tables.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE,yGAAyG;AACzG,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC;QACjB,WAAW;QACX,OAAO;QACP,OAAO;QACP,aAAa;QACb,UAAU;QACV,oBAAoB;QACpB,oBAAoB;QACpB,qBAAqB;QACrB,kBAAkB;QAClB,iBAAiB;QACjB,iBAAiB;QACjB,aAAa;KACd,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;QACtB,qBAAqB;QACrB,SAAS;QACT,eAAe;QACf,YAAY;QACZ,sBAAsB;QACtB,mBAAmB;QACnB,oBAAoB;KACrB,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QACnB,YAAY;QACZ,iBAAiB;QACjB,0BAA0B;QAC1B,eAAe;QACf,0BAA0B;QAC1B,wBAAwB;QACxB,cAAc;QACd,eAAe;QACf,qBAAqB;QACrB,oBAAoB;KACrB,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,wBAAwB,CAAC,CAAC;CAC7E,CAAC,CAAC;AAEH,iCAAiC;AACjC,MAAM,CAAC,MAAM,kBAAkB,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;AAEpF,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAEtF;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAY,EACZ,cAAsB,8BAA8B;IAEpD,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC7B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,WAAW,CAAC,WAAW,EAAE,CAAC;AAC5D,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAKpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAKpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -50,4 +50,6 @@ export * from './admin/index.js';
|
|
|
50
50
|
export * from './storage/index.js';
|
|
51
51
|
// Framework database names (configurable-framework-db, ADR-0037) — append-only.
|
|
52
52
|
export * from './database/index.js';
|
|
53
|
+
// Message delivery ports (G-010) — append-only.
|
|
54
|
+
export * from './messaging/index.js';
|
|
53
55
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,kEAAkE;AAClE,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAEnC,mFAAmF;AACnF,cAAc,qBAAqB,CAAC;AAEpC,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAEnC,gFAAgF;AAChF,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,kEAAkE;AAClE,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAEnC,mFAAmF;AACnF,cAAc,qBAAqB,CAAC;AAEpC,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAEnC,gFAAgF;AAChF,cAAc,qBAAqB,CAAC;AAEpC,gDAAgD;AAChD,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine seam: **Messaging** — framework messages (password reset, invite, email-change
|
|
3
|
+
* confirmation, security notices) leave through a channel port (G-010,
|
|
4
|
+
* docs/features/message-delivery/SPEC.md). Core defines the ports and the failure class; the
|
|
5
|
+
* provider adapters ship in `@astram/messaging` and guard binds, bounds and audits them.
|
|
6
|
+
*
|
|
7
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
|
|
8
|
+
*/
|
|
9
|
+
export type { MessageChannel, MessagePurpose, EmailMessage, SmsMessage, WhatsAppMessage, DeliveryReceipt, SendOptions, CancellationSignal, MessageProvider, EmailProvider, SmsProvider, WhatsAppProvider, DeliveryFailureClass, } from './ports.js';
|
|
10
|
+
export { MESSAGE_PURPOSES, MessageDeliveryError, isE164PhoneNumber } from './ports.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messaging/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine seam: **Messaging** — framework messages (password reset, invite, email-change
|
|
3
|
+
* confirmation, security notices) leave through a channel port (G-010,
|
|
4
|
+
* docs/features/message-delivery/SPEC.md). Core defines the ports and the failure class; the
|
|
5
|
+
* provider adapters ship in `@astram/messaging` and guard binds, bounds and audits them.
|
|
6
|
+
*
|
|
7
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
|
|
8
|
+
*/
|
|
9
|
+
export { MESSAGE_PURPOSES, MessageDeliveryError, isE164PhoneNumber } from './ports.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/messaging/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiBH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message delivery ports (G-010, docs/features/message-delivery/SPEC.md R1). One port per channel,
|
|
3
|
+
* each with its own message shape. Adapters (SMTP, Brevo, SendGrid, Mailgun) ship in
|
|
4
|
+
* `@astram/messaging`; guard binds and audits them. SMS and WhatsApp are ports only until users
|
|
5
|
+
* carry phone numbers (OD-1).
|
|
6
|
+
*
|
|
7
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
|
|
8
|
+
*/
|
|
9
|
+
/** The channels a provider can serve. */
|
|
10
|
+
export type MessageChannel = 'email' | 'sms' | 'whatsapp';
|
|
11
|
+
/** Why the framework sends a message. Recorded on every `message.sent` / `message.failed` row. */
|
|
12
|
+
export declare const MESSAGE_PURPOSES: readonly ["password_reset", "invite", "email_change_confirm", "security_notice"];
|
|
13
|
+
export type MessagePurpose = (typeof MESSAGE_PURPOSES)[number];
|
|
14
|
+
/** An email built by the framework. `html` interpolations are already escaped by the builder. */
|
|
15
|
+
export interface EmailMessage {
|
|
16
|
+
to: string;
|
|
17
|
+
subject: string;
|
|
18
|
+
html: string;
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
/** An SMS. `to` is an E.164 number (`isE164PhoneNumber`). */
|
|
22
|
+
export interface SmsMessage {
|
|
23
|
+
to: string;
|
|
24
|
+
text: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A WhatsApp business-initiated message. Providers accept only pre-approved templates for these,
|
|
28
|
+
* so the message names a template and its positional parameters instead of free text.
|
|
29
|
+
*/
|
|
30
|
+
export interface WhatsAppMessage {
|
|
31
|
+
to: string;
|
|
32
|
+
template: string;
|
|
33
|
+
language: string;
|
|
34
|
+
params: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
/** What a provider returns for an accepted message: its name and its own id, for audit. */
|
|
37
|
+
export interface DeliveryReceipt {
|
|
38
|
+
provider: string;
|
|
39
|
+
messageId?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The part of an `AbortSignal` a provider needs. Core compiles without DOM or Node types, so the
|
|
43
|
+
* port names the shape; a platform `AbortSignal` satisfies it.
|
|
44
|
+
*/
|
|
45
|
+
export interface CancellationSignal {
|
|
46
|
+
readonly aborted: boolean;
|
|
47
|
+
addEventListener(type: 'abort', listener: () => void): void;
|
|
48
|
+
}
|
|
49
|
+
/** Per-send options. The signal aborts the send when the caller's bound expires. */
|
|
50
|
+
export interface SendOptions {
|
|
51
|
+
signal: CancellationSignal;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A provider adapter for one channel. `send` resolves with a receipt or rejects with a
|
|
55
|
+
* `MessageDeliveryError`. `probe` checks reachability and credentials WITHOUT sending a message.
|
|
56
|
+
*/
|
|
57
|
+
export interface MessageProvider<M> {
|
|
58
|
+
readonly name: string;
|
|
59
|
+
send(message: M, options: SendOptions): Promise<DeliveryReceipt>;
|
|
60
|
+
probe?(options: SendOptions): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
export type EmailProvider = MessageProvider<EmailMessage>;
|
|
63
|
+
export type SmsProvider = MessageProvider<SmsMessage>;
|
|
64
|
+
export type WhatsAppProvider = MessageProvider<WhatsAppMessage>;
|
|
65
|
+
/**
|
|
66
|
+
* How a send failed. `transient` (network, 429, 5xx) may be retried once; `permanent` (other 4xx,
|
|
67
|
+
* bad credentials, rejected recipient) never is; `timeout` means the bound expired.
|
|
68
|
+
*/
|
|
69
|
+
export type DeliveryFailureClass = 'transient' | 'permanent' | 'timeout';
|
|
70
|
+
/**
|
|
71
|
+
* A classified delivery failure. The message is built from fixed parts only (provider name,
|
|
72
|
+
* class, HTTP status): never a provider response body, recipient, token or credential.
|
|
73
|
+
*/
|
|
74
|
+
export declare class MessageDeliveryError extends Error {
|
|
75
|
+
readonly failureClass: DeliveryFailureClass;
|
|
76
|
+
readonly provider: string;
|
|
77
|
+
readonly status?: number;
|
|
78
|
+
constructor(failureClass: DeliveryFailureClass, provider: string, detail?: {
|
|
79
|
+
status?: number;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** True for an E.164 number: `+`, a non-zero country digit, 7–15 digits in all, nothing else. */
|
|
83
|
+
export declare function isE164PhoneNumber(value: string): boolean;
|
|
84
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/messa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OAAO,CAAC,eAAe,CAAC,CAAC;IACjE,KAAK,CAAC,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,MAAM,MAAM,aAAa,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;AAC1D,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;AACtD,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG,WAAW,GAAG,SAAS,CAAC;AAEzE;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAGvB,YAAY,EAAE,oBAAoB,EAClC,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;CASnC;AAID,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAExD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message delivery ports (G-010, docs/features/message-delivery/SPEC.md R1). One port per channel,
|
|
3
|
+
* each with its own message shape. Adapters (SMTP, Brevo, SendGrid, Mailgun) ship in
|
|
4
|
+
* `@astram/messaging`; guard binds and audits them. SMS and WhatsApp are ports only until users
|
|
5
|
+
* carry phone numbers (OD-1).
|
|
6
|
+
*
|
|
7
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
|
|
8
|
+
*/
|
|
9
|
+
/** Why the framework sends a message. Recorded on every `message.sent` / `message.failed` row. */
|
|
10
|
+
export const MESSAGE_PURPOSES = Object.freeze([
|
|
11
|
+
'password_reset',
|
|
12
|
+
'invite',
|
|
13
|
+
'email_change_confirm',
|
|
14
|
+
'security_notice',
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* A classified delivery failure. The message is built from fixed parts only (provider name,
|
|
18
|
+
* class, HTTP status): never a provider response body, recipient, token or credential.
|
|
19
|
+
*/
|
|
20
|
+
export class MessageDeliveryError extends Error {
|
|
21
|
+
failureClass;
|
|
22
|
+
provider;
|
|
23
|
+
status;
|
|
24
|
+
constructor(failureClass, provider, detail = {}) {
|
|
25
|
+
const status = detail.status !== undefined ? `, HTTP ${detail.status}` : '';
|
|
26
|
+
super(`${provider} delivery failed (${failureClass}${status})`);
|
|
27
|
+
this.name = 'MessageDeliveryError';
|
|
28
|
+
this.failureClass = failureClass;
|
|
29
|
+
this.provider = provider;
|
|
30
|
+
if (detail.status !== undefined)
|
|
31
|
+
this.status = detail.status;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const E164 = /^\+[1-9]\d{6,14}$/;
|
|
35
|
+
/** True for an E.164 number: `+`, a non-zero country digit, 7–15 digits in all, nothing else. */
|
|
36
|
+
export function isE164PhoneNumber(value) {
|
|
37
|
+
return E164.test(value);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=ports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/messaging/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,kGAAkG;AAClG,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,gBAAgB;IAChB,QAAQ;IACR,sBAAsB;IACtB,iBAAiB;CACT,CAAC,CAAC;AAoEZ;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACpC,YAAY,CAAuB;IACnC,QAAQ,CAAS;IACjB,MAAM,CAAU;IAEzB,YACE,YAAkC,EAClC,QAAgB,EAChB,SAA8B,EAAE;QAEhC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,KAAK,CAAC,GAAG,QAAQ,qBAAqB,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/D,CAAC;CACF;AAED,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC,iGAAiG;AACjG,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
*/
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
exports.GENESIS = void 0;
|
|
46
|
+
exports.linkEntry = linkEntry;
|
|
46
47
|
exports.createAuditRecorder = createAuditRecorder;
|
|
47
48
|
exports.verifyChain = verifyChain;
|
|
48
49
|
const canonicalize_js_1 = require("./canonicalize.js");
|
|
@@ -66,6 +67,23 @@ const CHAIN_SEP = '|';
|
|
|
66
67
|
function entryPreimage(contentHash, prevHash, sequenceNumber) {
|
|
67
68
|
return `${contentHash}${CHAIN_SEP}${prevHash}${CHAIN_SEP}${sequenceNumber}`;
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* The pure chain math for ONE event (§3): `contentHash = H(canonicalize(content))`,
|
|
72
|
+
* `sequenceNumber = prev.sequenceNumber + 1` (or `0`), `prevHash = prev.entryHash`
|
|
73
|
+
* (or {@link GENESIS}), `entryHash = H(contentHash ‖ prevHash ‖ sequenceNumber)`.
|
|
74
|
+
*
|
|
75
|
+
* `content` is hashed exactly as given: the caller passes the already-cleaned event
|
|
76
|
+
* (the recorder strips secrets first; the sealer builds it from the stored row with
|
|
77
|
+
* `auditEventFromRow`). Equal inputs give equal outputs. `prev.tenantId` is not read
|
|
78
|
+
* here; the caller keeps chains per tenant.
|
|
79
|
+
*/
|
|
80
|
+
function linkEntry(content, prev, hash) {
|
|
81
|
+
const sequenceNumber = prev !== undefined ? prev.sequenceNumber + 1 : 0;
|
|
82
|
+
const prevHash = prev !== undefined ? prev.entryHash : exports.GENESIS;
|
|
83
|
+
const contentHash = hash.hash((0, canonicalize_js_1.canonicalizeEvent)(content));
|
|
84
|
+
const entryHash = hash.hash(entryPreimage(contentHash, prevHash, sequenceNumber));
|
|
85
|
+
return { sequenceNumber, contentHash, prevHash, entryHash };
|
|
86
|
+
}
|
|
69
87
|
/**
|
|
70
88
|
* A non-blank string guard — an actor/tenant id must be a present, non-whitespace
|
|
71
89
|
* string. (`.trim()` catches `' '`, which a bare `length === 0` would miss.)
|
|
@@ -134,10 +152,13 @@ function createAuditRecorder(deps) {
|
|
|
134
152
|
// prevHash from it. Per-tenant: `readChain` only returns THIS tenant's records.
|
|
135
153
|
const chain = await store.readChain(event.tenantId);
|
|
136
154
|
const tail = chain.length > 0 ? chain[chain.length - 1] : undefined;
|
|
137
|
-
const sequenceNumber
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
const { sequenceNumber, contentHash, prevHash, entryHash } = linkEntry(cleanEvent, tail !== undefined
|
|
156
|
+
? {
|
|
157
|
+
tenantId: tail.tenantId,
|
|
158
|
+
sequenceNumber: tail.sequenceNumber,
|
|
159
|
+
entryHash: tail.entryHash,
|
|
160
|
+
}
|
|
161
|
+
: undefined, hash);
|
|
141
162
|
// ── (4) STAMP (AC-9). The engine's own clock — distinct from occurredAtMs.
|
|
142
163
|
const recordedAtMs = clock.nowMs();
|
|
143
164
|
const stored = {
|
|
@@ -205,17 +226,24 @@ function createAuditRecorder(deps) {
|
|
|
205
226
|
* - `content_mismatch` — the recomputed `contentHash`/`entryHash` ≠ the stored
|
|
206
227
|
* ones: a field of the record was mutated.
|
|
207
228
|
*
|
|
229
|
+
* With an `anchor` (a pruned chain's checkpoint, or the last record of the previous
|
|
230
|
+
* page), the chain is expected to continue from it: the expected tenant is
|
|
231
|
+
* `anchor.tenantId` (a foreign first record is reported at index 0), the first
|
|
232
|
+
* sequence `anchor.sequenceNumber + 1` and the first `prevHash` `anchor.entryHash`.
|
|
233
|
+
* Without one, the chain must start at sequence 0 from {@link GENESIS}.
|
|
234
|
+
*
|
|
208
235
|
* @param records An ordered, single-tenant chain (sequence ascending).
|
|
209
236
|
* @param hash The SAME deterministic hash used to write the chain.
|
|
237
|
+
* @param anchor Optional position the records continue from.
|
|
210
238
|
*/
|
|
211
|
-
function verifyChain(records, hash) {
|
|
212
|
-
let expectedPrevHash = exports.GENESIS;
|
|
213
|
-
let expectedSequence = 0;
|
|
214
|
-
// The chain is contractually SINGLE-tenant. Pin the expected tenant to the
|
|
215
|
-
// record's; any
|
|
216
|
-
// (a foreign record chained on at the right sequence can self-verify) and MUST
|
|
217
|
-
// rejected. An empty array
|
|
218
|
-
const expectedTenantId = records.length > 0 ? records[0]?.tenantId : undefined;
|
|
239
|
+
function verifyChain(records, hash, anchor) {
|
|
240
|
+
let expectedPrevHash = anchor !== undefined ? anchor.entryHash : exports.GENESIS;
|
|
241
|
+
let expectedSequence = anchor !== undefined ? anchor.sequenceNumber + 1 : 0;
|
|
242
|
+
// The chain is contractually SINGLE-tenant. Pin the expected tenant to the anchor's
|
|
243
|
+
// (else the first record's); any record with a different `tenantId` is a cross-tenant
|
|
244
|
+
// splice (a foreign record chained on at the right sequence can self-verify) and MUST
|
|
245
|
+
// be rejected. An empty array is vacuously intact (loop does not run).
|
|
246
|
+
const expectedTenantId = anchor !== undefined ? anchor.tenantId : records.length > 0 ? records[0]?.tenantId : undefined;
|
|
219
247
|
for (let i = 0; i < records.length; i++) {
|
|
220
248
|
const record = records[i];
|
|
221
249
|
if (record === undefined) {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Stored-row mapping for the durable audit chain (audit-chain-store SPEC §5.D).
|
|
4
|
+
*
|
|
5
|
+
* `auditEventFromRow` is THE one mapping from an `audit_log` row back to the
|
|
6
|
+
* {@link AuditEvent} whose canonical form is hashed into the chain. The sealer (guard)
|
|
7
|
+
* and the verifier (`astram-migrate audit:verify`) both use it, so the content they
|
|
8
|
+
* hash is built the same way from the same stored columns. It is the inverse of the
|
|
9
|
+
* one INSERT shape (`@astram/engine` `MariaDbAuditSink.record`):
|
|
10
|
+
* - `al_type`, `al_actor_id`, `al_tenant_id` ⇒ `type`, `actorId`, `tenantId`;
|
|
11
|
+
* - `al_occurred_at_ms` (BIGINT) ⇒ `occurredAtMs` via {@link toSafeInteger};
|
|
12
|
+
* - `al_action_key` ⇒ `action: { key }`;
|
|
13
|
+
* - `al_resource_json`, `al_decision_json`, `al_attributes_json` ⇒ the parsed value
|
|
14
|
+
* (the driver may return JSON text or an already-parsed value);
|
|
15
|
+
* - SQL NULL ⇒ the field is absent (never `undefined`-valued, never `null`);
|
|
16
|
+
* - `al_uuid` is the row key, not content: it is never part of the event.
|
|
17
|
+
*
|
|
18
|
+
* BIGINT values never reach the hashed content as `bigint` (`canonicalizeEvent`
|
|
19
|
+
* rejects them): they are converted to a safe `number` or the row is rejected with a
|
|
20
|
+
* typed {@link AuditRowError}. A JSON column whose text does not parse is also rejected
|
|
21
|
+
* typed (`invalid_json`), so the sealer can tell a repeating row problem from a
|
|
22
|
+
* transient database error.
|
|
23
|
+
*
|
|
24
|
+
* Kept in its own file (not `audit-recorder.ts`): it is row/driver shape knowledge,
|
|
25
|
+
* not chain math, and the recorder stays independent of any storage layout.
|
|
26
|
+
*
|
|
27
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.toSafeInteger = toSafeInteger;
|
|
31
|
+
exports.auditEventFromRow = auditEventFromRow;
|
|
32
|
+
const errors_js_1 = require("./errors.js");
|
|
33
|
+
const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
|
|
34
|
+
const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
|
|
35
|
+
/** Optional sign, then decimal digits only; 17 digits already exceed the safe range. */
|
|
36
|
+
const DECIMAL_INTEGER = /^-?[0-9]{1,20}$/;
|
|
37
|
+
/**
|
|
38
|
+
* Convert a BIGINT column value (`number`, `bigint`, or decimal-integer string) to a
|
|
39
|
+
* JS `number`, refusing anything that is not exactly representable: a non-integer, a
|
|
40
|
+
* value outside `Number.MIN_SAFE_INTEGER..MAX_SAFE_INTEGER`, `NaN`/`±Infinity`, an
|
|
41
|
+
* empty or non-decimal string, `null`, `undefined` or any other type ⇒
|
|
42
|
+
* `AuditRowError('unsafe_integer')` (the value is never put in the message).
|
|
43
|
+
*
|
|
44
|
+
* Used for `al_occurred_at_ms`, `ac_sequence` and `acc_sequence`.
|
|
45
|
+
*/
|
|
46
|
+
function toSafeInteger(value) {
|
|
47
|
+
const v = value;
|
|
48
|
+
if (typeof v === 'number') {
|
|
49
|
+
if (!Number.isSafeInteger(v))
|
|
50
|
+
throw new errors_js_1.AuditRowError('unsafe_integer');
|
|
51
|
+
return v === 0 ? 0 : v; // normalize -0
|
|
52
|
+
}
|
|
53
|
+
if (typeof v === 'bigint') {
|
|
54
|
+
if (v > MAX_SAFE || v < MIN_SAFE)
|
|
55
|
+
throw new errors_js_1.AuditRowError('unsafe_integer');
|
|
56
|
+
return Number(v);
|
|
57
|
+
}
|
|
58
|
+
if (typeof v === 'string' && DECIMAL_INTEGER.test(v)) {
|
|
59
|
+
return toSafeInteger(BigInt(v));
|
|
60
|
+
}
|
|
61
|
+
throw new errors_js_1.AuditRowError('unsafe_integer');
|
|
62
|
+
}
|
|
63
|
+
/** A JSON column: SQL NULL (or a parsed JSON null) ⇒ absent; text ⇒ parsed; else as given. */
|
|
64
|
+
function jsonColumn(value) {
|
|
65
|
+
if (value === null || value === undefined)
|
|
66
|
+
return undefined;
|
|
67
|
+
if (typeof value !== 'string')
|
|
68
|
+
return value;
|
|
69
|
+
let parsed;
|
|
70
|
+
try {
|
|
71
|
+
parsed = JSON.parse(value);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
throw new errors_js_1.AuditRowError('invalid_json');
|
|
75
|
+
}
|
|
76
|
+
return parsed === null ? undefined : parsed;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Map one stored `audit_log` row to the {@link AuditEvent} that is hashed into the
|
|
80
|
+
* chain (see the file header for the column mapping). Throws {@link AuditRowError}
|
|
81
|
+
* for an unsafe BIGINT or unparseable JSON text.
|
|
82
|
+
*/
|
|
83
|
+
function auditEventFromRow(row) {
|
|
84
|
+
const occurredAtMs = toSafeInteger(row.al_occurred_at_ms);
|
|
85
|
+
const actionKey = row.al_action_key;
|
|
86
|
+
const resource = jsonColumn(row.al_resource_json);
|
|
87
|
+
const decision = jsonColumn(row.al_decision_json);
|
|
88
|
+
const attributes = jsonColumn(row.al_attributes_json);
|
|
89
|
+
const action = actionKey !== null && actionKey !== undefined ? { key: actionKey } : undefined;
|
|
90
|
+
return {
|
|
91
|
+
type: row.al_type,
|
|
92
|
+
occurredAtMs,
|
|
93
|
+
actorId: row.al_actor_id,
|
|
94
|
+
tenantId: row.al_tenant_id,
|
|
95
|
+
...(action !== undefined ? { action } : {}),
|
|
96
|
+
...(resource !== undefined ? { resource: resource } : {}),
|
|
97
|
+
...(decision !== undefined ? { decision: decision } : {}),
|
|
98
|
+
...(attributes !== undefined
|
|
99
|
+
? { attributes: attributes }
|
|
100
|
+
: {}),
|
|
101
|
+
};
|
|
102
|
+
}
|
package/dist-cjs/audit/errors.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.AuditValidationError = void 0;
|
|
21
|
+
exports.AuditRowError = exports.AuditValidationError = void 0;
|
|
22
22
|
/**
|
|
23
23
|
* Thrown by `record()` when an {@link import('./index.js').AuditEvent} fails the
|
|
24
24
|
* attribution / tenant-scope / UTC-time gate (AC-2): a blank/absent `actorId`, a
|
|
@@ -42,3 +42,22 @@ class AuditValidationError extends Error {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
exports.AuditValidationError = AuditValidationError;
|
|
45
|
+
/**
|
|
46
|
+
* Thrown by `auditEventFromRow` / `toSafeInteger` (`./audit-row.ts`) when a STORED
|
|
47
|
+
* row cannot be turned back into the exact `AuditEvent` that is hashed. A repeating
|
|
48
|
+
* error: the same row fails the same way on every retry, so the sealer parks that
|
|
49
|
+
* tenant until the next sweep (SPEC §5.G). Names the reason only; NEVER carries the
|
|
50
|
+
* offending value (it comes from the database and could be anything).
|
|
51
|
+
*/
|
|
52
|
+
class AuditRowError extends Error {
|
|
53
|
+
/** The specific row problem. */
|
|
54
|
+
reason;
|
|
55
|
+
constructor(reason) {
|
|
56
|
+
super(`audit_row_rejected:${reason}`);
|
|
57
|
+
this.name = 'AuditRowError';
|
|
58
|
+
this.reason = reason;
|
|
59
|
+
// Preserve the prototype chain when compiled down-level so `instanceof` works.
|
|
60
|
+
Object.setPrototypeOf(this, AuditRowError.prototype);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.AuditRowError = AuditRowError;
|
package/dist-cjs/audit/index.js
CHANGED
|
@@ -37,3 +37,6 @@ __exportStar(require("./errors.js"), exports);
|
|
|
37
37
|
// - the tamper-evident recorder `createAuditRecorder` (IS an AuditSink) + the pure
|
|
38
38
|
// `verifyChain` primitive + the GENESIS chain constant:
|
|
39
39
|
__exportStar(require("./audit-recorder.js"), exports);
|
|
40
|
+
// - the stored-row mapping for the durable chain (`auditEventFromRow`, `toSafeInteger`,
|
|
41
|
+
// `AuditLogRow`); `linkEntry` / `ChainAnchor` come from `./audit-recorder.js` above:
|
|
42
|
+
__exportStar(require("./audit-row.js"), exports);
|
package/dist-cjs/audit/ports.js
CHANGED
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
* knowing which crypto / DB backs them.
|
|
7
7
|
*
|
|
8
8
|
* ADR-0003 (zero-dep Core): every concrete adapter (`node:crypto` SHA-256, the
|
|
9
|
-
* append-only MariaDB `
|
|
10
|
-
* CANNOT live here. The Core defines only these interfaces
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* append-only MariaDB `<ns>_audit` tables) is a real runtime dependency and
|
|
10
|
+
* CANNOT live here. The Core defines only these interfaces. `@astram/guard` ships
|
|
11
|
+
* the SHA-256 `HashFunction` and the deferred sealer (`AuditChainSealer`,
|
|
12
|
+
* audit-chain-store SPEC §5.G), which chains committed `audit_log` rows with
|
|
13
|
+
* `linkEntry` instead of injecting a store into `createAuditRecorder(...)`. This
|
|
14
|
+
* keeps `@astram/core` at ZERO runtime dependencies (the load-bearing invariant)
|
|
15
|
+
* while the substrate stays swappable.
|
|
14
16
|
*
|
|
15
17
|
* ⛔ SECURITY — the audit engine records for INTEGRITY, not confidentiality. It
|
|
16
18
|
* NEVER persists a secret value (a denylist strips secret-bearing keys before a
|
|
@@ -47,7 +47,7 @@ exports.FRAMEWORK_TABLES = Object.freeze({
|
|
|
47
47
|
'service_account_key',
|
|
48
48
|
'cross_tenant_grant',
|
|
49
49
|
]),
|
|
50
|
-
audit: Object.freeze(['audit_log']),
|
|
50
|
+
audit: Object.freeze(['audit_log', 'audit_chain', 'audit_chain_checkpoint']),
|
|
51
51
|
});
|
|
52
52
|
/** Framework stored routines. */
|
|
53
53
|
exports.FRAMEWORK_ROUTINES = Object.freeze(['prune_audit']);
|
package/dist-cjs/index.js
CHANGED
|
@@ -66,3 +66,5 @@ __exportStar(require("./admin/index.js"), exports);
|
|
|
66
66
|
__exportStar(require("./storage/index.js"), exports);
|
|
67
67
|
// Framework database names (configurable-framework-db, ADR-0037) — append-only.
|
|
68
68
|
__exportStar(require("./database/index.js"), exports);
|
|
69
|
+
// Message delivery ports (G-010) — append-only.
|
|
70
|
+
__exportStar(require("./messaging/index.js"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Engine seam: **Messaging** — framework messages (password reset, invite, email-change
|
|
4
|
+
* confirmation, security notices) leave through a channel port (G-010,
|
|
5
|
+
* docs/features/message-delivery/SPEC.md). Core defines the ports and the failure class; the
|
|
6
|
+
* provider adapters ship in `@astram/messaging` and guard binds, bounds and audits them.
|
|
7
|
+
*
|
|
8
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.isE164PhoneNumber = exports.MessageDeliveryError = exports.MESSAGE_PURPOSES = void 0;
|
|
12
|
+
var ports_js_1 = require("./ports.js");
|
|
13
|
+
Object.defineProperty(exports, "MESSAGE_PURPOSES", { enumerable: true, get: function () { return ports_js_1.MESSAGE_PURPOSES; } });
|
|
14
|
+
Object.defineProperty(exports, "MessageDeliveryError", { enumerable: true, get: function () { return ports_js_1.MessageDeliveryError; } });
|
|
15
|
+
Object.defineProperty(exports, "isE164PhoneNumber", { enumerable: true, get: function () { return ports_js_1.isE164PhoneNumber; } });
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Message delivery ports (G-010, docs/features/message-delivery/SPEC.md R1). One port per channel,
|
|
4
|
+
* each with its own message shape. Adapters (SMTP, Brevo, SendGrid, Mailgun) ship in
|
|
5
|
+
* `@astram/messaging`; guard binds and audits them. SMS and WhatsApp are ports only until users
|
|
6
|
+
* carry phone numbers (OD-1).
|
|
7
|
+
*
|
|
8
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.MessageDeliveryError = exports.MESSAGE_PURPOSES = void 0;
|
|
12
|
+
exports.isE164PhoneNumber = isE164PhoneNumber;
|
|
13
|
+
/** Why the framework sends a message. Recorded on every `message.sent` / `message.failed` row. */
|
|
14
|
+
exports.MESSAGE_PURPOSES = Object.freeze([
|
|
15
|
+
'password_reset',
|
|
16
|
+
'invite',
|
|
17
|
+
'email_change_confirm',
|
|
18
|
+
'security_notice',
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* A classified delivery failure. The message is built from fixed parts only (provider name,
|
|
22
|
+
* class, HTTP status): never a provider response body, recipient, token or credential.
|
|
23
|
+
*/
|
|
24
|
+
class MessageDeliveryError extends Error {
|
|
25
|
+
failureClass;
|
|
26
|
+
provider;
|
|
27
|
+
status;
|
|
28
|
+
constructor(failureClass, provider, detail = {}) {
|
|
29
|
+
const status = detail.status !== undefined ? `, HTTP ${detail.status}` : '';
|
|
30
|
+
super(`${provider} delivery failed (${failureClass}${status})`);
|
|
31
|
+
this.name = 'MessageDeliveryError';
|
|
32
|
+
this.failureClass = failureClass;
|
|
33
|
+
this.provider = provider;
|
|
34
|
+
if (detail.status !== undefined)
|
|
35
|
+
this.status = detail.status;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.MessageDeliveryError = MessageDeliveryError;
|
|
39
|
+
const E164 = /^\+[1-9]\d{6,14}$/;
|
|
40
|
+
/** True for an E.164 number: `+`, a non-zero country digit, 7–15 digits in all, nothing else. */
|
|
41
|
+
function isE164PhoneNumber(value) {
|
|
42
|
+
return E164.test(value);
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astram/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Astram framework — sealed security core (Identity, Authentication, Session, Risk, Authorization, Audit). ZERO framework deps — the portable decision brain (ADR-0003). The frozen public contract consumers build against; installed, not edited (ADR-0023).",
|
|
6
6
|
"type": "module",
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
"typescript": "^5.7.0",
|
|
28
28
|
"vitest": "^2.1.8"
|
|
29
29
|
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/ASTRAM-2-0/astram-framework.git",
|
|
33
|
+
"directory": "packages/core"
|
|
34
|
+
},
|
|
30
35
|
"scripts": {
|
|
31
36
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/write-cjs-marker.mjs",
|
|
32
37
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|