@harrylabsj/kiwi-merchant-cloud 0.12.33 → 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.
- package/app/cloud/bootstrap.js +22 -1
- package/app/cloud/bootstrap.js.map +1 -1
- package/app/cloud-sample/products.json +3 -3
- package/app/http/customer-support-buyer.d.ts +24 -0
- package/app/http/customer-support-buyer.js +306 -0
- package/app/http/customer-support-buyer.js.map +1 -0
- package/app/http/merchant-management/api.d.ts +4 -0
- package/app/http/merchant-management/api.js +137 -24
- package/app/http/merchant-management/api.js.map +1 -1
- package/app/http/merchant-management/page.d.ts +1 -0
- package/app/http/merchant-management/page.js +302 -5
- package/app/http/merchant-management/page.js.map +1 -1
- package/app/mcp/merchant-runtime-assembly.d.ts +3 -0
- package/app/mcp/merchant-runtime-assembly.js +8 -0
- package/app/mcp/merchant-runtime-assembly.js.map +1 -1
- package/app/merchant/ai-runtime/owner-storage-admission.js.map +1 -1
- package/app/merchant/weixin-channel.d.ts +157 -1
- package/app/merchant/weixin-channel.js +127 -5
- package/app/merchant/weixin-channel.js.map +1 -1
- package/app/merchant/weixin-owner-agent-profile.d.ts +8 -0
- package/app/merchant/weixin-owner-agent-profile.js +29 -0
- package/app/merchant/weixin-owner-agent-profile.js.map +1 -0
- package/app/merchant/weixin-owner-agent.d.ts +42 -0
- package/app/merchant/weixin-owner-agent.js +97 -0
- package/app/merchant/weixin-owner-agent.js.map +1 -0
- package/app/merchant/weixin-owner-conversation.d.ts +156 -0
- package/app/merchant/weixin-owner-conversation.js +559 -0
- package/app/merchant/weixin-owner-conversation.js.map +1 -0
- package/app/merchant/weixin-owner-digest.d.ts +30 -0
- package/app/merchant/weixin-owner-digest.js +30 -0
- package/app/merchant/weixin-owner-digest.js.map +1 -0
- package/app/merchant/weixin-owner-inventory.d.ts +28 -0
- package/app/merchant/weixin-owner-inventory.js +48 -0
- package/app/merchant/weixin-owner-inventory.js.map +1 -0
- package/app/merchant/weixin-owner-source.d.ts +22 -0
- package/app/merchant/weixin-owner-source.js +104 -0
- package/app/merchant/weixin-owner-source.js.map +1 -0
- package/app/merchant/workbench-server.d.ts +4 -0
- package/app/merchant/workbench-server.js +63 -10
- package/app/merchant/workbench-server.js.map +1 -1
- package/app/merchant-core/operations-jobs/service.d.ts +11 -0
- package/app/merchant-core/operations-jobs/service.js +65 -34
- package/app/merchant-core/operations-jobs/service.js.map +1 -1
- package/app/merchant-core/ops/surface.d.ts +1 -0
- package/app/merchant-core/ops/surface.js +9 -0
- package/app/merchant-core/ops/surface.js.map +1 -1
- package/app/merchant-core/support/manual-service.d.ts +114 -0
- package/app/merchant-core/support/manual-service.js +300 -0
- package/app/merchant-core/support/manual-service.js.map +1 -0
- package/app/negotiation/ledger/store.d.ts +2 -0
- package/app/negotiation/ledger/store.js +8 -0
- package/app/negotiation/ledger/store.js.map +1 -1
- package/app/net/safe-http.d.ts +2 -0
- package/app/net/safe-http.js +1 -1
- package/app/net/safe-http.js.map +1 -1
- package/app/weixin/ilink-client.js +50 -19
- package/app/weixin/ilink-client.js.map +1 -1
- package/app/weixin/types.d.ts +3 -1
- package/app/weixin/types.js.map +1 -1
- package/build-manifest.json +203 -83
- package/deployment-lock.json +85 -77
- package/package.json +7 -7
- package/runtime-package.json +13 -13
- package/shipping-sbom.cdx.json +150 -145
- 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
|
+
"&": "&", "<": "<", ">": ">", '"': """, "'": "'",
|
|
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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E,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;YAC3I,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACnI,CAAC"}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
17
17
|
import type { WriteApprovalCandidate } from "../../agent/merchant/action-candidate.js";
|
|
18
18
|
import { type MerchantWeixinChannel } from "../../merchant/weixin-channel.js";
|
|
19
|
+
import { type ManualSupportService } from "../../merchant-core/support/manual-service.js";
|
|
19
20
|
import type { MerchantPolicy } from "../../config/profile.js";
|
|
20
21
|
import type { MerchantAdminSessions } from "../../auth/merchant-sessions.js";
|
|
21
22
|
import { type createFileListingPublicationService } from "../../cloud/file-listing-publication.js";
|
|
@@ -246,6 +247,9 @@ export interface MerchantManagementApiOptions {
|
|
|
246
247
|
workbenchEvents?: WorkbenchEventProjectionStore;
|
|
247
248
|
/** 商家持续经营(v0.2):经营计划/机会/方案/跟进;未配置时对应路由 404。 */
|
|
248
249
|
merchantOperations?: MerchantOperationsSurface;
|
|
250
|
+
operationsSchedulerAvailable?: () => boolean;
|
|
251
|
+
/** 私有 M0 验收装配显式提供;默认不注册客服路由。 */
|
|
252
|
+
manualSupport?: ManualSupportService;
|
|
249
253
|
/** M6-3 收件人绑定/订阅(P1 管理面;无则路由不存在)。 */
|
|
250
254
|
deliveryConsent?: import("../../merchant-core/customer-delivery/consent-repository.js").DeliveryConsentRepository;
|
|
251
255
|
/** M6 投递记录(UNKNOWN 核对路径;无则路由不存在)。 */
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
*/
|
|
40
40
|
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
41
41
|
import { MerchantWeixinError } from "../../merchant/weixin-channel.js";
|
|
42
|
+
import { OwnerConversationError } from "../../merchant/weixin-owner-conversation.js";
|
|
43
|
+
import { ManualSupportError } from "../../merchant-core/support/manual-service.js";
|
|
42
44
|
import { contentHash } from "../../agent/merchant/action-candidate.js";
|
|
43
45
|
import { ADMIN_SESSION_COOKIE } from "../../auth/merchant-sessions.js";
|
|
44
46
|
import { FileListingPublicationError, } from "../../cloud/file-listing-publication.js";
|
|
@@ -270,6 +272,10 @@ export function createMerchantManagementApiHandler(options) {
|
|
|
270
272
|
const requestId = `req_${randomBytes(12).toString("hex")}`;
|
|
271
273
|
const rest = pathname === WORKBENCH_API_PREFIX ? "/" : pathname.slice(WORKBENCH_API_PREFIX.length);
|
|
272
274
|
try {
|
|
275
|
+
if (options.manualSupport !== undefined && (rest === "/support" || rest.startsWith("/support/"))) {
|
|
276
|
+
await routeManualSupport(options.manualSupport, req, res, method, rest);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
273
279
|
if (rest === "/channels/weixin" || rest.startsWith("/channels/weixin/")) {
|
|
274
280
|
await routeWeixin(req, res, method, rest);
|
|
275
281
|
return;
|
|
@@ -317,6 +323,62 @@ export function createMerchantManagementApiHandler(options) {
|
|
|
317
323
|
}
|
|
318
324
|
writeJson(res, 404, errorBody("not_found", "unknown management api path"));
|
|
319
325
|
}
|
|
326
|
+
async function routeManualSupport(support, req, res, method, rest) {
|
|
327
|
+
const auth = requireActor(req);
|
|
328
|
+
if (auth.ctx.merchantId !== options.merchantId)
|
|
329
|
+
throw new ManagementError("not_found", "工单不存在。");
|
|
330
|
+
if (auth.ctx.role !== "owner")
|
|
331
|
+
throw new ManagementError("forbidden", "当前预览仅店主可处理售后工单。");
|
|
332
|
+
const match = /^\/support\/cases\/(CS-[0-9a-f-]{36})(?:\/(claim|reply|resolve|revoke))?$/.exec(rest);
|
|
333
|
+
try {
|
|
334
|
+
if (method === "GET" && rest === "/support/cases") {
|
|
335
|
+
writeJson(res, 200, { cases: support.list(auth.ctx) });
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (method === "GET" && match?.[1] !== undefined && match[2] === undefined) {
|
|
339
|
+
writeJson(res, 200, support.detail(auth.ctx, match[1]));
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (method === "POST" && match?.[1] !== undefined && match[2] !== undefined) {
|
|
343
|
+
assertWriteGuards(req, auth.sessionId);
|
|
344
|
+
const kind = match[2];
|
|
345
|
+
const fields = objectFields(await readJsonBody(req, 8192), kind === "reply" || kind === "resolve"
|
|
346
|
+
? ["expected_revision", "text"] : ["expected_revision"]);
|
|
347
|
+
const revision = fields.expected_revision;
|
|
348
|
+
if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 1) {
|
|
349
|
+
throw new ManagementError("invalid_input", "工单版本无效。");
|
|
350
|
+
}
|
|
351
|
+
// 请求体读取期间可能已经注销或撤销授权;不要提交旧会话已缓存的权限。
|
|
352
|
+
const fresh = requireActor(req);
|
|
353
|
+
if (fresh.ctx.generation !== auth.ctx.generation)
|
|
354
|
+
throw new ManagementError("forbidden", "管理部署代次已变化。");
|
|
355
|
+
if (kind === "reply" || kind === "resolve") {
|
|
356
|
+
if (typeof fields.text !== "string")
|
|
357
|
+
throw new ManagementError("invalid_input", "请输入人工说明。");
|
|
358
|
+
writeJson(res, 200, support.change(fresh.ctx, match[1], revision, { kind, text: fields.text }));
|
|
359
|
+
}
|
|
360
|
+
else if (kind === "claim" || kind === "revoke") {
|
|
361
|
+
writeJson(res, 200, support.change(fresh.ctx, match[1], revision, { kind }));
|
|
362
|
+
}
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
if (error instanceof BodyTooLarge)
|
|
368
|
+
throw new ManagementError("invalid_input", "工单请求过大。");
|
|
369
|
+
if (error instanceof ManualSupportError) {
|
|
370
|
+
switch (error.code) {
|
|
371
|
+
case "validation": throw new ManagementError("invalid_input", "工单输入无效。");
|
|
372
|
+
case "not_found": throw new ManagementError("not_found", "工单不存在。");
|
|
373
|
+
case "conflict": throw new ManagementError("precondition_changed", "工单版本、坐席或浏览器权限已变化。");
|
|
374
|
+
case "forbidden": throw new ManagementError("forbidden", "当前主体无权处理该工单。");
|
|
375
|
+
default: throw new ManagementError("unavailable", "工单服务暂不可用。");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
throw error;
|
|
379
|
+
}
|
|
380
|
+
throw new ManagementError("not_found", "工单路由不存在。");
|
|
381
|
+
}
|
|
320
382
|
async function routeWeixin(req, res, method, rest) {
|
|
321
383
|
const channel = options.weixinChannel;
|
|
322
384
|
if (channel === undefined)
|
|
@@ -328,27 +390,9 @@ export function createMerchantManagementApiHandler(options) {
|
|
|
328
390
|
if (actor.role !== "owner")
|
|
329
391
|
throw new ManagementError("forbidden", "仅店主可管理微信通道。");
|
|
330
392
|
const base = "/channels/weixin";
|
|
331
|
-
if (method === "GET" && rest === base) {
|
|
332
|
-
writeJson(res, 200, channel.status());
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
const action = rest.slice(base.length + 1);
|
|
336
|
-
if (method !== "POST" || !["begin", "poll", "cancel", "disconnect"].includes(action)) {
|
|
337
|
-
throw new ManagementError("not_found", "微信通道路由不存在。");
|
|
338
|
-
}
|
|
339
|
-
assertWriteGuards(req, auth.sessionId);
|
|
340
|
-
let fields;
|
|
341
|
-
try {
|
|
342
|
-
fields = objectFields(await readJsonBody(req, 2048), action === "poll" ? ["attempt_id", "verify_code"] : action === "cancel" ? ["attempt_id"] : []);
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
if (error instanceof BodyTooLarge || error instanceof ManagementError) {
|
|
346
|
-
throw new ManagementError("invalid_input", "微信通道请求字段无效或请求过大。");
|
|
347
|
-
}
|
|
348
|
-
throw error;
|
|
349
|
-
}
|
|
350
393
|
const owner = {
|
|
351
394
|
sessionId: auth.sessionId,
|
|
395
|
+
principalId: actor.actorId,
|
|
352
396
|
generation: actor.generation,
|
|
353
397
|
current: () => {
|
|
354
398
|
if (actor.generation !== options.generation())
|
|
@@ -358,8 +402,75 @@ export function createMerchantManagementApiHandler(options) {
|
|
|
358
402
|
session.principal_id === actor.actorId;
|
|
359
403
|
},
|
|
360
404
|
};
|
|
405
|
+
const action = rest.slice(base.length + 1);
|
|
406
|
+
const draftId = /^reply-drafts\/([0-9a-f-]{36})$/.exec(action)?.[1];
|
|
361
407
|
try {
|
|
362
|
-
if (
|
|
408
|
+
if (method === "GET" && rest === base) {
|
|
409
|
+
const status = channel.status(owner.principalId);
|
|
410
|
+
writeJson(res, 200, !("conversation" in status) ? status : {
|
|
411
|
+
...status, operations_available: options.governance?.flags.jobs_enabled === true && options.merchantOperations !== undefined &&
|
|
412
|
+
options.operationsSchedulerAvailable?.() === true,
|
|
413
|
+
});
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (method === "GET" && action === "followup-preference") {
|
|
417
|
+
writeJson(res, 200, channel.followupPreference(owner));
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (method === "GET" && action === "reply-drafts") {
|
|
421
|
+
writeJson(res, 200, { items: channel.replyDrafts(owner) });
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (method === "GET" && draftId !== undefined) {
|
|
425
|
+
writeJson(res, 200, channel.replyDraft(owner, draftId));
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (method !== "POST" || (draftId === undefined &&
|
|
429
|
+
!["begin", "poll", "cancel", "disconnect", "confirm-conversation", "clear-conversation", "revoke-conversation", "followup-preference"].includes(action))) {
|
|
430
|
+
throw new ManagementError("not_found", "微信通道路由不存在。");
|
|
431
|
+
}
|
|
432
|
+
assertWriteGuards(req, auth.sessionId);
|
|
433
|
+
let fields;
|
|
434
|
+
try {
|
|
435
|
+
fields = objectFields(await readJsonBody(req, draftId === undefined ? 2048 : 8192), draftId !== undefined ? ["version", "body"] : action === "followup-preference" ? ["version", "style"] : action === "poll" ? ["attempt_id", "verify_code"] : action === "cancel" ? ["attempt_id"] : action === "confirm-conversation" ? ["model_consent"] : []);
|
|
436
|
+
}
|
|
437
|
+
catch (error) {
|
|
438
|
+
if (error instanceof BodyTooLarge || error instanceof ManagementError) {
|
|
439
|
+
throw new ManagementError("invalid_input", "微信通道请求字段无效或请求过大。");
|
|
440
|
+
}
|
|
441
|
+
throw error;
|
|
442
|
+
}
|
|
443
|
+
if (draftId !== undefined) {
|
|
444
|
+
const version = fields["version"];
|
|
445
|
+
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 1) {
|
|
446
|
+
throw new ManagementError("invalid_input", "草稿版本无效。");
|
|
447
|
+
}
|
|
448
|
+
writeJson(res, 200, channel.replyDraft(owner, draftId, { version, body: requireString(fields["body"], "body") }));
|
|
449
|
+
}
|
|
450
|
+
else if (action === "followup-preference") {
|
|
451
|
+
const version = fields["version"];
|
|
452
|
+
const style = fields["style"];
|
|
453
|
+
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 0 ||
|
|
454
|
+
(style !== null && style !== "concise" && style !== "warm")) {
|
|
455
|
+
throw new ManagementError("invalid_input", "偏好的版本或语气无效。");
|
|
456
|
+
}
|
|
457
|
+
writeJson(res, 200, channel.followupPreference(owner, { version, style }));
|
|
458
|
+
}
|
|
459
|
+
else if (action === "confirm-conversation" || action === "clear-conversation" || action === "revoke-conversation") {
|
|
460
|
+
if (action === "confirm-conversation") {
|
|
461
|
+
const consent = fields["model_consent"];
|
|
462
|
+
if (consent !== undefined && (typeof consent !== "string" || !/^[a-f0-9]{64}$/.test(consent))) {
|
|
463
|
+
throw new ManagementError("invalid_input", "模型授权标识无效。");
|
|
464
|
+
}
|
|
465
|
+
channel.confirmConversation(owner, consent);
|
|
466
|
+
}
|
|
467
|
+
else if (action === "clear-conversation")
|
|
468
|
+
channel.clearConversation(owner);
|
|
469
|
+
else
|
|
470
|
+
channel.revokeConversation(owner);
|
|
471
|
+
writeJson(res, 200, { ok: true });
|
|
472
|
+
}
|
|
473
|
+
else if (action === "begin") {
|
|
363
474
|
writeJson(res, 200, await channel.begin(owner));
|
|
364
475
|
}
|
|
365
476
|
else if (action === "disconnect") {
|
|
@@ -379,8 +490,9 @@ export function createMerchantManagementApiHandler(options) {
|
|
|
379
490
|
}
|
|
380
491
|
}
|
|
381
492
|
catch (error) {
|
|
382
|
-
if (error instanceof MerchantWeixinError)
|
|
493
|
+
if (error instanceof MerchantWeixinError || error instanceof OwnerConversationError) {
|
|
383
494
|
throw new ManagementError(error.code, error.message);
|
|
495
|
+
}
|
|
384
496
|
throw error;
|
|
385
497
|
}
|
|
386
498
|
}
|
|
@@ -1563,13 +1675,14 @@ export function createMerchantManagementApiHandler(options) {
|
|
|
1563
1675
|
writeJson(res, 201, writeGoverned(() => ops.activateRule(body)), { "x-request-id": requestId });
|
|
1564
1676
|
return;
|
|
1565
1677
|
}
|
|
1566
|
-
const
|
|
1567
|
-
if (
|
|
1678
|
+
const ruleControlMatch = /^\/automation\/rules\/([^/]+)\/(pause|resume)$/.exec(rest);
|
|
1679
|
+
if (ruleControlMatch !== null) {
|
|
1568
1680
|
const auth = requireActor(req);
|
|
1569
1681
|
assertWriteGuards(req, auth.sessionId);
|
|
1570
1682
|
authorizeOrThrow(auth.ctx, "followups:manage");
|
|
1571
1683
|
const { body } = await readOpsBody();
|
|
1572
|
-
|
|
1684
|
+
const id = pathSegment(ruleControlMatch[1] ?? "");
|
|
1685
|
+
writeJson(res, 200, writeGoverned(() => ruleControlMatch[2] === "pause" ? ops.pauseRule(id, body) : ops.resumeRule(id, body)), {
|
|
1573
1686
|
"x-request-id": requestId,
|
|
1574
1687
|
});
|
|
1575
1688
|
return;
|