@harrylabsj/kiwi-merchant-cloud 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.
Files changed (50) hide show
  1. package/app/cloud/bootstrap.d.ts +2 -0
  2. package/app/cloud/bootstrap.js +93 -10
  3. package/app/cloud/bootstrap.js.map +1 -1
  4. package/app/cloud/catalog-client.d.ts +2 -0
  5. package/app/cloud/catalog-client.js +5 -1
  6. package/app/cloud/catalog-client.js.map +1 -1
  7. package/app/cloud/connect-service.d.ts +153 -0
  8. package/app/cloud/connect-service.js +897 -0
  9. package/app/cloud/connect-service.js.map +1 -0
  10. package/app/cloud/file-listing-publication.d.ts +105 -0
  11. package/app/cloud/file-listing-publication.js +436 -0
  12. package/app/cloud/file-listing-publication.js.map +1 -0
  13. package/app/cloud/merchant-connect.d.ts +19 -13
  14. package/app/cloud/merchant-connect.js +43 -284
  15. package/app/cloud/merchant-connect.js.map +1 -1
  16. package/app/cloud-sample/products.json +3 -3
  17. package/app/http/merchant-management/api.d.ts +23 -1
  18. package/app/http/merchant-management/api.js +141 -1
  19. package/app/http/merchant-management/api.js.map +1 -1
  20. package/app/http/merchant-management/page.d.ts +4 -1
  21. package/app/http/merchant-management/page.js +126 -7
  22. package/app/http/merchant-management/page.js.map +1 -1
  23. package/build-manifest.json +116 -86
  24. package/node_modules/@hono/node-server/dist/early-hints.cjs +1 -1
  25. package/node_modules/@hono/node-server/dist/early-hints.mjs +1 -1
  26. package/node_modules/@hono/node-server/dist/index.cjs +41 -19
  27. package/node_modules/@hono/node-server/dist/index.mjs +42 -20
  28. package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -0
  29. package/node_modules/@hono/node-server/dist/serve-static.d.cts +2 -1
  30. package/node_modules/@hono/node-server/dist/serve-static.d.mts +2 -1
  31. package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -0
  32. package/node_modules/@hono/node-server/package.json +3 -2
  33. package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +1 -1
  34. package/node_modules/hono/dist/cjs/jsx/utils.js +1 -1
  35. package/node_modules/hono/dist/cjs/middleware/combine/index.js +3 -1
  36. package/node_modules/hono/dist/cjs/middleware/etag/index.js +2 -2
  37. package/node_modules/hono/dist/cjs/middleware/language/language.js +1 -1
  38. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +1 -0
  39. package/node_modules/hono/dist/jsx/utils.js +1 -1
  40. package/node_modules/hono/dist/middleware/combine/index.js +3 -1
  41. package/node_modules/hono/dist/middleware/etag/index.js +2 -2
  42. package/node_modules/hono/dist/middleware/serve-static/index.js +1 -0
  43. package/node_modules/hono/package.json +2 -2
  44. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +19 -18
  45. package/node_modules/yaml/browser/dist/nodes/Alias.js +25 -23
  46. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +19 -18
  47. package/node_modules/yaml/dist/nodes/Alias.js +25 -23
  48. package/node_modules/yaml/package.json +1 -1
  49. package/package.json +2 -2
  50. package/runtime-package.json +2 -2
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { AgentCard } from "../discovery/agent-card/types.js";
17
+ import { type AuthorizedEnrollment } from "./binding/enrollment-challenge.js";
18
+ export declare class MerchantConnectError extends Error {
19
+ readonly code: string;
20
+ constructor(code: string, message: string);
21
+ }
22
+ /**
23
+ * 配对诊断固定安全码(A15):reconcile 各阶段失败只允许透出本集合内的自有
24
+ * 稳定码——绝不反射远端错误原文/grant/device_code/JWS/头/私钥。工作台 API
25
+ * 白名单(CATALOG_CONNECTION_SAFE_CODES)以此单源扩展。
26
+ */
27
+ export declare const CONNECTION_PAIRING_SAFE_CODES: Set<string>;
28
+ /**
29
+ * 公网入口 host 白名单口径(CLI parsePublicOrigin 与服务构造器共用,
30
+ * 两边边界一致,谁也不放宽):拒绝 localhost/私网 IP/链路本地域名/无点主机。
31
+ * 只判 host;协议与路径形态由各自调用点另行校验。
32
+ */
33
+ export declare function isPublicHostAllowed(hostname: string): boolean;
34
+ /** 连接会话(merchant-enrollments.json 中单条 session 的完整形状)。 */
35
+ export interface ConnectionSession extends AuthorizedEnrollment {
36
+ catalog_origin: string;
37
+ preview_digest: string;
38
+ frozen_card: AgentCard;
39
+ device_code: string;
40
+ user_code: string;
41
+ verification_uri: string;
42
+ interval: number;
43
+ generation?: number;
44
+ catalog_agent_id?: string;
45
+ expected_catalog_agent_id?: string;
46
+ /** 仅由验真 binding claim 写入;authorized 轮询结果不写入本字段。 */
47
+ merchant_id?: string;
48
+ grant?: string;
49
+ authorization_epoch?: number;
50
+ /**
51
+ * authorized 轮询里的 merchant_id 断言(**未验真**):仅供 bind 请求的
52
+ * 入参一致性校验,CatalogClient 会核对签名 claim 与它一致;商品盖戳等
53
+ * 任何权威用途都只认 claim 写入的 merchant_id。
54
+ */
55
+ offered_merchant_id?: string;
56
+ binding_id?: string;
57
+ binding_version?: number;
58
+ /** claim 里的 expires_at(已验证):**首签声明的短期 TTL**(Catalog 每次
59
+ * 公开读会重签新声明);bound 未发布时作有效期门槛,published 的续验以
60
+ * Catalog 当次重签的公开声明为准,不用它判死。 */
61
+ binding_expires_at?: string;
62
+ active_card_revision?: number;
63
+ expected_card_revision?: number;
64
+ card_revision?: number;
65
+ }
66
+ /**
67
+ * 纯 resume 选择:只有同 origin + 同公钥指纹 + 可续状态 + 未过期才复用。
68
+ * (自 merchant-connect.ts 原样搬移,行为被 tests/merchant-connect-migration.test.ts 钉住。)
69
+ *
70
+ * 过期口径按状态区分:preparing/authorized 看授权窗口 expires_at;
71
+ * **bound/published 看已验真绑定的 binding_expires_at**——绑定已建立后
72
+ * 授权 grant 过期不影响续办(用户无需重新授权),反过来绑定过期必须拒绝。
73
+ */
74
+ export declare function selectReusableEnrollment(sessions: readonly AuthorizedEnrollment[], input: {
75
+ runtimeOrigin: string;
76
+ keyThumbprint: string;
77
+ nowMs: number;
78
+ }): AuthorizedEnrollment | undefined;
79
+ /** Keep the Catalog account's single-agent identity through key loss and address migration. */
80
+ export declare function priorPublishedCatalogAgentId(sessions: readonly AuthorizedEnrollment[]): string | undefined;
81
+ /** 助手/工作台安全摘要:永不含 user_code/device_code/grant/授权链接。 */
82
+ export type ConnectionSummaryStatus = "idle" | "awaiting_confirmation" | "authorized" | "bound" | "published" | "replaced" | "revoked" | "paused" | "expired" | "canceled" | "unknown" | "error";
83
+ export type ConnectionStage = "prepare" | "authorize" | "publish";
84
+ export interface ConnectionSummary {
85
+ status: ConnectionSummaryStatus;
86
+ /** 自有固定阶段词(A15):preparing→prepare,authorized→authorize,bound/published→publish。 */
87
+ stage: ConnectionStage;
88
+ published: boolean;
89
+ agentId: string | null;
90
+ bindingId: string | null;
91
+ bindingExpiresAt: string | null;
92
+ cardRevision: number | null;
93
+ /** 可用性/安全错误码(如 PUBLICATION_NOT_ACTIVE);健康为 null。 */
94
+ code: string | null;
95
+ detail: string | null;
96
+ }
97
+ /** 仅商家本人可见的配对信息;只在 preparing/awaiting 阶段存在。 */
98
+ export interface ConnectionPairing {
99
+ userCode: string;
100
+ verificationUri: string;
101
+ expiresAt: string;
102
+ }
103
+ /**
104
+ * 已验证绑定投影:merchantId 只来自 CatalogClient 验真的 binding claim
105
+ * (或 published 会话经公开绑定复核一致的结果)。
106
+ */
107
+ export interface VerifiedBinding {
108
+ agentId: string;
109
+ bindingId: string;
110
+ bindingVersion: number;
111
+ merchantId: string;
112
+ keyThumbprint: string;
113
+ runtimeOrigin: string;
114
+ a2aEndpoint: string;
115
+ expiresAt: string;
116
+ cardRevision: number | null;
117
+ }
118
+ export interface MerchantConnectionServiceOptions {
119
+ /** 权威状态目录(merchant-enrollments.json 所在)。 */
120
+ dataDir: string;
121
+ /** Catalog 控制面根 URL(https;loopback 仅测试)。 */
122
+ catalogUrl: string;
123
+ /** 运行时公开 origin(只取自 KIWI_CLOUD_PUBLIC_ORIGIN 或 CLI 已校验值)。 */
124
+ publicOrigin: string;
125
+ /** 部署代次(当前 1);会话按此选择,拒绝悄悄迁移。 */
126
+ generation?: number;
127
+ serviceEpoch?: number;
128
+ fetchImpl?: typeof fetch;
129
+ now?: () => Date;
130
+ /**
131
+ * 公开名片提供者(缺省:匿名读自身 origin 的 well-known 卡并核对签名声明,
132
+ * 与 CLI 的 verifyPublicRuntimeReady 同口径)。云端可注入本地构建的同名卡。
133
+ */
134
+ loadPublicCard?: () => Promise<AgentCard>;
135
+ /** 绑定验真后、发名片前调用;失败保留 bound、不发布。 */
136
+ beforePublish?: (binding: VerifiedBinding) => Promise<void>;
137
+ /** 仅测试/本地回环:放宽公网 host 白名单(默认绝不放宽 CLI 的私网边界)。 */
138
+ allowPrivateOrigin?: boolean;
139
+ }
140
+ export interface MerchantConnectionService {
141
+ /** 唯一允许创建 enrollment 的入口;同 origin/key/catalog/冻结卡幂等复用。 */
142
+ begin(): Promise<ConnectionSummary>;
143
+ /** 单趟短执行:至多一次 poll + 已就绪格级联;后台调用绝不创建新会话。 */
144
+ reconcile(): Promise<ConnectionSummary>;
145
+ /** 本地状态摘要(便宜、不触发 Catalog 写);可用性码来自最近一次 reconcile。 */
146
+ getSummary(): Promise<ConnectionSummary>;
147
+ /** 本人配对信息(preparing 阶段);无会话或已过该阶段返回 null。 */
148
+ getPairing(): ConnectionPairing | null;
149
+ /** 已验证绑定(bound/published 且未过期;published 另经 Catalog 复核);无则 null。 */
150
+ getVerifiedBinding(): Promise<VerifiedBinding | null>;
151
+ }
152
+ /** 构造连接服务(幂等工厂;同一 dataDir 可由 CLI 与服务实例先后使用)。 */
153
+ export declare function createMerchantConnectionService(options: MerchantConnectionServiceOptions): MerchantConnectionService;