@beinformed/ui 1.15.1 → 1.16.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/esm/hooks/useAuthentication.js +4 -1
  3. package/esm/hooks/useAuthentication.js.map +1 -1
  4. package/esm/models/attributes/AttributeContent.js +4 -4
  5. package/esm/models/attributes/AttributeContent.js.map +1 -1
  6. package/esm/redux/actions/SignIn.js +9 -0
  7. package/esm/redux/actions/SignIn.js.map +1 -1
  8. package/esm/redux/reducers/AuthReducer.js +5 -0
  9. package/esm/redux/reducers/AuthReducer.js.map +1 -1
  10. package/esm/utils/helpers/checkResource.js +43 -0
  11. package/esm/utils/helpers/checkResource.js.map +1 -0
  12. package/esm/utils/index.js +1 -1
  13. package/esm/utils/index.js.map +1 -1
  14. package/lib/hooks/useAuthentication.js +3 -0
  15. package/lib/hooks/useAuthentication.js.flow +7 -5
  16. package/lib/hooks/useAuthentication.js.map +1 -1
  17. package/lib/models/attributes/AttributeContent.js +4 -4
  18. package/lib/models/attributes/AttributeContent.js.flow +3 -3
  19. package/lib/models/attributes/AttributeContent.js.map +1 -1
  20. package/lib/redux/actions/SignIn.js +14 -2
  21. package/lib/redux/actions/SignIn.js.flow +8 -0
  22. package/lib/redux/actions/SignIn.js.map +1 -1
  23. package/lib/redux/reducers/AuthReducer.js +5 -0
  24. package/lib/redux/reducers/AuthReducer.js.flow +3 -0
  25. package/lib/redux/reducers/AuthReducer.js.map +1 -1
  26. package/lib/redux/reducers/__tests__/AuthReducer.spec.js.flow +52 -13
  27. package/lib/redux/types.js.flow +5 -0
  28. package/lib/utils/helpers/__tests__/checkResource.spec.js.flow +56 -0
  29. package/lib/utils/helpers/checkResource.js +57 -0
  30. package/{src/utils/helpers/checkResourceExists.js → lib/utils/helpers/checkResource.js.flow} +19 -0
  31. package/lib/utils/helpers/checkResource.js.map +1 -0
  32. package/lib/utils/index.js +4 -4
  33. package/lib/utils/index.js.flow +1 -1
  34. package/lib/utils/index.js.map +1 -1
  35. package/package.json +7 -7
  36. package/src/hooks/useAuthentication.js +7 -5
  37. package/src/models/attributes/AttributeContent.js +3 -3
  38. package/src/redux/actions/SignIn.js +8 -0
  39. package/src/redux/reducers/AuthReducer.js +3 -0
  40. package/src/redux/reducers/__tests__/AuthReducer.spec.js +52 -13
  41. package/src/redux/types.js +5 -0
  42. package/src/utils/helpers/__tests__/checkResource.spec.js +56 -0
  43. package/{lib/utils/helpers/checkResourceExists.js.flow → src/utils/helpers/checkResource.js} +19 -0
  44. package/src/utils/index.js +1 -1
  45. package/esm/utils/helpers/checkResourceExists.js +0 -23
  46. package/esm/utils/helpers/checkResourceExists.js.map +0 -1
  47. package/lib/utils/helpers/checkResourceExists.js +0 -34
  48. package/lib/utils/helpers/checkResourceExists.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/redux/reducers/AuthReducer.js"],"names":["initialState","isAuthenticated","mustChangePassword","error","AuthReducer","state","action","type","payload","Cache","clear"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;AAKA;AACA,IAAMA,YAAuB,GAAG;AAC9BC,EAAAA,eAAe,EAAE,KADa;AAE9BC,EAAAA,kBAAkB,EAAE,KAFU;AAG9BC,EAAAA,KAAK,EAAE;AAHuB,CAAhC;AAMA;AACA;AACA;;AACA,IAAMC,WAA4C,GAAG,SAA/CA,WAA+C,GAGhD;AAAA,MAFHC,KAEG,uEAFKL,YAEL;AAAA,MADHM,MACG;;AACH,MAAI,CAACA,MAAL,EAAa;AACX,WAAOD,KAAP;AACD;;AAED,UAAQC,MAAM,CAACC,IAAf;AACE,SAAK,wBAAL;AACE,6CACKF,KADL;AAEEJ,QAAAA,eAAe,EAAE,IAFnB;AAGEE,QAAAA,KAAK,EAAE,IAHT;AAIED,QAAAA,kBAAkB,EAAE;AAJtB;;AAOF,SAAK,sBAAL;AACE,6CAAYG,KAAZ;AAAmBH,QAAAA,kBAAkB,EAAE,KAAvC;AAA8CC,QAAAA,KAAK,EAAEG,MAAM,CAACE;AAA5D;;AAEF,SAAK,uBAAL;AAA8B;AAC5B;AACA,YAAIH,KAAK,CAACJ,eAAV,EAA2B;AACzBQ,yBAAMC,KAAN;AACD;;AAED,+CACKL,KADL;AAEEH,UAAAA,kBAAkB,EAAE,KAFtB;AAGED,UAAAA,eAAe,EAAE,KAHnB;AAIEE,UAAAA,KAAK,EAAE;AAJT;AAMD;;AAED,SAAK,iBAAL;AACE,6CACKE,KADL;AAEEJ,QAAAA,eAAe,EAAE,IAFnB;AAGEC,QAAAA,kBAAkB,EAAE,IAHtB;AAIEC,QAAAA,KAAK,EAAE;AAJT;;AAOF;AACE,aAAOE,KAAP;AAnCJ;AAqCD,CA7CD;;eA+CeD,W","sourcesContent":["// @flow\nimport Cache from \"../../utils/browser/Cache\";\n\nimport type { Reducer } from \"redux\";\nimport type { AuthState, ReduxAction } from \"../types\";\n\n// REDUCER\nconst initialState: AuthState = {\n isAuthenticated: false,\n mustChangePassword: false,\n error: null,\n};\n\n/**\n * Auth reducer\n */\nconst AuthReducer: Reducer<AuthState, ReduxAction> = (\n state = initialState,\n action\n) => {\n if (!action) {\n return state;\n }\n\n switch (action.type) {\n case \"AUTHENTICATION_SUCCESS\":\n return {\n ...state,\n isAuthenticated: true,\n error: null,\n mustChangePassword: false,\n };\n\n case \"AUTHENTICATION_ERROR\":\n return { ...state, mustChangePassword: false, error: action.payload };\n\n case \"AUTHENTICATION_LOGOUT\": {\n // clear cache because of cached contributions\n if (state.isAuthenticated) {\n Cache.clear();\n }\n\n return {\n ...state,\n mustChangePassword: false,\n isAuthenticated: false,\n error: null,\n };\n }\n\n case \"CHANGE_PASSWORD\":\n return {\n ...state,\n isAuthenticated: true,\n mustChangePassword: true,\n error: null,\n };\n\n default:\n return state;\n }\n};\n\nexport default AuthReducer;\n"],"file":"AuthReducer.js"}
1
+ {"version":3,"sources":["../../../src/redux/reducers/AuthReducer.js"],"names":["initialState","isAuthenticated","mustChangePassword","error","AuthReducer","state","action","type","payload","Cache","clear"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;AAKA;AACA,IAAMA,YAAuB,GAAG;AAC9BC,EAAAA,eAAe,EAAE,KADa;AAE9BC,EAAAA,kBAAkB,EAAE,KAFU;AAG9BC,EAAAA,KAAK,EAAE;AAHuB,CAAhC;AAMA;AACA;AACA;;AACA,IAAMC,WAA4C,GAAG,SAA/CA,WAA+C,GAGhD;AAAA,MAFHC,KAEG,uEAFKL,YAEL;AAAA,MADHM,MACG;;AACH,MAAI,CAACA,MAAL,EAAa;AACX,WAAOD,KAAP;AACD;;AAED,UAAQC,MAAM,CAACC,IAAf;AACE,SAAK,wBAAL;AACE,6CACKF,KADL;AAEEJ,QAAAA,eAAe,EAAE,IAFnB;AAGEE,QAAAA,KAAK,EAAE,IAHT;AAIED,QAAAA,kBAAkB,EAAE;AAJtB;;AAOF,SAAK,sBAAL;AACE,6CAAYG,KAAZ;AAAmBH,QAAAA,kBAAkB,EAAE,KAAvC;AAA8CC,QAAAA,KAAK,EAAEG,MAAM,CAACE;AAA5D;;AAEF,SAAK,6BAAL;AACE,6CAAYH,KAAZ;AAAmBF,QAAAA,KAAK,EAAE;AAA1B;;AAEF,SAAK,uBAAL;AAA8B;AAC5B;AACA,YAAIE,KAAK,CAACJ,eAAV,EAA2B;AACzBQ,yBAAMC,KAAN;AACD;;AAED,+CACKL,KADL;AAEEH,UAAAA,kBAAkB,EAAE,KAFtB;AAGED,UAAAA,eAAe,EAAE,KAHnB;AAIEE,UAAAA,KAAK,EAAE;AAJT;AAMD;;AAED,SAAK,iBAAL;AACE,6CACKE,KADL;AAEEJ,QAAAA,eAAe,EAAE,IAFnB;AAGEC,QAAAA,kBAAkB,EAAE,IAHtB;AAIEC,QAAAA,KAAK,EAAE;AAJT;;AAOF;AACE,aAAOE,KAAP;AAtCJ;AAwCD,CAhDD;;eAkDeD,W","sourcesContent":["// @flow\nimport Cache from \"../../utils/browser/Cache\";\n\nimport type { Reducer } from \"redux\";\nimport type { AuthState, ReduxAction } from \"../types\";\n\n// REDUCER\nconst initialState: AuthState = {\n isAuthenticated: false,\n mustChangePassword: false,\n error: null,\n};\n\n/**\n * Auth reducer\n */\nconst AuthReducer: Reducer<AuthState, ReduxAction> = (\n state = initialState,\n action\n) => {\n if (!action) {\n return state;\n }\n\n switch (action.type) {\n case \"AUTHENTICATION_SUCCESS\":\n return {\n ...state,\n isAuthenticated: true,\n error: null,\n mustChangePassword: false,\n };\n\n case \"AUTHENTICATION_ERROR\":\n return { ...state, mustChangePassword: false, error: action.payload };\n\n case \"AUTHENTICATION_RESET_ERRORS\":\n return { ...state, error: null };\n\n case \"AUTHENTICATION_LOGOUT\": {\n // clear cache because of cached contributions\n if (state.isAuthenticated) {\n Cache.clear();\n }\n\n return {\n ...state,\n mustChangePassword: false,\n isAuthenticated: false,\n error: null,\n };\n }\n\n case \"CHANGE_PASSWORD\":\n return {\n ...state,\n isAuthenticated: true,\n mustChangePassword: true,\n error: null,\n };\n\n default:\n return state;\n }\n};\n\nexport default AuthReducer;\n"],"file":"AuthReducer.js"}
@@ -17,9 +17,12 @@ describe("authentication reducer", () => {
17
17
 
18
18
  it("should handle AUTHENTICATION_SUCCESS", () => {
19
19
  expect(
20
- AuthReducer([], {
21
- type: "AUTHENTICATION_SUCCESS",
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
- type: "AUTHENTICATION_ERROR",
34
- payload: "error",
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
- type: "AUTHENTICATION_LOGOUT",
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
- type: "CHANGE_PASSWORD",
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,
@@ -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
+ });
@@ -0,0 +1,57 @@
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 _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
11
+
12
+ var _endsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/ends-with"));
13
+
14
+ var _Constants = require("../../constants/Constants");
15
+
16
+ /**
17
+ * Checks if a given url to a modular ui resource exists using a HEAD request to the resource (synchronous)
18
+ * When the resource returns a 404, the resource does not exists and the method returns false
19
+ *
20
+ * @param url
21
+ * @returns {boolean}
22
+ */
23
+ var resourceExists = function resourceExists(url) {
24
+ var _context;
25
+
26
+ var fullUrl = (0, _concat.default)(_context = "".concat(_Constants.BASE, "/")).call(_context, url).replace(/\/\//g, "/");
27
+ var xhr = new XMLHttpRequest();
28
+ xhr.open("HEAD", fullUrl, false);
29
+ xhr.setRequestHeader("Accept", "application/json");
30
+ xhr.setRequestHeader("Content-Type", "application/json");
31
+ xhr.send();
32
+ return xhr.status !== 404;
33
+ };
34
+ /**
35
+ * Indicates if a request to the given url resuls in a redirect to /secureRedirect
36
+ * @param url
37
+ * @returns {boolean}
38
+ */
39
+
40
+
41
+ exports.resourceExists = resourceExists;
42
+
43
+ var resourceRedirectsToSecureLogin = function resourceRedirectsToSecureLogin(url) {
44
+ var _context2, _xhr$responseURL;
45
+
46
+ var fullUrl = (0, _concat.default)(_context2 = "".concat(_Constants.BASE, "/")).call(_context2, url).replace(/\/\//g, "/");
47
+ var xhr = new XMLHttpRequest();
48
+ xhr.open("HEAD", fullUrl, false);
49
+ xhr.setRequestHeader("Accept", "application/json");
50
+ xhr.setRequestHeader("Content-Type", "application/json");
51
+ xhr.send();
52
+ var responseURL = (_xhr$responseURL = xhr.responseURL) !== null && _xhr$responseURL !== void 0 ? _xhr$responseURL : "";
53
+ return xhr.status === 400 && (0, _endsWith.default)(responseURL).call(responseURL, "/secureLogin");
54
+ };
55
+
56
+ exports.resourceRedirectsToSecureLogin = resourceRedirectsToSecureLogin;
57
+ //# sourceMappingURL=checkResource.js.map
@@ -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
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/helpers/checkResource.js"],"names":["resourceExists","url","fullUrl","BASE","replace","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,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;AAYP;AACA;AACA;AACA;AACA;;;;;AACO,IAAMC,8BAA8B,GAAG,SAAjCA,8BAAiC,CAACV,GAAD,EAA0B;AAAA;;AACtE,MAAMC,OAAO,GAAG,2CAAGC,eAAH,wBAAWF,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,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 { 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\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): 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 const responseURL = xhr.responseURL ?? \"\";\n\n return xhr.status === 400 && responseURL.endsWith(\"/secureLogin\");\n};\n"],"file":"checkResource.js"}
@@ -153,16 +153,16 @@ _Object$keys(_text).forEach(function (key) {
153
153
  });
154
154
  });
155
155
 
156
- var _checkResourceExists = require("./helpers/checkResourceExists");
156
+ var _checkResource = require("./helpers/checkResource");
157
157
 
158
- _Object$keys(_checkResourceExists).forEach(function (key) {
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] === _checkResourceExists[key]) return;
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 _checkResourceExists[key];
165
+ return _checkResource[key];
166
166
  }
167
167
  });
168
168
  });
@@ -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/checkResourceExists";
22
+ export * from "./helpers/checkResource";
23
23
 
24
24
  // number
25
25
  export { default as DecimalFormat } from "./number/DecimalFormat";
@@ -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/checkResourceExists\";\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"}
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.15.1",
3
+ "version": "1.16.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.2",
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.5",
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",
@@ -118,11 +118,11 @@
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.1",
122
- "eslint-plugin-jsdoc": "^38.0.4",
121
+ "eslint-plugin-jest": "^26.1.2",
122
+ "eslint-plugin-jsdoc": "^38.0.6",
123
123
  "eslint-plugin-react": "^7.28.0",
124
124
  "eslint-plugin-react-hooks": "^4.3.0",
125
- "flow-bin": "^0.173.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,7 +132,7 @@
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.6",
135
+ "lint-staged": "^12.3.7",
136
136
  "polished": "^4.1.4",
137
137
  "prettier": "^2.6.0",
138
138
  "react": "^17.0.2",
@@ -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
- return dispatch(logout()).then(() => {
72
+ logout: () =>
73
+ dispatch(logout()).then(() => {
71
74
  if (!cancel) {
72
75
  setIsAuthenticated(false);
73
76
  }
74
- });
75
- },
77
+ }),
76
78
  };
77
79
  };
@@ -62,7 +62,7 @@ class AttributeContent {
62
62
  if (this._content?.elements) {
63
63
  return this._content.elements?.map((element) => {
64
64
  if ("propertyElement" in element) {
65
- // $FlowIssue[prop-missing]
65
+ // $FlowIssue[incompatible-use]
66
66
  const { label, layouthint, properties } = element.propertyElement;
67
67
 
68
68
  return {
@@ -75,8 +75,8 @@ class AttributeContent {
75
75
  }
76
76
 
77
77
  if ("textFragmentElement" in element) {
78
+ // $FlowIssue[incompatible-use]
78
79
  const { label, layouthint, textfragments } =
79
- // $FlowIssue[prop-missing]
80
80
  element.textFragmentElement;
81
81
  return {
82
82
  textFragmentElement: {
@@ -91,7 +91,7 @@ class AttributeContent {
91
91
  }
92
92
 
93
93
  if ("contentElement" in element) {
94
- // $FlowIssue[prop-missing]
94
+ // $FlowIssue[incompatible-use]
95
95
  const { label, layouthint, sections } = element.contentElement;
96
96
  return {
97
97
  contentElement: {
@@ -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
- type: "AUTHENTICATION_SUCCESS",
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
- type: "AUTHENTICATION_ERROR",
34
- payload: "error",
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
- type: "AUTHENTICATION_LOGOUT",
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
- type: "CHANGE_PASSWORD",
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,
@@ -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
+ });
@@ -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
+ };
@@ -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/checkResourceExists";
22
+ export * from "./helpers/checkResource";
23
23
 
24
24
  // number
25
25
  export { default as DecimalFormat } from "./number/DecimalFormat";