@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.
Files changed (288) hide show
  1. package/README.md +68 -20
  2. package/dist/Cli.js +30 -3
  3. package/dist/Cli.js.map +1 -1
  4. package/dist/Index.d.ts +5 -3
  5. package/dist/Index.d.ts.map +1 -1
  6. package/dist/Index.js +3 -1
  7. package/dist/Index.js.map +1 -1
  8. package/dist/TrustedExecutor.d.ts.map +1 -1
  9. package/dist/TrustedExecutor.js +2 -0
  10. package/dist/TrustedExecutor.js.map +1 -1
  11. package/dist/acceptance/AcceptancePlan.d.ts +109 -0
  12. package/dist/acceptance/AcceptancePlan.d.ts.map +1 -0
  13. package/dist/acceptance/AcceptancePlan.js +128 -0
  14. package/dist/acceptance/AcceptancePlan.js.map +1 -0
  15. package/dist/acceptance/AcceptanceReport.d.ts +596 -0
  16. package/dist/acceptance/AcceptanceReport.d.ts.map +1 -0
  17. package/dist/acceptance/AcceptanceReport.js +361 -0
  18. package/dist/acceptance/AcceptanceReport.js.map +1 -0
  19. package/dist/acceptance/AcceptanceRun.d.ts +118 -0
  20. package/dist/acceptance/AcceptanceRun.d.ts.map +1 -0
  21. package/dist/acceptance/AcceptanceRun.js +419 -0
  22. package/dist/acceptance/AcceptanceRun.js.map +1 -0
  23. package/dist/acceptance/Coverage.d.ts +12 -0
  24. package/dist/acceptance/Coverage.d.ts.map +1 -0
  25. package/dist/acceptance/Coverage.js +48 -0
  26. package/dist/acceptance/Coverage.js.map +1 -0
  27. package/dist/acceptance/OutageDoubles.d.ts +34 -0
  28. package/dist/acceptance/OutageDoubles.d.ts.map +1 -0
  29. package/dist/acceptance/OutageDoubles.js +67 -0
  30. package/dist/acceptance/OutageDoubles.js.map +1 -0
  31. package/dist/acceptance/ZoneProbes.d.ts +368 -0
  32. package/dist/acceptance/ZoneProbes.d.ts.map +1 -0
  33. package/dist/acceptance/ZoneProbes.js +488 -0
  34. package/dist/acceptance/ZoneProbes.js.map +1 -0
  35. package/dist/adapters/JcsDigest.d.ts +6 -5
  36. package/dist/adapters/JcsDigest.d.ts.map +1 -1
  37. package/dist/adapters/JcsDigest.js +9 -8
  38. package/dist/adapters/JcsDigest.js.map +1 -1
  39. package/dist/adapters/mcp/McpGuard.d.ts +32 -3
  40. package/dist/adapters/mcp/McpGuard.d.ts.map +1 -1
  41. package/dist/adapters/mcp/McpGuard.js +29 -5
  42. package/dist/adapters/mcp/McpGuard.js.map +1 -1
  43. package/dist/adapters/mcp/McpIntentBinder.d.ts +18 -3
  44. package/dist/adapters/mcp/McpIntentBinder.d.ts.map +1 -1
  45. package/dist/adapters/mcp/McpIntentBinder.js +48 -1
  46. package/dist/adapters/mcp/McpIntentBinder.js.map +1 -1
  47. package/dist/adapters/mcp/McpInvocation.d.ts +9 -2
  48. package/dist/adapters/mcp/McpInvocation.d.ts.map +1 -1
  49. package/dist/adapters/mcp/McpInvocation.js.map +1 -1
  50. package/dist/cli/Accept.d.ts +9 -0
  51. package/dist/cli/Accept.d.ts.map +1 -0
  52. package/dist/cli/Accept.js +209 -0
  53. package/dist/cli/Accept.js.map +1 -0
  54. package/dist/cli/Actions.d.ts +16 -0
  55. package/dist/cli/Actions.d.ts.map +1 -0
  56. package/dist/cli/Actions.js +194 -0
  57. package/dist/cli/Actions.js.map +1 -0
  58. package/dist/cli/Arguments.d.ts +4 -0
  59. package/dist/cli/Arguments.d.ts.map +1 -1
  60. package/dist/cli/Arguments.js +12 -3
  61. package/dist/cli/Arguments.js.map +1 -1
  62. package/dist/cli/Commands.d.ts +1 -1
  63. package/dist/cli/Commands.d.ts.map +1 -1
  64. package/dist/cli/Commands.js +5 -0
  65. package/dist/cli/Commands.js.map +1 -1
  66. package/dist/cli/ConfigCommand.d.ts.map +1 -1
  67. package/dist/cli/ConfigCommand.js +10 -0
  68. package/dist/cli/ConfigCommand.js.map +1 -1
  69. package/dist/cli/Doctor.d.ts.map +1 -1
  70. package/dist/cli/Doctor.js +67 -1
  71. package/dist/cli/Doctor.js.map +1 -1
  72. package/dist/cli/Help.d.ts.map +1 -1
  73. package/dist/cli/Help.js +18 -1
  74. package/dist/cli/Help.js.map +1 -1
  75. package/dist/cli/Host.d.ts +5 -2
  76. package/dist/cli/Host.d.ts.map +1 -1
  77. package/dist/cli/Host.js +24 -2
  78. package/dist/cli/Host.js.map +1 -1
  79. package/dist/cli/Identity.d.ts +13 -1
  80. package/dist/cli/Identity.d.ts.map +1 -1
  81. package/dist/cli/Identity.js +25 -2
  82. package/dist/cli/Identity.js.map +1 -1
  83. package/dist/cli/Profile.d.ts +24 -0
  84. package/dist/cli/Profile.d.ts.map +1 -0
  85. package/dist/cli/Profile.js +168 -0
  86. package/dist/cli/Profile.js.map +1 -0
  87. package/dist/cli/Records.d.ts +15 -0
  88. package/dist/cli/Records.d.ts.map +1 -0
  89. package/dist/cli/Records.js +205 -0
  90. package/dist/cli/Records.js.map +1 -0
  91. package/dist/cli/Status.d.ts +23 -0
  92. package/dist/cli/Status.d.ts.map +1 -1
  93. package/dist/cli/Status.js +80 -18
  94. package/dist/cli/Status.js.map +1 -1
  95. package/dist/cli/VerifyAcceptance.d.ts +38 -0
  96. package/dist/cli/VerifyAcceptance.d.ts.map +1 -0
  97. package/dist/cli/VerifyAcceptance.js +143 -0
  98. package/dist/cli/VerifyAcceptance.js.map +1 -0
  99. package/dist/config/ConfigKeys.d.ts +2 -2
  100. package/dist/config/ConfigKeys.d.ts.map +1 -1
  101. package/dist/config/ConfigKeys.js +6 -0
  102. package/dist/config/ConfigKeys.js.map +1 -1
  103. package/dist/config/ExecutorConfig.d.ts +35 -1
  104. package/dist/config/ExecutorConfig.d.ts.map +1 -1
  105. package/dist/config/ExecutorConfig.js +53 -1
  106. package/dist/config/ExecutorConfig.js.map +1 -1
  107. package/dist/egress/ZoneHttpClient.d.ts +3 -0
  108. package/dist/egress/ZoneHttpClient.d.ts.map +1 -0
  109. package/dist/egress/ZoneHttpClient.js +72 -0
  110. package/dist/egress/ZoneHttpClient.js.map +1 -0
  111. package/dist/exposure/DecionisExposureLedger.d.ts +44 -0
  112. package/dist/exposure/DecionisExposureLedger.d.ts.map +1 -0
  113. package/dist/exposure/DecionisExposureLedger.js +175 -0
  114. package/dist/exposure/DecionisExposureLedger.js.map +1 -0
  115. package/dist/exposure/ExposureDeclaration.d.ts +68 -0
  116. package/dist/exposure/ExposureDeclaration.d.ts.map +1 -0
  117. package/dist/exposure/ExposureDeclaration.js +83 -0
  118. package/dist/exposure/ExposureDeclaration.js.map +1 -0
  119. package/dist/exposure/ExposureFacts.d.ts +61 -0
  120. package/dist/exposure/ExposureFacts.d.ts.map +1 -0
  121. package/dist/exposure/ExposureFacts.js +201 -0
  122. package/dist/exposure/ExposureFacts.js.map +1 -0
  123. package/dist/exposure/ExposureGate.d.ts +144 -0
  124. package/dist/exposure/ExposureGate.d.ts.map +1 -0
  125. package/dist/exposure/ExposureGate.js +446 -0
  126. package/dist/exposure/ExposureGate.js.map +1 -0
  127. package/dist/exposure/ExposureLedger.d.ts +93 -0
  128. package/dist/exposure/ExposureLedger.d.ts.map +1 -0
  129. package/dist/exposure/ExposureLedger.js +24 -0
  130. package/dist/exposure/ExposureLedger.js.map +1 -0
  131. package/dist/gateway/AttemptStore.d.ts +83 -0
  132. package/dist/gateway/AttemptStore.d.ts.map +1 -0
  133. package/dist/gateway/AttemptStore.js +229 -0
  134. package/dist/gateway/AttemptStore.js.map +1 -0
  135. package/dist/gateway/ForwardHandler.d.ts +50 -6
  136. package/dist/gateway/ForwardHandler.d.ts.map +1 -1
  137. package/dist/gateway/ForwardHandler.js +58 -14
  138. package/dist/gateway/ForwardHandler.js.map +1 -1
  139. package/dist/gateway/Gateway.d.ts +347 -15
  140. package/dist/gateway/Gateway.d.ts.map +1 -1
  141. package/dist/gateway/Gateway.js +1524 -63
  142. package/dist/gateway/Gateway.js.map +1 -1
  143. package/dist/gateway/GatewayConfig.d.ts +295 -0
  144. package/dist/gateway/GatewayConfig.d.ts.map +1 -1
  145. package/dist/gateway/GatewayConfig.js +485 -13
  146. package/dist/gateway/GatewayConfig.js.map +1 -1
  147. package/dist/gateway/GatewayManifest.d.ts +18 -0
  148. package/dist/gateway/GatewayManifest.d.ts.map +1 -0
  149. package/dist/gateway/GatewayManifest.js +42 -0
  150. package/dist/gateway/GatewayManifest.js.map +1 -0
  151. package/dist/gateway/GatewayMetrics.d.ts +12 -4
  152. package/dist/gateway/GatewayMetrics.d.ts.map +1 -1
  153. package/dist/gateway/GatewayMetrics.js +5 -0
  154. package/dist/gateway/GatewayMetrics.js.map +1 -1
  155. package/dist/gateway/GatewayReport.d.ts +39 -2
  156. package/dist/gateway/GatewayReport.d.ts.map +1 -1
  157. package/dist/gateway/GatewayReport.js +14 -0
  158. package/dist/gateway/GatewayReport.js.map +1 -1
  159. package/dist/gateway/HoldStore.d.ts +89 -0
  160. package/dist/gateway/HoldStore.d.ts.map +1 -0
  161. package/dist/gateway/HoldStore.js +280 -0
  162. package/dist/gateway/HoldStore.js.map +1 -0
  163. package/dist/gateway/InterceptedRequest.d.ts +55 -1
  164. package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
  165. package/dist/gateway/InterceptedRequest.js +63 -1
  166. package/dist/gateway/InterceptedRequest.js.map +1 -1
  167. package/dist/gateway/PolicySelector.d.ts +5 -0
  168. package/dist/gateway/PolicySelector.d.ts.map +1 -0
  169. package/dist/gateway/PolicySelector.js +9 -0
  170. package/dist/gateway/PolicySelector.js.map +1 -0
  171. package/dist/gateway/RouteTable.d.ts +72 -7
  172. package/dist/gateway/RouteTable.d.ts.map +1 -1
  173. package/dist/gateway/RouteTable.js +133 -9
  174. package/dist/gateway/RouteTable.js.map +1 -1
  175. package/dist/gateway/ShadowLedger.d.ts +11 -0
  176. package/dist/gateway/ShadowLedger.d.ts.map +1 -1
  177. package/dist/gateway/ShadowLedger.js +11 -0
  178. package/dist/gateway/ShadowLedger.js.map +1 -1
  179. package/dist/gateway/SubjectSessions.d.ts +113 -0
  180. package/dist/gateway/SubjectSessions.d.ts.map +1 -0
  181. package/dist/gateway/SubjectSessions.js +219 -0
  182. package/dist/gateway/SubjectSessions.js.map +1 -0
  183. package/dist/gateway/TargetEffect.d.ts +74 -0
  184. package/dist/gateway/TargetEffect.d.ts.map +1 -0
  185. package/dist/gateway/TargetEffect.js +95 -0
  186. package/dist/gateway/TargetEffect.js.map +1 -0
  187. package/dist/gateway/TargetReader.d.ts +70 -0
  188. package/dist/gateway/TargetReader.d.ts.map +1 -0
  189. package/dist/gateway/TargetReader.js +106 -0
  190. package/dist/gateway/TargetReader.js.map +1 -0
  191. package/dist/gateway/Upstream.d.ts +26 -0
  192. package/dist/gateway/Upstream.d.ts.map +1 -1
  193. package/dist/gateway/Upstream.js +42 -3
  194. package/dist/gateway/Upstream.js.map +1 -1
  195. package/dist/hosted/TenantHost.d.ts +26 -6
  196. package/dist/hosted/TenantHost.d.ts.map +1 -1
  197. package/dist/hosted/TenantHost.js +45 -10
  198. package/dist/hosted/TenantHost.js.map +1 -1
  199. package/dist/hosted/TenantRegistry.d.ts +28 -0
  200. package/dist/hosted/TenantRegistry.d.ts.map +1 -1
  201. package/dist/hosted/TenantRegistry.js +60 -1
  202. package/dist/hosted/TenantRegistry.js.map +1 -1
  203. package/dist/http/GatewayHttpServer.d.ts +7 -0
  204. package/dist/http/GatewayHttpServer.d.ts.map +1 -1
  205. package/dist/http/GatewayHttpServer.js +103 -3
  206. package/dist/http/GatewayHttpServer.js.map +1 -1
  207. package/dist/identity/WorkloadJwtVerifier.d.ts +13 -0
  208. package/dist/identity/WorkloadJwtVerifier.d.ts.map +1 -1
  209. package/dist/identity/WorkloadJwtVerifier.js +40 -8
  210. package/dist/identity/WorkloadJwtVerifier.js.map +1 -1
  211. package/dist/incident/HaltSwitch.d.ts +10 -2
  212. package/dist/incident/HaltSwitch.d.ts.map +1 -1
  213. package/dist/incident/HaltSwitch.js +22 -2
  214. package/dist/incident/HaltSwitch.js.map +1 -1
  215. package/dist/incident/SecurityEvents.d.ts +18 -0
  216. package/dist/incident/SecurityEvents.d.ts.map +1 -1
  217. package/dist/incident/SecurityEvents.js +17 -0
  218. package/dist/incident/SecurityEvents.js.map +1 -1
  219. package/dist/limits/HardLimits.d.ts.map +1 -1
  220. package/dist/limits/HardLimits.js.map +1 -1
  221. package/dist/outcomes/CardOutcomeEvidence.d.ts +56 -0
  222. package/dist/outcomes/CardOutcomeEvidence.d.ts.map +1 -0
  223. package/dist/outcomes/CardOutcomeEvidence.js +211 -0
  224. package/dist/outcomes/CardOutcomeEvidence.js.map +1 -0
  225. package/dist/outcomes/CardOutcomeFact.d.ts +90 -0
  226. package/dist/outcomes/CardOutcomeFact.d.ts.map +1 -0
  227. package/dist/outcomes/CardOutcomeFact.js +76 -0
  228. package/dist/outcomes/CardOutcomeFact.js.map +1 -0
  229. package/dist/outcomes/CardOutcomeLedger.d.ts +26 -0
  230. package/dist/outcomes/CardOutcomeLedger.d.ts.map +1 -0
  231. package/dist/outcomes/CardOutcomeLedger.js +31 -0
  232. package/dist/outcomes/CardOutcomeLedger.js.map +1 -0
  233. package/dist/outcomes/CardOutcomeRecorder.d.ts +35 -0
  234. package/dist/outcomes/CardOutcomeRecorder.d.ts.map +1 -0
  235. package/dist/outcomes/CardOutcomeRecorder.js +84 -0
  236. package/dist/outcomes/CardOutcomeRecorder.js.map +1 -0
  237. package/dist/outcomes/CardOutcomes.d.ts +68 -0
  238. package/dist/outcomes/CardOutcomes.d.ts.map +1 -0
  239. package/dist/outcomes/CardOutcomes.js +191 -0
  240. package/dist/outcomes/CardOutcomes.js.map +1 -0
  241. package/dist/outcomes/CoreOutcomeEvidenceClient.d.ts +54 -0
  242. package/dist/outcomes/CoreOutcomeEvidenceClient.d.ts.map +1 -0
  243. package/dist/outcomes/CoreOutcomeEvidenceClient.js +116 -0
  244. package/dist/outcomes/CoreOutcomeEvidenceClient.js.map +1 -0
  245. package/dist/outcomes/FileCardOutcomeLedger.d.ts +36 -0
  246. package/dist/outcomes/FileCardOutcomeLedger.d.ts.map +1 -0
  247. package/dist/outcomes/FileCardOutcomeLedger.js +152 -0
  248. package/dist/outcomes/FileCardOutcomeLedger.js.map +1 -0
  249. package/dist/outcomes/OutcomeEvidence.d.ts +238 -0
  250. package/dist/outcomes/OutcomeEvidence.d.ts.map +1 -0
  251. package/dist/outcomes/OutcomeEvidence.js +130 -0
  252. package/dist/outcomes/OutcomeEvidence.js.map +1 -0
  253. package/dist/outcomes/OutcomeEvidencePublisher.d.ts +81 -0
  254. package/dist/outcomes/OutcomeEvidencePublisher.d.ts.map +1 -0
  255. package/dist/outcomes/OutcomeEvidencePublisher.js +189 -0
  256. package/dist/outcomes/OutcomeEvidencePublisher.js.map +1 -0
  257. package/dist/outcomes/OutcomeEvidenceStore.d.ts +57 -0
  258. package/dist/outcomes/OutcomeEvidenceStore.d.ts.map +1 -0
  259. package/dist/outcomes/OutcomeEvidenceStore.js +191 -0
  260. package/dist/outcomes/OutcomeEvidenceStore.js.map +1 -0
  261. package/dist/posture/ActionSpaceDrift.d.ts +40 -0
  262. package/dist/posture/ActionSpaceDrift.d.ts.map +1 -0
  263. package/dist/posture/ActionSpaceDrift.js +67 -0
  264. package/dist/posture/ActionSpaceDrift.js.map +1 -0
  265. package/dist/posture/DeploymentFingerprint.d.ts +88 -0
  266. package/dist/posture/DeploymentFingerprint.d.ts.map +1 -0
  267. package/dist/posture/DeploymentFingerprint.js +78 -0
  268. package/dist/posture/DeploymentFingerprint.js.map +1 -0
  269. package/dist/secrets/SecretStore.d.ts +6 -1
  270. package/dist/secrets/SecretStore.d.ts.map +1 -1
  271. package/dist/secrets/SecretStore.js.map +1 -1
  272. package/dist/service/EscalationResolver.d.ts +6 -6
  273. package/dist/service/EscalationResolver.d.ts.map +1 -1
  274. package/dist/service/EscalationResolver.js +8 -4
  275. package/dist/service/EscalationResolver.js.map +1 -1
  276. package/dist/service/Requests.d.ts +6 -0
  277. package/dist/service/Requests.d.ts.map +1 -1
  278. package/dist/service/Requests.js +9 -1
  279. package/dist/service/Requests.js.map +1 -1
  280. package/dist/service/TrustedExecutorService.d.ts +21 -1
  281. package/dist/service/TrustedExecutorService.d.ts.map +1 -1
  282. package/dist/service/TrustedExecutorService.js +54 -13
  283. package/dist/service/TrustedExecutorService.js.map +1 -1
  284. package/dist/verify/VerifyingProvider.d.ts +32 -6
  285. package/dist/verify/VerifyingProvider.d.ts.map +1 -1
  286. package/dist/verify/VerifyingProvider.js +16 -2
  287. package/dist/verify/VerifyingProvider.js.map +1 -1
  288. package/package.json +7 -6
@@ -0,0 +1,280 @@
1
+ import { createCipheriv, createDecipheriv, createHash, 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
+ /** The most holds one gateway keeps. */
5
+ export const MAX_HELD = 1_000;
6
+ /** Holds in this process's memory: lost on restart, and seen only by this replica. */
7
+ export class MemoryHoldStore {
8
+ clock;
9
+ held = new Map();
10
+ constructor(clock) {
11
+ this.clock = clock;
12
+ }
13
+ put(intentId, entry) {
14
+ this.sweep();
15
+ if (this.held.size >= MAX_HELD)
16
+ return false;
17
+ this.held.set(intentId, entry);
18
+ return true;
19
+ }
20
+ get(intentId) {
21
+ this.sweep();
22
+ return this.held.get(intentId);
23
+ }
24
+ claim(intentId) {
25
+ const entry = this.get(intentId);
26
+ if (entry !== undefined)
27
+ this.held.delete(intentId);
28
+ return entry;
29
+ }
30
+ delete(intentId) {
31
+ this.held.delete(intentId);
32
+ }
33
+ sweep() {
34
+ const now = this.clock();
35
+ for (const [id, entry] of this.held) {
36
+ if (entry.expiresAt <= now)
37
+ this.held.delete(id);
38
+ }
39
+ return this.held.size;
40
+ }
41
+ close() {
42
+ this.held.clear();
43
+ }
44
+ }
45
+ /** Why a durable hold store cannot be used: the code, never the key or a path's contents. */
46
+ export class HoldStoreError extends Error {
47
+ code;
48
+ constructor(code) {
49
+ super(code);
50
+ this.code = code;
51
+ this.name = "HoldStoreError";
52
+ }
53
+ }
54
+ const FORMAT = "agentsafe.hold/1";
55
+ const SUFFIX = ".hold";
56
+ /** A claimed hold's file, left only if the claiming process died before removing it. */
57
+ const CLAIMED = ".claimed";
58
+ const TEMPORARY = ".tmp";
59
+ /** How long a claimed or half-written file may stay before a sweep removes it. */
60
+ const ORPHAN_MS = 10 * 60_000;
61
+ /**
62
+ * Holds as files in a directory every replica of a gateway mounts: any
63
+ * replica can resume a hold, and a restart or a reload loses none. Each file
64
+ * is sealed with AES-256-GCM under a key read from a mounted file; the
65
+ * associated data binds it to its scope (the tenant) and its intent id, so a
66
+ * file copied to another tenant's directory or renamed to another intent does
67
+ * not open. File names are digests of the intent id, never the id itself.
68
+ *
69
+ * A claim renames the file to a name only the claimant knows; the rename
70
+ * succeeds for one caller and fails for every other, on one host or across
71
+ * hosts sharing the directory.
72
+ */
73
+ export class FileHoldStore {
74
+ dir;
75
+ scope;
76
+ clock;
77
+ key;
78
+ constructor(dir, keyFile, scope, clock) {
79
+ this.dir = dir;
80
+ this.scope = scope;
81
+ this.clock = clock;
82
+ this.key = FileHoldStore.readKey(keyFile);
83
+ try {
84
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
85
+ statSync(dir);
86
+ }
87
+ catch {
88
+ throw new HoldStoreError("HOLD_DIR_UNUSABLE");
89
+ }
90
+ }
91
+ /** The key: 32 bytes, written base64 or base64url (whitespace ignored), or hex. */
92
+ static readKey(keyFile) {
93
+ let text;
94
+ try {
95
+ text = readFileSync(keyFile, "utf8").trim();
96
+ }
97
+ catch {
98
+ throw new HoldStoreError("HOLD_KEY_UNREADABLE");
99
+ }
100
+ const key = /^[0-9a-f]{64}$/i.test(text)
101
+ ? Buffer.from(text, "hex")
102
+ : Buffer.from(text.replace(/\s+/g, ""), "base64url");
103
+ if (key.length !== 32)
104
+ throw new HoldStoreError("HOLD_KEY_INVALID");
105
+ return key;
106
+ }
107
+ put(intentId, entry) {
108
+ if (this.sweep() >= MAX_HELD)
109
+ return false;
110
+ const iv = randomBytes(12);
111
+ const cipher = createCipheriv("aes-256-gcm", this.key, iv);
112
+ cipher.setAAD(this.aad(intentId, entry.expiresAt));
113
+ const data = Buffer.concat([
114
+ cipher.update(JSON.stringify(FileHoldStore.encode(entry)), "utf8"),
115
+ cipher.final(),
116
+ ]);
117
+ const sealed = {
118
+ format: FORMAT,
119
+ expiresAt: entry.expiresAt,
120
+ iv: iv.toString("base64url"),
121
+ tag: cipher.getAuthTag().toString("base64url"),
122
+ data: data.toString("base64url"),
123
+ };
124
+ const path = this.path(intentId);
125
+ const temporary = `${path}.${randomBytes(6).toString("hex")}${TEMPORARY}`;
126
+ try {
127
+ const fd = openSync(temporary, "wx", 0o600);
128
+ try {
129
+ writeSync(fd, JSON.stringify(sealed));
130
+ fsyncSync(fd);
131
+ }
132
+ finally {
133
+ closeSync(fd);
134
+ }
135
+ renameSync(temporary, path);
136
+ return true;
137
+ }
138
+ catch {
139
+ rmSync(temporary, { force: true });
140
+ return false;
141
+ }
142
+ }
143
+ get(intentId) {
144
+ return this.open(intentId, this.path(intentId), true);
145
+ }
146
+ claim(intentId) {
147
+ const path = this.path(intentId);
148
+ const claimed = `${path}.${randomBytes(6).toString("hex")}${CLAIMED}`;
149
+ try {
150
+ renameSync(path, claimed);
151
+ }
152
+ catch {
153
+ return undefined;
154
+ }
155
+ try {
156
+ return this.open(intentId, claimed, false);
157
+ }
158
+ finally {
159
+ rmSync(claimed, { force: true });
160
+ }
161
+ }
162
+ delete(intentId) {
163
+ rmSync(this.path(intentId), { force: true });
164
+ }
165
+ sweep() {
166
+ const now = this.clock();
167
+ let live = 0;
168
+ let names;
169
+ try {
170
+ names = readdirSync(this.dir);
171
+ }
172
+ catch {
173
+ return 0;
174
+ }
175
+ for (const name of names) {
176
+ const path = join(this.dir, name);
177
+ if (name.endsWith(CLAIMED) || name.endsWith(TEMPORARY)) {
178
+ if (FileHoldStore.olderThan(path, now - ORPHAN_MS))
179
+ rmSync(path, { force: true });
180
+ continue;
181
+ }
182
+ if (!name.endsWith(SUFFIX))
183
+ continue;
184
+ const expiresAt = FileHoldStore.expiresAt(path);
185
+ if (expiresAt === null || expiresAt <= now) {
186
+ rmSync(path, { force: true });
187
+ continue;
188
+ }
189
+ live += 1;
190
+ }
191
+ return live;
192
+ }
193
+ close() {
194
+ // The holds are the next process's to resume.
195
+ }
196
+ /** A hold's file, opened and checked; expired, unreadable or forged files are removed. */
197
+ open(intentId, path, removeBad) {
198
+ let sealed;
199
+ try {
200
+ sealed = JSON.parse(readFileSync(path, "utf8"));
201
+ }
202
+ catch {
203
+ return undefined;
204
+ }
205
+ const entry = this.unseal(intentId, sealed);
206
+ if (entry === null || entry.expiresAt <= this.clock()) {
207
+ if (removeBad)
208
+ rmSync(path, { force: true });
209
+ return undefined;
210
+ }
211
+ return entry;
212
+ }
213
+ unseal(intentId, sealed) {
214
+ if (sealed?.format !== FORMAT || typeof sealed.expiresAt !== "number")
215
+ return null;
216
+ try {
217
+ const decipher = createDecipheriv("aes-256-gcm", this.key, Buffer.from(sealed.iv, "base64url"));
218
+ decipher.setAAD(this.aad(intentId, sealed.expiresAt));
219
+ decipher.setAuthTag(Buffer.from(sealed.tag, "base64url"));
220
+ const plain = Buffer.concat([
221
+ decipher.update(Buffer.from(sealed.data, "base64url")),
222
+ decipher.final(),
223
+ ]).toString("utf8");
224
+ const entry = FileHoldStore.decode(JSON.parse(plain));
225
+ return entry.expiresAt === sealed.expiresAt && entry.captured.intent.intentId === intentId
226
+ ? entry
227
+ : null;
228
+ }
229
+ catch {
230
+ return null;
231
+ }
232
+ }
233
+ aad(intentId, expiresAt) {
234
+ return Buffer.from(`${FORMAT}\u0000${this.scope}\u0000${intentId}\u0000${expiresAt}`, "utf8");
235
+ }
236
+ path(intentId) {
237
+ const name = createHash("sha256")
238
+ .update(`${this.scope}\u0000${intentId}`, "utf8")
239
+ .digest("hex");
240
+ return join(this.dir, `${name}${SUFFIX}`);
241
+ }
242
+ static expiresAt(path) {
243
+ try {
244
+ const sealed = JSON.parse(readFileSync(path, "utf8"));
245
+ return sealed.format === FORMAT && typeof sealed.expiresAt === "number"
246
+ ? sealed.expiresAt
247
+ : null;
248
+ }
249
+ catch {
250
+ return null;
251
+ }
252
+ }
253
+ static olderThan(path, cutoff) {
254
+ try {
255
+ return statSync(path).mtimeMs < cutoff;
256
+ }
257
+ catch {
258
+ return false;
259
+ }
260
+ }
261
+ static encode(entry) {
262
+ return {
263
+ captured: entry.captured,
264
+ request: { ...entry.request, body: entry.request.body.toString("base64") },
265
+ decision: entry.decision,
266
+ handoff: entry.handoff,
267
+ heldAt: entry.heldAt,
268
+ expiresAt: entry.expiresAt,
269
+ resumeDigest: entry.resumeDigest.toString("base64"),
270
+ };
271
+ }
272
+ static decode(encoded) {
273
+ return {
274
+ ...encoded,
275
+ request: { ...encoded.request, body: Buffer.from(encoded.request.body, "base64") },
276
+ resumeDigest: Buffer.from(encoded.resumeDigest, "base64"),
277
+ };
278
+ }
279
+ }
280
+ //# sourceMappingURL=HoldStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HoldStore.js","sourceRoot":"","sources":["../../src/gateway/HoldStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAqCjC,wCAAwC;AACxC,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC;AAE9B,sFAAsF;AACtF,MAAM,OAAO,eAAe;IAGU;IAFnB,IAAI,GAAG,IAAI,GAAG,EAA0B,CAAC;IAE1D,YAAoC,KAAmB;QAAnB,UAAK,GAAL,KAAK,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| null;
13
13
  readonly encrypted: boolean;
14
14
  }
15
- /** The HTTP action's parameters: exactly what the authority evaluates and the handler forwards. */
15
+ /** The held HTTP request and operator policy selectors, bound together for the authority. */
16
16
  export interface HttpActionParameters extends JsonObject {
17
17
  method: ConsequentialMethod;
18
18
  path: string;
@@ -20,6 +20,18 @@ export interface HttpActionParameters extends JsonObject {
20
20
  [key: string]: string | string[];
21
21
  };
22
22
  body?: JsonValue;
23
+ policy_id?: string;
24
+ policy_version?: string;
25
+ }
26
+ /**
27
+ * A facts-only HTTP action's parameters: the profile operation and its path
28
+ * template, never the path, query or body the request carried. The handler
29
+ * forwards the held request, bound by the keyed digest in the context.
30
+ */
31
+ export interface HttpFactsParameters extends JsonObject {
32
+ method: ConsequentialMethod;
33
+ operation: string;
34
+ path_template: string;
23
35
  }
24
36
  /** What the intent's context carries about the body: its digest, size and kind, never its bytes. */
25
37
  export interface HttpActionContext extends JsonObject {
@@ -44,6 +56,24 @@ export declare function bodyDigest(body: Uint8Array): `sha256:${string}`;
44
56
  * precedes the bytes; sorting header names makes object insertion order immaterial.
45
57
  */
46
58
  export declare function requestDigest(request: InterceptedRequest): `sha256:${string}`;
59
+ /**
60
+ * The same binding as `requestDigest`, keyed: an HMAC-SHA-256 under a key
61
+ * that never leaves the gateway process. Facts-only privacy sends this in
62
+ * place of the plain digests, which a reader holding a guess of a small body
63
+ * or a path could confirm; the keyed one confirms nothing to anyone without
64
+ * the key, and still binds the held request to the grant byte for byte.
65
+ */
66
+ export declare function keyedRequestDigest(request: InterceptedRequest, key: Uint8Array): `hmac-sha256:${string}`;
67
+ /**
68
+ * What a client's idempotency key promises: one operation, named by its
69
+ * method, path, query, content type and body bytes. Unlike `requestDigest`
70
+ * it leaves out the other headers and the caller's address, which a retry
71
+ * from another egress, or with a new trace id, changes without changing
72
+ * the operation. Kept only by the gateway, never sent to the authority.
73
+ */
74
+ export declare function retryDigest(request: InterceptedRequest): `sha256:${string}`;
75
+ /** The client's `Idempotency-Key` as the intent would state it, or null when absent, empty or over the bound. */
76
+ export declare function idempotencyKeyOf(request: InterceptedRequest): string | null;
47
77
  /**
48
78
  * Turns an intercepted request into the agent's part of an intent. The
49
79
  * proposal is method, path, query and, when the body is JSON within the
@@ -52,9 +82,33 @@ export declare function requestDigest(request: InterceptedRequest): `sha256:${st
52
82
  * embedded, which is what the forwarding handler checks before dispatch.
53
83
  * Raw request headers never reach the authority. Their digest binds their
54
84
  * meaning along with the exact query and bytes for the final dispatch check.
85
+ * Policy selectors come only from the matched operator route, never from
86
+ * the caller's body, query or headers. They are bound before intent hashing
87
+ * and do not change the request forwarded to the upstream.
55
88
  */
56
89
  export declare function normalizeRequest(request: InterceptedRequest, action: string, options: {
57
90
  readonly maxEmbeddedBodyBytes: number;
58
91
  readonly principalHeader: string | null;
92
+ readonly policyId?: string;
93
+ readonly policyVersion?: string;
59
94
  }): NormalizedAction;
95
+ /**
96
+ * The agent's part of an intent in facts-only privacy: the profile operation
97
+ * that names the call, its path template, and nothing the request carried.
98
+ * The context binds the held request by its keyed digest. The client's
99
+ * idempotency key is a header value, so it is keyed too: a retry through the
100
+ * same gateway process states the same key, and the value never leaves. A
101
+ * correlation id and a principal header are not carried at all.
102
+ */
103
+ export declare function normalizeFacts(request: InterceptedRequest, action: string, operation: {
104
+ readonly id: string;
105
+ readonly path: string;
106
+ }, key: Uint8Array): NormalizedFacts;
107
+ export interface NormalizedFacts {
108
+ readonly proposal: AgentProposal;
109
+ readonly context: {
110
+ readonly request_hmac_sha256: string;
111
+ };
112
+ readonly idempotencyKey: string | null;
113
+ }
60
114
  //# sourceMappingURL=InterceptedRequest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"InterceptedRequest.d.ts","sourceRoot":"","sources":["../../src/gateway/InterceptedRequest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MA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MAX_CORRELATION_LENGTH = 200;
@@ -32,6 +32,36 @@ export function requestDigest(request) {
32
32
  ]);
33
33
  return `sha256:${createHash("sha256").update(metadata, "utf8").update(request.body).digest("hex")}`;
34
34
  }
35
+ /**
36
+ * The same binding as `requestDigest`, keyed: an HMAC-SHA-256 under a key
37
+ * that never leaves the gateway process. Facts-only privacy sends this in
38
+ * place of the plain digests, which a reader holding a guess of a small body
39
+ * or a path could confirm; the keyed one confirms nothing to anyone without
40
+ * the key, and still binds the held request to the grant byte for byte.
41
+ */
42
+ export function keyedRequestDigest(request, key) {
43
+ return `hmac-sha256:${createHmac("sha256", key).update(requestDigest(request), "utf8").digest("hex")}`;
44
+ }
45
+ /**
46
+ * What a client's idempotency key promises: one operation, named by its
47
+ * method, path, query, content type and body bytes. Unlike `requestDigest`
48
+ * it leaves out the other headers and the caller's address, which a retry
49
+ * from another egress, or with a new trace id, changes without changing
50
+ * the operation. Kept only by the gateway, never sent to the authority.
51
+ */
52
+ export function retryDigest(request) {
53
+ const metadata = JSON.stringify([
54
+ request.method.toUpperCase(),
55
+ request.path,
56
+ request.search,
57
+ request.headers["content-type"] ?? null,
58
+ ]);
59
+ return `sha256:${createHash("sha256").update(metadata, "utf8").update(request.body).digest("hex")}`;
60
+ }
61
+ /** The client's `Idempotency-Key` as the intent would state it, or null when absent, empty or over the bound. */
62
+ export function idempotencyKeyOf(request) {
63
+ return header(request.headers, "idempotency-key", MAX_IDEMPOTENCY_KEY_LENGTH);
64
+ }
35
65
  /** Query pairs as an object: one value, or a list where a key repeats; keys sorted for stable hashing. */
36
66
  function queryObject(search) {
37
67
  const grouped = new Map();
@@ -66,6 +96,9 @@ function header(headers, name, maxLength) {
66
96
  * embedded, which is what the forwarding handler checks before dispatch.
67
97
  * Raw request headers never reach the authority. Their digest binds their
68
98
  * meaning along with the exact query and bytes for the final dispatch check.
99
+ * Policy selectors come only from the matched operator route, never from
100
+ * the caller's body, query or headers. They are bound before intent hashing
101
+ * and do not change the request forwarded to the upstream.
69
102
  */
70
103
  export function normalizeRequest(request, action, options) {
71
104
  const method = request.method.toUpperCase();
@@ -91,6 +124,8 @@ export function normalizeRequest(request, action, options) {
91
124
  path: request.path,
92
125
  query: queryObject(request.search),
93
126
  ...(body === undefined ? {} : { body }),
127
+ ...(options.policyId === undefined ? {} : { policy_id: options.policyId }),
128
+ ...(options.policyVersion === undefined ? {} : { policy_version: options.policyVersion }),
94
129
  };
95
130
  return {
96
131
  proposal: { action, target, parameters },
@@ -109,4 +144,31 @@ export function normalizeRequest(request, action, options) {
109
144
  : header(request.headers, options.principalHeader, MAX_PRINCIPAL_LENGTH),
110
145
  };
111
146
  }
147
+ /**
148
+ * The agent's part of an intent in facts-only privacy: the profile operation
149
+ * that names the call, its path template, and nothing the request carried.
150
+ * The context binds the held request by its keyed digest. The client's
151
+ * idempotency key is a header value, so it is keyed too: a retry through the
152
+ * same gateway process states the same key, and the value never leaves. A
153
+ * correlation id and a principal header are not carried at all.
154
+ */
155
+ export function normalizeFacts(request, action, operation, key) {
156
+ const method = request.method.toUpperCase();
157
+ const target = `${method} ${operation.path}`;
158
+ if (target.length > MAX_TARGET_LENGTH)
159
+ throw new Error("TARGET_TOO_LONG");
160
+ const parameters = {
161
+ method,
162
+ operation: operation.id,
163
+ path_template: operation.path,
164
+ };
165
+ const idempotency = header(request.headers, "idempotency-key", MAX_IDEMPOTENCY_KEY_LENGTH);
166
+ return {
167
+ proposal: { action, target, parameters },
168
+ context: { request_hmac_sha256: keyedRequestDigest(request, key) },
169
+ idempotencyKey: idempotency === null
170
+ ? null
171
+ : `hmac-sha256:${createHmac("sha256", key).update(idempotency, "utf8").digest("hex")}`,
172
+ };
173
+ }
112
174
  //# sourceMappingURL=InterceptedRequest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"InterceptedRequest.js","sourceRoot":"","sources":["../../src/gateway/InterceptedRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA0CzC,MA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AC,MAAM,GAAG,iBAAiB;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC1E,MAAM,UAAU,GAAwB;QACtC,MAAM;QACN,SAAS,EAAE,SAAS,CAAC,EAAE;QACvB,aAAa,EAAE,SAAS,CAAC,IAAI;KAC9B,CAAC;IACF,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;IAC3F,OAAO;QACL,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE;QACxC,OAAO,EAAE,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE;QAClE,cAAc,EACZ,WAAW,KAAK,IAAI;YAClB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,eAAe,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;KAC3F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ /** Published bundle selectors understood by Decionis, shared by config and dispatch validation. */
3
+ export declare const PolicyIdSchema: z.ZodString;
4
+ export declare const PolicyVersionSchema: z.ZodString;
5
+ //# sourceMappingURL=PolicySelector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PolicySelector.d.ts","sourceRoot":"","sources":["../../src/gateway/PolicySelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,mGAAmG;AACnG,eAAO,MAAM,cAAc,aAAoB,CAAC;AAChD,eAAO,MAAM,mBAAmB,aAIV,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ /** Published bundle selectors understood by Decionis, shared by config and dispatch validation. */
3
+ export const PolicyIdSchema = z.string().uuid();
4
+ export const PolicyVersionSchema = z
5
+ .string()
6
+ .min(1)
7
+ .max(100)
8
+ .regex(/^\P{Cc}+$/u);
9
+ //# sourceMappingURL=PolicySelector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PolicySelector.js","sourceRoot":"","sources":["../../src/gateway/PolicySelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,mGAAmG;AACnG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;AAChD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,GAAG,CAAC;KACR,KAAK,CAAC,YAAY,CAAC,CAAC"}
@@ -1,31 +1,96 @@
1
- import { type ConsequentialMethod, type RouteConfig, type UnmatchedPolicy } from "./GatewayConfig.js";
1
+ import { ApiProfile } from "@decionis/agent-safe-pipeline";
2
+ import { type ConsequentialMethod, type GatewayConfig, type PrivacyMode, type RouteConfig, type UnmatchedPolicy } from "./GatewayConfig.js";
3
+ /**
4
+ * What the gateway does with a read. `PASSTHROUGH` is today's: never
5
+ * evaluated. `CHECK` checks a read a profile operation names against the
6
+ * session's subject and passes the rest. `REFUSE_UNKNOWN` also refuses a
7
+ * read no profile operation names.
8
+ */
9
+ export type ReadPolicy = "PASSTHROUGH" | "CHECK" | "REFUSE_UNKNOWN";
2
10
  /** What the gateway decided about one request before reading its body. */
3
11
  export type RoutePlan = {
4
12
  readonly kind: "PASSTHROUGH";
5
13
  readonly reason: "SAFE_METHOD" | "UNMATCHED" | "DISABLED";
6
14
  } | {
7
15
  readonly kind: "REFUSE";
8
- readonly code: "HTTP_METHOD_UNSUPPORTED" | "HTTP_PATH_AMBIGUOUS";
16
+ readonly code: "HTTP_METHOD_UNSUPPORTED" | "HTTP_PATH_AMBIGUOUS" | "PROFILE_OPERATION_UNMATCHED" | "READ_OPERATION_UNMATCHED";
17
+ } | {
18
+ /** A read a profile operation names: checked against the session's subject, never decided. */
19
+ readonly kind: "CHECK";
20
+ readonly action: string;
21
+ readonly operation: string;
9
22
  } | {
10
23
  readonly kind: "GOVERN";
11
24
  readonly action: string;
12
25
  readonly route: RouteConfig | null;
26
+ /** The API profile operation that named the action, when a profile did. */
27
+ readonly operation?: string;
28
+ };
29
+ /**
30
+ * One row of what the table does with a consequential request, as it tries
31
+ * them: the methods and path pattern (`/**` for the rest), and the action it
32
+ * governs under (`GOVERN`), or that it passes the request (`PASSTHROUGH`) or
33
+ * refuses it (`REFUSE`) without asking anyone.
34
+ */
35
+ export interface RouteRow {
36
+ readonly methods: readonly ConsequentialMethod[];
37
+ readonly path: string;
38
+ readonly action: string | null;
39
+ readonly disposition: "GOVERN" | "PASSTHROUGH" | "REFUSE";
40
+ }
41
+ /** A request's query, as the gateway reads it for planning: each name to one value or a list. */
42
+ export type PlanQuery = {
43
+ readonly [key: string]: string | readonly string[];
13
44
  };
14
45
  /** The derived action for an unsafe request no route names. */
15
46
  export declare function derivedAction(method: ConsequentialMethod): string;
16
47
  /**
17
48
  * The route table: which requests are consequential, and what each is
18
- * called. A safe method is never consequential. An unsafe request the table
19
- * does not name is governed under a derived name unless the configuration
20
- * chose passthrough, so narrowing what is governed is an explicit act.
49
+ * called. A safe method is never consequential. An explicit route is tried
50
+ * first, then the API profile's operations, when the gateway governs by one
51
+ * (`agent-safe.profile.api/1`). An unsafe request neither names is governed
52
+ * under a derived name unless the configuration chose passthrough, so
53
+ * narrowing what is governed is an explicit act. In facts-only privacy the
54
+ * profile alone names a call: what it does not name is refused, because
55
+ * governing it would send the authority its raw path.
21
56
  */
22
57
  export declare class RouteTable {
23
58
  private readonly unmatched;
24
59
  private readonly enabled;
60
+ /** The API profile the table governs by, after any explicit route; null for routes alone. */
61
+ readonly profile: ApiProfile | null;
62
+ private readonly privacy;
63
+ readonly reads: ReadPolicy;
25
64
  private readonly routes;
26
- constructor(routes: readonly RouteConfig[], unmatched: UnmatchedPolicy, enabled?: boolean);
65
+ constructor(routes: readonly RouteConfig[], unmatched: UnmatchedPolicy, enabled?: boolean,
66
+ /** The API profile the table governs by, after any explicit route; null for routes alone. */
67
+ profile?: ApiProfile | null, privacy?: PrivacyMode, reads?: ReadPolicy);
68
+ /**
69
+ * The table a gateway with this configuration plans by. Reads are checked
70
+ * only when the gateway pins subjects, and unknown ones refused only when
71
+ * the configuration says so.
72
+ */
73
+ static of(config: GatewayConfig): RouteTable;
27
74
  /** Every action name this table can produce, for the registry to be sealed over. */
28
75
  actions(): readonly string[];
29
- plan(method: string, pathname: string): RoutePlan;
76
+ /**
77
+ * What the table governs, in the order `plan` tries it: the explicit routes
78
+ * (none in facts-only privacy, which never reads them), the profile's
79
+ * writes, then what becomes of every other consequential request. A read
80
+ * is never governed, so it is not a row.
81
+ */
82
+ rows(): readonly RouteRow[];
83
+ /**
84
+ * A read, when reads are checked. A `GET` a profile operation names is
85
+ * checked. One that only resembles an operation (another letter case, an
86
+ * encoded literal) is refused as ambiguous, since the upstream may serve
87
+ * it as that operation. A path beneath a checked read (`/$count`, a
88
+ * navigation, a media stream) answers what the read's subject rule does
89
+ * not check, and a `HEAD` or `OPTIONS` on a checked read's path has no
90
+ * answer to check while its status says whether a record exists: both are
91
+ * refused. Anything else passes, or is refused when unknown reads are.
92
+ */
93
+ private planRead;
94
+ plan(method: string, pathname: string, query?: PlanQuery): RoutePlan;
30
95
  }
31
96
  //# sourceMappingURL=RouteTable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RouteTable.d.ts","sourceRoot":"","sources":["../../src/gateway/RouteTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAE5B,0EAA0E;AAC1E,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,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