@harrylabsj/kiwi 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (531) hide show
  1. package/README.md +4 -1
  2. package/contracts/card-publication/0.1.2/request.schema.json +78 -0
  3. package/contracts/kiwi-contracts.lock.json +2 -2
  4. package/contracts/manifest.json +127 -1
  5. package/contracts/merchant-management/1.0/README.md +109 -0
  6. package/contracts/merchant-management/1.0/approval-decision.schema.json +16 -0
  7. package/contracts/merchant-management/1.0/approval-preview.schema.json +26 -0
  8. package/contracts/merchant-management/1.0/connector-delivery-manifest.schema.json +78 -0
  9. package/contracts/merchant-management/1.0/management-error.schema.json +30 -0
  10. package/contracts/merchant-management/1.0/operation-receipt.schema.json +28 -0
  11. package/contracts/merchant-management/1.0/runtime-management-descriptor.schema.json +33 -0
  12. package/contracts/merchant-management/1.0/runtime-status.schema.json +42 -0
  13. package/contracts/merchant-rfq/0.1.0/delivery-record.schema.json +206 -0
  14. package/contracts/merchant-rfq/0.1.0/fact-snapshot.schema.json +118 -0
  15. package/contracts/merchant-rfq/0.1.0/handoff-record.schema.json +251 -0
  16. package/contracts/merchant-rfq/0.1.0/pricing-input.schema.json +139 -0
  17. package/contracts/merchant-rfq/0.1.0/quote-revision.schema.json +153 -0
  18. package/contracts/merchant-rfq/0.1.0/release-request.schema.json +121 -0
  19. package/contracts/merchant-rfq/0.1.0/rfq-case.schema.json +357 -0
  20. package/contracts/merchant-rfq/0.1.0/source-record.schema.json +162 -0
  21. package/contracts/merchant-workbench/1.0/README.md +6 -0
  22. package/contracts/merchant-workbench/1.0/money.schema.json +19 -0
  23. package/contracts/merchant-workbench/1.0/problem.schema.json +73 -0
  24. package/contracts/runtime-binding/0.1.2/binding-request.schema.json +73 -0
  25. package/contracts/runtime-binding/0.1.2/claims.schema.json +100 -0
  26. package/contracts/runtime-binding/0.1.2/document.schema.json +163 -0
  27. package/contracts/vectors/binding-thumbprint.json +15 -0
  28. package/dist/a2a/node.d.ts +98 -2
  29. package/dist/a2a/node.js +252 -100
  30. package/dist/a2a/node.js.map +1 -1
  31. package/dist/a2a/server/errors.d.ts +8 -0
  32. package/dist/a2a/server/errors.js +8 -0
  33. package/dist/a2a/server/errors.js.map +1 -1
  34. package/dist/a2a/server/merchant-handler.d.ts +13 -0
  35. package/dist/a2a/server/merchant-handler.js +294 -47
  36. package/dist/a2a/server/merchant-handler.js.map +1 -1
  37. package/dist/a2a/server/pipeline.d.ts +15 -10
  38. package/dist/a2a/server/pipeline.js +49 -18
  39. package/dist/a2a/server/pipeline.js.map +1 -1
  40. package/dist/a2a/server/server.d.ts +20 -1
  41. package/dist/a2a/server/server.js +87 -13
  42. package/dist/a2a/server/server.js.map +1 -1
  43. package/dist/a2a/server/task-registry.d.ts +31 -11
  44. package/dist/a2a/server/task-registry.js +65 -20
  45. package/dist/a2a/server/task-registry.js.map +1 -1
  46. package/dist/a2a/server/types.d.ts +24 -0
  47. package/dist/a2a/signing-key.d.ts +6 -0
  48. package/dist/a2a/signing-key.js +12 -0
  49. package/dist/a2a/signing-key.js.map +1 -1
  50. package/dist/agent/buyer/buyer-tools.d.ts +2 -2
  51. package/dist/agent/buyer/buyer-tools.js +1 -1
  52. package/dist/agent/buyer/buyer-tools.js.map +1 -1
  53. package/dist/agent/chat-tools.d.ts +2 -11
  54. package/dist/agent/chat-tools.js.map +1 -1
  55. package/dist/agent/fake-chat-model.d.ts +3 -3
  56. package/dist/agent/fake-chat-model.js +3 -5
  57. package/dist/agent/fake-chat-model.js.map +1 -1
  58. package/dist/agent/host/web-renderer.d.ts +5 -0
  59. package/dist/agent/host/web-renderer.js +25 -6
  60. package/dist/agent/host/web-renderer.js.map +1 -1
  61. package/dist/agent/kernel-builder.js +4 -4
  62. package/dist/agent/kernel-builder.js.map +1 -1
  63. package/dist/agent/kernel.d.ts +15 -5
  64. package/dist/agent/kernel.js +149 -73
  65. package/dist/agent/kernel.js.map +1 -1
  66. package/dist/agent/kiwi-tool.d.ts +33 -0
  67. package/dist/agent/kiwi-tool.js +17 -0
  68. package/dist/agent/kiwi-tool.js.map +1 -0
  69. package/dist/agent/memory/schema.d.ts +1 -1
  70. package/dist/agent/memory/schema.js +190 -1
  71. package/dist/agent/memory/schema.js.map +1 -1
  72. package/dist/agent/memory/store.js +3 -1
  73. package/dist/agent/memory/store.js.map +1 -1
  74. package/dist/agent/merchant/action-candidate.d.ts +1 -0
  75. package/dist/agent/merchant/action-candidate.js +42 -24
  76. package/dist/agent/merchant/action-candidate.js.map +1 -1
  77. package/dist/agent/merchant/fake-merchant-client.d.ts +30 -1
  78. package/dist/agent/merchant/fake-merchant-client.js +151 -2
  79. package/dist/agent/merchant/fake-merchant-client.js.map +1 -1
  80. package/dist/agent/merchant/intelligence/default-backend.js +2 -2
  81. package/dist/agent/merchant/intelligence/default-backend.js.map +1 -1
  82. package/dist/agent/merchant/merchant-client.d.ts +38 -5
  83. package/dist/agent/merchant/merchant-client.js +103 -8
  84. package/dist/agent/merchant/merchant-client.js.map +1 -1
  85. package/dist/agent/merchant/merchant-tools.d.ts +2 -17
  86. package/dist/agent/merchant/merchant-tools.js.map +1 -1
  87. package/dist/agent/merchant/types.d.ts +107 -0
  88. package/dist/agent/merchant/types.js +69 -0
  89. package/dist/agent/merchant/types.js.map +1 -1
  90. package/dist/agent/negotiation-chat.d.ts +3 -2
  91. package/dist/agent/negotiation-chat.js.map +1 -1
  92. package/dist/agent/session.d.ts +15 -3
  93. package/dist/agent/session.js +114 -122
  94. package/dist/agent/session.js.map +1 -1
  95. package/dist/agent/skills/tools.d.ts +2 -2
  96. package/dist/agent/skills/tools.js.map +1 -1
  97. package/dist/alerts/external-delivery.d.ts +78 -0
  98. package/dist/alerts/external-delivery.js +256 -0
  99. package/dist/alerts/external-delivery.js.map +1 -0
  100. package/dist/auth/app-oauth-callback.d.ts +38 -0
  101. package/dist/auth/app-oauth-callback.js +119 -0
  102. package/dist/auth/app-oauth-callback.js.map +1 -0
  103. package/dist/auth/merchant-oauth.js +15 -41
  104. package/dist/auth/merchant-oauth.js.map +1 -1
  105. package/dist/auth/merchant-pairing.d.ts +51 -0
  106. package/dist/auth/merchant-pairing.js +66 -16
  107. package/dist/auth/merchant-pairing.js.map +1 -1
  108. package/dist/auth/merchant-sessions.d.ts +7 -1
  109. package/dist/auth/merchant-sessions.js +25 -3
  110. package/dist/auth/merchant-sessions.js.map +1 -1
  111. package/dist/buyer-core/build-service.d.ts +3 -1
  112. package/dist/buyer-core/build-service.js +4 -1
  113. package/dist/buyer-core/build-service.js.map +1 -1
  114. package/dist/buyer-core/merchant-index.d.ts +20 -0
  115. package/dist/buyer-core/merchant-index.js +83 -12
  116. package/dist/buyer-core/merchant-index.js.map +1 -1
  117. package/dist/buyer-core/network-search.d.ts +92 -0
  118. package/dist/buyer-core/network-search.js +144 -0
  119. package/dist/buyer-core/network-search.js.map +1 -0
  120. package/dist/buyer-core/product-summary.d.ts +71 -0
  121. package/dist/buyer-core/product-summary.js +63 -0
  122. package/dist/buyer-core/product-summary.js.map +1 -0
  123. package/dist/buyer-core/service.d.ts +26 -0
  124. package/dist/buyer-core/service.js +38 -8
  125. package/dist/buyer-core/service.js.map +1 -1
  126. package/dist/cli.d.ts +5 -1
  127. package/dist/cli.js +260 -274
  128. package/dist/cli.js.map +1 -1
  129. package/dist/cloud/binding/audit.d.ts +72 -0
  130. package/dist/cloud/binding/audit.js +137 -0
  131. package/dist/cloud/binding/audit.js.map +1 -0
  132. package/dist/cloud/binding/enrollment-challenge.d.ts +37 -0
  133. package/dist/cloud/binding/enrollment-challenge.js +153 -0
  134. package/dist/cloud/binding/enrollment-challenge.js.map +1 -0
  135. package/dist/cloud/binding/enrollment-heartbeat.d.ts +26 -0
  136. package/dist/cloud/binding/enrollment-heartbeat.js +146 -0
  137. package/dist/cloud/binding/enrollment-heartbeat.js.map +1 -0
  138. package/dist/cloud/binding/enrollment-key-recovery.d.ts +27 -0
  139. package/dist/cloud/binding/enrollment-key-recovery.js +127 -0
  140. package/dist/cloud/binding/enrollment-key-recovery.js.map +1 -0
  141. package/dist/cloud/binding/issuance.d.ts +76 -0
  142. package/dist/cloud/binding/issuance.js +121 -0
  143. package/dist/cloud/binding/issuance.js.map +1 -0
  144. package/dist/cloud/binding/proofs.d.ts +110 -0
  145. package/dist/cloud/binding/proofs.js +200 -0
  146. package/dist/cloud/binding/proofs.js.map +1 -0
  147. package/dist/cloud/binding/runtime-challenge.d.ts +48 -0
  148. package/dist/cloud/binding/runtime-challenge.js +185 -0
  149. package/dist/cloud/binding/runtime-challenge.js.map +1 -0
  150. package/dist/cloud/bootstrap.d.ts +63 -0
  151. package/dist/cloud/bootstrap.js +1161 -0
  152. package/dist/cloud/bootstrap.js.map +1 -0
  153. package/dist/cloud/catalog-client.d.ts +305 -0
  154. package/dist/cloud/catalog-client.js +962 -0
  155. package/dist/cloud/catalog-client.js.map +1 -0
  156. package/dist/cloud/config.d.ts +103 -0
  157. package/dist/cloud/config.js +274 -0
  158. package/dist/cloud/config.js.map +1 -0
  159. package/dist/cloud/http-router.d.ts +63 -0
  160. package/dist/cloud/http-router.js +135 -0
  161. package/dist/cloud/http-router.js.map +1 -0
  162. package/dist/cloud/listing-publisher.d.ts +45 -0
  163. package/dist/cloud/listing-publisher.js +244 -0
  164. package/dist/cloud/listing-publisher.js.map +1 -0
  165. package/dist/cloud/main.d.ts +16 -0
  166. package/dist/cloud/main.js +64 -0
  167. package/dist/cloud/main.js.map +1 -0
  168. package/dist/cloud/merchant-connect.d.ts +47 -0
  169. package/dist/cloud/merchant-connect.js +331 -0
  170. package/dist/cloud/merchant-connect.js.map +1 -0
  171. package/dist/cloud/merchant-identity.d.ts +14 -0
  172. package/dist/cloud/merchant-identity.js +76 -0
  173. package/dist/cloud/merchant-identity.js.map +1 -0
  174. package/dist/cloud/onboarding/catalog-pipeline.d.ts +135 -0
  175. package/dist/cloud/onboarding/catalog-pipeline.js +454 -0
  176. package/dist/cloud/onboarding/catalog-pipeline.js.map +1 -0
  177. package/dist/cloud/onboarding/local-fallback.d.ts +86 -0
  178. package/dist/cloud/onboarding/local-fallback.js +98 -0
  179. package/dist/cloud/onboarding/local-fallback.js.map +1 -0
  180. package/dist/cloud/onboarding/steps.d.ts +95 -0
  181. package/dist/cloud/onboarding/steps.js +175 -0
  182. package/dist/cloud/onboarding/steps.js.map +1 -0
  183. package/dist/cloud/onboarding/store.d.ts +136 -0
  184. package/dist/cloud/onboarding/store.js +472 -0
  185. package/dist/cloud/onboarding/store.js.map +1 -0
  186. package/dist/cloud/onboarding/types.d.ts +132 -0
  187. package/dist/cloud/onboarding/types.js +152 -0
  188. package/dist/cloud/onboarding/types.js.map +1 -0
  189. package/dist/cloud/product-import-tabular.d.ts +100 -0
  190. package/dist/cloud/product-import-tabular.js +1073 -0
  191. package/dist/cloud/product-import-tabular.js.map +1 -0
  192. package/dist/cloud/product-source.d.ts +104 -0
  193. package/dist/cloud/product-source.js +276 -0
  194. package/dist/cloud/product-source.js.map +1 -0
  195. package/dist/cloud/readiness.d.ts +49 -0
  196. package/dist/cloud/readiness.js +54 -0
  197. package/dist/cloud/readiness.js.map +1 -0
  198. package/dist/commerce/data-source.d.ts +5 -0
  199. package/dist/commerce/data-source.js.map +1 -1
  200. package/dist/config/profile.d.ts +4 -0
  201. package/dist/config/profile.js +14 -0
  202. package/dist/config/profile.js.map +1 -1
  203. package/dist/config/provider-kind.d.ts +26 -0
  204. package/dist/config/provider-kind.js +19 -0
  205. package/dist/config/provider-kind.js.map +1 -0
  206. package/dist/contracts/cloud-contracts.d.ts +23 -0
  207. package/dist/contracts/cloud-contracts.js +90 -0
  208. package/dist/contracts/cloud-contracts.js.map +1 -0
  209. package/dist/counterparty/a2a-direct/index.d.ts +3 -0
  210. package/dist/counterparty/a2a-direct/index.js +22 -6
  211. package/dist/counterparty/a2a-direct/index.js.map +1 -1
  212. package/dist/counterparty/registry.d.ts +2 -0
  213. package/dist/counterparty/registry.js +2 -0
  214. package/dist/counterparty/registry.js.map +1 -1
  215. package/dist/counterparty/shopping-cli-hosted/index.d.ts +3 -0
  216. package/dist/counterparty/shopping-cli-hosted/index.js +9 -2
  217. package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -1
  218. package/dist/discovery/catalog-source/buyer-follows.js +2 -2
  219. package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
  220. package/dist/discovery/catalog-source/cloud-card.d.ts +184 -0
  221. package/dist/discovery/catalog-source/cloud-card.js +385 -0
  222. package/dist/discovery/catalog-source/cloud-card.js.map +1 -0
  223. package/dist/discovery/catalog-source/cloud-hosting.d.ts +71 -0
  224. package/dist/discovery/catalog-source/cloud-hosting.js +70 -0
  225. package/dist/discovery/catalog-source/cloud-hosting.js.map +1 -0
  226. package/dist/discovery/catalog-source/errors.d.ts +12 -2
  227. package/dist/discovery/catalog-source/errors.js +14 -1
  228. package/dist/discovery/catalog-source/errors.js.map +1 -1
  229. package/dist/discovery/catalog-source/index.d.ts +2 -0
  230. package/dist/discovery/catalog-source/index.js +2 -0
  231. package/dist/discovery/catalog-source/index.js.map +1 -1
  232. package/dist/discovery/catalog-source/kiwi-source.js +2 -2
  233. package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
  234. package/dist/discovery/catalog-source/merchant-publications.d.ts +2 -2
  235. package/dist/discovery/catalog-source/merchant-publications.js +10 -5
  236. package/dist/discovery/catalog-source/merchant-publications.js.map +1 -1
  237. package/dist/discovery/catalog-source/source.js +2 -2
  238. package/dist/discovery/catalog-source/source.js.map +1 -1
  239. package/dist/discovery/merchant-subscriptions.d.ts +45 -0
  240. package/dist/discovery/merchant-subscriptions.js +319 -0
  241. package/dist/discovery/merchant-subscriptions.js.map +1 -0
  242. package/dist/discovery/resolve.d.ts +38 -0
  243. package/dist/discovery/resolve.js +100 -7
  244. package/dist/discovery/resolve.js.map +1 -1
  245. package/dist/fanout/orchestrator.d.ts +2 -0
  246. package/dist/fanout/orchestrator.js +4 -1
  247. package/dist/fanout/orchestrator.js.map +1 -1
  248. package/dist/handoff/ledger.d.ts +1 -0
  249. package/dist/handoff/ledger.js +3 -0
  250. package/dist/handoff/ledger.js.map +1 -1
  251. package/dist/handoff/transaction.js +1 -1
  252. package/dist/handoff/transaction.js.map +1 -1
  253. package/dist/http/merchant-engagement-api.d.ts +10 -0
  254. package/dist/http/merchant-engagement-api.js +138 -0
  255. package/dist/http/merchant-engagement-api.js.map +1 -0
  256. package/dist/http/merchant-feed-api.d.ts +7 -0
  257. package/dist/http/merchant-feed-api.js +129 -0
  258. package/dist/http/merchant-feed-api.js.map +1 -0
  259. package/dist/http/merchant-follow-api.d.ts +15 -0
  260. package/dist/http/merchant-follow-api.js +192 -0
  261. package/dist/http/merchant-follow-api.js.map +1 -0
  262. package/dist/http/merchant-management/api.d.ts +258 -0
  263. package/dist/http/merchant-management/api.js +3022 -0
  264. package/dist/http/merchant-management/api.js.map +1 -0
  265. package/dist/http/merchant-management/draft-store.d.ts +51 -0
  266. package/dist/http/merchant-management/draft-store.js +95 -0
  267. package/dist/http/merchant-management/draft-store.js.map +1 -0
  268. package/dist/http/merchant-management/event-projection.d.ts +41 -0
  269. package/dist/http/merchant-management/event-projection.js +190 -0
  270. package/dist/http/merchant-management/event-projection.js.map +1 -0
  271. package/dist/http/merchant-management/operation-store.d.ts +97 -0
  272. package/dist/http/merchant-management/operation-store.js +252 -0
  273. package/dist/http/merchant-management/operation-store.js.map +1 -0
  274. package/dist/http/merchant-management/page.d.ts +29 -0
  275. package/dist/http/merchant-management/page.js +641 -0
  276. package/dist/http/merchant-management/page.js.map +1 -0
  277. package/dist/http/merchant-management/problem-client.d.ts +19 -0
  278. package/dist/http/merchant-management/problem-client.js +55 -0
  279. package/dist/http/merchant-management/problem-client.js.map +1 -0
  280. package/dist/http/merchant-management/problem.d.ts +74 -0
  281. package/dist/http/merchant-management/problem.js +112 -0
  282. package/dist/http/merchant-management/problem.js.map +1 -0
  283. package/dist/http/merchant-management/reconciliation-worker.d.ts +95 -0
  284. package/dist/http/merchant-management/reconciliation-worker.js +397 -0
  285. package/dist/http/merchant-management/reconciliation-worker.js.map +1 -0
  286. package/dist/http/merchant-management/service-state.d.ts +86 -0
  287. package/dist/http/merchant-management/service-state.js +217 -0
  288. package/dist/http/merchant-management/service-state.js.map +1 -0
  289. package/dist/http/merchant-management/trusted-page.d.ts +3 -0
  290. package/dist/http/merchant-management/trusted-page.js +73 -0
  291. package/dist/http/merchant-management/trusted-page.js.map +1 -0
  292. package/dist/http/merchant-management/webauthn-confirmation.d.ts +148 -0
  293. package/dist/http/merchant-management/webauthn-confirmation.js +517 -0
  294. package/dist/http/merchant-management/webauthn-confirmation.js.map +1 -0
  295. package/dist/http/merchant-privacy-api.d.ts +9 -0
  296. package/dist/http/merchant-privacy-api.js +96 -0
  297. package/dist/http/merchant-privacy-api.js.map +1 -0
  298. package/dist/mcp/merchant-rfq-resources.d.ts +37 -0
  299. package/dist/mcp/merchant-rfq-resources.js +132 -0
  300. package/dist/mcp/merchant-rfq-resources.js.map +1 -0
  301. package/dist/mcp/merchant-rfq-tools.d.ts +61 -0
  302. package/dist/mcp/merchant-rfq-tools.js +584 -0
  303. package/dist/mcp/merchant-rfq-tools.js.map +1 -0
  304. package/dist/mcp/merchant-runtime-assembly.d.ts +74 -0
  305. package/dist/mcp/merchant-runtime-assembly.js +476 -0
  306. package/dist/mcp/merchant-runtime-assembly.js.map +1 -0
  307. package/dist/mcp/merchant-server.d.ts +66 -1
  308. package/dist/mcp/merchant-server.js +260 -23
  309. package/dist/mcp/merchant-server.js.map +1 -1
  310. package/dist/mcp/tools.js +8 -2
  311. package/dist/mcp/tools.js.map +1 -1
  312. package/dist/merchant/application/actor.d.ts +85 -0
  313. package/dist/merchant/application/actor.js +162 -0
  314. package/dist/merchant/application/actor.js.map +1 -0
  315. package/dist/merchant/application/money.d.ts +35 -0
  316. package/dist/merchant/application/money.js +124 -0
  317. package/dist/merchant/application/money.js.map +1 -0
  318. package/dist/merchant/application/service.d.ts +228 -0
  319. package/dist/merchant/application/service.js +262 -0
  320. package/dist/merchant/application/service.js.map +1 -0
  321. package/dist/merchant/clock-safety.d.ts +50 -0
  322. package/dist/merchant/clock-safety.js +153 -0
  323. package/dist/merchant/clock-safety.js.map +1 -0
  324. package/dist/merchant/engagement-store.d.ts +32 -0
  325. package/dist/merchant/engagement-store.js +119 -0
  326. package/dist/merchant/engagement-store.js.map +1 -0
  327. package/dist/merchant/exact-product-executors.d.ts +11 -0
  328. package/dist/merchant/exact-product-executors.js +132 -0
  329. package/dist/merchant/exact-product-executors.js.map +1 -0
  330. package/dist/merchant/feed-executors.d.ts +17 -0
  331. package/dist/merchant/feed-executors.js +151 -0
  332. package/dist/merchant/feed-executors.js.map +1 -0
  333. package/dist/merchant/feed-store.d.ts +141 -0
  334. package/dist/merchant/feed-store.js +496 -0
  335. package/dist/merchant/feed-store.js.map +1 -0
  336. package/dist/merchant/follow-store.d.ts +66 -0
  337. package/dist/merchant/follow-store.js +295 -0
  338. package/dist/merchant/follow-store.js.map +1 -0
  339. package/dist/merchant/grant-executors.d.ts +11 -0
  340. package/dist/merchant/grant-executors.js +136 -0
  341. package/dist/merchant/grant-executors.js.map +1 -0
  342. package/dist/merchant/grant-store.d.ts +125 -0
  343. package/dist/merchant/grant-store.js +313 -0
  344. package/dist/merchant/grant-store.js.map +1 -0
  345. package/dist/merchant/inventory-executors.d.ts +47 -0
  346. package/dist/merchant/inventory-executors.js +91 -0
  347. package/dist/merchant/inventory-executors.js.map +1 -0
  348. package/dist/merchant/listing-executors.d.ts +51 -0
  349. package/dist/merchant/listing-executors.js +100 -0
  350. package/dist/merchant/listing-executors.js.map +1 -0
  351. package/dist/merchant/negotiation-observer.d.ts +92 -0
  352. package/dist/merchant/negotiation-observer.js +278 -0
  353. package/dist/merchant/negotiation-observer.js.map +1 -0
  354. package/dist/merchant/operation-receipts.d.ts +57 -0
  355. package/dist/merchant/operation-receipts.js +138 -0
  356. package/dist/merchant/operation-receipts.js.map +1 -0
  357. package/dist/merchant/operations-report.d.ts +85 -0
  358. package/dist/merchant/operations-report.js +227 -0
  359. package/dist/merchant/operations-report.js.map +1 -0
  360. package/dist/merchant/promotion-broadcast-recovery.d.ts +22 -0
  361. package/dist/merchant/promotion-broadcast-recovery.js +74 -0
  362. package/dist/merchant/promotion-broadcast-recovery.js.map +1 -0
  363. package/dist/merchant/promotion-broadcast-workflow.d.ts +42 -0
  364. package/dist/merchant/promotion-broadcast-workflow.js +171 -0
  365. package/dist/merchant/promotion-broadcast-workflow.js.map +1 -0
  366. package/dist/merchant/promotion-executors.d.ts +18 -0
  367. package/dist/merchant/promotion-executors.js +133 -0
  368. package/dist/merchant/promotion-executors.js.map +1 -0
  369. package/dist/merchant/promotion-store.d.ts +114 -0
  370. package/dist/merchant/promotion-store.js +325 -0
  371. package/dist/merchant/promotion-store.js.map +1 -0
  372. package/dist/merchant/promotion-time.d.ts +19 -0
  373. package/dist/merchant/promotion-time.js +162 -0
  374. package/dist/merchant/promotion-time.js.map +1 -0
  375. package/dist/merchant/quote-calculator.d.ts +32 -0
  376. package/dist/merchant/quote-calculator.js +70 -0
  377. package/dist/merchant/quote-calculator.js.map +1 -0
  378. package/dist/merchant/service-control-executors.d.ts +15 -0
  379. package/dist/merchant/service-control-executors.js +52 -0
  380. package/dist/merchant/service-control-executors.js.map +1 -0
  381. package/dist/merchant/stats-store.d.ts +5 -0
  382. package/dist/merchant/stats-store.js +18 -0
  383. package/dist/merchant/stats-store.js.map +1 -1
  384. package/dist/merchant/workbench-service.d.ts +1 -0
  385. package/dist/merchant/workbench-service.js +11 -1
  386. package/dist/merchant/workbench-service.js.map +1 -1
  387. package/dist/merchant-admin/pending-page.d.ts +104 -0
  388. package/dist/merchant-admin/pending-page.js +20 -0
  389. package/dist/merchant-admin/pending-page.js.map +1 -1
  390. package/dist/merchant-admin/rfq-page.d.ts +105 -0
  391. package/dist/merchant-admin/rfq-page.js +176 -0
  392. package/dist/merchant-admin/rfq-page.js.map +1 -0
  393. package/dist/merchant-core/commands.d.ts +27 -0
  394. package/dist/merchant-core/commands.js +90 -1
  395. package/dist/merchant-core/commands.js.map +1 -1
  396. package/dist/merchant-core/executor.d.ts +27 -3
  397. package/dist/merchant-core/executor.js +13 -4
  398. package/dist/merchant-core/executor.js.map +1 -1
  399. package/dist/merchant-core/rfq/artifacts.d.ts +78 -0
  400. package/dist/merchant-core/rfq/artifacts.js +219 -0
  401. package/dist/merchant-core/rfq/artifacts.js.map +1 -0
  402. package/dist/merchant-core/rfq/data-source-adapter.d.ts +49 -0
  403. package/dist/merchant-core/rfq/data-source-adapter.js +128 -0
  404. package/dist/merchant-core/rfq/data-source-adapter.js.map +1 -0
  405. package/dist/merchant-core/rfq/delivery.d.ts +43 -0
  406. package/dist/merchant-core/rfq/delivery.js +57 -0
  407. package/dist/merchant-core/rfq/delivery.js.map +1 -0
  408. package/dist/merchant-core/rfq/fact-resolver.d.ts +76 -0
  409. package/dist/merchant-core/rfq/fact-resolver.js +220 -0
  410. package/dist/merchant-core/rfq/fact-resolver.js.map +1 -0
  411. package/dist/merchant-core/rfq/handoff.d.ts +54 -0
  412. package/dist/merchant-core/rfq/handoff.js +71 -0
  413. package/dist/merchant-core/rfq/handoff.js.map +1 -0
  414. package/dist/merchant-core/rfq/policy.d.ts +77 -0
  415. package/dist/merchant-core/rfq/policy.js +104 -0
  416. package/dist/merchant-core/rfq/policy.js.map +1 -0
  417. package/dist/merchant-core/rfq/pricing.d.ts +48 -0
  418. package/dist/merchant-core/rfq/pricing.js +150 -0
  419. package/dist/merchant-core/rfq/pricing.js.map +1 -0
  420. package/dist/merchant-core/rfq/quote-revisions.d.ts +52 -0
  421. package/dist/merchant-core/rfq/quote-revisions.js +126 -0
  422. package/dist/merchant-core/rfq/quote-revisions.js.map +1 -0
  423. package/dist/merchant-core/rfq/release-coordinator.d.ts +99 -0
  424. package/dist/merchant-core/rfq/release-coordinator.js +355 -0
  425. package/dist/merchant-core/rfq/release-coordinator.js.map +1 -0
  426. package/dist/merchant-core/rfq/repository.d.ts +398 -0
  427. package/dist/merchant-core/rfq/repository.js +855 -0
  428. package/dist/merchant-core/rfq/repository.js.map +1 -0
  429. package/dist/merchant-core/rfq/service.d.ts +398 -0
  430. package/dist/merchant-core/rfq/service.js +1036 -0
  431. package/dist/merchant-core/rfq/service.js.map +1 -0
  432. package/dist/merchant-core/rfq/source-records.d.ts +97 -0
  433. package/dist/merchant-core/rfq/source-records.js +349 -0
  434. package/dist/merchant-core/rfq/source-records.js.map +1 -0
  435. package/dist/merchant-core/rfq/types.d.ts +197 -0
  436. package/dist/merchant-core/rfq/types.js +110 -0
  437. package/dist/merchant-core/rfq/types.js.map +1 -0
  438. package/dist/merchant-core/service.d.ts +118 -1
  439. package/dist/merchant-core/service.js +202 -7
  440. package/dist/merchant-core/service.js.map +1 -1
  441. package/dist/merchant-core/storage/clock-skew-alerts.d.ts +21 -0
  442. package/dist/merchant-core/storage/clock-skew-alerts.js +67 -0
  443. package/dist/merchant-core/storage/clock-skew-alerts.js.map +1 -0
  444. package/dist/merchant-core/storage/leased-job.d.ts +42 -0
  445. package/dist/merchant-core/storage/leased-job.js +38 -0
  446. package/dist/merchant-core/storage/leased-job.js.map +1 -0
  447. package/dist/merchant-core/storage/operation-lifecycle.d.ts +78 -0
  448. package/dist/merchant-core/storage/operation-lifecycle.js +111 -0
  449. package/dist/merchant-core/storage/operation-lifecycle.js.map +1 -0
  450. package/dist/merchant-core/storage/redact.d.ts +29 -0
  451. package/dist/merchant-core/storage/redact.js +34 -0
  452. package/dist/merchant-core/storage/redact.js.map +1 -0
  453. package/dist/merchant-core/storage/schema.d.ts +24 -0
  454. package/dist/merchant-core/storage/schema.js +22 -0
  455. package/dist/merchant-core/storage/schema.js.map +1 -0
  456. package/dist/merchant-core/storage/transaction.d.ts +47 -0
  457. package/dist/merchant-core/storage/transaction.js +28 -0
  458. package/dist/merchant-core/storage/transaction.js.map +1 -0
  459. package/dist/merchant-gateway/catalog-publications.d.ts +28 -0
  460. package/dist/merchant-gateway/catalog-publications.js +69 -0
  461. package/dist/merchant-gateway/catalog-publications.js.map +1 -1
  462. package/dist/merchant-gateway/catalog-tools.js +20 -0
  463. package/dist/merchant-gateway/catalog-tools.js.map +1 -1
  464. package/dist/merchant-gateway/entry-server.js +10 -0
  465. package/dist/merchant-gateway/entry-server.js.map +1 -1
  466. package/dist/negotiation/domain/objects.d.ts +7 -0
  467. package/dist/negotiation/domain/objects.js +8 -0
  468. package/dist/negotiation/domain/objects.js.map +1 -1
  469. package/dist/negotiation/idempotency/store.d.ts +23 -0
  470. package/dist/negotiation/idempotency/store.js +72 -1
  471. package/dist/negotiation/idempotency/store.js.map +1 -1
  472. package/dist/negotiation/idempotency/types.d.ts +16 -0
  473. package/dist/negotiation/idempotency/types.js +2 -0
  474. package/dist/negotiation/idempotency/types.js.map +1 -1
  475. package/dist/negotiation/lease/store.d.ts +18 -22
  476. package/dist/negotiation/lease/store.js +152 -88
  477. package/dist/negotiation/lease/store.js.map +1 -1
  478. package/dist/negotiation/ledger/event.d.ts +6 -0
  479. package/dist/negotiation/ledger/event.js +1 -0
  480. package/dist/negotiation/ledger/event.js.map +1 -1
  481. package/dist/negotiation/ledger/index.d.ts +4 -2
  482. package/dist/negotiation/ledger/index.js +1 -0
  483. package/dist/negotiation/ledger/index.js.map +1 -1
  484. package/dist/negotiation/ledger/payload-segments.d.ts +51 -0
  485. package/dist/negotiation/ledger/payload-segments.js +247 -0
  486. package/dist/negotiation/ledger/payload-segments.js.map +1 -0
  487. package/dist/negotiation/ledger/store.d.ts +34 -0
  488. package/dist/negotiation/ledger/store.js +162 -0
  489. package/dist/negotiation/ledger/store.js.map +1 -1
  490. package/dist/negotiation/recovery/recover.js +1 -1
  491. package/dist/negotiation/recovery/recover.js.map +1 -1
  492. package/dist/privacy/ledger-payload-deletion.d.ts +10 -0
  493. package/dist/privacy/ledger-payload-deletion.js +31 -0
  494. package/dist/privacy/ledger-payload-deletion.js.map +1 -0
  495. package/dist/privacy/local-backup-deletion.d.ts +13 -0
  496. package/dist/privacy/local-backup-deletion.js +115 -0
  497. package/dist/privacy/local-backup-deletion.js.map +1 -0
  498. package/dist/privacy/workbench-retention.d.ts +105 -0
  499. package/dist/privacy/workbench-retention.js +501 -0
  500. package/dist/privacy/workbench-retention.js.map +1 -0
  501. package/dist/product-cli.d.ts +2 -2
  502. package/dist/product-cli.js +24 -9
  503. package/dist/product-cli.js.map +1 -1
  504. package/dist/product-init.d.ts +4 -1
  505. package/dist/product-init.js +39 -11
  506. package/dist/product-init.js.map +1 -1
  507. package/dist/product-publish.d.ts +8 -2
  508. package/dist/product-publish.js +222 -142
  509. package/dist/product-publish.js.map +1 -1
  510. package/dist/runtime/fake-model.js +9 -3
  511. package/dist/runtime/fake-model.js.map +1 -1
  512. package/dist/runtime/model.d.ts +1 -1
  513. package/dist/runtime/model.js +3 -3
  514. package/dist/runtime/model.js.map +1 -1
  515. package/dist/trust/binding/claims.d.ts +92 -0
  516. package/dist/trust/binding/claims.js +175 -0
  517. package/dist/trust/binding/claims.js.map +1 -0
  518. package/dist/trust/binding/thumbprint.d.ts +35 -0
  519. package/dist/trust/binding/thumbprint.js +88 -0
  520. package/dist/trust/binding/thumbprint.js.map +1 -0
  521. package/dist/trust/binding/verify.d.ts +84 -0
  522. package/dist/trust/binding/verify.js +121 -0
  523. package/dist/trust/binding/verify.js.map +1 -0
  524. package/dist/trust/identity/auth-verifier.d.ts +9 -0
  525. package/dist/trust/identity/auth-verifier.js +10 -2
  526. package/dist/trust/identity/auth-verifier.js.map +1 -1
  527. package/dist/trust/identity/jws.d.ts +22 -1
  528. package/dist/trust/identity/jws.js +31 -2
  529. package/dist/trust/identity/jws.js.map +1 -1
  530. package/package.json +17 -6
  531. package/skills/kiwi-buyer/SKILL.md +33 -2
@@ -0,0 +1,641 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * 商家工作台同源页面(BD 设计 §9.1 的 `/merchant/` 静态资源;BD-03)。
18
+ *
19
+ * 形态:**单文件静态壳**——无框架、无构建步、无外部资源;以 TS 模板常量随
20
+ * Runtime 编译进制品(不设第二份 web/ 拷贝,避免两处漂移;也不把 Node/Pi/
21
+ * 秘密带进浏览器产物——红线 9,verify:package 会核)。
22
+ *
23
+ * 边界(BD §9.1):页面壳本身不含业务数据也不做鉴权判断——所有数据经
24
+ * `/merchant/api/*` 取得,未持会话一律 401,页面只展示「请登录」入口
25
+ * (/admin/login)。`/merchant/api/*` 的 `Cache-Control: no-store` 同样
26
+ * 适用于本页(壳内嵌确认流程的中间态不留缓存)。
27
+ */
28
+ /** 页面按 owner 视角展示管理动作;角色由服务端权限逐次裁决,前端只是提示。 */
29
+ export function renderMerchantManagementPage() {
30
+ return `<!doctype html>
31
+ <html lang="zh-CN">
32
+ <head>
33
+ <meta charset="utf-8">
34
+ <meta name="viewport" content="width=device-width, initial-scale=1">
35
+ <title>商家工作台 — Kiwi</title>
36
+ <style>
37
+ :root { font-family: system-ui, -apple-system, "PingFang SC", sans-serif; }
38
+ body { margin: 0; background: #f6f7f9; color: #1c2330; }
39
+ header { background: #16324f; color: #fff; padding: 12px 20px; display: flex; gap: 16px; align-items: baseline; }
40
+ header h1 { font-size: 16px; margin: 0; font-weight: 600; }
41
+ header .who { font-size: 12px; opacity: .8; }
42
+ nav { display: flex; gap: 4px; padding: 8px 20px 0; background: #16324f; }
43
+ nav button { border: 0; padding: 8px 14px; border-radius: 6px 6px 0 0; background: #1e4066; color: #cdd8e4; cursor: pointer; font-size: 13px; }
44
+ nav button.on { background: #f6f7f9; color: #16324f; font-weight: 600; }
45
+ main { padding: 16px 20px 40px; max-width: 980px; margin: 0 auto; }
46
+ .card { background: #fff; border: 1px solid #e3e7ec; border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
47
+ .card h2 { font-size: 14px; margin: 0 0 10px; color: #3a4a5e; }
48
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
49
+ th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
50
+ th { color: #6b7a8c; font-weight: 500; white-space: nowrap; }
51
+ .pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; }
52
+ .ok { background: #e5f5ea; color: #1d7a3d; } .warn { background: #fdf1dc; color: #9a6b0f; } .bad { background: #fde8e8; color: #b3261e; }
53
+ button.act { border: 1px solid #c9d3dd; background: #fff; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px; }
54
+ button.act.primary { background: #16324f; color: #fff; border-color: #16324f; }
55
+ button.act.danger { color: #b3261e; border-color: #e5b4b1; }
56
+ #bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 20px; font-size: 13px; background: #101826; color: #dfe6ee; display: none; }
57
+ #bar.err { background: #5c1a16; }
58
+ textarea, input[type=text] { width: 100%; box-sizing: border-box; border: 1px solid #c9d3dd; border-radius: 6px; padding: 8px; font: 12px ui-monospace, monospace; }
59
+ .muted { color: #6b7a8c; font-size: 12px; }
60
+ .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
61
+ pre.digest { font: 11px ui-monospace, monospace; color: #6b7a8c; word-break: break-all; margin: 4px 0; }
62
+ label { font-weight: 400; font-size: 12px; }
63
+ select { border: 1px solid #c9d3dd; border-radius: 6px; padding: 4px 6px; font-size: 12px; background: #fff; }
64
+ .trendrow { display: flex; align-items: center; gap: 8px; margin: 3px 0; font-size: 12px; }
65
+ .trendrow > span:first-child { width: 44px; color: #6b7a8c; }
66
+ .trendbar { flex: 1; height: 10px; background: #eef1f4; border-radius: 5px; overflow: hidden; }
67
+ .trendfill { height: 100%; background: #1e4066; }
68
+ </style>
69
+ </head>
70
+ <body>
71
+ <header><h1>商家工作台</h1><span class="who" id="who"></span></header>
72
+ <nav id="tabs">
73
+ <button data-v="status" class="on">服务状态</button>
74
+ <button data-v="products">商品与导入</button>
75
+ <button data-v="approvals">待审批</button>
76
+ <button data-v="negotiations">会话旁观</button>
77
+ <button data-v="reports">运营报告</button>
78
+ <button data-v="policy">报价规则</button>
79
+ </nav>
80
+ <main id="view"><div class="card">加载中…</div></main>
81
+ <div id="bar"></div>
82
+ <script>
83
+ "use strict";
84
+ var CSRF = "";
85
+ var ROLE = "";
86
+ var API = "/merchant/api/v1";
87
+ var $ = function (id) { return document.getElementById(id); };
88
+ function esc(s) {
89
+ return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
90
+ return { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c];
91
+ });
92
+ }
93
+ function bar(msg, isErr) {
94
+ var b = $("bar");
95
+ b.textContent = msg;
96
+ b.className = isErr ? "err" : "";
97
+ b.style.display = "block";
98
+ if (!isErr) setTimeout(function () { b.style.display = "none"; }, 4000);
99
+ }
100
+ function recoveryHint(action) {
101
+ return {
102
+ none: "请勿重复操作。",
103
+ reauthenticate: "请重新登录后再试。",
104
+ refresh_resource: "请刷新页面并核对最新状态。",
105
+ confirm: "请在可信确认页完成授权。",
106
+ query_operation: "结果尚未确认,请先查询原操作状态,不要重新提交。",
107
+ retry_same_operation: "服务确认操作未生效;如需重试,请沿用原操作。",
108
+ resync_feed: "请重新同步资料游标。",
109
+ open_support: "请联系支持并提供请求编号。",
110
+ unknown: "恢复方式尚不明确,请勿自动重试。",
111
+ }[action] || "恢复方式尚不明确,请勿自动重试。";
112
+ }
113
+ async function apiError(res) {
114
+ var problem;
115
+ if ((res.headers.get("content-type") || "").toLowerCase().indexOf("application/problem+json") >= 0) {
116
+ try { problem = await res.clone().json(); } catch (_) { problem = null; }
117
+ }
118
+ if (problem && typeof problem === "object" && typeof problem.detail === "string") {
119
+ var text = problem.detail;
120
+ if (problem.operation_id) text += "(操作 " + problem.operation_id + ")";
121
+ if (problem.request_id) text += "(请求 " + problem.request_id + ")";
122
+ return new Error(text + " " + recoveryHint(problem.recovery_action));
123
+ }
124
+ var fallback = await res.json().catch(function () { return {}; });
125
+ return new Error((fallback.message || fallback.detail || fallback.code || ("HTTP " + res.status)) + "。请勿自动重复提交。");
126
+ }
127
+ function call(method, path, body) {
128
+ var headers = {};
129
+ if (body !== undefined) {
130
+ headers["content-type"] = "application/json";
131
+ if (CSRF) headers["x-csrf-token"] = CSRF;
132
+ }
133
+ return fetch(API + path, {
134
+ method: method,
135
+ credentials: "same-origin",
136
+ headers: headers,
137
+ body: body !== undefined ? JSON.stringify(body) : undefined,
138
+ }).then(function (res) {
139
+ if (!res.ok) {
140
+ if (res.status === 401) { showLogin(); throw new Error("需要登录"); }
141
+ return apiError(res).then(function (error) { throw error; });
142
+ }
143
+ return res.json();
144
+ });
145
+ }
146
+ function showLogin() {
147
+ $("view").innerHTML = '<div class="card"><h2>需要登录</h2>' +
148
+ '<p class="muted">请使用商家管理员口令登录后回到本页。</p>' +
149
+ '<p><a class="act" href="/admin/login?next=%2Fmerchant%2F"><button class="act primary">去登录</button></a></p></div>';
150
+ }
151
+ function key(p) { return p + "-" + Date.now() + "-" + Math.random().toString(36).slice(2, 8); }
152
+ function statePill(state) {
153
+ var map = { OPERATING: ["ok", "营业中"], PAUSED: ["warn", "已暂停"], WITHDRAWN: ["bad", "已撤回"], DEGRADED: ["warn", "降级"] };
154
+ var it = map[state] || ["warn", state];
155
+ return '<span class="pill ' + it[0] + '">' + esc(it[1]) + "</span>";
156
+ }
157
+
158
+ var views = {
159
+ status: function () {
160
+ return call("GET", "/runtime/status").then(function (s) {
161
+ var failed = s.readiness && s.readiness.failed_checks || [];
162
+ var html = '<div class="card"><h2>运行状态</h2><table>' +
163
+ "<tr><th>商家显示名</th><td>" + esc(s.merchant_name || "-") + "</td></tr>" +
164
+ "<tr><th>服务状态</th><td>" + statePill(s.service_state) + "</td></tr>" +
165
+ "<tr><th>部署代次</th><td>" + esc(s.generation) + "</td></tr>" +
166
+ "<tr><th>Runtime</th><td>" + esc(s.runtime_version) + "(管理 API v" + esc(s.api_version) + ")</td></tr>" +
167
+ "<tr><th>就绪</th><td>" + (s.readiness && s.readiness.ready
168
+ ? '<span class="pill ok">就绪</span>'
169
+ : '<span class="pill bad">未就绪</span> ' + esc(failed.join("、"))) + "</td></tr>" +
170
+ "<tr><th>能力</th><td>管理页 " + (s.capabilities.management_page ? "✓" : "✗") +
171
+ ";对话工具 " + (s.capabilities.dialog_tools ? "✓" : "未启用") + "</td></tr>" +
172
+ '</table><p class="muted">更新于 ' + esc(s.observed_at) + "</p>";
173
+ if (s.merchant_name_needs_update) {
174
+ html += '<p class="muted">请设置商家显示名;该名称会用于 Catalog 公开资料。</p>';
175
+ }
176
+ if (failed.indexOf("PRODUCTS_NOT_CONFIGURED") >= 0) {
177
+ html += '<p class="muted">请先导入商品。商品导入后会自动继续服务检查;当前不会报价或发布名片。</p>';
178
+ }
179
+ if (s.service_state === "OPERATING") {
180
+ html += '<div class="row"><button class="act danger" onclick="pauseService()">暂停接待</button>' +
181
+ '<span class="muted">暂停后拒新询价;既有会话不受影响。</span></div>';
182
+ } else if (s.service_state === "PAUSED") {
183
+ if (ROLE === "owner") {
184
+ html += '<div class="row"><button class="act primary" onclick="resumeService()">恢复接待</button>' +
185
+ '<span class="muted">恢复需通过就绪检查(owner)。</span></div>';
186
+ } else {
187
+ html += '<p class="muted">恢复接待需要 owner 角色。</p>';
188
+ }
189
+ }
190
+ return html + "</div>";
191
+ });
192
+ },
193
+ products: function () {
194
+ return call("GET", "/products?limit=100").then(function (p) {
195
+ var rows = (p.items || []).map(function (it) {
196
+ var money = it.money || {};
197
+ return "<tr><td>" + esc(it.sku) + "</td><td>" + esc(it.title) + "</td><td>" +
198
+ esc(money.currency || "-") + " " + esc(money.amount_minor == null ? "-" : money.amount_minor) +
199
+ "(最小币单位)</td><td>" + esc(it.stock == null ? "-" : it.stock) + "</td><td>" +
200
+ esc(it.authority_version == null ? "-" : it.authority_version) + "</td></tr>";
201
+ }).join("");
202
+ return '<div class="card"><h2>当前商品(' + (p.items || []).length + ")</h2>" +
203
+ (rows ? "<table><tr><th>SKU</th><th>名称</th><th>价格(最小币单位)</th><th>库存</th><th>版本</th></tr>" + rows + "</table>"
204
+ : '<p class="muted">暂无商品,请先导入商品。没有商品时服务不会报价或发布名片。</p>') + "</div>" +
205
+ '<div class="card"><h2>导入商品表(整表替换)</h2>' +
206
+ '<p class="muted">支持 CSV、Excel(.xlsx)与商品表 JSON:先转换校验、预览增/改/留/删,确认后整批生效(不成功的批次不改动现有商品)。</p>' +
207
+ '<p class="muted">模板:<a href="/merchant/api/v1/products/import-template?format=csv" download="kiwi-product-import-template.csv">下载 CSV 模板</a> · <a href="/merchant/api/v1/products/import-template?format=xlsx" download="kiwi-product-import-template.xlsx">下载 Excel 模板</a>(中文表头与示例行;中英文常见列名会自动识别)。</p>' +
208
+ '<div class="row"><input type="file" id="pfile" accept=".json,.csv,.xlsx">' +
209
+ '<button class="act" onclick="previewImport()">校验预览</button></div><div id="presult"></div></div>';
210
+ });
211
+ },
212
+ approvals: function () {
213
+ return call("GET", "/approvals").then(function (p) {
214
+ var rows = (p.items || []).map(function (it) {
215
+ return "<tr><td>" + esc(it.candidate_id) + "</td><td>" + esc(it.summary) + "</td><td>" +
216
+ '<span class="pill warn">' + esc(it.status) + "</span></td><td>" + esc(it.expires_at) + "</td>" +
217
+ '<td><pre class="digest">' + esc(it.arguments_hash) + "</pre></td>" +
218
+ '<td><button class="act primary" onclick="decide(\\'' + esc(it.candidate_id) + '\\',true)">批准</button> ' +
219
+ '<button class="act danger" onclick="decide(\\'' + esc(it.candidate_id) + '\\',false)">拒绝</button></td></tr>';
220
+ }).join("");
221
+ return '<div class="card"><h2>待审批(' + (p.items || []).length + ")</h2>" +
222
+ (rows ? "<table><tr><th>候选</th><th>内容</th><th>状态</th><th>有效期</th><th>参数摘要</th><th>操作</th></tr>" + rows + "</table>"
223
+ : '<p class="muted">暂无待审批请求。</p>') +
224
+ '<p class="muted">批准/拒绝只在本页完成;对话里的“同意”不构成批准。</p></div>';
225
+ });
226
+ },
227
+ negotiations: function () {
228
+ var qs = "/negotiations?limit=20&status=" + encodeURIComponent(NEG_STATUS) +
229
+ (NEG_CURSOR ? "&cursor=" + encodeURIComponent(NEG_CURSOR) : "");
230
+ return call("GET", qs).then(function (page) {
231
+ if (NEG_OPEN) return negotiationDetail(NEG_OPEN);
232
+ var filters = [["all", "全部"], ["active", "进行中"], ["agreement", "已达成"]].map(function (f) {
233
+ return '<button class="act' + (NEG_STATUS === f[0] ? " primary" : "") + '" onclick="setNegStatus(\\'' + f[0] + '\\')">' + f[1] + "</button>";
234
+ }).join(" ");
235
+ var rows = (page.items || []).map(function (it) {
236
+ return "<tr><td>" + esc(it.recorded_at) + "</td><td>" + esc(it.negotiation_id) + "</td>" +
237
+ "<td>" + phasePill(it.phase, it.agreement) + "</td><td>" + esc(it.sku || "-") + "</td>" +
238
+ "<td>" + esc(it.quantity == null ? "-" : it.quantity) + "</td>" +
239
+ "<td>" + esc(it.price_minor == null ? "-" : it.price_minor) + "</td>" +
240
+ "<td>" + (it.needs_attention ? '<span class="pill warn">待回应</span>' : '<span class="muted">—</span>') + "</td>" +
241
+ '<td><button class="act" onclick="openNegotiation(\\'' + esc(it.negotiation_id) + '\\')">查看时间线</button></td></tr>';
242
+ }).join("");
243
+ var pager = '<div class="row" style="margin-top:8px">' +
244
+ (NEG_CURSOR ? '<button class="act" onclick="negPage(\\'\\')">上一页</button>' : "") +
245
+ (page.next_cursor ? '<button class="act" onclick="negPage(\\'' + esc(page.next_cursor) + '\\')">下一页</button>' : "") +
246
+ '<span class="muted">共 ' + (page.total == null ? "-" : page.total) + " 条</span></div>";
247
+ return '<div class="card"><h2>会话旁观(只读)</h2>' +
248
+ '<div class="row" style="margin-bottom:8px">' + filters + "</div>" +
249
+ (rows ? "<table><tr><th>最近活动</th><th>磋商</th><th>相位</th><th>SKU</th><th>数量</th><th>单价(最小币单位)</th><th>待回应</th><th>操作</th></tr>" + rows + "</table>"
250
+ : '<p class="muted">当前过滤条件下没有磋商记录。</p>') + pager +
251
+ '<p class="muted">本页仅旁观:不能在这里向买家发送消息;回复都在接待会话内完成。买家只以协议身份出现,不展示私密联系方式。</p></div>';
252
+ });
253
+ },
254
+ reports: function () {
255
+ var periods = [["day", "今日"], ["week", "本周"], ["month", "本月"]].map(function (p) {
256
+ return '<button class="act' + (REP_PERIOD === p[0] ? " primary" : "") + '" onclick="setRepPeriod(\\'' + p[0] + '\\')">' + p[1] + "</button>";
257
+ }).join(" ");
258
+ return call("GET", "/reports?period=" + encodeURIComponent(REP_PERIOD)).then(function (r) {
259
+ var names = {
260
+ distinct_buyers: "去重买家数",
261
+ contact_events: "询价/触达事件",
262
+ negotiations: "磋商数",
263
+ agreements_reached: "达成非绑定协议",
264
+ human_escalations: "进入人工处理",
265
+ };
266
+ var rows = Object.keys(names).map(function (key) {
267
+ var m = (r.metrics || {})[key] || {};
268
+ if (!m.available) {
269
+ return "<tr><th>" + names[key] + "</th><td>" + esc(UNAVAILABLE_LABEL) +
270
+ '</td><td class="muted">' + esc(unavailableReason(m.reason)) + "</td><td>-</td></tr>";
271
+ }
272
+ var pct = m.change_pct == null ? "-" : (m.change_pct > 0 ? "+" : "") + m.change_pct + "%";
273
+ var delta = m.delta > 0 ? "+" + m.delta : String(m.delta);
274
+ return "<tr><th>" + names[key] + "</th><td>" + esc(m.value) + "</td><td>" + esc(m.previous) +
275
+ "</td><td>" + esc(delta) + "(" + esc(pct) + ")</td></tr>";
276
+ }).join("");
277
+ var skuRows = (r.top_skus || []).map(function (s) {
278
+ return "<tr><td>" + esc(s.sku) + "</td><td>" + esc(s.contact_events) + "</td><td>" +
279
+ esc(s.distinct_buyers) + "</td><td>" + esc(s.negotiations) + "</td></tr>";
280
+ }).join("");
281
+ var terms = (r.recent_inquiry_terms || []).map(function (t) {
282
+ return "<tr><td>" + esc(t.token) + "</td><td>" + esc(t.count) + "</td></tr>";
283
+ }).join("");
284
+ var trend = (r.series || []).map(function (p) {
285
+ var max = 1;
286
+ (r.series || []).forEach(function (q) { if (q.contact_events > max) max = q.contact_events; });
287
+ var w = Math.round((p.contact_events / max) * 100);
288
+ return '<div class="trendrow"><span class="muted">' + esc(p.day.slice(5)) + "</span>" +
289
+ '<div class="trendbar"><div class="trendfill" style="width:' + w + '%"></div></div>' +
290
+ "<span>" + esc(p.contact_events) + "</span></div>";
291
+ }).join("");
292
+ return '<div class="card"><h2>运营报告</h2><div class="row" style="margin-bottom:8px">' + periods + "</div>" +
293
+ '<p class="muted">窗口 ' + esc(r.window && r.window.since) + " 至 " + esc(r.window && r.window.until_exclusive) +
294
+ "(UTC);对比上一周期 " + esc(r.previous_window && r.previous_window.since) + " 至 " +
295
+ esc(r.previous_window && r.previous_window.until_exclusive) + "。</p>" +
296
+ "<table><tr><th>指标</th><th>本周期</th><th>上一周期</th><th>变化</th></tr>" + rows + "</table>" +
297
+ '<p class="muted">「进入人工处理」= 磋商进入澄清等待或生成人工交接候选;非绑定协议按账本 AGREEMENT_REACHED 事实统计。</p></div>' +
298
+ '<div class="card"><h2>SKU 热度 Top 10</h2>' +
299
+ (skuRows ? "<table><tr><th>SKU</th><th>触达</th><th>去重买家</th><th>磋商</th></tr>" + skuRows + "</table>"
300
+ : '<p class="muted">' + esc(UNAVAILABLE_LABEL) + "(没有触达统计数据)</p>") + "</div>" +
301
+ '<div class="card"><h2>最近询价关键词(原文计数)</h2>' +
302
+ (terms ? "<table><tr><th>问题 code</th><th>次数</th></tr>" + terms + "</table>"
303
+ : '<p class="muted">当前窗口没有询价问题记录。</p>') +
304
+ '<p class="muted">仅统计买家询价问题 code 原文出现次数;主题归纳(LLM)属后续工作。</p></div>' +
305
+ '<div class="card"><h2>触达趋势(按日)</h2>' +
306
+ (trend || '<p class="muted">' + esc(UNAVAILABLE_LABEL) + "</p>") + "</div>";
307
+ });
308
+ },
309
+ policy: function () {
310
+ return call("GET", "/policy").then(function (pol) {
311
+ return '<div class="card"><h2>当前报价规则</h2><table>' +
312
+ "<tr><th>规则版本</th><td>" + esc(pol.policy_revision) + "</td></tr>" +
313
+ '<tr><th>内容摘要</th><td><pre class="digest">' + esc(pol.digest) + "</pre></td></tr></table>" +
314
+ '<p class="muted">底价等敏感值不出现在本页接口;提交草稿后由系统校验并原子生效。</p></div>' +
315
+ (ROLE === "owner" || ROLE === "operator"
316
+ ? '<div class="card"><h2>常用规则表单</h2>' +
317
+ '<p class="muted">留空的字段不会写进补丁(不修改现有值);当前值因隐私不回显。提交后生成规则变更草稿,再确认才生效。</p>' +
318
+ '<table>' +
319
+ '<tr><th>自动应价</th><td><select id="pf-auto"><option value="">不修改</option><option value="on">开启</option><option value="off">关闭</option></select>' +
320
+ '<span class="muted">关闭后新询价转人工处理</span></td></tr>' +
321
+ '<tr><th>全局最低单价(元)</th><td><input type="text" id="pf-floor" placeholder="留空不修改"></td></tr>' +
322
+ '<tr><th>最大自动折扣(%)</th><td><input type="text" id="pf-discount" placeholder="0–100,留空不修改"></td></tr>' +
323
+ '<tr><th>交期承诺(天)</th><td><input type="text" id="pf-lead" placeholder="正数,留空不修改"></td></tr>' +
324
+ '<tr><th>报价有效期(秒)</th><td><input type="text" id="pf-ttl" placeholder="正数,留空不修改"></td></tr>' +
325
+ '<tr><th>超出范围转人工</th><td><span class="row">' +
326
+ '<label><input type="checkbox" id="pf-hr-below" checked> 低于底价</label>' +
327
+ '<label><input type="checkbox" id="pf-hr-warranty"> 特殊售后条款</label>' +
328
+ '<label><input type="checkbox" id="pf-hr-suspicious"> 可疑内容</label></span>' +
329
+ '<select id="pf-hr"><option value="">不修改</option><option value="set">按左侧勾选设置</option></select></td></tr>' +
330
+ "</table>" +
331
+ '<div class="row" style="margin-top:8px"><button class="act primary" onclick="draftPolicyForm()">生成规则草稿</button>' +
332
+ '<span class="muted">per-SKU 底价/折扣、促销与库存来源请用下方高级模式。</span></div><div id="polformresult"></div></div>' +
333
+ '<div class="card"><h2>高级:JSON patch 模式</h2>' +
334
+ '<p class="muted">适合 per-SKU 底价/折扣映射、促销与库存来源等完整 patch;字段名以策略 schema 文档为准,不在页面枚举。</p>' +
335
+ '<textarea id="patch" rows="8"></textarea>' +
336
+ '<div class="row" style="margin-top:8px"><button class="act" onclick="draftPolicy()">保存草稿</button>' +
337
+ '<span class="muted">保存后生成草稿摘要,再点提交才生效。</span></div><div id="polresult"></div></div>'
338
+ : '<div class="card"><p class="muted">规则调整需要 operator/owner 角色。</p></div>');
339
+ });
340
+ },
341
+ };
342
+
343
+ </script>
344
+ <script>
345
+ /* 暂停/恢复与规则/导入/审批的命令实现。 */
346
+ function currentRevision(cb) {
347
+ call("GET", "/runtime/status").then(cb).catch(function (e) { bar(e.message, true); });
348
+ }
349
+ /* 会话旁观 / 运营报告的视图状态(只读;不能从这里发消息)。 */
350
+ var NEG_STATUS = "all";
351
+ var NEG_CURSOR = "";
352
+ var NEG_OPEN = null;
353
+ var REP_PERIOD = "day";
354
+ var UNAVAILABLE_LABEL = "不可得";
355
+ function unavailableReason(reason) {
356
+ return {
357
+ merchant_stats_unavailable: "没有买家触达统计数据(stats.sqlite 不存在)",
358
+ negotiation_ledger_unavailable: "磋商账本不可读",
359
+ }[reason] || "数据源未配置";
360
+ }
361
+ function phasePill(phase, agreement) {
362
+ if (agreement) return '<span class="pill ok">已达成</span>';
363
+ var map = {
364
+ OPEN: ["", "开放"], AWAITING_CLARIFICATION: ["warn", "澄清等待"],
365
+ OFFER_OPEN: ["", "报价中"], DECLINED: ["bad", "已婉拒"],
366
+ WITHDRAWN: ["bad", "已撤回"], CANCELLED: ["bad", "已取消"], EXPIRED: ["warn", "已过期"],
367
+ };
368
+ var it = map[phase] || ["warn", phase];
369
+ return it[0] ? '<span class="pill ' + it[0] + '">' + esc(it[1]) + "</span>" : '<span class="pill">' + esc(it[1]) + "</span>";
370
+ }
371
+ function setNegStatus(status) { NEG_STATUS = status; NEG_CURSOR = ""; NEG_OPEN = null; refresh(); }
372
+ function negPage(cursor) { NEG_CURSOR = cursor; refresh(); }
373
+ function openNegotiation(id) { NEG_OPEN = id; refresh(); }
374
+ function closeNegotiation() { NEG_OPEN = null; refresh(); }
375
+ function negotiationDetail(id) {
376
+ return call("GET", "/negotiations/" + encodeURIComponent(id)).then(function (d) {
377
+ var entries = (d.timeline || []).map(function (e) {
378
+ var who = e.direction === "buyer" ? '<span class="pill">买家</span>'
379
+ : e.direction === "merchant" ? '<span class="pill">商家</span>'
380
+ : '<span class="muted">系统</span>';
381
+ var rule = e.rule_summary ? esc(e.rule_summary) : '<span class="muted">' + UNAVAILABLE_LABEL + "</span>";
382
+ return "<tr><td>" + esc(e.at) + "</td><td>" + who + "</td><td>" + esc(e.action) + "</td>" +
383
+ "<td>" + esc(e.summary) + "</td><td>" + rule + "</td>" +
384
+ "<td>" + (e.manual_review ? '<span class="pill warn">转人工</span>' : "—") + "</td></tr>";
385
+ }).join("");
386
+ return '<div class="card"><h2>磋商 ' + esc(d.negotiation_id) + "(时间线)</h2>" +
387
+ '<button class="act" onclick="closeNegotiation()">← 返回列表</button>' +
388
+ "<table><tr><th>相位</th><td>" + phasePill(d.phase, d.agreement) + "</td></tr>" +
389
+ "<tr><th>SKU</th><td>" + esc(d.sku || "-") + "</td></tr>" +
390
+ "<tr><th>数量</th><td>" + esc(d.quantity == null ? "-" : d.quantity) + "</td></tr>" +
391
+ "<tr><th>最新单价(最小币单位)</th><td>" + esc(d.price_minor == null ? "-" : d.price_minor) + "</td></tr>" +
392
+ "<tr><th>买家(协议身份)</th><td>" + esc(d.buyer_ref) + "</td></tr>" +
393
+ "<tr><th>最近活动</th><td>" + esc(d.recorded_at) + "</td></tr></table>" +
394
+ (entries
395
+ ? "<table style=\\"margin-top:10px\\"><tr><th>时间</th><th>方向</th><th>动作</th><th>内容</th><th>规则依据</th><th>人工</th></tr>" + entries + "</table>"
396
+ : '<p class="muted">账本中没有消息事件。</p>') +
397
+ '<p class="muted">「规则依据」不可得 = 账本未记录该步的规则事实;规则数值属私有数据,不在旁观视图展示。本页只读。</p></div>';
398
+ });
399
+ }
400
+ function setRepPeriod(period) { REP_PERIOD = period; refresh(); }
401
+ function numberOrUndefined(raw) {
402
+ var trimmed = String(raw == null ? "" : raw).trim();
403
+ if (trimmed === "") return undefined;
404
+ var value = Number(trimmed);
405
+ return Number.isFinite(value) ? value : NaN;
406
+ }
407
+ function draftPolicyForm() {
408
+ var form = {};
409
+ var auto = $("pf-auto") ? $("pf-auto").value : "";
410
+ if (auto === "on" || auto === "off") form.auto = auto;
411
+ var floor = numberOrUndefined($("pf-floor") && $("pf-floor").value);
412
+ if (floor !== undefined) {
413
+ if (Number.isNaN(floor) || floor < 0) { bar("最低单价须为非负数字(元)", true); return; }
414
+ form.floor = floor;
415
+ }
416
+ var discount = numberOrUndefined($("pf-discount") && $("pf-discount").value);
417
+ if (discount !== undefined) {
418
+ if (Number.isNaN(discount) || discount < 0 || discount > 100) { bar("最大折扣须在 0–100 之间", true); return; }
419
+ form.discount = discount;
420
+ }
421
+ var lead = numberOrUndefined($("pf-lead") && $("pf-lead").value);
422
+ if (lead !== undefined) {
423
+ if (Number.isNaN(lead) || lead <= 0) { bar("交期承诺须为正数(天)", true); return; }
424
+ form.lead_days = lead;
425
+ }
426
+ var ttl = numberOrUndefined($("pf-ttl") && $("pf-ttl").value);
427
+ if (ttl !== undefined) {
428
+ if (Number.isNaN(ttl) || ttl <= 0 || !Number.isInteger(ttl)) { bar("报价有效期须为正整数(秒)", true); return; }
429
+ form.ttl_seconds = ttl;
430
+ }
431
+ var hrMode = $("pf-hr") ? $("pf-hr").value : "";
432
+ if (hrMode === "set") {
433
+ var triggers = [];
434
+ if ($("pf-hr-below") && $("pf-hr-below").checked) triggers.push("below_floor");
435
+ if ($("pf-hr-warranty") && $("pf-hr-warranty").checked) triggers.push("exceptional_warranty");
436
+ if ($("pf-hr-suspicious") && $("pf-hr-suspicious").checked) triggers.push("suspicious_content");
437
+ form.human_review = triggers;
438
+ }
439
+ if (Object.keys(form).length === 0) { bar("所有字段都留空:没有可提交的修改", true); return; }
440
+ call("POST", "/policy/form-drafts", form)
441
+ .then(function (draft) {
442
+ $("polformresult").innerHTML = '<div class="card" style="margin-top:10px;background:#fbfcfd">' +
443
+ "本次涉及字段:<b>" + esc((draft.applied_keys || []).join("、")) + "</b>;草稿 <b>" + esc(draft.draft_id) + "</b>" +
444
+ '<pre class="digest">' + esc(draft.digest) + "</pre>" +
445
+ '<button class="act primary" id="pfd-commit" data-draft-id="' + esc(draft.draft_id) + '" data-digest="' + esc(draft.digest) + '">确认提交生效</button>' +
446
+ '<p class="muted">提交后由服务端按策略 schema 校验并原子生效(与高级模式同一确认流程)。</p></div>';
447
+ bindPolicyCommit("pfd-commit");
448
+ })
449
+ .catch(function (e) { bar("表单草稿未保存:" + e.message, true); });
450
+ }
451
+ function pauseService() {
452
+ currentRevision(function (s) {
453
+ call("POST", "/runtime/safety-stops", {
454
+ expected_revision: s.service_revision,
455
+ reason: "商家在工作台暂停",
456
+ idempotency_key: key("pause"),
457
+ }).then(function () { bar("已暂停接待"); refresh(); })
458
+ .catch(function (e) { bar("暂停失败:" + e.message, true); });
459
+ });
460
+ }
461
+ function resumeService() {
462
+ currentRevision(function (s) {
463
+ call("POST", "/runtime/mode-drafts", {
464
+ target_state: "OPERATING",
465
+ expected_revision: s.service_revision,
466
+ reason: "商家在工作台申请恢复接待",
467
+ }).then(function (draft) {
468
+ return trustedDecision(draft.candidate.candidate_id, "approve");
469
+ }).then(function () { bar("已准备可信确认,请在确认页完成恢复接待"); })
470
+ .catch(function (e) { bar("恢复失败:" + e.message, true); });
471
+ });
472
+ }
473
+ function trustedDecision(candidateId, decision) {
474
+ return call("POST", "/confirmations", { candidate_id: candidateId, decision: decision })
475
+ .then(function (confirmation) {
476
+ window.location.assign("/merchant/trusted/confirm?ref=" + encodeURIComponent(confirmation.request_ref));
477
+ });
478
+ }
479
+ function decide(candidateId, approve) {
480
+ trustedDecision(candidateId, approve ? "approve" : "reject")
481
+ .catch(function (e) { bar("操作失败:" + e.message, true); });
482
+ }
483
+ var pendingImport = null;
484
+ var parsedTable = null;
485
+ function previewImport() {
486
+ var f = $("pfile").files[0];
487
+ if (!f) { bar("请先选择 CSV / Excel / JSON 商品表文件", true); return; }
488
+ var name = String(f.name || "").toLowerCase();
489
+ if (name.endsWith(".csv") || f.type === "text/csv") { parseTabularFile(f, "csv"); return; }
490
+ if (name.endsWith(".xlsx")) { parseTabularFile(f, "xlsx"); return; }
491
+ var reader = new FileReader();
492
+ reader.onload = function () {
493
+ var table;
494
+ try { table = JSON.parse(reader.result); }
495
+ catch (e) { bar("文件不是合法 JSON", true); return; }
496
+ submitImportTable(table);
497
+ };
498
+ reader.readAsText(f);
499
+ }
500
+ function parseTabularFile(f, format) {
501
+ var done = function (content) {
502
+ fetch(API + "/products/import-parse?format=" + format, {
503
+ method: "POST",
504
+ credentials: "same-origin",
505
+ headers: {
506
+ "content-type": format === "csv" ? "text/csv" : "application/octet-stream",
507
+ "x-csrf-token": CSRF,
508
+ },
509
+ body: content,
510
+ }).then(function (res) {
511
+ if (res.status === 401) { showLogin(); throw new Error("需要登录"); }
512
+ if (!res.ok) return apiError(res).then(function (error) { throw error; });
513
+ return res.json();
514
+ }).then(function (r) {
515
+ if (!r.ok) { renderParseErrors(r); return; }
516
+ renderParseReport(r);
517
+ }).catch(function (e) { bar("表格解析未通过:" + e.message, true); });
518
+ };
519
+ if (format === "csv") {
520
+ var tr = new FileReader();
521
+ tr.onload = function () { done(tr.result); };
522
+ tr.readAsText(f);
523
+ } else {
524
+ var ar = new FileReader();
525
+ ar.onload = function () { done(ar.result); };
526
+ ar.readAsArrayBuffer(f);
527
+ }
528
+ }
529
+ function renderParseErrors(r) {
530
+ var errors = r.errors || [];
531
+ var rows = errors.slice(0, 50).map(function (e) {
532
+ return "<tr><td>" + esc(e.row == null ? "-" : e.row) + "</td><td>" +
533
+ esc(e.column || e.field || "-") + "</td><td>" + esc(e.message) + "</td></tr>";
534
+ }).join("");
535
+ var more = errors.length > 50 ? '<p class="muted">仅显示前 50 条,共 ' + errors.length + " 条。</p>" : "";
536
+ $("presult").innerHTML = '<div class="card" style="margin-top:10px;background:#fbfcfd">' +
537
+ '<h2 style="color:#b3261e">表格未通过检查,未导入任何数据</h2>' +
538
+ (rows ? "<table><tr><th>行</th><th>列/字段</th><th>问题</th></tr>" + rows + "</table>" : "") + more +
539
+ '<p class="muted">请修正后重新上传;可先下载模板核对列名与格式。疑似底价/成本/进价列请整列删除——它们属于报价私密策略,不能进入公开商品表。</p></div>';
540
+ }
541
+ function renderParseReport(r) {
542
+ var rep = r.report || {};
543
+ parsedTable = r.table;
544
+ var unrec = (rep.unrecognized_columns || []).map(esc).join("、");
545
+ var defaulted = (rep.defaulted_fields || []).join("、");
546
+ $("presult").innerHTML = '<div class="card" style="margin-top:10px;background:#fbfcfd">' +
547
+ "<div>表格读取成功:识别 " + esc(rep.rows || 0) + " 行商品(" +
548
+ esc(rep.format === "xlsx" ? "Excel" : "CSV") + ")。</div>" +
549
+ (unrec ? '<p class="muted" style="color:#9a6b0f">未识别的列(内容不会导入):' + unrec +
550
+ "。若其中有需要导入的信息,请改用模板列名后重新上传。</p>" : "") +
551
+ (defaulted ? '<p class="muted">未提供、按默认值处理的列:' + esc(defaulted) +
552
+ "(状态默认「在售」;更新时间默认取导入时刻)。</p>" : "") +
553
+ '<p class="muted">确认列映射无误后继续;下一步做整表严格校验与替换预览。' +
554
+ '<b style="color:#b3261e">整表替换:表里没有的 SKU 提交后会被移除下架。</b></p>' +
555
+ '<button class="act primary" id="pcontinue">已确认列映射,继续校验预览</button></div>';
556
+ var btn = $("pcontinue");
557
+ if (btn) btn.addEventListener("click", function () {
558
+ if (!parsedTable) { bar("请先上传表格", true); return; }
559
+ submitImportTable(parsedTable);
560
+ });
561
+ }
562
+ function submitImportTable(table) {
563
+ call("POST", "/products/import-drafts", { table: table })
564
+ .then(function (draft) {
565
+ pendingImport = draft;
566
+ var pv = draft.preview;
567
+ $("presult").innerHTML = '<div class="card" style="margin-top:10px;background:#fbfcfd">' +
568
+ "<div>草稿 <b>" + esc(draft.draft_id) + "</b>:新增 " + pv.added + ",更新 " + pv.updated +
569
+ ",不变 " + pv.unchanged + ",<b style=\\"color:#b3261e\\">移除 " + pv.removed + "</b>(共 " + pv.rows_total + " 行)</div>" +
570
+ '<pre class="digest">' + esc(draft.digest) + "</pre>" +
571
+ (pv.removed > 0 ? '<p class="muted" style="color:#b3261e">注意:整表替换会移除上表未包含的 SKU。</p>' : "") +
572
+ '<button class="act primary" onclick="commitImport()">确认导入(整批生效)</button></div>';
573
+ })
574
+ .catch(function (e) { bar("校验未通过:" + e.message, true); });
575
+ }
576
+ function commitImport() {
577
+ if (!pendingImport) { bar("请先校验预览", true); return; }
578
+ call("POST", "/products/import-drafts/" + encodeURIComponent(pendingImport.draft_id) + "/commit", {
579
+ expected_draft_digest: pendingImport.digest,
580
+ idempotency_key: key("import"),
581
+ }).then(function (receipt) {
582
+ pendingImport = null;
583
+ bar("导入完成(回执 " + receipt.operation_id + ")");
584
+ refresh();
585
+ }).catch(function (e) { bar("导入失败:" + e.message, true); });
586
+ }
587
+ function draftPolicy() {
588
+ var patch;
589
+ try { patch = JSON.parse($("patch").value); }
590
+ catch (e) { bar("补丁不是合法 JSON", true); return; }
591
+ call("POST", "/policy/drafts", { patch: patch })
592
+ .then(function (draft) {
593
+ $("polresult").innerHTML = '<div class="card" style="margin-top:10px;background:#fbfcfd">' +
594
+ "草稿 <b>" + esc(draft.draft_id) + "</b>(摘要 <pre class=\\"digest\\">" + esc(draft.digest) + "</pre>)" +
595
+ '<button class="act primary" id="pd-commit" data-draft-id="' + esc(draft.draft_id) + '" data-digest="' + esc(draft.digest) + '">提交生效</button></div>';
596
+ bindPolicyCommit("pd-commit");
597
+ })
598
+ .catch(function (e) { bar("草稿未保存:" + e.message, true); });
599
+ }
600
+ function bindPolicyCommit(btnId) {
601
+ var btn = $(btnId);
602
+ if (!btn) return;
603
+ btn.addEventListener("click", function () {
604
+ commitPolicy(btn.getAttribute("data-draft-id"), btn.getAttribute("data-digest"));
605
+ });
606
+ }
607
+ function commitPolicy(draftId, digest) {
608
+ call("POST", "/policy/drafts/" + encodeURIComponent(draftId) + "/commit", {
609
+ expected_draft_digest: digest,
610
+ idempotency_key: key("policy"),
611
+ }).then(function (receipt) {
612
+ bar("规则已生效(版本 " + receipt.result_revision + ")");
613
+ refresh();
614
+ }).catch(function (e) { bar("提交失败:" + e.message, true); });
615
+ }
616
+ var current = "status";
617
+ function refresh() { views[current]().then(function (html) { $("view").innerHTML = html; })
618
+ .catch(function (e) { if (e.message !== "需要登录") bar(e.message, true); }); }
619
+ Array.prototype.forEach.call(document.querySelectorAll("#tabs button"), function (btn) {
620
+ btn.addEventListener("click", function () {
621
+ Array.prototype.forEach.call(document.querySelectorAll("#tabs button"), function (b) { b.className = ""; });
622
+ btn.className = "on";
623
+ current = btn.getAttribute("data-v");
624
+ refresh();
625
+ });
626
+ });
627
+ fetch("/merchant/api/session", { credentials: "same-origin" }).then(function (res) {
628
+ if (res.status === 401) { showLogin(); return null; }
629
+ return res.json();
630
+ }).then(function (session) {
631
+ if (!session) return;
632
+ CSRF = session.csrf_token || "";
633
+ ROLE = session.role || "";
634
+ $("who").textContent = "商家 " + session.merchant_id + " · " + ROLE;
635
+ refresh();
636
+ });
637
+ </script>
638
+ </body>
639
+ </html>`;
640
+ }
641
+ //# sourceMappingURL=page.js.map