@harrylabsj/kiwi 0.12.3 → 0.12.5

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 (404) hide show
  1. package/README.md +1 -1
  2. package/contracts/kiwi-contracts.lock.json +1 -1
  3. package/dist/a2a/client/client.d.ts +3 -1
  4. package/dist/a2a/client/client.js +23 -14
  5. package/dist/a2a/client/client.js.map +1 -1
  6. package/dist/a2a/client/types.d.ts +1 -1
  7. package/dist/a2a/client/url-policy.d.ts +2 -1
  8. package/dist/a2a/client/url-policy.js +5 -2
  9. package/dist/a2a/client/url-policy.js.map +1 -1
  10. package/dist/a2a/negotiate.js +68 -27
  11. package/dist/a2a/negotiate.js.map +1 -1
  12. package/dist/a2a/node.d.ts +5 -1
  13. package/dist/a2a/node.js +68 -30
  14. package/dist/a2a/node.js.map +1 -1
  15. package/dist/a2a/server/merchant-handler.d.ts +4 -6
  16. package/dist/a2a/server/merchant-handler.js +679 -484
  17. package/dist/a2a/server/merchant-handler.js.map +1 -1
  18. package/dist/a2a/server/merchant-product-facts.d.ts +32 -0
  19. package/dist/a2a/server/merchant-product-facts.js +57 -0
  20. package/dist/a2a/server/merchant-product-facts.js.map +1 -0
  21. package/dist/a2a/server/pipeline.d.ts +1 -0
  22. package/dist/a2a/server/pipeline.js +48 -10
  23. package/dist/a2a/server/pipeline.js.map +1 -1
  24. package/dist/a2a/task/poller.d.ts +3 -0
  25. package/dist/a2a/task/poller.js +3 -0
  26. package/dist/a2a/task/poller.js.map +1 -1
  27. package/dist/agent/buyer/buyer-tools.d.ts +1 -1
  28. package/dist/agent/buyer/buyer-tools.js +322 -4
  29. package/dist/agent/buyer/buyer-tools.js.map +1 -1
  30. package/dist/agent/buyer/scheduler.d.ts +3 -0
  31. package/dist/agent/buyer/scheduler.js +25 -5
  32. package/dist/agent/buyer/scheduler.js.map +1 -1
  33. package/dist/agent/buyer/search-loop.js +6 -2
  34. package/dist/agent/buyer/search-loop.js.map +1 -1
  35. package/dist/agent/buyer/task-store.d.ts +12 -0
  36. package/dist/agent/buyer/task-store.js +101 -14
  37. package/dist/agent/buyer/task-store.js.map +1 -1
  38. package/dist/agent/kernel.d.ts +11 -0
  39. package/dist/agent/kernel.js +345 -273
  40. package/dist/agent/kernel.js.map +1 -1
  41. package/dist/agent/kiwi-tool.d.ts +11 -12
  42. package/dist/agent/merchant/action-candidate.d.ts +7 -0
  43. package/dist/agent/merchant/action-candidate.js +54 -9
  44. package/dist/agent/merchant/action-candidate.js.map +1 -1
  45. package/dist/agent/merchant/types.d.ts +4 -9
  46. package/dist/agent/merchant/types.js +14 -0
  47. package/dist/agent/merchant/types.js.map +1 -1
  48. package/dist/agent/negotiation-chat.js +36 -8
  49. package/dist/agent/negotiation-chat.js.map +1 -1
  50. package/dist/agent/session.js +8 -0
  51. package/dist/agent/session.js.map +1 -1
  52. package/dist/agent/write-gate.d.ts +4 -0
  53. package/dist/agent/write-gate.js +22 -20
  54. package/dist/agent/write-gate.js.map +1 -1
  55. package/dist/buyer-core/a2a-knp.d.ts +2 -8
  56. package/dist/buyer-core/a2a-knp.js +16 -3
  57. package/dist/buyer-core/a2a-knp.js.map +1 -1
  58. package/dist/buyer-core/a2a-negotiator.d.ts +26 -19
  59. package/dist/buyer-core/a2a-negotiator.js +105 -38
  60. package/dist/buyer-core/a2a-negotiator.js.map +1 -1
  61. package/dist/buyer-core/a2a-quote-fetcher.d.ts +17 -3
  62. package/dist/buyer-core/a2a-quote-fetcher.js +141 -57
  63. package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
  64. package/dist/buyer-core/build-service.d.ts +2 -0
  65. package/dist/buyer-core/build-service.js +28 -2
  66. package/dist/buyer-core/build-service.js.map +1 -1
  67. package/dist/buyer-core/errors.js +1 -1
  68. package/dist/buyer-core/negotiator.d.ts +0 -15
  69. package/dist/buyer-core/negotiator.js +3 -0
  70. package/dist/buyer-core/negotiator.js.map +1 -1
  71. package/dist/buyer-core/product-summary.d.ts +4 -0
  72. package/dist/buyer-core/product-summary.js +6 -0
  73. package/dist/buyer-core/product-summary.js.map +1 -1
  74. package/dist/buyer-core/protocol-recovery.d.ts +78 -0
  75. package/dist/buyer-core/protocol-recovery.js +368 -0
  76. package/dist/buyer-core/protocol-recovery.js.map +1 -0
  77. package/dist/buyer-core/receive-gate.d.ts +11 -0
  78. package/dist/buyer-core/receive-gate.js +107 -0
  79. package/dist/buyer-core/receive-gate.js.map +1 -0
  80. package/dist/buyer-core/service.d.ts +53 -2
  81. package/dist/buyer-core/service.js +584 -74
  82. package/dist/buyer-core/service.js.map +1 -1
  83. package/dist/buyer-core/store.d.ts +27 -2
  84. package/dist/buyer-core/store.js +131 -26
  85. package/dist/buyer-core/store.js.map +1 -1
  86. package/dist/cli.js +208 -21
  87. package/dist/cli.js.map +1 -1
  88. package/dist/cloud/binding/enrollment-challenge.d.ts +1 -0
  89. package/dist/cloud/binding/enrollment-challenge.js +84 -33
  90. package/dist/cloud/binding/enrollment-challenge.js.map +1 -1
  91. package/dist/cloud/binding/enrollment-heartbeat.d.ts +2 -0
  92. package/dist/cloud/binding/enrollment-heartbeat.js +6 -2
  93. package/dist/cloud/binding/enrollment-heartbeat.js.map +1 -1
  94. package/dist/cloud/binding/proofs.d.ts +5 -0
  95. package/dist/cloud/binding/proofs.js +14 -1
  96. package/dist/cloud/binding/proofs.js.map +1 -1
  97. package/dist/cloud/binding/runtime-challenge.d.ts +2 -0
  98. package/dist/cloud/binding/runtime-challenge.js +20 -8
  99. package/dist/cloud/binding/runtime-challenge.js.map +1 -1
  100. package/dist/cloud/binding/store-lock.d.ts +13 -0
  101. package/dist/cloud/binding/store-lock.js +77 -0
  102. package/dist/cloud/binding/store-lock.js.map +1 -0
  103. package/dist/cloud/bootstrap.d.ts +4 -0
  104. package/dist/cloud/bootstrap.js +74 -57
  105. package/dist/cloud/bootstrap.js.map +1 -1
  106. package/dist/cloud/catalog-client.d.ts +4 -0
  107. package/dist/cloud/catalog-client.js +106 -29
  108. package/dist/cloud/catalog-client.js.map +1 -1
  109. package/dist/cloud/connect-service.d.ts +6 -0
  110. package/dist/cloud/connect-service.js +360 -120
  111. package/dist/cloud/connect-service.js.map +1 -1
  112. package/dist/cloud/file-listing-publication.js +6 -0
  113. package/dist/cloud/file-listing-publication.js.map +1 -1
  114. package/dist/cloud/main.d.ts +3 -0
  115. package/dist/cloud/main.js +47 -11
  116. package/dist/cloud/main.js.map +1 -1
  117. package/dist/cloud/onboarding/catalog-pipeline.d.ts +32 -1
  118. package/dist/cloud/onboarding/catalog-pipeline.js +80 -19
  119. package/dist/cloud/onboarding/catalog-pipeline.js.map +1 -1
  120. package/dist/cloud/onboarding/store.js +12 -4
  121. package/dist/cloud/onboarding/store.js.map +1 -1
  122. package/dist/cloud/product-import-tabular.d.ts +1 -1
  123. package/dist/cloud/product-import-tabular.js +275 -36
  124. package/dist/cloud/product-import-tabular.js.map +1 -1
  125. package/dist/cloud/product-source.d.ts +6 -1
  126. package/dist/cloud/product-source.js +47 -15
  127. package/dist/cloud/product-source.js.map +1 -1
  128. package/dist/commerce/data-source.d.ts +4 -0
  129. package/dist/commerce/data-source.js.map +1 -1
  130. package/dist/commerce/http-client.d.ts +30 -1
  131. package/dist/commerce/http-client.js +11 -7
  132. package/dist/commerce/http-client.js.map +1 -1
  133. package/dist/commerce/shopping-cli-source.js +4 -0
  134. package/dist/commerce/shopping-cli-source.js.map +1 -1
  135. package/dist/commerce/types.d.ts +2 -1
  136. package/dist/commerce/types.js.map +1 -1
  137. package/dist/counterparty/a2a-direct/index.js +2 -20
  138. package/dist/counterparty/a2a-direct/index.js.map +1 -1
  139. package/dist/counterparty/channel.d.ts +2 -1
  140. package/dist/counterparty/channel.js.map +1 -1
  141. package/dist/counterparty/shopping-cli-hosted/index.js +2 -24
  142. package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -1
  143. package/dist/demo/demo-runner.d.ts +1 -1
  144. package/dist/demo/demo-runner.js +3 -6
  145. package/dist/demo/demo-runner.js.map +1 -1
  146. package/dist/discovery/catalog-source/cloud-card.d.ts +4 -3
  147. package/dist/discovery/catalog-source/cloud-card.js +28 -25
  148. package/dist/discovery/catalog-source/cloud-card.js.map +1 -1
  149. package/dist/discovery/catalog-source/kiwi-source.d.ts +7 -19
  150. package/dist/discovery/catalog-source/kiwi-source.js +19 -12
  151. package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
  152. package/dist/discovery/catalog-source/register.js +22 -12
  153. package/dist/discovery/catalog-source/register.js.map +1 -1
  154. package/dist/discovery/catalog-source/source.d.ts +3 -17
  155. package/dist/discovery/catalog-source/source.js +11 -8
  156. package/dist/discovery/catalog-source/source.js.map +1 -1
  157. package/dist/discovery/catalog-source/types.d.ts +3 -2
  158. package/dist/discovery/catalog-source/types.js +0 -15
  159. package/dist/discovery/catalog-source/types.js.map +1 -1
  160. package/dist/discovery/merchant-subscriptions.d.ts +4 -0
  161. package/dist/discovery/merchant-subscriptions.js +72 -23
  162. package/dist/discovery/merchant-subscriptions.js.map +1 -1
  163. package/dist/discovery/resolve.d.ts +7 -3
  164. package/dist/discovery/resolve.js +62 -30
  165. package/dist/discovery/resolve.js.map +1 -1
  166. package/dist/discovery/ucp/resolver.d.ts +3 -17
  167. package/dist/discovery/ucp/resolver.js +9 -3
  168. package/dist/discovery/ucp/resolver.js.map +1 -1
  169. package/dist/fanout/disclosure.js +27 -10
  170. package/dist/fanout/disclosure.js.map +1 -1
  171. package/dist/fanout/orchestrator.js +38 -24
  172. package/dist/fanout/orchestrator.js.map +1 -1
  173. package/dist/fs/atomic-write.d.ts +11 -0
  174. package/dist/fs/atomic-write.js +67 -10
  175. package/dist/fs/atomic-write.js.map +1 -1
  176. package/dist/handoff/index.d.ts +2 -1
  177. package/dist/handoff/index.js +1 -0
  178. package/dist/handoff/index.js.map +1 -1
  179. package/dist/handoff/launch-marketplace-policy.d.ts +149 -0
  180. package/dist/handoff/launch-marketplace-policy.js +301 -0
  181. package/dist/handoff/launch-marketplace-policy.js.map +1 -0
  182. package/dist/handoff/marketplace-product-link.d.ts +18 -0
  183. package/dist/handoff/marketplace-product-link.js +71 -0
  184. package/dist/handoff/marketplace-product-link.js.map +1 -0
  185. package/dist/handoff/order-record.js +25 -3
  186. package/dist/handoff/order-record.js.map +1 -1
  187. package/dist/handoff/transaction.d.ts +30 -0
  188. package/dist/handoff/transaction.js +64 -0
  189. package/dist/handoff/transaction.js.map +1 -1
  190. package/dist/handoff/ucp-checkout/channel.js +2 -1
  191. package/dist/handoff/ucp-checkout/channel.js.map +1 -1
  192. package/dist/handoff/ucp-checkout/client.d.ts +1 -0
  193. package/dist/handoff/ucp-checkout/client.js +48 -37
  194. package/dist/handoff/ucp-checkout/client.js.map +1 -1
  195. package/dist/handoff/url-safety.d.ts +3 -0
  196. package/dist/handoff/url-safety.js +7 -0
  197. package/dist/handoff/url-safety.js.map +1 -1
  198. package/dist/http/bounded-ip-rate-limit.d.ts +10 -0
  199. package/dist/http/bounded-ip-rate-limit.js +37 -0
  200. package/dist/http/bounded-ip-rate-limit.js.map +1 -0
  201. package/dist/http/cli.js +23 -0
  202. package/dist/http/cli.js.map +1 -1
  203. package/dist/http/merchant-feed-api.js +8 -1
  204. package/dist/http/merchant-feed-api.js.map +1 -1
  205. package/dist/http/merchant-management/api.js +20 -1
  206. package/dist/http/merchant-management/api.js.map +1 -1
  207. package/dist/http/merchant-management/page.js +176 -45
  208. package/dist/http/merchant-management/page.js.map +1 -1
  209. package/dist/http/merchant-management/reconciliation-worker.js +5 -2
  210. package/dist/http/merchant-management/reconciliation-worker.js.map +1 -1
  211. package/dist/http/merchant-management/trusted-page.js +1 -1
  212. package/dist/http/merchant-management/trusted-page.js.map +1 -1
  213. package/dist/http/merchant-server.js +2 -1
  214. package/dist/http/merchant-server.js.map +1 -1
  215. package/dist/http/server.d.ts +15 -0
  216. package/dist/http/server.js +107 -9
  217. package/dist/http/server.js.map +1 -1
  218. package/dist/i18n.d.ts +1 -0
  219. package/dist/i18n.js +3 -0
  220. package/dist/i18n.js.map +1 -1
  221. package/dist/lifecycle/close.d.ts +24 -0
  222. package/dist/lifecycle/close.js +131 -0
  223. package/dist/lifecycle/close.js.map +1 -0
  224. package/dist/mcp/merchant-rfq-tools.d.ts +6 -4
  225. package/dist/mcp/merchant-rfq-tools.js +2 -0
  226. package/dist/mcp/merchant-rfq-tools.js.map +1 -1
  227. package/dist/mcp/merchant-runtime-assembly.js +7 -22
  228. package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
  229. package/dist/mcp/merchant-server.d.ts +0 -22
  230. package/dist/mcp/merchant-server.js +25 -2
  231. package/dist/mcp/merchant-server.js.map +1 -1
  232. package/dist/mcp/tools.js +17 -16
  233. package/dist/mcp/tools.js.map +1 -1
  234. package/dist/mcp/types.d.ts +1 -1
  235. package/dist/mcp/types.js +1 -1
  236. package/dist/merchant/ai-runtime/config.d.ts +99 -0
  237. package/dist/merchant/ai-runtime/config.js +187 -0
  238. package/dist/merchant/ai-runtime/config.js.map +1 -0
  239. package/dist/merchant/ai-runtime/gate.d.ts +142 -0
  240. package/dist/merchant/ai-runtime/gate.js +343 -0
  241. package/dist/merchant/ai-runtime/gate.js.map +1 -0
  242. package/dist/merchant/ai-runtime/owner-authoritative-receipts.d.ts +5 -0
  243. package/dist/merchant/ai-runtime/owner-authoritative-receipts.js +53 -0
  244. package/dist/merchant/ai-runtime/owner-authoritative-receipts.js.map +1 -0
  245. package/dist/merchant/ai-runtime/owner-budget-gate.d.ts +10 -0
  246. package/dist/merchant/ai-runtime/owner-budget-gate.js +37 -0
  247. package/dist/merchant/ai-runtime/owner-budget-gate.js.map +1 -0
  248. package/dist/merchant/ai-runtime/owner-business-config.d.ts +33 -0
  249. package/dist/merchant/ai-runtime/owner-business-config.js +93 -0
  250. package/dist/merchant/ai-runtime/owner-business-config.js.map +1 -0
  251. package/dist/merchant/ai-runtime/owner-business-host.d.ts +24 -0
  252. package/dist/merchant/ai-runtime/owner-business-host.js +114 -0
  253. package/dist/merchant/ai-runtime/owner-business-host.js.map +1 -0
  254. package/dist/merchant/ai-runtime/owner-business-proof-contract.d.ts +26 -0
  255. package/dist/merchant/ai-runtime/owner-business-proof-contract.js +2 -0
  256. package/dist/merchant/ai-runtime/owner-business-proof-contract.js.map +1 -0
  257. package/dist/merchant/ai-runtime/owner-committed-proof.d.ts +55 -0
  258. package/dist/merchant/ai-runtime/owner-committed-proof.js +141 -0
  259. package/dist/merchant/ai-runtime/owner-committed-proof.js.map +1 -0
  260. package/dist/merchant/ai-runtime/owner-factory-config.d.ts +30 -0
  261. package/dist/merchant/ai-runtime/owner-factory-config.js +99 -0
  262. package/dist/merchant/ai-runtime/owner-factory-config.js.map +1 -0
  263. package/dist/merchant/ai-runtime/owner-file-grant.d.ts +71 -0
  264. package/dist/merchant/ai-runtime/owner-file-grant.js +118 -0
  265. package/dist/merchant/ai-runtime/owner-file-grant.js.map +1 -0
  266. package/dist/merchant/ai-runtime/owner-local-readonly-host.d.ts +17 -0
  267. package/dist/merchant/ai-runtime/owner-local-readonly-host.js +116 -0
  268. package/dist/merchant/ai-runtime/owner-local-readonly-host.js.map +1 -0
  269. package/dist/merchant/ai-runtime/owner-operation-reader.d.ts +24 -0
  270. package/dist/merchant/ai-runtime/owner-operation-reader.js +62 -0
  271. package/dist/merchant/ai-runtime/owner-operation-reader.js.map +1 -0
  272. package/dist/merchant/ai-runtime/owner-provider-guard.d.ts +9 -0
  273. package/dist/merchant/ai-runtime/owner-provider-guard.js +127 -0
  274. package/dist/merchant/ai-runtime/owner-provider-guard.js.map +1 -0
  275. package/dist/merchant/ai-runtime/owner-readonly-facts.d.ts +26 -0
  276. package/dist/merchant/ai-runtime/owner-readonly-facts.js +72 -0
  277. package/dist/merchant/ai-runtime/owner-readonly-facts.js.map +1 -0
  278. package/dist/merchant/ai-runtime/owner-sdk-tools.d.ts +43 -0
  279. package/dist/merchant/ai-runtime/owner-sdk-tools.js +83 -0
  280. package/dist/merchant/ai-runtime/owner-sdk-tools.js.map +1 -0
  281. package/dist/merchant/ai-runtime/owner-session.d.ts +341 -0
  282. package/dist/merchant/ai-runtime/owner-session.js +1280 -0
  283. package/dist/merchant/ai-runtime/owner-session.js.map +1 -0
  284. package/dist/merchant/ai-runtime/owner-storage-admission.d.ts +35 -0
  285. package/dist/merchant/ai-runtime/owner-storage-admission.js +324 -0
  286. package/dist/merchant/ai-runtime/owner-storage-admission.js.map +1 -0
  287. package/dist/merchant/ai-runtime/owner-trusted-factory.d.ts +44 -0
  288. package/dist/merchant/ai-runtime/owner-trusted-factory.js +185 -0
  289. package/dist/merchant/ai-runtime/owner-trusted-factory.js.map +1 -0
  290. package/dist/merchant/ai-runtime/sqlite-budget-store.d.ts +68 -0
  291. package/dist/merchant/ai-runtime/sqlite-budget-store.js +335 -0
  292. package/dist/merchant/ai-runtime/sqlite-budget-store.js.map +1 -0
  293. package/dist/merchant/ai-runtime/status.d.ts +64 -0
  294. package/dist/merchant/ai-runtime/status.js +56 -0
  295. package/dist/merchant/ai-runtime/status.js.map +1 -0
  296. package/dist/merchant/application/service.d.ts +5 -1
  297. package/dist/merchant/application/service.js +7 -8
  298. package/dist/merchant/application/service.js.map +1 -1
  299. package/dist/merchant/grant-store.js +9 -4
  300. package/dist/merchant/grant-store.js.map +1 -1
  301. package/dist/merchant/promotion-store.js +1 -0
  302. package/dist/merchant/promotion-store.js.map +1 -1
  303. package/dist/merchant/stats-store.d.ts +3 -0
  304. package/dist/merchant/stats-store.js +28 -8
  305. package/dist/merchant/stats-store.js.map +1 -1
  306. package/dist/merchant/workbench-service.d.ts +1 -0
  307. package/dist/merchant/workbench-service.js +28 -11
  308. package/dist/merchant/workbench-service.js.map +1 -1
  309. package/dist/merchant-core/commands.d.ts +3 -0
  310. package/dist/merchant-core/commands.js +39 -2
  311. package/dist/merchant-core/commands.js.map +1 -1
  312. package/dist/merchant-core/executor.d.ts +2 -0
  313. package/dist/merchant-core/executor.js +1 -1
  314. package/dist/merchant-core/executor.js.map +1 -1
  315. package/dist/merchant-core/operations.d.ts +2 -2
  316. package/dist/merchant-core/operations.js +11 -9
  317. package/dist/merchant-core/operations.js.map +1 -1
  318. package/dist/merchant-core/product-import.js +1 -1
  319. package/dist/merchant-core/product-import.js.map +1 -1
  320. package/dist/merchant-core/rfq/data-source-adapter.d.ts +2 -10
  321. package/dist/merchant-core/rfq/data-source-adapter.js +21 -9
  322. package/dist/merchant-core/rfq/data-source-adapter.js.map +1 -1
  323. package/dist/merchant-core/rfq/pending-candidates.d.ts +14 -0
  324. package/dist/merchant-core/rfq/pending-candidates.js +11 -0
  325. package/dist/merchant-core/rfq/pending-candidates.js.map +1 -0
  326. package/dist/merchant-core/rfq/release-coordinator.d.ts +9 -2
  327. package/dist/merchant-core/rfq/release-coordinator.js +32 -14
  328. package/dist/merchant-core/rfq/release-coordinator.js.map +1 -1
  329. package/dist/merchant-core/rfq/repository.d.ts +4 -7
  330. package/dist/merchant-core/rfq/repository.js +10 -24
  331. package/dist/merchant-core/rfq/repository.js.map +1 -1
  332. package/dist/merchant-core/rfq/service.d.ts +5 -2
  333. package/dist/merchant-core/rfq/service.js +4 -3
  334. package/dist/merchant-core/rfq/service.js.map +1 -1
  335. package/dist/merchant-gateway/entry-server.js +25 -1
  336. package/dist/merchant-gateway/entry-server.js.map +1 -1
  337. package/dist/merchant-gateway/pinned-fetch.d.ts +9 -2
  338. package/dist/merchant-gateway/pinned-fetch.js +68 -29
  339. package/dist/merchant-gateway/pinned-fetch.js.map +1 -1
  340. package/dist/merchant-runtime/manager.d.ts +5 -2
  341. package/dist/merchant-runtime/manager.js +40 -11
  342. package/dist/merchant-runtime/manager.js.map +1 -1
  343. package/dist/negotiation/context-map/store.js +4 -13
  344. package/dist/negotiation/context-map/store.js.map +1 -1
  345. package/dist/negotiation/domain/common.js +33 -2
  346. package/dist/negotiation/domain/common.js.map +1 -1
  347. package/dist/negotiation/domain/envelope.d.ts +2 -5
  348. package/dist/negotiation/domain/envelope.js +36 -9
  349. package/dist/negotiation/domain/envelope.js.map +1 -1
  350. package/dist/negotiation/domain/objects.js +14 -0
  351. package/dist/negotiation/domain/objects.js.map +1 -1
  352. package/dist/negotiation/idempotency/store.d.ts +4 -1
  353. package/dist/negotiation/idempotency/store.js +80 -52
  354. package/dist/negotiation/idempotency/store.js.map +1 -1
  355. package/dist/negotiation/idempotency/types.d.ts +7 -1
  356. package/dist/negotiation/idempotency/types.js +1 -1
  357. package/dist/negotiation/idempotency/types.js.map +1 -1
  358. package/dist/negotiation/jcs.js +11 -16
  359. package/dist/negotiation/jcs.js.map +1 -1
  360. package/dist/negotiation/ledger/store.d.ts +15 -9
  361. package/dist/negotiation/ledger/store.js +201 -65
  362. package/dist/negotiation/ledger/store.js.map +1 -1
  363. package/dist/negotiation/recovery/recover.js +30 -30
  364. package/dist/negotiation/recovery/recover.js.map +1 -1
  365. package/dist/negotiation/recovery/types.d.ts +3 -3
  366. package/dist/net/request-budget.d.ts +17 -0
  367. package/dist/net/request-budget.js +63 -0
  368. package/dist/net/request-budget.js.map +1 -0
  369. package/dist/operator/controller.d.ts +1 -1
  370. package/dist/operator/controller.js +23 -12
  371. package/dist/operator/controller.js.map +1 -1
  372. package/dist/operator/runner.d.ts +69 -0
  373. package/dist/operator/runner.js +260 -39
  374. package/dist/operator/runner.js.map +1 -1
  375. package/dist/operator/strategy.d.ts +2 -0
  376. package/dist/operator/strategy.js +11 -0
  377. package/dist/operator/strategy.js.map +1 -1
  378. package/dist/privacy/workbench-retention.js +28 -10
  379. package/dist/privacy/workbench-retention.js.map +1 -1
  380. package/dist/product-init.js +25 -4
  381. package/dist/product-init.js.map +1 -1
  382. package/dist/product-publish.js +3 -102
  383. package/dist/product-publish.js.map +1 -1
  384. package/dist/runtime/foreground.d.ts +1 -1
  385. package/dist/runtime/foreground.js +3 -0
  386. package/dist/runtime/foreground.js.map +1 -1
  387. package/dist/runtime/model.js +4 -0
  388. package/dist/runtime/model.js.map +1 -1
  389. package/dist/supervisor/manage.js +109 -35
  390. package/dist/supervisor/manage.js.map +1 -1
  391. package/dist/trust/identity/jws.js +46 -5
  392. package/dist/trust/identity/jws.js.map +1 -1
  393. package/dist/trust/identity/message-signature.js +15 -2
  394. package/dist/trust/identity/message-signature.js.map +1 -1
  395. package/dist/trust/records/store.d.ts +8 -1
  396. package/dist/trust/records/store.js +68 -6
  397. package/dist/trust/records/store.js.map +1 -1
  398. package/dist/weixin/channel.d.ts +4 -0
  399. package/dist/weixin/channel.js +17 -3
  400. package/dist/weixin/channel.js.map +1 -1
  401. package/dist/weixin/cli-weixin.js +8 -2
  402. package/dist/weixin/cli-weixin.js.map +1 -1
  403. package/package.json +30 -7
  404. package/scripts/check-install-toolchain.mjs +93 -0
@@ -31,7 +31,9 @@
31
31
  * 既有 import-drafts 严格校验与整表替换预览;
32
32
  * - 上限:数据行 5000、列 64、单文件 4 MiB、单元格 2000 字符。
33
33
  */
34
+ import { toMinorUnits as losslessToMinorUnits } from "../protocol/legacy-shopping-negotiation/money.js";
34
35
  import { inflateRawSync } from "node:zlib";
36
+ import { MarketplaceProductLinkError, parseMarketplaceProductFields, } from "../handoff/marketplace-product-link.js";
35
37
  import { parseProductTable, PRODUCT_TABLE_SCHEMA_VERSION, ProductTableError, } from "./product-source.js";
36
38
  // ── 上限与常量 ─────────────────────────────────────────────────────────
37
39
  export const TABULAR_IMPORT_MAX_ROWS = 5000;
@@ -58,7 +60,17 @@ export const TABULAR_FIELDS = [
58
60
  field: "title",
59
61
  zh: "名称",
60
62
  required: true,
61
- aliases: ["title", "name", "productname", "producttitle", "商品名称", "产品名称", "品名", "名称", "商品标题"],
63
+ aliases: [
64
+ "title",
65
+ "name",
66
+ "productname",
67
+ "producttitle",
68
+ "商品名称",
69
+ "产品名称",
70
+ "品名",
71
+ "名称",
72
+ "商品标题",
73
+ ],
62
74
  },
63
75
  {
64
76
  field: "currency",
@@ -70,7 +82,17 @@ export const TABULAR_FIELDS = [
70
82
  field: "unit",
71
83
  zh: "计价单位",
72
84
  required: true,
73
- aliases: ["unit", "units", "pricingunit", "unitofmeasure", "uom", "计价单位", "单位", "计量单位", "价格单位"],
85
+ aliases: [
86
+ "unit",
87
+ "units",
88
+ "pricingunit",
89
+ "unitofmeasure",
90
+ "uom",
91
+ "计价单位",
92
+ "单位",
93
+ "计量单位",
94
+ "价格单位",
95
+ ],
74
96
  },
75
97
  {
76
98
  field: "price",
@@ -100,19 +122,50 @@ export const TABULAR_FIELDS = [
100
122
  field: "stock",
101
123
  zh: "库存",
102
124
  required: false,
103
- aliases: ["stock", "stockqty", "inventory", "qty", "quantity", "库存", "库存数量", "可用库存", "剩余库存"],
125
+ aliases: [
126
+ "stock",
127
+ "stockqty",
128
+ "inventory",
129
+ "qty",
130
+ "quantity",
131
+ "库存",
132
+ "库存数量",
133
+ "可用库存",
134
+ "剩余库存",
135
+ ],
104
136
  },
105
137
  {
106
138
  field: "supply_note",
107
139
  zh: "供货说明",
108
140
  required: false,
109
- aliases: ["supplynote", "note", "notes", "remark", "remarks", "供货说明", "供货备注", "备注", "说明", "商品说明", "描述", "description"],
141
+ aliases: [
142
+ "supplynote",
143
+ "note",
144
+ "notes",
145
+ "remark",
146
+ "remarks",
147
+ "供货说明",
148
+ "供货备注",
149
+ "备注",
150
+ "说明",
151
+ "商品说明",
152
+ "描述",
153
+ "description",
154
+ ],
110
155
  },
111
156
  {
112
157
  field: "updated_at",
113
158
  zh: "更新时间",
114
159
  required: false,
115
- aliases: ["updatedat", "updatetime", "lastupdated", "更新时间", "数据时间", "修改时间", "最近更新"],
160
+ aliases: [
161
+ "updatedat",
162
+ "updatetime",
163
+ "lastupdated",
164
+ "更新时间",
165
+ "数据时间",
166
+ "修改时间",
167
+ "最近更新",
168
+ ],
116
169
  },
117
170
  {
118
171
  field: "valid_until",
@@ -140,6 +193,18 @@ export const TABULAR_FIELDS = [
140
193
  required: false,
141
194
  aliases: ["status", "listingstatus", "active", "状态", "商品状态", "销售状态", "上架状态"],
142
195
  },
196
+ {
197
+ field: "trade_platform",
198
+ zh: "交易平台",
199
+ required: false,
200
+ aliases: ["tradeplatform", "交易平台", "商品交易平台"],
201
+ },
202
+ {
203
+ field: "platform_product_id",
204
+ zh: "平台商品ID",
205
+ required: false,
206
+ aliases: ["platformproductid", "平台商品id", "交易平台商品id"],
207
+ },
143
208
  ];
144
209
  /**
145
210
  * 疑似底价/成本/进价列(归一化后**包含**即命中):整表拒绝。底价、成本
@@ -306,6 +371,7 @@ export function parseCsv(text) {
306
371
  let row = [];
307
372
  let cell = "";
308
373
  let inQuotes = false;
374
+ let closedQuote = false;
309
375
  for (let i = 0; i < stripped.length; i += 1) {
310
376
  const ch = stripped[i];
311
377
  if (inQuotes) {
@@ -316,6 +382,7 @@ export function parseCsv(text) {
316
382
  }
317
383
  else {
318
384
  inQuotes = false;
385
+ closedQuote = true;
319
386
  }
320
387
  }
321
388
  else {
@@ -323,18 +390,25 @@ export function parseCsv(text) {
323
390
  }
324
391
  continue;
325
392
  }
393
+ if (closedQuote && ch !== "," && ch !== "\n" && ch !== "\r") {
394
+ throw new TabularImportError("INVALID_CSV", "引号字段结束后必须为分隔符或换行");
395
+ }
326
396
  if (ch === '"') {
397
+ if (cell !== "")
398
+ throw new TabularImportError("INVALID_CSV", "裸字段中不能出现双引号");
327
399
  inQuotes = true;
328
400
  }
329
401
  else if (ch === ",") {
330
402
  row.push(cell);
331
403
  cell = "";
404
+ closedQuote = false;
332
405
  }
333
406
  else if (ch === "\n") {
334
407
  row.push(cell);
335
408
  rows.push(row);
336
409
  row = [];
337
410
  cell = "";
411
+ closedQuote = false;
338
412
  }
339
413
  else if (ch === "\r") {
340
414
  if (stripped[i + 1] === "\n")
@@ -343,11 +417,14 @@ export function parseCsv(text) {
343
417
  rows.push(row);
344
418
  row = [];
345
419
  cell = "";
420
+ closedQuote = false;
346
421
  }
347
422
  else {
348
423
  cell += ch;
349
424
  }
350
425
  }
426
+ if (inQuotes)
427
+ throw new TabularImportError("INVALID_CSV", "引号字段未闭合");
351
428
  if (cell !== "" || row.length > 0) {
352
429
  row.push(cell);
353
430
  rows.push(row);
@@ -487,6 +564,9 @@ function columnToIndex(ref) {
487
564
  }
488
565
  /** 解析第一张工作表为字符串矩阵;数值保持原文,日期样式数值转 ISO。 */
489
566
  export function parseXlsx(bytes) {
567
+ return parseXlsxGrid(bytes).rows;
568
+ }
569
+ function parseXlsxGrid(bytes) {
490
570
  if (bytes.length > TABULAR_IMPORT_MAX_BYTES) {
491
571
  throw new TabularImportError("LIMIT_BYTES", `文件超过上限 ${TABULAR_IMPORT_MAX_BYTES} 字节`);
492
572
  }
@@ -500,6 +580,7 @@ export function parseXlsx(bytes) {
500
580
  const dateStyles = readDateStyles(reader.read("xl/styles.xml"));
501
581
  const xml = new TextDecoder().decode(sheetXml);
502
582
  const rows = [];
583
+ const nonTextCells = new Set();
503
584
  const rowRe = /<row[^>]*\br="(\d+)"[^>]*>([\s\S]*?)<\/row>|<row[^>]*\/>/g;
504
585
  let rowMatch;
505
586
  while ((rowMatch = rowRe.exec(xml)) !== null) {
@@ -507,6 +588,7 @@ export function parseXlsx(bytes) {
507
588
  throw new TabularImportError("LIMIT_ROWS", `数据行超过上限 ${TABULAR_IMPORT_MAX_ROWS} 行`);
508
589
  }
509
590
  const cells = [];
591
+ const rowNonText = [];
510
592
  const body = rowMatch[2] ?? "";
511
593
  const cellRe = /<c([^>]*)(?:\/>|>([\s\S]*?)<\/c>)/g;
512
594
  let cellMatch;
@@ -527,13 +609,21 @@ export function parseXlsx(bytes) {
527
609
  }
528
610
  const value = readCellValue(inner, type, style, shared, dateStyles);
529
611
  cells[column] = value;
612
+ const sharedIndex = /<v>([\s\S]*?)<\/v>/.exec(inner)?.[1] ?? "";
613
+ const textCell = type === "inlineStr" || type === "str" || (type === "s" && /^[0-9]+$/.test(sharedIndex));
614
+ if (value !== "" && (!textCell || /<f[\s/>]/.test(inner)))
615
+ rowNonText.push(column);
530
616
  }
531
617
  // cells 是稀疏数组(按列号落位);map/forEach 会跳过空洞导致错位,
532
618
  // 必须先稠密化。
533
619
  const normalized = Array.from({ length: cells.length }, (_, index) => cells[index] ?? "");
534
- rows.push(normalized.slice(0, TABULAR_IMPORT_MAX_COLUMNS));
620
+ if (!normalized.every((cell) => cell === "")) {
621
+ for (const column of rowNonText)
622
+ nonTextCells.add(`${rows.length}:${column}`);
623
+ rows.push(normalized.slice(0, TABULAR_IMPORT_MAX_COLUMNS));
624
+ }
535
625
  }
536
- return rows.filter((line) => !line.every((cell) => cell === ""));
626
+ return { rows, nonTextCells };
537
627
  }
538
628
  function resolveFirstSheetPath(reader) {
539
629
  const workbook = reader.read("xl/workbook.xml");
@@ -619,7 +709,8 @@ function readDateStyles(xml) {
619
709
  const numFmtId = Number(/\bnumFmtId="(\d+)"/.exec(xfMatch[0])?.[1] ?? 0);
620
710
  if ((numFmtId >= 14 && numFmtId <= 22) ||
621
711
  (numFmtId >= 45 && numFmtId <= 47) ||
622
- (customFormats.get(numFmtId) ?? "").replace(/\[[^\]]*\]|"[^"]*"/g, "").match(/[ymdhs]/i) !== null) {
712
+ (customFormats.get(numFmtId) ?? "").replace(/\[[^\]]*\]|"[^"]*"/g, "").match(/[ymdhs]/i) !==
713
+ null) {
623
714
  styles.add(styleIndex);
624
715
  }
625
716
  styleIndex += 1;
@@ -640,33 +731,39 @@ export const TABULAR_TEMPLATE_HEADER = [
640
731
  "更新时间/updated_at",
641
732
  "有效期至/valid_until",
642
733
  "状态/status",
734
+ "交易平台/trade_platform",
735
+ "平台商品ID/platform_product_id",
643
736
  ];
644
737
  export const TABULAR_TEMPLATE_EXAMPLE_ROWS = [
645
738
  [
646
739
  "DEMO-001",
647
- "不锈钢保温杯 500ml",
740
+ "示例保温杯(请替换为实际商品)",
648
741
  "CNY",
649
742
  "piece",
650
743
  "29.90",
651
744
  "50",
652
745
  "2000",
653
- "现货,下单后 3 个工作日发货",
746
+ "仅格式示例;平台商品ID不代表已核实商品,请替换",
654
747
  "",
655
748
  "2027-12-31",
656
749
  "在售",
750
+ "京东",
751
+ "12345678901234567890",
657
752
  ],
658
753
  [
659
754
  "DEMO-002",
660
- "瓦楞纸箱 五层加强",
755
+ "示例纸箱(请替换为实际商品)",
661
756
  "CNY",
662
757
  "box",
663
758
  "3.50",
664
759
  "100",
665
760
  "8000",
666
- "按订单生产,约 7 天交期",
761
+ "仅格式示例;平台商品ID不代表已核实商品,请替换",
667
762
  "2026-09-01",
668
763
  "2028-06-30",
669
764
  "在售",
765
+ "淘宝",
766
+ "98765432101234567890",
670
767
  ],
671
768
  ];
672
769
  function csvEscape(cell) {
@@ -759,18 +856,19 @@ function sheetXmlFromGrid(rows) {
759
856
  const cells = row
760
857
  .map((cell, columnIndex) => cell === ""
761
858
  ? ""
762
- : `<c r="${columnName(columnIndex)}${rowIndex + 1}" t="inlineStr"><is><t xml:space="preserve">${xmlEscape(cell)}</t></is></c>`)
859
+ : `<c r="${columnName(columnIndex)}${rowIndex + 1}"${columnIndex === 12 ? ' s="1"' : ""} t="inlineStr"><is><t xml:space="preserve">${xmlEscape(cell)}</t></is></c>`)
763
860
  .join("");
764
861
  return `<row r="${rowIndex + 1}">${cells}</row>`;
765
862
  })
766
863
  .join("");
767
864
  const cols = Array.from({ length: columnCount }, (_, index) => {
768
865
  const width = index === 0 || index === 7 ? 260 : 110;
769
- return `<col min="${index + 1}" max="${index + 1}" width="${width}" customWidth="1"/>`;
866
+ return `<col min="${index + 1}" max="${index + 1}" width="${width}" customWidth="1"${index === 12 ? ' style="1"' : ""}/>`;
770
867
  }).join("");
771
868
  return (`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` +
772
869
  `<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">` +
773
- `<cols>${cols}</cols><sheetData>${body}</sheetData></worksheet>`);
870
+ `<cols>${cols}</cols><sheetData>${body}</sheetData>` +
871
+ `<dataValidations count="1"><dataValidation type="list" allowBlank="1" showErrorMessage="1" sqref="L2:L5001"><formula1>"京东,淘宝,天猫"</formula1></dataValidation></dataValidations></worksheet>`);
774
872
  }
775
873
  function columnName(index) {
776
874
  let name = "";
@@ -793,6 +891,7 @@ export function renderImportTemplateXlsx() {
793
891
  `<Default Extension="xml" ContentType="application/xml"/>` +
794
892
  `<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>` +
795
893
  `<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>` +
894
+ `<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>` +
796
895
  `</Types>`,
797
896
  },
798
897
  {
@@ -814,9 +913,20 @@ export function renderImportTemplateXlsx() {
814
913
  content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` +
815
914
  `<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">` +
816
915
  `<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>` +
916
+ `<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>` +
817
917
  `</Relationships>`,
818
918
  },
819
919
  { name: "xl/worksheets/sheet1.xml", content: sheetXmlFromGrid(grid) },
920
+ {
921
+ name: "xl/styles.xml",
922
+ content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` +
923
+ `<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">` +
924
+ `<fonts count="1"><font><sz val="11"/><name val="Calibri"/></font></fonts>` +
925
+ `<fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills>` +
926
+ `<borders count="1"><border/></borders><cellStyleXfs count="1"><xf numFmtId="0"/></cellStyleXfs>` +
927
+ `<cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/><xf numFmtId="49" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/></cellXfs>` +
928
+ `<cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles></styleSheet>`,
929
+ },
820
930
  ]);
821
931
  }
822
932
  /**
@@ -827,14 +937,28 @@ export function convertTabularImport(input, options) {
827
937
  const now = options.now ?? (() => new Date());
828
938
  const errors = [];
829
939
  let grid;
940
+ let nonTextCells = new Set();
830
941
  try {
831
- grid = input.kind === "csv" ? parseCsv(input.text) : parseXlsx(input.bytes);
942
+ if (input.kind === "csv")
943
+ grid = parseCsv(input.text);
944
+ else {
945
+ const parsed = parseXlsxGrid(input.bytes);
946
+ grid = parsed.rows;
947
+ nonTextCells = parsed.nonTextCells;
948
+ }
832
949
  }
833
950
  catch (err) {
834
951
  if (err instanceof TabularImportError) {
835
952
  return {
836
953
  ok: false,
837
- report: { format: input.kind, rows: 0, header_mapping: [], unrecognized_columns: [], defaulted_fields: [], skipped_empty_rows: 0 },
954
+ report: {
955
+ format: input.kind,
956
+ rows: 0,
957
+ header_mapping: [],
958
+ unrecognized_columns: [],
959
+ defaulted_fields: [],
960
+ skipped_empty_rows: 0,
961
+ },
838
962
  errors: [{ code: err.code, message: err.message }],
839
963
  };
840
964
  }
@@ -850,10 +974,18 @@ export function convertTabularImport(input, options) {
850
974
  };
851
975
  const headerRow = grid[0];
852
976
  if (headerRow === undefined || headerRow.every((cell) => cell.trim() === "")) {
853
- return { ok: false, report, errors: [{ code: "EMPTY_TABLE", message: "表格是空的:第一行应为表头" }] };
977
+ return {
978
+ ok: false,
979
+ report,
980
+ errors: [{ code: "EMPTY_TABLE", message: "表格是空的:第一行应为表头" }],
981
+ };
854
982
  }
855
983
  if (grid.length - 1 <= 0) {
856
- return { ok: false, report, errors: [{ code: "EMPTY_TABLE", message: "表格只有表头,没有商品行" }] };
984
+ return {
985
+ ok: false,
986
+ report,
987
+ errors: [{ code: "EMPTY_TABLE", message: "表格只有表头,没有商品行" }],
988
+ };
857
989
  }
858
990
  if (headerRow.length > TABULAR_IMPORT_MAX_COLUMNS) {
859
991
  return {
@@ -957,56 +1089,116 @@ export function convertTabularImport(input, options) {
957
1089
  }
958
1090
  const sku = cellOf(row, "sku");
959
1091
  if (sku === "") {
960
- errors.push({ row: rowNumber, field: "sku", code: "EMPTY_REQUIRED", message: `第 ${rowNumber} 行商品编号(sku)为空` });
1092
+ errors.push({
1093
+ row: rowNumber,
1094
+ field: "sku",
1095
+ code: "EMPTY_REQUIRED",
1096
+ message: `第 ${rowNumber} 行商品编号(sku)为空`,
1097
+ });
961
1098
  }
962
1099
  const title = cellOf(row, "title");
963
1100
  if (title === "") {
964
- errors.push({ row: rowNumber, field: "title", code: "EMPTY_REQUIRED", message: `第 ${rowNumber} 行名称(title)为空` });
1101
+ errors.push({
1102
+ row: rowNumber,
1103
+ field: "title",
1104
+ code: "EMPTY_REQUIRED",
1105
+ message: `第 ${rowNumber} 行名称(title)为空`,
1106
+ });
965
1107
  }
966
1108
  const unit = cellOf(row, "unit");
967
1109
  if (unit === "") {
968
- errors.push({ row: rowNumber, field: "unit", code: "EMPTY_REQUIRED", message: `第 ${rowNumber} 行计价单位(unit)为空` });
1110
+ errors.push({
1111
+ row: rowNumber,
1112
+ field: "unit",
1113
+ code: "EMPTY_REQUIRED",
1114
+ message: `第 ${rowNumber} 行计价单位(unit)为空`,
1115
+ });
969
1116
  }
970
1117
  const priceRaw = cellOf(row, "price");
971
1118
  const price = parseCellNumber(priceRaw);
972
1119
  if (priceRaw === "") {
973
- errors.push({ row: rowNumber, field: "price", code: "EMPTY_REQUIRED", message: `第 ${rowNumber} 行单价(price)为空:价格必须由商家提供,不能缺省` });
1120
+ errors.push({
1121
+ row: rowNumber,
1122
+ field: "price",
1123
+ code: "EMPTY_REQUIRED",
1124
+ message: `第 ${rowNumber} 行单价(price)为空:价格必须由商家提供,不能缺省`,
1125
+ });
974
1126
  }
975
- else if (Number.isNaN(price) || price <= 0) {
976
- errors.push({ row: rowNumber, field: "price", code: "BAD_NUMBER", message: `第 ${rowNumber} 行单价不是正数(收到「${priceRaw}」)` });
1127
+ else if (!Number.isFinite(price) || price < 0 || !losslessToMinorUnits(price, 2).lossless) {
1128
+ errors.push({
1129
+ row: rowNumber,
1130
+ field: "price",
1131
+ code: "BAD_NUMBER",
1132
+ message: `第 ${rowNumber} 行单价必须是非负且可无损表示为两位小数(收到「${priceRaw}」)`,
1133
+ });
977
1134
  }
978
1135
  const currencyRaw = cellOf(row, "currency");
979
1136
  const currency = parseCellCurrency(currencyRaw);
980
1137
  if (currencyRaw === "") {
981
- errors.push({ row: rowNumber, field: "currency", code: "EMPTY_REQUIRED", message: `第 ${rowNumber} 行币种为空` });
1138
+ errors.push({
1139
+ row: rowNumber,
1140
+ field: "currency",
1141
+ code: "EMPTY_REQUIRED",
1142
+ message: `第 ${rowNumber} 行币种为空`,
1143
+ });
982
1144
  }
983
1145
  else if (currency === "") {
984
- errors.push({ row: rowNumber, field: "currency", code: "BAD_CURRENCY", message: `第 ${rowNumber} 行币种无法识别(收到「${currencyRaw}」):请填三字母代码(如 CNY/USD)或常见中文名(人民币/美元/欧元/港币/日元/英镑)` });
1146
+ errors.push({
1147
+ row: rowNumber,
1148
+ field: "currency",
1149
+ code: "BAD_CURRENCY",
1150
+ message: `第 ${rowNumber} 行币种无法识别(收到「${currencyRaw}」):请填三字母代码(如 CNY/USD)或常见中文名(人民币/美元/欧元/港币/日元/英镑)`,
1151
+ });
985
1152
  }
986
1153
  const validRaw = cellOf(row, "valid_until");
987
1154
  const validUntil = parseCellDate(validRaw, { endOfDay: true });
988
1155
  if (validRaw === "") {
989
- errors.push({ row: rowNumber, field: "valid_until", code: "EMPTY_REQUIRED", message: `第 ${rowNumber} 行有效期至为空:请填商品可报价的截止日期(如 2027-12-31)` });
1156
+ errors.push({
1157
+ row: rowNumber,
1158
+ field: "valid_until",
1159
+ code: "EMPTY_REQUIRED",
1160
+ message: `第 ${rowNumber} 行有效期至为空:请填商品可报价的截止日期(如 2027-12-31)`,
1161
+ });
990
1162
  }
991
1163
  else if (validUntil === "") {
992
- errors.push({ row: rowNumber, field: "valid_until", code: "BAD_DATE", message: `第 ${rowNumber} 行有效期不是合法日期(收到「${validRaw}」):请用 2027-12-31、2027/12/31 或 2027年12月31日 格式` });
1164
+ errors.push({
1165
+ row: rowNumber,
1166
+ field: "valid_until",
1167
+ code: "BAD_DATE",
1168
+ message: `第 ${rowNumber} 行有效期不是合法日期(收到「${validRaw}」):请用 2027-12-31、2027/12/31 或 2027年12月31日 格式`,
1169
+ });
993
1170
  }
994
1171
  const updatedRaw = cellOf(row, "updated_at");
995
1172
  const updatedAt = updatedRaw === "" ? now().toISOString() : parseCellDate(updatedRaw, { endOfDay: false });
996
1173
  if (updatedRaw !== "" && updatedAt === "") {
997
- errors.push({ row: rowNumber, field: "updated_at", code: "BAD_DATE", message: `第 ${rowNumber} 行更新时间不是合法日期(收到「${updatedRaw}」):留空将自动使用导入时间` });
1174
+ errors.push({
1175
+ row: rowNumber,
1176
+ field: "updated_at",
1177
+ code: "BAD_DATE",
1178
+ message: `第 ${rowNumber} 行更新时间不是合法日期(收到「${updatedRaw}」):留空将自动使用导入时间`,
1179
+ });
998
1180
  }
999
1181
  const statusRaw = cellOf(row, "status");
1000
1182
  const status = statusRaw === "" ? "active" : parseCellStatus(statusRaw);
1001
1183
  if (statusRaw !== "" && status === "") {
1002
- errors.push({ row: rowNumber, field: "status", code: "BAD_STATUS", message: `第 ${rowNumber} 行状态无法识别(收到「${statusRaw}」):留空=在售;或填 在售/暂停` });
1184
+ errors.push({
1185
+ row: rowNumber,
1186
+ field: "status",
1187
+ code: "BAD_STATUS",
1188
+ message: `第 ${rowNumber} 行状态无法识别(收到「${statusRaw}」):留空=在售;或填 在售/暂停`,
1189
+ });
1003
1190
  }
1004
1191
  const moqRaw = cellOf(row, "moq");
1005
1192
  let moq;
1006
1193
  if (moqRaw !== "") {
1007
1194
  const parsed = parseCellNumber(moqRaw);
1008
1195
  if (Number.isNaN(parsed) || !Number.isInteger(parsed) || parsed <= 0) {
1009
- errors.push({ row: rowNumber, field: "moq", code: "BAD_NUMBER", message: `第 ${rowNumber} 行起订量必须是正整数(收到「${moqRaw}」)` });
1196
+ errors.push({
1197
+ row: rowNumber,
1198
+ field: "moq",
1199
+ code: "BAD_NUMBER",
1200
+ message: `第 ${rowNumber} 行起订量必须是正整数(收到「${moqRaw}」)`,
1201
+ });
1010
1202
  }
1011
1203
  else {
1012
1204
  moq = parsed;
@@ -1017,16 +1209,58 @@ export function convertTabularImport(input, options) {
1017
1209
  if (stockRaw !== "") {
1018
1210
  const parsed = parseCellNumber(stockRaw);
1019
1211
  if (Number.isNaN(parsed) || !Number.isInteger(parsed) || parsed < 0) {
1020
- errors.push({ row: rowNumber, field: "stock", code: "BAD_NUMBER", message: `第 ${rowNumber} 行库存必须是非负整数(收到「${stockRaw}」);不确定就留空,不要填 0 冒充` });
1212
+ errors.push({
1213
+ row: rowNumber,
1214
+ field: "stock",
1215
+ code: "BAD_NUMBER",
1216
+ message: `第 ${rowNumber} 行库存必须是非负整数(收到「${stockRaw}」);不确定就留空,不要填 0 冒充`,
1217
+ });
1021
1218
  }
1022
1219
  else {
1023
1220
  stock = parsed;
1024
1221
  }
1025
1222
  }
1223
+ let tradeFields = {};
1224
+ const platformRaw = cellOf(row, "trade_platform");
1225
+ const productIdRaw = cellOf(row, "platform_product_id");
1226
+ const productIdColumn = columnIndex.get("platform_product_id");
1227
+ if (productIdRaw !== "" &&
1228
+ productIdColumn !== undefined &&
1229
+ nonTextCells.has(`${index}:${productIdColumn}`)) {
1230
+ errors.push({
1231
+ row: rowNumber,
1232
+ field: "platform_product_id",
1233
+ code: "BAD_PLATFORM_PRODUCT_ID_TYPE",
1234
+ message: `第 ${rowNumber} 行平台商品ID必须是文本单元格,不能用数字或公式;请从平台重新复制准确ID到文本列`,
1235
+ });
1236
+ }
1237
+ else {
1238
+ try {
1239
+ tradeFields = parseMarketplaceProductFields({
1240
+ trade_platform: platformRaw,
1241
+ platform_product_id: productIdRaw,
1242
+ });
1243
+ }
1244
+ catch (error) {
1245
+ if (!(error instanceof MarketplaceProductLinkError))
1246
+ throw error;
1247
+ errors.push({
1248
+ row: rowNumber,
1249
+ field: error.field,
1250
+ code: "BAD_PRODUCT_TRADE_ENTRY",
1251
+ message: `第 ${rowNumber} 行:${error.message}`,
1252
+ });
1253
+ }
1254
+ }
1026
1255
  if (sku !== "") {
1027
1256
  const firstRow = skuRows.get(sku);
1028
1257
  if (firstRow !== undefined) {
1029
- errors.push({ row: rowNumber, field: "sku", code: "DUPLICATE_SKU", message: `第 ${rowNumber} 行商品编号「${sku}」与第 ${firstRow} 行重复:同一 SKU 只能出现一次` });
1258
+ errors.push({
1259
+ row: rowNumber,
1260
+ field: "sku",
1261
+ code: "DUPLICATE_SKU",
1262
+ message: `第 ${rowNumber} 行商品编号「${sku}」与第 ${firstRow} 行重复:同一 SKU 只能出现一次`,
1263
+ });
1030
1264
  }
1031
1265
  else {
1032
1266
  skuRows.set(sku, rowNumber);
@@ -1037,13 +1271,14 @@ export function convertTabularImport(input, options) {
1037
1271
  title,
1038
1272
  currency: currency === "" ? currencyRaw : currency,
1039
1273
  unit,
1040
- price: Number.isNaN(price) ? 0 : Math.round(price * 100) / 100,
1274
+ price: Number.isNaN(price) ? 0 : price,
1041
1275
  ...(moq !== undefined ? { moq } : {}),
1042
1276
  ...(stock !== undefined ? { stock } : {}),
1043
1277
  ...(cellOf(row, "supply_note") !== "" ? { supply_note: cellOf(row, "supply_note") } : {}),
1044
1278
  updated_at: updatedAt === "" ? now().toISOString() : updatedAt,
1045
1279
  valid_until: validUntil === "" ? validRaw : validUntil,
1046
1280
  status: status === "" ? "active" : status,
1281
+ ...tradeFields,
1047
1282
  });
1048
1283
  }
1049
1284
  if (errors.length > 0)
@@ -1066,7 +1301,11 @@ export function convertTabularImport(input, options) {
1066
1301
  }
1067
1302
  catch (err) {
1068
1303
  const message = err instanceof ProductTableError ? err.message : String(err);
1069
- return { ok: false, report, errors: [{ code: "TABLE_INVALID", message: `转换结果未通过商品表校验:${message}` }] };
1304
+ return {
1305
+ ok: false,
1306
+ report,
1307
+ errors: [{ code: "TABLE_INVALID", message: `转换结果未通过商品表校验:${message}` }],
1308
+ };
1070
1309
  }
1071
1310
  return { ok: true, table, report, errors: [] };
1072
1311
  }