swell-js 3.23.2 → 3.24.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.6ceb5c2c.mjs +322 -0
- package/dist/api.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/swell.cjs +146 -33
- package/dist/swell.cjs.map +1 -1
- package/dist/swell.umd.min.js +495 -375
- package/dist/swell.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +52 -12
- package/dist/api.1a1cff2e.mjs +0 -209
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { c as cardApi } from './card.982ad378.mjs';
|
|
2
|
+
import { g as getCookie, s as setCookie } from './cookie.40ff798c.mjs';
|
|
3
|
+
import { c as cacheApi } from './cache.70033487.mjs';
|
|
4
|
+
import { m as methods$3 } from './cart.dd00d6d6.mjs';
|
|
5
|
+
import { m as methods$4 } from './account.d991b136.mjs';
|
|
6
|
+
import { m as methods$5 } from './products.c20a4350.mjs';
|
|
7
|
+
import { m as methods$6 } from './categories.f6027058.mjs';
|
|
8
|
+
import { m as methods$7 } from './attributes.b332bfad.mjs';
|
|
9
|
+
import { m as methods$8 } from './subscriptions.fd44cccc.mjs';
|
|
10
|
+
import { d as defaultMethods, j as trimEnd, E as utils, i as trimStart, h as trimBoth, f as toSnake, k as stringifyQuery, y as base64Encode, t as toCamel, b as setOptions } from './index.b29eadc6.mjs';
|
|
11
|
+
import { m as methods$9 } from './content.5b4bea62.mjs';
|
|
12
|
+
import { m as methods$a } from './settings.6c0d2563.mjs';
|
|
13
|
+
import { P as PaymentController } from './index.33151a3b.mjs';
|
|
14
|
+
import { m as methods$b } from './locale.9d7241ac.mjs';
|
|
15
|
+
import { m as methods$c } from './currency.e2cd8985.mjs';
|
|
16
|
+
|
|
17
|
+
function methods$2(request) {
|
|
18
|
+
const { get, list } = defaultMethods(request, '/invoices', ['list', 'get']);
|
|
19
|
+
return {
|
|
20
|
+
get: (id, ...args) => {
|
|
21
|
+
return cacheApi.getFetch('invoices', id, () => get(id, ...args));
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
list,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function methods$1(request, opt) {
|
|
29
|
+
return {
|
|
30
|
+
/**
|
|
31
|
+
* Get the decoded session as an object of session values
|
|
32
|
+
*/
|
|
33
|
+
get() {
|
|
34
|
+
return request('get', '/session');
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the encoded session cookie
|
|
39
|
+
* This simplifies storing or passing the session to another system
|
|
40
|
+
*/
|
|
41
|
+
getCookie() {
|
|
42
|
+
return opt.getCookie('swell-session');
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Set the encoded session cookie
|
|
47
|
+
* This simplifies restoring the session from another system
|
|
48
|
+
*/
|
|
49
|
+
setCookie(value) {
|
|
50
|
+
opt.setCookie('swell-session', value);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function methods(request, _opt) {
|
|
56
|
+
return {
|
|
57
|
+
/**
|
|
58
|
+
* Make a request to an app function and greceiveet a response
|
|
59
|
+
* @param {string} method
|
|
60
|
+
* @param {string} appId
|
|
61
|
+
* @param {string} functionName
|
|
62
|
+
* @param {any} data
|
|
63
|
+
* @param {object?} options
|
|
64
|
+
* @returns {any}
|
|
65
|
+
*/
|
|
66
|
+
request(method, appId, functionName, data, options = undefined) {
|
|
67
|
+
return request(method, functionName, undefined, data, {
|
|
68
|
+
...options,
|
|
69
|
+
path: `/functions/${appId}`,
|
|
70
|
+
useCamelCase: false, // avoid mutating data
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Helper to make a GET request to an app function and receive a response
|
|
76
|
+
* @param {string} appId
|
|
77
|
+
* @param {string} functionName
|
|
78
|
+
* @param {any} data
|
|
79
|
+
* @param {object?} options
|
|
80
|
+
* @returns {any}
|
|
81
|
+
*/
|
|
82
|
+
get(appId, functionName, data, options = undefined) {
|
|
83
|
+
return this.request('get', appId, functionName, data, options);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Helper to make a PUT request to an app function and receive a response
|
|
88
|
+
* @param {string} appId
|
|
89
|
+
* @param {string} functionName
|
|
90
|
+
* @param {any} data
|
|
91
|
+
* @param {object?} options
|
|
92
|
+
* @returns {any}
|
|
93
|
+
*/
|
|
94
|
+
put(appId, functionName, data, options = undefined) {
|
|
95
|
+
return this.request('put', appId, functionName, data, options);
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Helper to make a POST request to an app function and receive a response
|
|
100
|
+
* @param {string} appId
|
|
101
|
+
* @param {string} functionName
|
|
102
|
+
* @param {any} data
|
|
103
|
+
* @param {object?} options
|
|
104
|
+
* @returns {any}
|
|
105
|
+
*/
|
|
106
|
+
post(appId, functionName, data, options = undefined) {
|
|
107
|
+
return this.request('post', appId, functionName, data, options);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Helper to make a DELETE request to an app function and receive a response
|
|
112
|
+
* @param {string} appId
|
|
113
|
+
* @param {string} functionName
|
|
114
|
+
* @param {any} data
|
|
115
|
+
* @param {object?} options
|
|
116
|
+
* @returns {any}
|
|
117
|
+
*/
|
|
118
|
+
delete(appId, functionName, data, options = undefined) {
|
|
119
|
+
return this.request('delete', appId, functionName, data, options);
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const options = {
|
|
125
|
+
store: null,
|
|
126
|
+
key: null,
|
|
127
|
+
url: null,
|
|
128
|
+
useCamelCase: null,
|
|
129
|
+
previewContent: null,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const api = {
|
|
133
|
+
version: '3.24.0',
|
|
134
|
+
options,
|
|
135
|
+
request,
|
|
136
|
+
|
|
137
|
+
init(store, key, opt = {}) {
|
|
138
|
+
options.key = key;
|
|
139
|
+
options.store = store;
|
|
140
|
+
options.url = opt.url
|
|
141
|
+
? trimEnd(opt.url)
|
|
142
|
+
: `https://${store}.swell.store`;
|
|
143
|
+
options.vaultUrl = opt.vaultUrl
|
|
144
|
+
? trimEnd(opt.vaultUrl)
|
|
145
|
+
: `https://vault.schema.io`;
|
|
146
|
+
options.timeout = (opt.timeout && parseInt(opt.timeout, 10)) || 20000;
|
|
147
|
+
options.useCamelCase = opt.useCamelCase || false;
|
|
148
|
+
options.previewContent = opt.previewContent || false;
|
|
149
|
+
options.session = opt.session;
|
|
150
|
+
options.locale = opt.locale;
|
|
151
|
+
options.currency = opt.currency;
|
|
152
|
+
options.api = api;
|
|
153
|
+
options.getCookie = opt.getCookie || getCookie;
|
|
154
|
+
options.setCookie = opt.setCookie || setCookie;
|
|
155
|
+
options.getCart = opt.getCart;
|
|
156
|
+
options.updateCart = opt.updateCart;
|
|
157
|
+
setOptions(options);
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
// Backward compatibility
|
|
161
|
+
auth(...args) {
|
|
162
|
+
return this.init(...args);
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
get(url, query) {
|
|
166
|
+
return request('get', url, query);
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
put(url, data) {
|
|
170
|
+
return request('put', url, data);
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
post(url, data) {
|
|
174
|
+
return request('post', url, data);
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
delete(url, data) {
|
|
178
|
+
return request('delete', url, data);
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
cache: cacheApi,
|
|
182
|
+
|
|
183
|
+
card: cardApi,
|
|
184
|
+
|
|
185
|
+
cart: methods$3(request, options),
|
|
186
|
+
|
|
187
|
+
account: methods$4(request),
|
|
188
|
+
|
|
189
|
+
products: methods$5(request, options),
|
|
190
|
+
|
|
191
|
+
categories: methods$6(request),
|
|
192
|
+
|
|
193
|
+
attributes: methods$7(request),
|
|
194
|
+
|
|
195
|
+
subscriptions: methods$8(request),
|
|
196
|
+
|
|
197
|
+
invoices: methods$2(request),
|
|
198
|
+
|
|
199
|
+
content: methods$9(request, options),
|
|
200
|
+
|
|
201
|
+
settings: methods$a(request, options),
|
|
202
|
+
|
|
203
|
+
payment: new PaymentController(request, options),
|
|
204
|
+
|
|
205
|
+
locale: methods$b(request, options),
|
|
206
|
+
|
|
207
|
+
currency: methods$c(request, options),
|
|
208
|
+
|
|
209
|
+
session: methods$1(request, options),
|
|
210
|
+
|
|
211
|
+
functions: methods(request),
|
|
212
|
+
|
|
213
|
+
utils,
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
async function request(
|
|
217
|
+
method,
|
|
218
|
+
url,
|
|
219
|
+
id = undefined,
|
|
220
|
+
data = undefined,
|
|
221
|
+
opt = undefined,
|
|
222
|
+
) {
|
|
223
|
+
const allOptions = {
|
|
224
|
+
...options,
|
|
225
|
+
...opt,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const session = allOptions.session || allOptions.getCookie('swell-session');
|
|
229
|
+
const locale = allOptions.locale || allOptions.getCookie('swell-locale');
|
|
230
|
+
const currency =
|
|
231
|
+
allOptions.currency || allOptions.getCookie('swell-currency');
|
|
232
|
+
const path = allOptions.path || '/api';
|
|
233
|
+
|
|
234
|
+
const baseUrl = `${allOptions.url}${allOptions.base || ''}${path}`;
|
|
235
|
+
const reqMethod = String(method).toLowerCase();
|
|
236
|
+
|
|
237
|
+
let reqUrl = url;
|
|
238
|
+
let reqData = id;
|
|
239
|
+
|
|
240
|
+
if (data !== undefined || typeof id === 'string') {
|
|
241
|
+
reqUrl = [trimEnd(url), trimStart(id)].join('/');
|
|
242
|
+
reqData = data;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
reqUrl = allOptions.fullUrl || `${baseUrl}/${trimBoth(reqUrl)}`;
|
|
246
|
+
reqData = allOptions.useCamelCase ? toSnake(reqData) : reqData;
|
|
247
|
+
|
|
248
|
+
let reqBody;
|
|
249
|
+
if (reqMethod === 'get') {
|
|
250
|
+
let exQuery;
|
|
251
|
+
[reqUrl, exQuery] = reqUrl.split('?');
|
|
252
|
+
const fullQuery = [exQuery, stringifyQuery(reqData)]
|
|
253
|
+
.join('&')
|
|
254
|
+
.replace(/^&/, '');
|
|
255
|
+
reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ''}`;
|
|
256
|
+
} else {
|
|
257
|
+
reqBody = JSON.stringify(reqData);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const reqHeaders = {
|
|
261
|
+
Accept: 'application/json',
|
|
262
|
+
'Content-Type': 'application/json',
|
|
263
|
+
Authorization: `Basic ${base64Encode(String(allOptions.key))}`,
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
if (session) {
|
|
267
|
+
reqHeaders['X-Session'] = session;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (locale) {
|
|
271
|
+
reqHeaders['X-Locale'] = locale;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (currency) {
|
|
275
|
+
reqHeaders['X-Currency'] = currency;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const response = await fetch(reqUrl, {
|
|
279
|
+
method: reqMethod,
|
|
280
|
+
headers: reqHeaders,
|
|
281
|
+
body: reqBody,
|
|
282
|
+
credentials: 'include',
|
|
283
|
+
mode: 'cors',
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const responseSession = response.headers.get('X-Session');
|
|
287
|
+
|
|
288
|
+
if (typeof responseSession === 'string' && session !== responseSession) {
|
|
289
|
+
allOptions.setCookie('swell-session', responseSession);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Response could be text, json, or empty
|
|
293
|
+
let result = null;
|
|
294
|
+
try {
|
|
295
|
+
result = await response.text();
|
|
296
|
+
try {
|
|
297
|
+
result = JSON.parse(result);
|
|
298
|
+
} catch (err) {
|
|
299
|
+
// noop
|
|
300
|
+
}
|
|
301
|
+
} catch (err) {
|
|
302
|
+
// noop
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (result && result.error) {
|
|
306
|
+
const err = new Error(result.error.message || result.error);
|
|
307
|
+
err.status = response.status;
|
|
308
|
+
err.code = result.error.code;
|
|
309
|
+
err.param = result.error.param;
|
|
310
|
+
throw err;
|
|
311
|
+
} else if (!response.ok) {
|
|
312
|
+
const err = new Error(
|
|
313
|
+
'A connection error occurred while making the request',
|
|
314
|
+
);
|
|
315
|
+
err.code = 'connection_error';
|
|
316
|
+
throw err;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return allOptions.useCamelCase ? toCamel(result) : result;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export { api as a };
|
package/dist/api.mjs
CHANGED
package/dist/index.mjs
CHANGED
package/dist/swell.cjs
CHANGED
|
@@ -5106,7 +5106,7 @@ const cacheApi = {
|
|
|
5106
5106
|
},
|
|
5107
5107
|
};
|
|
5108
5108
|
|
|
5109
|
-
function methods$
|
|
5109
|
+
function methods$c(request) {
|
|
5110
5110
|
const { get, list } = defaultMethods(request, '/attributes', ['list', 'get']);
|
|
5111
5111
|
|
|
5112
5112
|
return {
|
|
@@ -5120,7 +5120,7 @@ function methods$a(request) {
|
|
|
5120
5120
|
|
|
5121
5121
|
let OPTIONS;
|
|
5122
5122
|
|
|
5123
|
-
function methods$
|
|
5123
|
+
function methods$b(request, opt) {
|
|
5124
5124
|
OPTIONS = opt;
|
|
5125
5125
|
const { get, list } = defaultMethods(request, '/products', ['list', 'get']);
|
|
5126
5126
|
return {
|
|
@@ -5329,7 +5329,7 @@ function findPurchaseOption(product, purchaseOption) {
|
|
|
5329
5329
|
}
|
|
5330
5330
|
|
|
5331
5331
|
async function getFilterableAttributeFilters(request, products, options) {
|
|
5332
|
-
const { results: filterableAttributes } = await methods$
|
|
5332
|
+
const { results: filterableAttributes } = await methods$c(
|
|
5333
5333
|
request).list({
|
|
5334
5334
|
filterable: true,
|
|
5335
5335
|
});
|
|
@@ -5514,7 +5514,7 @@ function getPriceRange(products) {
|
|
|
5514
5514
|
};
|
|
5515
5515
|
}
|
|
5516
5516
|
|
|
5517
|
-
function methods$
|
|
5517
|
+
function methods$a(request, options) {
|
|
5518
5518
|
return {
|
|
5519
5519
|
state: null,
|
|
5520
5520
|
order: null,
|
|
@@ -5696,7 +5696,7 @@ function methods$8(request, options) {
|
|
|
5696
5696
|
};
|
|
5697
5697
|
}
|
|
5698
5698
|
|
|
5699
|
-
function methods$
|
|
5699
|
+
function methods$9(request) {
|
|
5700
5700
|
return {
|
|
5701
5701
|
state: null,
|
|
5702
5702
|
|
|
@@ -5795,7 +5795,7 @@ function methods$7(request) {
|
|
|
5795
5795
|
};
|
|
5796
5796
|
}
|
|
5797
5797
|
|
|
5798
|
-
function methods$
|
|
5798
|
+
function methods$8(request) {
|
|
5799
5799
|
const { get, list } = defaultMethods(request, '/categories', ['list', 'get']);
|
|
5800
5800
|
|
|
5801
5801
|
return {
|
|
@@ -5807,7 +5807,7 @@ function methods$6(request) {
|
|
|
5807
5807
|
};
|
|
5808
5808
|
}
|
|
5809
5809
|
|
|
5810
|
-
function methods$
|
|
5810
|
+
function methods$7(request) {
|
|
5811
5811
|
const { get, list } = defaultMethods(request, '/subscriptions', [
|
|
5812
5812
|
'list',
|
|
5813
5813
|
'get',
|
|
@@ -5871,7 +5871,7 @@ function methods$5(request) {
|
|
|
5871
5871
|
};
|
|
5872
5872
|
}
|
|
5873
5873
|
|
|
5874
|
-
function methods$
|
|
5874
|
+
function methods$6(request) {
|
|
5875
5875
|
const { get, list } = defaultMethods(request, '/invoices', ['list', 'get']);
|
|
5876
5876
|
return {
|
|
5877
5877
|
get: (id, ...args) => {
|
|
@@ -5882,7 +5882,7 @@ function methods$4(request) {
|
|
|
5882
5882
|
};
|
|
5883
5883
|
}
|
|
5884
5884
|
|
|
5885
|
-
function methods$
|
|
5885
|
+
function methods$5(request, opt) {
|
|
5886
5886
|
return {
|
|
5887
5887
|
get: (type, id, query) => {
|
|
5888
5888
|
return cacheApi.getFetch(`content_${type}`, id, () =>
|
|
@@ -5897,7 +5897,7 @@ function methods$3(request, opt) {
|
|
|
5897
5897
|
};
|
|
5898
5898
|
}
|
|
5899
5899
|
|
|
5900
|
-
function methods$
|
|
5900
|
+
function methods$4(request, opt) {
|
|
5901
5901
|
return {
|
|
5902
5902
|
state: null,
|
|
5903
5903
|
menuState: null,
|
|
@@ -6188,6 +6188,33 @@ function decodeLocaleValue(locale, values, key, configs, opt) {
|
|
|
6188
6188
|
}
|
|
6189
6189
|
}
|
|
6190
6190
|
|
|
6191
|
+
function methods$3(request, opt) {
|
|
6192
|
+
return {
|
|
6193
|
+
/**
|
|
6194
|
+
* Get the decoded session as an object of session values
|
|
6195
|
+
*/
|
|
6196
|
+
get() {
|
|
6197
|
+
return request('get', '/session');
|
|
6198
|
+
},
|
|
6199
|
+
|
|
6200
|
+
/**
|
|
6201
|
+
* Get the encoded session cookie
|
|
6202
|
+
* This simplifies storing or passing the session to another system
|
|
6203
|
+
*/
|
|
6204
|
+
getCookie() {
|
|
6205
|
+
return opt.getCookie('swell-session');
|
|
6206
|
+
},
|
|
6207
|
+
|
|
6208
|
+
/**
|
|
6209
|
+
* Set the encoded session cookie
|
|
6210
|
+
* This simplifies restoring the session from another system
|
|
6211
|
+
*/
|
|
6212
|
+
setCookie(value) {
|
|
6213
|
+
opt.setCookie('swell-session', value);
|
|
6214
|
+
},
|
|
6215
|
+
};
|
|
6216
|
+
}
|
|
6217
|
+
|
|
6191
6218
|
const SCRIPT_HANDLERS = {
|
|
6192
6219
|
'stripe-js': loadStripe,
|
|
6193
6220
|
'paypal-sdk': loadPaypal,
|
|
@@ -6507,7 +6534,7 @@ class Payment {
|
|
|
6507
6534
|
* @returns {object}
|
|
6508
6535
|
*/
|
|
6509
6536
|
async getCart() {
|
|
6510
|
-
const cart = await methods$
|
|
6537
|
+
const cart = await methods$a(this.request, this.options).get();
|
|
6511
6538
|
|
|
6512
6539
|
if (!cart) {
|
|
6513
6540
|
throw new Error('Cart not found');
|
|
@@ -6535,7 +6562,7 @@ class Payment {
|
|
|
6535
6562
|
}
|
|
6536
6563
|
}
|
|
6537
6564
|
|
|
6538
|
-
const updatedCart = await methods$
|
|
6565
|
+
const updatedCart = await methods$a(this.request, this.options).update(
|
|
6539
6566
|
updateData,
|
|
6540
6567
|
);
|
|
6541
6568
|
|
|
@@ -6548,7 +6575,7 @@ class Payment {
|
|
|
6548
6575
|
* @returns {object}
|
|
6549
6576
|
*/
|
|
6550
6577
|
async getSettings() {
|
|
6551
|
-
return methods$
|
|
6578
|
+
return methods$4(this.request, this.options).get();
|
|
6552
6579
|
}
|
|
6553
6580
|
|
|
6554
6581
|
/**
|
|
@@ -9418,7 +9445,7 @@ class PaymentController {
|
|
|
9418
9445
|
}
|
|
9419
9446
|
|
|
9420
9447
|
async _getPaymentMethods() {
|
|
9421
|
-
const paymentMethods = await methods$
|
|
9448
|
+
const paymentMethods = await methods$4(
|
|
9422
9449
|
this.request,
|
|
9423
9450
|
this.options,
|
|
9424
9451
|
).payments();
|
|
@@ -9626,7 +9653,7 @@ class PaymentController {
|
|
|
9626
9653
|
}
|
|
9627
9654
|
}
|
|
9628
9655
|
|
|
9629
|
-
function methods$
|
|
9656
|
+
function methods$2(request, opt) {
|
|
9630
9657
|
return {
|
|
9631
9658
|
code: null,
|
|
9632
9659
|
state: null,
|
|
@@ -9672,7 +9699,7 @@ function methods$1(request, opt) {
|
|
|
9672
9699
|
|
|
9673
9700
|
const FORMATTERS = {};
|
|
9674
9701
|
|
|
9675
|
-
function methods(request, opt) {
|
|
9702
|
+
function methods$1(request, opt) {
|
|
9676
9703
|
return {
|
|
9677
9704
|
code: null,
|
|
9678
9705
|
state: null,
|
|
@@ -9860,6 +9887,75 @@ function methods(request, opt) {
|
|
|
9860
9887
|
};
|
|
9861
9888
|
}
|
|
9862
9889
|
|
|
9890
|
+
function methods(request, _opt) {
|
|
9891
|
+
return {
|
|
9892
|
+
/**
|
|
9893
|
+
* Make a request to an app function and greceiveet a response
|
|
9894
|
+
* @param {string} method
|
|
9895
|
+
* @param {string} appId
|
|
9896
|
+
* @param {string} functionName
|
|
9897
|
+
* @param {any} data
|
|
9898
|
+
* @param {object?} options
|
|
9899
|
+
* @returns {any}
|
|
9900
|
+
*/
|
|
9901
|
+
request(method, appId, functionName, data, options = undefined) {
|
|
9902
|
+
return request(method, functionName, undefined, data, {
|
|
9903
|
+
...options,
|
|
9904
|
+
path: `/functions/${appId}`,
|
|
9905
|
+
useCamelCase: false, // avoid mutating data
|
|
9906
|
+
});
|
|
9907
|
+
},
|
|
9908
|
+
|
|
9909
|
+
/**
|
|
9910
|
+
* Helper to make a GET request to an app function and receive a response
|
|
9911
|
+
* @param {string} appId
|
|
9912
|
+
* @param {string} functionName
|
|
9913
|
+
* @param {any} data
|
|
9914
|
+
* @param {object?} options
|
|
9915
|
+
* @returns {any}
|
|
9916
|
+
*/
|
|
9917
|
+
get(appId, functionName, data, options = undefined) {
|
|
9918
|
+
return this.request('get', appId, functionName, data, options);
|
|
9919
|
+
},
|
|
9920
|
+
|
|
9921
|
+
/**
|
|
9922
|
+
* Helper to make a PUT request to an app function and receive a response
|
|
9923
|
+
* @param {string} appId
|
|
9924
|
+
* @param {string} functionName
|
|
9925
|
+
* @param {any} data
|
|
9926
|
+
* @param {object?} options
|
|
9927
|
+
* @returns {any}
|
|
9928
|
+
*/
|
|
9929
|
+
put(appId, functionName, data, options = undefined) {
|
|
9930
|
+
return this.request('put', appId, functionName, data, options);
|
|
9931
|
+
},
|
|
9932
|
+
|
|
9933
|
+
/**
|
|
9934
|
+
* Helper to make a POST request to an app function and receive a response
|
|
9935
|
+
* @param {string} appId
|
|
9936
|
+
* @param {string} functionName
|
|
9937
|
+
* @param {any} data
|
|
9938
|
+
* @param {object?} options
|
|
9939
|
+
* @returns {any}
|
|
9940
|
+
*/
|
|
9941
|
+
post(appId, functionName, data, options = undefined) {
|
|
9942
|
+
return this.request('post', appId, functionName, data, options);
|
|
9943
|
+
},
|
|
9944
|
+
|
|
9945
|
+
/**
|
|
9946
|
+
* Helper to make a DELETE request to an app function and receive a response
|
|
9947
|
+
* @param {string} appId
|
|
9948
|
+
* @param {string} functionName
|
|
9949
|
+
* @param {any} data
|
|
9950
|
+
* @param {object?} options
|
|
9951
|
+
* @returns {any}
|
|
9952
|
+
*/
|
|
9953
|
+
delete(appId, functionName, data, options = undefined) {
|
|
9954
|
+
return this.request('delete', appId, functionName, data, options);
|
|
9955
|
+
},
|
|
9956
|
+
};
|
|
9957
|
+
}
|
|
9958
|
+
|
|
9863
9959
|
const options = {
|
|
9864
9960
|
store: null,
|
|
9865
9961
|
key: null,
|
|
@@ -9869,7 +9965,7 @@ const options = {
|
|
|
9869
9965
|
};
|
|
9870
9966
|
|
|
9871
9967
|
const api = {
|
|
9872
|
-
version: '3.
|
|
9968
|
+
version: '3.24.0',
|
|
9873
9969
|
options,
|
|
9874
9970
|
request,
|
|
9875
9971
|
|
|
@@ -9921,29 +10017,33 @@ const api = {
|
|
|
9921
10017
|
|
|
9922
10018
|
card: cardApi,
|
|
9923
10019
|
|
|
9924
|
-
cart: methods$
|
|
10020
|
+
cart: methods$a(request, options),
|
|
9925
10021
|
|
|
9926
|
-
account: methods$
|
|
10022
|
+
account: methods$9(request),
|
|
9927
10023
|
|
|
9928
|
-
products: methods$
|
|
10024
|
+
products: methods$b(request, options),
|
|
9929
10025
|
|
|
9930
|
-
categories: methods$
|
|
10026
|
+
categories: methods$8(request),
|
|
9931
10027
|
|
|
9932
|
-
attributes: methods$
|
|
10028
|
+
attributes: methods$c(request),
|
|
9933
10029
|
|
|
9934
|
-
subscriptions: methods$
|
|
10030
|
+
subscriptions: methods$7(request),
|
|
9935
10031
|
|
|
9936
|
-
invoices: methods$
|
|
10032
|
+
invoices: methods$6(request),
|
|
9937
10033
|
|
|
9938
|
-
content: methods$
|
|
10034
|
+
content: methods$5(request, options),
|
|
9939
10035
|
|
|
9940
|
-
settings: methods$
|
|
10036
|
+
settings: methods$4(request, options),
|
|
9941
10037
|
|
|
9942
10038
|
payment: new PaymentController(request, options),
|
|
9943
10039
|
|
|
9944
|
-
locale: methods$
|
|
10040
|
+
locale: methods$2(request, options),
|
|
10041
|
+
|
|
10042
|
+
currency: methods$1(request, options),
|
|
9945
10043
|
|
|
9946
|
-
|
|
10044
|
+
session: methods$3(request, options),
|
|
10045
|
+
|
|
10046
|
+
functions: methods(request),
|
|
9947
10047
|
|
|
9948
10048
|
utils,
|
|
9949
10049
|
};
|
|
@@ -9962,9 +10062,11 @@ async function request(
|
|
|
9962
10062
|
|
|
9963
10063
|
const session = allOptions.session || allOptions.getCookie('swell-session');
|
|
9964
10064
|
const locale = allOptions.locale || allOptions.getCookie('swell-locale');
|
|
9965
|
-
const currency =
|
|
10065
|
+
const currency =
|
|
10066
|
+
allOptions.currency || allOptions.getCookie('swell-currency');
|
|
10067
|
+
const path = allOptions.path || '/api';
|
|
9966
10068
|
|
|
9967
|
-
const baseUrl = `${allOptions.url}${allOptions.base || ''}
|
|
10069
|
+
const baseUrl = `${allOptions.url}${allOptions.base || ''}${path}`;
|
|
9968
10070
|
const reqMethod = String(method).toLowerCase();
|
|
9969
10071
|
|
|
9970
10072
|
let reqUrl = url;
|
|
@@ -10022,10 +10124,21 @@ async function request(
|
|
|
10022
10124
|
allOptions.setCookie('swell-session', responseSession);
|
|
10023
10125
|
}
|
|
10024
10126
|
|
|
10025
|
-
|
|
10127
|
+
// Response could be text, json, or empty
|
|
10128
|
+
let result = null;
|
|
10129
|
+
try {
|
|
10130
|
+
result = await response.text();
|
|
10131
|
+
try {
|
|
10132
|
+
result = JSON.parse(result);
|
|
10133
|
+
} catch (err) {
|
|
10134
|
+
// noop
|
|
10135
|
+
}
|
|
10136
|
+
} catch (err) {
|
|
10137
|
+
// noop
|
|
10138
|
+
}
|
|
10026
10139
|
|
|
10027
10140
|
if (result && result.error) {
|
|
10028
|
-
const err = new Error(result.error.message);
|
|
10141
|
+
const err = new Error(result.error.message || result.error);
|
|
10029
10142
|
err.status = response.status;
|
|
10030
10143
|
err.code = result.error.code;
|
|
10031
10144
|
err.param = result.error.param;
|
|
@@ -10038,7 +10151,7 @@ async function request(
|
|
|
10038
10151
|
throw err;
|
|
10039
10152
|
}
|
|
10040
10153
|
|
|
10041
|
-
return
|
|
10154
|
+
return allOptions.useCamelCase ? toCamel(result) : result;
|
|
10042
10155
|
}
|
|
10043
10156
|
|
|
10044
10157
|
module.exports = api;
|