swell-js 5.9.2 → 5.9.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/dist/api.mjs CHANGED
@@ -3,7 +3,7 @@ import { getCookie, setCookie } from './cookie.mjs';
3
3
  import methods$4 from './cache.mjs';
4
4
  import methods$3 from './cart.mjs';
5
5
  import methods$6 from './account.mjs';
6
- import { j as isFunction, l as loadScript, e as isObject, v as vaultRequest, k as isEmpty, d as defaultMethods, x as trimEnd, y as utils, z as trimStart, A as trimBoth, b as toSnake, o as base64Encode, i as isServer, t as toCamel } from './index.3949a230.mjs';
6
+ import { j as isFunction, l as loadScript, e as isObject, v as vaultRequest, k as isEmpty, d as defaultMethods, x as trimEnd, y as utils, z as trimStart, A as trimBoth, b as toSnake, o as base64Encode, i as isServer, t as toCamel } from './index.76eb52e5.mjs';
7
7
  import { Q as stringifyQuery } from './find.ba551a2e.mjs';
8
8
  import 'deepmerge';
9
9
  import 'fast-case';
@@ -455,7 +455,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
455
455
  const api = {};
456
456
 
457
457
  Object.assign(api, {
458
- version: '5.9.2',
458
+ version: '5.9.3',
459
459
  options,
460
460
  request,
461
461
 
@@ -485,6 +485,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
485
485
  options.getCart = opt.getCart;
486
486
  options.updateCart = opt.updateCart;
487
487
  options.headers = opt.headers || {};
488
+ options.getCaptchaToken = opt.getCaptchaToken;
488
489
  },
489
490
 
490
491
  // Backward compatibility
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods } from './index.3949a230.mjs';
1
+ import { d as defaultMethods } from './index.76eb52e5.mjs';
2
2
  import './find.ba551a2e.mjs';
3
3
  import './round.c68b8be5.mjs';
4
4
  import 'deepmerge';
package/dist/cache.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { s as set, m as merge, t as toCamel, a as toCamelPath } from './index.3949a230.mjs';
1
+ import { s as set, m as merge, t as toCamel, a as toCamelPath } from './index.76eb52e5.mjs';
2
2
  import { g as get } from './find.ba551a2e.mjs';
3
3
  import './round.c68b8be5.mjs';
4
4
  import 'deepmerge';
package/dist/card.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { b as toSnake, v as vaultRequest } from './index.3949a230.mjs';
1
+ import { b as toSnake, v as vaultRequest } from './index.76eb52e5.mjs';
2
2
  import './find.ba551a2e.mjs';
3
3
  import './round.c68b8be5.mjs';
4
4
  import 'deepmerge';
package/dist/cart.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import './find.ba551a2e.mjs';
2
- import { c as cloneDeep } from './index.3949a230.mjs';
2
+ import { c as cloneDeep } from './index.76eb52e5.mjs';
3
3
  import 'deepmerge';
4
4
  import 'fast-case';
5
5
  import { cleanProductOptions } from './products.mjs';
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods } from './index.3949a230.mjs';
1
+ import { d as defaultMethods } from './index.76eb52e5.mjs';
2
2
  import './find.ba551a2e.mjs';
3
3
  import './round.c68b8be5.mjs';
4
4
  import 'deepmerge';
package/dist/cookie.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as isServer } from './index.3949a230.mjs';
1
+ import { i as isServer } from './index.76eb52e5.mjs';
2
2
  import './find.ba551a2e.mjs';
3
3
  import './round.c68b8be5.mjs';
4
4
  import 'deepmerge';
@@ -1586,8 +1586,36 @@ function defaultMethods(api, uri, methods) {
1586
1586
  };
1587
1587
  }
1588
1588
 
1589
+ function isCreateIntentRequest(method, url) {
1590
+ if (String(method).toLowerCase() !== 'post') {
1591
+ return false;
1592
+ }
1593
+
1594
+ return trimEnd(trimStart(url)) === 'intent';
1595
+ }
1596
+
1597
+ // Attach a captcha token to create-intent requests. The host supplies it via
1598
+ // the getCaptchaToken option and owns the widget and token lifecycle; here we
1599
+ // only forward it, so every intent-based payment method is covered. A rejection
1600
+ // from the host (timeout / failed challenge) propagates and aborts the request.
1601
+ async function addCaptchaToken(method, url, data, options) {
1602
+ if (
1603
+ typeof options.getCaptchaToken !== 'function' ||
1604
+ !isCreateIntentRequest(method, url)
1605
+ ) {
1606
+ return data;
1607
+ }
1608
+
1609
+ const token = await options.getCaptchaToken();
1610
+
1611
+ return token ? { ...data, captcha_token: token } : data;
1612
+ }
1613
+
1589
1614
  async function vaultRequest(method, url, data, options) {
1590
1615
  const { vaultUrl, timeout, key } = options;
1616
+
1617
+ data = await addCaptchaToken(method, url, data, options);
1618
+
1591
1619
  const requestData = {
1592
1620
  $jsonp: {
1593
1621
  method,
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { default } from './api.mjs';
2
2
  import './card.mjs';
3
- import './index.3949a230.mjs';
3
+ import './index.76eb52e5.mjs';
4
4
  import './find.ba551a2e.mjs';
5
5
  import './round.c68b8be5.mjs';
6
6
  import 'deepmerge';
package/dist/payment.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import methods from './cart.mjs';
2
2
  import methods$1 from './settings.mjs';
3
- import { e as isObject, j as isFunction, l as loadScript, c as cloneDeep, v as vaultRequest, b as toSnake, p as pick, k as isEmpty, n as isLiveMode, o as base64Encode, q as getLocationParams, w as removeUrlParams, t as toCamel } from './index.3949a230.mjs';
3
+ import { e as isObject, j as isFunction, l as loadScript, c as cloneDeep, v as vaultRequest, b as toSnake, p as pick, k as isEmpty, n as isLiveMode, o as base64Encode, q as getLocationParams, w as removeUrlParams, t as toCamel } from './index.76eb52e5.mjs';
4
4
  import { g as get } from './find.ba551a2e.mjs';
5
5
  import 'deepmerge';
6
6
  import 'fast-case';
package/dist/products.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods, r as reduce, b as toSnake, t as toCamel, g as snakeCase, u as uniq, h as isEqual } from './index.3949a230.mjs';
1
+ import { d as defaultMethods, r as reduce, b as toSnake, t as toCamel, g as snakeCase, u as uniq, h as isEqual } from './index.76eb52e5.mjs';
2
2
  import methods$1 from './attributes.mjs';
3
3
  import { g as get, f as find } from './find.ba551a2e.mjs';
4
4
  import './round.c68b8be5.mjs';
package/dist/settings.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { s as set, t as toCamel, m as merge, c as cloneDeep, e as isObject, f as camelCase } from './index.3949a230.mjs';
1
+ import { s as set, t as toCamel, m as merge, c as cloneDeep, e as isObject, f as camelCase } from './index.76eb52e5.mjs';
2
2
  import { g as get, f as find } from './find.ba551a2e.mjs';
3
3
  import './round.c68b8be5.mjs';
4
4
  import 'deepmerge';
@@ -1,5 +1,5 @@
1
1
  import { cleanProductOptions } from './products.mjs';
2
- import { d as defaultMethods } from './index.3949a230.mjs';
2
+ import { d as defaultMethods } from './index.76eb52e5.mjs';
3
3
  import './attributes.mjs';
4
4
  import './find.ba551a2e.mjs';
5
5
  import './round.c68b8be5.mjs';
package/dist/swell.cjs CHANGED
@@ -4726,8 +4726,36 @@ function defaultMethods(api, uri, methods) {
4726
4726
  };
4727
4727
  }
4728
4728
 
4729
+ function isCreateIntentRequest(method, url) {
4730
+ if (String(method).toLowerCase() !== 'post') {
4731
+ return false;
4732
+ }
4733
+
4734
+ return trimEnd(trimStart(url)) === 'intent';
4735
+ }
4736
+
4737
+ // Attach a captcha token to create-intent requests. The host supplies it via
4738
+ // the getCaptchaToken option and owns the widget and token lifecycle; here we
4739
+ // only forward it, so every intent-based payment method is covered. A rejection
4740
+ // from the host (timeout / failed challenge) propagates and aborts the request.
4741
+ async function addCaptchaToken(method, url, data, options) {
4742
+ if (
4743
+ typeof options.getCaptchaToken !== 'function' ||
4744
+ !isCreateIntentRequest(method, url)
4745
+ ) {
4746
+ return data;
4747
+ }
4748
+
4749
+ const token = await options.getCaptchaToken();
4750
+
4751
+ return token ? { ...data, captcha_token: token } : data;
4752
+ }
4753
+
4729
4754
  async function vaultRequest(method, url, data, options) {
4730
4755
  const { vaultUrl, timeout, key } = options;
4756
+
4757
+ data = await addCaptchaToken(method, url, data, options);
4758
+
4731
4759
  const requestData = {
4732
4760
  $jsonp: {
4733
4761
  method,
@@ -13368,7 +13396,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
13368
13396
  const api = {};
13369
13397
 
13370
13398
  Object.assign(api, {
13371
- version: '5.9.2',
13399
+ version: '5.9.3',
13372
13400
  options,
13373
13401
  request,
13374
13402
 
@@ -13398,6 +13426,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
13398
13426
  options.getCart = opt.getCart;
13399
13427
  options.updateCart = opt.updateCart;
13400
13428
  options.headers = opt.headers || {};
13429
+ options.getCaptchaToken = opt.getCaptchaToken;
13401
13430
  },
13402
13431
 
13403
13432
  // Backward compatibility