@zohodesk/library-platform 1.2.0 → 1.2.2-exp.2

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 (22) hide show
  1. package/es/index.js +6 -2
  2. package/es/library/custom-component/frameworks/json-schema-validator/Validator.js +1 -164
  3. package/es/library/custom-component/frameworks/ui/DependencyFactory.js +1 -1
  4. package/es/library/json-schema-validator/Validator.js +338 -0
  5. package/es/library/json-schema-validator/__tests__/Validator.test.js +753 -0
  6. package/es/library/json-schema-validator/index.js +1 -0
  7. package/es/platform/client-actions/behaviour/zclient-actions/adapters/presenters/FilterUtils.js +11 -0
  8. package/es/platform/client-actions/behaviour/zclient-actions/adapters/resources/ClientActionsFetchSDK.js +76 -0
  9. package/es/platform/client-actions/behaviour/zclient-actions/applications/interfaces/ClientActionsAPIGatewayParams.js +1 -0
  10. package/es/platform/client-actions/behaviour/zclient-actions/applications/interfaces/ClientActionsFetchSDKParams.js +10 -0
  11. package/es/platform/client-actions/behaviour/zclient-actions/applications/interfaces/IClientActionsFetchSDK.js +0 -0
  12. package/es/platform/client-scripts/behaviour/zclient-scripts-fetch/adapters/resources/ClientScriptsFetchSDK.js +43 -0
  13. package/es/platform/client-scripts/behaviour/zclient-scripts-fetch/applications/interfaces/ClientScriptsAPIGatewayParams.js +1 -0
  14. package/es/platform/client-scripts/behaviour/zclient-scripts-fetch/applications/interfaces/ClientScriptsSDKFetchParams.js +1 -0
  15. package/es/platform/client-scripts/behaviour/zclient-scripts-fetch/applications/interfaces/IClientScriptsFetchSDK.js +0 -0
  16. package/es/platform/components/smart-action-band/adapters/presenters/ActionBandTranslator.js +7 -4
  17. package/es/platform/data-source/http-template/getPageClientActions.js +23 -0
  18. package/es/platform/sdk/application/interfaces/gateways/AbstractResource.js +1 -1
  19. package/es/platform/zform/adapters/presenter/FormTranslator.js +18 -15
  20. package/es/platform/zform/adapters/presenter/translators/SectionTranslator.js +1 -1
  21. package/es/platform/zlist/adapters/presenters/TableTranslator.js +5 -4
  22. package/package.json +3 -4
package/es/index.js CHANGED
@@ -5,7 +5,9 @@ import ExternalConstants from "./cc/table-connected/constants/ExternalConstants"
5
5
  import ActionEventMediator from "./platform/client-actions/components/action-event-mediator/frameworks/ui/ActionEventMediator";
6
6
  import RowActionsRenderer from "./platform/client-actions/components/row-actions-renderer/frameworks/ui/RowActions/RowActionsRenderer";
7
7
  import AdaptiveRowActionsRenderer from "./platform/client-actions/components/row-actions-renderer/frameworks/ui/AdaptiveRowActions/AdaptiveRowActionsRenderer";
8
- import ClientActionReordererRegistry from "./platform/client-actions/components/action-event-mediator/frameworks/ui/ClientActionReordererRegistry"; // Rebuild SmartTableConstants without Events
8
+ import ClientActionReordererRegistry from "./platform/client-actions/components/action-event-mediator/frameworks/ui/ClientActionReordererRegistry";
9
+ import ClientActionsFetchSDK from "./platform/client-actions/behaviour/zclient-actions/adapters/resources/ClientActionsFetchSDK";
10
+ import ClientScriptsFetchSDK from "./platform/client-scripts/behaviour/zclient-scripts-fetch/adapters/resources/ClientScriptsFetchSDK"; // Rebuild SmartTableConstants without Events
9
11
 
10
12
  const SmartTableConstants = {
11
13
  ExternalConstants
@@ -40,4 +42,6 @@ export const Behaviours = {
40
42
  FieldSectionEventMappingBehaviourFactory
41
43
  };
42
44
  export * from "./library/analytics";
43
- export { ClientActionReordererRegistry };
45
+ export { ClientActionReordererRegistry };
46
+ export { ClientActionsFetchSDK };
47
+ export { ClientScriptsFetchSDK };
@@ -1,164 +1 @@
1
- /* eslint-disable complexity */
2
- import Ajv from 'ajv';
3
- let jsonValidator = new Ajv({
4
- useDefaults: true
5
- });
6
-
7
- class Validator {
8
- static validate(schema, value) {
9
- if (schema.schema) {
10
- return Validator.validatePropertySchema(schema, value);
11
- }
12
-
13
- let errors = [];
14
- Validator.checkFunctionsRecursively(schema, value, '', '#', errors); // Use AJV for the rest of the validation, ignoring functions
15
-
16
- const ajvSchema = JSON.parse(JSON.stringify(schema, (key, val) => val === 'function' ? undefined : val)); // validate is a type guard for MyData - type is inferred from schema type
17
- // const validate = jsonValidator.compile(schema);
18
-
19
- const validate = jsonValidator.compile(ajvSchema);
20
- const isValid = validate(value);
21
-
22
- if (!isValid) {
23
- // errors = validate.errors;
24
- validate.errors && errors.push(...validate.errors);
25
- }
26
-
27
- return {
28
- isValid: isValid && errors.length === 0,
29
- errors,
30
- warnings: []
31
- };
32
- }
33
-
34
- static checkFunctionsRecursively(schema, value) {
35
- let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
36
- let schemaPath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '#';
37
- let errors = arguments.length > 4 ? arguments[4] : undefined;
38
-
39
- if (schema.type === 'function') {
40
- if (typeof value !== 'function') {
41
- errors.push({
42
- keyword: 'type',
43
- dataPath: path ? `.${path}` : '',
44
- schemaPath: `${schemaPath}/type`,
45
- params: {
46
- type: 'function'
47
- },
48
- message: 'should be function'
49
- });
50
- }
51
-
52
- return;
53
- }
54
-
55
- if (schema.type === 'object' && schema.properties && typeof value === 'object' && value !== null) {
56
- for (const key in schema.properties) {
57
- Validator.checkFunctionsRecursively(schema.properties[key], value[key], path ? `${path}.${key}` : key, `${schemaPath}/properties/${key}`, errors);
58
- }
59
- }
60
-
61
- if (schema.type === 'array' && Array.isArray(value) && schema.items) {
62
- value.forEach((item, index) => {
63
- Validator.checkFunctionsRecursively(schema.items, item, `${path}[${index}]`, `${schemaPath}/items`, errors);
64
- });
65
- } // if (schema.anyOf && Array.isArray(schema.anyOf)) {
66
- // const subErrors = [];
67
- // const valid = schema.anyOf.some((subSchema, idx) => {
68
- // const tmpErrors = [];
69
- // Validator.checkFunctionsRecursively(subSchema, value, path, `${schemaPath}/anyOf/${idx}`, tmpErrors);
70
- // return tmpErrors.length === 0;
71
- // });
72
- // if (!valid) {
73
- // errors.push({ keyword: "anyOf", dataPath: path ? `.${path}` : "", schemaPath: `${schemaPath}/anyOf`, params: {}, message: "should match some schema in anyOf" });
74
- // }
75
- // return;
76
- // }
77
- // if (schema.allOf && Array.isArray(schema.allOf)) {
78
- // schema.allOf.forEach((subSchema, idx) => {
79
- // Validator.checkFunctionsRecursively(subSchema, value, path, `${schemaPath}/allOf/${idx}`, errors);
80
- // });
81
- // return;
82
- // }
83
- // if (schema.oneOf && Array.isArray(schema.oneOf)) {
84
- // let matchCount = 0;
85
- // schema.oneOf.forEach((subSchema, idx) => {
86
- // const tmpErrors = [];
87
- // Validator.checkFunctionsRecursively(subSchema, value, path, `${schemaPath}/oneOf/${idx}`, tmpErrors);
88
- // if (tmpErrors.length === 0) matchCount++;
89
- // });
90
- // if (matchCount !== 1) {
91
- // errors.push({ keyword: "oneOf", dataPath: path ? `.${path}` : "", schemaPath: `${schemaPath}/oneOf`, params: {}, message: "should match exactly one schema in oneOf" });
92
- // }
93
- // return;
94
- // }
95
-
96
- }
97
-
98
- static validatePropertySchema(propertySchema, value) {
99
- const {
100
- schema
101
- } = propertySchema;
102
- const result = Validator.validateRequired(propertySchema, value);
103
- const isProvided = propertySchema.isValueProvided;
104
-
105
- if (result.isValid === false) {
106
- return result;
107
- }
108
-
109
- if (!isProvided) {
110
- return {
111
- isValid: true,
112
- errors: [],
113
- warnings: result.warnings
114
- };
115
- }
116
-
117
- const {
118
- isValid,
119
- errors,
120
- warnings
121
- } = Validator.validate(schema, value);
122
- return {
123
- key: propertySchema.name,
124
- isValid,
125
- errors,
126
- warnings: [...result.warnings, ...warnings]
127
- };
128
- }
129
-
130
- static validateRequired(propertySchema, value) {
131
- const errors = [];
132
- const warnings = [];
133
- const isRequired = propertySchema.required === true;
134
- const hasDefault = Object.prototype.hasOwnProperty.call(propertySchema, 'defaultValue');
135
- const isProvided = propertySchema.isValueProvided;
136
-
137
- if (!isProvided && isRequired) {
138
- if (hasDefault) {
139
- if (propertySchema.defaultValue === undefined) {
140
- errors.push({
141
- message: `is required but missing. So, default value is undefined.`
142
- });
143
- } else {
144
- warnings.push({
145
- message: `is required but missing. So, Default value will be used.`
146
- });
147
- }
148
- } else {
149
- errors.push({
150
- message: `is required but missing. And, neither a value nor a default value is present.`
151
- });
152
- }
153
- }
154
-
155
- return {
156
- isValid: errors.length === 0,
157
- warnings,
158
- errors
159
- };
160
- }
161
-
162
- }
163
-
164
- export default Validator;
1
+ export { default } from "../../../json-schema-validator/Validator";
@@ -2,7 +2,7 @@ import Presenter from "../../adapters/presenters/Presenter";
2
2
  import Service from "../../adapters/gateways/service/Service";
3
3
  import Controller from "../../adapters/controllers/Controller";
4
4
  import Repository from "../../adapters/gateways/repository/Repository";
5
- import Validator from "../json-schema-validator/Validator";
5
+ import { Validator } from "../../../json-schema-validator";
6
6
  import EventManager from "../../adapters/gateways/event-manager/EventManager";
7
7
 
8
8
  class DependencyFactory {
@@ -0,0 +1,338 @@
1
+ /* eslint-disable complexity */
2
+ export class Validator {
3
+ static validate(schema, value) {
4
+ if (schema.schema) {
5
+ return Validator.validatePropertySchema(schema, value);
6
+ }
7
+
8
+ const errors = [];
9
+ Validator.validateNode(schema, value, '', errors, schema.definitions || schema.$defs || {});
10
+ return {
11
+ isValid: errors.length === 0,
12
+ errors,
13
+ warnings: []
14
+ };
15
+ }
16
+
17
+ static validateNode(schema, value, dataPath, errors, rootDefinitions) {
18
+ if (!schema || typeof schema !== 'object') return; // undefined is not a JSON type — skip validation (matches AJV behavior)
19
+
20
+ if (value === undefined) return; // $ref resolution
21
+
22
+ if (schema.$ref) {
23
+ const resolved = Validator.resolveRef(schema.$ref, rootDefinitions);
24
+
25
+ if (resolved) {
26
+ Validator.validateNode(resolved, value, dataPath, errors, rootDefinitions);
27
+ }
28
+
29
+ return;
30
+ } // Hoist definitions from nested schema to root
31
+
32
+
33
+ const definitions = schema.definitions || schema.$defs ? { ...rootDefinitions,
34
+ ...(schema.definitions || schema.$defs)
35
+ } : rootDefinitions; // anyOf
36
+
37
+ if (schema.anyOf) {
38
+ const anyOfValid = schema.anyOf.some(subSchema => {
39
+ const subErrors = [];
40
+ Validator.validateNode(subSchema, value, dataPath, subErrors, definitions);
41
+ return subErrors.length === 0;
42
+ });
43
+
44
+ if (!anyOfValid) {
45
+ errors.push({
46
+ keyword: 'anyOf',
47
+ dataPath,
48
+ message: 'should match at least one schema in anyOf'
49
+ });
50
+ }
51
+
52
+ return;
53
+ } // oneOf
54
+
55
+
56
+ if (schema.oneOf) {
57
+ const matchCount = schema.oneOf.filter(subSchema => {
58
+ const subErrors = [];
59
+ Validator.validateNode(subSchema, value, dataPath, subErrors, definitions);
60
+ return subErrors.length === 0;
61
+ }).length;
62
+
63
+ if (matchCount !== 1) {
64
+ errors.push({
65
+ keyword: 'oneOf',
66
+ dataPath,
67
+ message: 'should match exactly one schema in oneOf'
68
+ });
69
+ }
70
+
71
+ return;
72
+ } // not
73
+
74
+
75
+ if (schema.not) {
76
+ const notErrors = [];
77
+ Validator.validateNode(schema.not, value, dataPath, notErrors, definitions);
78
+
79
+ if (notErrors.length === 0) {
80
+ errors.push({
81
+ keyword: 'not',
82
+ dataPath,
83
+ message: 'should NOT match schema in not'
84
+ });
85
+ }
86
+
87
+ return;
88
+ } // type validation
89
+
90
+
91
+ if (schema.type) {
92
+ if (!Validator.checkType(schema.type, value)) {
93
+ const typeLabel = Array.isArray(schema.type) ? schema.type.join(',') : schema.type;
94
+ errors.push({
95
+ keyword: 'type',
96
+ dataPath,
97
+ message: `should be ${typeLabel}`
98
+ });
99
+ return; // Type mismatch — skip further checks
100
+ }
101
+ } // enum
102
+
103
+
104
+ if (schema.enum) {
105
+ if (!schema.enum.includes(value)) {
106
+ errors.push({
107
+ keyword: 'enum',
108
+ dataPath,
109
+ message: `should be one of ${JSON.stringify(schema.enum)}`
110
+ });
111
+ }
112
+ } // String constraints
113
+
114
+
115
+ if (typeof value === 'string') {
116
+ if (schema.minLength !== undefined && value.length < schema.minLength) {
117
+ errors.push({
118
+ keyword: 'minLength',
119
+ dataPath,
120
+ message: `should have at least ${schema.minLength} characters`
121
+ });
122
+ }
123
+
124
+ if (schema.maxLength !== undefined && value.length > schema.maxLength) {
125
+ errors.push({
126
+ keyword: 'maxLength',
127
+ dataPath,
128
+ message: `should have at most ${schema.maxLength} characters`
129
+ });
130
+ }
131
+
132
+ if (schema.pattern !== undefined) {
133
+ const regex = new RegExp(schema.pattern);
134
+
135
+ if (!regex.test(value)) {
136
+ errors.push({
137
+ keyword: 'pattern',
138
+ dataPath,
139
+ message: `should match pattern "${schema.pattern}"`
140
+ });
141
+ }
142
+ }
143
+ } // Array constraints
144
+
145
+
146
+ if (Array.isArray(value)) {
147
+ if (schema.minItems !== undefined && value.length < schema.minItems) {
148
+ errors.push({
149
+ keyword: 'minItems',
150
+ dataPath,
151
+ message: `should have at least ${schema.minItems} items`
152
+ });
153
+ }
154
+
155
+ if (schema.uniqueItems === true) {
156
+ const seen = new Set();
157
+ const hasDuplicates = value.some(item => {
158
+ const key = typeof item === 'object' ? JSON.stringify(item) : item;
159
+ if (seen.has(key)) return true;
160
+ seen.add(key);
161
+ return false;
162
+ });
163
+
164
+ if (hasDuplicates) {
165
+ errors.push({
166
+ keyword: 'uniqueItems',
167
+ dataPath,
168
+ message: 'should have unique items'
169
+ });
170
+ }
171
+ }
172
+
173
+ if (schema.items) {
174
+ value.forEach((item, index) => {
175
+ Validator.validateNode(schema.items, item, `${dataPath}[${index}]`, errors, definitions);
176
+ });
177
+ }
178
+ } // Object constraints
179
+
180
+
181
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
182
+ if (schema.required) {
183
+ schema.required.forEach(key => {
184
+ if (!(key in value)) {
185
+ const propPath = dataPath ? `${dataPath}.${key}` : `.${key}`;
186
+ errors.push({
187
+ keyword: 'required',
188
+ dataPath: propPath,
189
+ message: `should have required property '${key}'`
190
+ });
191
+ }
192
+ });
193
+ }
194
+
195
+ if (schema.properties) {
196
+ for (const key in schema.properties) {
197
+ if (key in value) {
198
+ const propPath = dataPath ? `${dataPath}.${key}` : `.${key}`;
199
+ Validator.validateNode(schema.properties[key], value[key], propPath, errors, definitions);
200
+ }
201
+ }
202
+ }
203
+
204
+ if (schema.additionalProperties !== undefined && schema.additionalProperties !== true && schema.properties) {
205
+ const allowed = new Set(Object.keys(schema.properties));
206
+
207
+ for (const key in value) {
208
+ if (!allowed.has(key)) {
209
+ if (schema.additionalProperties === false) {
210
+ const propPath = dataPath ? `${dataPath}.${key}` : `.${key}`;
211
+ errors.push({
212
+ keyword: 'additionalProperties',
213
+ dataPath: propPath,
214
+ message: `should NOT have additional property '${key}'`
215
+ });
216
+ } else if (typeof schema.additionalProperties === 'object') {
217
+ const propPath = dataPath ? `${dataPath}.${key}` : `.${key}`;
218
+ Validator.validateNode(schema.additionalProperties, value[key], propPath, errors, definitions);
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+
226
+ static checkType(type, value) {
227
+ if (Array.isArray(type)) {
228
+ return type.some(t => Validator.checkSingleType(t, value));
229
+ }
230
+
231
+ return Validator.checkSingleType(type, value);
232
+ }
233
+
234
+ static checkSingleType(type, value) {
235
+ switch (type) {
236
+ case 'string':
237
+ return typeof value === 'string';
238
+
239
+ case 'number':
240
+ return typeof value === 'number';
241
+
242
+ case 'boolean':
243
+ return typeof value === 'boolean';
244
+
245
+ case 'object':
246
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
247
+
248
+ case 'array':
249
+ return Array.isArray(value);
250
+
251
+ case 'null':
252
+ return value === null;
253
+
254
+ case 'function':
255
+ return typeof value === 'function';
256
+
257
+ default:
258
+ return true;
259
+ // 'any' or unknown types — accept anything
260
+ }
261
+ }
262
+
263
+ static resolveRef(ref, definitions) {
264
+ // Supports: #/definitions/Name and #/$defs/Name
265
+ const match = ref.match(/^#\/(definitions|\$defs)\/(.+)$/);
266
+
267
+ if (match && definitions[match[2]]) {
268
+ return definitions[match[2]];
269
+ }
270
+
271
+ return null;
272
+ }
273
+
274
+ static validatePropertySchema(propertySchema, value) {
275
+ const {
276
+ schema
277
+ } = propertySchema;
278
+ const result = Validator.validateRequired(propertySchema, value);
279
+ const isProvided = propertySchema.isValueProvided;
280
+
281
+ if (result.isValid === false) {
282
+ return result;
283
+ }
284
+
285
+ if (!isProvided) {
286
+ return {
287
+ isValid: true,
288
+ errors: [],
289
+ warnings: result.warnings
290
+ };
291
+ }
292
+
293
+ const {
294
+ isValid,
295
+ errors,
296
+ warnings
297
+ } = Validator.validate(schema, value);
298
+ return {
299
+ key: propertySchema.name,
300
+ isValid,
301
+ errors,
302
+ warnings: [...result.warnings, ...warnings]
303
+ };
304
+ }
305
+
306
+ static validateRequired(propertySchema, value) {
307
+ const errors = [];
308
+ const warnings = [];
309
+ const isRequired = propertySchema.required === true;
310
+ const hasDefault = Object.prototype.hasOwnProperty.call(propertySchema, 'defaultValue');
311
+ const isProvided = propertySchema.isValueProvided;
312
+
313
+ if (!isProvided && isRequired) {
314
+ if (hasDefault) {
315
+ if (propertySchema.defaultValue === undefined) {
316
+ errors.push({
317
+ message: `is required but missing. So, default value is undefined.`
318
+ });
319
+ } else {
320
+ warnings.push({
321
+ message: `is required but missing. So, Default value will be used.`
322
+ });
323
+ }
324
+ } else {
325
+ errors.push({
326
+ message: `is required but missing. And, neither a value nor a default value is present.`
327
+ });
328
+ }
329
+ }
330
+
331
+ return {
332
+ isValid: errors.length === 0,
333
+ warnings,
334
+ errors
335
+ };
336
+ }
337
+
338
+ }