@aemforms/af-core 0.22.8 → 0.22.10
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/FileUpload.js +6 -5
- package/lib/rules/FunctionRuntime.js +16 -26
- package/lib/utils/FormUtils.d.ts +3 -2
- package/lib/utils/FormUtils.js +3 -2
- package/package.json +2 -2
package/lib/FileUpload.js
CHANGED
|
@@ -116,11 +116,12 @@ class FileUpload extends Field_1.default {
|
|
|
116
116
|
}
|
|
117
117
|
accepts = Array.isArray(accepts) ? accepts : accepts.split(',');
|
|
118
118
|
accepts.forEach((accept) => {
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(
|
|
119
|
+
const trimmedAccept = accept.trim();
|
|
120
|
+
const prefixAccept = trimmedAccept.split('/')[0];
|
|
121
|
+
const suffixAccept = trimmedAccept.split('.')[1];
|
|
122
|
+
if ((trimmedAccept.includes('*') && type.startsWith(prefixAccept)) ||
|
|
123
|
+
(trimmedAccept.includes('.') && type.endsWith(suffixAccept)) ||
|
|
124
|
+
(trimmedAccept === type)) {
|
|
124
125
|
validFileType = true;
|
|
125
126
|
}
|
|
126
127
|
});
|
|
@@ -90,35 +90,25 @@ const multipartFormData = (data, attachments) => {
|
|
|
90
90
|
formData.append(key, value);
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// if (!attIdentifier.startsWith('/')) {
|
|
103
|
-
// attIdentifier = `/${attIdentifier}`;
|
|
104
|
-
// }
|
|
105
|
-
// formData.append(attIdentifier, objValue.data);
|
|
106
|
-
// newValue[':data'] = `#${attIdentifier}`;
|
|
107
|
-
// }
|
|
108
|
-
// return newValue;
|
|
109
|
-
// };
|
|
93
|
+
const addAttachmentToFormData = (objValue, formData) => {
|
|
94
|
+
if ((objValue === null || objValue === void 0 ? void 0 : objValue.data) instanceof File) {
|
|
95
|
+
let attIdentifier = `${objValue === null || objValue === void 0 ? void 0 : objValue.dataRef}/${objValue === null || objValue === void 0 ? void 0 : objValue.name}`;
|
|
96
|
+
if (!attIdentifier.startsWith('/')) {
|
|
97
|
+
attIdentifier = `/${attIdentifier}`;
|
|
98
|
+
}
|
|
99
|
+
formData.append(attIdentifier, objValue.data);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
110
102
|
// @ts-ignore
|
|
111
|
-
|
|
103
|
+
Object.keys(attachments).reduce((acc, curr) => {
|
|
112
104
|
const objValue = attachments[curr];
|
|
113
|
-
if(objValue && objValue instanceof Array) {
|
|
114
|
-
return [...acc, ...objValue.map((x)=>
|
|
115
|
-
}
|
|
116
|
-
|
|
105
|
+
if (objValue && objValue instanceof Array) {
|
|
106
|
+
return [...acc, ...objValue.map((x) => addAttachmentToFormData(x, formData))];
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return [...acc, addAttachmentToFormData(objValue, formData)];
|
|
117
110
|
}
|
|
118
111
|
}, []);
|
|
119
|
-
if (submitAttachments?.length > 0) {
|
|
120
|
-
formData.append(':attachments', jsonString(submitAttachments));
|
|
121
|
-
}*/
|
|
122
112
|
return formData;
|
|
123
113
|
};
|
|
124
114
|
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -129,7 +119,7 @@ const submit = (context, success, error, submitAs = 'multipart/form-data', input
|
|
|
129
119
|
}
|
|
130
120
|
// todo: have to implement sending of attachments here
|
|
131
121
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
132
|
-
const attachments = (0, FormUtils_1.getAttachments)(context
|
|
122
|
+
const attachments = (0, FormUtils_1.getAttachments)(context.form);
|
|
133
123
|
let submitContentType = submitAs;
|
|
134
124
|
let formData;
|
|
135
125
|
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
package/lib/utils/FormUtils.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ export declare const randomWord: (l: number) => string;
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const isEmpty: (value: any) => boolean;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
16
|
+
* Returns the list of attachments with its data reference
|
|
17
|
+
* @param input form model
|
|
18
|
+
* @returns list of file attachments {@link FileObject} present in the form
|
|
18
19
|
*/
|
|
19
20
|
export declare const getAttachments: (input: ContainerModel) => any;
|
|
20
21
|
/**
|
package/lib/utils/FormUtils.js
CHANGED
|
@@ -40,8 +40,9 @@ const isEmpty = (value) => {
|
|
|
40
40
|
};
|
|
41
41
|
exports.isEmpty = isEmpty;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @
|
|
43
|
+
* Returns the list of attachments with its data reference
|
|
44
|
+
* @param input form model
|
|
45
|
+
* @returns list of file attachments {@link FileObject} present in the form
|
|
45
46
|
*/
|
|
46
47
|
const getAttachments = (input) => {
|
|
47
48
|
const items = input.items || [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.10",
|
|
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.9"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jest": "^27.5.1",
|