@sunbay/checkout-sdk-protocol 0.0.0-stage → 0.0.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.
@@ -0,0 +1,598 @@
1
+ /**
2
+ * 协议公开类型(真源)。
3
+ *
4
+ * 这些类型对外公开,供商户侧 SDK(transport/CheckoutInstance/Element)与
5
+ * checkout 托管侧同步副本共同引用。字段与 checkout 后端现有类型对齐,但
6
+ * 对外视图(PublicSessionView)**不含** rsaPublicKey 等敏感/内部字段。
7
+ */
8
+ /**
9
+ * 交易状态(直接复用 checkout 后端 TxnStatus,不转义)。
10
+ * - `I` = 未支付 / 已创建(非终态)
11
+ * - `S` = 成功(终态)
12
+ * - `F` = 失败(终态)
13
+ * - `R` = 需跳转 / 处理中(非终态)
14
+ */
15
+ type TxnStatus = 'I' | 'S' | 'F' | 'R';
16
+ /**
17
+ * 地址信息(对齐 checkout 后端 AddressInfo 字段)。
18
+ * 非敏感数据,允许经公共协议传输。
19
+ */
20
+ interface AddressInfo {
21
+ country: string;
22
+ state?: string;
23
+ city: string;
24
+ line1: string;
25
+ line2?: string;
26
+ postalCode: string;
27
+ district?: string;
28
+ firstName?: string;
29
+ lastName?: string;
30
+ recipientName?: string;
31
+ phone?: string;
32
+ }
33
+ /** 首期支持的支付方式。 */
34
+ type PaymentMethod = 'card' | 'applePay' | 'googlePay';
35
+ /**
36
+ * 公开支付方式视图(对外只暴露 method/type/name/logoUrl,不含内部配置)。
37
+ */
38
+ interface PublicPaymentMethod {
39
+ method: string;
40
+ type: string;
41
+ name: string;
42
+ logoUrl: string;
43
+ }
44
+ /** 公开商品行。 */
45
+ interface PublicProductLine {
46
+ amount: number;
47
+ name: string;
48
+ num: string;
49
+ }
50
+ /**
51
+ * 公开 Session 视图:金额 / 币种 / 商品 / collect 标记 / 可用支付方式 / 商户信息。
52
+ * **不含** rsaPublicKey 等敏感或内部字段。
53
+ */
54
+ interface PublicSessionView {
55
+ sessionId: string;
56
+ sessionType: string;
57
+ currency: string;
58
+ totalAmount: number;
59
+ productList: PublicProductLine[];
60
+ taxAmount: number;
61
+ productAmount: number;
62
+ description: string;
63
+ expiresAt: string;
64
+ collectBillingAddress: boolean;
65
+ collectShippingAddress: boolean;
66
+ paymentMethods: PublicPaymentMethod[];
67
+ merchantName: string;
68
+ merchantLogoUrl: string;
69
+ merchantReturnUrl?: string;
70
+ }
71
+ /**
72
+ * 支付结果四态(spec 8.2)。
73
+ * `pending` 非终态,消费者不得只接受首条结果。
74
+ */
75
+ type PaymentOutcome = {
76
+ status: 'succeeded';
77
+ operationId: string;
78
+ txnId: string;
79
+ } | {
80
+ status: 'failed';
81
+ operationId: string;
82
+ txnId?: string;
83
+ error: CheckoutError;
84
+ } | {
85
+ status: 'canceled';
86
+ operationId: string;
87
+ } | {
88
+ status: 'pending';
89
+ operationId: string;
90
+ txnId?: string;
91
+ };
92
+ /** 错误分类(spec 5.4)。 */
93
+ type CheckoutErrorCategory = 'configuration' | 'validation' | 'network' | 'runtime' | 'payment';
94
+ /**
95
+ * 结构化错误(spec 5.4)。
96
+ */
97
+ interface CheckoutError {
98
+ code: string;
99
+ /** 展示用消息。 */
100
+ message: string;
101
+ category: CheckoutErrorCategory;
102
+ errorId: string;
103
+ elementId?: string;
104
+ field?: string;
105
+ traceId?: string;
106
+ }
107
+ /**
108
+ * 白名单设计变量(映射到 hosted 侧 `ThemeConfig`,复用现有 `generateThemeStyles` 与深色推导)。
109
+ *
110
+ * 全部可选;值为颜色或长度字符串,由 hosted 侧白名单校验器校验后方可进入 `<style>`。
111
+ * 属性名使用 camelCase(如 `borderRadius`),hosted 侧转 kebab。
112
+ */
113
+ interface AppearanceVariables {
114
+ /** 主色 → `ThemeConfig.primary`(并联动 ring)。 */
115
+ colorPrimary?: string;
116
+ /** 背景色 → background / card / popover。 */
117
+ colorBackground?: string;
118
+ /** 文字色 → foreground。 */
119
+ colorText?: string;
120
+ /** 边框色 → border / input。 */
121
+ colorBorder?: string;
122
+ /** 危险色 → destructive。 */
123
+ colorDanger?: string;
124
+ /** 圆角 → radius(长度值)。 */
125
+ borderRadius?: string;
126
+ /** 字体族 → `:root` font-family(不进 `ThemeConfig`,单独注入)。 */
127
+ fontFamily?: string;
128
+ }
129
+ /**
130
+ * rules 可定制的元素锚点(语义 key,对应 hosted 侧 `data-sunbay-el`)。
131
+ *
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 图标。
140
+ */
141
+ type AppearanceRuleTarget = 'input' | 'input:focus' | 'input:invalid' | 'label' | 'error' | 'cardBrand' | 'cvvIcon';
142
+ /**
143
+ * 单条 rule:白名单 CSS 属性(camelCase 或 kebab)到值的映射。
144
+ *
145
+ * 属性名与值均由 hosted 侧白名单校验后方可进入 `<style>`;非白名单属性 / 非法值被丢弃。
146
+ */
147
+ type AppearanceRuleStyle = Record<string, string>;
148
+ /**
149
+ * 外观定制(appearance)。受控两层:`variables`(整体风格的白名单设计变量)+
150
+ * `rules`(关键元素精调的受控语义选择器)。因 iframe 跨域 + PCI 合规,**不开放任意 CSS**。
151
+ *
152
+ * 所有进入 `<style>` 的文本全程由 hosted 侧白名单校验;appearance 不含任何卡值 / 支付参数。
153
+ */
154
+ interface Appearance {
155
+ /** 白名单设计变量(整体风格)。 */
156
+ variables?: AppearanceVariables;
157
+ /** 受控语义规则(关键元素精调);key 限 `AppearanceRuleTarget`。 */
158
+ rules?: Partial<Record<AppearanceRuleTarget, AppearanceRuleStyle>>;
159
+ /**
160
+ * 配色方案偏好。
161
+ * - `'light'`:浅色;
162
+ * - `'dark'`:深色;
163
+ * - `'auto'`:跟随系统 / 宿主环境。
164
+ *
165
+ * 协议层只定义类型;缺省时的默认语义(SDK 默认 `'light'`)由消费方实现,
166
+ * 协议不强制默认值。向后兼容的可选新增字段。
167
+ */
168
+ colorScheme?: 'light' | 'dark' | 'auto';
169
+ }
170
+ /**
171
+ * 支付方式过滤配置(spec 9:只做减法/排序,禁止前端增开)。
172
+ */
173
+ interface PaymentMethodFilter {
174
+ /** 要隐藏的支付方式(method 标识)。 */
175
+ hide?: string[];
176
+ /** 展示顺序(method 标识)。 */
177
+ order?: string[];
178
+ }
179
+ /** 可挂载 Element 类型(spec 6)。 */
180
+ type ElementType = 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address' | 'expressCheckout';
181
+ /** card Element 配置(spec 6)。 */
182
+ interface CardElementOptions {
183
+ showBillingAddress?: boolean;
184
+ showShippingAddress?: boolean;
185
+ showPostalCode?: boolean;
186
+ appearance?: Appearance;
187
+ }
188
+ /** 拆分卡字段配置(spec 6)。 */
189
+ interface CardFieldElementOptions {
190
+ appearance?: Appearance;
191
+ }
192
+ /** address Element 配置(spec 6)。 */
193
+ interface AddressElementOptions {
194
+ mode: 'billing' | 'shipping';
195
+ appearance?: Appearance;
196
+ }
197
+ /** Apple Pay 官方按钮主题。缺省跟随当前配色(浅 black / 深 white)。 */
198
+ type ApplePayButtonTheme = 'black' | 'white' | 'white-outline';
199
+ /** Google Pay 官方按钮主题。缺省跟随当前配色(浅 black / 深 white)。 */
200
+ type GooglePayButtonTheme = 'black' | 'white' | 'default';
201
+ /** Apple Pay 官方按钮文案类型(`apple-pay-button` 的 `type` 属性,官方全集)。 */
202
+ type ApplePayButtonType = 'plain' | 'buy' | 'donate' | 'check-out' | 'book' | 'subscribe' | 'reload' | 'add-money' | 'top-up' | 'order' | 'rent' | 'support' | 'contribute' | 'tip';
203
+ /** Google Pay 官方按钮文案类型(`buttonType`,官方全集)。 */
204
+ type GooglePayButtonType = 'buy' | 'plain' | 'checkout' | 'pay' | 'donate' | 'book' | 'order' | 'subscribe';
205
+ /** Apple Pay 单钱包配置(显示时的细粒度选项)。 */
206
+ interface ApplePayOptions {
207
+ /** 按钮主题;缺省跟随当前配色。 */
208
+ buttonTheme?: ApplePayButtonTheme;
209
+ /** 按钮文案类型;缺省 `'pay'`。 */
210
+ buttonType?: ApplePayButtonType;
211
+ }
212
+ /** Google Pay 单钱包配置(显示时的细粒度选项)。 */
213
+ interface GooglePayOptions {
214
+ /** 按钮主题;缺省跟随当前配色。 */
215
+ buttonTheme?: GooglePayButtonTheme;
216
+ /** 按钮文案类型;缺省 `'pay'`。 */
217
+ buttonType?: GooglePayButtonType;
218
+ }
219
+ /** expressCheckout Element 配置(spec 6)。 */
220
+ interface ExpressCheckoutElementOptions {
221
+ /**
222
+ * 各钱包开关 / 配置:
223
+ * - `false`:强制隐藏该钱包;
224
+ * - `true` 或缺省:自动显示(后端业务允许 ∩ 环境可用),主题跟随当前配色;
225
+ * - 配置对象:自动显示,并应用对象内的细粒度配置(如 buttonTheme)。
226
+ */
227
+ paymentMethods?: {
228
+ applePay?: boolean | ApplePayOptions;
229
+ googlePay?: boolean | GooglePayOptions;
230
+ };
231
+ /** 布局约束(首期仅最大列数)。 */
232
+ layout?: {
233
+ maxColumns?: number;
234
+ };
235
+ /** 钱包按钮高度(像素,全局应用到所有钱包按钮)。hosted 侧 clamp 到 [30, 64];缺省 40。 */
236
+ buttonHeight?: number;
237
+ }
238
+ /**
239
+ * express 可用钱包视图(spec 6)。
240
+ * 表示各钱包在当前环境下是否可用,用于 express 可用性事件载荷。
241
+ */
242
+ interface AvailableWallets {
243
+ applePay: boolean;
244
+ googlePay: boolean;
245
+ }
246
+ /** Element 配置联合(按 type 区分)。 */
247
+ type ElementOptions = CardElementOptions | CardFieldElementOptions | AddressElementOptions | ExpressCheckoutElementOptions;
248
+ /** Element 运行状态机(spec 6)。 */
249
+ type ElementStatus = 'created' | 'loading' | 'ready' | 'destroyed' | 'loadError';
250
+ /** action 载荷(spec 8.3;qrCode/showContent 首期预留)。 */
251
+ interface PaymentAction {
252
+ type: 'qrCode' | 'redirect' | 'showContent';
253
+ redirectUrl?: string;
254
+ qrData?: string;
255
+ content?: string;
256
+ }
257
+
258
+ /**
259
+ * 信封与握手契约(spec 5.1,真源)。
260
+ *
261
+ * 协议名 `sunbay-checkout`,`major = 1`。与现有 Native Bridge `{v:1,type,...}`
262
+ * 是不同协议,数字相同不代表兼容。
263
+ *
264
+ * `encodeEnvelope`/`decodeEnvelope`:JSON 序列化 + 最小运行时结构校验
265
+ * (校验 protocol/major/kind/必填字段),非法抛错。解码器**不**校验 request.name
266
+ * 是否为已知 CommandName —— 未知 name 仍解为 kind==='request',由调用方拒绝。
267
+ */
268
+
269
+ /** 协议名常量。 */
270
+ declare const PROTOCOL_NAME: "sunbay-checkout";
271
+ /** 当前主版本。 */
272
+ declare const PROTOCOL_MAJOR: 1;
273
+ /**
274
+ * 握手消息(spec 5.1)。main iframe 加载后先广播,此时尚无 checkoutId。
275
+ */
276
+ type RuntimeHello = {
277
+ protocol: 'sunbay-checkout';
278
+ kind: 'hello';
279
+ runtimeId: string;
280
+ supportedMajorVersions: number[];
281
+ /** 首期:['card','splitCard','address','express','paymentMethodFilter']。 */
282
+ capabilities: string[];
283
+ };
284
+ /**
285
+ * 初始化后的公共信封(spec 5.1)。
286
+ */
287
+ type Envelope = {
288
+ protocol: 'sunbay-checkout';
289
+ major: 1;
290
+ runtimeId: string;
291
+ checkoutId: string;
292
+ elementId?: string;
293
+ } & ({
294
+ kind: 'request';
295
+ requestId: string;
296
+ name: string;
297
+ payload: unknown;
298
+ } | {
299
+ kind: 'response';
300
+ requestId: string;
301
+ ok: true;
302
+ data: unknown;
303
+ } | {
304
+ kind: 'response';
305
+ requestId: string;
306
+ ok: false;
307
+ error: CheckoutError;
308
+ } | {
309
+ kind: 'event';
310
+ eventId: string;
311
+ name: string;
312
+ operationId?: string;
313
+ payload: unknown;
314
+ });
315
+ /** 协议校验失败错误。 */
316
+ declare class EnvelopeDecodeError extends Error {
317
+ constructor(message: string);
318
+ }
319
+ /**
320
+ * 将信封序列化为线缆字符串(JSON)。
321
+ *
322
+ * @param envelope 待发送的信封
323
+ * @returns JSON 字符串
324
+ * @example
325
+ * const wire = encodeEnvelope({ protocol: 'sunbay-checkout', major: 1, ... });
326
+ */
327
+ declare function encodeEnvelope(envelope: Envelope): string;
328
+ /**
329
+ * 解析并最小结构校验信封。非法(缺 protocol、错 major、非法 kind、缺必填字段、
330
+ * 非 JSON)一律抛 {@link EnvelopeDecodeError}。
331
+ *
332
+ * 注意:解码器不校验 request.name 是否为已知命令 —— 未知 name 仍解为
333
+ * kind==='request',交由调用方(如 Orchestrator)拒绝。
334
+ *
335
+ * @param wire 线缆字符串
336
+ * @returns 已校验结构的信封
337
+ * @example
338
+ * const env = decodeEnvelope(wire);
339
+ * if (env.kind === 'request') { ... }
340
+ */
341
+ declare function decodeEnvelope(wire: string): Envelope;
342
+
343
+ /**
344
+ * 协议错误码常量(单一真源,spec 5.4)。
345
+ *
346
+ * 不提供可能误导重复付款的通用 `retryable` 布尔。
347
+ * 仅保留实际会被产出的错误码;新增码须同时有产出点。
348
+ */
349
+ declare const ErrorCode: {
350
+ readonly INVALID_OPTIONS: "INVALID_OPTIONS";
351
+ readonly ELEMENT_CONFLICT: "ELEMENT_CONFLICT";
352
+ readonly INSTANCE_DESTROYED: "INSTANCE_DESTROYED";
353
+ readonly CHECKOUT_BUSY: "CHECKOUT_BUSY";
354
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
355
+ readonly SESSION_LOAD_FAILED: "SESSION_LOAD_FAILED";
356
+ readonly RUNTIME_LOAD_FAILED: "RUNTIME_LOAD_FAILED";
357
+ readonly PROTOCOL_UNSUPPORTED: "PROTOCOL_UNSUPPORTED";
358
+ readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
359
+ readonly PAYMENT_FLOW_ERROR: "PAYMENT_FLOW_ERROR";
360
+ readonly UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY";
361
+ };
362
+ /** 错误码字面量联合类型。 */
363
+ type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
364
+
365
+ /**
366
+ * 命令契约(商户 SDK → main,spec 5.2 表,真源)。
367
+ *
368
+ * 每命令的请求/响应类型在此定义;跨通道只传 JSON 可序列化数据。
369
+ */
370
+
371
+ /** 全部命令名(spec 5.2)。 */
372
+ type CommandName = 'initialize' | 'createElement' | 'updateElement' | 'destroyElement' | 'focus' | 'blur' | 'clear' | 'updateCheckout' | 'getSession' | 'refresh' | 'getPaymentStatus' | 'confirm' | 'destroy';
373
+ /** 已知命令名集合(供调用方校验 request.name 是否受支持)。 */
374
+ declare const COMMAND_NAMES: readonly CommandName[];
375
+ /** 判断字符串是否为已知命令名。 */
376
+ declare function isCommandName(name: string): name is CommandName;
377
+ interface InitializeReq {
378
+ sessionId: string;
379
+ locale?: string;
380
+ appearance?: Appearance;
381
+ paymentMethods?: PaymentMethodFilter;
382
+ }
383
+ interface InitializeResp {
384
+ capabilities: string[];
385
+ session: PublicSessionView;
386
+ }
387
+ interface CreateElementReq {
388
+ elementId: string;
389
+ type: ElementType;
390
+ options?: ElementOptions;
391
+ }
392
+ interface CreateElementResp {
393
+ elementId: string;
394
+ registered: true;
395
+ }
396
+ interface UpdateElementReq {
397
+ elementId: string;
398
+ patch: Partial<ElementOptions>;
399
+ }
400
+ interface UpdateElementResp {
401
+ elementId: string;
402
+ options: ElementOptions;
403
+ }
404
+ interface DestroyElementReq {
405
+ elementId: string;
406
+ }
407
+ interface DestroyElementResp {
408
+ elementId: string;
409
+ released: true;
410
+ }
411
+ interface ElementActionReq {
412
+ elementId: string;
413
+ }
414
+ interface ElementActionResp {
415
+ elementId: string;
416
+ done: true;
417
+ }
418
+ interface UpdateCheckoutReq {
419
+ locale?: string;
420
+ appearance?: Appearance;
421
+ }
422
+ interface UpdateCheckoutResp {
423
+ updated: true;
424
+ }
425
+ type GetSessionReq = Record<string, never>;
426
+ type GetSessionResp = PublicSessionView;
427
+ type GetPaymentStatusReq = Record<string, never>;
428
+ interface GetPaymentStatusResp {
429
+ txnStatus: TxnStatus;
430
+ txnId?: string;
431
+ }
432
+ interface ConfirmReq {
433
+ operationId: string;
434
+ billingAddress?: AddressInfo;
435
+ shippingAddress?: AddressInfo;
436
+ customerName?: string;
437
+ email?: string;
438
+ returnUrl?: string;
439
+ }
440
+ interface ConfirmResp {
441
+ accepted: true;
442
+ }
443
+ type DestroyReq = Record<string, never>;
444
+ interface DestroyResp {
445
+ released: true;
446
+ }
447
+ /** 命令名 → 请求载荷映射。 */
448
+ interface CommandRequestMap {
449
+ initialize: InitializeReq;
450
+ createElement: CreateElementReq;
451
+ updateElement: UpdateElementReq;
452
+ destroyElement: DestroyElementReq;
453
+ focus: ElementActionReq;
454
+ blur: ElementActionReq;
455
+ clear: ElementActionReq;
456
+ updateCheckout: UpdateCheckoutReq;
457
+ getSession: GetSessionReq;
458
+ refresh: GetSessionReq;
459
+ getPaymentStatus: GetPaymentStatusReq;
460
+ confirm: ConfirmReq;
461
+ destroy: DestroyReq;
462
+ }
463
+ /** 命令名 → 成功响应载荷映射。 */
464
+ interface CommandResponseMap {
465
+ initialize: InitializeResp;
466
+ createElement: CreateElementResp;
467
+ updateElement: UpdateElementResp;
468
+ destroyElement: DestroyElementResp;
469
+ focus: ElementActionResp;
470
+ blur: ElementActionResp;
471
+ clear: ElementActionResp;
472
+ updateCheckout: UpdateCheckoutResp;
473
+ getSession: GetSessionResp;
474
+ refresh: GetSessionResp;
475
+ getPaymentStatus: GetPaymentStatusResp;
476
+ confirm: ConfirmResp;
477
+ destroy: DestroyResp;
478
+ }
479
+
480
+ /**
481
+ * 事件契约(main → 商户 SDK,spec 5.3 表,真源)。
482
+ *
483
+ * 公开事件仅暴露 empty/complete/brand/error 等允许状态,**绝不含卡值**,
484
+ * 不提供卡数据 getValue。`on` 注册后不重放历史事件。
485
+ */
486
+
487
+ /** 全部事件名(spec 5.3)。 */
488
+ type EventName = 'ready' | 'change' | 'focus' | 'blur' | 'loadError' | 'elementReady' | 'expressAvailabilityChange' | 'paymentStateChange' | 'paymentResult' | 'error';
489
+ /** 已知事件名集合。 */
490
+ declare const EVENT_NAMES: readonly EventName[];
491
+ /** 判断字符串是否为已知事件名。 */
492
+ declare function isEventName(name: string): name is EventName;
493
+ interface ReadyEvent {
494
+ elementId: string;
495
+ }
496
+ interface ElementReadyEvent {
497
+ elementId: string;
498
+ /** 仅 expressCheckout Element ready 时携带:各钱包可用性。 */
499
+ availableWallets?: AvailableWallets;
500
+ }
501
+ interface ChangeEvent {
502
+ elementId: string;
503
+ empty: boolean;
504
+ complete: boolean;
505
+ error?: CheckoutError;
506
+ /** 仅卡号字段允许携带 brand;绝不含卡值。 */
507
+ brand?: string;
508
+ }
509
+ interface FocusEvent {
510
+ elementId: string;
511
+ }
512
+ interface BlurEvent {
513
+ elementId: string;
514
+ }
515
+ interface LoadErrorEvent {
516
+ elementId: string;
517
+ error: CheckoutError;
518
+ }
519
+ /**
520
+ * express 可用钱包变化事件(spec 6)。
521
+ * 专用于 expressCheckout:以 AvailableWallets 表达各钱包(Apple/Google Pay)可用性。
522
+ */
523
+ interface ExpressAvailabilityChangeEvent {
524
+ availableWallets: AvailableWallets;
525
+ }
526
+ interface PaymentStateChangeEvent {
527
+ operationId: string;
528
+ method: PaymentMethod;
529
+ /** 过程状态;requiresAction 时携带 action 信息。 */
530
+ state: string;
531
+ action?: PaymentAction;
532
+ }
533
+ interface PaymentResultEvent {
534
+ operationId: string;
535
+ method: PaymentMethod;
536
+ outcome: PaymentOutcome;
537
+ }
538
+ interface ErrorEvent {
539
+ /** 异步主动流程错误;可含 operationId(如已创建)。 */
540
+ operationId?: string;
541
+ error: CheckoutError;
542
+ }
543
+ /** 事件名 → 载荷映射。 */
544
+ interface EventPayloadMap {
545
+ ready: ReadyEvent;
546
+ change: ChangeEvent;
547
+ focus: FocusEvent;
548
+ blur: BlurEvent;
549
+ loadError: LoadErrorEvent;
550
+ elementReady: ElementReadyEvent;
551
+ expressAvailabilityChange: ExpressAvailabilityChangeEvent;
552
+ paymentStateChange: PaymentStateChangeEvent;
553
+ paymentResult: PaymentResultEvent;
554
+ error: ErrorEvent;
555
+ }
556
+
557
+ /**
558
+ * iframe 布局协议:托管 iframe(checkout,child)→ 父窗口(商户 SDK,parent)的
559
+ * **直连 postMessage** 契约,用于 iframe 自适应高度。
560
+ *
561
+ * 与外层 Envelope(商户 SDK ↔ main iframe)及内层点对点 port(element ↔ main)均区分:
562
+ * 本消息由每个可见 field / element iframe 直接 postMessage 到其 `window.parent`(商户页),
563
+ * 商户 SDK 的 Element 句柄监听后把外层 iframe 高度调整为内容真实高度(宽度保持 100%)。
564
+ *
565
+ * 安全约束(AGENTS/spec):本消息**绝不含任何卡值**(明文或密文),仅携带 height 与
566
+ * elementId。父窗口侧须校验来源(`event.source === iframe.contentWindow` 且
567
+ * `event.origin === hostOrigin`)后方可采信,防止跨源伪造。
568
+ */
569
+ /** iframe 自适应高度消息的判别字面量(命名空间化,避免与其它 postMessage 碰撞)。 */
570
+ declare const IFRAME_RESIZE_MESSAGE_TYPE: "sunbay:checkout:iframe-resize";
571
+ /**
572
+ * iframe(child)→ 父窗口(SDK)的内容高度变更通知。
573
+ *
574
+ * child 用 `ResizeObserver` 观测内容高度,变化时发送(去重);parent 据此设
575
+ * `iframe.style.height`。绝不含卡值。
576
+ */
577
+ interface IframeResizeMessage {
578
+ /** 判别字段,固定为 {@link IFRAME_RESIZE_MESSAGE_TYPE}。 */
579
+ type: typeof IFRAME_RESIZE_MESSAGE_TYPE;
580
+ /**
581
+ * 目标 Element 的唯一 id。由商户 SDK 经 iframe src 的 `&elementId=` 下发,child 原样
582
+ * 回传,供父窗口在同一页面多个 iframe 间按句柄分发。
583
+ */
584
+ elementId: string;
585
+ /** 内容高度(CSS px,已 `Math.ceil`;有限且非负)。 */
586
+ height: number;
587
+ }
588
+ /**
589
+ * 是否为合法的 {@link IframeResizeMessage}。
590
+ *
591
+ * 校验:非空对象 + type 字面量匹配 + elementId 为非空字符串 + height 为有限非负数。
592
+ *
593
+ * @param data - 任意来源数据(通常是 `MessageEvent.data`)。
594
+ * @returns data 是否为合法的 iframe-resize 消息。
595
+ */
596
+ declare function isIframeResizeMessage(data: unknown): data is IframeResizeMessage;
597
+
598
+ 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 };