@harrylabsj/kiwi-merchant-cloud 0.12.31 → 0.12.32

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 (314) hide show
  1. package/app/a2a/node.d.ts +1 -0
  2. package/app/a2a/node.js +170 -2
  3. package/app/a2a/node.js.map +1 -1
  4. package/app/a2a/reception/agent-runtime.d.ts +32 -1
  5. package/app/a2a/reception/agent-runtime.js +420 -11
  6. package/app/a2a/reception/agent-runtime.js.map +1 -1
  7. package/app/a2a/reception/customer-memory-tools.d.ts +73 -0
  8. package/app/a2a/reception/customer-memory-tools.js +17 -0
  9. package/app/a2a/reception/customer-memory-tools.js.map +1 -0
  10. package/app/a2a/reception/engine.d.ts +12 -0
  11. package/app/a2a/reception/engine.js +42 -1
  12. package/app/a2a/reception/engine.js.map +1 -1
  13. package/app/a2a/reception/publish.d.ts +14 -1
  14. package/app/a2a/reception/publish.js +62 -1
  15. package/app/a2a/reception/publish.js.map +1 -1
  16. package/app/a2a/reception/question-spec.d.ts +91 -0
  17. package/app/a2a/reception/question-spec.js +260 -0
  18. package/app/a2a/reception/question-spec.js.map +1 -0
  19. package/app/a2a/reception/reply-outbox.d.ts +6 -0
  20. package/app/a2a/reception/reply-outbox.js +44 -0
  21. package/app/a2a/reception/reply-outbox.js.map +1 -1
  22. package/app/a2a/reception/responder.d.ts +13 -1
  23. package/app/a2a/reception/responder.js +26 -3
  24. package/app/a2a/reception/responder.js.map +1 -1
  25. package/app/a2a/reception/skill-catalog.d.ts +72 -0
  26. package/app/a2a/reception/skill-catalog.js +85 -0
  27. package/app/a2a/reception/skill-catalog.js.map +1 -0
  28. package/app/a2a/reception/skill-contract.d.ts +70 -0
  29. package/app/a2a/reception/skill-contract.js +183 -0
  30. package/app/a2a/reception/skill-contract.js.map +1 -0
  31. package/app/a2a/reception/types.d.ts +12 -0
  32. package/app/a2a/server/customer-identity-gateway.d.ts +111 -0
  33. package/app/a2a/server/customer-identity-gateway.js +441 -0
  34. package/app/a2a/server/customer-identity-gateway.js.map +1 -0
  35. package/app/a2a/server/merchant-handler.d.ts +34 -0
  36. package/app/a2a/server/merchant-handler.js +439 -19
  37. package/app/a2a/server/merchant-handler.js.map +1 -1
  38. package/app/a2a/server/pipeline.js +74 -29
  39. package/app/a2a/server/pipeline.js.map +1 -1
  40. package/app/a2a/server/types.d.ts +2 -0
  41. package/app/a2a/unit-alias.d.ts +3 -3
  42. package/app/a2a/unit-alias.js +9 -5
  43. package/app/a2a/unit-alias.js.map +1 -1
  44. package/app/auth/merchant-sessions.d.ts +3 -0
  45. package/app/auth/merchant-sessions.js +21 -5
  46. package/app/auth/merchant-sessions.js.map +1 -1
  47. package/app/buyer-core/a2a-knp.d.ts +4 -2
  48. package/app/buyer-core/a2a-knp.js +5 -2
  49. package/app/buyer-core/a2a-knp.js.map +1 -1
  50. package/app/buyer-core/a2a-negotiator.d.ts +1 -0
  51. package/app/buyer-core/a2a-negotiator.js +18 -11
  52. package/app/buyer-core/a2a-negotiator.js.map +1 -1
  53. package/app/buyer-core/a2a-quote-fetcher.d.ts +25 -0
  54. package/app/buyer-core/a2a-quote-fetcher.js +82 -4
  55. package/app/buyer-core/a2a-quote-fetcher.js.map +1 -1
  56. package/app/buyer-core/a2a-quote-history.d.ts +94 -0
  57. package/app/buyer-core/a2a-quote-history.js +149 -0
  58. package/app/buyer-core/a2a-quote-history.js.map +1 -0
  59. package/app/buyer-core/build-service.d.ts +19 -0
  60. package/app/buyer-core/build-service.js +30 -1
  61. package/app/buyer-core/build-service.js.map +1 -1
  62. package/app/buyer-core/errors.d.ts +1 -1
  63. package/app/buyer-core/errors.js +1 -0
  64. package/app/buyer-core/errors.js.map +1 -1
  65. package/app/buyer-core/open-inquiry-signer.d.ts +1 -0
  66. package/app/buyer-core/open-inquiry-signer.js +5 -2
  67. package/app/buyer-core/open-inquiry-signer.js.map +1 -1
  68. package/app/buyer-core/protocol-recovery.d.ts +2 -1
  69. package/app/buyer-core/protocol-recovery.js +14 -4
  70. package/app/buyer-core/protocol-recovery.js.map +1 -1
  71. package/app/buyer-core/service.d.ts +57 -5
  72. package/app/buyer-core/service.js +275 -50
  73. package/app/buyer-core/service.js.map +1 -1
  74. package/app/buyer-core/store.d.ts +8 -0
  75. package/app/buyer-core/store.js +37 -7
  76. package/app/buyer-core/store.js.map +1 -1
  77. package/app/cli.js +13 -2
  78. package/app/cli.js.map +1 -1
  79. package/app/cloud/bootstrap.js +141 -7
  80. package/app/cloud/bootstrap.js.map +1 -1
  81. package/app/cloud-sample/products.json +3 -3
  82. package/app/commerce/receipt/dispatcher.d.ts +42 -0
  83. package/app/commerce/receipt/dispatcher.js +68 -0
  84. package/app/commerce/receipt/dispatcher.js.map +1 -0
  85. package/app/commerce/receipt/receipts.d.ts +140 -0
  86. package/app/commerce/receipt/receipts.js +247 -0
  87. package/app/commerce/receipt/receipts.js.map +1 -0
  88. package/app/config/profile.d.ts +2 -2
  89. package/app/handoff/order-receipts.d.ts +62 -0
  90. package/app/handoff/order-receipts.js +71 -0
  91. package/app/handoff/order-receipts.js.map +1 -0
  92. package/app/handoff/ucp-checkout/cart-channel.d.ts +2 -1
  93. package/app/handoff/ucp-checkout/cart-channel.js +1 -0
  94. package/app/handoff/ucp-checkout/cart-channel.js.map +1 -1
  95. package/app/handoff/ucp-checkout/channel.d.ts +6 -0
  96. package/app/handoff/ucp-checkout/channel.js +44 -0
  97. package/app/handoff/ucp-checkout/channel.js.map +1 -1
  98. package/app/http/cli.js +6 -0
  99. package/app/http/cli.js.map +1 -1
  100. package/app/http/merchant-management/api.d.ts +10 -0
  101. package/app/http/merchant-management/api.js +443 -0
  102. package/app/http/merchant-management/api.js.map +1 -1
  103. package/app/http/merchant-management/draft-store.js +8 -6
  104. package/app/http/merchant-management/draft-store.js.map +1 -1
  105. package/app/http/merchant-management/page.js +2 -2
  106. package/app/mcp/cli.js +6 -0
  107. package/app/mcp/cli.js.map +1 -1
  108. package/app/mcp/merchant-runtime-assembly.d.ts +20 -0
  109. package/app/mcp/merchant-runtime-assembly.js +93 -3
  110. package/app/mcp/merchant-runtime-assembly.js.map +1 -1
  111. package/app/mcp/merchant-server.d.ts +5 -0
  112. package/app/mcp/merchant-server.js +12 -0
  113. package/app/mcp/merchant-server.js.map +1 -1
  114. package/app/mcp/tools.js +7 -1
  115. package/app/mcp/tools.js.map +1 -1
  116. package/app/merchant/application/actor.d.ts +1 -1
  117. package/app/merchant/application/actor.js +15 -0
  118. package/app/merchant/application/actor.js.map +1 -1
  119. package/app/merchant/workbench-server.d.ts +1 -0
  120. package/app/merchant/workbench-server.js +176 -2
  121. package/app/merchant/workbench-server.js.map +1 -1
  122. package/app/merchant-core/budget/background-budget.d.ts +132 -0
  123. package/app/merchant-core/budget/background-budget.js +308 -0
  124. package/app/merchant-core/budget/background-budget.js.map +1 -0
  125. package/app/merchant-core/context-governance/actor-context.d.ts +56 -0
  126. package/app/merchant-core/context-governance/actor-context.js +76 -0
  127. package/app/merchant-core/context-governance/actor-context.js.map +1 -0
  128. package/app/merchant-core/context-governance/authority.d.ts +39 -0
  129. package/app/merchant-core/context-governance/authority.js +28 -0
  130. package/app/merchant-core/context-governance/authority.js.map +1 -0
  131. package/app/merchant-core/context-governance/context-guard.d.ts +104 -0
  132. package/app/merchant-core/context-governance/context-guard.js +194 -0
  133. package/app/merchant-core/context-governance/context-guard.js.map +1 -0
  134. package/app/merchant-core/context-governance/data-use-grant.d.ts +91 -0
  135. package/app/merchant-core/context-governance/data-use-grant.js +211 -0
  136. package/app/merchant-core/context-governance/data-use-grant.js.map +1 -0
  137. package/app/merchant-core/context-governance/feature-flags.d.ts +32 -0
  138. package/app/merchant-core/context-governance/feature-flags.js +83 -0
  139. package/app/merchant-core/context-governance/feature-flags.js.map +1 -0
  140. package/app/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
  141. package/app/merchant-core/context-governance/pilot-readiness.js +141 -0
  142. package/app/merchant-core/context-governance/pilot-readiness.js.map +1 -0
  143. package/app/merchant-core/context-governance/source-governance.d.ts +157 -0
  144. package/app/merchant-core/context-governance/source-governance.js +492 -0
  145. package/app/merchant-core/context-governance/source-governance.js.map +1 -0
  146. package/app/merchant-core/context-governance/types.d.ts +62 -0
  147. package/app/merchant-core/context-governance/types.js +92 -0
  148. package/app/merchant-core/context-governance/types.js.map +1 -0
  149. package/app/merchant-core/customer-delivery/binding.d.ts +55 -0
  150. package/app/merchant-core/customer-delivery/binding.js +121 -0
  151. package/app/merchant-core/customer-delivery/binding.js.map +1 -0
  152. package/app/merchant-core/customer-delivery/channel.d.ts +75 -0
  153. package/app/merchant-core/customer-delivery/channel.js +157 -0
  154. package/app/merchant-core/customer-delivery/channel.js.map +1 -0
  155. package/app/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
  156. package/app/merchant-core/customer-delivery/consent-repository.js +160 -0
  157. package/app/merchant-core/customer-delivery/consent-repository.js.map +1 -0
  158. package/app/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
  159. package/app/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
  160. package/app/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
  161. package/app/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
  162. package/app/merchant-core/customer-delivery/dispatcher.js +166 -0
  163. package/app/merchant-core/customer-delivery/dispatcher.js.map +1 -0
  164. package/app/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
  165. package/app/merchant-core/customer-delivery/email-adapter.js +90 -0
  166. package/app/merchant-core/customer-delivery/email-adapter.js.map +1 -0
  167. package/app/merchant-core/customer-delivery/gate.d.ts +37 -0
  168. package/app/merchant-core/customer-delivery/gate.js +196 -0
  169. package/app/merchant-core/customer-delivery/gate.js.map +1 -0
  170. package/app/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
  171. package/app/merchant-core/customer-delivery/reconciliation.js +70 -0
  172. package/app/merchant-core/customer-delivery/reconciliation.js.map +1 -0
  173. package/app/merchant-core/customer-delivery/repository.d.ts +55 -0
  174. package/app/merchant-core/customer-delivery/repository.js +235 -0
  175. package/app/merchant-core/customer-delivery/repository.js.map +1 -0
  176. package/app/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
  177. package/app/merchant-core/customer-delivery/smtp-adapter.js +183 -0
  178. package/app/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
  179. package/app/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
  180. package/app/merchant-core/customer-delivery/stream-gate.js +123 -0
  181. package/app/merchant-core/customer-delivery/stream-gate.js.map +1 -0
  182. package/app/merchant-core/customer-delivery/types.d.ts +103 -0
  183. package/app/merchant-core/customer-delivery/types.js +32 -0
  184. package/app/merchant-core/customer-delivery/types.js.map +1 -0
  185. package/app/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
  186. package/app/merchant-core/customer-delivery/weixin-adapter.js +56 -0
  187. package/app/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
  188. package/app/merchant-core/customer-memory/auto-identity.d.ts +43 -0
  189. package/app/merchant-core/customer-memory/auto-identity.js +163 -0
  190. package/app/merchant-core/customer-memory/auto-identity.js.map +1 -0
  191. package/app/merchant-core/customer-memory/grants.d.ts +72 -0
  192. package/app/merchant-core/customer-memory/grants.js +224 -0
  193. package/app/merchant-core/customer-memory/grants.js.map +1 -0
  194. package/app/merchant-core/customer-memory/history.d.ts +51 -0
  195. package/app/merchant-core/customer-memory/history.js +252 -0
  196. package/app/merchant-core/customer-memory/history.js.map +1 -0
  197. package/app/merchant-core/customer-memory/identity.d.ts +66 -0
  198. package/app/merchant-core/customer-memory/identity.js +249 -0
  199. package/app/merchant-core/customer-memory/identity.js.map +1 -0
  200. package/app/merchant-core/customer-memory/maintenance.d.ts +51 -0
  201. package/app/merchant-core/customer-memory/maintenance.js +67 -0
  202. package/app/merchant-core/customer-memory/maintenance.js.map +1 -0
  203. package/app/merchant-core/customer-memory/memory.d.ts +119 -0
  204. package/app/merchant-core/customer-memory/memory.js +502 -0
  205. package/app/merchant-core/customer-memory/memory.js.map +1 -0
  206. package/app/merchant-core/customer-memory/private-transport.d.ts +10 -0
  207. package/app/merchant-core/customer-memory/private-transport.js +108 -0
  208. package/app/merchant-core/customer-memory/private-transport.js.map +1 -0
  209. package/app/merchant-core/customer-memory/quote-history.d.ts +160 -0
  210. package/app/merchant-core/customer-memory/quote-history.js +392 -0
  211. package/app/merchant-core/customer-memory/quote-history.js.map +1 -0
  212. package/app/merchant-core/customer-memory/reception-provider.d.ts +69 -0
  213. package/app/merchant-core/customer-memory/reception-provider.js +250 -0
  214. package/app/merchant-core/customer-memory/reception-provider.js.map +1 -0
  215. package/app/merchant-core/customer-memory/reception-writer.d.ts +19 -0
  216. package/app/merchant-core/customer-memory/reception-writer.js +32 -0
  217. package/app/merchant-core/customer-memory/reception-writer.js.map +1 -0
  218. package/app/merchant-core/customer-memory/types.d.ts +111 -0
  219. package/app/merchant-core/customer-memory/types.js +58 -0
  220. package/app/merchant-core/customer-memory/types.js.map +1 -0
  221. package/app/merchant-core/followup/repository.d.ts +2 -1
  222. package/app/merchant-core/followup/repository.js +29 -23
  223. package/app/merchant-core/followup/repository.js.map +1 -1
  224. package/app/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
  225. package/app/merchant-core/learning/evaluation-fixtures.js +83 -0
  226. package/app/merchant-core/learning/evaluation-fixtures.js.map +1 -0
  227. package/app/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
  228. package/app/merchant-core/learning/evaluation-suite-v1.js +129 -0
  229. package/app/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
  230. package/app/merchant-core/learning/evaluation.d.ts +84 -0
  231. package/app/merchant-core/learning/evaluation.js +581 -0
  232. package/app/merchant-core/learning/evaluation.js.map +1 -0
  233. package/app/merchant-core/learning/initial-skills.d.ts +36 -0
  234. package/app/merchant-core/learning/initial-skills.js +67 -0
  235. package/app/merchant-core/learning/initial-skills.js.map +1 -0
  236. package/app/merchant-core/learning/precheck.d.ts +33 -0
  237. package/app/merchant-core/learning/precheck.js +56 -0
  238. package/app/merchant-core/learning/precheck.js.map +1 -0
  239. package/app/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
  240. package/app/merchant-core/learning/real-evaluation-runner.js +167 -0
  241. package/app/merchant-core/learning/real-evaluation-runner.js.map +1 -0
  242. package/app/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
  243. package/app/merchant-core/learning/reception-skill-catalog.js +145 -0
  244. package/app/merchant-core/learning/reception-skill-catalog.js.map +1 -0
  245. package/app/merchant-core/learning/recovery-gateway.d.ts +27 -0
  246. package/app/merchant-core/learning/recovery-gateway.js +106 -0
  247. package/app/merchant-core/learning/recovery-gateway.js.map +1 -0
  248. package/app/merchant-core/learning/repository.d.ts +130 -0
  249. package/app/merchant-core/learning/repository.js +588 -0
  250. package/app/merchant-core/learning/repository.js.map +1 -0
  251. package/app/merchant-core/learning/service.d.ts +262 -0
  252. package/app/merchant-core/learning/service.js +1498 -0
  253. package/app/merchant-core/learning/service.js.map +1 -0
  254. package/app/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
  255. package/app/merchant-core/learning/test-dispatch-gateway.js +145 -0
  256. package/app/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
  257. package/app/merchant-core/learning/types.d.ts +217 -0
  258. package/app/merchant-core/learning/types.js +52 -0
  259. package/app/merchant-core/learning/types.js.map +1 -0
  260. package/app/merchant-core/migrations/ledgers.d.ts +40 -0
  261. package/app/merchant-core/migrations/ledgers.js +824 -0
  262. package/app/merchant-core/migrations/ledgers.js.map +1 -0
  263. package/app/merchant-core/migrations/runner.d.ts +55 -0
  264. package/app/merchant-core/migrations/runner.js +114 -0
  265. package/app/merchant-core/migrations/runner.js.map +1 -0
  266. package/app/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
  267. package/app/merchant-core/operations-jobs/advice-runner.js +199 -0
  268. package/app/merchant-core/operations-jobs/advice-runner.js.map +1 -0
  269. package/app/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
  270. package/app/merchant-core/operations-jobs/pilot-evidence.js +109 -0
  271. package/app/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
  272. package/app/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
  273. package/app/merchant-core/operations-jobs/pilot-metrics.js +98 -0
  274. package/app/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
  275. package/app/merchant-core/operations-jobs/projection.d.ts +41 -0
  276. package/app/merchant-core/operations-jobs/projection.js +158 -0
  277. package/app/merchant-core/operations-jobs/projection.js.map +1 -0
  278. package/app/merchant-core/operations-jobs/scheduler.d.ts +68 -0
  279. package/app/merchant-core/operations-jobs/scheduler.js +233 -0
  280. package/app/merchant-core/operations-jobs/scheduler.js.map +1 -0
  281. package/app/merchant-core/operations-jobs/service.d.ts +260 -0
  282. package/app/merchant-core/operations-jobs/service.js +922 -0
  283. package/app/merchant-core/operations-jobs/service.js.map +1 -0
  284. package/app/merchant-core/ops/facade.d.ts +10 -0
  285. package/app/merchant-core/ops/facade.js +52 -0
  286. package/app/merchant-core/ops/facade.js.map +1 -1
  287. package/app/merchant-core/ops/schema.d.ts +1 -1
  288. package/app/merchant-core/ops/schema.js +119 -2
  289. package/app/merchant-core/ops/schema.js.map +1 -1
  290. package/app/merchant-core/ops/surface.d.ts +37 -0
  291. package/app/merchant-core/ops/surface.js +240 -0
  292. package/app/merchant-core/ops/surface.js.map +1 -1
  293. package/app/merchant-core/ownership/instance-ownership.d.ts +122 -0
  294. package/app/merchant-core/ownership/instance-ownership.js +236 -0
  295. package/app/merchant-core/ownership/instance-ownership.js.map +1 -0
  296. package/app/merchant-core/ownership/runtime.d.ts +175 -0
  297. package/app/merchant-core/ownership/runtime.js +422 -0
  298. package/app/merchant-core/ownership/runtime.js.map +1 -0
  299. package/app/merchant-core/storage/transaction.d.ts +102 -7
  300. package/app/merchant-core/storage/transaction.js +274 -3
  301. package/app/merchant-core/storage/transaction.js.map +1 -1
  302. package/app/merchant-credential-rotation.d.ts +4 -1
  303. package/app/merchant-credential-rotation.js +12 -8
  304. package/app/merchant-credential-rotation.js.map +1 -1
  305. package/app/merchant-runtime/manager.d.ts +2 -0
  306. package/app/merchant-runtime/manager.js +5 -0
  307. package/app/merchant-runtime/manager.js.map +1 -1
  308. package/build-manifest.json +1202 -242
  309. package/deployment-lock.json +2 -2
  310. package/package.json +1 -1
  311. package/prepare.mjs +5 -1
  312. package/runtime-package.json +1 -1
  313. package/shipping-sbom.cdx.json +6 -6
  314. package/shipping-source.json +12 -12
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actor-context.js","sourceRoot":"","sources":["../../../src/merchant-core/context-governance/actor-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,cAAc,GAIf,MAAM,YAAY,CAAC;AAyBpB,SAAS,iBAAiB,CAAC,GAAkC;IAC3D,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAmB,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;QACvB,IAAI,CAAE,kBAAwC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,sBAAsB,CAC9B,YAAY,EACZ,oBAAoB,EACpB,OAAO,IAAI,uBAAuB,CACnC,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAuB,CAAC,CAAC;IACpC,CAAC;IACD,uBAAuB;IACvB,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAA8B;IAC/D,IAAI,CAAE,cAAoC,CAAC,QAAQ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AAC,KAAmB,EAAE,UAA2B;IAChF,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,sBAAsB,CAC9B,eAAe,EACf,oBAAoB,EACpB,cAAc,UAAU,EAAE,CAC3B,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * grant 支撑的默认 ContextVersionAuthority(M1 共性控制)。
18
+ *
19
+ * grant 域直接读 `DataUseGrantStore`(撤销/过期即 `undefined`);其余域
20
+ * (data scope、技能、记忆集合、会话、配置版本、来源可用性)在后续里程碑
21
+ * 接入各自存储,通过可选回调注入。**未注入的域按失效处理**:快照一旦绑定
22
+ * 该域,守卫一律 stale_context——不允许"查不到就当没变"。
23
+ */
24
+ import type { DataUseGrantStore } from "./data-use-grant.js";
25
+ import type { ContextVersionAuthority, CurrentSkillBinding, SourceRefCheck } from "./context-guard.js";
26
+ export interface GrantBackedAuthorityOptions {
27
+ readonly grants: DataUseGrantStore;
28
+ /** 主体绑定当前 epoch(§9.2);undefined = 已撤销/不存在。 */
29
+ readonly bindingEpoch?: (merchantId: string, actorId: string) => number | undefined;
30
+ /** 数据域当前 epoch;undefined = 已封存/删除。 */
31
+ readonly dataScopeEpoch?: (merchantId: string, scopeKey: string) => number | undefined;
32
+ readonly skillBinding?: (merchantId: string, skillKey: string) => CurrentSkillBinding | undefined;
33
+ readonly memorySetVersion?: (merchantId: string) => number | undefined;
34
+ readonly conversationRevision?: (merchantId: string) => number | undefined;
35
+ /** 配置版本;undefined = 无法核实(绑定非空 config_version 的快照将被拒绝)。 */
36
+ readonly configVersion?: () => string | undefined;
37
+ readonly sourceAvailable?: (merchantId: string, ref: SourceRefCheck) => boolean;
38
+ }
39
+ export declare function createGrantBackedAuthority(options: GrantBackedAuthorityOptions): ContextVersionAuthority;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export function createGrantBackedAuthority(options) {
17
+ return {
18
+ currentGrantEpoch: (merchantId, grantId) => options.grants.currentGrantEpoch(merchantId, grantId),
19
+ currentBindingEpoch: options.bindingEpoch ?? ((_merchantId, _actorId) => undefined),
20
+ currentDataScopeEpoch: options.dataScopeEpoch ?? ((_merchantId, _scopeKey) => undefined),
21
+ currentSkillBinding: options.skillBinding ?? ((_merchantId, _skillKey) => undefined),
22
+ currentMemorySetVersion: options.memorySetVersion ?? ((_merchantId) => undefined),
23
+ currentConversationRevision: options.conversationRevision ?? ((_merchantId) => undefined),
24
+ currentConfigVersion: options.configVersion ?? (() => undefined),
25
+ sourceAvailable: options.sourceAvailable ?? ((_merchantId, _ref) => false),
26
+ };
27
+ }
28
+ //# sourceMappingURL=authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.js","sourceRoot":"","sources":["../../../src/merchant-core/context-governance/authority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmCH,MAAM,UAAU,0BAA0B,CACxC,OAAoC;IAEpC,OAAO;QACL,iBAAiB,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CACzC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,UAAU,EAAE,OAAO,CAAC;QACvD,mBAAmB,EAAE,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC;QACnF,qBAAqB,EACnB,OAAO,CAAC,cAAc,IAAI,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC;QACnE,mBAAmB,EAAE,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC;QACpF,uBAAuB,EAAE,OAAO,CAAC,gBAAgB,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,SAAS,CAAC;QACjF,2BAA2B,EAAE,OAAO,CAAC,oBAAoB,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,SAAS,CAAC;QACzF,oBAAoB,EAAE,OAAO,CAAC,aAAa,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;QAChE,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC;KAC3E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { type ActorContext } from "./actor-context.js";
17
+ import type { ActorCapability } from "./types.js";
18
+ export type ContextCheckpoint = "read" | "tool_call" | "provider_attempt" | "publish";
19
+ /** 运行开始时固定的技能绑定(§7.1);M1 只定义形状与校验。 */
20
+ export interface SkillBindingRef {
21
+ readonly skill_key: string;
22
+ readonly release_id: string;
23
+ readonly compiled_artifact_hash: string;
24
+ readonly generation: number;
25
+ readonly revocation_epoch: number;
26
+ }
27
+ /**
28
+ * 服务端签发的运行快照(§4.2)。版本号 0 / 空集合表示本次运行不使用该域;
29
+ * 使用中的域必须在每个检查点与当前版本一致。
30
+ */
31
+ export interface ContextSnapshot {
32
+ readonly snapshot_id: string;
33
+ readonly issued_at: string;
34
+ readonly binding_epoch: number;
35
+ /** grant_id → 签发时的 grant_epoch。 */
36
+ readonly grant_versions: Readonly<Record<string, number>>;
37
+ /** 数据域(erase_scope)→ 签发时的 data_scope_epoch。 */
38
+ readonly data_scope_epochs: Readonly<Record<string, number>>;
39
+ readonly memory_set_version: number;
40
+ readonly conversation_revision: number;
41
+ readonly config_version: string;
42
+ readonly skill_bindings: readonly SkillBindingRef[];
43
+ }
44
+ /** 来源可用性检查输入;不携带正文或秘密(§4.2 SourceRef)。 */
45
+ export interface SourceRefCheck {
46
+ readonly object_id: string;
47
+ readonly version: number;
48
+ readonly expires_at?: string;
49
+ readonly erased?: boolean;
50
+ }
51
+ /** 技能当前绑定(权威值);undefined = 已撤回/未绑定/已删除。 */
52
+ export interface CurrentSkillBinding {
53
+ readonly release_id: string;
54
+ /** 权威编译产物摘要(发布时冻结);快照绑定必须与之逐值一致(§7.1)。 */
55
+ readonly compiled_artifact_hash: string;
56
+ readonly generation: number;
57
+ readonly revocation_epoch: number;
58
+ }
59
+ /**
60
+ * "当前版本"权威。实现方返回 `undefined` 表示对象已不存在(撤权、封存、
61
+ * 接管后旧对象失效);guard 把一切与快照的不一致折叠为 stale_context。
62
+ */
63
+ export interface ContextVersionAuthority {
64
+ currentGrantEpoch(merchantId: string, grantId: string): number | undefined;
65
+ /** 主体绑定当前 epoch(§9.2);undefined = 绑定已撤销/不存在。 */
66
+ currentBindingEpoch(merchantId: string, actorId: string): number | undefined;
67
+ currentDataScopeEpoch(merchantId: string, scopeKey: string): number | undefined;
68
+ currentSkillBinding(merchantId: string, skillKey: string): CurrentSkillBinding | undefined;
69
+ currentMemorySetVersion(merchantId: string): number | undefined;
70
+ currentConversationRevision(merchantId: string): number | undefined;
71
+ currentConfigVersion(): string | undefined;
72
+ sourceAvailable(merchantId: string, ref: SourceRefCheck): boolean;
73
+ }
74
+ export interface ContextGuardCheckInput {
75
+ readonly actor: ActorContext;
76
+ readonly snapshot: ContextSnapshot;
77
+ /**
78
+ * 本检查点行使的能力。§4.3:四个检查点"分别检查权限"——全部必填,
79
+ * 不提供无权限旁路(缺省即 validation 失败)。
80
+ */
81
+ readonly capability: ActorCapability;
82
+ /** tool_call 的诊断名,进 trace 原因码,不参与判定。 */
83
+ readonly tool?: string;
84
+ /** 本次读取/调用要用的来源引用;每个都必须可用。 */
85
+ readonly source_refs?: readonly SourceRefCheck[];
86
+ }
87
+ export interface ContextGuardOptions {
88
+ readonly authority: ContextVersionAuthority;
89
+ readonly now: () => string;
90
+ }
91
+ export declare class ContextGuard {
92
+ private readonly authority;
93
+ private readonly now;
94
+ constructor(options: ContextGuardOptions);
95
+ /** 读取前检查:能力(必填)+ 主体绑定 + grant/来源/版本一致性。 */
96
+ checkRead(input: ContextGuardCheckInput): void;
97
+ /** 工具调用前检查:同 read;工具名进 trace。 */
98
+ checkToolCall(input: ContextGuardCheckInput): void;
99
+ /** provider attempt 派发前检查:重试/压缩/摘要分支同样要走(§4.3)。 */
100
+ checkProviderAttempt(input: ContextGuardCheckInput): void;
101
+ /** 发布前检查(发布临界区的版本半边):全部域必须仍一致。 */
102
+ checkPublish(input: ContextGuardCheckInput): void;
103
+ private check;
104
+ }
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * ContextGuard(TOP1-3 设计 v1.1 §4.3 / §17.3)。
18
+ *
19
+ * 读取前、每次工具调用前、每次 provider attempt 派发前和最终发布前,检查
20
+ * 权限、grant epoch、来源可用性与版本;失败抛类型化错误,旧快照/旧游标/
21
+ * 旧上下文一律失效(丢弃结果重算,不是删引用标记)。
22
+ *
23
+ * 只提供守卫,不实现业务逻辑;撤权、封存、接管共享同一份版本检查——
24
+ * "当前版本"由 ContextVersionAuthority 提供,各域存储在后续里程碑接入。
25
+ *
26
+ * 检查范围 = 快照绑定的域:快照里没出现的域不查询(grant_versions 空、
27
+ * memory_set_version 0、skill_bindings 空 …);authority 对某域回答
28
+ * `undefined` 视为"该对象已撤销/封存/失效"——fail-closed。
29
+ */
30
+ import { ContextGovernanceError, } from "./types.js";
31
+ import { requireCapability, } from "./actor-context.js";
32
+ function fail(checkpoint, code, reason) {
33
+ throw new ContextGovernanceError(code, `${checkpoint}.${reason}`);
34
+ }
35
+ function validateSnapshotShape(snapshot, now, checkpoint) {
36
+ // 审计要求:形状错误的原因码保留实际检查点(publish.validation.…),不固定为 read。
37
+ if (typeof snapshot.snapshot_id !== "string" || snapshot.snapshot_id.length === 0) {
38
+ fail(checkpoint, "validation", "snapshot_id_missing");
39
+ }
40
+ const issued = Date.parse(snapshot.issued_at);
41
+ if (!Number.isFinite(issued)) {
42
+ fail(checkpoint, "validation", "issued_at_invalid");
43
+ }
44
+ if (issued > Date.parse(now)) {
45
+ fail(checkpoint, "validation", "issued_at_future");
46
+ }
47
+ if (!Number.isSafeInteger(snapshot.binding_epoch) || snapshot.binding_epoch < 0) {
48
+ fail(checkpoint, "validation", "binding_epoch_invalid");
49
+ }
50
+ if (!Number.isSafeInteger(snapshot.memory_set_version) || snapshot.memory_set_version < 0) {
51
+ fail(checkpoint, "validation", "memory_set_version_invalid");
52
+ }
53
+ if (!Number.isSafeInteger(snapshot.conversation_revision) || snapshot.conversation_revision < 0) {
54
+ fail(checkpoint, "validation", "conversation_revision_invalid");
55
+ }
56
+ for (const [grantId, epoch] of Object.entries(snapshot.grant_versions)) {
57
+ if (!Number.isSafeInteger(epoch) || epoch < 1) {
58
+ fail(checkpoint, "validation", `grant_epoch_invalid:${grantId}`);
59
+ }
60
+ }
61
+ for (const [scopeKey, epoch] of Object.entries(snapshot.data_scope_epochs)) {
62
+ if (!Number.isSafeInteger(epoch) || epoch < 1) {
63
+ fail(checkpoint, "validation", `data_scope_epoch_invalid:${scopeKey}`);
64
+ }
65
+ }
66
+ for (const binding of snapshot.skill_bindings) {
67
+ if (typeof binding.skill_key !== "string" ||
68
+ binding.skill_key.length === 0 ||
69
+ typeof binding.release_id !== "string" ||
70
+ binding.release_id.length === 0 ||
71
+ typeof binding.compiled_artifact_hash !== "string" ||
72
+ binding.compiled_artifact_hash.length === 0 ||
73
+ !Number.isSafeInteger(binding.generation) ||
74
+ binding.generation < 1 ||
75
+ !Number.isSafeInteger(binding.revocation_epoch) ||
76
+ binding.revocation_epoch < 0) {
77
+ fail(checkpoint, "validation", "skill_binding_invalid");
78
+ }
79
+ }
80
+ }
81
+ export class ContextGuard {
82
+ authority;
83
+ now;
84
+ constructor(options) {
85
+ this.authority = options.authority;
86
+ this.now = options.now;
87
+ }
88
+ /** 读取前检查:能力(必填)+ 主体绑定 + grant/来源/版本一致性。 */
89
+ checkRead(input) {
90
+ this.check("read", input);
91
+ }
92
+ /** 工具调用前检查:同 read;工具名进 trace。 */
93
+ checkToolCall(input) {
94
+ this.check("tool_call", input);
95
+ }
96
+ /** provider attempt 派发前检查:重试/压缩/摘要分支同样要走(§4.3)。 */
97
+ checkProviderAttempt(input) {
98
+ this.check("provider_attempt", input);
99
+ }
100
+ /** 发布前检查(发布临界区的版本半边):全部域必须仍一致。 */
101
+ checkPublish(input) {
102
+ this.check("publish", input);
103
+ }
104
+ check(checkpoint, input) {
105
+ const now = this.now();
106
+ validateSnapshotShape(input.snapshot, now, checkpoint);
107
+ // §4.3:四个检查点"分别检查权限"——capability 必填,无旁路。
108
+ if (input.capability === undefined) {
109
+ fail(checkpoint, "validation", "capability_required");
110
+ }
111
+ try {
112
+ requireCapability(input.actor, input.capability);
113
+ }
114
+ catch (err) {
115
+ if (err instanceof ContextGovernanceError && err.code === "access_denied") {
116
+ fail(checkpoint, "access_denied", `capability_missing:${input.capability}`);
117
+ }
118
+ throw err;
119
+ }
120
+ const merchantId = input.actor.merchant_id;
121
+ const snapshot = input.snapshot;
122
+ // 主体绑定一致性(§9.1/§9.2):绑定态 actor 必须在快照中携带 binding_epoch,
123
+ // 匿名 actor 不能携带;否则快照可绕过绑定撤销失效检查。
124
+ if ((input.actor.subject_binding === "none") !== (snapshot.binding_epoch === 0)) {
125
+ fail(checkpoint, "validation", "binding_state_inconsistent");
126
+ }
127
+ if (snapshot.binding_epoch > 0) {
128
+ const current = this.authority.currentBindingEpoch(merchantId, input.actor.actor_id);
129
+ // 撤销绑定递增 binding_epoch(§9.2):旧快照在此统一失效。
130
+ if (current === undefined) {
131
+ fail(checkpoint, "stale_context", "binding_gone");
132
+ }
133
+ if (current !== snapshot.binding_epoch) {
134
+ fail(checkpoint, "stale_context", "binding_epoch_changed");
135
+ }
136
+ }
137
+ for (const [grantId, boundEpoch] of Object.entries(snapshot.grant_versions)) {
138
+ const current = this.authority.currentGrantEpoch(merchantId, grantId);
139
+ if (current === undefined) {
140
+ fail(checkpoint, "stale_context", `grant_gone:${grantId}`);
141
+ }
142
+ if (current !== boundEpoch) {
143
+ fail(checkpoint, "stale_context", `grant_epoch_changed:${grantId}`);
144
+ }
145
+ }
146
+ for (const [scopeKey, boundEpoch] of Object.entries(snapshot.data_scope_epochs)) {
147
+ const current = this.authority.currentDataScopeEpoch(merchantId, scopeKey);
148
+ if (current === undefined) {
149
+ fail(checkpoint, "stale_context", `data_scope_gone:${scopeKey}`);
150
+ }
151
+ if (current !== boundEpoch) {
152
+ fail(checkpoint, "stale_context", `data_scope_epoch_changed:${scopeKey}`);
153
+ }
154
+ }
155
+ if (snapshot.memory_set_version > 0) {
156
+ const current = this.authority.currentMemorySetVersion(merchantId);
157
+ if (current === undefined || current !== snapshot.memory_set_version) {
158
+ fail(checkpoint, "stale_context", "memory_set_version_changed");
159
+ }
160
+ }
161
+ if (snapshot.conversation_revision > 0) {
162
+ const current = this.authority.currentConversationRevision(merchantId);
163
+ if (current === undefined || current !== snapshot.conversation_revision) {
164
+ fail(checkpoint, "stale_context", "conversation_revision_changed");
165
+ }
166
+ }
167
+ const currentConfig = this.authority.currentConfigVersion();
168
+ if (snapshot.config_version !== "" && currentConfig !== snapshot.config_version) {
169
+ fail(checkpoint, "stale_context", "config_version_changed");
170
+ }
171
+ for (const binding of snapshot.skill_bindings) {
172
+ const current = this.authority.currentSkillBinding(merchantId, binding.skill_key);
173
+ if (current === undefined) {
174
+ fail(checkpoint, "stale_context", `skill_unbound:${binding.skill_key}`);
175
+ }
176
+ if (current.release_id !== binding.release_id ||
177
+ current.generation !== binding.generation ||
178
+ current.revocation_epoch !== binding.revocation_epoch) {
179
+ fail(checkpoint, "stale_context", `skill_version_changed:${binding.skill_key}`);
180
+ }
181
+ // 冻结产物必须与权威值逐值一致(§7.1"快照中的确切产物"):同 release
182
+ // 不同 hash 的绑定在此拒绝,防止旧产物借新版本号通过。
183
+ if (current.compiled_artifact_hash !== binding.compiled_artifact_hash) {
184
+ fail(checkpoint, "stale_context", `skill_artifact_changed:${binding.skill_key}`);
185
+ }
186
+ }
187
+ for (const ref of input.source_refs ?? []) {
188
+ if (!this.authority.sourceAvailable(merchantId, ref)) {
189
+ fail(checkpoint, "source_unavailable", `source:${ref.object_id}`);
190
+ }
191
+ }
192
+ }
193
+ }
194
+ //# sourceMappingURL=context-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-guard.js","sourceRoot":"","sources":["../../../src/merchant-core/context-governance/context-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,sBAAsB,GAEvB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAoF5B,SAAS,IAAI,CAAC,UAA6B,EAAE,IAAgC,EAAE,MAAc;IAC3F,MAAM,IAAI,sBAAsB,CAAC,IAAI,EAAE,GAAG,UAAU,IAAI,MAAM,EAAE,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAyB,EAAE,GAAW,EAAE,UAA6B;IAClG,wDAAwD;IACxD,IAAI,OAAO,QAAQ,CAAC,WAAW,KAAK,QAAQ,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClF,IAAI,CAAC,UAAU,EAAE,YAAY,EAAE,qBAAqB,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC,UAAU,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC,UAAU,EAAE,YAAY,EAAE,kBAAkB,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,QAAQ,CAAC,aAAa,GAAG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AI,CAAC,UAAU,EAAE,eAAe,EAAE,yBAAyB,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;YAClF,CAAC;YACD,2CAA2C;YAC3C,gCAAgC;YAChC,IAAI,OAAO,CAAC,sBAAsB,KAAK,OAAO,CAAC,sBAAsB,EAAE,CAAC;gBACtE,IAAI,CAAC,UAAU,EAAE,eAAe,EAAE,0BAA0B,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;YACnF,CAAC;QACH,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE,CAAC;gBACrD,IAAI,CAAC,UAAU,EAAE,oBAAoB,EAAE,UAAU,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DatabaseSync } from "node:sqlite";
17
+ import { type DataGrantStatus, type DataUsePurpose } from "./types.js";
18
+ export interface DataUseGrant {
19
+ readonly grant_id: string;
20
+ readonly merchant_id: string;
21
+ readonly subject_id: string;
22
+ readonly purpose: DataUsePurpose;
23
+ readonly resource_scope_id: string;
24
+ readonly grant_epoch: number;
25
+ readonly status: DataGrantStatus;
26
+ readonly expires_at: string;
27
+ readonly policy_version: string;
28
+ readonly created_at: string;
29
+ readonly updated_at: string;
30
+ }
31
+ export interface DataUseGrantStoreOptions {
32
+ db: DatabaseSync;
33
+ now: () => string;
34
+ }
35
+ export declare class DataUseGrantStore {
36
+ private readonly db;
37
+ private readonly now;
38
+ constructor(options: DataUseGrantStoreOptions);
39
+ /**
40
+ * 服务器时钟规范化为定宽 UTC(与存储形式一致,SQL 字符串比较才可靠)。
41
+ * 时钟是服务端可信注入:偏移/秒级形式一律规范化,只拒绝不可解析值。
42
+ */
43
+ private nowUtc;
44
+ /**
45
+ * 授予一个数据用途。purpose/scope 决定用途边界:记忆授权不等于历史检索
46
+ * 或经验提炼授权。撤销/过期后重新授权产生新 grant_id 与递增 epoch。
47
+ */
48
+ createGrant(input: {
49
+ merchant_id: string;
50
+ subject_id: string;
51
+ purpose: DataUsePurpose;
52
+ resource_scope_id: string;
53
+ expires_at: string;
54
+ }): DataUseGrant;
55
+ /**
56
+ * 撤销授权:CAS 在 expected_epoch 上;epoch 不匹配或已非 ACTIVE 抛
57
+ * version_conflict(§17.3:回读当前状态,不覆盖)。撤销本身递增
58
+ * grant_epoch(§17.1 `memory.revokeGrant` 返回新 grant_epoch)——递增值取
59
+ * 该 scope 当前最大 epoch +1,避免与同 scope 其他记录冲突;被撤记录的旧
60
+ * epoch 空出,旧快照绑定值此后必然失配。重新授权的 epoch 从递增后再 +1。
61
+ */
62
+ revokeGrant(input: {
63
+ merchant_id: string;
64
+ grant_id: string;
65
+ expected_epoch: number;
66
+ }): DataUseGrant;
67
+ /** 读取当前有效授权:状态 ACTIVE 且未过期;无效统一返回 undefined。 */
68
+ getActiveGrant(input: {
69
+ merchant_id: string;
70
+ subject_id: string;
71
+ purpose: DataUsePurpose;
72
+ resource_scope_id: string;
73
+ }): DataUseGrant | undefined;
74
+ /** 把已到期的 ACTIVE 行翻为 EXPIRED(幂等;读取路径本就按时间过滤)。 */
75
+ expireDue(): number;
76
+ /**
77
+ * 主体作用域列表(客户自助/工作台):最小字段,仅当前商家;不返回其他
78
+ * 商家或其他主体的记录。
79
+ */
80
+ listBySubject(input: {
81
+ merchant_id: string;
82
+ subject_id: string;
83
+ }): Array<Pick<DataUseGrant, "grant_id" | "purpose" | "resource_scope_id" | "grant_epoch" | "status" | "expires_at">>;
84
+ /**
85
+ * grant 当前有效 epoch(守卫用):仅当存在、ACTIVE 且未过期时返回 epoch,
86
+ * 否则 undefined——撤销、封存与到期在守卫语义下等价(旧快照失效)。
87
+ */
88
+ currentGrantEpoch(merchantId: string, grantId: string): number | undefined;
89
+ /** 作用域读取:merchant 必须匹配;不存在时返回 undefined(不泄露存在性)。 */
90
+ private requireGrant;
91
+ }