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.
@@ -4871,8 +4871,36 @@
4871
4871
  };
4872
4872
  }
4873
4873
 
4874
+ function isCreateIntentRequest(method, url) {
4875
+ if (String(method).toLowerCase() !== 'post') {
4876
+ return false;
4877
+ }
4878
+
4879
+ return trimEnd(trimStart(url)) === 'intent';
4880
+ }
4881
+
4882
+ // Attach a captcha token to create-intent requests. The host supplies it via
4883
+ // the getCaptchaToken option and owns the widget and token lifecycle; here we
4884
+ // only forward it, so every intent-based payment method is covered. A rejection
4885
+ // from the host (timeout / failed challenge) propagates and aborts the request.
4886
+ async function addCaptchaToken(method, url, data, options) {
4887
+ if (
4888
+ typeof options.getCaptchaToken !== 'function' ||
4889
+ !isCreateIntentRequest(method, url)
4890
+ ) {
4891
+ return data;
4892
+ }
4893
+
4894
+ const token = await options.getCaptchaToken();
4895
+
4896
+ return token ? { ...data, captcha_token: token } : data;
4897
+ }
4898
+
4874
4899
  async function vaultRequest(method, url, data, options) {
4875
4900
  const { vaultUrl, timeout, key } = options;
4901
+
4902
+ data = await addCaptchaToken(method, url, data, options);
4903
+
4876
4904
  const requestData = {
4877
4905
  $jsonp: {
4878
4906
  method,
@@ -13513,7 +13541,7 @@
13513
13541
  const api = {};
13514
13542
 
13515
13543
  Object.assign(api, {
13516
- version: '5.9.2',
13544
+ version: '5.9.3',
13517
13545
  options,
13518
13546
  request,
13519
13547
 
@@ -13543,6 +13571,7 @@
13543
13571
  options.getCart = opt.getCart;
13544
13572
  options.updateCart = opt.updateCart;
13545
13573
  options.headers = opt.headers || {};
13574
+ options.getCaptchaToken = opt.getCaptchaToken;
13546
13575
  },
13547
13576
 
13548
13577
  // Backward compatibility