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
package/dist/swell.cjs CHANGED
@@ -4493,8 +4493,6 @@ function isEmpty(value) {
4493
4493
 
4494
4494
  const LOADING_SCRIPTS = {};
4495
4495
 
4496
- let options = {};
4497
-
4498
4496
  function arrayMerge(target, source, options) {
4499
4497
  const destination = target.slice();
4500
4498
  source.forEach((item, index) => {
@@ -4532,14 +4530,6 @@ function merge(x, y, opt) {
4532
4530
  return deepmerge(x, y, opt);
4533
4531
  }
4534
4532
 
4535
- function setOptions(optns) {
4536
- options = optns;
4537
- }
4538
-
4539
- function getOptions() {
4540
- return options;
4541
- }
4542
-
4543
4533
  function isObject(val) {
4544
4534
  return val && typeof val === 'object' && !(val instanceof Array);
4545
4535
  }
@@ -4621,7 +4611,7 @@ function defaultMethods(api, uri, methods) {
4621
4611
  };
4622
4612
  }
4623
4613
 
4624
- async function vaultRequest(method, url, data) {
4614
+ async function vaultRequest(method, url, data, options) {
4625
4615
  const { vaultUrl, timeout, key } = options;
4626
4616
  const requestData = {
4627
4617
  $jsonp: {
@@ -4805,7 +4795,6 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4805
4795
  findIndex,
4806
4796
  get,
4807
4797
  getLocationParams,
4808
- getOptions,
4809
4798
  isEmpty,
4810
4799
  isEqual,
4811
4800
  isFunction,
@@ -4820,7 +4809,6 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4820
4809
  removeUrlParams,
4821
4810
  round: round$1,
4822
4811
  set,
4823
- setOptions,
4824
4812
  snakeCase,
4825
4813
  stringifyQuery,
4826
4814
  toCamel,
@@ -4835,171 +4823,173 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4835
4823
  vaultRequest
4836
4824
  }, Symbol.toStringTag, { value: 'Module' }));
4837
4825
 
4838
- const cardApi = {
4839
- async createToken(data) {
4840
- let error = null;
4841
- let code = null;
4842
- let param = null;
4843
- if (!data) {
4844
- error = 'Card details are missing in `swell.card.createToken(card)`';
4845
- param = '';
4846
- }
4847
- const card = toSnake(data);
4848
- if (!card.nonce) {
4849
- if (!this.validateNumber(card.number)) {
4850
- error = 'Card number appears to be invalid';
4851
- code = 'invalid_card_number';
4852
- param = 'number';
4826
+ function methods$e(options) {
4827
+ return {
4828
+ async createToken(data) {
4829
+ let error = null;
4830
+ let code = null;
4831
+ let param = null;
4832
+ if (!data) {
4833
+ error = 'Card details are missing in `swell.card.createToken(card)`';
4834
+ param = '';
4835
+ }
4836
+ const card = toSnake(data);
4837
+ if (!card.nonce) {
4838
+ if (!this.validateNumber(card.number)) {
4839
+ error = 'Card number appears to be invalid';
4840
+ code = 'invalid_card_number';
4841
+ param = 'number';
4842
+ }
4843
+ if (card.exp) {
4844
+ const exp = this.expiry(card.exp);
4845
+ card.exp_month = exp.month;
4846
+ card.exp_year = exp.year;
4847
+ }
4848
+ if (!this.validateExpiry(card.exp_month, card.exp_year)) {
4849
+ error = 'Card expiry appears to be invalid';
4850
+ code = 'invalid_card_expiry';
4851
+ param = 'exp_month';
4852
+ }
4853
+ if (!this.validateCVC(card.cvc)) {
4854
+ error = 'Card CVC code appears to be invalid';
4855
+ code = 'invalid_card_cvc';
4856
+ param = 'exp_cvc';
4857
+ }
4853
4858
  }
4854
- if (card.exp) {
4855
- const exp = this.expiry(card.exp);
4856
- card.exp_month = exp.month;
4857
- card.exp_year = exp.year;
4859
+
4860
+ if (error) {
4861
+ const err = new Error(error);
4862
+ err.code = code || 'invalid_card';
4863
+ err.status = 402;
4864
+ err.param = param;
4865
+ throw err;
4858
4866
  }
4859
- if (!this.validateExpiry(card.exp_month, card.exp_year)) {
4860
- error = 'Card expiry appears to be invalid';
4861
- code = 'invalid_card_expiry';
4862
- param = 'exp_month';
4867
+
4868
+ // Get a token from the vault
4869
+ const result = await vaultRequest('post', '/tokens', card, options);
4870
+ if (result.errors) {
4871
+ const param = Object.keys(result.errors)[0];
4872
+ const err = new Error(result.errors[param].message || 'Unknown error');
4873
+ err.code = 'vault_error';
4874
+ err.status = 402;
4875
+ err.param = param;
4876
+ throw err;
4863
4877
  }
4864
- if (!this.validateCVC(card.cvc)) {
4865
- error = 'Card CVC code appears to be invalid';
4866
- code = 'invalid_card_cvc';
4867
- param = 'exp_cvc';
4878
+ return result;
4879
+ },
4880
+
4881
+ expiry(value) {
4882
+ if (value && value.month && value.year) {
4883
+ return value;
4868
4884
  }
4869
- }
4870
4885
 
4871
- if (error) {
4872
- const err = new Error(error);
4873
- err.code = code || 'invalid_card';
4874
- err.status = 402;
4875
- err.param = param;
4876
- throw err;
4877
- }
4886
+ const parts = new String(value).split(/[\s/-]+/, 2);
4887
+ const month = parts[0];
4878
4888
 
4879
- // Get a token from the vault
4880
- const result = await vaultRequest('post', '/tokens', card);
4881
- if (result.errors) {
4882
- const param = Object.keys(result.errors)[0];
4883
- const err = new Error(result.errors[param].message || 'Unknown error');
4884
- err.code = 'vault_error';
4885
- err.status = 402;
4886
- err.param = param;
4887
- throw err;
4888
- }
4889
- return result;
4890
- },
4889
+ const currentYear = new Date().getUTCFullYear().toString();
4890
+ let strYear = parts[1];
4891
4891
 
4892
- expiry(value) {
4893
- if (value && value.month && value.year) {
4894
- return value;
4895
- }
4892
+ if (strYear.length < currentYear.length) {
4893
+ let fullYear =
4894
+ currentYear.slice(0, currentYear.length - strYear.length) + strYear;
4896
4895
 
4897
- const parts = new String(value).split(/[\s/-]+/, 2);
4898
- const month = parts[0];
4896
+ // If the expiration year is less than the current year,
4897
+ // then the expiration year is in the next century.
4898
+ if (fullYear < currentYear) {
4899
+ let year = Number(fullYear);
4900
+ year += 10 ** strYear.length;
4901
+ fullYear = year.toString();
4902
+ }
4899
4903
 
4900
- const currentYear = new Date().getUTCFullYear().toString();
4901
- let strYear = parts[1];
4904
+ strYear = fullYear;
4905
+ }
4902
4906
 
4903
- if (strYear.length < currentYear.length) {
4904
- let fullYear =
4905
- currentYear.slice(0, currentYear.length - strYear.length) + strYear;
4907
+ return {
4908
+ month: Number.parseInt(month, 10),
4909
+ year: Number.parseInt(strYear, 10),
4910
+ };
4911
+ },
4906
4912
 
4907
- // If the expiration year is less than the current year,
4908
- // then the expiration year is in the next century.
4909
- if (fullYear < currentYear) {
4910
- let year = Number(fullYear);
4911
- year += 10 ** strYear.length;
4912
- fullYear = year.toString();
4913
- }
4913
+ types() {
4914
+ let t = {};
4915
+ for (let e = 40; e <= 49; ++e) t[e] = 'Visa';
4916
+ for (let e = 50; e <= 59; ++e) t[e] = 'MasterCard';
4917
+ t[34] = t[37] = 'American Express';
4918
+ t[60] = t[62] = t[64] = t[65] = 'Discover';
4919
+ t[35] = 'JCB';
4920
+ t[30] = t[36] = t[38] = t[39] = 'Diners Club';
4921
+ return t;
4922
+ },
4914
4923
 
4915
- strYear = fullYear;
4916
- }
4924
+ type(num) {
4925
+ return this.types()[num.slice(0, 2)] || 'Unknown';
4926
+ },
4917
4927
 
4918
- return {
4919
- month: Number.parseInt(month, 10),
4920
- year: Number.parseInt(strYear, 10),
4921
- };
4922
- },
4923
-
4924
- types() {
4925
- let t = {};
4926
- for (let e = 40; e <= 49; ++e) t[e] = 'Visa';
4927
- for (let e = 50; e <= 59; ++e) t[e] = 'MasterCard';
4928
- t[34] = t[37] = 'American Express';
4929
- t[60] = t[62] = t[64] = t[65] = 'Discover';
4930
- t[35] = 'JCB';
4931
- t[30] = t[36] = t[38] = t[39] = 'Diners Club';
4932
- return t;
4933
- },
4934
-
4935
- type(num) {
4936
- return this.types()[num.slice(0, 2)] || 'Unknown';
4937
- },
4938
-
4939
- luhnCheck(num) {
4940
- const numbers = String(num);
4941
- let odd = false;
4942
- let sum = 0;
4943
-
4944
- for (let i = numbers.length - 1; i >= 0; --i) {
4945
- let digit = Number.parseInt(numbers[i], 10);
4946
-
4947
- if (odd) {
4948
- digit *= 2;
4949
-
4950
- if (digit > 9) {
4951
- digit -= 9;
4928
+ luhnCheck(num) {
4929
+ const numbers = String(num);
4930
+ let odd = false;
4931
+ let sum = 0;
4932
+
4933
+ for (let i = numbers.length - 1; i >= 0; --i) {
4934
+ let digit = Number.parseInt(numbers[i], 10);
4935
+
4936
+ if (odd) {
4937
+ digit *= 2;
4938
+
4939
+ if (digit > 9) {
4940
+ digit -= 9;
4941
+ }
4952
4942
  }
4953
- }
4954
4943
 
4955
- sum += digit;
4956
- odd = !odd;
4957
- }
4944
+ sum += digit;
4945
+ odd = !odd;
4946
+ }
4958
4947
 
4959
- return sum % 10 === 0;
4960
- },
4948
+ return sum % 10 === 0;
4949
+ },
4961
4950
 
4962
- validateNumber(num) {
4963
- num = String(num).replace(/\s+|-/g, '');
4951
+ validateNumber(num) {
4952
+ num = String(num).replace(/\s+|-/g, '');
4964
4953
 
4965
- return num.length >= 10 && num.length <= 16 && this.luhnCheck(num);
4966
- },
4954
+ return num.length >= 10 && num.length <= 16 && this.luhnCheck(num);
4955
+ },
4967
4956
 
4968
- validateExpiry(month, year) {
4969
- month = String(month).trim();
4970
- year = String(year).trim();
4957
+ validateExpiry(month, year) {
4958
+ month = String(month).trim();
4959
+ year = String(year).trim();
4971
4960
 
4972
- if (!/^\d+$/.test(month) || !/^\d+$/.test(year)) {
4973
- return false;
4974
- }
4961
+ if (!/^\d+$/.test(month) || !/^\d+$/.test(year)) {
4962
+ return false;
4963
+ }
4975
4964
 
4976
- const numMonth = Number.parseInt(month, 10);
4965
+ const numMonth = Number.parseInt(month, 10);
4977
4966
 
4978
- if (numMonth <= 0 || numMonth > 12) {
4979
- return false;
4980
- }
4967
+ if (numMonth <= 0 || numMonth > 12) {
4968
+ return false;
4969
+ }
4981
4970
 
4982
- const date = new Date(year, month);
4983
- date.setMonth(date.getMonth() - 1);
4984
- date.setMonth(date.getMonth() + 1, 1);
4971
+ const date = new Date(year, month);
4972
+ date.setMonth(date.getMonth() - 1);
4973
+ date.setMonth(date.getMonth() + 1, 1);
4985
4974
 
4986
- const diff = date.getTime() - Date.now();
4975
+ const diff = date.getTime() - Date.now();
4987
4976
 
4988
- // The card has expired
4989
- if (diff < 0) {
4990
- return false;
4991
- }
4977
+ // The card has expired
4978
+ if (diff < 0) {
4979
+ return false;
4980
+ }
4992
4981
 
4993
- // The card's validity period must not exceed 50 years from the current time.
4994
- return Math.round(diff / 31_557_600_000) < 50;
4995
- },
4982
+ // The card's validity period must not exceed 50 years from the current time.
4983
+ return Math.round(diff / 31_557_600_000) < 50;
4984
+ },
4996
4985
 
4997
- validateCVC(val) {
4998
- val = String(val).trim();
4986
+ validateCVC(val) {
4987
+ val = String(val).trim();
4999
4988
 
5000
- return /^\d+$/.test(val) && val.length >= 3 && val.length <= 4;
5001
- },
5002
- };
4989
+ return /^\d+$/.test(val) && val.length >= 3 && val.length <= 4;
4990
+ },
4991
+ };
4992
+ }
5003
4993
 
5004
4994
  const COOKIE_MAX_AGE = 604800; // 1 week
5005
4995
 
@@ -5050,191 +5040,191 @@ function setCookie(name, value, options = {}) {
5050
5040
 
5051
5041
  const RECORD_TIMEOUT = 5000;
5052
5042
 
5053
- let VALUES = {
5054
- /*
5055
- [model]: {
5056
- [id]: {
5057
- data,
5058
- record,
5059
- recordTimer,
5060
- presets,
5043
+ function methods$d(opt) {
5044
+ let VALUES = {
5045
+ /*
5046
+ [model]: {
5047
+ [id]: {
5048
+ data,
5049
+ record,
5050
+ recordTimer,
5051
+ presets,
5052
+ }
5061
5053
  }
5062
- }
5063
- */
5064
- };
5065
-
5066
- const cacheApi = {
5067
- options: {
5068
- enabled: true,
5069
- debug: false,
5070
- },
5054
+ */
5055
+ };
5071
5056
 
5072
- debug(...args) {
5073
- if (this.options.debug) {
5074
- console.log(...args);
5075
- }
5076
- },
5057
+ return {
5058
+ options: {
5059
+ enabled: true,
5060
+ debug: false,
5061
+ },
5077
5062
 
5078
- values({ model, id }, setValues = undefined) {
5079
- this.debug('cache.values', ...arguments);
5080
- if (setValues !== undefined) {
5081
- for (let key in setValues) {
5082
- set(VALUES, `${model}.${id}.${key}`, setValues[key]);
5063
+ debug(...args) {
5064
+ if (this.options.debug) {
5065
+ console.log(...args);
5083
5066
  }
5084
- return;
5085
- }
5086
- return get(VALUES, `${model}.${id}`, {});
5087
- },
5067
+ },
5088
5068
 
5089
- preset(details) {
5090
- this.debug('cache.preset', ...arguments);
5091
- const { presets = [] } = this.values(details);
5092
- presets.push(details);
5093
- this.values(details, { presets });
5094
- },
5069
+ values({ model, id }, setValues = undefined) {
5070
+ this.debug('cache.values', ...arguments);
5071
+ if (setValues !== undefined) {
5072
+ for (let key in setValues) {
5073
+ set(VALUES, `${model}.${id}.${key}`, setValues[key]);
5074
+ }
5075
+ return;
5076
+ }
5077
+ return get(VALUES, `${model}.${id}`, {});
5078
+ },
5095
5079
 
5096
- set(details) {
5097
- this.debug('cache.set', ...arguments);
5098
- let { model, id, path, value } = details;
5099
- let { data = {}, record } = this.values(details);
5080
+ preset(details) {
5081
+ this.debug('cache.preset', ...arguments);
5082
+ const { presets = [] } = this.values(details);
5083
+ presets.push(details);
5084
+ this.values(details, { presets });
5085
+ },
5100
5086
 
5101
- if (id === null) {
5102
- return;
5103
- }
5087
+ set(details) {
5088
+ this.debug('cache.set', ...arguments);
5089
+ let { model, id, path, value } = details;
5090
+ let { data = {}, record } = this.values(details);
5104
5091
 
5105
- if (record === undefined) {
5106
- return this.preset(details);
5107
- }
5092
+ if (id === null) {
5093
+ return;
5094
+ }
5108
5095
 
5109
- data = merge(record || {}, data);
5096
+ if (record === undefined) {
5097
+ return this.preset(details);
5098
+ }
5110
5099
 
5111
- const { useCamelCase } = getOptions();
5112
- if (useCamelCase && value && typeof value === 'object') {
5113
- value = toCamel(value);
5114
- }
5100
+ data = merge(record || {}, data);
5115
5101
 
5116
- if (path || value instanceof Array) {
5117
- let upData = { ...(data || {}) };
5118
- let upPath = useCamelCase ? toCamelPath(path) : path;
5119
- set(upData, upPath || '', value);
5120
- data = upData;
5121
- } else if (value && typeof value === 'object') {
5122
- data = data || {};
5123
- data = merge(data, value);
5124
- } else {
5125
- data = value;
5126
- }
5102
+ const { useCamelCase } = opt;
5103
+ if (useCamelCase && value && typeof value === 'object') {
5104
+ value = toCamel(value);
5105
+ }
5106
+
5107
+ if (path || value instanceof Array) {
5108
+ let upData = { ...(data || {}) };
5109
+ let upPath = useCamelCase ? toCamelPath(path) : path;
5110
+ set(upData, upPath || '', value);
5111
+ data = upData;
5112
+ } else if (value && typeof value === 'object') {
5113
+ data = data || {};
5114
+ data = merge(data, value);
5115
+ } else {
5116
+ data = value;
5117
+ }
5127
5118
 
5128
- this.values(details, { data });
5119
+ this.values(details, { data });
5129
5120
 
5130
- try {
5131
- // Make sure values have clean refs
5132
- const cache = VALUES[model][id];
5133
- if (cache !== undefined) {
5134
- if (cache.data !== undefined) {
5135
- cache.data = JSON.parse(JSON.stringify(cache.data));
5136
- }
5137
- if (cache.record !== undefined) {
5138
- cache.record = JSON.parse(JSON.stringify(cache.record));
5121
+ try {
5122
+ // Make sure values have clean refs
5123
+ const cache = VALUES[model][id];
5124
+ if (cache !== undefined) {
5125
+ if (cache.data !== undefined) {
5126
+ cache.data = JSON.parse(JSON.stringify(cache.data));
5127
+ }
5128
+ if (cache.record !== undefined) {
5129
+ cache.record = JSON.parse(JSON.stringify(cache.record));
5130
+ }
5139
5131
  }
5132
+ } catch (err) {
5133
+ // noop
5140
5134
  }
5141
- } catch (err) {
5142
- // noop
5143
- }
5144
- },
5135
+ },
5145
5136
 
5146
- get(model, id) {
5147
- this.debug('cache.get', ...arguments);
5148
- const { data, recordTimer } = this.values({ model, id });
5149
- this.debug('cache.get:data+recordTimer', ...arguments);
5150
- if (recordTimer) {
5151
- return data;
5152
- }
5153
- },
5137
+ get(model, id) {
5138
+ this.debug('cache.get', ...arguments);
5139
+ const { data, recordTimer } = this.values({ model, id });
5140
+ this.debug('cache.get:data+recordTimer', ...arguments);
5141
+ if (recordTimer) {
5142
+ return data;
5143
+ }
5144
+ },
5154
5145
 
5155
- setRecord(record, details) {
5156
- this.debug('cache.setRecord', ...arguments);
5157
- let { recordTimer, presets } = this.values(details);
5146
+ setRecord(record, details) {
5147
+ this.debug('cache.setRecord', ...arguments);
5148
+ let { recordTimer, presets } = this.values(details);
5158
5149
 
5159
- if (recordTimer) {
5160
- clearTimeout(recordTimer);
5161
- }
5150
+ if (recordTimer) {
5151
+ clearTimeout(recordTimer);
5152
+ }
5162
5153
 
5163
- recordTimer = setTimeout(() => {
5164
- this.values(details, { record: undefined, recordTimer: undefined });
5165
- }, RECORD_TIMEOUT);
5154
+ recordTimer = setTimeout(() => {
5155
+ this.values(details, { record: undefined, recordTimer: undefined });
5156
+ }, RECORD_TIMEOUT);
5166
5157
 
5167
- // Record has to be null at minimum, not undefined
5168
- this.values(details, {
5169
- record: record !== undefined ? record : null,
5170
- recordTimer,
5171
- });
5158
+ // Record has to be null at minimum, not undefined
5159
+ this.values(details, {
5160
+ record: record !== undefined ? record : null,
5161
+ recordTimer,
5162
+ });
5172
5163
 
5173
- if (presets) {
5174
- for (let preset of presets) {
5175
- this.set(preset);
5164
+ if (presets) {
5165
+ for (let preset of presets) {
5166
+ this.set(preset);
5167
+ }
5168
+ this.values(details, { presets: undefined });
5176
5169
  }
5177
- this.values(details, { presets: undefined });
5178
- }
5179
5170
 
5180
- const result = this.get(details.model, details.id);
5171
+ const result = this.get(details.model, details.id);
5181
5172
 
5182
- return result !== undefined ? result : record;
5183
- },
5173
+ return result !== undefined ? result : record;
5174
+ },
5184
5175
 
5185
- async getFetch(model, id, fetch) {
5186
- if (this.options.enabled) {
5187
- this.debug('cache.getFetch', ...arguments);
5188
- const value = this.get(model, id);
5176
+ async getFetch(model, id, fetch) {
5177
+ if (this.options.enabled) {
5178
+ this.debug('cache.getFetch', ...arguments);
5179
+ const value = this.get(model, id);
5189
5180
 
5190
- if (value !== undefined) {
5191
- return value;
5181
+ if (value !== undefined) {
5182
+ return value;
5183
+ }
5192
5184
  }
5193
- }
5194
5185
 
5195
- const record = await fetch();
5196
- return this.setRecord(record, { model, id });
5197
- },
5186
+ const record = await fetch();
5187
+ return this.setRecord(record, { model, id });
5188
+ },
5198
5189
 
5199
- clear(model = undefined, id = undefined) {
5200
- this.debug('cache.clear', ...arguments);
5201
- if (model) {
5202
- if (id) {
5203
- set(VALUES, `${model}.${id}`, undefined);
5190
+ clear(model = undefined, id = undefined) {
5191
+ this.debug('cache.clear', ...arguments);
5192
+ if (model) {
5193
+ if (id) {
5194
+ set(VALUES, `${model}.${id}`, undefined);
5195
+ } else {
5196
+ set(VALUES, model, undefined);
5197
+ }
5204
5198
  } else {
5205
- set(VALUES, model, undefined);
5199
+ VALUES = {};
5206
5200
  }
5207
- } else {
5208
- VALUES = {};
5209
- }
5210
- },
5211
- };
5201
+ },
5202
+ };
5203
+ }
5212
5204
 
5213
5205
  function methods$c(api) {
5214
5206
  const { get, list } = defaultMethods(api, '/attributes', ['list', 'get']);
5215
5207
 
5216
5208
  return {
5217
5209
  get: (id, ...args) => {
5218
- return cacheApi.getFetch('attributes', id, () => get(id, ...args));
5210
+ return api.cache.getFetch('attributes', id, () => get(id, ...args));
5219
5211
  },
5220
5212
 
5221
5213
  list,
5222
5214
  };
5223
5215
  }
5224
5216
 
5225
- let OPTIONS;
5226
-
5227
5217
  function methods$b(api, opt) {
5228
- OPTIONS = opt;
5229
5218
  const { get, list } = defaultMethods(api, '/products', ['list', 'get']);
5230
5219
  return {
5231
5220
  get: (id, ...args) => {
5232
- return cacheApi.getFetch('products', id, () => get(id, ...args));
5221
+ return api.cache.getFetch('products', id, () => get(id, ...args));
5233
5222
  },
5234
5223
 
5235
5224
  list,
5236
5225
 
5237
- variation: calculateVariation,
5226
+ variation: (input, options, purchaseOption) =>
5227
+ calculateVariation(input, options, purchaseOption, opt),
5238
5228
 
5239
5229
  categories: getCategories,
5240
5230
 
@@ -5314,8 +5304,8 @@ function findVariantWithOptionValueIds(product, ids) {
5314
5304
  return null;
5315
5305
  }
5316
5306
 
5317
- function calculateVariation(input, options, purchaseOption) {
5318
- const product = OPTIONS.useCamelCase ? toSnake(input) : input;
5307
+ function calculateVariation(input, options, purchaseOption, opt) {
5308
+ const product = opt.useCamelCase ? toSnake(input) : input;
5319
5309
  const purchaseOp = findPurchaseOption(product, purchaseOption);
5320
5310
  const variation = {
5321
5311
  ...product,
@@ -5378,7 +5368,7 @@ function calculateVariation(input, options, purchaseOption) {
5378
5368
  if (variation.orig_price === undefined) {
5379
5369
  delete variation.orig_price;
5380
5370
  }
5381
- return OPTIONS.useCamelCase ? toCamel(variation) : variation;
5371
+ return opt.useCamelCase ? toCamel(variation) : variation;
5382
5372
  }
5383
5373
 
5384
5374
  function findPurchaseOption(product, purchaseOption) {
@@ -5433,8 +5423,7 @@ function findPurchaseOption(product, purchaseOption) {
5433
5423
  }
5434
5424
 
5435
5425
  async function getFilterableAttributeFilters(api, products, options) {
5436
- const { results: filterableAttributes } = await methods$c(
5437
- api).list({
5426
+ const { results: filterableAttributes } = await methods$c(api).list({
5438
5427
  filterable: true,
5439
5428
  });
5440
5429
 
@@ -6041,19 +6030,29 @@ class AppPaymentComponent extends AppComponent {
6041
6030
  }
6042
6031
 
6043
6032
  #getIntent(data) {
6044
- return vaultRequest('GET', '/intent', {
6045
- gateway: this.#gateway,
6046
- account_id: this.#accountId,
6047
- intent: data,
6048
- });
6033
+ return vaultRequest(
6034
+ 'GET',
6035
+ '/intent',
6036
+ {
6037
+ gateway: this.#gateway,
6038
+ account_id: this.#accountId,
6039
+ intent: data,
6040
+ },
6041
+ this.options,
6042
+ );
6049
6043
  }
6050
6044
 
6051
6045
  #createIntent(data) {
6052
- return vaultRequest('POST', '/intent', {
6053
- gateway: this.#gateway,
6054
- account_id: this.#accountId,
6055
- intent: data,
6056
- });
6046
+ return vaultRequest(
6047
+ 'POST',
6048
+ '/intent',
6049
+ {
6050
+ gateway: this.#gateway,
6051
+ account_id: this.#accountId,
6052
+ intent: data,
6053
+ },
6054
+ this.options,
6055
+ );
6057
6056
  }
6058
6057
  }
6059
6058
 
@@ -6208,7 +6207,7 @@ function methods$8(api) {
6208
6207
 
6209
6208
  return {
6210
6209
  get: (id, ...args) => {
6211
- return cacheApi.getFetch('categories', id, () => get(id, ...args));
6210
+ return api.cache.getFetch('categories', id, () => get(id, ...args));
6212
6211
  },
6213
6212
 
6214
6213
  list,
@@ -6219,7 +6218,7 @@ function methods$7(api) {
6219
6218
  const { get, list } = defaultMethods(api, '/subscriptions', ['list', 'get']);
6220
6219
  return {
6221
6220
  get: (id, ...args) => {
6222
- return cacheApi.getFetch('subscriptions', id, () => get(id, ...args));
6221
+ return api.cache.getFetch('subscriptions', id, () => get(id, ...args));
6223
6222
  },
6224
6223
 
6225
6224
  list,
@@ -6284,7 +6283,7 @@ function methods$6(api) {
6284
6283
  const { get, list } = defaultMethods(api, '/invoices', ['list', 'get']);
6285
6284
  return {
6286
6285
  get: (id, ...args) => {
6287
- return cacheApi.getFetch('invoices', id, () => get(id, ...args));
6286
+ return api.cache.getFetch('invoices', id, () => get(id, ...args));
6288
6287
  },
6289
6288
 
6290
6289
  list,
@@ -6294,7 +6293,7 @@ function methods$6(api) {
6294
6293
  function methods$5(api, opt) {
6295
6294
  return {
6296
6295
  get: (type, id, query) => {
6297
- return cacheApi.getFetch(`content_${type}`, id, () =>
6296
+ return api.cache.getFetch(`content_${type}`, id, () =>
6298
6297
  api.request('get', `/content/${type}`, id, {
6299
6298
  $preview: opt.previewContent,
6300
6299
  ...(query || {}),
@@ -7041,7 +7040,7 @@ class Payment {
7041
7040
  * @returns {Promise<object>}
7042
7041
  */
7043
7042
  async createIntent(data) {
7044
- return vaultRequest('post', '/intent', data);
7043
+ return vaultRequest('post', '/intent', data, this.options);
7045
7044
  }
7046
7045
 
7047
7046
  /**
@@ -7051,7 +7050,7 @@ class Payment {
7051
7050
  * @returns {Promise<object>}
7052
7051
  */
7053
7052
  async updateIntent(data) {
7054
- return vaultRequest('put', '/intent', data);
7053
+ return vaultRequest('put', '/intent', data, this.options);
7055
7054
  }
7056
7055
 
7057
7056
  /**
@@ -7061,7 +7060,7 @@ class Payment {
7061
7060
  * @returns {Promise<object>}
7062
7061
  */
7063
7062
  async authorizeGateway(data) {
7064
- return vaultRequest('post', '/authorization', data);
7063
+ return vaultRequest('post', '/authorization', data, this.options);
7065
7064
  }
7066
7065
 
7067
7066
  /**
@@ -9345,7 +9344,7 @@ class BraintreeGooglePayment extends Payment {
9345
9344
 
9346
9345
  if (cart.subscription_delivery) {
9347
9346
  try {
9348
- const card = await cardApi.createToken({
9347
+ const card = await this.api.card.createToken({
9349
9348
  gateway: 'braintree',
9350
9349
  account_id: cart.account_id,
9351
9350
  nonce,
@@ -10022,7 +10021,7 @@ class BraintreeApplePayment extends Payment {
10022
10021
 
10023
10022
  if (cart.subscription_delivery) {
10024
10023
  try {
10025
- const card = await cardApi.createToken({
10024
+ const card = await this.api.card.createToken({
10026
10025
  gateway: 'braintree',
10027
10026
  account_id: cart.account_id,
10028
10027
  nonce: payload.nonce,
@@ -10928,7 +10927,7 @@ class ConvesioCardPayment extends Payment {
10928
10927
  ''
10929
10928
  ).replace(/[^0-9]+/g, '');
10930
10929
 
10931
- const cardExpiry = cardApi.expiry(
10930
+ const cardExpiry = this.api.card.expiry(
10932
10931
  this.params.exp ||
10933
10932
  document.getElementById(
10934
10933
  this.params.cardExpiry?.elementId || 'cardExpiry-element',
@@ -10952,7 +10951,7 @@ class ConvesioCardPayment extends Payment {
10952
10951
  ''
10953
10952
  ).trim();
10954
10953
 
10955
- const cardBrand = cardApi.type(cardNumber).toLowerCase();
10954
+ const cardBrand = this.api.card.type(cardNumber).toLowerCase();
10956
10955
 
10957
10956
  const payment = await createConvesioCardPaymentToken(this.method, {
10958
10957
  paymentMethod: {
@@ -12657,7 +12656,7 @@ class PaymentController {
12657
12656
  }
12658
12657
 
12659
12658
  async _vaultRequest(method, url, data) {
12660
- const response = await vaultRequest(method, url, data);
12659
+ const response = await vaultRequest(method, url, data, this.options);
12661
12660
 
12662
12661
  if (this.options.useCamelCase) {
12663
12662
  return toCamel(response);
@@ -13211,7 +13210,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
13211
13210
  const api = {};
13212
13211
 
13213
13212
  Object.assign(api, {
13214
- version: '5.8.2',
13213
+ version: '5.9.0',
13215
13214
  options,
13216
13215
  request,
13217
13216
 
@@ -13241,8 +13240,6 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
13241
13240
  options.getCart = opt.getCart;
13242
13241
  options.updateCart = opt.updateCart;
13243
13242
  options.headers = opt.headers || {};
13244
-
13245
- setOptions(options);
13246
13243
  },
13247
13244
 
13248
13245
  // Backward compatibility
@@ -13266,9 +13263,9 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
13266
13263
  return api.request('delete', url, data);
13267
13264
  },
13268
13265
 
13269
- cache: cacheApi,
13266
+ cache: methods$d(options),
13270
13267
 
13271
- card: cardApi,
13268
+ card: methods$e(options),
13272
13269
 
13273
13270
  cart: methods$a(api, options),
13274
13271
 
@@ -13302,9 +13299,13 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
13302
13299
 
13303
13300
  utils,
13304
13301
 
13305
- getCookie,
13302
+ getCookie(name) {
13303
+ return (options.getCookie || getCookie)(name);
13304
+ },
13306
13305
 
13307
- setCookie,
13306
+ setCookie(name, value, cookieOptions) {
13307
+ return (options.setCookie || setCookie)(name, value, cookieOptions);
13308
+ },
13308
13309
  });
13309
13310
 
13310
13311
  async function request(