@harrylabsj/kiwi 0.12.32 → 0.12.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/a2a/inquiry-nonce-store.d.ts +12 -1
- package/dist/a2a/inquiry-nonce-store.js +49 -17
- package/dist/a2a/inquiry-nonce-store.js.map +1 -1
- package/dist/a2a/negotiate.d.ts +30 -1
- package/dist/a2a/negotiate.js +121 -32
- package/dist/a2a/negotiate.js.map +1 -1
- package/dist/a2a/node.d.ts +3 -0
- package/dist/a2a/node.js +13 -3
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/open-inquiry-session.d.ts +1 -0
- package/dist/a2a/open-inquiry-session.js +3 -1
- package/dist/a2a/open-inquiry-session.js.map +1 -1
- package/dist/a2a/open-inquiry-verifier.js +2 -2
- package/dist/a2a/open-inquiry-verifier.js.map +1 -1
- package/dist/a2a/server/errors.d.ts +4 -3
- package/dist/a2a/server/errors.js +10 -2
- package/dist/a2a/server/errors.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +41 -1
- package/dist/a2a/server/merchant-handler.js +259 -89
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/merchant-procurement.d.ts +90 -0
- package/dist/a2a/server/merchant-procurement.js +75 -0
- package/dist/a2a/server/merchant-procurement.js.map +1 -0
- package/dist/a2a/server/merchant-product-facts.d.ts +2 -0
- package/dist/a2a/server/merchant-product-facts.js.map +1 -1
- package/dist/a2a/server/negotiation-approvals.d.ts +11 -0
- package/dist/a2a/server/negotiation-approvals.js +43 -0
- package/dist/a2a/server/negotiation-approvals.js.map +1 -1
- package/dist/a2a/server/pipeline.js +4 -1
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/server/server.js +4 -3
- package/dist/a2a/server/server.js.map +1 -1
- package/dist/a2a/server/types.d.ts +2 -1
- package/dist/agent/alipay-native-view.d.ts +27 -0
- package/dist/agent/alipay-native-view.js +113 -0
- package/dist/agent/alipay-native-view.js.map +1 -0
- package/dist/agent/buyer/buyer-tools.d.ts +20 -0
- package/dist/agent/buyer/buyer-tools.js +241 -48
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/types.d.ts +1 -1
- package/dist/agent/buyer/types.js.map +1 -1
- package/dist/agent/chat-tui.js +16 -1
- package/dist/agent/chat-tui.js.map +1 -1
- package/dist/agent/kernel-builder.d.ts +2 -0
- package/dist/agent/kernel-builder.js +14 -0
- package/dist/agent/kernel-builder.js.map +1 -1
- package/dist/agent/kernel.d.ts +8 -0
- package/dist/agent/kernel.js +67 -1
- package/dist/agent/kernel.js.map +1 -1
- package/dist/buyer-core/a2a-accept-terms.d.ts +11 -0
- package/dist/buyer-core/a2a-accept-terms.js +28 -0
- package/dist/buyer-core/a2a-accept-terms.js.map +1 -0
- package/dist/buyer-core/a2a-knp.d.ts +3 -0
- package/dist/buyer-core/a2a-knp.js +3 -3
- package/dist/buyer-core/a2a-knp.js.map +1 -1
- package/dist/buyer-core/a2a-negotiator.d.ts +16 -0
- package/dist/buyer-core/a2a-negotiator.js +53 -16
- package/dist/buyer-core/a2a-negotiator.js.map +1 -1
- package/dist/buyer-core/a2a-quote-fetcher.d.ts +0 -15
- package/dist/buyer-core/a2a-quote-fetcher.js +10 -15
- package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
- package/dist/buyer-core/merchant-index.d.ts +2 -2
- package/dist/buyer-core/merchant-index.js +23 -5
- package/dist/buyer-core/merchant-index.js.map +1 -1
- package/dist/buyer-core/procurement/cases.d.ts +441 -0
- package/dist/buyer-core/procurement/cases.js +457 -0
- package/dist/buyer-core/procurement/cases.js.map +1 -0
- package/dist/buyer-core/procurement/quote-comparison.d.ts +137 -0
- package/dist/buyer-core/procurement/quote-comparison.js +106 -0
- package/dist/buyer-core/procurement/quote-comparison.js.map +1 -0
- package/dist/buyer-core/procurement/quote-normalizer.d.ts +45 -0
- package/dist/buyer-core/procurement/quote-normalizer.js +153 -0
- package/dist/buyer-core/procurement/quote-normalizer.js.map +1 -0
- package/dist/buyer-core/procurement/requirements.d.ts +50 -0
- package/dist/buyer-core/procurement/requirements.js +43 -0
- package/dist/buyer-core/procurement/requirements.js.map +1 -0
- package/dist/buyer-core/procurement/source-observation.d.ts +57 -0
- package/dist/buyer-core/procurement/source-observation.js +54 -0
- package/dist/buyer-core/procurement/source-observation.js.map +1 -0
- package/dist/buyer-core/procurement/store.d.ts +21 -0
- package/dist/buyer-core/procurement/store.js +68 -0
- package/dist/buyer-core/procurement/store.js.map +1 -0
- package/dist/buyer-core/protocol-recovery.d.ts +8 -0
- package/dist/buyer-core/protocol-recovery.js +17 -2
- package/dist/buyer-core/protocol-recovery.js.map +1 -1
- package/dist/buyer-core/quote-quantity.d.ts +5 -0
- package/dist/buyer-core/quote-quantity.js +15 -0
- package/dist/buyer-core/quote-quantity.js.map +1 -0
- package/dist/buyer-core/service.d.ts +71 -3
- package/dist/buyer-core/service.js +271 -28
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/buyer-core/store.d.ts +13 -0
- package/dist/buyer-core/store.js +25 -3
- package/dist/buyer-core/store.js.map +1 -1
- package/dist/cli.js +13 -17
- package/dist/cli.js.map +1 -1
- package/dist/cloud/alipay-collection-http.d.ts +44 -0
- package/dist/cloud/alipay-collection-http.js +111 -0
- package/dist/cloud/alipay-collection-http.js.map +1 -0
- package/dist/cloud/bootstrap.js +98 -12
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/http-router.d.ts +2 -0
- package/dist/cloud/http-router.js +5 -0
- package/dist/cloud/http-router.js.map +1 -1
- package/dist/commerce/receipt/dispatcher.d.ts +2 -1
- package/dist/commerce/receipt/dispatcher.js +18 -0
- package/dist/commerce/receipt/dispatcher.js.map +1 -1
- package/dist/commerce/receipt/receipts.d.ts +7 -0
- package/dist/commerce/receipt/receipts.js +43 -5
- package/dist/commerce/receipt/receipts.js.map +1 -1
- package/dist/discovery/catalog-source/buyer-follows.d.ts +3 -3
- package/dist/discovery/catalog-source/buyer-follows.js +6 -3
- package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-record.d.ts +2 -0
- package/dist/discovery/catalog-source/kiwi-record.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.js +4 -0
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/handoff/alipay-collection.d.ts +23 -0
- package/dist/handoff/alipay-collection.js +70 -0
- package/dist/handoff/alipay-collection.js.map +1 -0
- package/dist/handoff/order-receipts.js +2 -1
- package/dist/handoff/order-receipts.js.map +1 -1
- package/dist/handoff/ucp-checkout/channel.d.ts +1 -0
- package/dist/handoff/ucp-checkout/channel.js +42 -17
- package/dist/handoff/ucp-checkout/channel.js.map +1 -1
- package/dist/http/customer-support-buyer.d.ts +24 -0
- package/dist/http/customer-support-buyer.js +306 -0
- package/dist/http/customer-support-buyer.js.map +1 -0
- package/dist/http/merchant-management/api.d.ts +12 -0
- package/dist/http/merchant-management/api.js +425 -6
- package/dist/http/merchant-management/api.js.map +1 -1
- package/dist/http/merchant-management/page.d.ts +2 -0
- package/dist/http/merchant-management/page.js +630 -3
- package/dist/http/merchant-management/page.js.map +1 -1
- package/dist/http/server.js +9 -2
- package/dist/http/server.js.map +1 -1
- package/dist/mcp/cli.d.ts +3 -1
- package/dist/mcp/cli.js +12 -2
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/merchant-runtime-assembly.d.ts +3 -0
- package/dist/mcp/merchant-runtime-assembly.js +9 -8
- package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
- package/dist/mcp/procurement-tools.d.ts +10 -0
- package/dist/mcp/procurement-tools.js +173 -0
- package/dist/mcp/procurement-tools.js.map +1 -0
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.js +63 -9
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +4 -1
- package/dist/mcp/tools.js +76 -27
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.js.map +1 -1
- package/dist/merchant/ai-runtime/owner-storage-admission.js.map +1 -1
- package/dist/merchant/application/actor.d.ts +2 -0
- package/dist/merchant/application/actor.js +6 -0
- package/dist/merchant/application/actor.js.map +1 -1
- package/dist/merchant/negotiation-ops.d.ts +2 -0
- package/dist/merchant/negotiation-ops.js +4 -0
- package/dist/merchant/negotiation-ops.js.map +1 -1
- package/dist/merchant/weixin-channel.d.ts +224 -0
- package/dist/merchant/weixin-channel.js +435 -0
- package/dist/merchant/weixin-channel.js.map +1 -0
- package/dist/merchant/weixin-owner-agent-profile.d.ts +8 -0
- package/dist/merchant/weixin-owner-agent-profile.js +29 -0
- package/dist/merchant/weixin-owner-agent-profile.js.map +1 -0
- package/dist/merchant/weixin-owner-agent.d.ts +42 -0
- package/dist/merchant/weixin-owner-agent.js +97 -0
- package/dist/merchant/weixin-owner-agent.js.map +1 -0
- package/dist/merchant/weixin-owner-conversation.d.ts +156 -0
- package/dist/merchant/weixin-owner-conversation.js +559 -0
- package/dist/merchant/weixin-owner-conversation.js.map +1 -0
- package/dist/merchant/weixin-owner-digest.d.ts +30 -0
- package/dist/merchant/weixin-owner-digest.js +30 -0
- package/dist/merchant/weixin-owner-digest.js.map +1 -0
- package/dist/merchant/weixin-owner-inventory.d.ts +28 -0
- package/dist/merchant/weixin-owner-inventory.js +48 -0
- package/dist/merchant/weixin-owner-inventory.js.map +1 -0
- package/dist/merchant/weixin-owner-source.d.ts +22 -0
- package/dist/merchant/weixin-owner-source.js +104 -0
- package/dist/merchant/weixin-owner-source.js.map +1 -0
- package/dist/merchant/workbench-server.d.ts +4 -0
- package/dist/merchant/workbench-server.js +75 -9
- package/dist/merchant/workbench-server.js.map +1 -1
- package/dist/merchant-core/collection/alipay-store.d.ts +22 -0
- package/dist/merchant-core/collection/alipay-store.js +125 -0
- package/dist/merchant-core/collection/alipay-store.js.map +1 -0
- package/dist/merchant-core/commercial/calculate.js +6 -6
- package/dist/merchant-core/commercial/calculate.js.map +1 -1
- package/dist/merchant-core/operating/repository.d.ts +0 -1
- package/dist/merchant-core/operating/repository.js +2 -17
- package/dist/merchant-core/operating/repository.js.map +1 -1
- package/dist/merchant-core/operations-jobs/service.d.ts +11 -0
- package/dist/merchant-core/operations-jobs/service.js +65 -34
- package/dist/merchant-core/operations-jobs/service.js.map +1 -1
- package/dist/merchant-core/opportunity/repository.d.ts +0 -1
- package/dist/merchant-core/opportunity/repository.js +2 -17
- package/dist/merchant-core/opportunity/repository.js.map +1 -1
- package/dist/merchant-core/ops/surface.d.ts +1 -0
- package/dist/merchant-core/ops/surface.js +9 -0
- package/dist/merchant-core/ops/surface.js.map +1 -1
- package/dist/merchant-core/orders/model.d.ts +1 -8
- package/dist/merchant-core/orders/model.js +10 -2
- package/dist/merchant-core/orders/model.js.map +1 -1
- package/dist/merchant-core/orders/repository.d.ts +0 -1
- package/dist/merchant-core/orders/repository.js +3 -18
- package/dist/merchant-core/orders/repository.js.map +1 -1
- package/dist/merchant-core/orders/service.js +34 -8
- package/dist/merchant-core/orders/service.js.map +1 -1
- package/dist/merchant-core/proposal/engine.js +2 -0
- package/dist/merchant-core/proposal/engine.js.map +1 -1
- package/dist/merchant-core/proposal/publish.d.ts +0 -6
- package/dist/merchant-core/proposal/publish.js +37 -3
- package/dist/merchant-core/proposal/publish.js.map +1 -1
- package/dist/merchant-core/proposal/repository.d.ts +0 -7
- package/dist/merchant-core/proposal/repository.js +8 -17
- package/dist/merchant-core/proposal/repository.js.map +1 -1
- package/dist/merchant-core/proposal/types.d.ts +1 -0
- package/dist/merchant-core/proposal/types.js.map +1 -1
- package/dist/merchant-core/rfq/policy.d.ts +1 -0
- package/dist/merchant-core/rfq/policy.js +6 -7
- package/dist/merchant-core/rfq/policy.js.map +1 -1
- package/dist/merchant-core/rfq/repository.d.ts +0 -1
- package/dist/merchant-core/rfq/repository.js +2 -17
- package/dist/merchant-core/rfq/repository.js.map +1 -1
- package/dist/merchant-core/rfq/service.d.ts +2 -1
- package/dist/merchant-core/rfq/service.js +2 -4
- package/dist/merchant-core/rfq/service.js.map +1 -1
- package/dist/merchant-core/storage/transaction.d.ts +4 -11
- package/dist/merchant-core/storage/transaction.js +43 -65
- package/dist/merchant-core/storage/transaction.js.map +1 -1
- package/dist/merchant-core/support/manual-service.d.ts +114 -0
- package/dist/merchant-core/support/manual-service.js +300 -0
- package/dist/merchant-core/support/manual-service.js.map +1 -0
- package/dist/negotiation/domain/objects.d.ts +2 -0
- package/dist/negotiation/domain/objects.js +3 -0
- package/dist/negotiation/domain/objects.js.map +1 -1
- package/dist/negotiation/ledger/store.d.ts +6 -0
- package/dist/negotiation/ledger/store.js +28 -0
- package/dist/negotiation/ledger/store.js.map +1 -1
- package/dist/net/safe-http.d.ts +2 -0
- package/dist/net/safe-http.js +1 -1
- package/dist/net/safe-http.js.map +1 -1
- package/dist/product-init.d.ts +1 -0
- package/dist/product-init.js +4 -1
- package/dist/product-init.js.map +1 -1
- package/dist/trust/identity/message-signature.d.ts +1 -1
- package/dist/trust/identity/message-signature.js +6 -1
- package/dist/trust/identity/message-signature.js.map +1 -1
- package/dist/trust/identity/nonce.d.ts +5 -0
- package/dist/trust/identity/nonce.js +2 -0
- package/dist/trust/identity/nonce.js.map +1 -1
- package/dist/weixin/ilink-client.d.ts +3 -2
- package/dist/weixin/ilink-client.js +58 -20
- package/dist/weixin/ilink-client.js.map +1 -1
- package/dist/weixin/types.d.ts +3 -1
- package/dist/weixin/types.js.map +1 -1
- package/package.json +14 -14
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import type { CloudRequestListener } from "./http-router.js";
|
|
3
|
+
export declare const ALIPAY_PRIVATE_PATH = "/buyer/v1/collection/alipay";
|
|
4
|
+
export declare const ALIPAY_LANDING_PREFIX = "/collect/alipay/";
|
|
5
|
+
export interface AlipayCollectionReadBinding {
|
|
6
|
+
negotiationId: string;
|
|
7
|
+
offerId: string;
|
|
8
|
+
version: string;
|
|
9
|
+
agreementId: string;
|
|
10
|
+
termsDigest: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AlipayCollectionQuote {
|
|
13
|
+
version: string;
|
|
14
|
+
totalMinor: number;
|
|
15
|
+
currency: "CNY";
|
|
16
|
+
expiresAt: string;
|
|
17
|
+
}
|
|
18
|
+
/** 读敏感资料时要求单个完整签名与随机 nonce;身份、签名及重放仍由 A2A verifier 验证。 */
|
|
19
|
+
export declare function hasAlipayReadSignature(signatureInput: unknown): boolean;
|
|
20
|
+
type VerifiedCollectionBuyer = {
|
|
21
|
+
merchantId: string;
|
|
22
|
+
buyerPrincipalId: string;
|
|
23
|
+
};
|
|
24
|
+
interface Options {
|
|
25
|
+
merchantId: string;
|
|
26
|
+
verifyBuyer: (req: IncomingMessage, body: Buffer) => Promise<VerifiedCollectionBuyer | "temporarily_unavailable" | undefined>;
|
|
27
|
+
lookup: (input: AlipayCollectionReadBinding & {
|
|
28
|
+
buyerPrincipalId: string;
|
|
29
|
+
}) => AlipayCollectionQuote | undefined;
|
|
30
|
+
current: () => {
|
|
31
|
+
version: string;
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
recipient: string;
|
|
34
|
+
account?: string;
|
|
35
|
+
qrPngBase64?: string;
|
|
36
|
+
} | undefined;
|
|
37
|
+
now?: () => number;
|
|
38
|
+
}
|
|
39
|
+
/** 公开地址仅供安全探测;完整收款资料仅从验签 API 返回。 */
|
|
40
|
+
export declare function createAlipayCollectionHttp(options: Options): {
|
|
41
|
+
landing: CloudRequestListener;
|
|
42
|
+
privateDetails: CloudRequestListener;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* Copyright 2026 harrylabsj
|
|
2
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
*/
|
|
4
|
+
import { NONCE_RETRY_AFTER_SECONDS } from "../trust/identity/nonce.js";
|
|
5
|
+
import { DEFAULT_COVERED_COMPONENTS, parseSignatureInput } from "../trust/identity/index.js";
|
|
6
|
+
export const ALIPAY_PRIVATE_PATH = "/buyer/v1/collection/alipay";
|
|
7
|
+
export const ALIPAY_LANDING_PREFIX = "/collect/alipay/";
|
|
8
|
+
const PRIVATE_HEADERS = {
|
|
9
|
+
"cache-control": "no-store",
|
|
10
|
+
"referrer-policy": "no-referrer",
|
|
11
|
+
"x-content-type-options": "nosniff",
|
|
12
|
+
"content-security-policy": "default-src 'none'; frame-ancestors 'none'; base-uri 'none'",
|
|
13
|
+
};
|
|
14
|
+
const MAX_SIGNATURE_INPUT_BYTES = 2048;
|
|
15
|
+
/** 读敏感资料时要求单个完整签名与随机 nonce;身份、签名及重放仍由 A2A verifier 验证。 */
|
|
16
|
+
export function hasAlipayReadSignature(signatureInput) {
|
|
17
|
+
if (typeof signatureInput !== "string" || signatureInput.length > MAX_SIGNATURE_INPUT_BYTES)
|
|
18
|
+
return false;
|
|
19
|
+
try {
|
|
20
|
+
const [entry, ...rest] = parseSignatureInput(signatureInput);
|
|
21
|
+
return entry !== undefined && rest.length === 0 && /^[a-f0-9]{32}$/.test(entry.params.nonce ?? "") &&
|
|
22
|
+
DEFAULT_COVERED_COMPONENTS.every((component) => entry.components.includes(component));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function json(res, status, value) {
|
|
29
|
+
res.writeHead(status, { ...PRIVATE_HEADERS, "content-type": "application/json; charset=utf-8" });
|
|
30
|
+
res.end(JSON.stringify(value));
|
|
31
|
+
}
|
|
32
|
+
function bindingFrom(raw) {
|
|
33
|
+
try {
|
|
34
|
+
const input = JSON.parse(raw.toString("utf8"));
|
|
35
|
+
if (input === null || typeof input !== "object" || Array.isArray(input) || Object.keys(input).length !== 5)
|
|
36
|
+
return;
|
|
37
|
+
const { negotiationId, offerId, version, agreementId, termsDigest } = input;
|
|
38
|
+
const id = (v) => typeof v === "string" && /^[a-zA-Z0-9_-]{1,128}$/.test(v);
|
|
39
|
+
if (!id(negotiationId) || !id(offerId) || !id(version) || !id(agreementId) ||
|
|
40
|
+
typeof termsDigest !== "string" || !/^sha256:[0-9a-f]{64}$/.test(termsDigest))
|
|
41
|
+
return;
|
|
42
|
+
return { negotiationId, offerId, version, agreementId, termsDigest };
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function readBinding(req) {
|
|
49
|
+
const chunks = [];
|
|
50
|
+
let size = 0;
|
|
51
|
+
// Do not destroy the connection on iterator early exit: return a bounded error.
|
|
52
|
+
for await (const value of req.iterator({ destroyOnReturn: false })) {
|
|
53
|
+
const chunk = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
54
|
+
size += chunk.length;
|
|
55
|
+
if (size > 2048)
|
|
56
|
+
return undefined;
|
|
57
|
+
chunks.push(chunk);
|
|
58
|
+
}
|
|
59
|
+
return Buffer.concat(chunks, size);
|
|
60
|
+
}
|
|
61
|
+
/** 公开地址仅供安全探测;完整收款资料仅从验签 API 返回。 */
|
|
62
|
+
export function createAlipayCollectionHttp(options) {
|
|
63
|
+
const landing = (req, res) => {
|
|
64
|
+
if (req.method !== "HEAD" && req.method !== "GET") {
|
|
65
|
+
res.writeHead(405, { ...PRIVATE_HEADERS, allow: "GET, HEAD" });
|
|
66
|
+
res.end();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
res.writeHead(200, { ...PRIVATE_HEADERS, "content-type": "text/html; charset=utf-8" });
|
|
70
|
+
res.end(req.method === "HEAD" ? undefined : "<!doctype html><html lang=zh-CN><meta charset=utf-8><title>Kiwi 支付宝收款</title><p>如已确认交接,请回到 Kiwi 买家端查看收款指引。本页不收款,也不确认到账。</p></html>");
|
|
71
|
+
};
|
|
72
|
+
const privateDetails = (req, res) => {
|
|
73
|
+
void (async () => {
|
|
74
|
+
if (req.method !== "POST" || req.url !== ALIPAY_PRIVATE_PATH) {
|
|
75
|
+
json(res, 404, { error: "collection_unavailable" });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const raw = await readBinding(req);
|
|
79
|
+
const binding = raw === undefined ? undefined : bindingFrom(raw);
|
|
80
|
+
if (raw === undefined || binding === undefined) {
|
|
81
|
+
json(res, 400, { error: "invalid_collection_request" });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const buyer = await options.verifyBuyer(req, raw);
|
|
85
|
+
if (buyer === "temporarily_unavailable") {
|
|
86
|
+
res.setHeader("Retry-After", NONCE_RETRY_AFTER_SECONDS);
|
|
87
|
+
json(res, 503, { error: buyer, retry_after: NONCE_RETRY_AFTER_SECONDS });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const quote = buyer?.merchantId === options.merchantId
|
|
91
|
+
? options.lookup({ ...binding, buyerPrincipalId: buyer.buyerPrincipalId }) : undefined;
|
|
92
|
+
const config = quote === undefined ? undefined : options.current();
|
|
93
|
+
if (quote === undefined || config?.enabled !== true || config.version !== binding.version || quote.version !== config.version ||
|
|
94
|
+
!(Date.parse(quote.expiresAt) > (options.now ?? Date.now)())) {
|
|
95
|
+
json(res, 404, { error: "collection_unavailable" });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
json(res, 200, { ...quote, recipient: config.recipient,
|
|
99
|
+
...(config.account === undefined ? {} : { account: config.account }),
|
|
100
|
+
...(config.qrPngBase64 === undefined ? {} : { qrPngBase64: config.qrPngBase64 }),
|
|
101
|
+
});
|
|
102
|
+
})().catch(() => {
|
|
103
|
+
if (!res.headersSent)
|
|
104
|
+
json(res, 404, { error: "collection_unavailable" });
|
|
105
|
+
else
|
|
106
|
+
res.destroy();
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
return { landing, privateDetails };
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=alipay-collection-http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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IAAI,IAAI,MAAM,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO;gBACzH,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;gBACjE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,CAAC;gBACpD,OAAO;YACT,CAAC;YACD,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS;gBACpD,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpE,GAAG,CAAC,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;aACjF,CAAC,CAAC;QACL,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,GAAG,CAAC,WAAW;gBAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,CAAC;;gBACrE,GAAG,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AACrC,CAAC"}
|
package/dist/cloud/bootstrap.js
CHANGED
|
@@ -36,12 +36,19 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
36
36
|
import { a2aCardSigningIdentity, createA2aNodeCore, createA2aAuthVerifier } from "../a2a/node.js";
|
|
37
37
|
import { isOpenInquiryIdentity } from "../a2a/open-inquiry-identity.js";
|
|
38
38
|
import { InquiryNonceStore } from "../a2a/inquiry-nonce-store.js";
|
|
39
|
+
import { AlipayCollectionStore } from "../merchant-core/collection/alipay-store.js";
|
|
40
|
+
import { NegotiationApprovalStore } from "../a2a/server/negotiation-approvals.js";
|
|
41
|
+
import { createNegotiationOps } from "../merchant/negotiation-ops.js";
|
|
42
|
+
import { ALIPAY_PRIVATE_PATH, createAlipayCollectionHttp, hasAlipayReadSignature } from "./alipay-collection-http.js";
|
|
39
43
|
import { OpenInquiryLocalPolicy } from "./access/open-inquiry-policy.js";
|
|
40
44
|
import { closeDatabase, closeHttpServer, createCleanup, CleanupError } from "../lifecycle/close.js";
|
|
41
45
|
import { A2A_SIGNING_KEY_FILE, loadA2aSigningIdentityFromFile, loadOrCreateA2aSigningIdentity, toJwsSigningIdentity } from "../a2a/signing-key.js";
|
|
42
46
|
import { publicKeyThumbprint } from "../trust/binding/thumbprint.js";
|
|
43
47
|
import { loadProfile, ProfileError } from "../config/profile.js";
|
|
44
48
|
import { createMerchantManagementApiHandler } from "../http/merchant-management/api.js";
|
|
49
|
+
import { MerchantWeixinChannel } from "../merchant/weixin-channel.js";
|
|
50
|
+
import { createWorkbenchWeixinOwnerOptions } from "../merchant/weixin-owner-source.js";
|
|
51
|
+
import { configuredWeixinOwnerAgent } from "../merchant/weixin-owner-agent-profile.js";
|
|
45
52
|
import { createMerchantFeedApiHandler } from "../http/merchant-feed-api.js";
|
|
46
53
|
import { createMerchantFollowApiHandler } from "../http/merchant-follow-api.js";
|
|
47
54
|
import { createMerchantEngagementApiHandler } from "../http/merchant-engagement-api.js";
|
|
@@ -454,6 +461,33 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
454
461
|
: undefined;
|
|
455
462
|
const openInquiryPolicy = new OpenInquiryLocalPolicy(config.dataDir, config.publicOrigin);
|
|
456
463
|
let inquiryNonces;
|
|
464
|
+
const lastNonceWarning = new Map();
|
|
465
|
+
function warnNonceUnavailable(reason, scope) {
|
|
466
|
+
const time = Date.now();
|
|
467
|
+
const signal = `${reason}|${scope}`;
|
|
468
|
+
const last = lastNonceWarning.get(signal);
|
|
469
|
+
if (last !== undefined && time - last < 60_000)
|
|
470
|
+
return;
|
|
471
|
+
lastNonceWarning.set(signal, time);
|
|
472
|
+
log(`[kiwi-cloud] WARNING a2a_nonce_store_unavailable reason=${reason} scope=${scope}; requests fail closed\n`);
|
|
473
|
+
}
|
|
474
|
+
function checkCloudNonce(key, scope) {
|
|
475
|
+
try {
|
|
476
|
+
inquiryNonces ??= new InquiryNonceStore(config.dataDir, { onUnavailable: warnNonceUnavailable });
|
|
477
|
+
}
|
|
478
|
+
catch {
|
|
479
|
+
warnNonceUnavailable("open", scope);
|
|
480
|
+
return "unavailable";
|
|
481
|
+
}
|
|
482
|
+
return inquiryNonces.record(scope === "signed" ? `signed:${key}` : key, scope);
|
|
483
|
+
}
|
|
484
|
+
function cloudNonceStore(scope) {
|
|
485
|
+
return {
|
|
486
|
+
record: (key) => checkCloudNonce(key, scope),
|
|
487
|
+
checkAndSet: (key) => checkCloudNonce(key, scope) === "fresh",
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
let collectionStore;
|
|
457
491
|
const authVerifier = createA2aAuthVerifier({
|
|
458
492
|
mode: config.a2aAuth.mode,
|
|
459
493
|
...(bearerToken !== undefined ? { bearerToken } : {}),
|
|
@@ -461,16 +495,9 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
461
495
|
signingKeyId: signingIdentity?.keyid ?? config.publicOrigin,
|
|
462
496
|
advertisedBase: config.publicOrigin,
|
|
463
497
|
...(config.a2aAuth.mode === "signature" ? {
|
|
498
|
+
signatureNonceStore: cloudNonceStore("signed"),
|
|
464
499
|
openInquiryEnabled: () => !config.a2aKillSwitch && openInquiryPolicy.isEnabled(),
|
|
465
|
-
openInquiryNonceStore:
|
|
466
|
-
try {
|
|
467
|
-
inquiryNonces ??= new InquiryNonceStore(config.dataDir);
|
|
468
|
-
return inquiryNonces.checkAndSet(key);
|
|
469
|
-
}
|
|
470
|
-
catch {
|
|
471
|
-
return false;
|
|
472
|
-
}
|
|
473
|
-
} },
|
|
500
|
+
openInquiryNonceStore: cloudNonceStore("open_inquiry"),
|
|
474
501
|
} : {}),
|
|
475
502
|
// 云端必须按声明 origin 重建目标 URI:平台网关会改写入站 Host(M0 事实 #4)。
|
|
476
503
|
authoritySource: "declared",
|
|
@@ -540,6 +567,9 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
540
567
|
a2aPath: CLOUD_A2A_PATH,
|
|
541
568
|
dataDir: config.dataDir,
|
|
542
569
|
authVerifier,
|
|
570
|
+
...(config.a2aAuth.mode === "signature" && new URL(config.publicOrigin).protocol === "https:" ? {
|
|
571
|
+
alipayCollection: { origin: config.publicOrigin, current: () => collectionStore?.current() },
|
|
572
|
+
} : {}),
|
|
543
573
|
...(a2aSigningIdentity !== undefined ? { signingIdentity: a2aSigningIdentity } : {}),
|
|
544
574
|
...(fileProductSource !== undefined ? { productSource: fileProductSource.source } : {}),
|
|
545
575
|
...(serviceAvailability !== undefined ? { serviceAvailability } : {}),
|
|
@@ -626,10 +656,30 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
626
656
|
const adminOptions = assembly.serverOptions.admin;
|
|
627
657
|
const productsFilePath = config.productsFile;
|
|
628
658
|
const applyPolicyOverride = assembly.service.policyApplier;
|
|
659
|
+
const weixinEnv = options.env ?? process.env;
|
|
660
|
+
const weixinOwnerAgent = adminOptions === undefined ? undefined : configuredWeixinOwnerAgent(profile, weixinEnv);
|
|
661
|
+
const weixinChannel = adminOptions === undefined ? undefined : new MerchantWeixinChannel({
|
|
662
|
+
dataDir: config.dataDir,
|
|
663
|
+
merchantId: profile.owner_id,
|
|
664
|
+
conversation: createWorkbenchWeixinOwnerOptions({
|
|
665
|
+
flag: weixinEnv.KIWI_WEIXIN_OWNER_PREVIEW,
|
|
666
|
+
replyFlag: weixinEnv.KIWI_WEIXIN_OWNER_REPLIES,
|
|
667
|
+
...(weixinOwnerAgent === undefined ? {} : { agent: weixinOwnerAgent }),
|
|
668
|
+
dataDir: config.dataDir,
|
|
669
|
+
adminDir: adminOptions.adminDir,
|
|
670
|
+
merchantId: profile.owner_id,
|
|
671
|
+
agentId: profile.agent_id,
|
|
672
|
+
origin: config.publicOrigin,
|
|
673
|
+
// 文件商品模式不把另一目录的 SKU 或库存视作当前实例的事实。
|
|
674
|
+
...(fileProductSource === undefined && adminOptions.surface.getExactProduct !== undefined
|
|
675
|
+
? { readExactProduct: adminOptions.surface.getExactProduct } : {}),
|
|
676
|
+
}),
|
|
677
|
+
});
|
|
629
678
|
let managementDb;
|
|
630
679
|
let merchantApiHandler;
|
|
631
680
|
let publicFeedHandler;
|
|
632
681
|
let buyerHandler;
|
|
682
|
+
let alipayLandingHandler;
|
|
633
683
|
let reconciliationTimer;
|
|
634
684
|
let clockTimer;
|
|
635
685
|
let bindingReconcileTimer;
|
|
@@ -655,6 +705,9 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
655
705
|
// 立即 SQLITE_BUSY;WAL 允许单写多读。
|
|
656
706
|
managementDb.exec("PRAGMA journal_mode = WAL");
|
|
657
707
|
managementDb.exec("PRAGMA busy_timeout = 5000");
|
|
708
|
+
if (config.a2aAuth.mode === "signature" && new URL(config.publicOrigin).protocol === "https:") {
|
|
709
|
+
collectionStore = new AlipayCollectionStore(managementDb, profile.owner_id);
|
|
710
|
+
}
|
|
658
711
|
// M1 收尾(D-M0-05/D-M0-08):三个独立迁移账本与 data_grants 在功能装配前
|
|
659
712
|
// 就绪;learning/memory/jobs 任一开启时 CAS 获取实例所有权并心跳续约。
|
|
660
713
|
// 获取失败只关闭新功能并记录原因(X12),现有接待/经营路径保持原行为
|
|
@@ -974,9 +1027,9 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
974
1027
|
merchantId: profile.owner_id,
|
|
975
1028
|
store: feedStore,
|
|
976
1029
|
});
|
|
977
|
-
const
|
|
1030
|
+
const authenticateBuyerRequest = async (request, body) => {
|
|
978
1031
|
const socketTls = request.socket;
|
|
979
|
-
|
|
1032
|
+
return await authVerifier.verify({
|
|
980
1033
|
remoteAddress: request.socket.remoteAddress,
|
|
981
1034
|
authorizationHeader: request.headers.authorization,
|
|
982
1035
|
method: request.method ?? "",
|
|
@@ -985,6 +1038,8 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
985
1038
|
headers: request.headers,
|
|
986
1039
|
body,
|
|
987
1040
|
});
|
|
1041
|
+
};
|
|
1042
|
+
const asVerifiedBuyer = (result) => {
|
|
988
1043
|
if (!result.authenticated ||
|
|
989
1044
|
result.identityVerified !== true ||
|
|
990
1045
|
typeof result.identity !== "string" ||
|
|
@@ -997,6 +1052,7 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
997
1052
|
buyerPrincipalId: result.identity,
|
|
998
1053
|
};
|
|
999
1054
|
};
|
|
1055
|
+
const resolveVerifiedBuyer = async (request, body) => asVerifiedBuyer(await authenticateBuyerRequest(request, body));
|
|
1000
1056
|
const followHandler = createMerchantFollowApiHandler({
|
|
1001
1057
|
merchantId: profile.owner_id,
|
|
1002
1058
|
store: followStore,
|
|
@@ -1013,9 +1069,23 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
1013
1069
|
store: retentionStore,
|
|
1014
1070
|
resolveBuyer: resolveVerifiedBuyer,
|
|
1015
1071
|
});
|
|
1072
|
+
const alipay = collectionStore === undefined || core.resolveAlipayCollection === undefined ? undefined : createAlipayCollectionHttp({
|
|
1073
|
+
merchantId: profile.owner_id,
|
|
1074
|
+
verifyBuyer: async (request, body) => {
|
|
1075
|
+
if (config.a2aKillSwitch || !hasAlipayReadSignature(request.headers["signature-input"]))
|
|
1076
|
+
return undefined;
|
|
1077
|
+
const result = await authenticateBuyerRequest(request, body);
|
|
1078
|
+
return result.protocolCode === "temporarily_unavailable" ? result.protocolCode : asVerifiedBuyer(result);
|
|
1079
|
+
},
|
|
1080
|
+
lookup: core.resolveAlipayCollection,
|
|
1081
|
+
current: () => collectionStore?.current(),
|
|
1082
|
+
});
|
|
1083
|
+
alipayLandingHandler = alipay?.landing;
|
|
1016
1084
|
buyerHandler = (request, response) => {
|
|
1017
1085
|
const pathname = new URL(request.url ?? "/", "http://buyer.internal").pathname;
|
|
1018
|
-
if (pathname ===
|
|
1086
|
+
if (pathname === ALIPAY_PRIVATE_PATH && alipay !== undefined)
|
|
1087
|
+
alipay.privateDetails(request, response);
|
|
1088
|
+
else if (pathname === "/buyer/v1/follow")
|
|
1019
1089
|
followHandler(request, response);
|
|
1020
1090
|
else if (pathname.startsWith("/buyer/v1/privacy-requests")) {
|
|
1021
1091
|
privacyHandler(request, response);
|
|
@@ -1024,6 +1094,7 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
1024
1094
|
engagementHandler(request, response);
|
|
1025
1095
|
};
|
|
1026
1096
|
merchantApiHandler = createMerchantManagementApiHandler({
|
|
1097
|
+
...(weixinChannel !== undefined ? { weixinChannel } : {}),
|
|
1027
1098
|
merchantId: profile.owner_id,
|
|
1028
1099
|
merchantName: profile.name ?? "待设置商家名称",
|
|
1029
1100
|
merchantNameNeedsUpdate: config.merchantNameNeedsUpdate && profile.name === "待设置商家名称",
|
|
@@ -1033,6 +1104,16 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
1033
1104
|
sessions: adminOptions.sessions,
|
|
1034
1105
|
...(adminOptions.secureCookies === true ? { secureCookies: true } : {}),
|
|
1035
1106
|
allowedOrigins: [config.publicOrigin],
|
|
1107
|
+
...(collectionStore === undefined ? {} : {
|
|
1108
|
+
alipayCollection: collectionStore,
|
|
1109
|
+
alipayCollectionOwnerActorId: profile.agent_id,
|
|
1110
|
+
alipayNegotiationApprovals: createNegotiationOps({
|
|
1111
|
+
ledgerDir: path.join(config.dataDir, "a2a"),
|
|
1112
|
+
approvals: NegotiationApprovalStore.forDataDir(config.dataDir),
|
|
1113
|
+
merchantId: profile.owner_id,
|
|
1114
|
+
version: PRODUCT_VERSION,
|
|
1115
|
+
}),
|
|
1116
|
+
}),
|
|
1036
1117
|
listPending: () => adminOptions.surface.listPending(),
|
|
1037
1118
|
mintCandidateConfirmation: (input) => adminOptions.store.createConfirmation(input),
|
|
1038
1119
|
executeDecision: async (input) => {
|
|
@@ -1051,6 +1132,7 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
1051
1132
|
},
|
|
1052
1133
|
policyCurrent: () => assembly.currentPolicy(),
|
|
1053
1134
|
merchantOperations,
|
|
1135
|
+
operationsSchedulerAvailable: () => operationsScheduler !== undefined && governanceRuntime?.active === true,
|
|
1054
1136
|
deliveryConsent: new DeliveryConsentRepository({ db: managementDb, now: () => new Date().toISOString() }),
|
|
1055
1137
|
...(governanceRuntime.active ? {
|
|
1056
1138
|
governance: {
|
|
@@ -1381,6 +1463,7 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
1381
1463
|
productAuthority: fileProductSource !== undefined ? "file" : "exact",
|
|
1382
1464
|
catalogConnection: directConnection !== undefined,
|
|
1383
1465
|
workbuddyAccess: new URL(config.publicOrigin).hostname.endsWith(".app.workbuddy.host"),
|
|
1466
|
+
weixinChannel: weixinChannel !== undefined,
|
|
1384
1467
|
}));
|
|
1385
1468
|
};
|
|
1386
1469
|
if (signingIdentity !== undefined) {
|
|
@@ -1400,6 +1483,7 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
1400
1483
|
...(merchantApiHandler !== undefined ? { merchantApiHandler } : {}),
|
|
1401
1484
|
...(publicFeedHandler !== undefined ? { publicFeedHandler } : {}),
|
|
1402
1485
|
...(buyerHandler !== undefined ? { buyerHandler } : {}),
|
|
1486
|
+
...(alipayLandingHandler !== undefined ? { alipayLandingHandler } : {}),
|
|
1403
1487
|
trustedPageHandler: createTrustedWorkbenchPageHandler(),
|
|
1404
1488
|
merchantHomePage,
|
|
1405
1489
|
readiness,
|
|
@@ -1464,6 +1548,7 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
1464
1548
|
{ id: "heartbeat", run: () => enrollmentHeartbeat?.stop() },
|
|
1465
1549
|
{ id: "operations_scheduler", run: () => operationsScheduler?.stop() },
|
|
1466
1550
|
{ id: "customer_data_maintenance", run: () => customerDataMaintenance?.stop() },
|
|
1551
|
+
{ id: "weixin_channel", run: () => weixinChannel?.close() },
|
|
1467
1552
|
{ id: "http_server", run: () => closeHttpServer(server) },
|
|
1468
1553
|
{ id: "background_work", after: ["timers"], run: async () => {
|
|
1469
1554
|
await Promise.allSettled([directConnectionWork, bindingReconcileWork]);
|
|
@@ -1504,6 +1589,7 @@ export async function bootstrapCloudRuntime(options = {}) {
|
|
|
1504
1589
|
}
|
|
1505
1590
|
throw err;
|
|
1506
1591
|
}
|
|
1592
|
+
weixinChannel?.restore();
|
|
1507
1593
|
const summary = describeCloudConfig(config);
|
|
1508
1594
|
log(`[kiwi-cloud] listening ${config.bindHost}:${config.port}` +
|
|
1509
1595
|
`(origin=${summary.publicOrigin},a2a=${CLOUD_A2A_PATH},auth=${summary.a2aAuth},` +
|