oneentry 1.0.153 → 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 CHANGED
@@ -1,5 +1,42 @@
1
1
  # SDK Change Log
2
2
 
3
+ ## v.1.0.154
4
+
5
+ ### What's New
6
+
7
+ - Products > per-method query types — the single `IProductsQuery` is split into focused query types so each method only accepts the parameters it actually supports:
8
+ - `IProductsQueryBase` — base query (`offset`, `limit`, `sortOrder`, `sortKey`, `signPrice`) used by `getProducts`, `getProductsEmptyPage`, `getProductsByPageId`, `getProductsByPageUrl`.
9
+ - `IProductsRelatedQuery` — base query plus `statusMarker` and `templateMarker`, used by `getRelatedProductsById`.
10
+ - `IProductsPriceQuery` — base query without `sortKey`, plus `statusMarker`, used by `getProductsPriceByPageUrl`.
11
+ - `IProductsByIdsQuery` — only `signPrice` (`ids` is a dedicated method argument), used by `getProductsByIds`.
12
+ - All four types are now exported.
13
+
14
+ - Orders > `IOrderProductData.signedPrice` — new optional `signedPrice` (`string`) field: the signed (fixed) product price obtained together with the product data when `signPrice` is set. Used to carry the fixed price into an order line item.
15
+
16
+ - Products > `IProductInfo.signedPrice` — new optional `signedPrice` (`string`) field on the price-list items returned by `getProductsPriceByPageUrl`; populated with the signed (fixed) price when `signPrice` is set (mirrors `IProductsEntity.signedPrice`).
17
+
18
+ ### What's Changed
19
+
20
+ - Products > `getProducts`, `getProductsEmptyPage`, `getProductsByPageId`, `getProductsByPageUrl`, `getProductsPriceByPageUrl`, `getRelatedProductsById`, `getProductsByIds` — `userQuery` is now typed with the corresponding per-method query type above instead of the broad `IProductsQuery`. `IProductsQuery` is retained as a **deprecated** alias of `IProductsQueryBase` for backward compatibility.
21
+
22
+ - Products > `getProductsByIds` — now accepts only `signPrice` in `userQuery` (`IProductsByIdsQuery`); `limit`/`sort`/filter markers are no longer query parameters of this endpoint. As a result `searchProduct` (quick search) no longer forwards an explicit `limit` to the internal `/ids` request.
23
+
24
+ - Products / Blocks / Orders — JSDoc for `signPrice` / `signedPrice` clarified ("Order storage marker for price fixing…") with links to the "Fixing the price" / "Fixed product price" documentation. Orders > `previewOrder` description cleaned up (removed the stray `???`). No structural change.
25
+
26
+ - HTTP core — the legacy Node.js `< 18` request path was removed. The SDK previously detected old Node versions and routed requests through a dynamically imported `https` module (`_NO_FETCH` / `state._https`); that branch did **not** perform token refresh, response validation, `errorsFunctions` callbacks or `isShell` handling, so behavior silently degraded on old Node. All requests now go through the native `fetch` path (browser and Node 18+), which collapses four duplicated `_fetchGet` / `_fetchPost` / `_fetchPut` / `_fetchDelete` implementations into one and gives every environment the same auth/validation/error behavior. **The SDK now requires Node 18+** (declared via `engines.node >= 18`).
27
+
28
+ ### Bug Fixes
29
+
30
+ - Query parameters and free-text search are now URL-encoded (`encodeURIComponent`). Previously values containing spaces, `&`, `=` or non-ASCII characters corrupted the query string — most visibly in the text search of `Products.searchProduct`, `Pages.searchPage` and `Blocks.searchBlock`.
31
+ - `Pages.searchPage` — fixed the `url` query part: when no `url` was passed the request string previously contained stray output (`undefined` / a leading `&`). It is now built correctly and omitted when absent.
32
+ - Auth — the `401 → refresh → retry` path now flows through the same response handling as the initial request. The retried response is checked for `ok`, tolerates an empty body, and runs `errorsFunctions` / honors `isShell`. Previously a failed retry returned the raw error body as if it were successful data, and an empty retry body could throw from `.json()`.
33
+
34
+ - `defineOneEntry` — initializing the SDK without a project URL or app token no longer crashes with a cryptic `TypeError: Cannot read properties of undefined (reading 'endsWith')`. The function now validates its inputs up front and throws a clear, actionable error instead: a missing/empty `url` (PROJECT_URL) and a missing/empty `config.token` (APP_TOKEN) each produce a descriptive message with a correct usage example. Empty / whitespace-only values (e.g. an unfilled `.env` variable) are treated as missing.
35
+
36
+ ### What's Deleted
37
+
38
+ - Removed the unused `src/base/result.ts` (dead `Result` class — never imported, and containing a misplaced `await` and unreachable branches).
39
+
3
40
  ## v.1.0.153
4
41
 
5
42
  ### What's New
@@ -8,8 +8,6 @@ import type { IError } from './utils';
8
8
  */
9
9
  export default abstract class AsyncModules extends SyncModules {
10
10
  protected state: StateModule;
11
- protected _NO_FETCH: boolean;
12
- protected _https: any;
13
11
  protected _url: string;
14
12
  /**
15
13
  * Constructor initializes the AsyncModules with a given state.
@@ -86,6 +84,16 @@ export default abstract class AsyncModules extends SyncModules {
86
84
  * @returns {IHttpOptions} An object representing the request options.
87
85
  */
88
86
  private makeOptions;
87
+ /**
88
+ * Reads a response body as JSON, tolerating an empty body.
89
+ *
90
+ * `Response.json()` throws on an empty body (e.g. 204 or an empty error
91
+ * payload); this helper mirrors the OK-path guard (`text ? JSON.parse : {}`)
92
+ * so both the success and the error branches handle empty bodies the same way.
93
+ * @param {Response} response - The fetch Response to read.
94
+ * @returns {Promise<unknown>} Parsed JSON, or an empty object when the body is empty/unparsable.
95
+ */
96
+ private _parseJson;
89
97
  /**
90
98
  * Handles responses from the browser's fetch API.
91
99
  * @param {string} path - The path to append to the base URL.
@@ -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
- // Create options for the GET request using the 'makeOptions' method
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
- // Create options for the POST request using the 'makeOptions' method, including the data to be sent
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
- // Create options for the PUT request using the 'makeOptions' method, including the data to be sent
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,47 +102,7 @@ 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
- // Create options for the DELETE request using the 'makeOptions' method
243
- const options = this.makeOptions('DELETE', body);
244
- // Check if the fetch operation should be performed using the Fetch API or an alternative method
245
- if (!this._NO_FETCH) {
246
- // If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
247
- return await this.browserResponse(path, options);
248
- }
249
- else {
250
- // If Fetch API is not allowed, perform the request using Node.js HTTPS module
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
- });
282
- }
105
+ return this.browserResponse(path, this.makeOptions('DELETE', body));
283
106
  }
284
107
  /**
285
108
  * Wraps a fetch call whose only meaningful outcome is success or failure.
@@ -429,6 +252,24 @@ class AsyncModules extends syncModules_1.default {
429
252
  }
430
253
  return options;
431
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
+ }
432
273
  /**
433
274
  * Handles responses from the browser's fetch API.
434
275
  * @param {string} path - The path to append to the base URL.
@@ -464,56 +305,45 @@ class AsyncModules extends syncModules_1.default {
464
305
  }
465
306
  }
466
307
  // Perform a fetch request using the full URL obtained from '_getFullPath' and the provided options
467
- const response = await fetch(this._getFullPath(path), options);
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
+ }
468
326
  // Check if the response status is OK (status code 200-299)
469
327
  if (response.ok) {
470
- try {
471
- // Attempt to read the response body as text
472
- const text = await response.text();
473
- // If the response body is not empty, parse it as JSON; otherwise, return an empty object
474
- return (text ? JSON.parse(text) : {});
475
- // Alternatively, you could directly return the parsed JSON with 'await response.json()'
476
- }
477
- catch (e) {
478
- // If parsing the response fails, return the error
479
- return e;
480
- }
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;
481
344
  }
482
345
  else {
483
- // Handle non-OK responses
484
- // Reactive refresh for mid-session expiry: access token was present but
485
- // the server rejected it. Skipped when a proactive refresh already ran
486
- // and failed (the refresh token is dead — retrying would 400 again).
487
- if (response.status === 401 &&
488
- !this.state.customAuth &&
489
- !proactiveRefreshFailed) {
490
- // Attempt to refresh the access token
491
- const refresh = await this.refreshToken();
492
- if (refresh) {
493
- // Update the Authorization header with the new access token
494
- options.headers['Authorization'] =
495
- 'Bearer ' + this.state.accessToken;
496
- // Retry the fetch request with updated headers
497
- const secondResponse = await fetch(this._getFullPath(path), options);
498
- // Return the JSON-parsed response of the retry request
499
- return (await secondResponse.json());
500
- }
501
- }
502
- // Store the response status and parse the response body as JSON
503
- const status = response.status;
504
- const res = await response.json();
505
- const statusKey = status;
506
- if (this.state.errorsFunctions &&
507
- this.state.errorsFunctions[statusKey]) {
508
- this.state.errorsFunctions[statusKey](res);
509
- }
510
- // Determine whether to return or throw the response based on 'isShell' state
511
- if (this.state.isShell) {
512
- return res;
513
- }
514
- else {
515
- throw res;
516
- }
346
+ throw res;
517
347
  }
518
348
  }
519
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 {};
@@ -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, _v, _w, _x, _y, _z, _0, _1;
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
- if (config.errors) {
80
- this.isShell = (_s = config.errors.isShell) !== null && _s !== void 0 ? _s : true;
81
- if (config.errors.customErrors) {
82
- this.errorsFunctions['400'] =
83
- (_t = config.errors.customErrors['400']) !== null && _t !== void 0 ? _t : undefined;
84
- this.errorsFunctions['401'] =
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
  */
@@ -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
  /**