@dintero/checkout-web-sdk 0.5.0 → 0.5.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.
Files changed (20) hide show
  1. package/.github/workflows/release.yml +6 -0
  2. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/base.css +0 -0
  3. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/block-navigation.js +0 -0
  4. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/checkout.ts.html +1 -1
  5. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/createIframeAsync.ts.html +1 -1
  6. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/favicon.png +0 -0
  7. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/index.html +1 -1
  8. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/index.ts.html +1 -1
  9. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/prettify.css +0 -0
  10. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/prettify.js +0 -0
  11. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/sort-arrow-sprite.png +0 -0
  12. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/sorter.js +0 -0
  13. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/subscribe.ts.html +1 -1
  14. package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/url.ts.html +1 -1
  15. package/dist/dintero-checkout-web-sdk.cjs.dev.js +51 -64
  16. package/dist/dintero-checkout-web-sdk.cjs.prod.js +51 -64
  17. package/dist/dintero-checkout-web-sdk.esm.js +51 -64
  18. package/dist/dintero-checkout-web-sdk.umd.min.js +1 -1
  19. package/dist/dintero-checkout-web-sdk.umd.min.js.map +1 -1
  20. package/package.json +2 -2
@@ -6,7 +6,7 @@ require('native-promise-only');
6
6
 
7
7
  var pkg = {
8
8
  name: "@dintero/checkout-web-sdk",
9
- version: "0.5.0",
9
+ version: "0.5.2",
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",
@@ -46,7 +46,7 @@ var pkg = {
46
46
  "karma-typescript": "^5.0.3",
47
47
  mocha: "^8.1.1",
48
48
  prettier: "^2.6.2",
49
- puppeteer: "^18.0.5",
49
+ puppeteer: "^19.0.0",
50
50
  "semantic-release": "^19.0.2",
51
51
  sinon: "^14.0.0",
52
52
  typescript: "^4.2.4"
@@ -57,7 +57,6 @@ var pkg = {
57
57
  };
58
58
 
59
59
  let CheckoutEvents;
60
-
61
60
  (function (CheckoutEvents) {
62
61
  CheckoutEvents["SessionNotFound"] = "SessionNotFound";
63
62
  CheckoutEvents["SessionLoaded"] = "SessionLoaded";
@@ -71,9 +70,7 @@ let CheckoutEvents;
71
70
  CheckoutEvents["ActivePaymentProductType"] = "ActivePaymentProductType";
72
71
  CheckoutEvents["ValidateSession"] = "ValidateSession";
73
72
  })(CheckoutEvents || (CheckoutEvents = {}));
74
-
75
73
  let InternalCheckoutEvents;
76
-
77
74
  (function (InternalCheckoutEvents) {
78
75
  InternalCheckoutEvents["HeightChanged"] = "HeightChanged";
79
76
  InternalCheckoutEvents["LanguageChanged"] = "LanguageChanged";
@@ -83,10 +80,10 @@ let InternalCheckoutEvents;
83
80
  /**
84
81
  * Wraps window.location.assign()
85
82
  */
86
-
87
83
  const windowLocationAssign = url => {
88
84
  window.location.assign(url);
89
85
  };
86
+
90
87
  /**
91
88
  * Get the url for the session./yarn-error.log
92
89
  .DS_Store
@@ -100,12 +97,11 @@ const getSessionUrl = options => {
100
97
  ui,
101
98
  shouldCallValidateSession
102
99
  } = options;
103
-
104
100
  if (!endpoint) {
105
101
  throw new Error("Invalid endpoint");
106
- } // Compose url for view session endpoint with optional language parameter.
107
-
102
+ }
108
103
 
104
+ // Compose url for view session endpoint with optional language parameter.
109
105
  let languageParam = language ? `language=${language}` : "";
110
106
  let uiParam = ui ? `ui=${ui}` : "";
111
107
  let sdk = `sdk=${pkg.version}`;
@@ -124,12 +120,14 @@ const createIframeAsync = (container, endpoint, url) => {
124
120
  if (!container || !container.appendChild) {
125
121
  throw new Error("Invalid container");
126
122
  }
123
+ const iframe = document.createElement("iframe");
127
124
 
128
- const iframe = document.createElement("iframe"); // No border, transparent and stretch to 100% of the container width.
129
-
125
+ // No border, transparent and stretch to 100% of the container width.
130
126
  iframe.setAttribute("frameborder", "0");
131
127
  iframe.setAttribute("allowTransparency", "true");
132
- iframe.setAttribute("style", "width:100%; height:0;"); // TODO: Get this to work as expected, might be tricky with current
128
+ iframe.setAttribute("style", "width:100%; height:0;");
129
+
130
+ // TODO: Get this to work as expected, might be tricky with current
133
131
  // tests since they will require the csp to be "unsafe-inline".
134
132
  // The server needs to add the same property in the Content Security
135
133
  // Policy headers in the response for this to work. A CSP header set by
@@ -137,25 +135,27 @@ const createIframeAsync = (container, endpoint, url) => {
137
135
  // CSP from the iframe host.
138
136
  // Content Security Policy, should be limited to "endpoint".
139
137
  // iframe.setAttribute("csp", `default-src ${endpoint}`);
138
+
140
139
  // Apply extra restrictions to the content in the iframe.
141
140
  // allow popups is needed to open terms in new window
141
+ iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox");
142
+
143
+ // The download priority of the resource in the <iframe>'s src attribute.
144
+ iframe.setAttribute("importance", "high");
142
145
 
143
- iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"); // The download priority of the resource in the <iframe>'s src attribute.
146
+ // Set the iframe source to the url.
147
+ iframe.setAttribute("src", url);
144
148
 
145
- iframe.setAttribute("importance", "high"); // Set the iframe source to the url.
149
+ // Resolve or reject promise when iframe loads.
146
150
 
147
- iframe.setAttribute("src", url); // Resolve or reject promise when iframe loads.
148
151
  // // Add iframe to the container.
149
152
  // container.appendChild(iframe);
150
-
151
153
  return {
152
154
  iframe,
153
155
  initiate: async () => {
154
156
  return new Promise((resolve, reject) => {
155
157
  iframe.onload = () => resolve();
156
-
157
158
  iframe.onerror = () => reject();
158
-
159
159
  container.appendChild(iframe);
160
160
  });
161
161
  }
@@ -176,11 +176,10 @@ const postAck = (iframe, event) => {
176
176
  }, event.origin || "*");
177
177
  }
178
178
  };
179
+
179
180
  /**
180
181
  * Post a SessionLock-event to the checkout iframe.
181
182
  */
182
-
183
-
184
183
  const postSessionLock = (iframe, sid) => {
185
184
  if (iframe.contentWindow) {
186
185
  iframe.contentWindow.postMessage({
@@ -189,10 +188,10 @@ const postSessionLock = (iframe, sid) => {
189
188
  }, "*");
190
189
  }
191
190
  };
191
+
192
192
  /**
193
193
  * Post the validation result to the checkout iframe
194
194
  */
195
-
196
195
  const postValidationResult = (iframe, sid, result) => {
197
196
  if (iframe.contentWindow) {
198
197
  iframe.contentWindow.postMessage({
@@ -202,10 +201,10 @@ const postValidationResult = (iframe, sid, result) => {
202
201
  }, "*");
203
202
  }
204
203
  };
204
+
205
205
  /**
206
206
  * Post RefreshSession-event to the checkout iframe.
207
207
  */
208
-
209
208
  const postSessionRefresh = (iframe, sid) => {
210
209
  if (iframe.contentWindow) {
211
210
  iframe.contentWindow.postMessage({
@@ -214,10 +213,10 @@ const postSessionRefresh = (iframe, sid) => {
214
213
  }, "*");
215
214
  }
216
215
  };
216
+
217
217
  /**
218
218
  * Post setActivePaymentProductType-event to the checkout iframe.
219
219
  */
220
-
221
220
  const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
222
221
  if (iframe.contentWindow) {
223
222
  iframe.contentWindow.postMessage({
@@ -227,11 +226,11 @@ const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
227
226
  }, "*");
228
227
  }
229
228
  };
229
+
230
230
  /**
231
231
  * Subscribe to events from an iframe given a handler and a set
232
232
  * of event types.
233
233
  */
234
-
235
234
  const subscribe = options => {
236
235
  const {
237
236
  sid,
@@ -239,29 +238,30 @@ const subscribe = options => {
239
238
  handler,
240
239
  eventTypes,
241
240
  checkout
242
- } = options; // Wrap event handler in a function that checks for correct origin and
243
- // filters on event type(s) in the event data.
241
+ } = options;
244
242
 
243
+ // Wrap event handler in a function that checks for correct origin and
244
+ // filters on event type(s) in the event data.
245
245
  const wrappedHandler = event => {
246
246
  const correctOrigin = event.origin === endpoint;
247
247
  const correctWindow = event.source === checkout.iframe.contentWindow;
248
248
  const correctSid = event.data && event.data.sid === sid;
249
249
  const correctMessageType = eventTypes.indexOf(event.data && event.data.type) !== -1;
250
-
251
250
  if (correctOrigin && correctWindow && correctSid && correctMessageType) {
252
251
  postAck(checkout.iframe, event);
253
252
  handler(event.data, checkout);
254
253
  }
255
- }; // Add event listener to the iframe.
256
-
254
+ };
257
255
 
258
- window.addEventListener("message", wrappedHandler, false); // Function to remove the event listener from the iframe.
256
+ // Add event listener to the iframe.
257
+ window.addEventListener("message", wrappedHandler, false);
259
258
 
259
+ // Function to remove the event listener from the iframe.
260
260
  const unsubscribe = () => {
261
261
  window.removeEventListener("message", wrappedHandler, false);
262
- }; // Return object with unsubscribe function.
263
-
262
+ };
264
263
 
264
+ // Return object with unsubscribe function.
265
265
  return {
266
266
  unsubscribe
267
267
  };
@@ -275,22 +275,20 @@ const followHref = event => {
275
275
  windowLocationAssign(event.href);
276
276
  }
277
277
  };
278
+
278
279
  /**
279
280
  * An event handler that sets height of the iframe.
280
281
  */
281
-
282
-
283
282
  const setIframeHeight = (event, checkout) => {
284
283
  if (event.height || event.height === 0) {
285
284
  checkout.iframe.setAttribute("style", `width:100%; height:${event.height}px;`);
286
285
  }
287
286
  };
287
+
288
288
  /**
289
289
  * An event handler that scrolls to the top of the iframe. This is useful when the user
290
290
  * is navigated to another page.
291
291
  */
292
-
293
-
294
292
  const scrollToIframeTop = (event, checkout) => {
295
293
  try {
296
294
  checkout.iframe.scrollIntoView({
@@ -302,26 +300,22 @@ const scrollToIframeTop = (event, checkout) => {
302
300
  console.error(e);
303
301
  }
304
302
  };
303
+
305
304
  /**
306
305
  * An event handler that sets language in the iframe.
307
306
  */
308
-
309
-
310
307
  const setLanguage = (event, checkout) => {
311
308
  if (event.language) {
312
309
  checkout.language = event.language;
313
310
  }
314
311
  };
315
-
316
312
  const handleWithResult = (sid, endpoint, handler) => {
317
313
  return (event, checkout) => {
318
314
  const eventKeys = ["sid", "merchant_reference", "transaction_id", "error"];
319
315
  const pairs = eventKeys.map(key => [key, event[key]]);
320
-
321
316
  if (event.type === CheckoutEvents.SessionCancel && !event.error) {
322
317
  pairs.push(["error", "cancelled"]);
323
318
  }
324
-
325
319
  pairs.push(["language", checkout.language]);
326
320
  pairs.push(["sdk", pkg.version]);
327
321
  const urlQuery = pairs.filter(([key, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
@@ -329,11 +323,10 @@ const handleWithResult = (sid, endpoint, handler) => {
329
323
  handler(event, checkout);
330
324
  };
331
325
  };
326
+
332
327
  /**
333
328
  * Show a dintero payment session in an embedded iframe.
334
329
  */
335
-
336
-
337
330
  const embed = async options => {
338
331
  const {
339
332
  container,
@@ -352,8 +345,9 @@ const embed = async options => {
352
345
  onValidateSession
353
346
  } = options;
354
347
  let checkout;
355
- const subscriptions = []; // Create iframe
348
+ const subscriptions = [];
356
349
 
350
+ // Create iframe
357
351
  const {
358
352
  iframe,
359
353
  initiate
@@ -364,30 +358,27 @@ const embed = async options => {
364
358
  ui: "inline",
365
359
  shouldCallValidateSession: onValidateSession !== undefined
366
360
  }));
361
+
367
362
  /**
368
363
  * Function that removes the iframe and all event listeners.
369
364
  */
370
-
371
365
  const destroy = () => {
372
366
  if (iframe) {
373
367
  subscriptions.forEach(sub => sub.unsubscribe());
374
-
375
368
  if (iframe.parentElement) {
376
369
  container.removeChild(iframe);
377
370
  }
378
371
  }
379
372
  };
373
+
380
374
  /**
381
375
  * Turn an action into a promise by specifying resolve and
382
376
  * reject events.
383
377
  */
384
-
385
-
386
378
  const promisifyAction = (action, resolveEvent, rejectEvent) => {
387
379
  if (!checkout) {
388
380
  throw new Error("Unable to create action promise: checkout is undefined");
389
381
  }
390
-
391
382
  return new Promise((resolve, reject) => {
392
383
  const eventSubscriptions = [];
393
384
  eventSubscriptions.push(subscribe({
@@ -413,40 +404,34 @@ const embed = async options => {
413
404
  action();
414
405
  });
415
406
  };
416
-
417
407
  const lockSession = () => {
418
408
  return promisifyAction(() => {
419
409
  postSessionLock(iframe, sid);
420
410
  }, CheckoutEvents.SessionLocked, CheckoutEvents.SessionLockFailed);
421
411
  };
422
-
423
412
  const refreshSession = () => {
424
413
  return promisifyAction(() => {
425
414
  postSessionRefresh(iframe, sid);
426
415
  }, CheckoutEvents.SessionUpdated, CheckoutEvents.SessionNotFound);
427
416
  };
428
-
429
417
  const setActivePaymentProductType = paymentProductType => {
430
418
  postActivePaymentProductType(iframe, sid, paymentProductType);
431
419
  };
432
-
433
420
  const submitValidationResult = result => {
434
421
  postValidationResult(iframe, sid, result);
435
422
  };
436
-
437
423
  const wrappedOnValidateSession = (event, checkout) => {
438
424
  if (onValidateSession) {
439
425
  onValidateSession(event, checkout, submitValidationResult);
440
426
  }
441
427
  };
442
-
443
428
  const wrappedOnSessionLocked = (event, checkout) => {
444
429
  if (onSessionLocked) {
445
430
  onSessionLocked(event, checkout, refreshSession);
446
431
  }
447
- }; // Create checkout object that wraps the destroy function.
448
-
432
+ };
449
433
 
434
+ // Create checkout object that wraps the destroy function.
450
435
  checkout = {
451
436
  destroy,
452
437
  iframe,
@@ -455,8 +440,9 @@ const embed = async options => {
455
440
  refreshSession,
456
441
  setActivePaymentProductType,
457
442
  submitValidationResult
458
- }; // Add event handlers (or in some cases add a fallback href handler).
443
+ };
459
444
 
445
+ // Add event handlers (or in some cases add a fallback href handler).
460
446
  [{
461
447
  handler: setLanguage,
462
448
  eventTypes: [InternalCheckoutEvents.LanguageChanged]
@@ -512,23 +498,24 @@ const embed = async options => {
512
498
  checkout
513
499
  }));
514
500
  }
515
- }); // Add iframe to DOM
516
-
517
- await initiate(); // Return object with function to destroy the checkout.
501
+ });
518
502
 
503
+ // Add iframe to DOM
504
+ await initiate();
505
+ // Return object with function to destroy the checkout.
519
506
  return checkout;
520
507
  };
508
+
521
509
  /**
522
510
  * Redirect the customer to a payment session in the Dintero Checkout.
523
511
  */
524
-
525
512
  const redirect = options => {
526
513
  const {
527
514
  sid,
528
515
  language,
529
516
  endpoint = "https://checkout.dintero.com"
530
- } = options; // Redirect the current browser window to the checkout session url.
531
-
517
+ } = options;
518
+ // Redirect the current browser window to the checkout session url.
532
519
  windowLocationAssign(getSessionUrl({
533
520
  sid,
534
521
  endpoint,