oneentry 1.0.141 → 1.0.143
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/dist/admins/adminsInterfaces.d.ts +1 -2
- package/dist/attribute-sets/attributeSetsInterfaces.d.ts +11 -13
- package/dist/auth-provider/authProviderApi.d.ts +1 -1
- package/dist/auth-provider/authProviderApi.js +13 -10
- package/dist/auth-provider/authProvidersInterfaces.d.ts +4 -17
- package/dist/base/asyncModules.js +8 -0
- package/dist/base/stateModule.js +1 -1
- package/dist/base/syncModules.d.ts +139 -2
- package/dist/base/syncModules.js +188 -21
- package/dist/base/utils.d.ts +1 -1
- package/dist/blocks/blocksInterfaces.d.ts +0 -5
- package/dist/blocks/blocksSchemas.d.ts +8 -0
- package/dist/file-uploading/fileUploadingApi.d.ts +5 -5
- package/dist/file-uploading/fileUploadingApi.js +3 -6
- package/dist/file-uploading/fileUploadingInterfaces.d.ts +5 -8
- package/dist/forms/formsInterfaces.d.ts +4 -2
- package/dist/forms-data/formsDataInterfaces.d.ts +0 -3
- package/dist/general-types/generalTypesInterfaces.d.ts +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/integration-collections/integrationCollectionsApi.d.ts +3 -13
- package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +26 -26
- package/dist/locales/localesInterfaces.d.ts +0 -1
- package/dist/menus/menusInterfaces.d.ts +0 -1
- package/dist/menus/menusInterfaces.js +0 -1
- package/dist/orders/ordersInterfaces.d.ts +8 -15
- package/dist/pages/pagesInterfaces.d.ts +0 -8
- package/dist/payments/paymentsInterfaces.d.ts +0 -6
- package/dist/product-statuses/productStatusesInterfaces.d.ts +0 -4
- package/dist/products/productsInterfaces.d.ts +10 -19
- package/dist/products/productsSchemas.d.ts +8 -0
- package/dist/products/productsSchemas.js +2 -0
- package/dist/system/systemApi.d.ts +6 -6
- package/dist/system/systemApi.js +3 -5
- package/dist/system/systemInterfaces.d.ts +6 -8
- package/dist/system/systemInterfaces.js +0 -3
- package/dist/templates/templatesInterfaces.d.ts +0 -3
- package/dist/templates-preview/templatesPreviewInterfaces.d.ts +0 -2
- package/dist/users/usersApi.js +1 -3
- package/dist/users/usersInterfaces.d.ts +1 -7
- package/dist/web-socket/wsInterfaces.d.ts +0 -1
- package/package.json +1 -1
package/configure.js
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
* OneEntry SDK Configuration Tool
|
|
5
5
|
*
|
|
6
6
|
* Interactive CLI tool for initial SDK setup. Prompts the user for:
|
|
7
|
+
* - Project type (Node.js or Next.js)
|
|
7
8
|
* - Project URL (must include https://)
|
|
8
9
|
* - Authentication token
|
|
9
10
|
*
|
|
10
|
-
* Generates an example.
|
|
11
|
-
*
|
|
11
|
+
* Node.js: Generates an example.mjs file with a ready-to-use SDK setup.
|
|
12
|
+
* Next.js: Initializes a new Next.js project via create-next-app and adds
|
|
13
|
+
* oneentry configuration in lib/oneentry.ts and .env.local.
|
|
12
14
|
*
|
|
13
15
|
* Usage:
|
|
14
16
|
* npx oneentry
|
|
@@ -22,6 +24,7 @@
|
|
|
22
24
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
23
25
|
|
|
24
26
|
const fs = require('fs');
|
|
27
|
+
const path = require('path');
|
|
25
28
|
const readline = require('readline');
|
|
26
29
|
const { spawn } = require('child_process');
|
|
27
30
|
|
|
@@ -30,26 +33,41 @@ const rl = readline.createInterface({
|
|
|
30
33
|
output: process.stdout,
|
|
31
34
|
});
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
console.log('\nOneEntry SDK setup\n');
|
|
37
|
+
console.log('1) Node.js');
|
|
38
|
+
console.log('2) Next.js\n');
|
|
39
|
+
|
|
40
|
+
rl.question('Choose project type (1/2): ', (type) => {
|
|
41
|
+
const isNext = type.trim() === '2';
|
|
42
|
+
|
|
43
|
+
if (isNext) {
|
|
44
|
+
rl.question('Enter Next.js project name: ', (projectName) => {
|
|
45
|
+
rl.question('Enter project URL with https://... : ', (url) => {
|
|
46
|
+
rl.question('Enter token: ', (token) => {
|
|
47
|
+
rl.close();
|
|
48
|
+
initNextProject(projectName.trim(), url.trim(), token.trim());
|
|
49
|
+
});
|
|
50
|
+
});
|
|
38
51
|
});
|
|
39
|
-
}
|
|
52
|
+
} else {
|
|
53
|
+
rl.question('Enter project URL with https://... : ', (url) => {
|
|
54
|
+
rl.question('Enter token: ', (token) => {
|
|
55
|
+
rl.question('Run example after creating? (y/n): ', (answer) => {
|
|
56
|
+
rl.close();
|
|
57
|
+
createNodeExample(url.trim(), token.trim(), answer.trim().toLowerCase() === 'y');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
40
62
|
});
|
|
41
63
|
|
|
42
64
|
/**
|
|
43
65
|
* Creates an example JavaScript file with SDK initialization and sample requests
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* that fetches admins, pages and products and prints them to the console.
|
|
47
|
-
* Run with: node example.mjs
|
|
48
|
-
* @param {string} url - Project URL with https:// (e.g., "https://example.oneentry.cloud")
|
|
49
|
-
* @param {string} token - Authentication token for API access
|
|
66
|
+
* @param {string} url - Project URL with https://
|
|
67
|
+
* @param {string} token - Authentication token
|
|
50
68
|
* @param {boolean} run - Whether to run the generated file immediately
|
|
51
69
|
*/
|
|
52
|
-
function
|
|
70
|
+
function createNodeExample(url, token, run) {
|
|
53
71
|
const filePath = 'example.mjs';
|
|
54
72
|
const tokenLine = token ? `\n token: '${token}',` : '';
|
|
55
73
|
fs.writeFile(
|
|
@@ -88,3 +106,77 @@ console.log('Products:', JSON.stringify(products, null, 2));
|
|
|
88
106
|
},
|
|
89
107
|
);
|
|
90
108
|
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Initializes a Next.js project and adds OneEntry SDK configuration
|
|
112
|
+
* @param {string} projectName - Directory name for the new Next.js project
|
|
113
|
+
* @param {string} url - Project URL with https://
|
|
114
|
+
* @param {string} token - Authentication token
|
|
115
|
+
*/
|
|
116
|
+
function initNextProject(projectName, url, token) {
|
|
117
|
+
console.log(`\nRunning create-next-app for "${projectName}"...\n`);
|
|
118
|
+
|
|
119
|
+
const child = spawn(
|
|
120
|
+
'npx',
|
|
121
|
+
['create-next-app@latest', projectName, '--ts', '--app', '--eslint', '--no-tailwind', '--src-dir', '--import-alias', '@/*'],
|
|
122
|
+
{ stdio: 'inherit', shell: true },
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
child.on('error', (e) => {
|
|
126
|
+
console.error('Failed to run create-next-app:', e.message);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
child.on('close', (code) => {
|
|
130
|
+
if (code !== 0) {
|
|
131
|
+
console.error(`create-next-app exited with code ${code}`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
addOneEntryConfig(projectName, url, token);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Writes oneentry config files into the newly created Next.js project
|
|
140
|
+
* @param {string} projectName - Project directory name
|
|
141
|
+
* @param {string} url - Project URL with https://
|
|
142
|
+
* @param {string} token - Authentication token
|
|
143
|
+
*/
|
|
144
|
+
function addOneEntryConfig(projectName, url, token) {
|
|
145
|
+
const libDir = path.join(projectName, 'src', 'lib');
|
|
146
|
+
fs.mkdirSync(libDir, { recursive: true });
|
|
147
|
+
|
|
148
|
+
const tokenLine = token ? `\n token: process.env.ONEENTRY_TOKEN,` : '';
|
|
149
|
+
const libContent = `import { defineOneEntry } from 'oneentry';
|
|
150
|
+
|
|
151
|
+
const { Admins, Pages, Products } = defineOneEntry(
|
|
152
|
+
process.env.NEXT_PUBLIC_ONEENTRY_URL ?? '',
|
|
153
|
+
{${tokenLine}
|
|
154
|
+
langCode: 'en_US',
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
export { Admins, Pages, Products };
|
|
159
|
+
`;
|
|
160
|
+
|
|
161
|
+
const envContent = `NEXT_PUBLIC_ONEENTRY_URL=${url}\n${token ? `ONEENTRY_TOKEN=${token}\n` : ''}`;
|
|
162
|
+
|
|
163
|
+
fs.writeFile(path.join(libDir, 'oneentry.ts'), libContent, (err) => {
|
|
164
|
+
if (err) {
|
|
165
|
+
console.error('Failed to create lib/oneentry.ts:', err.message);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
console.log(`Created ${projectName}/src/lib/oneentry.ts`);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
fs.writeFile(path.join(projectName, '.env.local'), envContent, (err) => {
|
|
172
|
+
if (err) {
|
|
173
|
+
console.error('Failed to create .env.local:', err.message);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
console.log(`Created ${projectName}/.env.local`);
|
|
177
|
+
console.log(`\nNext steps:`);
|
|
178
|
+
console.log(` cd ${projectName}`);
|
|
179
|
+
console.log(` npm install oneentry`);
|
|
180
|
+
console.log(` npm run dev`);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AttributeType, IAttributeValues, IError } from '../base/utils';
|
|
2
2
|
/**
|
|
3
3
|
* @interface IAdmins
|
|
4
|
-
* @property {Function} getAdminsInfo - Method to retrieve all admin user objects.
|
|
5
4
|
* @description This interface defines the contract for any class that implements it
|
|
6
5
|
*/
|
|
7
6
|
interface IAdmins {
|
|
@@ -81,7 +80,7 @@ interface IAdminEntity {
|
|
|
81
80
|
position: number | null;
|
|
82
81
|
isSync: boolean;
|
|
83
82
|
attributeValues: IAttributeValues;
|
|
84
|
-
[key: string]:
|
|
83
|
+
[key: string]: unknown;
|
|
85
84
|
}
|
|
86
85
|
/**
|
|
87
86
|
* Interface representing a query for fetching admin data.
|
|
@@ -2,8 +2,6 @@ import type { IError, ILocalizeInfo } from '../base/utils';
|
|
|
2
2
|
/**
|
|
3
3
|
* Interface for retrieving attributes based on markers and language codes.
|
|
4
4
|
* @interface IAttributesSets
|
|
5
|
-
* @property {Function} getAttributesByMarker - Get all attributes with data from the attribute sets.
|
|
6
|
-
* @property {Function} getSingleAttributeByMarkerSet - Get a single attribute with data from the attribute sets.
|
|
7
5
|
* @description This interface defines methods for retrieving attributes based on markers and language codes.
|
|
8
6
|
*/
|
|
9
7
|
interface IAttributesSets {
|
|
@@ -54,16 +52,16 @@ interface IListTitle {
|
|
|
54
52
|
* @type {AttributeType}
|
|
55
53
|
* @description This type defines the possible values for attribute types used in the system.
|
|
56
54
|
*/
|
|
57
|
-
type AttributeType = 'string' | 'text' | 'textWithHeader' | 'integer' | 'real' | 'float' | 'dateTime' | 'date' | 'time' | 'file' | 'image' | 'groupOfImages' | 'radioButton' | 'list' | 'button';
|
|
55
|
+
type AttributeType = 'string' | 'text' | 'textWithHeader' | 'integer' | 'real' | 'float' | 'dateTime' | 'date' | 'time' | 'file' | 'image' | 'groupOfImages' | 'radioButton' | 'list' | 'button' | 'entity' | 'timeInterval';
|
|
58
56
|
/**
|
|
59
57
|
* Represents an attribute set entity.
|
|
60
58
|
* @interface IAttributesSetsEntity
|
|
61
59
|
* @property {AttributeType} type - Attribute type. Example: "string", "text", "integer", "etc".
|
|
62
|
-
* @property {
|
|
63
|
-
* @property {
|
|
60
|
+
* @property {unknown} [value] - Value of the attribute, which can be of any type.
|
|
61
|
+
* @property {unknown} initialValue - Initial value of the attribute.
|
|
64
62
|
* @property {string} marker - Textual identifier of the attribute (marker). Example: "color", "size", "etc".
|
|
65
63
|
* @property {number} position - Position number for sorting. Example: 1.
|
|
66
|
-
* @property {IListTitle[] | Record<string,
|
|
64
|
+
* @property {IListTitle[] | Record<string, unknown>} [listTitles] - Array of values (with extended data) for list and radioButton attributes.
|
|
67
65
|
* @example
|
|
68
66
|
[
|
|
69
67
|
{
|
|
@@ -81,7 +79,7 @@ type AttributeType = 'string' | 'text' | 'textWithHeader' | 'integer' | 'real' |
|
|
|
81
79
|
"extendedValueType": null
|
|
82
80
|
}
|
|
83
81
|
]
|
|
84
|
-
* @property {Record<string,
|
|
82
|
+
* @property {Record<string, unknown>} [validators] - Set of validators for validation.
|
|
85
83
|
* @example
|
|
86
84
|
{
|
|
87
85
|
"requiredValidator": {
|
|
@@ -96,19 +94,19 @@ type AttributeType = 'string' | 'text' | 'textWithHeader' | 'integer' | 'real' |
|
|
|
96
94
|
{
|
|
97
95
|
"title": "My attribute"
|
|
98
96
|
}
|
|
99
|
-
* @property {Record<string,
|
|
97
|
+
* @property {Record<string, unknown>} [additionalFields] - Additional fields for the attribute (optional).
|
|
100
98
|
* @description This interface defines the structure of an attribute set entity, including its type, marker, position, validators, localization information, list titles, additional fields, and settings.
|
|
101
99
|
*/
|
|
102
100
|
interface IAttributesSetsEntity {
|
|
103
101
|
type: AttributeType;
|
|
104
|
-
value?:
|
|
105
|
-
initialValue:
|
|
102
|
+
value?: unknown;
|
|
103
|
+
initialValue: unknown;
|
|
106
104
|
marker: string;
|
|
107
105
|
position: number;
|
|
108
|
-
listTitles?: IListTitle[] | Record<string,
|
|
109
|
-
validators?: Record<string,
|
|
106
|
+
listTitles?: IListTitle[] | Record<string, unknown>;
|
|
107
|
+
validators?: Record<string, unknown>;
|
|
110
108
|
localizeInfos: ILocalizeInfo;
|
|
111
|
-
additionalFields?: Record<string,
|
|
109
|
+
additionalFields?: Record<string, unknown>;
|
|
112
110
|
}
|
|
113
111
|
/**
|
|
114
112
|
* Represents an attribute set entity.
|
|
@@ -16,7 +16,7 @@ const authProviderSchemas_1 = require("./authProviderSchemas");
|
|
|
16
16
|
*/
|
|
17
17
|
class AuthProviderApi extends asyncModules_1.default {
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* constructor
|
|
20
20
|
*/
|
|
21
21
|
constructor(state) {
|
|
22
22
|
super(state);
|
|
@@ -187,11 +187,12 @@ class AuthProviderApi extends asyncModules_1.default {
|
|
|
187
187
|
const result = await this._fetchPost(`/marker/${marker}/users/auth`, body);
|
|
188
188
|
// Validate response if validation is enabled
|
|
189
189
|
const validated = this._validateResponse(result, authProviderSchemas_1.AuthResponseSchema);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
if (!('statusCode' in validated)) {
|
|
191
|
+
this.state.accessToken = validated.accessToken;
|
|
192
|
+
this.state.refreshToken = validated.refreshToken;
|
|
193
|
+
if (this.state.saveFunction && validated.refreshToken) {
|
|
194
|
+
this.state.saveFunction(validated.refreshToken);
|
|
195
|
+
}
|
|
195
196
|
}
|
|
196
197
|
return validated;
|
|
197
198
|
}
|
|
@@ -207,10 +208,12 @@ class AuthProviderApi extends asyncModules_1.default {
|
|
|
207
208
|
async refresh(marker, token) {
|
|
208
209
|
const data = { refreshToken: token };
|
|
209
210
|
const result = await this._fetchPost(`/marker/${marker}/users/refresh`, data);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this.state.saveFunction
|
|
211
|
+
if (!('statusCode' in result)) {
|
|
212
|
+
this.state.accessToken = result.accessToken;
|
|
213
|
+
this.state.refreshToken = result.refreshToken;
|
|
214
|
+
if (this.state.saveFunction) {
|
|
215
|
+
this.state.saveFunction(result.refreshToken);
|
|
216
|
+
}
|
|
214
217
|
}
|
|
215
218
|
return result;
|
|
216
219
|
}
|
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import type { IError, ILocalizeInfo } from '../base/utils';
|
|
2
2
|
/**
|
|
3
3
|
* @interface IAuthProvider
|
|
4
|
-
* @property {Function} signUp - User registration.
|
|
5
|
-
* @property {Function} generateCode - Getting a user activation code.
|
|
6
|
-
* @property {Function} checkCode - User activation code verification.
|
|
7
|
-
* @property {Function} activateUser - User activate.
|
|
8
|
-
* @property {Function} auth - User authorization.
|
|
9
|
-
* @property {Function} refresh - Refresh token.
|
|
10
|
-
* @property {Function} logout - User logout.
|
|
11
|
-
* @property {Function} logoutAll - User logout.
|
|
12
|
-
* @property {Function} changePassword - Change password.
|
|
13
|
-
* @property {Function} getAuthProviders - Get all auth providers objects.
|
|
14
|
-
* @property {Function} getAuthProviderByMarker - Get one auth provider object by marker.
|
|
15
|
-
* @property {Function} getActiveSessionsByMarker - Get one auth provider object by marker.
|
|
16
|
-
* @property {Function} oauth - User registration (authorization) via OAUTH.
|
|
17
4
|
* @description This interface defines methods for user authentication and registration through various auth providers.
|
|
18
5
|
*/
|
|
19
6
|
interface IAuthProvider {
|
|
@@ -167,11 +154,11 @@ interface IAuthProvider {
|
|
|
167
154
|
* Retrieves active user sessions data object.
|
|
168
155
|
* @handleName getActiveSessionsByMarker
|
|
169
156
|
* @param {string} marker - The marker identifying the auth provider. Example: "email".
|
|
170
|
-
* @returns {
|
|
157
|
+
* @returns {Promise<IActiveSession[] | IError>} A promise that resolves to active user sessions data object.
|
|
171
158
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
172
159
|
* @description This method retrieves active user sessions data object.
|
|
173
160
|
*/
|
|
174
|
-
getActiveSessionsByMarker(marker: string): Promise<
|
|
161
|
+
getActiveSessionsByMarker(marker: string): Promise<IActiveSession[] | IError>;
|
|
175
162
|
/**
|
|
176
163
|
* User registration (authorization) via OAUTH.
|
|
177
164
|
* @handleName oauthSignUp
|
|
@@ -226,7 +213,7 @@ interface ISignUpData {
|
|
|
226
213
|
notificationData: {
|
|
227
214
|
email: string;
|
|
228
215
|
phonePush: Array<string>;
|
|
229
|
-
phoneSMS
|
|
216
|
+
phoneSMS?: string;
|
|
230
217
|
};
|
|
231
218
|
}
|
|
232
219
|
/**
|
|
@@ -289,7 +276,7 @@ interface ISignUpEntity {
|
|
|
289
276
|
notificationData: {
|
|
290
277
|
email: string;
|
|
291
278
|
phonePush: Array<string>;
|
|
292
|
-
phoneSMS
|
|
279
|
+
phoneSMS?: string;
|
|
293
280
|
};
|
|
294
281
|
locale?: string;
|
|
295
282
|
}
|
|
@@ -38,6 +38,14 @@ class AsyncModules extends syncModules_1.default {
|
|
|
38
38
|
if (!this.state.validationEnabled || !schema) {
|
|
39
39
|
return data;
|
|
40
40
|
}
|
|
41
|
+
// Skip validation for error responses (statusCode indicates API error)
|
|
42
|
+
if (data !== null &&
|
|
43
|
+
typeof data === 'object' &&
|
|
44
|
+
'statusCode' in data &&
|
|
45
|
+
typeof data.statusCode === 'number' &&
|
|
46
|
+
data.statusCode >= 400) {
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
41
49
|
// Use strict or safe validation based on config
|
|
42
50
|
if (this.state.validationStrictMode) {
|
|
43
51
|
const result = (0, validation_1.validateResponse)(schema, data, {
|
package/dist/base/stateModule.js
CHANGED
|
@@ -28,6 +28,20 @@ export default abstract class SyncModules {
|
|
|
28
28
|
protected _queryParamsToString(query: IProductsQuery | IUploadingQuery | any): string;
|
|
29
29
|
/**
|
|
30
30
|
* Normalizes data based on language code.
|
|
31
|
+
*
|
|
32
|
+
* Recursively traverses the API response and unwraps localized fields.
|
|
33
|
+
* The API stores translations as objects like
|
|
34
|
+
* `{ "en_US": "Hello", "ru_RU": "Hello" }`. The method replaces such an object
|
|
35
|
+
* with the value for the requested `langCode` when that key is present.
|
|
36
|
+
*
|
|
37
|
+
* Traversal order:
|
|
38
|
+
* 1. Array → recursively normalize each element, then `_normalizeAttr`.
|
|
39
|
+
* 2. Object → for each key:
|
|
40
|
+
* - value is an array: recurse;
|
|
41
|
+
* - value is a non-object (primitive) or falsy: copy as-is;
|
|
42
|
+
* - object has key `langCode`: take only the needed translation;
|
|
43
|
+
* - otherwise: recurse deeper.
|
|
44
|
+
* 3. Primitive → return as-is.
|
|
31
45
|
* @param {any} data - The data to normalize.
|
|
32
46
|
* @param {string} langCode - The language code for normalization.
|
|
33
47
|
* @returns {any} Normalized data.
|
|
@@ -35,6 +49,17 @@ export default abstract class SyncModules {
|
|
|
35
49
|
protected _normalizeData(data: any, langCode?: string): any;
|
|
36
50
|
/**
|
|
37
51
|
* Normalizes the body of a POST request.
|
|
52
|
+
*
|
|
53
|
+
* Performs two transformations before sending to the API:
|
|
54
|
+
*
|
|
55
|
+
* 1. **phoneSMS cleanup**: the API rejects an empty string as a field value,
|
|
56
|
+
* so if `notificationData.phoneSMS === ''` the key is deleted entirely.
|
|
57
|
+
* A missing key is treated by the API as "not provided"; an empty string is not.
|
|
58
|
+
*
|
|
59
|
+
* 2. **formData localization**: the API expects formData as
|
|
60
|
+
* `{ "<langCode>": [...fields] }`, but callers pass a flat array or a single object.
|
|
61
|
+
* The method wraps the data into the required structure.
|
|
62
|
+
* If `formData` is absent from the body — return the body as-is (only phoneSMS cleanup applied).
|
|
38
63
|
* @param {any} body - The body to normalize.
|
|
39
64
|
* @param {string} [langCode] - The language code for normalization.
|
|
40
65
|
* @returns {any} Normalized body.
|
|
@@ -42,12 +67,24 @@ export default abstract class SyncModules {
|
|
|
42
67
|
protected _normalizePostBody(body: any, langCode?: string): any;
|
|
43
68
|
/**
|
|
44
69
|
* Clears arrays within the data structure.
|
|
70
|
+
*
|
|
71
|
+
* Traverses the data and fixes a specific edge case with image attributes:
|
|
72
|
+
* when an `image` attribute has a single-element array in `value`,
|
|
73
|
+
* the API returns an array but consumers expect a plain object.
|
|
74
|
+
* In that case `value` is unwrapped: `[img]` → `img`.
|
|
75
|
+
*
|
|
76
|
+
* For all other keys the method recursively copies the structure unchanged.
|
|
45
77
|
* @param {Record<string, any>} data - The data to clear.
|
|
46
78
|
* @returns {any} Cleared data.
|
|
47
79
|
*/
|
|
48
80
|
protected _clearArray(data: Record<string, any>): any;
|
|
49
81
|
/**
|
|
50
82
|
* Sorts attributes by their positions.
|
|
83
|
+
*
|
|
84
|
+
* The API returns attributes as an object `{ marker: AttrObject }`.
|
|
85
|
+
* Each attribute has a `position` field. The method rebuilds the object
|
|
86
|
+
* with keys sorted by ascending `position` so that the display order
|
|
87
|
+
* matches the order defined in the CMS.
|
|
51
88
|
* @param {any} data - The data containing attributes.
|
|
52
89
|
* @returns {any} Sorted attributes.
|
|
53
90
|
*/
|
|
@@ -61,11 +98,26 @@ export default abstract class SyncModules {
|
|
|
61
98
|
protected _addDays(date: Date, days: number): any;
|
|
62
99
|
/**
|
|
63
100
|
* Common logic for processing schedule dates (weekly, monthly, or both).
|
|
101
|
+
*
|
|
102
|
+
* Abstracts date iteration for three scheduling modes:
|
|
103
|
+
*
|
|
104
|
+
* - **`inEveryWeek` only**: starting from the start date, generates dates
|
|
105
|
+
* with a 7-day step until the end of the current month.
|
|
106
|
+
*
|
|
107
|
+
* - **`inEveryMonth` only**: pins the day-of-month from the start date
|
|
108
|
+
* and repeats it for each of the next 12 months. If the month does not
|
|
109
|
+
* have that day (e.g. Feb 31), the iteration is skipped.
|
|
110
|
+
*
|
|
111
|
+
* - **`inEveryWeek` + `inEveryMonth`**: for each of the next 12 months finds
|
|
112
|
+
* the first occurrence of the target weekday (from the start date), then
|
|
113
|
+
* iterates all occurrences of that weekday in the month with a 7-day step.
|
|
114
|
+
*
|
|
115
|
+
* `processDate(currentDate)` is called for every resolved date.
|
|
64
116
|
* @param {Date} date - The date for which to process intervals.
|
|
65
117
|
* @param {object} config - Configuration for schedule repetition.
|
|
66
118
|
* @param {boolean} config.inEveryWeek - Whether to repeat weekly.
|
|
67
119
|
* @param {boolean} config.inEveryMonth - Whether to repeat monthly.
|
|
68
|
-
* @param {
|
|
120
|
+
* @param {(currentDate: Date) => void} processDate - Callback function to process each date.
|
|
69
121
|
*/
|
|
70
122
|
protected _processScheduleDates(date: Date, config: {
|
|
71
123
|
inEveryWeek: boolean;
|
|
@@ -73,6 +125,12 @@ export default abstract class SyncModules {
|
|
|
73
125
|
}, processDate: (currentDate: Date) => void): void;
|
|
74
126
|
/**
|
|
75
127
|
* Generates intervals for a specific date based on a schedule.
|
|
128
|
+
*
|
|
129
|
+
* For each date resolved by `_processScheduleDates`, iterates over
|
|
130
|
+
* the `schedule.times` array of time ranges. Each range is a pair
|
|
131
|
+
* `[startTime, endTime]` with `{ hours, minutes }` fields.
|
|
132
|
+
* Creates an ISO interval `[start.toISOString(), end.toISOString()]`
|
|
133
|
+
* and adds it to `utcIntervals` (Set deduplicates automatically).
|
|
76
134
|
* @param {Date} date - The date for which to generate intervals.
|
|
77
135
|
* @param {object} schedule - The schedule defining the intervals.
|
|
78
136
|
* @param {boolean} schedule.inEveryWeek - The number of weeks between intervals.
|
|
@@ -87,12 +145,32 @@ export default abstract class SyncModules {
|
|
|
87
145
|
}, utcIntervals: Set<Array<string>>): void;
|
|
88
146
|
/**
|
|
89
147
|
* Adds time intervals to schedules.
|
|
148
|
+
*
|
|
149
|
+
* Accepts an array of schedule groups (structure of `timeInterval` attributes
|
|
150
|
+
* for pages/products). For each group iterates over `values` — the set of
|
|
151
|
+
* concrete schedules. Each schedule contains a date range `dates[0..1]`.
|
|
152
|
+
*
|
|
153
|
+
* If both boundaries are equal (`isSameDay`), intervals are generated only
|
|
154
|
+
* for that single date. Otherwise — for every day in the range inclusive.
|
|
155
|
+
*
|
|
156
|
+
* The result (`schedule.timeIntervals`) is a sorted array of ISO pairs,
|
|
157
|
+
* ready to pass to UI components.
|
|
90
158
|
* @param {any[]} schedules - The schedules to process.
|
|
91
159
|
* @returns {any} Schedules with added time intervals.
|
|
92
160
|
*/
|
|
93
161
|
_addTimeIntervalsToSchedules(schedules: any[]): any;
|
|
94
162
|
/**
|
|
95
163
|
* Generates intervals for a specific date for form schedules.
|
|
164
|
+
*
|
|
165
|
+
* Unlike `_generateIntervalsForDate`, time ranges here have a different shape:
|
|
166
|
+
* each `timeInterval` contains `start`, `end` and `period`
|
|
167
|
+
* (slot length in minutes). The method slices the [start, end) window into
|
|
168
|
+
* fixed-length slots of `period` minutes:
|
|
169
|
+
*
|
|
170
|
+
* start=09:00, end=12:00, period=30 → [09:00–09:30], [09:30–10:00], …, [11:30–12:00]
|
|
171
|
+
*
|
|
172
|
+
* Generation stops if the next slot would exceed `end`.
|
|
173
|
+
* Each slot is added to `utcIntervals` (Set deduplicates automatically).
|
|
96
174
|
* @param {Date} date - The date for which to generate intervals.
|
|
97
175
|
* @param {object} interval - The interval configuration.
|
|
98
176
|
* @param {boolean} interval.inEveryWeek - Indicates whether the schedule is weekly.
|
|
@@ -106,24 +184,59 @@ export default abstract class SyncModules {
|
|
|
106
184
|
}, timeIntervals: any[], utcIntervals: Set<Array<string>>): void;
|
|
107
185
|
/**
|
|
108
186
|
* Adds time intervals to form schedules (different structure).
|
|
187
|
+
*
|
|
188
|
+
* Same as `_addTimeIntervalsToSchedules` but for `timeInterval` attributes
|
|
189
|
+
* in **forms** (different API data structure):
|
|
190
|
+
* - `interval.range[0..1]` instead of `schedule.dates[0..1]`
|
|
191
|
+
* - `interval.intervals` — array of time ranges with slots (`period`)
|
|
192
|
+
* instead of `[startTime, endTime]` pairs
|
|
193
|
+
*
|
|
194
|
+
* Result is written to `interval.timeIntervals`.
|
|
109
195
|
* @param {any[]} intervals - The intervals to process.
|
|
110
196
|
* @returns {any} Intervals with added time intervals.
|
|
111
197
|
*/
|
|
112
198
|
_addTimeIntervalsToFormSchedules(intervals: any[]): any;
|
|
113
199
|
/**
|
|
114
200
|
* Transforms additionalFields from array to object keyed by marker.
|
|
115
|
-
*
|
|
201
|
+
*
|
|
202
|
+
* The API returns `additionalFields` as an array: `[{ marker, ... }, ...]`.
|
|
203
|
+
* For convenient key-based access (`attr.additionalFields['fieldName']`)
|
|
204
|
+
* the method converts it to an object `{ marker: { marker, ... } }`.
|
|
205
|
+
* Transformation is skipped when `rawData` mode is enabled in config
|
|
206
|
+
* (the consumer wants the data as-is, without transformations).
|
|
116
207
|
* @param {any} attr - The attribute object that may contain additionalFields.
|
|
117
208
|
*/
|
|
118
209
|
private _normalizeAdditionalFields;
|
|
119
210
|
/**
|
|
120
211
|
* Normalizes attributes within the data.
|
|
212
|
+
*
|
|
213
|
+
* Handles three different attribute formats returned by the API:
|
|
214
|
+
*
|
|
215
|
+
* **1. `attributeValues`** — attributes of pages, products and other entities.
|
|
216
|
+
* Contains an object `{ marker: AttrObject }`. For each attribute:
|
|
217
|
+
* - `_normalizeAdditionalFields` is called;
|
|
218
|
+
* - numeric types (`integer`, `float`) are cast to a JS number (or `null`);
|
|
219
|
+
* - `timeInterval` attributes are enriched with computed `timeIntervals`;
|
|
220
|
+
* - the whole object is re-sorted by `position`.
|
|
221
|
+
*
|
|
222
|
+
* **2. `attributes`** — form attributes (different API structure).
|
|
223
|
+
* Same `additionalFields` and `timeInterval` processing,
|
|
224
|
+
* but numbers are not normalized here (commented out — logic differs).
|
|
225
|
+
*
|
|
226
|
+
* **3. `type`** — a single attribute from an attribute set.
|
|
227
|
+
* Same transformations as in case 1, but without sorting.
|
|
228
|
+
*
|
|
229
|
+
* If none of the keys are found — data is returned unchanged.
|
|
121
230
|
* @param {any} data - The data to normalize.
|
|
122
231
|
* @returns {any} Normalized attributes.
|
|
123
232
|
*/
|
|
124
233
|
protected _normalizeAttr(data: any): any;
|
|
125
234
|
/**
|
|
126
235
|
* Processes data after fetching or receiving it.
|
|
236
|
+
*
|
|
237
|
+
* Final post-processing of the API response: first unwraps localized fields
|
|
238
|
+
* (`_normalizeData`), then fixes single-element image attributes
|
|
239
|
+
* (`_clearArray`). Called at the end of every fetch method.
|
|
127
240
|
* @param {any} data - The data to process.
|
|
128
241
|
* @param {any} [langCode] - The language code for processing.
|
|
129
242
|
* @returns {any} Processed data.
|
|
@@ -143,6 +256,30 @@ export default abstract class SyncModules {
|
|
|
143
256
|
setRefreshToken(refreshToken: string): any;
|
|
144
257
|
/**
|
|
145
258
|
* Get deviceMetadata
|
|
259
|
+
*
|
|
260
|
+
* Builds a device metadata object to be sent in request headers.
|
|
261
|
+
* Used for analytics and anti-fraud on the API side.
|
|
262
|
+
*
|
|
263
|
+
* Returned JSON structure:
|
|
264
|
+
* ```json
|
|
265
|
+
* {
|
|
266
|
+
* "fingerprint": "UQ_<hash>_<instanceId>",
|
|
267
|
+
* "deviceInfo": { "os": "...", "browser": "...", "location": "en-US" }
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* **Fingerprint algorithm:**
|
|
272
|
+
* 1. Builds a string from stable characteristics: platform, userAgent, language,
|
|
273
|
+
* screen resolution, colorDepth, timezone, private-browsing mode, instanceId.
|
|
274
|
+
* 2. Runs it through a simple 32-bit hash (djb2-like).
|
|
275
|
+
* 3. Concatenates the hash and the first 12 characters of instanceId.
|
|
276
|
+
*
|
|
277
|
+
* **instanceId strategy:**
|
|
278
|
+
* - Browser: `_getBrowserDeviceId()` — read from localStorage, stable across sessions.
|
|
279
|
+
* - Node.js / no localStorage: `_nodeDeviceId` — generated at instance creation,
|
|
280
|
+
* lives until the process restarts.
|
|
281
|
+
*
|
|
282
|
+
* In a Node.js environment (no `window`) returns a simplified object without screen/navigator.
|
|
146
283
|
* @returns {string} - Returns an object containing device metadata.
|
|
147
284
|
*/
|
|
148
285
|
protected _getDeviceMetadata(): string;
|