@decionis/agentsafe 0.2.5 → 0.4.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 +264 -89
- package/dist/Cli.js +24 -0
- package/dist/Cli.js.map +1 -1
- package/dist/Index.d.ts +10 -4
- package/dist/Index.d.ts.map +1 -1
- package/dist/Index.js +8 -2
- 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/adapters/AdapterActionHandler.d.ts.map +1 -1
- package/dist/adapters/AdapterActionHandler.js +8 -4
- package/dist/adapters/AdapterActionHandler.js.map +1 -1
- package/dist/adapters/EffectAdapter.d.ts +6 -1
- package/dist/adapters/EffectAdapter.d.ts.map +1 -1
- package/dist/adapters/EffectAdapter.js +7 -1
- package/dist/adapters/EffectAdapter.js.map +1 -1
- package/dist/adapters/EffectAwareGrantVerifier.d.ts +5 -2
- package/dist/adapters/EffectAwareGrantVerifier.d.ts.map +1 -1
- package/dist/adapters/EffectAwareGrantVerifier.js +9 -0
- package/dist/adapters/EffectAwareGrantVerifier.js.map +1 -1
- package/dist/adapters/banking/BankingAction.d.ts +2 -2
- package/dist/adapters/banking/CoreBankingHttpAdapter.d.ts.map +1 -1
- package/dist/adapters/banking/CoreBankingHttpAdapter.js +4 -4
- package/dist/adapters/banking/CoreBankingHttpAdapter.js.map +1 -1
- package/dist/adapters/cards/CardAuthorizationMatcher.d.ts +44 -0
- package/dist/adapters/cards/CardAuthorizationMatcher.d.ts.map +1 -0
- package/dist/adapters/cards/CardAuthorizationMatcher.js +39 -0
- package/dist/adapters/cards/CardAuthorizationMatcher.js.map +1 -0
- package/dist/adapters/cards/CardEffect.d.ts +52 -0
- package/dist/adapters/cards/CardEffect.d.ts.map +1 -0
- package/dist/adapters/cards/CardEffect.js +117 -0
- package/dist/adapters/cards/CardEffect.js.map +1 -0
- package/dist/adapters/cards/CardHandlers.d.ts +15 -0
- package/dist/adapters/cards/CardHandlers.d.ts.map +1 -0
- package/dist/adapters/cards/CardHandlers.js +26 -0
- package/dist/adapters/cards/CardHandlers.js.map +1 -0
- package/dist/adapters/cards/CardHoldSeal.d.ts +29 -0
- package/dist/adapters/cards/CardHoldSeal.d.ts.map +1 -0
- package/dist/adapters/cards/CardHoldSeal.js +87 -0
- package/dist/adapters/cards/CardHoldSeal.js.map +1 -0
- package/dist/adapters/cards/CardHoldStore.d.ts +102 -0
- package/dist/adapters/cards/CardHoldStore.d.ts.map +1 -0
- package/dist/adapters/cards/CardHoldStore.js +9 -0
- package/dist/adapters/cards/CardHoldStore.js.map +1 -0
- package/dist/adapters/cards/CardHolds.d.ts +19 -0
- package/dist/adapters/cards/CardHolds.d.ts.map +1 -0
- package/dist/adapters/cards/CardHolds.js +57 -0
- package/dist/adapters/cards/CardHolds.js.map +1 -0
- package/dist/adapters/cards/CardPurchase.d.ts +61 -0
- package/dist/adapters/cards/CardPurchase.d.ts.map +1 -0
- package/dist/adapters/cards/CardPurchase.js +116 -0
- package/dist/adapters/cards/CardPurchase.js.map +1 -0
- package/dist/adapters/cards/HeldCardGrants.d.ts +69 -0
- package/dist/adapters/cards/HeldCardGrants.d.ts.map +1 -0
- package/dist/adapters/cards/HeldCardGrants.js +169 -0
- package/dist/adapters/cards/HeldCardGrants.js.map +1 -0
- package/dist/adapters/cards/Pan.d.ts +17 -0
- package/dist/adapters/cards/Pan.d.ts.map +1 -0
- package/dist/adapters/cards/Pan.js +52 -0
- package/dist/adapters/cards/Pan.js.map +1 -0
- package/dist/adapters/cards/PostgresCardHolds.d.ts +95 -0
- package/dist/adapters/cards/PostgresCardHolds.d.ts.map +1 -0
- package/dist/adapters/cards/PostgresCardHolds.js +411 -0
- package/dist/adapters/cards/PostgresCardHolds.js.map +1 -0
- package/dist/adapters/mcp/McpGuard.d.ts.map +1 -1
- package/dist/adapters/mcp/McpGuard.js +9 -4
- package/dist/adapters/mcp/McpGuard.js.map +1 -1
- package/dist/audit/HashChain.d.ts +8 -2
- package/dist/audit/HashChain.d.ts.map +1 -1
- package/dist/audit/HashChain.js +14 -2
- package/dist/audit/HashChain.js.map +1 -1
- package/dist/cli/Cards.d.ts +5 -0
- package/dist/cli/Cards.d.ts.map +1 -0
- package/dist/cli/Cards.js +48 -0
- package/dist/cli/Cards.js.map +1 -0
- 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/Edge.d.ts +4 -0
- package/dist/cli/Edge.d.ts.map +1 -0
- package/dist/cli/Edge.js +250 -0
- package/dist/cli/Edge.js.map +1 -0
- package/dist/cli/Help.d.ts.map +1 -1
- package/dist/cli/Help.js +9 -0
- package/dist/cli/Help.js.map +1 -1
- package/dist/cli/Host.d.ts +36 -0
- package/dist/cli/Host.d.ts.map +1 -0
- package/dist/cli/Host.js +247 -0
- package/dist/cli/Host.js.map +1 -0
- package/dist/cli/TcpBrokerCli.d.ts +4 -0
- package/dist/cli/TcpBrokerCli.d.ts.map +1 -0
- package/dist/cli/TcpBrokerCli.js +93 -0
- package/dist/cli/TcpBrokerCli.js.map +1 -0
- package/dist/cli/TcpClientCli.d.ts +16 -0
- package/dist/cli/TcpClientCli.d.ts.map +1 -0
- package/dist/cli/TcpClientCli.js +175 -0
- package/dist/cli/TcpClientCli.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 +31 -0
- package/dist/config/ConfigKeys.js.map +1 -1
- package/dist/config/ExecutorConfig.d.ts +115 -0
- package/dist/config/ExecutorConfig.d.ts.map +1 -1
- package/dist/config/ExecutorConfig.js +212 -0
- package/dist/config/ExecutorConfig.js.map +1 -1
- package/dist/edge/EdgeLicence.d.ts +25 -0
- package/dist/edge/EdgeLicence.d.ts.map +1 -0
- package/dist/edge/EdgeLicence.js +42 -0
- package/dist/edge/EdgeLicence.js.map +1 -0
- package/dist/edge/EdgeReplay.d.ts +45 -0
- package/dist/edge/EdgeReplay.d.ts.map +1 -0
- package/dist/edge/EdgeReplay.js +69 -0
- package/dist/edge/EdgeReplay.js.map +1 -0
- package/dist/edge/Entitlement.d.ts +57 -0
- package/dist/edge/Entitlement.d.ts.map +1 -0
- package/dist/edge/Entitlement.js +139 -0
- package/dist/edge/Entitlement.js.map +1 -0
- package/dist/edge/EntitlementEvaluation.d.ts +66 -0
- package/dist/edge/EntitlementEvaluation.d.ts.map +1 -0
- package/dist/edge/EntitlementEvaluation.js +74 -0
- package/dist/edge/EntitlementEvaluation.js.map +1 -0
- package/dist/edge/UsageCount.d.ts +40 -0
- package/dist/edge/UsageCount.d.ts.map +1 -0
- package/dist/edge/UsageCount.js +140 -0
- package/dist/edge/UsageCount.js.map +1 -0
- package/dist/edge/UsageKeyRegistration.d.ts +34 -0
- package/dist/edge/UsageKeyRegistration.d.ts.map +1 -0
- package/dist/edge/UsageKeyRegistration.js +74 -0
- package/dist/edge/UsageKeyRegistration.js.map +1 -0
- package/dist/edge/UsageMeter.d.ts +89 -0
- package/dist/edge/UsageMeter.d.ts.map +1 -0
- package/dist/edge/UsageMeter.js +275 -0
- package/dist/edge/UsageMeter.js.map +1 -0
- package/dist/edge/UsagePeriod.d.ts +23 -0
- package/dist/edge/UsagePeriod.d.ts.map +1 -0
- package/dist/edge/UsagePeriod.js +31 -0
- package/dist/edge/UsagePeriod.js.map +1 -0
- package/dist/edge/UsageReport.d.ts +92 -0
- package/dist/edge/UsageReport.d.ts.map +1 -0
- package/dist/edge/UsageReport.js +153 -0
- package/dist/edge/UsageReport.js.map +1 -0
- package/dist/edge/UsageTally.d.ts +63 -0
- package/dist/edge/UsageTally.d.ts.map +1 -0
- package/dist/edge/UsageTally.js +89 -0
- package/dist/edge/UsageTally.js.map +1 -0
- package/dist/egress/EgressError.d.ts +7 -1
- package/dist/egress/EgressError.d.ts.map +1 -1
- package/dist/egress/EgressError.js.map +1 -1
- package/dist/egress/EgressPolicy.d.ts +16 -3
- package/dist/egress/EgressPolicy.d.ts.map +1 -1
- package/dist/egress/EgressPolicy.js +33 -3
- package/dist/egress/EgressPolicy.js.map +1 -1
- package/dist/egress/GuardedFetch.d.ts +38 -1
- package/dist/egress/GuardedFetch.d.ts.map +1 -1
- package/dist/egress/GuardedFetch.js +52 -7
- package/dist/egress/GuardedFetch.js.map +1 -1
- package/dist/egress/TcpClient.d.ts +103 -0
- package/dist/egress/TcpClient.d.ts.map +1 -0
- package/dist/egress/TcpClient.js +490 -0
- package/dist/egress/TcpClient.js.map +1 -0
- package/dist/egress/TcpControlClient.d.ts +49 -0
- package/dist/egress/TcpControlClient.d.ts.map +1 -0
- package/dist/egress/TcpControlClient.js +186 -0
- package/dist/egress/TcpControlClient.js.map +1 -0
- package/dist/gateway/ForwardHandler.d.ts.map +1 -1
- package/dist/gateway/ForwardHandler.js +7 -4
- package/dist/gateway/ForwardHandler.js.map +1 -1
- package/dist/gateway/Gateway.d.ts +190 -10
- package/dist/gateway/Gateway.d.ts.map +1 -1
- package/dist/gateway/Gateway.js +465 -62
- package/dist/gateway/Gateway.js.map +1 -1
- package/dist/gateway/GatewayConfig.d.ts +67 -0
- package/dist/gateway/GatewayConfig.d.ts.map +1 -1
- package/dist/gateway/GatewayConfig.js +149 -2
- package/dist/gateway/GatewayConfig.js.map +1 -1
- package/dist/gateway/InterceptedRequest.d.ts +9 -2
- package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
- package/dist/gateway/InterceptedRequest.js +41 -9
- package/dist/gateway/InterceptedRequest.js.map +1 -1
- package/dist/gateway/RateLimit.d.ts +29 -0
- package/dist/gateway/RateLimit.d.ts.map +1 -0
- package/dist/gateway/RateLimit.js +33 -0
- package/dist/gateway/RateLimit.js.map +1 -0
- package/dist/gateway/RefusalSampler.d.ts +28 -0
- package/dist/gateway/RefusalSampler.d.ts.map +1 -0
- package/dist/gateway/RefusalSampler.js +52 -0
- package/dist/gateway/RefusalSampler.js.map +1 -0
- package/dist/gateway/RouteTable.d.ts +3 -0
- package/dist/gateway/RouteTable.d.ts.map +1 -1
- package/dist/gateway/RouteTable.js +44 -7
- package/dist/gateway/RouteTable.js.map +1 -1
- package/dist/gateway/Upstream.d.ts +26 -0
- package/dist/gateway/Upstream.d.ts.map +1 -1
- package/dist/gateway/Upstream.js +41 -2
- package/dist/gateway/Upstream.js.map +1 -1
- package/dist/gateway/UpstreamProof.d.ts +235 -0
- package/dist/gateway/UpstreamProof.d.ts.map +1 -0
- package/dist/gateway/UpstreamProof.js +375 -0
- package/dist/gateway/UpstreamProof.js.map +1 -0
- package/dist/handlers/ForwardRequestHandler.d.ts +5 -1
- package/dist/handlers/ForwardRequestHandler.d.ts.map +1 -1
- package/dist/handlers/ForwardRequestHandler.js +12 -2
- package/dist/handlers/ForwardRequestHandler.js.map +1 -1
- package/dist/hosted/TenantHost.d.ts +180 -0
- package/dist/hosted/TenantHost.d.ts.map +1 -0
- package/dist/hosted/TenantHost.js +432 -0
- package/dist/hosted/TenantHost.js.map +1 -0
- package/dist/hosted/TenantRegistry.d.ts +73 -0
- package/dist/hosted/TenantRegistry.d.ts.map +1 -0
- package/dist/hosted/TenantRegistry.js +123 -0
- package/dist/hosted/TenantRegistry.js.map +1 -0
- package/dist/http/ExecutorHttpServer.d.ts +7 -0
- package/dist/http/ExecutorHttpServer.d.ts.map +1 -1
- package/dist/http/ExecutorHttpServer.js +30 -5
- package/dist/http/ExecutorHttpServer.js.map +1 -1
- package/dist/http/GatewayHttpServer.d.ts +55 -3
- package/dist/http/GatewayHttpServer.d.ts.map +1 -1
- package/dist/http/GatewayHttpServer.js +157 -17
- package/dist/http/GatewayHttpServer.js.map +1 -1
- package/dist/http/RedirectServer.d.ts +26 -0
- package/dist/http/RedirectServer.d.ts.map +1 -0
- package/dist/http/RedirectServer.js +62 -0
- package/dist/http/RedirectServer.js.map +1 -0
- package/dist/http/Routes.d.ts +24 -0
- package/dist/http/Routes.d.ts.map +1 -1
- package/dist/http/Routes.js +28 -1
- package/dist/http/Routes.js.map +1 -1
- package/dist/http/TcpBroker.d.ts +57 -0
- package/dist/http/TcpBroker.d.ts.map +1 -0
- package/dist/http/TcpBroker.js +299 -0
- package/dist/http/TcpBroker.js.map +1 -0
- package/dist/http/TcpHostRelay.d.ts +24 -0
- package/dist/http/TcpHostRelay.d.ts.map +1 -0
- package/dist/http/TcpHostRelay.js +194 -0
- package/dist/http/TcpHostRelay.js.map +1 -0
- package/dist/http/TcpRelayStreams.d.ts +24 -0
- package/dist/http/TcpRelayStreams.d.ts.map +1 -0
- package/dist/http/TcpRelayStreams.js +128 -0
- package/dist/http/TcpRelayStreams.js.map +1 -0
- package/dist/http/TlsListener.d.ts +3 -1
- package/dist/http/TlsListener.d.ts.map +1 -1
- package/dist/http/TlsListener.js +7 -2
- package/dist/http/TlsListener.js.map +1 -1
- package/dist/identity/Authenticator.d.ts.map +1 -1
- package/dist/identity/Authenticator.js +5 -2
- package/dist/identity/Authenticator.js.map +1 -1
- package/dist/identity/PrincipalsFile.d.ts +5 -1
- package/dist/identity/PrincipalsFile.d.ts.map +1 -1
- package/dist/identity/PrincipalsFile.js +2 -0
- package/dist/identity/PrincipalsFile.js.map +1 -1
- package/dist/incident/Metrics.d.ts +2 -0
- package/dist/incident/Metrics.d.ts.map +1 -1
- package/dist/incident/Metrics.js +10 -0
- package/dist/incident/Metrics.js.map +1 -1
- package/dist/incident/SecurityEvents.d.ts +98 -0
- package/dist/incident/SecurityEvents.d.ts.map +1 -1
- package/dist/incident/SecurityEvents.js +96 -2
- package/dist/incident/SecurityEvents.js.map +1 -1
- package/dist/journal/ExecutionJournal.d.ts +27 -0
- package/dist/journal/ExecutionJournal.d.ts.map +1 -1
- package/dist/journal/ExecutionJournal.js +28 -0
- package/dist/journal/ExecutionJournal.js.map +1 -1
- package/dist/journal/FileExecutionJournal.d.ts +2 -1
- package/dist/journal/FileExecutionJournal.d.ts.map +1 -1
- package/dist/journal/FileExecutionJournal.js +4 -1
- package/dist/journal/FileExecutionJournal.js.map +1 -1
- package/dist/journal/InMemoryExecutionJournal.d.ts +2 -1
- package/dist/journal/InMemoryExecutionJournal.d.ts.map +1 -1
- package/dist/journal/InMemoryExecutionJournal.js +4 -1
- package/dist/journal/InMemoryExecutionJournal.js.map +1 -1
- package/dist/service/AuthorityClients.d.ts +8 -1
- package/dist/service/AuthorityClients.d.ts.map +1 -1
- package/dist/service/AuthorityClients.js +33 -5
- package/dist/service/AuthorityClients.js.map +1 -1
- package/dist/service/EdgeRuntime.d.ts +73 -0
- package/dist/service/EdgeRuntime.d.ts.map +1 -0
- package/dist/service/EdgeRuntime.js +209 -0
- package/dist/service/EdgeRuntime.js.map +1 -0
- package/dist/service/EscalationResolver.d.ts +109 -5
- package/dist/service/EscalationResolver.d.ts.map +1 -1
- package/dist/service/EscalationResolver.js +41 -3
- package/dist/service/EscalationResolver.js.map +1 -1
- package/dist/service/Requests.d.ts +45 -2
- package/dist/service/Requests.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.d.ts +144 -1
- package/dist/service/TrustedExecutorService.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.js +866 -37
- package/dist/service/TrustedExecutorService.js.map +1 -1
- package/dist/tcp/TcpWire.d.ts +18 -0
- package/dist/tcp/TcpWire.d.ts.map +1 -0
- package/dist/tcp/TcpWire.js +114 -0
- package/dist/tcp/TcpWire.js.map +1 -0
- package/dist/verify/VerifyAuditChain.d.ts +5 -0
- package/dist/verify/VerifyAuditChain.d.ts.map +1 -1
- package/dist/verify/VerifyAuditChain.js +20 -4
- package/dist/verify/VerifyAuditChain.js.map +1 -1
- package/package.json +7 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DecionisGate, DecionisGrantVerifier, SafeExecutor, ShadowPipeline, } from "@decionis/agent-safe-pipeline";
|
|
1
|
+
import { DecionisGate, DecionisGrantVerifier, EdgeDecisionAuthority, LocalAuthorizationVerifier, SafeExecutor, ShadowPipeline, } from "@decionis/agent-safe-pipeline";
|
|
2
2
|
import { EffectAwareGrantVerifier } from "../adapters/EffectAwareGrantVerifier.js";
|
|
3
3
|
import { EscalationResolver } from "./EscalationResolver.js";
|
|
4
4
|
/**
|
|
@@ -57,26 +57,54 @@ export class AuthorityClients {
|
|
|
57
57
|
const grantVerifier = new DecionisGrantVerifier(authority);
|
|
58
58
|
// The verifier the executor runs finalizes with whatever the handler
|
|
59
59
|
// observed; without an effect plane it is the grant verifier itself.
|
|
60
|
-
const
|
|
60
|
+
const hostedVerifier = options.effects === undefined
|
|
61
61
|
? grantVerifier
|
|
62
62
|
: new EffectAwareGrantVerifier({
|
|
63
63
|
verifier: grantVerifier,
|
|
64
64
|
register: options.effects,
|
|
65
65
|
observer: options.observer ?? { id: "agentsafe", version: "0.1.0" },
|
|
66
66
|
});
|
|
67
|
+
// With the edge evaluator, an intent is decided locally first and the
|
|
68
|
+
// gate is asked only for an escalation or when no local decision can be
|
|
69
|
+
// made; a local authorization is consumed here, a hosted one is claimed
|
|
70
|
+
// through the hosted verifier, and either way the intent runs once.
|
|
71
|
+
const edge = options.edge ?? null;
|
|
72
|
+
const decider = edge === null
|
|
73
|
+
? gate
|
|
74
|
+
: new EdgeDecisionAuthority({
|
|
75
|
+
module: edge.module,
|
|
76
|
+
bundles: edge.bundles,
|
|
77
|
+
hosted: gate,
|
|
78
|
+
grants: edge.grants,
|
|
79
|
+
replay: edge.replay,
|
|
80
|
+
mode: config.mode,
|
|
81
|
+
onUnavailable: edge.onUnavailable,
|
|
82
|
+
clock: edge.clock,
|
|
83
|
+
record: (record) => edge.record(record),
|
|
84
|
+
});
|
|
85
|
+
const verifier = edge === null
|
|
86
|
+
? hostedVerifier
|
|
87
|
+
: new LocalAuthorizationVerifier({
|
|
88
|
+
grants: edge.grants,
|
|
89
|
+
replay: edge.replay,
|
|
90
|
+
delegate: hostedVerifier,
|
|
91
|
+
clock: edge.clock,
|
|
92
|
+
record: (record) => edge.record(record),
|
|
93
|
+
});
|
|
67
94
|
const presenceApiKey = config.escalation.mode === "DIRECT"
|
|
68
95
|
? secrets.get("PRESENCE_API_KEY").use((value) => value.toString("utf8"))
|
|
69
96
|
: null;
|
|
70
97
|
const escalation = new EscalationResolver(config.escalation, gate, audit, {
|
|
71
98
|
...(options.presence === undefined ? {} : { presence: options.presence }),
|
|
72
99
|
...(options.fetch === undefined ? {} : { fetch: options.fetch }),
|
|
73
|
-
}, presenceApiKey);
|
|
100
|
+
}, presenceApiKey, decider);
|
|
74
101
|
return {
|
|
75
102
|
gate,
|
|
103
|
+
authority: decider,
|
|
76
104
|
verifier,
|
|
77
|
-
executor: new SafeExecutor(registry, verifier, audit),
|
|
105
|
+
executor: new SafeExecutor(registry, verifier, audit, options.attempts === undefined ? undefined : { attempts: options.attempts }),
|
|
78
106
|
escalation,
|
|
79
|
-
shadow: config.mode === "SHADOW" ? new ShadowPipeline(
|
|
107
|
+
shadow: config.mode === "SHADOW" ? new ShadowPipeline(decider, { audit }) : null,
|
|
80
108
|
};
|
|
81
109
|
}
|
|
82
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthorityClients.js","sourceRoot":"","sources":["../../src/service/AuthorityClients.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,YAAY,EACZ,cAAc,
|
|
1
|
+
{"version":3,"file":"AuthorityClients.js","sourceRoot":"","sources":["../../src/service/AuthorityClients.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,YAAY,EACZ,cAAc,GAOf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAOnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AA8B7D;;;;;;GAMG;AACH,MAAM,QAAQ,GAA0B,CAAC,kBAAkB,CAAC,CAAC;A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AAE,IAAI,YAAY,CACxB,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAC5E;YACD,UAAU;YACV,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI;SACjF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { EdgeBundleManager, EdgeModule, LocalGrants, type EdgeDecisionRecord, type LocalFinalizationRecord, type ReplayStore } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import type { HashChain } from "../audit/HashChain.js";
|
|
3
|
+
import type { LineWriter } from "../audit/LineAuditSink.js";
|
|
4
|
+
import type { ExecutorConfig } from "../config/ExecutorConfig.js";
|
|
5
|
+
import { EdgeLicence } from "../edge/EdgeLicence.js";
|
|
6
|
+
import { type LoadPg } from "../edge/EdgeReplay.js";
|
|
7
|
+
import { UsageMeter } from "../edge/UsageMeter.js";
|
|
8
|
+
import type { FetchLike } from "../handlers/HandlerRegistration.js";
|
|
9
|
+
import type { SecurityEvents } from "../incident/SecurityEvents.js";
|
|
10
|
+
import type { SecretStore } from "../secrets/SecretStore.js";
|
|
11
|
+
export interface EdgeRuntimeOptions {
|
|
12
|
+
readonly config: ExecutorConfig;
|
|
13
|
+
/** Where the replay store's connection string and the usage-report key are read from. */
|
|
14
|
+
readonly secrets: SecretStore;
|
|
15
|
+
/** The organisation's Decionis key, read at the moment of each bundle fetch. */
|
|
16
|
+
readonly apiKey: () => string;
|
|
17
|
+
/** The guarded fetch: a bundle comes from the authority's origin, and nowhere else. */
|
|
18
|
+
readonly fetch: FetchLike;
|
|
19
|
+
readonly events: SecurityEvents;
|
|
20
|
+
/** The executor's evidence chain, and the writer its audit lines go through. */
|
|
21
|
+
readonly chain: HashChain;
|
|
22
|
+
readonly write: LineWriter;
|
|
23
|
+
/** Loads the module; the configured file unless a test hands in its own. */
|
|
24
|
+
readonly loadModule?: (path: string) => EdgeModule;
|
|
25
|
+
/** Loads `pg` for the Postgres replay store; the installed package unless a test hands in its own. */
|
|
26
|
+
readonly loadPg?: LoadPg;
|
|
27
|
+
readonly clock?: () => number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The long-lived half of the edge authority: the module, the bundle it holds,
|
|
31
|
+
* the local grants, the replay store, the usage meter and the licence check.
|
|
32
|
+
* It outlives a rebuild of the authority clients, so a rotated Presence
|
|
33
|
+
* credential neither reloads the module nor forgets which intents have run.
|
|
34
|
+
*/
|
|
35
|
+
export declare class EdgeRuntime {
|
|
36
|
+
private readonly options;
|
|
37
|
+
readonly module: EdgeModule;
|
|
38
|
+
readonly bundles: EdgeBundleManager;
|
|
39
|
+
readonly grants: LocalGrants;
|
|
40
|
+
readonly replay: ReplayStore;
|
|
41
|
+
readonly usage: UsageMeter;
|
|
42
|
+
readonly licence: EdgeLicence;
|
|
43
|
+
readonly onUnavailable: "hosted" | "block";
|
|
44
|
+
readonly clock: () => number;
|
|
45
|
+
private readonly shared;
|
|
46
|
+
private timer;
|
|
47
|
+
private constructor();
|
|
48
|
+
/**
|
|
49
|
+
* The runtime the configuration asks for, or null for a hosted deployment.
|
|
50
|
+
* A module that cannot be read, is not WebAssembly, or is not ABI 3, and a
|
|
51
|
+
* usage-report key that is not an Ed25519 private key, are refusals to
|
|
52
|
+
* start that name the variable and the reason, never a deployment that
|
|
53
|
+
* quietly decides hosted instead.
|
|
54
|
+
*/
|
|
55
|
+
static create(options: EdgeRuntimeOptions): EdgeRuntime | null;
|
|
56
|
+
/**
|
|
57
|
+
* Links one local decision, or a local attempt's outcome, on the evidence
|
|
58
|
+
* chain. A decision is counted as its line is written, with the sequence
|
|
59
|
+
* and hash that line carries, so the count is the chain's own.
|
|
60
|
+
*/
|
|
61
|
+
record(record: EdgeDecisionRecord | LocalFinalizationRecord): void;
|
|
62
|
+
/**
|
|
63
|
+
* The replay store first: a shared store that cannot be reached is a
|
|
64
|
+
* refusal to start, since nothing could be run once. Then the first
|
|
65
|
+
* bundle fetch, the first usage report and licence check, and the hourly
|
|
66
|
+
* schedule for both and for removing lapsed claims.
|
|
67
|
+
*/
|
|
68
|
+
start(): Promise<void>;
|
|
69
|
+
/** One round of housekeeping. Never throws, and touches no decision. */
|
|
70
|
+
tick(): Promise<void>;
|
|
71
|
+
stop(): void;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=EdgeRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EdgeRuntime.d.ts","sourceRoot":"","sources":["../../src/service/EdgeRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,UAAU,EAGV,WAAW,EAGX,KAAK,kBAAkB,EAEvB,KAAK,uBAAuB,EAC5B,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAiD,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEnG,OAAO,EAGL,UAAU,EAEX,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,E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;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBnC,wEAAwE;IAC3D,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ3B,IAAI,IAAI,IAAI;CAOpB"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { EdgeBundleManager, EdgeModule, EdgeModuleError, FileBundleSource, LocalGrants, UrlBundleSource, } from "@decionis/agent-safe-pipeline";
|
|
3
|
+
import { EdgeLicence } from "../edge/EdgeLicence.js";
|
|
4
|
+
import { memoryReplay, postgresReplay } from "../edge/EdgeReplay.js";
|
|
5
|
+
import { FileEntitlementSource, UrlEntitlementSource } from "../edge/Entitlement.js";
|
|
6
|
+
import { FileUsageDelivery, UrlUsageDelivery, UsageMeter, } from "../edge/UsageMeter.js";
|
|
7
|
+
import { usageSigningKey } from "../edge/UsageReport.js";
|
|
8
|
+
import { RequestContext } from "../http/RequestContext.js";
|
|
9
|
+
/** How often usage reports are attempted, the entitlement re-read and lapsed claims removed. */
|
|
10
|
+
const TICK_MS = 3_600_000;
|
|
11
|
+
/**
|
|
12
|
+
* The long-lived half of the edge authority: the module, the bundle it holds,
|
|
13
|
+
* the local grants, the replay store, the usage meter and the licence check.
|
|
14
|
+
* It outlives a rebuild of the authority clients, so a rotated Presence
|
|
15
|
+
* credential neither reloads the module nor forgets which intents have run.
|
|
16
|
+
*/
|
|
17
|
+
export class EdgeRuntime {
|
|
18
|
+
options;
|
|
19
|
+
module;
|
|
20
|
+
bundles;
|
|
21
|
+
grants;
|
|
22
|
+
replay;
|
|
23
|
+
usage;
|
|
24
|
+
licence;
|
|
25
|
+
onUnavailable;
|
|
26
|
+
clock;
|
|
27
|
+
shared;
|
|
28
|
+
timer = null;
|
|
29
|
+
constructor(options, module, source, key) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
const { config, events } = options;
|
|
32
|
+
const edge = config.edge;
|
|
33
|
+
if (edge === null)
|
|
34
|
+
throw new Error("EDGE_NOT_CONFIGURED");
|
|
35
|
+
this.module = module;
|
|
36
|
+
this.clock = options.clock ?? Date.now;
|
|
37
|
+
this.onUnavailable = edge.onUnavailable;
|
|
38
|
+
this.grants = new LocalGrants(this.clock);
|
|
39
|
+
this.shared =
|
|
40
|
+
edge.replay.store === "memory"
|
|
41
|
+
? memoryReplay()
|
|
42
|
+
: postgresReplay({
|
|
43
|
+
databaseUrl: () => options.secrets
|
|
44
|
+
.get("EXECUTOR_EDGE_REPLAY_DATABASE_URL")
|
|
45
|
+
.use((value) => value.toString("utf8").trim()),
|
|
46
|
+
namespace: edge.orgId,
|
|
47
|
+
table: edge.replay.table,
|
|
48
|
+
clock: this.clock,
|
|
49
|
+
...(options.loadPg === undefined ? {} : { load: options.loadPg }),
|
|
50
|
+
});
|
|
51
|
+
this.replay = this.shared.store;
|
|
52
|
+
this.bundles = new EdgeBundleManager({
|
|
53
|
+
module,
|
|
54
|
+
source,
|
|
55
|
+
orgId: edge.orgId,
|
|
56
|
+
refreshSeconds: edge.refreshSeconds,
|
|
57
|
+
clock: this.clock,
|
|
58
|
+
onEvent: (event) => events.emit(event),
|
|
59
|
+
});
|
|
60
|
+
const url = edge.bundle.source === "url";
|
|
61
|
+
const delivery = url
|
|
62
|
+
? new UrlUsageDelivery({
|
|
63
|
+
baseUrl: config.authority.baseUrl,
|
|
64
|
+
apiKey: options.apiKey,
|
|
65
|
+
fetch: options.fetch,
|
|
66
|
+
})
|
|
67
|
+
: edge.usage.reportDir === null
|
|
68
|
+
? null
|
|
69
|
+
: new FileUsageDelivery(edge.usage.reportDir);
|
|
70
|
+
this.usage = new UsageMeter({
|
|
71
|
+
orgId: edge.orgId,
|
|
72
|
+
chain: options.chain,
|
|
73
|
+
installationId: edge.usage.installationId,
|
|
74
|
+
stateDir: config.evidence.journalDir === null ? null : join(config.evidence.journalDir, "edge"),
|
|
75
|
+
checkpointLines: config.evidence.checkpointLines,
|
|
76
|
+
events,
|
|
77
|
+
key,
|
|
78
|
+
delivery,
|
|
79
|
+
clock: this.clock,
|
|
80
|
+
});
|
|
81
|
+
this.licence = new EdgeLicence({
|
|
82
|
+
source: url
|
|
83
|
+
? new UrlEntitlementSource({
|
|
84
|
+
baseUrl: config.authority.baseUrl,
|
|
85
|
+
apiKey: options.apiKey,
|
|
86
|
+
fetch: options.fetch,
|
|
87
|
+
})
|
|
88
|
+
: new FileEntitlementSource(edge.entitlement.file, edge.entitlement.jwksFile),
|
|
89
|
+
meter: this.usage,
|
|
90
|
+
orgId: edge.orgId,
|
|
91
|
+
events,
|
|
92
|
+
clock: this.clock,
|
|
93
|
+
});
|
|
94
|
+
if (key !== null) {
|
|
95
|
+
// The kid an operator registers as a `usage_report` provider key.
|
|
96
|
+
events.emit({
|
|
97
|
+
event: "EDGE_USAGE_KEY_LOADED",
|
|
98
|
+
kid: key().kid,
|
|
99
|
+
installation_id: this.usage.installationId,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The runtime the configuration asks for, or null for a hosted deployment.
|
|
105
|
+
* A module that cannot be read, is not WebAssembly, or is not ABI 3, and a
|
|
106
|
+
* usage-report key that is not an Ed25519 private key, are refusals to
|
|
107
|
+
* start that name the variable and the reason, never a deployment that
|
|
108
|
+
* quietly decides hosted instead.
|
|
109
|
+
*/
|
|
110
|
+
static create(options) {
|
|
111
|
+
const edge = options.config.edge;
|
|
112
|
+
if (edge === null)
|
|
113
|
+
return null;
|
|
114
|
+
let module;
|
|
115
|
+
try {
|
|
116
|
+
module = (options.loadModule ?? EdgeModule.fromFile)(edge.wasmPath);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
const code = error instanceof EdgeModuleError ? error.code : "EDGE_MODULE_INVALID";
|
|
120
|
+
throw new Error(`CONFIG_INVALID: EXECUTOR_EDGE_WASM_PATH (${code})`);
|
|
121
|
+
}
|
|
122
|
+
let key = null;
|
|
123
|
+
if (edge.usage.signing) {
|
|
124
|
+
// Read at each use, so a rotated key file is followed; checked once here.
|
|
125
|
+
key = () => usageSigningKey(options.secrets
|
|
126
|
+
.get("EXECUTOR_EDGE_USAGE_SIGNING_KEY")
|
|
127
|
+
.use((value) => value.toString("utf8")), edge.usage.keyId);
|
|
128
|
+
try {
|
|
129
|
+
key();
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
throw new Error("CONFIG_INVALID: EXECUTOR_EDGE_USAGE_SIGNING_KEY (not an Ed25519 key)");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const source = edge.bundle.source === "file"
|
|
136
|
+
? new FileBundleSource(edge.bundle.file)
|
|
137
|
+
: new UrlBundleSource({
|
|
138
|
+
baseUrl: options.config.authority.baseUrl,
|
|
139
|
+
apiKey: options.apiKey,
|
|
140
|
+
allowInsecureLoopback: options.config.authority.allowInsecureLoopback,
|
|
141
|
+
fetch: options.fetch,
|
|
142
|
+
});
|
|
143
|
+
return new EdgeRuntime(options, module, source, key);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Links one local decision, or a local attempt's outcome, on the evidence
|
|
147
|
+
* chain. A decision is counted as its line is written, with the sequence
|
|
148
|
+
* and hash that line carries, so the count is the chain's own.
|
|
149
|
+
*/
|
|
150
|
+
record(record) {
|
|
151
|
+
// The record holds identifiers, codes and digests only; copied as JSON so
|
|
152
|
+
// the chain links exactly what the line will say.
|
|
153
|
+
const fields = JSON.parse(JSON.stringify(record));
|
|
154
|
+
const at = new Date(this.clock()).toISOString();
|
|
155
|
+
const chain = this.options.chain;
|
|
156
|
+
chain.link({ at, ...fields, caller_principal: RequestContext.current()?.principal ?? null }, (line) => {
|
|
157
|
+
this.options.write(line);
|
|
158
|
+
if (record.event !== "EDGE_DECISION")
|
|
159
|
+
return;
|
|
160
|
+
this.usage.observe({
|
|
161
|
+
at,
|
|
162
|
+
mode: record.mode,
|
|
163
|
+
verdict: record.verdict,
|
|
164
|
+
delegated: record.delegated,
|
|
165
|
+
jti: record.jti,
|
|
166
|
+
seq: chain.head.seq,
|
|
167
|
+
hash: chain.head.hash,
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The replay store first: a shared store that cannot be reached is a
|
|
173
|
+
* refusal to start, since nothing could be run once. Then the first
|
|
174
|
+
* bundle fetch, the first usage report and licence check, and the hourly
|
|
175
|
+
* schedule for both and for removing lapsed claims.
|
|
176
|
+
*/
|
|
177
|
+
async start() {
|
|
178
|
+
try {
|
|
179
|
+
await this.shared.ready();
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
const code = error instanceof Error && error.message === "REPLAY_DRIVER_MISSING"
|
|
183
|
+
? "REPLAY_DRIVER_MISSING"
|
|
184
|
+
: "REPLAY_STORE_UNAVAILABLE";
|
|
185
|
+
throw new Error(`CONFIG_INVALID: EXECUTOR_EDGE_REPLAY_DATABASE_URL (${code})`);
|
|
186
|
+
}
|
|
187
|
+
await this.bundles.start();
|
|
188
|
+
await this.tick();
|
|
189
|
+
this.timer = setInterval(() => void this.tick(), TICK_MS);
|
|
190
|
+
this.timer.unref();
|
|
191
|
+
}
|
|
192
|
+
/** One round of housekeeping. Never throws, and touches no decision. */
|
|
193
|
+
async tick() {
|
|
194
|
+
await this.usage.report();
|
|
195
|
+
await this.licence.check();
|
|
196
|
+
await this.shared.cleanup().catch(() => {
|
|
197
|
+
this.options.events.emit({ event: "EDGE_REPLAY_CLEANUP_FAILED" });
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
stop() {
|
|
201
|
+
if (this.timer !== null)
|
|
202
|
+
clearInterval(this.timer);
|
|
203
|
+
this.timer = null;
|
|
204
|
+
this.bundles.stop();
|
|
205
|
+
this.usage.stop();
|
|
206
|
+
void this.shared.close().catch(() => undefined);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=EdgeRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Edg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C,GAAG,EAAE;YACrC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,4BAA4B,EAAE,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,IAAI;QACT,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI;YAAE,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { type AuditRecorder, type CapturedIntent, type DecionisGate, type
|
|
2
|
+
import { type AuditRecorder, type CapturedIntent, type DecionisGate, type DecisionAuthority, type DecisionGate, type PresenceApprovalClient } from "@decionis/agent-safe-pipeline";
|
|
3
3
|
import type { EscalationConfig } from "../config/ExecutorConfig.js";
|
|
4
4
|
import type { FetchLike } from "../handlers/HandlerRegistration.js";
|
|
5
5
|
/**
|
|
@@ -45,13 +45,98 @@ export declare const EscalationHandoffSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
45
45
|
}, z.core.$strict>;
|
|
46
46
|
}, z.core.$strict>], "mode">;
|
|
47
47
|
export type EscalationHandoff = z.infer<typeof EscalationHandoffSchema>;
|
|
48
|
+
/**
|
|
49
|
+
* A presence provider's attestation presented for an open escalation: the
|
|
50
|
+
* exact intent, and the compact JWS the provider signed over it (a
|
|
51
|
+
* cardholder's tap, for instance). It is evidence for a fresh evaluation,
|
|
52
|
+
* never authority; this process shapes and bounds it, sends it to the
|
|
53
|
+
* authority, which verifies it, and keeps nothing of it.
|
|
54
|
+
*/
|
|
55
|
+
export declare const AttestationResumeSchema: z.ZodObject<{
|
|
56
|
+
mode: z.ZodLiteral<"ATTESTATION">;
|
|
57
|
+
intent: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
58
|
+
attestation: z.ZodString;
|
|
59
|
+
requirement: z.ZodOptional<z.ZodUnknown>;
|
|
60
|
+
}, z.core.$strict>;
|
|
61
|
+
/** What `/v1/escalations` accepts: a handoff it was given, or an attestation for the intent. */
|
|
62
|
+
export declare const EscalationResumeSchema: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
63
|
+
mode: z.ZodLiteral<"DIRECT">;
|
|
64
|
+
intent: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
65
|
+
request_id: z.ZodString;
|
|
66
|
+
approval_url: z.ZodNullable<z.ZodString>;
|
|
67
|
+
expires_at: z.ZodNullable<z.ZodString>;
|
|
68
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
69
|
+
mode: z.ZodLiteral<"MANAGED">;
|
|
70
|
+
intent: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
71
|
+
escalation: z.ZodObject<{
|
|
72
|
+
escalationId: z.ZodString;
|
|
73
|
+
intentId: z.ZodString;
|
|
74
|
+
status: z.ZodEnum<{
|
|
75
|
+
FAILED: "FAILED";
|
|
76
|
+
PENDING_PRESENCE: "PENDING_PRESENCE";
|
|
77
|
+
PRESENCE_REQUESTED: "PRESENCE_REQUESTED";
|
|
78
|
+
AWAITING_APPROVER: "AWAITING_APPROVER";
|
|
79
|
+
PRESENCE_VERIFIED: "PRESENCE_VERIFIED";
|
|
80
|
+
REAUTHORIZING: "REAUTHORIZING";
|
|
81
|
+
GRANT_READY: "GRANT_READY";
|
|
82
|
+
EXPIRED: "EXPIRED";
|
|
83
|
+
REJECTED: "REJECTED";
|
|
84
|
+
BLOCKED: "BLOCKED";
|
|
85
|
+
CANCELLED: "CANCELLED";
|
|
86
|
+
}>;
|
|
87
|
+
outcome: z.ZodEnum<{
|
|
88
|
+
ALLOW: "ALLOW";
|
|
89
|
+
BLOCK: "BLOCK";
|
|
90
|
+
ESCALATE_PENDING: "ESCALATE_PENDING";
|
|
91
|
+
ERROR: "ERROR";
|
|
92
|
+
}>;
|
|
93
|
+
expiresAt: z.ZodString;
|
|
94
|
+
reasonCodes: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
95
|
+
}, z.core.$strict>;
|
|
96
|
+
}, z.core.$strict>], "mode">, z.ZodObject<{
|
|
97
|
+
mode: z.ZodLiteral<"ATTESTATION">;
|
|
98
|
+
intent: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
99
|
+
attestation: z.ZodString;
|
|
100
|
+
requirement: z.ZodOptional<z.ZodUnknown>;
|
|
101
|
+
}, z.core.$strict>]>;
|
|
102
|
+
export type EscalationResume = z.infer<typeof EscalationResumeSchema>;
|
|
103
|
+
/**
|
|
104
|
+
* Where the authority sent the hold, as its decision carried it: the policy's
|
|
105
|
+
* selector (kind and role, never a person) and who proves the person, by
|
|
106
|
+
* which method. A third-party provider here (`koard`, method `CARD_TAP`)
|
|
107
|
+
* means that provider's attestation alone resumes the hold; `decionis` means
|
|
108
|
+
* Decionis Presence. Routing for whoever asks the person, never authority.
|
|
109
|
+
*/
|
|
110
|
+
export interface AttestationRequirement {
|
|
111
|
+
readonly requirement_id: string | null;
|
|
112
|
+
readonly expires_at: string;
|
|
113
|
+
readonly selector: {
|
|
114
|
+
readonly kind: "ROLE" | "PRINCIPAL";
|
|
115
|
+
readonly role_id?: string;
|
|
116
|
+
} | null;
|
|
117
|
+
readonly verification: {
|
|
118
|
+
readonly provider: string;
|
|
119
|
+
readonly methods: readonly string[];
|
|
120
|
+
readonly level: "STANDARD" | "HIGH_CONFIDENCE";
|
|
121
|
+
} | null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* What the caller is handed when an escalation can be resumed with an
|
|
125
|
+
* attestation and nothing else: the exact intent, to present back with it,
|
|
126
|
+
* and where the authority sent the hold when it said.
|
|
127
|
+
*/
|
|
128
|
+
export interface AttestationHandoff {
|
|
129
|
+
readonly mode: "ATTESTATION";
|
|
130
|
+
readonly intent: Record<string, unknown>;
|
|
131
|
+
readonly requirement: AttestationRequirement | null;
|
|
132
|
+
}
|
|
48
133
|
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
49
134
|
/** The handoff without the intent: what a mode knows, and what is echoed while pending. */
|
|
50
135
|
export type EscalationState = DistributiveOmit<EscalationHandoff, "intent">;
|
|
51
136
|
/** One step of a resumption: either a decision to run, or a state to report. */
|
|
52
137
|
export type EscalationResolution = {
|
|
53
138
|
readonly kind: "DECISION";
|
|
54
|
-
readonly decision:
|
|
139
|
+
readonly decision: DecisionGate;
|
|
55
140
|
} | {
|
|
56
141
|
readonly kind: "PENDING";
|
|
57
142
|
readonly handoff: EscalationState;
|
|
@@ -75,19 +160,38 @@ export interface EscalationDependencies {
|
|
|
75
160
|
export declare class EscalationResolver {
|
|
76
161
|
private readonly config;
|
|
77
162
|
private readonly gate;
|
|
163
|
+
/**
|
|
164
|
+
* What makes the first decision: the gate, unless an edge authority
|
|
165
|
+
* decides in front of it. Resumption is always the gate's: a ceremony's
|
|
166
|
+
* status and the re-evaluation with its receipt are hosted.
|
|
167
|
+
*/
|
|
168
|
+
private readonly first;
|
|
78
169
|
private readonly coordinator;
|
|
79
170
|
private readonly presence;
|
|
80
171
|
constructor(config: EscalationConfig, gate: DecionisGate, audit: AuditRecorder, dependencies?: EscalationDependencies,
|
|
81
172
|
/** The Presence credential for `DIRECT`, read from its handle by the caller for this build. */
|
|
82
|
-
presenceApiKey?: string | null
|
|
173
|
+
presenceApiKey?: string | null,
|
|
174
|
+
/**
|
|
175
|
+
* What makes the first decision: the gate, unless an edge authority
|
|
176
|
+
* decides in front of it. Resumption is always the gate's: a ceremony's
|
|
177
|
+
* status and the re-evaluation with its receipt are hosted.
|
|
178
|
+
*/
|
|
179
|
+
first?: DecisionAuthority);
|
|
83
180
|
get mode(): EscalationConfig["mode"];
|
|
84
181
|
/** The first evaluation: in managed mode it also asks the authority to orchestrate. */
|
|
85
|
-
evaluate(captured: CapturedIntent): Promise<
|
|
182
|
+
evaluate(captured: CapturedIntent): Promise<DecisionGate>;
|
|
86
183
|
/**
|
|
87
184
|
* What the caller is handed after an `ESCALATE`. In direct mode this opens
|
|
88
185
|
* the Presence request, bound to the intent hash the person will see.
|
|
89
186
|
*/
|
|
90
|
-
handoff(captured: CapturedIntent, decision:
|
|
187
|
+
handoff(captured: CapturedIntent, decision: DecisionGate): Promise<EscalationState | null>;
|
|
188
|
+
/**
|
|
189
|
+
* A fresh evaluation of the same intent with a presence attestation as the
|
|
190
|
+
* approval evidence. Whatever the escalation shape, this asks for no
|
|
191
|
+
* orchestration: the authority verifies the attestation against the
|
|
192
|
+
* intent hash and decides, and a refusal is a fail-closed `BLOCK`.
|
|
193
|
+
*/
|
|
194
|
+
attest(captured: CapturedIntent, attestation: string): Promise<DecisionGate>;
|
|
91
195
|
/** One bounded lookup, then either a fresh decision or the state to report. */
|
|
92
196
|
resume(captured: CapturedIntent, handoff: EscalationHandoff): Promise<EscalationResolution>;
|
|
93
197
|
private resumeManaged;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EscalationResolver.d.ts","sourceRoot":"","sources":["../../src/service/EscalationResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,YAAY,EAEjB,KAAK,sBAAsB,EAC5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAIpE;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;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CAAC,WAAW,CAAqC;IACjE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;gBAGtC,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,YAAY,EACnC,KAAK,EAAE,aAAa,EACpB,YAAY,GAAE,sBAA2B;IACzC,+FAA+F;IAC/F,cAAc,GAAE,MAAM,GAAG,IAAW;IACpC;;;;OAIG;IACc,KAAK,GAAE,iBAAwB;IA4BlD,IAAW,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAE1C;IAED,uFAAuF;IAC1E,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAiBtE;;;OAGG;IACU,OAAO,CAClB,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAsBlC;;;;;OAKG;IACU,MAAM,CAAC,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAMzF,+EAA+E;IAClE,MAAM,CACjB,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,oBAAoB,CAAC;YAQlB,aAAa;YA8Bb,YAAY;CAkC3B"}
|
|
@@ -42,6 +42,25 @@ export const EscalationHandoffSchema = z.discriminatedUnion("mode", [
|
|
|
42
42
|
}),
|
|
43
43
|
}),
|
|
44
44
|
]);
|
|
45
|
+
/**
|
|
46
|
+
* A presence provider's attestation presented for an open escalation: the
|
|
47
|
+
* exact intent, and the compact JWS the provider signed over it (a
|
|
48
|
+
* cardholder's tap, for instance). It is evidence for a fresh evaluation,
|
|
49
|
+
* never authority; this process shapes and bounds it, sends it to the
|
|
50
|
+
* authority, which verifies it, and keeps nothing of it.
|
|
51
|
+
*/
|
|
52
|
+
export const AttestationResumeSchema = z.strictObject({
|
|
53
|
+
mode: z.literal("ATTESTATION"),
|
|
54
|
+
intent: z.record(z.string(), z.unknown()),
|
|
55
|
+
attestation: z
|
|
56
|
+
.string()
|
|
57
|
+
.max(20_000)
|
|
58
|
+
.regex(/^[\w-]+\.[\w-]+\.[\w-]+$/),
|
|
59
|
+
/** The handoff's routing, echoed by a caller that presents the handoff whole; never read. */
|
|
60
|
+
requirement: z.unknown().optional(),
|
|
61
|
+
});
|
|
62
|
+
/** What `/v1/escalations` accepts: a handoff it was given, or an attestation for the intent. */
|
|
63
|
+
export const EscalationResumeSchema = z.union([EscalationHandoffSchema, AttestationResumeSchema]);
|
|
45
64
|
/**
|
|
46
65
|
* Resolves an `ESCALATE` in the shape the adopter configured. Both shapes
|
|
47
66
|
* are stateless on this side: the handoff the caller presents is validated
|
|
@@ -51,13 +70,21 @@ export const EscalationHandoffSchema = z.discriminatedUnion("mode", [
|
|
|
51
70
|
export class EscalationResolver {
|
|
52
71
|
config;
|
|
53
72
|
gate;
|
|
73
|
+
first;
|
|
54
74
|
coordinator;
|
|
55
75
|
presence;
|
|
56
76
|
constructor(config, gate, audit, dependencies = {},
|
|
57
77
|
/** The Presence credential for `DIRECT`, read from its handle by the caller for this build. */
|
|
58
|
-
presenceApiKey = null
|
|
78
|
+
presenceApiKey = null,
|
|
79
|
+
/**
|
|
80
|
+
* What makes the first decision: the gate, unless an edge authority
|
|
81
|
+
* decides in front of it. Resumption is always the gate's: a ceremony's
|
|
82
|
+
* status and the re-evaluation with its receipt are hosted.
|
|
83
|
+
*/
|
|
84
|
+
first = gate) {
|
|
59
85
|
this.config = config;
|
|
60
86
|
this.gate = gate;
|
|
87
|
+
this.first = first;
|
|
61
88
|
if (config.mode !== "DIRECT") {
|
|
62
89
|
this.coordinator = null;
|
|
63
90
|
this.presence = null;
|
|
@@ -81,8 +108,8 @@ export class EscalationResolver {
|
|
|
81
108
|
/** The first evaluation: in managed mode it also asks the authority to orchestrate. */
|
|
82
109
|
async evaluate(captured) {
|
|
83
110
|
if (this.config.mode !== "MANAGED")
|
|
84
|
-
return await this.
|
|
85
|
-
return await this.
|
|
111
|
+
return await this.first.evaluate(captured);
|
|
112
|
+
return await this.first.evaluate(captured, undefined, {
|
|
86
113
|
escalation: {
|
|
87
114
|
mode: "MANAGED",
|
|
88
115
|
approver: {
|
|
@@ -124,6 +151,17 @@ export class EscalationResolver {
|
|
|
124
151
|
expires_at: result.expires_at ?? null,
|
|
125
152
|
};
|
|
126
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* A fresh evaluation of the same intent with a presence attestation as the
|
|
156
|
+
* approval evidence. Whatever the escalation shape, this asks for no
|
|
157
|
+
* orchestration: the authority verifies the attestation against the
|
|
158
|
+
* intent hash and decides, and a refusal is a fail-closed `BLOCK`.
|
|
159
|
+
*/
|
|
160
|
+
async attest(captured, attestation) {
|
|
161
|
+
return await this.gate.evaluate(captured, {
|
|
162
|
+
humanApproval: { provider: "attestation", attestation },
|
|
163
|
+
});
|
|
164
|
+
}
|
|
127
165
|
/** One bounded lookup, then either a fresh decision or the state to report. */
|
|
128
166
|
async resume(captured, handoff) {
|
|
129
167
|
if (handoff.mode !== this.config.mode) {
|