@decionis/agentsafe 0.7.0 → 0.8.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/README.md +6 -1
- package/dist/Cli.js +13 -3
- package/dist/Cli.js.map +1 -1
- package/dist/acceptance/AcceptancePlan.d.ts +109 -0
- package/dist/acceptance/AcceptancePlan.d.ts.map +1 -0
- package/dist/acceptance/AcceptancePlan.js +128 -0
- package/dist/acceptance/AcceptancePlan.js.map +1 -0
- package/dist/acceptance/AcceptanceReport.d.ts +596 -0
- package/dist/acceptance/AcceptanceReport.d.ts.map +1 -0
- package/dist/acceptance/AcceptanceReport.js +361 -0
- package/dist/acceptance/AcceptanceReport.js.map +1 -0
- package/dist/acceptance/AcceptanceRun.d.ts +118 -0
- package/dist/acceptance/AcceptanceRun.d.ts.map +1 -0
- package/dist/acceptance/AcceptanceRun.js +419 -0
- package/dist/acceptance/AcceptanceRun.js.map +1 -0
- package/dist/acceptance/Coverage.d.ts +12 -0
- package/dist/acceptance/Coverage.d.ts.map +1 -0
- package/dist/acceptance/Coverage.js +48 -0
- package/dist/acceptance/Coverage.js.map +1 -0
- package/dist/acceptance/OutageDoubles.d.ts +34 -0
- package/dist/acceptance/OutageDoubles.d.ts.map +1 -0
- package/dist/acceptance/OutageDoubles.js +67 -0
- package/dist/acceptance/OutageDoubles.js.map +1 -0
- package/dist/acceptance/ZoneProbes.d.ts +368 -0
- package/dist/acceptance/ZoneProbes.d.ts.map +1 -0
- package/dist/acceptance/ZoneProbes.js +488 -0
- package/dist/acceptance/ZoneProbes.js.map +1 -0
- package/dist/adapters/JcsDigest.d.ts +6 -5
- package/dist/adapters/JcsDigest.d.ts.map +1 -1
- package/dist/adapters/JcsDigest.js +9 -8
- package/dist/adapters/JcsDigest.js.map +1 -1
- package/dist/cli/Accept.d.ts +9 -0
- package/dist/cli/Accept.d.ts.map +1 -0
- package/dist/cli/Accept.js +209 -0
- package/dist/cli/Accept.js.map +1 -0
- package/dist/cli/Actions.d.ts +6 -4
- package/dist/cli/Actions.d.ts.map +1 -1
- package/dist/cli/Actions.js +33 -7
- package/dist/cli/Actions.js.map +1 -1
- package/dist/cli/Commands.d.ts +1 -1
- package/dist/cli/Commands.d.ts.map +1 -1
- package/dist/cli/Commands.js +5 -0
- package/dist/cli/Commands.js.map +1 -1
- package/dist/cli/ConfigCommand.d.ts.map +1 -1
- package/dist/cli/ConfigCommand.js +5 -0
- package/dist/cli/ConfigCommand.js.map +1 -1
- package/dist/cli/Doctor.d.ts.map +1 -1
- package/dist/cli/Doctor.js +67 -1
- package/dist/cli/Doctor.js.map +1 -1
- package/dist/cli/Help.d.ts.map +1 -1
- package/dist/cli/Help.js +6 -1
- package/dist/cli/Help.js.map +1 -1
- package/dist/cli/Identity.d.ts +13 -1
- package/dist/cli/Identity.d.ts.map +1 -1
- package/dist/cli/Identity.js +25 -2
- package/dist/cli/Identity.js.map +1 -1
- package/dist/cli/Status.d.ts +23 -0
- package/dist/cli/Status.d.ts.map +1 -1
- package/dist/cli/Status.js +80 -18
- package/dist/cli/Status.js.map +1 -1
- package/dist/cli/VerifyAcceptance.d.ts +38 -0
- package/dist/cli/VerifyAcceptance.d.ts.map +1 -0
- package/dist/cli/VerifyAcceptance.js +143 -0
- package/dist/cli/VerifyAcceptance.js.map +1 -0
- package/dist/config/ExecutorConfig.d.ts +6 -1
- package/dist/config/ExecutorConfig.d.ts.map +1 -1
- package/dist/config/ExecutorConfig.js.map +1 -1
- package/dist/egress/ZoneHttpClient.d.ts +3 -0
- package/dist/egress/ZoneHttpClient.d.ts.map +1 -0
- package/dist/egress/ZoneHttpClient.js +72 -0
- package/dist/egress/ZoneHttpClient.js.map +1 -0
- package/dist/exposure/DecionisExposureLedger.d.ts +44 -0
- package/dist/exposure/DecionisExposureLedger.d.ts.map +1 -0
- package/dist/exposure/DecionisExposureLedger.js +175 -0
- package/dist/exposure/DecionisExposureLedger.js.map +1 -0
- package/dist/exposure/ExposureDeclaration.d.ts +68 -0
- package/dist/exposure/ExposureDeclaration.d.ts.map +1 -0
- package/dist/exposure/ExposureDeclaration.js +83 -0
- package/dist/exposure/ExposureDeclaration.js.map +1 -0
- package/dist/exposure/ExposureFacts.d.ts +61 -0
- package/dist/exposure/ExposureFacts.d.ts.map +1 -0
- package/dist/exposure/ExposureFacts.js +201 -0
- package/dist/exposure/ExposureFacts.js.map +1 -0
- package/dist/exposure/ExposureGate.d.ts +144 -0
- package/dist/exposure/ExposureGate.d.ts.map +1 -0
- package/dist/exposure/ExposureGate.js +446 -0
- package/dist/exposure/ExposureGate.js.map +1 -0
- package/dist/exposure/ExposureLedger.d.ts +93 -0
- package/dist/exposure/ExposureLedger.d.ts.map +1 -0
- package/dist/exposure/ExposureLedger.js +24 -0
- package/dist/exposure/ExposureLedger.js.map +1 -0
- package/dist/gateway/AttemptStore.d.ts +83 -0
- package/dist/gateway/AttemptStore.d.ts.map +1 -0
- package/dist/gateway/AttemptStore.js +229 -0
- package/dist/gateway/AttemptStore.js.map +1 -0
- package/dist/gateway/ForwardHandler.d.ts +29 -3
- package/dist/gateway/ForwardHandler.d.ts.map +1 -1
- package/dist/gateway/ForwardHandler.js +32 -5
- package/dist/gateway/ForwardHandler.js.map +1 -1
- package/dist/gateway/Gateway.d.ts +229 -17
- package/dist/gateway/Gateway.d.ts.map +1 -1
- package/dist/gateway/Gateway.js +1045 -81
- package/dist/gateway/Gateway.js.map +1 -1
- package/dist/gateway/GatewayConfig.d.ts +186 -0
- package/dist/gateway/GatewayConfig.d.ts.map +1 -1
- package/dist/gateway/GatewayConfig.js +219 -5
- package/dist/gateway/GatewayConfig.js.map +1 -1
- package/dist/gateway/GatewayManifest.d.ts +18 -0
- package/dist/gateway/GatewayManifest.d.ts.map +1 -0
- package/dist/gateway/GatewayManifest.js +42 -0
- package/dist/gateway/GatewayManifest.js.map +1 -0
- package/dist/gateway/GatewayMetrics.d.ts +12 -4
- package/dist/gateway/GatewayMetrics.d.ts.map +1 -1
- package/dist/gateway/GatewayMetrics.js +5 -0
- package/dist/gateway/GatewayMetrics.js.map +1 -1
- package/dist/gateway/GatewayReport.d.ts +34 -1
- package/dist/gateway/GatewayReport.d.ts.map +1 -1
- package/dist/gateway/GatewayReport.js +11 -0
- package/dist/gateway/GatewayReport.js.map +1 -1
- package/dist/gateway/HoldStore.d.ts +89 -0
- package/dist/gateway/HoldStore.d.ts.map +1 -0
- package/dist/gateway/HoldStore.js +280 -0
- package/dist/gateway/HoldStore.js.map +1 -0
- package/dist/gateway/InterceptedRequest.d.ts +10 -0
- package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
- package/dist/gateway/InterceptedRequest.js +20 -0
- package/dist/gateway/InterceptedRequest.js.map +1 -1
- package/dist/gateway/RouteTable.d.ts +33 -5
- package/dist/gateway/RouteTable.d.ts.map +1 -1
- package/dist/gateway/RouteTable.js +76 -1
- package/dist/gateway/RouteTable.js.map +1 -1
- package/dist/gateway/ShadowLedger.d.ts +11 -0
- package/dist/gateway/ShadowLedger.d.ts.map +1 -1
- package/dist/gateway/ShadowLedger.js +11 -0
- package/dist/gateway/ShadowLedger.js.map +1 -1
- package/dist/gateway/TargetEffect.d.ts +74 -0
- package/dist/gateway/TargetEffect.d.ts.map +1 -0
- package/dist/gateway/TargetEffect.js +95 -0
- package/dist/gateway/TargetEffect.js.map +1 -0
- package/dist/gateway/TargetReader.d.ts +70 -0
- package/dist/gateway/TargetReader.d.ts.map +1 -0
- package/dist/gateway/TargetReader.js +106 -0
- package/dist/gateway/TargetReader.js.map +1 -0
- package/dist/gateway/Upstream.d.ts +15 -0
- package/dist/gateway/Upstream.d.ts.map +1 -1
- package/dist/gateway/Upstream.js +24 -2
- package/dist/gateway/Upstream.js.map +1 -1
- package/dist/hosted/TenantHost.d.ts +3 -2
- package/dist/hosted/TenantHost.d.ts.map +1 -1
- package/dist/hosted/TenantHost.js +7 -1
- package/dist/hosted/TenantHost.js.map +1 -1
- package/dist/hosted/TenantRegistry.d.ts +8 -0
- package/dist/hosted/TenantRegistry.d.ts.map +1 -1
- package/dist/hosted/TenantRegistry.js +14 -1
- package/dist/hosted/TenantRegistry.js.map +1 -1
- package/dist/http/GatewayHttpServer.d.ts +7 -0
- package/dist/http/GatewayHttpServer.d.ts.map +1 -1
- package/dist/http/GatewayHttpServer.js +57 -1
- package/dist/http/GatewayHttpServer.js.map +1 -1
- package/dist/outcomes/OutcomeEvidence.d.ts +4 -4
- package/dist/posture/ActionSpaceDrift.d.ts +40 -0
- package/dist/posture/ActionSpaceDrift.d.ts.map +1 -0
- package/dist/posture/ActionSpaceDrift.js +67 -0
- package/dist/posture/ActionSpaceDrift.js.map +1 -0
- package/dist/posture/DeploymentFingerprint.d.ts +88 -0
- package/dist/posture/DeploymentFingerprint.d.ts.map +1 -0
- package/dist/posture/DeploymentFingerprint.js +78 -0
- package/dist/posture/DeploymentFingerprint.js.map +1 -0
- package/dist/secrets/SecretStore.d.ts +6 -1
- package/dist/secrets/SecretStore.d.ts.map +1 -1
- package/dist/secrets/SecretStore.js.map +1 -1
- package/dist/service/EscalationResolver.d.ts +6 -6
- package/dist/service/EscalationResolver.d.ts.map +1 -1
- package/dist/service/EscalationResolver.js +8 -4
- package/dist/service/EscalationResolver.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One governed attempt whose outcome nobody knows: the upstream answered 5xx
|
|
3
|
+
* or nothing after the request was sent. Kept by the client's
|
|
4
|
+
* `Idempotency-Key`, so a retry with that key can be linked to it, and a
|
|
5
|
+
* different request under that key refused.
|
|
6
|
+
*/
|
|
7
|
+
export interface IndeterminateAttempt {
|
|
8
|
+
/** `retryDigest` of the request: what the key promised. */
|
|
9
|
+
readonly requestDigest: string;
|
|
10
|
+
readonly intentId: string;
|
|
11
|
+
readonly decisionId: string | null;
|
|
12
|
+
readonly dossierId: string | null;
|
|
13
|
+
/**
|
|
14
|
+
* The exposure reservation key the attempt drew under, when its route
|
|
15
|
+
* releases money: a retry reserves under it, so what the attempt kept is
|
|
16
|
+
* ended with the retry's outcome rather than drawn a second time.
|
|
17
|
+
*/
|
|
18
|
+
readonly reservationKey?: string;
|
|
19
|
+
readonly recordedAt: string;
|
|
20
|
+
readonly expiresAt: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Where a gateway remembers its INDETERMINATE attempts, by the client's
|
|
24
|
+
* idempotency key, within one tenant. Nothing else is kept: no body, no
|
|
25
|
+
* header, and the key itself only as the name it is found by.
|
|
26
|
+
*/
|
|
27
|
+
export interface AttemptStore {
|
|
28
|
+
/** False when the store is full or cannot write: the attempt is not remembered. */
|
|
29
|
+
record(idempotencyKey: string, attempt: IndeterminateAttempt): boolean;
|
|
30
|
+
/** The live record under a key; an expired or unreadable one is removed and is absent. */
|
|
31
|
+
find(idempotencyKey: string): IndeterminateAttempt | undefined;
|
|
32
|
+
/** Forgets the record under a key, only if it is for this request. */
|
|
33
|
+
forget(idempotencyKey: string, requestDigest: string): void;
|
|
34
|
+
close(): void;
|
|
35
|
+
}
|
|
36
|
+
/** How long an INDETERMINATE attempt is remembered: a day, well inside the hold store's seven-day ceiling. */
|
|
37
|
+
export declare const ATTEMPT_TTL_MS: number;
|
|
38
|
+
/** The most INDETERMINATE attempts one gateway remembers. */
|
|
39
|
+
export declare const MAX_ATTEMPTS = 1000;
|
|
40
|
+
/** In this process's memory: lost on restart, and seen only by this replica. */
|
|
41
|
+
export declare class MemoryAttemptStore implements AttemptStore {
|
|
42
|
+
private readonly clock;
|
|
43
|
+
private readonly attempts;
|
|
44
|
+
constructor(clock: () => number);
|
|
45
|
+
record(idempotencyKey: string, attempt: IndeterminateAttempt): boolean;
|
|
46
|
+
find(idempotencyKey: string): IndeterminateAttempt | undefined;
|
|
47
|
+
forget(idempotencyKey: string, requestDigest: string): void;
|
|
48
|
+
close(): void;
|
|
49
|
+
private sweep;
|
|
50
|
+
}
|
|
51
|
+
/** The subdirectory of the hold directory the records live in. */
|
|
52
|
+
export declare const ATTEMPT_DIRECTORY = "attempts";
|
|
53
|
+
/**
|
|
54
|
+
* INDETERMINATE attempts as files beside the durable holds, in the same
|
|
55
|
+
* custody: the directory every replica mounts and the hold key. Each file is
|
|
56
|
+
* sealed with AES-256-GCM under the hold key, its associated data the tenant
|
|
57
|
+
* and the idempotency key, so a file copied to another tenant, or renamed to
|
|
58
|
+
* another key, does not open. A file is named by an HMAC of the tenant and
|
|
59
|
+
* the key under a name key derived from the hold key, so the directory says
|
|
60
|
+
* nothing about the keys clients sent. A record is replaced by a rename, so a
|
|
61
|
+
* reader on any replica sees a whole record or none.
|
|
62
|
+
*/
|
|
63
|
+
export declare class FileAttemptStore implements AttemptStore {
|
|
64
|
+
private readonly scope;
|
|
65
|
+
private readonly clock;
|
|
66
|
+
private readonly key;
|
|
67
|
+
private readonly nameKey;
|
|
68
|
+
private readonly dir;
|
|
69
|
+
constructor(holdDir: string, keyFile: string, scope: string, clock: () => number);
|
|
70
|
+
record(idempotencyKey: string, attempt: IndeterminateAttempt): boolean;
|
|
71
|
+
find(idempotencyKey: string): IndeterminateAttempt | undefined;
|
|
72
|
+
forget(idempotencyKey: string, requestDigest: string): void;
|
|
73
|
+
close(): void;
|
|
74
|
+
/** Removes expired records and orphaned temporary files; returns how many are live. */
|
|
75
|
+
sweep(): number;
|
|
76
|
+
private unseal;
|
|
77
|
+
private aad;
|
|
78
|
+
private path;
|
|
79
|
+
private static exists;
|
|
80
|
+
private static expiresAt;
|
|
81
|
+
private static olderThan;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=AttemptStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttemptStore.d.ts","sourceRoot":"","sources":["../../src/gateway/AttemptStore.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM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;;;;GASG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IAQjD,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IARxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;gBAG3B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACE,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,MAAM;IAa/B,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO;IA+BtE,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS;IAgB9D,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI;IAM3D,KAAK,IAAI,IAAI;IAIpB,uFAAuF;IAChF,KAAK,IAAI,MAAM;IA0BtB,OAAO,CAAC,MAAM;IAuBd,OAAO,CAAC,GAAG;IAOX,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,MAAM,CAAC,MAAM;IASrB,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,SAAS;CAOzB"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHmac, hkdfSync, randomBytes } from "node:crypto";
|
|
2
|
+
import { closeSync, fsyncSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeSync, } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { FileHoldStore, HoldStoreError } from "./HoldStore.js";
|
|
5
|
+
/** How long an INDETERMINATE attempt is remembered: a day, well inside the hold store's seven-day ceiling. */
|
|
6
|
+
export const ATTEMPT_TTL_MS = 24 * 60 * 60 * 1_000;
|
|
7
|
+
/** The most INDETERMINATE attempts one gateway remembers. */
|
|
8
|
+
export const MAX_ATTEMPTS = 1_000;
|
|
9
|
+
/** In this process's memory: lost on restart, and seen only by this replica. */
|
|
10
|
+
export class MemoryAttemptStore {
|
|
11
|
+
clock;
|
|
12
|
+
attempts = new Map();
|
|
13
|
+
constructor(clock) {
|
|
14
|
+
this.clock = clock;
|
|
15
|
+
}
|
|
16
|
+
record(idempotencyKey, attempt) {
|
|
17
|
+
this.sweep();
|
|
18
|
+
if (!this.attempts.has(idempotencyKey) && this.attempts.size >= MAX_ATTEMPTS)
|
|
19
|
+
return false;
|
|
20
|
+
this.attempts.set(idempotencyKey, attempt);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
find(idempotencyKey) {
|
|
24
|
+
const attempt = this.attempts.get(idempotencyKey);
|
|
25
|
+
if (attempt === undefined)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (attempt.expiresAt > this.clock())
|
|
28
|
+
return attempt;
|
|
29
|
+
this.attempts.delete(idempotencyKey);
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
forget(idempotencyKey, requestDigest) {
|
|
33
|
+
if (this.attempts.get(idempotencyKey)?.requestDigest === requestDigest) {
|
|
34
|
+
this.attempts.delete(idempotencyKey);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
close() {
|
|
38
|
+
this.attempts.clear();
|
|
39
|
+
}
|
|
40
|
+
sweep() {
|
|
41
|
+
const now = this.clock();
|
|
42
|
+
for (const [key, attempt] of this.attempts) {
|
|
43
|
+
if (attempt.expiresAt <= now)
|
|
44
|
+
this.attempts.delete(key);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const FORMAT = "agentsafe.attempt/1";
|
|
49
|
+
const SUFFIX = ".attempt";
|
|
50
|
+
const TEMPORARY = ".tmp";
|
|
51
|
+
/** A half-written file older than this is an orphan a sweep removes. */
|
|
52
|
+
const ORPHAN_MS = 10 * 60_000;
|
|
53
|
+
/** The subdirectory of the hold directory the records live in. */
|
|
54
|
+
export const ATTEMPT_DIRECTORY = "attempts";
|
|
55
|
+
/**
|
|
56
|
+
* INDETERMINATE attempts as files beside the durable holds, in the same
|
|
57
|
+
* custody: the directory every replica mounts and the hold key. Each file is
|
|
58
|
+
* sealed with AES-256-GCM under the hold key, its associated data the tenant
|
|
59
|
+
* and the idempotency key, so a file copied to another tenant, or renamed to
|
|
60
|
+
* another key, does not open. A file is named by an HMAC of the tenant and
|
|
61
|
+
* the key under a name key derived from the hold key, so the directory says
|
|
62
|
+
* nothing about the keys clients sent. A record is replaced by a rename, so a
|
|
63
|
+
* reader on any replica sees a whole record or none.
|
|
64
|
+
*/
|
|
65
|
+
export class FileAttemptStore {
|
|
66
|
+
scope;
|
|
67
|
+
clock;
|
|
68
|
+
key;
|
|
69
|
+
nameKey;
|
|
70
|
+
dir;
|
|
71
|
+
constructor(holdDir, keyFile, scope, clock) {
|
|
72
|
+
this.scope = scope;
|
|
73
|
+
this.clock = clock;
|
|
74
|
+
this.key = FileHoldStore.readKey(keyFile);
|
|
75
|
+
this.nameKey = Buffer.from(hkdfSync("sha256", this.key, Buffer.alloc(0), FORMAT, 32));
|
|
76
|
+
this.dir = join(holdDir, ATTEMPT_DIRECTORY);
|
|
77
|
+
try {
|
|
78
|
+
mkdirSync(this.dir, { recursive: true, mode: 0o700 });
|
|
79
|
+
statSync(this.dir);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new HoldStoreError("HOLD_DIR_UNUSABLE");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
record(idempotencyKey, attempt) {
|
|
86
|
+
const path = this.path(idempotencyKey);
|
|
87
|
+
if (this.sweep() >= MAX_ATTEMPTS && !FileAttemptStore.exists(path))
|
|
88
|
+
return false;
|
|
89
|
+
const iv = randomBytes(12);
|
|
90
|
+
const cipher = createCipheriv("aes-256-gcm", this.key, iv);
|
|
91
|
+
cipher.setAAD(this.aad(idempotencyKey, attempt.expiresAt));
|
|
92
|
+
const data = Buffer.concat([cipher.update(JSON.stringify(attempt), "utf8"), cipher.final()]);
|
|
93
|
+
const sealed = {
|
|
94
|
+
format: FORMAT,
|
|
95
|
+
expiresAt: attempt.expiresAt,
|
|
96
|
+
iv: iv.toString("base64url"),
|
|
97
|
+
tag: cipher.getAuthTag().toString("base64url"),
|
|
98
|
+
data: data.toString("base64url"),
|
|
99
|
+
};
|
|
100
|
+
const temporary = `${path}.${randomBytes(6).toString("hex")}${TEMPORARY}`;
|
|
101
|
+
try {
|
|
102
|
+
const fd = openSync(temporary, "wx", 0o600);
|
|
103
|
+
try {
|
|
104
|
+
writeSync(fd, JSON.stringify(sealed));
|
|
105
|
+
fsyncSync(fd);
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
closeSync(fd);
|
|
109
|
+
}
|
|
110
|
+
renameSync(temporary, path);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
rmSync(temporary, { force: true });
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
find(idempotencyKey) {
|
|
119
|
+
const path = this.path(idempotencyKey);
|
|
120
|
+
let sealed;
|
|
121
|
+
try {
|
|
122
|
+
sealed = JSON.parse(readFileSync(path, "utf8"));
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
const attempt = this.unseal(idempotencyKey, sealed);
|
|
128
|
+
if (attempt === null || attempt.expiresAt <= this.clock()) {
|
|
129
|
+
rmSync(path, { force: true });
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
return attempt;
|
|
133
|
+
}
|
|
134
|
+
forget(idempotencyKey, requestDigest) {
|
|
135
|
+
if (this.find(idempotencyKey)?.requestDigest === requestDigest) {
|
|
136
|
+
rmSync(this.path(idempotencyKey), { force: true });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
close() {
|
|
140
|
+
// The records are the next process's to read.
|
|
141
|
+
}
|
|
142
|
+
/** Removes expired records and orphaned temporary files; returns how many are live. */
|
|
143
|
+
sweep() {
|
|
144
|
+
const now = this.clock();
|
|
145
|
+
let live = 0;
|
|
146
|
+
let names;
|
|
147
|
+
try {
|
|
148
|
+
names = readdirSync(this.dir);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
for (const name of names) {
|
|
154
|
+
const path = join(this.dir, name);
|
|
155
|
+
if (name.endsWith(TEMPORARY)) {
|
|
156
|
+
if (FileAttemptStore.olderThan(path, now - ORPHAN_MS))
|
|
157
|
+
rmSync(path, { force: true });
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!name.endsWith(SUFFIX))
|
|
161
|
+
continue;
|
|
162
|
+
const expiresAt = FileAttemptStore.expiresAt(path);
|
|
163
|
+
if (expiresAt === null || expiresAt <= now) {
|
|
164
|
+
rmSync(path, { force: true });
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
live += 1;
|
|
168
|
+
}
|
|
169
|
+
return live;
|
|
170
|
+
}
|
|
171
|
+
unseal(idempotencyKey, sealed) {
|
|
172
|
+
if (sealed?.format !== FORMAT || typeof sealed.expiresAt !== "number")
|
|
173
|
+
return null;
|
|
174
|
+
try {
|
|
175
|
+
const decipher = createDecipheriv("aes-256-gcm", this.key, Buffer.from(sealed.iv, "base64url"));
|
|
176
|
+
decipher.setAAD(this.aad(idempotencyKey, sealed.expiresAt));
|
|
177
|
+
decipher.setAuthTag(Buffer.from(sealed.tag, "base64url"));
|
|
178
|
+
const plain = Buffer.concat([
|
|
179
|
+
decipher.update(Buffer.from(sealed.data, "base64url")),
|
|
180
|
+
decipher.final(),
|
|
181
|
+
]).toString("utf8");
|
|
182
|
+
const attempt = JSON.parse(plain);
|
|
183
|
+
return attempt.expiresAt === sealed.expiresAt && typeof attempt.requestDigest === "string"
|
|
184
|
+
? attempt
|
|
185
|
+
: null;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
aad(idempotencyKey, expiresAt) {
|
|
192
|
+
return Buffer.from(`${FORMAT}\u0000${this.scope}\u0000${idempotencyKey}\u0000${expiresAt}`, "utf8");
|
|
193
|
+
}
|
|
194
|
+
path(idempotencyKey) {
|
|
195
|
+
const name = createHmac("sha256", this.nameKey)
|
|
196
|
+
.update(`${this.scope}\u0000${idempotencyKey}`, "utf8")
|
|
197
|
+
.digest("hex");
|
|
198
|
+
return join(this.dir, `${name}${SUFFIX}`);
|
|
199
|
+
}
|
|
200
|
+
static exists(path) {
|
|
201
|
+
try {
|
|
202
|
+
statSync(path);
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
static expiresAt(path) {
|
|
210
|
+
try {
|
|
211
|
+
const sealed = JSON.parse(readFileSync(path, "utf8"));
|
|
212
|
+
return sealed.format === FORMAT && typeof sealed.expiresAt === "number"
|
|
213
|
+
? sealed.expiresAt
|
|
214
|
+
: null;
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
static olderThan(path, cutoff) {
|
|
221
|
+
try {
|
|
222
|
+
return statSync(path).mtimeMs < cutoff;
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=AttemptStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttemptStore.js","sourceRoot":"","sources":["../../src/gateway/AttemptStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,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C;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { type ActionHandler, type ActionRegistry } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import { type ActionHandler, type ActionRegistry, type VerifiedAuthorization } from "@decionis/agent-safe-pipeline";
|
|
3
3
|
import { type HttpActionParameters, type HttpFactsParameters, type InterceptedRequest } from "./InterceptedRequest.js";
|
|
4
4
|
import type { Upstream, UpstreamResult } from "./Upstream.js";
|
|
5
5
|
/** The parameters an HTTP action carries; anything else the registry refuses before a grant is spent. */
|
|
@@ -31,6 +31,27 @@ export declare const HttpFactsParametersSchema: z.ZodObject<{
|
|
|
31
31
|
export type HttpParameters = HttpActionParameters | HttpFactsParameters;
|
|
32
32
|
/** What the registry admits an HTTP action's parameters against: either shape, nothing else. */
|
|
33
33
|
export declare const HttpParametersSchema: z.ZodType<HttpParameters>;
|
|
34
|
+
/**
|
|
35
|
+
* The header a write carries the target version its intent bound in, as a
|
|
36
|
+
* verifying hop sets it after checking an attestation: an upstream that takes
|
|
37
|
+
* writes only through the gateway's credential, and honours it, refuses a
|
|
38
|
+
* write whose target has moved since the decision.
|
|
39
|
+
*/
|
|
40
|
+
export declare const EXPECTED_STATE_VERSION_HEADER = "x-agent-safe-expected-state-version";
|
|
41
|
+
/**
|
|
42
|
+
* Told when the upstream answered a forwarded write with a `2xx`, after the
|
|
43
|
+
* point of no return and before the attempt is finalized, so what it does
|
|
44
|
+
* rides on the finalization. It never throws.
|
|
45
|
+
*/
|
|
46
|
+
export type Landed = (authorization: VerifiedAuthorization) => Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Asked after the grant is claimed and the bytes are checked, immediately
|
|
49
|
+
* before the point of no return: a last check of the gateway's own (a
|
|
50
|
+
* payment's cumulative limits) that refuses by throwing a
|
|
51
|
+
* `PreDispatchRefusal`, so nothing is sent and the attempt is finalized as
|
|
52
|
+
* not executed.
|
|
53
|
+
*/
|
|
54
|
+
export type BeforeDispatch = (authorization: VerifiedAuthorization) => Promise<void>;
|
|
34
55
|
/** What the handler leaves behind for the relay, whichever way the attempt ended. */
|
|
35
56
|
export interface ForwardOutcome {
|
|
36
57
|
readonly response: UpstreamResult | null;
|
|
@@ -40,6 +61,8 @@ export interface ForwardOutcome {
|
|
|
40
61
|
interface Held {
|
|
41
62
|
readonly request: InterceptedRequest;
|
|
42
63
|
readonly extraHeaders: Readonly<Record<string, string>>;
|
|
64
|
+
readonly landed: Landed | null;
|
|
65
|
+
readonly before: BeforeDispatch | null;
|
|
43
66
|
outcome: ForwardOutcome;
|
|
44
67
|
}
|
|
45
68
|
/**
|
|
@@ -49,7 +72,7 @@ interface Held {
|
|
|
49
72
|
*/
|
|
50
73
|
export declare class RequestHolder {
|
|
51
74
|
private readonly held;
|
|
52
|
-
hold(intentId: string, request: InterceptedRequest, extraHeaders: Readonly<Record<string, string
|
|
75
|
+
hold(intentId: string, request: InterceptedRequest, extraHeaders: Readonly<Record<string, string>>, landed?: Landed | null, before?: BeforeDispatch | null): void;
|
|
53
76
|
/** @internal */
|
|
54
77
|
get(intentId: string): Held | undefined;
|
|
55
78
|
/** The outcome the handler recorded, and the end of the hold. */
|
|
@@ -65,7 +88,10 @@ export declare class RequestHolder {
|
|
|
65
88
|
* The upstream's status is the attempt's outcome: `2xx` and `3xx` commit,
|
|
66
89
|
* `4xx` is the provider's own refusal, `5xx` and a lost connection are
|
|
67
90
|
* unknown. A facts-only intent carries no path to compare: the held request
|
|
68
|
-
* is bound by its keyed digest instead, which covers the same bytes.
|
|
91
|
+
* is bound by its keyed digest instead, which covers the same bytes. When
|
|
92
|
+
* the intent bound its target's version, the write says so to the upstream,
|
|
93
|
+
* and a `2xx` is handed to whoever held the request before the runner
|
|
94
|
+
* finalizes the attempt.
|
|
69
95
|
*/
|
|
70
96
|
export declare function httpForwardHandler(upstream: Upstream, holder: RequestHolder, digestKey: Uint8Array): ActionHandler<HttpParameters, UpstreamResult>;
|
|
71
97
|
/** Registers the one handler under every name the route table can produce, then seals. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForwardHandler.d.ts","sourceRoot":"","sources":["../../src/gateway/ForwardHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"ForwardHandler.d.ts","sourceRoot":"","sources":["../../src/gateway/ForwardHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,+BAA+B,CAAC;AAKvC,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9D,yGAAyG;AACzG,eAAO,MAAM,0BAA0B;;;;;;;;;;;;kBAOrC,CAAC;AAEH,mGAAmG;AACnG,eAAO,MAAM,yBAAyB;;;;;;;;;kBAIpC,CAAC;AAEH,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;AAExE,gGAAgG;AAChG,eAAO,MAAM,oBAAoB,EAG3B,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,wCAAwC,CAAC;AAEnF;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,aAAa,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,aAAa,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,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S,MAAM,EAAE,EAC1B,OAAO,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,GACrD,cAAc,CAGhB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { JsonValueSchema, PreDispatchRefusal, ProviderRefusal, } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import { JsonValueSchema, preconditionOf, PreDispatchRefusal, ProviderRefusal, } from "@decionis/agent-safe-pipeline";
|
|
3
3
|
import { EFFECT_RECEIPT_HEADER } from "../verify/EffectReceipt.js";
|
|
4
4
|
import { dispatchBudgetMs, MonotonicDeadline } from "../time/MonotonicClock.js";
|
|
5
5
|
import { CONSEQUENTIAL_METHODS } from "./GatewayConfig.js";
|
|
@@ -25,6 +25,13 @@ export const HttpParametersSchema = z.union([
|
|
|
25
25
|
HttpActionParametersSchema,
|
|
26
26
|
HttpFactsParametersSchema,
|
|
27
27
|
]);
|
|
28
|
+
/**
|
|
29
|
+
* The header a write carries the target version its intent bound in, as a
|
|
30
|
+
* verifying hop sets it after checking an attestation: an upstream that takes
|
|
31
|
+
* writes only through the gateway's credential, and honours it, refuses a
|
|
32
|
+
* write whose target has moved since the decision.
|
|
33
|
+
*/
|
|
34
|
+
export const EXPECTED_STATE_VERSION_HEADER = "x-agent-safe-expected-state-version";
|
|
28
35
|
/** Thrown after dispatch when the upstream answered with a server error: the effect is unknown. */
|
|
29
36
|
class UpstreamIndeterminate extends Error {
|
|
30
37
|
constructor() {
|
|
@@ -39,8 +46,14 @@ class UpstreamIndeterminate extends Error {
|
|
|
39
46
|
*/
|
|
40
47
|
export class RequestHolder {
|
|
41
48
|
held = new Map();
|
|
42
|
-
hold(intentId, request, extraHeaders) {
|
|
43
|
-
this.held.set(intentId, {
|
|
49
|
+
hold(intentId, request, extraHeaders, landed = null, before = null) {
|
|
50
|
+
this.held.set(intentId, {
|
|
51
|
+
request,
|
|
52
|
+
extraHeaders,
|
|
53
|
+
landed,
|
|
54
|
+
before,
|
|
55
|
+
outcome: { response: null, failure: null },
|
|
56
|
+
});
|
|
44
57
|
}
|
|
45
58
|
/** @internal */
|
|
46
59
|
get(intentId) {
|
|
@@ -63,7 +76,10 @@ export class RequestHolder {
|
|
|
63
76
|
* The upstream's status is the attempt's outcome: `2xx` and `3xx` commit,
|
|
64
77
|
* `4xx` is the provider's own refusal, `5xx` and a lost connection are
|
|
65
78
|
* unknown. A facts-only intent carries no path to compare: the held request
|
|
66
|
-
* is bound by its keyed digest instead, which covers the same bytes.
|
|
79
|
+
* is bound by its keyed digest instead, which covers the same bytes. When
|
|
80
|
+
* the intent bound its target's version, the write says so to the upstream,
|
|
81
|
+
* and a `2xx` is handed to whoever held the request before the runner
|
|
82
|
+
* finalizes the attempt.
|
|
67
83
|
*/
|
|
68
84
|
export function httpForwardHandler(upstream, holder, digestKey) {
|
|
69
85
|
return {
|
|
@@ -83,16 +99,22 @@ export function httpForwardHandler(upstream, holder, digestKey) {
|
|
|
83
99
|
if (request.method.toUpperCase() !== parameters.method || !bound) {
|
|
84
100
|
throw new PreDispatchRefusal("PAYLOAD_BINDING_MISMATCH");
|
|
85
101
|
}
|
|
102
|
+
// The gateway's own last check runs on the bytes just verified, and
|
|
103
|
+
// before the dispatch budget is taken, so its time is not the upstream's.
|
|
104
|
+
if (held.before !== null)
|
|
105
|
+
await held.before(authorization);
|
|
106
|
+
const precondition = preconditionOf(context);
|
|
86
107
|
const headers = upstream.headersFor(request, {
|
|
87
108
|
...held.extraHeaders,
|
|
88
109
|
"x-agent-safe-intent-hash": intent.intentHash,
|
|
89
110
|
"x-agent-safe-decision-id": authorization.decisionId,
|
|
90
111
|
"x-agent-safe-dossier-id": authorization.dossierId,
|
|
112
|
+
...(precondition === null ? {} : { [EXPECTED_STATE_VERSION_HEADER]: precondition.version }),
|
|
91
113
|
});
|
|
92
114
|
// The upstream is never given more time than the authorization has
|
|
93
115
|
// left, and the budget is monotonic, so a clock change cannot extend it.
|
|
94
116
|
const deadline = MonotonicDeadline.after(dispatchBudgetMs(upstream.timeoutMs, authorization));
|
|
95
|
-
|
|
117
|
+
const answered = await dispatch.run(async () => {
|
|
96
118
|
// Everything after this line is the point of no return.
|
|
97
119
|
let response;
|
|
98
120
|
try {
|
|
@@ -127,6 +149,11 @@ export function httpForwardHandler(upstream, holder, digestKey) {
|
|
|
127
149
|
held.outcome = { response, failure: null };
|
|
128
150
|
return response;
|
|
129
151
|
});
|
|
152
|
+
// Past the point of no return: what follows observes the write, and
|
|
153
|
+
// can change neither its outcome nor whether it happened.
|
|
154
|
+
if (answered.status < 300)
|
|
155
|
+
await held.landed?.(authorization);
|
|
156
|
+
return answered;
|
|
130
157
|
},
|
|
131
158
|
};
|
|
132
159
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForwardHandler.js","sourceRoot":"","sources":["../../src/gateway/ForwardHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,eAAe,
|
|
1
|
+
{"version":3,"file":"ForwardHandler.js","sourceRoot":"","sources":["../../src/gateway/ForwardHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,eAAe,GAIhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,aAAa,GAId,MAAM,yBAAyB,CAAC;AAGjC,yGAAyG;AACzG,MAAM,CAAC,MAAM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