@aemforms/af-core 0.22.85 → 0.22.86
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-runtime.js +47 -19
- package/esm/types/src/Captcha.d.ts +2 -0
- package/esm/types/src/Form.d.ts +2 -0
- package/esm/types/src/Scriptable.d.ts +1 -1
- package/esm/types/src/rules/FunctionRuntime.d.ts +1 -1
- package/lib/Captcha.d.ts +2 -0
- package/lib/Captcha.js +3 -0
- package/lib/Form.d.ts +2 -0
- package/lib/Form.js +7 -0
- package/lib/Scriptable.d.ts +1 -1
- package/lib/rules/FunctionRuntime.d.ts +1 -1
- package/lib/rules/FunctionRuntime.js +40 -21
- package/package.json +3 -2
package/esm/afb-runtime.js
CHANGED
|
@@ -2553,6 +2553,24 @@ const urlEncoded = (data) => {
|
|
|
2553
2553
|
});
|
|
2554
2554
|
return formData;
|
|
2555
2555
|
};
|
|
2556
|
+
const submit = async (context, success, error, submitAs = 'multipart/form-data', input_data = null, action = '', metadata = null) => {
|
|
2557
|
+
const endpoint = action || context.form.action;
|
|
2558
|
+
let data = input_data;
|
|
2559
|
+
if (typeof data != 'object' || data == null) {
|
|
2560
|
+
data = context.form.exportData();
|
|
2561
|
+
}
|
|
2562
|
+
const attachments = getAttachments(context.form, true);
|
|
2563
|
+
let submitContentType = submitAs;
|
|
2564
|
+
const submitDataAndMetaData = { 'data': data, ...metadata };
|
|
2565
|
+
let formData = submitDataAndMetaData;
|
|
2566
|
+
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
2567
|
+
formData = multipartFormData(submitDataAndMetaData, attachments);
|
|
2568
|
+
submitContentType = 'multipart/form-data';
|
|
2569
|
+
}
|
|
2570
|
+
await request(context, endpoint, 'POST', formData, success, error, {
|
|
2571
|
+
'Content-Type': submitContentType
|
|
2572
|
+
});
|
|
2573
|
+
};
|
|
2556
2574
|
const multipartFormData = (data, attachments) => {
|
|
2557
2575
|
const formData = new FormData();
|
|
2558
2576
|
Object.entries(data).forEach(([key, value]) => {
|
|
@@ -2585,24 +2603,6 @@ const multipartFormData = (data, attachments) => {
|
|
|
2585
2603
|
}
|
|
2586
2604
|
return formData;
|
|
2587
2605
|
};
|
|
2588
|
-
const submit = async (context, success, error, submitAs = 'multipart/form-data', input_data = null, action = '', metadata = null) => {
|
|
2589
|
-
const endpoint = action || context.form.action;
|
|
2590
|
-
let data = input_data;
|
|
2591
|
-
if (typeof data != 'object' || data == null) {
|
|
2592
|
-
data = context.form.exportData();
|
|
2593
|
-
}
|
|
2594
|
-
const attachments = getAttachments(context.form, true);
|
|
2595
|
-
let submitContentType = submitAs;
|
|
2596
|
-
const submitDataAndMetaData = { 'data': data, ...metadata };
|
|
2597
|
-
let formData = submitDataAndMetaData;
|
|
2598
|
-
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
2599
|
-
formData = multipartFormData(submitDataAndMetaData, attachments);
|
|
2600
|
-
submitContentType = 'multipart/form-data';
|
|
2601
|
-
}
|
|
2602
|
-
await request(context, endpoint, 'POST', formData, success, error, {
|
|
2603
|
-
'Content-Type': submitContentType
|
|
2604
|
-
});
|
|
2605
|
-
};
|
|
2606
2606
|
const createAction = (name, payload = {}) => {
|
|
2607
2607
|
switch (name) {
|
|
2608
2608
|
case 'change':
|
|
@@ -2799,7 +2799,7 @@ class FunctionRuntimeImpl {
|
|
|
2799
2799
|
_signature: []
|
|
2800
2800
|
},
|
|
2801
2801
|
submitForm: {
|
|
2802
|
-
_func: (args, data, interpreter) => {
|
|
2802
|
+
_func: async (args, data, interpreter) => {
|
|
2803
2803
|
let success = null;
|
|
2804
2804
|
let error = null;
|
|
2805
2805
|
let submit_data;
|
|
@@ -2818,6 +2818,24 @@ class FunctionRuntimeImpl {
|
|
|
2818
2818
|
submit_data = args.length > 3 ? valueOf(args[3]) : null;
|
|
2819
2819
|
validate_form = args.length > 4 ? valueOf(args[4]) : true;
|
|
2820
2820
|
}
|
|
2821
|
+
const form = interpreter.globals.form;
|
|
2822
|
+
if (form.captcha && form.captcha.properties['fd:captcha'].config.version === 'enterprise'
|
|
2823
|
+
&& form.captcha.properties['fd:captcha'].config.keyType === 'score') {
|
|
2824
|
+
if (typeof interpreter.runtime.functionTable.fetchCaptchaToken?._func !== 'function') {
|
|
2825
|
+
interpreter.globals.form.logger.error('fetchCaptchaToken is not defined');
|
|
2826
|
+
interpreter.globals.form.dispatch(new SubmitError({ type: 'FetchCaptchaTokenNotDefined' }));
|
|
2827
|
+
return {};
|
|
2828
|
+
}
|
|
2829
|
+
try {
|
|
2830
|
+
const token = await interpreter.runtime.functionTable.fetchCaptchaToken._func([], data, interpreter);
|
|
2831
|
+
form.captcha.value = token;
|
|
2832
|
+
}
|
|
2833
|
+
catch (e) {
|
|
2834
|
+
interpreter.globals.form.logger.error('Error while fetching captcha token');
|
|
2835
|
+
interpreter.globals.form.dispatch(new SubmitError({ type: 'FetchCaptchaTokenFailed' }));
|
|
2836
|
+
return {};
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2821
2839
|
interpreter.globals.form.dispatch(new Submit({
|
|
2822
2840
|
success,
|
|
2823
2841
|
error,
|
|
@@ -2981,6 +2999,7 @@ class Form extends Container {
|
|
|
2981
2999
|
_fields = {};
|
|
2982
3000
|
_ids;
|
|
2983
3001
|
_invalidFields = [];
|
|
3002
|
+
_captcha = null;
|
|
2984
3003
|
constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue(), logLevel = 'off', mode = 'create') {
|
|
2985
3004
|
super(n, { fieldFactory: fieldFactory, mode });
|
|
2986
3005
|
this._ruleEngine = _ruleEngine;
|
|
@@ -3184,6 +3203,9 @@ class Form extends Container {
|
|
|
3184
3203
|
return this._ids.next().value;
|
|
3185
3204
|
}
|
|
3186
3205
|
fieldAdded(field) {
|
|
3206
|
+
if (field.fieldType === 'captcha' && !this._captcha) {
|
|
3207
|
+
this._captcha = field;
|
|
3208
|
+
}
|
|
3187
3209
|
this._fields[field.id] = field;
|
|
3188
3210
|
field.subscribe((action) => {
|
|
3189
3211
|
if (this._invalidFields.indexOf(action.target.id) === -1) {
|
|
@@ -3315,6 +3337,9 @@ class Form extends Container {
|
|
|
3315
3337
|
get title() {
|
|
3316
3338
|
return this._jsonModel.title || '';
|
|
3317
3339
|
}
|
|
3340
|
+
get captcha() {
|
|
3341
|
+
return this._captcha;
|
|
3342
|
+
}
|
|
3318
3343
|
}
|
|
3319
3344
|
|
|
3320
3345
|
function stringToNumber(str, language) {
|
|
@@ -4452,6 +4477,9 @@ class Captcha extends Field {
|
|
|
4452
4477
|
getDataNode() {
|
|
4453
4478
|
return undefined;
|
|
4454
4479
|
}
|
|
4480
|
+
custom_setProperty(action) {
|
|
4481
|
+
this.applyUpdates(action.payload);
|
|
4482
|
+
}
|
|
4455
4483
|
}
|
|
4456
4484
|
|
|
4457
4485
|
class Button extends Field {
|
package/esm/types/src/Form.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
15
15
|
private _fields;
|
|
16
16
|
_ids: Generator<string, void, string>;
|
|
17
17
|
private _invalidFields;
|
|
18
|
+
private _captcha;
|
|
18
19
|
constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
|
|
19
20
|
protected _applyDefaultsInModel(): void;
|
|
20
21
|
private _logger;
|
|
@@ -135,5 +136,6 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
135
136
|
get value(): null;
|
|
136
137
|
get id(): string;
|
|
137
138
|
get title(): string;
|
|
139
|
+
get captcha(): FieldModel | null;
|
|
138
140
|
}
|
|
139
141
|
export default Form;
|
|
@@ -8,7 +8,7 @@ declare abstract class Scriptable<T extends RulesJson> extends BaseNode<T> imple
|
|
|
8
8
|
getRules(): import("./types/Json").Items<string>;
|
|
9
9
|
private getCompiledRule;
|
|
10
10
|
private getCompiledEvent;
|
|
11
|
-
|
|
11
|
+
protected applyUpdates(updates: any): void;
|
|
12
12
|
protected executeAllRules(context: any): void;
|
|
13
13
|
private getExpressionScope;
|
|
14
14
|
private executeEvent;
|
|
@@ -37,7 +37,7 @@ declare class FunctionRuntimeImpl {
|
|
|
37
37
|
_signature: never[];
|
|
38
38
|
};
|
|
39
39
|
submitForm: {
|
|
40
|
-
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {}
|
|
40
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<{}>;
|
|
41
41
|
_signature: never[];
|
|
42
42
|
};
|
|
43
43
|
saveForm: {
|
package/lib/Captcha.d.ts
CHANGED
package/lib/Captcha.js
CHANGED
package/lib/Form.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
15
15
|
private _fields;
|
|
16
16
|
_ids: Generator<string, void, string>;
|
|
17
17
|
private _invalidFields;
|
|
18
|
+
private _captcha;
|
|
18
19
|
constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
|
|
19
20
|
protected _applyDefaultsInModel(): void;
|
|
20
21
|
private _logger;
|
|
@@ -135,5 +136,6 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
135
136
|
get value(): null;
|
|
136
137
|
get id(): string;
|
|
137
138
|
get title(): string;
|
|
139
|
+
get captcha(): FieldModel | null;
|
|
138
140
|
}
|
|
139
141
|
export default Form;
|
package/lib/Form.js
CHANGED
|
@@ -32,6 +32,7 @@ class Form extends Container_1.default {
|
|
|
32
32
|
this.additionalSubmitMetadata = {};
|
|
33
33
|
this._fields = {};
|
|
34
34
|
this._invalidFields = [];
|
|
35
|
+
this._captcha = null;
|
|
35
36
|
this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
|
|
36
37
|
this._logger = new Logger_1.Logger(logLevel);
|
|
37
38
|
this._applyDefaultsInModel();
|
|
@@ -192,6 +193,9 @@ class Form extends Container_1.default {
|
|
|
192
193
|
return this._ids.next().value;
|
|
193
194
|
}
|
|
194
195
|
fieldAdded(field) {
|
|
196
|
+
if (field.fieldType === 'captcha' && !this._captcha) {
|
|
197
|
+
this._captcha = field;
|
|
198
|
+
}
|
|
195
199
|
this._fields[field.id] = field;
|
|
196
200
|
field.subscribe((action) => {
|
|
197
201
|
if (this._invalidFields.indexOf(action.target.id) === -1) {
|
|
@@ -326,6 +330,9 @@ class Form extends Container_1.default {
|
|
|
326
330
|
get title() {
|
|
327
331
|
return this._jsonModel.title || '';
|
|
328
332
|
}
|
|
333
|
+
get captcha() {
|
|
334
|
+
return this._captcha;
|
|
335
|
+
}
|
|
329
336
|
}
|
|
330
337
|
_Form_instances = new WeakSet(), _Form_getNavigableChildren = function _Form_getNavigableChildren(children) {
|
|
331
338
|
return children.filter(child => child.visible === true);
|
package/lib/Scriptable.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare abstract class Scriptable<T extends RulesJson> extends BaseNode<T> imple
|
|
|
8
8
|
getRules(): import("./types/Json").Items<string>;
|
|
9
9
|
private getCompiledRule;
|
|
10
10
|
private getCompiledEvent;
|
|
11
|
-
|
|
11
|
+
protected applyUpdates(updates: any): void;
|
|
12
12
|
protected executeAllRules(context: any): void;
|
|
13
13
|
private getExpressionScope;
|
|
14
14
|
private executeEvent;
|
|
@@ -37,7 +37,7 @@ declare class FunctionRuntimeImpl {
|
|
|
37
37
|
_signature: never[];
|
|
38
38
|
};
|
|
39
39
|
submitForm: {
|
|
40
|
-
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {}
|
|
40
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<{}>;
|
|
41
41
|
_signature: never[];
|
|
42
42
|
};
|
|
43
43
|
saveForm: {
|
|
@@ -91,6 +91,25 @@ const urlEncoded = (data) => {
|
|
|
91
91
|
});
|
|
92
92
|
return formData;
|
|
93
93
|
};
|
|
94
|
+
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null, action = '', metadata = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
const endpoint = action || context.form.action;
|
|
96
|
+
let data = input_data;
|
|
97
|
+
if (typeof data != 'object' || data == null) {
|
|
98
|
+
data = context.form.exportData();
|
|
99
|
+
}
|
|
100
|
+
const attachments = (0, FormUtils_1.getAttachments)(context.form, true);
|
|
101
|
+
let submitContentType = submitAs;
|
|
102
|
+
const submitDataAndMetaData = Object.assign({ 'data': data }, metadata);
|
|
103
|
+
let formData = submitDataAndMetaData;
|
|
104
|
+
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
105
|
+
formData = multipartFormData(submitDataAndMetaData, attachments);
|
|
106
|
+
submitContentType = 'multipart/form-data';
|
|
107
|
+
}
|
|
108
|
+
yield (0, exports.request)(context, endpoint, 'POST', formData, success, error, {
|
|
109
|
+
'Content-Type': submitContentType
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
exports.submit = submit;
|
|
94
113
|
const multipartFormData = (data, attachments) => {
|
|
95
114
|
const formData = new FormData();
|
|
96
115
|
Object.entries(data).forEach(([key, value]) => {
|
|
@@ -123,25 +142,6 @@ const multipartFormData = (data, attachments) => {
|
|
|
123
142
|
}
|
|
124
143
|
return formData;
|
|
125
144
|
};
|
|
126
|
-
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null, action = '', metadata = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
-
const endpoint = action || context.form.action;
|
|
128
|
-
let data = input_data;
|
|
129
|
-
if (typeof data != 'object' || data == null) {
|
|
130
|
-
data = context.form.exportData();
|
|
131
|
-
}
|
|
132
|
-
const attachments = (0, FormUtils_1.getAttachments)(context.form, true);
|
|
133
|
-
let submitContentType = submitAs;
|
|
134
|
-
const submitDataAndMetaData = Object.assign({ 'data': data }, metadata);
|
|
135
|
-
let formData = submitDataAndMetaData;
|
|
136
|
-
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
137
|
-
formData = multipartFormData(submitDataAndMetaData, attachments);
|
|
138
|
-
submitContentType = 'multipart/form-data';
|
|
139
|
-
}
|
|
140
|
-
yield (0, exports.request)(context, endpoint, 'POST', formData, success, error, {
|
|
141
|
-
'Content-Type': submitContentType
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
exports.submit = submit;
|
|
145
145
|
const createAction = (name, payload = {}) => {
|
|
146
146
|
switch (name) {
|
|
147
147
|
case 'change':
|
|
@@ -338,7 +338,8 @@ class FunctionRuntimeImpl {
|
|
|
338
338
|
_signature: []
|
|
339
339
|
},
|
|
340
340
|
submitForm: {
|
|
341
|
-
_func: (args, data, interpreter) => {
|
|
341
|
+
_func: (args, data, interpreter) => __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
var _a;
|
|
342
343
|
let success = null;
|
|
343
344
|
let error = null;
|
|
344
345
|
let submit_data;
|
|
@@ -357,6 +358,24 @@ class FunctionRuntimeImpl {
|
|
|
357
358
|
submit_data = args.length > 3 ? valueOf(args[3]) : null;
|
|
358
359
|
validate_form = args.length > 4 ? valueOf(args[4]) : true;
|
|
359
360
|
}
|
|
361
|
+
const form = interpreter.globals.form;
|
|
362
|
+
if (form.captcha && form.captcha.properties['fd:captcha'].config.version === 'enterprise'
|
|
363
|
+
&& form.captcha.properties['fd:captcha'].config.keyType === 'score') {
|
|
364
|
+
if (typeof ((_a = interpreter.runtime.functionTable.fetchCaptchaToken) === null || _a === void 0 ? void 0 : _a._func) !== 'function') {
|
|
365
|
+
interpreter.globals.form.logger.error('fetchCaptchaToken is not defined');
|
|
366
|
+
interpreter.globals.form.dispatch(new Events_1.SubmitError({ type: 'FetchCaptchaTokenNotDefined' }));
|
|
367
|
+
return {};
|
|
368
|
+
}
|
|
369
|
+
try {
|
|
370
|
+
const token = yield interpreter.runtime.functionTable.fetchCaptchaToken._func([], data, interpreter);
|
|
371
|
+
form.captcha.value = token;
|
|
372
|
+
}
|
|
373
|
+
catch (e) {
|
|
374
|
+
interpreter.globals.form.logger.error('Error while fetching captcha token');
|
|
375
|
+
interpreter.globals.form.dispatch(new Events_1.SubmitError({ type: 'FetchCaptchaTokenFailed' }));
|
|
376
|
+
return {};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
360
379
|
interpreter.globals.form.dispatch(new Events_1.Submit({
|
|
361
380
|
success,
|
|
362
381
|
error,
|
|
@@ -365,7 +384,7 @@ class FunctionRuntimeImpl {
|
|
|
365
384
|
data: submit_data
|
|
366
385
|
}));
|
|
367
386
|
return {};
|
|
368
|
-
},
|
|
387
|
+
}),
|
|
369
388
|
_signature: []
|
|
370
389
|
},
|
|
371
390
|
saveForm: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.86",
|
|
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.86"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"jest-junit": "^12.2.0",
|
|
60
60
|
"nock": "^13.1.3",
|
|
61
61
|
"node-fetch": "^2.6.1",
|
|
62
|
+
"parse-multipart-data": "^1.5.0",
|
|
62
63
|
"ts-jest": "29.0",
|
|
63
64
|
"typedoc": "0.22.11",
|
|
64
65
|
"typedoc-plugin-markdown": "3.11.13",
|