@sunbay/checkout-sdk-js 0.1.1 → 0.2.0

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,5 +1,5 @@
1
- import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, EventPayloadMap, PublicSessionView, WarningEvent, ConfirmReq, PaymentOutcome, GetPaymentStatusResp, AddressInfo, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
- export { AddressElementOptions, AddressFormStyle, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, ChangeEvent, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementReadyEvent, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, SessionStatus, TxnStatus, WARNING_CODES, WalletErrorStage, WarningCode, WarningEvent } from '@sunbay/checkout-sdk-protocol';
1
+ import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, ElementState, EventPayloadMap, PublicSessionView, WarningEvent, ConfirmReq, PaymentOutcome, PaymentMethodsView, GetPaymentStatusResp, AddressInfo, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
+ export { AddressElementOptions, AddressFormStyle, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, ChangeEvent, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementReadyEvent, ElementState, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, ExpressMethodView, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentMethodsView, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, SessionStatus, TxnStatus, WARNING_CODES, WalletErrorStage, WarningCode, WarningEvent } from '@sunbay/checkout-sdk-protocol';
3
3
 
4
4
  /**
5
5
  * CheckoutElement — the merchant-side Element handle (spec 6).
@@ -127,6 +127,10 @@ declare class CheckoutElement {
127
127
  private availableWallets;
128
128
  /** expressCheckout only: the persistently subscribed expressAvailabilityChange handler (unbound on destroy). */
129
129
  private availabilityHandler;
130
+ /** Input Elements only: the last `change` snapshot, tracked from construction (never replayed to `on`). */
131
+ private state;
132
+ /** Input Elements only: the persistently subscribed `change` handler (unbound on destroy). */
133
+ private stateHandler;
130
134
  /** Merchant listeners registered via `on`: event → (original handler → transport wrapper). Cleared on destroy. */
131
135
  private readonly userListeners;
132
136
  /**
@@ -150,6 +154,16 @@ declare class CheckoutElement {
150
154
  * @returns The availability snapshot; undefined when not yet ready or non-express.
151
155
  */
152
156
  getAvailableWallets(): AvailableWallets | undefined;
157
+ /**
158
+ * Input Elements only: the last known `change` state (`empty`, `complete`, `brand?`, `error?`).
159
+ *
160
+ * `change` events are not replayed, so a handler registered after `mount()` resolves can miss
161
+ * changes (e.g. browser autofill). Read this to get the current value instead; it is tracked from
162
+ * construction. Starts as `{ empty: true, complete: false }`. Never contains values.
163
+ *
164
+ * @returns A copy of the snapshot; undefined for `expressCheckout`. Still readable after destroy.
165
+ */
166
+ getState(): ElementState | undefined;
153
167
  /**
154
168
  * Mount at the merchant DOM target: insert a visible iframe, send createElement, await elementReady.
155
169
  *
@@ -218,6 +232,8 @@ declare class CheckoutElement {
218
232
  * so there is no need to filter by elementId. Non-express types do not subscribe.
219
233
  */
220
234
  private installExpressAvailability;
235
+ /** Input Elements only: keep the `change` snapshot current so `getState()` works without a listener. */
236
+ private installInputState;
221
237
  /** Send one input-class action command (synchronously throws INSTANCE_DESTROYED after destruction). */
222
238
  private sendAction;
223
239
  /** Throw INSTANCE_DESTROYED if already destroyed. */
@@ -451,6 +467,17 @@ declare class CheckoutInstance {
451
467
  * @throws rejects INSTANCE_DESTROYED when destroyed.
452
468
  */
453
469
  getSession(): Promise<PublicSessionView>;
470
+ /**
471
+ * The session's payment methods split into quick wallets (`express`) and everything else
472
+ * (`regular`), from the local session snapshot (already filtered by `paymentMethods`).
473
+ *
474
+ * Each express entry carries `available` from the `expressCheckout` Element's availability
475
+ * snapshot; it is `undefined` while no such Element exists or it has not reported yet.
476
+ *
477
+ * @returns The split view.
478
+ * @throws INSTANCE_DESTROYED when destroyed.
479
+ */
480
+ getPaymentMethods(): PaymentMethodsView;
454
481
  /**
455
482
  * Refresh the session (passes through the refresh command and writes back the local snapshot).
456
483
  *
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, EventPayloadMap, PublicSessionView, WarningEvent, ConfirmReq, PaymentOutcome, GetPaymentStatusResp, AddressInfo, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
- export { AddressElementOptions, AddressFormStyle, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, ChangeEvent, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementReadyEvent, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, SessionStatus, TxnStatus, WARNING_CODES, WalletErrorStage, WarningCode, WarningEvent } from '@sunbay/checkout-sdk-protocol';
1
+ import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, ElementState, EventPayloadMap, PublicSessionView, WarningEvent, ConfirmReq, PaymentOutcome, PaymentMethodsView, GetPaymentStatusResp, AddressInfo, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
+ export { AddressElementOptions, AddressFormStyle, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, ChangeEvent, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementReadyEvent, ElementState, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, ExpressMethodView, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentMethodsView, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, SessionStatus, TxnStatus, WARNING_CODES, WalletErrorStage, WarningCode, WarningEvent } from '@sunbay/checkout-sdk-protocol';
3
3
 
4
4
  /**
5
5
  * CheckoutElement — the merchant-side Element handle (spec 6).
@@ -127,6 +127,10 @@ declare class CheckoutElement {
127
127
  private availableWallets;
128
128
  /** expressCheckout only: the persistently subscribed expressAvailabilityChange handler (unbound on destroy). */
129
129
  private availabilityHandler;
130
+ /** Input Elements only: the last `change` snapshot, tracked from construction (never replayed to `on`). */
131
+ private state;
132
+ /** Input Elements only: the persistently subscribed `change` handler (unbound on destroy). */
133
+ private stateHandler;
130
134
  /** Merchant listeners registered via `on`: event → (original handler → transport wrapper). Cleared on destroy. */
131
135
  private readonly userListeners;
132
136
  /**
@@ -150,6 +154,16 @@ declare class CheckoutElement {
150
154
  * @returns The availability snapshot; undefined when not yet ready or non-express.
151
155
  */
152
156
  getAvailableWallets(): AvailableWallets | undefined;
157
+ /**
158
+ * Input Elements only: the last known `change` state (`empty`, `complete`, `brand?`, `error?`).
159
+ *
160
+ * `change` events are not replayed, so a handler registered after `mount()` resolves can miss
161
+ * changes (e.g. browser autofill). Read this to get the current value instead; it is tracked from
162
+ * construction. Starts as `{ empty: true, complete: false }`. Never contains values.
163
+ *
164
+ * @returns A copy of the snapshot; undefined for `expressCheckout`. Still readable after destroy.
165
+ */
166
+ getState(): ElementState | undefined;
153
167
  /**
154
168
  * Mount at the merchant DOM target: insert a visible iframe, send createElement, await elementReady.
155
169
  *
@@ -218,6 +232,8 @@ declare class CheckoutElement {
218
232
  * so there is no need to filter by elementId. Non-express types do not subscribe.
219
233
  */
220
234
  private installExpressAvailability;
235
+ /** Input Elements only: keep the `change` snapshot current so `getState()` works without a listener. */
236
+ private installInputState;
221
237
  /** Send one input-class action command (synchronously throws INSTANCE_DESTROYED after destruction). */
222
238
  private sendAction;
223
239
  /** Throw INSTANCE_DESTROYED if already destroyed. */
@@ -451,6 +467,17 @@ declare class CheckoutInstance {
451
467
  * @throws rejects INSTANCE_DESTROYED when destroyed.
452
468
  */
453
469
  getSession(): Promise<PublicSessionView>;
470
+ /**
471
+ * The session's payment methods split into quick wallets (`express`) and everything else
472
+ * (`regular`), from the local session snapshot (already filtered by `paymentMethods`).
473
+ *
474
+ * Each express entry carries `available` from the `expressCheckout` Element's availability
475
+ * snapshot; it is `undefined` while no such Element exists or it has not reported yet.
476
+ *
477
+ * @returns The split view.
478
+ * @throws INSTANCE_DESTROYED when destroyed.
479
+ */
480
+ getPaymentMethods(): PaymentMethodsView;
454
481
  /**
455
482
  * Refresh the session (passes through the refresh command and writes back the local snapshot).
456
483
  *
@@ -564,6 +564,10 @@ var SunbayCheckout = (() => {
564
564
  this.abortMount = null;
565
565
  /** expressCheckout only: the persistently subscribed expressAvailabilityChange handler (unbound on destroy). */
566
566
  this.availabilityHandler = null;
567
+ /** Input Elements only: the last `change` snapshot, tracked from construction (never replayed to `on`). */
568
+ this.state = { empty: true, complete: false };
569
+ /** Input Elements only: the persistently subscribed `change` handler (unbound on destroy). */
570
+ this.stateHandler = null;
567
571
  /** Merchant listeners registered via `on`: event → (original handler → transport wrapper). Cleared on destroy. */
568
572
  this.userListeners = /* @__PURE__ */ new Map();
569
573
  /**
@@ -587,6 +591,7 @@ var SunbayCheckout = (() => {
587
591
  this.onDestroy = opts.onDestroy;
588
592
  this.installInputActions();
589
593
  this.installExpressAvailability();
594
+ this.installInputState();
590
595
  }
591
596
  /** The current status (read-only snapshot, for external/test observation). */
592
597
  getStatus() {
@@ -604,6 +609,21 @@ var SunbayCheckout = (() => {
604
609
  getAvailableWallets() {
605
610
  return this.availableWallets;
606
611
  }
612
+ /**
613
+ * Input Elements only: the last known `change` state (`empty`, `complete`, `brand?`, `error?`).
614
+ *
615
+ * `change` events are not replayed, so a handler registered after `mount()` resolves can miss
616
+ * changes (e.g. browser autofill). Read this to get the current value instead; it is tracked from
617
+ * construction. Starts as `{ empty: true, complete: false }`. Never contains values.
618
+ *
619
+ * @returns A copy of the snapshot; undefined for `expressCheckout`. Still readable after destroy.
620
+ */
621
+ getState() {
622
+ if (!INPUT_TYPES.includes(this.type)) {
623
+ return void 0;
624
+ }
625
+ return { ...this.state };
626
+ }
607
627
  /**
608
628
  * Mount at the merchant DOM target: insert a visible iframe, send createElement, await elementReady.
609
629
  *
@@ -820,6 +840,10 @@ var SunbayCheckout = (() => {
820
840
  this.transport.off("expressAvailabilityChange", this.availabilityHandler);
821
841
  this.availabilityHandler = null;
822
842
  }
843
+ if (this.stateHandler) {
844
+ this.transport.off("change", this.stateHandler);
845
+ this.stateHandler = null;
846
+ }
823
847
  for (const [event, wrappers] of this.userListeners) {
824
848
  for (const wrapper of wrappers.values()) {
825
849
  this.transport.off(event, wrapper);
@@ -931,6 +955,31 @@ var SunbayCheckout = (() => {
931
955
  this.availabilityHandler = handler;
932
956
  this.transport.on("expressAvailabilityChange", handler);
933
957
  }
958
+ /** Input Elements only: keep the `change` snapshot current so `getState()` works without a listener. */
959
+ installInputState() {
960
+ if (!INPUT_TYPES.includes(this.type)) {
961
+ return;
962
+ }
963
+ const handler = (payload) => {
964
+ const change = payload;
965
+ if (!change || change.elementId !== this.elementId) {
966
+ return;
967
+ }
968
+ const next = {
969
+ empty: change.empty === true,
970
+ complete: change.complete === true
971
+ };
972
+ if (change.brand !== void 0) {
973
+ next.brand = change.brand;
974
+ }
975
+ if (change.error !== void 0) {
976
+ next.error = change.error;
977
+ }
978
+ this.state = next;
979
+ };
980
+ this.stateHandler = handler;
981
+ this.transport.on("change", handler);
982
+ }
934
983
  /** Send one input-class action command (synchronously throws INSTANCE_DESTROYED after destruction). */
935
984
  sendAction(name) {
936
985
  this.assertAlive();
@@ -1288,6 +1337,35 @@ var SunbayCheckout = (() => {
1288
1337
  this.session = resp;
1289
1338
  return resp;
1290
1339
  }
1340
+ /**
1341
+ * The session's payment methods split into quick wallets (`express`) and everything else
1342
+ * (`regular`), from the local session snapshot (already filtered by `paymentMethods`).
1343
+ *
1344
+ * Each express entry carries `available` from the `expressCheckout` Element's availability
1345
+ * snapshot; it is `undefined` while no such Element exists or it has not reported yet.
1346
+ *
1347
+ * @returns The split view.
1348
+ * @throws INSTANCE_DESTROYED when destroyed.
1349
+ */
1350
+ getPaymentMethods() {
1351
+ this.assertAlive();
1352
+ let wallets;
1353
+ for (const element of this.elements.values()) {
1354
+ if (element.type === "expressCheckout") {
1355
+ wallets = element.getAvailableWallets();
1356
+ }
1357
+ }
1358
+ const view = { express: [], regular: [] };
1359
+ for (const method of this.session.paymentMethods) {
1360
+ if (method.method === "APPLE_PAY" || method.method === "GOOGLE_PAY") {
1361
+ const available = wallets === void 0 ? void 0 : method.method === "APPLE_PAY" ? wallets.applePay : wallets.googlePay;
1362
+ view.express.push({ ...method, available });
1363
+ } else {
1364
+ view.regular.push({ ...method });
1365
+ }
1366
+ }
1367
+ return view;
1368
+ }
1291
1369
  /**
1292
1370
  * Refresh the session (passes through the refresh command and writes back the local snapshot).
1293
1371
  *
@@ -1586,7 +1664,7 @@ var SunbayCheckout = (() => {
1586
1664
  const w = window;
1587
1665
  w.SunbayCheckout = { ...w.SunbayCheckout ?? {}, createCheckout };
1588
1666
  }
1589
- var version = true ? "0.1.1" : "0.0.0";
1667
+ var version = true ? "0.2.0" : "0.0.0";
1590
1668
  return __toCommonJS(index_exports);
1591
1669
  })();
1592
1670
  //# sourceMappingURL=index.global.js.map