@aemforms/af-core 0.22.149 → 0.22.151

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.
@@ -26,7 +26,8 @@ const ConstraintType = Object.freeze({
26
26
  MAX_ITEMS_MISMATCH: 'maxItemsMismatch',
27
27
  EXPRESSION_MISMATCH: 'expressionMismatch',
28
28
  EXCLUSIVE_MAXIMUM_MISMATCH: 'exclusiveMaximumMismatch',
29
- EXCLUSIVE_MINIMUM_MISMATCH: 'exclusiveMinimumMismatch'
29
+ EXCLUSIVE_MINIMUM_MISMATCH: 'exclusiveMinimumMismatch',
30
+ ENUM_MISMATCH: 'enumMismatch'
30
31
  });
31
32
  const constraintKeys = Object.freeze({
32
33
  pattern: ConstraintType.PATTERN_MISMATCH,
@@ -45,7 +46,8 @@ const constraintKeys = Object.freeze({
45
46
  maxItems: ConstraintType.MAX_ITEMS_MISMATCH,
46
47
  validationExpression: ConstraintType.EXPRESSION_MISMATCH,
47
48
  exclusiveMinimum: ConstraintType.EXCLUSIVE_MINIMUM_MISMATCH,
48
- exclusiveMaximum: ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH
49
+ exclusiveMaximum: ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH,
50
+ enum: ConstraintType.ENUM_MISMATCH
49
51
  });
50
52
  const defaultConstraintTypeMessages = Object.freeze({
51
53
  [ConstraintType.PATTERN_MISMATCH]: 'Please match the format requested.',
@@ -64,7 +66,8 @@ const defaultConstraintTypeMessages = Object.freeze({
64
66
  [ConstraintType.MAX_ITEMS_MISMATCH]: 'Specify a number of items equal to or less than ${0}.',
65
67
  [ConstraintType.EXPRESSION_MISMATCH]: 'Please enter a valid value.',
66
68
  [ConstraintType.EXCLUSIVE_MINIMUM_MISMATCH]: 'Value must be greater than ${0}.',
67
- [ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH]: 'Value must be less than ${0}.'
69
+ [ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH]: 'Value must be less than ${0}.',
70
+ [ConstraintType.ENUM_MISMATCH]: 'Please select a value from the allowed options.'
68
71
  });
69
72
  let customConstraintTypeMessages = {};
70
73
  const getConstraintTypeMessages = () => {
@@ -358,6 +361,22 @@ class DataValue {
358
361
  $bindToField(field) {
359
362
  if (this.$_fields.indexOf(field) === -1) {
360
363
  this.$_fields.push(field);
364
+ this._checkForTypeConflicts(field);
365
+ }
366
+ }
367
+ _checkForTypeConflicts(newField) {
368
+ if (this.$_fields.length <= 1) {
369
+ return;
370
+ }
371
+ const newFieldType = newField.type;
372
+ const conflictingFields = this.$_fields.filter(existingField => existingField &&
373
+ existingField !== newField &&
374
+ existingField.type !== newFieldType);
375
+ if (conflictingFields.length > 0) {
376
+ const conflictDetails = conflictingFields.map(field => `Field "${field.id}" (${field.type})`).join(', ');
377
+ console.error('Type conflict detected: Multiple fields with same dataRef have different types. ' +
378
+ `New field '${newField.id}' (${newFieldType}) conflicts with: ${conflictDetails}. ` +
379
+ `DataRef: ${this.$name}`);
361
380
  }
362
381
  }
363
382
  $convertToDataValue() {
@@ -1393,6 +1412,9 @@ const addOnly = (includeOrExclude) => (...fieldTypes) => (target, propertyKey, d
1393
1412
  const set = descriptor.set;
1394
1413
  if (set != undefined) {
1395
1414
  descriptor.set = function (value) {
1415
+ if (this === this._ruleNode) {
1416
+ console.error(`Property '${propertyKey}' is being set through a proxy, which is not supported. Please use globals.functions.setProperty instead.`);
1417
+ }
1396
1418
  if (fieldTypes.indexOf(this.fieldType) > -1 === includeOrExclude) {
1397
1419
  set.call(this, value);
1398
1420
  }
@@ -1649,16 +1671,16 @@ class BaseNode {
1649
1671
  this.form.getEventQueue().runPendingQueue();
1650
1672
  }
1651
1673
  withDependencyTrackingControl(disableDependencyTracking, callback) {
1652
- const currentDependencyTracking = this.form.ruleEngine.getDependencyTracking();
1674
+ const currentDependencyTracking = this.form?.ruleEngine.getDependencyTracking();
1653
1675
  if (disableDependencyTracking) {
1654
- this.form.ruleEngine.setDependencyTracking(false);
1676
+ this.form?.ruleEngine.setDependencyTracking(false);
1655
1677
  }
1656
1678
  try {
1657
1679
  return callback();
1658
1680
  }
1659
1681
  finally {
1660
1682
  if (disableDependencyTracking) {
1661
- this.form.ruleEngine.setDependencyTracking(currentDependencyTracking);
1683
+ this.form?.ruleEngine.setDependencyTracking(currentDependencyTracking);
1662
1684
  }
1663
1685
  }
1664
1686
  }
@@ -3585,12 +3607,26 @@ class FunctionRuntimeImpl {
3585
3607
  interpreter.globals.form.logger.error('Argument is missing in getQueryParameter. A parameter is expected');
3586
3608
  return '';
3587
3609
  }
3588
- if (interpreter.globals.form?.properties?.queryParams?.[param]) {
3589
- return interpreter.globals.form.properties.queryParams[param.toLowerCase()];
3610
+ const queryParams = interpreter.globals.form?.properties?.queryParams;
3611
+ if (queryParams) {
3612
+ if (queryParams[param] !== undefined) {
3613
+ return queryParams[param];
3614
+ }
3615
+ const lowerParam = param.toLowerCase();
3616
+ for (const [key, value] of Object.entries(queryParams)) {
3617
+ if (key.toLowerCase() === lowerParam) {
3618
+ return value;
3619
+ }
3620
+ }
3590
3621
  }
3591
3622
  try {
3592
3623
  const urlParams = new URLSearchParams(window?.location?.search || '');
3593
- return urlParams.get(param);
3624
+ const urlValue = urlParams.get(param) ||
3625
+ Array.from(urlParams.entries())
3626
+ .find(([key]) => key.toLowerCase() === param.toLowerCase())?.[1];
3627
+ if (urlValue !== null && urlValue !== undefined) {
3628
+ return urlValue;
3629
+ }
3594
3630
  }
3595
3631
  catch (e) {
3596
3632
  interpreter.globals.form.logger.warn('Error reading URL parameters:', e);
@@ -4768,10 +4804,10 @@ class Field extends Scriptable {
4768
4804
  if (this._jsonModel.enforceEnum === true && value != null) {
4769
4805
  const fn = constraints.enum;
4770
4806
  if (value instanceof Array && this.isArrayType()) {
4771
- return value.every(x => fn(this.enum || [], x).valid);
4807
+ return value.every(x => fn(this._jsonModel.enum || [], x).valid);
4772
4808
  }
4773
4809
  else {
4774
- return fn(this.enum || [], value).valid;
4810
+ return fn(this._jsonModel.enum || [], value).valid;
4775
4811
  }
4776
4812
  }
4777
4813
  return true;
@@ -13,6 +13,7 @@ export default class DataValue {
13
13
  setValue(typedValue: any, originalValue: any, fromField: FieldModel): void;
14
14
  get $type(): string;
15
15
  $bindToField(field: FieldModel): void;
16
+ private _checkForTypeConflicts;
16
17
  $convertToDataValue(): DataValue;
17
18
  get $isDataGroup(): boolean;
18
19
  $addDataNode(name: string | number, value: DataValue, override?: boolean): void;
@@ -148,6 +148,7 @@ export declare const ConstraintType: Readonly<{
148
148
  EXPRESSION_MISMATCH: "expressionMismatch";
149
149
  EXCLUSIVE_MAXIMUM_MISMATCH: "exclusiveMaximumMismatch";
150
150
  EXCLUSIVE_MINIMUM_MISMATCH: "exclusiveMinimumMismatch";
151
+ ENUM_MISMATCH: "enumMismatch";
151
152
  }>;
152
153
  export declare const constraintKeys: Readonly<{
153
154
  pattern: "patternMismatch";
@@ -167,6 +168,7 @@ export declare const constraintKeys: Readonly<{
167
168
  validationExpression: "expressionMismatch";
168
169
  exclusiveMinimum: "exclusiveMinimumMismatch";
169
170
  exclusiveMaximum: "exclusiveMaximumMismatch";
171
+ enum: "enumMismatch";
170
172
  }>;
171
173
  export declare const setCustomDefaultConstraintTypeMessages: (messages: Record<string, string>) => void;
172
174
  export declare const getConstraintTypeMessages: () => {
@@ -187,5 +189,6 @@ export declare const getConstraintTypeMessages: () => {
187
189
  expressionMismatch: "Please enter a valid value.";
188
190
  exclusiveMinimumMismatch: "Value must be greater than ${0}.";
189
191
  exclusiveMaximumMismatch: "Value must be less than ${0}.";
192
+ enumMismatch: "Please select a value from the allowed options.";
190
193
  };
191
194
  export {};
package/lib/BaseNode.js CHANGED
@@ -107,6 +107,9 @@ const addOnly = (includeOrExclude) => (...fieldTypes) => (target, propertyKey, d
107
107
  const set = descriptor.set;
108
108
  if (set != undefined) {
109
109
  descriptor.set = function (value) {
110
+ if (this === this._ruleNode) {
111
+ console.error(`Property '${propertyKey}' is being set through a proxy, which is not supported. Please use globals.functions.setProperty instead.`);
112
+ }
110
113
  if (fieldTypes.indexOf(this.fieldType) > -1 === includeOrExclude) {
111
114
  set.call(this, value);
112
115
  }
@@ -347,16 +350,17 @@ class BaseNode {
347
350
  this.form.getEventQueue().runPendingQueue();
348
351
  }
349
352
  withDependencyTrackingControl(disableDependencyTracking, callback) {
350
- const currentDependencyTracking = this.form.ruleEngine.getDependencyTracking();
353
+ var _a, _b, _c;
354
+ const currentDependencyTracking = (_a = this.form) === null || _a === void 0 ? void 0 : _a.ruleEngine.getDependencyTracking();
351
355
  if (disableDependencyTracking) {
352
- this.form.ruleEngine.setDependencyTracking(false);
356
+ (_b = this.form) === null || _b === void 0 ? void 0 : _b.ruleEngine.setDependencyTracking(false);
353
357
  }
354
358
  try {
355
359
  return callback();
356
360
  }
357
361
  finally {
358
362
  if (disableDependencyTracking) {
359
- this.form.ruleEngine.setDependencyTracking(currentDependencyTracking);
363
+ (_c = this.form) === null || _c === void 0 ? void 0 : _c.ruleEngine.setDependencyTracking(currentDependencyTracking);
360
364
  }
361
365
  }
362
366
  }
package/lib/Field.js CHANGED
@@ -504,10 +504,10 @@ class Field extends Scriptable_1.default {
504
504
  if (this._jsonModel.enforceEnum === true && value != null) {
505
505
  const fn = constraints.enum;
506
506
  if (value instanceof Array && this.isArrayType()) {
507
- return value.every(x => fn(this.enum || [], x).valid);
507
+ return value.every(x => fn(this._jsonModel.enum || [], x).valid);
508
508
  }
509
509
  else {
510
- return fn(this.enum || [], value).valid;
510
+ return fn(this._jsonModel.enum || [], value).valid;
511
511
  }
512
512
  }
513
513
  return true;
@@ -13,6 +13,7 @@ export default class DataValue {
13
13
  setValue(typedValue: any, originalValue: any, fromField: FieldModel): void;
14
14
  get $type(): string;
15
15
  $bindToField(field: FieldModel): void;
16
+ private _checkForTypeConflicts;
16
17
  $convertToDataValue(): DataValue;
17
18
  get $isDataGroup(): boolean;
18
19
  $addDataNode(name: string | number, value: DataValue, override?: boolean): void;
@@ -53,6 +53,22 @@ class DataValue {
53
53
  $bindToField(field) {
54
54
  if (this.$_fields.indexOf(field) === -1) {
55
55
  this.$_fields.push(field);
56
+ this._checkForTypeConflicts(field);
57
+ }
58
+ }
59
+ _checkForTypeConflicts(newField) {
60
+ if (this.$_fields.length <= 1) {
61
+ return;
62
+ }
63
+ const newFieldType = newField.type;
64
+ const conflictingFields = this.$_fields.filter(existingField => existingField &&
65
+ existingField !== newField &&
66
+ existingField.type !== newFieldType);
67
+ if (conflictingFields.length > 0) {
68
+ const conflictDetails = conflictingFields.map(field => `Field "${field.id}" (${field.type})`).join(', ');
69
+ console.error('Type conflict detected: Multiple fields with same dataRef have different types. ' +
70
+ `New field '${newField.id}' (${newFieldType}) conflicts with: ${conflictDetails}. ` +
71
+ `DataRef: ${this.$name}`);
56
72
  }
57
73
  }
58
74
  $convertToDataValue() {
@@ -755,12 +755,26 @@ class FunctionRuntimeImpl {
755
755
  interpreter.globals.form.logger.error('Argument is missing in getQueryParameter. A parameter is expected');
756
756
  return '';
757
757
  }
758
- if ((_c = (_b = (_a = interpreter.globals.form) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.queryParams) === null || _c === void 0 ? void 0 : _c[param]) {
759
- return interpreter.globals.form.properties.queryParams[param.toLowerCase()];
758
+ const queryParams = (_b = (_a = interpreter.globals.form) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.queryParams;
759
+ if (queryParams) {
760
+ if (queryParams[param] !== undefined) {
761
+ return queryParams[param];
762
+ }
763
+ const lowerParam = param.toLowerCase();
764
+ for (const [key, value] of Object.entries(queryParams)) {
765
+ if (key.toLowerCase() === lowerParam) {
766
+ return value;
767
+ }
768
+ }
760
769
  }
761
770
  try {
762
- const urlParams = new URLSearchParams(((_d = window === null || window === void 0 ? void 0 : window.location) === null || _d === void 0 ? void 0 : _d.search) || '');
763
- return urlParams.get(param);
771
+ const urlParams = new URLSearchParams(((_c = window === null || window === void 0 ? void 0 : window.location) === null || _c === void 0 ? void 0 : _c.search) || '');
772
+ const urlValue = urlParams.get(param) ||
773
+ ((_d = Array.from(urlParams.entries())
774
+ .find(([key]) => key.toLowerCase() === param.toLowerCase())) === null || _d === void 0 ? void 0 : _d[1]);
775
+ if (urlValue !== null && urlValue !== undefined) {
776
+ return urlValue;
777
+ }
764
778
  }
765
779
  catch (e) {
766
780
  interpreter.globals.form.logger.warn('Error reading URL parameters:', e);
@@ -148,6 +148,7 @@ export declare const ConstraintType: Readonly<{
148
148
  EXPRESSION_MISMATCH: "expressionMismatch";
149
149
  EXCLUSIVE_MAXIMUM_MISMATCH: "exclusiveMaximumMismatch";
150
150
  EXCLUSIVE_MINIMUM_MISMATCH: "exclusiveMinimumMismatch";
151
+ ENUM_MISMATCH: "enumMismatch";
151
152
  }>;
152
153
  export declare const constraintKeys: Readonly<{
153
154
  pattern: "patternMismatch";
@@ -167,6 +168,7 @@ export declare const constraintKeys: Readonly<{
167
168
  validationExpression: "expressionMismatch";
168
169
  exclusiveMinimum: "exclusiveMinimumMismatch";
169
170
  exclusiveMaximum: "exclusiveMaximumMismatch";
171
+ enum: "enumMismatch";
170
172
  }>;
171
173
  export declare const setCustomDefaultConstraintTypeMessages: (messages: Record<string, string>) => void;
172
174
  export declare const getConstraintTypeMessages: () => {
@@ -187,5 +189,6 @@ export declare const getConstraintTypeMessages: () => {
187
189
  expressionMismatch: "Please enter a valid value.";
188
190
  exclusiveMinimumMismatch: "Value must be greater than ${0}.";
189
191
  exclusiveMaximumMismatch: "Value must be less than ${0}.";
192
+ enumMismatch: "Please select a value from the allowed options.";
190
193
  };
191
194
  export {};
package/lib/types/Json.js CHANGED
@@ -25,7 +25,8 @@ exports.ConstraintType = Object.freeze({
25
25
  MAX_ITEMS_MISMATCH: 'maxItemsMismatch',
26
26
  EXPRESSION_MISMATCH: 'expressionMismatch',
27
27
  EXCLUSIVE_MAXIMUM_MISMATCH: 'exclusiveMaximumMismatch',
28
- EXCLUSIVE_MINIMUM_MISMATCH: 'exclusiveMinimumMismatch'
28
+ EXCLUSIVE_MINIMUM_MISMATCH: 'exclusiveMinimumMismatch',
29
+ ENUM_MISMATCH: 'enumMismatch'
29
30
  });
30
31
  exports.constraintKeys = Object.freeze({
31
32
  pattern: exports.ConstraintType.PATTERN_MISMATCH,
@@ -44,7 +45,8 @@ exports.constraintKeys = Object.freeze({
44
45
  maxItems: exports.ConstraintType.MAX_ITEMS_MISMATCH,
45
46
  validationExpression: exports.ConstraintType.EXPRESSION_MISMATCH,
46
47
  exclusiveMinimum: exports.ConstraintType.EXCLUSIVE_MINIMUM_MISMATCH,
47
- exclusiveMaximum: exports.ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH
48
+ exclusiveMaximum: exports.ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH,
49
+ enum: exports.ConstraintType.ENUM_MISMATCH
48
50
  });
49
51
  const defaultConstraintTypeMessages = Object.freeze({
50
52
  [exports.ConstraintType.PATTERN_MISMATCH]: 'Please match the format requested.',
@@ -63,7 +65,8 @@ const defaultConstraintTypeMessages = Object.freeze({
63
65
  [exports.ConstraintType.MAX_ITEMS_MISMATCH]: 'Specify a number of items equal to or less than ${0}.',
64
66
  [exports.ConstraintType.EXPRESSION_MISMATCH]: 'Please enter a valid value.',
65
67
  [exports.ConstraintType.EXCLUSIVE_MINIMUM_MISMATCH]: 'Value must be greater than ${0}.',
66
- [exports.ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH]: 'Value must be less than ${0}.'
68
+ [exports.ConstraintType.EXCLUSIVE_MAXIMUM_MISMATCH]: 'Value must be less than ${0}.',
69
+ [exports.ConstraintType.ENUM_MISMATCH]: 'Please select a value from the allowed options.'
67
70
  });
68
71
  const transformObjectKeys = (obj, transformer) => {
69
72
  if (typeof obj !== 'object' || obj === null) {
@@ -81,7 +84,13 @@ const transformObjectKeys = (obj, transformer) => {
81
84
  };
82
85
  let customConstraintTypeMessages = {};
83
86
  const setCustomDefaultConstraintTypeMessages = (messages) => {
84
- customConstraintTypeMessages = transformObjectKeys(messages, (key) => {
87
+ const validMessages = Object.entries(messages).reduce((acc, [key, value]) => {
88
+ if (exports.constraintKeys[key] !== undefined) {
89
+ acc[key] = value;
90
+ }
91
+ return acc;
92
+ }, {});
93
+ customConstraintTypeMessages = transformObjectKeys(validMessages, (key) => {
85
94
  return exports.constraintKeys[key];
86
95
  });
87
96
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.149",
3
+ "version": "0.22.151",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@adobe/json-formula": "0.1.50",
40
- "@aemforms/af-formatters": "^0.22.149"
40
+ "@aemforms/af-formatters": "^0.22.151"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",