@zohodesk/library-platform 1.2.2 → 1.2.3

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 (45) hide show
  1. package/es/.DS_Store +0 -0
  2. package/es/cc/action-status/Constants.js +5 -0
  3. package/es/cc/action-status/Events.js +6 -0
  4. package/es/cc/action-status/Properties.js +29 -0
  5. package/es/cc/action-status/index.js +3 -0
  6. package/es/cc/button/Properties.js +28 -0
  7. package/es/cc/fields/field/Events.js +8 -0
  8. package/es/cc/highlighted-value/Properties.js +28 -0
  9. package/es/cc/index.js +1 -0
  10. package/es/cc/radio-dropdown/Events.js +16 -0
  11. package/es/cc/table-column-filter/Properties.js +9 -0
  12. package/es/cc/table-list/Events.js +8 -0
  13. package/es/library/custom-component/frameworks/ui/DependencyFactory.js +1 -1
  14. package/es/library/dot/components/action-location/frameworks/ui/ActionComponentMapping.js +3 -1
  15. package/es/library/dot/components/action-status/frameworks/ui/ActionStatus.js +12 -0
  16. package/es/library/dot/components/action-status/frameworks/ui/ActionStatusView.js +57 -0
  17. package/es/library/dot/components/action-status/frameworks/ui/css/ActionStatus.module.css +61 -0
  18. package/es/library/dot/components/form/frameworks/ui/sub-components/Footer.js +1 -1
  19. package/es/library/dot/components/table-list/adapters/controllers/FieldChangeController.js +4 -2
  20. package/es/library/dot/legacy-to-new-arch/button/frameworks/ui/ButtonView.js +17 -2
  21. package/es/library/dot/legacy-to-new-arch/highlighted-value/frameworks/ui/HighlightedValueView.js +13 -2
  22. package/es/library/dot/legacy-to-new-arch/highlighted-value/frameworks/ui/css/HighlightedValue.module.css +4 -0
  23. package/es/library/dot/legacy-to-new-arch/radio-dropdown/frameworks/ui/RadioDropdownView.js +3 -1
  24. package/es/library/dot/legacy-to-new-arch/table-column-filter/frameworks/ui/EventHandlersFactory.js +26 -0
  25. package/es/library/dot/legacy-to-new-arch/table-column-filter/frameworks/ui/TableColumnFilter.js +19 -1
  26. package/es/library/dot/legacy-to-new-arch/table-column-filter/frameworks/ui/TableColumnFilterView.js +3 -1
  27. package/es/library/dot/legacy-to-new-arch/table-field-components/checkbox-field/frameworks/ui/EventHandlersFactory.js +2 -1
  28. package/es/library/dot/legacy-to-new-arch/table-field-components/highlighted-value-field/frameworks/ui/HighlightedValueFieldView.js +8 -2
  29. package/es/library/dot/legacy-to-new-arch/table-field-components/radio-dropdown-field/frameworks/ui/EventHandlersFactory.js +4 -2
  30. package/es/library/dot/legacy-to-new-arch/table-field-components/switch-field/frameworks/ui/EventHandlersFactory.js +2 -1
  31. package/es/library/json-schema-validator/Validator.js +338 -0
  32. package/es/library/json-schema-validator/__tests__/Validator.test.js +753 -0
  33. package/es/library/json-schema-validator/index.js +1 -0
  34. package/es/platform/.DS_Store +0 -0
  35. package/es/platform/client-actions/cc/client-actions-renderer/Properties.js +1 -1
  36. package/es/platform/client-actions/cc/client-actions-renderer/ViewMetaSchema.js +1 -1
  37. package/es/platform/client-actions/components/client-actions-renderer/domain/entities/State.js +1 -8
  38. package/es/platform/client-actions/components/client-actions-renderer/frameworks/ui/client-actions-renderer/ClientActionsRendererView.js +2 -2
  39. package/es/platform/client-actions/components/client-actions-renderer/frameworks/ui/client-actions-renderer/views/DefaultActionsRendererView.js +2 -2
  40. package/es/platform/data-source/http-template/getAvailableFields.js +4 -2
  41. package/es/platform/sdk/application/interfaces/gateways/AbstractResource.js +1 -1
  42. package/es/platform/zform/domain/interfaces/IZForm.js +2 -5
  43. package/es/platform/zform/domain/interfaces/ValidationEvents.js +4 -0
  44. package/package.json +18 -6
  45. package/es/library/custom-component/frameworks/json-schema-validator/Validator.js +0 -164
@@ -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
+ }