@beinformed/ui 1.15.0 → 1.16.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 +15 -0
- package/esm/hooks/useAuthentication.js +4 -1
- package/esm/hooks/useAuthentication.js.map +1 -1
- package/esm/models/attributes/AttributeContent.js +4 -7
- package/esm/models/attributes/AttributeContent.js.map +1 -1
- package/esm/redux/actions/FormAttributeSet.js +4 -0
- package/esm/redux/actions/FormAttributeSet.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 +43 -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/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/redux/actions/FormAttributeSet.js +4 -0
- package/lib/redux/actions/FormAttributeSet.js.flow +4 -0
- package/lib/redux/actions/FormAttributeSet.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 +56 -0
- package/lib/utils/helpers/checkResource.js +57 -0
- package/{src/utils/helpers/checkResourceExists.js → lib/utils/helpers/checkResource.js.flow} +19 -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 +7 -7
- package/src/hooks/useAuthentication.js +7 -5
- package/src/models/attributes/AttributeContent.js +3 -6
- package/src/redux/actions/FormAttributeSet.js +4 -0
- 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 +56 -0
- package/{lib/utils/helpers/checkResourceExists.js.flow → src/utils/helpers/checkResource.js} +19 -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.map +0 -1
|
@@ -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,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resourceExists,
|
|
3
|
+
resourceRedirectsToSecureLogin,
|
|
4
|
+
} from "../checkResource";
|
|
5
|
+
|
|
6
|
+
const mockXMLHttpRequest = () => {
|
|
7
|
+
const mock = {
|
|
8
|
+
open: jest.fn(),
|
|
9
|
+
addEventListener: jest.fn(),
|
|
10
|
+
setRequestHeader: jest.fn(),
|
|
11
|
+
send: jest.fn(),
|
|
12
|
+
getResponseHeader: jest.fn(),
|
|
13
|
+
|
|
14
|
+
upload: {
|
|
15
|
+
addEventListener: jest.fn(),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
jest.spyOn(global, "XMLHttpRequest").mockImplementation(() => mock);
|
|
20
|
+
|
|
21
|
+
return mock;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe("checkResource", () => {
|
|
25
|
+
it("indicates a resource exists if it has a status code other then 404", () => {
|
|
26
|
+
const mock = mockXMLHttpRequest();
|
|
27
|
+
mock.status = 200;
|
|
28
|
+
|
|
29
|
+
expect.assertions(1);
|
|
30
|
+
|
|
31
|
+
const exists = resourceExists("/");
|
|
32
|
+
|
|
33
|
+
expect(exists).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("indicates a resource does not exists if it has a status code of 404", () => {
|
|
37
|
+
const mock = mockXMLHttpRequest();
|
|
38
|
+
mock.status = 404;
|
|
39
|
+
|
|
40
|
+
expect.assertions(1);
|
|
41
|
+
|
|
42
|
+
const exists = resourceExists("/");
|
|
43
|
+
|
|
44
|
+
expect(exists).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("indicates resource request redirects to secureLogin", () => {
|
|
48
|
+
const mock = mockXMLHttpRequest();
|
|
49
|
+
mock.responseURL = "/BeInformed/secureLogin";
|
|
50
|
+
mock.status = 400;
|
|
51
|
+
|
|
52
|
+
const toLogin = resourceRedirectsToSecureLogin("/");
|
|
53
|
+
|
|
54
|
+
expect(toLogin).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
});
|
package/{lib/utils/helpers/checkResourceExists.js.flow → src/utils/helpers/checkResource.js}
RENAMED
|
@@ -19,3 +19,22 @@ export const resourceExists = (url: string): boolean => {
|
|
|
19
19
|
|
|
20
20
|
return xhr.status !== 404;
|
|
21
21
|
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Indicates if a request to the given url resuls in a redirect to /secureRedirect
|
|
25
|
+
* @param url
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export const resourceRedirectsToSecureLogin = (url: string): boolean => {
|
|
29
|
+
const fullUrl = `${BASE}/${url}`.replace(/\/\//g, "/");
|
|
30
|
+
|
|
31
|
+
const xhr = new XMLHttpRequest();
|
|
32
|
+
xhr.open("HEAD", fullUrl, false);
|
|
33
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
34
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
35
|
+
xhr.send();
|
|
36
|
+
|
|
37
|
+
const responseURL = xhr.responseURL ?? "";
|
|
38
|
+
|
|
39
|
+
return xhr.status === 400 && responseURL.endsWith("/secureLogin");
|
|
40
|
+
};
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/helpers/checkResourceExists.js"],"names":["resourceExists","url","fullUrl","BASE","replace","xhr","XMLHttpRequest","open","setRequestHeader","send","status"],"mappings":";;;;;;;;;;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAACC,GAAD,EAA0B;AAAA;;AACtD,MAAMC,OAAO,GAAG,0CAAGC,eAAH,uBAAWF,GAAX,EAAiBG,OAAjB,CAAyB,OAAzB,EAAkC,GAAlC,CAAhB;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,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"}
|