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/api.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import methods$5 from './card.mjs';
|
|
2
2
|
import { getCookie, setCookie } from './cookie.mjs';
|
|
3
|
-
import
|
|
3
|
+
import methods$4 from './cache.mjs';
|
|
4
4
|
import methods$3 from './cart.mjs';
|
|
5
|
-
import methods$
|
|
6
|
-
import {
|
|
5
|
+
import methods$6 from './account.mjs';
|
|
6
|
+
import { j as isFunction, l as loadScript, e as isObject, v as vaultRequest, k as isEmpty, d as defaultMethods, x as trimEnd, y as utils, z as trimStart, A as trimBoth, b as toSnake, B as stringifyQuery, o as base64Encode, i as isServer, t as toCamel } from './index.777df7a8.mjs';
|
|
7
7
|
import 'qs';
|
|
8
8
|
import 'deepmerge';
|
|
9
9
|
import 'fast-case';
|
|
10
|
-
import methods$
|
|
11
|
-
import methods$
|
|
12
|
-
import methods$
|
|
13
|
-
import methods$
|
|
14
|
-
import methods$
|
|
15
|
-
import methods$
|
|
10
|
+
import methods$7 from './products.mjs';
|
|
11
|
+
import methods$8 from './categories.mjs';
|
|
12
|
+
import methods$9 from './attributes.mjs';
|
|
13
|
+
import methods$a from './subscriptions.mjs';
|
|
14
|
+
import methods$b from './content.mjs';
|
|
15
|
+
import methods$c from './settings.mjs';
|
|
16
16
|
import PaymentController from './payment.mjs';
|
|
17
|
-
import methods$
|
|
18
|
-
import methods$
|
|
17
|
+
import methods$d from './locale.mjs';
|
|
18
|
+
import methods$e from './currency.mjs';
|
|
19
19
|
import './find.18f1ac6d.mjs';
|
|
20
20
|
import './round.577a8441.mjs';
|
|
21
21
|
|
|
@@ -146,19 +146,29 @@ class AppPaymentComponent extends AppComponent {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
#getIntent(data) {
|
|
149
|
-
return vaultRequest(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
return vaultRequest(
|
|
150
|
+
'GET',
|
|
151
|
+
'/intent',
|
|
152
|
+
{
|
|
153
|
+
gateway: this.#gateway,
|
|
154
|
+
account_id: this.#accountId,
|
|
155
|
+
intent: data,
|
|
156
|
+
},
|
|
157
|
+
this.options,
|
|
158
|
+
);
|
|
154
159
|
}
|
|
155
160
|
|
|
156
161
|
#createIntent(data) {
|
|
157
|
-
return vaultRequest(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
return vaultRequest(
|
|
163
|
+
'POST',
|
|
164
|
+
'/intent',
|
|
165
|
+
{
|
|
166
|
+
gateway: this.#gateway,
|
|
167
|
+
account_id: this.#accountId,
|
|
168
|
+
intent: data,
|
|
169
|
+
},
|
|
170
|
+
this.options,
|
|
171
|
+
);
|
|
162
172
|
}
|
|
163
173
|
}
|
|
164
174
|
|
|
@@ -312,7 +322,7 @@ function methods$2(api) {
|
|
|
312
322
|
const { get, list } = defaultMethods(api, '/invoices', ['list', 'get']);
|
|
313
323
|
return {
|
|
314
324
|
get: (id, ...args) => {
|
|
315
|
-
return
|
|
325
|
+
return api.cache.getFetch('invoices', id, () => get(id, ...args));
|
|
316
326
|
},
|
|
317
327
|
|
|
318
328
|
list,
|
|
@@ -446,7 +456,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
|
|
|
446
456
|
const api = {};
|
|
447
457
|
|
|
448
458
|
Object.assign(api, {
|
|
449
|
-
version: '5.
|
|
459
|
+
version: '5.9.0',
|
|
450
460
|
options,
|
|
451
461
|
request,
|
|
452
462
|
|
|
@@ -476,8 +486,6 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
|
|
|
476
486
|
options.getCart = opt.getCart;
|
|
477
487
|
options.updateCart = opt.updateCart;
|
|
478
488
|
options.headers = opt.headers || {};
|
|
479
|
-
|
|
480
|
-
setOptions(options);
|
|
481
489
|
},
|
|
482
490
|
|
|
483
491
|
// Backward compatibility
|
|
@@ -501,35 +509,35 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
|
|
|
501
509
|
return api.request('delete', url, data);
|
|
502
510
|
},
|
|
503
511
|
|
|
504
|
-
cache:
|
|
512
|
+
cache: methods$4(options),
|
|
505
513
|
|
|
506
|
-
card:
|
|
514
|
+
card: methods$5(options),
|
|
507
515
|
|
|
508
516
|
cart: methods$3(api, options),
|
|
509
517
|
|
|
510
|
-
account: methods$
|
|
518
|
+
account: methods$6(api),
|
|
511
519
|
|
|
512
520
|
app: new AppController(api, options),
|
|
513
521
|
|
|
514
|
-
products: methods$
|
|
522
|
+
products: methods$7(api, options),
|
|
515
523
|
|
|
516
|
-
categories: methods$
|
|
524
|
+
categories: methods$8(api),
|
|
517
525
|
|
|
518
|
-
attributes: methods$
|
|
526
|
+
attributes: methods$9(api),
|
|
519
527
|
|
|
520
|
-
subscriptions: methods$
|
|
528
|
+
subscriptions: methods$a(api),
|
|
521
529
|
|
|
522
530
|
invoices: methods$2(api),
|
|
523
531
|
|
|
524
|
-
content: methods$
|
|
532
|
+
content: methods$b(api, options),
|
|
525
533
|
|
|
526
|
-
settings: methods$
|
|
534
|
+
settings: methods$c(api, options),
|
|
527
535
|
|
|
528
536
|
payment: new PaymentController(api, options),
|
|
529
537
|
|
|
530
|
-
locale: methods$
|
|
538
|
+
locale: methods$d(api, options),
|
|
531
539
|
|
|
532
|
-
currency: methods$
|
|
540
|
+
currency: methods$e(api, options),
|
|
533
541
|
|
|
534
542
|
session: methods$1(api, options),
|
|
535
543
|
|
|
@@ -537,9 +545,13 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
|
|
|
537
545
|
|
|
538
546
|
utils,
|
|
539
547
|
|
|
540
|
-
getCookie
|
|
548
|
+
getCookie(name) {
|
|
549
|
+
return (options.getCookie || getCookie)(name);
|
|
550
|
+
},
|
|
541
551
|
|
|
542
|
-
setCookie,
|
|
552
|
+
setCookie(name, value, cookieOptions) {
|
|
553
|
+
return (options.setCookie || setCookie)(name, value, cookieOptions);
|
|
554
|
+
},
|
|
543
555
|
});
|
|
544
556
|
|
|
545
557
|
async function request(
|
package/dist/attributes.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('attributes', id, () => get(id, ...args));
|
|
15
14
|
},
|
|
16
15
|
|
|
17
16
|
list,
|
package/dist/cache.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as set, m as merge,
|
|
1
|
+
import { s as set, m as merge, t as toCamel, a as toCamelPath } from './index.777df7a8.mjs';
|
|
2
2
|
import { g as get } from './find.18f1ac6d.mjs';
|
|
3
3
|
import 'qs';
|
|
4
4
|
import './round.577a8441.mjs';
|
|
@@ -7,164 +7,166 @@ import 'fast-case';
|
|
|
7
7
|
|
|
8
8
|
const RECORD_TIMEOUT = 5000;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
[
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
*/
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const cacheApi = {
|
|
24
|
-
options: {
|
|
25
|
-
enabled: true,
|
|
26
|
-
debug: false,
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
debug(...args) {
|
|
30
|
-
if (this.options.debug) {
|
|
31
|
-
console.log(...args);
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
values({ model, id }, setValues = undefined) {
|
|
36
|
-
this.debug('cache.values', ...arguments);
|
|
37
|
-
if (setValues !== undefined) {
|
|
38
|
-
for (let key in setValues) {
|
|
39
|
-
set(VALUES, `${model}.${id}.${key}`, setValues[key]);
|
|
10
|
+
function methods(opt) {
|
|
11
|
+
let VALUES = {
|
|
12
|
+
/*
|
|
13
|
+
[model]: {
|
|
14
|
+
[id]: {
|
|
15
|
+
data,
|
|
16
|
+
record,
|
|
17
|
+
recordTimer,
|
|
18
|
+
presets,
|
|
40
19
|
}
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
return get(VALUES, `${model}.${id}`, {});
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
preset(details) {
|
|
47
|
-
this.debug('cache.preset', ...arguments);
|
|
48
|
-
const { presets = [] } = this.values(details);
|
|
49
|
-
presets.push(details);
|
|
50
|
-
this.values(details, { presets });
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
set(details) {
|
|
54
|
-
this.debug('cache.set', ...arguments);
|
|
55
|
-
let { model, id, path, value } = details;
|
|
56
|
-
let { data = {}, record } = this.values(details);
|
|
57
|
-
|
|
58
|
-
if (id === null) {
|
|
59
|
-
return;
|
|
60
20
|
}
|
|
21
|
+
*/
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
options: {
|
|
26
|
+
enabled: true,
|
|
27
|
+
debug: false,
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
debug(...args) {
|
|
31
|
+
if (this.options.debug) {
|
|
32
|
+
console.log(...args);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
61
35
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
36
|
+
values({ model, id }, setValues = undefined) {
|
|
37
|
+
this.debug('cache.values', ...arguments);
|
|
38
|
+
if (setValues !== undefined) {
|
|
39
|
+
for (let key in setValues) {
|
|
40
|
+
set(VALUES, `${model}.${id}.${key}`, setValues[key]);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return get(VALUES, `${model}.${id}`, {});
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
preset(details) {
|
|
48
|
+
this.debug('cache.preset', ...arguments);
|
|
49
|
+
const { presets = [] } = this.values(details);
|
|
50
|
+
presets.push(details);
|
|
51
|
+
this.values(details, { presets });
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
set(details) {
|
|
55
|
+
this.debug('cache.set', ...arguments);
|
|
56
|
+
let { model, id, path, value } = details;
|
|
57
|
+
let { data = {}, record } = this.values(details);
|
|
58
|
+
|
|
59
|
+
if (id === null) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
65
62
|
|
|
66
|
-
|
|
63
|
+
if (record === undefined) {
|
|
64
|
+
return this.preset(details);
|
|
65
|
+
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
if (useCamelCase && value && typeof value === 'object') {
|
|
70
|
-
value = toCamel(value);
|
|
71
|
-
}
|
|
67
|
+
data = merge(record || {}, data);
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
data = upData;
|
|
78
|
-
} else if (value && typeof value === 'object') {
|
|
79
|
-
data = data || {};
|
|
80
|
-
data = merge(data, value);
|
|
81
|
-
} else {
|
|
82
|
-
data = value;
|
|
83
|
-
}
|
|
69
|
+
const { useCamelCase } = opt;
|
|
70
|
+
if (useCamelCase && value && typeof value === 'object') {
|
|
71
|
+
value = toCamel(value);
|
|
72
|
+
}
|
|
84
73
|
|
|
85
|
-
|
|
74
|
+
if (path || value instanceof Array) {
|
|
75
|
+
let upData = { ...(data || {}) };
|
|
76
|
+
let upPath = useCamelCase ? toCamelPath(path) : path;
|
|
77
|
+
set(upData, upPath || '', value);
|
|
78
|
+
data = upData;
|
|
79
|
+
} else if (value && typeof value === 'object') {
|
|
80
|
+
data = data || {};
|
|
81
|
+
data = merge(data, value);
|
|
82
|
+
} else {
|
|
83
|
+
data = value;
|
|
84
|
+
}
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
this.values(details, { data });
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
// Make sure values have clean refs
|
|
90
|
+
const cache = VALUES[model][id];
|
|
91
|
+
if (cache !== undefined) {
|
|
92
|
+
if (cache.data !== undefined) {
|
|
93
|
+
cache.data = JSON.parse(JSON.stringify(cache.data));
|
|
94
|
+
}
|
|
95
|
+
if (cache.record !== undefined) {
|
|
96
|
+
cache.record = JSON.parse(JSON.stringify(cache.record));
|
|
97
|
+
}
|
|
96
98
|
}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
// noop
|
|
97
101
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return data;
|
|
109
|
-
}
|
|
110
|
-
},
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
get(model, id) {
|
|
105
|
+
this.debug('cache.get', ...arguments);
|
|
106
|
+
const { data, recordTimer } = this.values({ model, id });
|
|
107
|
+
this.debug('cache.get:data+recordTimer', ...arguments);
|
|
108
|
+
if (recordTimer) {
|
|
109
|
+
return data;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
111
112
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
setRecord(record, details) {
|
|
114
|
+
this.debug('cache.setRecord', ...arguments);
|
|
115
|
+
let { recordTimer, presets } = this.values(details);
|
|
115
116
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
if (recordTimer) {
|
|
118
|
+
clearTimeout(recordTimer);
|
|
119
|
+
}
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
recordTimer = setTimeout(() => {
|
|
122
|
+
this.values(details, { record: undefined, recordTimer: undefined });
|
|
123
|
+
}, RECORD_TIMEOUT);
|
|
123
124
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
// Record has to be null at minimum, not undefined
|
|
126
|
+
this.values(details, {
|
|
127
|
+
record: record !== undefined ? record : null,
|
|
128
|
+
recordTimer,
|
|
129
|
+
});
|
|
129
130
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
if (presets) {
|
|
132
|
+
for (let preset of presets) {
|
|
133
|
+
this.set(preset);
|
|
134
|
+
}
|
|
135
|
+
this.values(details, { presets: undefined });
|
|
133
136
|
}
|
|
134
|
-
this.values(details, { presets: undefined });
|
|
135
|
-
}
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
const result = this.get(details.model, details.id);
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
return result !== undefined ? result : record;
|
|
141
|
+
},
|
|
141
142
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
async getFetch(model, id, fetch) {
|
|
144
|
+
if (this.options.enabled) {
|
|
145
|
+
this.debug('cache.getFetch', ...arguments);
|
|
146
|
+
const value = this.get(model, id);
|
|
146
147
|
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
if (value !== undefined) {
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
149
151
|
}
|
|
150
|
-
}
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
const record = await fetch();
|
|
154
|
+
return this.setRecord(record, { model, id });
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
clear(model = undefined, id = undefined) {
|
|
158
|
+
this.debug('cache.clear', ...arguments);
|
|
159
|
+
if (model) {
|
|
160
|
+
if (id) {
|
|
161
|
+
set(VALUES, `${model}.${id}`, undefined);
|
|
162
|
+
} else {
|
|
163
|
+
set(VALUES, model, undefined);
|
|
164
|
+
}
|
|
161
165
|
} else {
|
|
162
|
-
|
|
166
|
+
VALUES = {};
|
|
163
167
|
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
};
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
169
171
|
|
|
170
|
-
export {
|
|
172
|
+
export { methods as default };
|