@sunbay/checkout-sdk-protocol 0.0.1 → 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,75 +106,160 @@ interface CheckoutError {
105
106
  traceId?: string;
106
107
  }
107
108
  /**
108
- * 外观定制(appearance)。首期为开放映射,交由托管侧解释。
109
+ * Whitelisted design variables (mapped to the hosted-side `ThemeConfig`, reusing the existing
110
+ * `generateThemeStyles` and dark-mode derivation).
111
+ *
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.
115
+ */
116
+ interface AppearanceVariables {
117
+ /** Primary color → `ThemeConfig.primary` (also drives ring). */
118
+ colorPrimary?: string;
119
+ /** Background color → background / card / popover. */
120
+ colorBackground?: string;
121
+ /** Text color → foreground. */
122
+ colorText?: string;
123
+ /** Border color → border / input. */
124
+ colorBorder?: string;
125
+ /** Danger color → destructive. */
126
+ colorDanger?: string;
127
+ /** Border radius → radius (length value). */
128
+ borderRadius?: string;
129
+ /** Font family → `:root` font-family (not part of `ThemeConfig`, injected separately). */
130
+ fontFamily?: string;
131
+ }
132
+ /**
133
+ * Customizable element anchors for rules (semantic keys, corresponding to the hosted-side
134
+ * `data-sunbay-el`).
135
+ *
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.
145
+ */
146
+ type AppearanceRuleTarget = 'input' | 'input:focus' | 'input:invalid' | 'label' | 'error' | 'cardBrand' | 'cvvIcon';
147
+ /**
148
+ * A single rule: a mapping from whitelisted CSS properties (camelCase or kebab) to values.
149
+ *
150
+ * Both property names and values only enter `<style>` after hosted-side whitelist validation;
151
+ * non-whitelisted properties / invalid values are discarded.
152
+ */
153
+ type AppearanceRuleStyle = Record<string, string>;
154
+ /**
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.
158
+ *
159
+ * All text entering `<style>` is whitelist-validated by the hosted side throughout; appearance
160
+ * contains no card values / payment parameters.
109
161
  */
110
162
  interface Appearance {
111
- theme?: string;
112
- variables?: Record<string, string>;
163
+ /** Whitelisted design variables (overall style). */
164
+ variables?: AppearanceVariables;
165
+ /** Controlled semantic rules (fine-tuning key elements); keys limited to `AppearanceRuleTarget`. */
166
+ rules?: Partial<Record<AppearanceRuleTarget, AppearanceRuleStyle>>;
167
+ /**
168
+ * Color scheme preference.
169
+ * - `'light'`: light;
170
+ * - `'dark'`: dark;
171
+ * - `'auto'`: follow the system / host environment.
172
+ *
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.
176
+ */
177
+ colorScheme?: 'light' | 'dark' | 'auto';
113
178
  }
114
179
  /**
115
- * 支付方式过滤配置(spec 9:只做减法/排序,禁止前端增开)。
180
+ * Payment method filter configuration (spec 9: subtraction/ordering only, enabling new methods on
181
+ * the frontend is forbidden).
116
182
  */
117
183
  interface PaymentMethodFilter {
118
- /** 要隐藏的支付方式(method 标识)。 */
184
+ /** Payment methods to hide (method identifiers). */
119
185
  hide?: string[];
120
- /** 展示顺序(method 标识)。 */
186
+ /** Display order (method identifiers). */
121
187
  order?: string[];
122
188
  }
123
- /** 可挂载 Element 类型(spec 6)。 */
189
+ /** Mountable Element types (spec 6). */
124
190
  type ElementType = 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address' | 'expressCheckout';
125
- /** card Element 配置(spec 6)。 */
191
+ /** card Element options (spec 6). */
126
192
  interface CardElementOptions {
127
193
  showBillingAddress?: boolean;
128
194
  showShippingAddress?: boolean;
129
195
  showPostalCode?: boolean;
130
196
  appearance?: Appearance;
131
197
  }
132
- /** 拆分卡字段配置(spec 6)。 */
198
+ /** Split card field options (spec 6). */
133
199
  interface CardFieldElementOptions {
134
200
  appearance?: Appearance;
135
201
  }
136
- /** address Element 配置(spec 6)。 */
202
+ /** address Element options (spec 6). */
137
203
  interface AddressElementOptions {
138
204
  mode: 'billing' | 'shipping';
139
205
  appearance?: Appearance;
140
206
  }
141
- /** expressCheckout Element 配置(spec 6)。 */
207
+ /** Apple Pay official button theme. Defaults to follow the current color scheme (light black / dark white). */
208
+ type ApplePayButtonTheme = 'black' | 'white' | 'white-outline';
209
+ /** Google Pay official button theme. Defaults to follow the current color scheme (light black / dark white). */
210
+ type GooglePayButtonTheme = 'black' | 'white' | 'default';
211
+ /** Apple Pay official button text type (the `type` attribute of `apple-pay-button`, full official set). */
212
+ type ApplePayButtonType = 'plain' | 'buy' | 'donate' | 'check-out' | 'book' | 'subscribe' | 'reload' | 'add-money' | 'top-up' | 'order' | 'rent' | 'support' | 'contribute' | 'tip';
213
+ /** Google Pay official button text type (`buttonType`, full official set). */
214
+ type GooglePayButtonType = 'buy' | 'plain' | 'checkout' | 'pay' | 'donate' | 'book' | 'order' | 'subscribe';
215
+ /** Apple Pay single-wallet options (fine-grained options when shown). */
216
+ interface ApplePayOptions {
217
+ /** Button theme; defaults to follow the current color scheme. */
218
+ buttonTheme?: ApplePayButtonTheme;
219
+ /** Button text type; defaults to `'pay'`. */
220
+ buttonType?: ApplePayButtonType;
221
+ }
222
+ /** Google Pay single-wallet options (fine-grained options when shown). */
223
+ interface GooglePayOptions {
224
+ /** Button theme; defaults to follow the current color scheme. */
225
+ buttonTheme?: GooglePayButtonTheme;
226
+ /** Button text type; defaults to `'pay'`. */
227
+ buttonType?: GooglePayButtonType;
228
+ }
229
+ /** expressCheckout Element options (spec 6). */
142
230
  interface ExpressCheckoutElementOptions {
143
231
  /**
144
- * 各钱包开关(商户显式控制):
145
- * - `false`:强制隐藏该钱包;
146
- * - `true` 或缺省:自动模式,按后端业务允许 ∩ 环境可用展示。
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).
147
237
  */
148
238
  paymentMethods?: {
149
- applePay?: boolean;
150
- googlePay?: boolean;
239
+ applePay?: boolean | ApplePayOptions;
240
+ googlePay?: boolean | GooglePayOptions;
151
241
  };
152
- /** 布局约束(首期仅最大列数)。 */
242
+ /** Layout constraints (first phase: maximum columns only). */
153
243
  layout?: {
154
244
  maxColumns?: number;
155
245
  };
156
- /** 按钮主题(按钱包区分)。 */
157
- buttonTheme?: {
158
- applePay?: string;
159
- googlePay?: string;
160
- };
161
- /** 按钮高度(像素)。 */
246
+ /** Wallet button height (pixels, applied globally to all wallet buttons). The hosted side clamps to [30, 64]; defaults to 40. */
162
247
  buttonHeight?: number;
163
248
  }
164
249
  /**
165
- * express 可用钱包视图(spec 6)。
166
- * 表示各钱包在当前环境下是否可用,用于 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.
167
253
  */
168
254
  interface AvailableWallets {
169
255
  applePay: boolean;
170
256
  googlePay: boolean;
171
257
  }
172
- /** Element 配置联合(按 type 区分)。 */
258
+ /** Element options union (distinguished by type). */
173
259
  type ElementOptions = CardElementOptions | CardFieldElementOptions | AddressElementOptions | ExpressCheckoutElementOptions;
174
- /** Element 运行状态机(spec 6)。 */
260
+ /** Element runtime state machine (spec 6). */
175
261
  type ElementStatus = 'created' | 'loading' | 'ready' | 'destroyed' | 'loadError';
176
- /** action 载荷(spec 8.3;qrCode/showContent 首期预留)。 */
262
+ /** action payload (spec 8.3; qrCode/showContent reserved for the first phase). */
177
263
  interface PaymentAction {
178
264
  type: 'qrCode' | 'redirect' | 'showContent';
179
265
  redirectUrl?: string;
@@ -182,33 +268,35 @@ interface PaymentAction {
182
268
  }
183
269
 
184
270
  /**
185
- * 信封与握手契约(spec 5.1,真源)。
271
+ * Envelope and handshake contract (spec 5.1, source of truth).
186
272
  *
187
- * 协议名 `sunbay-checkout`,`major = 1`。与现有 Native Bridge `{v:1,type,...}`
188
- * 是不同协议,数字相同不代表兼容。
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.
189
275
  *
190
- * `encodeEnvelope`/`decodeEnvelope`:JSON 序列化 + 最小运行时结构校验
191
- * (校验 protocol/major/kind/必填字段),非法抛错。解码器**不**校验 request.name
192
- * 是否为已知 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.
193
280
  */
194
281
 
195
- /** 协议名常量。 */
282
+ /** Protocol name constant. */
196
283
  declare const PROTOCOL_NAME: "sunbay-checkout";
197
- /** 当前主版本。 */
284
+ /** Current major version. */
198
285
  declare const PROTOCOL_MAJOR: 1;
199
286
  /**
200
- * 握手消息(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.
201
289
  */
202
290
  type RuntimeHello = {
203
291
  protocol: 'sunbay-checkout';
204
292
  kind: 'hello';
205
293
  runtimeId: string;
206
294
  supportedMajorVersions: number[];
207
- /** 首期:['card','splitCard','address','express','paymentMethodFilter']。 */
295
+ /** First phase: ['card','splitCard','address','express','paymentMethodFilter']. */
208
296
  capabilities: string[];
209
297
  };
210
298
  /**
211
- * 初始化后的公共信封(spec 5.1)。
299
+ * Public envelope after initialization (spec 5.1).
212
300
  */
213
301
  type Envelope = {
214
302
  protocol: 'sunbay-checkout';
@@ -238,28 +326,28 @@ type Envelope = {
238
326
  operationId?: string;
239
327
  payload: unknown;
240
328
  });
241
- /** 协议校验失败错误。 */
329
+ /** Protocol validation failure error. */
242
330
  declare class EnvelopeDecodeError extends Error {
243
331
  constructor(message: string);
244
332
  }
245
333
  /**
246
- * 将信封序列化为线缆字符串(JSON)。
334
+ * Serialize an envelope into a wire string (JSON).
247
335
  *
248
- * @param envelope 待发送的信封
249
- * @returns JSON 字符串
336
+ * @param envelope The envelope to send
337
+ * @returns JSON string
250
338
  * @example
251
339
  * const wire = encodeEnvelope({ protocol: 'sunbay-checkout', major: 1, ... });
252
340
  */
253
341
  declare function encodeEnvelope(envelope: Envelope): string;
254
342
  /**
255
- * 解析并最小结构校验信封。非法(缺 protocol、错 major、非法 kind、缺必填字段、
256
- * 非 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}.
257
345
  *
258
- * 注意:解码器不校验 request.name 是否为已知命令 —— 未知 name 仍解为
259
- * 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.
260
348
  *
261
- * @param wire 线缆字符串
262
- * @returns 已校验结构的信封
349
+ * @param wire The wire string
350
+ * @returns The structurally validated envelope
263
351
  * @example
264
352
  * const env = decodeEnvelope(wire);
265
353
  * if (env.kind === 'request') { ... }
@@ -267,10 +355,10 @@ declare function encodeEnvelope(envelope: Envelope): string;
267
355
  declare function decodeEnvelope(wire: string): Envelope;
268
356
 
269
357
  /**
270
- * 协议错误码常量(单一真源,spec 5.4)。
358
+ * Protocol error code constants (single source of truth, spec 5.4).
271
359
  *
272
- * 不提供可能误导重复付款的通用 `retryable` 布尔。
273
- * 仅保留实际会被产出的错误码;新增码须同时有产出点。
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.
274
362
  */
275
363
  declare const ErrorCode: {
276
364
  readonly INVALID_OPTIONS: "INVALID_OPTIONS";
@@ -285,20 +373,21 @@ declare const ErrorCode: {
285
373
  readonly PAYMENT_FLOW_ERROR: "PAYMENT_FLOW_ERROR";
286
374
  readonly UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY";
287
375
  };
288
- /** 错误码字面量联合类型。 */
376
+ /** Error code literal union type. */
289
377
  type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
290
378
 
291
379
  /**
292
- * 命令契约(商户 SDK → main,spec 5.2 表,真源)。
380
+ * Command contract (merchant SDK → main, spec 5.2 table, source of truth).
293
381
  *
294
- * 每命令的请求/响应类型在此定义;跨通道只传 JSON 可序列化数据。
382
+ * The request/response types for each command are defined here; only JSON-serializable data is sent
383
+ * across the channel.
295
384
  */
296
385
 
297
- /** 全部命令名(spec 5.2)。 */
386
+ /** All command names (spec 5.2). */
298
387
  type CommandName = 'initialize' | 'createElement' | 'updateElement' | 'destroyElement' | 'focus' | 'blur' | 'clear' | 'updateCheckout' | 'getSession' | 'refresh' | 'getPaymentStatus' | 'confirm' | 'destroy';
299
- /** 已知命令名集合(供调用方校验 request.name 是否受支持)。 */
388
+ /** Set of known command names (for callers to validate whether request.name is supported). */
300
389
  declare const COMMAND_NAMES: readonly CommandName[];
301
- /** 判断字符串是否为已知命令名。 */
390
+ /** Determine whether a string is a known command name. */
302
391
  declare function isCommandName(name: string): name is CommandName;
303
392
  interface InitializeReq {
304
393
  sessionId: string;
@@ -370,7 +459,7 @@ type DestroyReq = Record<string, never>;
370
459
  interface DestroyResp {
371
460
  released: true;
372
461
  }
373
- /** 命令名 → 请求载荷映射。 */
462
+ /** Command name → request payload mapping. */
374
463
  interface CommandRequestMap {
375
464
  initialize: InitializeReq;
376
465
  createElement: CreateElementReq;
@@ -386,7 +475,7 @@ interface CommandRequestMap {
386
475
  confirm: ConfirmReq;
387
476
  destroy: DestroyReq;
388
477
  }
389
- /** 命令名 → 成功响应载荷映射。 */
478
+ /** Command name → success response payload mapping. */
390
479
  interface CommandResponseMap {
391
480
  initialize: InitializeResp;
392
481
  createElement: CreateElementResp;
@@ -404,24 +493,25 @@ interface CommandResponseMap {
404
493
  }
405
494
 
406
495
  /**
407
- * 事件契约(main → 商户 SDK,spec 5.3 表,真源)。
496
+ * Event contract (main → merchant SDK, spec 5.3 table, source of truth).
408
497
  *
409
- * 公开事件仅暴露 empty/complete/brand/error 等允许状态,**绝不含卡值**,
410
- * 不提供卡数据 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.
411
501
  */
412
502
 
413
- /** 全部事件名(spec 5.3)。 */
414
- type EventName = 'ready' | 'change' | 'focus' | 'blur' | 'loadError' | 'elementReady' | 'availablePaymentMethodsChange' | 'expressAvailabilityChange' | 'paymentStateChange' | 'paymentResult' | 'error';
415
- /** 已知事件名集合。 */
503
+ /** All event names (spec 5.3). */
504
+ type EventName = 'ready' | 'change' | 'focus' | 'blur' | 'loadError' | 'elementReady' | 'expressAvailabilityChange' | 'paymentStateChange' | 'paymentResult' | 'error';
505
+ /** Set of known event names. */
416
506
  declare const EVENT_NAMES: readonly EventName[];
417
- /** 判断字符串是否为已知事件名。 */
507
+ /** Determine whether a string is a known event name. */
418
508
  declare function isEventName(name: string): name is EventName;
419
509
  interface ReadyEvent {
420
510
  elementId: string;
421
511
  }
422
512
  interface ElementReadyEvent {
423
513
  elementId: string;
424
- /** 仅 expressCheckout Element ready 时携带:各钱包可用性。 */
514
+ /** Only carried when the expressCheckout Element is ready: per-wallet availability. */
425
515
  availableWallets?: AvailableWallets;
426
516
  }
427
517
  interface ChangeEvent {
@@ -429,7 +519,7 @@ interface ChangeEvent {
429
519
  empty: boolean;
430
520
  complete: boolean;
431
521
  error?: CheckoutError;
432
- /** 仅卡号字段允许携带 brand;绝不含卡值。 */
522
+ /** Only the card number field may carry brand; never contains card values. */
433
523
  brand?: string;
434
524
  }
435
525
  interface FocusEvent {
@@ -442,13 +532,10 @@ interface LoadErrorEvent {
442
532
  elementId: string;
443
533
  error: CheckoutError;
444
534
  }
445
- interface AvailablePaymentMethodsChangeEvent {
446
- availablePaymentMethods: PublicPaymentMethod[];
447
- }
448
535
  /**
449
- * express 可用钱包变化事件(spec 6)。
450
- * 专用于 expressCheckout:以 AvailableWallets 表达各钱包可用性,
451
- * 与 AvailablePaymentMethodsChangeEvent(PublicPaymentMethod[])并存,互不破坏。
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).
452
539
  */
453
540
  interface ExpressAvailabilityChangeEvent {
454
541
  availableWallets: AvailableWallets;
@@ -456,7 +543,7 @@ interface ExpressAvailabilityChangeEvent {
456
543
  interface PaymentStateChangeEvent {
457
544
  operationId: string;
458
545
  method: PaymentMethod;
459
- /** 过程状态;requiresAction 时携带 action 信息。 */
546
+ /** Intermediate state; carries action info when requiresAction. */
460
547
  state: string;
461
548
  action?: PaymentAction;
462
549
  }
@@ -466,11 +553,11 @@ interface PaymentResultEvent {
466
553
  outcome: PaymentOutcome;
467
554
  }
468
555
  interface ErrorEvent {
469
- /** 异步主动流程错误;可含 operationId(如已创建)。 */
556
+ /** Error in an asynchronous proactive flow; may include operationId (if already created). */
470
557
  operationId?: string;
471
558
  error: CheckoutError;
472
559
  }
473
- /** 事件名 → 载荷映射。 */
560
+ /** Event name → payload mapping. */
474
561
  interface EventPayloadMap {
475
562
  ready: ReadyEvent;
476
563
  change: ChangeEvent;
@@ -478,11 +565,55 @@ interface EventPayloadMap {
478
565
  blur: BlurEvent;
479
566
  loadError: LoadErrorEvent;
480
567
  elementReady: ElementReadyEvent;
481
- availablePaymentMethodsChange: AvailablePaymentMethodsChangeEvent;
482
568
  expressAvailabilityChange: ExpressAvailabilityChangeEvent;
483
569
  paymentStateChange: PaymentStateChangeEvent;
484
570
  paymentResult: PaymentResultEvent;
485
571
  error: ErrorEvent;
486
572
  }
487
573
 
488
- export { type AddressElementOptions, type AddressInfo, type Appearance, type AvailablePaymentMethodsChangeEvent, type AvailableWallets, type BlurEvent, COMMAND_NAMES, type CardElementOptions, type CardFieldElementOptions, type ChangeEvent, type CheckoutError, type CheckoutErrorCategory, type CommandName, type CommandRequestMap, type CommandResponseMap, type ConfirmReq, type ConfirmResp, type CreateElementReq, type CreateElementResp, type DestroyElementReq, type DestroyElementResp, type DestroyReq, type DestroyResp, EVENT_NAMES, type ElementActionReq, type ElementActionResp, type ElementOptions, type ElementReadyEvent, type ElementStatus, type ElementType, type Envelope, EnvelopeDecodeError, ErrorCode, type ErrorCodeValue, type ErrorEvent, type EventName, type EventPayloadMap, type ExpressAvailabilityChangeEvent, type ExpressCheckoutElementOptions, type FocusEvent, type GetPaymentStatusReq, type GetPaymentStatusResp, type GetSessionReq, type GetSessionResp, type InitializeReq, type InitializeResp, type LoadErrorEvent, PROTOCOL_MAJOR, PROTOCOL_NAME, type PaymentAction, type PaymentMethod, type PaymentMethodFilter, type PaymentOutcome, type PaymentResultEvent, type PaymentStateChangeEvent, type PublicPaymentMethod, type PublicProductLine, type PublicSessionView, type ReadyEvent, type RuntimeHello, type TxnStatus, type UpdateCheckoutReq, type UpdateCheckoutResp, type UpdateElementReq, type UpdateElementResp, decodeEnvelope, encodeEnvelope, isCommandName, isEventName };
574
+ /**
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.
577
+ *
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%).
582
+ *
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.
587
+ */
588
+ /** Discriminant literal for the iframe auto-height message (namespaced to avoid colliding with other postMessages). */
589
+ declare const IFRAME_RESIZE_MESSAGE_TYPE: "sunbay:checkout:iframe-resize";
590
+ /**
591
+ * Content height change notification from the iframe (child) → parent window (SDK).
592
+ *
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.
595
+ */
596
+ interface IframeResizeMessage {
597
+ /** Discriminant field, fixed to {@link IFRAME_RESIZE_MESSAGE_TYPE}. */
598
+ type: typeof IFRAME_RESIZE_MESSAGE_TYPE;
599
+ /**
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.
603
+ */
604
+ elementId: string;
605
+ /** Content height (CSS px, already `Math.ceil`-ed; finite and non-negative). */
606
+ height: number;
607
+ }
608
+ /**
609
+ * Whether the value is a valid {@link IframeResizeMessage}.
610
+ *
611
+ * Validates: non-null object + type literal match + elementId is a non-empty string + height is a
612
+ * finite non-negative number.
613
+ *
614
+ * @param data - Data from any source (typically `MessageEvent.data`).
615
+ * @returns Whether data is a valid iframe-resize message.
616
+ */
617
+ declare function isIframeResizeMessage(data: unknown): data is IframeResizeMessage;
618
+
619
+ export { type AddressElementOptions, type AddressInfo, type Appearance, type AppearanceRuleStyle, type AppearanceRuleTarget, type AppearanceVariables, type ApplePayButtonTheme, type ApplePayButtonType, type ApplePayOptions, type AvailableWallets, type BlurEvent, COMMAND_NAMES, type CardElementOptions, type CardFieldElementOptions, type ChangeEvent, type CheckoutError, type CheckoutErrorCategory, type CommandName, type CommandRequestMap, type CommandResponseMap, type ConfirmReq, type ConfirmResp, type CreateElementReq, type CreateElementResp, type DestroyElementReq, type DestroyElementResp, type DestroyReq, type DestroyResp, EVENT_NAMES, type ElementActionReq, type ElementActionResp, type ElementOptions, type ElementReadyEvent, type ElementStatus, type ElementType, type Envelope, EnvelopeDecodeError, ErrorCode, type ErrorCodeValue, type ErrorEvent, type EventName, type EventPayloadMap, type ExpressAvailabilityChangeEvent, type ExpressCheckoutElementOptions, type FocusEvent, type GetPaymentStatusReq, type GetPaymentStatusResp, type GetSessionReq, type GetSessionResp, type GooglePayButtonTheme, type GooglePayButtonType, type GooglePayOptions, IFRAME_RESIZE_MESSAGE_TYPE, type IframeResizeMessage, type InitializeReq, type InitializeResp, type LoadErrorEvent, PROTOCOL_MAJOR, PROTOCOL_NAME, type PaymentAction, type PaymentMethod, type PaymentMethodFilter, type PaymentOutcome, type PaymentResultEvent, type PaymentStateChangeEvent, type PublicPaymentMethod, type PublicProductLine, type PublicSessionView, type ReadyEvent, type RuntimeHello, type TxnStatus, type UpdateCheckoutReq, type UpdateCheckoutResp, type UpdateElementReq, type UpdateElementResp, decodeEnvelope, encodeEnvelope, isCommandName, isEventName, isIframeResizeMessage };