@aemforms/af-core 0.22.38 → 0.22.41

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 CHANGED
@@ -17,6 +17,7 @@ const Field_1 = __importDefault(require("./Field"));
17
17
  const FormUtils_1 = require("./utils/FormUtils");
18
18
  const FileObject_1 = require("./FileObject");
19
19
  const ValidationUtils_1 = require("./utils/ValidationUtils");
20
+ const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
20
21
  function addNameToDataURL(dataURL, name) {
21
22
  return dataURL.replace(';base64', `;name=${encodeURIComponent(name)};base64`);
22
23
  }
@@ -105,7 +106,7 @@ class FileUpload extends Field_1.default {
105
106
  importData(dataModel) {
106
107
  this._bindToDataModel(dataModel);
107
108
  const dataNode = this.getDataNode();
108
- if (dataNode !== undefined) {
109
+ if (dataNode !== undefined && dataNode !== EmptyDataValue_1.default) {
109
110
  const value = dataNode === null || dataNode === void 0 ? void 0 : dataNode.$value;
110
111
  if (value != null) {
111
112
  const res = ValidationUtils_1.Constraints.type(this.getInternalType(), value);
@@ -64,7 +64,7 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
64
64
  else {
65
65
  context.form.logger.error('Error invoking a rest API');
66
66
  const eName = getCustomEventName(error);
67
- context.form.dispatch(new Events_1.CustomEvent(eName, {}, true));
67
+ context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
68
68
  }
69
69
  });
70
70
  exports.request = request;
@@ -118,7 +118,7 @@ const submit = (context, success, error, submitAs = 'multipart/form-data', input
118
118
  if (typeof data != 'object' || data == null) {
119
119
  data = context.form.exportData();
120
120
  }
121
- const attachments = (0, FormUtils_1.getAttachments)(context.form);
121
+ const attachments = (0, FormUtils_1.getAttachments)(context.form, true);
122
122
  let submitContentType = submitAs;
123
123
  const submitDataAndMetaData = { 'data': data, 'submitMetadata': { 'lang': context.form.lang } };
124
124
  let formData = submitDataAndMetaData;
@@ -20,16 +20,13 @@ const request = (url, data = null, options = {}) => {
20
20
  var _a, _b, _c;
21
21
  let body;
22
22
  if (!response.ok) {
23
- console.error(`Error fetching response from ${url} : ${response.statusText}`);
24
- body = response.statusText;
23
+ console.error(`Error while fetching response from ${url} : ${response.statusText}`);
24
+ }
25
+ if ((_b = (_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a.get('Content-Type')) === null || _b === void 0 ? void 0 : _b.includes('application/json')) {
26
+ body = yield response.json();
25
27
  }
26
28
  else {
27
- if ((_b = (_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a.get('Content-Type')) === null || _b === void 0 ? void 0 : _b.includes('application/json')) {
28
- body = yield response.json();
29
- }
30
- else {
31
- body = yield response.text();
32
- }
29
+ body = yield response.text();
33
30
  }
34
31
  const headers = {};
35
32
  (_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c.forEach((value, key) => {
@@ -1,7 +1,7 @@
1
1
  import { ContainerModel } from '../types/index';
2
2
  export declare const randomWord: (l: number) => string;
3
3
  export declare const isEmpty: (value: any) => boolean;
4
- export declare const getAttachments: (input: ContainerModel) => any;
4
+ export declare const getAttachments: (input: ContainerModel, excludeUnbound?: boolean) => any;
5
5
  export declare const getFileSizeInBytes: (str: any) => number;
6
6
  export declare const IdGenerator: (initial?: number) => Generator<string, void, string>;
7
7
  export declare const isDataUrl: (str: string) => boolean;
@@ -24,12 +24,15 @@ const isEmpty = (value) => {
24
24
  return value === '' || value === null || value === undefined;
25
25
  };
26
26
  exports.isEmpty = isEmpty;
27
- const getAttachments = (input) => {
27
+ const getAttachments = (input, excludeUnbound = false) => {
28
28
  const items = input.items || [];
29
29
  return items === null || items === void 0 ? void 0 : items.reduce((acc, item) => {
30
+ if (excludeUnbound && item.dataRef === null) {
31
+ return acc;
32
+ }
30
33
  let ret = null;
31
34
  if (item.isContainer) {
32
- ret = (0, exports.getAttachments)(item);
35
+ ret = (0, exports.getAttachments)(item, excludeUnbound);
33
36
  }
34
37
  else {
35
38
  if ((0, JsonUtils_1.isFile)(item.getState())) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.38",
3
+ "version": "0.22.41",
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.50",
38
- "@aemforms/af-formatters": "^0.22.38"
38
+ "@aemforms/af-formatters": "^0.22.41"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/preset-env": "^7.20.2",