@aemforms/af-core 0.22.15 → 0.22.16
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/lib/Scriptable.js +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +4 -1
- package/lib/rules/FunctionRuntime.d.ts +4 -4
- package/lib/rules/FunctionRuntime.js +72 -26
- package/lib/rules/RuleEngine.js +2 -5
- package/package.json +2 -2
package/lib/Scriptable.js
CHANGED
|
@@ -148,7 +148,7 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
148
148
|
if (node) {
|
|
149
149
|
updates = this.ruleEngine.execute(node, this.getExpressionScope(), context);
|
|
150
150
|
}
|
|
151
|
-
if (typeof updates !== 'undefined') {
|
|
151
|
+
if (typeof updates !== 'undefined' && updates != null) {
|
|
152
152
|
this.applyUpdates(updates);
|
|
153
153
|
}
|
|
154
154
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -24,4 +24,5 @@ import FormMetaData from './FormMetaData';
|
|
|
24
24
|
import Node from './Node';
|
|
25
25
|
import Scriptable from './Scriptable';
|
|
26
26
|
import Form from './Form';
|
|
27
|
-
|
|
27
|
+
import { FunctionRuntime, request } from './rules/FunctionRuntime';
|
|
28
|
+
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, FunctionRuntime, request };
|
package/lib/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.extractFileInfo = exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
|
|
27
|
+
exports.request = exports.FunctionRuntime = exports.extractFileInfo = exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
|
|
28
28
|
__exportStar(require("./FormInstance"), exports);
|
|
29
29
|
__exportStar(require("./types/index"), exports);
|
|
30
30
|
__exportStar(require("./controller/index"), exports);
|
|
@@ -58,3 +58,6 @@ const Scriptable_1 = __importDefault(require("./Scriptable"));
|
|
|
58
58
|
exports.Scriptable = Scriptable_1.default;
|
|
59
59
|
const Form_1 = __importDefault(require("./Form"));
|
|
60
60
|
exports.Form = Form_1.default;
|
|
61
|
+
const FunctionRuntime_1 = require("./rules/FunctionRuntime");
|
|
62
|
+
Object.defineProperty(exports, "FunctionRuntime", { enumerable: true, get: function () { return FunctionRuntime_1.FunctionRuntime; } });
|
|
63
|
+
Object.defineProperty(exports, "request", { enumerable: true, get: function () { return FunctionRuntime_1.request; } });
|
|
@@ -7,10 +7,10 @@ declare type HTTP_VERB = 'GET' | 'POST';
|
|
|
7
7
|
* @param payload request payload
|
|
8
8
|
* @param success success handler
|
|
9
9
|
* @param error error handler
|
|
10
|
-
* @param
|
|
10
|
+
* @param headers headers
|
|
11
11
|
* @private
|
|
12
12
|
*/
|
|
13
|
-
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string,
|
|
13
|
+
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<void>;
|
|
14
14
|
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data', input_data?: any) => Promise<void>;
|
|
15
15
|
declare type CustomFunction = Function;
|
|
16
16
|
declare type FunctionDefinition = {
|
|
@@ -65,5 +65,5 @@ declare class FunctionRuntimeImpl {
|
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
-
declare const FunctionRuntime: FunctionRuntimeImpl;
|
|
69
|
-
export
|
|
68
|
+
export declare const FunctionRuntime: FunctionRuntimeImpl;
|
|
69
|
+
export {};
|
|
@@ -16,7 +16,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.submit = exports.request = void 0;
|
|
19
|
+
exports.FunctionRuntime = exports.submit = exports.request = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* Implementation of function runtime in rule engine
|
|
22
22
|
*/
|
|
@@ -26,6 +26,13 @@ const Fetch_1 = require("../utils/Fetch");
|
|
|
26
26
|
const FileObject_1 = require("../FileObject");
|
|
27
27
|
const FormUtils_1 = require("../utils/FormUtils");
|
|
28
28
|
const JsonUtils_1 = require("../utils/JsonUtils");
|
|
29
|
+
const getCustomEventName = (name) => {
|
|
30
|
+
const eName = name;
|
|
31
|
+
if (eName.length > 0 && eName.startsWith('custom:')) {
|
|
32
|
+
return eName.substring('custom:'.length);
|
|
33
|
+
}
|
|
34
|
+
return eName;
|
|
35
|
+
};
|
|
29
36
|
/**
|
|
30
37
|
* Implementation of generic request API. This API can be used to make external web request
|
|
31
38
|
* @param context expression execution context(consists of current form, current field, current event)
|
|
@@ -34,10 +41,11 @@ const JsonUtils_1 = require("../utils/JsonUtils");
|
|
|
34
41
|
* @param payload request payload
|
|
35
42
|
* @param success success handler
|
|
36
43
|
* @param error error handler
|
|
37
|
-
* @param
|
|
44
|
+
* @param headers headers
|
|
38
45
|
* @private
|
|
39
46
|
*/
|
|
40
|
-
const request = (context, uri, httpVerb, payload, success, error,
|
|
47
|
+
const request = (context, uri, httpVerb, payload, success, error, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
var _a;
|
|
41
49
|
const endpoint = uri;
|
|
42
50
|
const requestOptions = {
|
|
43
51
|
method: httpVerb
|
|
@@ -55,24 +63,50 @@ const request = (context, uri, httpVerb, payload, success, error, payloadContent
|
|
|
55
63
|
inputPayload = payload;
|
|
56
64
|
}
|
|
57
65
|
else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
const headerNames = Object.keys(headers);
|
|
67
|
+
if (headerNames.length > 0) {
|
|
68
|
+
requestOptions.headers = Object.assign(Object.assign({}, headers), (headerNames.indexOf('Content-Type') === -1 ? { 'Content-Type': 'application/json' } : {}) // this should match content type of the payload
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
requestOptions.headers = { 'Content-Type': 'application/json' };
|
|
73
|
+
}
|
|
74
|
+
const contentType = ((_a = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) || 'application/json';
|
|
75
|
+
if (contentType === 'application/json') {
|
|
76
|
+
inputPayload = JSON.stringify(payload);
|
|
77
|
+
}
|
|
78
|
+
else if (contentType.indexOf('multipart/form-data') > -1) {
|
|
79
|
+
inputPayload = multipartFormData(payload);
|
|
80
|
+
}
|
|
81
|
+
else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
|
|
82
|
+
inputPayload = urlEncoded(payload);
|
|
62
83
|
}
|
|
63
|
-
inputPayload = JSON.stringify(payload);
|
|
64
84
|
}
|
|
65
85
|
result = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
|
|
66
86
|
}
|
|
67
87
|
catch (e) {
|
|
68
88
|
//todo: define error payload
|
|
69
89
|
context.form.logger.error('Error invoking a rest API');
|
|
70
|
-
|
|
90
|
+
const eName = getCustomEventName(error);
|
|
91
|
+
context.form.dispatch(new Controller_1.CustomEvent(eName, {}, true));
|
|
71
92
|
return;
|
|
72
93
|
}
|
|
73
|
-
|
|
94
|
+
const eName = getCustomEventName(success);
|
|
95
|
+
context.form.dispatch(new Controller_1.CustomEvent(eName, result, true));
|
|
74
96
|
});
|
|
75
97
|
exports.request = request;
|
|
98
|
+
const urlEncoded = (data) => {
|
|
99
|
+
const formData = new URLSearchParams();
|
|
100
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
101
|
+
if (value != null && typeof value === 'object') {
|
|
102
|
+
formData.append(key, (0, JsonUtils_1.jsonString)(value));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
formData.append(key, value);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return formData;
|
|
109
|
+
};
|
|
76
110
|
/**
|
|
77
111
|
* Create multi part form data using form data and form attachments
|
|
78
112
|
* @param data form data
|
|
@@ -99,16 +133,18 @@ const multipartFormData = (data, attachments) => {
|
|
|
99
133
|
formData.append(attIdentifier, objValue.data);
|
|
100
134
|
}
|
|
101
135
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
136
|
+
if (attachments) {
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
Object.keys(attachments).reduce((acc, curr) => {
|
|
139
|
+
const objValue = attachments[curr];
|
|
140
|
+
if (objValue && objValue instanceof Array) {
|
|
141
|
+
return [...acc, ...objValue.map((x) => addAttachmentToFormData(x, formData))];
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return [...acc, addAttachmentToFormData(objValue, formData)];
|
|
145
|
+
}
|
|
146
|
+
}, []);
|
|
147
|
+
}
|
|
112
148
|
return formData;
|
|
113
149
|
};
|
|
114
150
|
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -131,7 +167,9 @@ const submit = (context, success, error, submitAs = 'multipart/form-data', input
|
|
|
131
167
|
}
|
|
132
168
|
// submitContentType = submitAs;
|
|
133
169
|
// note: don't send multipart/form-data let browser decide on the content type
|
|
134
|
-
yield (0, exports.request)(context, endpoint, 'POST', formData, success, error,
|
|
170
|
+
yield (0, exports.request)(context, endpoint, 'POST', formData, success, error, {
|
|
171
|
+
'Content-Type': submitContentType
|
|
172
|
+
});
|
|
135
173
|
});
|
|
136
174
|
exports.submit = submit;
|
|
137
175
|
/**
|
|
@@ -279,9 +317,18 @@ class FunctionRuntimeImpl {
|
|
|
279
317
|
const uri = toString(args[0]);
|
|
280
318
|
const httpVerb = toString(args[1]);
|
|
281
319
|
const payload = valueOf(args[2]);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
320
|
+
let success, error, headers = {};
|
|
321
|
+
if (typeof (args[3]) === 'string') {
|
|
322
|
+
interpreter.globals.form.logger.warn('This usage of request is deprecated. Please see the documentation and update');
|
|
323
|
+
success = valueOf(args[3]);
|
|
324
|
+
error = valueOf(args[4]);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
headers = valueOf(args[3]);
|
|
328
|
+
success = valueOf(args[4]);
|
|
329
|
+
error = valueOf(args[5]);
|
|
330
|
+
}
|
|
331
|
+
(0, exports.request)(interpreter.globals, uri, httpVerb, payload, success, error, headers);
|
|
285
332
|
return {};
|
|
286
333
|
},
|
|
287
334
|
_signature: []
|
|
@@ -327,5 +374,4 @@ class FunctionRuntimeImpl {
|
|
|
327
374
|
return Object.assign(Object.assign({}, defaultFunctions), this.customFunctions);
|
|
328
375
|
}
|
|
329
376
|
}
|
|
330
|
-
|
|
331
|
-
exports.default = FunctionRuntime;
|
|
377
|
+
exports.FunctionRuntime = new FunctionRuntimeImpl();
|
package/lib/rules/RuleEngine.js
CHANGED
|
@@ -6,12 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
8
|
*/
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
10
|
const json_formula_1 = require("@adobe/json-formula");
|
|
14
|
-
const FunctionRuntime_1 =
|
|
11
|
+
const FunctionRuntime_1 = require("./FunctionRuntime");
|
|
15
12
|
/**
|
|
16
13
|
* Implementation of rule engine
|
|
17
14
|
* @private
|
|
@@ -25,7 +22,7 @@ class RuleEngine {
|
|
|
25
22
|
];
|
|
26
23
|
}
|
|
27
24
|
compileRule(rule) {
|
|
28
|
-
const customFunctions = FunctionRuntime_1.
|
|
25
|
+
const customFunctions = FunctionRuntime_1.FunctionRuntime.getFunctions();
|
|
29
26
|
return new json_formula_1.Formula(rule, customFunctions, undefined, this._globalNames);
|
|
30
27
|
}
|
|
31
28
|
execute(node, data, globals, useValueOf = false) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.16",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@adobe/json-formula": "^0.1.44",
|
|
38
|
-
"@aemforms/af-formatters": "^0.22.
|
|
38
|
+
"@aemforms/af-formatters": "^0.22.16"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jest": "^27.5.1",
|