@harrylabsj/kiwi 0.12.30 → 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 (330) hide show
  1. package/dist/a2a/node.d.ts +1 -0
  2. package/dist/a2a/node.js +170 -2
  3. package/dist/a2a/node.js.map +1 -1
  4. package/dist/a2a/reception/agent-runtime.d.ts +32 -1
  5. package/dist/a2a/reception/agent-runtime.js +420 -11
  6. package/dist/a2a/reception/agent-runtime.js.map +1 -1
  7. package/dist/a2a/reception/customer-memory-tools.d.ts +73 -0
  8. package/dist/a2a/reception/customer-memory-tools.js +17 -0
  9. package/dist/a2a/reception/customer-memory-tools.js.map +1 -0
  10. package/dist/a2a/reception/engine.d.ts +12 -0
  11. package/dist/a2a/reception/engine.js +42 -1
  12. package/dist/a2a/reception/engine.js.map +1 -1
  13. package/dist/a2a/reception/publish.d.ts +14 -1
  14. package/dist/a2a/reception/publish.js +62 -1
  15. package/dist/a2a/reception/publish.js.map +1 -1
  16. package/dist/a2a/reception/question-spec.d.ts +91 -0
  17. package/dist/a2a/reception/question-spec.js +260 -0
  18. package/dist/a2a/reception/question-spec.js.map +1 -0
  19. package/dist/a2a/reception/reply-outbox.d.ts +6 -0
  20. package/dist/a2a/reception/reply-outbox.js +44 -0
  21. package/dist/a2a/reception/reply-outbox.js.map +1 -1
  22. package/dist/a2a/reception/responder.d.ts +13 -1
  23. package/dist/a2a/reception/responder.js +26 -3
  24. package/dist/a2a/reception/responder.js.map +1 -1
  25. package/dist/a2a/reception/skill-catalog.d.ts +72 -0
  26. package/dist/a2a/reception/skill-catalog.js +85 -0
  27. package/dist/a2a/reception/skill-catalog.js.map +1 -0
  28. package/dist/a2a/reception/skill-contract.d.ts +70 -0
  29. package/dist/a2a/reception/skill-contract.js +183 -0
  30. package/dist/a2a/reception/skill-contract.js.map +1 -0
  31. package/dist/a2a/reception/types.d.ts +12 -0
  32. package/dist/a2a/server/customer-identity-gateway.d.ts +111 -0
  33. package/dist/a2a/server/customer-identity-gateway.js +441 -0
  34. package/dist/a2a/server/customer-identity-gateway.js.map +1 -0
  35. package/dist/a2a/server/merchant-handler.d.ts +56 -1
  36. package/dist/a2a/server/merchant-handler.js +659 -44
  37. package/dist/a2a/server/merchant-handler.js.map +1 -1
  38. package/dist/a2a/server/pipeline.js +74 -29
  39. package/dist/a2a/server/pipeline.js.map +1 -1
  40. package/dist/a2a/server/types.d.ts +2 -0
  41. package/dist/a2a/unit-alias.d.ts +3 -3
  42. package/dist/a2a/unit-alias.js +9 -5
  43. package/dist/a2a/unit-alias.js.map +1 -1
  44. package/dist/agent/buyer/buyer-tools.js +1 -2
  45. package/dist/agent/buyer/buyer-tools.js.map +1 -1
  46. package/dist/agent/buyer/search-loop.js +0 -1
  47. package/dist/agent/buyer/search-loop.js.map +1 -1
  48. package/dist/auth/merchant-sessions.d.ts +3 -0
  49. package/dist/auth/merchant-sessions.js +21 -5
  50. package/dist/auth/merchant-sessions.js.map +1 -1
  51. package/dist/buyer-core/a2a-knp.d.ts +4 -2
  52. package/dist/buyer-core/a2a-knp.js +5 -2
  53. package/dist/buyer-core/a2a-knp.js.map +1 -1
  54. package/dist/buyer-core/a2a-negotiator.d.ts +1 -0
  55. package/dist/buyer-core/a2a-negotiator.js +18 -11
  56. package/dist/buyer-core/a2a-negotiator.js.map +1 -1
  57. package/dist/buyer-core/a2a-quote-fetcher.d.ts +25 -0
  58. package/dist/buyer-core/a2a-quote-fetcher.js +82 -4
  59. package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
  60. package/dist/buyer-core/a2a-quote-history.d.ts +94 -0
  61. package/dist/buyer-core/a2a-quote-history.js +149 -0
  62. package/dist/buyer-core/a2a-quote-history.js.map +1 -0
  63. package/dist/buyer-core/build-service.d.ts +19 -0
  64. package/dist/buyer-core/build-service.js +30 -1
  65. package/dist/buyer-core/build-service.js.map +1 -1
  66. package/dist/buyer-core/errors.d.ts +1 -1
  67. package/dist/buyer-core/errors.js +1 -0
  68. package/dist/buyer-core/errors.js.map +1 -1
  69. package/dist/buyer-core/merchant-index.js +0 -1
  70. package/dist/buyer-core/merchant-index.js.map +1 -1
  71. package/dist/buyer-core/open-inquiry-signer.d.ts +1 -0
  72. package/dist/buyer-core/open-inquiry-signer.js +5 -2
  73. package/dist/buyer-core/open-inquiry-signer.js.map +1 -1
  74. package/dist/buyer-core/protocol-recovery.d.ts +2 -1
  75. package/dist/buyer-core/protocol-recovery.js +14 -4
  76. package/dist/buyer-core/protocol-recovery.js.map +1 -1
  77. package/dist/buyer-core/service.d.ts +58 -5
  78. package/dist/buyer-core/service.js +279 -53
  79. package/dist/buyer-core/service.js.map +1 -1
  80. package/dist/buyer-core/store.d.ts +8 -0
  81. package/dist/buyer-core/store.js +37 -7
  82. package/dist/buyer-core/store.js.map +1 -1
  83. package/dist/cli.js +136 -34
  84. package/dist/cli.js.map +1 -1
  85. package/dist/cloud/bootstrap.d.ts +1 -1
  86. package/dist/cloud/bootstrap.js +162 -35
  87. package/dist/cloud/bootstrap.js.map +1 -1
  88. package/dist/cloud/product-import-tabular.js +13 -5
  89. package/dist/cloud/product-import-tabular.js.map +1 -1
  90. package/dist/cloud/trade-platforms-client.d.ts +30 -0
  91. package/dist/cloud/trade-platforms-client.js +34 -1
  92. package/dist/cloud/trade-platforms-client.js.map +1 -1
  93. package/dist/commerce/receipt/dispatcher.d.ts +42 -0
  94. package/dist/commerce/receipt/dispatcher.js +68 -0
  95. package/dist/commerce/receipt/dispatcher.js.map +1 -0
  96. package/dist/commerce/receipt/receipts.d.ts +140 -0
  97. package/dist/commerce/receipt/receipts.js +247 -0
  98. package/dist/commerce/receipt/receipts.js.map +1 -0
  99. package/dist/config/profile.d.ts +2 -2
  100. package/dist/handoff/order-receipts.d.ts +62 -0
  101. package/dist/handoff/order-receipts.js +71 -0
  102. package/dist/handoff/order-receipts.js.map +1 -0
  103. package/dist/handoff/trade-platform-rules.js +5 -2
  104. package/dist/handoff/trade-platform-rules.js.map +1 -1
  105. package/dist/handoff/ucp-checkout/cart-channel.d.ts +2 -1
  106. package/dist/handoff/ucp-checkout/cart-channel.js +1 -0
  107. package/dist/handoff/ucp-checkout/cart-channel.js.map +1 -1
  108. package/dist/handoff/ucp-checkout/channel.d.ts +6 -0
  109. package/dist/handoff/ucp-checkout/channel.js +44 -0
  110. package/dist/handoff/ucp-checkout/channel.js.map +1 -1
  111. package/dist/http/cli.js +6 -0
  112. package/dist/http/cli.js.map +1 -1
  113. package/dist/http/merchant-management/api.d.ts +11 -1
  114. package/dist/http/merchant-management/api.js +471 -3
  115. package/dist/http/merchant-management/api.js.map +1 -1
  116. package/dist/http/merchant-management/draft-store.js +8 -6
  117. package/dist/http/merchant-management/draft-store.js.map +1 -1
  118. package/dist/http/merchant-management/page.js +83 -22
  119. package/dist/http/merchant-management/page.js.map +1 -1
  120. package/dist/mcp/cli.js +6 -0
  121. package/dist/mcp/cli.js.map +1 -1
  122. package/dist/mcp/merchant-runtime-assembly.d.ts +20 -0
  123. package/dist/mcp/merchant-runtime-assembly.js +93 -3
  124. package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
  125. package/dist/mcp/merchant-server.d.ts +5 -0
  126. package/dist/mcp/merchant-server.js +12 -0
  127. package/dist/mcp/merchant-server.js.map +1 -1
  128. package/dist/mcp/tools.js +12 -3
  129. package/dist/mcp/tools.js.map +1 -1
  130. package/dist/merchant/application/actor.d.ts +1 -1
  131. package/dist/merchant/application/actor.js +15 -0
  132. package/dist/merchant/application/actor.js.map +1 -1
  133. package/dist/merchant/workbench-server.d.ts +38 -0
  134. package/dist/merchant/workbench-server.js +428 -0
  135. package/dist/merchant/workbench-server.js.map +1 -0
  136. package/dist/merchant-core/budget/background-budget.d.ts +132 -0
  137. package/dist/merchant-core/budget/background-budget.js +308 -0
  138. package/dist/merchant-core/budget/background-budget.js.map +1 -0
  139. package/dist/merchant-core/context-governance/actor-context.d.ts +56 -0
  140. package/dist/merchant-core/context-governance/actor-context.js +76 -0
  141. package/dist/merchant-core/context-governance/actor-context.js.map +1 -0
  142. package/dist/merchant-core/context-governance/authority.d.ts +39 -0
  143. package/dist/merchant-core/context-governance/authority.js +28 -0
  144. package/dist/merchant-core/context-governance/authority.js.map +1 -0
  145. package/dist/merchant-core/context-governance/context-guard.d.ts +104 -0
  146. package/dist/merchant-core/context-governance/context-guard.js +194 -0
  147. package/dist/merchant-core/context-governance/context-guard.js.map +1 -0
  148. package/dist/merchant-core/context-governance/data-use-grant.d.ts +91 -0
  149. package/dist/merchant-core/context-governance/data-use-grant.js +211 -0
  150. package/dist/merchant-core/context-governance/data-use-grant.js.map +1 -0
  151. package/dist/merchant-core/context-governance/feature-flags.d.ts +32 -0
  152. package/dist/merchant-core/context-governance/feature-flags.js +83 -0
  153. package/dist/merchant-core/context-governance/feature-flags.js.map +1 -0
  154. package/dist/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
  155. package/dist/merchant-core/context-governance/pilot-readiness.js +141 -0
  156. package/dist/merchant-core/context-governance/pilot-readiness.js.map +1 -0
  157. package/dist/merchant-core/context-governance/source-governance.d.ts +157 -0
  158. package/dist/merchant-core/context-governance/source-governance.js +492 -0
  159. package/dist/merchant-core/context-governance/source-governance.js.map +1 -0
  160. package/dist/merchant-core/context-governance/types.d.ts +62 -0
  161. package/dist/merchant-core/context-governance/types.js +92 -0
  162. package/dist/merchant-core/context-governance/types.js.map +1 -0
  163. package/dist/merchant-core/customer-delivery/binding.d.ts +55 -0
  164. package/dist/merchant-core/customer-delivery/binding.js +121 -0
  165. package/dist/merchant-core/customer-delivery/binding.js.map +1 -0
  166. package/dist/merchant-core/customer-delivery/channel.d.ts +75 -0
  167. package/dist/merchant-core/customer-delivery/channel.js +157 -0
  168. package/dist/merchant-core/customer-delivery/channel.js.map +1 -0
  169. package/dist/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
  170. package/dist/merchant-core/customer-delivery/consent-repository.js +160 -0
  171. package/dist/merchant-core/customer-delivery/consent-repository.js.map +1 -0
  172. package/dist/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
  173. package/dist/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
  174. package/dist/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
  175. package/dist/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
  176. package/dist/merchant-core/customer-delivery/dispatcher.js +166 -0
  177. package/dist/merchant-core/customer-delivery/dispatcher.js.map +1 -0
  178. package/dist/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
  179. package/dist/merchant-core/customer-delivery/email-adapter.js +90 -0
  180. package/dist/merchant-core/customer-delivery/email-adapter.js.map +1 -0
  181. package/dist/merchant-core/customer-delivery/gate.d.ts +37 -0
  182. package/dist/merchant-core/customer-delivery/gate.js +196 -0
  183. package/dist/merchant-core/customer-delivery/gate.js.map +1 -0
  184. package/dist/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
  185. package/dist/merchant-core/customer-delivery/reconciliation.js +70 -0
  186. package/dist/merchant-core/customer-delivery/reconciliation.js.map +1 -0
  187. package/dist/merchant-core/customer-delivery/repository.d.ts +55 -0
  188. package/dist/merchant-core/customer-delivery/repository.js +235 -0
  189. package/dist/merchant-core/customer-delivery/repository.js.map +1 -0
  190. package/dist/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
  191. package/dist/merchant-core/customer-delivery/smtp-adapter.js +183 -0
  192. package/dist/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
  193. package/dist/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
  194. package/dist/merchant-core/customer-delivery/stream-gate.js +123 -0
  195. package/dist/merchant-core/customer-delivery/stream-gate.js.map +1 -0
  196. package/dist/merchant-core/customer-delivery/types.d.ts +103 -0
  197. package/dist/merchant-core/customer-delivery/types.js +32 -0
  198. package/dist/merchant-core/customer-delivery/types.js.map +1 -0
  199. package/dist/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
  200. package/dist/merchant-core/customer-delivery/weixin-adapter.js +56 -0
  201. package/dist/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
  202. package/dist/merchant-core/customer-memory/auto-identity.d.ts +43 -0
  203. package/dist/merchant-core/customer-memory/auto-identity.js +163 -0
  204. package/dist/merchant-core/customer-memory/auto-identity.js.map +1 -0
  205. package/dist/merchant-core/customer-memory/grants.d.ts +72 -0
  206. package/dist/merchant-core/customer-memory/grants.js +224 -0
  207. package/dist/merchant-core/customer-memory/grants.js.map +1 -0
  208. package/dist/merchant-core/customer-memory/history.d.ts +51 -0
  209. package/dist/merchant-core/customer-memory/history.js +252 -0
  210. package/dist/merchant-core/customer-memory/history.js.map +1 -0
  211. package/dist/merchant-core/customer-memory/identity.d.ts +66 -0
  212. package/dist/merchant-core/customer-memory/identity.js +249 -0
  213. package/dist/merchant-core/customer-memory/identity.js.map +1 -0
  214. package/dist/merchant-core/customer-memory/maintenance.d.ts +51 -0
  215. package/dist/merchant-core/customer-memory/maintenance.js +67 -0
  216. package/dist/merchant-core/customer-memory/maintenance.js.map +1 -0
  217. package/dist/merchant-core/customer-memory/memory.d.ts +119 -0
  218. package/dist/merchant-core/customer-memory/memory.js +502 -0
  219. package/dist/merchant-core/customer-memory/memory.js.map +1 -0
  220. package/dist/merchant-core/customer-memory/private-transport.d.ts +10 -0
  221. package/dist/merchant-core/customer-memory/private-transport.js +108 -0
  222. package/dist/merchant-core/customer-memory/private-transport.js.map +1 -0
  223. package/dist/merchant-core/customer-memory/quote-history.d.ts +160 -0
  224. package/dist/merchant-core/customer-memory/quote-history.js +392 -0
  225. package/dist/merchant-core/customer-memory/quote-history.js.map +1 -0
  226. package/dist/merchant-core/customer-memory/reception-provider.d.ts +69 -0
  227. package/dist/merchant-core/customer-memory/reception-provider.js +250 -0
  228. package/dist/merchant-core/customer-memory/reception-provider.js.map +1 -0
  229. package/dist/merchant-core/customer-memory/reception-writer.d.ts +19 -0
  230. package/dist/merchant-core/customer-memory/reception-writer.js +32 -0
  231. package/dist/merchant-core/customer-memory/reception-writer.js.map +1 -0
  232. package/dist/merchant-core/customer-memory/types.d.ts +111 -0
  233. package/dist/merchant-core/customer-memory/types.js +58 -0
  234. package/dist/merchant-core/customer-memory/types.js.map +1 -0
  235. package/dist/merchant-core/followup/repository.d.ts +2 -1
  236. package/dist/merchant-core/followup/repository.js +29 -23
  237. package/dist/merchant-core/followup/repository.js.map +1 -1
  238. package/dist/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
  239. package/dist/merchant-core/learning/evaluation-fixtures.js +83 -0
  240. package/dist/merchant-core/learning/evaluation-fixtures.js.map +1 -0
  241. package/dist/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
  242. package/dist/merchant-core/learning/evaluation-suite-v1.js +129 -0
  243. package/dist/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
  244. package/dist/merchant-core/learning/evaluation.d.ts +84 -0
  245. package/dist/merchant-core/learning/evaluation.js +581 -0
  246. package/dist/merchant-core/learning/evaluation.js.map +1 -0
  247. package/dist/merchant-core/learning/initial-skills.d.ts +36 -0
  248. package/dist/merchant-core/learning/initial-skills.js +67 -0
  249. package/dist/merchant-core/learning/initial-skills.js.map +1 -0
  250. package/dist/merchant-core/learning/precheck.d.ts +33 -0
  251. package/dist/merchant-core/learning/precheck.js +56 -0
  252. package/dist/merchant-core/learning/precheck.js.map +1 -0
  253. package/dist/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
  254. package/dist/merchant-core/learning/real-evaluation-runner.js +167 -0
  255. package/dist/merchant-core/learning/real-evaluation-runner.js.map +1 -0
  256. package/dist/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
  257. package/dist/merchant-core/learning/reception-skill-catalog.js +145 -0
  258. package/dist/merchant-core/learning/reception-skill-catalog.js.map +1 -0
  259. package/dist/merchant-core/learning/recovery-gateway.d.ts +27 -0
  260. package/dist/merchant-core/learning/recovery-gateway.js +106 -0
  261. package/dist/merchant-core/learning/recovery-gateway.js.map +1 -0
  262. package/dist/merchant-core/learning/repository.d.ts +130 -0
  263. package/dist/merchant-core/learning/repository.js +588 -0
  264. package/dist/merchant-core/learning/repository.js.map +1 -0
  265. package/dist/merchant-core/learning/service.d.ts +262 -0
  266. package/dist/merchant-core/learning/service.js +1498 -0
  267. package/dist/merchant-core/learning/service.js.map +1 -0
  268. package/dist/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
  269. package/dist/merchant-core/learning/test-dispatch-gateway.js +145 -0
  270. package/dist/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
  271. package/dist/merchant-core/learning/types.d.ts +217 -0
  272. package/dist/merchant-core/learning/types.js +52 -0
  273. package/dist/merchant-core/learning/types.js.map +1 -0
  274. package/dist/merchant-core/migrations/ledgers.d.ts +40 -0
  275. package/dist/merchant-core/migrations/ledgers.js +824 -0
  276. package/dist/merchant-core/migrations/ledgers.js.map +1 -0
  277. package/dist/merchant-core/migrations/runner.d.ts +55 -0
  278. package/dist/merchant-core/migrations/runner.js +114 -0
  279. package/dist/merchant-core/migrations/runner.js.map +1 -0
  280. package/dist/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
  281. package/dist/merchant-core/operations-jobs/advice-runner.js +199 -0
  282. package/dist/merchant-core/operations-jobs/advice-runner.js.map +1 -0
  283. package/dist/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
  284. package/dist/merchant-core/operations-jobs/pilot-evidence.js +109 -0
  285. package/dist/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
  286. package/dist/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
  287. package/dist/merchant-core/operations-jobs/pilot-metrics.js +98 -0
  288. package/dist/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
  289. package/dist/merchant-core/operations-jobs/projection.d.ts +41 -0
  290. package/dist/merchant-core/operations-jobs/projection.js +158 -0
  291. package/dist/merchant-core/operations-jobs/projection.js.map +1 -0
  292. package/dist/merchant-core/operations-jobs/scheduler.d.ts +68 -0
  293. package/dist/merchant-core/operations-jobs/scheduler.js +233 -0
  294. package/dist/merchant-core/operations-jobs/scheduler.js.map +1 -0
  295. package/dist/merchant-core/operations-jobs/service.d.ts +260 -0
  296. package/dist/merchant-core/operations-jobs/service.js +922 -0
  297. package/dist/merchant-core/operations-jobs/service.js.map +1 -0
  298. package/dist/merchant-core/ops/facade.d.ts +10 -0
  299. package/dist/merchant-core/ops/facade.js +52 -0
  300. package/dist/merchant-core/ops/facade.js.map +1 -1
  301. package/dist/merchant-core/ops/schema.d.ts +1 -1
  302. package/dist/merchant-core/ops/schema.js +119 -2
  303. package/dist/merchant-core/ops/schema.js.map +1 -1
  304. package/dist/merchant-core/ops/surface.d.ts +37 -0
  305. package/dist/merchant-core/ops/surface.js +240 -0
  306. package/dist/merchant-core/ops/surface.js.map +1 -1
  307. package/dist/merchant-core/ownership/instance-ownership.d.ts +122 -0
  308. package/dist/merchant-core/ownership/instance-ownership.js +236 -0
  309. package/dist/merchant-core/ownership/instance-ownership.js.map +1 -0
  310. package/dist/merchant-core/ownership/runtime.d.ts +175 -0
  311. package/dist/merchant-core/ownership/runtime.js +422 -0
  312. package/dist/merchant-core/ownership/runtime.js.map +1 -0
  313. package/dist/merchant-core/storage/transaction.d.ts +102 -7
  314. package/dist/merchant-core/storage/transaction.js +274 -3
  315. package/dist/merchant-core/storage/transaction.js.map +1 -1
  316. package/dist/merchant-credential-rotation.d.ts +4 -1
  317. package/dist/merchant-credential-rotation.js +12 -8
  318. package/dist/merchant-credential-rotation.js.map +1 -1
  319. package/dist/merchant-gateway/catalog-tools.js +4 -2
  320. package/dist/merchant-gateway/catalog-tools.js.map +1 -1
  321. package/dist/merchant-runtime/manager.d.ts +2 -0
  322. package/dist/merchant-runtime/manager.js +5 -0
  323. package/dist/merchant-runtime/manager.js.map +1 -1
  324. package/dist/product-buyer.d.ts +1 -0
  325. package/dist/product-buyer.js +0 -1
  326. package/dist/product-buyer.js.map +1 -1
  327. package/dist/product-cli.js +11 -1
  328. package/dist/product-cli.js.map +1 -1
  329. package/package.json +5 -3
  330. package/skills/kiwi-buyer/SKILL.md +1 -1
@@ -64,6 +64,10 @@ import { OperatingPlanError } from "../../merchant-core/operating/types.js";
64
64
  import { OpportunityError } from "../../merchant-core/opportunity/types.js";
65
65
  import { ProposalError } from "../../merchant-core/proposal/types.js";
66
66
  import { FollowUpError } from "../../merchant-core/followup/types.js";
67
+ import { GovernanceRuntimeError } from "../../merchant-core/ownership/runtime.js";
68
+ import { InstanceOwnershipError } from "../../merchant-core/ownership/instance-ownership.js";
69
+ import { LearningError } from "../../merchant-core/learning/types.js";
70
+ import { OperationsJobsError } from "../../merchant-core/operations-jobs/service.js";
67
71
  import { parseExactMoney, WorkbenchMoneyError, WORKBENCH_CURRENCY_TABLE_VERSION, } from "../../merchant/application/money.js";
68
72
  import { CONNECTION_PAIRING_SAFE_CODES } from "../../cloud/connect-service.js";
69
73
  import { EXACT_PRODUCT_TOOLS } from "../../merchant/exact-product-executors.js";
@@ -113,6 +117,32 @@ async function resolvePlatformRules(options) {
113
117
  return normalizeTradePlatformRules(undefined);
114
118
  }
115
119
  }
120
+ function deliveryField(body, key) {
121
+ const value = body[key];
122
+ if (typeof value !== "string" || value.trim() === "") {
123
+ throw new ManagementError("invalid_input", `${key} must be a non-empty string`);
124
+ }
125
+ return value;
126
+ }
127
+ function deliveryNumber(body, key) {
128
+ const value = body[key];
129
+ if (!Number.isSafeInteger(value)) {
130
+ throw new ManagementError("invalid_input", `${key} must be an integer`);
131
+ }
132
+ return value;
133
+ }
134
+ function deliveryCall(work) {
135
+ try {
136
+ return work();
137
+ }
138
+ catch (err) {
139
+ const code = err?.code;
140
+ if (typeof code === "string" && code !== "") {
141
+ throw new ManagementError("invalid_input", err instanceof Error ? err.message : code);
142
+ }
143
+ throw err;
144
+ }
145
+ }
116
146
  export function createMerchantManagementApiHandler(options) {
117
147
  const log = options.log ??
118
148
  ((line) => {
@@ -180,6 +210,11 @@ export function createMerchantManagementApiHandler(options) {
180
210
  writeJson(res, 404, errorBody("not_found", "unknown management api path"));
181
211
  return;
182
212
  }
213
+ if (pathname === `${API_PREFIX}/internal/customer-identity` && method === "POST") {
214
+ const result = await options.receiveCustomerIdentity?.(req.headers["x-kiwi-identity-channel-token"], () => readJsonBody(req));
215
+ writeJson(res, result?.status ?? 404, result?.body ?? { ok: false });
216
+ return;
217
+ }
183
218
  if (pathname === WORKBENCH_API_PREFIX || pathname.startsWith(`${WORKBENCH_API_PREFIX}/`)) {
184
219
  const requestId = `req_${randomBytes(12).toString("hex")}`;
185
220
  const rest = pathname === WORKBENCH_API_PREFIX ? "/" : pathname.slice(WORKBENCH_API_PREFIX.length);
@@ -229,7 +264,56 @@ export function createMerchantManagementApiHandler(options) {
229
264
  }
230
265
  // ── 只读路由(认证即鉴权入口;业务授权在服务层逐次复核)────────────────
231
266
  /** Workbench v1 读取面复用同一应用服务;未实现路由明确失败,不返回假数据。 */
267
+ function governanceRouteDisabled(rest) {
268
+ if (rest.startsWith("/learning/"))
269
+ return options.governance?.flags.learning_enabled !== true;
270
+ if (rest.startsWith("/automation/"))
271
+ return options.governance?.flags.jobs_enabled !== true;
272
+ return false;
273
+ }
274
+ function writeGoverned(work) {
275
+ if (options.governance === undefined) {
276
+ throw new ManagementError("conflict", "governance runtime is not initialized");
277
+ }
278
+ try {
279
+ return options.governance.write(work);
280
+ }
281
+ catch (error) {
282
+ if (error instanceof GovernanceRuntimeError || error instanceof InstanceOwnershipError) {
283
+ throw new ManagementError("conflict", "governance ownership is not held by this process");
284
+ }
285
+ throw error;
286
+ }
287
+ }
232
288
  async function routeWorkbenchV1Get(req, res, url, rest, requestId) {
289
+ if (governanceRouteDisabled(rest)) {
290
+ writeWorkbenchProblem(res, "RESOURCE_NOT_FOUND", requestId, "资源不存在", "Workbench API 路由不存在或尚未实现。");
291
+ return;
292
+ }
293
+ if (options.customerDeliveries !== undefined && rest === "/delivery/unknown") {
294
+ const auth = requireActor(req);
295
+ authorizeOrThrow(auth.ctx, "followups:read");
296
+ writeJson(res, 200, {
297
+ deliveries: options.customerDeliveries.listByStatus(auth.ctx.merchantId, "UNKNOWN"),
298
+ reconciliation_audit: options.customerDeliveries.listReconciliationAudit(auth.ctx.merchantId),
299
+ }, { "x-request-id": requestId });
300
+ return;
301
+ }
302
+ if (options.deliveryConsent !== undefined && rest.startsWith("/delivery/")) {
303
+ const auth = requireActor(req);
304
+ authorizeOrThrow(auth.ctx, "followups:read");
305
+ if (rest === "/delivery/bindings") {
306
+ writeJson(res, 200, { bindings: options.deliveryConsent.listBindings(auth.ctx.merchantId) }, { "x-request-id": requestId });
307
+ return;
308
+ }
309
+ if (rest === "/delivery/subscriptions") {
310
+ const bindingId = url.searchParams.get("binding_id") ?? undefined;
311
+ writeJson(res, 200, {
312
+ subscriptions: options.deliveryConsent.listSubscriptions(auth.ctx.merchantId, bindingId),
313
+ }, { "x-request-id": requestId });
314
+ return;
315
+ }
316
+ }
233
317
  if (rest === "/products/publication-status") {
234
318
  const auth = requireActor(req);
235
319
  authorizeOrThrow(auth.ctx, "products:import");
@@ -381,7 +465,10 @@ export function createMerchantManagementApiHandler(options) {
381
465
  // Workbench 页面(v1)与旧 v0 页面读取同一份脱敏策略投影;
382
466
  // 此前 v1 缺少该路由,商家后台「报价规则」报 API 路由不存在。
383
467
  const auth = requireActor(req);
384
- writeJson(res, 200, await readService.getPolicy(auth.ctx), { "x-request-id": requestId });
468
+ writeJson(res, 200, {
469
+ ...await readService.getPolicy(auth.ctx),
470
+ ...policyWorkbenchSummary(options.policyCurrent?.()),
471
+ }, { "x-request-id": requestId });
385
472
  return;
386
473
  }
387
474
  if (rest === "/runtime/status") {
@@ -707,10 +794,180 @@ export function createMerchantManagementApiHandler(options) {
707
794
  writeJson(res, 200, { orders: ops.listOrders() }, { "x-request-id": requestId });
708
795
  return;
709
796
  }
797
+ if (rest === "/learning/corrections") {
798
+ const auth = requireActor(req);
799
+ authorizeOrThrow(auth.ctx, "learning:read");
800
+ writeJson(res, 200, { corrections: ops.listCorrections() }, { "x-request-id": requestId });
801
+ return;
802
+ }
803
+ const recoveryMatch = /^\/learning\/evaluations\/([^/]+)\/recovery$/.exec(rest);
804
+ if (recoveryMatch !== null) {
805
+ const auth = requireActor(req);
806
+ authorizeOrThrow(auth.ctx, "learning:review");
807
+ writeJson(res, 200, ops.getEvaluationRecovery(pathSegment(recoveryMatch[1] ?? ""), {
808
+ actor_id: auth.ctx.actorId, merchant_id: auth.ctx.merchantId, auth_method: auth.ctx.authMethod, permissions: [...auth.ctx.permissions],
809
+ }), { "x-request-id": requestId });
810
+ return;
811
+ }
812
+ const correctionMatch = /^\/learning\/corrections\/([^/]+)$/.exec(rest);
813
+ if (correctionMatch !== null) {
814
+ const auth = requireActor(req);
815
+ authorizeOrThrow(auth.ctx, "learning:read");
816
+ writeJson(res, 200, ops.getCorrection(pathSegment(correctionMatch[1] ?? "")), {
817
+ "x-request-id": requestId,
818
+ });
819
+ return;
820
+ }
821
+ if (rest === "/learning/candidates") {
822
+ const auth = requireActor(req);
823
+ authorizeOrThrow(auth.ctx, "learning:read");
824
+ writeJson(res, 200, { candidates: ops.listCandidates() }, { "x-request-id": requestId });
825
+ return;
826
+ }
827
+ const candidateMatch = /^\/learning\/candidates\/([^/]+)$/.exec(rest);
828
+ if (candidateMatch !== null) {
829
+ const auth = requireActor(req);
830
+ authorizeOrThrow(auth.ctx, "learning:read");
831
+ writeJson(res, 200, ops.getCandidate(pathSegment(candidateMatch[1] ?? "")), {
832
+ "x-request-id": requestId,
833
+ });
834
+ return;
835
+ }
836
+ if (rest === "/learning/reviews") {
837
+ const auth = requireActor(req);
838
+ authorizeOrThrow(auth.ctx, "learning:read");
839
+ writeJson(res, 200, { reviews: ops.listReviews() }, { "x-request-id": requestId });
840
+ return;
841
+ }
842
+ const reviewMatch = /^\/learning\/reviews\/([^/]+)$/.exec(rest);
843
+ if (reviewMatch !== null) {
844
+ const auth = requireActor(req);
845
+ authorizeOrThrow(auth.ctx, "learning:read");
846
+ writeJson(res, 200, ops.getReview(pathSegment(reviewMatch[1] ?? "")), {
847
+ "x-request-id": requestId,
848
+ });
849
+ return;
850
+ }
851
+ if (rest === "/learning/releases/active") {
852
+ const auth = requireActor(req);
853
+ authorizeOrThrow(auth.ctx, "learning:read");
854
+ const skillKey = url.searchParams.get("skill_key");
855
+ if (skillKey === null || skillKey.trim() === "") {
856
+ throw new ManagementError("invalid_input", "skill_key query parameter is required");
857
+ }
858
+ writeJson(res, 200, ops.getActiveRelease(skillKey));
859
+ return;
860
+ }
861
+ if (rest === "/learning/releases") {
862
+ const auth = requireActor(req);
863
+ authorizeOrThrow(auth.ctx, "learning:read");
864
+ const skillKey = url.searchParams.get("skill_key") ?? undefined;
865
+ writeJson(res, 200, { releases: ops.listReleases(skillKey) }, {
866
+ "x-request-id": requestId,
867
+ });
868
+ return;
869
+ }
870
+ const releaseMatch = /^\/learning\/releases\/([^/]+)$/.exec(rest);
871
+ if (releaseMatch !== null) {
872
+ const auth = requireActor(req);
873
+ authorizeOrThrow(auth.ctx, "learning:read");
874
+ writeJson(res, 200, ops.getRelease(pathSegment(releaseMatch[1] ?? "")), {
875
+ "x-request-id": requestId,
876
+ });
877
+ return;
878
+ }
879
+ if (rest === "/automation/rules") {
880
+ const auth = requireActor(req);
881
+ authorizeOrThrow(auth.ctx, "followups:read");
882
+ writeJson(res, 200, { rules: ops.listRules() }, { "x-request-id": requestId });
883
+ return;
884
+ }
885
+ const ruleMatch = /^\/automation\/rules\/([^/]+)$/.exec(rest);
886
+ if (ruleMatch !== null) {
887
+ const auth = requireActor(req);
888
+ authorizeOrThrow(auth.ctx, "followups:read");
889
+ writeJson(res, 200, ops.getRule(pathSegment(ruleMatch[1] ?? "")), {
890
+ "x-request-id": requestId,
891
+ });
892
+ return;
893
+ }
894
+ if (rest === "/automation/artifacts") {
895
+ const auth = requireActor(req);
896
+ authorizeOrThrow(auth.ctx, "followups:read");
897
+ const taskId = url.searchParams.get("task_id") ?? undefined;
898
+ writeJson(res, 200, { artifacts: ops.listArtifacts(taskId) }, {
899
+ "x-request-id": requestId,
900
+ });
901
+ return;
902
+ }
710
903
  }
711
904
  writeWorkbenchProblem(res, "RESOURCE_NOT_FOUND", requestId, "资源不存在", "Workbench API 路由不存在或尚未实现。");
712
905
  }
713
906
  async function routeWorkbenchV1Post(req, res, rest, requestId, url) {
907
+ if (governanceRouteDisabled(rest)) {
908
+ writeWorkbenchProblem(res, "RESOURCE_NOT_FOUND", requestId, "资源不存在", "Workbench API 路由不存在或尚未实现。");
909
+ return;
910
+ }
911
+ if (options.deliveryConsent !== undefined && rest.startsWith("/delivery/")) {
912
+ const auth = requireActor(req);
913
+ assertWriteGuards(req, auth.sessionId);
914
+ authorizeOrThrow(auth.ctx, "followups:manage");
915
+ const body = await readJsonBody(req);
916
+ const fields = objectFields(body, [
917
+ "channel",
918
+ "address_ref",
919
+ "proof_ref",
920
+ "expected_epoch",
921
+ "binding_id",
922
+ "purpose",
923
+ "max_per_day",
924
+ "expires_at",
925
+ "consent_evidence_ref",
926
+ "verified_not_executed",
927
+ "channel_idempotent",
928
+ ]);
929
+ const retryMatch = /^\/delivery\/unknown\/([^/]+)\/retry$/.exec(rest);
930
+ if (retryMatch !== null) {
931
+ if (options.customerDeliveries === undefined) {
932
+ writeWorkbenchProblem(res, "RESOURCE_NOT_FOUND", requestId, "资源不存在", "投递记录不可用。");
933
+ return;
934
+ }
935
+ // The deployed SMTP adapter cannot prove non-execution or deduplicate a retry.
936
+ // Keep UNKNOWN available for inspection until a trusted reconciliation adapter exists.
937
+ throw new ManagementError("precondition_changed", "渠道尚未提供可验证的未发送回执,结果未知的通知不能重发");
938
+ }
939
+ if (rest === "/delivery/bindings") {
940
+ writeJson(res, 201, deliveryCall(() => options.deliveryConsent.createBinding({
941
+ merchant_id: auth.ctx.merchantId,
942
+ channel: deliveryField(fields, "channel"),
943
+ address_ref: deliveryField(fields, "address_ref"),
944
+ proof_ref: deliveryField(fields, "proof_ref"),
945
+ })), { "x-request-id": requestId });
946
+ return;
947
+ }
948
+ const revokeBindingMatch = /^\/delivery\/bindings\/([^/]+)\/revoke$/.exec(rest);
949
+ if (revokeBindingMatch !== null) {
950
+ writeJson(res, 200, deliveryCall(() => options.deliveryConsent.revokeBinding(auth.ctx.merchantId, pathSegment(revokeBindingMatch[1] ?? ""), deliveryNumber(fields, "expected_epoch"))), { "x-request-id": requestId });
951
+ return;
952
+ }
953
+ if (rest === "/delivery/subscriptions") {
954
+ const expiresAt = typeof fields["expires_at"] === "string" ? fields["expires_at"] : null;
955
+ writeJson(res, 201, deliveryCall(() => options.deliveryConsent.createSubscription({
956
+ merchant_id: auth.ctx.merchantId,
957
+ binding_id: deliveryField(fields, "binding_id"),
958
+ purpose: deliveryField(fields, "purpose"),
959
+ max_per_day: deliveryNumber(fields, "max_per_day"),
960
+ expires_at: expiresAt,
961
+ consent_evidence_ref: deliveryField(fields, "consent_evidence_ref"),
962
+ })), { "x-request-id": requestId });
963
+ return;
964
+ }
965
+ const unsubscribeMatch = /^\/delivery\/subscriptions\/([^/]+)\/unsubscribe$/.exec(rest);
966
+ if (unsubscribeMatch !== null) {
967
+ writeJson(res, 200, deliveryCall(() => options.deliveryConsent.unsubscribe(auth.ctx.merchantId, pathSegment(unsubscribeMatch[1] ?? ""), deliveryNumber(fields, "expected_epoch"))), { "x-request-id": requestId });
968
+ return;
969
+ }
970
+ }
714
971
  if (options.merchantOperations !== undefined) {
715
972
  const ops = options.merchantOperations;
716
973
  const readOpsBody = async () => {
@@ -856,6 +1113,163 @@ export function createMerchantManagementApiHandler(options) {
856
1113
  writeJson(res, 200, ops.assessOrderContribution(pathSegment(orderContributionMatch[1] ?? ""), body), { "x-request-id": requestId });
857
1114
  return;
858
1115
  }
1116
+ if (rest === "/learning/corrections") {
1117
+ const auth = requireActor(req);
1118
+ assertWriteGuards(req, auth.sessionId);
1119
+ authorizeOrThrow(auth.ctx, "learning:manage");
1120
+ const { body, idempotencyKey } = await readOpsBody();
1121
+ writeJson(res, 201, writeGoverned(() => ops.submitCorrection(body, {
1122
+ actor_id: auth.ctx.actorId,
1123
+ merchant_id: auth.ctx.merchantId,
1124
+ auth_method: auth.ctx.authMethod,
1125
+ permissions: [...auth.ctx.permissions],
1126
+ }, idempotencyKey)), { "x-request-id": requestId });
1127
+ return;
1128
+ }
1129
+ const recoveryMatch = /^\/learning\/evaluations\/([^/]+)\/recovery$/.exec(rest);
1130
+ if (recoveryMatch !== null) {
1131
+ const auth = requireActor(req);
1132
+ assertWriteGuards(req, auth.sessionId);
1133
+ authorizeOrThrow(auth.ctx, "learning:review");
1134
+ const { body } = await readOpsBody();
1135
+ let result;
1136
+ try {
1137
+ result = await ops.resolveEvaluationRecovery(pathSegment(recoveryMatch[1] ?? ""), body, {
1138
+ actor_id: auth.ctx.actorId, merchant_id: auth.ctx.merchantId, auth_method: auth.ctx.authMethod, permissions: [...auth.ctx.permissions],
1139
+ });
1140
+ }
1141
+ catch (error) {
1142
+ if (error instanceof GovernanceRuntimeError || error instanceof InstanceOwnershipError) {
1143
+ throw new ManagementError("conflict", "governance ownership is not held by this process");
1144
+ }
1145
+ throw error;
1146
+ }
1147
+ writeJson(res, 200, result, { "x-request-id": requestId });
1148
+ return;
1149
+ }
1150
+ const promoteCorrectionMatch = /^\/learning\/corrections\/([^/]+)\/promote$/.exec(rest);
1151
+ if (promoteCorrectionMatch !== null) {
1152
+ const auth = requireActor(req);
1153
+ assertWriteGuards(req, auth.sessionId);
1154
+ authorizeOrThrow(auth.ctx, "learning:manage");
1155
+ const { body, idempotencyKey } = await readOpsBody();
1156
+ writeJson(res, 200, writeGoverned(() => ops.promoteCorrection(pathSegment(promoteCorrectionMatch[1] ?? ""), body, {
1157
+ actor_id: auth.ctx.actorId,
1158
+ merchant_id: auth.ctx.merchantId,
1159
+ auth_method: auth.ctx.authMethod,
1160
+ permissions: [...auth.ctx.permissions],
1161
+ }, idempotencyKey)), { "x-request-id": requestId });
1162
+ return;
1163
+ }
1164
+ if (rest === "/learning/candidates") {
1165
+ const auth = requireActor(req);
1166
+ assertWriteGuards(req, auth.sessionId);
1167
+ authorizeOrThrow(auth.ctx, "learning:manage");
1168
+ const { body, idempotencyKey } = await readOpsBody();
1169
+ writeJson(res, 201, writeGoverned(() => ops.proposeCandidate(body, {
1170
+ actor_id: auth.ctx.actorId,
1171
+ merchant_id: auth.ctx.merchantId,
1172
+ auth_method: auth.ctx.authMethod,
1173
+ permissions: [...auth.ctx.permissions],
1174
+ }, idempotencyKey)), { "x-request-id": requestId });
1175
+ return;
1176
+ }
1177
+ const reviseCandidateMatch = /^\/learning\/candidates\/([^/]+)\/revise$/.exec(rest);
1178
+ if (reviseCandidateMatch !== null) {
1179
+ const auth = requireActor(req);
1180
+ assertWriteGuards(req, auth.sessionId);
1181
+ authorizeOrThrow(auth.ctx, "learning:manage");
1182
+ const { body, idempotencyKey } = await readOpsBody();
1183
+ writeJson(res, 200, writeGoverned(() => ops.reviseCandidate(pathSegment(reviseCandidateMatch[1] ?? ""), body, {
1184
+ actor_id: auth.ctx.actorId,
1185
+ merchant_id: auth.ctx.merchantId,
1186
+ auth_method: auth.ctx.authMethod,
1187
+ permissions: [...auth.ctx.permissions],
1188
+ }, idempotencyKey)), { "x-request-id": requestId });
1189
+ return;
1190
+ }
1191
+ const reviewCandidateMatch = /^\/learning\/candidates\/([^/]+)\/review$/.exec(rest);
1192
+ if (reviewCandidateMatch !== null) {
1193
+ const auth = requireActor(req);
1194
+ assertWriteGuards(req, auth.sessionId);
1195
+ authorizeOrThrow(auth.ctx, "learning:review");
1196
+ const { body, idempotencyKey } = await readOpsBody();
1197
+ writeJson(res, 200, writeGoverned(() => ops.reviewCandidate(pathSegment(reviewCandidateMatch[1] ?? ""), body, {
1198
+ actor_id: auth.ctx.actorId,
1199
+ merchant_id: auth.ctx.merchantId,
1200
+ auth_method: auth.ctx.authMethod,
1201
+ permissions: [...auth.ctx.permissions],
1202
+ }, idempotencyKey)), { "x-request-id": requestId });
1203
+ return;
1204
+ }
1205
+ if (rest === "/learning/releases/publish") {
1206
+ const auth = requireActor(req);
1207
+ assertWriteGuards(req, auth.sessionId);
1208
+ authorizeOrThrow(auth.ctx, "learning:publish");
1209
+ const { body, idempotencyKey } = await readOpsBody();
1210
+ writeJson(res, 201, writeGoverned(() => ops.publishRelease(body, {
1211
+ actor_id: auth.ctx.actorId,
1212
+ merchant_id: auth.ctx.merchantId,
1213
+ auth_method: auth.ctx.authMethod,
1214
+ permissions: [...auth.ctx.permissions],
1215
+ }, idempotencyKey)), { "x-request-id": requestId });
1216
+ return;
1217
+ }
1218
+ const rollbackReleaseMatch = /^\/learning\/releases\/([^/]+)\/rollback$/.exec(rest);
1219
+ if (rollbackReleaseMatch !== null) {
1220
+ const auth = requireActor(req);
1221
+ assertWriteGuards(req, auth.sessionId);
1222
+ authorizeOrThrow(auth.ctx, "learning:publish");
1223
+ const { body, idempotencyKey } = await readOpsBody();
1224
+ writeJson(res, 200, writeGoverned(() => ops.rollbackRelease(pathSegment(rollbackReleaseMatch[1] ?? ""), body, {
1225
+ actor_id: auth.ctx.actorId,
1226
+ merchant_id: auth.ctx.merchantId,
1227
+ auth_method: auth.ctx.authMethod,
1228
+ permissions: [...auth.ctx.permissions],
1229
+ }, idempotencyKey)), { "x-request-id": requestId });
1230
+ return;
1231
+ }
1232
+ const revokeReleaseMatch = /^\/learning\/releases\/([^/]+)\/revoke$/.exec(rest);
1233
+ if (revokeReleaseMatch !== null) {
1234
+ const auth = requireActor(req);
1235
+ assertWriteGuards(req, auth.sessionId);
1236
+ authorizeOrThrow(auth.ctx, "learning:publish");
1237
+ const { body, idempotencyKey } = await readOpsBody();
1238
+ writeJson(res, 200, writeGoverned(() => ops.revokeRelease(pathSegment(revokeReleaseMatch[1] ?? ""), body, {
1239
+ actor_id: auth.ctx.actorId,
1240
+ merchant_id: auth.ctx.merchantId,
1241
+ auth_method: auth.ctx.authMethod,
1242
+ permissions: [...auth.ctx.permissions],
1243
+ }, idempotencyKey)), { "x-request-id": requestId });
1244
+ return;
1245
+ }
1246
+ if (rest === "/automation/rules/prepare") {
1247
+ const auth = requireActor(req);
1248
+ assertWriteGuards(req, auth.sessionId);
1249
+ authorizeOrThrow(auth.ctx, "followups:manage");
1250
+ const { body } = await readOpsBody();
1251
+ writeJson(res, 201, writeGoverned(() => ops.prepareRule(body)), { "x-request-id": requestId });
1252
+ return;
1253
+ }
1254
+ if (rest === "/automation/rules/activate") {
1255
+ const auth = requireActor(req);
1256
+ assertWriteGuards(req, auth.sessionId);
1257
+ authorizeOrThrow(auth.ctx, "followups:manage");
1258
+ const { body } = await readOpsBody();
1259
+ writeJson(res, 201, writeGoverned(() => ops.activateRule(body)), { "x-request-id": requestId });
1260
+ return;
1261
+ }
1262
+ const pauseRuleMatch = /^\/automation\/rules\/([^/]+)\/pause$/.exec(rest);
1263
+ if (pauseRuleMatch !== null) {
1264
+ const auth = requireActor(req);
1265
+ assertWriteGuards(req, auth.sessionId);
1266
+ authorizeOrThrow(auth.ctx, "followups:manage");
1267
+ const { body } = await readOpsBody();
1268
+ writeJson(res, 200, writeGoverned(() => ops.pauseRule(pathSegment(pauseRuleMatch[1] ?? ""), body)), {
1269
+ "x-request-id": requestId,
1270
+ });
1271
+ return;
1272
+ }
859
1273
  }
860
1274
  const publicationCommitMatch = /^\/products\/publication-drafts\/(flp_[a-z0-9]+_[0-9a-f]{12})\/commit$/.exec(rest);
861
1275
  if (rest === "/products/publication-drafts" || publicationCommitMatch !== null) {
@@ -2027,7 +2441,10 @@ export function createMerchantManagementApiHandler(options) {
2027
2441
  }
2028
2442
  if (rest === "/policy") {
2029
2443
  const auth = requireActor(req);
2030
- writeJson(res, 200, await readService.getPolicy(auth.ctx));
2444
+ writeJson(res, 200, {
2445
+ ...await readService.getPolicy(auth.ctx),
2446
+ ...policyWorkbenchSummary(options.policyCurrent?.()),
2447
+ });
2031
2448
  return;
2032
2449
  }
2033
2450
  if (rest === "/approvals") {
@@ -2886,7 +3303,8 @@ export function createMerchantManagementApiHandler(options) {
2886
3303
  }
2887
3304
  let table;
2888
3305
  try {
2889
- // 导入预览/提交都用运营最新规则校验平台与链接,不依赖进程启动快照。
3306
+ // 导入预览/提交都用运营规则校验平台与链接;规则来自 TTL 缓存(成功后最多
3307
+ // 30s 陈旧、失败后 10s 不重试),不是进程启动快照,也不保证每次实时。
2890
3308
  const platformRules = await options.marketplacePlatforms?.();
2891
3309
  table = parseProductTable(fields["table"], "request body", platformRules);
2892
3310
  table = await importChannel.prepareTable?.(table) ?? table;
@@ -3078,6 +3496,11 @@ export function createMerchantManagementApiHandler(options) {
3078
3496
  try {
3079
3497
  // 落盘前再刷一次运营规则:运营新增平台后无需重启实例即可提交。
3080
3498
  await options.marketplacePlatforms?.();
3499
+ if (importChannel.currentTable().digest !== (draft.base_digest ?? "")) {
3500
+ operations.release(begun.operationId);
3501
+ respondError(res, new ManagementError("precondition_changed", "product table changed since draft creation"));
3502
+ return;
3503
+ }
3081
3504
  const written = importChannel.commit(table);
3082
3505
  const marked = options.drafts.markCommitted(auth.ctx.merchantId, draftId);
3083
3506
  if (!marked) {
@@ -3614,6 +4037,24 @@ function candidateIdFromPreparation(value) {
3614
4037
  const candidate = requireObject(prepared["candidate"], "prepared candidate.candidate");
3615
4038
  return requireString(candidate["candidate_id"], "prepared candidate.candidate_id");
3616
4039
  }
4040
+ /**
4041
+ * 工作台规则页的安全投影:只回显**公开/可判定**的值与私有值的“是否已设置”,
4042
+ * 不返回底价金额。字段名用页面别名,避免把策略 schema 字段名带进页面壳。
4043
+ */
4044
+ function policyWorkbenchSummary(policy) {
4045
+ if (policy === undefined)
4046
+ return {};
4047
+ return {
4048
+ auto_quote: policy.auto_negotiate !== false,
4049
+ global_floor_configured: policy.min_unit_price_private !== undefined,
4050
+ global_discount: policy.max_auto_discount_percent ?? null,
4051
+ lead_days: policy.delivery_lead_days ?? null,
4052
+ quote_ttl_seconds: policy.quote_ttl_seconds ?? null,
4053
+ human_review: policy.human_review_on ?? [],
4054
+ sku_discounts: policy.sku_max_discount_percent ?? {},
4055
+ sku_floors_configured: Object.keys(policy.price_floors ?? {}),
4056
+ };
4057
+ }
3617
4058
  function exactProductProjection(product) {
3618
4059
  if (product.currency_table_version !== WORKBENCH_CURRENCY_TABLE_VERSION) {
3619
4060
  throw new ManagementError("unavailable", "exact product currency table version does not match Workbench v1");
@@ -3750,6 +4191,33 @@ function respondWorkbenchError(res, error, requestId) {
3750
4191
  writeWorkbenchProblem(res, code, requestId, "经营请求未完成", error instanceof Error ? error.message : "经营请求未完成");
3751
4192
  return;
3752
4193
  }
4194
+ if (error instanceof OperationsJobsError) {
4195
+ const mapping = {
4196
+ validation: "VALIDATION_ERROR",
4197
+ not_found: "RESOURCE_NOT_FOUND",
4198
+ conflict: "VERSION_CONFLICT",
4199
+ version_conflict: "VERSION_CONFLICT",
4200
+ invalid_transition: "VERSION_CONFLICT",
4201
+ budget_exhausted: "RATE_LIMITED",
4202
+ idempotency_conflict: "IDEMPOTENCY_KEY_REUSED",
4203
+ };
4204
+ writeWorkbenchProblem(res, mapping[error.code], requestId, "经营任务请求未完成", error.message);
4205
+ return;
4206
+ }
4207
+ if (error instanceof LearningError) {
4208
+ const mapping = {
4209
+ validation: "VALIDATION_ERROR",
4210
+ sensitive_content: "VALIDATION_ERROR",
4211
+ unsupported_capability: "VALIDATION_ERROR",
4212
+ access_denied: "PERMISSION_REVOKED",
4213
+ not_found: "RESOURCE_NOT_FOUND",
4214
+ version_conflict: "VERSION_CONFLICT",
4215
+ idempotency_conflict: "IDEMPOTENCY_KEY_REUSED",
4216
+ schema_unavailable: "DEPENDENCY_UNAVAILABLE",
4217
+ };
4218
+ writeWorkbenchProblem(res, mapping[error.code], requestId, "学习请求未完成", error.message);
4219
+ return;
4220
+ }
3753
4221
  if (error instanceof WorkbenchEventProjectionError) {
3754
4222
  writeWorkbenchProblem(res, "VALIDATION_ERROR", requestId, "事件游标无效", error.message);
3755
4223
  return;