oneentry 1.0.159 → 1.0.161
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 +2 -0
- package/changelog.md +56 -1
- package/dist/admins/adminsApi.d.ts +15 -1
- package/dist/admins/adminsApi.js +29 -0
- package/dist/admins/adminsInterfaces.d.ts +37 -1
- package/dist/base/lazySchema.d.ts +15 -0
- package/dist/base/lazySchema.js +20 -0
- package/dist/discounts/discountsApi.d.ts +14 -1
- package/dist/discounts/discountsApi.js +21 -0
- package/dist/discounts/discountsInterfaces.d.ts +27 -1
- package/dist/filters/filtersInterfaces.d.ts +2 -2
- package/dist/filters/filtersSchemas.d.ts +1 -1
- package/dist/filters/filtersSchemas.js +4 -1
- package/dist/forms-data/formsDataApi.d.ts +14 -1
- package/dist/forms-data/formsDataApi.js +21 -0
- package/dist/forms-data/formsDataInterfaces.d.ts +74 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/orders/ordersApi.d.ts +15 -1
- package/dist/orders/ordersApi.js +22 -0
- package/dist/orders/ordersInterfaces.d.ts +27 -1
- package/dist/pages/pagesApi.d.ts +14 -1
- package/dist/pages/pagesApi.js +21 -0
- package/dist/pages/pagesInterfaces.d.ts +38 -1
- package/dist/payments/paymentsInterfaces.d.ts +2 -2
- package/dist/products/productsInterfaces.d.ts +1 -1
- package/dist/search/searchApi.d.ts +35 -0
- package/dist/search/searchApi.js +86 -0
- package/dist/search/searchInterfaces.d.ts +94 -0
- package/dist/search/searchInterfaces.js +2 -0
- package/dist/search/searchSchemas.d.ts +73 -0
- package/dist/search/searchSchemas.js +44 -0
- package/dist/templates-preview/templatesPreviewInterfaces.d.ts +0 -2
- package/dist/templates-preview/templatesPreviewSchemas.d.ts +0 -2
- package/dist/templates-preview/templatesPreviewSchemas.js +0 -1
- package/dist/types.d.ts +35 -0
- package/dist/types.js +2 -0
- package/dist/users/usersApi.d.ts +15 -1
- package/dist/users/usersApi.js +22 -0
- package/dist/users/usersInterfaces.d.ts +39 -1
- package/dist/web-socket/lazySocket.d.ts +18 -0
- package/dist/web-socket/lazySocket.js +70 -0
- package/esm/admins/adminsApi.d.ts +66 -0
- package/esm/admins/adminsApi.js +90 -0
- package/esm/admins/adminsInterfaces.d.ts +137 -0
- package/esm/admins/adminsInterfaces.js +1 -0
- package/esm/admins/adminsSchemas.d.ts +48 -0
- package/esm/admins/adminsSchemas.js +31 -0
- package/esm/attribute-sets/attributeSetsApi.d.ts +67 -0
- package/esm/attribute-sets/attributeSetsApi.js +97 -0
- package/esm/attribute-sets/attributeSetsInterfaces.d.ts +285 -0
- package/esm/attribute-sets/attributeSetsInterfaces.js +1 -0
- package/esm/attribute-sets/attributeSetsSchemas.d.ts +84 -0
- package/esm/attribute-sets/attributeSetsSchemas.js +66 -0
- package/esm/auth-provider/authProviderApi.d.ts +262 -0
- package/esm/auth-provider/authProviderApi.js +362 -0
- package/esm/auth-provider/authProviderSchemas.d.ts +124 -0
- package/esm/auth-provider/authProviderSchemas.js +92 -0
- package/esm/auth-provider/authProvidersInterfaces.d.ts +430 -0
- package/esm/auth-provider/authProvidersInterfaces.js +1 -0
- package/esm/base/asyncModules.d.ts +123 -0
- package/esm/base/asyncModules.js +382 -0
- package/esm/base/lazySchema.d.ts +15 -0
- package/esm/base/lazySchema.js +17 -0
- package/esm/base/stateModule.d.ts +35 -0
- package/esm/base/stateModule.js +51 -0
- package/esm/base/syncModules.d.ts +245 -0
- package/esm/base/syncModules.js +555 -0
- package/esm/base/timeIntervals.d.ts +95 -0
- package/esm/base/timeIntervals.js +317 -0
- package/esm/base/utils.d.ts +354 -0
- package/esm/base/utils.js +1 -0
- package/esm/base/validation.d.ts +98 -0
- package/esm/base/validation.js +118 -0
- package/esm/blocks/blocksApi.d.ts +252 -0
- package/esm/blocks/blocksApi.js +394 -0
- package/esm/blocks/blocksInterfaces.d.ts +361 -0
- package/esm/blocks/blocksInterfaces.js +1 -0
- package/esm/blocks/blocksSchemas.d.ts +213 -0
- package/esm/blocks/blocksSchemas.js +40 -0
- package/esm/discounts/discountsApi.d.ts +94 -0
- package/esm/discounts/discountsApi.js +136 -0
- package/esm/discounts/discountsInterfaces.d.ts +293 -0
- package/esm/discounts/discountsInterfaces.js +1 -0
- package/esm/events/eventsApi.d.ts +108 -0
- package/esm/events/eventsApi.js +141 -0
- package/esm/events/eventsInterfaces.d.ts +176 -0
- package/esm/events/eventsInterfaces.js +1 -0
- package/esm/file-uploading/fileUploadingApi.d.ts +91 -0
- package/esm/file-uploading/fileUploadingApi.js +127 -0
- package/esm/file-uploading/fileUploadingInterfaces.d.ts +116 -0
- package/esm/file-uploading/fileUploadingInterfaces.js +1 -0
- package/esm/file-uploading/fileUploadingSchemas.d.ts +24 -0
- package/esm/file-uploading/fileUploadingSchemas.js +19 -0
- package/esm/filters/filtersApi.d.ts +32 -0
- package/esm/filters/filtersApi.js +36 -0
- package/esm/filters/filtersInterfaces.d.ts +56 -0
- package/esm/filters/filtersInterfaces.js +1 -0
- package/esm/filters/filtersSchemas.d.ts +32 -0
- package/esm/filters/filtersSchemas.js +29 -0
- package/esm/forms/formsApi.d.ts +44 -0
- package/esm/forms/formsApi.js +54 -0
- package/esm/forms/formsInterfaces.d.ts +237 -0
- package/esm/forms/formsInterfaces.js +1 -0
- package/esm/forms/formsSchemas.d.ts +56 -0
- package/esm/forms/formsSchemas.js +32 -0
- package/esm/forms-data/formsDataApi.d.ts +124 -0
- package/esm/forms-data/formsDataApi.js +210 -0
- package/esm/forms-data/formsDataInterfaces.d.ts +670 -0
- package/esm/forms-data/formsDataInterfaces.js +1 -0
- package/esm/forms-data/formsDataSchemas.d.ts +107 -0
- package/esm/forms-data/formsDataSchemas.js +83 -0
- package/esm/general-types/generalTypesApi.d.ts +29 -0
- package/esm/general-types/generalTypesApi.js +34 -0
- package/esm/general-types/generalTypesInterfaces.d.ts +29 -0
- package/esm/general-types/generalTypesInterfaces.js +1 -0
- package/esm/general-types/generalTypesSchemas.d.ts +68 -0
- package/esm/general-types/generalTypesSchemas.js +42 -0
- package/esm/index.d.ts +143 -0
- package/esm/index.js +124 -0
- package/esm/integration-collections/integrationCollectionsApi.d.ts +172 -0
- package/esm/integration-collections/integrationCollectionsApi.js +224 -0
- package/esm/integration-collections/integrationCollectionsInterfaces.d.ts +317 -0
- package/esm/integration-collections/integrationCollectionsInterfaces.js +1 -0
- package/esm/integration-collections/integrationCollectionsSchemas.d.ts +84 -0
- package/esm/integration-collections/integrationCollectionsSchemas.js +60 -0
- package/esm/locales/localesApi.d.ts +28 -0
- package/esm/locales/localesApi.js +33 -0
- package/esm/locales/localesInterfaces.d.ts +40 -0
- package/esm/locales/localesInterfaces.js +1 -0
- package/esm/locales/localesSchemas.d.ts +32 -0
- package/esm/locales/localesSchemas.js +23 -0
- package/esm/menus/menusApi.d.ts +30 -0
- package/esm/menus/menusApi.js +35 -0
- package/esm/menus/menusInterfaces.d.ts +87 -0
- package/esm/menus/menusInterfaces.js +2 -0
- package/esm/menus/menusSchemas.d.ts +16 -0
- package/esm/menus/menusSchemas.js +25 -0
- package/esm/orders/ordersApi.d.ts +213 -0
- package/esm/orders/ordersApi.js +288 -0
- package/esm/orders/ordersInterfaces.d.ts +763 -0
- package/esm/orders/ordersInterfaces.js +1 -0
- package/esm/orders/ordersSchemas.d.ts +312 -0
- package/esm/orders/ordersSchemas.js +171 -0
- package/esm/package.json +4 -0
- package/esm/pages/pagesApi.d.ts +173 -0
- package/esm/pages/pagesApi.js +414 -0
- package/esm/pages/pagesInterfaces.d.ts +344 -0
- package/esm/pages/pagesInterfaces.js +1 -0
- package/esm/pages/pagesSchemas.d.ts +121 -0
- package/esm/pages/pagesSchemas.js +60 -0
- package/esm/payments/paymentsApi.d.ts +88 -0
- package/esm/payments/paymentsApi.js +122 -0
- package/esm/payments/paymentsInterfaces.d.ts +189 -0
- package/esm/payments/paymentsInterfaces.js +1 -0
- package/esm/payments/paymentsSchemas.d.ts +94 -0
- package/esm/payments/paymentsSchemas.js +53 -0
- package/esm/product-statuses/productStatusesApi.d.ts +50 -0
- package/esm/product-statuses/productStatusesApi.js +68 -0
- package/esm/product-statuses/productStatusesInterfaces.d.ts +62 -0
- package/esm/product-statuses/productStatusesInterfaces.js +1 -0
- package/esm/product-statuses/productStatusesSchemas.d.ts +34 -0
- package/esm/product-statuses/productStatusesSchemas.js +27 -0
- package/esm/products/productsApi.d.ts +366 -0
- package/esm/products/productsApi.js +468 -0
- package/esm/products/productsInterfaces.d.ts +723 -0
- package/esm/products/productsInterfaces.js +1 -0
- package/esm/products/productsSchemas.d.ts +234 -0
- package/esm/products/productsSchemas.js +121 -0
- package/esm/search/searchApi.d.ts +35 -0
- package/esm/search/searchApi.js +47 -0
- package/esm/search/searchInterfaces.d.ts +94 -0
- package/esm/search/searchInterfaces.js +1 -0
- package/esm/search/searchSchemas.d.ts +73 -0
- package/esm/search/searchSchemas.js +41 -0
- package/esm/sitemap/sitemapApi.d.ts +37 -0
- package/esm/sitemap/sitemapApi.js +41 -0
- package/esm/sitemap/sitemapInterfaces.d.ts +51 -0
- package/esm/sitemap/sitemapInterfaces.js +1 -0
- package/esm/subscriptions/subscriptionsApi.d.ts +74 -0
- package/esm/subscriptions/subscriptionsApi.js +90 -0
- package/esm/subscriptions/subscriptionsInterfaces.d.ts +111 -0
- package/esm/subscriptions/subscriptionsInterfaces.js +1 -0
- package/esm/subscriptions/subscriptionsSchemas.d.ts +46 -0
- package/esm/subscriptions/subscriptionsSchemas.js +38 -0
- package/esm/system/systemApi.d.ts +46 -0
- package/esm/system/systemApi.js +53 -0
- package/esm/system/systemInterfaces.d.ts +29 -0
- package/esm/system/systemInterfaces.js +1 -0
- package/esm/templates/templatesApi.d.ts +53 -0
- package/esm/templates/templatesApi.js +78 -0
- package/esm/templates/templatesInterfaces.d.ts +68 -0
- package/esm/templates/templatesInterfaces.js +1 -0
- package/esm/templates/templatesSchemas.d.ts +48 -0
- package/esm/templates/templatesSchemas.js +28 -0
- package/esm/templates-preview/templatesPreviewApi.d.ts +40 -0
- package/esm/templates-preview/templatesPreviewApi.js +50 -0
- package/esm/templates-preview/templatesPreviewInterfaces.d.ts +129 -0
- package/esm/templates-preview/templatesPreviewInterfaces.js +1 -0
- package/esm/templates-preview/templatesPreviewSchemas.d.ts +79 -0
- package/esm/templates-preview/templatesPreviewSchemas.js +43 -0
- package/esm/types.d.ts +35 -0
- package/esm/types.js +1 -0
- package/esm/user-activity/userActivityApi.d.ts +31 -0
- package/esm/user-activity/userActivityApi.js +37 -0
- package/esm/user-activity/userActivityInterfaces.d.ts +42 -0
- package/esm/user-activity/userActivityInterfaces.js +1 -0
- package/esm/users/usersApi.d.ts +249 -0
- package/esm/users/usersApi.js +312 -0
- package/esm/users/usersInterfaces.d.ts +419 -0
- package/esm/users/usersInterfaces.js +1 -0
- package/esm/users/usersSchemas.d.ts +72 -0
- package/esm/users/usersSchemas.js +55 -0
- package/esm/web-socket/lazySocket.d.ts +18 -0
- package/esm/web-socket/lazySocket.js +67 -0
- package/esm/web-socket/wsApi.d.ts +27 -0
- package/esm/web-socket/wsApi.js +43 -0
- package/esm/web-socket/wsInterfaces.d.ts +16 -0
- package/esm/web-socket/wsInterfaces.js +1 -0
- package/package.json +47 -2
- package/types.d.ts +1 -0
- package/types.js +1 -0
|
@@ -0,0 +1,98 @@
|
|
|
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.ZodString;
|
|
45
|
+
authProviderIdentifier: z.ZodString;
|
|
46
|
+
formData: z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>;
|
|
47
|
+
formIdentifier: z.ZodString;
|
|
48
|
+
total: z.ZodString;
|
|
49
|
+
groups: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
50
|
+
state: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
51
|
+
moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
52
|
+
rating: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
/**
|
|
55
|
+
* Auth entity schema
|
|
56
|
+
* API returns only accessToken and refreshToken
|
|
57
|
+
* userIdentifier and authProviderIdentifier are optional legacy fields
|
|
58
|
+
*/
|
|
59
|
+
export declare const AuthEntitySchema: z.ZodObject<{
|
|
60
|
+
userIdentifier: z.ZodString;
|
|
61
|
+
authProviderIdentifier: z.ZodString;
|
|
62
|
+
accessToken: z.ZodString;
|
|
63
|
+
refreshToken: z.ZodString;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
/**
|
|
66
|
+
* Paginated response schema factory
|
|
67
|
+
* @param {T} itemSchema - The schema for each item in the paginated response
|
|
68
|
+
* @returns {any} Paginated response schema
|
|
69
|
+
*/
|
|
70
|
+
export declare function createPaginatedSchema<T extends z.ZodTypeAny>(itemSchema: T): any;
|
|
71
|
+
/**
|
|
72
|
+
* Validation helper function
|
|
73
|
+
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
74
|
+
* @param {unknown} data - Data to validate
|
|
75
|
+
* @param {object} options - Validation options
|
|
76
|
+
* @param {boolean} options.strict - Whether to use strict mode
|
|
77
|
+
* @param {boolean} options.logErrors - Whether to log errors
|
|
78
|
+
* @returns {object} Validated data or error
|
|
79
|
+
*/
|
|
80
|
+
export declare function validateResponse<T>(schema: z.ZodSchema<T>, data: unknown, options?: {
|
|
81
|
+
strict?: boolean;
|
|
82
|
+
logErrors?: boolean;
|
|
83
|
+
}): {
|
|
84
|
+
success: true;
|
|
85
|
+
data: T;
|
|
86
|
+
} | {
|
|
87
|
+
success: false;
|
|
88
|
+
error: z.ZodError;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Safe validation helper - returns data even if validation fails
|
|
92
|
+
* Used when strict mode is disabled
|
|
93
|
+
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
94
|
+
* @param {unknown} data - Data to validate
|
|
95
|
+
* @param {boolean} logErrors - Whether to log errors
|
|
96
|
+
* @returns {T} Validated data or original data if validation fails in non-strict mode
|
|
97
|
+
*/
|
|
98
|
+
export declare function validateResponseSafe<T>(schema: z.ZodSchema<T>, data: unknown, logErrors?: boolean): T;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Common validation schemas for API responses
|
|
5
|
+
* @description Base schemas that can be reused across different modules
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Error response schema
|
|
9
|
+
*/
|
|
10
|
+
export const ErrorSchema = z.object({
|
|
11
|
+
statusCode: z.number(),
|
|
12
|
+
message: z.string(),
|
|
13
|
+
localizeMessage: z.string().optional(),
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Localize info schema
|
|
17
|
+
*/
|
|
18
|
+
export const LocalizeInfoSchema = z.object({
|
|
19
|
+
title: z.string(),
|
|
20
|
+
content: z.string().optional(),
|
|
21
|
+
menuTitle: z.string().optional(),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Attribute schema
|
|
25
|
+
*/
|
|
26
|
+
export const AttributeSchema = z.object({
|
|
27
|
+
id: z.number().optional(),
|
|
28
|
+
marker: z.string(),
|
|
29
|
+
type: z.string(),
|
|
30
|
+
isVisible: z.boolean().optional(),
|
|
31
|
+
isRequired: z.boolean().optional(),
|
|
32
|
+
position: z.number().optional(),
|
|
33
|
+
localizeInfos: z.record(z.string(), LocalizeInfoSchema).optional(),
|
|
34
|
+
value: z.any().optional(),
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* User entity schema
|
|
38
|
+
*/
|
|
39
|
+
export const UserEntitySchema = z.object({
|
|
40
|
+
id: z.number(),
|
|
41
|
+
identifier: z.string(),
|
|
42
|
+
authProviderIdentifier: z.string(),
|
|
43
|
+
formData: z.union([z.array(z.any()), z.record(z.string(), z.any())]),
|
|
44
|
+
formIdentifier: z.string(),
|
|
45
|
+
total: z.string(),
|
|
46
|
+
groups: z.array(z.union([z.string(), z.number()])),
|
|
47
|
+
state: z.record(z.string(), z.any()),
|
|
48
|
+
moduleFormConfigs: z.array(z.any()).optional(),
|
|
49
|
+
rating: z.record(z.string(), z.unknown()).optional(),
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Auth entity schema
|
|
53
|
+
* API returns only accessToken and refreshToken
|
|
54
|
+
* userIdentifier and authProviderIdentifier are optional legacy fields
|
|
55
|
+
*/
|
|
56
|
+
export const AuthEntitySchema = z.object({
|
|
57
|
+
userIdentifier: z.string(),
|
|
58
|
+
authProviderIdentifier: z.string(),
|
|
59
|
+
accessToken: z.string(),
|
|
60
|
+
refreshToken: z.string(),
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Paginated response schema factory
|
|
64
|
+
* @param {T} itemSchema - The schema for each item in the paginated response
|
|
65
|
+
* @returns {any} Paginated response schema
|
|
66
|
+
*/
|
|
67
|
+
export function createPaginatedSchema(itemSchema) {
|
|
68
|
+
return z.object({
|
|
69
|
+
items: z.array(itemSchema),
|
|
70
|
+
total: z.number(),
|
|
71
|
+
page: z.number().optional(),
|
|
72
|
+
limit: z.number().optional(),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Validation helper function
|
|
77
|
+
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
78
|
+
* @param {unknown} data - Data to validate
|
|
79
|
+
* @param {object} options - Validation options
|
|
80
|
+
* @param {boolean} options.strict - Whether to use strict mode
|
|
81
|
+
* @param {boolean} options.logErrors - Whether to log errors
|
|
82
|
+
* @returns {object} Validated data or error
|
|
83
|
+
*/
|
|
84
|
+
export function validateResponse(schema, data, options) {
|
|
85
|
+
try {
|
|
86
|
+
const validated = schema.parse(data);
|
|
87
|
+
return { success: true, data: validated };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (error instanceof z.ZodError) {
|
|
91
|
+
if (options === null || options === void 0 ? void 0 : options.logErrors) {
|
|
92
|
+
// eslint-disable-next-line no-undef, no-console
|
|
93
|
+
console.error('Validation error:', {
|
|
94
|
+
errors: error.issues,
|
|
95
|
+
data,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return { success: false, error };
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Safe validation helper - returns data even if validation fails
|
|
105
|
+
* Used when strict mode is disabled
|
|
106
|
+
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
107
|
+
* @param {unknown} data - Data to validate
|
|
108
|
+
* @param {boolean} logErrors - Whether to log errors
|
|
109
|
+
* @returns {T} Validated data or original data if validation fails in non-strict mode
|
|
110
|
+
*/
|
|
111
|
+
export function validateResponseSafe(schema, data, logErrors = false) {
|
|
112
|
+
const result = validateResponse(schema, data, { logErrors });
|
|
113
|
+
if (result.success) {
|
|
114
|
+
return result.data;
|
|
115
|
+
}
|
|
116
|
+
// Return original data if validation fails in non-strict mode
|
|
117
|
+
return data;
|
|
118
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import AsyncModules from '../base/asyncModules.js';
|
|
2
|
+
import type StateModule from '../base/stateModule.js';
|
|
3
|
+
import type { IError } from '../base/utils.js';
|
|
4
|
+
import type { IProductsResponse } from '../products/productsInterfaces.js';
|
|
5
|
+
import type { BlockType, IBlockEntity, IBlockProductsLookup, IBlocks, IBlockSlidesResponse, IBlocksResponse, ISearchBlock } from './blocksInterfaces.js';
|
|
6
|
+
/**
|
|
7
|
+
* Controllers for working with blocks.
|
|
8
|
+
* @handle /api/content/blocks
|
|
9
|
+
* @class BlocksApi
|
|
10
|
+
* @augments AsyncModules
|
|
11
|
+
* @implements {IBlocks}
|
|
12
|
+
* @description This class provides methods to interact with blocks.
|
|
13
|
+
*/
|
|
14
|
+
export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
15
|
+
protected state: StateModule;
|
|
16
|
+
protected _url: string;
|
|
17
|
+
/**
|
|
18
|
+
* Constructor for BlocksApi class.
|
|
19
|
+
*/
|
|
20
|
+
constructor(state: StateModule);
|
|
21
|
+
/**
|
|
22
|
+
* Get blocks by parameters.
|
|
23
|
+
* @handleName getBlocks
|
|
24
|
+
* @param {BlockType} [type] - Optional block type to filter by. Available values: "product" | "error_page" | "catalog_page" | "product_preview" | "similar_products_block" | "product_block" | "form" | "common_page" | "common_block" | "order" | "service" | "none". When omitted, blocks of all types are returned. Example: 'product'.
|
|
25
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
26
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
27
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
28
|
+
* @returns {Promise<IBlocksResponse | IError>} Returns BlocksEntity object.
|
|
29
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
30
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getBlocks getBlocks} documentation.
|
|
31
|
+
*/
|
|
32
|
+
getBlocks(type?: BlockType, langCode?: string, offset?: number, limit?: number): Promise<IBlocksResponse | IError>;
|
|
33
|
+
/**
|
|
34
|
+
* Get block by marker.
|
|
35
|
+
* @handleName getBlockByMarker
|
|
36
|
+
* @param {string} marker - Marker of Block. Example: "product_block".
|
|
37
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
38
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
39
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
40
|
+
* @returns {Promise<IBlockEntity | IError>} - Returns a BlockEntity object.
|
|
41
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
42
|
+
* @description This method retrieves a block by its marker and includes additional information such as similar products or products associated with the block.
|
|
43
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getBlockByMarker getBlockByMarker} documentation.
|
|
44
|
+
*/
|
|
45
|
+
getBlockByMarker(marker: string, langCode?: string, offset?: number, limit?: number): Promise<IBlockEntity | IError>;
|
|
46
|
+
/**
|
|
47
|
+
* Enrich a single block in place.
|
|
48
|
+
*
|
|
49
|
+
* Lifts product display settings from `customSettings.productConfig` to
|
|
50
|
+
* numeric top-level fields, strips internal-only fields, and — when
|
|
51
|
+
* `loadProducts` is true — fetches the related products for
|
|
52
|
+
* `similar_products_block` / `product_block` blocks. Shared by `getBlocks`
|
|
53
|
+
* (array) and `getBlockByMarker` (single block). Mutates `block` in place.
|
|
54
|
+
* @param {any} block - Normalized block to enrich (mutated in place).
|
|
55
|
+
* @param {string} langCode - Language code passed to product sub-requests.
|
|
56
|
+
* @param {number} offset - Pagination offset for product sub-requests.
|
|
57
|
+
* @param {number} limit - Pagination limit for product sub-requests.
|
|
58
|
+
* @param {boolean} loadProducts - Whether to fetch related products.
|
|
59
|
+
* @returns {Promise<void>} Resolves when enrichment (incl. sub-requests) is done.
|
|
60
|
+
*/
|
|
61
|
+
private _enrichBlock;
|
|
62
|
+
/**
|
|
63
|
+
* Get similar products by block marker.
|
|
64
|
+
* @handleName getSimilarProducts
|
|
65
|
+
* @param {string} marker - Block identifier. Example: "similar_products_block".
|
|
66
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
67
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
68
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
69
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
70
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
71
|
+
* @param {number} [productId] - Optional product id to find similar products for.
|
|
72
|
+
* @returns {Promise<IProductsResponse | IError>} Returns the total count and an array of product items in object by specified block marker.
|
|
73
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
74
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getSimilarProducts getSimilarProducts} documentation.
|
|
75
|
+
*/
|
|
76
|
+
private getSimilarProducts;
|
|
77
|
+
/**
|
|
78
|
+
* Get products by block marker.
|
|
79
|
+
* @handleName getProductsByBlockMarker
|
|
80
|
+
* @param {string} marker - Block identifier. Example: "product_block".
|
|
81
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
82
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
83
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
84
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
85
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
86
|
+
* @returns {Promise<IProductsEntity[] | IError>} Return array of BlocksEntity object.
|
|
87
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
88
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getProductsByBlockMarker getProductsByBlockMarker} documentation.
|
|
89
|
+
*/
|
|
90
|
+
private getProductsByBlockMarker;
|
|
91
|
+
/**
|
|
92
|
+
* Get frequently ordered products by block marker and product id.
|
|
93
|
+
* @handleName getFrequentlyOrderedProducts
|
|
94
|
+
* @param {number} productId - Product id. Example: 1.
|
|
95
|
+
* @param {string} marker - Block marker. Example: "frequently_ordered_block".
|
|
96
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
97
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
98
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
99
|
+
* @returns {Promise<IProductsResponse | IError>} Returns a products response with items and total.
|
|
100
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
101
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getFrequentlyOrderedProducts getFrequentlyOrderedProducts} documentation.
|
|
102
|
+
*/
|
|
103
|
+
getFrequentlyOrderedProducts(productId: number, marker: string, langCode?: string, signPrice?: string): Promise<IProductsResponse | IError>;
|
|
104
|
+
/**
|
|
105
|
+
* Quick search for block objects with limited output.
|
|
106
|
+
* @handleName searchBlock
|
|
107
|
+
* @param {string} name - Search string. Example: "product_block".
|
|
108
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
109
|
+
* @returns {Promise<ISearchBlock[] | IError>} Returns an array of ISearchBlock objects.
|
|
110
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
111
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/searchBlock searchBlock} documentation.
|
|
112
|
+
*/
|
|
113
|
+
searchBlock(name: string, langCode?: string): Promise<ISearchBlock[] | IError>;
|
|
114
|
+
/**
|
|
115
|
+
* Get "complete your cart" products by the cart from context (auth user or guest).
|
|
116
|
+
* @handleName getCartComplement
|
|
117
|
+
* @param {string} marker - Block marker. Example: "cart_complement_block".
|
|
118
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
119
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
120
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
121
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
122
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
123
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getCartComplement getCartComplement} documentation.
|
|
124
|
+
*/
|
|
125
|
+
getCartComplement(marker: string, langCode?: string, signPrice?: string): Promise<IProductsResponse | IError>;
|
|
126
|
+
/**
|
|
127
|
+
* Get "complete your cart" products by an explicit list of productIds (POST body).
|
|
128
|
+
* @handleName getCartComplementByProductIds
|
|
129
|
+
* @param {string} marker - Block marker. Example: "cart_complement_block".
|
|
130
|
+
* @param {IBlockProductsLookup} body - Lookup body.
|
|
131
|
+
* @example
|
|
132
|
+
{
|
|
133
|
+
"productIds": [1, 2],
|
|
134
|
+
"langCode": "en_US"
|
|
135
|
+
}
|
|
136
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
137
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
138
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getCartComplementByProductIds getCartComplementByProductIds} documentation.
|
|
139
|
+
*/
|
|
140
|
+
getCartComplementByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsResponse | IError>;
|
|
141
|
+
/**
|
|
142
|
+
* Get "similar to cart" products by the cart from context (auth user or guest).
|
|
143
|
+
* @handleName getCartSimilar
|
|
144
|
+
* @param {string} marker - Block marker. Example: "cart_similar_block".
|
|
145
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
146
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
147
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
148
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
149
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
150
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getCartSimilar getCartSimilar} documentation.
|
|
151
|
+
*/
|
|
152
|
+
getCartSimilar(marker: string, langCode?: string, signPrice?: string): Promise<IProductsResponse | IError>;
|
|
153
|
+
/**
|
|
154
|
+
* Get "similar to cart" products by an explicit list of productIds (POST body).
|
|
155
|
+
* @handleName getCartSimilarByProductIds
|
|
156
|
+
* @param {string} marker - Block marker. Example: "cart_similar_block".
|
|
157
|
+
* @param {IBlockProductsLookup} body - Lookup body.
|
|
158
|
+
* @example
|
|
159
|
+
{
|
|
160
|
+
"productIds": [1, 2],
|
|
161
|
+
"langCode": "en_US"
|
|
162
|
+
}
|
|
163
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
164
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
165
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getCartSimilarByProductIds getCartSimilarByProductIds} documentation.
|
|
166
|
+
*/
|
|
167
|
+
getCartSimilarByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsResponse | IError>;
|
|
168
|
+
/**
|
|
169
|
+
* Get personal recommendations for the user.
|
|
170
|
+
* @handleName getPersonalRecommendations
|
|
171
|
+
* @param {string} marker - Block marker. Example: "personal_recommendations_block".
|
|
172
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
173
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
174
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
175
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
176
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
177
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getPersonalRecommendations getPersonalRecommendations} documentation.
|
|
178
|
+
*/
|
|
179
|
+
getPersonalRecommendations(marker: string, langCode?: string, signPrice?: string): Promise<IProductsResponse | IError>;
|
|
180
|
+
/**
|
|
181
|
+
* Get recently viewed products.
|
|
182
|
+
* @handleName getRecentlyViewed
|
|
183
|
+
* @param {string} marker - Block marker. Example: "recently_viewed_block".
|
|
184
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
185
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
186
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
187
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
188
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
189
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getRecentlyViewed getRecentlyViewed} documentation.
|
|
190
|
+
*/
|
|
191
|
+
getRecentlyViewed(marker: string, langCode?: string, signPrice?: string): Promise<IProductsResponse | IError>;
|
|
192
|
+
/**
|
|
193
|
+
* Get products for repeat purchase.
|
|
194
|
+
* @handleName getRepeatPurchase
|
|
195
|
+
* @param {string} marker - Block marker. Example: "repeat_purchase_block".
|
|
196
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
197
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
198
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
199
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
200
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
201
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getRepeatPurchase getRepeatPurchase} documentation.
|
|
202
|
+
*/
|
|
203
|
+
getRepeatPurchase(marker: string, langCode?: string, signPrice?: string): Promise<IProductsResponse | IError>;
|
|
204
|
+
/**
|
|
205
|
+
* Get the block's slides tree as a flat pre-order array (slider_block only).
|
|
206
|
+
* @handleName getSlides
|
|
207
|
+
* @param {string} marker - Block marker. Example: "slider_block".
|
|
208
|
+
* @returns {Promise<IBlockSlidesResponse | IError>} Returns the slides response.
|
|
209
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
210
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getSlides getSlides} documentation.
|
|
211
|
+
*/
|
|
212
|
+
getSlides(marker: string): Promise<IBlockSlidesResponse | IError>;
|
|
213
|
+
/**
|
|
214
|
+
* Get trending products of the block.
|
|
215
|
+
* @handleName getTrending
|
|
216
|
+
* @param {string} marker - Block marker. Example: "trending_block".
|
|
217
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
218
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
219
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
220
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
221
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
222
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getTrending getTrending} documentation.
|
|
223
|
+
*/
|
|
224
|
+
getTrending(marker: string, langCode?: string, signPrice?: string): Promise<IProductsResponse | IError>;
|
|
225
|
+
/**
|
|
226
|
+
* Get "similar to wishlist" products by the wishlist from context (auth user or guest).
|
|
227
|
+
* @handleName getWishlistSimilar
|
|
228
|
+
* @param {string} marker - Block marker. Example: "wishlist_similar_block".
|
|
229
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
230
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
231
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
232
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
233
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
234
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getWishlistSimilar getWishlistSimilar} documentation.
|
|
235
|
+
*/
|
|
236
|
+
getWishlistSimilar(marker: string, langCode?: string, signPrice?: string): Promise<IProductsResponse | IError>;
|
|
237
|
+
/**
|
|
238
|
+
* Get "similar to wishlist" products by an explicit list of productIds (POST body).
|
|
239
|
+
* @handleName getWishlistSimilarByProductIds
|
|
240
|
+
* @param {string} marker - Block marker. Example: "wishlist_similar_block".
|
|
241
|
+
* @param {IBlockProductsLookup} body - Lookup body.
|
|
242
|
+
* @example
|
|
243
|
+
{
|
|
244
|
+
"productIds": [1, 2],
|
|
245
|
+
"langCode": "en_US"
|
|
246
|
+
}
|
|
247
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
248
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
249
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getWishlistSimilarByProductIds getWishlistSimilarByProductIds} documentation.
|
|
250
|
+
*/
|
|
251
|
+
getWishlistSimilarByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsResponse | IError>;
|
|
252
|
+
}
|