@sunbay/checkout-sdk-protocol 0.0.2 → 0.0.3

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/dist/index.d.cts CHANGED
@@ -1,21 +1,22 @@
1
1
  /**
2
- * 协议公开类型(真源)。
2
+ * Public protocol types (source of truth).
3
3
  *
4
- * 这些类型对外公开,供商户侧 SDK(transport/CheckoutInstance/Element)与
5
- * checkout 托管侧同步副本共同引用。字段与 checkout 后端现有类型对齐,但
6
- * 对外视图(PublicSessionView)**不含** rsaPublicKey 等敏感/内部字段。
4
+ * These types are public and shared by the merchant-side SDK (transport/CheckoutInstance/Element)
5
+ * and the checkout hosted-side synchronized copy. Fields align with the existing checkout backend
6
+ * types, but the public view (PublicSessionView) does **not** include sensitive/internal fields
7
+ * such as rsaPublicKey.
7
8
  */
8
9
  /**
9
- * 交易状态(直接复用 checkout 后端 TxnStatus,不转义)。
10
- * - `I` = 未支付 / 已创建(非终态)
11
- * - `S` = 成功(终态)
12
- * - `F` = 失败(终态)
13
- * - `R` = 需跳转 / 处理中(非终态)
10
+ * Transaction status (reuses the checkout backend TxnStatus verbatim, no translation).
11
+ * - `I` = unpaid / created (non-terminal)
12
+ * - `S` = succeeded (terminal)
13
+ * - `F` = failed (terminal)
14
+ * - `R` = requires redirect / processing (non-terminal)
14
15
  */
15
16
  type TxnStatus = 'I' | 'S' | 'F' | 'R';
16
17
  /**
17
- * 地址信息(对齐 checkout 后端 AddressInfo 字段)。
18
- * 非敏感数据,允许经公共协议传输。
18
+ * Address information (aligned with the checkout backend AddressInfo fields).
19
+ * Non-sensitive data; allowed to be transmitted over the public protocol.
19
20
  */
20
21
  interface AddressInfo {
21
22
  country: string;
@@ -30,10 +31,10 @@ interface AddressInfo {
30
31
  recipientName?: string;
31
32
  phone?: string;
32
33
  }
33
- /** 首期支持的支付方式。 */
34
+ /** Payment methods supported in the first phase. */
34
35
  type PaymentMethod = 'card' | 'applePay' | 'googlePay';
35
36
  /**
36
- * 公开支付方式视图(对外只暴露 method/type/name/logoUrl,不含内部配置)。
37
+ * Public payment method view (only exposes method/type/name/logoUrl, no internal config).
37
38
  */
38
39
  interface PublicPaymentMethod {
39
40
  method: string;
@@ -41,15 +42,15 @@ interface PublicPaymentMethod {
41
42
  name: string;
42
43
  logoUrl: string;
43
44
  }
44
- /** 公开商品行。 */
45
+ /** Public product line. */
45
46
  interface PublicProductLine {
46
47
  amount: number;
47
48
  name: string;
48
49
  num: string;
49
50
  }
50
51
  /**
51
- * 公开 Session 视图:金额 / 币种 / 商品 / collect 标记 / 可用支付方式 / 商户信息。
52
- * **不含** rsaPublicKey 等敏感或内部字段。
52
+ * Public session view: amount / currency / products / collect flags / available payment methods /
53
+ * merchant info. Does **not** include sensitive or internal fields such as rsaPublicKey.
53
54
  */
54
55
  interface PublicSessionView {
55
56
  sessionId: string;
@@ -69,8 +70,8 @@ interface PublicSessionView {
69
70
  merchantReturnUrl?: string;
70
71
  }
71
72
  /**
72
- * 支付结果四态(spec 8.2)。
73
- * `pending` 非终态,消费者不得只接受首条结果。
73
+ * Four payment outcome states (spec 8.2).
74
+ * `pending` is non-terminal; consumers must not accept only the first result.
74
75
  */
75
76
  type PaymentOutcome = {
76
77
  status: 'succeeded';
@@ -89,14 +90,14 @@ type PaymentOutcome = {
89
90
  operationId: string;
90
91
  txnId?: string;
91
92
  };
92
- /** 错误分类(spec 5.4)。 */
93
+ /** Error categories (spec 5.4). */
93
94
  type CheckoutErrorCategory = 'configuration' | 'validation' | 'network' | 'runtime' | 'payment';
94
95
  /**
95
- * 结构化错误(spec 5.4)。
96
+ * Structured error (spec 5.4).
96
97
  */
97
98
  interface CheckoutError {
98
99
  code: string;
99
- /** 展示用消息。 */
100
+ /** Message for display. */
100
101
  message: string;
101
102
  category: CheckoutErrorCategory;
102
103
  errorId: string;
@@ -105,149 +106,160 @@ interface CheckoutError {
105
106
  traceId?: string;
106
107
  }
107
108
  /**
108
- * 白名单设计变量(映射到 hosted 侧 `ThemeConfig`,复用现有 `generateThemeStyles` 与深色推导)。
109
+ * Whitelisted design variables (mapped to the hosted-side `ThemeConfig`, reusing the existing
110
+ * `generateThemeStyles` and dark-mode derivation).
109
111
  *
110
- * 全部可选;值为颜色或长度字符串,由 hosted 侧白名单校验器校验后方可进入 `<style>`。
111
- * 属性名使用 camelCase(如 `borderRadius`),hosted 侧转 kebab。
112
+ * All optional; values are color or length strings, and only enter `<style>` after being validated
113
+ * by the hosted-side whitelist validator. Property names use camelCase (e.g. `borderRadius`); the
114
+ * hosted side converts them to kebab-case.
112
115
  */
113
116
  interface AppearanceVariables {
114
- /** 主色 → `ThemeConfig.primary`(并联动 ring)。 */
117
+ /** Primary color → `ThemeConfig.primary` (also drives ring). */
115
118
  colorPrimary?: string;
116
- /** 背景色 → background / card / popover。 */
119
+ /** Background color → background / card / popover. */
117
120
  colorBackground?: string;
118
- /** 文字色 → foreground。 */
121
+ /** Text color → foreground. */
119
122
  colorText?: string;
120
- /** 边框色 → border / input。 */
123
+ /** Border color → border / input. */
121
124
  colorBorder?: string;
122
- /** 危险色 → destructive。 */
125
+ /** Danger color → destructive. */
123
126
  colorDanger?: string;
124
- /** 圆角 → radius(长度值)。 */
127
+ /** Border radius → radius (length value). */
125
128
  borderRadius?: string;
126
- /** 字体族 → `:root` font-family(不进 `ThemeConfig`,单独注入)。 */
129
+ /** Font family → `:root` font-family (not part of `ThemeConfig`, injected separately). */
127
130
  fontFamily?: string;
128
131
  }
129
132
  /**
130
- * rules 可定制的元素锚点(语义 key,对应 hosted 侧 `data-sunbay-el`)。
133
+ * Customizable element anchors for rules (semantic keys, corresponding to the hosted-side
134
+ * `data-sunbay-el`).
131
135
  *
132
- * 选择器由 hosted 生成,商户只提供语义 key,不接受选择器字符串。
133
- * - `'input'`:卡号 / 有效期 / CVV 输入框;
134
- * - `'input:focus'`:输入框聚焦态;
135
- * - `'input:invalid'`:输入框错误态(`[data-sunbay-invalid]`);
136
- * - `'label'`:iframe 内标签文字;
137
- * - `'error'`:iframe 内错误文字;
138
- * - `'cardBrand'`:卡品牌图标容器;
139
- * - `'cvvIcon'`:CVV 图标。
136
+ * Selectors are generated by the hosted side; merchants only provide semantic keys and selector
137
+ * strings are not accepted.
138
+ * - `'input'`: card number / expiry / CVV input fields;
139
+ * - `'input:focus'`: input focus state;
140
+ * - `'input:invalid'`: input error state (`[data-sunbay-invalid]`);
141
+ * - `'label'`: label text inside the iframe;
142
+ * - `'error'`: error text inside the iframe;
143
+ * - `'cardBrand'`: card brand icon container;
144
+ * - `'cvvIcon'`: CVV icon.
140
145
  */
141
146
  type AppearanceRuleTarget = 'input' | 'input:focus' | 'input:invalid' | 'label' | 'error' | 'cardBrand' | 'cvvIcon';
142
147
  /**
143
- * 单条 rule:白名单 CSS 属性(camelCase 或 kebab)到值的映射。
148
+ * A single rule: a mapping from whitelisted CSS properties (camelCase or kebab) to values.
144
149
  *
145
- * 属性名与值均由 hosted 侧白名单校验后方可进入 `<style>`;非白名单属性 / 非法值被丢弃。
150
+ * Both property names and values only enter `<style>` after hosted-side whitelist validation;
151
+ * non-whitelisted properties / invalid values are discarded.
146
152
  */
147
153
  type AppearanceRuleStyle = Record<string, string>;
148
154
  /**
149
- * 外观定制(appearance)。受控两层:`variables`(整体风格的白名单设计变量)+
150
- * `rules`(关键元素精调的受控语义选择器)。因 iframe 跨域 + PCI 合规,**不开放任意 CSS**。
155
+ * Appearance customization. Controlled in two layers: `variables` (whitelisted design variables for
156
+ * the overall style) + `rules` (controlled semantic selectors for fine-tuning key elements). Due to
157
+ * cross-origin iframes + PCI compliance, arbitrary CSS is **not** allowed.
151
158
  *
152
- * 所有进入 `<style>` 的文本全程由 hosted 侧白名单校验;appearance 不含任何卡值 / 支付参数。
159
+ * All text entering `<style>` is whitelist-validated by the hosted side throughout; appearance
160
+ * contains no card values / payment parameters.
153
161
  */
154
162
  interface Appearance {
155
- /** 白名单设计变量(整体风格)。 */
163
+ /** Whitelisted design variables (overall style). */
156
164
  variables?: AppearanceVariables;
157
- /** 受控语义规则(关键元素精调);key 限 `AppearanceRuleTarget`。 */
165
+ /** Controlled semantic rules (fine-tuning key elements); keys limited to `AppearanceRuleTarget`. */
158
166
  rules?: Partial<Record<AppearanceRuleTarget, AppearanceRuleStyle>>;
159
167
  /**
160
- * 配色方案偏好。
161
- * - `'light'`:浅色;
162
- * - `'dark'`:深色;
163
- * - `'auto'`:跟随系统 / 宿主环境。
168
+ * Color scheme preference.
169
+ * - `'light'`: light;
170
+ * - `'dark'`: dark;
171
+ * - `'auto'`: follow the system / host environment.
164
172
  *
165
- * 协议层只定义类型;缺省时的默认语义(SDK 默认 `'light'`)由消费方实现,
166
- * 协议不强制默认值。向后兼容的可选新增字段。
173
+ * The protocol layer only defines the type; the default semantics when omitted (the SDK defaults
174
+ * to `'light'`) are implemented by the consumer, and the protocol does not enforce a default
175
+ * value. A backward-compatible optional new field.
167
176
  */
168
177
  colorScheme?: 'light' | 'dark' | 'auto';
169
178
  }
170
179
  /**
171
- * 支付方式过滤配置(spec 9:只做减法/排序,禁止前端增开)。
180
+ * Payment method filter configuration (spec 9: subtraction/ordering only, enabling new methods on
181
+ * the frontend is forbidden).
172
182
  */
173
183
  interface PaymentMethodFilter {
174
- /** 要隐藏的支付方式(method 标识)。 */
184
+ /** Payment methods to hide (method identifiers). */
175
185
  hide?: string[];
176
- /** 展示顺序(method 标识)。 */
186
+ /** Display order (method identifiers). */
177
187
  order?: string[];
178
188
  }
179
- /** 可挂载 Element 类型(spec 6)。 */
189
+ /** Mountable Element types (spec 6). */
180
190
  type ElementType = 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address' | 'expressCheckout';
181
- /** card Element 配置(spec 6)。 */
191
+ /** card Element options (spec 6). */
182
192
  interface CardElementOptions {
183
193
  showBillingAddress?: boolean;
184
194
  showShippingAddress?: boolean;
185
195
  showPostalCode?: boolean;
186
196
  appearance?: Appearance;
187
197
  }
188
- /** 拆分卡字段配置(spec 6)。 */
198
+ /** Split card field options (spec 6). */
189
199
  interface CardFieldElementOptions {
190
200
  appearance?: Appearance;
191
201
  }
192
- /** address Element 配置(spec 6)。 */
202
+ /** address Element options (spec 6). */
193
203
  interface AddressElementOptions {
194
204
  mode: 'billing' | 'shipping';
195
205
  appearance?: Appearance;
196
206
  }
197
- /** Apple Pay 官方按钮主题。缺省跟随当前配色(浅 black / 深 white)。 */
207
+ /** Apple Pay official button theme. Defaults to follow the current color scheme (light black / dark white). */
198
208
  type ApplePayButtonTheme = 'black' | 'white' | 'white-outline';
199
- /** Google Pay 官方按钮主题。缺省跟随当前配色(浅 black / 深 white)。 */
209
+ /** Google Pay official button theme. Defaults to follow the current color scheme (light black / dark white). */
200
210
  type GooglePayButtonTheme = 'black' | 'white' | 'default';
201
- /** Apple Pay 官方按钮文案类型(`apple-pay-button` 的 `type` 属性,官方全集)。 */
211
+ /** Apple Pay official button text type (the `type` attribute of `apple-pay-button`, full official set). */
202
212
  type ApplePayButtonType = 'plain' | 'buy' | 'donate' | 'check-out' | 'book' | 'subscribe' | 'reload' | 'add-money' | 'top-up' | 'order' | 'rent' | 'support' | 'contribute' | 'tip';
203
- /** Google Pay 官方按钮文案类型(`buttonType`,官方全集)。 */
213
+ /** Google Pay official button text type (`buttonType`, full official set). */
204
214
  type GooglePayButtonType = 'buy' | 'plain' | 'checkout' | 'pay' | 'donate' | 'book' | 'order' | 'subscribe';
205
- /** Apple Pay 单钱包配置(显示时的细粒度选项)。 */
215
+ /** Apple Pay single-wallet options (fine-grained options when shown). */
206
216
  interface ApplePayOptions {
207
- /** 按钮主题;缺省跟随当前配色。 */
217
+ /** Button theme; defaults to follow the current color scheme. */
208
218
  buttonTheme?: ApplePayButtonTheme;
209
- /** 按钮文案类型;缺省 `'pay'`。 */
219
+ /** Button text type; defaults to `'pay'`. */
210
220
  buttonType?: ApplePayButtonType;
211
221
  }
212
- /** Google Pay 单钱包配置(显示时的细粒度选项)。 */
222
+ /** Google Pay single-wallet options (fine-grained options when shown). */
213
223
  interface GooglePayOptions {
214
- /** 按钮主题;缺省跟随当前配色。 */
224
+ /** Button theme; defaults to follow the current color scheme. */
215
225
  buttonTheme?: GooglePayButtonTheme;
216
- /** 按钮文案类型;缺省 `'pay'`。 */
226
+ /** Button text type; defaults to `'pay'`. */
217
227
  buttonType?: GooglePayButtonType;
218
228
  }
219
- /** expressCheckout Element 配置(spec 6)。 */
229
+ /** expressCheckout Element options (spec 6). */
220
230
  interface ExpressCheckoutElementOptions {
221
231
  /**
222
- * 各钱包开关 / 配置:
223
- * - `false`:强制隐藏该钱包;
224
- * - `true` 或缺省:自动显示(后端业务允许 ∩ 环境可用),主题跟随当前配色;
225
- * - 配置对象:自动显示,并应用对象内的细粒度配置(如 buttonTheme)。
232
+ * Per-wallet toggle / configuration:
233
+ * - `false`: force-hide this wallet;
234
+ * - `true` or omitted: auto-show (backend business allows ∩ environment available), theme follows
235
+ * the current color scheme;
236
+ * - config object: auto-show, and apply the fine-grained config in the object (e.g. buttonTheme).
226
237
  */
227
238
  paymentMethods?: {
228
239
  applePay?: boolean | ApplePayOptions;
229
240
  googlePay?: boolean | GooglePayOptions;
230
241
  };
231
- /** 布局约束(首期仅最大列数)。 */
242
+ /** Layout constraints (first phase: maximum columns only). */
232
243
  layout?: {
233
244
  maxColumns?: number;
234
245
  };
235
- /** 钱包按钮高度(像素,全局应用到所有钱包按钮)。hosted 侧 clamp 到 [30, 64];缺省 40。 */
246
+ /** Wallet button height (pixels, applied globally to all wallet buttons). The hosted side clamps to [30, 64]; defaults to 40. */
236
247
  buttonHeight?: number;
237
248
  }
238
249
  /**
239
- * express 可用钱包视图(spec 6)。
240
- * 表示各钱包在当前环境下是否可用,用于 express 可用性事件载荷。
250
+ * Express available wallets view (spec 6).
251
+ * Indicates whether each wallet is available in the current environment; used as the payload for the
252
+ * express availability event.
241
253
  */
242
254
  interface AvailableWallets {
243
255
  applePay: boolean;
244
256
  googlePay: boolean;
245
257
  }
246
- /** Element 配置联合(按 type 区分)。 */
258
+ /** Element options union (distinguished by type). */
247
259
  type ElementOptions = CardElementOptions | CardFieldElementOptions | AddressElementOptions | ExpressCheckoutElementOptions;
248
- /** Element 运行状态机(spec 6)。 */
260
+ /** Element runtime state machine (spec 6). */
249
261
  type ElementStatus = 'created' | 'loading' | 'ready' | 'destroyed' | 'loadError';
250
- /** action 载荷(spec 8.3;qrCode/showContent 首期预留)。 */
262
+ /** action payload (spec 8.3; qrCode/showContent reserved for the first phase). */
251
263
  interface PaymentAction {
252
264
  type: 'qrCode' | 'redirect' | 'showContent';
253
265
  redirectUrl?: string;
@@ -256,33 +268,35 @@ interface PaymentAction {
256
268
  }
257
269
 
258
270
  /**
259
- * 信封与握手契约(spec 5.1,真源)。
271
+ * Envelope and handshake contract (spec 5.1, source of truth).
260
272
  *
261
- * 协议名 `sunbay-checkout`,`major = 1`。与现有 Native Bridge `{v:1,type,...}`
262
- * 是不同协议,数字相同不代表兼容。
273
+ * Protocol name `sunbay-checkout`, `major = 1`. This is a different protocol from the existing
274
+ * Native Bridge `{v:1,type,...}`; identical numbers do not imply compatibility.
263
275
  *
264
- * `encodeEnvelope`/`decodeEnvelope`:JSON 序列化 + 最小运行时结构校验
265
- * (校验 protocol/major/kind/必填字段),非法抛错。解码器**不**校验 request.name
266
- * 是否为已知 CommandName —— 未知 name 仍解为 kind==='request',由调用方拒绝。
276
+ * `encodeEnvelope`/`decodeEnvelope`: JSON serialization + minimal runtime structural validation
277
+ * (validates protocol/major/kind/required fields), throwing on invalid input. The decoder does
278
+ * **not** validate whether request.name is a known CommandName — an unknown name is still decoded
279
+ * as kind==='request' and rejected by the caller.
267
280
  */
268
281
 
269
- /** 协议名常量。 */
282
+ /** Protocol name constant. */
270
283
  declare const PROTOCOL_NAME: "sunbay-checkout";
271
- /** 当前主版本。 */
284
+ /** Current major version. */
272
285
  declare const PROTOCOL_MAJOR: 1;
273
286
  /**
274
- * 握手消息(spec 5.1)。main iframe 加载后先广播,此时尚无 checkoutId。
287
+ * Handshake message (spec 5.1). Broadcast first after the main iframe loads, when there is no
288
+ * checkoutId yet.
275
289
  */
276
290
  type RuntimeHello = {
277
291
  protocol: 'sunbay-checkout';
278
292
  kind: 'hello';
279
293
  runtimeId: string;
280
294
  supportedMajorVersions: number[];
281
- /** 首期:['card','splitCard','address','express','paymentMethodFilter']。 */
295
+ /** First phase: ['card','splitCard','address','express','paymentMethodFilter']. */
282
296
  capabilities: string[];
283
297
  };
284
298
  /**
285
- * 初始化后的公共信封(spec 5.1)。
299
+ * Public envelope after initialization (spec 5.1).
286
300
  */
287
301
  type Envelope = {
288
302
  protocol: 'sunbay-checkout';
@@ -312,28 +326,28 @@ type Envelope = {
312
326
  operationId?: string;
313
327
  payload: unknown;
314
328
  });
315
- /** 协议校验失败错误。 */
329
+ /** Protocol validation failure error. */
316
330
  declare class EnvelopeDecodeError extends Error {
317
331
  constructor(message: string);
318
332
  }
319
333
  /**
320
- * 将信封序列化为线缆字符串(JSON)。
334
+ * Serialize an envelope into a wire string (JSON).
321
335
  *
322
- * @param envelope 待发送的信封
323
- * @returns JSON 字符串
336
+ * @param envelope The envelope to send
337
+ * @returns JSON string
324
338
  * @example
325
339
  * const wire = encodeEnvelope({ protocol: 'sunbay-checkout', major: 1, ... });
326
340
  */
327
341
  declare function encodeEnvelope(envelope: Envelope): string;
328
342
  /**
329
- * 解析并最小结构校验信封。非法(缺 protocol、错 major、非法 kind、缺必填字段、
330
- * 非 JSON)一律抛 {@link EnvelopeDecodeError}。
343
+ * Parse and minimally structurally validate an envelope. Invalid input (missing protocol, wrong
344
+ * major, invalid kind, missing required fields, non-JSON) always throws {@link EnvelopeDecodeError}.
331
345
  *
332
- * 注意:解码器不校验 request.name 是否为已知命令 —— 未知 name 仍解为
333
- * kind==='request',交由调用方(如 Orchestrator)拒绝。
346
+ * Note: the decoder does not validate whether request.name is a known command — an unknown name is
347
+ * still decoded as kind==='request' and left for the caller (e.g. the Orchestrator) to reject.
334
348
  *
335
- * @param wire 线缆字符串
336
- * @returns 已校验结构的信封
349
+ * @param wire The wire string
350
+ * @returns The structurally validated envelope
337
351
  * @example
338
352
  * const env = decodeEnvelope(wire);
339
353
  * if (env.kind === 'request') { ... }
@@ -341,10 +355,10 @@ declare function encodeEnvelope(envelope: Envelope): string;
341
355
  declare function decodeEnvelope(wire: string): Envelope;
342
356
 
343
357
  /**
344
- * 协议错误码常量(单一真源,spec 5.4)。
358
+ * Protocol error code constants (single source of truth, spec 5.4).
345
359
  *
346
- * 不提供可能误导重复付款的通用 `retryable` 布尔。
347
- * 仅保留实际会被产出的错误码;新增码须同时有产出点。
360
+ * Does not provide a generic `retryable` boolean that could mislead into duplicate payments.
361
+ * Only keeps error codes that are actually produced; new codes must have a production point.
348
362
  */
349
363
  declare const ErrorCode: {
350
364
  readonly INVALID_OPTIONS: "INVALID_OPTIONS";
@@ -359,20 +373,21 @@ declare const ErrorCode: {
359
373
  readonly PAYMENT_FLOW_ERROR: "PAYMENT_FLOW_ERROR";
360
374
  readonly UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY";
361
375
  };
362
- /** 错误码字面量联合类型。 */
376
+ /** Error code literal union type. */
363
377
  type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
364
378
 
365
379
  /**
366
- * 命令契约(商户 SDK → main,spec 5.2 表,真源)。
380
+ * Command contract (merchant SDK → main, spec 5.2 table, source of truth).
367
381
  *
368
- * 每命令的请求/响应类型在此定义;跨通道只传 JSON 可序列化数据。
382
+ * The request/response types for each command are defined here; only JSON-serializable data is sent
383
+ * across the channel.
369
384
  */
370
385
 
371
- /** 全部命令名(spec 5.2)。 */
386
+ /** All command names (spec 5.2). */
372
387
  type CommandName = 'initialize' | 'createElement' | 'updateElement' | 'destroyElement' | 'focus' | 'blur' | 'clear' | 'updateCheckout' | 'getSession' | 'refresh' | 'getPaymentStatus' | 'confirm' | 'destroy';
373
- /** 已知命令名集合(供调用方校验 request.name 是否受支持)。 */
388
+ /** Set of known command names (for callers to validate whether request.name is supported). */
374
389
  declare const COMMAND_NAMES: readonly CommandName[];
375
- /** 判断字符串是否为已知命令名。 */
390
+ /** Determine whether a string is a known command name. */
376
391
  declare function isCommandName(name: string): name is CommandName;
377
392
  interface InitializeReq {
378
393
  sessionId: string;
@@ -444,7 +459,7 @@ type DestroyReq = Record<string, never>;
444
459
  interface DestroyResp {
445
460
  released: true;
446
461
  }
447
- /** 命令名 → 请求载荷映射。 */
462
+ /** Command name → request payload mapping. */
448
463
  interface CommandRequestMap {
449
464
  initialize: InitializeReq;
450
465
  createElement: CreateElementReq;
@@ -460,7 +475,7 @@ interface CommandRequestMap {
460
475
  confirm: ConfirmReq;
461
476
  destroy: DestroyReq;
462
477
  }
463
- /** 命令名 → 成功响应载荷映射。 */
478
+ /** Command name → success response payload mapping. */
464
479
  interface CommandResponseMap {
465
480
  initialize: InitializeResp;
466
481
  createElement: CreateElementResp;
@@ -478,24 +493,25 @@ interface CommandResponseMap {
478
493
  }
479
494
 
480
495
  /**
481
- * 事件契约(main → 商户 SDK,spec 5.3 表,真源)。
496
+ * Event contract (main → merchant SDK, spec 5.3 table, source of truth).
482
497
  *
483
- * 公开事件仅暴露 empty/complete/brand/error 等允许状态,**绝不含卡值**,
484
- * 不提供卡数据 getValue。`on` 注册后不重放历史事件。
498
+ * Public events only expose allowed states such as empty/complete/brand/error, and **never contain
499
+ * card values**; no card-data getValue is provided. After `on` registration, historical events are
500
+ * not replayed.
485
501
  */
486
502
 
487
- /** 全部事件名(spec 5.3)。 */
503
+ /** All event names (spec 5.3). */
488
504
  type EventName = 'ready' | 'change' | 'focus' | 'blur' | 'loadError' | 'elementReady' | 'expressAvailabilityChange' | 'paymentStateChange' | 'paymentResult' | 'error';
489
- /** 已知事件名集合。 */
505
+ /** Set of known event names. */
490
506
  declare const EVENT_NAMES: readonly EventName[];
491
- /** 判断字符串是否为已知事件名。 */
507
+ /** Determine whether a string is a known event name. */
492
508
  declare function isEventName(name: string): name is EventName;
493
509
  interface ReadyEvent {
494
510
  elementId: string;
495
511
  }
496
512
  interface ElementReadyEvent {
497
513
  elementId: string;
498
- /** 仅 expressCheckout Element ready 时携带:各钱包可用性。 */
514
+ /** Only carried when the expressCheckout Element is ready: per-wallet availability. */
499
515
  availableWallets?: AvailableWallets;
500
516
  }
501
517
  interface ChangeEvent {
@@ -503,7 +519,7 @@ interface ChangeEvent {
503
519
  empty: boolean;
504
520
  complete: boolean;
505
521
  error?: CheckoutError;
506
- /** 仅卡号字段允许携带 brand;绝不含卡值。 */
522
+ /** Only the card number field may carry brand; never contains card values. */
507
523
  brand?: string;
508
524
  }
509
525
  interface FocusEvent {
@@ -517,8 +533,9 @@ interface LoadErrorEvent {
517
533
  error: CheckoutError;
518
534
  }
519
535
  /**
520
- * express 可用钱包变化事件(spec 6)。
521
- * 专用于 expressCheckout:以 AvailableWallets 表达各钱包(Apple/Google Pay)可用性。
536
+ * Express available-wallets change event (spec 6).
537
+ * Dedicated to expressCheckout: uses AvailableWallets to express the availability of each wallet
538
+ * (Apple/Google Pay).
522
539
  */
523
540
  interface ExpressAvailabilityChangeEvent {
524
541
  availableWallets: AvailableWallets;
@@ -526,7 +543,7 @@ interface ExpressAvailabilityChangeEvent {
526
543
  interface PaymentStateChangeEvent {
527
544
  operationId: string;
528
545
  method: PaymentMethod;
529
- /** 过程状态;requiresAction 时携带 action 信息。 */
546
+ /** Intermediate state; carries action info when requiresAction. */
530
547
  state: string;
531
548
  action?: PaymentAction;
532
549
  }
@@ -536,11 +553,11 @@ interface PaymentResultEvent {
536
553
  outcome: PaymentOutcome;
537
554
  }
538
555
  interface ErrorEvent {
539
- /** 异步主动流程错误;可含 operationId(如已创建)。 */
556
+ /** Error in an asynchronous proactive flow; may include operationId (if already created). */
540
557
  operationId?: string;
541
558
  error: CheckoutError;
542
559
  }
543
- /** 事件名 → 载荷映射。 */
560
+ /** Event name → payload mapping. */
544
561
  interface EventPayloadMap {
545
562
  ready: ReadyEvent;
546
563
  change: ChangeEvent;
@@ -555,43 +572,47 @@ interface EventPayloadMap {
555
572
  }
556
573
 
557
574
  /**
558
- * iframe 布局协议:托管 iframe(checkout,child)→ 父窗口(商户 SDK,parent)的
559
- * **直连 postMessage** 契约,用于 iframe 自适应高度。
575
+ * iframe layout protocol: the **direct postMessage** contract from the hosted iframe (checkout,
576
+ * child) → parent window (merchant SDK, parent), used for iframe auto-height.
560
577
  *
561
- * 与外层 Envelope(商户 SDK ↔ main iframe)及内层点对点 port(element ↔ main)均区分:
562
- * 本消息由每个可见 field / element iframe 直接 postMessage 到其 `window.parent`(商户页),
563
- * 商户 SDK 的 Element 句柄监听后把外层 iframe 高度调整为内容真实高度(宽度保持 100%)。
578
+ * Distinct from both the outer Envelope (merchant SDK ↔ main iframe) and the inner point-to-point
579
+ * port (element ↔ main): this message is posted directly by each visible field / element iframe to
580
+ * its `window.parent` (the merchant page), and the merchant SDK's Element handle listens for it and
581
+ * adjusts the outer iframe height to the real content height (width stays 100%).
564
582
  *
565
- * 安全约束(AGENTS/spec):本消息**绝不含任何卡值**(明文或密文),仅携带 height 与
566
- * elementId。父窗口侧须校验来源(`event.source === iframe.contentWindow` 且
567
- * `event.origin === hostOrigin`)后方可采信,防止跨源伪造。
583
+ * Security constraint (AGENTS/spec): this message **never contains any card value** (plaintext or
584
+ * ciphertext); it only carries height and elementId. The parent-window side must validate the
585
+ * source (`event.source === iframe.contentWindow` and `event.origin === hostOrigin`) before
586
+ * trusting it, to prevent cross-origin forgery.
568
587
  */
569
- /** iframe 自适应高度消息的判别字面量(命名空间化,避免与其它 postMessage 碰撞)。 */
588
+ /** Discriminant literal for the iframe auto-height message (namespaced to avoid colliding with other postMessages). */
570
589
  declare const IFRAME_RESIZE_MESSAGE_TYPE: "sunbay:checkout:iframe-resize";
571
590
  /**
572
- * iframe(child)→ 父窗口(SDK)的内容高度变更通知。
591
+ * Content height change notification from the iframe (child) → parent window (SDK).
573
592
  *
574
- * child 用 `ResizeObserver` 观测内容高度,变化时发送(去重);parent 据此设
575
- * `iframe.style.height`。绝不含卡值。
593
+ * The child observes content height with a `ResizeObserver` and sends on change (deduplicated); the
594
+ * parent sets `iframe.style.height` accordingly. Never contains card values.
576
595
  */
577
596
  interface IframeResizeMessage {
578
- /** 判别字段,固定为 {@link IFRAME_RESIZE_MESSAGE_TYPE}。 */
597
+ /** Discriminant field, fixed to {@link IFRAME_RESIZE_MESSAGE_TYPE}. */
579
598
  type: typeof IFRAME_RESIZE_MESSAGE_TYPE;
580
599
  /**
581
- * 目标 Element 的唯一 id。由商户 SDK 经 iframe src 的 `&elementId=` 下发,child 原样
582
- * 回传,供父窗口在同一页面多个 iframe 间按句柄分发。
600
+ * The unique id of the target Element. Passed down by the merchant SDK via the iframe src's
601
+ * `&elementId=`, echoed back verbatim by the child, so the parent window can dispatch by handle
602
+ * among multiple iframes on the same page.
583
603
  */
584
604
  elementId: string;
585
- /** 内容高度(CSS px,已 `Math.ceil`;有限且非负)。 */
605
+ /** Content height (CSS px, already `Math.ceil`-ed; finite and non-negative). */
586
606
  height: number;
587
607
  }
588
608
  /**
589
- * 是否为合法的 {@link IframeResizeMessage}。
609
+ * Whether the value is a valid {@link IframeResizeMessage}.
590
610
  *
591
- * 校验:非空对象 + type 字面量匹配 + elementId 为非空字符串 + height 为有限非负数。
611
+ * Validates: non-null object + type literal match + elementId is a non-empty string + height is a
612
+ * finite non-negative number.
592
613
  *
593
- * @param data - 任意来源数据(通常是 `MessageEvent.data`)。
594
- * @returns data 是否为合法的 iframe-resize 消息。
614
+ * @param data - Data from any source (typically `MessageEvent.data`).
615
+ * @returns Whether data is a valid iframe-resize message.
595
616
  */
596
617
  declare function isIframeResizeMessage(data: unknown): data is IframeResizeMessage;
597
618