oneentry 1.0.136 → 1.0.137

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +15 -3
  2. package/configure.js +27 -3
  3. package/dist/admins/adminsApi.js +4 -1
  4. package/dist/admins/adminsInterfaces.d.ts +1 -1
  5. package/dist/admins/adminsSchemas.d.ts +30 -0
  6. package/dist/admins/adminsSchemas.js +27 -0
  7. package/dist/attribute-sets/attributeSetsApi.js +13 -4
  8. package/dist/attribute-sets/attributeSetsSchemas.d.ts +90 -0
  9. package/dist/attribute-sets/attributeSetsSchemas.js +74 -0
  10. package/dist/auth-provider/authProviderApi.d.ts +11 -8
  11. package/dist/auth-provider/authProviderApi.js +25 -15
  12. package/dist/auth-provider/authProviderSchemas.d.ts +137 -0
  13. package/dist/auth-provider/authProviderSchemas.js +85 -0
  14. package/dist/auth-provider/authProvidersInterfaces.d.ts +6 -6
  15. package/dist/base/asyncModules.d.ts +25 -15
  16. package/dist/base/asyncModules.js +91 -24
  17. package/dist/base/stateModule.d.ts +7 -0
  18. package/dist/base/stateModule.js +26 -11
  19. package/dist/base/syncModules.d.ts +12 -0
  20. package/dist/base/syncModules.js +45 -94
  21. package/dist/base/utils.d.ts +41 -2
  22. package/dist/base/validation.d.ts +118 -0
  23. package/dist/base/validation.js +132 -0
  24. package/dist/blocks/blocksApi.js +16 -11
  25. package/dist/blocks/blocksInterfaces.d.ts +1 -1
  26. package/dist/blocks/blocksSchemas.d.ts +187 -0
  27. package/dist/blocks/blocksSchemas.js +43 -0
  28. package/dist/config.d.ts +10 -2
  29. package/dist/config.js +20 -4
  30. package/dist/file-uploading/fileUploadingApi.js +4 -1
  31. package/dist/file-uploading/fileUploadingSchemas.d.ts +22 -0
  32. package/dist/file-uploading/fileUploadingSchemas.js +21 -0
  33. package/dist/forms/formsApi.js +7 -2
  34. package/dist/forms/formsInterfaces.d.ts +20 -8
  35. package/dist/forms/formsSchemas.d.ts +65 -0
  36. package/dist/forms/formsSchemas.js +36 -0
  37. package/dist/forms-data/formsDataApi.js +10 -3
  38. package/dist/forms-data/formsDataInterfaces.d.ts +2 -2
  39. package/dist/forms-data/formsDataSchemas.d.ts +107 -0
  40. package/dist/forms-data/formsDataSchemas.js +83 -0
  41. package/dist/general-types/generalTypesApi.js +4 -1
  42. package/dist/general-types/generalTypesSchemas.d.ts +50 -0
  43. package/dist/general-types/generalTypesSchemas.js +35 -0
  44. package/dist/integration-collections/integrationCollectionsApi.js +25 -9
  45. package/dist/integration-collections/integrationCollectionsSchemas.d.ts +84 -0
  46. package/dist/integration-collections/integrationCollectionsSchemas.js +63 -0
  47. package/dist/locales/localesApi.js +4 -1
  48. package/dist/locales/localesSchemas.d.ts +32 -0
  49. package/dist/locales/localesSchemas.js +26 -0
  50. package/dist/menus/menusApi.js +4 -1
  51. package/dist/menus/menusSchemas.d.ts +16 -0
  52. package/dist/menus/menusSchemas.js +28 -0
  53. package/dist/orders/ordersApi.js +13 -4
  54. package/dist/orders/ordersInterfaces.d.ts +3 -3
  55. package/dist/orders/ordersSchemas.d.ts +158 -0
  56. package/dist/orders/ordersSchemas.js +120 -0
  57. package/dist/pages/pagesApi.d.ts +2 -1
  58. package/dist/pages/pagesApi.js +87 -34
  59. package/dist/pages/pagesInterfaces.d.ts +6 -5
  60. package/dist/pages/pagesSchemas.d.ts +85 -0
  61. package/dist/pages/pagesSchemas.js +46 -0
  62. package/dist/payments/paymentsApi.js +13 -4
  63. package/dist/payments/paymentsInterfaces.d.ts +3 -3
  64. package/dist/payments/paymentsSchemas.d.ts +121 -0
  65. package/dist/payments/paymentsSchemas.js +75 -0
  66. package/dist/product-statuses/productStatusesApi.js +13 -3
  67. package/dist/product-statuses/productStatusesSchemas.d.ts +34 -0
  68. package/dist/product-statuses/productStatusesSchemas.js +30 -0
  69. package/dist/products/productsApi.js +19 -6
  70. package/dist/products/productsInterfaces.d.ts +4 -4
  71. package/dist/products/productsSchemas.d.ts +212 -0
  72. package/dist/products/productsSchemas.js +85 -0
  73. package/dist/templates/templatesApi.js +11 -4
  74. package/dist/templates/templatesSchemas.d.ts +48 -0
  75. package/dist/templates/templatesSchemas.js +31 -0
  76. package/dist/templates-preview/templatesPreviewApi.js +7 -2
  77. package/dist/templates-preview/templatesPreviewSchemas.d.ts +83 -0
  78. package/dist/templates-preview/templatesPreviewSchemas.js +48 -0
  79. package/dist/users/usersApi.js +8 -5
  80. package/dist/users/usersInterfaces.d.ts +2 -1
  81. package/dist/users/usersSchemas.d.ts +38 -0
  82. package/dist/users/usersSchemas.js +28 -0
  83. package/package.json +5 -4
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MenuEntitySchema = exports.MenusPagesSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Menu pages schema (recursive)
7
+ * Can have children that are also menu pages
8
+ */
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ exports.MenusPagesSchema = zod_1.z.lazy(() => zod_1.z.object({
11
+ children: zod_1.z.union([zod_1.z.array(exports.MenusPagesSchema), exports.MenusPagesSchema]).optional(),
12
+ id: zod_1.z.number().nullable(),
13
+ pageUrl: zod_1.z.string().nullable(),
14
+ localizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
15
+ attributeValues: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
16
+ position: zod_1.z.number(),
17
+ parentId: zod_1.z.number().nullable(),
18
+ }));
19
+ /**
20
+ * Menu entity schema
21
+ * Includes all fields returned by the API
22
+ */
23
+ exports.MenuEntitySchema = zod_1.z.object({
24
+ id: zod_1.z.number(),
25
+ identifier: zod_1.z.string(),
26
+ localizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
27
+ pages: zod_1.z.union([zod_1.z.array(exports.MenusPagesSchema), exports.MenusPagesSchema]),
28
+ });
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const asyncModules_1 = __importDefault(require("../base/asyncModules"));
7
+ const ordersSchemas_1 = require("./ordersSchemas");
7
8
  /**
8
9
  * Controllers for working with orders.
9
10
  * @handle /api/content/orders-storage
@@ -49,7 +50,9 @@ class OrdersApi extends asyncModules_1.default {
49
50
  */
50
51
  async getAllOrdersByMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
51
52
  const result = await this._fetchGet(`/marker/${marker}/orders?langCode=${langCode}&limit=${limit}&offset=${offset}`);
52
- return this._normalizeData(result);
53
+ // Validate response if validation is enabled
54
+ const validated = this._validateResponse(result, ordersSchemas_1.OrdersResponseSchema);
55
+ return this._normalizeData(validated);
53
56
  }
54
57
  /**
55
58
  * Retrieve one order storage object by marker.
@@ -78,7 +81,9 @@ class OrdersApi extends asyncModules_1.default {
78
81
  */
79
82
  async getOrderByMarkerAndId(marker, id, langCode = this.state.lang) {
80
83
  const result = await this._fetchGet(`/marker/${marker}/orders/${id}?langCode=${langCode}`);
81
- return this._normalizeData(result);
84
+ // Validate response if validation is enabled
85
+ const validated = this._validateResponse(result, ordersSchemas_1.OrderEntitySchema);
86
+ return this._normalizeData(validated);
82
87
  }
83
88
  /**
84
89
  * Creation of an order in the order storage.
@@ -115,7 +120,9 @@ class OrdersApi extends asyncModules_1.default {
115
120
  : [body.formData];
116
121
  body.formData = formData;
117
122
  const result = await this._fetchPost(`/marker/${marker}/orders`, body);
118
- return this._normalizeData(result);
123
+ // Validate response if validation is enabled
124
+ const validated = this._validateResponse(result, ordersSchemas_1.CreateOrderResponseSchema);
125
+ return this._normalizeData(validated);
119
126
  }
120
127
  /**
121
128
  * Changing an order in the orders storage
@@ -154,7 +161,9 @@ class OrdersApi extends asyncModules_1.default {
154
161
  : [body.formData];
155
162
  body.formData = formData;
156
163
  const result = await this._fetchPut(`/marker/${marker}/orders/${id}?langCode=${langCode}`, body);
157
- return this._normalizeData(result);
164
+ // Validate response if validation is enabled
165
+ const validated = this._validateResponse(result, ordersSchemas_1.UpdateOrderResponseSchema);
166
+ return this._normalizeData(validated);
158
167
  }
159
168
  }
160
169
  exports.default = OrdersApi;
@@ -86,7 +86,7 @@ interface IOrdersApi {
86
86
  * @description This method requires user authorization.
87
87
  * @see For more information about configuring the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider authorization module}, see the documentation in the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider configuration settings section of the SDK}.
88
88
  */
89
- createOrder(marker: string, body: IOrderData, langCode: string): Promise<IBaseOrdersEntity | IError>;
89
+ createOrder(marker: string, body: IOrderData, langCode?: string): Promise<IBaseOrdersEntity | IError>;
90
90
  /**
91
91
  * Changing an order in the orders storage
92
92
  * @handleName updateOrderByMarkerAndId
@@ -419,8 +419,8 @@ interface IOrderByMarkerEntity {
419
419
  currency: string;
420
420
  paymentAccountIdentifier?: string;
421
421
  paymentAccountLocalizeInfos?: Record<string, any>;
422
- paymentUrl: null | string;
422
+ paymentUrl: string | null;
423
423
  products: IOrderProducts[];
424
- isCompleted: null | boolean;
424
+ isCompleted: boolean | null;
425
425
  }
426
426
  export type { IBaseOrdersEntity, IBaseOrdersEntityResponse, IOrderByMarkerEntity, IOrderData, IOrderProductData, IOrderProducts, IOrdersApi, IOrdersByMarkerEntity, IOrdersEntity, IOrdersFormData, IPaymentAccountIdentifiers, IPicture, };
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Validation schemas for Orders module
3
+ * @description Zod schemas for validating orders-related API responses
4
+ */
5
+ import { z } from 'zod';
6
+ /**
7
+ * Order item schema
8
+ * @description Order item schema for validating orders-related API responses
9
+ */
10
+ export declare const OrderItemSchema: z.ZodObject<{
11
+ id: z.ZodNumber;
12
+ productId: z.ZodNumber;
13
+ quantity: z.ZodNumber;
14
+ price: z.ZodNumber;
15
+ total: z.ZodNumber;
16
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
17
+ }, z.core.$strip>;
18
+ /**
19
+ * Order entity schema
20
+ * @description Order entity schema for validating orders-related API responses
21
+ */
22
+ export declare const OrderEntitySchema: z.ZodObject<{
23
+ id: z.ZodNumber;
24
+ identifier: z.ZodOptional<z.ZodString>;
25
+ statusMarker: z.ZodOptional<z.ZodString>;
26
+ statusIdentifier: z.ZodOptional<z.ZodString>;
27
+ userId: z.ZodOptional<z.ZodNumber>;
28
+ userIdentifier: z.ZodOptional<z.ZodString>;
29
+ total: z.ZodOptional<z.ZodNumber>;
30
+ totalSum: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
31
+ items: z.ZodOptional<z.ZodArray<z.ZodObject<{
32
+ id: z.ZodNumber;
33
+ productId: z.ZodNumber;
34
+ quantity: z.ZodNumber;
35
+ price: z.ZodNumber;
36
+ total: z.ZodNumber;
37
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
38
+ }, z.core.$strip>>>;
39
+ products: z.ZodOptional<z.ZodArray<z.ZodAny>>;
40
+ formData: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
41
+ createdAt: z.ZodOptional<z.ZodString>;
42
+ createdDate: z.ZodOptional<z.ZodString>;
43
+ updatedAt: z.ZodOptional<z.ZodString>;
44
+ storageId: z.ZodOptional<z.ZodNumber>;
45
+ formIdentifier: z.ZodOptional<z.ZodString>;
46
+ attributeSetIdentifier: z.ZodOptional<z.ZodString>;
47
+ currency: z.ZodOptional<z.ZodString>;
48
+ paymentAccountIdentifier: z.ZodOptional<z.ZodString>;
49
+ paymentAccountLocalizeInfos: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
50
+ paymentUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
51
+ isCompleted: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
52
+ }, z.core.$strip>;
53
+ /**
54
+ * Orders list response schema
55
+ * @returns Orders list response schema
56
+ */
57
+ export declare const OrdersResponseSchema: z.ZodObject<{
58
+ items: z.ZodArray<z.ZodObject<{
59
+ id: z.ZodNumber;
60
+ identifier: z.ZodOptional<z.ZodString>;
61
+ statusMarker: z.ZodOptional<z.ZodString>;
62
+ statusIdentifier: z.ZodOptional<z.ZodString>;
63
+ userId: z.ZodOptional<z.ZodNumber>;
64
+ userIdentifier: z.ZodOptional<z.ZodString>;
65
+ total: z.ZodOptional<z.ZodNumber>;
66
+ totalSum: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
67
+ items: z.ZodOptional<z.ZodArray<z.ZodObject<{
68
+ id: z.ZodNumber;
69
+ productId: z.ZodNumber;
70
+ quantity: z.ZodNumber;
71
+ price: z.ZodNumber;
72
+ total: z.ZodNumber;
73
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
74
+ }, z.core.$strip>>>;
75
+ products: z.ZodOptional<z.ZodArray<z.ZodAny>>;
76
+ formData: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
77
+ createdAt: z.ZodOptional<z.ZodString>;
78
+ createdDate: z.ZodOptional<z.ZodString>;
79
+ updatedAt: z.ZodOptional<z.ZodString>;
80
+ storageId: z.ZodOptional<z.ZodNumber>;
81
+ formIdentifier: z.ZodOptional<z.ZodString>;
82
+ attributeSetIdentifier: z.ZodOptional<z.ZodString>;
83
+ currency: z.ZodOptional<z.ZodString>;
84
+ paymentAccountIdentifier: z.ZodOptional<z.ZodString>;
85
+ paymentAccountLocalizeInfos: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
86
+ paymentUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
87
+ isCompleted: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
88
+ }, z.core.$strip>>;
89
+ total: z.ZodNumber;
90
+ }, z.core.$strip>;
91
+ /**
92
+ * Order storage schema
93
+ * @returns Order storage validation schema
94
+ */
95
+ export declare const OrderStorageSchema: z.ZodObject<{
96
+ id: z.ZodNumber;
97
+ marker: z.ZodString;
98
+ name: z.ZodString;
99
+ isActive: z.ZodBoolean;
100
+ position: z.ZodOptional<z.ZodNumber>;
101
+ statuses: z.ZodOptional<z.ZodArray<z.ZodObject<{
102
+ id: z.ZodNumber;
103
+ marker: z.ZodString;
104
+ name: z.ZodString;
105
+ position: z.ZodOptional<z.ZodNumber>;
106
+ }, z.core.$strip>>>;
107
+ }, z.core.$strip>;
108
+ /**
109
+ * Orders storage list response schema
110
+ * @returns Orders storage list response schema
111
+ */
112
+ export declare const OrdersStorageResponseSchema: z.ZodArray<z.ZodObject<{
113
+ id: z.ZodNumber;
114
+ marker: z.ZodString;
115
+ name: z.ZodString;
116
+ isActive: z.ZodBoolean;
117
+ position: z.ZodOptional<z.ZodNumber>;
118
+ statuses: z.ZodOptional<z.ZodArray<z.ZodObject<{
119
+ id: z.ZodNumber;
120
+ marker: z.ZodString;
121
+ name: z.ZodString;
122
+ position: z.ZodOptional<z.ZodNumber>;
123
+ }, z.core.$strip>>>;
124
+ }, z.core.$strip>>;
125
+ /**
126
+ * Create order response schema
127
+ * API returns a simplified order object after creation
128
+ * @returns Create order response schema
129
+ */
130
+ export declare const CreateOrderResponseSchema: z.ZodObject<{
131
+ id: z.ZodNumber;
132
+ identifier: z.ZodOptional<z.ZodString>;
133
+ statusMarker: z.ZodOptional<z.ZodString>;
134
+ total: z.ZodOptional<z.ZodNumber>;
135
+ totalSum: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
136
+ createdAt: z.ZodOptional<z.ZodString>;
137
+ createdDate: z.ZodOptional<z.ZodString>;
138
+ formIdentifier: z.ZodOptional<z.ZodString>;
139
+ paymentAccountIdentifier: z.ZodOptional<z.ZodString>;
140
+ formData: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
141
+ products: z.ZodOptional<z.ZodArray<z.ZodAny>>;
142
+ currency: z.ZodOptional<z.ZodString>;
143
+ }, z.core.$strip>;
144
+ /**
145
+ * Update order response schema
146
+ * API returns the full order object after update
147
+ */
148
+ export declare const UpdateOrderResponseSchema: z.ZodObject<{
149
+ id: z.ZodNumber;
150
+ formIdentifier: z.ZodOptional<z.ZodString>;
151
+ paymentAccountIdentifier: z.ZodOptional<z.ZodString>;
152
+ formData: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
153
+ products: z.ZodOptional<z.ZodArray<z.ZodAny>>;
154
+ currency: z.ZodOptional<z.ZodString>;
155
+ totalSum: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
156
+ success: z.ZodOptional<z.ZodBoolean>;
157
+ message: z.ZodOptional<z.ZodString>;
158
+ }, z.core.$strip>;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateOrderResponseSchema = exports.CreateOrderResponseSchema = exports.OrdersStorageResponseSchema = exports.OrderStorageSchema = exports.OrdersResponseSchema = exports.OrderEntitySchema = exports.OrderItemSchema = void 0;
4
+ /**
5
+ * Validation schemas for Orders module
6
+ * @description Zod schemas for validating orders-related API responses
7
+ */
8
+ const zod_1 = require("zod");
9
+ /**
10
+ * Order item schema
11
+ * @description Order item schema for validating orders-related API responses
12
+ */
13
+ exports.OrderItemSchema = zod_1.z.object({
14
+ id: zod_1.z.number(),
15
+ productId: zod_1.z.number(),
16
+ quantity: zod_1.z.number(),
17
+ price: zod_1.z.number(),
18
+ total: zod_1.z.number(),
19
+ attributes: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
20
+ });
21
+ /**
22
+ * Order entity schema
23
+ * @description Order entity schema for validating orders-related API responses
24
+ */
25
+ exports.OrderEntitySchema = zod_1.z.object({
26
+ id: zod_1.z.number(),
27
+ identifier: zod_1.z.string().optional(),
28
+ statusMarker: zod_1.z.string().optional(),
29
+ statusIdentifier: zod_1.z.string().optional(),
30
+ userId: zod_1.z.number().optional(),
31
+ userIdentifier: zod_1.z.string().optional(),
32
+ total: zod_1.z.number().optional(),
33
+ totalSum: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
34
+ items: zod_1.z.array(exports.OrderItemSchema).optional(),
35
+ products: zod_1.z.array(zod_1.z.any()).optional(),
36
+ formData: zod_1.z
37
+ .union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())])
38
+ .optional(),
39
+ createdAt: zod_1.z.string().optional(),
40
+ createdDate: zod_1.z.string().optional(),
41
+ updatedAt: zod_1.z.string().optional(),
42
+ storageId: zod_1.z.number().optional(),
43
+ formIdentifier: zod_1.z.string().optional(),
44
+ attributeSetIdentifier: zod_1.z.string().optional(),
45
+ currency: zod_1.z.string().optional(),
46
+ paymentAccountIdentifier: zod_1.z.string().optional(),
47
+ paymentAccountLocalizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
48
+ paymentUrl: zod_1.z.string().optional().nullable(),
49
+ isCompleted: zod_1.z.boolean().optional().nullable(),
50
+ });
51
+ /**
52
+ * Orders list response schema
53
+ * @returns Orders list response schema
54
+ */
55
+ exports.OrdersResponseSchema = zod_1.z.object({
56
+ items: zod_1.z.array(exports.OrderEntitySchema),
57
+ total: zod_1.z.number(),
58
+ });
59
+ /**
60
+ * Order storage schema
61
+ * @returns Order storage validation schema
62
+ */
63
+ exports.OrderStorageSchema = zod_1.z.object({
64
+ id: zod_1.z.number(),
65
+ marker: zod_1.z.string(),
66
+ name: zod_1.z.string(),
67
+ isActive: zod_1.z.boolean(),
68
+ position: zod_1.z.number().optional(),
69
+ statuses: zod_1.z
70
+ .array(zod_1.z.object({
71
+ id: zod_1.z.number(),
72
+ marker: zod_1.z.string(),
73
+ name: zod_1.z.string(),
74
+ position: zod_1.z.number().optional(),
75
+ }))
76
+ .optional(),
77
+ });
78
+ /**
79
+ * Orders storage list response schema
80
+ * @returns Orders storage list response schema
81
+ */
82
+ exports.OrdersStorageResponseSchema = zod_1.z.array(exports.OrderStorageSchema);
83
+ /**
84
+ * Create order response schema
85
+ * API returns a simplified order object after creation
86
+ * @returns Create order response schema
87
+ */
88
+ exports.CreateOrderResponseSchema = zod_1.z.object({
89
+ id: zod_1.z.number(),
90
+ identifier: zod_1.z.string().optional(),
91
+ statusMarker: zod_1.z.string().optional(),
92
+ total: zod_1.z.number().optional(),
93
+ totalSum: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
94
+ createdAt: zod_1.z.string().optional(),
95
+ createdDate: zod_1.z.string().optional(),
96
+ formIdentifier: zod_1.z.string().optional(),
97
+ paymentAccountIdentifier: zod_1.z.string().optional(),
98
+ formData: zod_1.z
99
+ .union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())])
100
+ .optional(),
101
+ products: zod_1.z.array(zod_1.z.any()).optional(),
102
+ currency: zod_1.z.string().optional(),
103
+ });
104
+ /**
105
+ * Update order response schema
106
+ * API returns the full order object after update
107
+ */
108
+ exports.UpdateOrderResponseSchema = zod_1.z.object({
109
+ id: zod_1.z.number(),
110
+ formIdentifier: zod_1.z.string().optional(),
111
+ paymentAccountIdentifier: zod_1.z.string().optional(),
112
+ formData: zod_1.z
113
+ .union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())])
114
+ .optional(),
115
+ products: zod_1.z.array(zod_1.z.any()).optional(),
116
+ currency: zod_1.z.string().optional(),
117
+ totalSum: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
118
+ success: zod_1.z.boolean().optional(),
119
+ message: zod_1.z.string().optional(),
120
+ });
@@ -135,7 +135,8 @@ export default class PageApi extends AsyncModules implements IPageApi {
135
135
  ]
136
136
  * @returns {any} An array of page objects with template data added
137
137
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
138
- * @description Add template data to pages
138
+ * @description Add template data to pages. Optimized to avoid N+1 query problem by fetching only unique templates in parallel.
139
+ * For example, if 100 pages use 3 different templates, this method makes 3 requests instead of 100.
139
140
  */
140
141
  protected addTemplateToPages(data: IPagesEntity[]): Promise<any | IError>;
141
142
  /**
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  /* eslint-disable @typescript-eslint/no-explicit-any */
8
8
  const asyncModules_1 = __importDefault(require("../base/asyncModules"));
9
9
  const templatesApi_1 = __importDefault(require("../templates/templatesApi"));
10
+ const pagesSchemas_1 = require("./pagesSchemas");
10
11
  /**
11
12
  * Controllers for working with page objects, including catalog pages
12
13
  * @handle /api/content/pages
@@ -33,8 +34,10 @@ class PageApi extends asyncModules_1.default {
33
34
  async getRootPages(langCode = this.state.lang) {
34
35
  // Fetch data from the server using a GET request to retrieve root pages for the specified language code
35
36
  const data = await this._fetchGet(`/root?langCode=${langCode}`);
37
+ // Validate response if validation is enabled
38
+ const validated = this._validateResponse(data, pagesSchemas_1.PagesResponseSchema);
36
39
  // Add template information to each page in the fetched root pages data
37
- const withTemplate = await this.addTemplateToPages(data);
40
+ const withTemplate = await this.addTemplateToPages(validated);
38
41
  // Normalize the data and return it; ensures consistent structure or handles errors
39
42
  return this._normalizeData(withTemplate, langCode);
40
43
  }
@@ -49,8 +52,10 @@ class PageApi extends asyncModules_1.default {
49
52
  async getPages(langCode = this.state.lang) {
50
53
  // Fetch data from the server using a GET request to retrieve all pages for the specified language code
51
54
  const data = await this._fetchGet(`?langCode=${langCode}`);
55
+ // Validate response if validation is enabled
56
+ const validated = this._validateResponse(data, pagesSchemas_1.PagesResponseSchema);
52
57
  // Add template information to each page in the fetched data
53
- const withTemplate = await this.addTemplateToPages(data);
58
+ const withTemplate = await this.addTemplateToPages(validated);
54
59
  // Normalize the data and return it; ensures consistent structure or handles errors
55
60
  return this._normalizeData(withTemplate, langCode);
56
61
  }
@@ -66,8 +71,10 @@ class PageApi extends asyncModules_1.default {
66
71
  async getPageById(id, langCode = this.state.lang) {
67
72
  // Fetch data from the server using a GET request to retrieve page details by ID and language code
68
73
  const data = await this._fetchGet(`/${id}?langCode=${langCode}`);
74
+ // Validate response if validation is enabled
75
+ const validated = this._validateResponse(data, pagesSchemas_1.PageEntitySchema);
69
76
  // Add template information to the fetched page data
70
- const withTemplate = await this.addTemplateToPage(data);
77
+ const withTemplate = await this.addTemplateToPage(validated);
71
78
  // Normalize the data and return it; ensures consistent structure or handles errors
72
79
  return this._normalizeData(withTemplate, langCode);
73
80
  }
@@ -83,8 +90,10 @@ class PageApi extends asyncModules_1.default {
83
90
  async getPageByUrl(url, langCode = this.state.lang) {
84
91
  // Fetch data from the server using a GET request with the specified URL and language code
85
92
  const data = await this._fetchGet(`/url/${url}?langCode=${langCode}`);
93
+ // Validate response if validation is enabled
94
+ const validated = this._validateResponse(data, pagesSchemas_1.PageEntitySchema);
86
95
  // Add template information to the fetched page data
87
- const withTemplate = await this.addTemplateToPage(data);
96
+ const withTemplate = await this.addTemplateToPage(validated);
88
97
  // Normalize the result data and return it; ensures consistent structure or handles errors
89
98
  return this._normalizeData(withTemplate, langCode);
90
99
  }
@@ -100,8 +109,10 @@ class PageApi extends asyncModules_1.default {
100
109
  async getChildPagesByParentUrl(url, langCode = this.state.lang) {
101
110
  // Fetch data from the server using a GET request to retrieve child pages for the specified parent URL and language code
102
111
  const data = await this._fetchGet(`/${url}/children?langCode=${langCode}`);
112
+ // Validate response if validation is enabled
113
+ const validated = this._validateResponse(data, pagesSchemas_1.PagesResponseSchema);
103
114
  // Add template information to each of the fetched child pages
104
- const withTemplate = await this.addTemplateToPages(data);
115
+ const withTemplate = await this.addTemplateToPages(validated);
105
116
  // Normalize the result data and return it; ensures consistent structure or handles errors
106
117
  return this._normalizeData(withTemplate, langCode);
107
118
  }
@@ -122,8 +133,8 @@ class PageApi extends asyncModules_1.default {
122
133
  normalizeResponse.map((item) => {
123
134
  const customSettings = item.customSettings;
124
135
  // Check if customSettings contains 'productConfig' property
125
- // eslint-disable-next-line no-prototype-builtins
126
- if (customSettings && customSettings.hasOwnProperty('productConfig')) {
136
+ if (customSettings &&
137
+ Object.prototype.hasOwnProperty.call(customSettings, 'productConfig')) {
127
138
  // If 'countElementsPerRow' exists, set it on the item
128
139
  if (customSettings.productConfig.countElementsPerRow)
129
140
  item.countElementsPerRow =
@@ -140,25 +151,6 @@ class PageApi extends asyncModules_1.default {
140
151
  });
141
152
  // Check if traffic limit is not set
142
153
  if (!this.state.traficLimit) {
143
- // Define a class 'StaffModule' extending 'AsyncModules'
144
- class StaffModule extends asyncModules_1.default {
145
- constructor(state) {
146
- super(state); // Call parent constructor
147
- this._url = state.url + '/api/content/blocks'; // Set URL for content blocks
148
- }
149
- // Method to fetch similar products by marker
150
- async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30) {
151
- // Fetch similar products from the server
152
- const result = await this._fetchGet(`/${marker}/similar-products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
153
- return this._normalizeData(result.items);
154
- }
155
- // Method to fetch products by block marker
156
- async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
157
- // Fetch products from the server
158
- const result = await this._fetchGet(`/${marker}/products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
159
- return this._normalizeData(result.items);
160
- }
161
- }
162
154
  // Create an instance of 'StaffModule' with the current state
163
155
  const staffModule = new StaffModule(this.state);
164
156
  // If the block type is 'similar_products_block', fetch similar products
@@ -204,8 +196,10 @@ class PageApi extends asyncModules_1.default {
204
196
  async getConfigPageByUrl(url) {
205
197
  // Fetch data from the server using a GET request to retrieve forms for the specified page URL and language code
206
198
  const result = await this._fetchGet(`/${url}/config`);
199
+ // Validate response if validation is enabled
200
+ const validated = this._validateResponse(result, pagesSchemas_1.PageConfigSchema);
207
201
  // return fetched data
208
- return result;
202
+ return validated;
209
203
  }
210
204
  /**
211
205
  * Quick search for page objects with limited output.
@@ -283,16 +277,53 @@ class PageApi extends asyncModules_1.default {
283
277
  ]
284
278
  * @returns {any} An array of page objects with template data added
285
279
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
286
- * @description Add template data to pages
280
+ * @description Add template data to pages. Optimized to avoid N+1 query problem by fetching only unique templates in parallel.
281
+ * For example, if 100 pages use 3 different templates, this method makes 3 requests instead of 100.
287
282
  */
288
283
  async addTemplateToPages(data) {
289
- // Use Promise.all to handle an array of promises returned by mapping over 'data'
290
- return Promise.all(data.map(async (d) => {
291
- // For each element 'd' in the 'data' array, call 'addTemplateToPage'
292
- const result = await this.addTemplateToPage(d);
293
- // Return the result of 'addTemplateToPage' for the current element
294
- return result;
284
+ // Step 1: Collect unique templateIdentifiers from all pages
285
+ const uniqueIdentifiers = [
286
+ ...new Set(data
287
+ .filter((page) => 'templateIdentifier' in page &&
288
+ page.templateIdentifier !== null &&
289
+ page.templateIdentifier !== '')
290
+ .map((page) => page.templateIdentifier)),
291
+ ];
292
+ // Step 2: If no templates needed, return pages as-is
293
+ if (uniqueIdentifiers.length === 0) {
294
+ return data;
295
+ }
296
+ // Step 3: Fetch unique templates in parallel (not N queries, but unique count queries)
297
+ const Templates = new templatesApi_1.default(this.state);
298
+ const templatePromises = uniqueIdentifiers.map((identifier) => Templates.getTemplateByMarker(identifier).catch((error) => {
299
+ // eslint-disable-next-line no-undef, no-console
300
+ console.error(`Template fetch error for ${identifier}: `, error);
301
+ return null; // Return null for failed templates
295
302
  }));
303
+ const templates = await Promise.all(templatePromises);
304
+ // Step 4: Create a Map for O(1) template lookup
305
+ const templateMap = new Map();
306
+ templates.forEach((template, index) => {
307
+ if (template !== null) {
308
+ templateMap.set(uniqueIdentifiers[index], template);
309
+ }
310
+ });
311
+ // Step 5: Apply templates to pages (no additional API calls)
312
+ return data.map((page) => {
313
+ if ('templateIdentifier' in page &&
314
+ page.templateIdentifier !== null &&
315
+ page.templateIdentifier !== '') {
316
+ const template = templateMap.get(page.templateIdentifier);
317
+ if (template) {
318
+ return {
319
+ ...page,
320
+ template,
321
+ };
322
+ }
323
+ }
324
+ // Return page without template if identifier is missing or template not found
325
+ return page;
326
+ });
296
327
  }
297
328
  /**
298
329
  * Add template data to page by page templateIdentifier
@@ -335,3 +366,25 @@ class PageApi extends asyncModules_1.default {
335
366
  }
336
367
  }
337
368
  exports.default = PageApi;
369
+ /**
370
+ * Helper module for working with blocks (similar products and product blocks)
371
+ * @description Internal module for fetching products and similar products for blocks
372
+ */
373
+ class StaffModule extends asyncModules_1.default {
374
+ constructor(state) {
375
+ super(state); // Call parent constructor
376
+ this._url = state.url + '/api/content/blocks'; // Set URL for content blocks
377
+ }
378
+ // Method to fetch similar products by marker
379
+ async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30) {
380
+ // Fetch similar products from the server
381
+ const result = await this._fetchGet(`/${marker}/similar-products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
382
+ return this._normalizeData(result.items);
383
+ }
384
+ // Method to fetch products by block marker
385
+ async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
386
+ // Fetch products from the server
387
+ const result = await this._fetchGet(`/${marker}/products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
388
+ return this._normalizeData(result.items);
389
+ }
390
+ }
@@ -1,3 +1,4 @@
1
+ import type { IBlockEntity } from 'blocks/blocksInterfaces';
1
2
  import type { IFormConfig } from 'forms/formsInterfaces';
2
3
  import type { ITemplateEntity } from 'templates/templatesInterfaces';
3
4
  import type { AttributeType, IAttributes, IError, ILocalizeInfo, LangType, Types } from '../base/utils';
@@ -85,12 +86,13 @@ interface IPageApi {
85
86
  * Quick search for page objects with limited output.
86
87
  * @handleName searchPage
87
88
  * @param {string} name - Text for searching page objects (search is performed on the title field of the localizeInfos object with the language taken into account). Example: "About Us".
89
+ * @param {string} [url] - Optional page URL to filter search results. Example: "catalog".
88
90
  * @param {string} [langCode] - Language code. Default: "en_US".
89
91
  * @returns {IPagesEntity[]} Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
90
92
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
91
93
  * @description This method performs a quick search for page objects with limited output.
92
94
  */
93
- searchPage(name: string, langCode?: LangType): Promise<IPagesEntity[] | IError>;
95
+ searchPage(name: string, url?: string, langCode?: LangType): Promise<IPagesEntity[] | IError>;
94
96
  }
95
97
  /**
96
98
  * @interface IPageConfig
@@ -269,8 +271,6 @@ interface IPagesEntity {
269
271
  depth: number;
270
272
  localizeInfos: ILocalizeInfo;
271
273
  isVisible: boolean;
272
- blocks?: any[];
273
- forms?: any[];
274
274
  type: Types;
275
275
  templateIdentifier: string | null;
276
276
  attributeSetIdentifier: string | null;
@@ -278,11 +278,12 @@ interface IPagesEntity {
278
278
  moduleFormConfigs?: IFormConfig[];
279
279
  isSync: boolean;
280
280
  template?: ITemplateEntity;
281
+ blocks?: IBlockEntity[] | string[];
281
282
  position?: number;
282
283
  config?: Record<string, number>;
283
284
  products?: number;
284
- childrenCount?: string | number;
285
- total?: string | number;
285
+ childrenCount?: string;
286
+ total?: string;
286
287
  categoryPath?: string;
287
288
  }
288
289
  export type { IPageApi, IPageConfig, IPagesEntity, IPositionBlock, IPositionForm, };