@aemforms/af-core 0.15.0 → 0.16.0
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/Checkbox.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ declare class Checkbox extends Field {
|
|
|
12
12
|
valid: boolean;
|
|
13
13
|
value: any;
|
|
14
14
|
};
|
|
15
|
-
format: (constraint: string, input: string) => {
|
|
15
|
+
format: (constraint: string, input: string | null) => {
|
|
16
|
+
value: string | null;
|
|
16
17
|
valid: boolean;
|
|
17
|
-
value: string;
|
|
18
18
|
};
|
|
19
19
|
minimum: (constraint: number, value: number) => {
|
|
20
20
|
valid: boolean;
|
package/lib/Field.d.ts
CHANGED
|
@@ -71,14 +71,20 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
71
71
|
valid: boolean;
|
|
72
72
|
value: any;
|
|
73
73
|
};
|
|
74
|
-
format: (constraint: string, input: string) => {
|
|
74
|
+
format: (constraint: string, input: string | null) => {
|
|
75
|
+
value: string | null;
|
|
75
76
|
valid: boolean;
|
|
76
|
-
value: string;
|
|
77
77
|
};
|
|
78
78
|
minimum: (constraint: number, value: number) => {
|
|
79
79
|
valid: boolean;
|
|
80
80
|
value: number;
|
|
81
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param value
|
|
85
|
+
* @param constraints
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
82
88
|
maximum: (constraint: number, value: number) => {
|
|
83
89
|
valid: boolean;
|
|
84
90
|
value: number;
|
|
@@ -10,8 +10,8 @@ declare type HTTP_VERB = 'GET' | 'POST';
|
|
|
10
10
|
* @param payloadContentType content type of the request
|
|
11
11
|
* @private
|
|
12
12
|
*/
|
|
13
|
-
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, payloadContentType
|
|
14
|
-
export declare const submit: (context: any, success: string, error: string, submitAs?: 'json' | 'multipart', input_data?: any) => Promise<void>;
|
|
13
|
+
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, payloadContentType: string) => Promise<void>;
|
|
14
|
+
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data', input_data?: any) => Promise<void>;
|
|
15
15
|
/**
|
|
16
16
|
* Implementation of function runtime
|
|
17
17
|
* @private
|
|
@@ -20,11 +20,12 @@ exports.submit = exports.request = void 0;
|
|
|
20
20
|
/**
|
|
21
21
|
* Implementation of function runtime in rule engine
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
//import {jsonString} from '../utils/JsonUtils';
|
|
24
24
|
const Controller_1 = require("../controller/Controller");
|
|
25
25
|
const Fetch_1 = require("../utils/Fetch");
|
|
26
26
|
const FileObject_1 = require("../FileObject");
|
|
27
27
|
const FormUtils_1 = require("../utils/FormUtils");
|
|
28
|
+
const JsonUtils_1 = require("../utils/JsonUtils");
|
|
28
29
|
/**
|
|
29
30
|
* Implementation of generic request API. This API can be used to make external web request
|
|
30
31
|
* @param context expression execution context(consists of current form, current field, current event)
|
|
@@ -36,7 +37,7 @@ const FormUtils_1 = require("../utils/FormUtils");
|
|
|
36
37
|
* @param payloadContentType content type of the request
|
|
37
38
|
* @private
|
|
38
39
|
*/
|
|
39
|
-
const request = (context, uri, httpVerb, payload, success, error, payloadContentType
|
|
40
|
+
const request = (context, uri, httpVerb, payload, success, error, payloadContentType) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
41
|
const endpoint = uri;
|
|
41
42
|
const requestOptions = {
|
|
42
43
|
method: httpVerb
|
|
@@ -50,6 +51,9 @@ const request = (context, uri, httpVerb, payload, success, error, payloadContent
|
|
|
50
51
|
formData.append(payload.name, payload.data);
|
|
51
52
|
inputPayload = formData;
|
|
52
53
|
}
|
|
54
|
+
else if (payload instanceof FormData) {
|
|
55
|
+
inputPayload = payload;
|
|
56
|
+
}
|
|
53
57
|
else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
|
|
54
58
|
if (payloadContentType.length > 0) {
|
|
55
59
|
requestOptions.headers = {
|
|
@@ -78,41 +82,46 @@ exports.request = request;
|
|
|
78
82
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
79
83
|
const multipartFormData = (data, attachments) => {
|
|
80
84
|
const formData = new FormData();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const newValue = {
|
|
85
|
-
':name': objValue.name,
|
|
86
|
-
':contentType': objValue.mediaType,
|
|
87
|
-
':data': objValue.data,
|
|
88
|
-
':bindRef': objValue.dataRef
|
|
89
|
-
};
|
|
90
|
-
if ((objValue === null || objValue === void 0 ? void 0 : objValue.data) instanceof File) {
|
|
91
|
-
let attIdentifier = `${objValue === null || objValue === void 0 ? void 0 : objValue.dataRef}/${objValue === null || objValue === void 0 ? void 0 : objValue.name}`;
|
|
92
|
-
if (!attIdentifier.startsWith('/')) {
|
|
93
|
-
attIdentifier = `/${attIdentifier}`;
|
|
94
|
-
}
|
|
95
|
-
formData.append(attIdentifier, objValue.data);
|
|
96
|
-
newValue[':data'] = `#${attIdentifier}`;
|
|
85
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
86
|
+
if (value != null && typeof value === 'object') {
|
|
87
|
+
formData.append(key, (0, JsonUtils_1.jsonString)(value));
|
|
97
88
|
}
|
|
98
|
-
|
|
99
|
-
|
|
89
|
+
else {
|
|
90
|
+
formData.append(key, value);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// const transformAttachment = (objValue: any, formData: any) : any => {
|
|
94
|
+
// const newValue = {
|
|
95
|
+
// ':name' : objValue.name,
|
|
96
|
+
// ':contentType' : objValue.mediaType,
|
|
97
|
+
// ':data' : objValue.data,
|
|
98
|
+
// ':bindRef' : objValue.dataRef
|
|
99
|
+
// };
|
|
100
|
+
// if (objValue?.data instanceof File) {
|
|
101
|
+
// let attIdentifier = `${objValue?.dataRef}/${objValue?.name}`;
|
|
102
|
+
// if (!attIdentifier.startsWith('/')) {
|
|
103
|
+
// attIdentifier = `/${attIdentifier}`;
|
|
104
|
+
// }
|
|
105
|
+
// formData.append(attIdentifier, objValue.data);
|
|
106
|
+
// newValue[':data'] = `#${attIdentifier}`;
|
|
107
|
+
// }
|
|
108
|
+
// return newValue;
|
|
109
|
+
// };
|
|
100
110
|
// @ts-ignore
|
|
101
|
-
const submitAttachments = Object.keys(attachments).reduce((acc, curr) => {
|
|
111
|
+
/*const submitAttachments = Object.keys(attachments).reduce((acc, curr) => {
|
|
102
112
|
const objValue = attachments[curr];
|
|
103
|
-
if
|
|
104
|
-
return [...acc, ...objValue.map((x)
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
113
|
+
if(objValue && objValue instanceof Array) {
|
|
114
|
+
return [...acc, ...objValue.map((x)=>transformAttachment(x, formData))];
|
|
115
|
+
} else {
|
|
107
116
|
return [...acc, transformAttachment(objValue, formData)];
|
|
108
117
|
}
|
|
109
118
|
}, []);
|
|
110
|
-
if (
|
|
111
|
-
formData.append(':attachments',
|
|
112
|
-
}
|
|
119
|
+
if (submitAttachments?.length > 0) {
|
|
120
|
+
formData.append(':attachments', jsonString(submitAttachments));
|
|
121
|
+
}*/
|
|
113
122
|
return formData;
|
|
114
123
|
};
|
|
115
|
-
const submit = (context, success, error, submitAs = '
|
|
124
|
+
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
125
|
const endpoint = context.form.action;
|
|
117
126
|
let data = input_data;
|
|
118
127
|
if (typeof data != 'object' || data == null) {
|
|
@@ -122,14 +131,15 @@ const submit = (context, success, error, submitAs = 'json', input_data = null) =
|
|
|
122
131
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
123
132
|
const attachments = (0, FormUtils_1.getAttachments)(context.$form);
|
|
124
133
|
let submitContentType = submitAs;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
let formData;
|
|
135
|
+
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
136
|
+
formData = multipartFormData({ 'data': data }, attachments);
|
|
137
|
+
submitContentType = 'multipart/form-data';
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
formData = { 'data': data };
|
|
141
|
+
}
|
|
142
|
+
// submitContentType = submitAs;
|
|
133
143
|
// note: don't send multipart/form-data let browser decide on the content type
|
|
134
144
|
yield (0, exports.request)(context, endpoint, 'POST', formData, success, error, submitContentType);
|
|
135
145
|
});
|
|
@@ -209,7 +219,7 @@ class FunctionRuntimeImpl {
|
|
|
209
219
|
// success: string, error: string, submit_as: 'json' | 'multipart' = 'json', data: any = null
|
|
210
220
|
const success = toString(args[0]);
|
|
211
221
|
const error = toString(args[1]);
|
|
212
|
-
const submit_as = args.length > 2 ? toString(args[2]) : '
|
|
222
|
+
const submit_as = args.length > 2 ? toString(args[2]) : 'multipart/form-data';
|
|
213
223
|
const submit_data = args.length > 3 ? valueOf(args[3]) : null;
|
|
214
224
|
interpreter.globals.form.dispatch(new Controller_1.Submit({
|
|
215
225
|
success,
|
|
@@ -28,9 +28,9 @@ export declare const Constraints: {
|
|
|
28
28
|
* @param input value of the form object
|
|
29
29
|
* @return {@link ValidationResult | validation result}
|
|
30
30
|
*/
|
|
31
|
-
format: (constraint: string, input: string) => {
|
|
31
|
+
format: (constraint: string, input: string | null) => {
|
|
32
|
+
value: string | null;
|
|
32
33
|
valid: boolean;
|
|
33
|
-
value: string;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Implementation of minimum constraint
|
|
@@ -192,10 +192,13 @@ exports.Constraints = {
|
|
|
192
192
|
format: (constraint, input) => {
|
|
193
193
|
let valid = true;
|
|
194
194
|
const value = input;
|
|
195
|
+
if (input === null) {
|
|
196
|
+
return { value, valid };
|
|
197
|
+
}
|
|
195
198
|
let res;
|
|
196
199
|
switch (constraint) {
|
|
197
200
|
case 'date':
|
|
198
|
-
res = dateRegex.exec(input.trim());
|
|
201
|
+
res = dateRegex.exec((input || '').trim());
|
|
199
202
|
if (res != null) {
|
|
200
203
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
201
204
|
const [match, year, month, date] = res;
|
package/package.json
CHANGED