@beinformed/ui 1.60.1 → 1.60.2
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/CHANGELOG.md +7 -0
- package/esm/models/form/__tests__/FormModel.spec.js.flow +2 -0
- package/esm/modularui/UploadRequest.js +5 -4
- package/esm/modularui/UploadRequest.js.flow +16 -6
- package/esm/modularui/UploadRequest.js.map +1 -1
- package/lib/modularui/UploadRequest.js +4 -3
- package/lib/modularui/UploadRequest.js.map +1 -1
- package/package.json +5 -5
- package/src/models/form/__tests__/FormModel.spec.js +2 -0
- package/src/modularui/UploadRequest.js +16 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.60.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.60.1...v1.60.2) (2025-03-03)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **upload:** improve error handling on form uploads ([134de76](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/134de76b6b10dbcaecdd007fe27afc0a9a2a80f6))
|
|
11
|
+
|
|
5
12
|
## [1.60.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.60.0...v1.60.1) (2025-02-19)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
2
2
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
3
|
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
4
|
-
import { getBasePathModularUI, getUploadPath, HTTP_METHODS } from "../constants";
|
|
4
|
+
import { getBasePathModularUI, getSetting, getUploadPath, HTTP_METHODS } from "../constants";
|
|
5
5
|
import xhr from "../utils/fetch/xhr";
|
|
6
6
|
import ErrorModel from "../models/error/ErrorModel";
|
|
7
|
+
import { ErrorResponse } from "../models";
|
|
7
8
|
/**
|
|
8
9
|
* Upload a file to the upload file service of Be Informed
|
|
9
10
|
*/
|
|
@@ -50,7 +51,7 @@ class UploadRequest {
|
|
|
50
51
|
*/
|
|
51
52
|
uploadFile(file) {
|
|
52
53
|
const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
|
|
53
|
-
if (this.exceedsMaxFileSize(file)) {
|
|
54
|
+
if (getSetting("USE_CLIENTSIDE_VALIDATION") && this.exceedsMaxFileSize(file)) {
|
|
54
55
|
this._progressHandler(file, {
|
|
55
56
|
error: "errorExceedsMaxFileSize"
|
|
56
57
|
});
|
|
@@ -58,7 +59,7 @@ class UploadRequest {
|
|
|
58
59
|
"max-filesize": maxFileSize
|
|
59
60
|
}, true));
|
|
60
61
|
}
|
|
61
|
-
if (this.isNotAllowedFileType(file)) {
|
|
62
|
+
if (getSetting("USE_CLIENTSIDE_VALIDATION") && this.isNotAllowedFileType(file)) {
|
|
62
63
|
this._progressHandler(file, {
|
|
63
64
|
error: "errorExtensionNotAllowed"
|
|
64
65
|
});
|
|
@@ -89,7 +90,7 @@ class UploadRequest {
|
|
|
89
90
|
token: response.token
|
|
90
91
|
});
|
|
91
92
|
return response;
|
|
92
|
-
});
|
|
93
|
+
}).catch(e => _Promise.reject(new ErrorResponse(e)));
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
export default UploadRequest;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {
|
|
3
3
|
getBasePathModularUI,
|
|
4
|
+
getSetting,
|
|
4
5
|
getUploadPath,
|
|
5
6
|
HTTP_METHODS,
|
|
6
7
|
} from "../constants";
|
|
@@ -12,6 +13,7 @@ import type {
|
|
|
12
13
|
FiletypeConstraintsType,
|
|
13
14
|
} from "../models";
|
|
14
15
|
import ErrorModel from "../models/error/ErrorModel";
|
|
16
|
+
import { ErrorResponse } from "../models";
|
|
15
17
|
|
|
16
18
|
type ProgressHandler = (file: File, uploadInfo: Object) => void;
|
|
17
19
|
|
|
@@ -86,7 +88,10 @@ class UploadRequest {
|
|
|
86
88
|
uploadFile(file: File): Promise<UploadResponse> {
|
|
87
89
|
const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
|
|
88
90
|
|
|
89
|
-
if (
|
|
91
|
+
if (
|
|
92
|
+
getSetting("USE_CLIENTSIDE_VALIDATION") &&
|
|
93
|
+
this.exceedsMaxFileSize(file)
|
|
94
|
+
) {
|
|
90
95
|
this._progressHandler(file, { error: "errorExceedsMaxFileSize" });
|
|
91
96
|
return Promise.reject(
|
|
92
97
|
new ErrorModel(
|
|
@@ -100,7 +105,10 @@ class UploadRequest {
|
|
|
100
105
|
);
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
if (
|
|
108
|
+
if (
|
|
109
|
+
getSetting("USE_CLIENTSIDE_VALIDATION") &&
|
|
110
|
+
this.isNotAllowedFileType(file)
|
|
111
|
+
) {
|
|
104
112
|
this._progressHandler(file, { error: "errorExtensionNotAllowed" });
|
|
105
113
|
return Promise.reject(
|
|
106
114
|
new ErrorModel(
|
|
@@ -131,10 +139,12 @@ class UploadRequest {
|
|
|
131
139
|
}
|
|
132
140
|
},
|
|
133
141
|
data: file,
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
})
|
|
143
|
+
.then((response) => {
|
|
144
|
+
this._progressHandler(file, { progress: 100, token: response.token });
|
|
145
|
+
return response;
|
|
146
|
+
})
|
|
147
|
+
.catch((e) => Promise.reject(new ErrorResponse(e)));
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
150
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadRequest.js","names":["getBasePathModularUI","getUploadPath","HTTP_METHODS","xhr","ErrorModel","UploadRequest","constructor","uploadConstraints","progressHandler","options","_defineProperty","_uploadConstraints","_progressHandler","_origin","origin","_contextPath","contextPath","getFileExtension","file","name","split","pop","toLowerCase","isNotAllowedFileType","allowedFileTypes","fileTypes","length","fileExtension","some","fileType","_context","_includesInstanceProperty","extensions","call","exceedsMaxFileSize","maxFileSize","fileSize","size","uploadFile","error","_Promise","reject","extension","join","url","method","POST","headers","type","encodeURIComponent","toString","onProgress","e","lengthComputable","progress","Math","ceil","loaded","total","data","then","response","token"],"sources":["../../src/modularui/UploadRequest.js"],"sourcesContent":["// @flow\nimport {\n getBasePathModularUI,\n getUploadPath,\n HTTP_METHODS,\n} from \"../constants\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport type {\n FilesizeConstraintsType,\n FiletypeConstraintsType,\n} from \"../models\";\nimport ErrorModel from \"../models/error/ErrorModel\";\n\ntype ProgressHandler = (file: File, uploadInfo: Object) => void;\n\ntype UploadRequestOptions = {\n origin?: string,\n contextPath?: string,\n};\n\ntype UploadResponse = {\n token: string,\n};\n\n/**\n * Upload a file to the upload file service of Be Informed\n */\nclass UploadRequest {\n _uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n };\n _progressHandler: ProgressHandler;\n _origin: string = \"\";\n _contextPath: string = getBasePathModularUI();\n\n constructor(\n uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n },\n progressHandler: ProgressHandler,\n options?: UploadRequestOptions,\n ) {\n this._uploadConstraints = uploadConstraints;\n this._progressHandler = progressHandler;\n this._origin = options?.origin || \"\";\n this._contextPath = options?.contextPath || getBasePathModularUI();\n }\n\n /**\n */\n getFileExtension(file: File): string {\n return file.name.split(\".\").pop().toLowerCase();\n }\n\n /**\n */\n isNotAllowedFileType(file: File): boolean {\n const allowedFileTypes = this._uploadConstraints.fileTypes;\n\n if (allowedFileTypes.length > 0) {\n const fileExtension = this.getFileExtension(file);\n\n return !allowedFileTypes.some((fileType) =>\n fileType.extensions.includes(fileExtension),\n );\n }\n\n return false;\n }\n\n /**\n */\n exceedsMaxFileSize(file: File): boolean {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n return maxFileSize > -1 && file.size > maxFileSize;\n }\n\n /**\n */\n uploadFile(file: File): Promise<UploadResponse> {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n\n if (this.exceedsMaxFileSize(file)) {\n this._progressHandler(file, { error: \"errorExceedsMaxFileSize\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.MaxFileSizeExceeded\",\n \"Maximum file upload size is ${max-filesize}\",\n {\n \"max-filesize\": maxFileSize,\n },\n true,\n ),\n );\n }\n\n if (this.isNotAllowedFileType(file)) {\n this._progressHandler(file, { error: \"errorExtensionNotAllowed\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.InvalidExtension\",\n \"Allowed extensions are: ${extensions}\",\n {\n extension: this.getFileExtension(file),\n extensions: this._uploadConstraints.fileTypes.join(\", \"),\n },\n true,\n ),\n );\n }\n\n return xhr({\n url: getUploadPath(this._contextPath, this._origin),\n method: HTTP_METHODS.POST,\n headers: {\n \"Content-Type\": file.type,\n \"x-filename\": encodeURIComponent(file.name),\n \"x-filesize\": file.size.toString(),\n },\n onProgress: (e: ProgressEvent) => {\n if (this._progressHandler && e.lengthComputable) {\n this._progressHandler(file, {\n progress: Math.ceil((e.loaded / e.total) * 100),\n });\n }\n },\n data: file,\n }).then((response) => {\n
|
|
1
|
+
{"version":3,"file":"UploadRequest.js","names":["getBasePathModularUI","getSetting","getUploadPath","HTTP_METHODS","xhr","ErrorModel","ErrorResponse","UploadRequest","constructor","uploadConstraints","progressHandler","options","_defineProperty","_uploadConstraints","_progressHandler","_origin","origin","_contextPath","contextPath","getFileExtension","file","name","split","pop","toLowerCase","isNotAllowedFileType","allowedFileTypes","fileTypes","length","fileExtension","some","fileType","_context","_includesInstanceProperty","extensions","call","exceedsMaxFileSize","maxFileSize","fileSize","size","uploadFile","error","_Promise","reject","extension","join","url","method","POST","headers","type","encodeURIComponent","toString","onProgress","e","lengthComputable","progress","Math","ceil","loaded","total","data","then","response","token","catch"],"sources":["../../src/modularui/UploadRequest.js"],"sourcesContent":["// @flow\nimport {\n getBasePathModularUI,\n getSetting,\n getUploadPath,\n HTTP_METHODS,\n} from \"../constants\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport type {\n FilesizeConstraintsType,\n FiletypeConstraintsType,\n} from \"../models\";\nimport ErrorModel from \"../models/error/ErrorModel\";\nimport { ErrorResponse } from \"../models\";\n\ntype ProgressHandler = (file: File, uploadInfo: Object) => void;\n\ntype UploadRequestOptions = {\n origin?: string,\n contextPath?: string,\n};\n\ntype UploadResponse = {\n token: string,\n};\n\n/**\n * Upload a file to the upload file service of Be Informed\n */\nclass UploadRequest {\n _uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n };\n _progressHandler: ProgressHandler;\n _origin: string = \"\";\n _contextPath: string = getBasePathModularUI();\n\n constructor(\n uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n },\n progressHandler: ProgressHandler,\n options?: UploadRequestOptions,\n ) {\n this._uploadConstraints = uploadConstraints;\n this._progressHandler = progressHandler;\n this._origin = options?.origin || \"\";\n this._contextPath = options?.contextPath || getBasePathModularUI();\n }\n\n /**\n */\n getFileExtension(file: File): string {\n return file.name.split(\".\").pop().toLowerCase();\n }\n\n /**\n */\n isNotAllowedFileType(file: File): boolean {\n const allowedFileTypes = this._uploadConstraints.fileTypes;\n\n if (allowedFileTypes.length > 0) {\n const fileExtension = this.getFileExtension(file);\n\n return !allowedFileTypes.some((fileType) =>\n fileType.extensions.includes(fileExtension),\n );\n }\n\n return false;\n }\n\n /**\n */\n exceedsMaxFileSize(file: File): boolean {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n return maxFileSize > -1 && file.size > maxFileSize;\n }\n\n /**\n */\n uploadFile(file: File): Promise<UploadResponse> {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n\n if (\n getSetting(\"USE_CLIENTSIDE_VALIDATION\") &&\n this.exceedsMaxFileSize(file)\n ) {\n this._progressHandler(file, { error: \"errorExceedsMaxFileSize\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.MaxFileSizeExceeded\",\n \"Maximum file upload size is ${max-filesize}\",\n {\n \"max-filesize\": maxFileSize,\n },\n true,\n ),\n );\n }\n\n if (\n getSetting(\"USE_CLIENTSIDE_VALIDATION\") &&\n this.isNotAllowedFileType(file)\n ) {\n this._progressHandler(file, { error: \"errorExtensionNotAllowed\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.InvalidExtension\",\n \"Allowed extensions are: ${extensions}\",\n {\n extension: this.getFileExtension(file),\n extensions: this._uploadConstraints.fileTypes.join(\", \"),\n },\n true,\n ),\n );\n }\n\n return xhr({\n url: getUploadPath(this._contextPath, this._origin),\n method: HTTP_METHODS.POST,\n headers: {\n \"Content-Type\": file.type,\n \"x-filename\": encodeURIComponent(file.name),\n \"x-filesize\": file.size.toString(),\n },\n onProgress: (e: ProgressEvent) => {\n if (this._progressHandler && e.lengthComputable) {\n this._progressHandler(file, {\n progress: Math.ceil((e.loaded / e.total) * 100),\n });\n }\n },\n data: file,\n })\n .then((response) => {\n this._progressHandler(file, { progress: 100, token: response.token });\n return response;\n })\n .catch((e) => Promise.reject(new ErrorResponse(e)));\n }\n}\n\nexport default UploadRequest;\n"],"mappings":";;;AACA,SACEA,oBAAoB,EACpBC,UAAU,EACVC,aAAa,EACbC,YAAY,QACP,cAAc;AAErB,OAAOC,GAAG,MAAM,oBAAoB;AAMpC,OAAOC,UAAU,MAAM,4BAA4B;AACnD,SAASC,a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3C,YAAY,EAAED,IAAI,CAACmB,IAAI,CAACa,QAAQ,CAAC;MACnC,CAAC;MACDC,UAAU,EAAGC,CAAgB,IAAK;QAChC,IAAI,IAAI,CAACxC,gBAAgB,IAAIwC,CAAC,CAACC,gBAAgB,EAAE;UAC/C,IAAI,CAACzC,gBAAgB,CAACM,IAAI,EAAE;YAC1BoC,QAAQ,EAAEC,IAAI,CAACC,IAAI,CAAEJ,CAAC,CAACK,MAAM,GAAGL,CAAC,CAACM,KAAK,GAAI,GAAG;UAChD,CAAC,CAAC;QACJ;MACF,CAAC;MACDC,IAAI,EAAEzC;IACR,CAAC,CAAC,CACC0C,IAAI,CAAEC,QAAQ,IAAK;MAClB,IAAI,CAACjD,gBAAgB,CAACM,IAAI,EAAE;QAAEoC,QAAQ,EAAE,GAAG;QAAEQ,KAAK,EAAED,QAAQ,CAACC;MAAM,CAAC,CAAC;MACrE,OAAOD,QAAQ;IACjB,CAAC,CAAC,CACDE,KAAK,CAAEX,CAAC,IAAKZ,QAAA,CAAQC,MAAM,CAAC,IAAIrC,aAAa,CAACgD,CAAC,CAAC,CAAC,CAAC;EACvD;AACF;AAEA,eAAe/C,aAAa","ignoreList":[]}
|
|
@@ -11,6 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/he
|
|
|
11
11
|
var _constants = require("../constants");
|
|
12
12
|
var _xhr = _interopRequireDefault(require("../utils/fetch/xhr"));
|
|
13
13
|
var _ErrorModel = _interopRequireDefault(require("../models/error/ErrorModel"));
|
|
14
|
+
var _models = require("../models");
|
|
14
15
|
/**
|
|
15
16
|
* Upload a file to the upload file service of Be Informed
|
|
16
17
|
*/
|
|
@@ -57,7 +58,7 @@ class UploadRequest {
|
|
|
57
58
|
*/
|
|
58
59
|
uploadFile(file) {
|
|
59
60
|
const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
|
|
60
|
-
if (this.exceedsMaxFileSize(file)) {
|
|
61
|
+
if ((0, _constants.getSetting)("USE_CLIENTSIDE_VALIDATION") && this.exceedsMaxFileSize(file)) {
|
|
61
62
|
this._progressHandler(file, {
|
|
62
63
|
error: "errorExceedsMaxFileSize"
|
|
63
64
|
});
|
|
@@ -65,7 +66,7 @@ class UploadRequest {
|
|
|
65
66
|
"max-filesize": maxFileSize
|
|
66
67
|
}, true));
|
|
67
68
|
}
|
|
68
|
-
if (this.isNotAllowedFileType(file)) {
|
|
69
|
+
if ((0, _constants.getSetting)("USE_CLIENTSIDE_VALIDATION") && this.isNotAllowedFileType(file)) {
|
|
69
70
|
this._progressHandler(file, {
|
|
70
71
|
error: "errorExtensionNotAllowed"
|
|
71
72
|
});
|
|
@@ -96,7 +97,7 @@ class UploadRequest {
|
|
|
96
97
|
token: response.token
|
|
97
98
|
});
|
|
98
99
|
return response;
|
|
99
|
-
});
|
|
100
|
+
}).catch(e => _promise.default.reject(new _models.ErrorResponse(e)));
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
var _default = exports.default = UploadRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadRequest.js","names":["_constants","require","_xhr","_interopRequireDefault","_ErrorModel","UploadRequest","constructor","uploadConstraints","progressHandler","options","_defineProperty2","default","getBasePathModularUI","_uploadConstraints","_progressHandler","_origin","origin","_contextPath","contextPath","getFileExtension","file","name","split","pop","toLowerCase","isNotAllowedFileType","allowedFileTypes","fileTypes","length","fileExtension","some","fileType","_context","_includes","extensions","call","exceedsMaxFileSize","maxFileSize","fileSize","size","uploadFile","error","_promise","reject","ErrorModel","extension","join","xhr","url","getUploadPath","method","HTTP_METHODS","POST","headers","type","encodeURIComponent","toString","onProgress","e","lengthComputable","progress","Math","ceil","loaded","total","data","then","response","token","_default","exports"],"sources":["../../src/modularui/UploadRequest.js"],"sourcesContent":["// @flow\nimport {\n getBasePathModularUI,\n getUploadPath,\n HTTP_METHODS,\n} from \"../constants\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport type {\n FilesizeConstraintsType,\n FiletypeConstraintsType,\n} from \"../models\";\nimport ErrorModel from \"../models/error/ErrorModel\";\n\ntype ProgressHandler = (file: File, uploadInfo: Object) => void;\n\ntype UploadRequestOptions = {\n origin?: string,\n contextPath?: string,\n};\n\ntype UploadResponse = {\n token: string,\n};\n\n/**\n * Upload a file to the upload file service of Be Informed\n */\nclass UploadRequest {\n _uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n };\n _progressHandler: ProgressHandler;\n _origin: string = \"\";\n _contextPath: string = getBasePathModularUI();\n\n constructor(\n uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n },\n progressHandler: ProgressHandler,\n options?: UploadRequestOptions,\n ) {\n this._uploadConstraints = uploadConstraints;\n this._progressHandler = progressHandler;\n this._origin = options?.origin || \"\";\n this._contextPath = options?.contextPath || getBasePathModularUI();\n }\n\n /**\n */\n getFileExtension(file: File): string {\n return file.name.split(\".\").pop().toLowerCase();\n }\n\n /**\n */\n isNotAllowedFileType(file: File): boolean {\n const allowedFileTypes = this._uploadConstraints.fileTypes;\n\n if (allowedFileTypes.length > 0) {\n const fileExtension = this.getFileExtension(file);\n\n return !allowedFileTypes.some((fileType) =>\n fileType.extensions.includes(fileExtension),\n );\n }\n\n return false;\n }\n\n /**\n */\n exceedsMaxFileSize(file: File): boolean {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n return maxFileSize > -1 && file.size > maxFileSize;\n }\n\n /**\n */\n uploadFile(file: File): Promise<UploadResponse> {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n\n if (this.exceedsMaxFileSize(file)) {\n this._progressHandler(file, { error: \"errorExceedsMaxFileSize\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.MaxFileSizeExceeded\",\n \"Maximum file upload size is ${max-filesize}\",\n {\n \"max-filesize\": maxFileSize,\n },\n true,\n ),\n );\n }\n\n if (this.isNotAllowedFileType(file)) {\n this._progressHandler(file, { error: \"errorExtensionNotAllowed\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.InvalidExtension\",\n \"Allowed extensions are: ${extensions}\",\n {\n extension: this.getFileExtension(file),\n extensions: this._uploadConstraints.fileTypes.join(\", \"),\n },\n true,\n ),\n );\n }\n\n return xhr({\n url: getUploadPath(this._contextPath, this._origin),\n method: HTTP_METHODS.POST,\n headers: {\n \"Content-Type\": file.type,\n \"x-filename\": encodeURIComponent(file.name),\n \"x-filesize\": file.size.toString(),\n },\n onProgress: (e: ProgressEvent) => {\n if (this._progressHandler && e.lengthComputable) {\n this._progressHandler(file, {\n progress: Math.ceil((e.loaded / e.total) * 100),\n });\n }\n },\n data: file,\n }).then((response) => {\n
|
|
1
|
+
{"version":3,"file":"UploadRequest.js","names":["_constants","require","_xhr","_interopRequireDefault","_ErrorModel","_models","UploadRequest","constructor","uploadConstraints","progressHandler","options","_defineProperty2","default","getBasePathModularUI","_uploadConstraints","_progressHandler","_origin","origin","_contextPath","contextPath","getFileExtension","file","name","split","pop","toLowerCase","isNotAllowedFileType","allowedFileTypes","fileTypes","length","fileExtension","some","fileType","_context","_includes","extensions","call","exceedsMaxFileSize","maxFileSize","fileSize","size","uploadFile","getSetting","error","_promise","reject","ErrorModel","extension","join","xhr","url","getUploadPath","method","HTTP_METHODS","POST","headers","type","encodeURIComponent","toString","onProgress","e","lengthComputable","progress","Math","ceil","loaded","total","data","then","response","token","catch","ErrorResponse","_default","exports"],"sources":["../../src/modularui/UploadRequest.js"],"sourcesContent":["// @flow\nimport {\n getBasePathModularUI,\n getSetting,\n getUploadPath,\n HTTP_METHODS,\n} from \"../constants\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport type {\n FilesizeConstraintsType,\n FiletypeConstraintsType,\n} from \"../models\";\nimport ErrorModel from \"../models/error/ErrorModel\";\nimport { ErrorResponse } from \"../models\";\n\ntype ProgressHandler = (file: File, uploadInfo: Object) => void;\n\ntype UploadRequestOptions = {\n origin?: string,\n contextPath?: string,\n};\n\ntype UploadResponse = {\n token: string,\n};\n\n/**\n * Upload a file to the upload file service of Be Informed\n */\nclass UploadRequest {\n _uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n };\n _progressHandler: ProgressHandler;\n _origin: string = \"\";\n _contextPath: string = getBasePathModularUI();\n\n constructor(\n uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n },\n progressHandler: ProgressHandler,\n options?: UploadRequestOptions,\n ) {\n this._uploadConstraints = uploadConstraints;\n this._progressHandler = progressHandler;\n this._origin = options?.origin || \"\";\n this._contextPath = options?.contextPath || getBasePathModularUI();\n }\n\n /**\n */\n getFileExtension(file: File): string {\n return file.name.split(\".\").pop().toLowerCase();\n }\n\n /**\n */\n isNotAllowedFileType(file: File): boolean {\n const allowedFileTypes = this._uploadConstraints.fileTypes;\n\n if (allowedFileTypes.length > 0) {\n const fileExtension = this.getFileExtension(file);\n\n return !allowedFileTypes.some((fileType) =>\n fileType.extensions.includes(fileExtension),\n );\n }\n\n return false;\n }\n\n /**\n */\n exceedsMaxFileSize(file: File): boolean {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n return maxFileSize > -1 && file.size > maxFileSize;\n }\n\n /**\n */\n uploadFile(file: File): Promise<UploadResponse> {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n\n if (\n getSetting(\"USE_CLIENTSIDE_VALIDATION\") &&\n this.exceedsMaxFileSize(file)\n ) {\n this._progressHandler(file, { error: \"errorExceedsMaxFileSize\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.MaxFileSizeExceeded\",\n \"Maximum file upload size is ${max-filesize}\",\n {\n \"max-filesize\": maxFileSize,\n },\n true,\n ),\n );\n }\n\n if (\n getSetting(\"USE_CLIENTSIDE_VALIDATION\") &&\n this.isNotAllowedFileType(file)\n ) {\n this._progressHandler(file, { error: \"errorExtensionNotAllowed\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.InvalidExtension\",\n \"Allowed extensions are: ${extensions}\",\n {\n extension: this.getFileExtension(file),\n extensions: this._uploadConstraints.fileTypes.join(\", \"),\n },\n true,\n ),\n );\n }\n\n return xhr({\n url: getUploadPath(this._contextPath, this._origin),\n method: HTTP_METHODS.POST,\n headers: {\n \"Content-Type\": file.type,\n \"x-filename\": encodeURIComponent(file.name),\n \"x-filesize\": file.size.toString(),\n },\n onProgress: (e: ProgressEvent) => {\n if (this._progressHandler && e.lengthComputable) {\n this._progressHandler(file, {\n progress: Math.ceil((e.loaded / e.total) * 100),\n });\n }\n },\n data: file,\n })\n .then((response) => {\n this._progressHandler(file, { progress: 100, token: response.token });\n return response;\n })\n .catch((e) => Promise.reject(new ErrorResponse(e)));\n }\n}\n\nexport default UploadRequest;\n"],"mappings":";;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAOA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AAMA,IAAAG,WAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAaA;AACA;AACA;AACA,MAAMK,aAAa,CAAC;EAUlBC,WAAWA,CACTC,iBAIC,EACDC,eAAgC,EAChCC,OAA8B,EAC9B;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,mBAXgB,EAAE;IAAA,IAAAD,gBAAA,CAAAC,OAAA,wBACG,IAAAC,+BAAoB,EAAC,CAAC;IAW3C,IAAI,CAACC,kBAAkB,GAAGN,iBAAiB;IAC3C,IAAI,CAACO,gBAAgB,GAAGN,eAAe;IACvC,IAAI,CAACO,OAAO,GAAGN,OAAO,EAAEO,MAAM,IAAI,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L,CAAC,CAACM,KAAK,GAAI,GAAG;UAChD,CAAC,CAAC;QACJ;MACF,CAAC;MACDC,IAAI,EAAE9C;IACR,CAAC,CAAC,CACC+C,IAAI,CAAEC,QAAQ,IAAK;MAClB,IAAI,CAACtD,gBAAgB,CAACM,IAAI,EAAE;QAAEyC,QAAQ,EAAE,GAAG;QAAEQ,KAAK,EAAED,QAAQ,CAACC;MAAM,CAAC,CAAC;MACrE,OAAOD,QAAQ;IACjB,CAAC,CAAC,CACDE,KAAK,CAAEX,CAAC,IAAKhB,QAAA,CAAAhC,OAAA,CAAQiC,MAAM,CAAC,IAAI2B,qBAAa,CAACZ,CAAC,CAAC,CAAC,CAAC;EACvD;AACF;AAAC,IAAAa,QAAA,GAAAC,OAAA,CAAA9D,OAAA,GAEcN,aAAa","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.60.
|
|
3
|
+
"version": "1.60.2",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "https://support.beinformed.com",
|
|
@@ -108,13 +108,13 @@
|
|
|
108
108
|
"cross-env": "^7.0.3",
|
|
109
109
|
"documentation": "^14.0.2",
|
|
110
110
|
"eslint": "^8.57.0",
|
|
111
|
-
"eslint-config-prettier": "^10.0.
|
|
111
|
+
"eslint-config-prettier": "^10.0.2",
|
|
112
112
|
"eslint-plugin-babel": "^5.3.1",
|
|
113
113
|
"eslint-plugin-ft-flow": "^3.0.11",
|
|
114
114
|
"eslint-plugin-jest": "^28.11.0",
|
|
115
115
|
"eslint-plugin-jsdoc": "^50.6.3",
|
|
116
116
|
"eslint-plugin-react": "^7.37.4",
|
|
117
|
-
"eslint-plugin-react-hooks": "^5.
|
|
117
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
118
118
|
"eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",
|
|
119
119
|
"flow-bin": "^0.200.1",
|
|
120
120
|
"flow-copy-source": "^2.0.9",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"jscodeshift": "^17.1.2",
|
|
130
130
|
"lint-staged": "^15.4.3",
|
|
131
131
|
"polished": "^4.0.0",
|
|
132
|
-
"prettier": "^3.5.
|
|
132
|
+
"prettier": "^3.5.3",
|
|
133
133
|
"react": "^19.0.0",
|
|
134
134
|
"react-dom": "^19.0.0",
|
|
135
135
|
"react-helmet-async": "^2.0.5",
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"redux-thunk": "^2.4.2",
|
|
142
142
|
"rimraf": "^6.0.1",
|
|
143
143
|
"styled-components": "^5.3.11",
|
|
144
|
-
"typescript": "^5.
|
|
144
|
+
"typescript": "^5.8.2",
|
|
145
145
|
"xhr-mock": "^2.5.1"
|
|
146
146
|
},
|
|
147
147
|
"scarfSettings": {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {
|
|
3
3
|
getBasePathModularUI,
|
|
4
|
+
getSetting,
|
|
4
5
|
getUploadPath,
|
|
5
6
|
HTTP_METHODS,
|
|
6
7
|
} from "../constants";
|
|
@@ -12,6 +13,7 @@ import type {
|
|
|
12
13
|
FiletypeConstraintsType,
|
|
13
14
|
} from "../models";
|
|
14
15
|
import ErrorModel from "../models/error/ErrorModel";
|
|
16
|
+
import { ErrorResponse } from "../models";
|
|
15
17
|
|
|
16
18
|
type ProgressHandler = (file: File, uploadInfo: Object) => void;
|
|
17
19
|
|
|
@@ -86,7 +88,10 @@ class UploadRequest {
|
|
|
86
88
|
uploadFile(file: File): Promise<UploadResponse> {
|
|
87
89
|
const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
|
|
88
90
|
|
|
89
|
-
if (
|
|
91
|
+
if (
|
|
92
|
+
getSetting("USE_CLIENTSIDE_VALIDATION") &&
|
|
93
|
+
this.exceedsMaxFileSize(file)
|
|
94
|
+
) {
|
|
90
95
|
this._progressHandler(file, { error: "errorExceedsMaxFileSize" });
|
|
91
96
|
return Promise.reject(
|
|
92
97
|
new ErrorModel(
|
|
@@ -100,7 +105,10 @@ class UploadRequest {
|
|
|
100
105
|
);
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
if (
|
|
108
|
+
if (
|
|
109
|
+
getSetting("USE_CLIENTSIDE_VALIDATION") &&
|
|
110
|
+
this.isNotAllowedFileType(file)
|
|
111
|
+
) {
|
|
104
112
|
this._progressHandler(file, { error: "errorExtensionNotAllowed" });
|
|
105
113
|
return Promise.reject(
|
|
106
114
|
new ErrorModel(
|
|
@@ -131,10 +139,12 @@ class UploadRequest {
|
|
|
131
139
|
}
|
|
132
140
|
},
|
|
133
141
|
data: file,
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
})
|
|
143
|
+
.then((response) => {
|
|
144
|
+
this._progressHandler(file, { progress: 100, token: response.token });
|
|
145
|
+
return response;
|
|
146
|
+
})
|
|
147
|
+
.catch((e) => Promise.reject(new ErrorResponse(e)));
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
150
|
|