oneentry 1.0.141 → 1.0.142
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/configure.js +107 -15
- package/package.json +81 -3
- package/dist/admins/adminsApi.d.ts +0 -50
- package/dist/admins/adminsApi.js +0 -65
- package/dist/admins/adminsInterfaces.d.ts +0 -99
- package/dist/admins/adminsInterfaces.js +0 -2
- package/dist/admins/adminsSchemas.d.ts +0 -30
- package/dist/admins/adminsSchemas.js +0 -27
- package/dist/attribute-sets/attributeSetsApi.d.ts +0 -63
- package/dist/attribute-sets/attributeSetsApi.js +0 -98
- package/dist/attribute-sets/attributeSetsInterfaces.d.ts +0 -187
- package/dist/attribute-sets/attributeSetsInterfaces.js +0 -2
- package/dist/attribute-sets/attributeSetsSchemas.d.ts +0 -90
- package/dist/attribute-sets/attributeSetsSchemas.js +0 -74
- package/dist/auth-provider/authProviderApi.d.ts +0 -249
- package/dist/auth-provider/authProviderApi.js +0 -351
- package/dist/auth-provider/authProviderSchemas.d.ts +0 -131
- package/dist/auth-provider/authProviderSchemas.js +0 -82
- package/dist/auth-provider/authProvidersInterfaces.d.ts +0 -425
- package/dist/auth-provider/authProvidersInterfaces.js +0 -2
- package/dist/base/asyncModules.d.ts +0 -80
- package/dist/base/asyncModules.js +0 -440
- package/dist/base/result.d.ts +0 -39
- package/dist/base/result.js +0 -154
- package/dist/base/stateModule.d.ts +0 -41
- package/dist/base/stateModule.js +0 -128
- package/dist/base/syncModules.d.ts +0 -149
- package/dist/base/syncModules.js +0 -549
- package/dist/base/utils.d.ts +0 -197
- package/dist/base/utils.js +0 -2
- package/dist/base/validation.d.ts +0 -118
- package/dist/base/validation.js +0 -132
- package/dist/blocks/blocksApi.d.ts +0 -76
- package/dist/blocks/blocksApi.js +0 -188
- package/dist/blocks/blocksInterfaces.d.ts +0 -173
- package/dist/blocks/blocksInterfaces.js +0 -2
- package/dist/blocks/blocksSchemas.d.ts +0 -187
- package/dist/blocks/blocksSchemas.js +0 -43
- package/dist/discounts/discountsApi.d.ts +0 -56
- package/dist/discounts/discountsApi.js +0 -82
- package/dist/discounts/discountsInterfaces.d.ts +0 -145
- package/dist/discounts/discountsInterfaces.js +0 -2
- package/dist/events/eventsApi.d.ts +0 -60
- package/dist/events/eventsApi.js +0 -97
- package/dist/events/eventsInterfaces.d.ts +0 -87
- package/dist/events/eventsInterfaces.js +0 -2
- package/dist/file-uploading/fileUploadingApi.d.ts +0 -88
- package/dist/file-uploading/fileUploadingApi.js +0 -132
- package/dist/file-uploading/fileUploadingInterfaces.d.ts +0 -117
- package/dist/file-uploading/fileUploadingInterfaces.js +0 -2
- package/dist/file-uploading/fileUploadingSchemas.d.ts +0 -22
- package/dist/file-uploading/fileUploadingSchemas.js +0 -21
- package/dist/forms/formsApi.d.ts +0 -42
- package/dist/forms/formsApi.js +0 -57
- package/dist/forms/formsInterfaces.d.ts +0 -132
- package/dist/forms/formsInterfaces.js +0 -2
- package/dist/forms/formsSchemas.d.ts +0 -50
- package/dist/forms/formsSchemas.js +0 -31
- package/dist/forms-data/formsDataApi.d.ts +0 -106
- package/dist/forms-data/formsDataApi.js +0 -189
- package/dist/forms-data/formsDataInterfaces.d.ts +0 -525
- package/dist/forms-data/formsDataInterfaces.js +0 -2
- package/dist/forms-data/formsDataSchemas.d.ts +0 -115
- package/dist/forms-data/formsDataSchemas.js +0 -86
- package/dist/general-types/generalTypesApi.d.ts +0 -28
- package/dist/general-types/generalTypesApi.js +0 -38
- package/dist/general-types/generalTypesInterfaces.d.ts +0 -30
- package/dist/general-types/generalTypesInterfaces.js +0 -2
- package/dist/general-types/generalTypesSchemas.d.ts +0 -50
- package/dist/general-types/generalTypesSchemas.js +0 -35
- package/dist/index.d.ts +0 -100
- package/dist/index.js +0 -103
- package/dist/integration-collections/integrationCollectionsApi.d.ts +0 -173
- package/dist/integration-collections/integrationCollectionsApi.js +0 -220
- package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +0 -313
- package/dist/integration-collections/integrationCollectionsInterfaces.js +0 -2
- package/dist/integration-collections/integrationCollectionsSchemas.d.ts +0 -80
- package/dist/integration-collections/integrationCollectionsSchemas.js +0 -61
- package/dist/locales/localesApi.d.ts +0 -27
- package/dist/locales/localesApi.js +0 -37
- package/dist/locales/localesInterfaces.d.ts +0 -41
- package/dist/locales/localesInterfaces.js +0 -2
- package/dist/locales/localesSchemas.d.ts +0 -32
- package/dist/locales/localesSchemas.js +0 -26
- package/dist/menus/menusApi.d.ts +0 -29
- package/dist/menus/menusApi.js +0 -39
- package/dist/menus/menusInterfaces.d.ts +0 -88
- package/dist/menus/menusInterfaces.js +0 -4
- package/dist/menus/menusSchemas.d.ts +0 -16
- package/dist/menus/menusSchemas.js +0 -28
- package/dist/orders/ordersApi.d.ts +0 -149
- package/dist/orders/ordersApi.js +0 -203
- package/dist/orders/ordersInterfaces.d.ts +0 -527
- package/dist/orders/ordersInterfaces.js +0 -2
- package/dist/orders/ordersSchemas.d.ts +0 -120
- package/dist/orders/ordersSchemas.js +0 -101
- package/dist/pages/pagesApi.d.ts +0 -151
- package/dist/pages/pagesApi.js +0 -390
- package/dist/pages/pagesInterfaces.d.ts +0 -292
- package/dist/pages/pagesInterfaces.js +0 -2
- package/dist/pages/pagesSchemas.d.ts +0 -85
- package/dist/pages/pagesSchemas.js +0 -46
- package/dist/payments/paymentsApi.d.ts +0 -82
- package/dist/payments/paymentsApi.js +0 -121
- package/dist/payments/paymentsInterfaces.d.ts +0 -206
- package/dist/payments/paymentsInterfaces.js +0 -2
- package/dist/payments/paymentsSchemas.d.ts +0 -100
- package/dist/payments/paymentsSchemas.js +0 -65
- package/dist/product-statuses/productStatusesApi.d.ts +0 -47
- package/dist/product-statuses/productStatusesApi.js +0 -70
- package/dist/product-statuses/productStatusesInterfaces.d.ts +0 -66
- package/dist/product-statuses/productStatusesInterfaces.js +0 -2
- package/dist/product-statuses/productStatusesSchemas.d.ts +0 -34
- package/dist/product-statuses/productStatusesSchemas.js +0 -30
- package/dist/products/productsApi.d.ts +0 -365
- package/dist/products/productsApi.js +0 -459
- package/dist/products/productsInterfaces.d.ts +0 -586
- package/dist/products/productsInterfaces.js +0 -2
- package/dist/products/productsSchemas.d.ts +0 -192
- package/dist/products/productsSchemas.js +0 -96
- package/dist/sitemap/sitemapApi.d.ts +0 -35
- package/dist/sitemap/sitemapApi.js +0 -45
- package/dist/sitemap/sitemapInterfaces.d.ts +0 -40
- package/dist/sitemap/sitemapInterfaces.js +0 -2
- package/dist/system/systemApi.d.ts +0 -43
- package/dist/system/systemApi.js +0 -58
- package/dist/system/systemInterfaces.d.ts +0 -31
- package/dist/system/systemInterfaces.js +0 -5
- package/dist/templates/templatesApi.d.ts +0 -49
- package/dist/templates/templatesApi.js +0 -75
- package/dist/templates/templatesInterfaces.d.ts +0 -70
- package/dist/templates/templatesInterfaces.js +0 -2
- package/dist/templates/templatesSchemas.d.ts +0 -48
- package/dist/templates/templatesSchemas.js +0 -31
- package/dist/templates-preview/templatesPreviewApi.d.ts +0 -38
- package/dist/templates-preview/templatesPreviewApi.js +0 -53
- package/dist/templates-preview/templatesPreviewInterfaces.d.ts +0 -121
- package/dist/templates-preview/templatesPreviewInterfaces.js +0 -2
- package/dist/templates-preview/templatesPreviewSchemas.d.ts +0 -83
- package/dist/templates-preview/templatesPreviewSchemas.js +0 -48
- package/dist/users/usersApi.d.ts +0 -143
- package/dist/users/usersApi.js +0 -173
- package/dist/users/usersInterfaces.d.ts +0 -235
- package/dist/users/usersInterfaces.js +0 -2
- package/dist/users/usersSchemas.d.ts +0 -38
- package/dist/users/usersSchemas.js +0 -28
- package/dist/web-socket/wsApi.d.ts +0 -25
- package/dist/web-socket/wsApi.js +0 -45
- package/dist/web-socket/wsInterfaces.d.ts +0 -17
- package/dist/web-socket/wsInterfaces.js +0 -2
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
import type StateModule from './stateModule';
|
|
3
|
-
import SyncModules from './syncModules';
|
|
4
|
-
import type { IError } from './utils';
|
|
5
|
-
/**
|
|
6
|
-
* Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
|
|
7
|
-
* @description Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
|
|
8
|
-
*/
|
|
9
|
-
export default abstract class AsyncModules extends SyncModules {
|
|
10
|
-
protected state: StateModule;
|
|
11
|
-
protected _NO_FETCH: boolean;
|
|
12
|
-
protected _https: any;
|
|
13
|
-
protected _url: string;
|
|
14
|
-
/**
|
|
15
|
-
* Constructor initializes the AsyncModules with a given state.
|
|
16
|
-
* @param {StateModule} state - Instance of StateModule containing configuration and state data.
|
|
17
|
-
* @description Constructor initializes the AsyncModules with a given state.
|
|
18
|
-
*/
|
|
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;
|
|
28
|
-
/**
|
|
29
|
-
* Performs an HTTP GET request.
|
|
30
|
-
* @param {string} path - The path to append to the base URL.
|
|
31
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
32
|
-
* @description Define a protected asynchronous method '_fetchGet' that performs a GET request
|
|
33
|
-
*/
|
|
34
|
-
protected _fetchGet<T = unknown>(path: string): Promise<T>;
|
|
35
|
-
/**
|
|
36
|
-
* Performs an HTTP POST request.
|
|
37
|
-
* @param {string} path - The path to append to the base URL.
|
|
38
|
-
* @param {unknown} [data] - The data to send in the request body.
|
|
39
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
40
|
-
* @description Define a protected asynchronous method '_fetchPost' that performs a POST request
|
|
41
|
-
*/
|
|
42
|
-
protected _fetchPost<T = unknown>(path: string, data?: unknown): Promise<T>;
|
|
43
|
-
/**
|
|
44
|
-
* Performs an HTTP PUT request.
|
|
45
|
-
* @param {string} path - The path to append to the base URL.
|
|
46
|
-
* @param {unknown} body - The data to send in the request body.
|
|
47
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
48
|
-
* @description Define a protected asynchronous method '_fetchPut' that performs a PUT request
|
|
49
|
-
*/
|
|
50
|
-
protected _fetchPut<T = unknown>(path: string, body: unknown): Promise<T>;
|
|
51
|
-
/**
|
|
52
|
-
* Performs an HTTP DELETE request.
|
|
53
|
-
* @param {string} path - The path to append to the base URL.
|
|
54
|
-
* @param {unknown} body - The body of the request.
|
|
55
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
56
|
-
* @description Define a protected asynchronous method '_fetchDelete' that performs a DELETE request
|
|
57
|
-
*/
|
|
58
|
-
protected _fetchDelete<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
59
|
-
/**
|
|
60
|
-
* Refreshes the authentication token.
|
|
61
|
-
* @returns {Promise<boolean>} A promise resolving to a boolean indicating success or failure.
|
|
62
|
-
* @description Define an asynchronous method 'refreshToken' that attempts to refresh the authentication token
|
|
63
|
-
*/
|
|
64
|
-
protected refreshToken(): Promise<boolean>;
|
|
65
|
-
/**
|
|
66
|
-
* Creates options for HTTP requests.
|
|
67
|
-
* @param {string} method - The HTTP method (GET, POST, PUT, DELETE, etc.).
|
|
68
|
-
* @param {unknown} data - Optional data to include in the request body.
|
|
69
|
-
* @returns {IHttpOptions} An object representing the request options.
|
|
70
|
-
*/
|
|
71
|
-
private makeOptions;
|
|
72
|
-
/**
|
|
73
|
-
* Handles responses from the browser's fetch API.
|
|
74
|
-
* @param {string} path - The path to append to the base URL.
|
|
75
|
-
* @param {IHttpOptions} options - The options for the fetch request.
|
|
76
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
77
|
-
* @description Define an asynchronous method 'browserResponse' that takes a path and options as parameters
|
|
78
|
-
*/
|
|
79
|
-
private browserResponse;
|
|
80
|
-
}
|
|
@@ -1,440 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
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
|
-
const syncModules_1 = __importDefault(require("./syncModules"));
|
|
10
|
-
const validation_1 = require("./validation");
|
|
11
|
-
/**
|
|
12
|
-
* Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
|
|
13
|
-
* @description Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
|
|
14
|
-
*/
|
|
15
|
-
class AsyncModules extends syncModules_1.default {
|
|
16
|
-
/**
|
|
17
|
-
* Constructor initializes the AsyncModules with a given state.
|
|
18
|
-
* @param {StateModule} state - Instance of StateModule containing configuration and state data.
|
|
19
|
-
* @description Constructor initializes the AsyncModules with a given state.
|
|
20
|
-
*/
|
|
21
|
-
constructor(state) {
|
|
22
|
-
var _a;
|
|
23
|
-
super(state);
|
|
24
|
-
this.state = state;
|
|
25
|
-
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
|
-
}
|
|
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
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Performs an HTTP GET request.
|
|
68
|
-
* @param {string} path - The path to append to the base URL.
|
|
69
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
70
|
-
* @description Define a protected asynchronous method '_fetchGet' that performs a GET request
|
|
71
|
-
*/
|
|
72
|
-
async _fetchGet(path) {
|
|
73
|
-
// Create options for the GET request using the 'makeOptions' method
|
|
74
|
-
const options = this.makeOptions('GET');
|
|
75
|
-
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
76
|
-
if (!this._NO_FETCH) {
|
|
77
|
-
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
78
|
-
return await this.browserResponse(path, options);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
82
|
-
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
83
|
-
return new Promise((resolve, reject) => {
|
|
84
|
-
// Use the HTTPS module to send a GET request to the specified path with the given options
|
|
85
|
-
const req = this._https.get(this._getFullPath(path), // Get the full URL path for the request
|
|
86
|
-
options, // Pass the options for the request
|
|
87
|
-
(res) => {
|
|
88
|
-
// Handle the response from the server
|
|
89
|
-
let responseData = ''; // Initialize a variable to accumulate response data
|
|
90
|
-
// Listen for 'data' events to receive chunks of data from the response
|
|
91
|
-
res.on('data', (chunk) => {
|
|
92
|
-
responseData += chunk; // Append each chunk to the accumulated response data
|
|
93
|
-
});
|
|
94
|
-
// Listen for the 'end' event to know when the response has been fully received
|
|
95
|
-
res.on('end', () => {
|
|
96
|
-
try {
|
|
97
|
-
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
98
|
-
resolve(JSON.parse(responseData));
|
|
99
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
// If parsing fails, resolve the promise with the raw response data
|
|
103
|
-
resolve(responseData);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
// Listen for 'error' events on the request to handle any errors that occur
|
|
108
|
-
req.on('error', (error) => {
|
|
109
|
-
// Reject the promise with the error
|
|
110
|
-
reject(error);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Performs an HTTP POST request.
|
|
117
|
-
* @param {string} path - The path to append to the base URL.
|
|
118
|
-
* @param {unknown} [data] - The data to send in the request body.
|
|
119
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
120
|
-
* @description Define a protected asynchronous method '_fetchPost' that performs a POST request
|
|
121
|
-
*/
|
|
122
|
-
async _fetchPost(path, data) {
|
|
123
|
-
// Create options for the POST request using the 'makeOptions' method, including the data to be sent
|
|
124
|
-
const options = this.makeOptions('POST', data);
|
|
125
|
-
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
126
|
-
if (!this._NO_FETCH) {
|
|
127
|
-
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
128
|
-
return await this.browserResponse(path, options);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
132
|
-
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
133
|
-
return new Promise((resolve, reject) => {
|
|
134
|
-
// Use the HTTPS module to send a POST request to the specified path with the given options
|
|
135
|
-
const req = this._https.request(this._getFullPath(path), // Get the full URL path for the request
|
|
136
|
-
options, // Pass the options for the request
|
|
137
|
-
(res) => {
|
|
138
|
-
// Handle the response from the server
|
|
139
|
-
// Accumulate response chunks in an array for efficient memory usage
|
|
140
|
-
const chunks = [];
|
|
141
|
-
// Listen for 'data' events to receive chunks of data from the response
|
|
142
|
-
res.on('data', (chunk) => {
|
|
143
|
-
chunks.push(buffer_1.Buffer.isBuffer(chunk) ? chunk : buffer_1.Buffer.from(chunk));
|
|
144
|
-
});
|
|
145
|
-
// Listen for the 'end' event to know when the response has been fully received
|
|
146
|
-
res.on('end', () => {
|
|
147
|
-
try {
|
|
148
|
-
// Concatenate all chunks efficiently and parse as JSON
|
|
149
|
-
const responseData = buffer_1.Buffer.concat(chunks).toString('utf8');
|
|
150
|
-
resolve(JSON.parse(responseData));
|
|
151
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
// If parsing fails, resolve the promise with the raw response data
|
|
155
|
-
const responseData = buffer_1.Buffer.concat(chunks).toString('utf8');
|
|
156
|
-
resolve(responseData);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
// Listen for 'error' events on the request to handle any errors that occur
|
|
161
|
-
req.on('error', (error) => {
|
|
162
|
-
// Reject the promise with the error
|
|
163
|
-
reject(error);
|
|
164
|
-
});
|
|
165
|
-
// Write the provided data to the request body in JSON format
|
|
166
|
-
req.write(JSON.stringify(data));
|
|
167
|
-
// End the request to signal that all data has been sent
|
|
168
|
-
req.end();
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Performs an HTTP PUT request.
|
|
174
|
-
* @param {string} path - The path to append to the base URL.
|
|
175
|
-
* @param {unknown} body - The data to send in the request body.
|
|
176
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
177
|
-
* @description Define a protected asynchronous method '_fetchPut' that performs a PUT request
|
|
178
|
-
*/
|
|
179
|
-
async _fetchPut(path, body) {
|
|
180
|
-
// Create options for the PUT request using the 'makeOptions' method, including the data to be sent
|
|
181
|
-
const options = this.makeOptions('PUT', body);
|
|
182
|
-
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
183
|
-
if (!this._NO_FETCH) {
|
|
184
|
-
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
185
|
-
return await this.browserResponse(path, options);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
189
|
-
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
190
|
-
return new Promise((resolve, reject) => {
|
|
191
|
-
// Use the HTTPS module to send a PUT request to the specified path with the given options
|
|
192
|
-
const req = this._https.request(this._getFullPath(path), // Get the full URL path for the request
|
|
193
|
-
options, // Pass the options for the request
|
|
194
|
-
(res) => {
|
|
195
|
-
// Handle the response from the server
|
|
196
|
-
let responseData = ''; // Initialize a variable to accumulate response data
|
|
197
|
-
// Listen for 'data' events to receive chunks of data from the response
|
|
198
|
-
res.on('data', (chunk) => {
|
|
199
|
-
responseData += chunk; // Append each chunk to the accumulated response data
|
|
200
|
-
});
|
|
201
|
-
// Listen for the 'end' event to know when the response has been fully received
|
|
202
|
-
res.on('end', () => {
|
|
203
|
-
try {
|
|
204
|
-
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
205
|
-
resolve(JSON.parse(responseData));
|
|
206
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
// If parsing fails, resolve the promise with the raw response data
|
|
210
|
-
resolve(responseData);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
// Listen for 'error' events on the request to handle any errors that occur
|
|
215
|
-
req.on('error', (error) => {
|
|
216
|
-
// Reject the promise with the error
|
|
217
|
-
reject(error);
|
|
218
|
-
});
|
|
219
|
-
// Write the provided data to the request body in JSON format
|
|
220
|
-
req.write(JSON.stringify(body));
|
|
221
|
-
// End the request to signal that all data has been sent
|
|
222
|
-
req.end();
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Performs an HTTP DELETE request.
|
|
228
|
-
* @param {string} path - The path to append to the base URL.
|
|
229
|
-
* @param {unknown} body - The body of the request.
|
|
230
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
231
|
-
* @description Define a protected asynchronous method '_fetchDelete' that performs a DELETE request
|
|
232
|
-
*/
|
|
233
|
-
async _fetchDelete(path, body) {
|
|
234
|
-
// Create options for the DELETE request using the 'makeOptions' method
|
|
235
|
-
const options = this.makeOptions('DELETE', body);
|
|
236
|
-
// Check if the fetch operation should be performed using the Fetch API or an alternative method
|
|
237
|
-
if (!this._NO_FETCH) {
|
|
238
|
-
// If Fetch API is allowed, use 'browserResponse' to perform the request and return the result
|
|
239
|
-
return await this.browserResponse(path, options);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
// If Fetch API is not allowed, perform the request using Node.js HTTPS module
|
|
243
|
-
// Return a new promise to handle the asynchronous nature of the HTTPS request
|
|
244
|
-
return new Promise((resolve, reject) => {
|
|
245
|
-
// Use the HTTPS module to send a DELETE request to the specified path with the given options
|
|
246
|
-
const req = this._https.delete(this._getFullPath(path), // Get the full URL path for the request
|
|
247
|
-
options, // Pass the options for the request
|
|
248
|
-
(res) => {
|
|
249
|
-
// Handle the response from the server
|
|
250
|
-
let responseData = ''; // Initialize a variable to accumulate response data
|
|
251
|
-
// Listen for 'data' events to receive chunks of data from the response
|
|
252
|
-
res.on('data', (chunk) => {
|
|
253
|
-
responseData += chunk; // Append each chunk to the accumulated response data
|
|
254
|
-
});
|
|
255
|
-
// Listen for the 'end' event to know when the response has been fully received
|
|
256
|
-
res.on('end', () => {
|
|
257
|
-
try {
|
|
258
|
-
// Attempt to parse the accumulated response data as JSON and resolve the promise with it
|
|
259
|
-
resolve(JSON.parse(responseData));
|
|
260
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
// If parsing fails, resolve the promise with the raw response data
|
|
264
|
-
resolve(responseData);
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
// Listen for 'error' events on the request to handle any errors that occur
|
|
269
|
-
req.on('error', (error) => {
|
|
270
|
-
// Reject the promise with the error
|
|
271
|
-
reject(error);
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Refreshes the authentication token.
|
|
278
|
-
* @returns {Promise<boolean>} A promise resolving to a boolean indicating success or failure.
|
|
279
|
-
* @description Define an asynchronous method 'refreshToken' that attempts to refresh the authentication token
|
|
280
|
-
*/
|
|
281
|
-
async refreshToken() {
|
|
282
|
-
const url = this.state.url +
|
|
283
|
-
`/api/content/users-auth-providers/marker/` +
|
|
284
|
-
this.state.providerMarker +
|
|
285
|
-
`/users/refresh`;
|
|
286
|
-
/**
|
|
287
|
-
* Perform a fetch request to the specified URL to refresh the token
|
|
288
|
-
* @param {string} url - The URL to which the request will be sent
|
|
289
|
-
* @param {object} options - The options for the fetch request
|
|
290
|
-
* @param {string} options.method - The HTTP method to use for the request (default: 'POST')
|
|
291
|
-
* @param {object} options.headers - Set the necessary headers for the request
|
|
292
|
-
* @param {object} options.body - Send the current refresh token in the request body as a JSON string
|
|
293
|
-
*/
|
|
294
|
-
const response = await fetch(url, {
|
|
295
|
-
method: 'POST',
|
|
296
|
-
headers: {
|
|
297
|
-
// Indicate that the request body is in JSON format
|
|
298
|
-
'Content-Type': 'application/json',
|
|
299
|
-
// Include the application token from the state
|
|
300
|
-
'x-app-token': this.state.token,
|
|
301
|
-
// Include the device fingerprint
|
|
302
|
-
'x-device-metadata': this._getDeviceMetadata(),
|
|
303
|
-
},
|
|
304
|
-
body: JSON.stringify({ refreshToken: this.state.refreshToken }),
|
|
305
|
-
});
|
|
306
|
-
// Check if the response status is OK (status code 200-299)
|
|
307
|
-
if (response.ok) {
|
|
308
|
-
// Parse the response body as JSON and store the result
|
|
309
|
-
const result = await response.json();
|
|
310
|
-
// Update the state's refreshToken and accessToken with the new tokens from the response
|
|
311
|
-
this.state.refreshToken = result.refreshToken;
|
|
312
|
-
this.state.accessToken = result.accessToken;
|
|
313
|
-
// If a save function is defined in the state, call it with the new refresh token
|
|
314
|
-
if (this.state.saveFunction) {
|
|
315
|
-
this.state.saveFunction(result.refreshToken);
|
|
316
|
-
}
|
|
317
|
-
// Return true to indicate that the token refresh was successful
|
|
318
|
-
return true;
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
// Return false to indicate that the token refresh failed
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Creates options for HTTP requests.
|
|
327
|
-
* @param {string} method - The HTTP method (GET, POST, PUT, DELETE, etc.).
|
|
328
|
-
* @param {unknown} data - Optional data to include in the request body.
|
|
329
|
-
* @returns {IHttpOptions} An object representing the request options.
|
|
330
|
-
*/
|
|
331
|
-
makeOptions(method, data) {
|
|
332
|
-
const options = {
|
|
333
|
-
method: method,
|
|
334
|
-
headers: {
|
|
335
|
-
'Content-Type': 'application/json',
|
|
336
|
-
'x-app-token': this.state.token,
|
|
337
|
-
},
|
|
338
|
-
};
|
|
339
|
-
// if method = 'POST' add x-device-metadata
|
|
340
|
-
if (method === 'POST') {
|
|
341
|
-
options.headers = {
|
|
342
|
-
...options.headers,
|
|
343
|
-
'x-device-metadata': this._getDeviceMetadata(),
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
// Check if 'data' is an instance of FormData or Blob
|
|
347
|
-
if (data instanceof FormData || data instanceof Blob) {
|
|
348
|
-
// Remove the 'Content-Type' header from options.headers
|
|
349
|
-
delete options.headers['Content-Type'];
|
|
350
|
-
// Set the 'accept' header to 'application/json', while preserving existing headers
|
|
351
|
-
options.headers = {
|
|
352
|
-
...options.headers,
|
|
353
|
-
accept: 'application/json',
|
|
354
|
-
};
|
|
355
|
-
// Assign 'data' to options.body for sending as request payload
|
|
356
|
-
options.body = data;
|
|
357
|
-
}
|
|
358
|
-
else if (data) {
|
|
359
|
-
// If 'data' exists and is not FormData or Blob, convert it to a JSON string
|
|
360
|
-
// and assign it to options.body
|
|
361
|
-
options.body = JSON.stringify(data);
|
|
362
|
-
}
|
|
363
|
-
// Check if there is an access token available in the state
|
|
364
|
-
if (this.state.accessToken) {
|
|
365
|
-
// Add an 'Authorization' header with the Bearer token to options.headers
|
|
366
|
-
options.headers['Authorization'] = 'Bearer ' + this.state.accessToken;
|
|
367
|
-
}
|
|
368
|
-
return options;
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Handles responses from the browser's fetch API.
|
|
372
|
-
* @param {string} path - The path to append to the base URL.
|
|
373
|
-
* @param {IHttpOptions} options - The options for the fetch request.
|
|
374
|
-
* @returns {Promise<T>} A promise resolving to the response data.
|
|
375
|
-
* @description Define an asynchronous method 'browserResponse' that takes a path and options as parameters
|
|
376
|
-
*/
|
|
377
|
-
async browserResponse(path, options) {
|
|
378
|
-
try {
|
|
379
|
-
// Perform a fetch request using the full URL obtained from '_getFullPath' and the provided options
|
|
380
|
-
const response = await fetch(this._getFullPath(path), options);
|
|
381
|
-
// Check if the response status is OK (status code 200-299)
|
|
382
|
-
if (response.ok) {
|
|
383
|
-
try {
|
|
384
|
-
// Attempt to read the response body as text
|
|
385
|
-
const text = await response.text();
|
|
386
|
-
// If the response body is not empty, parse it as JSON; otherwise, return an empty object
|
|
387
|
-
return (text ? JSON.parse(text) : {});
|
|
388
|
-
// Alternatively, you could directly return the parsed JSON with 'await response.json()'
|
|
389
|
-
}
|
|
390
|
-
catch (e) {
|
|
391
|
-
// If parsing the response fails, return the error
|
|
392
|
-
return e;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
// Handle non-OK responses
|
|
397
|
-
// Check if the status is 401 (Unauthorized) and custom authentication is not used
|
|
398
|
-
if (response.status === 401 && !this.state.customAuth) {
|
|
399
|
-
// Attempt to refresh the access token
|
|
400
|
-
const refresh = await this.refreshToken();
|
|
401
|
-
if (refresh) {
|
|
402
|
-
// Update the Authorization header with the new access token
|
|
403
|
-
options.headers['Authorization'] =
|
|
404
|
-
'Bearer ' + this.state.accessToken;
|
|
405
|
-
// Retry the fetch request with updated headers
|
|
406
|
-
const secondResponse = await fetch(this._getFullPath(path), options);
|
|
407
|
-
// Return the JSON-parsed response of the retry request
|
|
408
|
-
return (await secondResponse.json());
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
// Store the response status and parse the response body as JSON
|
|
412
|
-
const status = response.status;
|
|
413
|
-
const res = await response.json();
|
|
414
|
-
const statusKey = status;
|
|
415
|
-
if (this.state.errorsFunctions &&
|
|
416
|
-
this.state.errorsFunctions[statusKey]) {
|
|
417
|
-
this.state.errorsFunctions[statusKey](res);
|
|
418
|
-
}
|
|
419
|
-
// Determine whether to return or throw the response based on 'isShell' state
|
|
420
|
-
if (this.state.isShell) {
|
|
421
|
-
return res;
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
throw res;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
catch (e) {
|
|
429
|
-
// Handle any errors that occur during the fetch process
|
|
430
|
-
// Determine whether to return or throw the error based on 'isShell' state
|
|
431
|
-
if (this.state.isShell) {
|
|
432
|
-
return e;
|
|
433
|
-
}
|
|
434
|
-
else {
|
|
435
|
-
throw e;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
exports.default = AsyncModules;
|
package/dist/base/result.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Result class for handling response data.
|
|
3
|
-
* @description Result class for handling response data.
|
|
4
|
-
*/
|
|
5
|
-
export default class Result {
|
|
6
|
-
body: any;
|
|
7
|
-
/**
|
|
8
|
-
* Constructor that initializes the class with a given data.
|
|
9
|
-
* @param {Response | string} data - Response or string data.
|
|
10
|
-
* @description Constructor that initializes the class with a given data, which can be of type Response or string.
|
|
11
|
-
*/
|
|
12
|
-
constructor(data: Response | string);
|
|
13
|
-
/**
|
|
14
|
-
* Asynchronously converts the body to a blob and returns the current instance.
|
|
15
|
-
* @returns {Promise<Result>} Current instance.
|
|
16
|
-
* @description Asynchronously converts the body to a blob and returns the current instance.
|
|
17
|
-
*/
|
|
18
|
-
blob(): Promise<Result>;
|
|
19
|
-
/**
|
|
20
|
-
* Asynchronously parses the body as JSON and returns the current instance.
|
|
21
|
-
* @returns {Promise<Result>} Current instance.
|
|
22
|
-
* @description Asynchronously parses the body as JSON and returns the current instance.
|
|
23
|
-
*/
|
|
24
|
-
json(): Promise<Result>;
|
|
25
|
-
/**
|
|
26
|
-
* Recursively removes language-specific data from the provided data or the body.
|
|
27
|
-
* @param {string} langCode - Language code.
|
|
28
|
-
* @param {any} [data] - Data to process.
|
|
29
|
-
* @returns {any} Processed data.
|
|
30
|
-
* @description Recursively removes language-specific data from the provided data or the body.
|
|
31
|
-
*/
|
|
32
|
-
makeDataWithoutLang(langCode: string, data?: any): any;
|
|
33
|
-
/**
|
|
34
|
-
* Recursively simplifies arrays in the provided data or the body by removing single-element arrays.
|
|
35
|
-
* @param {any} data - The data to simplify.
|
|
36
|
-
* @returns {any} The simplified data.
|
|
37
|
-
*/
|
|
38
|
-
makeDataWithoutArray(data?: any): any;
|
|
39
|
-
}
|