@dintero/checkout-web-sdk 0.2.0 → 0.4.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.
Files changed (28) hide show
  1. package/.github/workflows/release.yml +1 -2
  2. package/CHANGELOG.md +25 -1
  3. package/README.md +26 -4
  4. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/base.css +0 -0
  5. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/block-navigation.js +0 -0
  6. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/checkout.ts.html +9 -3
  7. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/createIframeAsync.ts.html +15 -15
  8. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/favicon.png +0 -0
  9. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/index.html +30 -30
  10. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/index.ts.html +203 -38
  11. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/prettify.css +0 -0
  12. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/prettify.js +0 -0
  13. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/sort-arrow-sprite.png +0 -0
  14. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/sorter.js +0 -0
  15. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/subscribe.ts.html +34 -34
  16. package/coverage/{Chrome Headless 80.0.3987.0 (Linux x86_64) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/url.ts.html +1 -1
  17. package/dist/declarations/src/checkout.d.ts +75 -73
  18. package/dist/declarations/src/createIframeAsync.d.ts +10 -10
  19. package/dist/declarations/src/index.d.ts +43 -43
  20. package/dist/declarations/src/subscribe.d.ts +41 -41
  21. package/dist/declarations/src/url.d.ts +16 -16
  22. package/dist/dintero-checkout-web-sdk.cjs.dev.js +57 -10
  23. package/dist/dintero-checkout-web-sdk.cjs.prod.js +57 -10
  24. package/dist/dintero-checkout-web-sdk.esm.js +57 -10
  25. package/dist/dintero-checkout-web-sdk.umd.min.js +1 -1
  26. package/dist/dintero-checkout-web-sdk.umd.min.js.map +1 -1
  27. package/package.json +6 -6
  28. package/dist/declarations/package.d.ts +0 -52
@@ -1,73 +1,75 @@
1
- import { Session } from "./session";
2
- export declare enum CheckoutEvents {
3
- SessionNotFound = "SessionNotFound",
4
- SessionLoaded = "SessionLoaded",
5
- SessionUpdated = "SessionUpdated",
6
- SessionCancel = "SessionCancel",
7
- SessionPaymentOnHold = "SessionPaymentOnHold",
8
- SessionPaymentAuthorized = "SessionPaymentAuthorized",
9
- SessionPaymentError = "SessionPaymentError",
10
- SessionLocked = "SessionLocked",
11
- SessionLockFailed = "SessionLockFailed",
12
- ActivePaymentProductType = "ActivePaymentProductType",
13
- ValidateSession = "ValidateSession"
14
- }
15
- export declare enum InternalCheckoutEvents {
16
- HeightChanged = "HeightChanged",
17
- LanguageChanged = "LanguageChanged"
18
- }
19
- export declare type SessionNotFound = {
20
- type: CheckoutEvents.SessionNotFound;
21
- };
22
- export declare type SessionLoaded = {
23
- type: CheckoutEvents.SessionLoaded;
24
- session: Session;
25
- };
26
- export declare type SessionUpdated = {
27
- type: CheckoutEvents.SessionUpdated;
28
- session: Session;
29
- };
30
- export declare type SessionCancel = {
31
- type: CheckoutEvents.SessionCancel;
32
- href: string;
33
- };
34
- export declare type SessionPaymentOnHold = {
35
- type: CheckoutEvents.SessionPaymentOnHold;
36
- transaction_id: string;
37
- merchant_reference: string;
38
- href: string;
39
- };
40
- export declare type SessionPaymentAuthorized = {
41
- type: CheckoutEvents.SessionPaymentAuthorized;
42
- transaction_id: string;
43
- merchant_reference: string;
44
- href: string;
45
- };
46
- export declare type SessionLocked = {
47
- type: CheckoutEvents.SessionLocked;
48
- pay_lock_id: string;
49
- };
50
- export declare type SessionLockFailed = {
51
- type: CheckoutEvents.SessionLockFailed;
52
- };
53
- export declare type ActivePaymentProductType = {
54
- type: CheckoutEvents.ActivePaymentProductType;
55
- payment_product_type: string | undefined;
56
- };
57
- export declare type ValidateSession = {
58
- type: CheckoutEvents.ValidateSession;
59
- session: Session;
60
- callback: (result: SessionValidationCallback) => void;
61
- };
62
- export interface SessionValidationCallback {
63
- success: boolean;
64
- clientValidationError?: string;
65
- }
66
- export declare type WrappedValidateSession = Pick<ValidateSession, "type" | "session">;
67
- export declare type SessionPayment = SessionPaymentAuthorized | SessionPaymentOnHold;
68
- export declare type SessionPaymentError = {
69
- type: CheckoutEvents.SessionPaymentError;
70
- error: string;
71
- href: string;
72
- };
73
- export declare type SessionEvent = SessionNotFound | SessionLoaded | SessionUpdated | SessionCancel | SessionPaymentOnHold | SessionPaymentAuthorized | SessionPaymentError | SessionLocked | SessionLockFailed | ActivePaymentProductType | WrappedValidateSession;
1
+ import { Session } from "./session";
2
+ export declare enum CheckoutEvents {
3
+ SessionNotFound = "SessionNotFound",
4
+ SessionLoaded = "SessionLoaded",
5
+ SessionUpdated = "SessionUpdated",
6
+ SessionCancel = "SessionCancel",
7
+ SessionPaymentOnHold = "SessionPaymentOnHold",
8
+ SessionPaymentAuthorized = "SessionPaymentAuthorized",
9
+ SessionPaymentError = "SessionPaymentError",
10
+ SessionLocked = "SessionLocked",
11
+ SessionLockFailed = "SessionLockFailed",
12
+ ActivePaymentProductType = "ActivePaymentProductType",
13
+ ValidateSession = "ValidateSession"
14
+ }
15
+ export declare enum InternalCheckoutEvents {
16
+ HeightChanged = "HeightChanged",
17
+ LanguageChanged = "LanguageChanged"
18
+ }
19
+ export declare type SessionNotFound = {
20
+ type: CheckoutEvents.SessionNotFound;
21
+ };
22
+ export declare type SessionLoaded = {
23
+ type: CheckoutEvents.SessionLoaded;
24
+ session: Session;
25
+ };
26
+ export declare type SessionUpdated = {
27
+ type: CheckoutEvents.SessionUpdated;
28
+ session: Session;
29
+ };
30
+ export declare type SessionCancel = {
31
+ type: CheckoutEvents.SessionCancel;
32
+ href: string;
33
+ };
34
+ export declare type SessionPaymentOnHold = {
35
+ type: CheckoutEvents.SessionPaymentOnHold;
36
+ transaction_id: string;
37
+ merchant_reference: string;
38
+ href: string;
39
+ };
40
+ export declare type SessionPaymentAuthorized = {
41
+ type: CheckoutEvents.SessionPaymentAuthorized;
42
+ transaction_id: string;
43
+ merchant_reference: string;
44
+ href: string;
45
+ };
46
+ export declare type SessionLocked = {
47
+ type: CheckoutEvents.SessionLocked;
48
+ pay_lock_id: string;
49
+ callback: () => void;
50
+ };
51
+ export declare type SessionLockFailed = {
52
+ type: CheckoutEvents.SessionLockFailed;
53
+ };
54
+ export declare type ActivePaymentProductType = {
55
+ type: CheckoutEvents.ActivePaymentProductType;
56
+ payment_product_type: string | undefined;
57
+ };
58
+ export declare type ValidateSession = {
59
+ type: CheckoutEvents.ValidateSession;
60
+ session: Session;
61
+ callback: (result: SessionValidationCallback) => void;
62
+ };
63
+ export interface SessionValidationCallback {
64
+ success: boolean;
65
+ clientValidationError?: string;
66
+ }
67
+ export declare type WrappedValidateSession = Pick<ValidateSession, "type" | "session">;
68
+ export declare type WrappedSessionLocked = Pick<SessionLocked, "type" | "pay_lock_id">;
69
+ export declare type SessionPayment = SessionPaymentAuthorized | SessionPaymentOnHold;
70
+ export declare type SessionPaymentError = {
71
+ type: CheckoutEvents.SessionPaymentError;
72
+ error: string;
73
+ href: string;
74
+ };
75
+ export declare type SessionEvent = SessionNotFound | SessionLoaded | SessionUpdated | SessionCancel | SessionPaymentOnHold | SessionPaymentAuthorized | SessionPaymentError | WrappedSessionLocked | SessionLockFailed | ActivePaymentProductType | WrappedValidateSession;
@@ -1,10 +1,10 @@
1
- /**
2
- * Creates an iframe and adds it to the container.
3
- *
4
- * Returns a promise that resolves to the iframe when the iframe has loaded.
5
- * Rejects the promise if there is a problem loading the iframe.
6
- */
7
- export declare const createIframeAsync: (container: HTMLDivElement, endpoint: string, url: string) => {
8
- iframe: HTMLIFrameElement;
9
- initiate: () => void;
10
- };
1
+ /**
2
+ * Creates an iframe and adds it to the container.
3
+ *
4
+ * Returns a promise that resolves to the iframe when the iframe has loaded.
5
+ * Rejects the promise if there is a problem loading the iframe.
6
+ */
7
+ export declare const createIframeAsync: (container: HTMLDivElement, endpoint: string, url: string) => {
8
+ iframe: HTMLIFrameElement;
9
+ initiate: () => void;
10
+ };
@@ -1,43 +1,43 @@
1
- import "native-promise-only";
2
- import { SessionNotFound, SessionLoaded, SessionUpdated, SessionCancel, SessionPaymentOnHold, SessionPaymentAuthorized, SessionPaymentError, SessionLocked, SessionLockFailed, ActivePaymentProductType, ValidateSession, SessionValidationCallback } from "./checkout";
3
- export interface DinteroCheckoutInstance {
4
- /**
5
- * Remove iframe and all event listeners.
6
- */
7
- destroy: () => void;
8
- iframe: HTMLIFrameElement;
9
- language: string;
10
- lockSession: () => void;
11
- refreshSession: () => void;
12
- setActivePaymentProductType: (paymentProductType: string) => void;
13
- submitValidationResult: (result: SessionValidationCallback) => void;
14
- }
15
- export interface DinteroCheckoutOptions {
16
- sid: string;
17
- endpoint?: string;
18
- language?: string;
19
- }
20
- export interface DinteroEmbedCheckoutOptions extends DinteroCheckoutOptions {
21
- container: HTMLDivElement;
22
- onPayment?: (event: SessionPaymentAuthorized | SessionPaymentOnHold, checkout: DinteroCheckoutInstance) => void;
23
- /**
24
- * @deprecated Since version 0.0.1. Will be deleted in version 1.0.0. Use onPayment instead.
25
- */
26
- onPaymentAuthorized?: (event: SessionPaymentAuthorized, checkout: DinteroCheckoutInstance) => void;
27
- onSession?: (event: SessionLoaded | SessionUpdated, checkout: DinteroCheckoutInstance) => void;
28
- onPaymentError?: (event: SessionPaymentError, checkout: DinteroCheckoutInstance) => void;
29
- onSessionCancel?: (event: SessionCancel, checkout: DinteroCheckoutInstance) => void;
30
- onSessionNotFound?: (event: SessionNotFound, checkout: DinteroCheckoutInstance) => void;
31
- onSessionLocked?: (event: SessionLocked, checkout: DinteroCheckoutInstance) => void;
32
- onSessionLockFailed?: (event: SessionLockFailed, checkout: DinteroCheckoutInstance) => void;
33
- onActivePaymentType?: (event: ActivePaymentProductType, checkout: DinteroCheckoutInstance) => void;
34
- onValidateSession?: (event: ValidateSession, checkout: DinteroCheckoutInstance, callback: (result: SessionValidationCallback) => void) => void;
35
- }
36
- /**
37
- * Show a dintero payment session in an embedded iframe.
38
- */
39
- export declare const embed: (options: DinteroEmbedCheckoutOptions) => Promise<DinteroCheckoutInstance>;
40
- /**
41
- * Redirect the customer to a payment session in the Dintero Checkout.
42
- */
43
- export declare const redirect: (options: DinteroCheckoutOptions) => void;
1
+ import "native-promise-only";
2
+ import { SessionNotFound, SessionLoaded, SessionUpdated, SessionCancel, SessionPaymentOnHold, SessionPaymentAuthorized, SessionPaymentError, SessionLocked, SessionLockFailed, ActivePaymentProductType, ValidateSession, SessionValidationCallback, SessionEvent } from "./checkout";
3
+ export interface DinteroCheckoutInstance {
4
+ /**
5
+ * Remove iframe and all event listeners.
6
+ */
7
+ destroy: () => void;
8
+ iframe: HTMLIFrameElement;
9
+ language: string;
10
+ lockSession: () => Promise<SessionEvent>;
11
+ refreshSession: () => Promise<SessionEvent>;
12
+ setActivePaymentProductType: (paymentProductType: string) => void;
13
+ submitValidationResult: (result: SessionValidationCallback) => void;
14
+ }
15
+ export interface DinteroCheckoutOptions {
16
+ sid: string;
17
+ endpoint?: string;
18
+ language?: string;
19
+ }
20
+ export interface DinteroEmbedCheckoutOptions extends DinteroCheckoutOptions {
21
+ container: HTMLDivElement;
22
+ onPayment?: (event: SessionPaymentAuthorized | SessionPaymentOnHold, checkout: DinteroCheckoutInstance) => void;
23
+ /**
24
+ * @deprecated Since version 0.0.1. Will be deleted in version 1.0.0. Use onPayment instead.
25
+ */
26
+ onPaymentAuthorized?: (event: SessionPaymentAuthorized, checkout: DinteroCheckoutInstance) => void;
27
+ onSession?: (event: SessionLoaded | SessionUpdated, checkout: DinteroCheckoutInstance) => void;
28
+ onPaymentError?: (event: SessionPaymentError, checkout: DinteroCheckoutInstance) => void;
29
+ onSessionCancel?: (event: SessionCancel, checkout: DinteroCheckoutInstance) => void;
30
+ onSessionNotFound?: (event: SessionNotFound, checkout: DinteroCheckoutInstance) => void;
31
+ onSessionLocked?: (event: SessionLocked, checkout: DinteroCheckoutInstance, callback: () => void) => void;
32
+ onSessionLockFailed?: (event: SessionLockFailed, checkout: DinteroCheckoutInstance) => void;
33
+ onActivePaymentType?: (event: ActivePaymentProductType, checkout: DinteroCheckoutInstance) => void;
34
+ onValidateSession?: (event: ValidateSession, checkout: DinteroCheckoutInstance, callback: (result: SessionValidationCallback) => void) => void;
35
+ }
36
+ /**
37
+ * Show a dintero payment session in an embedded iframe.
38
+ */
39
+ export declare const embed: (options: DinteroEmbedCheckoutOptions) => Promise<DinteroCheckoutInstance>;
40
+ /**
41
+ * Redirect the customer to a payment session in the Dintero Checkout.
42
+ */
43
+ export declare const redirect: (options: DinteroCheckoutOptions) => void;
@@ -1,41 +1,41 @@
1
- import { CheckoutEvents, InternalCheckoutEvents, SessionEvent, SessionValidationCallback } from "./checkout";
2
- import { DinteroCheckoutInstance } from ".";
3
- /**
4
- * Unsubscribe handler from event(s).
5
- */
6
- export declare type SubscriptionHandler = (sessionEvent: SessionEvent, checkout: DinteroCheckoutInstance) => void;
7
- interface SubscriptionOptions {
8
- sid: string;
9
- endpoint: string;
10
- handler: SubscriptionHandler;
11
- eventTypes: (CheckoutEvents | InternalCheckoutEvents)[];
12
- checkout: DinteroCheckoutInstance;
13
- }
14
- export declare type Subscription = {
15
- /**
16
- * Unsubscribe handler from event(s).
17
- */
18
- unsubscribe: () => void;
19
- };
20
- /**
21
- * Post a SessionLock-event to the checkout iframe.
22
- */
23
- export declare const postSessionLock: (iframe: HTMLIFrameElement, sid: string) => void;
24
- /**
25
- * Post the validation result to the checkout iframe
26
- */
27
- export declare const postValidationResult: (iframe: HTMLIFrameElement, sid: string, result: SessionValidationCallback) => void;
28
- /**
29
- * Post RefreshSession-event to the checkout iframe.
30
- */
31
- export declare const postSessionRefresh: (iframe: HTMLIFrameElement, sid: string) => void;
32
- /**
33
- * Post setActivePaymentProductType-event to the checkout iframe.
34
- */
35
- export declare const postActivePaymentProductType: (iframe: HTMLIFrameElement, sid: string, paymentProductType?: string) => void;
36
- /**
37
- * Subscribe to events from an iframe given a handler and a set
38
- * of event types.
39
- */
40
- export declare const subscribe: (options: SubscriptionOptions) => Subscription;
41
- export {};
1
+ import { CheckoutEvents, InternalCheckoutEvents, SessionEvent, SessionValidationCallback } from "./checkout";
2
+ import { DinteroCheckoutInstance } from ".";
3
+ /**
4
+ * Unsubscribe handler from event(s).
5
+ */
6
+ export declare type SubscriptionHandler = (sessionEvent: SessionEvent, checkout: DinteroCheckoutInstance) => void;
7
+ interface SubscriptionOptions {
8
+ sid: string;
9
+ endpoint: string;
10
+ handler: SubscriptionHandler;
11
+ eventTypes: (CheckoutEvents | InternalCheckoutEvents)[];
12
+ checkout: DinteroCheckoutInstance;
13
+ }
14
+ export declare type Subscription = {
15
+ /**
16
+ * Unsubscribe handler from event(s).
17
+ */
18
+ unsubscribe: () => void;
19
+ };
20
+ /**
21
+ * Post a SessionLock-event to the checkout iframe.
22
+ */
23
+ export declare const postSessionLock: (iframe: HTMLIFrameElement, sid: string) => void;
24
+ /**
25
+ * Post the validation result to the checkout iframe
26
+ */
27
+ export declare const postValidationResult: (iframe: HTMLIFrameElement, sid: string, result: SessionValidationCallback) => void;
28
+ /**
29
+ * Post RefreshSession-event to the checkout iframe.
30
+ */
31
+ export declare const postSessionRefresh: (iframe: HTMLIFrameElement, sid: string) => void;
32
+ /**
33
+ * Post setActivePaymentProductType-event to the checkout iframe.
34
+ */
35
+ export declare const postActivePaymentProductType: (iframe: HTMLIFrameElement, sid: string, paymentProductType?: string) => void;
36
+ /**
37
+ * Subscribe to events from an iframe given a handler and a set
38
+ * of event types.
39
+ */
40
+ export declare const subscribe: (options: SubscriptionOptions) => Subscription;
41
+ export {};
@@ -1,16 +1,16 @@
1
- /**
2
- * Wraps window.location.assign()
3
- */
4
- export declare const windowLocationAssign: (url: string) => void;
5
- /**
6
- * Get the url for the session./yarn-error.log
7
- .DS_Store
8
- */
9
- export interface SessionUrlOptions {
10
- sid: string;
11
- endpoint: string;
12
- language: string | undefined;
13
- ui?: "fullscreen" | "inline";
14
- shouldCallValidateSession: boolean;
15
- }
16
- export declare const getSessionUrl: (options: SessionUrlOptions) => string;
1
+ /**
2
+ * Wraps window.location.assign()
3
+ */
4
+ export declare const windowLocationAssign: (url: string) => void;
5
+ /**
6
+ * Get the url for the session./yarn-error.log
7
+ .DS_Store
8
+ */
9
+ export interface SessionUrlOptions {
10
+ sid: string;
11
+ endpoint: string;
12
+ language: string | undefined;
13
+ ui?: "fullscreen" | "inline";
14
+ shouldCallValidateSession: boolean;
15
+ }
16
+ export declare const getSessionUrl: (options: SessionUrlOptions) => string;
@@ -6,7 +6,7 @@ require('native-promise-only');
6
6
 
7
7
  var pkg = {
8
8
  name: "@dintero/checkout-web-sdk",
9
- version: "0.0.0-development",
9
+ version: "0.4.0",
10
10
  description: "Dintero Checkout SDK for web frontends",
11
11
  main: "dist/dintero-checkout-web-sdk.cjs.js",
12
12
  module: "dist/dintero-checkout-web-sdk.esm.js",
@@ -19,7 +19,8 @@ var pkg = {
19
19
  scripts: {
20
20
  build: "preconstruct build",
21
21
  test: "karma start",
22
- "semantic-release": "semantic-release"
22
+ "semantic-release": "semantic-release",
23
+ prepublishOnly: "npm run build"
23
24
  },
24
25
  "private": false,
25
26
  repository: {
@@ -35,7 +36,7 @@ var pkg = {
35
36
  devDependencies: {
36
37
  "@babel/preset-env": "^7.14.1",
37
38
  "@babel/preset-typescript": "^7.13.0",
38
- "@preconstruct/cli": "^2.1.0",
39
+ "@preconstruct/cli": "^2.1.5",
39
40
  "@semantic-release/git": "^10.0.1",
40
41
  chai: "^4.2.0",
41
42
  karma: "^6.3.14",
@@ -45,10 +46,9 @@ var pkg = {
45
46
  "karma-typescript": "^5.0.3",
46
47
  mocha: "^8.1.1",
47
48
  prettier: "^1.19.1",
48
- puppeteer: "^2.1.0",
49
- rollup: "^1.30.1",
49
+ puppeteer: "^13.3.2",
50
50
  "semantic-release": "^19.0.2",
51
- sinon: "^8.1.1",
51
+ sinon: "^13.0.1",
52
52
  typescript: "^4.2.4"
53
53
  },
54
54
  dependencies: {
@@ -329,6 +329,7 @@ const embed = async options => {
329
329
  onActivePaymentType,
330
330
  onValidateSession
331
331
  } = options;
332
+ let checkout;
332
333
  const subscriptions = []; // Create iframe
333
334
 
334
335
  const {
@@ -354,13 +355,53 @@ const embed = async options => {
354
355
  }
355
356
  }
356
357
  };
358
+ /**
359
+ * Turn an action into a promise by specifying resolve and
360
+ * reject events.
361
+ */
362
+
363
+
364
+ const promisifyAction = (action, resolveEvent, rejectEvent) => {
365
+ if (!checkout) {
366
+ throw new Error("Unable to create action promise: checkout is undefined");
367
+ }
368
+
369
+ return new Promise((resolve, reject) => {
370
+ const eventSubscriptions = [];
371
+ eventSubscriptions.push(subscribe({
372
+ sid,
373
+ endpoint,
374
+ handler: sessionEvent => {
375
+ eventSubscriptions.forEach(sub => sub.unsubscribe());
376
+ resolve(sessionEvent);
377
+ },
378
+ eventTypes: [resolveEvent],
379
+ checkout
380
+ }));
381
+ eventSubscriptions.push(subscribe({
382
+ sid,
383
+ endpoint,
384
+ handler: () => {
385
+ eventSubscriptions.forEach(sub => sub.unsubscribe());
386
+ reject(`Received unexpected event: ${rejectEvent}`);
387
+ },
388
+ eventTypes: [rejectEvent],
389
+ checkout
390
+ }));
391
+ action();
392
+ });
393
+ };
357
394
 
358
395
  const lockSession = () => {
359
- postSessionLock(iframe, sid);
396
+ return promisifyAction(() => {
397
+ postSessionLock(iframe, sid);
398
+ }, CheckoutEvents.SessionLocked, CheckoutEvents.SessionLockFailed);
360
399
  };
361
400
 
362
401
  const refreshSession = () => {
363
- postSessionRefresh(iframe, sid);
402
+ return promisifyAction(() => {
403
+ postSessionRefresh(iframe, sid);
404
+ }, CheckoutEvents.SessionUpdated, CheckoutEvents.SessionNotFound);
364
405
  };
365
406
 
366
407
  const setActivePaymentProductType = paymentProductType => {
@@ -375,10 +416,16 @@ const embed = async options => {
375
416
  if (onValidateSession) {
376
417
  onValidateSession(event, checkout, submitValidationResult);
377
418
  }
419
+ };
420
+
421
+ const wrappedOnSessionLocked = (event, checkout) => {
422
+ if (onSessionLocked) {
423
+ onSessionLocked(event, checkout, refreshSession);
424
+ }
378
425
  }; // Create checkout object that wraps the destroy function.
379
426
 
380
427
 
381
- const checkout = {
428
+ checkout = {
382
429
  destroy,
383
430
  iframe,
384
431
  language,
@@ -413,7 +460,7 @@ const embed = async options => {
413
460
  handler: onSessionNotFound,
414
461
  eventTypes: [CheckoutEvents.SessionNotFound]
415
462
  }, {
416
- handler: onSessionLocked,
463
+ handler: wrappedOnSessionLocked,
417
464
  eventTypes: [CheckoutEvents.SessionLocked]
418
465
  }, {
419
466
  handler: onSessionLockFailed,
@@ -6,7 +6,7 @@ require('native-promise-only');
6
6
 
7
7
  var pkg = {
8
8
  name: "@dintero/checkout-web-sdk",
9
- version: "0.0.0-development",
9
+ version: "0.4.0",
10
10
  description: "Dintero Checkout SDK for web frontends",
11
11
  main: "dist/dintero-checkout-web-sdk.cjs.js",
12
12
  module: "dist/dintero-checkout-web-sdk.esm.js",
@@ -19,7 +19,8 @@ var pkg = {
19
19
  scripts: {
20
20
  build: "preconstruct build",
21
21
  test: "karma start",
22
- "semantic-release": "semantic-release"
22
+ "semantic-release": "semantic-release",
23
+ prepublishOnly: "npm run build"
23
24
  },
24
25
  "private": false,
25
26
  repository: {
@@ -35,7 +36,7 @@ var pkg = {
35
36
  devDependencies: {
36
37
  "@babel/preset-env": "^7.14.1",
37
38
  "@babel/preset-typescript": "^7.13.0",
38
- "@preconstruct/cli": "^2.1.0",
39
+ "@preconstruct/cli": "^2.1.5",
39
40
  "@semantic-release/git": "^10.0.1",
40
41
  chai: "^4.2.0",
41
42
  karma: "^6.3.14",
@@ -45,10 +46,9 @@ var pkg = {
45
46
  "karma-typescript": "^5.0.3",
46
47
  mocha: "^8.1.1",
47
48
  prettier: "^1.19.1",
48
- puppeteer: "^2.1.0",
49
- rollup: "^1.30.1",
49
+ puppeteer: "^13.3.2",
50
50
  "semantic-release": "^19.0.2",
51
- sinon: "^8.1.1",
51
+ sinon: "^13.0.1",
52
52
  typescript: "^4.2.4"
53
53
  },
54
54
  dependencies: {
@@ -329,6 +329,7 @@ const embed = async options => {
329
329
  onActivePaymentType,
330
330
  onValidateSession
331
331
  } = options;
332
+ let checkout;
332
333
  const subscriptions = []; // Create iframe
333
334
 
334
335
  const {
@@ -354,13 +355,53 @@ const embed = async options => {
354
355
  }
355
356
  }
356
357
  };
358
+ /**
359
+ * Turn an action into a promise by specifying resolve and
360
+ * reject events.
361
+ */
362
+
363
+
364
+ const promisifyAction = (action, resolveEvent, rejectEvent) => {
365
+ if (!checkout) {
366
+ throw new Error("Unable to create action promise: checkout is undefined");
367
+ }
368
+
369
+ return new Promise((resolve, reject) => {
370
+ const eventSubscriptions = [];
371
+ eventSubscriptions.push(subscribe({
372
+ sid,
373
+ endpoint,
374
+ handler: sessionEvent => {
375
+ eventSubscriptions.forEach(sub => sub.unsubscribe());
376
+ resolve(sessionEvent);
377
+ },
378
+ eventTypes: [resolveEvent],
379
+ checkout
380
+ }));
381
+ eventSubscriptions.push(subscribe({
382
+ sid,
383
+ endpoint,
384
+ handler: () => {
385
+ eventSubscriptions.forEach(sub => sub.unsubscribe());
386
+ reject(`Received unexpected event: ${rejectEvent}`);
387
+ },
388
+ eventTypes: [rejectEvent],
389
+ checkout
390
+ }));
391
+ action();
392
+ });
393
+ };
357
394
 
358
395
  const lockSession = () => {
359
- postSessionLock(iframe, sid);
396
+ return promisifyAction(() => {
397
+ postSessionLock(iframe, sid);
398
+ }, CheckoutEvents.SessionLocked, CheckoutEvents.SessionLockFailed);
360
399
  };
361
400
 
362
401
  const refreshSession = () => {
363
- postSessionRefresh(iframe, sid);
402
+ return promisifyAction(() => {
403
+ postSessionRefresh(iframe, sid);
404
+ }, CheckoutEvents.SessionUpdated, CheckoutEvents.SessionNotFound);
364
405
  };
365
406
 
366
407
  const setActivePaymentProductType = paymentProductType => {
@@ -375,10 +416,16 @@ const embed = async options => {
375
416
  if (onValidateSession) {
376
417
  onValidateSession(event, checkout, submitValidationResult);
377
418
  }
419
+ };
420
+
421
+ const wrappedOnSessionLocked = (event, checkout) => {
422
+ if (onSessionLocked) {
423
+ onSessionLocked(event, checkout, refreshSession);
424
+ }
378
425
  }; // Create checkout object that wraps the destroy function.
379
426
 
380
427
 
381
- const checkout = {
428
+ checkout = {
382
429
  destroy,
383
430
  iframe,
384
431
  language,
@@ -413,7 +460,7 @@ const embed = async options => {
413
460
  handler: onSessionNotFound,
414
461
  eventTypes: [CheckoutEvents.SessionNotFound]
415
462
  }, {
416
- handler: onSessionLocked,
463
+ handler: wrappedOnSessionLocked,
417
464
  eventTypes: [CheckoutEvents.SessionLocked]
418
465
  }, {
419
466
  handler: onSessionLockFailed,