@aemforms/af-core 0.22.157 → 0.22.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 +18 -0
- package/esm/afb-events.js +6 -1
- package/esm/afb-runtime.js +65 -9
- package/esm/types/src/Field.d.ts +1 -0
- package/esm/types/src/controller/Events.d.ts +10 -0
- package/esm/types/src/controller/Logger.d.ts +5 -5
- package/lib/BaseNode.js +2 -1
- package/lib/DateField.js +18 -0
- package/lib/Field.d.ts +1 -0
- package/lib/Field.js +5 -1
- package/lib/Scriptable.js +23 -4
- package/lib/controller/Events.d.ts +10 -0
- package/lib/controller/Events.js +7 -1
- package/lib/controller/Logger.d.ts +5 -5
- package/lib/rules/RuleEngine.js +20 -3
- package/lib/utils/DataRefParser.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,6 +33,24 @@ const data = {...}
|
|
|
33
33
|
const valid = validateFormInstance(formJson, data)
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
## Testing Local Changes
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Login to download dependencies
|
|
40
|
+
npm login
|
|
41
|
+
|
|
42
|
+
# Build the package
|
|
43
|
+
npm run build
|
|
44
|
+
|
|
45
|
+
# Link it for local testing
|
|
46
|
+
npm link
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
In your project that uses this package:
|
|
50
|
+
```bash
|
|
51
|
+
npm link @aemforms/af-core
|
|
52
|
+
```
|
|
53
|
+
|
|
36
54
|
## License
|
|
37
55
|
|
|
38
56
|
Copyright 2022 Adobe
|
package/esm/afb-events.js
CHANGED
|
@@ -192,5 +192,10 @@ class RequestFailure extends ActionImpl {
|
|
|
192
192
|
super(payload, 'requestFailure', { dispatch });
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
+
class ScriptError extends ActionImpl {
|
|
196
|
+
constructor(payload, dispatch = false) {
|
|
197
|
+
super(payload, 'scriptError', { dispatch });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
195
200
|
|
|
196
|
-
export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, RequestFailure, RequestSuccess, Reset, Save, Submit, SubmitError, SubmitFailure, SubmitSuccess, UIChange, Valid, ValidationComplete, propertyChange };
|
|
201
|
+
export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, RequestFailure, RequestSuccess, Reset, Save, ScriptError, Submit, SubmitError, SubmitFailure, SubmitSuccess, UIChange, Valid, ValidationComplete, propertyChange };
|
package/esm/afb-runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, RequestSuccess, RequestFailure, SubmitError, Submit, Save, SubmitFailure, Focus, Valid, Invalid, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete } from './afb-events.js';
|
|
1
|
+
import { propertyChange, ExecuteRule, ScriptError, Initialize, RemoveItem, SubmitSuccess, CustomEvent, RequestSuccess, RequestFailure, SubmitError, Submit, Save, SubmitFailure, Focus, Valid, Invalid, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete } from './afb-events.js';
|
|
2
2
|
import Formula from '@adobe/json-formula';
|
|
3
3
|
import { parseDefaultDate, datetimeToNumber, format, parseDateSkeleton, numberToDatetime, formatDate, parseDate } from '@aemforms/af-formatters';
|
|
4
4
|
|
|
@@ -545,7 +545,7 @@ const isAlphaNum = function (ch) {
|
|
|
545
545
|
return (ch >= 'a' && ch <= 'z')
|
|
546
546
|
|| (ch >= 'A' && ch <= 'Z')
|
|
547
547
|
|| (ch >= '0' && ch <= '9')
|
|
548
|
-
|| ch === '_';
|
|
548
|
+
|| ch === '_' || ch === '-';
|
|
549
549
|
};
|
|
550
550
|
const isGlobal = (prev, stream, pos) => {
|
|
551
551
|
return prev === null && stream[pos] === globalStartToken;
|
|
@@ -560,7 +560,7 @@ const isIdentifier = (stream, pos) => {
|
|
|
560
560
|
}
|
|
561
561
|
return (ch >= 'a' && ch <= 'z')
|
|
562
562
|
|| (ch >= 'A' && ch <= 'Z')
|
|
563
|
-
|| ch === '_';
|
|
563
|
+
|| ch === '_' || ch === '-';
|
|
564
564
|
};
|
|
565
565
|
const isNum = (ch) => {
|
|
566
566
|
return (ch >= '0' && ch <= '9');
|
|
@@ -1366,7 +1366,8 @@ const editableProperties = [
|
|
|
1366
1366
|
'maxItems',
|
|
1367
1367
|
'minimum',
|
|
1368
1368
|
'minItems',
|
|
1369
|
-
'checked'
|
|
1369
|
+
'checked',
|
|
1370
|
+
'placeholder'
|
|
1370
1371
|
];
|
|
1371
1372
|
const dynamicProps = [
|
|
1372
1373
|
...editableProperties,
|
|
@@ -1961,8 +1962,8 @@ class Scriptable extends BaseNode {
|
|
|
1961
1962
|
if (!(eName in this._rules)) {
|
|
1962
1963
|
const eString = rule || this.getRules()[eName];
|
|
1963
1964
|
if (typeof eString === 'string' && eString.length > 0) {
|
|
1965
|
+
let updatedRule = eString;
|
|
1964
1966
|
try {
|
|
1965
|
-
let updatedRule = eString;
|
|
1966
1967
|
if (this.fragment !== '$form') {
|
|
1967
1968
|
const sanitizedFragment = sanitizeName(this.fragment);
|
|
1968
1969
|
updatedRule = eString.replaceAll('$form', sanitizedFragment);
|
|
@@ -1970,7 +1971,16 @@ class Scriptable extends BaseNode {
|
|
|
1970
1971
|
this._rules[eName] = this.ruleEngine.compileRule(updatedRule, this.lang);
|
|
1971
1972
|
}
|
|
1972
1973
|
catch (e) {
|
|
1973
|
-
|
|
1974
|
+
const errorMsg = `Unable to compile rule \`"${eName}" : "${updatedRule}"\` Exception : ${e}`;
|
|
1975
|
+
this.form.logger.error(errorMsg);
|
|
1976
|
+
const errorPayload = {
|
|
1977
|
+
name: this.name,
|
|
1978
|
+
error: errorMsg,
|
|
1979
|
+
event: eName,
|
|
1980
|
+
rule: updatedRule,
|
|
1981
|
+
stack: e instanceof Error ? e.stack : undefined
|
|
1982
|
+
};
|
|
1983
|
+
this.form.dispatch(new ScriptError(errorPayload, false));
|
|
1974
1984
|
}
|
|
1975
1985
|
}
|
|
1976
1986
|
else {
|
|
@@ -1987,8 +1997,8 @@ class Scriptable extends BaseNode {
|
|
|
1987
1997
|
}
|
|
1988
1998
|
if (typeof eString !== 'undefined' && eString.length > 0) {
|
|
1989
1999
|
this._events[eName] = eString.map(x => {
|
|
2000
|
+
let updatedExpr = x;
|
|
1990
2001
|
try {
|
|
1991
|
-
let updatedExpr = x;
|
|
1992
2002
|
if (this.fragment !== '$form') {
|
|
1993
2003
|
const sanitizedFragment = sanitizeName(this.fragment);
|
|
1994
2004
|
updatedExpr = x.replaceAll('$form', sanitizedFragment);
|
|
@@ -1996,7 +2006,16 @@ class Scriptable extends BaseNode {
|
|
|
1996
2006
|
return this.ruleEngine.compileRule(updatedExpr, this.lang);
|
|
1997
2007
|
}
|
|
1998
2008
|
catch (e) {
|
|
1999
|
-
|
|
2009
|
+
const errorMsg = `Unable to compile expression \`"${eName}" : "${updatedExpr}"\` Exception : ${e}`;
|
|
2010
|
+
this.form.logger.error(errorMsg);
|
|
2011
|
+
const errorPayload = {
|
|
2012
|
+
name: this.name,
|
|
2013
|
+
error: errorMsg,
|
|
2014
|
+
event: eName,
|
|
2015
|
+
rule: updatedExpr,
|
|
2016
|
+
stack: e instanceof Error ? e.stack : undefined
|
|
2017
|
+
};
|
|
2018
|
+
this.form.dispatch(new ScriptError(errorPayload, false));
|
|
2000
2019
|
}
|
|
2001
2020
|
return null;
|
|
2002
2021
|
}).filter(x => x !== null);
|
|
@@ -4313,6 +4332,22 @@ class RuleEngine {
|
|
|
4313
4332
|
}
|
|
4314
4333
|
catch (err) {
|
|
4315
4334
|
this._context?.form?.logger?.error(err);
|
|
4335
|
+
if (this._context?.form) {
|
|
4336
|
+
const field = this._context?.field;
|
|
4337
|
+
const fieldName = field?.name;
|
|
4338
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
4339
|
+
const fullError = fieldName
|
|
4340
|
+
? `Script execution error in field "${fieldName}": ${errorMsg}. Expression: ${eString}`
|
|
4341
|
+
: `Script execution error: ${errorMsg}. Expression: ${eString}`;
|
|
4342
|
+
const errorPayload = {
|
|
4343
|
+
name: fieldName,
|
|
4344
|
+
error: fullError,
|
|
4345
|
+
event: this._context?.$event?.type,
|
|
4346
|
+
rule: eString,
|
|
4347
|
+
stack: err instanceof Error ? err.stack : undefined
|
|
4348
|
+
};
|
|
4349
|
+
this._context.form.dispatch(new ScriptError(errorPayload, false));
|
|
4350
|
+
}
|
|
4316
4351
|
}
|
|
4317
4352
|
if (this.debugInfo.length) {
|
|
4318
4353
|
this._context?.form?.logger?.warn(`Form rule expression string: ${eString}`);
|
|
@@ -4594,6 +4629,9 @@ class Field extends Scriptable {
|
|
|
4594
4629
|
get placeholder() {
|
|
4595
4630
|
return this._jsonModel.placeholder;
|
|
4596
4631
|
}
|
|
4632
|
+
set placeholder(value) {
|
|
4633
|
+
this._setProperty('placeholder', value);
|
|
4634
|
+
}
|
|
4597
4635
|
get readOnly() {
|
|
4598
4636
|
if (this.parent.readOnly !== undefined) {
|
|
4599
4637
|
return this.parent.readOnly === true ? true : this._jsonModel.readOnly;
|
|
@@ -4695,7 +4733,7 @@ class Field extends Scriptable {
|
|
|
4695
4733
|
}
|
|
4696
4734
|
get editValue() {
|
|
4697
4735
|
const df = this.editFormat;
|
|
4698
|
-
if (df && this.isNotEmpty(this.value) && this
|
|
4736
|
+
if (df && this.isNotEmpty(this.value) && this?.validity?.typeMismatch !== true) {
|
|
4699
4737
|
try {
|
|
4700
4738
|
return format(this.value, this.lang, df);
|
|
4701
4739
|
}
|
|
@@ -5405,6 +5443,20 @@ class CheckboxGroup extends Field {
|
|
|
5405
5443
|
}
|
|
5406
5444
|
}
|
|
5407
5445
|
|
|
5446
|
+
const warnedPatterns = new Set();
|
|
5447
|
+
function normalizeDatePattern(pattern) {
|
|
5448
|
+
if (!pattern || typeof pattern !== 'string') {
|
|
5449
|
+
return pattern;
|
|
5450
|
+
}
|
|
5451
|
+
const normalized = pattern
|
|
5452
|
+
.replace(/DD/g, 'dd')
|
|
5453
|
+
.replace(/YYYY/g, 'yyyy');
|
|
5454
|
+
if (normalized !== pattern && !warnedPatterns.has(pattern)) {
|
|
5455
|
+
warnedPatterns.add(pattern);
|
|
5456
|
+
console.warn(`[AEM Forms] Date field pattern "${pattern}" uses deprecated format. Auto-corrected to "${normalized}". Please update to use lowercase 'y' for year and 'd' for day.`);
|
|
5457
|
+
}
|
|
5458
|
+
return normalized;
|
|
5459
|
+
}
|
|
5408
5460
|
class DateField extends Field {
|
|
5409
5461
|
locale;
|
|
5410
5462
|
_dataFormat = 'yyyy-MM-dd';
|
|
@@ -5414,9 +5466,13 @@ class DateField extends Field {
|
|
|
5414
5466
|
if (!this._jsonModel.editFormat) {
|
|
5415
5467
|
this._jsonModel.editFormat = 'short';
|
|
5416
5468
|
}
|
|
5469
|
+
this._jsonModel.editFormat = normalizeDatePattern(this._jsonModel.editFormat);
|
|
5417
5470
|
if (!this._jsonModel.displayFormat) {
|
|
5418
5471
|
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
5419
5472
|
}
|
|
5473
|
+
else {
|
|
5474
|
+
this._jsonModel.displayFormat = normalizeDatePattern(this._jsonModel.displayFormat);
|
|
5475
|
+
}
|
|
5420
5476
|
if (!this._jsonModel.placeholder) {
|
|
5421
5477
|
this._jsonModel.placeholder = parseDateSkeleton(this._jsonModel.editFormat, this.locale);
|
|
5422
5478
|
}
|
package/esm/types/src/Field.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
32
32
|
get displayFormat(): string | undefined;
|
|
33
33
|
get displayValueExpression(): string | undefined;
|
|
34
34
|
get placeholder(): string | undefined;
|
|
35
|
+
set placeholder(value: string | undefined);
|
|
35
36
|
get readOnly(): boolean | undefined;
|
|
36
37
|
set readOnly(e: boolean | undefined);
|
|
37
38
|
get enabled(): boolean | undefined;
|
|
@@ -114,4 +114,14 @@ export declare class RequestSuccess extends ActionImpl {
|
|
|
114
114
|
export declare class RequestFailure extends ActionImpl {
|
|
115
115
|
constructor(payload?: any, dispatch?: boolean);
|
|
116
116
|
}
|
|
117
|
+
export type ScriptErrorPayload = {
|
|
118
|
+
name?: string;
|
|
119
|
+
error: string;
|
|
120
|
+
event?: string;
|
|
121
|
+
rule?: string;
|
|
122
|
+
stack?: string;
|
|
123
|
+
};
|
|
124
|
+
export declare class ScriptError extends ActionImpl {
|
|
125
|
+
constructor(payload: ScriptErrorPayload, dispatch?: boolean);
|
|
126
|
+
}
|
|
117
127
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export type LogFunction = 'info' | 'warn' | 'error' | 'debug';
|
|
2
2
|
export type LogLevel = 'off' | LogFunction;
|
|
3
3
|
export declare class Logger {
|
|
4
|
-
debug(msg:
|
|
5
|
-
info(msg:
|
|
6
|
-
warn(msg:
|
|
7
|
-
error(msg:
|
|
8
|
-
log(msg:
|
|
4
|
+
debug(msg: any): void;
|
|
5
|
+
info(msg: any): void;
|
|
6
|
+
warn(msg: any): void;
|
|
7
|
+
error(msg: any): void;
|
|
8
|
+
log(msg: any, level: LogFunction): void;
|
|
9
9
|
isLevelEnabled(level: LogFunction): boolean;
|
|
10
10
|
private logLevel;
|
|
11
11
|
constructor(logLevel?: LogLevel);
|
package/lib/BaseNode.js
CHANGED
package/lib/DateField.js
CHANGED
|
@@ -11,6 +11,20 @@ var _DateField_instances, _DateField_convertNumberToDate;
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const Field_1 = __importDefault(require("./Field"));
|
|
13
13
|
const af_formatters_1 = require("@aemforms/af-formatters");
|
|
14
|
+
const warnedPatterns = new Set();
|
|
15
|
+
function normalizeDatePattern(pattern) {
|
|
16
|
+
if (!pattern || typeof pattern !== 'string') {
|
|
17
|
+
return pattern;
|
|
18
|
+
}
|
|
19
|
+
const normalized = pattern
|
|
20
|
+
.replace(/DD/g, 'dd')
|
|
21
|
+
.replace(/YYYY/g, 'yyyy');
|
|
22
|
+
if (normalized !== pattern && !warnedPatterns.has(pattern)) {
|
|
23
|
+
warnedPatterns.add(pattern);
|
|
24
|
+
console.warn(`[AEM Forms] Date field pattern "${pattern}" uses deprecated format. Auto-corrected to "${normalized}". Please update to use lowercase 'y' for year and 'd' for day.`);
|
|
25
|
+
}
|
|
26
|
+
return normalized;
|
|
27
|
+
}
|
|
14
28
|
class DateField extends Field_1.default {
|
|
15
29
|
constructor() {
|
|
16
30
|
super(...arguments);
|
|
@@ -23,9 +37,13 @@ class DateField extends Field_1.default {
|
|
|
23
37
|
if (!this._jsonModel.editFormat) {
|
|
24
38
|
this._jsonModel.editFormat = 'short';
|
|
25
39
|
}
|
|
40
|
+
this._jsonModel.editFormat = normalizeDatePattern(this._jsonModel.editFormat);
|
|
26
41
|
if (!this._jsonModel.displayFormat) {
|
|
27
42
|
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
28
43
|
}
|
|
44
|
+
else {
|
|
45
|
+
this._jsonModel.displayFormat = normalizeDatePattern(this._jsonModel.displayFormat);
|
|
46
|
+
}
|
|
29
47
|
if (!this._jsonModel.placeholder) {
|
|
30
48
|
this._jsonModel.placeholder = (0, af_formatters_1.parseDateSkeleton)(this._jsonModel.editFormat, this.locale);
|
|
31
49
|
}
|
package/lib/Field.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
32
32
|
get displayFormat(): string | undefined;
|
|
33
33
|
get displayValueExpression(): string | undefined;
|
|
34
34
|
get placeholder(): string | undefined;
|
|
35
|
+
set placeholder(value: string | undefined);
|
|
35
36
|
get readOnly(): boolean | undefined;
|
|
36
37
|
set readOnly(e: boolean | undefined);
|
|
37
38
|
get enabled(): boolean | undefined;
|
package/lib/Field.js
CHANGED
|
@@ -212,6 +212,9 @@ class Field extends Scriptable_1.default {
|
|
|
212
212
|
get placeholder() {
|
|
213
213
|
return this._jsonModel.placeholder;
|
|
214
214
|
}
|
|
215
|
+
set placeholder(value) {
|
|
216
|
+
this._setProperty('placeholder', value);
|
|
217
|
+
}
|
|
215
218
|
get readOnly() {
|
|
216
219
|
if (this.parent.readOnly !== undefined) {
|
|
217
220
|
return this.parent.readOnly === true ? true : this._jsonModel.readOnly;
|
|
@@ -311,8 +314,9 @@ class Field extends Scriptable_1.default {
|
|
|
311
314
|
return df;
|
|
312
315
|
}
|
|
313
316
|
get editValue() {
|
|
317
|
+
var _a;
|
|
314
318
|
const df = this.editFormat;
|
|
315
|
-
if (df && this.isNotEmpty(this.value) && this.
|
|
319
|
+
if (df && this.isNotEmpty(this.value) && ((_a = this === null || this === void 0 ? void 0 : this.validity) === null || _a === void 0 ? void 0 : _a.typeMismatch) !== true) {
|
|
316
320
|
try {
|
|
317
321
|
return (0, af_formatters_1.format)(this.value, this.lang, df);
|
|
318
322
|
}
|
package/lib/Scriptable.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const BaseNode_1 = require("./BaseNode");
|
|
4
4
|
const FormUtils_1 = require("./utils/FormUtils");
|
|
5
|
+
const Events_1 = require("./controller/Events");
|
|
5
6
|
class Scriptable extends BaseNode_1.BaseNode {
|
|
6
7
|
constructor() {
|
|
7
8
|
super(...arguments);
|
|
@@ -15,8 +16,8 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
15
16
|
if (!(eName in this._rules)) {
|
|
16
17
|
const eString = rule || this.getRules()[eName];
|
|
17
18
|
if (typeof eString === 'string' && eString.length > 0) {
|
|
19
|
+
let updatedRule = eString;
|
|
18
20
|
try {
|
|
19
|
-
let updatedRule = eString;
|
|
20
21
|
if (this.fragment !== '$form') {
|
|
21
22
|
const sanitizedFragment = (0, FormUtils_1.sanitizeName)(this.fragment);
|
|
22
23
|
updatedRule = eString.replaceAll('$form', sanitizedFragment);
|
|
@@ -24,7 +25,16 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
24
25
|
this._rules[eName] = this.ruleEngine.compileRule(updatedRule, this.lang);
|
|
25
26
|
}
|
|
26
27
|
catch (e) {
|
|
27
|
-
|
|
28
|
+
const errorMsg = `Unable to compile rule \`"${eName}" : "${updatedRule}"\` Exception : ${e}`;
|
|
29
|
+
this.form.logger.error(errorMsg);
|
|
30
|
+
const errorPayload = {
|
|
31
|
+
name: this.name,
|
|
32
|
+
error: errorMsg,
|
|
33
|
+
event: eName,
|
|
34
|
+
rule: updatedRule,
|
|
35
|
+
stack: e instanceof Error ? e.stack : undefined
|
|
36
|
+
};
|
|
37
|
+
this.form.dispatch(new Events_1.ScriptError(errorPayload, false));
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
else {
|
|
@@ -42,8 +52,8 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
42
52
|
}
|
|
43
53
|
if (typeof eString !== 'undefined' && eString.length > 0) {
|
|
44
54
|
this._events[eName] = eString.map(x => {
|
|
55
|
+
let updatedExpr = x;
|
|
45
56
|
try {
|
|
46
|
-
let updatedExpr = x;
|
|
47
57
|
if (this.fragment !== '$form') {
|
|
48
58
|
const sanitizedFragment = (0, FormUtils_1.sanitizeName)(this.fragment);
|
|
49
59
|
updatedExpr = x.replaceAll('$form', sanitizedFragment);
|
|
@@ -51,7 +61,16 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
51
61
|
return this.ruleEngine.compileRule(updatedExpr, this.lang);
|
|
52
62
|
}
|
|
53
63
|
catch (e) {
|
|
54
|
-
|
|
64
|
+
const errorMsg = `Unable to compile expression \`"${eName}" : "${updatedExpr}"\` Exception : ${e}`;
|
|
65
|
+
this.form.logger.error(errorMsg);
|
|
66
|
+
const errorPayload = {
|
|
67
|
+
name: this.name,
|
|
68
|
+
error: errorMsg,
|
|
69
|
+
event: eName,
|
|
70
|
+
rule: updatedExpr,
|
|
71
|
+
stack: e instanceof Error ? e.stack : undefined
|
|
72
|
+
};
|
|
73
|
+
this.form.dispatch(new Events_1.ScriptError(errorPayload, false));
|
|
55
74
|
}
|
|
56
75
|
return null;
|
|
57
76
|
}).filter(x => x !== null);
|
|
@@ -114,4 +114,14 @@ export declare class RequestSuccess extends ActionImpl {
|
|
|
114
114
|
export declare class RequestFailure extends ActionImpl {
|
|
115
115
|
constructor(payload?: any, dispatch?: boolean);
|
|
116
116
|
}
|
|
117
|
+
export declare type ScriptErrorPayload = {
|
|
118
|
+
name?: string;
|
|
119
|
+
error: string;
|
|
120
|
+
event?: string;
|
|
121
|
+
rule?: string;
|
|
122
|
+
stack?: string;
|
|
123
|
+
};
|
|
124
|
+
export declare class ScriptError extends ActionImpl {
|
|
125
|
+
constructor(payload: ScriptErrorPayload, dispatch?: boolean);
|
|
126
|
+
}
|
|
117
127
|
export {};
|
package/lib/controller/Events.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestFailure = exports.RequestSuccess = exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.SubmitError = exports.SubmitFailure = exports.SubmitSuccess = exports.Save = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.UIChange = exports.Change = void 0;
|
|
3
|
+
exports.ScriptError = exports.RequestFailure = exports.RequestSuccess = exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.SubmitError = exports.SubmitFailure = exports.SubmitSuccess = exports.Save = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.UIChange = exports.Change = void 0;
|
|
4
4
|
var EventSource;
|
|
5
5
|
(function (EventSource) {
|
|
6
6
|
EventSource["CODE"] = "code";
|
|
@@ -216,3 +216,9 @@ class RequestFailure extends ActionImpl {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
exports.RequestFailure = RequestFailure;
|
|
219
|
+
class ScriptError extends ActionImpl {
|
|
220
|
+
constructor(payload, dispatch = false) {
|
|
221
|
+
super(payload, 'scriptError', { dispatch });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.ScriptError = ScriptError;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare type LogFunction = 'info' | 'warn' | 'error' | 'debug';
|
|
2
2
|
export declare type LogLevel = 'off' | LogFunction;
|
|
3
3
|
export declare class Logger {
|
|
4
|
-
debug(msg:
|
|
5
|
-
info(msg:
|
|
6
|
-
warn(msg:
|
|
7
|
-
error(msg:
|
|
8
|
-
log(msg:
|
|
4
|
+
debug(msg: any): void;
|
|
5
|
+
info(msg: any): void;
|
|
6
|
+
warn(msg: any): void;
|
|
7
|
+
error(msg: any): void;
|
|
8
|
+
log(msg: any, level: LogFunction): void;
|
|
9
9
|
isLevelEnabled(level: LogFunction): boolean;
|
|
10
10
|
private logLevel;
|
|
11
11
|
constructor(logLevel?: LogLevel);
|
package/lib/rules/RuleEngine.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const json_formula_1 = __importDefault(require("@adobe/json-formula"));
|
|
7
7
|
const FunctionRuntime_1 = require("./FunctionRuntime");
|
|
8
8
|
const CoercionUtils_1 = require("../utils/CoercionUtils");
|
|
9
|
+
const Events_1 = require("../controller/Events");
|
|
9
10
|
function getStringToNumberFn(locale) {
|
|
10
11
|
if (locale == null) {
|
|
11
12
|
const localeOptions = new Intl.DateTimeFormat().resolvedOptions();
|
|
@@ -29,7 +30,7 @@ class RuleEngine {
|
|
|
29
30
|
return { formula, ast: formula.compile(rule, this._globalNames) };
|
|
30
31
|
}
|
|
31
32
|
execute(node, data, globals, useValueOf = false, eString) {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
33
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
33
34
|
const { formula, ast } = node;
|
|
34
35
|
const oldContext = this._context;
|
|
35
36
|
this._context = globals;
|
|
@@ -39,11 +40,27 @@ class RuleEngine {
|
|
|
39
40
|
}
|
|
40
41
|
catch (err) {
|
|
41
42
|
(_c = (_b = (_a = this._context) === null || _a === void 0 ? void 0 : _a.form) === null || _b === void 0 ? void 0 : _b.logger) === null || _c === void 0 ? void 0 : _c.error(err);
|
|
43
|
+
if ((_d = this._context) === null || _d === void 0 ? void 0 : _d.form) {
|
|
44
|
+
const field = (_e = this._context) === null || _e === void 0 ? void 0 : _e.field;
|
|
45
|
+
const fieldName = field === null || field === void 0 ? void 0 : field.name;
|
|
46
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
47
|
+
const fullError = fieldName
|
|
48
|
+
? `Script execution error in field "${fieldName}": ${errorMsg}. Expression: ${eString}`
|
|
49
|
+
: `Script execution error: ${errorMsg}. Expression: ${eString}`;
|
|
50
|
+
const errorPayload = {
|
|
51
|
+
name: fieldName,
|
|
52
|
+
error: fullError,
|
|
53
|
+
event: (_g = (_f = this._context) === null || _f === void 0 ? void 0 : _f.$event) === null || _g === void 0 ? void 0 : _g.type,
|
|
54
|
+
rule: eString,
|
|
55
|
+
stack: err instanceof Error ? err.stack : undefined
|
|
56
|
+
};
|
|
57
|
+
this._context.form.dispatch(new Events_1.ScriptError(errorPayload, false));
|
|
58
|
+
}
|
|
42
59
|
}
|
|
43
60
|
if (this.debugInfo.length) {
|
|
44
|
-
(
|
|
61
|
+
(_k = (_j = (_h = this._context) === null || _h === void 0 ? void 0 : _h.form) === null || _j === void 0 ? void 0 : _j.logger) === null || _k === void 0 ? void 0 : _k.warn(`Form rule expression string: ${eString}`);
|
|
45
62
|
while (this.debugInfo.length > 0) {
|
|
46
|
-
(
|
|
63
|
+
(_o = (_m = (_l = this._context) === null || _l === void 0 ? void 0 : _l.form) === null || _m === void 0 ? void 0 : _m.logger) === null || _o === void 0 ? void 0 : _o.warn(this.debugInfo.pop());
|
|
47
64
|
}
|
|
48
65
|
}
|
|
49
66
|
let finalRes = res;
|
|
@@ -49,7 +49,7 @@ const isAlphaNum = function (ch) {
|
|
|
49
49
|
return (ch >= 'a' && ch <= 'z')
|
|
50
50
|
|| (ch >= 'A' && ch <= 'Z')
|
|
51
51
|
|| (ch >= '0' && ch <= '9')
|
|
52
|
-
|| ch === '_';
|
|
52
|
+
|| ch === '_' || ch === '-';
|
|
53
53
|
};
|
|
54
54
|
const isGlobal = (prev, stream, pos) => {
|
|
55
55
|
return prev === null && stream[pos] === globalStartToken;
|
|
@@ -64,7 +64,7 @@ const isIdentifier = (stream, pos) => {
|
|
|
64
64
|
}
|
|
65
65
|
return (ch >= 'a' && ch <= 'z')
|
|
66
66
|
|| (ch >= 'A' && ch <= 'Z')
|
|
67
|
-
|| ch === '_';
|
|
67
|
+
|| ch === '_' || ch === '-';
|
|
68
68
|
};
|
|
69
69
|
const isNum = (ch) => {
|
|
70
70
|
return (ch >= '0' && ch <= '9');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.161",
|
|
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.
|
|
40
|
+
"@aemforms/af-formatters": "^0.22.161"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|