swell-js 3.18.1 → 3.18.2
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/account-328cc590.js +100 -0
- package/dist/account.js +1 -1
- package/dist/api-b810ea57.js +192 -0
- package/dist/api.js +17 -33
- package/dist/attributes-a5d59cae.js +16 -0
- package/dist/attributes.js +4 -14
- package/dist/{cache-f2b62a15.js → cache-70cd9241.js} +70 -49
- package/dist/cache.js +3 -13
- package/dist/card-31d20d88.js +141 -0
- package/dist/card.js +3 -13
- package/dist/cart-5e54de2c.js +169 -0
- package/dist/cart.js +6 -16
- package/dist/categories-bb6f6179.js +16 -0
- package/dist/categories.js +4 -14
- package/dist/content-8feae575.js +18 -0
- package/dist/content.js +4 -14
- package/dist/cookie-dff5d694.js +50 -0
- package/dist/cookie.js +3 -13
- package/dist/{currency-59a7db42.js → currency-85151e0d.js} +89 -43
- package/dist/currency.js +4 -14
- package/dist/index-bee7164f.js +4339 -0
- package/dist/index.js +17 -33
- package/dist/{locale-f2899567.js → locale-abdc14e0.js} +13 -17
- package/dist/locale.js +4 -14
- package/dist/payment-ed203c03.js +1669 -0
- package/dist/payment.js +8 -23
- package/dist/{products-b9b703d9.js → products-e5e8d7fe.js} +160 -121
- package/dist/products.js +5 -15
- package/dist/{settings-3a746fb9.js → settings-3cf85d69.js} +113 -79
- package/dist/settings.js +3 -13
- package/dist/{subscriptions-a38628b4.js → subscriptions-afa9565b.js} +24 -16
- package/dist/subscriptions.js +6 -16
- package/dist/swell.cjs.js +7817 -0
- package/dist/swell.cjs.js.map +1 -0
- package/dist/swell.umd.min.js +12241 -4
- package/dist/swell.umd.min.js.map +1 -1
- package/dist/utils/index.js +2 -12
- package/package.json +7 -7
- package/dist/account-1c594341.js +0 -81
- package/dist/api-597b011e.js +0 -155
- package/dist/attributes-8d23dd28.js +0 -14
- package/dist/card-3225c3a9.js +0 -104
- package/dist/cart-0249dad3.js +0 -173
- package/dist/categories-efae21dd.js +0 -14
- package/dist/content-82dc195e.js +0 -34
- package/dist/cookie-8e91f8dd.js +0 -54
- package/dist/index-b1ee0b3d.js +0 -256
- package/dist/payment-a1113b03.js +0 -1145
- package/dist/swell.cjs.min.js +0 -2970
- package/dist/swell.cjs.min.js.map +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
function methods(request) {
|
|
2
|
+
return {
|
|
3
|
+
state: null,
|
|
4
|
+
|
|
5
|
+
async requestStateChange(method, url, id, data) {
|
|
6
|
+
const result = await request(method, url, id, data);
|
|
7
|
+
if (result && result.errors) {
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
return (this.state = result);
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
get(query) {
|
|
14
|
+
return this.requestStateChange('get', '/account', query);
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
create(data) {
|
|
18
|
+
return this.requestStateChange('post', '/account', data);
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
update(data) {
|
|
22
|
+
return this.requestStateChange('put', '/account', data);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
login(email, password) {
|
|
26
|
+
if (password && password.password_token) {
|
|
27
|
+
return this.requestStateChange('post', '/account/login', {
|
|
28
|
+
email,
|
|
29
|
+
password_token: password.password_token,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return this.requestStateChange('post', '/account/login', {
|
|
33
|
+
email,
|
|
34
|
+
password,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
logout() {
|
|
39
|
+
this.state = null;
|
|
40
|
+
return request('post', '/account/logout');
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
recover(data) {
|
|
44
|
+
return request('post', '/account/recover', data);
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
listAddresses(query) {
|
|
48
|
+
return request('get', '/account/addresses', query);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
createAddress(data) {
|
|
52
|
+
return request('post', '/account/addresses', data);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
updateAddress(id, data) {
|
|
56
|
+
return request('put', `/account/addresses/${id}`, data);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
deleteAddress(id) {
|
|
60
|
+
return request('delete', `/account/addresses/${id}`);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
listCards(query) {
|
|
64
|
+
return request('get', '/account/cards', query);
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
createCard(data) {
|
|
68
|
+
return request('post', '/account/cards', data);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
updateCard(id, data) {
|
|
72
|
+
return request('put', `/account/cards/${id}`, data);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
deleteCard(id) {
|
|
76
|
+
return request('delete', `/account/cards/${id}`);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
listOrders(query) {
|
|
80
|
+
return request('get', `/account/orders`, query);
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
getOrder(id) {
|
|
84
|
+
return request('get', `/account/orders/${id}`);
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
// Deprecated methods
|
|
88
|
+
getAddresses(query) {
|
|
89
|
+
return request('get', '/account/addresses', query);
|
|
90
|
+
},
|
|
91
|
+
getCards(query) {
|
|
92
|
+
return request('get', '/account/cards', query);
|
|
93
|
+
},
|
|
94
|
+
getOrders(query) {
|
|
95
|
+
return request('get', `/account/orders`, query);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { methods as m };
|
package/dist/account.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { m as default } from './account-
|
|
1
|
+
export { m as default } from './account-328cc590.js';
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { c as cardApi } from './card-31d20d88.js';
|
|
2
|
+
import { g as getCookie, s as setCookie } from './cookie-dff5d694.js';
|
|
3
|
+
import { c as cacheApi } from './cache-70cd9241.js';
|
|
4
|
+
import { m as methods } from './cart-5e54de2c.js';
|
|
5
|
+
import { m as methods$1 } from './account-328cc590.js';
|
|
6
|
+
import { m as methods$2 } from './products-e5e8d7fe.js';
|
|
7
|
+
import { m as methods$3 } from './categories-bb6f6179.js';
|
|
8
|
+
import { m as methods$4 } from './attributes-a5d59cae.js';
|
|
9
|
+
import { m as methods$5 } from './subscriptions-afa9565b.js';
|
|
10
|
+
import { m as methods$6 } from './content-8feae575.js';
|
|
11
|
+
import { m as methods$7 } from './settings-3cf85d69.js';
|
|
12
|
+
import { m as methods$8 } from './payment-ed203c03.js';
|
|
13
|
+
import { m as methods$9 } from './locale-abdc14e0.js';
|
|
14
|
+
import { m as methods$a } from './currency-85151e0d.js';
|
|
15
|
+
import { n as trimEnd, E as utils, l as trimStart, k as trimBoth, j as toSnake, o as stringifyQuery, A as base64Encode, t as toCamel, e as setOptions } from './index-bee7164f.js';
|
|
16
|
+
|
|
17
|
+
const options = {
|
|
18
|
+
store: null,
|
|
19
|
+
key: null,
|
|
20
|
+
url: null,
|
|
21
|
+
useCamelCase: null,
|
|
22
|
+
previewContent: null,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const api = {
|
|
26
|
+
version: '3.18.2',
|
|
27
|
+
options,
|
|
28
|
+
request,
|
|
29
|
+
|
|
30
|
+
init(store, key, opt = {}) {
|
|
31
|
+
options.key = key;
|
|
32
|
+
options.store = store;
|
|
33
|
+
options.url = opt.url
|
|
34
|
+
? trimEnd(opt.url)
|
|
35
|
+
: `https://${store}.swell.store`;
|
|
36
|
+
options.vaultUrl = opt.vaultUrl
|
|
37
|
+
? trimEnd(opt.vaultUrl)
|
|
38
|
+
: `https://vault.schema.io`;
|
|
39
|
+
options.timeout = (opt.timeout && parseInt(opt.timeout, 10)) || 20000;
|
|
40
|
+
options.useCamelCase = opt.useCamelCase || false;
|
|
41
|
+
options.previewContent = opt.previewContent || false;
|
|
42
|
+
options.session = opt.session;
|
|
43
|
+
options.locale = opt.locale;
|
|
44
|
+
options.currency = opt.currency;
|
|
45
|
+
options.api = api;
|
|
46
|
+
setOptions(options);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
// Backward compatibility
|
|
50
|
+
auth(...args) {
|
|
51
|
+
return this.init(...args);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
get(url, query) {
|
|
55
|
+
return request('get', url, query);
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
put(url, data) {
|
|
59
|
+
return request('put', url, data);
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
post(url, data) {
|
|
63
|
+
return request('post', url, data);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
delete(url, data) {
|
|
67
|
+
return request('delete', url, data);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
cache: cacheApi,
|
|
71
|
+
|
|
72
|
+
card: cardApi,
|
|
73
|
+
|
|
74
|
+
cart: methods(request, options),
|
|
75
|
+
|
|
76
|
+
account: methods$1(request),
|
|
77
|
+
|
|
78
|
+
products: methods$2(request, options),
|
|
79
|
+
|
|
80
|
+
categories: methods$3(request),
|
|
81
|
+
|
|
82
|
+
attributes: methods$4(request),
|
|
83
|
+
|
|
84
|
+
subscriptions: methods$5(request),
|
|
85
|
+
|
|
86
|
+
content: methods$6(request, options),
|
|
87
|
+
|
|
88
|
+
settings: methods$7(request, options),
|
|
89
|
+
|
|
90
|
+
payment: methods$8(request, options),
|
|
91
|
+
|
|
92
|
+
locale: methods$9(request, options),
|
|
93
|
+
|
|
94
|
+
currency: methods$a(request, options),
|
|
95
|
+
|
|
96
|
+
utils,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
async function request(
|
|
100
|
+
method,
|
|
101
|
+
url,
|
|
102
|
+
id = undefined,
|
|
103
|
+
data = undefined,
|
|
104
|
+
opt = undefined,
|
|
105
|
+
) {
|
|
106
|
+
const allOptions = {
|
|
107
|
+
...options,
|
|
108
|
+
...opt,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const session = allOptions.session || getCookie('swell-session');
|
|
112
|
+
const locale = allOptions.locale || getCookie('swell-locale');
|
|
113
|
+
const currency = allOptions.currency || getCookie('swell-currency');
|
|
114
|
+
|
|
115
|
+
const baseUrl = `${allOptions.url}${allOptions.base || ''}/api`;
|
|
116
|
+
const reqMethod = String(method).toLowerCase();
|
|
117
|
+
|
|
118
|
+
let reqUrl = url;
|
|
119
|
+
let reqData = id;
|
|
120
|
+
|
|
121
|
+
if (data !== undefined || typeof id === 'string') {
|
|
122
|
+
reqUrl = [trimEnd(url), trimStart(id)].join('/');
|
|
123
|
+
reqData = data;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
reqUrl = allOptions.fullUrl || `${baseUrl}/${trimBoth(reqUrl)}`;
|
|
127
|
+
reqData = allOptions.useCamelCase ? toSnake(reqData) : reqData;
|
|
128
|
+
|
|
129
|
+
let reqBody;
|
|
130
|
+
if (reqMethod === 'get') {
|
|
131
|
+
let exQuery;
|
|
132
|
+
[reqUrl, exQuery] = reqUrl.split('?');
|
|
133
|
+
const fullQuery = [exQuery, stringifyQuery(reqData)]
|
|
134
|
+
.join('&')
|
|
135
|
+
.replace(/^&/, '');
|
|
136
|
+
reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ''}`;
|
|
137
|
+
} else {
|
|
138
|
+
reqBody = JSON.stringify(reqData);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const reqHeaders = {
|
|
142
|
+
Accept: 'application/json',
|
|
143
|
+
'Content-Type': 'application/json',
|
|
144
|
+
Authorization: `Basic ${base64Encode(String(allOptions.key))}`,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
if (session) {
|
|
148
|
+
reqHeaders['X-Session'] = session;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (locale) {
|
|
152
|
+
reqHeaders['X-Locale'] = locale;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (currency) {
|
|
156
|
+
reqHeaders['X-Currency'] = currency;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const response = await fetch(reqUrl, {
|
|
160
|
+
method: reqMethod,
|
|
161
|
+
headers: reqHeaders,
|
|
162
|
+
body: reqBody,
|
|
163
|
+
credentials: 'include',
|
|
164
|
+
mode: 'cors',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const responseSession = response.headers.get('X-Session');
|
|
168
|
+
|
|
169
|
+
if (typeof responseSession === 'string' && session !== responseSession) {
|
|
170
|
+
setCookie('swell-session', responseSession);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const result = await response.json();
|
|
174
|
+
|
|
175
|
+
if (result && result.error) {
|
|
176
|
+
const err = new Error(result.error.message);
|
|
177
|
+
err.status = response.status;
|
|
178
|
+
err.code = result.error.code;
|
|
179
|
+
err.param = result.error.param;
|
|
180
|
+
throw err;
|
|
181
|
+
} else if (!response.ok) {
|
|
182
|
+
const err = new Error(
|
|
183
|
+
'A connection error occurred while making the request',
|
|
184
|
+
);
|
|
185
|
+
err.code = 'connection_error';
|
|
186
|
+
throw err;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return options.useCamelCase ? toCamel(result) : result;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export { api as a };
|
package/dist/api.js
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
export { a as default } from './api-
|
|
2
|
-
import '
|
|
3
|
-
import './
|
|
4
|
-
import './index-b1ee0b3d.js';
|
|
1
|
+
export { a as default } from './api-b810ea57.js';
|
|
2
|
+
import './card-31d20d88.js';
|
|
3
|
+
import './index-bee7164f.js';
|
|
5
4
|
import 'qs';
|
|
6
|
-
import 'lodash/set';
|
|
7
|
-
import 'lodash/get';
|
|
8
|
-
import 'lodash/uniq';
|
|
9
|
-
import 'lodash/find';
|
|
10
|
-
import 'lodash/round';
|
|
11
|
-
import 'lodash/findIndex';
|
|
12
|
-
import 'lodash/camelCase';
|
|
13
|
-
import 'lodash/snakeCase';
|
|
14
|
-
import 'lodash/cloneDeep';
|
|
15
|
-
import 'lodash/isEqual';
|
|
16
5
|
import 'deepmerge';
|
|
17
|
-
import '
|
|
18
|
-
import './cookie-
|
|
19
|
-
import './cache-
|
|
20
|
-
import './cart-
|
|
21
|
-
import './products-
|
|
22
|
-
import './attributes-
|
|
23
|
-
import './account-
|
|
24
|
-
import './categories-
|
|
25
|
-
import './subscriptions-
|
|
26
|
-
import './content-
|
|
27
|
-
import './settings-
|
|
28
|
-
import './payment-
|
|
29
|
-
import '
|
|
30
|
-
import '
|
|
31
|
-
import 'lodash/isEmpty';
|
|
32
|
-
import 'lodash/map';
|
|
33
|
-
import 'lodash/toNumber';
|
|
34
|
-
import './locale-f2899567.js';
|
|
35
|
-
import './currency-59a7db42.js';
|
|
6
|
+
import 'fast-case';
|
|
7
|
+
import './cookie-dff5d694.js';
|
|
8
|
+
import './cache-70cd9241.js';
|
|
9
|
+
import './cart-5e54de2c.js';
|
|
10
|
+
import './products-e5e8d7fe.js';
|
|
11
|
+
import './attributes-a5d59cae.js';
|
|
12
|
+
import './account-328cc590.js';
|
|
13
|
+
import './categories-bb6f6179.js';
|
|
14
|
+
import './subscriptions-afa9565b.js';
|
|
15
|
+
import './content-8feae575.js';
|
|
16
|
+
import './settings-3cf85d69.js';
|
|
17
|
+
import './payment-ed203c03.js';
|
|
18
|
+
import './locale-abdc14e0.js';
|
|
19
|
+
import './currency-85151e0d.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { d as defaultMethods } from './index-bee7164f.js';
|
|
2
|
+
import { c as cacheApi } from './cache-70cd9241.js';
|
|
3
|
+
|
|
4
|
+
function methods(request) {
|
|
5
|
+
const { get, list } = defaultMethods(request, '/attributes', ['list', 'get']);
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
get: (id, ...args) => {
|
|
9
|
+
return cacheApi.getFetch('attributes', id, () => get(id, ...args));
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
list,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { methods as m };
|
package/dist/attributes.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
export { m as default } from './attributes-
|
|
2
|
-
import './index-
|
|
1
|
+
export { m as default } from './attributes-a5d59cae.js';
|
|
2
|
+
import './index-bee7164f.js';
|
|
3
3
|
import 'qs';
|
|
4
|
-
import 'lodash/set';
|
|
5
|
-
import 'lodash/get';
|
|
6
|
-
import 'lodash/uniq';
|
|
7
|
-
import 'lodash/find';
|
|
8
|
-
import 'lodash/round';
|
|
9
|
-
import 'lodash/findIndex';
|
|
10
|
-
import 'lodash/camelCase';
|
|
11
|
-
import 'lodash/snakeCase';
|
|
12
|
-
import 'lodash/cloneDeep';
|
|
13
|
-
import 'lodash/isEqual';
|
|
14
4
|
import 'deepmerge';
|
|
15
|
-
import '
|
|
16
|
-
import './cache-
|
|
5
|
+
import 'fast-case';
|
|
6
|
+
import './cache-70cd9241.js';
|
|
@@ -1,38 +1,35 @@
|
|
|
1
|
-
import { m as merge, t as toCamel,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1
|
+
import { s as set, g as get, m as merge, t as toCamel, i as toCamelPath, h as getOptions } from './index-bee7164f.js';
|
|
2
|
+
|
|
3
|
+
const RECORD_TIMEOUT = 5000;
|
|
4
|
+
|
|
5
|
+
let VALUES = {
|
|
6
|
+
/*
|
|
7
|
+
[model]: {
|
|
8
|
+
[id]: {
|
|
9
|
+
data,
|
|
10
|
+
record,
|
|
11
|
+
recordTimer,
|
|
12
|
+
presets,
|
|
18
13
|
}
|
|
19
|
-
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
20
16
|
};
|
|
21
|
-
|
|
22
|
-
let VALUES = {};
|
|
17
|
+
|
|
23
18
|
const cacheApi = {
|
|
24
19
|
options: {
|
|
25
20
|
enabled: true,
|
|
26
|
-
debug: false
|
|
21
|
+
debug: false,
|
|
27
22
|
},
|
|
23
|
+
|
|
28
24
|
debug(...args) {
|
|
29
25
|
if (this.options.debug) {
|
|
30
26
|
console.log(...args);
|
|
31
27
|
}
|
|
32
28
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
|
|
30
|
+
values({ model, id }, setValues = undefined) {
|
|
31
|
+
this.debug('cache.values', ...arguments);
|
|
32
|
+
if (setValues !== undefined) {
|
|
36
33
|
for (let key in setValues) {
|
|
37
34
|
set(VALUES, `${model}.${id}.${key}`, setValues[key]);
|
|
38
35
|
}
|
|
@@ -40,105 +37,129 @@ const cacheApi = {
|
|
|
40
37
|
}
|
|
41
38
|
return get(VALUES, `${model}.${id}`, {});
|
|
42
39
|
},
|
|
40
|
+
|
|
43
41
|
preset(details) {
|
|
44
|
-
this.debug(
|
|
42
|
+
this.debug('cache.preset', ...arguments);
|
|
45
43
|
const { presets = [] } = this.values(details);
|
|
46
44
|
presets.push(details);
|
|
47
45
|
this.values(details, { presets });
|
|
48
46
|
},
|
|
47
|
+
|
|
49
48
|
set(details) {
|
|
50
|
-
this.debug(
|
|
49
|
+
this.debug('cache.set', ...arguments);
|
|
51
50
|
let { model, id, path, value } = details;
|
|
52
51
|
let { data = {}, record, presets } = this.values(details);
|
|
52
|
+
|
|
53
53
|
if (id === null) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
|
|
57
|
+
if (record === undefined) {
|
|
57
58
|
return this.preset(details);
|
|
58
59
|
}
|
|
60
|
+
|
|
59
61
|
data = merge(record || {}, data);
|
|
62
|
+
|
|
60
63
|
const { useCamelCase } = getOptions();
|
|
61
|
-
if (useCamelCase && value && typeof value ===
|
|
64
|
+
if (useCamelCase && value && typeof value === 'object') {
|
|
62
65
|
value = toCamel(value);
|
|
63
66
|
}
|
|
67
|
+
|
|
64
68
|
if (path || value instanceof Array) {
|
|
65
|
-
let upData =
|
|
69
|
+
let upData = { ...(data || {}) };
|
|
66
70
|
let upPath = useCamelCase ? toCamelPath(path) : path;
|
|
67
|
-
set(upData, upPath ||
|
|
71
|
+
set(upData, upPath || '', value);
|
|
68
72
|
data = upData;
|
|
69
|
-
} else if (value && typeof value ===
|
|
73
|
+
} else if (value && typeof value === 'object') {
|
|
70
74
|
data = data || {};
|
|
71
75
|
data = merge(data, value);
|
|
72
76
|
} else {
|
|
73
77
|
data = value;
|
|
74
78
|
}
|
|
79
|
+
|
|
75
80
|
this.values(details, { data });
|
|
81
|
+
|
|
76
82
|
try {
|
|
83
|
+
// Make sure values have clean refs
|
|
77
84
|
const cache = VALUES[model][id];
|
|
78
|
-
if (cache !==
|
|
79
|
-
if (cache.data !==
|
|
85
|
+
if (cache !== undefined) {
|
|
86
|
+
if (cache.data !== undefined) {
|
|
80
87
|
cache.data = JSON.parse(JSON.stringify(cache.data));
|
|
81
88
|
}
|
|
82
|
-
if (cache.record !==
|
|
89
|
+
if (cache.record !== undefined) {
|
|
83
90
|
cache.record = JSON.parse(JSON.stringify(cache.record));
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
93
|
} catch (err) {
|
|
94
|
+
// noop
|
|
87
95
|
}
|
|
88
96
|
},
|
|
97
|
+
|
|
89
98
|
get(model, id) {
|
|
90
|
-
this.debug(
|
|
99
|
+
this.debug('cache.get', ...arguments);
|
|
91
100
|
const { data, recordTimer } = this.values({ model, id });
|
|
92
|
-
this.debug(
|
|
101
|
+
this.debug('cache.get:data+recordTimer', ...arguments);
|
|
93
102
|
if (recordTimer) {
|
|
94
103
|
return data;
|
|
95
104
|
}
|
|
96
105
|
},
|
|
106
|
+
|
|
97
107
|
setRecord(record, details) {
|
|
98
|
-
this.debug(
|
|
108
|
+
this.debug('cache.setRecord', ...arguments);
|
|
99
109
|
let { recordTimer, presets } = this.values(details);
|
|
110
|
+
|
|
100
111
|
if (recordTimer) {
|
|
101
112
|
clearTimeout(recordTimer);
|
|
102
113
|
}
|
|
114
|
+
|
|
103
115
|
recordTimer = setTimeout(() => {
|
|
104
|
-
this.values(details, { record:
|
|
116
|
+
this.values(details, { record: undefined, recordTimer: undefined });
|
|
105
117
|
}, RECORD_TIMEOUT);
|
|
118
|
+
|
|
119
|
+
// Record has to be null at minimum, not undefined
|
|
106
120
|
this.values(details, {
|
|
107
|
-
record: record !==
|
|
108
|
-
recordTimer
|
|
121
|
+
record: record !== undefined ? record : null,
|
|
122
|
+
recordTimer,
|
|
109
123
|
});
|
|
124
|
+
|
|
110
125
|
if (presets) {
|
|
111
126
|
for (let preset of presets) {
|
|
112
127
|
this.set(preset);
|
|
113
128
|
}
|
|
114
|
-
this.values(details, { presets:
|
|
129
|
+
this.values(details, { presets: undefined });
|
|
115
130
|
}
|
|
131
|
+
|
|
116
132
|
const result = this.get(details.model, details.id);
|
|
117
|
-
|
|
133
|
+
|
|
134
|
+
return result !== undefined ? result : record;
|
|
118
135
|
},
|
|
136
|
+
|
|
119
137
|
async getFetch(model, id, fetch) {
|
|
120
138
|
if (this.options.enabled) {
|
|
121
|
-
this.debug(
|
|
139
|
+
this.debug('cache.getFetch', ...arguments);
|
|
122
140
|
const value = this.get(model, id);
|
|
123
|
-
|
|
141
|
+
|
|
142
|
+
if (value !== undefined) {
|
|
124
143
|
return value;
|
|
125
144
|
}
|
|
126
145
|
}
|
|
146
|
+
|
|
127
147
|
const record = await fetch();
|
|
128
148
|
return this.setRecord(record, { model, id });
|
|
129
149
|
},
|
|
130
|
-
|
|
131
|
-
|
|
150
|
+
|
|
151
|
+
clear(model = undefined, id = undefined) {
|
|
152
|
+
this.debug('cache.clear', ...arguments);
|
|
132
153
|
if (model) {
|
|
133
154
|
if (id) {
|
|
134
|
-
set(VALUES, `${model}.${id}`,
|
|
155
|
+
set(VALUES, `${model}.${id}`, undefined);
|
|
135
156
|
} else {
|
|
136
|
-
set(VALUES, model,
|
|
157
|
+
set(VALUES, model, undefined);
|
|
137
158
|
}
|
|
138
159
|
} else {
|
|
139
160
|
VALUES = {};
|
|
140
161
|
}
|
|
141
|
-
}
|
|
162
|
+
},
|
|
142
163
|
};
|
|
143
164
|
|
|
144
165
|
export { cacheApi as c };
|
package/dist/cache.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
export { c as default } from './cache-
|
|
2
|
-
import './index-
|
|
1
|
+
export { c as default } from './cache-70cd9241.js';
|
|
2
|
+
import './index-bee7164f.js';
|
|
3
3
|
import 'qs';
|
|
4
|
-
import 'lodash/set';
|
|
5
|
-
import 'lodash/get';
|
|
6
|
-
import 'lodash/uniq';
|
|
7
|
-
import 'lodash/find';
|
|
8
|
-
import 'lodash/round';
|
|
9
|
-
import 'lodash/findIndex';
|
|
10
|
-
import 'lodash/camelCase';
|
|
11
|
-
import 'lodash/snakeCase';
|
|
12
|
-
import 'lodash/cloneDeep';
|
|
13
|
-
import 'lodash/isEqual';
|
|
14
4
|
import 'deepmerge';
|
|
15
|
-
import '
|
|
5
|
+
import 'fast-case';
|