@harrylabsj/kiwi-merchant-cloud 0.12.32 → 0.12.34

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 (264) hide show
  1. package/app/a2a/inquiry-nonce-store.d.ts +12 -1
  2. package/app/a2a/inquiry-nonce-store.js +49 -17
  3. package/app/a2a/inquiry-nonce-store.js.map +1 -1
  4. package/app/a2a/negotiate.d.ts +30 -1
  5. package/app/a2a/negotiate.js +121 -32
  6. package/app/a2a/negotiate.js.map +1 -1
  7. package/app/a2a/node.d.ts +3 -0
  8. package/app/a2a/node.js +13 -3
  9. package/app/a2a/node.js.map +1 -1
  10. package/app/a2a/open-inquiry-session.d.ts +1 -0
  11. package/app/a2a/open-inquiry-session.js +3 -1
  12. package/app/a2a/open-inquiry-session.js.map +1 -1
  13. package/app/a2a/open-inquiry-verifier.js +2 -2
  14. package/app/a2a/open-inquiry-verifier.js.map +1 -1
  15. package/app/a2a/server/errors.d.ts +4 -3
  16. package/app/a2a/server/errors.js +10 -2
  17. package/app/a2a/server/errors.js.map +1 -1
  18. package/app/a2a/server/merchant-handler.d.ts +41 -1
  19. package/app/a2a/server/merchant-handler.js +259 -89
  20. package/app/a2a/server/merchant-handler.js.map +1 -1
  21. package/app/a2a/server/merchant-procurement.d.ts +90 -0
  22. package/app/a2a/server/merchant-procurement.js +75 -0
  23. package/app/a2a/server/merchant-procurement.js.map +1 -0
  24. package/app/a2a/server/merchant-product-facts.d.ts +2 -0
  25. package/app/a2a/server/merchant-product-facts.js.map +1 -1
  26. package/app/a2a/server/negotiation-approvals.d.ts +11 -0
  27. package/app/a2a/server/negotiation-approvals.js +43 -0
  28. package/app/a2a/server/negotiation-approvals.js.map +1 -1
  29. package/app/a2a/server/pipeline.js +4 -1
  30. package/app/a2a/server/pipeline.js.map +1 -1
  31. package/app/a2a/server/server.js +4 -3
  32. package/app/a2a/server/server.js.map +1 -1
  33. package/app/a2a/server/types.d.ts +2 -1
  34. package/app/agent/alipay-native-view.d.ts +27 -0
  35. package/app/agent/alipay-native-view.js +113 -0
  36. package/app/agent/alipay-native-view.js.map +1 -0
  37. package/app/agent/buyer/buyer-tools.d.ts +20 -0
  38. package/app/agent/buyer/buyer-tools.js +241 -48
  39. package/app/agent/buyer/buyer-tools.js.map +1 -1
  40. package/app/agent/buyer/types.d.ts +1 -1
  41. package/app/agent/buyer/types.js.map +1 -1
  42. package/app/agent/chat-tui.js +16 -1
  43. package/app/agent/chat-tui.js.map +1 -1
  44. package/app/agent/kernel-builder.d.ts +2 -0
  45. package/app/agent/kernel-builder.js +14 -0
  46. package/app/agent/kernel-builder.js.map +1 -1
  47. package/app/agent/kernel.d.ts +8 -0
  48. package/app/agent/kernel.js +67 -1
  49. package/app/agent/kernel.js.map +1 -1
  50. package/app/buyer-core/a2a-accept-terms.d.ts +11 -0
  51. package/app/buyer-core/a2a-accept-terms.js +28 -0
  52. package/app/buyer-core/a2a-accept-terms.js.map +1 -0
  53. package/app/buyer-core/a2a-knp.d.ts +3 -0
  54. package/app/buyer-core/a2a-knp.js +3 -3
  55. package/app/buyer-core/a2a-knp.js.map +1 -1
  56. package/app/buyer-core/a2a-negotiator.d.ts +16 -0
  57. package/app/buyer-core/a2a-negotiator.js +53 -16
  58. package/app/buyer-core/a2a-negotiator.js.map +1 -1
  59. package/app/buyer-core/a2a-quote-fetcher.d.ts +0 -15
  60. package/app/buyer-core/a2a-quote-fetcher.js +10 -15
  61. package/app/buyer-core/a2a-quote-fetcher.js.map +1 -1
  62. package/app/buyer-core/merchant-index.d.ts +2 -2
  63. package/app/buyer-core/merchant-index.js +23 -5
  64. package/app/buyer-core/merchant-index.js.map +1 -1
  65. package/app/buyer-core/procurement/cases.d.ts +441 -0
  66. package/app/buyer-core/procurement/cases.js +457 -0
  67. package/app/buyer-core/procurement/cases.js.map +1 -0
  68. package/app/buyer-core/procurement/quote-comparison.d.ts +137 -0
  69. package/app/buyer-core/procurement/quote-comparison.js +106 -0
  70. package/app/buyer-core/procurement/quote-comparison.js.map +1 -0
  71. package/app/buyer-core/procurement/quote-normalizer.d.ts +45 -0
  72. package/app/buyer-core/procurement/quote-normalizer.js +153 -0
  73. package/app/buyer-core/procurement/quote-normalizer.js.map +1 -0
  74. package/app/buyer-core/procurement/requirements.d.ts +50 -0
  75. package/app/buyer-core/procurement/requirements.js +43 -0
  76. package/app/buyer-core/procurement/requirements.js.map +1 -0
  77. package/app/buyer-core/procurement/source-observation.d.ts +57 -0
  78. package/app/buyer-core/procurement/source-observation.js +54 -0
  79. package/app/buyer-core/procurement/source-observation.js.map +1 -0
  80. package/app/buyer-core/procurement/store.d.ts +21 -0
  81. package/app/buyer-core/procurement/store.js +68 -0
  82. package/app/buyer-core/procurement/store.js.map +1 -0
  83. package/app/buyer-core/protocol-recovery.d.ts +8 -0
  84. package/app/buyer-core/protocol-recovery.js +17 -2
  85. package/app/buyer-core/protocol-recovery.js.map +1 -1
  86. package/app/buyer-core/quote-quantity.d.ts +5 -0
  87. package/app/buyer-core/quote-quantity.js +15 -0
  88. package/app/buyer-core/quote-quantity.js.map +1 -0
  89. package/app/buyer-core/service.d.ts +71 -3
  90. package/app/buyer-core/service.js +271 -28
  91. package/app/buyer-core/service.js.map +1 -1
  92. package/app/buyer-core/store.d.ts +13 -0
  93. package/app/buyer-core/store.js +25 -3
  94. package/app/buyer-core/store.js.map +1 -1
  95. package/app/cli.js +13 -17
  96. package/app/cli.js.map +1 -1
  97. package/app/cloud/alipay-collection-http.d.ts +44 -0
  98. package/app/cloud/alipay-collection-http.js +111 -0
  99. package/app/cloud/alipay-collection-http.js.map +1 -0
  100. package/app/cloud/bootstrap.js +98 -12
  101. package/app/cloud/bootstrap.js.map +1 -1
  102. package/app/cloud/http-router.d.ts +2 -0
  103. package/app/cloud/http-router.js +5 -0
  104. package/app/cloud/http-router.js.map +1 -1
  105. package/app/cloud-sample/products.json +3 -3
  106. package/app/commerce/receipt/dispatcher.d.ts +2 -1
  107. package/app/commerce/receipt/dispatcher.js +18 -0
  108. package/app/commerce/receipt/dispatcher.js.map +1 -1
  109. package/app/commerce/receipt/receipts.d.ts +7 -0
  110. package/app/commerce/receipt/receipts.js +43 -5
  111. package/app/commerce/receipt/receipts.js.map +1 -1
  112. package/app/discovery/catalog-source/buyer-follows.d.ts +3 -3
  113. package/app/discovery/catalog-source/buyer-follows.js +6 -3
  114. package/app/discovery/catalog-source/buyer-follows.js.map +1 -1
  115. package/app/discovery/catalog-source/kiwi-record.d.ts +2 -0
  116. package/app/discovery/catalog-source/kiwi-record.js.map +1 -1
  117. package/app/discovery/catalog-source/kiwi-source.js +4 -0
  118. package/app/discovery/catalog-source/kiwi-source.js.map +1 -1
  119. package/app/handoff/alipay-collection.d.ts +23 -0
  120. package/app/handoff/alipay-collection.js +70 -0
  121. package/app/handoff/alipay-collection.js.map +1 -0
  122. package/app/handoff/order-receipts.js +2 -1
  123. package/app/handoff/order-receipts.js.map +1 -1
  124. package/app/handoff/ucp-checkout/channel.d.ts +1 -0
  125. package/app/handoff/ucp-checkout/channel.js +42 -17
  126. package/app/handoff/ucp-checkout/channel.js.map +1 -1
  127. package/app/http/customer-support-buyer.d.ts +24 -0
  128. package/app/http/customer-support-buyer.js +306 -0
  129. package/app/http/customer-support-buyer.js.map +1 -0
  130. package/app/http/merchant-management/api.d.ts +12 -0
  131. package/app/http/merchant-management/api.js +425 -6
  132. package/app/http/merchant-management/api.js.map +1 -1
  133. package/app/http/merchant-management/page.d.ts +2 -0
  134. package/app/http/merchant-management/page.js +630 -3
  135. package/app/http/merchant-management/page.js.map +1 -1
  136. package/app/http/server.js +9 -2
  137. package/app/http/server.js.map +1 -1
  138. package/app/mcp/cli.d.ts +3 -1
  139. package/app/mcp/cli.js +12 -2
  140. package/app/mcp/cli.js.map +1 -1
  141. package/app/mcp/merchant-runtime-assembly.d.ts +3 -0
  142. package/app/mcp/merchant-runtime-assembly.js +9 -8
  143. package/app/mcp/merchant-runtime-assembly.js.map +1 -1
  144. package/app/mcp/procurement-tools.d.ts +10 -0
  145. package/app/mcp/procurement-tools.js +173 -0
  146. package/app/mcp/procurement-tools.js.map +1 -0
  147. package/app/mcp/server.d.ts +4 -0
  148. package/app/mcp/server.js +63 -9
  149. package/app/mcp/server.js.map +1 -1
  150. package/app/mcp/tools.d.ts +4 -1
  151. package/app/mcp/tools.js +76 -27
  152. package/app/mcp/tools.js.map +1 -1
  153. package/app/mcp/types.d.ts +1 -0
  154. package/app/mcp/types.js.map +1 -1
  155. package/app/merchant/ai-runtime/owner-storage-admission.js.map +1 -1
  156. package/app/merchant/application/actor.d.ts +2 -0
  157. package/app/merchant/application/actor.js +6 -0
  158. package/app/merchant/application/actor.js.map +1 -1
  159. package/app/merchant/negotiation-ops.d.ts +2 -0
  160. package/app/merchant/negotiation-ops.js +4 -0
  161. package/app/merchant/negotiation-ops.js.map +1 -1
  162. package/app/merchant/weixin-channel.d.ts +224 -0
  163. package/app/merchant/weixin-channel.js +435 -0
  164. package/app/merchant/weixin-channel.js.map +1 -0
  165. package/app/merchant/weixin-owner-agent-profile.d.ts +8 -0
  166. package/app/merchant/weixin-owner-agent-profile.js +29 -0
  167. package/app/merchant/weixin-owner-agent-profile.js.map +1 -0
  168. package/app/merchant/weixin-owner-agent.d.ts +42 -0
  169. package/app/merchant/weixin-owner-agent.js +97 -0
  170. package/app/merchant/weixin-owner-agent.js.map +1 -0
  171. package/app/merchant/weixin-owner-conversation.d.ts +156 -0
  172. package/app/merchant/weixin-owner-conversation.js +559 -0
  173. package/app/merchant/weixin-owner-conversation.js.map +1 -0
  174. package/app/merchant/weixin-owner-digest.d.ts +30 -0
  175. package/app/merchant/weixin-owner-digest.js +30 -0
  176. package/app/merchant/weixin-owner-digest.js.map +1 -0
  177. package/app/merchant/weixin-owner-inventory.d.ts +28 -0
  178. package/app/merchant/weixin-owner-inventory.js +48 -0
  179. package/app/merchant/weixin-owner-inventory.js.map +1 -0
  180. package/app/merchant/weixin-owner-source.d.ts +22 -0
  181. package/app/merchant/weixin-owner-source.js +104 -0
  182. package/app/merchant/weixin-owner-source.js.map +1 -0
  183. package/app/merchant/workbench-server.d.ts +4 -0
  184. package/app/merchant/workbench-server.js +75 -9
  185. package/app/merchant/workbench-server.js.map +1 -1
  186. package/app/merchant-core/collection/alipay-store.d.ts +22 -0
  187. package/app/merchant-core/collection/alipay-store.js +125 -0
  188. package/app/merchant-core/collection/alipay-store.js.map +1 -0
  189. package/app/merchant-core/commercial/calculate.js +6 -6
  190. package/app/merchant-core/commercial/calculate.js.map +1 -1
  191. package/app/merchant-core/operating/repository.d.ts +0 -1
  192. package/app/merchant-core/operating/repository.js +2 -17
  193. package/app/merchant-core/operating/repository.js.map +1 -1
  194. package/app/merchant-core/operations-jobs/service.d.ts +11 -0
  195. package/app/merchant-core/operations-jobs/service.js +65 -34
  196. package/app/merchant-core/operations-jobs/service.js.map +1 -1
  197. package/app/merchant-core/opportunity/repository.d.ts +0 -1
  198. package/app/merchant-core/opportunity/repository.js +2 -17
  199. package/app/merchant-core/opportunity/repository.js.map +1 -1
  200. package/app/merchant-core/ops/surface.d.ts +1 -0
  201. package/app/merchant-core/ops/surface.js +9 -0
  202. package/app/merchant-core/ops/surface.js.map +1 -1
  203. package/app/merchant-core/orders/model.d.ts +1 -8
  204. package/app/merchant-core/orders/model.js +10 -2
  205. package/app/merchant-core/orders/model.js.map +1 -1
  206. package/app/merchant-core/orders/repository.d.ts +0 -1
  207. package/app/merchant-core/orders/repository.js +3 -18
  208. package/app/merchant-core/orders/repository.js.map +1 -1
  209. package/app/merchant-core/orders/service.js +34 -8
  210. package/app/merchant-core/orders/service.js.map +1 -1
  211. package/app/merchant-core/proposal/engine.js +2 -0
  212. package/app/merchant-core/proposal/engine.js.map +1 -1
  213. package/app/merchant-core/proposal/publish.d.ts +0 -6
  214. package/app/merchant-core/proposal/publish.js +37 -3
  215. package/app/merchant-core/proposal/publish.js.map +1 -1
  216. package/app/merchant-core/proposal/repository.d.ts +0 -7
  217. package/app/merchant-core/proposal/repository.js +8 -17
  218. package/app/merchant-core/proposal/repository.js.map +1 -1
  219. package/app/merchant-core/proposal/types.d.ts +1 -0
  220. package/app/merchant-core/proposal/types.js.map +1 -1
  221. package/app/merchant-core/rfq/policy.d.ts +1 -0
  222. package/app/merchant-core/rfq/policy.js +6 -7
  223. package/app/merchant-core/rfq/policy.js.map +1 -1
  224. package/app/merchant-core/rfq/repository.d.ts +0 -1
  225. package/app/merchant-core/rfq/repository.js +2 -17
  226. package/app/merchant-core/rfq/repository.js.map +1 -1
  227. package/app/merchant-core/rfq/service.d.ts +2 -1
  228. package/app/merchant-core/rfq/service.js +2 -4
  229. package/app/merchant-core/rfq/service.js.map +1 -1
  230. package/app/merchant-core/storage/transaction.d.ts +4 -11
  231. package/app/merchant-core/storage/transaction.js +43 -65
  232. package/app/merchant-core/storage/transaction.js.map +1 -1
  233. package/app/merchant-core/support/manual-service.d.ts +114 -0
  234. package/app/merchant-core/support/manual-service.js +300 -0
  235. package/app/merchant-core/support/manual-service.js.map +1 -0
  236. package/app/negotiation/domain/objects.d.ts +2 -0
  237. package/app/negotiation/domain/objects.js +3 -0
  238. package/app/negotiation/domain/objects.js.map +1 -1
  239. package/app/negotiation/ledger/store.d.ts +6 -0
  240. package/app/negotiation/ledger/store.js +28 -0
  241. package/app/negotiation/ledger/store.js.map +1 -1
  242. package/app/net/safe-http.d.ts +2 -0
  243. package/app/net/safe-http.js +1 -1
  244. package/app/net/safe-http.js.map +1 -1
  245. package/app/product-init.d.ts +1 -0
  246. package/app/product-init.js +4 -1
  247. package/app/product-init.js.map +1 -1
  248. package/app/trust/identity/message-signature.d.ts +1 -1
  249. package/app/trust/identity/message-signature.js +6 -1
  250. package/app/trust/identity/message-signature.js.map +1 -1
  251. package/app/trust/identity/nonce.d.ts +5 -0
  252. package/app/trust/identity/nonce.js +2 -0
  253. package/app/trust/identity/nonce.js.map +1 -1
  254. package/app/weixin/ilink-client.d.ts +3 -2
  255. package/app/weixin/ilink-client.js +58 -20
  256. package/app/weixin/ilink-client.js.map +1 -1
  257. package/app/weixin/types.d.ts +3 -1
  258. package/app/weixin/types.js.map +1 -1
  259. package/build-manifest.json +731 -386
  260. package/deployment-lock.json +85 -77
  261. package/package.json +7 -7
  262. package/runtime-package.json +13 -13
  263. package/shipping-sbom.cdx.json +150 -145
  264. package/shipping-source.json +12 -12
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { randomBytes } from "node:crypto";
6
+ import { createServer } from "node:https";
7
+ import { TLSSocket } from "node:tls";
8
+ import { ManualSupportError } from "../merchant-core/support/manual-service.js";
9
+ const API = "/api/customer-service/v1";
10
+ const COOKIE = "__Host-kiwi_cs";
11
+ const DAY_SECONDS = 86_400;
12
+ const MAX_BODY_BYTES = 8192;
13
+ const MAX_NEW_SESSIONS_PER_WINDOW = 10;
14
+ const WINDOW_MS = 10 * 60_000;
15
+ const CASE_PATH = /^\/sessions\/current\/cases\/(CS-[0-9a-f-]{36})$/;
16
+ const STATUS = {
17
+ validation: [400, "检查输入后重试。"], unauthorized: [401, "原会话不可继续,请重新建立会话或通过商家人工渠道联系。"],
18
+ forbidden: [403, "请求未获授权。"], not_found: [404, "未找到资源。"], conflict: [409, "提交与原请求不一致或状态已变化。"],
19
+ capacity: [429, "暂时不能继续提交,请稍后重试。"], unavailable: [503, "暂时无法确认操作结果,请用同一请求重试。"],
20
+ };
21
+ function single(req, name) {
22
+ const values = req.headersDistinct[name];
23
+ return values?.length === 1 ? values[0] : undefined;
24
+ }
25
+ function token(req) {
26
+ const matches = (req.headers.cookie ?? "").split(";").map((part) => part.trim())
27
+ .filter((part) => part.startsWith(`${COOKIE}=`));
28
+ if (matches.length > 1)
29
+ throw new ManualSupportError("validation");
30
+ return matches[0]?.slice(COOKIE.length + 1);
31
+ }
32
+ async function body(req) {
33
+ if (single(req, "content-type")?.split(";")[0]?.trim().toLowerCase() !== "application/json")
34
+ throw new ManualSupportError("validation");
35
+ const chunks = [];
36
+ let bytes = 0;
37
+ // 使用 iterator 的非销毁模式,让有界拒绝可以返回 400,而不替客户端接受半个 JSON。
38
+ for await (const chunk of req.iterator({ destroyOnReturn: false })) {
39
+ const value = Buffer.from(chunk);
40
+ bytes += value.length;
41
+ if (bytes > MAX_BODY_BYTES) {
42
+ req.resume();
43
+ throw new ManualSupportError("validation");
44
+ }
45
+ chunks.push(value);
46
+ }
47
+ try {
48
+ const decoded = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks));
49
+ const value = JSON.parse(decoded);
50
+ if (value === null || typeof value !== "object" || Array.isArray(value))
51
+ throw new Error();
52
+ return value;
53
+ }
54
+ catch {
55
+ throw new ManualSupportError("validation");
56
+ }
57
+ }
58
+ const SCRIPT = String.raw `
59
+ const api = '/api/customer-service/v1';
60
+ const messages = document.getElementById('messages');
61
+ const note = document.getElementById('note');
62
+ const originalNote = note.textContent;
63
+ const form = document.getElementById('intake');
64
+ const send = document.getElementById('submit');
65
+ const retry = document.getElementById('retry');
66
+ const older = document.getElementById('older');
67
+ const resume = document.getElementById('resume');
68
+ const description = document.getElementById('description');
69
+ const skuField = document.getElementById('sku');
70
+ let pending, cursor, before, timer, established = false, busy = false, generation = 0, delay = 3000;
71
+ const statusText = {case_receipt:'已登记,等待商家领取。', claimed:'人工已领取。', human_reply:'商家回复', resolved:'商家标记本工单已解决'};
72
+ async function call(path, payload) {
73
+ const options = {credentials:'same-origin',cache:'no-store'};
74
+ if (payload !== undefined) Object.assign(options,{method:'POST', headers:{'content-type':'application/json'}, body:JSON.stringify(payload)});
75
+ const r = await fetch(api + path, options);
76
+ const data = await r.json();
77
+ if (!r.ok) throw {status:r.status, message:data.message};
78
+ return data;
79
+ }
80
+ function unavailable(error, hadCursor = false) {
81
+ note.textContent = error.message || '连接中断,未确认处理结果。';
82
+ if (error.status === 401 || (hadCursor && error.status === 400)) {
83
+ // 另一标签页可能重建了 Cookie,旧游标不能用来继续显示原会话。
84
+ if (error.status === 400) note.textContent = '无法确认当前浏览器仍在原会话,请重新连接或联系商家。';
85
+ generation++; established=false; pending=undefined; cursor=undefined; before=undefined;
86
+ messages.textContent=''; description.value=''; skuField.value=''; form.hidden=true; older.hidden=true;
87
+ retry.hidden=true; resume.hidden=false;
88
+ clearTimeout(timer);
89
+ }
90
+ }
91
+ function display(items, prepend) {
92
+ const fragment = document.createDocumentFragment();
93
+ for (const event of items) {
94
+ const li = document.createElement('li');
95
+ li.textContent = event.case_id + ' · ' + statusText[event.kind] + (event.text ? ':' + event.text : '');
96
+ fragment.appendChild(li);
97
+ }
98
+ if (prepend) messages.prepend(fragment); else messages.appendChild(fragment);
99
+ }
100
+ async function update() {
101
+ clearTimeout(timer);
102
+ if (!established || document.hidden || busy) return;
103
+ const currentGeneration = generation;
104
+ const previousCursor = cursor;
105
+ busy = true;
106
+ try {
107
+ const data = await call('/sessions/current/updates'+(previousCursor ? '?after='+encodeURIComponent(previousCursor) : ''));
108
+ if (generation !== currentGeneration) return;
109
+ if (!previousCursor) { messages.textContent=''; before=data.previous_cursor; older.hidden=!before; }
110
+ display(data.events, false); cursor=data.next_cursor;
111
+ delay = data.events.length ? 3000 : Math.min(30000, delay*2);
112
+ } catch (e) {
113
+ if (generation === currentGeneration) { unavailable(e, !!previousCursor); delay = Math.min(30000, delay*2); }
114
+ }
115
+ finally {
116
+ busy=false;
117
+ if (established && !document.hidden) timer=setTimeout(update,delay);
118
+ }
119
+ }
120
+ async function start() {
121
+ resume.disabled = true;
122
+ try {
123
+ const result = await call('/sessions',{});
124
+ established=true; form.hidden=false; resume.hidden=true;
125
+ note.textContent = result.reset ? '原会话已失效,已开始新会话。如需跟进原工单,请联系商家。' : originalNote;
126
+ cursor=undefined; generation++; delay=3000; update();
127
+ } catch(e) { unavailable(e); resume.hidden=false; } finally { resume.disabled=false; }
128
+ }
129
+ async function submit() {
130
+ if (!pending || !established || send.disabled) return;
131
+ const currentGeneration = generation;
132
+ send.disabled=true; retry.disabled=true;
133
+ try {
134
+ await call('/sessions/current/messages',pending);
135
+ if (generation !== currentGeneration) return;
136
+ pending=undefined; description.value=''; skuField.value=''; note.textContent='售后请求已登记,等待商家处理。';
137
+ delay=3000; update();
138
+ } catch(e) {
139
+ if (generation !== currentGeneration) return;
140
+ unavailable(e);
141
+ if (e.status === 400 || e.status === 409) pending=undefined;
142
+ } finally { send.disabled=false; retry.disabled=false; retry.hidden=!pending; }
143
+ }
144
+ form.onsubmit = (event) => {
145
+ event.preventDefault();
146
+ if (pending) { note.textContent='上一条尚未确认,请先重试原请求。'; return; }
147
+ pending={type:'confirm_case',client_message_id:crypto.randomUUID(),description:description.value};
148
+ const sku=skuField.value.trim(); if (sku) pending.sku=sku;
149
+ void submit();
150
+ };
151
+ retry.onclick=submit;
152
+ older.onclick=async () => {
153
+ if (!before) return;
154
+ older.disabled=true; const currentGeneration=generation;
155
+ try {
156
+ const data=await call('/sessions/current/updates?before='+encodeURIComponent(before));
157
+ if (generation!==currentGeneration) return;
158
+ display(data.events,true); before=data.previous_cursor; older.hidden=!before;
159
+ } catch(e) { if (generation === currentGeneration) unavailable(e, true); } finally { older.disabled=false; }
160
+ };
161
+ resume.onclick=start;
162
+ document.addEventListener('visibilitychange',() => { if (document.hidden) clearTimeout(timer); else update(); });
163
+ void start();`;
164
+ const escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => ({
165
+ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;",
166
+ })[char]);
167
+ function page(nonce, serviceHours, contactHint) {
168
+ return `<!doctype html><html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
169
+ <title>商家售后</title><main><h1>商家售后</h1><p>服务时段:${escapeHtml(serviceHours)}。人工联系:${escapeHtml(contactHint)}。</p>
170
+ <p>此处只登记售后,不验证订单或执行退款。不要填写付款凭据、地址或完整联系方式。请用当前浏览器回来查看回复。</p>
171
+ <p id="note" role="status">等待商家领取,不承诺处理时限。</p><button id="resume" type="button" hidden>开始新会话</button>
172
+ <form id="intake" hidden><p><label>SKU(可选) <input id="sku" maxlength="64"></label></p>
173
+ <p><label>问题描述 <textarea id="description" maxlength="2000" required></textarea></label></p>
174
+ <button id="submit" type="submit">提交售后</button><button id="retry" type="button" hidden>重试原请求</button></form>
175
+ <h2>我的工单更新</h2><button id="older" type="button" hidden>查看更早记录</button><ol id="messages"></ol></main>
176
+ <script nonce="${nonce}">${SCRIPT}</script></html>`;
177
+ }
178
+ /** 只提供独立的买家 HTTPS 页面/API;不受理 Workbench、A2A 或代理身份请求。 */
179
+ export function createManualSupportBuyerHandler(options) {
180
+ const origin = new URL(options.origin);
181
+ if (origin.protocol !== "https:" || origin.origin !== options.origin || !options.serviceHours.trim() || !options.contactHint.trim()) {
182
+ throw new ManualSupportError("validation");
183
+ }
184
+ const end = new Map();
185
+ const count = new Map();
186
+ function limit(peer) {
187
+ const now = Date.now();
188
+ for (const [key, expiry] of end)
189
+ if (expiry <= now) {
190
+ end.delete(key);
191
+ count.delete(key);
192
+ }
193
+ if (!end.has(peer)) {
194
+ if (end.size >= 1000)
195
+ throw new ManualSupportError("capacity");
196
+ end.set(peer, now + WINDOW_MS);
197
+ }
198
+ const used = count.get(peer) ?? 0;
199
+ if (used >= MAX_NEW_SESSIONS_PER_WINDOW)
200
+ throw new ManualSupportError("capacity");
201
+ count.set(peer, used + 1);
202
+ }
203
+ function json(res, status, data) {
204
+ res.writeHead(status, { "content-type": "application/json; charset=utf-8" });
205
+ res.end(JSON.stringify(data));
206
+ }
207
+ async function handle(req, res) {
208
+ if (!(req.socket instanceof TLSSocket) || !req.socket.encrypted || single(req, "host") !== origin.host)
209
+ throw new ManualSupportError("forbidden");
210
+ const raw = req.url ?? "";
211
+ if (raw.length > 2048 || !raw.startsWith("/") || raw.startsWith("//") || raw.includes("\\"))
212
+ throw new ManualSupportError("validation");
213
+ const path = new URL(raw, origin);
214
+ if (req.method === "GET" && path.pathname === "/" && path.search === "") {
215
+ const nonce = randomBytes(24).toString("base64");
216
+ res.writeHead(200, { "content-type": "text/html; charset=utf-8", "content-security-policy": `default-src 'none'; script-src 'nonce-${nonce}'; connect-src 'self'; base-uri 'none'; frame-ancestors 'none'; form-action 'none'` });
217
+ res.end(page(nonce, options.serviceHours, options.contactHint));
218
+ return;
219
+ }
220
+ if (!path.pathname.startsWith(`${API}/`))
221
+ throw new ManualSupportError("not_found");
222
+ const relative = path.pathname.slice(API.length);
223
+ const access = token(req);
224
+ const peerOrigin = single(req, "origin");
225
+ const fetchSite = single(req, "sec-fetch-site");
226
+ if ((fetchSite !== undefined && fetchSite !== "same-origin") || (peerOrigin !== undefined && peerOrigin !== origin.origin) ||
227
+ (req.method === "POST" && peerOrigin !== origin.origin))
228
+ throw new ManualSupportError("forbidden");
229
+ if (req.method === "POST" && path.search === "") {
230
+ if (relative === "/sessions") {
231
+ if (Object.keys(await body(req)).length !== 0)
232
+ throw new ManualSupportError("validation");
233
+ const opened = options.service.begin(access, () => limit(req.socket.remoteAddress ?? "unknown"));
234
+ if (opened.token !== undefined)
235
+ res.setHeader("set-cookie", `${COOKIE}=${opened.token}; Path=/; Secure; HttpOnly; SameSite=Strict; Max-Age=${90 * DAY_SECONDS}`);
236
+ json(res, 200, { reset: opened.reset, service_hours: options.serviceHours });
237
+ return;
238
+ }
239
+ if (relative === "/sessions/current/messages") {
240
+ const value = await body(req);
241
+ if (Object.keys(value).some((key) => !["type", "client_message_id", "description", "sku"].includes(key)) ||
242
+ value.type !== "confirm_case" || typeof value.description !== "string" || typeof value.client_message_id !== "string" ||
243
+ (value.sku !== undefined && typeof value.sku !== "string"))
244
+ throw new ManualSupportError("validation");
245
+ json(res, 202, options.service.confirmCase(access, { client_message_id: value.client_message_id, description: value.description,
246
+ ...(value.sku === undefined ? {} : { sku: value.sku }) }));
247
+ return;
248
+ }
249
+ }
250
+ if (req.method === "GET") {
251
+ if (relative === "/sessions/current/updates") {
252
+ const keys = [...path.searchParams.keys()];
253
+ if (keys.length > 1 || keys.some((key) => key !== "after" && key !== "before"))
254
+ throw new ManualSupportError("validation");
255
+ const after = path.searchParams.get("after"), before = path.searchParams.get("before");
256
+ json(res, 200, options.service.updates(access, after !== null ? { after } : before !== null ? { before } : {}));
257
+ return;
258
+ }
259
+ const id = CASE_PATH.exec(relative)?.[1];
260
+ if (id !== undefined && path.search === "") {
261
+ json(res, 200, options.service.ownCase(access, id));
262
+ return;
263
+ }
264
+ }
265
+ throw new ManualSupportError("not_found");
266
+ }
267
+ return (req, res) => {
268
+ res.setHeader("cache-control", "no-store");
269
+ res.setHeader("referrer-policy", "no-referrer");
270
+ res.setHeader("x-content-type-options", "nosniff");
271
+ void handle(req, res).catch((error) => {
272
+ if (res.headersSent) {
273
+ res.destroy();
274
+ return;
275
+ }
276
+ const code = error instanceof ManualSupportError ? error.code : "unavailable";
277
+ const [status, message] = STATUS[code];
278
+ if (status === 429)
279
+ res.setHeader("retry-after", "600");
280
+ json(res, status, { error: code, message });
281
+ });
282
+ };
283
+ }
284
+ /** 只为本地验收开启;独立 hostname,使 host-only Cookie 不进入 127.0.0.1 工作台。 */
285
+ export async function startLocalManualSupportBuyer(service, options) {
286
+ if (!options.tls.key || !options.tls.cert || !options.serviceHours.trim() || !options.contactHint.trim())
287
+ throw new ManualSupportError("validation");
288
+ let handle;
289
+ const server = createServer({ ...options.tls, requestTimeout: 10_000, headersTimeout: 10_000 }, (req, res) => handle(req, res));
290
+ const origin = await new Promise((resolve, reject) => {
291
+ server.once("error", reject);
292
+ server.listen(0, "127.0.0.1", () => {
293
+ const address = server.address();
294
+ if (address === null || typeof address === "string") {
295
+ server.close();
296
+ reject(new ManualSupportError("unavailable"));
297
+ return;
298
+ }
299
+ const value = `https://localhost:${address.port}`;
300
+ handle = createManualSupportBuyerHandler({ origin: value, service, serviceHours: options.serviceHours, contactHint: options.contactHint });
301
+ resolve(value);
302
+ });
303
+ });
304
+ return { origin, close: () => new Promise((resolve) => { server.close(() => resolve()); server.closeAllConnections(); }) };
305
+ }
306
+ //# sourceMappingURL=customer-support-buyer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customer-support-buyer.js","sourceRoot":"","sources":["../../src/http/customer-support-buyer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAsB,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAA6B,MAAM,4CAA4C,CAAC;AAE3G,MAAM,GAAG,GAAG,0BAA0B,CAAC;AACvC,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAChC,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,2BAA2B,GAAG,EAAE,CAAC;AACvC,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,CAAC;AAC9B,MAAM,SAAS,GAAG,kDAAkD,CAAC;AAErE,MAAM,MAAM,GAAG;IACb,UAAU,EAAE,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,6BAA6B,CAAC;IACjF,SAAS,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,kBAAkB,CAAC;IAC5F,QAAQ,EAAE,CAAC,GAAG,EAAE,iBAAiB,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,sBAAsB,CAAC;CACtE,CAAC;AAEX,SAAS,MAAM,CAAC,GAAoB,EAAE,IAAY;IAChD,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,MAAM,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CA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EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACnI,CAAC"}
@@ -15,6 +15,8 @@
15
15
  */
16
16
  import type { IncomingMessage, ServerResponse } from "node:http";
17
17
  import type { WriteApprovalCandidate } from "../../agent/merchant/action-candidate.js";
18
+ import { type MerchantWeixinChannel } from "../../merchant/weixin-channel.js";
19
+ import { type ManualSupportService } from "../../merchant-core/support/manual-service.js";
18
20
  import type { MerchantPolicy } from "../../config/profile.js";
19
21
  import type { MerchantAdminSessions } from "../../auth/merchant-sessions.js";
20
22
  import { type createFileListingPublicationService } from "../../cloud/file-listing-publication.js";
@@ -31,10 +33,12 @@ import { type MerchantAccessMode } from "../../cloud/access/access-mode.js";
31
33
  import type { PlatformEvidenceResult } from "../../cloud/onboarding/types.js";
32
34
  import { type WorkbenchConfirmationStore } from "./webauthn-confirmation.js";
33
35
  import { type A2aNegotiationRow } from "../../merchant/workbench-service.js";
36
+ import { type NegotiationOps } from "../../merchant/negotiation-ops.js";
34
37
  import { type NegotiationObserver } from "../../merchant/negotiation-observer.js";
35
38
  import { type OperationsReportBuilder } from "../../merchant/operations-report.js";
36
39
  import type { ExactMerchantProduct } from "../../agent/merchant/types.js";
37
40
  import type { MerchantOperationsSurface } from "../../merchant-core/ops/surface.js";
41
+ import { type AlipayCollectionStore } from "../../merchant-core/collection/alipay-store.js";
38
42
  import type { GovernanceFeatureFlags } from "../../merchant-core/context-governance/feature-flags.js";
39
43
  import { type ExactMoney } from "../../merchant/application/money.js";
40
44
  import type { WorkbenchQuoteResult } from "../../merchant/quote-calculator.js";
@@ -71,6 +75,7 @@ export interface CatalogAccessSummary {
71
75
  catalogSyncError?: string | null;
72
76
  }
73
77
  export interface MerchantManagementApiOptions {
78
+ weixinChannel?: MerchantWeixinChannel;
74
79
  receiveCustomerIdentity?: ReturnType<typeof import("../../a2a/server/customer-identity-gateway.js").createCustomerIdentityReceiver>;
75
80
  /** 本实例商家(服务端绑定;不来自请求)。 */
76
81
  merchantId: string;
@@ -83,6 +88,10 @@ export interface MerchantManagementApiOptions {
83
88
  sessions: MerchantAdminSessions;
84
89
  /** 允许的写请求 Origin(精确匹配,含 scheme;请求未带 Origin 时仅 CSRF 防护)。 */
85
90
  allowedOrigins?: readonly string[];
91
+ alipayCollection?: AlipayCollectionStore;
92
+ /** Exact principal of the direct admin login, not a Catalog gateway owner-role session. */
93
+ alipayCollectionOwnerActorId?: string;
94
+ alipayNegotiationApprovals?: Pick<NegotiationOps, "listApprovals" | "approve">;
86
95
  /** 待审批候选(core 命令日志 pending 列表)。 */
87
96
  listPending: () => WriteApprovalCandidate[];
88
97
  /** 一次性候选确认凭证签发(core 凭证存储;执行层逐项核销)。 */
@@ -238,6 +247,9 @@ export interface MerchantManagementApiOptions {
238
247
  workbenchEvents?: WorkbenchEventProjectionStore;
239
248
  /** 商家持续经营(v0.2):经营计划/机会/方案/跟进;未配置时对应路由 404。 */
240
249
  merchantOperations?: MerchantOperationsSurface;
250
+ operationsSchedulerAvailable?: () => boolean;
251
+ /** 私有 M0 验收装配显式提供;默认不注册客服路由。 */
252
+ manualSupport?: ManualSupportService;
241
253
  /** M6-3 收件人绑定/订阅(P1 管理面;无则路由不存在)。 */
242
254
  deliveryConsent?: import("../../merchant-core/customer-delivery/consent-repository.js").DeliveryConsentRepository;
243
255
  /** M6 投递记录(UNKNOWN 核对路径;无则路由不存在)。 */