oneentry 1.0.152 → 1.0.154
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/changelog.md +49 -0
- package/dist/admins/adminsApi.d.ts +2 -1
- package/dist/admins/adminsApi.js +2 -1
- package/dist/admins/adminsInterfaces.d.ts +1 -1
- package/dist/attribute-sets/attributeSetsApi.d.ts +4 -0
- package/dist/attribute-sets/attributeSetsApi.js +4 -0
- package/dist/auth-provider/authProviderApi.d.ts +14 -1
- package/dist/auth-provider/authProviderApi.js +14 -1
- package/dist/base/asyncModules.d.ts +21 -2
- package/dist/base/asyncModules.js +74 -225
- package/dist/base/stateModule.d.ts +4 -13
- package/dist/base/stateModule.js +12 -96
- package/dist/base/syncModules.d.ts +4 -0
- package/dist/base/syncModules.js +5 -1
- package/dist/blocks/blocksApi.d.ts +54 -11
- package/dist/blocks/blocksApi.js +90 -73
- package/dist/blocks/blocksInterfaces.d.ts +18 -9
- package/dist/discounts/discountsApi.d.ts +5 -0
- package/dist/discounts/discountsApi.js +5 -0
- package/dist/events/eventsApi.d.ts +7 -0
- package/dist/events/eventsApi.js +11 -28
- package/dist/file-uploading/fileUploadingApi.d.ts +4 -1
- package/dist/file-uploading/fileUploadingApi.js +4 -1
- package/dist/file-uploading/fileUploadingInterfaces.d.ts +1 -1
- package/dist/filters/filtersApi.d.ts +1 -0
- package/dist/filters/filtersApi.js +1 -0
- package/dist/forms/formsApi.d.ts +2 -0
- package/dist/forms/formsApi.js +2 -0
- package/dist/forms-data/formsDataApi.d.ts +5 -0
- package/dist/forms-data/formsDataApi.js +5 -0
- package/dist/general-types/generalTypesApi.d.ts +1 -0
- package/dist/general-types/generalTypesApi.js +1 -0
- package/dist/index.js +12 -0
- package/dist/integration-collections/integrationCollectionsApi.d.ts +10 -1
- package/dist/integration-collections/integrationCollectionsApi.js +10 -1
- package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +1 -1
- package/dist/locales/localesApi.d.ts +1 -0
- package/dist/locales/localesApi.js +1 -0
- package/dist/menus/menusApi.d.ts +1 -0
- package/dist/menus/menusApi.js +1 -0
- package/dist/orders/ordersApi.d.ts +25 -1
- package/dist/orders/ordersApi.js +36 -12
- package/dist/orders/ordersInterfaces.d.ts +5 -2
- package/dist/pages/pagesApi.d.ts +9 -0
- package/dist/pages/pagesApi.js +35 -39
- package/dist/pages/pagesInterfaces.d.ts +5 -0
- package/dist/payments/paymentsApi.d.ts +6 -0
- package/dist/payments/paymentsApi.js +6 -0
- package/dist/product-statuses/productStatusesApi.d.ts +3 -0
- package/dist/product-statuses/productStatusesApi.js +3 -0
- package/dist/products/productsApi.d.ts +39 -64
- package/dist/products/productsApi.js +33 -61
- package/dist/products/productsInterfaces.d.ts +76 -72
- package/dist/sitemap/sitemapApi.d.ts +2 -0
- package/dist/sitemap/sitemapApi.js +2 -0
- package/dist/subscriptions/subscriptionsApi.d.ts +5 -0
- package/dist/subscriptions/subscriptionsApi.js +7 -14
- package/dist/system/systemApi.d.ts +3 -0
- package/dist/system/systemApi.js +3 -0
- package/dist/templates/templatesApi.d.ts +3 -0
- package/dist/templates/templatesApi.js +3 -0
- package/dist/templates-preview/templatesPreviewApi.d.ts +2 -0
- package/dist/templates-preview/templatesPreviewApi.js +2 -0
- package/dist/user-activity/userActivityApi.d.ts +1 -0
- package/dist/user-activity/userActivityApi.js +1 -0
- package/dist/users/usersApi.d.ts +14 -0
- package/dist/users/usersApi.js +14 -0
- package/dist/web-socket/wsApi.d.ts +1 -1
- package/dist/web-socket/wsApi.js +1 -1
- package/package.json +4 -1
|
@@ -3,9 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
/* eslint-disable jsdoc/no-undefined-types */
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
-
const buffer_1 = require("buffer");
|
|
9
6
|
const syncModules_1 = __importDefault(require("./syncModules"));
|
|
10
7
|
const validation_1 = require("./validation");
|
|
11
8
|
/**
|
|
@@ -19,12 +16,9 @@ class AsyncModules extends syncModules_1.default {
|
|
|
19
16
|
* @description Constructor initializes the AsyncModules with a given state.
|
|
20
17
|
*/
|
|
21
18
|
constructor(state) {
|
|
22
|
-
var _a;
|
|
23
19
|
super(state);
|
|
24
20
|
this.state = state;
|
|
25
21
|
this._url = this.state.url;
|
|
26
|
-
this._NO_FETCH = state._NO_FETCH;
|
|
27
|
-
this._https = (_a = state._https) !== null && _a !== void 0 ? _a : null;
|
|
28
22
|
}
|
|
29
23
|
/**
|
|
30
24
|
* Validates API response against a Zod schema (optional)
|
|
@@ -78,47 +72,7 @@ class AsyncModules extends syncModules_1.default {
|
|
|
78
72
|
* @description Define a protected asynchronous method '_fetchGet' that performs a GET request
|
|
79
73
|
*/
|
|
80
74
|
async _fetchGet(path) {
|
|
81
|
-
|
|
82
|
-
const options = this.makeOptions('GET');
|
|
83
|
-
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
84
|
-
if (!this._NO_FETCH) {
|
|
85
|
-
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
86
|
-
return await this.browserResponse(path, options);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
90
|
-
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
91
|
-
return new Promise((resolve, reject) => {
|
|
92
|
-
// Use the HTTPS module to send a GET request to the specified path with the given options
|
|
93
|
-
const req = this._https.get(this._getFullPath(path), // Get the full URL path for the request
|
|
94
|
-
options, // Pass the options for the request
|
|
95
|
-
(res) => {
|
|
96
|
-
// Handle the response from the server
|
|
97
|
-
let responseData = ''; // Initialize a variable to accumulate response data
|
|
98
|
-
// Listen for 'data' events to receive chunks of data from the response
|
|
99
|
-
res.on('data', (chunk) => {
|
|
100
|
-
responseData += chunk; // Append each chunk to the accumulated response data
|
|
101
|
-
});
|
|
102
|
-
// Listen for the 'end' event to know when the response has been fully received
|
|
103
|
-
res.on('end', () => {
|
|
104
|
-
try {
|
|
105
|
-
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
106
|
-
resolve(JSON.parse(responseData));
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
// If parsing fails, resolve the promise with the raw response data
|
|
111
|
-
resolve(responseData);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
// Listen for 'error' events on the request to handle any errors that occur
|
|
116
|
-
req.on('error', (error) => {
|
|
117
|
-
// Reject the promise with the error
|
|
118
|
-
reject(error);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
}
|
|
75
|
+
return this.browserResponse(path, this.makeOptions('GET'));
|
|
122
76
|
}
|
|
123
77
|
/**
|
|
124
78
|
* Performs an HTTP POST request.
|
|
@@ -128,54 +82,7 @@ class AsyncModules extends syncModules_1.default {
|
|
|
128
82
|
* @description Define a protected asynchronous method '_fetchPost' that performs a POST request
|
|
129
83
|
*/
|
|
130
84
|
async _fetchPost(path, data) {
|
|
131
|
-
|
|
132
|
-
const options = this.makeOptions('POST', data);
|
|
133
|
-
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
134
|
-
if (!this._NO_FETCH) {
|
|
135
|
-
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
136
|
-
return await this.browserResponse(path, options);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
140
|
-
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
141
|
-
return new Promise((resolve, reject) => {
|
|
142
|
-
// Use the HTTPS module to send a POST request to the specified path with the given options
|
|
143
|
-
const req = this._https.request(this._getFullPath(path), // Get the full URL path for the request
|
|
144
|
-
options, // Pass the options for the request
|
|
145
|
-
(res) => {
|
|
146
|
-
// Handle the response from the server
|
|
147
|
-
// Accumulate response chunks in an array for efficient memory usage
|
|
148
|
-
const chunks = [];
|
|
149
|
-
// Listen for 'data' events to receive chunks of data from the response
|
|
150
|
-
res.on('data', (chunk) => {
|
|
151
|
-
chunks.push(buffer_1.Buffer.isBuffer(chunk) ? chunk : buffer_1.Buffer.from(chunk));
|
|
152
|
-
});
|
|
153
|
-
// Listen for the 'end' event to know when the response has been fully received
|
|
154
|
-
res.on('end', () => {
|
|
155
|
-
try {
|
|
156
|
-
// Concatenate all chunks efficiently and parse as JSON
|
|
157
|
-
const responseData = buffer_1.Buffer.concat(chunks).toString('utf8');
|
|
158
|
-
resolve(JSON.parse(responseData));
|
|
159
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
// If parsing fails, resolve the promise with the raw response data
|
|
163
|
-
const responseData = buffer_1.Buffer.concat(chunks).toString('utf8');
|
|
164
|
-
resolve(responseData);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
// Listen for 'error' events on the request to handle any errors that occur
|
|
169
|
-
req.on('error', (error) => {
|
|
170
|
-
// Reject the promise with the error
|
|
171
|
-
reject(error);
|
|
172
|
-
});
|
|
173
|
-
// Write the provided data to the request body in JSON format
|
|
174
|
-
req.write(JSON.stringify(data));
|
|
175
|
-
// End the request to signal that all data has been sent
|
|
176
|
-
req.end();
|
|
177
|
-
});
|
|
178
|
-
}
|
|
85
|
+
return this.browserResponse(path, this.makeOptions('POST', data));
|
|
179
86
|
}
|
|
180
87
|
/**
|
|
181
88
|
* Performs an HTTP PUT request.
|
|
@@ -185,51 +92,7 @@ class AsyncModules extends syncModules_1.default {
|
|
|
185
92
|
* @description Define a protected asynchronous method '_fetchPut' that performs a PUT request
|
|
186
93
|
*/
|
|
187
94
|
async _fetchPut(path, body) {
|
|
188
|
-
|
|
189
|
-
const options = this.makeOptions('PUT', body);
|
|
190
|
-
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
191
|
-
if (!this._NO_FETCH) {
|
|
192
|
-
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
193
|
-
return await this.browserResponse(path, options);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
197
|
-
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
198
|
-
return new Promise((resolve, reject) => {
|
|
199
|
-
// Use the HTTPS module to send a PUT request to the specified path with the given options
|
|
200
|
-
const req = this._https.request(this._getFullPath(path), // Get the full URL path for the request
|
|
201
|
-
options, // Pass the options for the request
|
|
202
|
-
(res) => {
|
|
203
|
-
// Handle the response from the server
|
|
204
|
-
let responseData = ''; // Initialize a variable to accumulate response data
|
|
205
|
-
// Listen for 'data' events to receive chunks of data from the response
|
|
206
|
-
res.on('data', (chunk) => {
|
|
207
|
-
responseData += chunk; // Append each chunk to the accumulated response data
|
|
208
|
-
});
|
|
209
|
-
// Listen for the 'end' event to know when the response has been fully received
|
|
210
|
-
res.on('end', () => {
|
|
211
|
-
try {
|
|
212
|
-
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
213
|
-
resolve(JSON.parse(responseData));
|
|
214
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
// If parsing fails, resolve the promise with the raw response data
|
|
218
|
-
resolve(responseData);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
// Listen for 'error' events on the request to handle any errors that occur
|
|
223
|
-
req.on('error', (error) => {
|
|
224
|
-
// Reject the promise with the error
|
|
225
|
-
reject(error);
|
|
226
|
-
});
|
|
227
|
-
// Write the provided data to the request body in JSON format
|
|
228
|
-
req.write(JSON.stringify(body));
|
|
229
|
-
// End the request to signal that all data has been sent
|
|
230
|
-
req.end();
|
|
231
|
-
});
|
|
232
|
-
}
|
|
95
|
+
return this.browserResponse(path, this.makeOptions('PUT', body));
|
|
233
96
|
}
|
|
234
97
|
/**
|
|
235
98
|
* Performs an HTTP DELETE request.
|
|
@@ -239,46 +102,25 @@ class AsyncModules extends syncModules_1.default {
|
|
|
239
102
|
* @description Define a protected asynchronous method '_fetchDelete' that performs a DELETE request
|
|
240
103
|
*/
|
|
241
104
|
async _fetchDelete(path, body) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
105
|
+
return this.browserResponse(path, this.makeOptions('DELETE', body));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Wraps a fetch call whose only meaningful outcome is success or failure.
|
|
109
|
+
*
|
|
110
|
+
* Several endpoints (cancel/recover subscription, subscribe/unsubscribe to
|
|
111
|
+
* events) return no useful body — callers only care whether the request
|
|
112
|
+
* succeeded. This helper resolves to `true` on success and to the caught
|
|
113
|
+
* error (as IError) on failure, centralizing the repeated try/catch.
|
|
114
|
+
* @param {() => Promise<unknown>} request - Thunk performing the fetch call.
|
|
115
|
+
* @returns {Promise<boolean | IError>} `true` on success, IError on failure.
|
|
116
|
+
*/
|
|
117
|
+
async _fetchBoolean(request) {
|
|
118
|
+
try {
|
|
119
|
+
await request();
|
|
120
|
+
return true;
|
|
248
121
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
252
|
-
return new Promise((resolve, reject) => {
|
|
253
|
-
// Use the HTTPS module to send a DELETE request to the specified path with the given options
|
|
254
|
-
const req = this._https.delete(this._getFullPath(path), // Get the full URL path for the request
|
|
255
|
-
options, // Pass the options for the request
|
|
256
|
-
(res) => {
|
|
257
|
-
// Handle the response from the server
|
|
258
|
-
let responseData = ''; // Initialize a variable to accumulate response data
|
|
259
|
-
// Listen for 'data' events to receive chunks of data from the response
|
|
260
|
-
res.on('data', (chunk) => {
|
|
261
|
-
responseData += chunk; // Append each chunk to the accumulated response data
|
|
262
|
-
});
|
|
263
|
-
// Listen for the 'end' event to know when the response has been fully received
|
|
264
|
-
res.on('end', () => {
|
|
265
|
-
try {
|
|
266
|
-
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
267
|
-
resolve(JSON.parse(responseData));
|
|
268
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
// If parsing fails, resolve the promise with the raw response data
|
|
272
|
-
resolve(responseData);
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
// Listen for 'error' events on the request to handle any errors that occur
|
|
277
|
-
req.on('error', (error) => {
|
|
278
|
-
// Reject the promise with the error
|
|
279
|
-
reject(error);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
122
|
+
catch (e) {
|
|
123
|
+
return e;
|
|
282
124
|
}
|
|
283
125
|
}
|
|
284
126
|
/**
|
|
@@ -410,6 +252,24 @@ class AsyncModules extends syncModules_1.default {
|
|
|
410
252
|
}
|
|
411
253
|
return options;
|
|
412
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Reads a response body as JSON, tolerating an empty body.
|
|
257
|
+
*
|
|
258
|
+
* `Response.json()` throws on an empty body (e.g. 204 or an empty error
|
|
259
|
+
* payload); this helper mirrors the OK-path guard (`text ? JSON.parse : {}`)
|
|
260
|
+
* so both the success and the error branches handle empty bodies the same way.
|
|
261
|
+
* @param {Response} response - The fetch Response to read.
|
|
262
|
+
* @returns {Promise<unknown>} Parsed JSON, or an empty object when the body is empty/unparsable.
|
|
263
|
+
*/
|
|
264
|
+
async _parseJson(response) {
|
|
265
|
+
try {
|
|
266
|
+
const text = await response.text();
|
|
267
|
+
return text ? JSON.parse(text) : {};
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return {};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
413
273
|
/**
|
|
414
274
|
* Handles responses from the browser's fetch API.
|
|
415
275
|
* @param {string} path - The path to append to the base URL.
|
|
@@ -445,56 +305,45 @@ class AsyncModules extends syncModules_1.default {
|
|
|
445
305
|
}
|
|
446
306
|
}
|
|
447
307
|
// Perform a fetch request using the full URL obtained from '_getFullPath' and the provided options
|
|
448
|
-
|
|
308
|
+
let response = await fetch(this._getFullPath(path), options);
|
|
309
|
+
// Reactive refresh for mid-session expiry: access token was present but
|
|
310
|
+
// the server rejected it. Skipped when a proactive refresh already ran
|
|
311
|
+
// and failed (the refresh token is dead — retrying would 400 again).
|
|
312
|
+
// On success the request is retried once; the retry response then flows
|
|
313
|
+
// through the SAME ok / error handling below (status check, errorsFunctions,
|
|
314
|
+
// isShell) instead of being returned blindly.
|
|
315
|
+
if (!response.ok &&
|
|
316
|
+
response.status === 401 &&
|
|
317
|
+
!this.state.customAuth &&
|
|
318
|
+
!proactiveRefreshFailed) {
|
|
319
|
+
const refresh = await this.refreshToken();
|
|
320
|
+
if (refresh) {
|
|
321
|
+
// Update the Authorization header with the new access token and retry.
|
|
322
|
+
options.headers['Authorization'] = 'Bearer ' + this.state.accessToken;
|
|
323
|
+
response = await fetch(this._getFullPath(path), options);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
449
326
|
// Check if the response status is OK (status code 200-299)
|
|
450
327
|
if (response.ok) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
328
|
+
// Read the body as text; if it is empty return an empty object,
|
|
329
|
+
// otherwise parse it as JSON. A parse failure propagates to the
|
|
330
|
+
// catch below and is handled according to isShell.
|
|
331
|
+
const text = await response.text();
|
|
332
|
+
return (text ? JSON.parse(text) : {});
|
|
333
|
+
}
|
|
334
|
+
// Handle non-OK responses (applies to the first response and to a failed retry).
|
|
335
|
+
const status = response.status;
|
|
336
|
+
const res = await this._parseJson(response);
|
|
337
|
+
const statusKey = status;
|
|
338
|
+
if (this.state.errorsFunctions && this.state.errorsFunctions[statusKey]) {
|
|
339
|
+
this.state.errorsFunctions[statusKey](res);
|
|
340
|
+
}
|
|
341
|
+
// Determine whether to return or throw the response based on 'isShell' state
|
|
342
|
+
if (this.state.isShell) {
|
|
343
|
+
return res;
|
|
462
344
|
}
|
|
463
345
|
else {
|
|
464
|
-
|
|
465
|
-
// Reactive refresh for mid-session expiry: access token was present but
|
|
466
|
-
// the server rejected it. Skipped when a proactive refresh already ran
|
|
467
|
-
// and failed (the refresh token is dead — retrying would 400 again).
|
|
468
|
-
if (response.status === 401 &&
|
|
469
|
-
!this.state.customAuth &&
|
|
470
|
-
!proactiveRefreshFailed) {
|
|
471
|
-
// Attempt to refresh the access token
|
|
472
|
-
const refresh = await this.refreshToken();
|
|
473
|
-
if (refresh) {
|
|
474
|
-
// Update the Authorization header with the new access token
|
|
475
|
-
options.headers['Authorization'] =
|
|
476
|
-
'Bearer ' + this.state.accessToken;
|
|
477
|
-
// Retry the fetch request with updated headers
|
|
478
|
-
const secondResponse = await fetch(this._getFullPath(path), options);
|
|
479
|
-
// Return the JSON-parsed response of the retry request
|
|
480
|
-
return (await secondResponse.json());
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
// Store the response status and parse the response body as JSON
|
|
484
|
-
const status = response.status;
|
|
485
|
-
const res = await response.json();
|
|
486
|
-
const statusKey = status;
|
|
487
|
-
if (this.state.errorsFunctions &&
|
|
488
|
-
this.state.errorsFunctions[statusKey]) {
|
|
489
|
-
this.state.errorsFunctions[statusKey](res);
|
|
490
|
-
}
|
|
491
|
-
// Determine whether to return or throw the response based on 'isShell' state
|
|
492
|
-
if (this.state.isShell) {
|
|
493
|
-
return res;
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
throw res;
|
|
497
|
-
}
|
|
346
|
+
throw res;
|
|
498
347
|
}
|
|
499
348
|
}
|
|
500
349
|
catch (e) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { IConfig, IError } from './utils';
|
|
2
|
+
declare const ERROR_STATUS_CODES: readonly [400, 401, 403, 404, 429, 500, 502, 503, 504];
|
|
3
|
+
type ErrorStatusCode = (typeof ERROR_STATUS_CODES)[number];
|
|
2
4
|
/**
|
|
3
5
|
* State module for managing application state and configuration.
|
|
4
6
|
* @description State module for managing application state and configuration.
|
|
@@ -14,24 +16,12 @@ export default class StateModule {
|
|
|
14
16
|
_refreshPromise: Promise<boolean> | null;
|
|
15
17
|
providerMarker: string;
|
|
16
18
|
customAuth: boolean;
|
|
17
|
-
_NO_FETCH: boolean;
|
|
18
|
-
_https: any;
|
|
19
19
|
isShell: boolean;
|
|
20
20
|
validationEnabled: boolean;
|
|
21
21
|
validationStrictMode: boolean;
|
|
22
22
|
validationLogErrors: boolean;
|
|
23
23
|
rawData: boolean;
|
|
24
|
-
errorsFunctions:
|
|
25
|
-
400?: (data: IError) => any | null;
|
|
26
|
-
401?: (data: IError) => any | null;
|
|
27
|
-
403?: (data: IError) => any | null;
|
|
28
|
-
404?: (data: IError) => any | null;
|
|
29
|
-
429?: (data: IError) => any | null;
|
|
30
|
-
500?: (data: IError) => any | null;
|
|
31
|
-
502?: (data: IError) => any | null;
|
|
32
|
-
503?: (data: IError) => any | null;
|
|
33
|
-
504?: (data: IError) => any | null;
|
|
34
|
-
};
|
|
24
|
+
errorsFunctions: Partial<Record<ErrorStatusCode, (data: IError) => any>>;
|
|
35
25
|
saveFunction: (param: string) => void | null;
|
|
36
26
|
/**
|
|
37
27
|
* Constructor for StateModule
|
|
@@ -41,3 +31,4 @@ export default class StateModule {
|
|
|
41
31
|
*/
|
|
42
32
|
constructor(url: string, config: IConfig);
|
|
43
33
|
}
|
|
34
|
+
export {};
|
package/dist/base/stateModule.js
CHANGED
|
@@ -1,38 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// HTTP status codes for which a custom error handler may be configured.
|
|
4
|
+
const ERROR_STATUS_CODES = [
|
|
5
|
+
400, 401, 403, 404, 429, 500, 502, 503, 504,
|
|
6
|
+
];
|
|
36
7
|
/**
|
|
37
8
|
* State module for managing application state and configuration.
|
|
38
9
|
* @description State module for managing application state and configuration.
|
|
@@ -45,7 +16,7 @@ class StateModule {
|
|
|
45
16
|
* @description Constructor for StateModule.
|
|
46
17
|
*/
|
|
47
18
|
constructor(url, config) {
|
|
48
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
49
20
|
// In-flight token refresh, shared across all module instances (they share this
|
|
50
21
|
// state object). De-duplicates concurrent refreshes so the single-use refresh
|
|
51
22
|
// token is not burned by parallel requests. Null when no refresh is running.
|
|
@@ -64,71 +35,16 @@ class StateModule {
|
|
|
64
35
|
this.refreshToken = (_k = (_j = config.auth) === null || _j === void 0 ? void 0 : _j.refreshToken) !== null && _k !== void 0 ? _k : undefined;
|
|
65
36
|
this.providerMarker = (_m = (_l = config.auth) === null || _l === void 0 ? void 0 : _l.providerMarker) !== null && _m !== void 0 ? _m : 'email';
|
|
66
37
|
this.customAuth = (_p = (_o = config.auth) === null || _o === void 0 ? void 0 : _o.customAuth) !== null && _p !== void 0 ? _p : false;
|
|
67
|
-
this.errorsFunctions = {
|
|
68
|
-
'400': undefined,
|
|
69
|
-
'401': undefined,
|
|
70
|
-
'403': undefined,
|
|
71
|
-
'404': undefined,
|
|
72
|
-
'429': undefined,
|
|
73
|
-
'500': undefined,
|
|
74
|
-
'502': undefined,
|
|
75
|
-
'503': undefined,
|
|
76
|
-
'504': undefined,
|
|
77
|
-
};
|
|
38
|
+
this.errorsFunctions = {};
|
|
78
39
|
this.saveFunction = (_r = (_q = config.auth) === null || _q === void 0 ? void 0 : _q.saveFunction) !== null && _r !== void 0 ? _r : null;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(_u = config.errors.customErrors['401']) !== null && _u !== void 0 ? _u : undefined;
|
|
86
|
-
this.errorsFunctions['403'] =
|
|
87
|
-
(_v = config.errors.customErrors['403']) !== null && _v !== void 0 ? _v : undefined;
|
|
88
|
-
this.errorsFunctions['404'] =
|
|
89
|
-
(_w = config.errors.customErrors['404']) !== null && _w !== void 0 ? _w : undefined;
|
|
90
|
-
this.errorsFunctions['429'] =
|
|
91
|
-
(_x = config.errors.customErrors['429']) !== null && _x !== void 0 ? _x : undefined;
|
|
92
|
-
this.errorsFunctions['500'] =
|
|
93
|
-
(_y = config.errors.customErrors['500']) !== null && _y !== void 0 ? _y : undefined;
|
|
94
|
-
this.errorsFunctions['502'] =
|
|
95
|
-
(_z = config.errors.customErrors['502']) !== null && _z !== void 0 ? _z : undefined;
|
|
96
|
-
this.errorsFunctions['503'] =
|
|
97
|
-
(_0 = config.errors.customErrors['503']) !== null && _0 !== void 0 ? _0 : undefined;
|
|
98
|
-
this.errorsFunctions['504'] =
|
|
99
|
-
(_1 = config.errors.customErrors['504']) !== null && _1 !== void 0 ? _1 : undefined;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
this.isShell = true;
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
if (typeof process === 'object' &&
|
|
107
|
-
+process.versions.node.split('.')[0] < 18) {
|
|
108
|
-
try {
|
|
109
|
-
this._NO_FETCH = true;
|
|
110
|
-
// Dynamically import https for older Node.js versions
|
|
111
|
-
Promise.resolve().then(() => __importStar(require('https'))).then((https) => {
|
|
112
|
-
this._https = https;
|
|
113
|
-
})
|
|
114
|
-
.catch(() => {
|
|
115
|
-
this._https = null;
|
|
116
|
-
});
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
|
+
this.isShell = (_t = (_s = config.errors) === null || _s === void 0 ? void 0 : _s.isShell) !== null && _t !== void 0 ? _t : true;
|
|
41
|
+
const customErrors = (_u = config.errors) === null || _u === void 0 ? void 0 : _u.customErrors;
|
|
42
|
+
if (customErrors) {
|
|
43
|
+
for (const code of ERROR_STATUS_CODES) {
|
|
44
|
+
if (customErrors[code]) {
|
|
45
|
+
this.errorsFunctions[code] = customErrors[code];
|
|
118
46
|
}
|
|
119
|
-
catch (e) {
|
|
120
|
-
this._https = null;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
this._NO_FETCH = false;
|
|
125
|
-
this._https = null;
|
|
126
47
|
}
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
128
|
-
}
|
|
129
|
-
catch (e) {
|
|
130
|
-
this._NO_FETCH = false;
|
|
131
|
-
this._https = null;
|
|
132
48
|
}
|
|
133
49
|
}
|
|
134
50
|
}
|
|
@@ -40,6 +40,10 @@ export default abstract class SyncModules {
|
|
|
40
40
|
protected _getFullPath(path: string): string;
|
|
41
41
|
/**
|
|
42
42
|
* Converts query parameters into a query string.
|
|
43
|
+
*
|
|
44
|
+
* Values are percent-encoded so free-text and special characters (spaces,
|
|
45
|
+
* `&`, `=`, non-ASCII) cannot corrupt the query string. Keys are known,
|
|
46
|
+
* machine-safe field names and are left as-is.
|
|
43
47
|
* @param {IProductsQuery | IUploadingQuery | any} query - The query object containing key-value pairs.
|
|
44
48
|
* @returns {string} A string representation of the query parameters.
|
|
45
49
|
*/
|
package/dist/base/syncModules.js
CHANGED
|
@@ -143,6 +143,10 @@ class SyncModules {
|
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* Converts query parameters into a query string.
|
|
146
|
+
*
|
|
147
|
+
* Values are percent-encoded so free-text and special characters (spaces,
|
|
148
|
+
* `&`, `=`, non-ASCII) cannot corrupt the query string. Keys are known,
|
|
149
|
+
* machine-safe field names and are left as-is.
|
|
146
150
|
* @param {IProductsQuery | IUploadingQuery | any} query - The query object containing key-value pairs.
|
|
147
151
|
* @returns {string} A string representation of the query parameters.
|
|
148
152
|
*/
|
|
@@ -151,7 +155,7 @@ class SyncModules {
|
|
|
151
155
|
// 0, false and '' are kept — they are semantically meaningful.
|
|
152
156
|
return Object.keys(query)
|
|
153
157
|
.filter((key) => query[key] !== null && query[key] !== undefined)
|
|
154
|
-
.map((key) => `${key}=${query[key]}`)
|
|
158
|
+
.map((key) => `${key}=${encodeURIComponent(query[key])}`)
|
|
155
159
|
.join('&');
|
|
156
160
|
}
|
|
157
161
|
/**
|