swell-js 5.8.1 → 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 +296 -118
  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 +605 -424
  16. package/dist/swell.cjs.map +1 -1
  17. package/dist/swell.umd.min.js +604 -423
  18. package/dist/swell.umd.min.js.map +1 -1
  19. package/dist/utils/index.mjs +1 -1
  20. package/package.json +14 -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 +9 -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/card.mjs CHANGED
@@ -1,174 +1,176 @@
1
- import { t as toSnake, v as vaultRequest } from './index.a8d5c125.mjs';
1
+ import { b as toSnake, v as vaultRequest } from './index.777df7a8.mjs';
2
2
  import 'qs';
3
3
  import './find.18f1ac6d.mjs';
4
4
  import './round.577a8441.mjs';
5
5
  import 'deepmerge';
6
6
  import 'fast-case';
7
7
 
8
- const cardApi = {
9
- async createToken(data) {
10
- let error = null;
11
- let code = null;
12
- let param = null;
13
- if (!data) {
14
- error = 'Card details are missing in `swell.card.createToken(card)`';
15
- param = '';
16
- }
17
- const card = toSnake(data);
18
- if (!card.nonce) {
19
- if (!this.validateNumber(card.number)) {
20
- error = 'Card number appears to be invalid';
21
- code = 'invalid_card_number';
22
- param = 'number';
8
+ function methods(options) {
9
+ return {
10
+ async createToken(data) {
11
+ let error = null;
12
+ let code = null;
13
+ let param = null;
14
+ if (!data) {
15
+ error = 'Card details are missing in `swell.card.createToken(card)`';
16
+ param = '';
23
17
  }
24
- if (card.exp) {
25
- const exp = this.expiry(card.exp);
26
- card.exp_month = exp.month;
27
- card.exp_year = exp.year;
18
+ const card = toSnake(data);
19
+ if (!card.nonce) {
20
+ if (!this.validateNumber(card.number)) {
21
+ error = 'Card number appears to be invalid';
22
+ code = 'invalid_card_number';
23
+ param = 'number';
24
+ }
25
+ if (card.exp) {
26
+ const exp = this.expiry(card.exp);
27
+ card.exp_month = exp.month;
28
+ card.exp_year = exp.year;
29
+ }
30
+ if (!this.validateExpiry(card.exp_month, card.exp_year)) {
31
+ error = 'Card expiry appears to be invalid';
32
+ code = 'invalid_card_expiry';
33
+ param = 'exp_month';
34
+ }
35
+ if (!this.validateCVC(card.cvc)) {
36
+ error = 'Card CVC code appears to be invalid';
37
+ code = 'invalid_card_cvc';
38
+ param = 'exp_cvc';
39
+ }
28
40
  }
29
- if (!this.validateExpiry(card.exp_month, card.exp_year)) {
30
- error = 'Card expiry appears to be invalid';
31
- code = 'invalid_card_expiry';
32
- param = 'exp_month';
41
+
42
+ if (error) {
43
+ const err = new Error(error);
44
+ err.code = code || 'invalid_card';
45
+ err.status = 402;
46
+ err.param = param;
47
+ throw err;
33
48
  }
34
- if (!this.validateCVC(card.cvc)) {
35
- error = 'Card CVC code appears to be invalid';
36
- code = 'invalid_card_cvc';
37
- param = 'exp_cvc';
49
+
50
+ // Get a token from the vault
51
+ const result = await vaultRequest('post', '/tokens', card, options);
52
+ if (result.errors) {
53
+ const param = Object.keys(result.errors)[0];
54
+ const err = new Error(result.errors[param].message || 'Unknown error');
55
+ err.code = 'vault_error';
56
+ err.status = 402;
57
+ err.param = param;
58
+ throw err;
38
59
  }
39
- }
40
-
41
- if (error) {
42
- const err = new Error(error);
43
- err.code = code || 'invalid_card';
44
- err.status = 402;
45
- err.param = param;
46
- throw err;
47
- }
48
-
49
- // Get a token from the vault
50
- const result = await vaultRequest('post', '/tokens', card);
51
- if (result.errors) {
52
- const param = Object.keys(result.errors)[0];
53
- const err = new Error(result.errors[param].message || 'Unknown error');
54
- err.code = 'vault_error';
55
- err.status = 402;
56
- err.param = param;
57
- throw err;
58
- }
59
- return result;
60
- },
61
-
62
- expiry(value) {
63
- if (value && value.month && value.year) {
64
- return value;
65
- }
66
-
67
- const parts = new String(value).split(/[\s/-]+/, 2);
68
- const month = parts[0];
69
-
70
- const currentYear = new Date().getUTCFullYear().toString();
71
- let strYear = parts[1];
72
-
73
- if (strYear.length < currentYear.length) {
74
- let fullYear =
75
- currentYear.slice(0, currentYear.length - strYear.length) + strYear;
76
-
77
- // If the expiration year is less than the current year,
78
- // then the expiration year is in the next century.
79
- if (fullYear < currentYear) {
80
- let year = Number(fullYear);
81
- year += 10 ** strYear.length;
82
- fullYear = year.toString();
60
+ return result;
61
+ },
62
+
63
+ expiry(value) {
64
+ if (value && value.month && value.year) {
65
+ return value;
83
66
  }
84
67
 
85
- strYear = fullYear;
86
- }
87
-
88
- return {
89
- month: Number.parseInt(month, 10),
90
- year: Number.parseInt(strYear, 10),
91
- };
92
- },
93
-
94
- types() {
95
- let t = {};
96
- for (let e = 40; e <= 49; ++e) t[e] = 'Visa';
97
- for (let e = 50; e <= 59; ++e) t[e] = 'MasterCard';
98
- t[34] = t[37] = 'American Express';
99
- t[60] = t[62] = t[64] = t[65] = 'Discover';
100
- t[35] = 'JCB';
101
- t[30] = t[36] = t[38] = t[39] = 'Diners Club';
102
- return t;
103
- },
104
-
105
- type(num) {
106
- return this.types()[num.slice(0, 2)] || 'Unknown';
107
- },
108
-
109
- luhnCheck(num) {
110
- const numbers = String(num);
111
- let odd = false;
112
- let sum = 0;
113
-
114
- for (let i = numbers.length - 1; i >= 0; --i) {
115
- let digit = Number.parseInt(numbers[i], 10);
116
-
117
- if (odd) {
118
- digit *= 2;
119
-
120
- if (digit > 9) {
121
- digit -= 9;
68
+ const parts = new String(value).split(/[\s/-]+/, 2);
69
+ const month = parts[0];
70
+
71
+ const currentYear = new Date().getUTCFullYear().toString();
72
+ let strYear = parts[1];
73
+
74
+ if (strYear.length < currentYear.length) {
75
+ let fullYear =
76
+ currentYear.slice(0, currentYear.length - strYear.length) + strYear;
77
+
78
+ // If the expiration year is less than the current year,
79
+ // then the expiration year is in the next century.
80
+ if (fullYear < currentYear) {
81
+ let year = Number(fullYear);
82
+ year += 10 ** strYear.length;
83
+ fullYear = year.toString();
122
84
  }
85
+
86
+ strYear = fullYear;
123
87
  }
124
88
 
125
- sum += digit;
126
- odd = !odd;
127
- }
89
+ return {
90
+ month: Number.parseInt(month, 10),
91
+ year: Number.parseInt(strYear, 10),
92
+ };
93
+ },
94
+
95
+ types() {
96
+ let t = {};
97
+ for (let e = 40; e <= 49; ++e) t[e] = 'Visa';
98
+ for (let e = 50; e <= 59; ++e) t[e] = 'MasterCard';
99
+ t[34] = t[37] = 'American Express';
100
+ t[60] = t[62] = t[64] = t[65] = 'Discover';
101
+ t[35] = 'JCB';
102
+ t[30] = t[36] = t[38] = t[39] = 'Diners Club';
103
+ return t;
104
+ },
105
+
106
+ type(num) {
107
+ return this.types()[num.slice(0, 2)] || 'Unknown';
108
+ },
109
+
110
+ luhnCheck(num) {
111
+ const numbers = String(num);
112
+ let odd = false;
113
+ let sum = 0;
114
+
115
+ for (let i = numbers.length - 1; i >= 0; --i) {
116
+ let digit = Number.parseInt(numbers[i], 10);
117
+
118
+ if (odd) {
119
+ digit *= 2;
120
+
121
+ if (digit > 9) {
122
+ digit -= 9;
123
+ }
124
+ }
125
+
126
+ sum += digit;
127
+ odd = !odd;
128
+ }
128
129
 
129
- return sum % 10 === 0;
130
- },
130
+ return sum % 10 === 0;
131
+ },
131
132
 
132
- validateNumber(num) {
133
- num = String(num).replace(/\s+|-/g, '');
133
+ validateNumber(num) {
134
+ num = String(num).replace(/\s+|-/g, '');
134
135
 
135
- return num.length >= 10 && num.length <= 16 && this.luhnCheck(num);
136
- },
136
+ return num.length >= 10 && num.length <= 16 && this.luhnCheck(num);
137
+ },
137
138
 
138
- validateExpiry(month, year) {
139
- month = String(month).trim();
140
- year = String(year).trim();
139
+ validateExpiry(month, year) {
140
+ month = String(month).trim();
141
+ year = String(year).trim();
141
142
 
142
- if (!/^\d+$/.test(month) || !/^\d+$/.test(year)) {
143
- return false;
144
- }
143
+ if (!/^\d+$/.test(month) || !/^\d+$/.test(year)) {
144
+ return false;
145
+ }
145
146
 
146
- const numMonth = Number.parseInt(month, 10);
147
+ const numMonth = Number.parseInt(month, 10);
147
148
 
148
- if (numMonth <= 0 || numMonth > 12) {
149
- return false;
150
- }
149
+ if (numMonth <= 0 || numMonth > 12) {
150
+ return false;
151
+ }
151
152
 
152
- const date = new Date(year, month);
153
- date.setMonth(date.getMonth() - 1);
154
- date.setMonth(date.getMonth() + 1, 1);
153
+ const date = new Date(year, month);
154
+ date.setMonth(date.getMonth() - 1);
155
+ date.setMonth(date.getMonth() + 1, 1);
155
156
 
156
- const diff = date.getTime() - Date.now();
157
+ const diff = date.getTime() - Date.now();
157
158
 
158
- // The card has expired
159
- if (diff < 0) {
160
- return false;
161
- }
159
+ // The card has expired
160
+ if (diff < 0) {
161
+ return false;
162
+ }
162
163
 
163
- // The card's validity period must not exceed 50 years from the current time.
164
- return Math.round(diff / 31_557_600_000) < 50;
165
- },
164
+ // The card's validity period must not exceed 50 years from the current time.
165
+ return Math.round(diff / 31_557_600_000) < 50;
166
+ },
166
167
 
167
- validateCVC(val) {
168
- val = String(val).trim();
168
+ validateCVC(val) {
169
+ val = String(val).trim();
169
170
 
170
- return /^\d+$/.test(val) && val.length >= 3 && val.length <= 4;
171
- },
172
- };
171
+ return /^\d+$/.test(val) && val.length >= 3 && val.length <= 4;
172
+ },
173
+ };
174
+ }
173
175
 
174
- export { cardApi as default };
176
+ export { methods as default };
package/dist/cart.mjs CHANGED
@@ -1,11 +1,10 @@
1
1
  import 'qs';
2
- import { c as cloneDeep } from './index.a8d5c125.mjs';
2
+ import { c as cloneDeep } from './index.777df7a8.mjs';
3
3
  import 'deepmerge';
4
4
  import 'fast-case';
5
5
  import { cleanProductOptions } from './products.mjs';
6
6
  import './find.18f1ac6d.mjs';
7
7
  import './round.577a8441.mjs';
8
- import './cache.mjs';
9
8
  import './attributes.mjs';
10
9
 
11
10
  function methods(api, options) {
@@ -1,5 +1,4 @@
1
- import { d as defaultMethods } from './index.a8d5c125.mjs';
2
- import cacheApi from './cache.mjs';
1
+ import { d as defaultMethods } from './index.777df7a8.mjs';
3
2
  import 'qs';
4
3
  import './find.18f1ac6d.mjs';
5
4
  import './round.577a8441.mjs';
@@ -11,7 +10,7 @@ function methods(api) {
11
10
 
12
11
  return {
13
12
  get: (id, ...args) => {
14
- return cacheApi.getFetch('categories', id, () => get(id, ...args));
13
+ return api.cache.getFetch('categories', id, () => get(id, ...args));
15
14
  },
16
15
 
17
16
  list,
package/dist/content.mjs CHANGED
@@ -1,15 +1,7 @@
1
- import cacheApi from './cache.mjs';
2
- import './index.a8d5c125.mjs';
3
- import 'qs';
4
- import './find.18f1ac6d.mjs';
5
- import './round.577a8441.mjs';
6
- import 'deepmerge';
7
- import 'fast-case';
8
-
9
1
  function methods(api, opt) {
10
2
  return {
11
3
  get: (type, id, query) => {
12
- return cacheApi.getFetch(`content_${type}`, id, () =>
4
+ return api.cache.getFetch(`content_${type}`, id, () =>
13
5
  api.request('get', `/content/${type}`, id, {
14
6
  $preview: opt.previewContent,
15
7
  ...(query || {}),
package/dist/cookie.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as isServer } from './index.a8d5c125.mjs';
1
+ import { i as isServer } from './index.777df7a8.mjs';
2
2
  import 'qs';
3
3
  import './find.18f1ac6d.mjs';
4
4
  import './round.577a8441.mjs';
@@ -1473,8 +1473,6 @@ function isEmpty(value) {
1473
1473
 
1474
1474
  const LOADING_SCRIPTS = {};
1475
1475
 
1476
- let options = {};
1477
-
1478
1476
  function arrayMerge(target, source, options) {
1479
1477
  const destination = target.slice();
1480
1478
  source.forEach((item, index) => {
@@ -1512,14 +1510,6 @@ function merge(x, y, opt) {
1512
1510
  return deepmerge(x, y, opt);
1513
1511
  }
1514
1512
 
1515
- function setOptions(optns) {
1516
- options = optns;
1517
- }
1518
-
1519
- function getOptions() {
1520
- return options;
1521
- }
1522
-
1523
1513
  function isObject(val) {
1524
1514
  return val && typeof val === 'object' && !(val instanceof Array);
1525
1515
  }
@@ -1601,7 +1591,7 @@ function defaultMethods(api, uri, methods) {
1601
1591
  };
1602
1592
  }
1603
1593
 
1604
- async function vaultRequest(method, url, data) {
1594
+ async function vaultRequest(method, url, data, options) {
1605
1595
  const { vaultUrl, timeout, key } = options;
1606
1596
  const requestData = {
1607
1597
  $jsonp: {
@@ -1785,7 +1775,6 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1785
1775
  findIndex,
1786
1776
  get,
1787
1777
  getLocationParams,
1788
- getOptions,
1789
1778
  isEmpty,
1790
1779
  isEqual,
1791
1780
  isFunction,
@@ -1800,7 +1789,6 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1800
1789
  removeUrlParams,
1801
1790
  round,
1802
1791
  set,
1803
- setOptions,
1804
1792
  snakeCase,
1805
1793
  stringifyQuery,
1806
1794
  toCamel,
@@ -1815,4 +1803,4 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1815
1803
  vaultRequest
1816
1804
  }, Symbol.toStringTag, { value: 'Module' }));
1817
1805
 
1818
- export { utils as A, trimStart as B, trimBoth as C, stringifyQuery as D, toLower as E, map as F, toCamel as a, isObject as b, cloneDeep as c, defaultMethods as d, camelCase as e, snakeCase as f, isEqual as g, toCamelPath as h, isServer as i, getOptions as j, isFunction as k, loadScript as l, merge as m, isEmpty as n, isLiveMode as o, pick$1 as p, base64Encode as q, reduce as r, set as s, toSnake as t, uniq as u, vaultRequest as v, getLocationParams as w, removeUrlParams as x, trimEnd as y, setOptions as z };
1806
+ export { trimBoth as A, stringifyQuery as B, toLower as C, map as D, toCamelPath as a, toSnake as b, cloneDeep as c, defaultMethods as d, isObject as e, camelCase as f, snakeCase as g, isEqual as h, isServer as i, isFunction as j, isEmpty as k, loadScript as l, merge as m, isLiveMode as n, base64Encode as o, pick$1 as p, getLocationParams as q, reduce as r, set as s, toCamel as t, uniq as u, vaultRequest as v, removeUrlParams as w, trimEnd as x, utils as y, trimStart as z };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { default } from './api.mjs';
2
2
  import './card.mjs';
3
- import './index.a8d5c125.mjs';
3
+ import './index.777df7a8.mjs';
4
4
  import 'qs';
5
5
  import './find.18f1ac6d.mjs';
6
6
  import './round.577a8441.mjs';