@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/README.md +43 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +168 -147
- package/dist/index.d.ts +168 -147
- package/dist/index.mjs.map +1 -1
- package/package.json +28 -28
package/dist/index.d.cts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Public protocol types (source of truth).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* checkout
|
|
6
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
52
|
-
*
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
93
|
+
/** Error categories (spec 5.4). */
|
|
93
94
|
type CheckoutErrorCategory = 'configuration' | 'validation' | 'network' | 'runtime' | 'payment';
|
|
94
95
|
/**
|
|
95
|
-
*
|
|
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
|
-
*
|
|
109
|
+
* Whitelisted design variables (mapped to the hosted-side `ThemeConfig`, reusing the existing
|
|
110
|
+
* `generateThemeStyles` and dark-mode derivation).
|
|
109
111
|
*
|
|
110
|
-
*
|
|
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.
|
|
112
115
|
*/
|
|
113
116
|
interface AppearanceVariables {
|
|
114
|
-
/**
|
|
117
|
+
/** Primary color → `ThemeConfig.primary` (also drives ring). */
|
|
115
118
|
colorPrimary?: string;
|
|
116
|
-
/**
|
|
119
|
+
/** Background color → background / card / popover. */
|
|
117
120
|
colorBackground?: string;
|
|
118
|
-
/**
|
|
121
|
+
/** Text color → foreground. */
|
|
119
122
|
colorText?: string;
|
|
120
|
-
/**
|
|
123
|
+
/** Border color → border / input. */
|
|
121
124
|
colorBorder?: string;
|
|
122
|
-
/**
|
|
125
|
+
/** Danger color → destructive. */
|
|
123
126
|
colorDanger?: string;
|
|
124
|
-
/**
|
|
127
|
+
/** Border radius → radius (length value). */
|
|
125
128
|
borderRadius?: string;
|
|
126
|
-
/**
|
|
129
|
+
/** Font family → `:root` font-family (not part of `ThemeConfig`, injected separately). */
|
|
127
130
|
fontFamily?: string;
|
|
128
131
|
}
|
|
129
132
|
/**
|
|
130
|
-
* rules
|
|
133
|
+
* Customizable element anchors for rules (semantic keys, corresponding to the hosted-side
|
|
134
|
+
* `data-sunbay-el`).
|
|
131
135
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* - `'input
|
|
135
|
-
* - `'input:
|
|
136
|
-
* - `'
|
|
137
|
-
* - `'
|
|
138
|
-
* - `'
|
|
139
|
-
* - `'
|
|
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
|
-
*
|
|
148
|
+
* A single rule: a mapping from whitelisted CSS properties (camelCase or kebab) to values.
|
|
144
149
|
*
|
|
145
|
-
*
|
|
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
|
-
*
|
|
150
|
-
* `rules
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
184
|
+
/** Payment methods to hide (method identifiers). */
|
|
175
185
|
hide?: string[];
|
|
176
|
-
/**
|
|
186
|
+
/** Display order (method identifiers). */
|
|
177
187
|
order?: string[];
|
|
178
188
|
}
|
|
179
|
-
/**
|
|
189
|
+
/** Mountable Element types (spec 6). */
|
|
180
190
|
type ElementType = 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address' | 'expressCheckout';
|
|
181
|
-
/** card Element
|
|
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
|
-
/**
|
|
198
|
+
/** Split card field options (spec 6). */
|
|
189
199
|
interface CardFieldElementOptions {
|
|
190
200
|
appearance?: Appearance;
|
|
191
201
|
}
|
|
192
|
-
/** address Element
|
|
202
|
+
/** address Element options (spec 6). */
|
|
193
203
|
interface AddressElementOptions {
|
|
194
204
|
mode: 'billing' | 'shipping';
|
|
195
205
|
appearance?: Appearance;
|
|
196
206
|
}
|
|
197
|
-
/** Apple Pay
|
|
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
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
226
|
+
/** Button text type; defaults to `'pay'`. */
|
|
217
227
|
buttonType?: GooglePayButtonType;
|
|
218
228
|
}
|
|
219
|
-
/** expressCheckout Element
|
|
229
|
+
/** expressCheckout Element options (spec 6). */
|
|
220
230
|
interface ExpressCheckoutElementOptions {
|
|
221
231
|
/**
|
|
222
|
-
*
|
|
223
|
-
* - `false
|
|
224
|
-
* - `true`
|
|
225
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
240
|
-
*
|
|
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
|
|
258
|
+
/** Element options union (distinguished by type). */
|
|
247
259
|
type ElementOptions = CardElementOptions | CardFieldElementOptions | AddressElementOptions | ExpressCheckoutElementOptions;
|
|
248
|
-
/** Element
|
|
260
|
+
/** Element runtime state machine (spec 6). */
|
|
249
261
|
type ElementStatus = 'created' | 'loading' | 'ready' | 'destroyed' | 'loadError';
|
|
250
|
-
/** action
|
|
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
|
-
*
|
|
271
|
+
* Envelope and handshake contract (spec 5.1, source of truth).
|
|
260
272
|
*
|
|
261
|
-
*
|
|
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
|
|
265
|
-
*
|
|
266
|
-
*
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
295
|
+
/** First phase: ['card','splitCard','address','express','paymentMethodFilter']. */
|
|
282
296
|
capabilities: string[];
|
|
283
297
|
};
|
|
284
298
|
/**
|
|
285
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
330
|
-
*
|
|
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
|
-
*
|
|
333
|
-
* kind==='request'
|
|
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
|
-
*
|
|
358
|
+
* Protocol error code constants (single source of truth, spec 5.4).
|
|
345
359
|
*
|
|
346
|
-
*
|
|
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
|
-
*
|
|
380
|
+
* Command contract (merchant SDK → main, spec 5.2 table, source of truth).
|
|
367
381
|
*
|
|
368
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
496
|
+
* Event contract (main → merchant SDK, spec 5.3 table, source of truth).
|
|
482
497
|
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
521
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
559
|
-
*
|
|
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
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
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
|
-
*
|
|
566
|
-
* elementId
|
|
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
|
|
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)→
|
|
591
|
+
* Content height change notification from the iframe (child) → parent window (SDK).
|
|
573
592
|
*
|
|
574
|
-
* child
|
|
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
|
-
/**
|
|
597
|
+
/** Discriminant field, fixed to {@link IFRAME_RESIZE_MESSAGE_TYPE}. */
|
|
579
598
|
type: typeof IFRAME_RESIZE_MESSAGE_TYPE;
|
|
580
599
|
/**
|
|
581
|
-
*
|
|
582
|
-
*
|
|
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
|
-
/**
|
|
605
|
+
/** Content height (CSS px, already `Math.ceil`-ed; finite and non-negative). */
|
|
586
606
|
height: number;
|
|
587
607
|
}
|
|
588
608
|
/**
|
|
589
|
-
*
|
|
609
|
+
* Whether the value is a valid {@link IframeResizeMessage}.
|
|
590
610
|
*
|
|
591
|
-
*
|
|
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 -
|
|
594
|
-
* @returns data
|
|
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
|
|