@aemforms/af-core 0.22.157 → 0.22.158
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/esm/afb-events.js +6 -1
- package/esm/afb-runtime.js +39 -5
- package/esm/types/src/controller/Events.d.ts +10 -0
- package/esm/types/src/controller/Logger.d.ts +5 -5
- 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/package.json +2 -2
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
|
|
|
@@ -1961,8 +1961,8 @@ class Scriptable extends BaseNode {
|
|
|
1961
1961
|
if (!(eName in this._rules)) {
|
|
1962
1962
|
const eString = rule || this.getRules()[eName];
|
|
1963
1963
|
if (typeof eString === 'string' && eString.length > 0) {
|
|
1964
|
+
let updatedRule = eString;
|
|
1964
1965
|
try {
|
|
1965
|
-
let updatedRule = eString;
|
|
1966
1966
|
if (this.fragment !== '$form') {
|
|
1967
1967
|
const sanitizedFragment = sanitizeName(this.fragment);
|
|
1968
1968
|
updatedRule = eString.replaceAll('$form', sanitizedFragment);
|
|
@@ -1970,7 +1970,16 @@ class Scriptable extends BaseNode {
|
|
|
1970
1970
|
this._rules[eName] = this.ruleEngine.compileRule(updatedRule, this.lang);
|
|
1971
1971
|
}
|
|
1972
1972
|
catch (e) {
|
|
1973
|
-
|
|
1973
|
+
const errorMsg = `Unable to compile rule \`"${eName}" : "${updatedRule}"\` Exception : ${e}`;
|
|
1974
|
+
this.form.logger.error(errorMsg);
|
|
1975
|
+
const errorPayload = {
|
|
1976
|
+
name: this.name,
|
|
1977
|
+
error: errorMsg,
|
|
1978
|
+
event: eName,
|
|
1979
|
+
rule: updatedRule,
|
|
1980
|
+
stack: e instanceof Error ? e.stack : undefined
|
|
1981
|
+
};
|
|
1982
|
+
this.form.dispatch(new ScriptError(errorPayload, false));
|
|
1974
1983
|
}
|
|
1975
1984
|
}
|
|
1976
1985
|
else {
|
|
@@ -1987,8 +1996,8 @@ class Scriptable extends BaseNode {
|
|
|
1987
1996
|
}
|
|
1988
1997
|
if (typeof eString !== 'undefined' && eString.length > 0) {
|
|
1989
1998
|
this._events[eName] = eString.map(x => {
|
|
1999
|
+
let updatedExpr = x;
|
|
1990
2000
|
try {
|
|
1991
|
-
let updatedExpr = x;
|
|
1992
2001
|
if (this.fragment !== '$form') {
|
|
1993
2002
|
const sanitizedFragment = sanitizeName(this.fragment);
|
|
1994
2003
|
updatedExpr = x.replaceAll('$form', sanitizedFragment);
|
|
@@ -1996,7 +2005,16 @@ class Scriptable extends BaseNode {
|
|
|
1996
2005
|
return this.ruleEngine.compileRule(updatedExpr, this.lang);
|
|
1997
2006
|
}
|
|
1998
2007
|
catch (e) {
|
|
1999
|
-
|
|
2008
|
+
const errorMsg = `Unable to compile expression \`"${eName}" : "${updatedExpr}"\` Exception : ${e}`;
|
|
2009
|
+
this.form.logger.error(errorMsg);
|
|
2010
|
+
const errorPayload = {
|
|
2011
|
+
name: this.name,
|
|
2012
|
+
error: errorMsg,
|
|
2013
|
+
event: eName,
|
|
2014
|
+
rule: updatedExpr,
|
|
2015
|
+
stack: e instanceof Error ? e.stack : undefined
|
|
2016
|
+
};
|
|
2017
|
+
this.form.dispatch(new ScriptError(errorPayload, false));
|
|
2000
2018
|
}
|
|
2001
2019
|
return null;
|
|
2002
2020
|
}).filter(x => x !== null);
|
|
@@ -4313,6 +4331,22 @@ class RuleEngine {
|
|
|
4313
4331
|
}
|
|
4314
4332
|
catch (err) {
|
|
4315
4333
|
this._context?.form?.logger?.error(err);
|
|
4334
|
+
if (this._context?.form) {
|
|
4335
|
+
const field = this._context?.field;
|
|
4336
|
+
const fieldName = field?.name;
|
|
4337
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
4338
|
+
const fullError = fieldName
|
|
4339
|
+
? `Script execution error in field "${fieldName}": ${errorMsg}. Expression: ${eString}`
|
|
4340
|
+
: `Script execution error: ${errorMsg}. Expression: ${eString}`;
|
|
4341
|
+
const errorPayload = {
|
|
4342
|
+
name: fieldName,
|
|
4343
|
+
error: fullError,
|
|
4344
|
+
event: this._context?.$event?.type,
|
|
4345
|
+
rule: eString,
|
|
4346
|
+
stack: err instanceof Error ? err.stack : undefined
|
|
4347
|
+
};
|
|
4348
|
+
this._context.form.dispatch(new ScriptError(errorPayload, false));
|
|
4349
|
+
}
|
|
4316
4350
|
}
|
|
4317
4351
|
if (this.debugInfo.length) {
|
|
4318
4352
|
this._context?.form?.logger?.warn(`Form rule expression string: ${eString}`);
|
|
@@ -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/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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.158",
|
|
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.158"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|