oneentry 1.0.136 → 1.0.137

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.
Files changed (83) hide show
  1. package/README.md +15 -3
  2. package/configure.js +27 -3
  3. package/dist/admins/adminsApi.js +4 -1
  4. package/dist/admins/adminsInterfaces.d.ts +1 -1
  5. package/dist/admins/adminsSchemas.d.ts +30 -0
  6. package/dist/admins/adminsSchemas.js +27 -0
  7. package/dist/attribute-sets/attributeSetsApi.js +13 -4
  8. package/dist/attribute-sets/attributeSetsSchemas.d.ts +90 -0
  9. package/dist/attribute-sets/attributeSetsSchemas.js +74 -0
  10. package/dist/auth-provider/authProviderApi.d.ts +11 -8
  11. package/dist/auth-provider/authProviderApi.js +25 -15
  12. package/dist/auth-provider/authProviderSchemas.d.ts +137 -0
  13. package/dist/auth-provider/authProviderSchemas.js +85 -0
  14. package/dist/auth-provider/authProvidersInterfaces.d.ts +6 -6
  15. package/dist/base/asyncModules.d.ts +25 -15
  16. package/dist/base/asyncModules.js +91 -24
  17. package/dist/base/stateModule.d.ts +7 -0
  18. package/dist/base/stateModule.js +26 -11
  19. package/dist/base/syncModules.d.ts +12 -0
  20. package/dist/base/syncModules.js +45 -94
  21. package/dist/base/utils.d.ts +41 -2
  22. package/dist/base/validation.d.ts +118 -0
  23. package/dist/base/validation.js +132 -0
  24. package/dist/blocks/blocksApi.js +16 -11
  25. package/dist/blocks/blocksInterfaces.d.ts +1 -1
  26. package/dist/blocks/blocksSchemas.d.ts +187 -0
  27. package/dist/blocks/blocksSchemas.js +43 -0
  28. package/dist/config.d.ts +10 -2
  29. package/dist/config.js +20 -4
  30. package/dist/file-uploading/fileUploadingApi.js +4 -1
  31. package/dist/file-uploading/fileUploadingSchemas.d.ts +22 -0
  32. package/dist/file-uploading/fileUploadingSchemas.js +21 -0
  33. package/dist/forms/formsApi.js +7 -2
  34. package/dist/forms/formsInterfaces.d.ts +20 -8
  35. package/dist/forms/formsSchemas.d.ts +65 -0
  36. package/dist/forms/formsSchemas.js +36 -0
  37. package/dist/forms-data/formsDataApi.js +10 -3
  38. package/dist/forms-data/formsDataInterfaces.d.ts +2 -2
  39. package/dist/forms-data/formsDataSchemas.d.ts +107 -0
  40. package/dist/forms-data/formsDataSchemas.js +83 -0
  41. package/dist/general-types/generalTypesApi.js +4 -1
  42. package/dist/general-types/generalTypesSchemas.d.ts +50 -0
  43. package/dist/general-types/generalTypesSchemas.js +35 -0
  44. package/dist/integration-collections/integrationCollectionsApi.js +25 -9
  45. package/dist/integration-collections/integrationCollectionsSchemas.d.ts +84 -0
  46. package/dist/integration-collections/integrationCollectionsSchemas.js +63 -0
  47. package/dist/locales/localesApi.js +4 -1
  48. package/dist/locales/localesSchemas.d.ts +32 -0
  49. package/dist/locales/localesSchemas.js +26 -0
  50. package/dist/menus/menusApi.js +4 -1
  51. package/dist/menus/menusSchemas.d.ts +16 -0
  52. package/dist/menus/menusSchemas.js +28 -0
  53. package/dist/orders/ordersApi.js +13 -4
  54. package/dist/orders/ordersInterfaces.d.ts +3 -3
  55. package/dist/orders/ordersSchemas.d.ts +158 -0
  56. package/dist/orders/ordersSchemas.js +120 -0
  57. package/dist/pages/pagesApi.d.ts +2 -1
  58. package/dist/pages/pagesApi.js +87 -34
  59. package/dist/pages/pagesInterfaces.d.ts +6 -5
  60. package/dist/pages/pagesSchemas.d.ts +85 -0
  61. package/dist/pages/pagesSchemas.js +46 -0
  62. package/dist/payments/paymentsApi.js +13 -4
  63. package/dist/payments/paymentsInterfaces.d.ts +3 -3
  64. package/dist/payments/paymentsSchemas.d.ts +121 -0
  65. package/dist/payments/paymentsSchemas.js +75 -0
  66. package/dist/product-statuses/productStatusesApi.js +13 -3
  67. package/dist/product-statuses/productStatusesSchemas.d.ts +34 -0
  68. package/dist/product-statuses/productStatusesSchemas.js +30 -0
  69. package/dist/products/productsApi.js +19 -6
  70. package/dist/products/productsInterfaces.d.ts +4 -4
  71. package/dist/products/productsSchemas.d.ts +212 -0
  72. package/dist/products/productsSchemas.js +85 -0
  73. package/dist/templates/templatesApi.js +11 -4
  74. package/dist/templates/templatesSchemas.d.ts +48 -0
  75. package/dist/templates/templatesSchemas.js +31 -0
  76. package/dist/templates-preview/templatesPreviewApi.js +7 -2
  77. package/dist/templates-preview/templatesPreviewSchemas.d.ts +83 -0
  78. package/dist/templates-preview/templatesPreviewSchemas.js +48 -0
  79. package/dist/users/usersApi.js +8 -5
  80. package/dist/users/usersInterfaces.d.ts +2 -1
  81. package/dist/users/usersSchemas.d.ts +38 -0
  82. package/dist/users/usersSchemas.js +28 -0
  83. package/package.json +5 -4
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActiveSessionsResponseSchema = exports.ActiveSessionSchema = exports.LogoutResponseSchema = exports.GenerateCodeResponseSchema = exports.AuthProvidersResponseSchema = exports.AuthProviderEntitySchema = exports.UserResponseSchema = exports.AuthResponseSchema = exports.SignUpResponseSchema = void 0;
4
+ /**
5
+ * Validation schemas for Auth Provider module
6
+ * @description Zod schemas for validating auth-related API responses
7
+ */
8
+ const zod_1 = require("zod");
9
+ const validation_1 = require("../base/validation");
10
+ /**
11
+ * Sign up response schema
12
+ * @description Schema for validating sign up response
13
+ */
14
+ exports.SignUpResponseSchema = zod_1.z.object({
15
+ id: zod_1.z.number(),
16
+ identifier: zod_1.z.string().optional(),
17
+ email: zod_1.z.string().email().optional(),
18
+ phoneMask: zod_1.z.string().optional(),
19
+ phoneCode: zod_1.z.string().optional(),
20
+ phoneNumber: zod_1.z.string().optional(),
21
+ statusMarker: zod_1.z.string().optional(),
22
+ });
23
+ /**
24
+ * Auth response schema (login/refresh)
25
+ * @description Schema for validating auth response
26
+ */
27
+ exports.AuthResponseSchema = validation_1.AuthEntitySchema;
28
+ /**
29
+ * User response schema
30
+ * @description Schema for validating user response
31
+ */
32
+ exports.UserResponseSchema = validation_1.UserEntitySchema;
33
+ /**
34
+ * Auth provider entity schema
35
+ * @description Schema for validating auth provider entity
36
+ * Includes all fields returned by the API
37
+ */
38
+ exports.AuthProviderEntitySchema = zod_1.z.object({
39
+ id: zod_1.z.number(),
40
+ identifier: zod_1.z.string(),
41
+ type: zod_1.z.string().optional(),
42
+ formIdentifier: zod_1.z.string().optional(),
43
+ userGroupIdentifier: zod_1.z.string().optional(),
44
+ isActive: zod_1.z.boolean(),
45
+ isCheckCode: zod_1.z.boolean().optional(),
46
+ version: zod_1.z.number().optional(),
47
+ localizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
48
+ config: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
49
+ marker: zod_1.z.string().optional(),
50
+ name: zod_1.z.string().optional(),
51
+ position: zod_1.z.number().optional(),
52
+ });
53
+ /**
54
+ * Auth providers list response schema
55
+ * @description Schema for validating auth providers list response
56
+ */
57
+ exports.AuthProvidersResponseSchema = zod_1.z.array(exports.AuthProviderEntitySchema);
58
+ /**
59
+ * Generate code response schema
60
+ * @description Schema for validating generate code response
61
+ */
62
+ exports.GenerateCodeResponseSchema = zod_1.z.object({
63
+ success: zod_1.z.boolean(),
64
+ message: zod_1.z.string().optional(),
65
+ });
66
+ /**
67
+ * Logout response schema
68
+ * @description Schema for validating logout response
69
+ */
70
+ exports.LogoutResponseSchema = zod_1.z.object({
71
+ success: zod_1.z.boolean(),
72
+ message: zod_1.z.string().optional(),
73
+ });
74
+ /**
75
+ * Active sessions response schema
76
+ * @description Schema for validating active sessions response
77
+ */
78
+ exports.ActiveSessionSchema = zod_1.z.object({
79
+ id: zod_1.z.string(),
80
+ deviceInfo: zod_1.z.string().optional(),
81
+ ipAddress: zod_1.z.string().optional(),
82
+ lastActive: zod_1.z.string().optional(),
83
+ createdAt: zod_1.z.string(),
84
+ });
85
+ exports.ActiveSessionsResponseSchema = zod_1.z.array(exports.ActiveSessionSchema);
@@ -13,7 +13,7 @@ import type { IError, ILocalizeInfo } from '../base/utils';
13
13
  * @property {Function} getAuthProviders - Get all auth providers objects.
14
14
  * @property {Function} getAuthProviderByMarker - Get one auth provider object by marker.
15
15
  * @property {Function} getActiveSessionsByMarker - Get one auth provider object by marker.
16
- * @property {Function} oauthSignUp - User registration (authorization) via OAUTH.
16
+ * @property {Function} oauth - User registration (authorization) via OAUTH.
17
17
  * @description This interface defines methods for user authentication and registration through various auth providers.
18
18
  */
19
19
  interface IAuthProvider {
@@ -176,7 +176,7 @@ interface IAuthProvider {
176
176
  * User registration (authorization) via OAUTH.
177
177
  * @handleName oauthSignUp
178
178
  * @param {string} marker - The text identifier of the authorization provider. Example: "email".
179
- * @param {IOAuthSignUpData} body - Object contains OAuth information for registration.
179
+ * @param {IOauthData} body - Object contains OAuth information for registration.
180
180
  * @example
181
181
  {
182
182
  "client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com",
@@ -190,7 +190,7 @@ interface IAuthProvider {
190
190
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
191
191
  * @description User registration (authorization) via OAUTH.
192
192
  */
193
- oauthSignUp(marker: string, body: IOAuthSignUpData, langCode: string): Promise<IAuthEntity | IError>;
193
+ oauth(marker: string, body: IOauthData, langCode?: string): Promise<IAuthEntity | IError>;
194
194
  }
195
195
  /**
196
196
  * Interface representing the structure of authentication form data.
@@ -282,7 +282,7 @@ interface ISignUpData {
282
282
  }
283
283
  /**
284
284
  * Interface representing the data required for user registration via OAUTH.
285
- * @interface IOAuthSignUpData
285
+ * @interface IOauthData
286
286
  * @property {string} client_id - The client ID for the OAuth application. Example: "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com".
287
287
  * @property {string} client_secret - The client secret for the OAuth application. Example: "43434343434".
288
288
  * @property {string} code - The authorization code received from the OAuth provider. Example: "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g".
@@ -290,7 +290,7 @@ interface ISignUpData {
290
290
  * @property {string} redirect_uri - The redirect URI for the OAuth application. Example: "http://localhost:3000".
291
291
  * @description User registration (❗️For a provider with user activation, the activation code is sent through the corresponding user notification method).
292
292
  */
293
- interface IOAuthSignUpData {
293
+ interface IOauthData {
294
294
  client_id: string;
295
295
  client_secret: string;
296
296
  code: string;
@@ -464,4 +464,4 @@ interface IActiveSession {
464
464
  location: string;
465
465
  };
466
466
  }
467
- export type { IActiveSession, IAuthEntity, IAuthFormData, IAuthPostBody, IAuthProvider, IAuthProvidersEntity, ICodeEntity, IOAuthSignUpData, ISignUpData, ISignUpEntity, };
467
+ export type { IActiveSession, IAuthEntity, IAuthFormData, IAuthPostBody, IAuthProvider, IAuthProvidersEntity, ICodeEntity, IOauthData, ISignUpData, ISignUpEntity, };
@@ -1,5 +1,7 @@
1
+ import type { z } from 'zod';
1
2
  import type StateModule from './stateModule';
2
3
  import SyncModules from './syncModules';
4
+ import type { IError } from './utils';
3
5
  /**
4
6
  * Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
5
7
  * @description Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
@@ -15,37 +17,45 @@ export default abstract class AsyncModules extends SyncModules {
15
17
  * @description Constructor initializes the AsyncModules with a given state.
16
18
  */
17
19
  protected constructor(state: StateModule);
20
+ /**
21
+ * Validates API response against a Zod schema (optional)
22
+ * @param {unknown} data - The data to validate
23
+ * @param {z.ZodSchema<T>} [schema] - Optional Zod schema for validation
24
+ * @returns {T | IError} Validated data or error object
25
+ * @description Validates response data if validation is enabled in config
26
+ */
27
+ protected _validateResponse<T>(data: unknown, schema?: z.ZodSchema<T>): T | IError;
18
28
  /**
19
29
  * Performs an HTTP GET request.
20
30
  * @param {string} path - The path to append to the base URL.
21
- * @returns {Promise<any>} A promise resolving to the response data.
31
+ * @returns {Promise<T>} A promise resolving to the response data.
22
32
  * @description Define a protected asynchronous method '_fetchGet' that performs a GET request
23
33
  */
24
- protected _fetchGet(path: string): Promise<any>;
34
+ protected _fetchGet<T = unknown>(path: string): Promise<T>;
25
35
  /**
26
36
  * Performs an HTTP POST request.
27
37
  * @param {string} path - The path to append to the base URL.
28
- * @param {any} [data] - The data to send in the request body.
29
- * @returns {Promise<any>} A promise resolving to the response data.
38
+ * @param {unknown} [data] - The data to send in the request body.
39
+ * @returns {Promise<T>} A promise resolving to the response data.
30
40
  * @description Define a protected asynchronous method '_fetchPost' that performs a POST request
31
41
  */
32
- protected _fetchPost(path: string, data?: any): Promise<any>;
42
+ protected _fetchPost<T = unknown>(path: string, data?: unknown): Promise<T>;
33
43
  /**
34
44
  * Performs an HTTP PUT request.
35
45
  * @param {string} path - The path to append to the base URL.
36
- * @param {any} body - The data to send in the request body.
37
- * @returns {Promise<any>} A promise resolving to the response data.
46
+ * @param {unknown} body - The data to send in the request body.
47
+ * @returns {Promise<T>} A promise resolving to the response data.
38
48
  * @description Define a protected asynchronous method '_fetchPut' that performs a PUT request
39
49
  */
40
- protected _fetchPut(path: string, body: any): Promise<any>;
50
+ protected _fetchPut<T = unknown>(path: string, body: unknown): Promise<T>;
41
51
  /**
42
52
  * Performs an HTTP DELETE request.
43
53
  * @param {string} path - The path to append to the base URL.
44
- * @param {any} body - The body of the request.
45
- * @returns {Promise<any>} A promise resolving to the response data.
54
+ * @param {unknown} body - The body of the request.
55
+ * @returns {Promise<T>} A promise resolving to the response data.
46
56
  * @description Define a protected asynchronous method '_fetchDelete' that performs a DELETE request
47
57
  */
48
- protected _fetchDelete(path: string, body?: any): Promise<any>;
58
+ protected _fetchDelete<T = unknown>(path: string, body?: unknown): Promise<T>;
49
59
  /**
50
60
  * Refreshes the authentication token.
51
61
  * @returns {Promise<boolean>} A promise resolving to a boolean indicating success or failure.
@@ -55,15 +65,15 @@ export default abstract class AsyncModules extends SyncModules {
55
65
  /**
56
66
  * Creates options for HTTP requests.
57
67
  * @param {string} method - The HTTP method (GET, POST, PUT, DELETE, etc.).
58
- * @param {any} data - Optional data to include in the request body.
59
- * @returns {any} An object representing the request options.
68
+ * @param {unknown} data - Optional data to include in the request body.
69
+ * @returns {IHttpOptions} An object representing the request options.
60
70
  */
61
71
  private makeOptions;
62
72
  /**
63
73
  * Handles responses from the browser's fetch API.
64
74
  * @param {string} path - The path to append to the base URL.
65
- * @param {any} options - The options for the fetch request.
66
- * @returns {any} A promise resolving to the response data.
75
+ * @param {IHttpOptions} options - The options for the fetch request.
76
+ * @returns {Promise<T>} A promise resolving to the response data.
67
77
  * @description Define an asynchronous method 'browserResponse' that takes a path and options as parameters
68
78
  */
69
79
  private browserResponse;
@@ -3,8 +3,11 @@ 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");
6
9
  const syncModules_1 = __importDefault(require("./syncModules"));
7
- // import { IError } from './utils';
10
+ const validation_1 = require("./validation");
8
11
  /**
9
12
  * Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
10
13
  * @description Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
@@ -23,10 +26,47 @@ class AsyncModules extends syncModules_1.default {
23
26
  this._NO_FETCH = state._NO_FETCH;
24
27
  this._https = (_a = state._https) !== null && _a !== void 0 ? _a : null;
25
28
  }
29
+ /**
30
+ * Validates API response against a Zod schema (optional)
31
+ * @param {unknown} data - The data to validate
32
+ * @param {z.ZodSchema<T>} [schema] - Optional Zod schema for validation
33
+ * @returns {T | IError} Validated data or error object
34
+ * @description Validates response data if validation is enabled in config
35
+ */
36
+ _validateResponse(data, schema) {
37
+ // Skip validation if not enabled or no schema provided
38
+ if (!this.state.validationEnabled || !schema) {
39
+ return data;
40
+ }
41
+ // Use strict or safe validation based on config
42
+ if (this.state.validationStrictMode) {
43
+ const result = (0, validation_1.validateResponse)(schema, data, {
44
+ logErrors: this.state.validationLogErrors,
45
+ });
46
+ if (!result.success) {
47
+ // Return error object compatible with IError interface
48
+ return {
49
+ statusCode: 422,
50
+ message: 'Response validation failed',
51
+ pageData: null,
52
+ timestamp: new Date().toISOString(),
53
+ localizeMessage: result.error.issues
54
+ .map((e) => `${e.path.join('.')}: ${e.message}`)
55
+ .join(', '),
56
+ validationErrors: result.error.issues,
57
+ };
58
+ }
59
+ return result.data;
60
+ }
61
+ else {
62
+ // Non-strict mode: log errors but return original data
63
+ return (0, validation_1.validateResponseSafe)(schema, data, this.state.validationLogErrors);
64
+ }
65
+ }
26
66
  /**
27
67
  * Performs an HTTP GET request.
28
68
  * @param {string} path - The path to append to the base URL.
29
- * @returns {Promise<any>} A promise resolving to the response data.
69
+ * @returns {Promise<T>} A promise resolving to the response data.
30
70
  * @description Define a protected asynchronous method '_fetchGet' that performs a GET request
31
71
  */
32
72
  async _fetchGet(path) {
@@ -75,8 +115,8 @@ class AsyncModules extends syncModules_1.default {
75
115
  /**
76
116
  * Performs an HTTP POST request.
77
117
  * @param {string} path - The path to append to the base URL.
78
- * @param {any} [data] - The data to send in the request body.
79
- * @returns {Promise<any>} A promise resolving to the response data.
118
+ * @param {unknown} [data] - The data to send in the request body.
119
+ * @returns {Promise<T>} A promise resolving to the response data.
80
120
  * @description Define a protected asynchronous method '_fetchPost' that performs a POST request
81
121
  */
82
122
  async _fetchPost(path, data) {
@@ -96,21 +136,23 @@ class AsyncModules extends syncModules_1.default {
96
136
  options, // Pass the options for the request
97
137
  (res) => {
98
138
  // Handle the response from the server
99
- // Initialize a variable to accumulate response data
100
- let responseData = '';
139
+ // Accumulate response chunks in an array for efficient memory usage
140
+ const chunks = [];
101
141
  // Listen for 'data' events to receive chunks of data from the response
102
142
  res.on('data', (chunk) => {
103
- responseData += chunk;
143
+ chunks.push(buffer_1.Buffer.isBuffer(chunk) ? chunk : buffer_1.Buffer.from(chunk));
104
144
  });
105
145
  // Listen for the 'end' event to know when the response has been fully received
106
146
  res.on('end', () => {
107
147
  try {
108
- // Attempt to parse the accumulated response data as JSON and resolve the promise with it
148
+ // Concatenate all chunks efficiently and parse as JSON
149
+ const responseData = buffer_1.Buffer.concat(chunks).toString('utf8');
109
150
  resolve(JSON.parse(responseData));
110
151
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
111
152
  }
112
153
  catch (error) {
113
154
  // If parsing fails, resolve the promise with the raw response data
155
+ const responseData = buffer_1.Buffer.concat(chunks).toString('utf8');
114
156
  resolve(responseData);
115
157
  }
116
158
  });
@@ -130,8 +172,8 @@ class AsyncModules extends syncModules_1.default {
130
172
  /**
131
173
  * Performs an HTTP PUT request.
132
174
  * @param {string} path - The path to append to the base URL.
133
- * @param {any} body - The data to send in the request body.
134
- * @returns {Promise<any>} A promise resolving to the response data.
175
+ * @param {unknown} body - The data to send in the request body.
176
+ * @returns {Promise<T>} A promise resolving to the response data.
135
177
  * @description Define a protected asynchronous method '_fetchPut' that performs a PUT request
136
178
  */
137
179
  async _fetchPut(path, body) {
@@ -184,8 +226,8 @@ class AsyncModules extends syncModules_1.default {
184
226
  /**
185
227
  * Performs an HTTP DELETE request.
186
228
  * @param {string} path - The path to append to the base URL.
187
- * @param {any} body - The body of the request.
188
- * @returns {Promise<any>} A promise resolving to the response data.
229
+ * @param {unknown} body - The body of the request.
230
+ * @returns {Promise<T>} A promise resolving to the response data.
189
231
  * @description Define a protected asynchronous method '_fetchDelete' that performs a DELETE request
190
232
  */
191
233
  async _fetchDelete(path, body) {
@@ -283,8 +325,8 @@ class AsyncModules extends syncModules_1.default {
283
325
  /**
284
326
  * Creates options for HTTP requests.
285
327
  * @param {string} method - The HTTP method (GET, POST, PUT, DELETE, etc.).
286
- * @param {any} data - Optional data to include in the request body.
287
- * @returns {any} An object representing the request options.
328
+ * @param {unknown} data - Optional data to include in the request body.
329
+ * @returns {IHttpOptions} An object representing the request options.
288
330
  */
289
331
  makeOptions(method, data) {
290
332
  const options = {
@@ -328,8 +370,8 @@ class AsyncModules extends syncModules_1.default {
328
370
  /**
329
371
  * Handles responses from the browser's fetch API.
330
372
  * @param {string} path - The path to append to the base URL.
331
- * @param {any} options - The options for the fetch request.
332
- * @returns {any} A promise resolving to the response data.
373
+ * @param {IHttpOptions} options - The options for the fetch request.
374
+ * @returns {Promise<T>} A promise resolving to the response data.
333
375
  * @description Define an asynchronous method 'browserResponse' that takes a path and options as parameters
334
376
  */
335
377
  async browserResponse(path, options) {
@@ -342,7 +384,7 @@ class AsyncModules extends syncModules_1.default {
342
384
  // Attempt to read the response body as text
343
385
  const text = await response.text();
344
386
  // If the response body is not empty, parse it as JSON; otherwise, return an empty object
345
- return text ? JSON.parse(text) : {};
387
+ return (text ? JSON.parse(text) : {});
346
388
  // Alternatively, you could directly return the parsed JSON with 'await response.json()'
347
389
  }
348
390
  catch (e) {
@@ -353,7 +395,7 @@ class AsyncModules extends syncModules_1.default {
353
395
  else {
354
396
  // Handle non-OK responses
355
397
  // Check if the status is 401 (Unauthorized) and custom authentication is not used
356
- if (response.status == 401 && !this.state.customAuth) {
398
+ if (response.status === 401 && !this.state.customAuth) {
357
399
  // Attempt to refresh the access token
358
400
  const refresh = await this.refreshToken();
359
401
  if (refresh) {
@@ -363,38 +405,63 @@ class AsyncModules extends syncModules_1.default {
363
405
  // Retry the fetch request with updated headers
364
406
  const secondResponse = await fetch(this._getFullPath(path), options);
365
407
  // Return the JSON-parsed response of the retry request
366
- return await secondResponse.json();
408
+ return (await secondResponse.json());
367
409
  }
368
410
  }
369
411
  // Store the response status and parse the response body as JSON
370
412
  const status = response.status;
371
413
  const res = await response.json();
372
414
  // Handle different HTTP status codes with corresponding error functions
373
- if (status == 400) {
415
+ // Using strict equality (===) for type safety
416
+ if (status === 400) {
374
417
  if (this.state.errorsFunctions && this.state.errorsFunctions['400']) {
375
418
  this.state.errorsFunctions['400'](res);
376
419
  }
377
420
  }
378
- else if (status == 401) {
421
+ else if (status === 401) {
379
422
  if (this.state.errorsFunctions && this.state.errorsFunctions['401']) {
380
423
  this.state.errorsFunctions['401'](res);
381
424
  }
382
425
  }
383
- else if (status == 403) {
426
+ else if (status === 403) {
384
427
  if (this.state.errorsFunctions && this.state.errorsFunctions['403']) {
385
428
  this.state.errorsFunctions['403'](res);
386
429
  }
387
430
  }
388
- else if (status == 404) {
431
+ else if (status === 404) {
389
432
  if (this.state.errorsFunctions && this.state.errorsFunctions['404']) {
390
433
  this.state.errorsFunctions['404'](res);
391
434
  }
392
435
  }
393
- else if (status == 500) {
436
+ else if (status === 429) {
437
+ // Handle rate limiting
438
+ if (this.state.errorsFunctions && this.state.errorsFunctions['429']) {
439
+ this.state.errorsFunctions['429'](res);
440
+ }
441
+ }
442
+ else if (status === 500) {
394
443
  if (this.state.errorsFunctions && this.state.errorsFunctions['500']) {
395
444
  this.state.errorsFunctions['500'](res);
396
445
  }
397
446
  }
447
+ else if (status === 502) {
448
+ // Handle bad gateway
449
+ if (this.state.errorsFunctions && this.state.errorsFunctions['502']) {
450
+ this.state.errorsFunctions['502'](res);
451
+ }
452
+ }
453
+ else if (status === 503) {
454
+ // Handle service unavailable
455
+ if (this.state.errorsFunctions && this.state.errorsFunctions['503']) {
456
+ this.state.errorsFunctions['503'](res);
457
+ }
458
+ }
459
+ else if (status === 504) {
460
+ // Handle gateway timeout
461
+ if (this.state.errorsFunctions && this.state.errorsFunctions['504']) {
462
+ this.state.errorsFunctions['504'](res);
463
+ }
464
+ }
398
465
  // Determine whether to return or throw the response based on 'isShell' state
399
466
  if (this.state.isShell) {
400
467
  return res;
@@ -15,12 +15,19 @@ export default class StateModule {
15
15
  _NO_FETCH: boolean;
16
16
  _https: any;
17
17
  isShell: boolean;
18
+ validationEnabled: boolean;
19
+ validationStrictMode: boolean;
20
+ validationLogErrors: boolean;
18
21
  errorsFunctions: {
19
22
  400?: (data: IError) => any | null;
20
23
  401?: (data: IError) => any | null;
21
24
  403?: (data: IError) => any | null;
22
25
  404?: (data: IError) => any | null;
26
+ 429?: (data: IError) => any | null;
23
27
  500?: (data: IError) => any | null;
28
+ 502?: (data: IError) => any | null;
29
+ 503?: (data: IError) => any | null;
30
+ 504?: (data: IError) => any | null;
24
31
  };
25
32
  saveFunction: (param: string) => void | null;
26
33
  /**
@@ -45,35 +45,50 @@ class StateModule {
45
45
  * @description Constructor for StateModule.
46
46
  */
47
47
  constructor(url, config) {
48
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
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;
49
49
  this.url = url;
50
50
  this.lang = (_a = config.langCode) !== null && _a !== void 0 ? _a : 'en_US';
51
51
  this.token = config.token;
52
52
  this.traficLimit = config.traficLimit || false;
53
- this.refreshToken = (_c = (_b = config.auth) === null || _b === void 0 ? void 0 : _b.refreshToken) !== null && _c !== void 0 ? _c : undefined;
54
- this.providerMarker = (_e = (_d = config.auth) === null || _d === void 0 ? void 0 : _d.providerMarker) !== null && _e !== void 0 ? _e : 'email';
55
- this.customAuth = (_g = (_f = config.auth) === null || _f === void 0 ? void 0 : _f.customAuth) !== null && _g !== void 0 ? _g : false;
53
+ this.validationEnabled = (_c = (_b = config.validation) === null || _b === void 0 ? void 0 : _b.enabled) !== null && _c !== void 0 ? _c : false;
54
+ this.validationStrictMode = (_e = (_d = config.validation) === null || _d === void 0 ? void 0 : _d.strictMode) !== null && _e !== void 0 ? _e : false;
55
+ this.validationLogErrors = (_g = (_f = config.validation) === null || _f === void 0 ? void 0 : _f.logErrors) !== null && _g !== void 0 ? _g : true;
56
+ this.refreshToken = (_j = (_h = config.auth) === null || _h === void 0 ? void 0 : _h.refreshToken) !== null && _j !== void 0 ? _j : undefined;
57
+ this.providerMarker = (_l = (_k = config.auth) === null || _k === void 0 ? void 0 : _k.providerMarker) !== null && _l !== void 0 ? _l : 'email';
58
+ this.customAuth = (_o = (_m = config.auth) === null || _m === void 0 ? void 0 : _m.customAuth) !== null && _o !== void 0 ? _o : false;
56
59
  this.errorsFunctions = {
57
60
  '400': undefined,
58
61
  '401': undefined,
59
62
  '403': undefined,
60
63
  '404': undefined,
64
+ '429': undefined,
61
65
  '500': undefined,
66
+ '502': undefined,
67
+ '503': undefined,
68
+ '504': undefined,
62
69
  };
63
- this.saveFunction = (_j = (_h = config.auth) === null || _h === void 0 ? void 0 : _h.saveFunction) !== null && _j !== void 0 ? _j : null;
70
+ this.saveFunction = (_q = (_p = config.auth) === null || _p === void 0 ? void 0 : _p.saveFunction) !== null && _q !== void 0 ? _q : null;
64
71
  if (config.errors) {
65
- this.isShell = (_k = config.errors.isShell) !== null && _k !== void 0 ? _k : true;
72
+ this.isShell = (_r = config.errors.isShell) !== null && _r !== void 0 ? _r : true;
66
73
  if (config.errors.customErrors) {
67
74
  this.errorsFunctions['400'] =
68
- (_l = config.errors.customErrors['400']) !== null && _l !== void 0 ? _l : undefined;
75
+ (_s = config.errors.customErrors['400']) !== null && _s !== void 0 ? _s : undefined;
69
76
  this.errorsFunctions['401'] =
70
- (_m = config.errors.customErrors['401']) !== null && _m !== void 0 ? _m : undefined;
77
+ (_t = config.errors.customErrors['401']) !== null && _t !== void 0 ? _t : undefined;
71
78
  this.errorsFunctions['403'] =
72
- (_o = config.errors.customErrors['403']) !== null && _o !== void 0 ? _o : undefined;
79
+ (_u = config.errors.customErrors['403']) !== null && _u !== void 0 ? _u : undefined;
73
80
  this.errorsFunctions['404'] =
74
- (_p = config.errors.customErrors['404']) !== null && _p !== void 0 ? _p : undefined;
81
+ (_v = config.errors.customErrors['404']) !== null && _v !== void 0 ? _v : undefined;
82
+ this.errorsFunctions['429'] =
83
+ (_w = config.errors.customErrors['429']) !== null && _w !== void 0 ? _w : undefined;
75
84
  this.errorsFunctions['500'] =
76
- (_q = config.errors.customErrors['400']) !== null && _q !== void 0 ? _q : undefined;
85
+ (_x = config.errors.customErrors['500']) !== null && _x !== void 0 ? _x : undefined;
86
+ this.errorsFunctions['502'] =
87
+ (_y = config.errors.customErrors['502']) !== null && _y !== void 0 ? _y : undefined;
88
+ this.errorsFunctions['503'] =
89
+ (_z = config.errors.customErrors['503']) !== null && _z !== void 0 ? _z : undefined;
90
+ this.errorsFunctions['504'] =
91
+ (_0 = config.errors.customErrors['504']) !== null && _0 !== void 0 ? _0 : undefined;
77
92
  }
78
93
  }
79
94
  else {
@@ -58,6 +58,18 @@ export default abstract class SyncModules {
58
58
  * @returns {any} The new date with added days.
59
59
  */
60
60
  protected _addDays(date: Date, days: number): any;
61
+ /**
62
+ * Common logic for processing schedule dates (weekly, monthly, or both).
63
+ * @param {Date} date - The date for which to process intervals.
64
+ * @param {object} config - Configuration for schedule repetition.
65
+ * @param {boolean} config.inEveryWeek - Whether to repeat weekly.
66
+ * @param {boolean} config.inEveryMonth - Whether to repeat monthly.
67
+ * @param {Function} processDate - Callback function to process each date.
68
+ */
69
+ protected _processScheduleDates(date: Date, config: {
70
+ inEveryWeek: boolean;
71
+ inEveryMonth: boolean;
72
+ }, processDate: (currentDate: Date) => void): void;
61
73
  /**
62
74
  * Generates intervals for a specific date based on a schedule.
63
75
  * @param {Date} date - The date for which to generate intervals.