@harrylabsj/kiwi 0.12.27 → 0.12.29
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 +9 -2
- package/contracts/kiwi-catalog/1.0/agent-record.schema.json +29 -0
- package/contracts/kiwi-contracts.lock.json +2 -2
- package/contracts/manifest.json +2 -2
- package/dist/a2a/admission.js +2 -1
- package/dist/a2a/admission.js.map +1 -1
- package/dist/a2a/node.d.ts +6 -0
- package/dist/a2a/node.js +70 -10
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/reception/agent-runtime.js +9 -3
- package/dist/a2a/reception/agent-runtime.js.map +1 -1
- package/dist/a2a/reception/reply-outbox.d.ts +6 -0
- package/dist/a2a/reception/reply-outbox.js +13 -0
- package/dist/a2a/reception/reply-outbox.js.map +1 -1
- package/dist/a2a/reception/retention.d.ts +1 -0
- package/dist/a2a/reception/retention.js +9 -1
- package/dist/a2a/reception/retention.js.map +1 -1
- package/dist/a2a/server/auth.js +22 -3
- package/dist/a2a/server/auth.js.map +1 -1
- package/dist/a2a/server/identity.d.ts +23 -0
- package/dist/a2a/server/identity.js +27 -0
- package/dist/a2a/server/identity.js.map +1 -0
- package/dist/a2a/server/merchant-handler.d.ts +0 -11
- package/dist/a2a/server/merchant-handler.js +13 -6
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/negotiation-advisor.js +3 -1
- package/dist/a2a/server/negotiation-advisor.js.map +1 -1
- package/dist/a2a/server/pipeline.d.ts +7 -1
- package/dist/a2a/server/pipeline.js +65 -35
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/server/server.d.ts +0 -17
- package/dist/a2a/server/server.js +21 -4
- package/dist/a2a/server/server.js.map +1 -1
- package/dist/a2a/server/task-registry.d.ts +3 -0
- package/dist/a2a/server/task-registry.js +33 -1
- package/dist/a2a/server/task-registry.js.map +1 -1
- package/dist/agent/buyer/buyer-tools.js +33 -19
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/ranker.js +32 -14
- package/dist/agent/buyer/ranker.js.map +1 -1
- package/dist/agent/buyer/scheduler.js +12 -3
- package/dist/agent/buyer/scheduler.js.map +1 -1
- package/dist/agent/buyer/types.d.ts +2 -1
- package/dist/agent/buyer/types.js.map +1 -1
- package/dist/agent/connector/types.d.ts +4 -2
- package/dist/agent/connector/types.js +8 -2
- package/dist/agent/connector/types.js.map +1 -1
- package/dist/agent/host/events.js +1 -1
- package/dist/agent/host/events.js.map +1 -1
- package/dist/agent/kernel.js +14 -7
- package/dist/agent/kernel.js.map +1 -1
- package/dist/agent/negotiation-chat.js +6 -4
- package/dist/agent/negotiation-chat.js.map +1 -1
- package/dist/agent/presentation/sanitize.js +1 -1
- package/dist/agent/presentation/sanitize.js.map +1 -1
- package/dist/agent/supplier/scheduler.js.map +1 -1
- package/dist/auth/merchant-pairing.js +5 -0
- package/dist/auth/merchant-pairing.js.map +1 -1
- package/dist/auth/merchant-sessions.js +19 -4
- package/dist/auth/merchant-sessions.js.map +1 -1
- package/dist/buyer-core/a2a-negotiator.d.ts +7 -0
- package/dist/buyer-core/a2a-negotiator.js +17 -3
- package/dist/buyer-core/a2a-negotiator.js.map +1 -1
- package/dist/buyer-core/a2a-quote-fetcher.d.ts +22 -0
- package/dist/buyer-core/a2a-quote-fetcher.js +71 -3
- package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
- package/dist/buyer-core/build-service.d.ts +7 -0
- package/dist/buyer-core/build-service.js +249 -22
- package/dist/buyer-core/build-service.js.map +1 -1
- package/dist/buyer-core/buyer-route-hint-store.d.ts +21 -0
- package/dist/buyer-core/buyer-route-hint-store.js +119 -0
- package/dist/buyer-core/buyer-route-hint-store.js.map +1 -0
- package/dist/buyer-core/merchant-index.js +7 -2
- package/dist/buyer-core/merchant-index.js.map +1 -1
- package/dist/buyer-core/service.d.ts +15 -0
- package/dist/buyer-core/service.js +34 -9
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/buyer-core/store.d.ts +11 -0
- package/dist/buyer-core/store.js +68 -0
- package/dist/buyer-core/store.js.map +1 -1
- package/dist/cli.js +61 -8
- package/dist/cli.js.map +1 -1
- package/dist/cloud/access/access-mode.d.ts +56 -0
- package/dist/cloud/access/access-mode.js +129 -0
- package/dist/cloud/access/access-mode.js.map +1 -0
- package/dist/cloud/binding/enrollment-challenge.js +3 -2
- package/dist/cloud/binding/enrollment-challenge.js.map +1 -1
- package/dist/cloud/binding/runtime-challenge.js +3 -2
- package/dist/cloud/binding/runtime-challenge.js.map +1 -1
- package/dist/cloud/binding/store-lock.js +16 -7
- package/dist/cloud/binding/store-lock.js.map +1 -1
- package/dist/cloud/bootstrap.d.ts +1 -1
- package/dist/cloud/bootstrap.js +64 -7
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/catalog-client.d.ts +25 -1
- package/dist/cloud/catalog-client.js +163 -4
- package/dist/cloud/catalog-client.js.map +1 -1
- package/dist/cloud/connect-service.d.ts +69 -0
- package/dist/cloud/connect-service.js +418 -50
- package/dist/cloud/connect-service.js.map +1 -1
- package/dist/cloud/file-listing-publication.d.ts +15 -0
- package/dist/cloud/file-listing-publication.js +34 -3
- package/dist/cloud/file-listing-publication.js.map +1 -1
- package/dist/cloud/owned-runtime.js +21 -2
- package/dist/cloud/owned-runtime.js.map +1 -1
- package/dist/cloud/product-import-tabular.d.ts +7 -3
- package/dist/cloud/product-import-tabular.js +100 -45
- package/dist/cloud/product-import-tabular.js.map +1 -1
- package/dist/cloud/product-source.d.ts +10 -3
- package/dist/cloud/product-source.js +12 -8
- package/dist/cloud/product-source.js.map +1 -1
- package/dist/cloud/trade-platforms-client.d.ts +14 -0
- package/dist/cloud/trade-platforms-client.js +40 -0
- package/dist/cloud/trade-platforms-client.js.map +1 -0
- package/dist/commerce/types.d.ts +6 -2
- package/dist/commerce/types.js +10 -3
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/profile.d.ts +5 -0
- package/dist/config/profile.js +7 -2
- package/dist/config/profile.js.map +1 -1
- package/dist/counterparty/shopping-cli-hosted/index.js +20 -12
- package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-record.d.ts +23 -0
- package/dist/discovery/catalog-source/kiwi-record.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.js +4 -1
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/discovery/merchant-subscriptions.js +9 -0
- package/dist/discovery/merchant-subscriptions.js.map +1 -1
- package/dist/handoff/channel.js +3 -1
- package/dist/handoff/channel.js.map +1 -1
- package/dist/handoff/idempotency.d.ts +6 -0
- package/dist/handoff/idempotency.js +71 -18
- package/dist/handoff/idempotency.js.map +1 -1
- package/dist/handoff/launch-marketplace-policy.d.ts +1 -1
- package/dist/handoff/launch-marketplace-policy.js +9 -1
- package/dist/handoff/launch-marketplace-policy.js.map +1 -1
- package/dist/handoff/ledger.d.ts +6 -1
- package/dist/handoff/ledger.js +13 -2
- package/dist/handoff/ledger.js.map +1 -1
- package/dist/handoff/marketplace-product-link.d.ts +28 -9
- package/dist/handoff/marketplace-product-link.js +172 -46
- package/dist/handoff/marketplace-product-link.js.map +1 -1
- package/dist/handoff/operator-approval.d.ts +3 -0
- package/dist/handoff/operator-approval.js +34 -1
- package/dist/handoff/operator-approval.js.map +1 -1
- package/dist/handoff/trade-platform-rules.d.ts +26 -0
- package/dist/handoff/trade-platform-rules.js +95 -0
- package/dist/handoff/trade-platform-rules.js.map +1 -0
- package/dist/handoff/transaction.d.ts +5 -0
- package/dist/handoff/transaction.js +7 -1
- package/dist/handoff/transaction.js.map +1 -1
- package/dist/handoff/ucp-checkout/channel.d.ts +14 -0
- package/dist/handoff/ucp-checkout/channel.js +87 -1
- package/dist/handoff/ucp-checkout/channel.js.map +1 -1
- package/dist/handoff/ucp-checkout/types.d.ts +1 -1
- package/dist/handoff/ucp-checkout/types.js +3 -0
- package/dist/handoff/ucp-checkout/types.js.map +1 -1
- package/dist/handoff/url-safety.js +8 -1
- package/dist/handoff/url-safety.js.map +1 -1
- package/dist/http/bounded-ip-rate-limit.js +16 -2
- package/dist/http/bounded-ip-rate-limit.js.map +1 -1
- package/dist/http/merchant-management/api.d.ts +20 -0
- package/dist/http/merchant-management/api.js +125 -14
- package/dist/http/merchant-management/api.js.map +1 -1
- package/dist/http/merchant-management/draft-store.d.ts +8 -1
- package/dist/http/merchant-management/draft-store.js +36 -6
- package/dist/http/merchant-management/draft-store.js.map +1 -1
- package/dist/http/merchant-management/page.js +343 -82
- package/dist/http/merchant-management/page.js.map +1 -1
- package/dist/http/merchant-management/trusted-page.js +5 -3
- package/dist/http/merchant-management/trusted-page.js.map +1 -1
- package/dist/http/merchant-privacy-api.js +24 -0
- package/dist/http/merchant-privacy-api.js.map +1 -1
- package/dist/http/merchant-server.js +13 -4
- package/dist/http/merchant-server.js.map +1 -1
- package/dist/http/server.js +25 -5
- package/dist/http/server.js.map +1 -1
- package/dist/mcp/cli.d.ts +2 -0
- package/dist/mcp/cli.js +11 -0
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/merchant-server.js +8 -6
- package/dist/mcp/merchant-server.js.map +1 -1
- package/dist/merchant/application/service.d.ts +2 -1
- package/dist/merchant/application/service.js.map +1 -1
- package/dist/merchant/decision-backend.js +24 -2
- package/dist/merchant/decision-backend.js.map +1 -1
- package/dist/merchant/negotiation-observer.js +12 -2
- package/dist/merchant/negotiation-observer.js.map +1 -1
- package/dist/merchant/watch/detect.js +14 -0
- package/dist/merchant/watch/detect.js.map +1 -1
- package/dist/merchant/watch/weixin.js +7 -1
- package/dist/merchant/watch/weixin.js.map +1 -1
- package/dist/merchant-core/commands.d.ts +5 -0
- package/dist/merchant-core/commands.js +19 -0
- package/dist/merchant-core/commands.js.map +1 -1
- package/dist/merchant-core/executor.js +3 -2
- package/dist/merchant-core/executor.js.map +1 -1
- package/dist/merchant-core/operating/service.js +9 -0
- package/dist/merchant-core/operating/service.js.map +1 -1
- package/dist/merchant-core/operations.js +18 -4
- package/dist/merchant-core/operations.js.map +1 -1
- package/dist/merchant-core/opportunity/service.js +9 -0
- package/dist/merchant-core/opportunity/service.js.map +1 -1
- package/dist/merchant-core/orders/repository.js +8 -0
- package/dist/merchant-core/orders/repository.js.map +1 -1
- package/dist/merchant-core/product-import.d.ts +9 -0
- package/dist/merchant-core/product-import.js +17 -3
- package/dist/merchant-core/product-import.js.map +1 -1
- package/dist/merchant-core/proposal/service.js +9 -0
- package/dist/merchant-core/proposal/service.js.map +1 -1
- package/dist/merchant-core/rfq/delivery.js +1 -1
- package/dist/merchant-core/rfq/delivery.js.map +1 -1
- package/dist/merchant-core/rfq/handoff.js +2 -3
- package/dist/merchant-core/rfq/handoff.js.map +1 -1
- package/dist/merchant-core/rfq/policy.d.ts +0 -8
- package/dist/merchant-core/rfq/policy.js +6 -1
- package/dist/merchant-core/rfq/policy.js.map +1 -1
- package/dist/merchant-core/rfq/repository.d.ts +2 -0
- package/dist/merchant-core/rfq/repository.js +10 -1
- package/dist/merchant-core/rfq/repository.js.map +1 -1
- package/dist/merchant-core/service.js +21 -3
- package/dist/merchant-core/service.js.map +1 -1
- package/dist/merchant-gateway/credential-vault.d.ts +3 -0
- package/dist/merchant-gateway/credential-vault.js +54 -10
- package/dist/merchant-gateway/credential-vault.js.map +1 -1
- package/dist/merchant-gateway/entry-server.js +13 -3
- package/dist/merchant-gateway/entry-server.js.map +1 -1
- package/dist/merchant-runtime/manager.d.ts +2 -0
- package/dist/merchant-runtime/manager.js +49 -1
- package/dist/merchant-runtime/manager.js.map +1 -1
- package/dist/negotiation/ledger/store.js +6 -3
- package/dist/negotiation/ledger/store.js.map +1 -1
- package/dist/net/client-ip.d.ts +29 -0
- package/dist/net/client-ip.js +39 -0
- package/dist/net/client-ip.js.map +1 -0
- package/dist/net/safe-http.d.ts +1 -1
- package/dist/net/safe-http.js +8 -0
- package/dist/net/safe-http.js.map +1 -1
- package/dist/operator/controller.js +3 -1
- package/dist/operator/controller.js.map +1 -1
- package/dist/operator/runner.js +1 -1
- package/dist/operator/runner.js.map +1 -1
- package/dist/operator/tui.js +10 -3
- package/dist/operator/tui.js.map +1 -1
- package/dist/product-buyer.js +1 -0
- package/dist/product-buyer.js.map +1 -1
- package/dist/product-cli.js +2 -1
- package/dist/product-cli.js.map +1 -1
- package/dist/protocol/legacy-shopping-negotiation/adapter.js +9 -0
- package/dist/protocol/legacy-shopping-negotiation/adapter.js.map +1 -1
- package/dist/runtime/bounded-memory.d.ts +25 -0
- package/dist/runtime/bounded-memory.js +60 -0
- package/dist/runtime/bounded-memory.js.map +1 -0
- package/dist/runtime/fake-model.js +7 -1
- package/dist/runtime/fake-model.js.map +1 -1
- package/dist/runtime/lock-owner.d.ts +36 -0
- package/dist/runtime/lock-owner.js +98 -0
- package/dist/runtime/lock-owner.js.map +1 -0
- package/dist/runtime/locks-cli.d.ts +21 -0
- package/dist/runtime/locks-cli.js +94 -0
- package/dist/runtime/locks-cli.js.map +1 -0
- package/dist/runtime/locks.d.ts +60 -0
- package/dist/runtime/locks.js +202 -0
- package/dist/runtime/locks.js.map +1 -0
- package/dist/runtime/negotiation-turn.js +1 -1
- package/dist/runtime/negotiation-turn.js.map +1 -1
- package/dist/trust/identity/auth-verifier.d.ts +23 -21
- package/dist/trust/identity/auth-verifier.js +65 -1
- package/dist/trust/identity/auth-verifier.js.map +1 -1
- package/dist/trust/identity/jwk.d.ts +1 -0
- package/dist/trust/identity/signature-base.js +3 -1
- package/dist/trust/identity/signature-base.js.map +1 -1
- package/dist/trust/records/store.d.ts +7 -1
- package/dist/trust/records/store.js +44 -14
- package/dist/trust/records/store.js.map +1 -1
- package/dist/weixin/channel.js +11 -1
- package/dist/weixin/channel.js.map +1 -1
- package/package.json +5 -3
|
@@ -42,6 +42,7 @@ export function renderMerchantManagementPage(options = {}) {
|
|
|
42
42
|
a { color: var(--kiwi); text-underline-offset: 3px; }
|
|
43
43
|
button { cursor: pointer; }
|
|
44
44
|
button:disabled { cursor: not-allowed; opacity: .55; }
|
|
45
|
+
.act.primary:disabled { background: #a4aea7; border-color: #a4aea7; color: #fff; }
|
|
45
46
|
:focus-visible { outline: 3px solid #9b7214; outline-offset: 3px; }
|
|
46
47
|
.skip-link { position: fixed; left: 16px; top: -80px; z-index: 20; padding: 10px 16px; background: #fff; border: 2px solid var(--kiwi); border-radius: 8px; }
|
|
47
48
|
.skip-link:focus { top: 12px; }
|
|
@@ -94,6 +95,10 @@ export function renderMerchantManagementPage(options = {}) {
|
|
|
94
95
|
input[type=checkbox] { accent-color: var(--kiwi); width: 16px; height: 16px; vertical-align: middle; }
|
|
95
96
|
.muted { color: var(--muted); font-size: 12px; line-height: 1.8; }
|
|
96
97
|
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
|
|
98
|
+
.consent-label { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
|
|
99
|
+
.consent-label span { flex: 1; min-width: 0; }
|
|
100
|
+
.consent-label input { flex: none; margin: 3px 0 0; }
|
|
101
|
+
details summary { cursor: pointer; color: var(--kiwi); text-decoration: underline; text-underline-offset: 3px; }
|
|
97
102
|
.row > .muted { flex: 1 1 180px; }
|
|
98
103
|
pre.digest { font: 11px ui-monospace, monospace; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; margin: 4px 0; max-width: 320px; }
|
|
99
104
|
label { font-size: 13px; }
|
|
@@ -173,6 +178,7 @@ var catalogBeginKey = "";
|
|
|
173
178
|
var catalogBeginPending = false;
|
|
174
179
|
var catalogConnectionState = null;
|
|
175
180
|
var catalogAccessState = null;
|
|
181
|
+
var catalogAccessDetection = null;
|
|
176
182
|
var publicationDraft = null;
|
|
177
183
|
var publicationPicks = null;
|
|
178
184
|
var publicationBusy = false;
|
|
@@ -187,8 +193,19 @@ function marketplaceLink(it) {
|
|
|
187
193
|
if (typeof value !== "string") return "-";
|
|
188
194
|
try {
|
|
189
195
|
var url = new URL(value);
|
|
190
|
-
if (url.protocol !== "https:" || url.username || url.password
|
|
191
|
-
|
|
196
|
+
if (url.protocol !== "https:" || url.username || url.password) return "-";
|
|
197
|
+
// 链接由服务端按运营配置的模板生成;这里仍拒绝仿冒已知平台的域名
|
|
198
|
+
// (如 item.jd.com.evil.example),避免页面为冒名站点背书。
|
|
199
|
+
var labels = url.hostname.split(".");
|
|
200
|
+
var knownDomains = [["jd", "com"], ["taobao", "com"], ["tmall", "com"]];
|
|
201
|
+
var allowedHosts = ["item.jd.com", "item.taobao.com", "detail.tmall.com"];
|
|
202
|
+
var looksLikeKnown = knownDomains.some(function (d) {
|
|
203
|
+
for (var i = 0; i + 1 < labels.length; i += 1) {
|
|
204
|
+
if (labels[i] === d[0] && labels[i + 1] === d[1]) return true;
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
});
|
|
208
|
+
if (looksLikeKnown && allowedHosts.indexOf(url.hostname) < 0) return "-";
|
|
192
209
|
return '<a href="' + esc(value) + '" target="_blank" rel="noopener noreferrer">' + esc(value) + '</a>';
|
|
193
210
|
} catch (_) { return "-"; }
|
|
194
211
|
}
|
|
@@ -309,52 +326,122 @@ function appendCatalogConnection(html) {
|
|
|
309
326
|
catalogConnectionState = s;
|
|
310
327
|
return html + '<div class="card"><h2>连接 Kiwi 目录</h2><p id="catalog-status">' + esc(catalogStatusText(s)) +
|
|
311
328
|
(s.errorCode ? ' <span class="muted">[' + esc(s.errorCode) + ']</span>' : '') + '</p>' +
|
|
329
|
+
(s.bindingId ? '<p>Kiwi 账户:<span id="bound-account">正在核对…</span></p>' : '<p>Kiwi 账户:尚未连接</p>') +
|
|
312
330
|
(s.errorCode && PAIRING_CODE_HINTS[s.errorCode] ? '<p class="muted">' + esc(PAIRING_CODE_HINTS[s.errorCode]) + '</p>' : '') +
|
|
313
331
|
'<p class="muted">连接后,采购方可在目录发现本店。请本人核对配对码与公开资料,并在目录授权页确认发布。</p>' +
|
|
314
|
-
(s.published ? "" : (
|
|
332
|
+
(s.published ? "" : ('<p class="muted">接入方式默认自动检测:连接时先尝试无码读取;单次失败不会判定为已加白或未加白。如平台门禁要求分享码,请在下方提交并授权。</p>' +
|
|
333
|
+
'<button class="act primary" onclick="beginCatalogConnect()">发起或继续连接</button> ' +
|
|
334
|
+
(WORKBUDDY_ACCESS && !s.bindingId ? '<button class="act" onclick="stageAccessAndBegin()">提交分享链接并发起</button> ' : '') +
|
|
315
335
|
'<button class="act" onclick="showCatalogPairing()">本人查看配对信息</button>')) +
|
|
316
336
|
' <button class="act" onclick="refresh()">刷新连接状态</button><div id="catalog-pairing"></div></div>';
|
|
317
337
|
}).catch(function () {
|
|
318
338
|
return html + '<div class="card"><h2>连接 Kiwi 目录</h2><p>暂时无法读取连接状态,请稍后刷新。</p></div>';
|
|
319
339
|
});
|
|
320
340
|
}
|
|
341
|
+
function accessModeLabel(mode) {
|
|
342
|
+
return { auto: "自动检测(默认)", share_code: "使用分享码", no_share_code: "无分享码(直连)" }[mode] || "自动检测(默认)";
|
|
343
|
+
}
|
|
344
|
+
function safeAccessMode(mode) {
|
|
345
|
+
return ["auto", "share_code", "no_share_code"].indexOf(mode) >= 0 ? mode : "auto";
|
|
346
|
+
}
|
|
347
|
+
function detectionText(d) {
|
|
348
|
+
if (!d) {
|
|
349
|
+
return "尚未检测。默认自动检测:连接时先尝试无码读取;单次失败不会判定为已加白或未加白,也不会删除已保存的分享码。";
|
|
350
|
+
}
|
|
351
|
+
if (d.status === "direct_ok") {
|
|
352
|
+
return "检测结果:本次无码读取公开名片成功。这不等于平台已加白,检测本身不改写已保存的接入方式或买家路由状态;如后续仍被门禁拦截,请重新检测或改用分享码。";
|
|
353
|
+
}
|
|
354
|
+
if (d.status === "share_code_ok") {
|
|
355
|
+
return "检测结果:本次分享码可通过平台门禁。平台是否加白仍未确认;切换接入方式或重新检测都不会删除已保存的分享码。";
|
|
356
|
+
}
|
|
357
|
+
return "检测结果:不确定。" + (d.guidance || "单次 401/403、网络错误或不完整响应不能判定实例未加白。请先确认服务、公网入口与 TLS 正常,再提交分享链接或稍后重试。");
|
|
358
|
+
}
|
|
359
|
+
function showAccessDetection(d) {
|
|
360
|
+
catalogAccessDetection = d || null;
|
|
361
|
+
var target = $("access-detection");
|
|
362
|
+
if (target) target.textContent = detectionText(d);
|
|
363
|
+
}
|
|
321
364
|
function accessStatusText(a) {
|
|
322
365
|
if (!a) return "暂时无法读取访问配置状态";
|
|
323
366
|
// 目录已有分享码,本次随绑凭据被按版本冲突跳过(目录保留原配置、不覆盖)。
|
|
324
367
|
// 唯一可恢复路径是商家用权威版本显式更新,所以文案必须指向这个动作。
|
|
325
368
|
if (a.statusReason === "catalog_access_exists")
|
|
326
369
|
return "目录已有分享码配置,本次绑定没有覆盖它(不会用旧码顶掉已生效的码)。如需更换或启用,请重新粘贴分享链接并「提交或更新」,会按目录当前版本更新。";
|
|
327
|
-
if (a.status === "active")
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
370
|
+
if (a.status === "active") {
|
|
371
|
+
var routeSynced = a.catalogSync === undefined || a.catalogSync === "synced";
|
|
372
|
+
if (a.mode === "no_share_code") {
|
|
373
|
+
return routeSynced
|
|
374
|
+
? "目录已保存分享码(配置版本 " + a.configVersion + "),但当前接入方式为无分享码:买家按无码直连,已保存的分享码不用于路由,也不会被删除。"
|
|
375
|
+
: "目录已保存分享码(配置版本 " + a.configVersion + "),本机选择无分享码,但目录路由状态尚未同步;买家仍按旧状态路由。已保存的分享码不会删除。";
|
|
376
|
+
}
|
|
377
|
+
return routeSynced
|
|
378
|
+
? "分享码已生效(配置版本 " + a.configVersion + "):买家按目录中继传输,中继只传输,不决定磋商。"
|
|
379
|
+
: "分享码已生效(配置版本 " + a.configVersion + "),但目录路由状态尚未同步;买家仍按旧状态路由。目录中继只传输,不决定磋商。";
|
|
380
|
+
}
|
|
381
|
+
if (a.statusReason === "local_saved_not_used") return "分享码已加密保存,但当前接入方式为无分享码;连接时不会提交或发送。切换为自动检测或使用分享码后可继续,已保存的分享码不会被删除。";
|
|
382
|
+
if (a.status === "pending" && a.statusReason === "local_staged") return "分享码已加密暂存,请继续连接;绑定完成后由目录验证";
|
|
383
|
+
if (a.status === "pending") return "分享码已提交,等待平台校验";
|
|
384
|
+
if (a.status === "invalid") return "分享码校验未通过,请重新提交分享链接";
|
|
331
385
|
if (a.status === "revoked") {
|
|
332
386
|
return a.statusReason === "superseded"
|
|
333
|
-
? "
|
|
334
|
-
: "
|
|
387
|
+
? "分享码已被新版本替换(旧码不再发放)"
|
|
388
|
+
: "分享码已撤回,采购方当前无法经平台网关访问";
|
|
335
389
|
}
|
|
336
|
-
return "
|
|
390
|
+
return "未保存分享码;当前接入方式:" + accessModeLabel(a.mode) + "。默认自动检测会先尝试无码读取;如平台门禁拦截,请提交本实例分享链接。";
|
|
391
|
+
}
|
|
392
|
+
function accessSyncText(a) {
|
|
393
|
+
var state = a && a.catalogSync;
|
|
394
|
+
if (state === "synced")
|
|
395
|
+
return "目录路由状态已同步" + (a.catalogRevision ? "(revision " + a.catalogRevision + ")" : "") + "。";
|
|
396
|
+
if (state === "pending")
|
|
397
|
+
return "本机已保存,但目录尚未确认同步;买家仍按旧状态路由。请点击“保存接入方式”或“刷新状态”重试。已保存的分享码不会被删除。";
|
|
398
|
+
if (state === "failed")
|
|
399
|
+
// 错误码只做纯文本插值:HTML 调用点在拼接时统一 esc(),textContent
|
|
400
|
+
// 调用点本身安全;此处再转义会变成双重转义。
|
|
401
|
+
return "目录同步失败(" + (a.catalogSyncError || "SYNC_FAILED") + ");本机选择已保留,买家仍按旧状态路由。已保存的分享码不会被删除。";
|
|
402
|
+
if (state === "unsupported")
|
|
403
|
+
return "目录不支持接入方式同步,或当前没有可用的活动绑定;买家仍按旧规则/安全回退。请确认目录连接后重新保存,本机选择与已保存分享码均已保留。";
|
|
404
|
+
if (state === "unbound")
|
|
405
|
+
return "尚未完成目录连接:接入方式只在本机保存,完成绑定后会自动同步。";
|
|
406
|
+
return "目录同步状态未知;请点击“刷新状态”核对。买家不会按未经确认的本机选择路由。";
|
|
337
407
|
}
|
|
338
408
|
function appendCatalogAccess(html) {
|
|
339
409
|
if (!CATALOG_CONNECT || ROLE !== "owner") return html;
|
|
340
410
|
return call("GET", "/catalog/access").then(function (result) {
|
|
341
411
|
var a = result.access || {};
|
|
342
412
|
catalogAccessState = a;
|
|
413
|
+
catalogAccessDetection = a.detection || null;
|
|
414
|
+
var mode = safeAccessMode(a.mode);
|
|
415
|
+
var modeOptions = ["auto", "share_code", "no_share_code"].map(function (value) {
|
|
416
|
+
return '<option value="' + value + '"' + (mode === value ? ' selected' : '') + '>' + accessModeLabel(value) + '</option>';
|
|
417
|
+
}).join("");
|
|
343
418
|
var firstConnect = WORKBUDDY_ACCESS && catalogConnectionState && !catalogConnectionState.bindingId && !catalogConnectionState.published;
|
|
344
|
-
return html + '<div class="card"><h2
|
|
419
|
+
return html + '<div class="card"><h2>接入方式与平台门禁</h2>' +
|
|
420
|
+
'<div class="row"><label for="access-mode">接入方式</label>' +
|
|
421
|
+
'<select id="access-mode" aria-label="接入方式">' + modeOptions + '</select>' +
|
|
422
|
+
'<button class="act" onclick="saveAccessMode()">保存接入方式</button>' +
|
|
423
|
+
'<button class="act" onclick="detectAccessMode()">检测当前接入方式</button></div>' +
|
|
424
|
+
'<p id="access-detection" class="muted">' + esc(detectionText(a.detection)) + '</p>' +
|
|
425
|
+
'<p id="access-sync" class="muted">' + esc(accessSyncText(a)) + '</p>' +
|
|
426
|
+
'<p class="muted">默认自动检测。接入方式经目录公开为买家路由状态:使用分享码时买家中继,无分享码时买家直连,自动检测按目录已有分享码保守回退。无分享码不等于平台已确认加白;平台没有公开的白名单验证接口。切换接入方式不会删除已保存分享码;只有「撤回授权并撤销」会清除分享码。</p>' +
|
|
427
|
+
(a.modeInvalid ? '<p class="warn">接入方式偏好无法解析,已安全回退自动检测;未删除任何分享码。</p>' : '') +
|
|
428
|
+
'<h3>WorkBuddy 分享码(平台门禁)</h3>' +
|
|
345
429
|
'<p id="access-status">' + esc(accessStatusText(a)) + '</p>' +
|
|
346
|
-
'<p class="muted">分享码只用于通过 WorkBuddy 网关,不是商家身份或业务授权。本页不会显示分享码;请从平台复制分享链接后粘贴在此。</p>' +
|
|
347
|
-
'<p class="muted">平台口径:关闭「发布为网站」后链接立即失效;<b>删除源任务或源文件不会</b>让已分享链接失效,需要主动下线;平台不承诺分享码有固定有效期或自动轮换。若平台侧换了码,请重新粘贴新的分享链接。</p>' +
|
|
348
|
-
'<p class="muted"><b>平台未提供机器专用入口</b>:分享码等价于访问凭据、官方定位为人工分享,网关也不透传 Authorization;平台明确表示不适合大规模机器自动分发。Kiwi 的做法是在<b>你授权</b>后由目录代管、仅对你已接受的采购方按需出示,并按买家限流、可随时撤回。若平台策略变化或你希望不依赖它,请改用自托管公网入口(你的服务器直接对外提供 A2A)。</p>' +
|
|
349
430
|
(a.custodyEnabled === false
|
|
350
431
|
? '<p class="warn">目录代管当前已被运营关闭,无法新建或更新;你仍可撤回授权。</p>'
|
|
351
432
|
: '') +
|
|
352
|
-
'<div class="row"><input id="access-link" type="text" autocomplete="off" spellcheck="false" aria-label="WorkBuddy 分享链接" placeholder="粘贴 WorkBuddy 分享链接">' +
|
|
353
|
-
(firstConnect ? '<button class="act primary" onclick="stageAccessAndBegin()">授权并发起或继续连接</button>' : '<button class="act primary" onclick="submitAccessLink()">提交或更新</button>') +
|
|
433
|
+
'<div class="row"><input id="access-link" type="text" oninput="updateAccessButton()" autocomplete="off" spellcheck="false" aria-label="WorkBuddy 分享链接" placeholder="粘贴 WorkBuddy 分享链接">' +
|
|
434
|
+
(firstConnect ? '<button class="act primary" onclick="stageAccessAndBegin()">授权并发起或继续连接</button>' : '<button id="access-submit" class="act primary" onclick="submitAccessLink()" disabled>提交或更新</button>') +
|
|
354
435
|
'<button class="act" onclick="refreshAccess()">刷新状态</button>' +
|
|
355
|
-
(a.consentGranted ? '<button class="act danger" onclick="revokeAccess()">撤回授权并撤销</button>' : '') + '</div>' +
|
|
356
|
-
'<
|
|
357
|
-
'
|
|
436
|
+
(a.consentGranted ? '<button id="access-revoke" class="act danger" onclick="revokeAccess()">撤回授权并撤销</button>' : '') + '</div>' +
|
|
437
|
+
'<div class="row"><label class="consent-label"><input id="access-consent" type="checkbox" aria-label="同意分享码代管授权">' +
|
|
438
|
+
' <span>我同意 Kiwi 目录代管分享码,并按需向我已接受的采购方出示。</span></label> ' +
|
|
439
|
+
'<details><summary>查看代管授权与使用说明</summary><p>平台仍以分享码门禁拦截时,请以本应用的具体应用 ID 向腾讯云提交工单,申请白名单并取消平台分享码门禁。本页不会自动识别平台是否加白。</p>' +
|
|
440
|
+
'<p>加白前,新版买家经 Kiwi 目录中继传输询价与磋商。平台确认加白且你自行核实无需分享码后,可在本页选择「无分享码(直连)」并保存;待目录同步确认后,新版买家改为直连,不再经中继。</p>' +
|
|
441
|
+
'<p>旧客户端可能仍使用旧访问机制,并非所有买家都会立即切换;已接受的采购方仍可能按旧访问机制获取分享码,目录仅向他们按需出示并按买家限流。</p>' +
|
|
442
|
+
'<p>分享码用于通过 WorkBuddy 网关,不是商家身份或业务授权;本页不会显示分享码。你可随时撤回,撤回后目录会清空已保存的分享码。</p>' +
|
|
443
|
+
'<p>关闭「发布为网站」后链接立即失效;删除源任务或源文件不会使分享链接失效,需要主动下线。平台不承诺分享码的固定有效期或自动轮换;换码后请重新提交。</p>' +
|
|
444
|
+
'<p>分享码等价于访问凭据,平台未提供机器专用入口,网关不透传 Authorization,也不适合大规模机器自动分发。如不希望依赖此方式,可使用自托管公网入口。</p></details></div>' +
|
|
358
445
|
(a.recentFaults > 0
|
|
359
446
|
? '<p class="warn">最近 24 小时有 ' + a.recentFaults +
|
|
360
447
|
' 次采购方报告门禁失败' + (a.recentFaultsLastAt ? '(最后一次 ' + esc(a.recentFaultsLastAt) + ')' : '') +
|
|
@@ -364,42 +451,87 @@ function appendCatalogAccess(html) {
|
|
|
364
451
|
(a.authMode ? '<p class="muted">业务认证:' + esc(a.authMode) + ' · 适配版本:' + esc(a.adapterVersion || "-") + '</p>' : '') +
|
|
365
452
|
'</div>' +
|
|
366
453
|
'<div class="card"><h2>开放询价</h2>' +
|
|
367
|
-
'<p>允许买家通过 Kiwi 目录主动询价,无需注册、关注或商家逐个批准。Kiwi 负责通过平台门禁;商家后台仍仅供管理员登录。</p>' +
|
|
368
|
-
'<p class="muted">需先完成目录连接与分享码代管。本项是单独授权,可随时关闭;关闭后停止新的开放询价。</p>' +
|
|
369
454
|
'<p id="public-inquiry-status" class="muted">请查询当前授权状态。</p>' +
|
|
370
|
-
'<
|
|
371
|
-
'<div class="row"><button class="act primary" onclick="setPublicInquiry(true)">授权开放询价</button> ' +
|
|
455
|
+
'<div class="row"><label class="consent-label"><input id="public-inquiry-consent" type="checkbox" aria-label="同意开放询价"> <span>我同意买家无需注册或事先批准即可通过 Kiwi 目录询价。</span></label> <details><summary>查看开放询价授权与使用说明</summary><p>允许买家无需注册、关注或商家逐个批准,通过 Kiwi 目录主动询价。询价与报价报文会经 Kiwi 目录转发给商家;目录不裁决条款、不保存磋商内容,但能读到报文明文。Kiwi 负责通过平台门禁;商家后台仍仅供管理员登录。需先完成目录连接;如平台门禁要求分享码,还需完成受控代管。本项为单独授权,可随时关闭;关闭后停止新的开放询价。</p></details></div>' +
|
|
456
|
+
'<div class="row"><button id="inquiry-submit" class="act primary" onclick="setPublicInquiry(true)" disabled>授权开放询价</button> ' +
|
|
372
457
|
'<button class="act" onclick="refreshPublicInquiry()">查询授权状态</button> ' +
|
|
373
458
|
'<button class="act danger" onclick="setPublicInquiry(false)">关闭开放询价</button></div></div>';
|
|
374
459
|
}).catch(function () {
|
|
375
|
-
return html + '<div class="card"><h2
|
|
460
|
+
return html + '<div class="card"><h2>接入方式与平台门禁</h2><p>暂时无法读取访问配置状态,请稍后刷新。</p></div>';
|
|
376
461
|
});
|
|
377
462
|
}
|
|
378
|
-
function showPublicInquiryStatus(consent) {
|
|
463
|
+
function showPublicInquiryStatus(consent, notify) {
|
|
379
464
|
var target = $("public-inquiry-status");
|
|
380
465
|
var text = !consent || !consent.granted ? "尚未授权开放询价" :
|
|
381
466
|
consent.policyActive && consent.localEnabled ? "已授权;买家接入仍需完成实际验证" : "已授权,当前尚未就绪;请检查目录连接和分享码";
|
|
382
467
|
if (target) target.textContent = text;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
468
|
+
var button = $("inquiry-submit");
|
|
469
|
+
if (button) button.disabled = !!(consent && consent.granted);
|
|
470
|
+
// 后台刷新不得覆盖全局状态条(例如“已撤销”)。只有显式查询/操作才写 bar。
|
|
471
|
+
if (notify !== false) bar(text, false);
|
|
472
|
+
}
|
|
473
|
+
function refreshPublicInquiry(notify) {
|
|
474
|
+
var button = $("inquiry-submit"); if (button) button.disabled = true;
|
|
475
|
+
return call("POST", "/catalog/public-inquiry/status", {}).then(function (result) {
|
|
476
|
+
showPublicInquiryStatus(result.consent, notify);
|
|
477
|
+
}).catch(function (error) {
|
|
478
|
+
// 后台刷新失败同样不得覆盖全局状态条。
|
|
479
|
+
if (notify !== false) bar(error && error.message ? error.message : "无法查询开放询价状态", true);
|
|
480
|
+
});
|
|
389
481
|
}
|
|
390
482
|
function setPublicInquiry(granted) {
|
|
483
|
+
var button = $("inquiry-submit");
|
|
484
|
+
if (granted && button && button.disabled) return;
|
|
391
485
|
var checkbox = $("public-inquiry-consent");
|
|
392
486
|
if (granted && (!checkbox || !checkbox.checked)) { bar("请先勾选开放询价授权。", true); return; }
|
|
393
487
|
if (!granted && !window.confirm("关闭后,新的买家将不能通过 Kiwi 目录向本店发起开放询价。确定关闭?")) return;
|
|
394
|
-
|
|
488
|
+
if (button) button.disabled = true;
|
|
489
|
+
return call("POST", "/catalog/public-inquiry/consent", { granted: granted, terms_version: "open-inquiry-v1" }).then(function (result) {
|
|
395
490
|
if (checkbox) checkbox.checked = false;
|
|
396
491
|
showPublicInquiryStatus(result.consent);
|
|
397
492
|
}).catch(function () { bar("开放询价状态尚未确认,请先查询授权状态后再决定是否重试。", true); });
|
|
398
493
|
}
|
|
399
494
|
function accessSummaryBar(a, verb) {
|
|
400
|
-
|
|
495
|
+
var target = $("access-status"); if (target) target.textContent = accessStatusText(a);
|
|
496
|
+
var sync = $("access-sync"); if (sync) sync.textContent = accessSyncText(a);
|
|
497
|
+
if (a && a.detection !== undefined) showAccessDetection(a.detection);
|
|
498
|
+
bar(verb + ":" + accessStatusText(a) + " " + accessSyncText(a), a && (a.status === "invalid" || (a.catalogSync && a.catalogSync !== "synced")));
|
|
499
|
+
}
|
|
500
|
+
function saveAccessMode() {
|
|
501
|
+
var select = $("access-mode");
|
|
502
|
+
var mode = select ? String(select.value || "") : "";
|
|
503
|
+
if (["auto", "share_code", "no_share_code"].indexOf(mode) < 0) {
|
|
504
|
+
bar("请选择自动检测、使用分享码或无分享码。", true);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
return call("POST", "/catalog/access/mode", { mode: mode }).then(function (result) {
|
|
508
|
+
catalogAccessState = result.access || {};
|
|
509
|
+
showAccessDetection(catalogAccessState.detection);
|
|
510
|
+
var sync = $("access-sync"); if (sync) sync.textContent = accessSyncText(catalogAccessState);
|
|
511
|
+
var synced = catalogAccessState.catalogSync === "synced";
|
|
512
|
+
bar("接入方式已保存:" + accessModeLabel(mode) + "。" + accessSyncText(catalogAccessState) + " 已保存的分享码没有被删除。", !synced);
|
|
513
|
+
}).catch(function (error) {
|
|
514
|
+
bar(error && error.message ? error.message : "接入方式未保存,请刷新后重试。", true);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
function detectAccessMode() {
|
|
518
|
+
return call("POST", "/catalog/access/detect", {}).then(function (result) {
|
|
519
|
+
showAccessDetection(result.detection);
|
|
520
|
+
bar(detectionText(result.detection), !!(result.detection && result.detection.status === "uncertain"));
|
|
521
|
+
}).catch(function () {
|
|
522
|
+
var target = $("access-detection");
|
|
523
|
+
if (target) target.textContent = "检测结果:不确定。单次 401/403、网络错误或不完整响应不能判定实例未加白。请确认服务已启动、公网入口与 TLS 正常后重试;如平台门禁拦截,可提交分享链接。已保存的分享码不会被删除。";
|
|
524
|
+
bar("接入方式检测未完成,请按页面提示核对后重试。", true);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
var accessSubmitPending = false;
|
|
528
|
+
function updateAccessButton() {
|
|
529
|
+
var button = $("access-submit"), input = $("access-link");
|
|
530
|
+
if (button) button.disabled = accessSubmitPending || !input || !String(input.value || "").trim();
|
|
401
531
|
}
|
|
402
532
|
function submitAccessLink() {
|
|
533
|
+
var button = $("access-submit");
|
|
534
|
+
if (button && button.disabled) return;
|
|
403
535
|
var input = $("access-link");
|
|
404
536
|
var consent = $("access-consent");
|
|
405
537
|
var link = input ? String(input.value || "").trim() : "";
|
|
@@ -408,17 +540,24 @@ function submitAccessLink() {
|
|
|
408
540
|
bar("请先勾选并同意《分享码代管授权》。", true);
|
|
409
541
|
return;
|
|
410
542
|
}
|
|
411
|
-
|
|
543
|
+
accessSubmitPending = true;
|
|
544
|
+
if (button) button.disabled = true;
|
|
545
|
+
return call("POST", "/catalog/access/share-link", {
|
|
412
546
|
link: link,
|
|
413
547
|
consent_terms_version: ACCESS_CONSENT_TERMS
|
|
414
548
|
}).then(function (result) {
|
|
415
549
|
catalogAccessState = result.access;
|
|
416
550
|
if (input) input.value = "";
|
|
551
|
+
accessSubmitPending = false;
|
|
552
|
+
updateAccessButton();
|
|
417
553
|
if (consent) consent.checked = false;
|
|
418
554
|
accessSummaryBar(result.access, "已提交");
|
|
419
555
|
}).catch(function (e) {
|
|
420
556
|
// 错误文本由服务端给自有码说明;不把链接回显到页面。
|
|
421
|
-
|
|
557
|
+
// 审查 C-11:失败时保留输入框内容,允许用户核对后直接重试。
|
|
558
|
+
accessSubmitPending = false;
|
|
559
|
+
updateAccessButton();
|
|
560
|
+
bar(e && e.message ? e.message : "提交未完成,请先刷新状态后再试。", true);
|
|
422
561
|
});
|
|
423
562
|
}
|
|
424
563
|
function stageAccessAndBegin() {
|
|
@@ -452,7 +591,11 @@ function refreshAccess() {
|
|
|
452
591
|
function revokeAccess() {
|
|
453
592
|
if (!window.confirm("撤回授权后:采购方将无法经 WorkBuddy 访问本店,目录会清空已保存的分享码。确定撤回?")) return;
|
|
454
593
|
call("POST", "/catalog/access/revoke", {}).then(function (result) {
|
|
594
|
+
catalogAccessState = result.access;
|
|
455
595
|
accessSummaryBar(result.access, "已撤销");
|
|
596
|
+
var button = $("access-revoke"); if (button) button.disabled = true;
|
|
597
|
+
refreshPublicInquiry(false);
|
|
598
|
+
refresh();
|
|
456
599
|
}).catch(function () { bar("撤销未完成,请稍后重试。", true); });
|
|
457
600
|
}
|
|
458
601
|
function beginCatalogConnect() {
|
|
@@ -465,7 +608,17 @@ function beginCatalogConnect() {
|
|
|
465
608
|
if (receipt.status === "succeeded") { catalogBeginKey = ""; try { sessionStorage.removeItem("kiwi-catalog-connect-key"); } catch (_) {} }
|
|
466
609
|
bar(receipt.status === "succeeded" ? "连接申请已准备,请本人查看配对信息并确认公开资料。" : "连接结果尚未确认,请先查看状态,不要重复提交。");
|
|
467
610
|
refresh();
|
|
468
|
-
}).catch(function (error) {
|
|
611
|
+
}).catch(function (error) {
|
|
612
|
+
var message = error && error.message ? error.message : "连接申请暂未完成,请先刷新状态后再试。";
|
|
613
|
+
// 连接时的公开探测失败同样只能呈现“不确定”,不能把单次失败说成未加白。
|
|
614
|
+
if (/接入方式|公开名片|公网入口|商家服务|分享码|不确定|超时/.test(message)) {
|
|
615
|
+
showAccessDetection({
|
|
616
|
+
status: "uncertain",
|
|
617
|
+
guidance: message + " 单次失败不能判定实例未加白;已保存的分享码不会被删除。"
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
bar(message, true);
|
|
621
|
+
})
|
|
469
622
|
.finally(function () { catalogBeginPending = false; });
|
|
470
623
|
}
|
|
471
624
|
function showCatalogPairing() {
|
|
@@ -482,28 +635,38 @@ function showCatalogPairing() {
|
|
|
482
635
|
}).catch(function () { bar("无法读取配对信息,请刷新连接状态。", true); });
|
|
483
636
|
}
|
|
484
637
|
|
|
485
|
-
/**
|
|
486
|
-
function
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
638
|
+
/** 目录发布状态文案:known=false 时不把“读不到”说成“未发布”。 */
|
|
639
|
+
function publicationStateLabel(state, known) {
|
|
640
|
+
if (!known) return "状态未知";
|
|
641
|
+
var normalized = String(state || "").toLowerCase();
|
|
642
|
+
if (normalized === "active") return "已发布";
|
|
643
|
+
if (normalized === "paused") return "已暂停";
|
|
644
|
+
return "未发布";
|
|
645
|
+
}
|
|
646
|
+
function togglePublicationPicks(box) {
|
|
647
|
+
if (publicationDraft !== null) {
|
|
648
|
+
box.checked = false;
|
|
649
|
+
bar("预览已生成,选择已锁定;如需修改请先点「重新选择」", true);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
var rows = document.querySelectorAll("#pub-rows input.pub-pick");
|
|
653
|
+
for (var i = 0; i < rows.length; i++) {
|
|
654
|
+
if (!rows[i].disabled) rows[i].checked = box.checked;
|
|
655
|
+
}
|
|
656
|
+
syncPublicationSelectAll();
|
|
657
|
+
}
|
|
658
|
+
function syncPublicationSelectAll() {
|
|
659
|
+
var all = $("pub-select-all");
|
|
660
|
+
if (!all) return;
|
|
661
|
+
var picks = document.querySelectorAll("#pub-rows input.pub-pick");
|
|
662
|
+
var enabled = 0, checked = 0;
|
|
663
|
+
for (var i = 0; i < picks.length; i++) {
|
|
664
|
+
if (picks[i].disabled) continue;
|
|
665
|
+
enabled += 1;
|
|
666
|
+
if (picks[i].checked) checked += 1;
|
|
667
|
+
}
|
|
668
|
+
all.checked = enabled > 0 && checked === enabled;
|
|
669
|
+
all.indeterminate = checked > 0 && checked < enabled;
|
|
507
670
|
}
|
|
508
671
|
function applyPublicationCategory() {
|
|
509
672
|
if (publicationDraft !== null) { bar("预览已生成,选择已锁定;如需修改请先点「重新选择」", true); return; }
|
|
@@ -526,6 +689,7 @@ function clearPublicationPicks() {
|
|
|
526
689
|
if (box) box.checked = false;
|
|
527
690
|
if (input) input.value = "";
|
|
528
691
|
}
|
|
692
|
+
syncPublicationSelectAll();
|
|
529
693
|
}
|
|
530
694
|
function lockPublicationSelection(locked) {
|
|
531
695
|
var rows = document.querySelectorAll("#pub-rows tr");
|
|
@@ -537,10 +701,13 @@ function lockPublicationSelection(locked) {
|
|
|
537
701
|
}
|
|
538
702
|
var all = $("pub-category-all");
|
|
539
703
|
if (all) all.disabled = locked;
|
|
704
|
+
var selectAll = $("pub-select-all");
|
|
705
|
+
if (selectAll) selectAll.disabled = locked;
|
|
540
706
|
var apply = $("pub-apply");
|
|
541
707
|
if (apply) apply.disabled = locked;
|
|
542
708
|
var clear = $("pub-clear");
|
|
543
709
|
if (clear) clear.disabled = locked;
|
|
710
|
+
if (!locked) syncPublicationSelectAll();
|
|
544
711
|
}
|
|
545
712
|
function samePublicationPicks(a, b) {
|
|
546
713
|
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
|
|
@@ -613,36 +780,75 @@ function renderPublicationReceipts(receipts, heading, counts) {
|
|
|
613
780
|
return "<h3>" + esc(heading) + "</h3>" + (counts ? "<p>" + esc(counts) + "</p>" : "") +
|
|
614
781
|
'<div class="table-scroll"><table><tr><th>SKU</th><th>结果</th><th>说明</th></tr>' + rows + "</table></div>";
|
|
615
782
|
}
|
|
616
|
-
/**
|
|
617
|
-
function renderProducts(items) {
|
|
783
|
+
/** 商品页统一渲染:一张表同时承载商品信息、目录发布状态与发布选择。 */
|
|
784
|
+
function renderProducts(items, publication) {
|
|
618
785
|
var list = items || [];
|
|
786
|
+
var pub = publication || {};
|
|
787
|
+
var canPublish = pub.canPublish === true;
|
|
788
|
+
var known = pub.known === true;
|
|
789
|
+
var published = pub.published || {};
|
|
790
|
+
var publishedCount = 0;
|
|
791
|
+
for (var n = 0; n < list.length; n++) {
|
|
792
|
+
if (published[list[n].sku]) publishedCount += 1;
|
|
793
|
+
}
|
|
619
794
|
var rows = list.map(function (it) {
|
|
795
|
+
var sku = esc(it.sku);
|
|
620
796
|
if (FILE_PRODUCTS) {
|
|
621
|
-
|
|
622
|
-
|
|
797
|
+
var price = esc(it.currency) + " " + esc(it.price) + " / " + esc(it.price_unit);
|
|
798
|
+
var platform = esc(({jd:"京东",taobao:"淘宝",tmall:"天猫"})[it.trade_platform] || it.trade_platform || "-");
|
|
799
|
+
if (canPublish) {
|
|
800
|
+
return '<tr data-sku="' + sku + '">' +
|
|
801
|
+
'<td><input type="checkbox" class="pub-pick" onchange="syncPublicationSelectAll()" aria-label="选择商品 ' + sku + '"></td>' +
|
|
802
|
+
"<td>" + sku + "</td><td>" + esc(it.title) + "</td><td>" + esc(it.status) + "</td>" +
|
|
803
|
+
'<td class="pub-state">' + esc(publicationStateLabel(published[it.sku], known)) + "</td>" +
|
|
804
|
+
'<td><input type="text" class="pub-category" maxlength="120" placeholder="填写分类" aria-label="' + sku + ' 的分类"></td>' +
|
|
805
|
+
"<td>" + price + "</td><td>" + esc(it.min_order_qty == null ? "-" : it.min_order_qty) + "</td><td>" +
|
|
806
|
+
esc(it.valid_until) + "</td><td>" + platform + "</td><td>" +
|
|
807
|
+
esc(it.platform_product_id || "-") + "</td><td>" + marketplaceLink(it) + "</td></tr>";
|
|
808
|
+
}
|
|
809
|
+
return "<tr><td>" + sku + "</td><td>" + esc(it.title) + "</td><td>" + price + "</td><td>" +
|
|
623
810
|
esc(it.min_order_qty == null ? "-" : it.min_order_qty) + "</td><td>" +
|
|
624
|
-
esc(it.valid_until) + "</td><td>" + esc(it.status) + "</td><td>" +
|
|
625
|
-
esc(({jd:"京东",taobao:"淘宝",tmall:"天猫"})[it.trade_platform] || "-") + "</td><td>" +
|
|
811
|
+
esc(it.valid_until) + "</td><td>" + esc(it.status) + "</td><td>" + platform + "</td><td>" +
|
|
626
812
|
esc(it.platform_product_id || "-") + "</td><td>" + marketplaceLink(it) + "</td></tr>";
|
|
627
813
|
}
|
|
628
814
|
var money = it.money || {};
|
|
629
|
-
return "<tr><td>" +
|
|
815
|
+
return "<tr><td>" + sku + "</td><td>" + esc(it.title) + "</td><td>" +
|
|
630
816
|
esc(money.currency || "-") + " " + esc(money.amount_minor == null ? "-" : money.amount_minor) +
|
|
631
817
|
"(最小币单位)</td><td>" + esc(it.stock == null ? "-" : it.stock) + "</td><td>" +
|
|
632
818
|
esc(it.authority_version == null ? "-" : it.authority_version) + "</td></tr>";
|
|
633
819
|
}).join("");
|
|
634
|
-
|
|
635
|
-
(
|
|
636
|
-
? "
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
'<div class="
|
|
820
|
+
var summary = canPublish
|
|
821
|
+
? '<p class="muted" id="pub-summary">已发布到目录 ' + publishedCount + " 件,未发布 " + (list.length - publishedCount) + " 件。" +
|
|
822
|
+
(known ? "" : "目录发布状态暂不可读取,刷新后重试。") + "</p>"
|
|
823
|
+
: "";
|
|
824
|
+
var selectAll = canPublish && list.length > 0
|
|
825
|
+
? '<div class="row"><label class="consent-label"><input type="checkbox" id="pub-select-all" aria-label="全选商品" onchange="togglePublicationPicks(this)"> 全选当前商品</label></div>'
|
|
826
|
+
: "";
|
|
827
|
+
var header = canPublish
|
|
828
|
+
? "<tr><th>选择</th><th>SKU</th><th>名称</th><th>状态</th><th>目录状态</th><th>分类(必填)</th><th>单价</th><th>起订量</th><th>有效期至</th><th>交易平台</th><th>平台商品ID</th><th>平台商品页链接</th></tr>"
|
|
829
|
+
: (FILE_PRODUCTS
|
|
830
|
+
? "<tr><th>SKU</th><th>名称</th><th>单价</th><th>起订量</th><th>有效期至</th><th>状态</th><th>交易平台</th><th>平台商品ID</th><th>平台商品页链接</th></tr>"
|
|
831
|
+
: "<tr><th>SKU</th><th>名称</th><th>价格(最小币单位)</th><th>库存</th><th>版本</th></tr>");
|
|
832
|
+
var table = '<div class="table-scroll"><table' + (canPublish ? ' id="pub-table"' : '') + ">" + header +
|
|
833
|
+
(canPublish ? '<tbody id="pub-rows">' + rows + "</tbody>" : rows) + "</table></div>";
|
|
834
|
+
var publishControls = canPublish && list.length > 0
|
|
835
|
+
? '<div class="row"><input type="text" id="pub-category-all" maxlength="120" placeholder="统一分类(可选)" aria-label="统一分类">' +
|
|
836
|
+
'<button class="act" id="pub-apply" onclick="applyPublicationCategory()">应用到已勾选</button>' +
|
|
837
|
+
'<button class="act" id="pub-clear" onclick="clearPublicationPicks()">清空选择</button></div>' +
|
|
838
|
+
'<p class="muted">公开名称、SKU、分类、商品页链接与其余公开字段;价格、库存及私有规则不会发布。' +
|
|
839
|
+
'可发布已导入或已有商品,不涉及下架其他商品。预览后选择会锁定,修改需先「重新选择」。</p>' +
|
|
840
|
+
'<button class="act" id="pub-preview" onclick="previewPublication()">预览公开内容</button>' +
|
|
841
|
+
'<div id="publication-result"></div>'
|
|
842
|
+
: (canPublish ? '<p class="muted">暂无商品,请先在下方导入商品后再选择发布。</p>' : "");
|
|
843
|
+
return '<div class="card"><h2>' + (canPublish ? "商品与目录发布" : "当前商品") + "(" + list.length + ")</h2>" + summary +
|
|
844
|
+
selectAll + (rows ? table : '<p class="muted">暂无商品,请先导入商品。没有商品时服务不会报价或发布名片。</p>') +
|
|
845
|
+
publishControls + "</div>" +
|
|
846
|
+
'<div class="card"><h2>导入商品表(按 SKU 追加/更新)</h2>' +
|
|
640
847
|
'<p class="muted">交易链接仅为平台商品页;是否成交、实际价格与付款结果由交易平台确认。</p>' +
|
|
641
|
-
'<p class="muted">支持 CSV、Excel(.xlsx)与商品表 JSON
|
|
848
|
+
'<p class="muted">支持 CSV、Excel(.xlsx)与商品表 JSON:先转换校验、预览新增/更新/保留,确认后整批生效(不成功的批次不改动现有商品)。文件里没有的商品会保留,只有同 SKU 会被更新;导入不会撤回已发布到目录的商品。</p>' +
|
|
642
849
|
'<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>' +
|
|
643
850
|
'<div class="row"><input type="file" id="pfile" aria-label="选择商品导入文件" accept=".json,.csv,.xlsx">' +
|
|
644
|
-
'<button class="act" onclick="previewImport()">校验预览</button></div><div id="presult"></div></div>'
|
|
645
|
-
(FILE_PRODUCTS && CATALOG_CONNECT && ROLE === "owner" ? publicationCard(list) : '');
|
|
851
|
+
'<button class="act" onclick="previewImport()">校验预览</button></div><div id="presult"></div></div>';
|
|
646
852
|
}
|
|
647
853
|
var views = {
|
|
648
854
|
status: function () {
|
|
@@ -684,16 +890,32 @@ var views = {
|
|
|
684
890
|
// 商品可能超过 100 件:跟随 next_cursor 拉全量,保证全部可选、计数准确。
|
|
685
891
|
var base = FILE_PRODUCTS ? "/merchant/api" : API;
|
|
686
892
|
var items = [];
|
|
893
|
+
var canPublish = FILE_PRODUCTS && CATALOG_CONNECT && ROLE === "owner";
|
|
894
|
+
var published = {};
|
|
895
|
+
var known = false;
|
|
687
896
|
function loadPage(cursor, page) {
|
|
688
897
|
var path = "/products?limit=100" + (cursor ? "&cursor=" + encodeURIComponent(cursor) : "");
|
|
689
898
|
return call("GET", path, undefined, base).then(function (p) {
|
|
690
899
|
items = items.concat(p.items || []);
|
|
691
900
|
var next = p.next_cursor;
|
|
692
901
|
if (typeof next === "string" && next !== "" && page < 50) return loadPage(next, page + 1);
|
|
693
|
-
return renderProducts(items);
|
|
694
902
|
});
|
|
695
903
|
}
|
|
696
|
-
|
|
904
|
+
var statusPromise = canPublish
|
|
905
|
+
? call("GET", "/products/publication-status").then(function (result) {
|
|
906
|
+
var rows = (result && result.results) || [];
|
|
907
|
+
for (var i = 0; i < rows.length; i++) {
|
|
908
|
+
var sku = String(rows[i].sku || "");
|
|
909
|
+
if (!sku) continue;
|
|
910
|
+
var state = String(rows[i].publication_state || "");
|
|
911
|
+
if (!published[sku] || state.toLowerCase() === "active") published[sku] = state;
|
|
912
|
+
}
|
|
913
|
+
known = true;
|
|
914
|
+
}).catch(function () { known = false; })
|
|
915
|
+
: Promise.resolve();
|
|
916
|
+
return Promise.all([loadPage("", 0), statusPromise]).then(function () {
|
|
917
|
+
return renderProducts(items, { canPublish: canPublish, known: known, published: published });
|
|
918
|
+
});
|
|
697
919
|
},
|
|
698
920
|
approvals: function () {
|
|
699
921
|
return call("GET", "/approvals").then(function (p) {
|
|
@@ -1155,7 +1377,7 @@ function previewPublication() {
|
|
|
1155
1377
|
'<div class="table-scroll"><table><tr><th>名称</th><th>SKU</th><th>分类</th><th>商品页链接</th><th>新鲜期至</th><th>其余公开字段</th></tr>' +
|
|
1156
1378
|
rows + "</table></div>" +
|
|
1157
1379
|
'<p class="muted">预览有效期至 ' + esc(draft.expires_at) +
|
|
1158
|
-
'
|
|
1380
|
+
'(草稿到期时间);价格、库存与私有规则不在公开内容中。导入只按 SKU 新增/更新本机商品,不会撤回本次未勾选的其他已发布商品。</p>' +
|
|
1159
1381
|
'<button class="act primary" onclick="commitPublication()">确认公开这 ' + esc(items.length) + ' 件商品</button> ' +
|
|
1160
1382
|
'<button class="act" onclick="resetPublication()">重新选择(作废本次预览)</button>';
|
|
1161
1383
|
}).catch(function (err) {
|
|
@@ -1163,6 +1385,33 @@ function previewPublication() {
|
|
|
1163
1385
|
bar(err.message, true);
|
|
1164
1386
|
}).finally(function () { publicationBusy = false; });
|
|
1165
1387
|
}
|
|
1388
|
+
/** 发布/续办后只刷新目录状态列与摘要,不覆盖发布回执。 */
|
|
1389
|
+
function refreshPublicationStatus() {
|
|
1390
|
+
if (!(FILE_PRODUCTS && CATALOG_CONNECT && ROLE === "owner")) return Promise.resolve();
|
|
1391
|
+
return call("GET", "/products/publication-status").then(function (result) {
|
|
1392
|
+
var published = {};
|
|
1393
|
+
var rows = (result && result.results) || [];
|
|
1394
|
+
for (var i = 0; i < rows.length; i++) {
|
|
1395
|
+
var sku = String(rows[i].sku || "");
|
|
1396
|
+
if (!sku) continue;
|
|
1397
|
+
var state = String(rows[i].publication_state || "");
|
|
1398
|
+
if (!published[sku] || state.toLowerCase() === "active") published[sku] = state;
|
|
1399
|
+
}
|
|
1400
|
+
var trs = document.querySelectorAll("#pub-rows tr");
|
|
1401
|
+
var publishedCount = 0;
|
|
1402
|
+
for (var j = 0; j < trs.length; j++) {
|
|
1403
|
+
var rowSku = String(trs[j].getAttribute("data-sku") || "");
|
|
1404
|
+
var current = published[rowSku];
|
|
1405
|
+
if (current) publishedCount += 1;
|
|
1406
|
+
var cell = trs[j].querySelector(".pub-state");
|
|
1407
|
+
if (cell) cell.textContent = publicationStateLabel(current, true);
|
|
1408
|
+
}
|
|
1409
|
+
var summary = $("pub-summary");
|
|
1410
|
+
if (summary) {
|
|
1411
|
+
summary.textContent = "已发布到目录 " + publishedCount + " 件,未发布 " + Math.max(0, trs.length - publishedCount) + " 件。";
|
|
1412
|
+
}
|
|
1413
|
+
}).catch(function () { bar("目录发布状态暂不可读取,请稍后刷新。", true); });
|
|
1414
|
+
}
|
|
1166
1415
|
function commitPublication() {
|
|
1167
1416
|
if (publicationBusy || !publicationDraft) return;
|
|
1168
1417
|
var current = publicationSelections();
|
|
@@ -1187,6 +1436,7 @@ function commitPublication() {
|
|
|
1187
1436
|
publicationPicks = null;
|
|
1188
1437
|
lockPublicationSelection(false);
|
|
1189
1438
|
}
|
|
1439
|
+
refreshPublicationStatus();
|
|
1190
1440
|
}).catch(function (err) { bar(err.message + " 请保留本页,查看原草稿回执。", true); })
|
|
1191
1441
|
.finally(function () { publicationBusy = false; });
|
|
1192
1442
|
}
|
|
@@ -1276,8 +1526,8 @@ function renderParseReport(r) {
|
|
|
1276
1526
|
"。若其中有需要导入的信息,请改用模板列名后重新上传。</p>" : "") +
|
|
1277
1527
|
(defaulted ? '<p class="muted">未提供、按默认值处理的列:' + esc(defaulted) +
|
|
1278
1528
|
"(状态默认「在售」;更新时间默认取导入时刻)。</p>" : "") +
|
|
1279
|
-
'<p class="muted"
|
|
1280
|
-
'
|
|
1529
|
+
'<p class="muted">确认列映射无误后继续;下一步做严格校验与合并预览。' +
|
|
1530
|
+
'只会新增或更新文件中的 SKU,现有商品与已发布到目录的商品都不会被删除或撤回。</p>' +
|
|
1281
1531
|
'<button class="act primary" id="pcontinue">已确认列映射,继续校验预览</button></div>';
|
|
1282
1532
|
var btn = $("pcontinue");
|
|
1283
1533
|
if (btn) btn.addEventListener("click", function () {
|
|
@@ -1292,9 +1542,9 @@ function submitImportTable(table) {
|
|
|
1292
1542
|
var pv = draft.preview;
|
|
1293
1543
|
$("presult").innerHTML = '<div class="card" style="margin-top:10px;background:#fbfcfd">' +
|
|
1294
1544
|
"<div>草稿 <b>" + esc(draft.draft_id) + "</b>:新增 " + pv.added + ",更新 " + pv.updated +
|
|
1295
|
-
",不变 " + pv.unchanged + "
|
|
1545
|
+
",不变 " + pv.unchanged + ",保留现有 " + (pv.kept || 0) + "(文件共 " + pv.rows_total + " 行)。</div>" +
|
|
1296
1546
|
'<pre class="digest">' + esc(draft.digest) + "</pre>" +
|
|
1297
|
-
|
|
1547
|
+
'<p class="muted">确认后只合并本文件中的 SKU;不会撤回已发布到目录的商品。</p>' +
|
|
1298
1548
|
'<button class="act primary" onclick="commitImport()">确认导入(整批生效)</button></div>';
|
|
1299
1549
|
})
|
|
1300
1550
|
.catch(function (e) { bar("校验未通过:" + e.message, true); });
|
|
@@ -1385,7 +1635,18 @@ function refresh() {
|
|
|
1385
1635
|
$("page-title").textContent = copy[0];
|
|
1386
1636
|
$("page-description").textContent = copy[1];
|
|
1387
1637
|
$("view").setAttribute("data-view", current);
|
|
1388
|
-
views[current]().then(function (html) {
|
|
1638
|
+
views[current]().then(function (html) {
|
|
1639
|
+
$("view").innerHTML = html; decorateView();
|
|
1640
|
+
if (current === "status" && CATALOG_CONNECT && ROLE === "owner") {
|
|
1641
|
+
if (catalogConnectionState && catalogConnectionState.bindingId) {
|
|
1642
|
+
call("GET", "/catalog/bound-account").then(function (result) {
|
|
1643
|
+
var target = $("bound-account"); if (target) target.textContent = result.email || "无法确定,请到 Kiwi 商家门户核对";
|
|
1644
|
+
}).catch(function () { var target = $("bound-account"); if (target) target.textContent = "暂时无法读取,请稍后刷新"; });
|
|
1645
|
+
// 后台刷新只更新局部状态,不覆盖全局提示条。
|
|
1646
|
+
refreshPublicInquiry(false);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
})
|
|
1389
1650
|
.catch(function (e) { if (e.message !== "需要登录") bar(e.message, true); }); }
|
|
1390
1651
|
Array.prototype.forEach.call(document.querySelectorAll("#tabs button"), function (btn) {
|
|
1391
1652
|
btn.addEventListener("click", function () {
|