@uuaid/pillar 2.8.1 → 2.8.3
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/README.md +258 -2
- package/package.json +3 -1
- package/src/groups-v2-admin.mjs +3 -0
- package/src/groups-v2.mjs +198 -5
- package/src/mailbox/mailbox.mjs +36 -5
- package/src/net/carrier-client.mjs +81 -9
- package/src/net/seed-registry.mjs +9 -1
- package/src/net/seed-routes.mjs +214 -0
- package/src/net/tunnel-relay.mjs +12 -0
- package/src/pillar.mjs +547 -65
- package/src/registry/stats.mjs +1 -1
- package/src/send-permit.mjs +66 -0
- package/src/vnext/json-dir-mailbox.mjs +3 -0
- package/src/vnext/jsonl-mailbox.mjs +38 -2
- package/src/vnext/retired-import.mjs +4 -1
- package/src/vnext/verify-cli.mjs +1 -1
package/src/registry/stats.mjs
CHANGED
|
@@ -52,7 +52,7 @@ export const TTFA_METHODS = Object.freeze(["ci-canary", "field-cohort"]);
|
|
|
52
52
|
export const TTFA_MIN_N = 10;
|
|
53
53
|
|
|
54
54
|
/** Tool stamped on B8 verdicts (same string the `pillar verify` CLI uses). */
|
|
55
|
-
export const STATS_VERDICT_TOOL = "pillar/2.8.
|
|
55
|
+
export const STATS_VERDICT_TOOL = "pillar/2.8.3";
|
|
56
56
|
|
|
57
57
|
/** Closed key set of `pillar-ttfa-report/1`. */
|
|
58
58
|
export const TTFA_REPORT_KEYS = Object.freeze([
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Optional, instance-bound outbound policy. No payload, keys or exception text crosses this boundary. */
|
|
2
|
+
export const SEND_PERMIT_DENIED = "send-permit-denied";
|
|
3
|
+
// Denials this SDK raised. The code string alone proves nothing: a carrier's refusal reason, a
|
|
4
|
+
// transport error or a caller's own error can carry the same text.
|
|
5
|
+
const DENIALS = new WeakSet();
|
|
6
|
+
|
|
7
|
+
export function sendPermitDenied(partial = null) {
|
|
8
|
+
const error = new Error("outbound send permission denied");
|
|
9
|
+
error.code = SEND_PERMIT_DENIED;
|
|
10
|
+
if (partial) error.partial = partial;
|
|
11
|
+
DENIALS.add(error);
|
|
12
|
+
return error;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A denial raised here (permit, outbound policy or abort), never one that only names the code. */
|
|
16
|
+
export function isSendPermitDenied(error) {
|
|
17
|
+
if (!DENIALS.has(error)) return false; // @spaces-check denial-by-identity
|
|
18
|
+
return error?.code === SEND_PERMIT_DENIED;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The code a caller may match on. The reserved denial code survives only on a real denial. */
|
|
22
|
+
export function sendErrorCode(error) {
|
|
23
|
+
const code = typeof error?.code === "string" ? error.code : null;
|
|
24
|
+
return code === SEND_PERMIT_DENIED && !isSendPermitDenied(error) ? null : code;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function assertSendNotAborted(signal) {
|
|
28
|
+
if (signal?.aborted) throw sendPermitDenied();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Null preserves the omitted-option path (including its scheduling/parallelism). */
|
|
32
|
+
export function createSendGuard({ outboundPolicy = null, permit = null, signal = null, context = {} } = {}) {
|
|
33
|
+
if (outboundPolicy == null && permit == null && signal == null) return null;
|
|
34
|
+
for (const policy of [outboundPolicy, permit]) {
|
|
35
|
+
if (policy != null && typeof policy !== "function") throw sendPermitDenied();
|
|
36
|
+
}
|
|
37
|
+
if (signal != null && !(signal instanceof AbortSignal)) throw sendPermitDenied();
|
|
38
|
+
return async (details = {}) => {
|
|
39
|
+
assertSendNotAborted(signal);
|
|
40
|
+
const fields = { phase: "seal", route: "auto", recipient: null, groupId: null, op: null, ...context, ...details };
|
|
41
|
+
// Only scalar routing metadata reaches policy callbacks, never caller objects.
|
|
42
|
+
const dto = Object.freeze({ phase: fields.phase, route: fields.route,
|
|
43
|
+
recipient: typeof fields.recipient === "string" ? fields.recipient : null,
|
|
44
|
+
groupId: typeof fields.groupId === "string" ? fields.groupId : null,
|
|
45
|
+
op: typeof fields.op === "string" ? fields.op : null,
|
|
46
|
+
...(typeof fields.carrier === "string" ? { carrier: fields.carrier } : {}) });
|
|
47
|
+
for (const policy of [outboundPolicy, permit]) {
|
|
48
|
+
if (!policy) continue;
|
|
49
|
+
let allowed;
|
|
50
|
+
try { allowed = await policy(dto); } catch { throw sendPermitDenied(); }
|
|
51
|
+
assertSendNotAborted(signal);
|
|
52
|
+
if (allowed !== true) throw sendPermitDenied(); // @spaces-check send-permit-exact-true
|
|
53
|
+
}
|
|
54
|
+
// A consent callback may await a dialog or itself retire the host. Re-read
|
|
55
|
+
// the instance baseline after it, before giving the caller its final gate.
|
|
56
|
+
if (outboundPolicy && permit) {
|
|
57
|
+
let allowed;
|
|
58
|
+
try { allowed = outboundPolicy(dto); if (allowed && typeof allowed.then === "function") allowed = await allowed; }
|
|
59
|
+
catch { throw sendPermitDenied(); }
|
|
60
|
+
assertSendNotAborted(signal);
|
|
61
|
+
if (allowed !== true) throw sendPermitDenied();
|
|
62
|
+
}
|
|
63
|
+
assertSendNotAborted(signal);
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -283,14 +283,17 @@ export class JsonDirMailboxReader {
|
|
|
283
283
|
|
|
284
284
|
eraseRows() { return this._readOnly("eraseRows"); }
|
|
285
285
|
setCarrierCursor() { return this._readOnly("setCarrierCursor"); }
|
|
286
|
+
deleteCarrierCursor() { return this._readOnly("deleteCarrierCursor"); }
|
|
286
287
|
appendOutbound() { return this._readOnly("appendOutbound"); }
|
|
287
288
|
appendInbound() { return this._readOnly("appendInbound"); }
|
|
288
289
|
markOutboundDelivered() { return this._readOnly("markOutboundDelivered"); }
|
|
290
|
+
markOutboundSuperseded() { return this._readOnly("markOutboundSuperseded"); }
|
|
289
291
|
admitKnock() { return this._readOnly("admitKnock"); }
|
|
290
292
|
markKnockAnswered() { return this._readOnly("markKnockAnswered"); }
|
|
291
293
|
markQuarantined() { return this._readOnly("markQuarantined"); }
|
|
292
294
|
enqueueGroupV2Sends() { return this._readOnly("enqueueGroupV2Sends"); }
|
|
293
295
|
markGroupV2Send() { return this._readOnly("markGroupV2Send"); }
|
|
296
|
+
claimGroupV2Attempt() { return this._readOnly("claimGroupV2Attempt"); }
|
|
294
297
|
releaseQuarantined() { return this._readOnly("releaseQuarantined"); }
|
|
295
298
|
markInboxRead() { return this._readOnly("markInboxRead"); }
|
|
296
299
|
setInboundGroup() { return this._readOnly("setInboundGroup"); }
|
|
@@ -423,6 +423,15 @@ export class JsonlMailboxStore {
|
|
|
423
423
|
this._writeJsonObj("cursors", this.cursorsPath, cursors);
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
+
/** 2.8.3: forget one carrier's cursor (Pillar#setSeedRoutes drops a removed seed's). True when one went. */
|
|
427
|
+
deleteCarrierCursor(carrier) {
|
|
428
|
+
const cursors = this.getCarrierCursors();
|
|
429
|
+
if (!Object.hasOwn(cursors, carrier)) return false;
|
|
430
|
+
delete cursors[carrier];
|
|
431
|
+
this._writeJsonObj("cursors", this.cursorsPath, cursors);
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
|
|
426
435
|
// ── Outbox & Inbox ─────────────────────────────────────────────────────────
|
|
427
436
|
|
|
428
437
|
appendOutbound(envelope, { thread = null, groupId = null, groupMsgId = null } = {}) {
|
|
@@ -550,6 +559,16 @@ export class JsonlMailboxStore {
|
|
|
550
559
|
if (changed) this._writeJsonl("outbox", this.outboxPath, rows);
|
|
551
560
|
}
|
|
552
561
|
|
|
562
|
+
/** 2.8.2 r2: Mailbox#markOutboundSuperseded (a live pending row only). */
|
|
563
|
+
markOutboundSuperseded(envelopeId) {
|
|
564
|
+
const rows = this._outboxRows();
|
|
565
|
+
let changed = false;
|
|
566
|
+
for (const r of rows) {
|
|
567
|
+
if (r.envelope_id === envelopeId && r.status === "pending" && !isErased(r)) { r.status = "superseded"; changed = true; }
|
|
568
|
+
}
|
|
569
|
+
if (changed) this._writeJsonl("outbox", this.outboxPath, rows);
|
|
570
|
+
}
|
|
571
|
+
|
|
553
572
|
outboxTip() {
|
|
554
573
|
const rows = this._outboxRows();
|
|
555
574
|
return rows.length > 0 ? rows[rows.length - 1].chain_hash : EMPTY_TIP;
|
|
@@ -903,15 +922,29 @@ export class JsonlMailboxStore {
|
|
|
903
922
|
.sort((a, b) => (a.queued_at < b.queued_at ? -1 : a.queued_at > b.queued_at ? 1 : 0));
|
|
904
923
|
}
|
|
905
924
|
|
|
906
|
-
markGroupV2Send
|
|
925
|
+
/** Mailbox#markGroupV2Send; with `attempt`, only a queued item that still names it (2.8.2 r4). True when written. */
|
|
926
|
+
markGroupV2Send(id, state, { envelopeId = null, reason = null, attempt } = {}) {
|
|
907
927
|
const q = this._readJsonObj("sendq", this.sendqPath, []);
|
|
908
928
|
const row = q.find((x) => x.id === id);
|
|
909
|
-
if (!row) return;
|
|
929
|
+
if (!row) return false;
|
|
930
|
+
if (attempt !== undefined && (row.state !== "queued" || (row.envelope_id ?? null) !== attempt)) return false;
|
|
910
931
|
row.state = state;
|
|
911
932
|
row.state_at = new Date().toISOString();
|
|
912
933
|
if (envelopeId != null) row.envelope_id = envelopeId;
|
|
913
934
|
row.reason = reason ? String(reason).slice(0, 200) : null;
|
|
914
935
|
this._writeJsonObj("sendq", this.sendqPath, q);
|
|
936
|
+
return true;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/** 2.8.2 r3: Mailbox#claimGroupV2Attempt (a queued item that still names `expected`). */
|
|
940
|
+
claimGroupV2Attempt(id, expected, next) {
|
|
941
|
+
const q = this._readJsonObj("sendq", this.sendqPath, []);
|
|
942
|
+
const row = q.find((x) => x.id === id);
|
|
943
|
+
if (!row || row.state !== "queued" || (row.envelope_id ?? null) !== (expected ?? null)) return false;
|
|
944
|
+
row.envelope_id = next;
|
|
945
|
+
row.state_at = new Date().toISOString();
|
|
946
|
+
this._writeJsonObj("sendq", this.sendqPath, q);
|
|
947
|
+
return true;
|
|
915
948
|
}
|
|
916
949
|
|
|
917
950
|
// ── Readers & Leases ───────────────────────────────────────────────────────
|
|
@@ -1247,9 +1280,11 @@ export class JsonlMailboxStore {
|
|
|
1247
1280
|
*/
|
|
1248
1281
|
export const LOCKED_METHODS = Object.freeze([
|
|
1249
1282
|
"setCarrierCursor",
|
|
1283
|
+
"deleteCarrierCursor",
|
|
1250
1284
|
"appendOutbound",
|
|
1251
1285
|
"appendInbound",
|
|
1252
1286
|
"markOutboundDelivered",
|
|
1287
|
+
"markOutboundSuperseded",
|
|
1253
1288
|
"admitKnock",
|
|
1254
1289
|
"markKnockAnswered",
|
|
1255
1290
|
"markQuarantined",
|
|
@@ -1258,6 +1293,7 @@ export const LOCKED_METHODS = Object.freeze([
|
|
|
1258
1293
|
"setInboundGroup",
|
|
1259
1294
|
"enqueueGroupV2Sends",
|
|
1260
1295
|
"markGroupV2Send",
|
|
1296
|
+
"claimGroupV2Attempt",
|
|
1261
1297
|
"touchReader",
|
|
1262
1298
|
"setReaderCursor",
|
|
1263
1299
|
"holdLease",
|
|
@@ -497,7 +497,10 @@ export async function importRetiredMail(pillar, { now = new Date().toISOString()
|
|
|
497
497
|
catch (e) { out.errors.push({ uuaid: r.uuaid, error: `archive key: ${e.message}` }); continue; }
|
|
498
498
|
pillar.metrics?.inc?.("continuity.import.archive-key-load");
|
|
499
499
|
out.keys++;
|
|
500
|
-
const
|
|
500
|
+
const clientOpts = { keychain: kc, carriers: pillar.carriers };
|
|
501
|
+
// 2.8.2: a retired key's inbox auth follows the same trustedCarriers rule as the current key's.
|
|
502
|
+
if (pillar.trustedCarriers != null) clientOpts.trustedCarriers = pillar.trustedCarriers; // @t282 retired-trusted
|
|
503
|
+
const client = new CarrierClient(clientOpts);
|
|
501
504
|
for (const base of pillar.carriers) {
|
|
502
505
|
const key = `${base}#${r.uuaid}`;
|
|
503
506
|
let since = r.cursors?.[base] ?? 0;
|
package/src/vnext/verify-cli.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
verifyStatsArtifact,
|
|
32
32
|
} from "../registry/stats.mjs";
|
|
33
33
|
|
|
34
|
-
export const VERIFY_CLI_TOOL = "pillar/2.8.
|
|
34
|
+
export const VERIFY_CLI_TOOL = "pillar/2.8.3";
|
|
35
35
|
const TYPE_SET = new Set([...VERIFY_TYPES, TTFA_VERDICT_TYPE, REGISTRY_STATS_VERDICT_TYPE]);
|
|
36
36
|
|
|
37
37
|
const VALUE_FLAGS = new Set([
|