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.
- package/README.md +15 -3
- package/configure.js +27 -3
- package/dist/admins/adminsApi.js +4 -1
- package/dist/admins/adminsInterfaces.d.ts +1 -1
- package/dist/admins/adminsSchemas.d.ts +30 -0
- package/dist/admins/adminsSchemas.js +27 -0
- package/dist/attribute-sets/attributeSetsApi.js +13 -4
- package/dist/attribute-sets/attributeSetsSchemas.d.ts +90 -0
- package/dist/attribute-sets/attributeSetsSchemas.js +74 -0
- package/dist/auth-provider/authProviderApi.d.ts +11 -8
- package/dist/auth-provider/authProviderApi.js +25 -15
- package/dist/auth-provider/authProviderSchemas.d.ts +137 -0
- package/dist/auth-provider/authProviderSchemas.js +85 -0
- package/dist/auth-provider/authProvidersInterfaces.d.ts +6 -6
- package/dist/base/asyncModules.d.ts +25 -15
- package/dist/base/asyncModules.js +91 -24
- package/dist/base/stateModule.d.ts +7 -0
- package/dist/base/stateModule.js +26 -11
- package/dist/base/syncModules.d.ts +12 -0
- package/dist/base/syncModules.js +45 -94
- package/dist/base/utils.d.ts +41 -2
- package/dist/base/validation.d.ts +118 -0
- package/dist/base/validation.js +132 -0
- package/dist/blocks/blocksApi.js +16 -11
- package/dist/blocks/blocksInterfaces.d.ts +1 -1
- package/dist/blocks/blocksSchemas.d.ts +187 -0
- package/dist/blocks/blocksSchemas.js +43 -0
- package/dist/config.d.ts +10 -2
- package/dist/config.js +20 -4
- package/dist/file-uploading/fileUploadingApi.js +4 -1
- package/dist/file-uploading/fileUploadingSchemas.d.ts +22 -0
- package/dist/file-uploading/fileUploadingSchemas.js +21 -0
- package/dist/forms/formsApi.js +7 -2
- package/dist/forms/formsInterfaces.d.ts +20 -8
- package/dist/forms/formsSchemas.d.ts +65 -0
- package/dist/forms/formsSchemas.js +36 -0
- package/dist/forms-data/formsDataApi.js +10 -3
- package/dist/forms-data/formsDataInterfaces.d.ts +2 -2
- package/dist/forms-data/formsDataSchemas.d.ts +107 -0
- package/dist/forms-data/formsDataSchemas.js +83 -0
- package/dist/general-types/generalTypesApi.js +4 -1
- package/dist/general-types/generalTypesSchemas.d.ts +50 -0
- package/dist/general-types/generalTypesSchemas.js +35 -0
- package/dist/integration-collections/integrationCollectionsApi.js +25 -9
- package/dist/integration-collections/integrationCollectionsSchemas.d.ts +84 -0
- package/dist/integration-collections/integrationCollectionsSchemas.js +63 -0
- package/dist/locales/localesApi.js +4 -1
- package/dist/locales/localesSchemas.d.ts +32 -0
- package/dist/locales/localesSchemas.js +26 -0
- package/dist/menus/menusApi.js +4 -1
- package/dist/menus/menusSchemas.d.ts +16 -0
- package/dist/menus/menusSchemas.js +28 -0
- package/dist/orders/ordersApi.js +13 -4
- package/dist/orders/ordersInterfaces.d.ts +3 -3
- package/dist/orders/ordersSchemas.d.ts +158 -0
- package/dist/orders/ordersSchemas.js +120 -0
- package/dist/pages/pagesApi.d.ts +2 -1
- package/dist/pages/pagesApi.js +87 -34
- package/dist/pages/pagesInterfaces.d.ts +6 -5
- package/dist/pages/pagesSchemas.d.ts +85 -0
- package/dist/pages/pagesSchemas.js +46 -0
- package/dist/payments/paymentsApi.js +13 -4
- package/dist/payments/paymentsInterfaces.d.ts +3 -3
- package/dist/payments/paymentsSchemas.d.ts +121 -0
- package/dist/payments/paymentsSchemas.js +75 -0
- package/dist/product-statuses/productStatusesApi.js +13 -3
- package/dist/product-statuses/productStatusesSchemas.d.ts +34 -0
- package/dist/product-statuses/productStatusesSchemas.js +30 -0
- package/dist/products/productsApi.js +19 -6
- package/dist/products/productsInterfaces.d.ts +4 -4
- package/dist/products/productsSchemas.d.ts +212 -0
- package/dist/products/productsSchemas.js +85 -0
- package/dist/templates/templatesApi.js +11 -4
- package/dist/templates/templatesSchemas.d.ts +48 -0
- package/dist/templates/templatesSchemas.js +31 -0
- package/dist/templates-preview/templatesPreviewApi.js +7 -2
- package/dist/templates-preview/templatesPreviewSchemas.d.ts +83 -0
- package/dist/templates-preview/templatesPreviewSchemas.js +48 -0
- package/dist/users/usersApi.js +8 -5
- package/dist/users/usersInterfaces.d.ts +2 -1
- package/dist/users/usersSchemas.d.ts +38 -0
- package/dist/users/usersSchemas.js +28 -0
- package/package.json +5 -4
package/dist/base/syncModules.js
CHANGED
|
@@ -136,44 +136,29 @@ class SyncModules {
|
|
|
136
136
|
return result;
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
|
-
*
|
|
140
|
-
* @param {Date} date - The date for which to
|
|
141
|
-
* @param {object}
|
|
142
|
-
* @param {boolean}
|
|
143
|
-
* @param {
|
|
144
|
-
* @param {
|
|
145
|
-
* @param {Set<Array<string>>} utcIntervals - A set to store unique intervals.
|
|
139
|
+
* Common logic for processing schedule dates (weekly, monthly, or both).
|
|
140
|
+
* @param {Date} date - The date for which to process intervals.
|
|
141
|
+
* @param {object} config - Configuration for schedule repetition.
|
|
142
|
+
* @param {boolean} config.inEveryWeek - Whether to repeat weekly.
|
|
143
|
+
* @param {boolean} config.inEveryMonth - Whether to repeat monthly.
|
|
144
|
+
* @param {Function} processDate - Callback function to process each date.
|
|
146
145
|
*/
|
|
147
|
-
|
|
146
|
+
_processScheduleDates(date, config, processDate) {
|
|
148
147
|
// Handle weekly schedules
|
|
149
|
-
if (
|
|
148
|
+
if (config.inEveryWeek && !config.inEveryMonth) {
|
|
150
149
|
let currentDate = new Date(date);
|
|
151
150
|
// Calculate the last day of the current month
|
|
152
151
|
const endOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
|
|
153
152
|
while (currentDate <= endOfMonth) {
|
|
154
|
-
|
|
155
|
-
const [startTime, endTime] = timeRange;
|
|
156
|
-
const intervalStart = new Date(currentDate);
|
|
157
|
-
intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
|
|
158
|
-
const intervalEnd = new Date(currentDate);
|
|
159
|
-
intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
|
|
160
|
-
// Add JSON string to Set for uniqueness
|
|
161
|
-
utcIntervals.add([
|
|
162
|
-
intervalStart.toISOString(),
|
|
163
|
-
intervalEnd.toISOString(),
|
|
164
|
-
]);
|
|
165
|
-
});
|
|
153
|
+
processDate(currentDate);
|
|
166
154
|
// Move to the next week
|
|
167
155
|
currentDate = this._addDays(currentDate, 7);
|
|
168
156
|
}
|
|
169
157
|
}
|
|
170
158
|
// Handle monthly schedules
|
|
171
|
-
if (
|
|
172
|
-
// Начальная дата
|
|
159
|
+
if (config.inEveryMonth && !config.inEveryWeek) {
|
|
173
160
|
const startDate = new Date(date);
|
|
174
|
-
// Определяем день месяца начальной даты
|
|
175
161
|
const targetDayOfMonth = startDate.getUTCDate();
|
|
176
|
-
// Количество месяцев, на которые нужно повторить
|
|
177
162
|
const numberOfMonths = 12;
|
|
178
163
|
for (let i = 0; i < numberOfMonths; i++) {
|
|
179
164
|
const currentDate = new Date(startDate);
|
|
@@ -184,26 +169,13 @@ class SyncModules {
|
|
|
184
169
|
if (currentDate.getUTCMonth() !== (startDate.getUTCMonth() + i) % 12) {
|
|
185
170
|
continue; // Skip this month if exceeded
|
|
186
171
|
}
|
|
187
|
-
|
|
188
|
-
const [startTime, endTime] = timeRange;
|
|
189
|
-
const intervalStart = new Date(currentDate);
|
|
190
|
-
intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
|
|
191
|
-
const intervalEnd = new Date(currentDate);
|
|
192
|
-
intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
|
|
193
|
-
utcIntervals.add([
|
|
194
|
-
intervalStart.toISOString(),
|
|
195
|
-
intervalEnd.toISOString(),
|
|
196
|
-
]);
|
|
197
|
-
});
|
|
172
|
+
processDate(currentDate);
|
|
198
173
|
}
|
|
199
174
|
}
|
|
200
175
|
// Handle both weekly and monthly schedules
|
|
201
|
-
if (
|
|
202
|
-
// Initial date
|
|
176
|
+
if (config.inEveryMonth && config.inEveryWeek) {
|
|
203
177
|
const startDate = new Date(date);
|
|
204
|
-
// Determine the day of the week
|
|
205
178
|
const targetDayOfWeek = startDate.getUTCDay();
|
|
206
|
-
// Number of months to repeat
|
|
207
179
|
const numberOfMonths = 12;
|
|
208
180
|
for (let i = 0; i < numberOfMonths; i++) {
|
|
209
181
|
const currentDate = new Date(startDate);
|
|
@@ -216,30 +188,50 @@ class SyncModules {
|
|
|
216
188
|
// Iterate over all target days of the week in the current month
|
|
217
189
|
while (currentDate.getUTCMonth() ===
|
|
218
190
|
(startDate.getUTCMonth() + i) % 12) {
|
|
219
|
-
|
|
220
|
-
const [startTime, endTime] = timeRange;
|
|
221
|
-
const intervalStart = new Date(currentDate);
|
|
222
|
-
intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
|
|
223
|
-
const intervalEnd = new Date(currentDate);
|
|
224
|
-
intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
|
|
225
|
-
utcIntervals.add([
|
|
226
|
-
intervalStart.toISOString(),
|
|
227
|
-
intervalEnd.toISOString(),
|
|
228
|
-
]);
|
|
229
|
-
});
|
|
191
|
+
processDate(currentDate);
|
|
230
192
|
// Move to the next week (same day of the week)
|
|
231
193
|
currentDate.setUTCDate(currentDate.getUTCDate() + 7);
|
|
232
194
|
}
|
|
233
195
|
}
|
|
234
196
|
}
|
|
235
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Generates intervals for a specific date based on a schedule.
|
|
200
|
+
* @param {Date} date - The date for which to generate intervals.
|
|
201
|
+
* @param {object} schedule - The schedule defining the intervals.
|
|
202
|
+
* @param {boolean} schedule.inEveryWeek - The number of weeks between intervals.
|
|
203
|
+
* @param {any[]} schedule.times - The times for each interval.
|
|
204
|
+
* @param {boolean} schedule.inEveryMonth - The month intervals for each interval.
|
|
205
|
+
* @param {Set<Array<string>>} utcIntervals - A set to store unique intervals.
|
|
206
|
+
*/
|
|
207
|
+
_generateIntervalsForDate(date, schedule, utcIntervals) {
|
|
208
|
+
this._processScheduleDates(date, schedule, (currentDate) => {
|
|
209
|
+
schedule.times.forEach((timeRange) => {
|
|
210
|
+
const [startTime, endTime] = timeRange;
|
|
211
|
+
const intervalStart = new Date(currentDate);
|
|
212
|
+
intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
|
|
213
|
+
const intervalEnd = new Date(currentDate);
|
|
214
|
+
intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
|
|
215
|
+
utcIntervals.add([
|
|
216
|
+
intervalStart.toISOString(),
|
|
217
|
+
intervalEnd.toISOString(),
|
|
218
|
+
]);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
236
222
|
/**
|
|
237
223
|
* Adds time intervals to schedules.
|
|
238
224
|
* @param {any[]} schedules - The schedules to process.
|
|
239
225
|
* @returns {any} Schedules with added time intervals.
|
|
240
226
|
*/
|
|
241
227
|
_addTimeIntervalsToSchedules(schedules) {
|
|
242
|
-
schedules.forEach((scheduleGroup) => {
|
|
228
|
+
schedules === null || schedules === void 0 ? void 0 : schedules.forEach((scheduleGroup) => {
|
|
229
|
+
// Skip if scheduleGroup.values is not an array
|
|
230
|
+
if (!scheduleGroup ||
|
|
231
|
+
!scheduleGroup.values ||
|
|
232
|
+
!Array.isArray(scheduleGroup.values)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
243
235
|
scheduleGroup.values.forEach((schedule) => {
|
|
244
236
|
const utcIntervals = new Set();
|
|
245
237
|
const startDate = new Date(schedule.dates[0]);
|
|
@@ -294,48 +286,7 @@ class SyncModules {
|
|
|
294
286
|
}
|
|
295
287
|
});
|
|
296
288
|
};
|
|
297
|
-
|
|
298
|
-
if (interval.inEveryWeek && !interval.inEveryMonth) {
|
|
299
|
-
let currentDate = new Date(date);
|
|
300
|
-
const endOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
|
|
301
|
-
while (currentDate <= endOfMonth) {
|
|
302
|
-
generateTimeSlotsForDate(currentDate);
|
|
303
|
-
currentDate = this._addDays(currentDate, 7);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
// Handle monthly schedules
|
|
307
|
-
if (interval.inEveryMonth && !interval.inEveryWeek) {
|
|
308
|
-
const startDate = new Date(date);
|
|
309
|
-
const targetDayOfMonth = startDate.getUTCDate();
|
|
310
|
-
const numberOfMonths = 12;
|
|
311
|
-
for (let i = 0; i < numberOfMonths; i++) {
|
|
312
|
-
const currentDate = new Date(startDate);
|
|
313
|
-
currentDate.setUTCMonth(currentDate.getUTCMonth() + i);
|
|
314
|
-
currentDate.setUTCDate(targetDayOfMonth);
|
|
315
|
-
if (currentDate.getUTCMonth() !== (startDate.getUTCMonth() + i) % 12) {
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
generateTimeSlotsForDate(currentDate);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
// Handle both weekly and monthly schedules
|
|
322
|
-
if (interval.inEveryMonth && interval.inEveryWeek) {
|
|
323
|
-
const startDate = new Date(date);
|
|
324
|
-
const targetDayOfWeek = startDate.getUTCDay();
|
|
325
|
-
const numberOfMonths = 12;
|
|
326
|
-
for (let i = 0; i < numberOfMonths; i++) {
|
|
327
|
-
const currentDate = new Date(startDate);
|
|
328
|
-
currentDate.setUTCMonth(currentDate.getUTCMonth() + i);
|
|
329
|
-
currentDate.setUTCDate(1);
|
|
330
|
-
const daysUntilTargetDay = (targetDayOfWeek - currentDate.getUTCDay() + 7) % 7;
|
|
331
|
-
currentDate.setUTCDate(currentDate.getUTCDate() + daysUntilTargetDay);
|
|
332
|
-
while (currentDate.getUTCMonth() ===
|
|
333
|
-
(startDate.getUTCMonth() + i) % 12) {
|
|
334
|
-
generateTimeSlotsForDate(currentDate);
|
|
335
|
-
currentDate.setUTCDate(currentDate.getUTCDate() + 7);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
289
|
+
this._processScheduleDates(date, interval, generateTimeSlotsForDate);
|
|
339
290
|
}
|
|
340
291
|
/**
|
|
341
292
|
* Adds time intervals to form schedules (different structure).
|
package/dist/base/utils.d.ts
CHANGED
|
@@ -27,8 +27,11 @@ type Types = 'product' | 'error_page' | 'catalog_page' | 'product_preview' | 'si
|
|
|
27
27
|
* errors: {
|
|
28
28
|
* isShell: true,
|
|
29
29
|
* customErrors: {
|
|
30
|
+
* '400': badRequestFunction,
|
|
30
31
|
* '404': notFoundFunction,
|
|
31
|
-
* '
|
|
32
|
+
* '429': rateLimitFunction,
|
|
33
|
+
* '500': serverErrorFunction,
|
|
34
|
+
* '503': serviceUnavailableFunction
|
|
32
35
|
* }
|
|
33
36
|
* }
|
|
34
37
|
* }
|
|
@@ -38,6 +41,11 @@ interface IConfig {
|
|
|
38
41
|
token?: string;
|
|
39
42
|
langCode?: string;
|
|
40
43
|
traficLimit?: boolean;
|
|
44
|
+
validation?: {
|
|
45
|
+
enabled?: boolean;
|
|
46
|
+
strictMode?: boolean;
|
|
47
|
+
logErrors?: boolean;
|
|
48
|
+
};
|
|
41
49
|
auth?: {
|
|
42
50
|
customAuth?: boolean;
|
|
43
51
|
refreshToken?: string;
|
|
@@ -51,7 +59,11 @@ interface IConfig {
|
|
|
51
59
|
401?: (data?: IError) => any;
|
|
52
60
|
403?: (data?: IError) => any;
|
|
53
61
|
404?: (data?: IError) => any;
|
|
62
|
+
429?: (data?: IError) => any;
|
|
54
63
|
500?: (data?: IError) => any;
|
|
64
|
+
502?: (data?: IError) => any;
|
|
65
|
+
503?: (data?: IError) => any;
|
|
66
|
+
504?: (data?: IError) => any;
|
|
55
67
|
};
|
|
56
68
|
};
|
|
57
69
|
}
|
|
@@ -136,6 +148,33 @@ interface IError {
|
|
|
136
148
|
timestamp: string;
|
|
137
149
|
[key: string]: any;
|
|
138
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* @interface IHttpHeaders
|
|
153
|
+
* @property {string} [Content-Type] - Content type header
|
|
154
|
+
* @property {string} [x-app-token] - App token header
|
|
155
|
+
* @property {string} [x-device-metadata] - Device metadata header
|
|
156
|
+
* @property {string} [Authorization] - Authorization header
|
|
157
|
+
* @description Interface for HTTP headers
|
|
158
|
+
*/
|
|
159
|
+
interface IHttpHeaders {
|
|
160
|
+
'Content-Type'?: string;
|
|
161
|
+
'x-app-token'?: string;
|
|
162
|
+
'x-device-metadata'?: string;
|
|
163
|
+
Authorization?: string;
|
|
164
|
+
[key: string]: string | undefined;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @interface IHttpOptions
|
|
168
|
+
* @property {string} method - HTTP method
|
|
169
|
+
* @property {IHttpHeaders} headers - HTTP headers
|
|
170
|
+
* @property {string | FormData | Blob} [body] - Request body
|
|
171
|
+
* @description Interface for HTTP request options
|
|
172
|
+
*/
|
|
173
|
+
interface IHttpOptions {
|
|
174
|
+
method: string;
|
|
175
|
+
headers: IHttpHeaders;
|
|
176
|
+
body?: string | FormData | Blob;
|
|
177
|
+
}
|
|
139
178
|
/**
|
|
140
179
|
* AttributeType
|
|
141
180
|
*/
|
|
@@ -148,4 +187,4 @@ type LangType = string | Array<string>;
|
|
|
148
187
|
* LocalizeType
|
|
149
188
|
*/
|
|
150
189
|
type LocalizeType = ILocalizeInfos | ILocalizeInfo;
|
|
151
|
-
export type { AttributeType, IAttributes, IAttributeValues, IConfig, IError, ILocalizeInfo, ILocalizeInfos, LangType, LocalizeType, Types, };
|
|
190
|
+
export type { AttributeType, IAttributes, IAttributeValues, IConfig, IError, IHttpHeaders, IHttpOptions, ILocalizeInfo, ILocalizeInfos, LangType, LocalizeType, Types, };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Common validation schemas for API responses
|
|
4
|
+
* @description Base schemas that can be reused across different modules
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Error response schema
|
|
8
|
+
*/
|
|
9
|
+
export declare const ErrorSchema: z.ZodObject<{
|
|
10
|
+
statusCode: z.ZodNumber;
|
|
11
|
+
message: z.ZodString;
|
|
12
|
+
localizeMessage: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
/**
|
|
15
|
+
* Localize info schema
|
|
16
|
+
*/
|
|
17
|
+
export declare const LocalizeInfoSchema: z.ZodObject<{
|
|
18
|
+
title: z.ZodString;
|
|
19
|
+
content: z.ZodOptional<z.ZodString>;
|
|
20
|
+
menuTitle: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/**
|
|
23
|
+
* Attribute schema
|
|
24
|
+
*/
|
|
25
|
+
export declare const AttributeSchema: z.ZodObject<{
|
|
26
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
marker: z.ZodString;
|
|
28
|
+
type: z.ZodString;
|
|
29
|
+
isVisible: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
isRequired: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
+
position: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
localizeInfos: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
33
|
+
title: z.ZodString;
|
|
34
|
+
content: z.ZodOptional<z.ZodString>;
|
|
35
|
+
menuTitle: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>>>;
|
|
37
|
+
value: z.ZodOptional<z.ZodAny>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
/**
|
|
40
|
+
* User entity schema
|
|
41
|
+
*/
|
|
42
|
+
export declare const UserEntitySchema: z.ZodObject<{
|
|
43
|
+
id: z.ZodNumber;
|
|
44
|
+
identifier: z.ZodOptional<z.ZodString>;
|
|
45
|
+
email: z.ZodOptional<z.ZodString>;
|
|
46
|
+
phoneMask: z.ZodOptional<z.ZodString>;
|
|
47
|
+
phoneCode: z.ZodOptional<z.ZodString>;
|
|
48
|
+
phoneNumber: z.ZodOptional<z.ZodString>;
|
|
49
|
+
statusMarker: z.ZodOptional<z.ZodString>;
|
|
50
|
+
formData: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
|
|
51
|
+
total: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
52
|
+
authProviderIdentifier: z.ZodOptional<z.ZodString>;
|
|
53
|
+
formIdentifier: z.ZodOptional<z.ZodString>;
|
|
54
|
+
groups: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
55
|
+
state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
56
|
+
moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
/**
|
|
59
|
+
* Auth entity schema
|
|
60
|
+
* API returns only accessToken and refreshToken
|
|
61
|
+
* userIdentifier and authProviderIdentifier are optional legacy fields
|
|
62
|
+
*/
|
|
63
|
+
export declare const AuthEntitySchema: z.ZodObject<{
|
|
64
|
+
accessToken: z.ZodString;
|
|
65
|
+
refreshToken: z.ZodString;
|
|
66
|
+
userIdentifier: z.ZodOptional<z.ZodString>;
|
|
67
|
+
authProviderIdentifier: z.ZodOptional<z.ZodString>;
|
|
68
|
+
user: z.ZodOptional<z.ZodObject<{
|
|
69
|
+
id: z.ZodNumber;
|
|
70
|
+
identifier: z.ZodOptional<z.ZodString>;
|
|
71
|
+
email: z.ZodOptional<z.ZodString>;
|
|
72
|
+
phoneMask: z.ZodOptional<z.ZodString>;
|
|
73
|
+
phoneCode: z.ZodOptional<z.ZodString>;
|
|
74
|
+
phoneNumber: z.ZodOptional<z.ZodString>;
|
|
75
|
+
statusMarker: z.ZodOptional<z.ZodString>;
|
|
76
|
+
formData: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
|
|
77
|
+
total: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
78
|
+
authProviderIdentifier: z.ZodOptional<z.ZodString>;
|
|
79
|
+
formIdentifier: z.ZodOptional<z.ZodString>;
|
|
80
|
+
groups: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
81
|
+
state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
82
|
+
moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
83
|
+
}, z.core.$strip>>;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
/**
|
|
86
|
+
* Paginated response schema factory
|
|
87
|
+
* @param {T} itemSchema - The schema for each item in the paginated response
|
|
88
|
+
* @returns {any} Paginated response schema
|
|
89
|
+
*/
|
|
90
|
+
export declare function createPaginatedSchema<T extends z.ZodTypeAny>(itemSchema: T): any;
|
|
91
|
+
/**
|
|
92
|
+
* Validation helper function
|
|
93
|
+
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
94
|
+
* @param {unknown} data - Data to validate
|
|
95
|
+
* @param {object} options - Validation options
|
|
96
|
+
* @param {boolean} options.strict - Whether to use strict mode
|
|
97
|
+
* @param {boolean} options.logErrors - Whether to log errors
|
|
98
|
+
* @returns {object} Validated data or error
|
|
99
|
+
*/
|
|
100
|
+
export declare function validateResponse<T>(schema: z.ZodSchema<T>, data: unknown, options?: {
|
|
101
|
+
strict?: boolean;
|
|
102
|
+
logErrors?: boolean;
|
|
103
|
+
}): {
|
|
104
|
+
success: true;
|
|
105
|
+
data: T;
|
|
106
|
+
} | {
|
|
107
|
+
success: false;
|
|
108
|
+
error: z.ZodError;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Safe validation helper - returns data even if validation fails
|
|
112
|
+
* Used when strict mode is disabled
|
|
113
|
+
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
114
|
+
* @param {unknown} data - Data to validate
|
|
115
|
+
* @param {boolean} logErrors - Whether to log errors
|
|
116
|
+
* @returns {T} Validated data or original data if validation fails in non-strict mode
|
|
117
|
+
*/
|
|
118
|
+
export declare function validateResponseSafe<T>(schema: z.ZodSchema<T>, data: unknown, logErrors?: boolean): T;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthEntitySchema = exports.UserEntitySchema = exports.AttributeSchema = exports.LocalizeInfoSchema = exports.ErrorSchema = void 0;
|
|
4
|
+
exports.createPaginatedSchema = createPaginatedSchema;
|
|
5
|
+
exports.validateResponse = validateResponse;
|
|
6
|
+
exports.validateResponseSafe = validateResponseSafe;
|
|
7
|
+
/* eslint-disable jsdoc/reject-any-type */
|
|
8
|
+
/* eslint-disable jsdoc/no-undefined-types */
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
/**
|
|
11
|
+
* Common validation schemas for API responses
|
|
12
|
+
* @description Base schemas that can be reused across different modules
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Error response schema
|
|
16
|
+
*/
|
|
17
|
+
exports.ErrorSchema = zod_1.z.object({
|
|
18
|
+
statusCode: zod_1.z.number(),
|
|
19
|
+
message: zod_1.z.string(),
|
|
20
|
+
localizeMessage: zod_1.z.string().optional(),
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Localize info schema
|
|
24
|
+
*/
|
|
25
|
+
exports.LocalizeInfoSchema = zod_1.z.object({
|
|
26
|
+
title: zod_1.z.string(),
|
|
27
|
+
content: zod_1.z.string().optional(),
|
|
28
|
+
menuTitle: zod_1.z.string().optional(),
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Attribute schema
|
|
32
|
+
*/
|
|
33
|
+
exports.AttributeSchema = zod_1.z.object({
|
|
34
|
+
id: zod_1.z.number().optional(),
|
|
35
|
+
marker: zod_1.z.string(),
|
|
36
|
+
type: zod_1.z.string(),
|
|
37
|
+
isVisible: zod_1.z.boolean().optional(),
|
|
38
|
+
isRequired: zod_1.z.boolean().optional(),
|
|
39
|
+
position: zod_1.z.number().optional(),
|
|
40
|
+
localizeInfos: zod_1.z.record(zod_1.z.string(), exports.LocalizeInfoSchema).optional(),
|
|
41
|
+
value: zod_1.z.any().optional(),
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* User entity schema
|
|
45
|
+
*/
|
|
46
|
+
exports.UserEntitySchema = zod_1.z.object({
|
|
47
|
+
id: zod_1.z.number(),
|
|
48
|
+
identifier: zod_1.z.string().optional(),
|
|
49
|
+
email: zod_1.z.string().email().optional(),
|
|
50
|
+
phoneMask: zod_1.z.string().optional(),
|
|
51
|
+
phoneCode: zod_1.z.string().optional(),
|
|
52
|
+
phoneNumber: zod_1.z.string().optional(),
|
|
53
|
+
statusMarker: zod_1.z.string().optional(),
|
|
54
|
+
formData: zod_1.z
|
|
55
|
+
.union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())])
|
|
56
|
+
.optional(),
|
|
57
|
+
total: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
|
|
58
|
+
authProviderIdentifier: zod_1.z.string().optional(),
|
|
59
|
+
formIdentifier: zod_1.z.string().optional(),
|
|
60
|
+
groups: zod_1.z.array(zod_1.z.number()).optional(),
|
|
61
|
+
state: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
|
|
62
|
+
moduleFormConfigs: zod_1.z.array(zod_1.z.any()).optional(),
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Auth entity schema
|
|
66
|
+
* API returns only accessToken and refreshToken
|
|
67
|
+
* userIdentifier and authProviderIdentifier are optional legacy fields
|
|
68
|
+
*/
|
|
69
|
+
exports.AuthEntitySchema = zod_1.z.object({
|
|
70
|
+
accessToken: zod_1.z.string(),
|
|
71
|
+
refreshToken: zod_1.z.string(),
|
|
72
|
+
userIdentifier: zod_1.z.string().optional(),
|
|
73
|
+
authProviderIdentifier: zod_1.z.string().optional(),
|
|
74
|
+
user: exports.UserEntitySchema.optional(),
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Paginated response schema factory
|
|
78
|
+
* @param {T} itemSchema - The schema for each item in the paginated response
|
|
79
|
+
* @returns {any} Paginated response schema
|
|
80
|
+
*/
|
|
81
|
+
function createPaginatedSchema(itemSchema) {
|
|
82
|
+
return zod_1.z.object({
|
|
83
|
+
items: zod_1.z.array(itemSchema),
|
|
84
|
+
total: zod_1.z.number(),
|
|
85
|
+
page: zod_1.z.number().optional(),
|
|
86
|
+
limit: zod_1.z.number().optional(),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Validation helper function
|
|
91
|
+
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
92
|
+
* @param {unknown} data - Data to validate
|
|
93
|
+
* @param {object} options - Validation options
|
|
94
|
+
* @param {boolean} options.strict - Whether to use strict mode
|
|
95
|
+
* @param {boolean} options.logErrors - Whether to log errors
|
|
96
|
+
* @returns {object} Validated data or error
|
|
97
|
+
*/
|
|
98
|
+
function validateResponse(schema, data, options) {
|
|
99
|
+
try {
|
|
100
|
+
const validated = schema.parse(data);
|
|
101
|
+
return { success: true, data: validated };
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
105
|
+
if (options === null || options === void 0 ? void 0 : options.logErrors) {
|
|
106
|
+
// eslint-disable-next-line no-undef, no-console
|
|
107
|
+
console.error('Validation error:', {
|
|
108
|
+
errors: error.issues,
|
|
109
|
+
data,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return { success: false, error };
|
|
113
|
+
}
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Safe validation helper - returns data even if validation fails
|
|
119
|
+
* Used when strict mode is disabled
|
|
120
|
+
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
121
|
+
* @param {unknown} data - Data to validate
|
|
122
|
+
* @param {boolean} logErrors - Whether to log errors
|
|
123
|
+
* @returns {T} Validated data or original data if validation fails in non-strict mode
|
|
124
|
+
*/
|
|
125
|
+
function validateResponseSafe(schema, data, logErrors = false) {
|
|
126
|
+
const result = validateResponse(schema, data, { logErrors });
|
|
127
|
+
if (result.success) {
|
|
128
|
+
return result.data;
|
|
129
|
+
}
|
|
130
|
+
// Return original data if validation fails in non-strict mode
|
|
131
|
+
return data;
|
|
132
|
+
}
|
package/dist/blocks/blocksApi.js
CHANGED
|
@@ -3,7 +3,9 @@ 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 @typescript-eslint/no-explicit-any */
|
|
6
7
|
const asyncModules_1 = __importDefault(require("../base/asyncModules"));
|
|
8
|
+
const blocksSchemas_1 = require("./blocksSchemas");
|
|
7
9
|
/**
|
|
8
10
|
* Controllers for working with blocks.
|
|
9
11
|
* @handle /api/content/blocks
|
|
@@ -32,15 +34,14 @@ class BlocksApi extends asyncModules_1.default {
|
|
|
32
34
|
*/
|
|
33
35
|
async getBlocks(type = '', langCode = this.state.lang, offset = 0, limit = 30) {
|
|
34
36
|
const response = await this._fetchPost(`?langCode=${langCode}&type=${type}&offset=${offset}&limit=${limit}`);
|
|
37
|
+
// Validate response if validation is enabled
|
|
38
|
+
const validated = this._validateResponse(response, blocksSchemas_1.BlocksResponseSchema);
|
|
35
39
|
if (!this.state.traficLimit) {
|
|
36
|
-
const normalizeResponse = this._normalizeData(
|
|
37
|
-
await Promise.all(
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
normalizeResponse.items.map(async (block) => {
|
|
40
|
+
const normalizeResponse = this._normalizeData(validated);
|
|
41
|
+
await Promise.all(normalizeResponse.items.map(async (block) => {
|
|
40
42
|
const customSettings = block.customSettings;
|
|
41
43
|
if (customSettings &&
|
|
42
|
-
|
|
43
|
-
customSettings.hasOwnProperty('productConfig')) {
|
|
44
|
+
Object.prototype.hasOwnProperty.call(customSettings, 'productConfig')) {
|
|
44
45
|
if (customSettings.productConfig.countElementsPerRow)
|
|
45
46
|
block.countElementsPerRow =
|
|
46
47
|
+customSettings.productConfig.countElementsPerRow;
|
|
@@ -73,7 +74,7 @@ class BlocksApi extends asyncModules_1.default {
|
|
|
73
74
|
}));
|
|
74
75
|
return this._normalizeData(normalizeResponse);
|
|
75
76
|
}
|
|
76
|
-
return this._normalizeData(
|
|
77
|
+
return this._normalizeData(validated);
|
|
77
78
|
}
|
|
78
79
|
/**
|
|
79
80
|
* Get block by marker.
|
|
@@ -88,10 +89,12 @@ class BlocksApi extends asyncModules_1.default {
|
|
|
88
89
|
*/
|
|
89
90
|
async getBlockByMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
90
91
|
const response = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
|
|
91
|
-
|
|
92
|
+
// Validate response if validation is enabled
|
|
93
|
+
const validated = this._validateResponse(response, blocksSchemas_1.BlockEntitySchema);
|
|
94
|
+
const normalizeResponse = this._normalizeData(validated);
|
|
92
95
|
const customSettings = normalizeResponse.customSettings;
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
if (customSettings &&
|
|
97
|
+
Object.prototype.hasOwnProperty.call(customSettings, 'productConfig')) {
|
|
95
98
|
if (customSettings.productConfig.countElementsPerRow)
|
|
96
99
|
normalizeResponse.countElementsPerRow =
|
|
97
100
|
+customSettings.productConfig.countElementsPerRow;
|
|
@@ -173,7 +176,9 @@ class BlocksApi extends asyncModules_1.default {
|
|
|
173
176
|
*/
|
|
174
177
|
async searchBlock(name, langCode = this.state.lang) {
|
|
175
178
|
const result = await this._fetchGet(`/quick/search?langCode=${langCode}&name=${name}`);
|
|
176
|
-
|
|
179
|
+
// Validate response if validation is enabled
|
|
180
|
+
const validated = this._validateResponse(result, blocksSchemas_1.SearchBlocksResponseSchema);
|
|
181
|
+
return validated;
|
|
177
182
|
}
|
|
178
183
|
}
|
|
179
184
|
exports.default = BlocksApi;
|
|
@@ -168,5 +168,5 @@ interface ISearchBlock {
|
|
|
168
168
|
* @type {BlockType}
|
|
169
169
|
* @description This type defines the possible values for block types used in the system.
|
|
170
170
|
*/
|
|
171
|
-
type BlockType = 'product' | 'error_page' | 'catalog_page' | 'product_preview' | 'similar_products_block' | 'product_block' | 'form' | 'common_page' | 'common_block' | 'order' | 'service' | 'none';
|
|
171
|
+
type BlockType = 'product' | 'error_page' | 'catalog_page' | 'product_preview' | 'similar_products_block' | 'product_block' | 'form' | 'common_page' | 'common_block' | 'order' | 'service' | 'external_page' | 'discount' | 'none';
|
|
172
172
|
export type { BlockType, IBlockEntity, IBlocks, IBlocksResponse, ISearchBlock };
|