@harrylabsj/kiwi 0.12.0 → 0.12.2
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/README.md +12 -0
- package/dist/cloud/bootstrap.d.ts +2 -0
- package/dist/cloud/bootstrap.js +93 -10
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/catalog-client.d.ts +2 -0
- package/dist/cloud/catalog-client.js +5 -1
- package/dist/cloud/catalog-client.js.map +1 -1
- package/dist/cloud/connect-service.d.ts +153 -0
- package/dist/cloud/connect-service.js +897 -0
- package/dist/cloud/connect-service.js.map +1 -0
- package/dist/cloud/file-listing-publication.d.ts +105 -0
- package/dist/cloud/file-listing-publication.js +436 -0
- package/dist/cloud/file-listing-publication.js.map +1 -0
- package/dist/cloud/merchant-connect.d.ts +19 -13
- package/dist/cloud/merchant-connect.js +43 -284
- package/dist/cloud/merchant-connect.js.map +1 -1
- package/dist/http/merchant-management/api.d.ts +23 -1
- package/dist/http/merchant-management/api.js +141 -1
- package/dist/http/merchant-management/api.js.map +1 -1
- package/dist/http/merchant-management/page.d.ts +4 -1
- package/dist/http/merchant-management/page.js +126 -7
- package/dist/http/merchant-management/page.js.map +1 -1
- package/package.json +5 -3
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* 适用于本页(壳内嵌确认流程的中间态不留缓存)。
|
|
27
27
|
*/
|
|
28
28
|
/** 页面按 owner 视角展示管理动作;角色由服务端权限逐次裁决,前端只是提示。 */
|
|
29
|
-
export function renderMerchantManagementPage() {
|
|
29
|
+
export function renderMerchantManagementPage(options = {}) {
|
|
30
30
|
return `<!doctype html>
|
|
31
31
|
<html lang="zh-CN">
|
|
32
32
|
<head>
|
|
@@ -84,6 +84,12 @@ export function renderMerchantManagementPage() {
|
|
|
84
84
|
var CSRF = "";
|
|
85
85
|
var ROLE = "";
|
|
86
86
|
var API = "/merchant/api/v1";
|
|
87
|
+
var FILE_PRODUCTS = ${options.productAuthority === "file"};
|
|
88
|
+
var CATALOG_CONNECT = ${options.catalogConnection === true};
|
|
89
|
+
var catalogBeginKey = "";
|
|
90
|
+
var catalogBeginPending = false;
|
|
91
|
+
var publicationDraft = null;
|
|
92
|
+
var publicationBusy = false;
|
|
87
93
|
var $ = function (id) { return document.getElementById(id); };
|
|
88
94
|
function esc(s) {
|
|
89
95
|
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
|
|
@@ -124,13 +130,13 @@ async function apiError(res) {
|
|
|
124
130
|
var fallback = await res.json().catch(function () { return {}; });
|
|
125
131
|
return new Error((fallback.message || fallback.detail || fallback.code || ("HTTP " + res.status)) + "。请勿自动重复提交。");
|
|
126
132
|
}
|
|
127
|
-
function call(method, path, body) {
|
|
133
|
+
function call(method, path, body, apiBase) {
|
|
128
134
|
var headers = {};
|
|
129
135
|
if (body !== undefined) {
|
|
130
136
|
headers["content-type"] = "application/json";
|
|
131
137
|
if (CSRF) headers["x-csrf-token"] = CSRF;
|
|
132
138
|
}
|
|
133
|
-
return fetch(API + path, {
|
|
139
|
+
return fetch((apiBase || API) + path, {
|
|
134
140
|
method: method,
|
|
135
141
|
credentials: "same-origin",
|
|
136
142
|
headers: headers,
|
|
@@ -155,6 +161,64 @@ function statePill(state) {
|
|
|
155
161
|
return '<span class="pill ' + it[0] + '">' + esc(it[1]) + "</span>";
|
|
156
162
|
}
|
|
157
163
|
|
|
164
|
+
var PAIRING_CODE_HINTS = {
|
|
165
|
+
PAIRING_WINDOW_EXPIRED: "上次授权已过期:请重新发起,并在 10 分钟内到目录完成确认",
|
|
166
|
+
BIND_REJECTED: "目录拒绝了本次绑定请求:请重新发起,反复出现请联系管理员",
|
|
167
|
+
BIND_CLAIM_CARD_URL_MISMATCH: "目录名片地址与已确认的公开预览不一致:请重新核对后再发起",
|
|
168
|
+
BIND_CLAIM_FIELD_MISMATCH: "目录绑定材料与预览不一致:请重新发起",
|
|
169
|
+
BIND_CLAIM_INVALID: "目录签名材料未通过本机校验:请重新发起",
|
|
170
|
+
CARD_PUBLISH_REJECTED: "名片发布被目录拒绝:请稍后重试或联系管理员",
|
|
171
|
+
CARD_PUBLISH_INVALID: "名片发布回执不完整:请刷新后重试",
|
|
172
|
+
PAIRING_COMMUNICATION_FAILED: "与目录通信暂时失败:请稍后刷新重试"
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
function catalogStatusText(s) {
|
|
176
|
+
if (s.published) return "目录名片已发布";
|
|
177
|
+
var labels = { idle: "尚未连接", preparing: "等待你确认授权", pending: "等待你确认授权",
|
|
178
|
+
awaiting_confirmation: "等待你确认授权", authorized: "授权已收到,正在连接",
|
|
179
|
+
bound: "已连接,正在检查接待能力", expired: "授权已过期,请重新发起",
|
|
180
|
+
blocked: "连接未完成,请核对状态", paused: "目录服务已暂停", revoked: "授权已撤销" };
|
|
181
|
+
return labels[s.status] || "连接尚未完成";
|
|
182
|
+
}
|
|
183
|
+
function appendCatalogConnection(html) {
|
|
184
|
+
if (!CATALOG_CONNECT || ROLE !== "owner") return html;
|
|
185
|
+
return call("GET", "/catalog/connect").then(function (s) {
|
|
186
|
+
return html + '<div class="card"><h2>连接 Kiwi 目录</h2><p id="catalog-status">' + esc(catalogStatusText(s)) +
|
|
187
|
+
(s.errorCode ? ' <span class="muted">[' + esc(s.errorCode) + ']</span>' : '') + '</p>' +
|
|
188
|
+
(s.errorCode && PAIRING_CODE_HINTS[s.errorCode] ? '<p class="muted">' + esc(PAIRING_CODE_HINTS[s.errorCode]) + '</p>' : '') +
|
|
189
|
+
'<p class="muted">连接后,采购方可在目录发现本店。请本人核对配对码与公开资料,并在目录授权页确认发布。</p>' +
|
|
190
|
+
(s.published ? "" : '<button class="act primary" onclick="beginCatalogConnect()">发起或继续连接</button> ' +
|
|
191
|
+
'<button class="act" onclick="showCatalogPairing()">本人查看配对信息</button>') +
|
|
192
|
+
' <button class="act" onclick="refresh()">刷新连接状态</button><div id="catalog-pairing"></div></div>';
|
|
193
|
+
}).catch(function () {
|
|
194
|
+
return html + '<div class="card"><h2>连接 Kiwi 目录</h2><p>暂时无法读取连接状态,请稍后刷新。</p></div>';
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function beginCatalogConnect() {
|
|
198
|
+
if (catalogBeginPending) return;
|
|
199
|
+
catalogBeginPending = true;
|
|
200
|
+
if (!catalogBeginKey) catalogBeginKey = key("catalog-connect");
|
|
201
|
+
return call("POST", "/catalog/connect/begin", { idempotency_key: catalogBeginKey }).then(function (receipt) {
|
|
202
|
+
if (receipt.status === "succeeded") catalogBeginKey = "";
|
|
203
|
+
bar(receipt.status === "succeeded" ? "连接申请已准备,请本人查看配对信息并确认公开资料。" : "连接结果尚未确认,请先查看状态,不要重复提交。");
|
|
204
|
+
refresh();
|
|
205
|
+
}).catch(function () { bar("连接申请暂未完成,请先刷新状态后再试。", true); })
|
|
206
|
+
.finally(function () { catalogBeginPending = false; });
|
|
207
|
+
}
|
|
208
|
+
function showCatalogPairing() {
|
|
209
|
+
return call("GET", "/catalog/connect/pairing").then(function (result) {
|
|
210
|
+
var box = $("catalog-pairing");
|
|
211
|
+
if (!box) return;
|
|
212
|
+
var p = result.pairing;
|
|
213
|
+
if (!p) { box.textContent = "当前没有待确认的配对信息,请先发起连接或刷新状态。"; return; }
|
|
214
|
+
var url = new URL(p.verification_uri);
|
|
215
|
+
if (url.protocol !== "https:" || url.username || url.password) throw new Error("invalid link");
|
|
216
|
+
box.innerHTML = '<p>请在目录授权页核对相同配对码:<strong>' + esc(p.user_code) + '</strong></p>' +
|
|
217
|
+
'<p class="muted">有效期至 ' + esc(p.expires_at) + '。配对码请自行核对,不要发送给助手。</p>' +
|
|
218
|
+
'<a target="_blank" rel="noopener noreferrer" href="' + esc(url.href) + '">前往 Kiwi 目录核对并授权</a>';
|
|
219
|
+
}).catch(function () { bar("无法读取配对信息,请刷新连接状态。", true); });
|
|
220
|
+
}
|
|
221
|
+
|
|
158
222
|
var views = {
|
|
159
223
|
status: function () {
|
|
160
224
|
return call("GET", "/runtime/status").then(function (s) {
|
|
@@ -187,12 +251,19 @@ var views = {
|
|
|
187
251
|
html += '<p class="muted">恢复接待需要 owner 角色。</p>';
|
|
188
252
|
}
|
|
189
253
|
}
|
|
190
|
-
return html + "</div>";
|
|
254
|
+
return appendCatalogConnection(html + "</div>");
|
|
191
255
|
});
|
|
192
256
|
},
|
|
193
257
|
products: function () {
|
|
194
|
-
|
|
258
|
+
// 云端导入表与 exact 商品库是不同权威源;按装配选择,不能把空 exact 库当作导入失败。
|
|
259
|
+
return call("GET", "/products?limit=100", undefined, FILE_PRODUCTS ? "/merchant/api" : API).then(function (p) {
|
|
195
260
|
var rows = (p.items || []).map(function (it) {
|
|
261
|
+
if (FILE_PRODUCTS) {
|
|
262
|
+
return "<tr><td>" + esc(it.sku) + "</td><td>" + esc(it.title) + "</td><td>" +
|
|
263
|
+
esc(it.currency) + " " + esc(it.price) + " / " + esc(it.price_unit) + "</td><td>" +
|
|
264
|
+
esc(it.min_order_qty == null ? "-" : it.min_order_qty) + "</td><td>" +
|
|
265
|
+
esc(it.valid_until) + "</td><td>" + esc(it.status) + "</td></tr>";
|
|
266
|
+
}
|
|
196
267
|
var money = it.money || {};
|
|
197
268
|
return "<tr><td>" + esc(it.sku) + "</td><td>" + esc(it.title) + "</td><td>" +
|
|
198
269
|
esc(money.currency || "-") + " " + esc(money.amount_minor == null ? "-" : money.amount_minor) +
|
|
@@ -200,13 +271,20 @@ var views = {
|
|
|
200
271
|
esc(it.authority_version == null ? "-" : it.authority_version) + "</td></tr>";
|
|
201
272
|
}).join("");
|
|
202
273
|
return '<div class="card"><h2>当前商品(' + (p.items || []).length + ")</h2>" +
|
|
203
|
-
(rows ?
|
|
274
|
+
(rows ? (FILE_PRODUCTS
|
|
275
|
+
? "<table><tr><th>SKU</th><th>名称</th><th>单价</th><th>起订量</th><th>有效期至</th><th>状态</th></tr>"
|
|
276
|
+
: "<table><tr><th>SKU</th><th>名称</th><th>价格(最小币单位)</th><th>库存</th><th>版本</th></tr>") + rows + "</table>"
|
|
204
277
|
: '<p class="muted">暂无商品,请先导入商品。没有商品时服务不会报价或发布名片。</p>') + "</div>" +
|
|
205
278
|
'<div class="card"><h2>导入商品表(整表替换)</h2>' +
|
|
206
279
|
'<p class="muted">支持 CSV、Excel(.xlsx)与商品表 JSON:先转换校验、预览增/改/留/删,确认后整批生效(不成功的批次不改动现有商品)。</p>' +
|
|
207
280
|
'<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
281
|
'<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>'
|
|
282
|
+
'<button class="act" onclick="previewImport()">校验预览</button></div><div id="presult"></div></div>' +
|
|
283
|
+
(FILE_PRODUCTS && CATALOG_CONNECT && ROLE === "owner" ?
|
|
284
|
+
'<div class="card"><h2>发布商品到 Kiwi 目录</h2><p>先完成目录连接,再选择商品并填写分类。公开名称、SKU 和分类;价格、库存及私有规则不会发布。</p>' +
|
|
285
|
+
'<p>每行填写一个 SKU 和分类,用英文竖线分隔,例如:KIWI-ACCEPT-001 | 验收测试</p>' +
|
|
286
|
+
'<textarea id="publication-selection" rows="4" aria-label="选定商品与分类"></textarea>' +
|
|
287
|
+
'<button class="act" onclick="previewPublication()">预览公开内容</button><div id="publication-result"></div></div>' : '');
|
|
210
288
|
});
|
|
211
289
|
},
|
|
212
290
|
approvals: function () {
|
|
@@ -482,6 +560,47 @@ function decide(candidateId, approve) {
|
|
|
482
560
|
}
|
|
483
561
|
var pendingImport = null;
|
|
484
562
|
var parsedTable = null;
|
|
563
|
+
function previewPublication() {
|
|
564
|
+
if (publicationBusy) return;
|
|
565
|
+
publicationDraft = null;
|
|
566
|
+
var selection = $("publication-selection");
|
|
567
|
+
var lines = selection.value.split(/\\r?\\n/).filter(function (line) { return line.trim(); });
|
|
568
|
+
var selections = [];
|
|
569
|
+
for (var i = 0; i < lines.length; i++) {
|
|
570
|
+
var parts = lines[i].split("|");
|
|
571
|
+
if (parts.length !== 2 || !parts[0].trim() || !parts[1].trim()) { bar("每行需填写 SKU | 分类", true); return; }
|
|
572
|
+
selections.push({ sku: parts[0].trim(), category: parts[1].trim() });
|
|
573
|
+
}
|
|
574
|
+
publicationBusy = true;
|
|
575
|
+
return call("POST", "/products/publication-drafts", { selections: selections }).then(function (draft) {
|
|
576
|
+
publicationDraft = draft;
|
|
577
|
+
$("publication-result").innerHTML = '<h3>将公开以下内容</h3><pre>' +
|
|
578
|
+
esc(JSON.stringify(draft.items.map(function (it) { return it.listing; }), null, 2)) +
|
|
579
|
+
'</pre><p>预览有效期至 ' + esc(draft.expires_at) + '</p>' +
|
|
580
|
+
'<button class="act primary" onclick="commitPublication()">确认公开这些商品</button>';
|
|
581
|
+
}).catch(function (err) { bar(err.message, true); }).finally(function () { publicationBusy = false; });
|
|
582
|
+
}
|
|
583
|
+
function commitPublication() {
|
|
584
|
+
if (publicationBusy || !publicationDraft) return;
|
|
585
|
+
publicationBusy = true;
|
|
586
|
+
var draft = publicationDraft;
|
|
587
|
+
return call("POST", "/products/publication-drafts/" + encodeURIComponent(draft.draft_id) + "/commit", {
|
|
588
|
+
expected_digest: draft.digest, confirm_publication: true,
|
|
589
|
+
}).then(function (receipt) {
|
|
590
|
+
var text = "已确认 " + receipt.succeeded + ";失败 " + receipt.failed + ";待确认 " + receipt.pending;
|
|
591
|
+
$("publication-result").innerHTML = '<p>' + esc(text) + '</p>' +
|
|
592
|
+
'<pre>' + esc(JSON.stringify(receipt.results, null, 2)) + '</pre>' +
|
|
593
|
+
(receipt.status !== "succeeded" ? '<button class="act" onclick="checkPublication()">查看原草稿回执</button><button class="act" onclick="commitPublication()">按原草稿继续确认</button>' : '');
|
|
594
|
+
if (receipt.status === "succeeded") publicationDraft = null;
|
|
595
|
+
}).catch(function (err) { bar(err.message + " 请保留本页,查看原草稿回执。", true); })
|
|
596
|
+
.finally(function () { publicationBusy = false; });
|
|
597
|
+
}
|
|
598
|
+
function checkPublication() {
|
|
599
|
+
if (!publicationDraft) return;
|
|
600
|
+
return call("GET", "/products/publication-drafts/" + encodeURIComponent(publicationDraft.draft_id)).then(function (result) {
|
|
601
|
+
bar("原草稿回执:" + JSON.stringify(result.receipts));
|
|
602
|
+
}).catch(function (err) { bar(err.message, true); });
|
|
603
|
+
}
|
|
485
604
|
function previewImport() {
|
|
486
605
|
var f = $("pfile").files[0];
|
|
487
606
|
if (!f) { bar("请先选择 CSV / Excel / JSON 商品表文件", true); return; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../../src/http/merchant-management/page.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;GAWG;AAEH,8CAA8C;AAC9C,MAAM,UAAU,4BAA4B;
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../../src/http/merchant-management/page.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;GAWG;AAEH,8CAA8C;AAC9C,MAAM,UAAU,4BAA4B,CAAC,UAGzC,EAAE;IACJ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAyDa,OAAO,CAAC,gBAAgB,KAAK,MAAM;wBACjC,OAAO,CAAC,iBAAiB,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA8pBlD,CAAC;AACT,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harrylabsj/kiwi",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Kiwi: standalone A2A commerce negotiation agent runtime (Pi Agent Core + shopping-cli Commerce API)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,7 +42,9 @@
|
|
|
42
42
|
"demo:hermes-buyer": "bash scripts/demo-hermes-buyer.sh",
|
|
43
43
|
"verify:harness": "node integrations/harnesses/deepseek-harness/validate-contract-cases.mjs",
|
|
44
44
|
"verify:supply-chain": "node scripts/verify-facade-supply-chain.mjs",
|
|
45
|
-
"verify": "
|
|
45
|
+
"verify:workbuddy": "node integrations/hosts/workbuddy/kiwi-sourcing/scripts/validate.mjs",
|
|
46
|
+
"package:workbuddy": "bash integrations/hosts/workbuddy/kiwi-sourcing/scripts/package.sh",
|
|
47
|
+
"verify": "npm run lint && npm run typecheck && npm run build && npm run verify:browser-artifact && npm run test && npm run verify:contracts && npm run verify:vectors && npm run verify:buyer-skills && npm run verify:harness && npm run verify:portfolio-products && npm run verify:supply-chain && npm run verify:workbuddy && npm run verify:package && npm run verify:python-ref",
|
|
46
48
|
"prepublishOnly": "npm run build",
|
|
47
49
|
"conformance:a2a-sdk": "node scripts/conformance/a2a-sdk-roundtrip.mjs",
|
|
48
50
|
"conformance:tck-sut": "node scripts/conformance/start-tck-sut.mjs",
|
|
@@ -59,7 +61,7 @@
|
|
|
59
61
|
"@simplewebauthn/server": "14.0.2",
|
|
60
62
|
"ajv": "8.20.0",
|
|
61
63
|
"ajv-formats": "3.0.1",
|
|
62
|
-
"yaml": "2.9.
|
|
64
|
+
"yaml": "2.9.1"
|
|
63
65
|
},
|
|
64
66
|
"devDependencies": {
|
|
65
67
|
"@a2a-js/sdk": "^1.0.1",
|