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.
- package/dist/api.mjs +51 -39
- package/dist/attributes.mjs +2 -3
- package/dist/cache.mjs +139 -137
- package/dist/card.mjs +147 -145
- package/dist/cart.mjs +1 -2
- package/dist/categories.mjs +2 -3
- package/dist/content.mjs +1 -9
- package/dist/cookie.mjs +1 -1
- package/dist/{index.a8d5c125.mjs → index.777df7a8.mjs} +2 -14
- package/dist/index.mjs +1 -1
- package/dist/payment.mjs +296 -118
- package/dist/products.mjs +8 -12
- package/dist/settings.mjs +1 -1
- package/dist/subscriptions.mjs +2 -3
- package/dist/swell.cjs +605 -424
- package/dist/swell.cjs.map +1 -1
- package/dist/swell.umd.min.js +604 -423
- package/dist/swell.umd.min.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/package.json +14 -6
- package/types/account/camel.ts +10 -7
- package/types/account/index.ts +3 -3
- package/types/account/snake.ts +5 -5
- package/types/attribute/camel.ts +7 -4
- package/types/attribute/index.ts +3 -3
- package/types/attribute/snake.ts +2 -2
- package/types/billing/camel.ts +4 -4
- package/types/billing/index.ts +2 -2
- package/types/billing/snake.ts +1 -1
- package/types/card/camel.ts +5 -5
- package/types/card/index.ts +3 -3
- package/types/card/snake.ts +3 -3
- package/types/cart/camel.ts +17 -14
- package/types/cart/index.ts +3 -3
- package/types/cart/snake.ts +12 -12
- package/types/category/camel.ts +4 -4
- package/types/category/index.ts +3 -3
- package/types/category/snake.ts +2 -2
- package/types/content/camel.ts +5 -5
- package/types/content/index.ts +3 -3
- package/types/content/snake.ts +3 -3
- package/types/coupon/camel.ts +4 -4
- package/types/coupon/index.ts +2 -2
- package/types/coupon/snake.ts +2 -2
- package/types/currency/camel.ts +2 -2
- package/types/currency/index.ts +3 -3
- package/types/discount/camel.ts +3 -3
- package/types/discount/index.ts +2 -2
- package/types/giftcard/camel.ts +10 -7
- package/types/giftcard/index.ts +2 -2
- package/types/giftcard/snake.ts +5 -5
- package/types/index.d.cts +207 -0
- package/types/index.d.ts +83 -56
- package/types/invoice/camel.ts +10 -10
- package/types/invoice/index.ts +3 -3
- package/types/invoice/snake.ts +8 -8
- package/types/order/camel.ts +18 -15
- package/types/order/index.ts +3 -3
- package/types/order/snake.ts +18 -13
- package/types/payment/camel.ts +13 -10
- package/types/payment/index.ts +9 -3
- package/types/payment/snake.ts +8 -8
- package/types/product/camel.ts +5 -5
- package/types/product/index.ts +4 -4
- package/types/product/snake.ts +3 -3
- package/types/promotion/camel.ts +6 -6
- package/types/promotion/index.ts +2 -2
- package/types/promotion/snake.ts +4 -4
- package/types/purchase_link/camel.ts +10 -7
- package/types/purchase_link/index.ts +2 -2
- package/types/purchase_link/snake.ts +5 -5
- package/types/refund/camel.ts +6 -6
- package/types/refund/index.ts +2 -2
- package/types/refund/snake.ts +4 -4
- package/types/shipment_rating/camel.ts +3 -3
- package/types/shipment_rating/index.ts +2 -2
- package/types/subscription/camel.ts +16 -13
- package/types/subscription/index.ts +3 -3
- package/types/subscription/snake.ts +16 -11
- package/types/user/camel.ts +2 -2
- package/types/user/index.ts +3 -3
- package/types/user/snake.ts +1 -1
package/dist/card.mjs
CHANGED
|
@@ -1,174 +1,176 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
card.
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
126
|
-
|
|
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
|
-
|
|
130
|
-
|
|
130
|
+
return sum % 10 === 0;
|
|
131
|
+
},
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
validateNumber(num) {
|
|
134
|
+
num = String(num).replace(/\s+|-/g, '');
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
return num.length >= 10 && num.length <= 16 && this.luhnCheck(num);
|
|
137
|
+
},
|
|
137
138
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
validateExpiry(month, year) {
|
|
140
|
+
month = String(month).trim();
|
|
141
|
+
year = String(year).trim();
|
|
141
142
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
if (!/^\d+$/.test(month) || !/^\d+$/.test(year)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
145
146
|
|
|
146
|
-
|
|
147
|
+
const numMonth = Number.parseInt(month, 10);
|
|
147
148
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
if (numMonth <= 0 || numMonth > 12) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const date = new Date(year, month);
|
|
154
|
+
date.setMonth(date.getMonth() - 1);
|
|
155
|
+
date.setMonth(date.getMonth() + 1, 1);
|
|
155
156
|
|
|
156
|
-
|
|
157
|
+
const diff = date.getTime() - Date.now();
|
|
157
158
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
// The card has expired
|
|
160
|
+
if (diff < 0) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
168
|
-
|
|
168
|
+
validateCVC(val) {
|
|
169
|
+
val = String(val).trim();
|
|
169
170
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
};
|
|
171
|
+
return /^\d+$/.test(val) && val.length >= 3 && val.length <= 4;
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
173
175
|
|
|
174
|
-
export {
|
|
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.
|
|
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) {
|
package/dist/categories.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { d as defaultMethods } from './index.
|
|
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
|
|
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
|
|
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
|
@@ -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 {
|
|
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 };
|