@beinformed/ui 1.26.0 → 1.27.0-beta.1
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 +21 -0
- package/esm/constants/Constants.js +9 -35
- package/esm/constants/Constants.js.map +1 -1
- package/esm/constants/Settings.js +47 -1
- package/esm/constants/Settings.js.map +1 -1
- package/esm/hooks/useAuthentication.js +7 -6
- package/esm/hooks/useAuthentication.js.map +1 -1
- package/esm/models/application/ApplicationModel.js +2 -3
- package/esm/models/application/ApplicationModel.js.map +1 -1
- package/esm/models/attributes/UploadAttributeModel.js +15 -3
- package/esm/models/attributes/UploadAttributeModel.js.map +1 -1
- package/esm/models/error/ErrorModel.js +11 -0
- package/esm/models/error/ErrorModel.js.map +1 -1
- package/esm/models/href/Href.js +4 -4
- package/esm/models/href/Href.js.map +1 -1
- package/esm/modularui/Authenticate.js +6 -6
- package/esm/modularui/Authenticate.js.map +1 -1
- package/esm/modularui/CaptchaRequest.js +38 -0
- package/esm/modularui/CaptchaRequest.js.map +1 -0
- package/esm/modularui/ModularUIRequest.js +8 -6
- package/esm/modularui/ModularUIRequest.js.map +1 -1
- package/esm/modularui/UploadRequest.js +92 -0
- package/esm/modularui/UploadRequest.js.map +1 -0
- package/esm/modularui/index.js +2 -0
- package/esm/modularui/index.js.map +1 -1
- package/esm/react-client/client.js +2 -2
- package/esm/react-client/client.js.map +1 -1
- package/esm/react-server/contextPath.js +2 -2
- package/esm/react-server/contextPath.js.map +1 -1
- package/esm/react-server/renderSSRComplete.js +5 -4
- package/esm/react-server/renderSSRComplete.js.map +1 -1
- package/esm/react-server/renderSSRMinimal.js +2 -2
- package/esm/react-server/renderSSRMinimal.js.map +1 -1
- package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/esm/redux/_modularui/types.js.map +1 -1
- package/esm/utils/browser/Cookies.js +6 -7
- package/esm/utils/browser/Cookies.js.map +1 -1
- package/esm/utils/fetch/serverFetch.js +2 -2
- package/esm/utils/fetch/serverFetch.js.map +1 -1
- package/esm/utils/fetch/types.js.map +1 -1
- package/esm/utils/fetch/universalFetch.js +4 -3
- package/esm/utils/fetch/universalFetch.js.map +1 -1
- package/esm/utils/fetch/xhr.js.map +1 -1
- package/esm/utils/helpers/checkResource.js +0 -3
- package/esm/utils/helpers/checkResource.js.map +1 -1
- package/esm/utils/helpers/index.js +8 -0
- package/esm/utils/helpers/index.js.map +1 -0
- package/esm/utils/helpers/repositoryResource.js +18 -0
- package/esm/utils/helpers/repositoryResource.js.map +1 -0
- package/esm/utils/index.js +1 -6
- package/esm/utils/index.js.map +1 -1
- package/lib/constants/Constants.js +13 -42
- package/lib/constants/Constants.js.flow +9 -41
- package/lib/constants/Constants.js.map +1 -1
- package/lib/constants/Settings.js +53 -1
- package/lib/constants/Settings.js.flow +60 -0
- package/lib/constants/Settings.js.map +1 -1
- package/lib/hooks/useAuthentication.js +6 -5
- package/lib/hooks/useAuthentication.js.flow +9 -8
- package/lib/hooks/useAuthentication.js.map +1 -1
- package/lib/models/application/ApplicationModel.js +1 -1
- package/lib/models/application/ApplicationModel.js.flow +3 -2
- package/lib/models/application/ApplicationModel.js.map +1 -1
- package/lib/models/attributes/UploadAttributeModel.js +15 -3
- package/lib/models/attributes/UploadAttributeModel.js.flow +21 -0
- package/lib/models/attributes/UploadAttributeModel.js.map +1 -1
- package/lib/models/error/ErrorModel.js +11 -0
- package/lib/models/error/ErrorModel.js.flow +12 -1
- package/lib/models/error/ErrorModel.js.map +1 -1
- package/lib/models/href/Href.js +6 -6
- package/lib/models/href/Href.js.flow +4 -4
- package/lib/models/href/Href.js.map +1 -1
- package/lib/models/href/__tests__/Href.spec.js.flow +2 -3
- package/lib/modularui/Authenticate.js +4 -4
- package/lib/modularui/Authenticate.js.flow +6 -5
- package/lib/modularui/Authenticate.js.map +1 -1
- package/lib/modularui/CaptchaRequest.js +46 -0
- package/lib/modularui/CaptchaRequest.js.flow +45 -0
- package/lib/modularui/CaptchaRequest.js.map +1 -0
- package/lib/modularui/ModularUIRequest.js +6 -4
- package/lib/modularui/ModularUIRequest.js.flow +10 -10
- package/lib/modularui/ModularUIRequest.js.map +1 -1
- package/lib/modularui/UploadRequest.js +100 -0
- package/lib/modularui/UploadRequest.js.flow +127 -0
- package/lib/modularui/UploadRequest.js.map +1 -0
- package/lib/modularui/index.js +14 -0
- package/lib/modularui/index.js.flow +2 -0
- package/lib/modularui/index.js.map +1 -1
- package/lib/react-client/client.js +2 -2
- package/lib/react-client/client.js.flow +2 -2
- package/lib/react-client/client.js.map +1 -1
- package/lib/react-server/contextPath.js +2 -2
- package/lib/react-server/contextPath.js.flow +2 -2
- package/lib/react-server/contextPath.js.map +1 -1
- package/lib/react-server/renderSSRComplete.js +5 -4
- package/lib/react-server/renderSSRComplete.js.flow +6 -4
- package/lib/react-server/renderSSRComplete.js.map +1 -1
- package/lib/react-server/renderSSRMinimal.js +2 -2
- package/lib/react-server/renderSSRMinimal.js.flow +2 -2
- package/lib/react-server/renderSSRMinimal.js.map +1 -1
- package/lib/redux/_modularui/ModularUIMiddleware.js.flow +1 -1
- package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
- package/lib/redux/_modularui/types.js.flow +1 -1
- package/lib/redux/_modularui/types.js.map +1 -1
- package/lib/utils/browser/Cookies.js +3 -3
- package/lib/utils/browser/Cookies.js.flow +10 -8
- package/lib/utils/browser/Cookies.js.map +1 -1
- package/lib/utils/fetch/serverFetch.js +2 -2
- package/lib/utils/fetch/serverFetch.js.flow +2 -2
- package/lib/utils/fetch/serverFetch.js.map +1 -1
- package/lib/utils/fetch/types.js.flow +1 -1
- package/lib/utils/fetch/types.js.map +1 -1
- package/lib/utils/fetch/universalFetch.js +3 -2
- package/lib/utils/fetch/universalFetch.js.flow +5 -3
- package/lib/utils/fetch/universalFetch.js.map +1 -1
- package/lib/utils/fetch/xhr.js.flow +1 -1
- package/lib/utils/fetch/xhr.js.map +1 -1
- package/lib/utils/helpers/checkResource.js +0 -3
- package/lib/utils/helpers/checkResource.js.flow +0 -2
- package/lib/utils/helpers/checkResource.js.map +1 -1
- package/lib/utils/helpers/index.js +90 -0
- package/lib/utils/helpers/index.js.flow +8 -0
- package/lib/utils/helpers/index.js.map +1 -0
- package/lib/utils/helpers/repositoryResource.js +25 -0
- package/lib/utils/helpers/repositoryResource.js.flow +20 -0
- package/lib/utils/helpers/repositoryResource.js.map +1 -0
- package/lib/utils/index.js +4 -60
- package/lib/utils/index.js.flow +1 -6
- package/lib/utils/index.js.map +1 -1
- package/package.json +11 -11
- package/src/constants/Constants.js +9 -41
- package/src/constants/Settings.js +60 -0
- package/src/hooks/useAuthentication.js +9 -8
- package/src/models/application/ApplicationModel.js +3 -2
- package/src/models/attributes/UploadAttributeModel.js +21 -0
- package/src/models/error/ErrorModel.js +12 -1
- package/src/models/href/Href.js +4 -4
- package/src/models/href/__tests__/Href.spec.js +2 -3
- package/src/modularui/Authenticate.js +6 -5
- package/src/modularui/CaptchaRequest.js +45 -0
- package/src/modularui/ModularUIRequest.js +10 -10
- package/src/modularui/UploadRequest.js +127 -0
- package/src/modularui/index.js +2 -0
- package/src/react-client/client.js +2 -2
- package/src/react-server/contextPath.js +2 -2
- package/src/react-server/renderSSRComplete.js +6 -4
- package/src/react-server/renderSSRMinimal.js +2 -2
- package/src/redux/_modularui/ModularUIMiddleware.js +1 -1
- package/src/redux/_modularui/types.js +1 -1
- package/src/utils/browser/Cookies.js +10 -8
- package/src/utils/fetch/serverFetch.js +2 -2
- package/src/utils/fetch/types.js +1 -1
- package/src/utils/fetch/universalFetch.js +5 -3
- package/src/utils/fetch/xhr.js +1 -1
- package/src/utils/helpers/checkResource.js +0 -2
- package/src/utils/helpers/index.js +8 -0
- package/src/utils/helpers/repositoryResource.js +20 -0
- package/src/utils/index.js +1 -6
- package/types/constants/Constants.d.ts +8 -24
- package/types/constants/Settings.d.ts +12 -0
- package/types/models/attributes/UploadAttributeModel.d.ts +6 -0
- package/types/models/error/ErrorModel.d.ts +5 -0
- package/types/models/href/Href.d.ts +1 -1
- package/types/modularui/CaptchaRequest.d.ts +17 -0
- package/types/modularui/ModularUIRequest.d.ts +4 -6
- package/types/modularui/UploadRequest.d.ts +35 -0
- package/types/modularui/index.d.ts +2 -0
- package/types/redux/_modularui/types.d.ts +1 -3
- package/types/utils/browser/Cookies.d.ts +0 -6
- package/types/utils/fetch/types.d.ts +1 -3
- package/types/utils/helpers/index.d.ts +7 -0
- package/types/utils/helpers/repositoryResource.d.ts +1 -0
- package/types/utils/index.d.ts +1 -6
|
@@ -6,9 +6,9 @@ import { login, logout, resetAuthErrors } from "../redux/actions";
|
|
|
6
6
|
|
|
7
7
|
import Cache from "../utils/browser/Cache";
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
DEFAULT_AUTHENTICATION_TYPE,
|
|
10
|
+
getBasePath,
|
|
11
|
+
logoutPath,
|
|
12
12
|
} from "../constants";
|
|
13
13
|
|
|
14
14
|
import type { ResetAuthErrorsAction } from "../redux/types";
|
|
@@ -43,7 +43,7 @@ export const useLogin = (): LoginHook => {
|
|
|
43
43
|
return {
|
|
44
44
|
isAuthenticated,
|
|
45
45
|
authenticationTypes: application?.authenticationTypes ?? [
|
|
46
|
-
|
|
46
|
+
DEFAULT_AUTHENTICATION_TYPE,
|
|
47
47
|
],
|
|
48
48
|
errorMessage: auth.error,
|
|
49
49
|
resetErrors: () => dispatch(resetAuthErrors()),
|
|
@@ -62,7 +62,7 @@ export const useLogin = (): LoginHook => {
|
|
|
62
62
|
if (!isAuthenticated) {
|
|
63
63
|
Cache.setItem("isRedirectLogin", true);
|
|
64
64
|
window.location.assign(
|
|
65
|
-
`${
|
|
65
|
+
`${getBasePath()}${authenticationType.redirectUri ?? ""}`
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
},
|
|
@@ -75,18 +75,19 @@ export const useLogout = (): LogoutHook => {
|
|
|
75
75
|
const dispatch = useDispatch();
|
|
76
76
|
const application = useSelector(getApplication);
|
|
77
77
|
|
|
78
|
-
const LOGOUT_PATH =
|
|
78
|
+
const LOGOUT_PATH = logoutPath();
|
|
79
|
+
const BASE_PATH = getBasePath();
|
|
79
80
|
|
|
80
81
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
81
82
|
return {
|
|
82
83
|
isAuthenticated,
|
|
83
84
|
authenticationTypes: application?.authenticationTypes ?? [
|
|
84
|
-
|
|
85
|
+
DEFAULT_AUTHENTICATION_TYPE,
|
|
85
86
|
],
|
|
86
87
|
logout: () => {
|
|
87
88
|
if (Cache.getItem("isRedirectLogin")) {
|
|
88
89
|
const origin = window.location.origin;
|
|
89
|
-
const url = `${origin}${
|
|
90
|
+
const url = `${origin}${BASE_PATH}/logout?url=${origin}${BASE_PATH}${LOGOUT_PATH}`;
|
|
90
91
|
Cache.setItem("isRedirectLogin", false);
|
|
91
92
|
window.location.assign(url);
|
|
92
93
|
} else {
|
|
@@ -5,11 +5,12 @@ import UserServicesModel from "../user/UserServicesModel";
|
|
|
5
5
|
|
|
6
6
|
import { NotAllowedUriException } from "../../exceptions";
|
|
7
7
|
|
|
8
|
+
import { DEFAULT_AUTHENTICATION_TYPE } from "../../constants";
|
|
9
|
+
|
|
8
10
|
import type { ModularUIModel, AuthenticationType } from "../types";
|
|
9
11
|
import type { ModularUIResponse } from "../../modularui";
|
|
10
12
|
import type LinkCollection from "../links/LinkCollection";
|
|
11
13
|
import type Href from "../href/Href";
|
|
12
|
-
import { fallbackDefaultAuthenticationType } from "../../constants";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* The Application model
|
|
@@ -76,7 +77,7 @@ export default class ApplicationModel extends ResourceModel {
|
|
|
76
77
|
*/
|
|
77
78
|
get authenticationTypes(): Array<AuthenticationType> {
|
|
78
79
|
const authenticationTypes = this.getContribution("security", [
|
|
79
|
-
|
|
80
|
+
DEFAULT_AUTHENTICATION_TYPE,
|
|
80
81
|
]);
|
|
81
82
|
|
|
82
83
|
//put primary first
|
|
@@ -108,6 +108,7 @@ export default class UploadAttributeModel extends StringAttributeModel {
|
|
|
108
108
|
get uploadConstraints(): {
|
|
109
109
|
fileTypes: FiletypeConstraintsType,
|
|
110
110
|
maxFileSize: FilesizeConstraintsType,
|
|
111
|
+
acceptedFiles: Array<string>,
|
|
111
112
|
} {
|
|
112
113
|
const mimeTypes = this.contributions.allowedMimeTypes
|
|
113
114
|
? this.contributions.allowedMimeTypes.filter(
|
|
@@ -132,9 +133,29 @@ export default class UploadAttributeModel extends StringAttributeModel {
|
|
|
132
133
|
maxTotalFileSize: this.maxTotalFileSize,
|
|
133
134
|
isMaxTotal: this.maxTotalFileSize !== undefined,
|
|
134
135
|
},
|
|
136
|
+
acceptedFiles: this.acceptedFiles,
|
|
135
137
|
};
|
|
136
138
|
}
|
|
137
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Array of accepted file extensions and mime types.
|
|
142
|
+
* Convenience method for accept attribute of file input html control
|
|
143
|
+
*/
|
|
144
|
+
get acceptedFiles(): Array<string> {
|
|
145
|
+
const mimeTypes = this.contributions.allowedMimeTypes
|
|
146
|
+
? this.contributions.allowedMimeTypes.filter(
|
|
147
|
+
(mimeType) => mimeType !== "[...]"
|
|
148
|
+
)
|
|
149
|
+
: [];
|
|
150
|
+
const extensions = this.contributions.allowedExtensions
|
|
151
|
+
? this.contributions.allowedExtensions
|
|
152
|
+
.filter((extension) => extension !== "[...]")
|
|
153
|
+
.map((extension) => `.${extension}`)
|
|
154
|
+
: [];
|
|
155
|
+
|
|
156
|
+
return [...extensions, ...mimeTypes];
|
|
157
|
+
}
|
|
158
|
+
|
|
138
159
|
/**
|
|
139
160
|
* Add upload constraints
|
|
140
161
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import type { MessageParameters } from "../../i18n/types";
|
|
2
|
+
import type { MessageObject, MessageParameters } from "../../i18n/types";
|
|
3
3
|
import LayoutHintCollection from "../layouthint/LayoutHintCollection";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -67,6 +67,17 @@ class ErrorModel {
|
|
|
67
67
|
get isMandatoryConstraint(): boolean {
|
|
68
68
|
return this.id === "Constraint.Mandatory";
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Returns a message object from the error
|
|
73
|
+
*/
|
|
74
|
+
getMessage(): MessageObject {
|
|
75
|
+
return {
|
|
76
|
+
id: this.id,
|
|
77
|
+
defaultMessage: this.defaultMessage ?? "",
|
|
78
|
+
parameters: this.parameters ?? {},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
export default ErrorModel;
|
package/src/models/href/Href.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {
|
|
2
|
+
import { getBasePath, HTTP_METHODS, CONTENT_PATH } from "../../constants";
|
|
3
3
|
|
|
4
4
|
import Parameter from "../parameter/Parameter";
|
|
5
5
|
import { IllegalArgumentException } from "../../exceptions";
|
|
@@ -341,14 +341,14 @@ class Href {
|
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
/**
|
|
344
|
-
* Retrieve the path combined with the
|
|
344
|
+
* Retrieve the path combined with the base path (context-path) of the application, e.g. /BeInformed
|
|
345
345
|
*/
|
|
346
346
|
get absolutepath(): string {
|
|
347
347
|
if (this.isExternal) {
|
|
348
348
|
return this.path;
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
return
|
|
351
|
+
return getBasePath() + this.path;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
/**
|
|
@@ -433,7 +433,7 @@ class Href {
|
|
|
433
433
|
* Indicates if the link is a content link
|
|
434
434
|
*/
|
|
435
435
|
get isContent(): boolean {
|
|
436
|
-
return this.absolutepath.startsWith(CONTENT_PATH);
|
|
436
|
+
return this.absolutepath.startsWith(`${getBasePath()}${CONTENT_PATH}`);
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getBasePath } from "../../../constants";
|
|
2
2
|
import Href from "../Href";
|
|
3
3
|
|
|
4
4
|
describe("href spec", () => {
|
|
@@ -140,8 +140,7 @@ describe("href spec", () => {
|
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
it("a tab can have the same uri as the contextPath", () => {
|
|
143
|
-
expect(
|
|
144
|
-
expect(APPLICATION_PATH).toBe("/BeInformed/");
|
|
143
|
+
expect(getBasePath()).toBe("/BeInformed");
|
|
145
144
|
|
|
146
145
|
const tabHref = new Href("/BeInformed");
|
|
147
146
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {
|
|
2
|
+
import { HTTP_METHODS } from "../constants/Constants";
|
|
3
3
|
|
|
4
4
|
import universalFetch from "../utils/fetch/universalFetch";
|
|
5
5
|
import Cache from "../utils/browser/Cache";
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
loginPasswordField,
|
|
12
12
|
loginUsernameField,
|
|
13
13
|
logoutPath,
|
|
14
|
+
getBasePath,
|
|
14
15
|
} from "../constants";
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -57,7 +58,7 @@ class Authenticate {
|
|
|
57
58
|
*/
|
|
58
59
|
requestLogin(): Promise<any> {
|
|
59
60
|
return universalFetch({
|
|
60
|
-
url: `${
|
|
61
|
+
url: `${getBasePath()}/login`,
|
|
61
62
|
method: HTTP_METHODS.GET,
|
|
62
63
|
headers: {
|
|
63
64
|
Accept: "application/json",
|
|
@@ -104,9 +105,9 @@ class Authenticate {
|
|
|
104
105
|
switch (this.authenticationType) {
|
|
105
106
|
case "PAC4J_BASIC":
|
|
106
107
|
case "PAC4J_FORM":
|
|
107
|
-
return `${
|
|
108
|
+
return `${getBasePath()}${loginPath()}`;
|
|
108
109
|
default:
|
|
109
|
-
return `${
|
|
110
|
+
return `${getBasePath()}/j_security_check`;
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -161,7 +162,7 @@ class Authenticate {
|
|
|
161
162
|
*/
|
|
162
163
|
logout(): Promise<any> {
|
|
163
164
|
return universalFetch({
|
|
164
|
-
url: `${
|
|
165
|
+
url: `${getBasePath()}${logoutPath()}`,
|
|
165
166
|
}).then((response) => {
|
|
166
167
|
// clear cache because of cached contributions
|
|
167
168
|
Cache.clear();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import xhr from "../utils/fetch/xhr";
|
|
3
|
+
import { getCaptchaPath, HTTP_METHODS } from "../constants";
|
|
4
|
+
|
|
5
|
+
type CaptchaResponse = {
|
|
6
|
+
tokenId: string,
|
|
7
|
+
image: any,
|
|
8
|
+
valid: boolean,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*/
|
|
13
|
+
class CaptchaRequest {
|
|
14
|
+
_tokenId: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*/
|
|
18
|
+
init(): Promise<CaptchaResponse> {
|
|
19
|
+
return xhr({
|
|
20
|
+
url: getCaptchaPath(),
|
|
21
|
+
}).then((response) => {
|
|
22
|
+
this._tokenId = response.tokenId;
|
|
23
|
+
|
|
24
|
+
return response;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*/
|
|
30
|
+
send(answer?: string): Promise<CaptchaResponse> {
|
|
31
|
+
return xhr({
|
|
32
|
+
url: getCaptchaPath(),
|
|
33
|
+
method: HTTP_METHODS.POST,
|
|
34
|
+
data: {
|
|
35
|
+
tokenId: this._tokenId ?? "",
|
|
36
|
+
answer: answer ?? "",
|
|
37
|
+
},
|
|
38
|
+
}).catch((error) => {
|
|
39
|
+
this._tokenId = error.response.tokenId;
|
|
40
|
+
return error.response;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default CaptchaRequest;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import deepmerge from "deepmerge";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
BASE,
|
|
6
|
-
HTTP_METHODS,
|
|
7
|
-
TIMEVERSION_FILTER_NAME,
|
|
8
|
-
} from "../constants/Constants";
|
|
4
|
+
import { HTTP_METHODS, TIMEVERSION_FILTER_NAME } from "../constants/Constants";
|
|
9
5
|
|
|
10
6
|
import { HIDE_WHEN_EMPTY } from "../constants/LayoutHints";
|
|
11
7
|
|
|
12
|
-
import { getSetting } from "../constants/Settings";
|
|
8
|
+
import { getBasePath, getSetting } from "../constants/Settings";
|
|
13
9
|
|
|
14
10
|
import Href from "../models/href/Href";
|
|
15
11
|
|
|
@@ -49,6 +45,8 @@ class ModularUIRequest {
|
|
|
49
45
|
|
|
50
46
|
_progressEvent: ProgressEventHandler;
|
|
51
47
|
|
|
48
|
+
_basePath: string = "/BeInformed";
|
|
49
|
+
|
|
52
50
|
/**
|
|
53
51
|
*/
|
|
54
52
|
constructor(
|
|
@@ -61,6 +59,8 @@ class ModularUIRequest {
|
|
|
61
59
|
);
|
|
62
60
|
}
|
|
63
61
|
|
|
62
|
+
this._basePath = getBasePath();
|
|
63
|
+
|
|
64
64
|
this.options = options;
|
|
65
65
|
|
|
66
66
|
this._response = new ModularUIResponse();
|
|
@@ -331,7 +331,7 @@ class ModularUIRequest {
|
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
return universalFetch({
|
|
334
|
-
url: `${
|
|
334
|
+
url: `${this._basePath}${this.contributionsHref}`,
|
|
335
335
|
cache: true,
|
|
336
336
|
locale: this.options.locale,
|
|
337
337
|
});
|
|
@@ -342,7 +342,7 @@ class ModularUIRequest {
|
|
|
342
342
|
fetchDataService(): Promise<any> {
|
|
343
343
|
return universalFetch({
|
|
344
344
|
...this.requestOptions,
|
|
345
|
-
url: `${
|
|
345
|
+
url: `${this._basePath}${this.href.path}`,
|
|
346
346
|
params: this.href.getQuerystringForModularUI(),
|
|
347
347
|
locale: this.options.locale,
|
|
348
348
|
onProgress: this.onProgress,
|
|
@@ -519,7 +519,7 @@ class ModularUIRequest {
|
|
|
519
519
|
|
|
520
520
|
return universalFetch({
|
|
521
521
|
...this.requestOptions,
|
|
522
|
-
url: `${
|
|
522
|
+
url: `${this._basePath}${href}`,
|
|
523
523
|
})
|
|
524
524
|
.then((response: Object) => {
|
|
525
525
|
if (isPlainObject(response)) {
|
|
@@ -587,7 +587,7 @@ class ModularUIRequest {
|
|
|
587
587
|
const validationHref = this.href.setParameter("commit", "false");
|
|
588
588
|
return universalFetch({
|
|
589
589
|
...this.requestOptions,
|
|
590
|
-
url: `${
|
|
590
|
+
url: `${this._basePath}${this.href.path}`,
|
|
591
591
|
params: validationHref.getQuerystringForModularUI(),
|
|
592
592
|
data: this.getDynamicValidationData(model),
|
|
593
593
|
}).then((data) => {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { getUploadPath, HTTP_METHODS } from "../constants";
|
|
3
|
+
|
|
4
|
+
import xhr from "../utils/fetch/xhr";
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
FilesizeConstraintsType,
|
|
8
|
+
FiletypeConstraintsType,
|
|
9
|
+
} from "../models";
|
|
10
|
+
import ErrorModel from "../models/error/ErrorModel";
|
|
11
|
+
|
|
12
|
+
type ProgressHandler = (file: File, uploadInfo: Object) => void;
|
|
13
|
+
|
|
14
|
+
type UploadResponse = {
|
|
15
|
+
token: string,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Upload a file to the upload file service of Be Informed
|
|
20
|
+
*/
|
|
21
|
+
class UploadRequest {
|
|
22
|
+
_uploadConstraints: {
|
|
23
|
+
fileTypes: FiletypeConstraintsType,
|
|
24
|
+
maxFileSize: FilesizeConstraintsType,
|
|
25
|
+
acceptedFiles: Array<string>,
|
|
26
|
+
};
|
|
27
|
+
_progressHandler: ProgressHandler;
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
uploadConstraints: {
|
|
31
|
+
fileTypes: FiletypeConstraintsType,
|
|
32
|
+
maxFileSize: FilesizeConstraintsType,
|
|
33
|
+
acceptedFiles: Array<string>,
|
|
34
|
+
},
|
|
35
|
+
progressHandler: ProgressHandler
|
|
36
|
+
) {
|
|
37
|
+
this._uploadConstraints = uploadConstraints;
|
|
38
|
+
this._progressHandler = progressHandler;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*/
|
|
43
|
+
getFileExtension(file: File): string {
|
|
44
|
+
return file.name.split(".").pop().toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*/
|
|
49
|
+
isNotAllowedFileType(file: File): boolean {
|
|
50
|
+
const allowedFileTypes = this._uploadConstraints.fileTypes;
|
|
51
|
+
|
|
52
|
+
if (allowedFileTypes.length > 0) {
|
|
53
|
+
const fileExtension = this.getFileExtension(file);
|
|
54
|
+
|
|
55
|
+
return !allowedFileTypes.some((fileType) =>
|
|
56
|
+
fileType.extensions.includes(fileExtension)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*/
|
|
65
|
+
exceedsMaxFileSize(file: File): boolean {
|
|
66
|
+
const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
|
|
67
|
+
return maxFileSize > -1 && file.size > maxFileSize;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
*/
|
|
72
|
+
uploadFile(file: File): Promise<UploadResponse> {
|
|
73
|
+
const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
|
|
74
|
+
|
|
75
|
+
if (this.exceedsMaxFileSize(file)) {
|
|
76
|
+
this._progressHandler(file, { error: "errorExceedsMaxFileSize" });
|
|
77
|
+
return Promise.reject(
|
|
78
|
+
new ErrorModel(
|
|
79
|
+
"Constraint.File.MaxFileSizeExceeded",
|
|
80
|
+
"Maximum file upload size is ${max-filesize}",
|
|
81
|
+
{
|
|
82
|
+
"max-filesize": maxFileSize,
|
|
83
|
+
},
|
|
84
|
+
true
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (this.isNotAllowedFileType(file)) {
|
|
90
|
+
this._progressHandler(file, { error: "errorExtensionNotAllowed" });
|
|
91
|
+
return Promise.reject(
|
|
92
|
+
new ErrorModel(
|
|
93
|
+
"Constraint.File.InvalidExtension",
|
|
94
|
+
"Allowed extensions are: ${extensions}",
|
|
95
|
+
{
|
|
96
|
+
extension: this.getFileExtension(file),
|
|
97
|
+
extensions: this._uploadConstraints.fileTypes.join(", "),
|
|
98
|
+
},
|
|
99
|
+
true
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return xhr({
|
|
105
|
+
url: getUploadPath(),
|
|
106
|
+
method: HTTP_METHODS.POST,
|
|
107
|
+
headers: {
|
|
108
|
+
"Content-Type": file.type,
|
|
109
|
+
"x-filename": encodeURIComponent(file.name),
|
|
110
|
+
"x-filesize": file.size.toString(),
|
|
111
|
+
},
|
|
112
|
+
onProgress: (e: ProgressEvent) => {
|
|
113
|
+
if (this._progressHandler && e.lengthComputable) {
|
|
114
|
+
this._progressHandler(file, {
|
|
115
|
+
progress: Math.ceil((e.loaded / e.total) * 100),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
data: file,
|
|
120
|
+
}).then((response) => {
|
|
121
|
+
this._progressHandler(file, { progress: 100, token: response.token });
|
|
122
|
+
return response;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default UploadRequest;
|
package/src/modularui/index.js
CHANGED
|
@@ -2,3 +2,5 @@
|
|
|
2
2
|
export { default as Authenticate } from "./Authenticate";
|
|
3
3
|
export { default as ModularUIRequest } from "./ModularUIRequest";
|
|
4
4
|
export { default as ModularUIResponse } from "./ModularUIResponse";
|
|
5
|
+
export { default as UploadRequest } from "./UploadRequest";
|
|
6
|
+
export { default as CaptchaRequest } from "./CaptchaRequest";
|
|
@@ -17,7 +17,7 @@ import { createBrowserHistory } from "history";
|
|
|
17
17
|
import configureStore from "../redux/store/configureStore";
|
|
18
18
|
|
|
19
19
|
import rehydrate from "./rehydrate";
|
|
20
|
-
import {
|
|
20
|
+
import { getBasePath } from "../constants/Settings";
|
|
21
21
|
|
|
22
22
|
import {
|
|
23
23
|
setAllContentInDataSetting,
|
|
@@ -87,7 +87,7 @@ const client = (props: Props) => {
|
|
|
87
87
|
|
|
88
88
|
// $FlowExpectedError
|
|
89
89
|
const browserHistory: RouterHistory = createBrowserHistory({
|
|
90
|
-
basename:
|
|
90
|
+
basename: getBasePath(),
|
|
91
91
|
});
|
|
92
92
|
const { history, store } = configureStore(
|
|
93
93
|
browserHistory,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {
|
|
2
|
+
import { getBasePath } from "../constants/Settings";
|
|
3
3
|
|
|
4
4
|
(function x() {
|
|
5
|
-
__webpack_public_path__ = `${
|
|
5
|
+
__webpack_public_path__ = `${getBasePath()}/`; // NOSONAR
|
|
6
6
|
})();
|
|
7
7
|
|
|
8
8
|
export {};
|
|
@@ -10,7 +10,7 @@ import { ServerStyleSheet, StyleSheetManager } from "styled-components";
|
|
|
10
10
|
import createSSRComplete from "./createSSRComplete";
|
|
11
11
|
import htmlpage from "./htmlpage";
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { getBasePath } from "../constants/Settings";
|
|
14
14
|
|
|
15
15
|
import ThemeProvider from "../react-theme/ThemeProvider";
|
|
16
16
|
import ErrorBoundary from "../react/ErrorBoundary";
|
|
@@ -52,6 +52,8 @@ const renderSSRComplete = ({
|
|
|
52
52
|
// $FlowFixMe[prop-missing]
|
|
53
53
|
const location: Location = requestHref.toLocation();
|
|
54
54
|
|
|
55
|
+
const basePath = getBasePath();
|
|
56
|
+
|
|
55
57
|
return createSSRComplete(store, () =>
|
|
56
58
|
renderToString(
|
|
57
59
|
<Provider store={store}>
|
|
@@ -60,7 +62,7 @@ const renderSSRComplete = ({
|
|
|
60
62
|
<HelmetProvider context={helmetContext}>
|
|
61
63
|
<ErrorBoundary>
|
|
62
64
|
<Router
|
|
63
|
-
basename={
|
|
65
|
+
basename={basePath}
|
|
64
66
|
location={location}
|
|
65
67
|
context={routerContext}
|
|
66
68
|
>
|
|
@@ -77,7 +79,7 @@ const renderSSRComplete = ({
|
|
|
77
79
|
handleErrors(store);
|
|
78
80
|
const head = createHead(sheet, UUID, helmetContext);
|
|
79
81
|
return template({
|
|
80
|
-
contextPath:
|
|
82
|
+
contextPath: basePath,
|
|
81
83
|
html: appHTML,
|
|
82
84
|
head,
|
|
83
85
|
state: dehydrate(store),
|
|
@@ -86,7 +88,7 @@ const renderSSRComplete = ({
|
|
|
86
88
|
})
|
|
87
89
|
.catch((error) =>
|
|
88
90
|
template({
|
|
89
|
-
contextPath:
|
|
91
|
+
contextPath: basePath,
|
|
90
92
|
html: renderToString(
|
|
91
93
|
<StyleSheetManager sheet={sheet.instance}>
|
|
92
94
|
<ThemeProvider theme={theme}>
|
|
@@ -6,7 +6,7 @@ import { Provider } from "react-redux";
|
|
|
6
6
|
import { ServerStyleSheet, StyleSheetManager } from "styled-components";
|
|
7
7
|
import ThemeProvider from "../react-theme/ThemeProvider";
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { getBasePath } from "../constants/Settings";
|
|
10
10
|
|
|
11
11
|
import { createHead, dehydrate } from "./serverUtil";
|
|
12
12
|
import htmlpage from "./htmlpage";
|
|
@@ -43,7 +43,7 @@ const renderSSRMinimal = ({
|
|
|
43
43
|
|
|
44
44
|
const head = createHead(sheet, UUID);
|
|
45
45
|
return template({
|
|
46
|
-
contextPath:
|
|
46
|
+
contextPath: getBasePath(),
|
|
47
47
|
html: appHTML,
|
|
48
48
|
head,
|
|
49
49
|
state: dehydrate(store),
|
|
@@ -21,7 +21,7 @@ import type { TargetModel } from "../../modularui/types";
|
|
|
21
21
|
type RequestOptions = {
|
|
22
22
|
href: Href,
|
|
23
23
|
method?: $Keys<typeof HTTP_METHODS>,
|
|
24
|
-
data?:
|
|
24
|
+
data?: any,
|
|
25
25
|
locale: string,
|
|
26
26
|
childmodels?: boolean,
|
|
27
27
|
targetModel?: TargetModel,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import Cookies from "js-cookie";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { getBasePath } from "../../constants/Settings";
|
|
5
5
|
|
|
6
6
|
type CookieOptions = {
|
|
7
7
|
days?: number,
|
|
@@ -18,14 +18,18 @@ type CookieAttributes = {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
*/
|
|
21
|
-
const getCookie = (name: string): null | string => {
|
|
21
|
+
export const getCookie = (name: string): null | string => {
|
|
22
22
|
return Cookies.get(name);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
*/
|
|
27
|
-
const setCookie = (
|
|
28
|
-
|
|
27
|
+
export const setCookie = (
|
|
28
|
+
name: string,
|
|
29
|
+
value: any,
|
|
30
|
+
options?: CookieOptions
|
|
31
|
+
) => {
|
|
32
|
+
const attributes: CookieAttributes = { path: getBasePath() };
|
|
29
33
|
attributes.expires = options?.days;
|
|
30
34
|
attributes.sameSite = options?.sameSite ?? "Strict";
|
|
31
35
|
attributes.secure = options?.secure;
|
|
@@ -35,8 +39,6 @@ const setCookie = (name: string, value: any, options?: CookieOptions) => {
|
|
|
35
39
|
|
|
36
40
|
/**
|
|
37
41
|
*/
|
|
38
|
-
const clearCookie = (name: string) => {
|
|
39
|
-
Cookies.remove(name, { path:
|
|
42
|
+
export const clearCookie = (name: string) => {
|
|
43
|
+
Cookies.remove(name, { path: getBasePath() });
|
|
40
44
|
};
|
|
41
|
-
|
|
42
|
-
export { getCookie, setCookie, clearCookie };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import {
|
|
2
|
+
import { getBasePath } from "../../constants/Settings";
|
|
3
3
|
import { FetchException } from "../../exceptions";
|
|
4
4
|
|
|
5
5
|
import type { RequestOptions } from "./types";
|
|
@@ -11,7 +11,7 @@ export default function serverFetch(args: RequestOptions): Promise<any> {
|
|
|
11
11
|
// remove contextPath of url, when the request is internal the context path is not needed
|
|
12
12
|
const urlNoBase = args.url.includes("http")
|
|
13
13
|
? args.url
|
|
14
|
-
: args.url.replace(
|
|
14
|
+
: args.url.replace(getBasePath(), "");
|
|
15
15
|
const params = args.params
|
|
16
16
|
? args.params.replace("includeContext=true", "")
|
|
17
17
|
: "";
|
package/src/utils/fetch/types.js
CHANGED