@harrylabsj/kiwi-merchant-cloud 0.12.31 → 0.12.33

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 (473) hide show
  1. package/app/a2a/inquiry-nonce-store.d.ts +12 -1
  2. package/app/a2a/inquiry-nonce-store.js +49 -17
  3. package/app/a2a/inquiry-nonce-store.js.map +1 -1
  4. package/app/a2a/negotiate.d.ts +30 -1
  5. package/app/a2a/negotiate.js +121 -32
  6. package/app/a2a/negotiate.js.map +1 -1
  7. package/app/a2a/node.d.ts +4 -0
  8. package/app/a2a/node.js +182 -4
  9. package/app/a2a/node.js.map +1 -1
  10. package/app/a2a/open-inquiry-session.d.ts +1 -0
  11. package/app/a2a/open-inquiry-session.js +3 -1
  12. package/app/a2a/open-inquiry-session.js.map +1 -1
  13. package/app/a2a/open-inquiry-verifier.js +2 -2
  14. package/app/a2a/open-inquiry-verifier.js.map +1 -1
  15. package/app/a2a/reception/agent-runtime.d.ts +32 -1
  16. package/app/a2a/reception/agent-runtime.js +420 -11
  17. package/app/a2a/reception/agent-runtime.js.map +1 -1
  18. package/app/a2a/reception/customer-memory-tools.d.ts +73 -0
  19. package/app/a2a/reception/customer-memory-tools.js +17 -0
  20. package/app/a2a/reception/customer-memory-tools.js.map +1 -0
  21. package/app/a2a/reception/engine.d.ts +12 -0
  22. package/app/a2a/reception/engine.js +42 -1
  23. package/app/a2a/reception/engine.js.map +1 -1
  24. package/app/a2a/reception/publish.d.ts +14 -1
  25. package/app/a2a/reception/publish.js +62 -1
  26. package/app/a2a/reception/publish.js.map +1 -1
  27. package/app/a2a/reception/question-spec.d.ts +91 -0
  28. package/app/a2a/reception/question-spec.js +260 -0
  29. package/app/a2a/reception/question-spec.js.map +1 -0
  30. package/app/a2a/reception/reply-outbox.d.ts +6 -0
  31. package/app/a2a/reception/reply-outbox.js +44 -0
  32. package/app/a2a/reception/reply-outbox.js.map +1 -1
  33. package/app/a2a/reception/responder.d.ts +13 -1
  34. package/app/a2a/reception/responder.js +26 -3
  35. package/app/a2a/reception/responder.js.map +1 -1
  36. package/app/a2a/reception/skill-catalog.d.ts +72 -0
  37. package/app/a2a/reception/skill-catalog.js +85 -0
  38. package/app/a2a/reception/skill-catalog.js.map +1 -0
  39. package/app/a2a/reception/skill-contract.d.ts +70 -0
  40. package/app/a2a/reception/skill-contract.js +183 -0
  41. package/app/a2a/reception/skill-contract.js.map +1 -0
  42. package/app/a2a/reception/types.d.ts +12 -0
  43. package/app/a2a/server/customer-identity-gateway.d.ts +111 -0
  44. package/app/a2a/server/customer-identity-gateway.js +441 -0
  45. package/app/a2a/server/customer-identity-gateway.js.map +1 -0
  46. package/app/a2a/server/errors.d.ts +4 -3
  47. package/app/a2a/server/errors.js +10 -2
  48. package/app/a2a/server/errors.js.map +1 -1
  49. package/app/a2a/server/merchant-handler.d.ts +75 -1
  50. package/app/a2a/server/merchant-handler.js +676 -86
  51. package/app/a2a/server/merchant-handler.js.map +1 -1
  52. package/app/a2a/server/merchant-procurement.d.ts +90 -0
  53. package/app/a2a/server/merchant-procurement.js +75 -0
  54. package/app/a2a/server/merchant-procurement.js.map +1 -0
  55. package/app/a2a/server/merchant-product-facts.d.ts +2 -0
  56. package/app/a2a/server/merchant-product-facts.js.map +1 -1
  57. package/app/a2a/server/negotiation-approvals.d.ts +11 -0
  58. package/app/a2a/server/negotiation-approvals.js +43 -0
  59. package/app/a2a/server/negotiation-approvals.js.map +1 -1
  60. package/app/a2a/server/pipeline.js +78 -30
  61. package/app/a2a/server/pipeline.js.map +1 -1
  62. package/app/a2a/server/server.js +4 -3
  63. package/app/a2a/server/server.js.map +1 -1
  64. package/app/a2a/server/types.d.ts +4 -1
  65. package/app/a2a/unit-alias.d.ts +3 -3
  66. package/app/a2a/unit-alias.js +9 -5
  67. package/app/a2a/unit-alias.js.map +1 -1
  68. package/app/agent/alipay-native-view.d.ts +27 -0
  69. package/app/agent/alipay-native-view.js +113 -0
  70. package/app/agent/alipay-native-view.js.map +1 -0
  71. package/app/agent/buyer/buyer-tools.d.ts +20 -0
  72. package/app/agent/buyer/buyer-tools.js +241 -48
  73. package/app/agent/buyer/buyer-tools.js.map +1 -1
  74. package/app/agent/buyer/types.d.ts +1 -1
  75. package/app/agent/buyer/types.js.map +1 -1
  76. package/app/agent/chat-tui.js +16 -1
  77. package/app/agent/chat-tui.js.map +1 -1
  78. package/app/agent/kernel-builder.d.ts +2 -0
  79. package/app/agent/kernel-builder.js +14 -0
  80. package/app/agent/kernel-builder.js.map +1 -1
  81. package/app/agent/kernel.d.ts +8 -0
  82. package/app/agent/kernel.js +67 -1
  83. package/app/agent/kernel.js.map +1 -1
  84. package/app/auth/merchant-sessions.d.ts +3 -0
  85. package/app/auth/merchant-sessions.js +21 -5
  86. package/app/auth/merchant-sessions.js.map +1 -1
  87. package/app/buyer-core/a2a-accept-terms.d.ts +11 -0
  88. package/app/buyer-core/a2a-accept-terms.js +28 -0
  89. package/app/buyer-core/a2a-accept-terms.js.map +1 -0
  90. package/app/buyer-core/a2a-knp.d.ts +7 -2
  91. package/app/buyer-core/a2a-knp.js +8 -5
  92. package/app/buyer-core/a2a-knp.js.map +1 -1
  93. package/app/buyer-core/a2a-negotiator.d.ts +17 -0
  94. package/app/buyer-core/a2a-negotiator.js +70 -26
  95. package/app/buyer-core/a2a-negotiator.js.map +1 -1
  96. package/app/buyer-core/a2a-quote-fetcher.d.ts +25 -15
  97. package/app/buyer-core/a2a-quote-fetcher.js +92 -19
  98. package/app/buyer-core/a2a-quote-fetcher.js.map +1 -1
  99. package/app/buyer-core/a2a-quote-history.d.ts +94 -0
  100. package/app/buyer-core/a2a-quote-history.js +149 -0
  101. package/app/buyer-core/a2a-quote-history.js.map +1 -0
  102. package/app/buyer-core/build-service.d.ts +19 -0
  103. package/app/buyer-core/build-service.js +30 -1
  104. package/app/buyer-core/build-service.js.map +1 -1
  105. package/app/buyer-core/errors.d.ts +1 -1
  106. package/app/buyer-core/errors.js +1 -0
  107. package/app/buyer-core/errors.js.map +1 -1
  108. package/app/buyer-core/merchant-index.d.ts +2 -2
  109. package/app/buyer-core/merchant-index.js +23 -5
  110. package/app/buyer-core/merchant-index.js.map +1 -1
  111. package/app/buyer-core/open-inquiry-signer.d.ts +1 -0
  112. package/app/buyer-core/open-inquiry-signer.js +5 -2
  113. package/app/buyer-core/open-inquiry-signer.js.map +1 -1
  114. package/app/buyer-core/procurement/cases.d.ts +441 -0
  115. package/app/buyer-core/procurement/cases.js +457 -0
  116. package/app/buyer-core/procurement/cases.js.map +1 -0
  117. package/app/buyer-core/procurement/quote-comparison.d.ts +137 -0
  118. package/app/buyer-core/procurement/quote-comparison.js +106 -0
  119. package/app/buyer-core/procurement/quote-comparison.js.map +1 -0
  120. package/app/buyer-core/procurement/quote-normalizer.d.ts +45 -0
  121. package/app/buyer-core/procurement/quote-normalizer.js +153 -0
  122. package/app/buyer-core/procurement/quote-normalizer.js.map +1 -0
  123. package/app/buyer-core/procurement/requirements.d.ts +50 -0
  124. package/app/buyer-core/procurement/requirements.js +43 -0
  125. package/app/buyer-core/procurement/requirements.js.map +1 -0
  126. package/app/buyer-core/procurement/source-observation.d.ts +57 -0
  127. package/app/buyer-core/procurement/source-observation.js +54 -0
  128. package/app/buyer-core/procurement/source-observation.js.map +1 -0
  129. package/app/buyer-core/procurement/store.d.ts +21 -0
  130. package/app/buyer-core/procurement/store.js +68 -0
  131. package/app/buyer-core/procurement/store.js.map +1 -0
  132. package/app/buyer-core/protocol-recovery.d.ts +10 -1
  133. package/app/buyer-core/protocol-recovery.js +31 -6
  134. package/app/buyer-core/protocol-recovery.js.map +1 -1
  135. package/app/buyer-core/quote-quantity.d.ts +5 -0
  136. package/app/buyer-core/quote-quantity.js +15 -0
  137. package/app/buyer-core/quote-quantity.js.map +1 -0
  138. package/app/buyer-core/service.d.ts +128 -8
  139. package/app/buyer-core/service.js +543 -75
  140. package/app/buyer-core/service.js.map +1 -1
  141. package/app/buyer-core/store.d.ts +21 -0
  142. package/app/buyer-core/store.js +62 -10
  143. package/app/buyer-core/store.js.map +1 -1
  144. package/app/cli.js +26 -19
  145. package/app/cli.js.map +1 -1
  146. package/app/cloud/alipay-collection-http.d.ts +44 -0
  147. package/app/cloud/alipay-collection-http.js +111 -0
  148. package/app/cloud/alipay-collection-http.js.map +1 -0
  149. package/app/cloud/bootstrap.js +218 -19
  150. package/app/cloud/bootstrap.js.map +1 -1
  151. package/app/cloud/http-router.d.ts +2 -0
  152. package/app/cloud/http-router.js +5 -0
  153. package/app/cloud/http-router.js.map +1 -1
  154. package/app/cloud-sample/products.json +3 -3
  155. package/app/commerce/receipt/dispatcher.d.ts +43 -0
  156. package/app/commerce/receipt/dispatcher.js +86 -0
  157. package/app/commerce/receipt/dispatcher.js.map +1 -0
  158. package/app/commerce/receipt/receipts.d.ts +147 -0
  159. package/app/commerce/receipt/receipts.js +285 -0
  160. package/app/commerce/receipt/receipts.js.map +1 -0
  161. package/app/config/profile.d.ts +2 -2
  162. package/app/discovery/catalog-source/buyer-follows.d.ts +3 -3
  163. package/app/discovery/catalog-source/buyer-follows.js +6 -3
  164. package/app/discovery/catalog-source/buyer-follows.js.map +1 -1
  165. package/app/discovery/catalog-source/kiwi-record.d.ts +2 -0
  166. package/app/discovery/catalog-source/kiwi-record.js.map +1 -1
  167. package/app/discovery/catalog-source/kiwi-source.js +4 -0
  168. package/app/discovery/catalog-source/kiwi-source.js.map +1 -1
  169. package/app/handoff/alipay-collection.d.ts +23 -0
  170. package/app/handoff/alipay-collection.js +70 -0
  171. package/app/handoff/alipay-collection.js.map +1 -0
  172. package/app/handoff/order-receipts.d.ts +62 -0
  173. package/app/handoff/order-receipts.js +72 -0
  174. package/app/handoff/order-receipts.js.map +1 -0
  175. package/app/handoff/ucp-checkout/cart-channel.d.ts +2 -1
  176. package/app/handoff/ucp-checkout/cart-channel.js +1 -0
  177. package/app/handoff/ucp-checkout/cart-channel.js.map +1 -1
  178. package/app/handoff/ucp-checkout/channel.d.ts +7 -0
  179. package/app/handoff/ucp-checkout/channel.js +79 -10
  180. package/app/handoff/ucp-checkout/channel.js.map +1 -1
  181. package/app/http/cli.js +6 -0
  182. package/app/http/cli.js.map +1 -1
  183. package/app/http/merchant-management/api.d.ts +18 -0
  184. package/app/http/merchant-management/api.js +752 -3
  185. package/app/http/merchant-management/api.js.map +1 -1
  186. package/app/http/merchant-management/draft-store.js +8 -6
  187. package/app/http/merchant-management/draft-store.js.map +1 -1
  188. package/app/http/merchant-management/page.d.ts +1 -0
  189. package/app/http/merchant-management/page.js +335 -5
  190. package/app/http/merchant-management/page.js.map +1 -1
  191. package/app/http/server.js +9 -2
  192. package/app/http/server.js.map +1 -1
  193. package/app/mcp/cli.d.ts +3 -1
  194. package/app/mcp/cli.js +18 -2
  195. package/app/mcp/cli.js.map +1 -1
  196. package/app/mcp/merchant-runtime-assembly.d.ts +20 -0
  197. package/app/mcp/merchant-runtime-assembly.js +94 -11
  198. package/app/mcp/merchant-runtime-assembly.js.map +1 -1
  199. package/app/mcp/merchant-server.d.ts +5 -0
  200. package/app/mcp/merchant-server.js +12 -0
  201. package/app/mcp/merchant-server.js.map +1 -1
  202. package/app/mcp/procurement-tools.d.ts +10 -0
  203. package/app/mcp/procurement-tools.js +173 -0
  204. package/app/mcp/procurement-tools.js.map +1 -0
  205. package/app/mcp/server.d.ts +4 -0
  206. package/app/mcp/server.js +63 -9
  207. package/app/mcp/server.js.map +1 -1
  208. package/app/mcp/tools.d.ts +4 -1
  209. package/app/mcp/tools.js +83 -28
  210. package/app/mcp/tools.js.map +1 -1
  211. package/app/mcp/types.d.ts +1 -0
  212. package/app/mcp/types.js.map +1 -1
  213. package/app/merchant/application/actor.d.ts +3 -1
  214. package/app/merchant/application/actor.js +21 -0
  215. package/app/merchant/application/actor.js.map +1 -1
  216. package/app/merchant/negotiation-ops.d.ts +2 -0
  217. package/app/merchant/negotiation-ops.js +4 -0
  218. package/app/merchant/negotiation-ops.js.map +1 -1
  219. package/app/merchant/weixin-channel.d.ts +68 -0
  220. package/app/merchant/weixin-channel.js +313 -0
  221. package/app/merchant/weixin-channel.js.map +1 -0
  222. package/app/merchant/workbench-server.d.ts +1 -0
  223. package/app/merchant/workbench-server.js +189 -2
  224. package/app/merchant/workbench-server.js.map +1 -1
  225. package/app/merchant-core/budget/background-budget.d.ts +132 -0
  226. package/app/merchant-core/budget/background-budget.js +308 -0
  227. package/app/merchant-core/budget/background-budget.js.map +1 -0
  228. package/app/merchant-core/collection/alipay-store.d.ts +22 -0
  229. package/app/merchant-core/collection/alipay-store.js +125 -0
  230. package/app/merchant-core/collection/alipay-store.js.map +1 -0
  231. package/app/merchant-core/commercial/calculate.js +6 -6
  232. package/app/merchant-core/commercial/calculate.js.map +1 -1
  233. package/app/merchant-core/context-governance/actor-context.d.ts +56 -0
  234. package/app/merchant-core/context-governance/actor-context.js +76 -0
  235. package/app/merchant-core/context-governance/actor-context.js.map +1 -0
  236. package/app/merchant-core/context-governance/authority.d.ts +39 -0
  237. package/app/merchant-core/context-governance/authority.js +28 -0
  238. package/app/merchant-core/context-governance/authority.js.map +1 -0
  239. package/app/merchant-core/context-governance/context-guard.d.ts +104 -0
  240. package/app/merchant-core/context-governance/context-guard.js +194 -0
  241. package/app/merchant-core/context-governance/context-guard.js.map +1 -0
  242. package/app/merchant-core/context-governance/data-use-grant.d.ts +91 -0
  243. package/app/merchant-core/context-governance/data-use-grant.js +211 -0
  244. package/app/merchant-core/context-governance/data-use-grant.js.map +1 -0
  245. package/app/merchant-core/context-governance/feature-flags.d.ts +32 -0
  246. package/app/merchant-core/context-governance/feature-flags.js +83 -0
  247. package/app/merchant-core/context-governance/feature-flags.js.map +1 -0
  248. package/app/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
  249. package/app/merchant-core/context-governance/pilot-readiness.js +141 -0
  250. package/app/merchant-core/context-governance/pilot-readiness.js.map +1 -0
  251. package/app/merchant-core/context-governance/source-governance.d.ts +157 -0
  252. package/app/merchant-core/context-governance/source-governance.js +492 -0
  253. package/app/merchant-core/context-governance/source-governance.js.map +1 -0
  254. package/app/merchant-core/context-governance/types.d.ts +62 -0
  255. package/app/merchant-core/context-governance/types.js +92 -0
  256. package/app/merchant-core/context-governance/types.js.map +1 -0
  257. package/app/merchant-core/customer-delivery/binding.d.ts +55 -0
  258. package/app/merchant-core/customer-delivery/binding.js +121 -0
  259. package/app/merchant-core/customer-delivery/binding.js.map +1 -0
  260. package/app/merchant-core/customer-delivery/channel.d.ts +75 -0
  261. package/app/merchant-core/customer-delivery/channel.js +157 -0
  262. package/app/merchant-core/customer-delivery/channel.js.map +1 -0
  263. package/app/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
  264. package/app/merchant-core/customer-delivery/consent-repository.js +160 -0
  265. package/app/merchant-core/customer-delivery/consent-repository.js.map +1 -0
  266. package/app/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
  267. package/app/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
  268. package/app/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
  269. package/app/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
  270. package/app/merchant-core/customer-delivery/dispatcher.js +166 -0
  271. package/app/merchant-core/customer-delivery/dispatcher.js.map +1 -0
  272. package/app/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
  273. package/app/merchant-core/customer-delivery/email-adapter.js +90 -0
  274. package/app/merchant-core/customer-delivery/email-adapter.js.map +1 -0
  275. package/app/merchant-core/customer-delivery/gate.d.ts +37 -0
  276. package/app/merchant-core/customer-delivery/gate.js +196 -0
  277. package/app/merchant-core/customer-delivery/gate.js.map +1 -0
  278. package/app/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
  279. package/app/merchant-core/customer-delivery/reconciliation.js +70 -0
  280. package/app/merchant-core/customer-delivery/reconciliation.js.map +1 -0
  281. package/app/merchant-core/customer-delivery/repository.d.ts +55 -0
  282. package/app/merchant-core/customer-delivery/repository.js +235 -0
  283. package/app/merchant-core/customer-delivery/repository.js.map +1 -0
  284. package/app/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
  285. package/app/merchant-core/customer-delivery/smtp-adapter.js +183 -0
  286. package/app/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
  287. package/app/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
  288. package/app/merchant-core/customer-delivery/stream-gate.js +123 -0
  289. package/app/merchant-core/customer-delivery/stream-gate.js.map +1 -0
  290. package/app/merchant-core/customer-delivery/types.d.ts +103 -0
  291. package/app/merchant-core/customer-delivery/types.js +32 -0
  292. package/app/merchant-core/customer-delivery/types.js.map +1 -0
  293. package/app/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
  294. package/app/merchant-core/customer-delivery/weixin-adapter.js +56 -0
  295. package/app/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
  296. package/app/merchant-core/customer-memory/auto-identity.d.ts +43 -0
  297. package/app/merchant-core/customer-memory/auto-identity.js +163 -0
  298. package/app/merchant-core/customer-memory/auto-identity.js.map +1 -0
  299. package/app/merchant-core/customer-memory/grants.d.ts +72 -0
  300. package/app/merchant-core/customer-memory/grants.js +224 -0
  301. package/app/merchant-core/customer-memory/grants.js.map +1 -0
  302. package/app/merchant-core/customer-memory/history.d.ts +51 -0
  303. package/app/merchant-core/customer-memory/history.js +252 -0
  304. package/app/merchant-core/customer-memory/history.js.map +1 -0
  305. package/app/merchant-core/customer-memory/identity.d.ts +66 -0
  306. package/app/merchant-core/customer-memory/identity.js +249 -0
  307. package/app/merchant-core/customer-memory/identity.js.map +1 -0
  308. package/app/merchant-core/customer-memory/maintenance.d.ts +51 -0
  309. package/app/merchant-core/customer-memory/maintenance.js +67 -0
  310. package/app/merchant-core/customer-memory/maintenance.js.map +1 -0
  311. package/app/merchant-core/customer-memory/memory.d.ts +119 -0
  312. package/app/merchant-core/customer-memory/memory.js +502 -0
  313. package/app/merchant-core/customer-memory/memory.js.map +1 -0
  314. package/app/merchant-core/customer-memory/private-transport.d.ts +10 -0
  315. package/app/merchant-core/customer-memory/private-transport.js +108 -0
  316. package/app/merchant-core/customer-memory/private-transport.js.map +1 -0
  317. package/app/merchant-core/customer-memory/quote-history.d.ts +160 -0
  318. package/app/merchant-core/customer-memory/quote-history.js +392 -0
  319. package/app/merchant-core/customer-memory/quote-history.js.map +1 -0
  320. package/app/merchant-core/customer-memory/reception-provider.d.ts +69 -0
  321. package/app/merchant-core/customer-memory/reception-provider.js +250 -0
  322. package/app/merchant-core/customer-memory/reception-provider.js.map +1 -0
  323. package/app/merchant-core/customer-memory/reception-writer.d.ts +19 -0
  324. package/app/merchant-core/customer-memory/reception-writer.js +32 -0
  325. package/app/merchant-core/customer-memory/reception-writer.js.map +1 -0
  326. package/app/merchant-core/customer-memory/types.d.ts +111 -0
  327. package/app/merchant-core/customer-memory/types.js +58 -0
  328. package/app/merchant-core/customer-memory/types.js.map +1 -0
  329. package/app/merchant-core/followup/repository.d.ts +2 -1
  330. package/app/merchant-core/followup/repository.js +29 -23
  331. package/app/merchant-core/followup/repository.js.map +1 -1
  332. package/app/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
  333. package/app/merchant-core/learning/evaluation-fixtures.js +83 -0
  334. package/app/merchant-core/learning/evaluation-fixtures.js.map +1 -0
  335. package/app/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
  336. package/app/merchant-core/learning/evaluation-suite-v1.js +129 -0
  337. package/app/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
  338. package/app/merchant-core/learning/evaluation.d.ts +84 -0
  339. package/app/merchant-core/learning/evaluation.js +581 -0
  340. package/app/merchant-core/learning/evaluation.js.map +1 -0
  341. package/app/merchant-core/learning/initial-skills.d.ts +36 -0
  342. package/app/merchant-core/learning/initial-skills.js +67 -0
  343. package/app/merchant-core/learning/initial-skills.js.map +1 -0
  344. package/app/merchant-core/learning/precheck.d.ts +33 -0
  345. package/app/merchant-core/learning/precheck.js +56 -0
  346. package/app/merchant-core/learning/precheck.js.map +1 -0
  347. package/app/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
  348. package/app/merchant-core/learning/real-evaluation-runner.js +167 -0
  349. package/app/merchant-core/learning/real-evaluation-runner.js.map +1 -0
  350. package/app/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
  351. package/app/merchant-core/learning/reception-skill-catalog.js +145 -0
  352. package/app/merchant-core/learning/reception-skill-catalog.js.map +1 -0
  353. package/app/merchant-core/learning/recovery-gateway.d.ts +27 -0
  354. package/app/merchant-core/learning/recovery-gateway.js +106 -0
  355. package/app/merchant-core/learning/recovery-gateway.js.map +1 -0
  356. package/app/merchant-core/learning/repository.d.ts +130 -0
  357. package/app/merchant-core/learning/repository.js +588 -0
  358. package/app/merchant-core/learning/repository.js.map +1 -0
  359. package/app/merchant-core/learning/service.d.ts +262 -0
  360. package/app/merchant-core/learning/service.js +1498 -0
  361. package/app/merchant-core/learning/service.js.map +1 -0
  362. package/app/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
  363. package/app/merchant-core/learning/test-dispatch-gateway.js +145 -0
  364. package/app/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
  365. package/app/merchant-core/learning/types.d.ts +217 -0
  366. package/app/merchant-core/learning/types.js +52 -0
  367. package/app/merchant-core/learning/types.js.map +1 -0
  368. package/app/merchant-core/migrations/ledgers.d.ts +40 -0
  369. package/app/merchant-core/migrations/ledgers.js +824 -0
  370. package/app/merchant-core/migrations/ledgers.js.map +1 -0
  371. package/app/merchant-core/migrations/runner.d.ts +55 -0
  372. package/app/merchant-core/migrations/runner.js +114 -0
  373. package/app/merchant-core/migrations/runner.js.map +1 -0
  374. package/app/merchant-core/operating/repository.d.ts +0 -1
  375. package/app/merchant-core/operating/repository.js +2 -17
  376. package/app/merchant-core/operating/repository.js.map +1 -1
  377. package/app/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
  378. package/app/merchant-core/operations-jobs/advice-runner.js +199 -0
  379. package/app/merchant-core/operations-jobs/advice-runner.js.map +1 -0
  380. package/app/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
  381. package/app/merchant-core/operations-jobs/pilot-evidence.js +109 -0
  382. package/app/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
  383. package/app/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
  384. package/app/merchant-core/operations-jobs/pilot-metrics.js +98 -0
  385. package/app/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
  386. package/app/merchant-core/operations-jobs/projection.d.ts +41 -0
  387. package/app/merchant-core/operations-jobs/projection.js +158 -0
  388. package/app/merchant-core/operations-jobs/projection.js.map +1 -0
  389. package/app/merchant-core/operations-jobs/scheduler.d.ts +68 -0
  390. package/app/merchant-core/operations-jobs/scheduler.js +233 -0
  391. package/app/merchant-core/operations-jobs/scheduler.js.map +1 -0
  392. package/app/merchant-core/operations-jobs/service.d.ts +260 -0
  393. package/app/merchant-core/operations-jobs/service.js +922 -0
  394. package/app/merchant-core/operations-jobs/service.js.map +1 -0
  395. package/app/merchant-core/opportunity/repository.d.ts +0 -1
  396. package/app/merchant-core/opportunity/repository.js +2 -17
  397. package/app/merchant-core/opportunity/repository.js.map +1 -1
  398. package/app/merchant-core/ops/facade.d.ts +10 -0
  399. package/app/merchant-core/ops/facade.js +52 -0
  400. package/app/merchant-core/ops/facade.js.map +1 -1
  401. package/app/merchant-core/ops/schema.d.ts +1 -1
  402. package/app/merchant-core/ops/schema.js +119 -2
  403. package/app/merchant-core/ops/schema.js.map +1 -1
  404. package/app/merchant-core/ops/surface.d.ts +37 -0
  405. package/app/merchant-core/ops/surface.js +240 -0
  406. package/app/merchant-core/ops/surface.js.map +1 -1
  407. package/app/merchant-core/orders/model.d.ts +1 -8
  408. package/app/merchant-core/orders/model.js +10 -2
  409. package/app/merchant-core/orders/model.js.map +1 -1
  410. package/app/merchant-core/orders/repository.d.ts +0 -1
  411. package/app/merchant-core/orders/repository.js +3 -18
  412. package/app/merchant-core/orders/repository.js.map +1 -1
  413. package/app/merchant-core/orders/service.js +34 -8
  414. package/app/merchant-core/orders/service.js.map +1 -1
  415. package/app/merchant-core/ownership/instance-ownership.d.ts +122 -0
  416. package/app/merchant-core/ownership/instance-ownership.js +236 -0
  417. package/app/merchant-core/ownership/instance-ownership.js.map +1 -0
  418. package/app/merchant-core/ownership/runtime.d.ts +175 -0
  419. package/app/merchant-core/ownership/runtime.js +422 -0
  420. package/app/merchant-core/ownership/runtime.js.map +1 -0
  421. package/app/merchant-core/proposal/engine.js +2 -0
  422. package/app/merchant-core/proposal/engine.js.map +1 -1
  423. package/app/merchant-core/proposal/publish.d.ts +0 -6
  424. package/app/merchant-core/proposal/publish.js +37 -3
  425. package/app/merchant-core/proposal/publish.js.map +1 -1
  426. package/app/merchant-core/proposal/repository.d.ts +0 -7
  427. package/app/merchant-core/proposal/repository.js +8 -17
  428. package/app/merchant-core/proposal/repository.js.map +1 -1
  429. package/app/merchant-core/proposal/types.d.ts +1 -0
  430. package/app/merchant-core/proposal/types.js.map +1 -1
  431. package/app/merchant-core/rfq/policy.d.ts +1 -0
  432. package/app/merchant-core/rfq/policy.js +6 -7
  433. package/app/merchant-core/rfq/policy.js.map +1 -1
  434. package/app/merchant-core/rfq/repository.d.ts +0 -1
  435. package/app/merchant-core/rfq/repository.js +2 -17
  436. package/app/merchant-core/rfq/repository.js.map +1 -1
  437. package/app/merchant-core/rfq/service.d.ts +2 -1
  438. package/app/merchant-core/rfq/service.js +2 -4
  439. package/app/merchant-core/rfq/service.js.map +1 -1
  440. package/app/merchant-core/storage/transaction.d.ts +95 -7
  441. package/app/merchant-core/storage/transaction.js +251 -2
  442. package/app/merchant-core/storage/transaction.js.map +1 -1
  443. package/app/merchant-credential-rotation.d.ts +4 -1
  444. package/app/merchant-credential-rotation.js +12 -8
  445. package/app/merchant-credential-rotation.js.map +1 -1
  446. package/app/merchant-runtime/manager.d.ts +2 -0
  447. package/app/merchant-runtime/manager.js +5 -0
  448. package/app/merchant-runtime/manager.js.map +1 -1
  449. package/app/negotiation/domain/objects.d.ts +2 -0
  450. package/app/negotiation/domain/objects.js +3 -0
  451. package/app/negotiation/domain/objects.js.map +1 -1
  452. package/app/negotiation/ledger/store.d.ts +4 -0
  453. package/app/negotiation/ledger/store.js +20 -0
  454. package/app/negotiation/ledger/store.js.map +1 -1
  455. package/app/product-init.d.ts +1 -0
  456. package/app/product-init.js +4 -1
  457. package/app/product-init.js.map +1 -1
  458. package/app/trust/identity/message-signature.d.ts +1 -1
  459. package/app/trust/identity/message-signature.js +6 -1
  460. package/app/trust/identity/message-signature.js.map +1 -1
  461. package/app/trust/identity/nonce.d.ts +5 -0
  462. package/app/trust/identity/nonce.js +2 -0
  463. package/app/trust/identity/nonce.js.map +1 -1
  464. package/app/weixin/ilink-client.d.ts +3 -2
  465. package/app/weixin/ilink-client.js +9 -2
  466. package/app/weixin/ilink-client.js.map +1 -1
  467. package/build-manifest.json +1672 -487
  468. package/deployment-lock.json +2 -2
  469. package/package.json +1 -1
  470. package/prepare.mjs +5 -1
  471. package/runtime-package.json +1 -1
  472. package/shipping-sbom.cdx.json +6 -6
  473. package/shipping-source.json +12 -12
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../../src/merchant-core/customer-delivery/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAwDH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,IAAI,CAA4B;IACzC,YAAY,IAA+B,EAAE,OAAe;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAgBD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAChF,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;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IAC7E,CAAC;IACD,MAAM,IAAI,GAAmB;QAC3B,GAAG,MAAM;QACT,OAAO,EAAE,KAAK,CAAC,GAAG;QAClB,iBAAiB,EAAE,KAAK,CAAC,YAAY;KACtC,CAAC;IACF,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAOpC;IACC,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAChF,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,qBAAqB,CAAC,oBAAoB,EAAE,MAAM,MAAM,CAAC,MAAM,OAAO,CAAC,CAAC;IACpF,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC;QACjC,MAAM,IAAI,qBAAqB,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAC9B,MAAM,IAAI,qBAAqB,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,OAAO,GAAmB;QAC9B,GAAG,MAAM;QACT,MAAM,EAAE,SAAS;QACjB,WAAW,EAAE,SAAS;QACtB,gBAAgB,EAAE,SAAS;QAC3B,UAAU,EAAE,SAAS;QACrB,cAAc,EAAE,SAAS;KAC1B,CAAC;IACF,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,31 @@
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
+ * 邮件发送适配器(M6-6,Resend HTTP API)。
18
+ *
19
+ * 收件地址不进入冻结 payload;由宿主按绑定解析后传入 `to`。2xx 表示平台
20
+ * 接受(不等于已读),4xx 可证明未发送,5xx/网络错误为 UNKNOWN。
21
+ */
22
+ import type { DeliveryChannelAdapter } from "./channel.js";
23
+ export interface EmailChannelAdapterOptions {
24
+ readonly api_key: string;
25
+ readonly from: string;
26
+ /** 仅测试注入;生产必须由调用方按授权绑定传入 recipient。 */
27
+ readonly to?: string;
28
+ readonly endpoint?: string;
29
+ readonly fetchImpl?: typeof fetch;
30
+ }
31
+ export declare function createEmailChannelAdapter(options: EmailChannelAdapterOptions): DeliveryChannelAdapter;
@@ -0,0 +1,90 @@
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 createEmailChannelAdapter(options) {
17
+ const endpoint = options.endpoint ?? "https://api.resend.com/emails";
18
+ const fetchImpl = options.fetchImpl ?? fetch;
19
+ return {
20
+ async send({ delivery, idempotency_key, timeout_ms, recipient }) {
21
+ if (delivery.channel !== "email") {
22
+ return { outcome: "not_sent", reason: "channel_mismatch" };
23
+ }
24
+ const to = recipient ?? options.to;
25
+ if (to === undefined || to.trim() === "") {
26
+ return { outcome: "not_sent", reason: "recipient_unresolved" };
27
+ }
28
+ const subject = typeof delivery.payload.title === "string" ? delivery.payload.title : "通知";
29
+ const body = typeof delivery.payload.body === "string" ? delivery.payload.body : "";
30
+ if (body.trim() === "")
31
+ return { outcome: "not_sent", reason: "payload_empty" };
32
+ const controller = new AbortController();
33
+ const timer = setTimeout(() => controller.abort(), timeout_ms);
34
+ try {
35
+ const response = await fetchImpl(endpoint, {
36
+ method: "POST",
37
+ headers: {
38
+ authorization: `Bearer ${options.api_key}`,
39
+ "content-type": "application/json",
40
+ "idempotency-key": idempotency_key,
41
+ },
42
+ body: JSON.stringify({
43
+ from: options.from,
44
+ to: [to],
45
+ subject,
46
+ text: body,
47
+ }),
48
+ signal: controller.signal,
49
+ });
50
+ const text = await response.text();
51
+ let receipt = {};
52
+ try {
53
+ receipt = text === "" ? {} : JSON.parse(text);
54
+ }
55
+ catch {
56
+ receipt = { raw: text.slice(0, 500) };
57
+ }
58
+ if (response.status >= 200 && response.status < 300) {
59
+ return {
60
+ outcome: "accepted",
61
+ ...(typeof receipt.id === "string" ? { provider_request_id: receipt.id } : {}),
62
+ receipt,
63
+ };
64
+ }
65
+ if (response.status === 429) {
66
+ const retryAfter = response.headers.get("retry-after")?.trim() ?? "";
67
+ const waitMs = /^[0-9]+$/.test(retryAfter)
68
+ ? Number(retryAfter) * 1_000
69
+ : Date.parse(retryAfter) - Date.now();
70
+ return {
71
+ outcome: "not_sent",
72
+ reason: "http_429",
73
+ retry_after_ms: Number.isNaN(waitMs) ? 0 : Math.max(0, waitMs),
74
+ };
75
+ }
76
+ if (response.status >= 400 && response.status < 500 && response.status !== 408) {
77
+ return { outcome: "not_sent", reason: `http_${response.status}` };
78
+ }
79
+ return { outcome: "unknown", receipt: { status: response.status, ...receipt } };
80
+ }
81
+ catch {
82
+ return { outcome: "unknown" };
83
+ }
84
+ finally {
85
+ clearTimeout(timer);
86
+ }
87
+ },
88
+ };
89
+ }
90
+ //# sourceMappingURL=email-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-adapter.js","sourceRoot":"","sources":["../../../src/merchant-core/customer-delivery/email-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAoBH,MAAM,UAAU,yBAAyB,CACvC,OAAmC;IAEnC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,+BAA+B,CAAC;IACrE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;IAC7C,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,EAAE;YAC7D,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;gBACjC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;YAC7D,CAAC;YACD,MAAM,EAAE,GAAG,SAAS,IAAI,OAAO,CAAC,EAAE,CAAC;YACnC,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;gBACzC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;YACjE,CAAC;YACD,MAAM,OAAO,GAAG,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;YAC3F,MAAM,IAAI,GAAG,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACpF,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;gBAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,eAA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AC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
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 DeliveryPurpose, type DeliverySourceGrant, type NotificationSubscription, type PrepareDeliveryInput, type PreparedDelivery, type RecipientBinding } from "./types.js";
17
+ /**
18
+ * 发送时复核(P1-4):prepare 之后客户可能退订/撤销/过期,或已发送频次
19
+ * 达到上限。调用方在 claim 事务内重读绑定/订阅/回执后调用本函数;失败
20
+ * 抛 `DeliveryGateError`,该条不得发送。
21
+ */
22
+ export declare function assertDeliveryStillAuthorized(input: {
23
+ merchant_id: string;
24
+ binding: RecipientBinding | undefined;
25
+ subscription: NotificationSubscription | undefined;
26
+ purpose: DeliveryPurpose;
27
+ source_grants: readonly DeliverySourceGrant[];
28
+ now: string;
29
+ sent_today: number;
30
+ expected_binding_epoch?: number;
31
+ expected_subscription_epoch?: number;
32
+ }): void;
33
+ /**
34
+ * 校验并冻结一条 P1 待发送通知。成功返回 PENDING 记录;失败抛错,
35
+ * 调用方不得落发送队列。
36
+ */
37
+ export declare function prepareDelivery(input: PrepareDeliveryInput): PreparedDelivery;
@@ -0,0 +1,196 @@
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
+ * P1 客户发送门的纯判定(设计 §16.3)。
18
+ *
19
+ * 只做校验与冻结:不调用渠道、不写数据库。任何一项不满足都抛
20
+ * `DeliveryGateError`,调用方保持工作台草稿(C12)。
21
+ */
22
+ import { assertFeatureEnabled } from "../context-governance/feature-flags.js";
23
+ import { contentDigest } from "../../negotiation/jcs.js";
24
+ import { DeliveryGateError, } from "./types.js";
25
+ const ISO_UTC = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;
26
+ /** 明文渠道地址形态(手机号/邮箱)不得进入 payload。 */
27
+ const RAW_ADDRESS_PATTERNS = [
28
+ /\+?\d[\d\s-]{6,}\d/,
29
+ /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/,
30
+ ];
31
+ function isAtOrBefore(a, b) {
32
+ return Date.parse(a) <= Date.parse(b);
33
+ }
34
+ function requireIso(value, field) {
35
+ if (!ISO_UTC.test(value) || !Number.isFinite(Date.parse(value))) {
36
+ throw new DeliveryGateError("valid_until_invalid", `${field} 必须是 RFC3339 UTC`);
37
+ }
38
+ return value;
39
+ }
40
+ function containsRawAddress(value) {
41
+ if (typeof value === "string")
42
+ return RAW_ADDRESS_PATTERNS.some((pattern) => pattern.test(value));
43
+ if (Array.isArray(value))
44
+ return value.some(containsRawAddress);
45
+ if (value !== null && typeof value === "object") {
46
+ return Object.values(value).some(containsRawAddress);
47
+ }
48
+ return false;
49
+ }
50
+ function checkBinding(merchantId, binding) {
51
+ if (binding === undefined) {
52
+ throw new DeliveryGateError("binding_missing", "收件人绑定不存在");
53
+ }
54
+ if (binding.merchant_id !== merchantId) {
55
+ throw new DeliveryGateError("binding_mismatch", "收件人绑定不属于本商家");
56
+ }
57
+ if (binding.revoked_at !== null) {
58
+ throw new DeliveryGateError("binding_revoked", "收件人绑定已撤销");
59
+ }
60
+ if (binding.verified_at.trim() === "") {
61
+ throw new DeliveryGateError("binding_unverified", "收件人绑定未验证");
62
+ }
63
+ if (binding.address_ref.trim() === "") {
64
+ throw new DeliveryGateError("binding_unverified", "收件人地址引用为空");
65
+ }
66
+ return binding;
67
+ }
68
+ function checkSubscription(input) {
69
+ const subscription = input.subscription;
70
+ if (subscription === undefined) {
71
+ throw new DeliveryGateError("subscription_missing", "缺少目的授权");
72
+ }
73
+ if (subscription.merchant_id !== input.merchantId) {
74
+ throw new DeliveryGateError("subscription_mismatch", "授权不属于本商家");
75
+ }
76
+ if (subscription.binding_id !== input.binding.binding_id) {
77
+ throw new DeliveryGateError("subscription_mismatch", "授权与收件人绑定不一致");
78
+ }
79
+ if (subscription.purpose !== input.purpose) {
80
+ throw new DeliveryGateError("subscription_mismatch", "授权用途不一致");
81
+ }
82
+ if (subscription.unsubscribed_at !== null) {
83
+ throw new DeliveryGateError("subscription_revoked", "客户已退订");
84
+ }
85
+ if (subscription.expires_at !== null && isAtOrBefore(subscription.expires_at, input.now)) {
86
+ throw new DeliveryGateError("subscription_expired", "授权已过期");
87
+ }
88
+ if (!Number.isSafeInteger(subscription.max_per_day) || subscription.max_per_day <= 0) {
89
+ throw new DeliveryGateError("frequency_exceeded", "该目的不允许主动通知");
90
+ }
91
+ if (input.sentToday >= subscription.max_per_day) {
92
+ throw new DeliveryGateError("frequency_exceeded", "超过当日发送频率");
93
+ }
94
+ return subscription;
95
+ }
96
+ function checkGrants(grants, now) {
97
+ for (const grant of grants) {
98
+ if (grant.status === "REVOKED") {
99
+ throw new DeliveryGateError("grant_revoked", `来源授权 ${grant.grant_id} 已撤销`);
100
+ }
101
+ if (grant.status === "EXPIRED" || (grant.expires_at !== null && isAtOrBefore(grant.expires_at, now))) {
102
+ throw new DeliveryGateError("grant_expired", `来源授权 ${grant.grant_id} 已过期`);
103
+ }
104
+ }
105
+ }
106
+ /**
107
+ * 发送时复核(P1-4):prepare 之后客户可能退订/撤销/过期,或已发送频次
108
+ * 达到上限。调用方在 claim 事务内重读绑定/订阅/回执后调用本函数;失败
109
+ * 抛 `DeliveryGateError`,该条不得发送。
110
+ */
111
+ export function assertDeliveryStillAuthorized(input) {
112
+ const binding = checkBinding(input.merchant_id, input.binding);
113
+ if (input.expected_binding_epoch !== undefined &&
114
+ binding.binding_epoch !== input.expected_binding_epoch) {
115
+ throw new DeliveryGateError("epoch_mismatch", "收件人绑定已变化");
116
+ }
117
+ const subscription = checkSubscription({
118
+ merchantId: input.merchant_id,
119
+ binding,
120
+ purpose: input.purpose,
121
+ subscription: input.subscription,
122
+ now: input.now,
123
+ sentToday: input.sent_today,
124
+ });
125
+ if (input.expected_subscription_epoch !== undefined &&
126
+ subscription.grant_epoch !== input.expected_subscription_epoch) {
127
+ throw new DeliveryGateError("epoch_mismatch", "目的授权已变化");
128
+ }
129
+ checkGrants(input.source_grants, input.now);
130
+ }
131
+ /**
132
+ * 校验并冻结一条 P1 待发送通知。成功返回 PENDING 记录;失败抛错,
133
+ * 调用方不得落发送队列。
134
+ */
135
+ export function prepareDelivery(input) {
136
+ assertFeatureEnabled(input.flags, "customer_delivery_enabled");
137
+ const now = requireIso(input.now, "now");
138
+ const validUntil = requireIso(input.valid_until, "valid_until");
139
+ if (!isAtOrBefore(now, validUntil)) {
140
+ throw new DeliveryGateError("valid_until_invalid", "valid_until 不得早于当前时间");
141
+ }
142
+ if (!Number.isSafeInteger(input.seq) || input.seq <= 0) {
143
+ throw new DeliveryGateError("seq_invalid", "seq 必须是正整数");
144
+ }
145
+ if (input.stream_busy) {
146
+ throw new DeliveryGateError("stream_busy", "该发送流已有在途通知");
147
+ }
148
+ const binding = checkBinding(input.merchant_id, input.binding);
149
+ const subscription = checkSubscription({
150
+ merchantId: input.merchant_id,
151
+ binding,
152
+ purpose: input.purpose,
153
+ subscription: input.subscription,
154
+ now,
155
+ sentToday: input.sent_today,
156
+ });
157
+ checkGrants(input.source_grants, now);
158
+ if (subscription.expires_at !== null && isAtOrBefore(validUntil, now)) {
159
+ throw new DeliveryGateError("valid_until_invalid", "valid_until 已失效");
160
+ }
161
+ if (subscription.expires_at !== null && Date.parse(validUntil) > Date.parse(subscription.expires_at)) {
162
+ throw new DeliveryGateError("valid_until_invalid", "valid_until 超过授权有效期");
163
+ }
164
+ if (input.payload === null || typeof input.payload !== "object" || Array.isArray(input.payload)) {
165
+ throw new DeliveryGateError("payload_invalid", "payload 必须是对象");
166
+ }
167
+ if (Object.keys(input.payload).length === 0) {
168
+ throw new DeliveryGateError("payload_invalid", "payload 不能为空");
169
+ }
170
+ if (containsRawAddress(input.payload)) {
171
+ throw new DeliveryGateError("payload_invalid", "payload 不得包含明文渠道地址");
172
+ }
173
+ const payload = Object.freeze({ ...input.payload });
174
+ // P2-3:流按“商家 + 渠道 + 收件人绑定”划分;purpose 不能成为并行旁路,
175
+ // 否则同一收件人会同时收到多条在途通知。
176
+ const streamKey = `${input.merchant_id}:${binding.channel}:${binding.binding_id}`;
177
+ return Object.freeze({
178
+ delivery_id: input.delivery_id,
179
+ merchant_id: input.merchant_id,
180
+ stream_key: streamKey,
181
+ binding_id: binding.binding_id,
182
+ binding_epoch: binding.binding_epoch,
183
+ channel: binding.channel,
184
+ purpose: input.purpose,
185
+ payload,
186
+ payload_digest: contentDigest(payload),
187
+ seq: input.seq,
188
+ valid_until: validUntil,
189
+ subscription_id: subscription.subscription_id,
190
+ subscription_epoch: subscription.grant_epoch,
191
+ source_grants: Object.freeze([...input.source_grants]),
192
+ created_at: now,
193
+ status: "PENDING",
194
+ });
195
+ }
196
+ //# sourceMappingURL=gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate.js","sourceRoot":"","sources":["../../../src/merchant-core/customer-delivery/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;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,WAAW;QAC5C,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;QACtD,UAAU,EAAE,GAAG;QACf,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { DeliveryRecord } from "./dispatcher.js";
2
+ export type DeliveryEvidence = {
3
+ outcome: "accepted";
4
+ evidence_ref: string;
5
+ accepted_at: string;
6
+ } | {
7
+ outcome: "not_sent";
8
+ evidence_ref: string;
9
+ future_execution_blocked: true;
10
+ };
11
+ export declare function deliveryAttemptDigest(record: DeliveryRecord): string;
12
+ /** Read-only lookup against the deployment's authoritative channel log gateway. */
13
+ export declare function createDeliveryReconciler(env: Record<string, string | undefined>, fetchImpl?: typeof fetch): ((record: DeliveryRecord) => Promise<DeliveryEvidence | undefined>) | undefined;
@@ -0,0 +1,70 @@
1
+ import { contentDigest } from "../../negotiation/jcs.js";
2
+ export function deliveryAttemptDigest(record) {
3
+ return contentDigest({
4
+ merchant_id: record.merchant_id,
5
+ delivery_id: record.delivery_id,
6
+ channel: record.channel,
7
+ attempts: record.attempts ?? 0,
8
+ started_at: record.started_at ?? null,
9
+ payload_digest: record.payload_digest,
10
+ provider_request_id: record.provider_request_id ?? null,
11
+ });
12
+ }
13
+ /** Read-only lookup against the deployment's authoritative channel log gateway. */
14
+ export function createDeliveryReconciler(env, fetchImpl = fetch) {
15
+ const configuredUrl = env.KIWI_DELIVERY_EVIDENCE_URL?.trim();
16
+ if (!configuredUrl)
17
+ return undefined;
18
+ let endpoint;
19
+ try {
20
+ endpoint = new URL(configuredUrl);
21
+ }
22
+ catch {
23
+ throw new Error("Invalid delivery evidence gateway URL");
24
+ }
25
+ const token = env.KIWI_DELIVERY_EVIDENCE_TOKEN?.trim();
26
+ if (endpoint.protocol !== "https:" || endpoint.username || endpoint.password ||
27
+ endpoint.search || endpoint.hash || !token) {
28
+ throw new Error("Delivery evidence gateway requires an HTTPS endpoint and a service token");
29
+ }
30
+ return async (record) => {
31
+ if (record.started_at === undefined)
32
+ return undefined;
33
+ const url = new URL(endpoint);
34
+ const digest = deliveryAttemptDigest(record);
35
+ url.searchParams.set("attempt_digest", digest);
36
+ url.searchParams.set("merchant_id", record.merchant_id);
37
+ url.searchParams.set("delivery_id", record.delivery_id);
38
+ url.searchParams.set("attempt", String(record.attempts ?? 0));
39
+ url.searchParams.set("started_at", record.started_at);
40
+ url.searchParams.set("channel", record.channel);
41
+ if (record.provider_request_id !== undefined) {
42
+ url.searchParams.set("provider_request_id", record.provider_request_id);
43
+ }
44
+ try {
45
+ const response = await fetchImpl(url, {
46
+ headers: { accept: "application/json", authorization: `Bearer ${token}` },
47
+ redirect: "error",
48
+ signal: AbortSignal.timeout(3000),
49
+ });
50
+ if (!response.ok)
51
+ return undefined;
52
+ const body = await response.json();
53
+ if (body?.attempt_digest !== digest || typeof body.evidence_ref !== "string" ||
54
+ !/^[A-Za-z0-9_.:/-]{1,180}$/.test(body.evidence_ref))
55
+ return undefined;
56
+ if (body.outcome === "not_sent" && body.future_execution_blocked === true) {
57
+ return { outcome: "not_sent", evidence_ref: body.evidence_ref, future_execution_blocked: true };
58
+ }
59
+ if (body.outcome === "accepted" && typeof body.accepted_at === "string" &&
60
+ Number.isFinite(Date.parse(body.accepted_at))) {
61
+ return { outcome: "accepted", evidence_ref: body.evidence_ref, accepted_at: new Date(body.accepted_at).toISOString() };
62
+ }
63
+ }
64
+ catch {
65
+ // A transport or evidence error must not settle or resend the delivery.
66
+ }
67
+ return undefined;
68
+ };
69
+ }
70
+ //# sourceMappingURL=reconciliation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconciliation.js","sourceRoot":"","sources":["../../../src/merchant-core/customer-delivery/reconciliation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAOzD,MAAM,UAAU,qBAAqB,CAAC,MAAsB;IAC1D,OAAO,aAAa,CA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AY,CAAC;gBAAE,OAAO,SAAS,CAAC;YAC3E,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,IAAI,IAAI,CAAC,wBAAwB,KAAK,IAAI,EAAE,CAAC;gBAC1E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,wBAAwB,EAAE,IAAI,EAAE,CAAC;YAClG,CAAC;YACD,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,IAAI,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ;gBACnE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;gBAClD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;YACzH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,wEAAwE;QAC1E,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,55 @@
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
+ * P1 客户通知的持久化(设计 §16.3 / M6-2)。
18
+ *
19
+ * 唯一发送真相是 `followup_outbox`:本模块只把已冻结的 DeliveryRecord 映射
20
+ * 到该表,不另建第二份队列表。领取/回执通过 `inImmediateTransaction` 与
21
+ * dispatcher 组合,保证同一 stream 的单流在途约束。
22
+ */
23
+ import { type DeliveryEvidence } from "./reconciliation.js";
24
+ import type { DatabaseSync } from "node:sqlite";
25
+ import { type DeliveryStatus } from "./types.js";
26
+ import type { DeliveryRecord, DeliveryStore } from "./dispatcher.js";
27
+ export declare class CustomerDeliveryRepository implements DeliveryStore {
28
+ private readonly db;
29
+ private readonly now;
30
+ constructor(options: {
31
+ db: DatabaseSync;
32
+ now: () => string;
33
+ });
34
+ /** 插入已冻结的 PENDING 通知;delivery_id 即 outbox_id。 */
35
+ insert(record: DeliveryRecord, taskId: string): void;
36
+ get(merchantId: string, deliveryId: string): DeliveryRecord | undefined;
37
+ findBlocking(merchantId: string, streamKey: string, deliveryId: string): DeliveryRecord | undefined;
38
+ save(record: DeliveryRecord): void;
39
+ /** A vanished worker may have reached the channel before recording the result. */
40
+ recoverExpiredClaims(merchantId: string, now: string): number;
41
+ /** Settle only the exact attempt inspected by the trusted evidence source. */
42
+ reconcileUnknown(snapshot: DeliveryRecord, evidence: DeliveryEvidence): boolean;
43
+ listReconciliationAudit(merchantId: string): Record<string, unknown>[];
44
+ /** dispatcher 扫描:PENDING、未过期、尚未领取、已过重试退避。 */
45
+ listDue(merchantId: string, now: string, limit?: number): DeliveryRecord[];
46
+ /** 当日(UTC 日)同一订阅已 accepted 的发送数;频控复核用。 */
47
+ countSentToday(merchantId: string, subscriptionId: string, now: string): number;
48
+ countUnknown(merchantId: string): number;
49
+ /** 运营核对:列出指定状态的投递记录(默认 UNKNOWN)。 */
50
+ listByStatus(merchantId: string, status: DeliveryStatus, limit?: number, offset?: number): DeliveryRecord[];
51
+ /** 在 IMMEDIATE 事务内执行领取/回执组合,确保单流约束与写入原子。 */
52
+ inTransaction<T>(fn: () => T): T;
53
+ /** DeliveryStore.transaction:dispatcher 在领取时使用。 */
54
+ transaction<T>(fn: () => T): T;
55
+ }