@beinformed/ui 1.15.1 → 1.17.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/CHANGELOG.md +20 -0
- package/esm/hooks/useAuthentication.js +4 -1
- package/esm/hooks/useAuthentication.js.map +1 -1
- package/esm/models/application/ApplicationModel.js +13 -2
- package/esm/models/application/ApplicationModel.js.map +1 -1
- package/esm/models/attributes/AttributeContent.js +4 -7
- package/esm/models/attributes/AttributeContent.js.map +1 -1
- package/esm/models/href/Href.js +11 -1
- package/esm/models/href/Href.js.map +1 -1
- package/esm/redux/actions/SignIn.js +9 -0
- package/esm/redux/actions/SignIn.js.map +1 -1
- package/esm/redux/reducers/AuthReducer.js +5 -0
- package/esm/redux/reducers/AuthReducer.js.map +1 -1
- package/esm/utils/helpers/checkResource.js +39 -0
- package/esm/utils/helpers/checkResource.js.map +1 -0
- package/esm/utils/index.js +1 -1
- package/esm/utils/index.js.map +1 -1
- package/lib/hooks/useAuthentication.js +3 -0
- package/lib/hooks/useAuthentication.js.flow +7 -5
- package/lib/hooks/useAuthentication.js.map +1 -1
- package/lib/models/application/ApplicationModel.js +13 -2
- package/lib/models/application/ApplicationModel.js.flow +7 -0
- package/lib/models/application/ApplicationModel.js.map +1 -1
- package/lib/models/attributes/AttributeContent.js +4 -7
- package/lib/models/attributes/AttributeContent.js.flow +3 -6
- package/lib/models/attributes/AttributeContent.js.map +1 -1
- package/lib/models/href/Href.js +11 -1
- package/lib/models/href/Href.js.flow +12 -1
- package/lib/models/href/Href.js.map +1 -1
- package/lib/redux/actions/SignIn.js +14 -2
- package/lib/redux/actions/SignIn.js.flow +8 -0
- package/lib/redux/actions/SignIn.js.map +1 -1
- package/lib/redux/reducers/AuthReducer.js +5 -0
- package/lib/redux/reducers/AuthReducer.js.flow +3 -0
- package/lib/redux/reducers/AuthReducer.js.map +1 -1
- package/lib/redux/reducers/__tests__/AuthReducer.spec.js.flow +52 -13
- package/lib/redux/types.js.flow +5 -0
- package/lib/utils/helpers/__tests__/checkResource.spec.js.flow +60 -0
- package/lib/utils/helpers/checkResource.js +54 -0
- package/lib/utils/helpers/checkResource.js.flow +42 -0
- package/lib/utils/helpers/checkResource.js.map +1 -0
- package/lib/utils/index.js +4 -4
- package/lib/utils/index.js.flow +1 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +10 -10
- package/src/hooks/useAuthentication.js +7 -5
- package/src/models/application/ApplicationModel.js +7 -0
- package/src/models/attributes/AttributeContent.js +3 -6
- package/src/models/href/Href.js +12 -1
- package/src/redux/actions/SignIn.js +8 -0
- package/src/redux/reducers/AuthReducer.js +3 -0
- package/src/redux/reducers/__tests__/AuthReducer.spec.js +52 -13
- package/src/redux/types.js +5 -0
- package/src/utils/helpers/__tests__/checkResource.spec.js +60 -0
- package/src/utils/helpers/checkResource.js +42 -0
- package/src/utils/index.js +1 -1
- package/esm/utils/helpers/checkResourceExists.js +0 -23
- package/esm/utils/helpers/checkResourceExists.js.map +0 -1
- package/lib/utils/helpers/checkResourceExists.js +0 -34
- package/lib/utils/helpers/checkResourceExists.js.flow +0 -21
- package/lib/utils/helpers/checkResourceExists.js.map +0 -1
- package/src/utils/helpers/checkResourceExists.js +0 -21
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.resourceRedirectsToSecureLogin = exports.resourceExists = void 0;
|
|
9
|
+
|
|
10
|
+
var _endsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/ends-with"));
|
|
11
|
+
|
|
12
|
+
var _Href = _interopRequireDefault(require("../../models/href/Href"));
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)
|
|
16
|
+
* When the resource returns a 404, the resource does not exists and the method returns false
|
|
17
|
+
*
|
|
18
|
+
* @param url
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
var resourceExists = function resourceExists(url) {
|
|
22
|
+
var fullUrl = new _Href.default(url).absolutehref; // const fullUrl = `${BASE}/${url}`.replace(/\/\//g, "/");
|
|
23
|
+
|
|
24
|
+
var xhr = new XMLHttpRequest();
|
|
25
|
+
xhr.open("HEAD", fullUrl, false);
|
|
26
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
27
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
28
|
+
xhr.send();
|
|
29
|
+
return xhr.status !== 404;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Indicates if a request to the given url resuls in a redirect to /secureRedirect
|
|
33
|
+
* @param url
|
|
34
|
+
* @returns {boolean}
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
exports.resourceExists = resourceExists;
|
|
39
|
+
|
|
40
|
+
var resourceRedirectsToSecureLogin = function resourceRedirectsToSecureLogin(url) {
|
|
41
|
+
var _xhr$responseURL;
|
|
42
|
+
|
|
43
|
+
var fullUrl = new _Href.default(url).absolutehref;
|
|
44
|
+
var xhr = new XMLHttpRequest();
|
|
45
|
+
xhr.open("HEAD", fullUrl, false);
|
|
46
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
47
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
48
|
+
xhr.send();
|
|
49
|
+
var responseURL = (_xhr$responseURL = xhr.responseURL) !== null && _xhr$responseURL !== void 0 ? _xhr$responseURL : "";
|
|
50
|
+
return xhr.status === 400 && (0, _endsWith.default)(responseURL).call(responseURL, "/secureLogin");
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.resourceRedirectsToSecureLogin = resourceRedirectsToSecureLogin;
|
|
54
|
+
//# sourceMappingURL=checkResource.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import Href from "../../models/href/Href";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)
|
|
6
|
+
* When the resource returns a 404, the resource does not exists and the method returns false
|
|
7
|
+
*
|
|
8
|
+
* @param url
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export const resourceExists = (url: string | Href): boolean => {
|
|
12
|
+
const fullUrl = new Href(url).absolutehref;
|
|
13
|
+
|
|
14
|
+
// const fullUrl = `${BASE}/${url}`.replace(/\/\//g, "/");
|
|
15
|
+
|
|
16
|
+
const xhr = new XMLHttpRequest();
|
|
17
|
+
xhr.open("HEAD", fullUrl, false);
|
|
18
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
19
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
20
|
+
xhr.send();
|
|
21
|
+
|
|
22
|
+
return xhr.status !== 404;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Indicates if a request to the given url resuls in a redirect to /secureRedirect
|
|
27
|
+
* @param url
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export const resourceRedirectsToSecureLogin = (url: string | Href): boolean => {
|
|
31
|
+
const fullUrl = new Href(url).absolutehref;
|
|
32
|
+
|
|
33
|
+
const xhr = new XMLHttpRequest();
|
|
34
|
+
xhr.open("HEAD", fullUrl, false);
|
|
35
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
36
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
37
|
+
xhr.send();
|
|
38
|
+
|
|
39
|
+
const responseURL = xhr.responseURL ?? "";
|
|
40
|
+
|
|
41
|
+
return xhr.status === 400 && responseURL.endsWith("/secureLogin");
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/helpers/checkResource.js"],"names":["resourceExists","url","fullUrl","Href","absolutehref","xhr","XMLHttpRequest","open","setRequestHeader","send","status","resourceRedirectsToSecureLogin","responseURL"],"mappings":";;;;;;;;;;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAACC,GAAD,EAAiC;AAC7D,MAAMC,OAAO,GAAG,IAAIC,aAAJ,CAASF,GAAT,EAAcG,YAA9B,CAD6D,CAG7D;;AAEA,MAAMC,GAAG,GAAG,IAAIC,cAAJ,EAAZ;AACAD,EAAAA,GAAG,CAACE,IAAJ,CAAS,MAAT,EAAiBL,OAAjB,EAA0B,KAA1B;AACAG,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,QAArB,EAA+B,kBAA/B;AACAH,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,cAArB,EAAqC,kBAArC;AACAH,EAAAA,GAAG,CAACI,IAAJ;AAEA,SAAOJ,GAAG,CAACK,MAAJ,KAAe,GAAtB;AACD,CAZM;AAcP;AACA;AACA;AACA;AACA;;;;;AACO,IAAMC,8BAA8B,GAAG,SAAjCA,8BAAiC,CAACV,GAAD,EAAiC;AAAA;;AAC7E,MAAMC,OAAO,GAAG,IAAIC,aAAJ,CAASF,GAAT,EAAcG,YAA9B;AAEA,MAAMC,GAAG,GAAG,IAAIC,cAAJ,EAAZ;AACAD,EAAAA,GAAG,CAACE,IAAJ,CAAS,MAAT,EAAiBL,OAAjB,EAA0B,KAA1B;AACAG,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,QAArB,EAA+B,kBAA/B;AACAH,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,cAArB,EAAqC,kBAArC;AACAH,EAAAA,GAAG,CAACI,IAAJ;AAEA,MAAMG,WAAW,uBAAGP,GAAG,CAACO,WAAP,+DAAsB,EAAvC;AAEA,SAAOP,GAAG,CAACK,MAAJ,KAAe,GAAf,IAAsB,uBAAAE,WAAW,MAAX,CAAAA,WAAW,EAAU,cAAV,CAAxC;AACD,CAZM","sourcesContent":["// @flow\nimport Href from \"../../models/href/Href\";\n\n/**\n * Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)\n * When the resource returns a 404, the resource does not exists and the method returns false\n *\n * @param url\n * @returns {boolean}\n */\nexport const resourceExists = (url: string | Href): boolean => {\n const fullUrl = new Href(url).absolutehref;\n\n // const fullUrl = `${BASE}/${url}`.replace(/\\/\\//g, \"/\");\n\n const xhr = new XMLHttpRequest();\n xhr.open(\"HEAD\", fullUrl, false);\n xhr.setRequestHeader(\"Accept\", \"application/json\");\n xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n xhr.send();\n\n return xhr.status !== 404;\n};\n\n/**\n * Indicates if a request to the given url resuls in a redirect to /secureRedirect\n * @param url\n * @returns {boolean}\n */\nexport const resourceRedirectsToSecureLogin = (url: string | Href): boolean => {\n const fullUrl = new Href(url).absolutehref;\n\n const xhr = new XMLHttpRequest();\n xhr.open(\"HEAD\", fullUrl, false);\n xhr.setRequestHeader(\"Accept\", \"application/json\");\n xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n xhr.send();\n\n const responseURL = xhr.responseURL ?? \"\";\n\n return xhr.status === 400 && responseURL.endsWith(\"/secureLogin\");\n};\n"],"file":"checkResource.js"}
|
package/lib/utils/index.js
CHANGED
|
@@ -153,16 +153,16 @@ _Object$keys(_text).forEach(function (key) {
|
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
-
var
|
|
156
|
+
var _checkResource = require("./helpers/checkResource");
|
|
157
157
|
|
|
158
|
-
_Object$keys(
|
|
158
|
+
_Object$keys(_checkResource).forEach(function (key) {
|
|
159
159
|
if (key === "default" || key === "__esModule") return;
|
|
160
160
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
161
|
-
if (key in exports && exports[key] ===
|
|
161
|
+
if (key in exports && exports[key] === _checkResource[key]) return;
|
|
162
162
|
Object.defineProperty(exports, key, {
|
|
163
163
|
enumerable: true,
|
|
164
164
|
get: function get() {
|
|
165
|
-
return
|
|
165
|
+
return _checkResource[key];
|
|
166
166
|
}
|
|
167
167
|
});
|
|
168
168
|
});
|
package/lib/utils/index.js.flow
CHANGED
|
@@ -19,7 +19,7 @@ export { default as createUUID } from "./helpers/createUUID";
|
|
|
19
19
|
export * from "./helpers/sanitizeHtml";
|
|
20
20
|
export * from "./helpers/objects";
|
|
21
21
|
export * from "./helpers/text";
|
|
22
|
-
export * from "./helpers/
|
|
22
|
+
export * from "./helpers/checkResource";
|
|
23
23
|
|
|
24
24
|
// number
|
|
25
25
|
export { default as DecimalFormat } from "./number/DecimalFormat";
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AACA;;AAIA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["// @flow\n\n// browser\nexport { default as Cache } from \"./browser/Cache\";\nexport * from \"./browser/Cookies\";\n\n// datetime\nexport * from \"./datetime/DateTimeUtil\";\n\n// fetch\nexport { default as serverFetch } from \"./fetch/serverFetch\";\nexport { default as universalFetch } from \"./fetch/universalFetch\";\nexport { default as xhr } from \"./fetch/xhr\";\nexport type * from \"./fetch/types\";\n\n// helpers\nexport * from \"./helpers/createHash\";\nexport { default as createUUID } from \"./helpers/createUUID\";\nexport * from \"./helpers/sanitizeHtml\";\nexport * from \"./helpers/objects\";\nexport * from \"./helpers/text\";\nexport * from \"./helpers/
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AACA;;AAIA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["// @flow\n\n// browser\nexport { default as Cache } from \"./browser/Cache\";\nexport * from \"./browser/Cookies\";\n\n// datetime\nexport * from \"./datetime/DateTimeUtil\";\n\n// fetch\nexport { default as serverFetch } from \"./fetch/serverFetch\";\nexport { default as universalFetch } from \"./fetch/universalFetch\";\nexport { default as xhr } from \"./fetch/xhr\";\nexport type * from \"./fetch/types\";\n\n// helpers\nexport * from \"./helpers/createHash\";\nexport { default as createUUID } from \"./helpers/createUUID\";\nexport * from \"./helpers/sanitizeHtml\";\nexport * from \"./helpers/objects\";\nexport * from \"./helpers/text\";\nexport * from \"./helpers/checkResource\";\n\n// number\nexport { default as DecimalFormat } from \"./number/DecimalFormat\";\nexport { default as formatValue } from \"./number/formatValue\";\nexport * from \"./number/parseNumbers\";\n"],"file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "http://support.beinformed.com",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"styled-components": "^5.2.0"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@babel/runtime-corejs3": "^7.17.
|
|
81
|
+
"@babel/runtime-corejs3": "^7.17.8",
|
|
82
82
|
"big.js": "^6.1.1",
|
|
83
83
|
"date-fns": "^2.28.0",
|
|
84
84
|
"deepmerge": "^4.2.2",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@babel/cli": "^7.17.3",
|
|
99
|
-
"@babel/core": "^7.17.
|
|
99
|
+
"@babel/core": "^7.17.8",
|
|
100
100
|
"@babel/eslint-parser": "^7.17.0",
|
|
101
101
|
"@babel/eslint-plugin": "^7.16.5",
|
|
102
102
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
@@ -113,16 +113,16 @@
|
|
|
113
113
|
"cherry-pick": "^0.5.0",
|
|
114
114
|
"cross-env": "^7.0.3",
|
|
115
115
|
"documentation": "^13.2.5",
|
|
116
|
-
"eslint": "^8.
|
|
116
|
+
"eslint": "^8.12.0",
|
|
117
117
|
"eslint-config-prettier": "^8.3.0",
|
|
118
118
|
"eslint-plugin-babel": "^5.3.1",
|
|
119
119
|
"eslint-plugin-ft-flow": "^2.0.1",
|
|
120
120
|
"eslint-plugin-import": "^2.25.4",
|
|
121
|
-
"eslint-plugin-jest": "^26.1.
|
|
122
|
-
"eslint-plugin-jsdoc": "^38.
|
|
121
|
+
"eslint-plugin-jest": "^26.1.3",
|
|
122
|
+
"eslint-plugin-jsdoc": "^38.1.3",
|
|
123
123
|
"eslint-plugin-react": "^7.28.0",
|
|
124
124
|
"eslint-plugin-react-hooks": "^4.3.0",
|
|
125
|
-
"flow-bin": "^0.
|
|
125
|
+
"flow-bin": "^0.174.1",
|
|
126
126
|
"flow-copy-source": "^2.0.9",
|
|
127
127
|
"flow-typed": "^3.6.1",
|
|
128
128
|
"glob": "^7.2.0",
|
|
@@ -132,9 +132,9 @@
|
|
|
132
132
|
"jest-junit": "^13.0.0",
|
|
133
133
|
"jest-sonar-reporter": "^2.0.0",
|
|
134
134
|
"jscodeshift": "^0.13.1",
|
|
135
|
-
"lint-staged": "^12.3.
|
|
135
|
+
"lint-staged": "^12.3.7",
|
|
136
136
|
"polished": "^4.1.4",
|
|
137
|
-
"prettier": "^2.6.
|
|
137
|
+
"prettier": "^2.6.1",
|
|
138
138
|
"react": "^17.0.2",
|
|
139
139
|
"react-dom": "^17.0.2",
|
|
140
140
|
"react-helmet-async": "^1.2.3",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"redux-thunk": "^2.4.1",
|
|
147
147
|
"rimraf": "^3.0.2",
|
|
148
148
|
"standard-version": "^9.3.2",
|
|
149
|
-
"styled-components": "^5.3.
|
|
149
|
+
"styled-components": "^5.3.5",
|
|
150
150
|
"xhr-mock": "^2.5.1"
|
|
151
151
|
},
|
|
152
152
|
"scarfSettings": {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import { useSelector, useDispatch } from "react-redux";
|
|
3
3
|
import { getApplication } from "../redux/_modularui/selectors";
|
|
4
|
-
import { login, logout } from "../redux/actions";
|
|
4
|
+
import { login, logout, resetAuthErrors } from "../redux/actions";
|
|
5
5
|
import UserServicesModel from "../models/user/UserServicesModel";
|
|
6
6
|
import { useState, useEffect } from "react";
|
|
7
7
|
|
|
8
|
+
import type { ResetAuthErrorsAction } from "../redux/types";
|
|
8
9
|
type LoginHook = {
|
|
9
10
|
isAuthenticated: boolean,
|
|
10
11
|
errorMessage: ?string,
|
|
12
|
+
resetErrors: () => ResetAuthErrorsAction,
|
|
11
13
|
login: (username: string, password: string) => void,
|
|
12
14
|
};
|
|
13
15
|
type LogoutHook = {
|
|
@@ -39,6 +41,7 @@ export const useLogin = (): LoginHook => {
|
|
|
39
41
|
return {
|
|
40
42
|
isAuthenticated: getIsAuthenticated(auth.isAuthenticated, application),
|
|
41
43
|
errorMessage: auth.error,
|
|
44
|
+
resetErrors: () => dispatch(resetAuthErrors()),
|
|
42
45
|
login: (username: string, password: string) =>
|
|
43
46
|
dispatch(login(username, password)),
|
|
44
47
|
};
|
|
@@ -66,12 +69,11 @@ export const useLogout = (): LogoutHook => {
|
|
|
66
69
|
|
|
67
70
|
return {
|
|
68
71
|
isAuthenticated,
|
|
69
|
-
logout: () =>
|
|
70
|
-
|
|
72
|
+
logout: () =>
|
|
73
|
+
dispatch(logout()).then(() => {
|
|
71
74
|
if (!cancel) {
|
|
72
75
|
setIsAuthenticated(false);
|
|
73
76
|
}
|
|
74
|
-
})
|
|
75
|
-
},
|
|
77
|
+
}),
|
|
76
78
|
};
|
|
77
79
|
};
|
|
@@ -92,6 +92,13 @@ export default class ApplicationModel extends ResourceModel {
|
|
|
92
92
|
return this._userServices ? this._userServices : null;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Indicates if the user is logged in
|
|
97
|
+
*/
|
|
98
|
+
get isLoggedIn(): boolean {
|
|
99
|
+
return this.userServices?.isLoggedIn ?? false;
|
|
100
|
+
}
|
|
101
|
+
|
|
95
102
|
/**
|
|
96
103
|
* Retrieve link to the user information,
|
|
97
104
|
* only available when the user services are available
|
|
@@ -61,8 +61,7 @@ class AttributeContent {
|
|
|
61
61
|
get elements(): ContentAll {
|
|
62
62
|
if (this._content?.elements) {
|
|
63
63
|
return this._content.elements?.map((element) => {
|
|
64
|
-
if (
|
|
65
|
-
// $FlowIssue[prop-missing]
|
|
64
|
+
if (element.propertyElement) {
|
|
66
65
|
const { label, layouthint, properties } = element.propertyElement;
|
|
67
66
|
|
|
68
67
|
return {
|
|
@@ -74,9 +73,8 @@ class AttributeContent {
|
|
|
74
73
|
};
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
if (
|
|
76
|
+
if (element.textFragmentElement) {
|
|
78
77
|
const { label, layouthint, textfragments } =
|
|
79
|
-
// $FlowIssue[prop-missing]
|
|
80
78
|
element.textFragmentElement;
|
|
81
79
|
return {
|
|
82
80
|
textFragmentElement: {
|
|
@@ -90,8 +88,7 @@ class AttributeContent {
|
|
|
90
88
|
};
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
if (
|
|
94
|
-
// $FlowIssue[prop-missing]
|
|
91
|
+
if (element.contentElement) {
|
|
95
92
|
const { label, layouthint, sections } = element.contentElement;
|
|
96
93
|
return {
|
|
97
94
|
contentElement: {
|
package/src/models/href/Href.js
CHANGED
|
@@ -366,9 +366,20 @@ class Href {
|
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
/**
|
|
369
|
-
* Getting the URL including the base path
|
|
369
|
+
* Getting the URL including the base path, querystring is prefixed
|
|
370
370
|
*/
|
|
371
371
|
get absolutehref(): string {
|
|
372
|
+
const querystring = this.getQuerystring(false);
|
|
373
|
+
|
|
374
|
+
return querystring.length > 0
|
|
375
|
+
? [this.absolutepath, querystring].join("?")
|
|
376
|
+
: this.absolutepath;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Getting the URL including the base path, the querystring is prefixed
|
|
381
|
+
*/
|
|
382
|
+
get absolutehrefPrefixedQuerystring(): string {
|
|
372
383
|
const querystring = this.getQuerystring(true);
|
|
373
384
|
|
|
374
385
|
return querystring.length > 0
|
|
@@ -10,6 +10,7 @@ import { CHANGEPASSWORD_PATH } from "../../constants/Constants";
|
|
|
10
10
|
|
|
11
11
|
import type {
|
|
12
12
|
LoginFailedAction,
|
|
13
|
+
ResetAuthErrorsAction,
|
|
13
14
|
LoginSuccessAction,
|
|
14
15
|
ThunkAction,
|
|
15
16
|
} from "../types";
|
|
@@ -22,6 +23,13 @@ export const loginFailed = (errorMessage: string): LoginFailedAction => ({
|
|
|
22
23
|
payload: errorMessage,
|
|
23
24
|
});
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Resets any authentication errors
|
|
28
|
+
*/
|
|
29
|
+
export const resetAuthErrors = (): ResetAuthErrorsAction => ({
|
|
30
|
+
type: "AUTHENTICATION_RESET_ERRORS",
|
|
31
|
+
});
|
|
32
|
+
|
|
25
33
|
/**
|
|
26
34
|
* Send login success action
|
|
27
35
|
*/
|
|
@@ -34,6 +34,9 @@ const AuthReducer: Reducer<AuthState, ReduxAction> = (
|
|
|
34
34
|
case "AUTHENTICATION_ERROR":
|
|
35
35
|
return { ...state, mustChangePassword: false, error: action.payload };
|
|
36
36
|
|
|
37
|
+
case "AUTHENTICATION_RESET_ERRORS":
|
|
38
|
+
return { ...state, error: null };
|
|
39
|
+
|
|
37
40
|
case "AUTHENTICATION_LOGOUT": {
|
|
38
41
|
// clear cache because of cached contributions
|
|
39
42
|
if (state.isAuthenticated) {
|
|
@@ -17,9 +17,12 @@ describe("authentication reducer", () => {
|
|
|
17
17
|
|
|
18
18
|
it("should handle AUTHENTICATION_SUCCESS", () => {
|
|
19
19
|
expect(
|
|
20
|
-
AuthReducer(
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
AuthReducer(
|
|
21
|
+
{},
|
|
22
|
+
{
|
|
23
|
+
type: "AUTHENTICATION_SUCCESS",
|
|
24
|
+
}
|
|
25
|
+
)
|
|
23
26
|
).toStrictEqual({
|
|
24
27
|
isAuthenticated: true,
|
|
25
28
|
mustChangePassword: false,
|
|
@@ -29,10 +32,13 @@ describe("authentication reducer", () => {
|
|
|
29
32
|
|
|
30
33
|
it("should handle AUTHENTICATION_ERROR", () => {
|
|
31
34
|
expect(
|
|
32
|
-
AuthReducer(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
AuthReducer(
|
|
36
|
+
{},
|
|
37
|
+
{
|
|
38
|
+
type: "AUTHENTICATION_ERROR",
|
|
39
|
+
payload: "error",
|
|
40
|
+
}
|
|
41
|
+
)
|
|
36
42
|
).toStrictEqual({
|
|
37
43
|
mustChangePassword: false,
|
|
38
44
|
error: "error",
|
|
@@ -41,9 +47,35 @@ describe("authentication reducer", () => {
|
|
|
41
47
|
|
|
42
48
|
it("should handle AUTHENTICATION_LOGOUT", () => {
|
|
43
49
|
expect(
|
|
44
|
-
AuthReducer(
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
AuthReducer(
|
|
51
|
+
{
|
|
52
|
+
isAuthenticated: true,
|
|
53
|
+
mustChangePassword: false,
|
|
54
|
+
error: null,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "AUTHENTICATION_LOGOUT",
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
).toStrictEqual({
|
|
61
|
+
isAuthenticated: false,
|
|
62
|
+
mustChangePassword: false,
|
|
63
|
+
error: null,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should handle AUTHENTICATION_RESET_ERRORS", () => {
|
|
68
|
+
expect(
|
|
69
|
+
AuthReducer(
|
|
70
|
+
{
|
|
71
|
+
isAuthenticated: false,
|
|
72
|
+
mustChangePassword: false,
|
|
73
|
+
error: "In error",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: "AUTHENTICATION_RESET_ERRORS",
|
|
77
|
+
}
|
|
78
|
+
)
|
|
47
79
|
).toStrictEqual({
|
|
48
80
|
isAuthenticated: false,
|
|
49
81
|
mustChangePassword: false,
|
|
@@ -53,9 +85,16 @@ describe("authentication reducer", () => {
|
|
|
53
85
|
|
|
54
86
|
it("should handle CHANGE_PASSWORD", () => {
|
|
55
87
|
expect(
|
|
56
|
-
AuthReducer(
|
|
57
|
-
|
|
58
|
-
|
|
88
|
+
AuthReducer(
|
|
89
|
+
{
|
|
90
|
+
isAuthenticated: true,
|
|
91
|
+
mustChangePassword: false,
|
|
92
|
+
error: null,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
type: "CHANGE_PASSWORD",
|
|
96
|
+
}
|
|
97
|
+
)
|
|
59
98
|
).toStrictEqual({
|
|
60
99
|
isAuthenticated: true,
|
|
61
100
|
mustChangePassword: true,
|
package/src/redux/types.js
CHANGED
|
@@ -104,6 +104,10 @@ export type LoginFailedAction = {
|
|
|
104
104
|
payload: string,
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
+
export type ResetAuthErrorsAction = {
|
|
108
|
+
type: "AUTHENTICATION_RESET_ERRORS",
|
|
109
|
+
};
|
|
110
|
+
|
|
107
111
|
export type LoginSuccessAction = {
|
|
108
112
|
type: "AUTHENTICATION_SUCCESS",
|
|
109
113
|
};
|
|
@@ -143,6 +147,7 @@ export type ReduxAction =
|
|
|
143
147
|
| ResetProgressAction
|
|
144
148
|
| UpdateProgressAction
|
|
145
149
|
| LoginFailedAction
|
|
150
|
+
| ResetAuthErrorsAction
|
|
146
151
|
| LoginSuccessAction
|
|
147
152
|
| ChangePasswordAction
|
|
148
153
|
| LogoutSuccessAction
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resourceExists,
|
|
3
|
+
resourceRedirectsToSecureLogin,
|
|
4
|
+
} from "../checkResource";
|
|
5
|
+
|
|
6
|
+
import Href from "../../../models/href/Href";
|
|
7
|
+
|
|
8
|
+
const mockXMLHttpRequest = () => {
|
|
9
|
+
const mock = {
|
|
10
|
+
open: jest.fn(),
|
|
11
|
+
addEventListener: jest.fn(),
|
|
12
|
+
setRequestHeader: jest.fn(),
|
|
13
|
+
send: jest.fn(),
|
|
14
|
+
getResponseHeader: jest.fn(),
|
|
15
|
+
|
|
16
|
+
upload: {
|
|
17
|
+
addEventListener: jest.fn(),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
jest.spyOn(global, "XMLHttpRequest").mockImplementation(() => mock);
|
|
22
|
+
|
|
23
|
+
return mock;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe("checkResource", () => {
|
|
27
|
+
it("indicates a resource exists if it has a status code other then 404", () => {
|
|
28
|
+
const mock = mockXMLHttpRequest();
|
|
29
|
+
mock.status = 200;
|
|
30
|
+
|
|
31
|
+
const exists = resourceExists("/");
|
|
32
|
+
expect(exists).toBe(true);
|
|
33
|
+
|
|
34
|
+
const hrefExists = resourceExists(new Href("/caseview"));
|
|
35
|
+
expect(hrefExists).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("indicates a resource does not exists if it has a status code of 404", () => {
|
|
39
|
+
const mock = mockXMLHttpRequest();
|
|
40
|
+
mock.status = 404;
|
|
41
|
+
|
|
42
|
+
const exists = resourceExists("/");
|
|
43
|
+
expect(exists).toBe(false);
|
|
44
|
+
|
|
45
|
+
const hrefExists = resourceExists(new Href("/caseview"));
|
|
46
|
+
expect(hrefExists).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("indicates resource request redirects to secureLogin", () => {
|
|
50
|
+
const mock = mockXMLHttpRequest();
|
|
51
|
+
mock.responseURL = "/BeInformed/secureLogin";
|
|
52
|
+
mock.status = 400;
|
|
53
|
+
|
|
54
|
+
const toLogin = resourceRedirectsToSecureLogin("/");
|
|
55
|
+
expect(toLogin).toBe(true);
|
|
56
|
+
|
|
57
|
+
const hrefToLogin = resourceExists(new Href("/caseview"));
|
|
58
|
+
expect(hrefToLogin).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import Href from "../../models/href/Href";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)
|
|
6
|
+
* When the resource returns a 404, the resource does not exists and the method returns false
|
|
7
|
+
*
|
|
8
|
+
* @param url
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export const resourceExists = (url: string | Href): boolean => {
|
|
12
|
+
const fullUrl = new Href(url).absolutehref;
|
|
13
|
+
|
|
14
|
+
// const fullUrl = `${BASE}/${url}`.replace(/\/\//g, "/");
|
|
15
|
+
|
|
16
|
+
const xhr = new XMLHttpRequest();
|
|
17
|
+
xhr.open("HEAD", fullUrl, false);
|
|
18
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
19
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
20
|
+
xhr.send();
|
|
21
|
+
|
|
22
|
+
return xhr.status !== 404;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Indicates if a request to the given url resuls in a redirect to /secureRedirect
|
|
27
|
+
* @param url
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export const resourceRedirectsToSecureLogin = (url: string | Href): boolean => {
|
|
31
|
+
const fullUrl = new Href(url).absolutehref;
|
|
32
|
+
|
|
33
|
+
const xhr = new XMLHttpRequest();
|
|
34
|
+
xhr.open("HEAD", fullUrl, false);
|
|
35
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
36
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
37
|
+
xhr.send();
|
|
38
|
+
|
|
39
|
+
const responseURL = xhr.responseURL ?? "";
|
|
40
|
+
|
|
41
|
+
return xhr.status === 400 && responseURL.endsWith("/secureLogin");
|
|
42
|
+
};
|
package/src/utils/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export { default as createUUID } from "./helpers/createUUID";
|
|
|
19
19
|
export * from "./helpers/sanitizeHtml";
|
|
20
20
|
export * from "./helpers/objects";
|
|
21
21
|
export * from "./helpers/text";
|
|
22
|
-
export * from "./helpers/
|
|
22
|
+
export * from "./helpers/checkResource";
|
|
23
23
|
|
|
24
24
|
// number
|
|
25
25
|
export { default as DecimalFormat } from "./number/DecimalFormat";
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
2
|
-
import { BASE } from "../../constants/Constants";
|
|
3
|
-
/**
|
|
4
|
-
* Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)
|
|
5
|
-
* When the resource returns a 404, the resource does not exists and the method returns false
|
|
6
|
-
*
|
|
7
|
-
* @param url
|
|
8
|
-
* @returns {boolean}
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export var resourceExists = function resourceExists(url) {
|
|
12
|
-
var _context;
|
|
13
|
-
|
|
14
|
-
var fullUrl = _concatInstanceProperty(_context = "".concat(BASE, "/")).call(_context, url).replace(/\/\//g, "/");
|
|
15
|
-
|
|
16
|
-
var xhr = new XMLHttpRequest();
|
|
17
|
-
xhr.open("HEAD", fullUrl, false);
|
|
18
|
-
xhr.setRequestHeader("Accept", "application/json");
|
|
19
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
20
|
-
xhr.send();
|
|
21
|
-
return xhr.status !== 404;
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=checkResourceExists.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/helpers/checkResourceExists.js"],"names":["BASE","resourceExists","url","fullUrl","replace","xhr","XMLHttpRequest","open","setRequestHeader","send","status"],"mappings":";AACA,SAASA,IAAT,QAAqB,2BAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACC,GAAD,EAA0B;AAAA;;AACtD,MAAMC,OAAO,GAAG,6CAAGH,IAAH,uBAAWE,GAAX,EAAiBE,OAAjB,CAAyB,OAAzB,EAAkC,GAAlC,CAAhB;;AAEA,MAAMC,GAAG,GAAG,IAAIC,cAAJ,EAAZ;AACAD,EAAAA,GAAG,CAACE,IAAJ,CAAS,MAAT,EAAiBJ,OAAjB,EAA0B,KAA1B;AACAE,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,QAArB,EAA+B,kBAA/B;AACAH,EAAAA,GAAG,CAACG,gBAAJ,CAAqB,cAArB,EAAqC,kBAArC;AACAH,EAAAA,GAAG,CAACI,IAAJ;AAEA,SAAOJ,GAAG,CAACK,MAAJ,KAAe,GAAtB;AACD,CAVM","sourcesContent":["// @flow\nimport { BASE } from \"../../constants/Constants\";\n\n/**\n * Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)\n * When the resource returns a 404, the resource does not exists and the method returns false\n *\n * @param url\n * @returns {boolean}\n */\nexport const resourceExists = (url: string): boolean => {\n const fullUrl = `${BASE}/${url}`.replace(/\\/\\//g, \"/\");\n\n const xhr = new XMLHttpRequest();\n xhr.open(\"HEAD\", fullUrl, false);\n xhr.setRequestHeader(\"Accept\", \"application/json\");\n xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n xhr.send();\n\n return xhr.status !== 404;\n};\n"],"file":"checkResourceExists.js"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.resourceExists = void 0;
|
|
9
|
-
|
|
10
|
-
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
11
|
-
|
|
12
|
-
var _Constants = require("../../constants/Constants");
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)
|
|
16
|
-
* When the resource returns a 404, the resource does not exists and the method returns false
|
|
17
|
-
*
|
|
18
|
-
* @param url
|
|
19
|
-
* @returns {boolean}
|
|
20
|
-
*/
|
|
21
|
-
var resourceExists = function resourceExists(url) {
|
|
22
|
-
var _context;
|
|
23
|
-
|
|
24
|
-
var fullUrl = (0, _concat.default)(_context = "".concat(_Constants.BASE, "/")).call(_context, url).replace(/\/\//g, "/");
|
|
25
|
-
var xhr = new XMLHttpRequest();
|
|
26
|
-
xhr.open("HEAD", fullUrl, false);
|
|
27
|
-
xhr.setRequestHeader("Accept", "application/json");
|
|
28
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
29
|
-
xhr.send();
|
|
30
|
-
return xhr.status !== 404;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
exports.resourceExists = resourceExists;
|
|
34
|
-
//# sourceMappingURL=checkResourceExists.js.map
|