@decionis/agentsafe 0.6.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 +68 -20
- package/dist/Cli.js +30 -3
- package/dist/Cli.js.map +1 -1
- package/dist/Index.d.ts +5 -3
- package/dist/Index.d.ts.map +1 -1
- package/dist/Index.js +3 -1
- package/dist/Index.js.map +1 -1
- package/dist/TrustedExecutor.d.ts.map +1 -1
- package/dist/TrustedExecutor.js +2 -0
- package/dist/TrustedExecutor.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/adapters/mcp/McpGuard.d.ts +32 -3
- package/dist/adapters/mcp/McpGuard.d.ts.map +1 -1
- package/dist/adapters/mcp/McpGuard.js +29 -5
- package/dist/adapters/mcp/McpGuard.js.map +1 -1
- package/dist/adapters/mcp/McpIntentBinder.d.ts +18 -3
- package/dist/adapters/mcp/McpIntentBinder.d.ts.map +1 -1
- package/dist/adapters/mcp/McpIntentBinder.js +48 -1
- package/dist/adapters/mcp/McpIntentBinder.js.map +1 -1
- package/dist/adapters/mcp/McpInvocation.d.ts +9 -2
- package/dist/adapters/mcp/McpInvocation.d.ts.map +1 -1
- package/dist/adapters/mcp/McpInvocation.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 +16 -0
- package/dist/cli/Actions.d.ts.map +1 -0
- package/dist/cli/Actions.js +194 -0
- package/dist/cli/Actions.js.map +1 -0
- package/dist/cli/Arguments.d.ts +4 -0
- package/dist/cli/Arguments.d.ts.map +1 -1
- package/dist/cli/Arguments.js +12 -3
- package/dist/cli/Arguments.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 +10 -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 +18 -1
- package/dist/cli/Help.js.map +1 -1
- package/dist/cli/Host.d.ts +5 -2
- package/dist/cli/Host.d.ts.map +1 -1
- package/dist/cli/Host.js +24 -2
- package/dist/cli/Host.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/Profile.d.ts +24 -0
- package/dist/cli/Profile.d.ts.map +1 -0
- package/dist/cli/Profile.js +168 -0
- package/dist/cli/Profile.js.map +1 -0
- package/dist/cli/Records.d.ts +15 -0
- package/dist/cli/Records.d.ts.map +1 -0
- package/dist/cli/Records.js +205 -0
- package/dist/cli/Records.js.map +1 -0
- 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/ConfigKeys.d.ts +2 -2
- package/dist/config/ConfigKeys.d.ts.map +1 -1
- package/dist/config/ConfigKeys.js +6 -0
- package/dist/config/ConfigKeys.js.map +1 -1
- package/dist/config/ExecutorConfig.d.ts +35 -1
- package/dist/config/ExecutorConfig.d.ts.map +1 -1
- package/dist/config/ExecutorConfig.js +53 -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 +50 -6
- package/dist/gateway/ForwardHandler.d.ts.map +1 -1
- package/dist/gateway/ForwardHandler.js +58 -14
- package/dist/gateway/ForwardHandler.js.map +1 -1
- package/dist/gateway/Gateway.d.ts +347 -15
- package/dist/gateway/Gateway.d.ts.map +1 -1
- package/dist/gateway/Gateway.js +1524 -63
- package/dist/gateway/Gateway.js.map +1 -1
- package/dist/gateway/GatewayConfig.d.ts +295 -0
- package/dist/gateway/GatewayConfig.d.ts.map +1 -1
- package/dist/gateway/GatewayConfig.js +485 -13
- 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 +39 -2
- package/dist/gateway/GatewayReport.d.ts.map +1 -1
- package/dist/gateway/GatewayReport.js +14 -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 +55 -1
- package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
- package/dist/gateway/InterceptedRequest.js +63 -1
- package/dist/gateway/InterceptedRequest.js.map +1 -1
- package/dist/gateway/PolicySelector.d.ts +5 -0
- package/dist/gateway/PolicySelector.d.ts.map +1 -0
- package/dist/gateway/PolicySelector.js +9 -0
- package/dist/gateway/PolicySelector.js.map +1 -0
- package/dist/gateway/RouteTable.d.ts +72 -7
- package/dist/gateway/RouteTable.d.ts.map +1 -1
- package/dist/gateway/RouteTable.js +133 -9
- 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/SubjectSessions.d.ts +113 -0
- package/dist/gateway/SubjectSessions.d.ts.map +1 -0
- package/dist/gateway/SubjectSessions.js +219 -0
- package/dist/gateway/SubjectSessions.js.map +1 -0
- 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 +26 -0
- package/dist/gateway/Upstream.d.ts.map +1 -1
- package/dist/gateway/Upstream.js +42 -3
- package/dist/gateway/Upstream.js.map +1 -1
- package/dist/hosted/TenantHost.d.ts +26 -6
- package/dist/hosted/TenantHost.d.ts.map +1 -1
- package/dist/hosted/TenantHost.js +45 -10
- package/dist/hosted/TenantHost.js.map +1 -1
- package/dist/hosted/TenantRegistry.d.ts +28 -0
- package/dist/hosted/TenantRegistry.d.ts.map +1 -1
- package/dist/hosted/TenantRegistry.js +60 -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 +103 -3
- package/dist/http/GatewayHttpServer.js.map +1 -1
- package/dist/identity/WorkloadJwtVerifier.d.ts +13 -0
- package/dist/identity/WorkloadJwtVerifier.d.ts.map +1 -1
- package/dist/identity/WorkloadJwtVerifier.js +40 -8
- package/dist/identity/WorkloadJwtVerifier.js.map +1 -1
- package/dist/incident/HaltSwitch.d.ts +10 -2
- package/dist/incident/HaltSwitch.d.ts.map +1 -1
- package/dist/incident/HaltSwitch.js +22 -2
- package/dist/incident/HaltSwitch.js.map +1 -1
- package/dist/incident/SecurityEvents.d.ts +18 -0
- package/dist/incident/SecurityEvents.d.ts.map +1 -1
- package/dist/incident/SecurityEvents.js +17 -0
- package/dist/incident/SecurityEvents.js.map +1 -1
- package/dist/limits/HardLimits.d.ts.map +1 -1
- package/dist/limits/HardLimits.js.map +1 -1
- package/dist/outcomes/CardOutcomeEvidence.d.ts +56 -0
- package/dist/outcomes/CardOutcomeEvidence.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomeEvidence.js +211 -0
- package/dist/outcomes/CardOutcomeEvidence.js.map +1 -0
- package/dist/outcomes/CardOutcomeFact.d.ts +90 -0
- package/dist/outcomes/CardOutcomeFact.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomeFact.js +76 -0
- package/dist/outcomes/CardOutcomeFact.js.map +1 -0
- package/dist/outcomes/CardOutcomeLedger.d.ts +26 -0
- package/dist/outcomes/CardOutcomeLedger.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomeLedger.js +31 -0
- package/dist/outcomes/CardOutcomeLedger.js.map +1 -0
- package/dist/outcomes/CardOutcomeRecorder.d.ts +35 -0
- package/dist/outcomes/CardOutcomeRecorder.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomeRecorder.js +84 -0
- package/dist/outcomes/CardOutcomeRecorder.js.map +1 -0
- package/dist/outcomes/CardOutcomes.d.ts +68 -0
- package/dist/outcomes/CardOutcomes.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomes.js +191 -0
- package/dist/outcomes/CardOutcomes.js.map +1 -0
- package/dist/outcomes/CoreOutcomeEvidenceClient.d.ts +54 -0
- package/dist/outcomes/CoreOutcomeEvidenceClient.d.ts.map +1 -0
- package/dist/outcomes/CoreOutcomeEvidenceClient.js +116 -0
- package/dist/outcomes/CoreOutcomeEvidenceClient.js.map +1 -0
- package/dist/outcomes/FileCardOutcomeLedger.d.ts +36 -0
- package/dist/outcomes/FileCardOutcomeLedger.d.ts.map +1 -0
- package/dist/outcomes/FileCardOutcomeLedger.js +152 -0
- package/dist/outcomes/FileCardOutcomeLedger.js.map +1 -0
- package/dist/outcomes/OutcomeEvidence.d.ts +238 -0
- package/dist/outcomes/OutcomeEvidence.d.ts.map +1 -0
- package/dist/outcomes/OutcomeEvidence.js +130 -0
- package/dist/outcomes/OutcomeEvidence.js.map +1 -0
- package/dist/outcomes/OutcomeEvidencePublisher.d.ts +81 -0
- package/dist/outcomes/OutcomeEvidencePublisher.d.ts.map +1 -0
- package/dist/outcomes/OutcomeEvidencePublisher.js +189 -0
- package/dist/outcomes/OutcomeEvidencePublisher.js.map +1 -0
- package/dist/outcomes/OutcomeEvidenceStore.d.ts +57 -0
- package/dist/outcomes/OutcomeEvidenceStore.d.ts.map +1 -0
- package/dist/outcomes/OutcomeEvidenceStore.js +191 -0
- package/dist/outcomes/OutcomeEvidenceStore.js.map +1 -0
- 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/dist/service/Requests.d.ts +6 -0
- package/dist/service/Requests.d.ts.map +1 -1
- package/dist/service/Requests.js +9 -1
- package/dist/service/Requests.js.map +1 -1
- package/dist/service/TrustedExecutorService.d.ts +21 -1
- package/dist/service/TrustedExecutorService.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.js +54 -13
- package/dist/service/TrustedExecutorService.js.map +1 -1
- package/dist/verify/VerifyingProvider.d.ts +32 -6
- package/dist/verify/VerifyingProvider.d.ts.map +1 -1
- package/dist/verify/VerifyingProvider.js +16 -2
- package/dist/verify/VerifyingProvider.js.map +1 -1
- package/package.json +7 -6
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { ChainFields } from "../audit/HashChain.js";
|
|
2
|
+
import type { ExposureFacts } from "./ExposureFacts.js";
|
|
3
|
+
import { type ExposureLedger } from "./ExposureLedger.js";
|
|
4
|
+
/**
|
|
5
|
+
* The subject digest scheme Decionis Commerce uses (`Subject.digest`), so one
|
|
6
|
+
* vendor is one subject whichever channel paid it: the identifier trimmed and
|
|
7
|
+
* lower-cased, scoped by the organisation.
|
|
8
|
+
*/
|
|
9
|
+
export declare const EXPOSURE_DIGEST_VERSION = "decionis-exposure-v1";
|
|
10
|
+
/** An enforced reservation key: what an earlier attempt's record may name. */
|
|
11
|
+
export declare const RESERVATION_KEY: RegExp;
|
|
12
|
+
/** One reservation held against one limit. */
|
|
13
|
+
export interface HeldReservation {
|
|
14
|
+
readonly limitKey: string;
|
|
15
|
+
readonly reservationId: string;
|
|
16
|
+
}
|
|
17
|
+
/** What the intent the reservations are made for is, as the ledger and the evidence name it. */
|
|
18
|
+
export interface ExposureBinding {
|
|
19
|
+
readonly intentId: string;
|
|
20
|
+
readonly intentHash: string;
|
|
21
|
+
readonly capturedAt: string;
|
|
22
|
+
/**
|
|
23
|
+
* The reservation key of the INDETERMINATE attempt this one retries under
|
|
24
|
+
* the same idempotency key, for the same request. The retry reserves under
|
|
25
|
+
* it, so the ledger answers with what the earlier attempt kept: one
|
|
26
|
+
* operation, drawn once, and ended once its outcome is known.
|
|
27
|
+
*/
|
|
28
|
+
readonly retryOf?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* What the ledger said about one money release, across every limit that
|
|
32
|
+
* covers it. `unstated` names a limit that covers the action but whose
|
|
33
|
+
* subject the route does not state: the payment is not counted against it,
|
|
34
|
+
* and the evidence says so.
|
|
35
|
+
*/
|
|
36
|
+
export type ExposureCheck = {
|
|
37
|
+
readonly status: "WITHIN_LIMIT";
|
|
38
|
+
readonly held: readonly HeldReservation[];
|
|
39
|
+
readonly unstated: readonly string[];
|
|
40
|
+
/** The limits whose reservation the ledger already held under the key: no second draw. */
|
|
41
|
+
readonly replayed?: readonly string[];
|
|
42
|
+
} | {
|
|
43
|
+
readonly status: "EXCEEDED";
|
|
44
|
+
readonly limitKey: string;
|
|
45
|
+
readonly onExceed: "HOLD" | "ESCALATE";
|
|
46
|
+
readonly reasonCode: string;
|
|
47
|
+
readonly unstated: readonly string[];
|
|
48
|
+
} | {
|
|
49
|
+
readonly status: "UNAVAILABLE";
|
|
50
|
+
readonly code: string;
|
|
51
|
+
/** Kept only under a route's explicit fail-open; released otherwise. */
|
|
52
|
+
readonly held: readonly HeldReservation[];
|
|
53
|
+
readonly unstated: readonly string[];
|
|
54
|
+
/** The route fails open: the payment goes on, uncounted where nothing was held. */
|
|
55
|
+
readonly ungoverned: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** How the forwarded payment ended, as the executor classified it. */
|
|
58
|
+
export type PaymentOutcome = "COMMITTED" | "NOT_EXECUTED" | "INDETERMINATE";
|
|
59
|
+
/** What became of the reservations once the payment's outcome was known. */
|
|
60
|
+
export type Settlement = "SETTLED" | "RELEASED" | "KEPT" | "NONE" | "FAILED";
|
|
61
|
+
export interface ExposureGateOptions {
|
|
62
|
+
readonly ledger: ExposureLedger;
|
|
63
|
+
/** The organisation that scopes every subject digest: the gateway's tenant. */
|
|
64
|
+
readonly orgId: string;
|
|
65
|
+
/** The gateway's actor type, for a limit restricted to some actor types. */
|
|
66
|
+
readonly actorType: string;
|
|
67
|
+
/** Writes one chained line on the gateway's own stream. */
|
|
68
|
+
readonly evidence: (fields: ChainFields) => void;
|
|
69
|
+
/** Counts each outcome, by a code the gateway produced. */
|
|
70
|
+
readonly count?: (outcome: string) => void;
|
|
71
|
+
/** How many times a settle or release is attempted before it is recorded as failed. */
|
|
72
|
+
readonly attempts?: number;
|
|
73
|
+
readonly retryDelayMs?: number;
|
|
74
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The cumulative-limit check on the execution path. After the authority's
|
|
78
|
+
* ALLOW and the claim of its grant, and before the payment is sent, it
|
|
79
|
+
* reserves the amount against every limit in the organisation's policy that
|
|
80
|
+
* covers the route's action type, in key order, under a reservation key
|
|
81
|
+
* derived from the intent hash, so the same intent never draws twice. Any
|
|
82
|
+
* limit that would be exceeded refuses the payment and gives back what was
|
|
83
|
+
* already reserved. Once the upstream has answered, a committed payment is
|
|
84
|
+
* settled, one that was not executed is released, and one whose outcome is
|
|
85
|
+
* unknown keeps its reservation, so the ledger errs toward the cap.
|
|
86
|
+
*/
|
|
87
|
+
export declare class ExposureGate {
|
|
88
|
+
private readonly options;
|
|
89
|
+
private readonly attempts;
|
|
90
|
+
private readonly retryDelayMs;
|
|
91
|
+
private readonly sleep;
|
|
92
|
+
constructor(options: ExposureGateOptions);
|
|
93
|
+
/** A subject's digest as the ledger receives it; the identifier itself never leaves. */
|
|
94
|
+
digest(kind: string, id: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* The reservation key for an intent: the same intent, the same key, on
|
|
97
|
+
* every retry. A retry of an INDETERMINATE attempt takes that attempt's
|
|
98
|
+
* key; a shadow observation never does.
|
|
99
|
+
*/
|
|
100
|
+
static reservationKey(binding: ExposureBinding, shadow?: boolean): string;
|
|
101
|
+
/** The key derived from the intent's own hash. */
|
|
102
|
+
private static ownKey;
|
|
103
|
+
/**
|
|
104
|
+
* Reserves against every covering limit. A refusal releases what was
|
|
105
|
+
* held; so does a fault, unless the route explicitly fails open, when
|
|
106
|
+
* what was held is kept to be settled or released with the payment.
|
|
107
|
+
*/
|
|
108
|
+
reserve(facts: ExposureFacts, binding: ExposureBinding, failOpen: boolean): Promise<ExposureCheck>;
|
|
109
|
+
/**
|
|
110
|
+
* In shadow, what the ledger would have said, without counting the
|
|
111
|
+
* payment. A ledger that reports a subject's usage read-only is asked
|
|
112
|
+
* that, and nothing is reserved: the amount is compared with each
|
|
113
|
+
* covering limit's cap exactly as the ledger compares it (over the cap
|
|
114
|
+
* when used + amount exceeds it; a currency without a cap is not
|
|
115
|
+
* limited). A sequence limit counts steps, not amounts, so it cannot be
|
|
116
|
+
* previewed and is named as such. A ledger without that read is asked by
|
|
117
|
+
* reserving under a shadow key and releasing at once. The payment itself
|
|
118
|
+
* went through unchanged.
|
|
119
|
+
*/
|
|
120
|
+
observe(facts: ExposureFacts, binding: ExposureBinding): Promise<ExposureCheck>;
|
|
121
|
+
/** Shadow's read-only answer: usage plus this amount against each covering limit's cap. */
|
|
122
|
+
private preview;
|
|
123
|
+
/**
|
|
124
|
+
* Ends the reservations once the payment's outcome is known: settled
|
|
125
|
+
* when it committed (for the amount the answer states, when the route
|
|
126
|
+
* names where and it is no more than reserved), released when it was not
|
|
127
|
+
* executed, kept when nobody can say. A failure to settle or release is
|
|
128
|
+
* retried and then recorded; it never changes what already executed.
|
|
129
|
+
*/
|
|
130
|
+
conclude(check: ExposureCheck, outcome: PaymentOutcome, binding: ExposureBinding, settledAmount?: number | null): Promise<Settlement>;
|
|
131
|
+
/** The limits that cover the facts, the reservations made against them, in key order. */
|
|
132
|
+
private draw;
|
|
133
|
+
/** Whether a limit governs this action: its action type, its actor type, and an amount to count. */
|
|
134
|
+
private covers;
|
|
135
|
+
/** The reservation for one limit; null when the route does not state its subject. */
|
|
136
|
+
private request;
|
|
137
|
+
/** Settles or releases each reservation; the ones that still failed, each recorded. */
|
|
138
|
+
private end;
|
|
139
|
+
/** Asks again only where asking again cannot count twice, a bounded number of times. */
|
|
140
|
+
private retrying;
|
|
141
|
+
private record;
|
|
142
|
+
private static codeOf;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=ExposureGate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExposureGate.d.ts","sourceRoot":"","sources":["../../src/exposure/ExposureGate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAGL,KAAK,cAAc,EAIpB,MAAM,qBAAqB,CAAC;AAE7B;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AAU9D,8EAA8E;AAC9E,eAAO,MAAM,eAAe,QAA6B,CAAC;AAE1D,8CAA8C;AAC9C,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,gGAAgG;AAChG,MAAM,WAAW,eAAe;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AAK,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAyB5F,2FAA2F;YAC7E,OAAO;IA0ErB;;;;;;OAMG;IACU,QAAQ,CACnB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,eAAe,EACxB,aAAa,GAAE,MAAM,GAAG,IAAW,GAClC,OAAO,CAAC,UAAU,CAAC;IA0BtB,yFAAyF;YAC3E,IAAI;IAkFlB,oGAAoG;IACpG,OAAO,CAAC,MAAM;IAYd,qFAAqF;IACrF,OAAO,CAAC,OAAO;IAqCf,uFAAuF;YACzE,GAAG;IAiCjB,wFAAwF;YAC1E,QAAQ;IAYtB,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,MAAM,CAAC,MAAM;CAGtB"}
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { Rfc8785 } from "@decionis/agent-safe-pipeline";
|
|
3
|
+
import { ExposureUnavailable, } from "./ExposureLedger.js";
|
|
4
|
+
/**
|
|
5
|
+
* The subject digest scheme Decionis Commerce uses (`Subject.digest`), so one
|
|
6
|
+
* vendor is one subject whichever channel paid it: the identifier trimmed and
|
|
7
|
+
* lower-cased, scoped by the organisation.
|
|
8
|
+
*/
|
|
9
|
+
export const EXPOSURE_DIGEST_VERSION = "decionis-exposure-v1";
|
|
10
|
+
/** The steps a sequence limit spreads across actors, by the action type that takes them. */
|
|
11
|
+
const STEP_OF = {
|
|
12
|
+
PAYMENT_RELEASE: "payment_release",
|
|
13
|
+
VENDOR_BANK_CHANGE: "vendor_bank_change",
|
|
14
|
+
};
|
|
15
|
+
/** The digest an organisation-wide limit counts under (Decionis `ORG_SUBJECT_DIGEST`). */
|
|
16
|
+
const ORG_SUBJECT_DIGEST = "0".repeat(64);
|
|
17
|
+
/** `source.platform` and `source.channel` of every reservation the gateway makes. */
|
|
18
|
+
const SOURCE = { platform: "agentsafe", channel: "gateway" };
|
|
19
|
+
/** An enforced reservation key: what an earlier attempt's record may name. */
|
|
20
|
+
export const RESERVATION_KEY = /^agentsafe:[0-9a-f]{64}$/;
|
|
21
|
+
function sha256(text) {
|
|
22
|
+
return createHash("sha256").update(text).digest("hex");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The cumulative-limit check on the execution path. After the authority's
|
|
26
|
+
* ALLOW and the claim of its grant, and before the payment is sent, it
|
|
27
|
+
* reserves the amount against every limit in the organisation's policy that
|
|
28
|
+
* covers the route's action type, in key order, under a reservation key
|
|
29
|
+
* derived from the intent hash, so the same intent never draws twice. Any
|
|
30
|
+
* limit that would be exceeded refuses the payment and gives back what was
|
|
31
|
+
* already reserved. Once the upstream has answered, a committed payment is
|
|
32
|
+
* settled, one that was not executed is released, and one whose outcome is
|
|
33
|
+
* unknown keeps its reservation, so the ledger errs toward the cap.
|
|
34
|
+
*/
|
|
35
|
+
export class ExposureGate {
|
|
36
|
+
options;
|
|
37
|
+
attempts;
|
|
38
|
+
retryDelayMs;
|
|
39
|
+
sleep;
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.options = options;
|
|
42
|
+
this.attempts = Math.max(1, Math.min(options.attempts ?? 3, 5));
|
|
43
|
+
this.retryDelayMs = Math.max(0, Math.min(options.retryDelayMs ?? 200, 2_000));
|
|
44
|
+
this.sleep =
|
|
45
|
+
options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, Math.max(ms, 0))));
|
|
46
|
+
}
|
|
47
|
+
/** A subject's digest as the ledger receives it; the identifier itself never leaves. */
|
|
48
|
+
digest(kind, id) {
|
|
49
|
+
return sha256([
|
|
50
|
+
EXPOSURE_DIGEST_VERSION,
|
|
51
|
+
this.options.orgId.toLowerCase(),
|
|
52
|
+
kind,
|
|
53
|
+
id.trim().toLowerCase(),
|
|
54
|
+
].join("\n"));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The reservation key for an intent: the same intent, the same key, on
|
|
58
|
+
* every retry. A retry of an INDETERMINATE attempt takes that attempt's
|
|
59
|
+
* key; a shadow observation never does.
|
|
60
|
+
*/
|
|
61
|
+
static reservationKey(binding, shadow = false) {
|
|
62
|
+
if (!shadow && binding.retryOf !== undefined && RESERVATION_KEY.test(binding.retryOf)) {
|
|
63
|
+
return binding.retryOf;
|
|
64
|
+
}
|
|
65
|
+
return ExposureGate.ownKey(binding, shadow);
|
|
66
|
+
}
|
|
67
|
+
/** The key derived from the intent's own hash. */
|
|
68
|
+
static ownKey(binding, shadow) {
|
|
69
|
+
const hex = binding.intentHash.replace(/^sha256:/, "");
|
|
70
|
+
return `${shadow ? "agentsafe-shadow" : "agentsafe"}:${hex}`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reserves against every covering limit. A refusal releases what was
|
|
74
|
+
* held; so does a fault, unless the route explicitly fails open, when
|
|
75
|
+
* what was held is kept to be settled or released with the payment.
|
|
76
|
+
*/
|
|
77
|
+
async reserve(facts, binding, failOpen) {
|
|
78
|
+
const key = ExposureGate.reservationKey(binding);
|
|
79
|
+
const own = ExposureGate.ownKey(binding, false);
|
|
80
|
+
const check = await this.draw(facts, binding, key, key === own ? null : own);
|
|
81
|
+
if (check.status === "WITHIN_LIMIT") {
|
|
82
|
+
this.record({
|
|
83
|
+
event: "EXPOSURE_RESERVED",
|
|
84
|
+
intent_id: binding.intentId,
|
|
85
|
+
intent_hash: binding.intentHash,
|
|
86
|
+
reservation_key: key,
|
|
87
|
+
limits: check.held.map((entry) => entry.limitKey),
|
|
88
|
+
unstated: [...check.unstated],
|
|
89
|
+
...(key === own ? {} : { retry_of: true, replayed: [...(check.replayed ?? [])] }),
|
|
90
|
+
});
|
|
91
|
+
this.options.count?.(check.held.length === 0 ? "NOT_APPLICABLE" : "WITHIN_LIMIT");
|
|
92
|
+
return check;
|
|
93
|
+
}
|
|
94
|
+
if (check.status === "EXCEEDED") {
|
|
95
|
+
this.record({
|
|
96
|
+
event: "EXPOSURE_EXCEEDED",
|
|
97
|
+
intent_id: binding.intentId,
|
|
98
|
+
intent_hash: binding.intentHash,
|
|
99
|
+
limit_key: check.limitKey,
|
|
100
|
+
on_exceed: check.onExceed,
|
|
101
|
+
reason_code: check.reasonCode,
|
|
102
|
+
});
|
|
103
|
+
this.options.count?.("EXCEEDED");
|
|
104
|
+
return check;
|
|
105
|
+
}
|
|
106
|
+
const held = failOpen ? check.held : [];
|
|
107
|
+
if (!failOpen)
|
|
108
|
+
await this.end(check.held, "release", binding);
|
|
109
|
+
this.record({
|
|
110
|
+
event: failOpen ? "EXPOSURE_UNGOVERNED" : "EXPOSURE_UNAVAILABLE",
|
|
111
|
+
intent_id: binding.intentId,
|
|
112
|
+
intent_hash: binding.intentHash,
|
|
113
|
+
reason_codes: ["EXPOSURE_UNAVAILABLE", check.code],
|
|
114
|
+
failure_policy: failOpen ? "FAIL_OPEN" : "FAIL_CLOSED",
|
|
115
|
+
limits: held.map((entry) => entry.limitKey),
|
|
116
|
+
});
|
|
117
|
+
this.options.count?.(failOpen ? "UNGOVERNED" : "UNAVAILABLE");
|
|
118
|
+
return { ...check, held, ungoverned: failOpen };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* In shadow, what the ledger would have said, without counting the
|
|
122
|
+
* payment. A ledger that reports a subject's usage read-only is asked
|
|
123
|
+
* that, and nothing is reserved: the amount is compared with each
|
|
124
|
+
* covering limit's cap exactly as the ledger compares it (over the cap
|
|
125
|
+
* when used + amount exceeds it; a currency without a cap is not
|
|
126
|
+
* limited). A sequence limit counts steps, not amounts, so it cannot be
|
|
127
|
+
* previewed and is named as such. A ledger without that read is asked by
|
|
128
|
+
* reserving under a shadow key and releasing at once. The payment itself
|
|
129
|
+
* went through unchanged.
|
|
130
|
+
*/
|
|
131
|
+
async observe(facts, binding) {
|
|
132
|
+
const previewing = this.options.ledger.subjectUsage !== undefined;
|
|
133
|
+
let check;
|
|
134
|
+
let unpreviewed = [];
|
|
135
|
+
if (previewing) {
|
|
136
|
+
({ check, unpreviewed } = await this.preview(facts));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
check = await this.draw(facts, binding, ExposureGate.reservationKey(binding, true));
|
|
140
|
+
if (check.status !== "EXCEEDED")
|
|
141
|
+
await this.end(check.held, "release", binding);
|
|
142
|
+
}
|
|
143
|
+
this.record({
|
|
144
|
+
event: "EXPOSURE_OBSERVED",
|
|
145
|
+
intent_id: binding.intentId,
|
|
146
|
+
intent_hash: binding.intentHash,
|
|
147
|
+
would: check.status,
|
|
148
|
+
...(check.status === "EXCEEDED"
|
|
149
|
+
? { limit_key: check.limitKey, on_exceed: check.onExceed, reason_code: check.reasonCode }
|
|
150
|
+
: {}),
|
|
151
|
+
...(check.status === "UNAVAILABLE" ? { reason_code: check.code } : {}),
|
|
152
|
+
unstated: [...check.unstated],
|
|
153
|
+
...(previewing ? { read_only: true, unpreviewed: [...unpreviewed] } : {}),
|
|
154
|
+
});
|
|
155
|
+
return check;
|
|
156
|
+
}
|
|
157
|
+
/** Shadow's read-only answer: usage plus this amount against each covering limit's cap. */
|
|
158
|
+
async preview(facts) {
|
|
159
|
+
const unavailable = (error) => ({
|
|
160
|
+
check: {
|
|
161
|
+
status: "UNAVAILABLE",
|
|
162
|
+
code: ExposureGate.codeOf(error),
|
|
163
|
+
held: [],
|
|
164
|
+
unstated: [],
|
|
165
|
+
ungoverned: false,
|
|
166
|
+
},
|
|
167
|
+
unpreviewed: [],
|
|
168
|
+
});
|
|
169
|
+
let limits;
|
|
170
|
+
try {
|
|
171
|
+
limits = await this.retrying(() => this.options.ledger.limits());
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
return unavailable(error);
|
|
175
|
+
}
|
|
176
|
+
const unstated = [];
|
|
177
|
+
const unpreviewed = [];
|
|
178
|
+
const asked = new Map();
|
|
179
|
+
const covering = limits
|
|
180
|
+
.filter((limit) => this.covers(limit, facts))
|
|
181
|
+
.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
182
|
+
for (const limit of covering) {
|
|
183
|
+
if (limit.kind === "sequence") {
|
|
184
|
+
unpreviewed.push(limit.key);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const cap = limit.caps?.find((entry) => entry.currency === facts.currency);
|
|
188
|
+
if (cap === undefined)
|
|
189
|
+
continue;
|
|
190
|
+
let kind = "vendor";
|
|
191
|
+
let digest = ORG_SUBJECT_DIGEST;
|
|
192
|
+
if (limit.subject !== "org") {
|
|
193
|
+
const id = facts.subjects[limit.subject];
|
|
194
|
+
if (id === undefined) {
|
|
195
|
+
unstated.push(limit.key);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
kind = limit.subject;
|
|
199
|
+
digest = this.digest(limit.subject, id);
|
|
200
|
+
}
|
|
201
|
+
let usage = asked.get(`${kind}:${digest}`);
|
|
202
|
+
if (usage === undefined) {
|
|
203
|
+
try {
|
|
204
|
+
usage = await this.retrying(() => this.options.ledger.subjectUsage(kind, digest));
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
return unavailable(error);
|
|
208
|
+
}
|
|
209
|
+
asked.set(`${kind}:${digest}`, usage);
|
|
210
|
+
}
|
|
211
|
+
const counted = usage.get(limit.key);
|
|
212
|
+
if (counted === undefined || counted === null) {
|
|
213
|
+
unpreviewed.push(limit.key);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const used = counted.find((entry) => entry.currency === facts.currency)?.used ?? 0;
|
|
217
|
+
if (facts.amount > Math.max(0, cap.maxAmount - used)) {
|
|
218
|
+
return {
|
|
219
|
+
check: {
|
|
220
|
+
status: "EXCEEDED",
|
|
221
|
+
limitKey: limit.key,
|
|
222
|
+
onExceed: limit.onExceed,
|
|
223
|
+
reasonCode: "EXPOSURE_LIMIT_EXCEEDED",
|
|
224
|
+
unstated,
|
|
225
|
+
},
|
|
226
|
+
unpreviewed,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return { check: { status: "WITHIN_LIMIT", held: [], unstated }, unpreviewed };
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Ends the reservations once the payment's outcome is known: settled
|
|
234
|
+
* when it committed (for the amount the answer states, when the route
|
|
235
|
+
* names where and it is no more than reserved), released when it was not
|
|
236
|
+
* executed, kept when nobody can say. A failure to settle or release is
|
|
237
|
+
* retried and then recorded; it never changes what already executed.
|
|
238
|
+
*/
|
|
239
|
+
async conclude(check, outcome, binding, settledAmount = null) {
|
|
240
|
+
const held = check.status === "EXCEEDED" ? [] : check.held;
|
|
241
|
+
if (held.length === 0)
|
|
242
|
+
return "NONE";
|
|
243
|
+
if (outcome === "INDETERMINATE") {
|
|
244
|
+
this.record({
|
|
245
|
+
event: "EXPOSURE_KEPT",
|
|
246
|
+
intent_id: binding.intentId,
|
|
247
|
+
intent_hash: binding.intentHash,
|
|
248
|
+
reason_codes: ["EXECUTION_INDETERMINATE"],
|
|
249
|
+
reservations: held.map((entry) => ({ ...entry })),
|
|
250
|
+
});
|
|
251
|
+
return "KEPT";
|
|
252
|
+
}
|
|
253
|
+
const end = outcome === "COMMITTED" ? "settle" : "release";
|
|
254
|
+
const failed = await this.end(held, end, binding, settledAmount);
|
|
255
|
+
this.record({
|
|
256
|
+
event: end === "settle" ? "EXPOSURE_SETTLED" : "EXPOSURE_RELEASED",
|
|
257
|
+
intent_id: binding.intentId,
|
|
258
|
+
intent_hash: binding.intentHash,
|
|
259
|
+
limits: held.filter((entry) => !failed.includes(entry)).map((entry) => entry.limitKey),
|
|
260
|
+
...(end === "settle" && settledAmount !== null ? { amount_stated: true } : {}),
|
|
261
|
+
});
|
|
262
|
+
if (failed.length > 0)
|
|
263
|
+
return "FAILED";
|
|
264
|
+
return end === "settle" ? "SETTLED" : "RELEASED";
|
|
265
|
+
}
|
|
266
|
+
/** The limits that cover the facts, the reservations made against them, in key order. */
|
|
267
|
+
async draw(facts, binding, reservationKey,
|
|
268
|
+
/** Reserved under instead where the earlier attempt's reservation was released by hand. */
|
|
269
|
+
fallbackKey = null) {
|
|
270
|
+
let limits;
|
|
271
|
+
try {
|
|
272
|
+
limits = await this.retrying(() => this.options.ledger.limits());
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
return {
|
|
276
|
+
status: "UNAVAILABLE",
|
|
277
|
+
code: ExposureGate.codeOf(error),
|
|
278
|
+
held: [],
|
|
279
|
+
unstated: [],
|
|
280
|
+
ungoverned: false,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const held = [];
|
|
284
|
+
const unstated = [];
|
|
285
|
+
const replayed = [];
|
|
286
|
+
const covering = limits
|
|
287
|
+
.filter((limit) => this.covers(limit, facts))
|
|
288
|
+
.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
289
|
+
for (const limit of covering) {
|
|
290
|
+
const request = this.request(limit, facts, binding, reservationKey);
|
|
291
|
+
if (request === null) {
|
|
292
|
+
unstated.push(limit.key);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
// The same reservation_key and body on a retry: the ledger answers
|
|
297
|
+
// with the reservation it already holds, never a second draw.
|
|
298
|
+
let answer;
|
|
299
|
+
try {
|
|
300
|
+
answer = await this.retrying(() => this.options.ledger.reserve(limit.key, request));
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
// The earlier attempt's reservation was released: someone found its
|
|
304
|
+
// payment did not happen. This one draws afresh, under its own key.
|
|
305
|
+
if (fallbackKey === null ||
|
|
306
|
+
!(error instanceof ExposureUnavailable) ||
|
|
307
|
+
error.code !== "EXPOSURE_RESERVATION_RELEASED") {
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
const fresh = this.request(limit, facts, binding, fallbackKey);
|
|
311
|
+
answer = await this.retrying(() => this.options.ledger.reserve(limit.key, fresh));
|
|
312
|
+
}
|
|
313
|
+
if (answer.decision !== "PROCEED") {
|
|
314
|
+
await this.end(held, "release", binding);
|
|
315
|
+
return {
|
|
316
|
+
status: "EXCEEDED",
|
|
317
|
+
limitKey: limit.key,
|
|
318
|
+
onExceed: answer.decision,
|
|
319
|
+
reasonCode: answer.reasonCode,
|
|
320
|
+
unstated,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
if (answer.reservationId !== null) {
|
|
324
|
+
held.push({ limitKey: limit.key, reservationId: answer.reservationId });
|
|
325
|
+
if (answer.replayed)
|
|
326
|
+
replayed.push(limit.key);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
return {
|
|
331
|
+
status: "UNAVAILABLE",
|
|
332
|
+
code: ExposureGate.codeOf(error),
|
|
333
|
+
held,
|
|
334
|
+
unstated,
|
|
335
|
+
ungoverned: false,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
status: "WITHIN_LIMIT",
|
|
341
|
+
held,
|
|
342
|
+
unstated,
|
|
343
|
+
...(replayed.length === 0 ? {} : { replayed }),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/** Whether a limit governs this action: its action type, its actor type, and an amount to count. */
|
|
347
|
+
covers(limit, facts) {
|
|
348
|
+
if (!limit.actionTypes.includes(facts.actionType))
|
|
349
|
+
return false;
|
|
350
|
+
if (limit.actorTypes !== undefined && !limit.actorTypes.includes(this.options.actorType)) {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
if (limit.kind === "sequence") {
|
|
354
|
+
const step = STEP_OF[facts.actionType];
|
|
355
|
+
return step !== undefined && (limit.steps?.includes(step) ?? true);
|
|
356
|
+
}
|
|
357
|
+
return facts.amount > 0;
|
|
358
|
+
}
|
|
359
|
+
/** The reservation for one limit; null when the route does not state its subject. */
|
|
360
|
+
request(limit, facts, binding, reservationKey) {
|
|
361
|
+
let idDigest;
|
|
362
|
+
if (limit.subject !== "org") {
|
|
363
|
+
const id = facts.subjects[limit.subject];
|
|
364
|
+
if (id === undefined)
|
|
365
|
+
return null;
|
|
366
|
+
idDigest = this.digest(limit.subject, id);
|
|
367
|
+
}
|
|
368
|
+
const sequence = limit.kind === "sequence";
|
|
369
|
+
const agent = facts.subjects.agent;
|
|
370
|
+
if (sequence && agent === undefined)
|
|
371
|
+
return null;
|
|
372
|
+
const core = {
|
|
373
|
+
subject: { kind: limit.subject, ...(idDigest === undefined ? {} : { id_digest: idDigest }) },
|
|
374
|
+
amount: facts.amount,
|
|
375
|
+
currency: facts.currency,
|
|
376
|
+
action_type: facts.actionType,
|
|
377
|
+
reservation_key: reservationKey,
|
|
378
|
+
...(sequence && agent !== undefined
|
|
379
|
+
? {
|
|
380
|
+
actor: { kind: "agent", id_digest: this.digest("actor", agent) },
|
|
381
|
+
step: STEP_OF[facts.actionType],
|
|
382
|
+
}
|
|
383
|
+
: {}),
|
|
384
|
+
};
|
|
385
|
+
return {
|
|
386
|
+
...core,
|
|
387
|
+
// Binds the key to this request: the same key with anything else is a conflict.
|
|
388
|
+
request_digest: sha256(Rfc8785.stringify({ limit: limit.key, ...core })),
|
|
389
|
+
occurred_at: binding.capturedAt,
|
|
390
|
+
source: { ...SOURCE, record_id: binding.intentId },
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
/** Settles or releases each reservation; the ones that still failed, each recorded. */
|
|
394
|
+
async end(held, end, binding, amount = null) {
|
|
395
|
+
const failed = [];
|
|
396
|
+
for (const entry of held) {
|
|
397
|
+
try {
|
|
398
|
+
await this.retrying(() => end === "settle"
|
|
399
|
+
? this.options.ledger.settle(entry.limitKey, entry.reservationId, amount ?? undefined)
|
|
400
|
+
: this.options.ledger.release(entry.limitKey, entry.reservationId));
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
failed.push(entry);
|
|
404
|
+
// An unsettled reservation keeps counting, and an unreleased one counts
|
|
405
|
+
// until it leaves the window: either errs toward the cap. The line names
|
|
406
|
+
// the reservation, so it can be ended by hand.
|
|
407
|
+
this.record({
|
|
408
|
+
event: end === "settle" ? "EXPOSURE_SETTLE_FAILED" : "EXPOSURE_RELEASE_FAILED",
|
|
409
|
+
intent_id: binding.intentId,
|
|
410
|
+
intent_hash: binding.intentHash,
|
|
411
|
+
limit_key: entry.limitKey,
|
|
412
|
+
reservation_id: entry.reservationId,
|
|
413
|
+
reason_code: ExposureGate.codeOf(error),
|
|
414
|
+
});
|
|
415
|
+
this.options.count?.(end === "settle" ? "SETTLE_FAILED" : "RELEASE_FAILED");
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return failed;
|
|
419
|
+
}
|
|
420
|
+
/** Asks again only where asking again cannot count twice, a bounded number of times. */
|
|
421
|
+
async retrying(call) {
|
|
422
|
+
for (let attempt = 1;; attempt += 1) {
|
|
423
|
+
try {
|
|
424
|
+
return await call();
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
const retryable = error instanceof ExposureUnavailable && error.retryable;
|
|
428
|
+
if (!retryable || attempt >= this.attempts)
|
|
429
|
+
throw error;
|
|
430
|
+
await this.sleep(this.retryDelayMs * attempt);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
record(fields) {
|
|
435
|
+
try {
|
|
436
|
+
this.options.evidence(fields);
|
|
437
|
+
}
|
|
438
|
+
catch {
|
|
439
|
+
// A line that cannot be written leaves the payment's outcome as it was.
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
static codeOf(error) {
|
|
443
|
+
return error instanceof ExposureUnavailable ? error.code : "EXPOSURE_FAILED";
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
//# sourceMappingURL=ExposureGate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExposureGate.js","sourceRoot":"","sources":["../../src/exposure/ExposureGate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAkB,M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