oneentry 1.0.124 → 1.0.125
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/README.md +24 -22
- package/dist/admins/adminsApi.d.ts +17 -4
- package/dist/admins/adminsApi.js +16 -3
- package/dist/admins/adminsInterfaces.d.ts +47 -26
- package/dist/attribute-sets/attributeSetsApi.d.ts +10 -18
- package/dist/attribute-sets/attributeSetsApi.js +9 -17
- package/dist/attribute-sets/attributeSetsInterfaces.d.ts +92 -44
- package/dist/auth-provider/authProviderApi.d.ts +146 -36
- package/dist/auth-provider/authProviderApi.js +163 -37
- package/dist/auth-provider/authProvidersInterfaces.d.ts +189 -40
- package/dist/base/asyncModules.d.ts +7 -1
- package/dist/base/asyncModules.js +127 -21
- package/dist/base/result.js +23 -0
- package/dist/base/syncModules.d.ts +4 -0
- package/dist/base/syncModules.js +19 -1
- package/dist/base/utils.d.ts +1 -1
- package/dist/blocks/blocksApi.d.ts +7 -17
- package/dist/blocks/blocksApi.js +7 -17
- package/dist/blocks/blocksInterfaces.d.ts +77 -32
- package/dist/events/eventsApi.d.ts +7 -8
- package/dist/events/eventsApi.js +12 -7
- package/dist/events/eventsInterfaces.d.ts +16 -11
- package/dist/file-uploading/fileUploadingApi.d.ts +22 -14
- package/dist/file-uploading/fileUploadingApi.js +20 -12
- package/dist/file-uploading/fileUploadingInterfaces.d.ts +42 -18
- package/dist/forms/formsApi.d.ts +3 -7
- package/dist/forms/formsApi.js +2 -6
- package/dist/forms/formsInterfaces.d.ts +44 -28
- package/dist/formsData/formsDataApi.d.ts +21 -9
- package/dist/formsData/formsDataApi.js +21 -9
- package/dist/formsData/formsDataInterfaces.d.ts +128 -45
- package/dist/general-types/generalTypesApi.d.ts +1 -3
- package/dist/general-types/generalTypesApi.js +0 -2
- package/dist/general-types/generalTypesInterfaces.d.ts +2 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/integration-collections/integrationCollectionsApi.d.ts +74 -47
- package/dist/integration-collections/integrationCollectionsApi.js +64 -45
- package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +144 -63
- package/dist/locales/localesApi.d.ts +1 -2
- package/dist/locales/localesApi.js +1 -2
- package/dist/locales/localesInterfaces.d.ts +2 -4
- package/dist/menus/menusApi.d.ts +1 -3
- package/dist/menus/menusApi.js +1 -3
- package/dist/menus/menusInterfaces.d.ts +39 -13
- package/dist/orders/ordersApi.d.ts +36 -18
- package/dist/orders/ordersApi.js +40 -22
- package/dist/orders/ordersInterfaces.d.ts +163 -81
- package/dist/pages/pagesApi.d.ts +48 -48
- package/dist/pages/pagesApi.js +40 -45
- package/dist/pages/pagesInterfaces.d.ts +147 -98
- package/dist/payments/paymentsApi.d.ts +25 -45
- package/dist/payments/paymentsApi.js +27 -46
- package/dist/payments/paymentsInterfaces.d.ts +42 -60
- package/dist/product-statuses/productStatusesApi.d.ts +6 -12
- package/dist/product-statuses/productStatusesApi.js +5 -11
- package/dist/product-statuses/productStatusesInterfaces.d.ts +16 -15
- package/dist/products/productsApi.d.ts +256 -104
- package/dist/products/productsApi.js +263 -97
- package/dist/products/productsInterfaces.d.ts +343 -160
- package/dist/system/systemApi.d.ts +21 -10
- package/dist/system/systemApi.js +22 -8
- package/dist/system/systemInterfaces.d.ts +0 -1
- package/dist/templates/templatesApi.d.ts +6 -12
- package/dist/templates/templatesApi.js +4 -10
- package/dist/templates/templatesInterfaces.d.ts +20 -20
- package/dist/templates-preview/templatesPreviewApi.d.ts +2 -6
- package/dist/templates-preview/templatesPreviewApi.js +1 -5
- package/dist/templates-preview/templatesPreviewInterfaces.d.ts +50 -25
- package/dist/users/usersApi.d.ts +33 -13
- package/dist/users/usersApi.js +38 -15
- package/dist/users/usersInterfaces.d.ts +78 -27
- package/dist/web-socket/wsApi.d.ts +1 -5
- package/dist/web-socket/wsApi.js +1 -5
- package/dist/web-socket/wsInterfaces.d.ts +0 -1
- package/package.json +18 -16
|
@@ -25,31 +25,45 @@ class AsyncModules extends syncModules_1.default {
|
|
|
25
25
|
* Performs an HTTP GET request.
|
|
26
26
|
* @param path - The path to append to the base URL.
|
|
27
27
|
* @return A promise resolving to the response data.
|
|
28
|
+
* @description Define a protected asynchronous method '_fetchGet' that performs a GET request
|
|
28
29
|
*/
|
|
29
30
|
async _fetchGet(path) {
|
|
31
|
+
// Create options for the GET request using the 'makeOptions' method
|
|
30
32
|
const options = this.makeOptions('GET');
|
|
31
|
-
//
|
|
33
|
+
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
32
34
|
if (!this._NO_FETCH) {
|
|
35
|
+
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
33
36
|
return await this.browserResponse(path, options);
|
|
34
37
|
}
|
|
35
38
|
else {
|
|
39
|
+
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
40
|
+
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
36
41
|
return new Promise((resolve, reject) => {
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
// Use the HTTPS module to send a GET request to the specified path with the given options
|
|
43
|
+
const req = this._https.get(this._getFullPath(path), // Get the full URL path for the request
|
|
44
|
+
options, // Pass the options for the request
|
|
45
|
+
(res) => {
|
|
46
|
+
// Handle the response from the server
|
|
47
|
+
let responseData = ''; // Initialize a variable to accumulate response data
|
|
48
|
+
// Listen for 'data' events to receive chunks of data from the response
|
|
39
49
|
res.on('data', (chunk) => {
|
|
40
|
-
responseData += chunk;
|
|
50
|
+
responseData += chunk; // Append each chunk to the accumulated response data
|
|
41
51
|
});
|
|
52
|
+
// Listen for the 'end' event to know when the response has been fully received
|
|
42
53
|
res.on('end', () => {
|
|
43
54
|
try {
|
|
55
|
+
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
44
56
|
resolve(JSON.parse(responseData));
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
46
57
|
}
|
|
47
58
|
catch (error) {
|
|
59
|
+
// If parsing fails, resolve the promise with the raw response data
|
|
48
60
|
resolve(responseData);
|
|
49
61
|
}
|
|
50
62
|
});
|
|
51
63
|
});
|
|
64
|
+
// Listen for 'error' events on the request to handle any errors that occur
|
|
52
65
|
req.on('error', (error) => {
|
|
66
|
+
// Reject the promise with the error
|
|
53
67
|
reject(error);
|
|
54
68
|
});
|
|
55
69
|
});
|
|
@@ -60,33 +74,50 @@ class AsyncModules extends syncModules_1.default {
|
|
|
60
74
|
* @param path - The path to append to the base URL.
|
|
61
75
|
* @param data - The data to send in the request body.
|
|
62
76
|
* @return A promise resolving to the response data.
|
|
77
|
+
* @description Define a protected asynchronous method '_fetchPost' that performs a POST request
|
|
63
78
|
*/
|
|
64
79
|
async _fetchPost(path, data) {
|
|
80
|
+
// Create options for the POST request using the 'makeOptions' method, including the data to be sent
|
|
65
81
|
const options = this.makeOptions('POST', data);
|
|
82
|
+
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
66
83
|
if (!this._NO_FETCH) {
|
|
84
|
+
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
67
85
|
return await this.browserResponse(path, options);
|
|
68
86
|
}
|
|
69
87
|
else {
|
|
88
|
+
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
89
|
+
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
70
90
|
return new Promise((resolve, reject) => {
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
// Use the HTTPS module to send a POST request to the specified path with the given options
|
|
92
|
+
const req = this._https.request(this._getFullPath(path), // Get the full URL path for the request
|
|
93
|
+
options, // Pass the options for the request
|
|
94
|
+
(res) => {
|
|
95
|
+
// Handle the response from the server
|
|
96
|
+
let responseData = ''; // Initialize a variable to accumulate response data
|
|
97
|
+
// Listen for 'data' events to receive chunks of data from the response
|
|
73
98
|
res.on('data', (chunk) => {
|
|
74
|
-
responseData += chunk;
|
|
99
|
+
responseData += chunk; // Append each chunk to the accumulated response data
|
|
75
100
|
});
|
|
101
|
+
// Listen for the 'end' event to know when the response has been fully received
|
|
76
102
|
res.on('end', () => {
|
|
77
103
|
try {
|
|
104
|
+
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
78
105
|
resolve(JSON.parse(responseData));
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
106
|
}
|
|
81
107
|
catch (error) {
|
|
108
|
+
// If parsing fails, resolve the promise with the raw response data
|
|
82
109
|
resolve(responseData);
|
|
83
110
|
}
|
|
84
111
|
});
|
|
85
112
|
});
|
|
113
|
+
// Listen for 'error' events on the request to handle any errors that occur
|
|
86
114
|
req.on('error', (error) => {
|
|
115
|
+
// Reject the promise with the error
|
|
87
116
|
reject(error);
|
|
88
117
|
});
|
|
118
|
+
// Write the provided data to the request body in JSON format
|
|
89
119
|
req.write(JSON.stringify(data));
|
|
120
|
+
// End the request to signal that all data has been sent
|
|
90
121
|
req.end();
|
|
91
122
|
});
|
|
92
123
|
}
|
|
@@ -96,33 +127,50 @@ class AsyncModules extends syncModules_1.default {
|
|
|
96
127
|
* @param path - The path to append to the base URL.
|
|
97
128
|
* @param data - The data to send in the request body.
|
|
98
129
|
* @return A promise resolving to the response data.
|
|
130
|
+
* @description Define a protected asynchronous method '_fetchPut' that performs a PUT request
|
|
99
131
|
*/
|
|
100
132
|
async _fetchPut(path, data) {
|
|
133
|
+
// Create options for the PUT request using the 'makeOptions' method, including the data to be sent
|
|
101
134
|
const options = this.makeOptions('PUT', data);
|
|
135
|
+
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
102
136
|
if (!this._NO_FETCH) {
|
|
137
|
+
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
103
138
|
return await this.browserResponse(path, options);
|
|
104
139
|
}
|
|
105
140
|
else {
|
|
141
|
+
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
142
|
+
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
106
143
|
return new Promise((resolve, reject) => {
|
|
107
|
-
|
|
108
|
-
|
|
144
|
+
// Use the HTTPS module to send a PUT request to the specified path with the given options
|
|
145
|
+
const req = this._https.request(this._getFullPath(path), // Get the full URL path for the request
|
|
146
|
+
options, // Pass the options for the request
|
|
147
|
+
(res) => {
|
|
148
|
+
// Handle the response from the server
|
|
149
|
+
let responseData = ''; // Initialize a variable to accumulate response data
|
|
150
|
+
// Listen for 'data' events to receive chunks of data from the response
|
|
109
151
|
res.on('data', (chunk) => {
|
|
110
|
-
responseData += chunk;
|
|
152
|
+
responseData += chunk; // Append each chunk to the accumulated response data
|
|
111
153
|
});
|
|
154
|
+
// Listen for the 'end' event to know when the response has been fully received
|
|
112
155
|
res.on('end', () => {
|
|
113
156
|
try {
|
|
157
|
+
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
114
158
|
resolve(JSON.parse(responseData));
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
116
159
|
}
|
|
117
160
|
catch (error) {
|
|
161
|
+
// If parsing fails, resolve the promise with the raw response data
|
|
118
162
|
resolve(responseData);
|
|
119
163
|
}
|
|
120
164
|
});
|
|
121
165
|
});
|
|
166
|
+
// Listen for 'error' events on the request to handle any errors that occur
|
|
122
167
|
req.on('error', (error) => {
|
|
168
|
+
// Reject the promise with the error
|
|
123
169
|
reject(error);
|
|
124
170
|
});
|
|
171
|
+
// Write the provided data to the request body in JSON format
|
|
125
172
|
req.write(JSON.stringify(data));
|
|
173
|
+
// End the request to signal that all data has been sent
|
|
126
174
|
req.end();
|
|
127
175
|
});
|
|
128
176
|
}
|
|
@@ -132,31 +180,46 @@ class AsyncModules extends syncModules_1.default {
|
|
|
132
180
|
* @param path - The path to append to the base URL.
|
|
133
181
|
* @param data - Optional data to send in the request body.
|
|
134
182
|
* @return A promise resolving to the response data.
|
|
183
|
+
* @description Define a protected asynchronous method '_fetchDelete' that performs a DELETE request
|
|
135
184
|
*/
|
|
136
185
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
137
186
|
async _fetchDelete(path, data) {
|
|
187
|
+
// Create options for the DELETE request using the 'makeOptions' method
|
|
138
188
|
const options = this.makeOptions('DELETE');
|
|
189
|
+
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
139
190
|
if (!this._NO_FETCH) {
|
|
191
|
+
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
140
192
|
return await this.browserResponse(path, options);
|
|
141
193
|
}
|
|
142
194
|
else {
|
|
195
|
+
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
196
|
+
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
143
197
|
return new Promise((resolve, reject) => {
|
|
144
|
-
|
|
145
|
-
|
|
198
|
+
// Use the HTTPS module to send a DELETE request to the specified path with the given options
|
|
199
|
+
const req = this._https.delete(this._getFullPath(path), // Get the full URL path for the request
|
|
200
|
+
options, // Pass the options for the request
|
|
201
|
+
(res) => {
|
|
202
|
+
// Handle the response from the server
|
|
203
|
+
let responseData = ''; // Initialize a variable to accumulate response data
|
|
204
|
+
// Listen for 'data' events to receive chunks of data from the response
|
|
146
205
|
res.on('data', (chunk) => {
|
|
147
|
-
responseData += chunk;
|
|
206
|
+
responseData += chunk; // Append each chunk to the accumulated response data
|
|
148
207
|
});
|
|
208
|
+
// Listen for the 'end' event to know when the response has been fully received
|
|
149
209
|
res.on('end', () => {
|
|
150
210
|
try {
|
|
211
|
+
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
151
212
|
resolve(JSON.parse(responseData));
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
213
|
}
|
|
154
214
|
catch (error) {
|
|
215
|
+
// If parsing fails, resolve the promise with the raw response data
|
|
155
216
|
resolve(responseData);
|
|
156
217
|
}
|
|
157
218
|
});
|
|
158
219
|
});
|
|
220
|
+
// Listen for 'error' events on the request to handle any errors that occur
|
|
159
221
|
req.on('error', (error) => {
|
|
222
|
+
// Reject the promise with the error
|
|
160
223
|
reject(error);
|
|
161
224
|
});
|
|
162
225
|
});
|
|
@@ -165,33 +228,44 @@ class AsyncModules extends syncModules_1.default {
|
|
|
165
228
|
/**
|
|
166
229
|
* Refreshes the authentication token.
|
|
167
230
|
* @return A promise resolving to a boolean indicating success or failure.
|
|
231
|
+
* @description Define an asynchronous method 'refreshToken' that attempts to refresh the authentication token
|
|
168
232
|
*/
|
|
169
233
|
async refreshToken() {
|
|
234
|
+
// Perform a fetch request to the specified URL to refresh the token
|
|
170
235
|
const response = await fetch(this.state.url +
|
|
171
236
|
`/api/content/users-auth-providers/marker/email/users/refresh`, {
|
|
237
|
+
// Use the POST method for the request
|
|
172
238
|
method: 'POST',
|
|
239
|
+
// Set the necessary headers for the request
|
|
173
240
|
headers: {
|
|
174
|
-
'Content-Type': 'application/json',
|
|
175
|
-
'x-app-token': this.state.token,
|
|
241
|
+
'Content-Type': 'application/json', // Indicate that the request body is in JSON format
|
|
242
|
+
'x-app-token': this.state.token, // Include the application token from the state
|
|
176
243
|
},
|
|
244
|
+
// Send the current refresh token in the request body as a JSON string
|
|
177
245
|
body: JSON.stringify({ refreshToken: this.state.refreshToken }),
|
|
178
246
|
});
|
|
247
|
+
// Check if the response status is OK (status code 200-299)
|
|
179
248
|
if (response.ok) {
|
|
249
|
+
// Parse the response body as JSON and store the result
|
|
180
250
|
const result = await response.json();
|
|
251
|
+
// Update the state's refreshToken and accessToken with the new tokens from the response
|
|
181
252
|
this.state.refreshToken = result.refreshToken;
|
|
182
253
|
this.state.accessToken = result.accessToken;
|
|
254
|
+
// If a save function is defined in the state, call it with the new refresh token
|
|
183
255
|
if (this.state.saveFunction) {
|
|
184
256
|
this.state.saveFunction(result.refreshToken);
|
|
185
257
|
}
|
|
258
|
+
// Return true to indicate that the token refresh was successful
|
|
186
259
|
return true;
|
|
187
260
|
}
|
|
188
261
|
else {
|
|
262
|
+
// Return false to indicate that the token refresh failed
|
|
189
263
|
return false;
|
|
190
264
|
}
|
|
191
265
|
}
|
|
192
266
|
/**
|
|
193
267
|
* Creates options for HTTP requests.
|
|
194
|
-
* @param method - The HTTP method (GET, POST, etc.).
|
|
268
|
+
* @param method - The HTTP method (GET, POST, PUT, DELETE, etc.).
|
|
195
269
|
* @param data - Optional data to include in the request body.
|
|
196
270
|
* @return An object representing the request options.
|
|
197
271
|
*/
|
|
@@ -203,18 +277,33 @@ class AsyncModules extends syncModules_1.default {
|
|
|
203
277
|
'x-app-token': this.state.token,
|
|
204
278
|
},
|
|
205
279
|
};
|
|
280
|
+
// if method = 'POST' add x-device-metadata
|
|
281
|
+
if (method === 'POST') {
|
|
282
|
+
options.headers = {
|
|
283
|
+
...options.headers,
|
|
284
|
+
'x-device-metadata': this._getDeviceMetadata(),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// Check if 'data' is an instance of FormData or Blob
|
|
206
288
|
if (data instanceof FormData || data instanceof Blob) {
|
|
289
|
+
// Remove the 'Content-Type' header from options.headers
|
|
207
290
|
delete options.headers['Content-Type'];
|
|
291
|
+
// Set the 'accept' header to 'application/json', while preserving existing headers
|
|
208
292
|
options.headers = {
|
|
209
293
|
...options.headers,
|
|
210
294
|
accept: 'application/json',
|
|
211
295
|
};
|
|
296
|
+
// Assign 'data' to options.body for sending as request payload
|
|
212
297
|
options.body = data;
|
|
213
298
|
}
|
|
214
299
|
else if (data) {
|
|
300
|
+
// If 'data' exists and is not FormData or Blob, convert it to a JSON string
|
|
301
|
+
// and assign it to options.body
|
|
215
302
|
options.body = JSON.stringify(data);
|
|
216
303
|
}
|
|
304
|
+
// Check if there is an access token available in the state
|
|
217
305
|
if (this.state.accessToken) {
|
|
306
|
+
// Add an 'Authorization' header with the Bearer token to options.headers
|
|
218
307
|
options.headers['Authorization'] = 'Bearer ' + this.state.accessToken;
|
|
219
308
|
}
|
|
220
309
|
return options;
|
|
@@ -224,32 +313,46 @@ class AsyncModules extends syncModules_1.default {
|
|
|
224
313
|
* @param path - The path to append to the base URL.
|
|
225
314
|
* @param options - The options for the fetch request.
|
|
226
315
|
* @return A promise resolving to the response data.
|
|
316
|
+
* @description Define an asynchronous method 'browserResponse' that takes a path and options as parameters
|
|
227
317
|
*/
|
|
228
318
|
async browserResponse(path, options) {
|
|
229
319
|
try {
|
|
320
|
+
// Perform a fetch request using the full URL obtained from '_getFullPath' and the provided options
|
|
230
321
|
const response = await fetch(this._getFullPath(path), options);
|
|
322
|
+
// Check if the response status is OK (status code 200-299)
|
|
231
323
|
if (response.ok) {
|
|
232
324
|
try {
|
|
325
|
+
// Attempt to read the response body as text
|
|
233
326
|
const text = await response.text();
|
|
327
|
+
// If the response body is not empty, parse it as JSON; otherwise, return an empty object
|
|
234
328
|
return text ? JSON.parse(text) : {};
|
|
235
|
-
// return await response.json()
|
|
329
|
+
// Alternatively, you could directly return the parsed JSON with 'await response.json()'
|
|
236
330
|
}
|
|
237
331
|
catch (e) {
|
|
332
|
+
// If parsing the response fails, return the error
|
|
238
333
|
return e;
|
|
239
334
|
}
|
|
240
335
|
}
|
|
241
336
|
else {
|
|
337
|
+
// Handle non-OK responses
|
|
338
|
+
// Check if the status is 401 (Unauthorized) and custom authentication is not used
|
|
242
339
|
if (response.status == 401 && !this.state.customAuth) {
|
|
340
|
+
// Attempt to refresh the access token
|
|
243
341
|
const refresh = await this.refreshToken();
|
|
244
342
|
if (refresh) {
|
|
343
|
+
// Update the Authorization header with the new access token
|
|
245
344
|
options.headers['Authorization'] =
|
|
246
345
|
'Bearer ' + this.state.accessToken;
|
|
346
|
+
// Retry the fetch request with updated headers
|
|
247
347
|
const secondResponse = await fetch(this._getFullPath(path), options);
|
|
348
|
+
// Return the JSON-parsed response of the retry request
|
|
248
349
|
return await secondResponse.json();
|
|
249
350
|
}
|
|
250
351
|
}
|
|
352
|
+
// Store the response status and parse the response body as JSON
|
|
251
353
|
const status = response.status;
|
|
252
354
|
const res = await response.json();
|
|
355
|
+
// Handle different HTTP status codes with corresponding error functions
|
|
253
356
|
if (status == 400) {
|
|
254
357
|
if (this.state.errorsFunctions && this.state.errorsFunctions['400']) {
|
|
255
358
|
this.state.errorsFunctions['400'](res);
|
|
@@ -275,6 +378,7 @@ class AsyncModules extends syncModules_1.default {
|
|
|
275
378
|
this.state.errorsFunctions['500'](res);
|
|
276
379
|
}
|
|
277
380
|
}
|
|
381
|
+
// Determine whether to return or throw the response based on 'isShell' state
|
|
278
382
|
if (this.state.isShell) {
|
|
279
383
|
return res;
|
|
280
384
|
}
|
|
@@ -284,6 +388,8 @@ class AsyncModules extends syncModules_1.default {
|
|
|
284
388
|
}
|
|
285
389
|
}
|
|
286
390
|
catch (e) {
|
|
391
|
+
// Handle any errors that occur during the fetch process
|
|
392
|
+
// Determine whether to return or throw the error based on 'isShell' state
|
|
287
393
|
if (this.state.isShell) {
|
|
288
394
|
return e;
|
|
289
395
|
}
|
package/dist/base/result.js
CHANGED
|
@@ -3,48 +3,63 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
/* eslint-disable no-restricted-syntax */
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
class Result {
|
|
6
|
+
// Constructor that initializes the class with a given data, which can be of type Response or string.
|
|
6
7
|
constructor(data) {
|
|
7
8
|
this.body = data;
|
|
8
9
|
}
|
|
10
|
+
// Asynchronously converts the body to a blob and returns the current instance.
|
|
9
11
|
async blob() {
|
|
12
|
+
// Convert the body to a blob using the blob() method.
|
|
10
13
|
this.body = await this.body.blob();
|
|
11
14
|
return this;
|
|
12
15
|
}
|
|
16
|
+
// Asynchronously parses the body as JSON and returns the current instance.
|
|
13
17
|
async json() {
|
|
18
|
+
// Check if the body is a string, then parse it as JSON, otherwise call the json() method.
|
|
14
19
|
this.body =
|
|
15
20
|
(await typeof this.body) === 'string'
|
|
16
21
|
? JSON.parse(this.body)
|
|
17
22
|
: this.body.json();
|
|
18
23
|
return this;
|
|
19
24
|
}
|
|
25
|
+
// Recursively removes language-specific data from the provided data or the body.
|
|
20
26
|
makeDataWithoutLang(langCode, data) {
|
|
21
27
|
if (data) {
|
|
28
|
+
// If data is an array, recursively process each item.
|
|
22
29
|
if (Array.isArray(data)) {
|
|
23
30
|
return data.map((item) => this.makeDataWithoutLang(langCode, item));
|
|
24
31
|
}
|
|
25
32
|
else {
|
|
33
|
+
// Iterate through each key in the data object.
|
|
26
34
|
for (const key in data) {
|
|
35
|
+
// If the value is an object containing the specified language code, replace it with the language-specific value.
|
|
27
36
|
if (typeof data[key] === 'object' &&
|
|
28
37
|
data[key] &&
|
|
29
38
|
langCode in data[key]) {
|
|
30
39
|
data[key] = data[key][langCode];
|
|
31
40
|
}
|
|
32
41
|
else if (typeof data[key] === 'object' && data[key] != null) {
|
|
42
|
+
// If the value is an object, recursively process it
|
|
33
43
|
data[key] = this.makeDataWithoutLang(langCode, data[key]);
|
|
34
44
|
}
|
|
35
45
|
else if (Array.isArray(data[key])) {
|
|
46
|
+
// If the value is an array, recursively process each item.
|
|
36
47
|
data[key] = data.map((item) => this.makeDataWithoutLang(langCode, item));
|
|
37
48
|
}
|
|
38
49
|
}
|
|
50
|
+
// Return the processed data.
|
|
39
51
|
return data;
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
else {
|
|
55
|
+
// Process the body if no specific data is provided.
|
|
43
56
|
if (Array.isArray(this.body)) {
|
|
44
57
|
this.body = this.body.map((item) => this.makeDataWithoutLang(langCode, item));
|
|
45
58
|
}
|
|
46
59
|
else {
|
|
60
|
+
// Iterate through each key in the body object.
|
|
47
61
|
for (const key in this.body) {
|
|
62
|
+
// Similar processing as above but applied to the body.
|
|
48
63
|
if (typeof this.body[key] === 'object' &&
|
|
49
64
|
this.body[key] &&
|
|
50
65
|
langCode in this.body[key]) {
|
|
@@ -62,19 +77,24 @@ class Result {
|
|
|
62
77
|
return this;
|
|
63
78
|
}
|
|
64
79
|
}
|
|
80
|
+
// Recursively simplifies arrays in the provided data or the body by removing single-element arrays.
|
|
65
81
|
makeDataWithoutArray(data) {
|
|
66
82
|
if (data) {
|
|
83
|
+
// If data is an array, recursively process each item.
|
|
67
84
|
if (Array.isArray(data)) {
|
|
68
85
|
return data.map((item) => this.makeDataWithoutArray(item));
|
|
69
86
|
}
|
|
70
87
|
else {
|
|
88
|
+
// Iterate through each key in the data object.
|
|
71
89
|
for (const key in data) {
|
|
90
|
+
// If the value is a single-element array, replace it with the element itself.
|
|
72
91
|
if (Array.isArray(data[key]) && data[key].length === 1) {
|
|
73
92
|
data[key] = data[key][0];
|
|
74
93
|
}
|
|
75
94
|
else if (typeof data[key] === 'object' &&
|
|
76
95
|
data[key] &&
|
|
77
96
|
!Array.isArray(data[key])) {
|
|
97
|
+
// If the value is an object, recursively process it.
|
|
78
98
|
data[key] = this.makeDataWithoutArray(data[key]);
|
|
79
99
|
}
|
|
80
100
|
}
|
|
@@ -82,11 +102,14 @@ class Result {
|
|
|
82
102
|
}
|
|
83
103
|
}
|
|
84
104
|
else {
|
|
105
|
+
// Process the body if no specific data is provided.
|
|
85
106
|
if (Array.isArray(this.body)) {
|
|
86
107
|
return this.body.map((item) => this.makeDataWithoutArray(item));
|
|
87
108
|
}
|
|
88
109
|
else {
|
|
110
|
+
// Iterate through each key in the body object.
|
|
89
111
|
for (const key in this.body) {
|
|
112
|
+
// Similar processing as above but applied to the body.
|
|
90
113
|
if (Array.isArray(this.body[key]) && this.body[key].length === 1) {
|
|
91
114
|
this.body[key] = this.body[key][0];
|
|
92
115
|
}
|
package/dist/base/syncModules.js
CHANGED
|
@@ -269,7 +269,7 @@ class SyncModules {
|
|
|
269
269
|
// add timeIntervals
|
|
270
270
|
if (data.attributeValues[attr].type === 'timeInterval') {
|
|
271
271
|
const schedules = data.attributeValues[attr].value;
|
|
272
|
-
// console.log(JSON.stringify(schedules));
|
|
272
|
+
// console.log('Schedules: ', JSON.stringify(schedules));
|
|
273
273
|
if (Array.isArray(schedules) && schedules.length > 0) {
|
|
274
274
|
const result = this._addTimeIntervalsToSchedules(schedules);
|
|
275
275
|
data.attributeValues[attr].value = result;
|
|
@@ -292,6 +292,7 @@ class SyncModules {
|
|
|
292
292
|
// Add time intervals
|
|
293
293
|
if (d[attr].type === 'timeInterval') {
|
|
294
294
|
// const schedules = d[attr].localizeInfos.intervals;
|
|
295
|
+
// console.log('Schedules:: ', JSON.stringify(schedules));
|
|
295
296
|
// if (Array.isArray(schedules) && schedules.length > 0) {
|
|
296
297
|
// const result = this._addTimeIntervalsToSchedulesForm(schedules);
|
|
297
298
|
// d[attr].localizeInfos.intervals = result;
|
|
@@ -334,5 +335,22 @@ class SyncModules {
|
|
|
334
335
|
this.state.refreshToken = refreshToken;
|
|
335
336
|
return this;
|
|
336
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Get deviceMetadata
|
|
340
|
+
*/
|
|
341
|
+
_getDeviceMetadata() {
|
|
342
|
+
const platform = navigator.platform;
|
|
343
|
+
const userAgent = navigator.userAgent;
|
|
344
|
+
const language = navigator.language;
|
|
345
|
+
const deviceMetadata = {
|
|
346
|
+
fingerprint: 'abc123-fp',
|
|
347
|
+
deviceInfo: {
|
|
348
|
+
os: platform,
|
|
349
|
+
browser: userAgent,
|
|
350
|
+
location: language,
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
return JSON.stringify(deviceMetadata);
|
|
354
|
+
}
|
|
337
355
|
}
|
|
338
356
|
exports.default = SyncModules;
|
package/dist/base/utils.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ interface IAttributeValues {
|
|
|
84
84
|
interface IAttributeValue {
|
|
85
85
|
[key: string]: any;
|
|
86
86
|
}
|
|
87
|
-
type AttributeType =
|
|
87
|
+
type AttributeType = IAttributeValue | IAttributeValues;
|
|
88
88
|
type LangType = string | Array<string>;
|
|
89
89
|
type LocalizeType = ILocalizeInfos | ILocalizeInfo;
|
|
90
90
|
interface IError {
|
|
@@ -21,30 +21,26 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
|
21
21
|
*
|
|
22
22
|
* @handleName getBlocks
|
|
23
23
|
*
|
|
24
|
-
* @param {BlockType} type - Available values
|
|
24
|
+
* @param {BlockType} type - Available values: "product" | "error_page" | "catalog_page" | "product_preview" | "similar_products_block" | "product_block" | "form" | "common_page" | "common_block" | "order" | "service" | "none". Example: 'product'.
|
|
25
25
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
26
26
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
27
27
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
28
|
-
*
|
|
29
28
|
* @return {IBlocksResponse} Returns BlocksEntity object.
|
|
30
29
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
31
|
-
*
|
|
32
30
|
* @description This method requires user authorization. For more information about configuring the authorization module, see the documentation in the configuration settings section of the SDK.
|
|
33
31
|
*/
|
|
34
|
-
getBlocks(type
|
|
32
|
+
getBlocks(type?: BlockType, langCode?: string, offset?: number, limit?: number): Promise<IBlocksResponse | IError>;
|
|
35
33
|
/**
|
|
36
34
|
* Get block by marker.
|
|
37
35
|
*
|
|
38
36
|
* @handleName getBlockByMarker
|
|
39
37
|
*
|
|
40
|
-
* @param {string} marker - Marker of Block. Example:
|
|
38
|
+
* @param {string} marker - Marker of Block. Example: "product_block".
|
|
41
39
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
42
40
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
43
41
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
44
|
-
*
|
|
45
42
|
* @return {IBlockEntity} - Returns a BlockEntity object.
|
|
46
43
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
47
|
-
*
|
|
48
44
|
* @description This method retrieves a block by its marker and includes additional information such as similar products or products associated with the block.
|
|
49
45
|
*/
|
|
50
46
|
getBlockByMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<IBlockEntity | IError>;
|
|
@@ -53,14 +49,12 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
|
53
49
|
*
|
|
54
50
|
* @handleName getSimilarProducts
|
|
55
51
|
*
|
|
56
|
-
* @param {string} marker - Block identifier. Example:
|
|
52
|
+
* @param {string} marker - Block identifier. Example: "similar_products_block".
|
|
57
53
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
58
54
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
59
55
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
60
|
-
*
|
|
61
56
|
* @return {IProductsResponse} - Returns the total count and an array of product items in object by specified block marker.
|
|
62
57
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
63
|
-
*
|
|
64
58
|
* @description This method requires user authorization. For more information about configuring the authorization module, see the documentation in the configuration settings section of the SDK.
|
|
65
59
|
*/
|
|
66
60
|
private getSimilarProducts;
|
|
@@ -69,14 +63,12 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
|
69
63
|
*
|
|
70
64
|
* @handleName getProductsByBlockMarker
|
|
71
65
|
*
|
|
72
|
-
* @param {string} marker - Block identifier. Example:
|
|
66
|
+
* @param {string} marker - Block identifier. Example: "product_block".
|
|
73
67
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
74
68
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
75
69
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
76
|
-
*
|
|
77
70
|
* @return {IProductsEntity[]} Return array of BlocksEntity object.
|
|
78
71
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
79
|
-
*
|
|
80
72
|
* @description This method requires user authorization. For more information about configuring the authorization module, see the documentation in the configuration settings section of the SDK.
|
|
81
73
|
*/
|
|
82
74
|
private getProductsByBlockMarker;
|
|
@@ -85,13 +77,11 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
|
85
77
|
*
|
|
86
78
|
* @handleName searchBlock
|
|
87
79
|
*
|
|
88
|
-
* @param {string} name - Search string. Example:
|
|
80
|
+
* @param {string} name - Search string. Example: "product_block".
|
|
89
81
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
90
|
-
*
|
|
91
82
|
* @return {ISearchBlock[]} Returns an array of ISearchBlock objects.
|
|
92
83
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
93
|
-
*
|
|
94
84
|
* @description This method requires user authorization. For more information about configuring the authorization module, see the documentation in the configuration settings section of the SDK.
|
|
95
85
|
*/
|
|
96
|
-
searchBlock(name: string, langCode?: string): Promise<
|
|
86
|
+
searchBlock(name: string, langCode?: string): Promise<ISearchBlock[] | IError>;
|
|
97
87
|
}
|