swell-js 5.8.2 → 5.9.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 (82) hide show
  1. package/dist/api.mjs +51 -39
  2. package/dist/attributes.mjs +2 -3
  3. package/dist/cache.mjs +139 -137
  4. package/dist/card.mjs +147 -145
  5. package/dist/cart.mjs +1 -2
  6. package/dist/categories.mjs +2 -3
  7. package/dist/content.mjs +1 -9
  8. package/dist/cookie.mjs +1 -1
  9. package/dist/{index.a8d5c125.mjs → index.777df7a8.mjs} +2 -14
  10. package/dist/index.mjs +1 -1
  11. package/dist/payment.mjs +10 -12
  12. package/dist/products.mjs +8 -12
  13. package/dist/settings.mjs +1 -1
  14. package/dist/subscriptions.mjs +2 -3
  15. package/dist/swell.cjs +319 -318
  16. package/dist/swell.cjs.map +1 -1
  17. package/dist/swell.umd.min.js +318 -317
  18. package/dist/swell.umd.min.js.map +1 -1
  19. package/dist/utils/index.mjs +1 -1
  20. package/package.json +13 -6
  21. package/types/account/camel.ts +10 -7
  22. package/types/account/index.ts +3 -3
  23. package/types/account/snake.ts +5 -5
  24. package/types/attribute/camel.ts +7 -4
  25. package/types/attribute/index.ts +3 -3
  26. package/types/attribute/snake.ts +2 -2
  27. package/types/billing/camel.ts +4 -4
  28. package/types/billing/index.ts +2 -2
  29. package/types/billing/snake.ts +1 -1
  30. package/types/card/camel.ts +5 -5
  31. package/types/card/index.ts +3 -3
  32. package/types/card/snake.ts +3 -3
  33. package/types/cart/camel.ts +17 -14
  34. package/types/cart/index.ts +3 -3
  35. package/types/cart/snake.ts +12 -12
  36. package/types/category/camel.ts +4 -4
  37. package/types/category/index.ts +3 -3
  38. package/types/category/snake.ts +2 -2
  39. package/types/content/camel.ts +5 -5
  40. package/types/content/index.ts +3 -3
  41. package/types/content/snake.ts +3 -3
  42. package/types/coupon/camel.ts +4 -4
  43. package/types/coupon/index.ts +2 -2
  44. package/types/coupon/snake.ts +2 -2
  45. package/types/currency/camel.ts +2 -2
  46. package/types/currency/index.ts +3 -3
  47. package/types/discount/camel.ts +3 -3
  48. package/types/discount/index.ts +2 -2
  49. package/types/giftcard/camel.ts +10 -7
  50. package/types/giftcard/index.ts +2 -2
  51. package/types/giftcard/snake.ts +5 -5
  52. package/types/index.d.cts +207 -0
  53. package/types/index.d.ts +83 -56
  54. package/types/invoice/camel.ts +10 -10
  55. package/types/invoice/index.ts +3 -3
  56. package/types/invoice/snake.ts +8 -8
  57. package/types/order/camel.ts +18 -15
  58. package/types/order/index.ts +3 -3
  59. package/types/order/snake.ts +18 -13
  60. package/types/payment/camel.ts +13 -10
  61. package/types/payment/index.ts +3 -3
  62. package/types/payment/snake.ts +8 -8
  63. package/types/product/camel.ts +5 -5
  64. package/types/product/index.ts +4 -4
  65. package/types/product/snake.ts +3 -3
  66. package/types/promotion/camel.ts +6 -6
  67. package/types/promotion/index.ts +2 -2
  68. package/types/promotion/snake.ts +4 -4
  69. package/types/purchase_link/camel.ts +10 -7
  70. package/types/purchase_link/index.ts +2 -2
  71. package/types/purchase_link/snake.ts +5 -5
  72. package/types/refund/camel.ts +6 -6
  73. package/types/refund/index.ts +2 -2
  74. package/types/refund/snake.ts +4 -4
  75. package/types/shipment_rating/camel.ts +3 -3
  76. package/types/shipment_rating/index.ts +2 -2
  77. package/types/subscription/camel.ts +16 -13
  78. package/types/subscription/index.ts +3 -3
  79. package/types/subscription/snake.ts +16 -11
  80. package/types/user/camel.ts +2 -2
  81. package/types/user/index.ts +3 -3
  82. package/types/user/snake.ts +1 -1
@@ -9938,8 +9938,6 @@
9938
9938
 
9939
9939
  const LOADING_SCRIPTS = {};
9940
9940
 
9941
- let options = {};
9942
-
9943
9941
  function arrayMerge(target, source, options) {
9944
9942
  const destination = target.slice();
9945
9943
  source.forEach((item, index) => {
@@ -9977,14 +9975,6 @@
9977
9975
  return deepmerge$1(x, y, opt);
9978
9976
  }
9979
9977
 
9980
- function setOptions(optns) {
9981
- options = optns;
9982
- }
9983
-
9984
- function getOptions() {
9985
- return options;
9986
- }
9987
-
9988
9978
  function isObject(val) {
9989
9979
  return val && typeof val === 'object' && !(val instanceof Array);
9990
9980
  }
@@ -10066,7 +10056,7 @@
10066
10056
  };
10067
10057
  }
10068
10058
 
10069
- async function vaultRequest(method, url, data) {
10059
+ async function vaultRequest(method, url, data, options) {
10070
10060
  const { vaultUrl, timeout, key } = options;
10071
10061
  const requestData = {
10072
10062
  $jsonp: {
@@ -10250,7 +10240,6 @@
10250
10240
  findIndex: findIndex,
10251
10241
  get: get,
10252
10242
  getLocationParams: getLocationParams,
10253
- getOptions: getOptions,
10254
10243
  isEmpty: isEmpty,
10255
10244
  isEqual: isEqual,
10256
10245
  isFunction: isFunction,
@@ -10265,7 +10254,6 @@
10265
10254
  removeUrlParams: removeUrlParams,
10266
10255
  round: round$1,
10267
10256
  set: set,
10268
- setOptions: setOptions,
10269
10257
  snakeCase: snakeCase,
10270
10258
  stringifyQuery: stringifyQuery,
10271
10259
  toCamel: toCamel,
@@ -10280,171 +10268,173 @@
10280
10268
  vaultRequest: vaultRequest
10281
10269
  });
10282
10270
 
10283
- const cardApi = {
10284
- async createToken(data) {
10285
- let error = null;
10286
- let code = null;
10287
- let param = null;
10288
- if (!data) {
10289
- error = 'Card details are missing in `swell.card.createToken(card)`';
10290
- param = '';
10291
- }
10292
- const card = toSnake(data);
10293
- if (!card.nonce) {
10294
- if (!this.validateNumber(card.number)) {
10295
- error = 'Card number appears to be invalid';
10296
- code = 'invalid_card_number';
10297
- param = 'number';
10298
- }
10299
- if (card.exp) {
10300
- const exp = this.expiry(card.exp);
10301
- card.exp_month = exp.month;
10302
- card.exp_year = exp.year;
10271
+ function methods$e(options) {
10272
+ return {
10273
+ async createToken(data) {
10274
+ let error = null;
10275
+ let code = null;
10276
+ let param = null;
10277
+ if (!data) {
10278
+ error = 'Card details are missing in `swell.card.createToken(card)`';
10279
+ param = '';
10303
10280
  }
10304
- if (!this.validateExpiry(card.exp_month, card.exp_year)) {
10305
- error = 'Card expiry appears to be invalid';
10306
- code = 'invalid_card_expiry';
10307
- param = 'exp_month';
10281
+ const card = toSnake(data);
10282
+ if (!card.nonce) {
10283
+ if (!this.validateNumber(card.number)) {
10284
+ error = 'Card number appears to be invalid';
10285
+ code = 'invalid_card_number';
10286
+ param = 'number';
10287
+ }
10288
+ if (card.exp) {
10289
+ const exp = this.expiry(card.exp);
10290
+ card.exp_month = exp.month;
10291
+ card.exp_year = exp.year;
10292
+ }
10293
+ if (!this.validateExpiry(card.exp_month, card.exp_year)) {
10294
+ error = 'Card expiry appears to be invalid';
10295
+ code = 'invalid_card_expiry';
10296
+ param = 'exp_month';
10297
+ }
10298
+ if (!this.validateCVC(card.cvc)) {
10299
+ error = 'Card CVC code appears to be invalid';
10300
+ code = 'invalid_card_cvc';
10301
+ param = 'exp_cvc';
10302
+ }
10308
10303
  }
10309
- if (!this.validateCVC(card.cvc)) {
10310
- error = 'Card CVC code appears to be invalid';
10311
- code = 'invalid_card_cvc';
10312
- param = 'exp_cvc';
10304
+
10305
+ if (error) {
10306
+ const err = new Error(error);
10307
+ err.code = code || 'invalid_card';
10308
+ err.status = 402;
10309
+ err.param = param;
10310
+ throw err;
10313
10311
  }
10314
- }
10315
10312
 
10316
- if (error) {
10317
- const err = new Error(error);
10318
- err.code = code || 'invalid_card';
10319
- err.status = 402;
10320
- err.param = param;
10321
- throw err;
10322
- }
10313
+ // Get a token from the vault
10314
+ const result = await vaultRequest('post', '/tokens', card, options);
10315
+ if (result.errors) {
10316
+ const param = Object.keys(result.errors)[0];
10317
+ const err = new Error(result.errors[param].message || 'Unknown error');
10318
+ err.code = 'vault_error';
10319
+ err.status = 402;
10320
+ err.param = param;
10321
+ throw err;
10322
+ }
10323
+ return result;
10324
+ },
10323
10325
 
10324
- // Get a token from the vault
10325
- const result = await vaultRequest('post', '/tokens', card);
10326
- if (result.errors) {
10327
- const param = Object.keys(result.errors)[0];
10328
- const err = new Error(result.errors[param].message || 'Unknown error');
10329
- err.code = 'vault_error';
10330
- err.status = 402;
10331
- err.param = param;
10332
- throw err;
10333
- }
10334
- return result;
10335
- },
10326
+ expiry(value) {
10327
+ if (value && value.month && value.year) {
10328
+ return value;
10329
+ }
10336
10330
 
10337
- expiry(value) {
10338
- if (value && value.month && value.year) {
10339
- return value;
10340
- }
10331
+ const parts = new String(value).split(/[\s/-]+/, 2);
10332
+ const month = parts[0];
10341
10333
 
10342
- const parts = new String(value).split(/[\s/-]+/, 2);
10343
- const month = parts[0];
10334
+ const currentYear = new Date().getUTCFullYear().toString();
10335
+ let strYear = parts[1];
10344
10336
 
10345
- const currentYear = new Date().getUTCFullYear().toString();
10346
- let strYear = parts[1];
10337
+ if (strYear.length < currentYear.length) {
10338
+ let fullYear =
10339
+ currentYear.slice(0, currentYear.length - strYear.length) + strYear;
10347
10340
 
10348
- if (strYear.length < currentYear.length) {
10349
- let fullYear =
10350
- currentYear.slice(0, currentYear.length - strYear.length) + strYear;
10341
+ // If the expiration year is less than the current year,
10342
+ // then the expiration year is in the next century.
10343
+ if (fullYear < currentYear) {
10344
+ let year = Number(fullYear);
10345
+ year += 10 ** strYear.length;
10346
+ fullYear = year.toString();
10347
+ }
10351
10348
 
10352
- // If the expiration year is less than the current year,
10353
- // then the expiration year is in the next century.
10354
- if (fullYear < currentYear) {
10355
- let year = Number(fullYear);
10356
- year += 10 ** strYear.length;
10357
- fullYear = year.toString();
10349
+ strYear = fullYear;
10358
10350
  }
10359
10351
 
10360
- strYear = fullYear;
10361
- }
10352
+ return {
10353
+ month: Number.parseInt(month, 10),
10354
+ year: Number.parseInt(strYear, 10),
10355
+ };
10356
+ },
10362
10357
 
10363
- return {
10364
- month: Number.parseInt(month, 10),
10365
- year: Number.parseInt(strYear, 10),
10366
- };
10367
- },
10368
-
10369
- types() {
10370
- let t = {};
10371
- for (let e = 40; e <= 49; ++e) t[e] = 'Visa';
10372
- for (let e = 50; e <= 59; ++e) t[e] = 'MasterCard';
10373
- t[34] = t[37] = 'American Express';
10374
- t[60] = t[62] = t[64] = t[65] = 'Discover';
10375
- t[35] = 'JCB';
10376
- t[30] = t[36] = t[38] = t[39] = 'Diners Club';
10377
- return t;
10378
- },
10379
-
10380
- type(num) {
10381
- return this.types()[num.slice(0, 2)] || 'Unknown';
10382
- },
10383
-
10384
- luhnCheck(num) {
10385
- const numbers = String(num);
10386
- let odd = false;
10387
- let sum = 0;
10388
-
10389
- for (let i = numbers.length - 1; i >= 0; --i) {
10390
- let digit = Number.parseInt(numbers[i], 10);
10391
-
10392
- if (odd) {
10393
- digit *= 2;
10394
-
10395
- if (digit > 9) {
10396
- digit -= 9;
10358
+ types() {
10359
+ let t = {};
10360
+ for (let e = 40; e <= 49; ++e) t[e] = 'Visa';
10361
+ for (let e = 50; e <= 59; ++e) t[e] = 'MasterCard';
10362
+ t[34] = t[37] = 'American Express';
10363
+ t[60] = t[62] = t[64] = t[65] = 'Discover';
10364
+ t[35] = 'JCB';
10365
+ t[30] = t[36] = t[38] = t[39] = 'Diners Club';
10366
+ return t;
10367
+ },
10368
+
10369
+ type(num) {
10370
+ return this.types()[num.slice(0, 2)] || 'Unknown';
10371
+ },
10372
+
10373
+ luhnCheck(num) {
10374
+ const numbers = String(num);
10375
+ let odd = false;
10376
+ let sum = 0;
10377
+
10378
+ for (let i = numbers.length - 1; i >= 0; --i) {
10379
+ let digit = Number.parseInt(numbers[i], 10);
10380
+
10381
+ if (odd) {
10382
+ digit *= 2;
10383
+
10384
+ if (digit > 9) {
10385
+ digit -= 9;
10386
+ }
10397
10387
  }
10398
- }
10399
10388
 
10400
- sum += digit;
10401
- odd = !odd;
10402
- }
10389
+ sum += digit;
10390
+ odd = !odd;
10391
+ }
10403
10392
 
10404
- return sum % 10 === 0;
10405
- },
10393
+ return sum % 10 === 0;
10394
+ },
10406
10395
 
10407
- validateNumber(num) {
10408
- num = String(num).replace(/\s+|-/g, '');
10396
+ validateNumber(num) {
10397
+ num = String(num).replace(/\s+|-/g, '');
10409
10398
 
10410
- return num.length >= 10 && num.length <= 16 && this.luhnCheck(num);
10411
- },
10399
+ return num.length >= 10 && num.length <= 16 && this.luhnCheck(num);
10400
+ },
10412
10401
 
10413
- validateExpiry(month, year) {
10414
- month = String(month).trim();
10415
- year = String(year).trim();
10402
+ validateExpiry(month, year) {
10403
+ month = String(month).trim();
10404
+ year = String(year).trim();
10416
10405
 
10417
- if (!/^\d+$/.test(month) || !/^\d+$/.test(year)) {
10418
- return false;
10419
- }
10406
+ if (!/^\d+$/.test(month) || !/^\d+$/.test(year)) {
10407
+ return false;
10408
+ }
10420
10409
 
10421
- const numMonth = Number.parseInt(month, 10);
10410
+ const numMonth = Number.parseInt(month, 10);
10422
10411
 
10423
- if (numMonth <= 0 || numMonth > 12) {
10424
- return false;
10425
- }
10412
+ if (numMonth <= 0 || numMonth > 12) {
10413
+ return false;
10414
+ }
10426
10415
 
10427
- const date = new Date(year, month);
10428
- date.setMonth(date.getMonth() - 1);
10429
- date.setMonth(date.getMonth() + 1, 1);
10416
+ const date = new Date(year, month);
10417
+ date.setMonth(date.getMonth() - 1);
10418
+ date.setMonth(date.getMonth() + 1, 1);
10430
10419
 
10431
- const diff = date.getTime() - Date.now();
10420
+ const diff = date.getTime() - Date.now();
10432
10421
 
10433
- // The card has expired
10434
- if (diff < 0) {
10435
- return false;
10436
- }
10422
+ // The card has expired
10423
+ if (diff < 0) {
10424
+ return false;
10425
+ }
10437
10426
 
10438
- // The card's validity period must not exceed 50 years from the current time.
10439
- return Math.round(diff / 31_557_600_000) < 50;
10440
- },
10427
+ // The card's validity period must not exceed 50 years from the current time.
10428
+ return Math.round(diff / 31_557_600_000) < 50;
10429
+ },
10441
10430
 
10442
- validateCVC(val) {
10443
- val = String(val).trim();
10431
+ validateCVC(val) {
10432
+ val = String(val).trim();
10444
10433
 
10445
- return /^\d+$/.test(val) && val.length >= 3 && val.length <= 4;
10446
- },
10447
- };
10434
+ return /^\d+$/.test(val) && val.length >= 3 && val.length <= 4;
10435
+ },
10436
+ };
10437
+ }
10448
10438
 
10449
10439
  const COOKIE_MAX_AGE = 604800; // 1 week
10450
10440
 
@@ -10495,191 +10485,191 @@
10495
10485
 
10496
10486
  const RECORD_TIMEOUT = 5000;
10497
10487
 
10498
- let VALUES = {
10499
- /*
10500
- [model]: {
10501
- [id]: {
10502
- data,
10503
- record,
10504
- recordTimer,
10505
- presets,
10488
+ function methods$d(opt) {
10489
+ let VALUES = {
10490
+ /*
10491
+ [model]: {
10492
+ [id]: {
10493
+ data,
10494
+ record,
10495
+ recordTimer,
10496
+ presets,
10497
+ }
10506
10498
  }
10507
- }
10508
- */
10509
- };
10499
+ */
10500
+ };
10510
10501
 
10511
- const cacheApi = {
10512
- options: {
10513
- enabled: true,
10514
- debug: false,
10515
- },
10502
+ return {
10503
+ options: {
10504
+ enabled: true,
10505
+ debug: false,
10506
+ },
10516
10507
 
10517
- debug(...args) {
10518
- if (this.options.debug) {
10519
- console.log(...args);
10520
- }
10521
- },
10508
+ debug(...args) {
10509
+ if (this.options.debug) {
10510
+ console.log(...args);
10511
+ }
10512
+ },
10522
10513
 
10523
- values({ model, id }, setValues = undefined) {
10524
- this.debug('cache.values', ...arguments);
10525
- if (setValues !== undefined) {
10526
- for (let key in setValues) {
10527
- set(VALUES, `${model}.${id}.${key}`, setValues[key]);
10514
+ values({ model, id }, setValues = undefined) {
10515
+ this.debug('cache.values', ...arguments);
10516
+ if (setValues !== undefined) {
10517
+ for (let key in setValues) {
10518
+ set(VALUES, `${model}.${id}.${key}`, setValues[key]);
10519
+ }
10520
+ return;
10528
10521
  }
10529
- return;
10530
- }
10531
- return get(VALUES, `${model}.${id}`, {});
10532
- },
10522
+ return get(VALUES, `${model}.${id}`, {});
10523
+ },
10533
10524
 
10534
- preset(details) {
10535
- this.debug('cache.preset', ...arguments);
10536
- const { presets = [] } = this.values(details);
10537
- presets.push(details);
10538
- this.values(details, { presets });
10539
- },
10525
+ preset(details) {
10526
+ this.debug('cache.preset', ...arguments);
10527
+ const { presets = [] } = this.values(details);
10528
+ presets.push(details);
10529
+ this.values(details, { presets });
10530
+ },
10540
10531
 
10541
- set(details) {
10542
- this.debug('cache.set', ...arguments);
10543
- let { model, id, path, value } = details;
10544
- let { data = {}, record } = this.values(details);
10532
+ set(details) {
10533
+ this.debug('cache.set', ...arguments);
10534
+ let { model, id, path, value } = details;
10535
+ let { data = {}, record } = this.values(details);
10545
10536
 
10546
- if (id === null) {
10547
- return;
10548
- }
10537
+ if (id === null) {
10538
+ return;
10539
+ }
10549
10540
 
10550
- if (record === undefined) {
10551
- return this.preset(details);
10552
- }
10541
+ if (record === undefined) {
10542
+ return this.preset(details);
10543
+ }
10553
10544
 
10554
- data = merge(record || {}, data);
10545
+ data = merge(record || {}, data);
10555
10546
 
10556
- const { useCamelCase } = getOptions();
10557
- if (useCamelCase && value && typeof value === 'object') {
10558
- value = toCamel(value);
10559
- }
10547
+ const { useCamelCase } = opt;
10548
+ if (useCamelCase && value && typeof value === 'object') {
10549
+ value = toCamel(value);
10550
+ }
10560
10551
 
10561
- if (path || value instanceof Array) {
10562
- let upData = { ...(data || {}) };
10563
- let upPath = useCamelCase ? toCamelPath(path) : path;
10564
- set(upData, upPath || '', value);
10565
- data = upData;
10566
- } else if (value && typeof value === 'object') {
10567
- data = data || {};
10568
- data = merge(data, value);
10569
- } else {
10570
- data = value;
10571
- }
10552
+ if (path || value instanceof Array) {
10553
+ let upData = { ...(data || {}) };
10554
+ let upPath = useCamelCase ? toCamelPath(path) : path;
10555
+ set(upData, upPath || '', value);
10556
+ data = upData;
10557
+ } else if (value && typeof value === 'object') {
10558
+ data = data || {};
10559
+ data = merge(data, value);
10560
+ } else {
10561
+ data = value;
10562
+ }
10572
10563
 
10573
- this.values(details, { data });
10564
+ this.values(details, { data });
10574
10565
 
10575
- try {
10576
- // Make sure values have clean refs
10577
- const cache = VALUES[model][id];
10578
- if (cache !== undefined) {
10579
- if (cache.data !== undefined) {
10580
- cache.data = JSON.parse(JSON.stringify(cache.data));
10581
- }
10582
- if (cache.record !== undefined) {
10583
- cache.record = JSON.parse(JSON.stringify(cache.record));
10566
+ try {
10567
+ // Make sure values have clean refs
10568
+ const cache = VALUES[model][id];
10569
+ if (cache !== undefined) {
10570
+ if (cache.data !== undefined) {
10571
+ cache.data = JSON.parse(JSON.stringify(cache.data));
10572
+ }
10573
+ if (cache.record !== undefined) {
10574
+ cache.record = JSON.parse(JSON.stringify(cache.record));
10575
+ }
10584
10576
  }
10577
+ } catch (err) {
10578
+ // noop
10585
10579
  }
10586
- } catch (err) {
10587
- // noop
10588
- }
10589
- },
10580
+ },
10590
10581
 
10591
- get(model, id) {
10592
- this.debug('cache.get', ...arguments);
10593
- const { data, recordTimer } = this.values({ model, id });
10594
- this.debug('cache.get:data+recordTimer', ...arguments);
10595
- if (recordTimer) {
10596
- return data;
10597
- }
10598
- },
10582
+ get(model, id) {
10583
+ this.debug('cache.get', ...arguments);
10584
+ const { data, recordTimer } = this.values({ model, id });
10585
+ this.debug('cache.get:data+recordTimer', ...arguments);
10586
+ if (recordTimer) {
10587
+ return data;
10588
+ }
10589
+ },
10599
10590
 
10600
- setRecord(record, details) {
10601
- this.debug('cache.setRecord', ...arguments);
10602
- let { recordTimer, presets } = this.values(details);
10591
+ setRecord(record, details) {
10592
+ this.debug('cache.setRecord', ...arguments);
10593
+ let { recordTimer, presets } = this.values(details);
10603
10594
 
10604
- if (recordTimer) {
10605
- clearTimeout(recordTimer);
10606
- }
10595
+ if (recordTimer) {
10596
+ clearTimeout(recordTimer);
10597
+ }
10607
10598
 
10608
- recordTimer = setTimeout(() => {
10609
- this.values(details, { record: undefined, recordTimer: undefined });
10610
- }, RECORD_TIMEOUT);
10599
+ recordTimer = setTimeout(() => {
10600
+ this.values(details, { record: undefined, recordTimer: undefined });
10601
+ }, RECORD_TIMEOUT);
10611
10602
 
10612
- // Record has to be null at minimum, not undefined
10613
- this.values(details, {
10614
- record: record !== undefined ? record : null,
10615
- recordTimer,
10616
- });
10603
+ // Record has to be null at minimum, not undefined
10604
+ this.values(details, {
10605
+ record: record !== undefined ? record : null,
10606
+ recordTimer,
10607
+ });
10617
10608
 
10618
- if (presets) {
10619
- for (let preset of presets) {
10620
- this.set(preset);
10609
+ if (presets) {
10610
+ for (let preset of presets) {
10611
+ this.set(preset);
10612
+ }
10613
+ this.values(details, { presets: undefined });
10621
10614
  }
10622
- this.values(details, { presets: undefined });
10623
- }
10624
10615
 
10625
- const result = this.get(details.model, details.id);
10616
+ const result = this.get(details.model, details.id);
10626
10617
 
10627
- return result !== undefined ? result : record;
10628
- },
10618
+ return result !== undefined ? result : record;
10619
+ },
10629
10620
 
10630
- async getFetch(model, id, fetch) {
10631
- if (this.options.enabled) {
10632
- this.debug('cache.getFetch', ...arguments);
10633
- const value = this.get(model, id);
10621
+ async getFetch(model, id, fetch) {
10622
+ if (this.options.enabled) {
10623
+ this.debug('cache.getFetch', ...arguments);
10624
+ const value = this.get(model, id);
10634
10625
 
10635
- if (value !== undefined) {
10636
- return value;
10626
+ if (value !== undefined) {
10627
+ return value;
10628
+ }
10637
10629
  }
10638
- }
10639
10630
 
10640
- const record = await fetch();
10641
- return this.setRecord(record, { model, id });
10642
- },
10631
+ const record = await fetch();
10632
+ return this.setRecord(record, { model, id });
10633
+ },
10643
10634
 
10644
- clear(model = undefined, id = undefined) {
10645
- this.debug('cache.clear', ...arguments);
10646
- if (model) {
10647
- if (id) {
10648
- set(VALUES, `${model}.${id}`, undefined);
10635
+ clear(model = undefined, id = undefined) {
10636
+ this.debug('cache.clear', ...arguments);
10637
+ if (model) {
10638
+ if (id) {
10639
+ set(VALUES, `${model}.${id}`, undefined);
10640
+ } else {
10641
+ set(VALUES, model, undefined);
10642
+ }
10649
10643
  } else {
10650
- set(VALUES, model, undefined);
10644
+ VALUES = {};
10651
10645
  }
10652
- } else {
10653
- VALUES = {};
10654
- }
10655
- },
10656
- };
10646
+ },
10647
+ };
10648
+ }
10657
10649
 
10658
10650
  function methods$c(api) {
10659
10651
  const { get, list } = defaultMethods(api, '/attributes', ['list', 'get']);
10660
10652
 
10661
10653
  return {
10662
10654
  get: (id, ...args) => {
10663
- return cacheApi.getFetch('attributes', id, () => get(id, ...args));
10655
+ return api.cache.getFetch('attributes', id, () => get(id, ...args));
10664
10656
  },
10665
10657
 
10666
10658
  list,
10667
10659
  };
10668
10660
  }
10669
10661
 
10670
- let OPTIONS;
10671
-
10672
10662
  function methods$b(api, opt) {
10673
- OPTIONS = opt;
10674
10663
  const { get, list } = defaultMethods(api, '/products', ['list', 'get']);
10675
10664
  return {
10676
10665
  get: (id, ...args) => {
10677
- return cacheApi.getFetch('products', id, () => get(id, ...args));
10666
+ return api.cache.getFetch('products', id, () => get(id, ...args));
10678
10667
  },
10679
10668
 
10680
10669
  list,
10681
10670
 
10682
- variation: calculateVariation,
10671
+ variation: (input, options, purchaseOption) =>
10672
+ calculateVariation(input, options, purchaseOption, opt),
10683
10673
 
10684
10674
  categories: getCategories,
10685
10675
 
@@ -10759,8 +10749,8 @@
10759
10749
  return null;
10760
10750
  }
10761
10751
 
10762
- function calculateVariation(input, options, purchaseOption) {
10763
- const product = OPTIONS.useCamelCase ? toSnake(input) : input;
10752
+ function calculateVariation(input, options, purchaseOption, opt) {
10753
+ const product = opt.useCamelCase ? toSnake(input) : input;
10764
10754
  const purchaseOp = findPurchaseOption(product, purchaseOption);
10765
10755
  const variation = {
10766
10756
  ...product,
@@ -10823,7 +10813,7 @@
10823
10813
  if (variation.orig_price === undefined) {
10824
10814
  delete variation.orig_price;
10825
10815
  }
10826
- return OPTIONS.useCamelCase ? toCamel(variation) : variation;
10816
+ return opt.useCamelCase ? toCamel(variation) : variation;
10827
10817
  }
10828
10818
 
10829
10819
  function findPurchaseOption(product, purchaseOption) {
@@ -10878,8 +10868,7 @@
10878
10868
  }
10879
10869
 
10880
10870
  async function getFilterableAttributeFilters(api, products, options) {
10881
- const { results: filterableAttributes } = await methods$c(
10882
- api).list({
10871
+ const { results: filterableAttributes } = await methods$c(api).list({
10883
10872
  filterable: true,
10884
10873
  });
10885
10874
 
@@ -11486,19 +11475,29 @@
11486
11475
  }
11487
11476
 
11488
11477
  #getIntent(data) {
11489
- return vaultRequest('GET', '/intent', {
11490
- gateway: this.#gateway,
11491
- account_id: this.#accountId,
11492
- intent: data,
11493
- });
11478
+ return vaultRequest(
11479
+ 'GET',
11480
+ '/intent',
11481
+ {
11482
+ gateway: this.#gateway,
11483
+ account_id: this.#accountId,
11484
+ intent: data,
11485
+ },
11486
+ this.options,
11487
+ );
11494
11488
  }
11495
11489
 
11496
11490
  #createIntent(data) {
11497
- return vaultRequest('POST', '/intent', {
11498
- gateway: this.#gateway,
11499
- account_id: this.#accountId,
11500
- intent: data,
11501
- });
11491
+ return vaultRequest(
11492
+ 'POST',
11493
+ '/intent',
11494
+ {
11495
+ gateway: this.#gateway,
11496
+ account_id: this.#accountId,
11497
+ intent: data,
11498
+ },
11499
+ this.options,
11500
+ );
11502
11501
  }
11503
11502
  }
11504
11503
 
@@ -11653,7 +11652,7 @@
11653
11652
 
11654
11653
  return {
11655
11654
  get: (id, ...args) => {
11656
- return cacheApi.getFetch('categories', id, () => get(id, ...args));
11655
+ return api.cache.getFetch('categories', id, () => get(id, ...args));
11657
11656
  },
11658
11657
 
11659
11658
  list,
@@ -11664,7 +11663,7 @@
11664
11663
  const { get, list } = defaultMethods(api, '/subscriptions', ['list', 'get']);
11665
11664
  return {
11666
11665
  get: (id, ...args) => {
11667
- return cacheApi.getFetch('subscriptions', id, () => get(id, ...args));
11666
+ return api.cache.getFetch('subscriptions', id, () => get(id, ...args));
11668
11667
  },
11669
11668
 
11670
11669
  list,
@@ -11729,7 +11728,7 @@
11729
11728
  const { get, list } = defaultMethods(api, '/invoices', ['list', 'get']);
11730
11729
  return {
11731
11730
  get: (id, ...args) => {
11732
- return cacheApi.getFetch('invoices', id, () => get(id, ...args));
11731
+ return api.cache.getFetch('invoices', id, () => get(id, ...args));
11733
11732
  },
11734
11733
 
11735
11734
  list,
@@ -11739,7 +11738,7 @@
11739
11738
  function methods$5(api, opt) {
11740
11739
  return {
11741
11740
  get: (type, id, query) => {
11742
- return cacheApi.getFetch(`content_${type}`, id, () =>
11741
+ return api.cache.getFetch(`content_${type}`, id, () =>
11743
11742
  api.request('get', `/content/${type}`, id, {
11744
11743
  $preview: opt.previewContent,
11745
11744
  ...(query || {}),
@@ -12486,7 +12485,7 @@
12486
12485
  * @returns {Promise<object>}
12487
12486
  */
12488
12487
  async createIntent(data) {
12489
- return vaultRequest('post', '/intent', data);
12488
+ return vaultRequest('post', '/intent', data, this.options);
12490
12489
  }
12491
12490
 
12492
12491
  /**
@@ -12496,7 +12495,7 @@
12496
12495
  * @returns {Promise<object>}
12497
12496
  */
12498
12497
  async updateIntent(data) {
12499
- return vaultRequest('put', '/intent', data);
12498
+ return vaultRequest('put', '/intent', data, this.options);
12500
12499
  }
12501
12500
 
12502
12501
  /**
@@ -12506,7 +12505,7 @@
12506
12505
  * @returns {Promise<object>}
12507
12506
  */
12508
12507
  async authorizeGateway(data) {
12509
- return vaultRequest('post', '/authorization', data);
12508
+ return vaultRequest('post', '/authorization', data, this.options);
12510
12509
  }
12511
12510
 
12512
12511
  /**
@@ -14790,7 +14789,7 @@
14790
14789
 
14791
14790
  if (cart.subscription_delivery) {
14792
14791
  try {
14793
- const card = await cardApi.createToken({
14792
+ const card = await this.api.card.createToken({
14794
14793
  gateway: 'braintree',
14795
14794
  account_id: cart.account_id,
14796
14795
  nonce,
@@ -15467,7 +15466,7 @@
15467
15466
 
15468
15467
  if (cart.subscription_delivery) {
15469
15468
  try {
15470
- const card = await cardApi.createToken({
15469
+ const card = await this.api.card.createToken({
15471
15470
  gateway: 'braintree',
15472
15471
  account_id: cart.account_id,
15473
15472
  nonce: payload.nonce,
@@ -16373,7 +16372,7 @@
16373
16372
  ''
16374
16373
  ).replace(/[^0-9]+/g, '');
16375
16374
 
16376
- const cardExpiry = cardApi.expiry(
16375
+ const cardExpiry = this.api.card.expiry(
16377
16376
  this.params.exp ||
16378
16377
  document.getElementById(
16379
16378
  this.params.cardExpiry?.elementId || 'cardExpiry-element',
@@ -16397,7 +16396,7 @@
16397
16396
  ''
16398
16397
  ).trim();
16399
16398
 
16400
- const cardBrand = cardApi.type(cardNumber).toLowerCase();
16399
+ const cardBrand = this.api.card.type(cardNumber).toLowerCase();
16401
16400
 
16402
16401
  const payment = await createConvesioCardPaymentToken(this.method, {
16403
16402
  paymentMethod: {
@@ -18102,7 +18101,7 @@
18102
18101
  }
18103
18102
 
18104
18103
  async _vaultRequest(method, url, data) {
18105
- const response = await vaultRequest(method, url, data);
18104
+ const response = await vaultRequest(method, url, data, this.options);
18106
18105
 
18107
18106
  if (this.options.useCamelCase) {
18108
18107
  return toCamel(response);
@@ -18656,7 +18655,7 @@
18656
18655
  const api = {};
18657
18656
 
18658
18657
  Object.assign(api, {
18659
- version: '5.8.2',
18658
+ version: '5.9.0',
18660
18659
  options,
18661
18660
  request,
18662
18661
 
@@ -18686,8 +18685,6 @@
18686
18685
  options.getCart = opt.getCart;
18687
18686
  options.updateCart = opt.updateCart;
18688
18687
  options.headers = opt.headers || {};
18689
-
18690
- setOptions(options);
18691
18688
  },
18692
18689
 
18693
18690
  // Backward compatibility
@@ -18711,9 +18708,9 @@
18711
18708
  return api.request('delete', url, data);
18712
18709
  },
18713
18710
 
18714
- cache: cacheApi,
18711
+ cache: methods$d(options),
18715
18712
 
18716
- card: cardApi,
18713
+ card: methods$e(options),
18717
18714
 
18718
18715
  cart: methods$a(api, options),
18719
18716
 
@@ -18747,9 +18744,13 @@
18747
18744
 
18748
18745
  utils,
18749
18746
 
18750
- getCookie,
18747
+ getCookie(name) {
18748
+ return (options.getCookie || getCookie)(name);
18749
+ },
18751
18750
 
18752
- setCookie,
18751
+ setCookie(name, value, cookieOptions) {
18752
+ return (options.setCookie || setCookie)(name, value, cookieOptions);
18753
+ },
18753
18754
  });
18754
18755
 
18755
18756
  async function request(