@beinformed/ui 1.33.0-beta.7 → 1.34.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 CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [1.34.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0...v1.34.0) (2023-09-13)
6
+
7
+
8
+ ### Features
9
+
10
+ * **redirectUri:** the redirectURI to a secure page is now handled through the UI library ([cc54f8e](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/cc54f8e5d436d2c14e6f50dd3793ac074a8dcc2f))
11
+
12
+ ## [1.33.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0-beta.7...v1.33.0) (2023-08-29)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **filters:** only handle filter formatting on bsn, iban and zip code with exact and not ([4ebe97c](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/4ebe97c593380a9837460eb1ad9bbf26d1c7e106))
18
+ * **sanitize-html:** handle escaped html ([2e9aa73](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/2e9aa730fb9c48ea69cd7d29419e635b6384c723))
19
+
5
20
  ## [1.33.0-beta.7](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.33.0-beta.6...v1.33.0-beta.7) (2023-08-28)
6
21
 
7
22
 
@@ -66,7 +66,7 @@ export default class StringFilterModel extends BaseFilterModel {
66
66
  update(attribute, value) {
67
67
  this._isValid = true;
68
68
  this._inputvalue = typeof value !== "string" ? value.toString() : value;
69
- if (this.operator === "exactly" || this.operator === "isNot") {
69
+ if (this.shouldHandleFormat()) {
70
70
  var _context, _context2;
71
71
  const values = this.isMultiple ? _mapInstanceProperty(_context = this._inputvalue.split(",")).call(_context, val => _trimInstanceProperty(val).call(val)) : [_trimInstanceProperty(_context2 = this._inputvalue).call(_context2)];
72
72
  const outputValues = [];
@@ -94,7 +94,7 @@ export default class StringFilterModel extends BaseFilterModel {
94
94
  /**
95
95
  */
96
96
  formatValue(value) {
97
- if (this.operator === "exactly" || this.operator === "isNot") {
97
+ if (this.shouldHandleFormat()) {
98
98
  return this.attribute.formatValue(value);
99
99
  }
100
100
  return value;
@@ -124,10 +124,16 @@ export default class StringFilterModel extends BaseFilterModel {
124
124
  if (value == null || value.toString() === "") {
125
125
  return "";
126
126
  }
127
- if ((this.operator === "exactly" || this.operator === "isNot") && (this.isIBAN() || this.isZipcode() || this.isBSN())) {
127
+ if (this.shouldHandleFormat()) {
128
128
  return value.replace(/[^a-z0-9,]/gi, "");
129
129
  }
130
130
  return value;
131
131
  }
132
+
133
+ /**
134
+ */
135
+ shouldHandleFormat() {
136
+ return (this.operator === "exactly" || this.operator === "isNot") && (this.isIBAN() || this.isZipcode() || this.isBSN());
137
+ }
132
138
  }
133
139
  //# sourceMappingURL=StringFilterModel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"StringFilterModel.js","names":["BaseFilterModel","StringFilterModel","constructor","data","contributions","_defineProperty","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","operator","_context","_context2","values","isMultiple","_mapInstanceProperty","split","call","val","_trimInstanceProperty","outputValues","formattedValue","formatValue","push","validate","join","getContribution","isBSN","layouthint","has","isIBAN","isZipcode","replace"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.removeFormat(this.value),\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._isValid = true;\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n\n /**\n */\n isBSN(): boolean {\n return this.layouthint.has(\"bsn\");\n }\n\n /**\n */\n isIBAN(): boolean {\n return this.layouthint.has(\"iban\");\n }\n\n /**\n */\n isZipcode(): boolean {\n return this.layouthint.has(\"zipcode\");\n }\n\n /**\n */\n removeFormat(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n if (\n (this.operator === \"exactly\" || this.operator === \"isNot\") &&\n (this.isIBAN() || this.isZipcode() || this.isBSN())\n ) {\n return value.replace(/[^a-z0-9,]/gi, \"\");\n }\n\n return value;\n }\n}\n"],"mappings":";;;AACA,OAAOA,eAAe,MAAM,mBAAmB;AAI/C;AACA;AACA;AACA,eAAe,MAAMC,iBAAiB,SAASD,eAAe,CAAC;EAK7D;AACF;EACEE,WAAWA,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAC/C,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACC,eAAA,mBAPT,IAAI;IAAAA,eAAA;IAAAA,eAAA;IAStB,IAAI,CAACC,MAAM,CAAC,IAAI,CAACC,SAAS,EAAEJ,IAAI,CAACK,KAAK,IAAI,EAAE,CAAC;;IAE7C;IACA,IAAI,CAACC,WAAW,GAAG,IAAI,CAACC,MAAM,IAAI,EAAE;EACtC;;EAEA;AACF;AACA;EACE,IAAIC,MAAMA,CAAA,EAA4C;IACpD,IAAI,CAAC,IAAI,CAACC,KAAK,EAAE;MACf,OAAO,EAAE;IACX;IAEA,OAAO,CACL;MACEC,IAAI,EAAE,IAAI,CAACD,KAAK;MAChBJ,KAAK,EAAE,IAAI,CAACM,YAAY,CAAC,IAAI,CAACN,KAAK;IACrC,CAAC,CACF;EACH;;EAEA;AACF;AACA;EACE,IAAIA,KAAKA,CAAA,EAAkB;IACzB,OAAO,IAAI,CAACE,MAAM;EACpB;;EAEA;AACF;EACE,IAAIK,UAAUA,CAAA,EAAW;IACvB,OAAO,IAAI,CAACN,WAAW;EACzB;;EAEA;AACF;AACA;EACEO,KAAKA,CAAA,EAAe;IAClB,IAAI,CAACP,WAAW,GAAG,EAAE;IACrB,IAAI,CAACC,MAAM,GAAG,IAAI;IAElB,OAAO,IAAI;EACb;;EAEA;AACF;EACE,IAAIO,OAAOA,CAAA,EAAY;IACrB,OAAO,IAAI,CAACC,QAAQ;EACtB;;EAEA;AACF;AACA;EACEZ,MAAMA,CAACC,SAAwB,EAAEC,KAAa,EAAE;IAC9C,IAAI,CAACU,QAAQ,GAAG,IAAI;IACpB,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AS,IAAI,IAAI,CAACA,QAAQ,KAAK,OAAO,EAAE;MAC5D,OAAO,IAAI,CAACb,SAAS,CAACyB,WAAW,CAACxB,KAAK,CAAC;IAC1C;IACA,OAAOA,KAAK;EACd;;EAEA;AACF;EACE6B,KAAKA,CAAA,EAAY;IACf,OAAO,IAAI,CAACC,UAAU,CAACC,GAAG,CAAC,KAAK,CAAC;EACnC;;EAEA;AACF;EACEC,MAAMA,CAAA,EAAY;IAChB,OAAO,IAAI,CAACF,UAAU,CAACC,GAAG,CAAC,MAAM,CAAC;EACpC;;EAEA;AACF;EACEE,SAASA,CAAA,EAAY;IACnB,OAAO,IAAI,CAACH,UAAU,CAACC,GAAG,CAAC,SAAS,CAAC;EACvC;;EAEA;AACF;EACEzB,YAAYA,CAACN,KAAc,EAAU;IACnC,IAAIA,KAAK,IAAI,IAAI,IAAIA,KAAK,CAACW,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;MAC5C,OAAO,EAAE;IACX;IAEA,IACE,CAAC,IAAI,CAACC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAACA,QAAQ,KAAK,OAAO,MACxD,IAAI,CAACoB,MAAM,CAAC,CAAC,IAAI,IAAI,CAACC,SAAS,CAAC,CAAC,IAAI,IAAI,CAACJ,KAAK,CAAC,CAAC,CAAC,EACnD;MACA,OAAO7B,KAAK,CAACkC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;IAC1C;IAEA,OAAOlC,KAAK;EACd;AACF"}
1
+ {"version":3,"file":"StringFilterModel.js","names":["BaseFilterModel","StringFilterModel","constructor","data","contributions","_defineProperty","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","shouldHandleFormat","_context","_context2","values","isMultiple","_mapInstanceProperty","split","call","val","_trimInstanceProperty","outputValues","formattedValue","formatValue","push","validate","join","operator","getContribution","isBSN","layouthint","has","isIBAN","isZipcode","replace"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.removeFormat(this.value),\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._isValid = true;\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.shouldHandleFormat()) {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.shouldHandleFormat()) {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n\n /**\n */\n isBSN(): boolean {\n return this.layouthint.has(\"bsn\");\n }\n\n /**\n */\n isIBAN(): boolean {\n return this.layouthint.has(\"iban\");\n }\n\n /**\n */\n isZipcode(): boolean {\n return this.layouthint.has(\"zipcode\");\n }\n\n /**\n */\n removeFormat(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n if (this.shouldHandleFormat()) {\n return value.replace(/[^a-z0-9,]/gi, \"\");\n }\n\n return value;\n }\n\n /**\n */\n shouldHandleFormat(): boolean {\n return (\n (this.operator === \"exactly\" || this.operator === \"isNot\") &&\n (this.isIBAN() || this.isZipcode() || this.isBSN())\n );\n }\n}\n"],"mappings":";;;AACA,OAAOA,eAAe,MAAM,mBAAmB;AAI/C;AACA;AACA;AACA,eAAe,MAAMC,iBAAiB,SAASD,eAAe,CAAC;EAK7D;AACF;EACEE,WAAWA,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAC/C,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACC,eAAA,mBAPT,IAAI;IAAAA,eAAA;IAAAA,eAAA;IAStB,IAAI,CAACC,MAAM,CAAC,IAAI,CAACC,SAAS,EAAEJ,IAAI,CAACK,KAAK,IAAI,EAAE,CAAC;;IAE7C;IACA,IAAI,CAACC,WAAW,GAAG,IAAI,CAACC,MAAM,IAAI,EAAE;EACtC;;EAEA;AACF;AACA;EACE,IAAIC,MAAMA,CAAA,EAA4C;IACpD,IAAI,CAAC,IAAI,CAACC,KAAK,EAAE;MACf,OAAO,EAAE;IACX;IAEA,OAAO,CACL;MACEC,IAAI,EAAE,IAAI,CAACD,KAAK;MAChBJ,KAAK,EAAE,IAAI,CAACM,YAAY,CAAC,IAAI,CAACN,KAAK;IACrC,CAAC,CACF;EACH;;EAEA;AACF;AACA;EACE,IAAIA,KAAKA,CAAA,EAAkB;IACzB,OAAO,IAAI,CAACE,MAAM;EACpB;;EAEA;AACF;EACE,IAAIK,UAAUA,CAAA,EAAW;IACvB,OAAO,IAAI,CAACN,WAAW;EACzB;;EAEA;AACF;AACA;EACEO,KAAKA,CAAA,EAAe;IAClB,IAAI,CAACP,WAAW,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ceProperty from "@babel/runtime-corejs3/core-js-stable/instance/trim";
2
+ import _URLSearchParams from "@babel/runtime-corejs3/core-js-stable/url-search-params";
2
3
  // eslint-disable-next-line react/no-deprecated
3
4
  import { hydrate, render } from "react-dom";
4
5
  import { has } from "../utils/helpers/objects";
5
6
  import setImmediate from "setimmediate";
6
7
  import Cache from "../utils/browser/Cache";
8
+ import xhr from "../utils/fetch/xhr";
7
9
  import { createBrowserHistory } from "history";
8
10
  import configureStore from "../redux/store/configureStore";
9
11
  import rehydrate from "./rehydrate";
10
- import { getBasePath } from "../constants/Settings";
12
+ import { getBasePath, getSetting } from "../constants/Settings";
11
13
  import { setAllContentInDataSetting, setLoginPreferences } from "../redux/actions/Preferences";
12
14
  import { showXHRErrorNotification } from "../redux/actions/Notification";
13
15
  import { handleError } from "../redux/actions/Error";
14
16
  import { loginSuccess } from "../redux/actions/SignIn";
15
- import { locationChange } from "../redux/_router/RouterActions";
17
+ import { locationChange, replace } from "../redux/_router/RouterActions";
16
18
  import { JsonParseException, FetchException } from "../exceptions";
17
19
  import { Init } from "./Init";
18
20
  import { handleBeforeRenderHooks } from "../redux/store/beforeRenderHooks";
21
+ import UnauthorizedException from "../exceptions/UnauthorizedException";
19
22
  import { jsx as _jsx } from "react/jsx-runtime";
20
23
  /*
21
24
  * deserialize serialized data from the server to provide a smooth dehydration.
@@ -53,6 +56,30 @@ export const setUnhandledRejectionEvent = store => {
53
56
  };
54
57
  };
55
58
 
59
+ /**
60
+ * The redirectURI querystring parameter is available when the server is redirecting an unauthorized deep link
61
+ * @param store
62
+ */
63
+ const handleRedirectURI = store => {
64
+ const urlParams = new _URLSearchParams(window.location.search);
65
+ const redirectURI = urlParams.get("redirectURI");
66
+ if (redirectURI) {
67
+ xhr({
68
+ url: `${getBasePath()}${redirectURI}`
69
+ }).catch(e => {
70
+ if (e instanceof UnauthorizedException) {
71
+ const LOGIN_PATH = getSetting("LOGIN_PATH", "/signin");
72
+ store.dispatch(replace(LOGIN_PATH, {
73
+ from: {
74
+ pathname: redirectURI
75
+ },
76
+ modal: false
77
+ }));
78
+ }
79
+ });
80
+ }
81
+ };
82
+
56
83
  /**
57
84
  */
58
85
  export const setupClient = function () {
@@ -74,6 +101,7 @@ export const setupClient = function () {
74
101
  routerHistory,
75
102
  store
76
103
  } = configureStore(browserHistory, customReducers, rehydrate(data));
104
+ handleRedirectURI(store);
77
105
  setAllContentInDataSetting(store.getState());
78
106
  setLoginPreferences(store.getState());
79
107
 
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["hydrate","render","has","setImmediate","Cache","createBrowserHistory","configureStore","rehydrate","getBasePath","setAllContentInDataSetting","setLoginPreferences","showXHRErrorNotification","handleError","loginSuccess","locationChange","JsonParseException","FetchException","Init","handleBeforeRenderHooks","jsx","_jsx","parseDataToJSON","data","JSON","parse","error","getDataFromServer","_context","dataElement","document","querySelector","Error","_trimInstanceProperty","textContent","call","setUnhandledRejectionEvent","store","window","onunhandledrejection","event","detail","errorMessage","reason","message","toString","dispatch","setupClient","customReducers","arguments","length","undefined","beforeRenderHooks","contextPath","clear","browserHistory","basename","routerHistory","getState","loadOtherBrowserTabs","getItem","response","listen","location","action","body","className","addContentLoadedEvent","theme","ErrorFallbackComponent","mount","addEventListener","applicationNode","children","mountClient","element","isSSR","client","_ref"],"sources":["../../src/react-client/client.js"],"sourcesContent":["// @flow\n// eslint-disable-next-line react/no-deprecated\nimport { hydrate, render } from \"react-dom\";\n\nimport { has } from \"../utils/helpers/objects\";\nimport setImmediate from \"setimmediate\";\n\nimport Cache from \"../utils/browser/Cache\";\n\nimport { createBrowserHistory } from \"history\";\nimport configureStore from \"../redux/store/configureStore\";\n\nimport rehydrate from \"./rehydrate\";\nimport { getBasePath } from \"../constants/Settings\";\n\nimport {\n setAllContentInDataSetting,\n setLoginPreferences,\n} from \"../redux/actions/Preferences\";\nimport { showXHRErrorNotification } from \"../redux/actions/Notification\";\n\nimport { handleError } from \"../redux/actions/Error\";\nimport { loginSuccess } from \"../redux/actions/SignIn\";\n\nimport { locationChange } from \"../redux/_router/RouterActions\";\n\nimport { JsonParseException, FetchException } from \"../exceptions\";\n\nimport { Init } from \"./Init\";\n\nimport { handleBeforeRenderHooks } from \"../redux/store/beforeRenderHooks\";\n\nimport type {\n ComponentType,\n Element as ReactElement,\n ElementType,\n} from \"react\";\nimport type { Theme } from \"../react-theme/types\";\nimport type { CustomReducers, ReduxStore } from \"../redux/types\";\nimport type { RouterHistory } from \"react-router\";\nimport type { BeforeRenderHook } from \"../redux/store/beforeRenderHooks\";\nimport type { Props as FallbackProps } from \"../react/ErrorBoundaryFallback\";\n\ntype RenderFunction = () => ReactElement<ElementType>;\ntype MountFunction = (\n applicationNode: Element,\n element: ReactElement<ElementType>,\n) => void;\ntype Props = {\n customReducers?: CustomReducers,\n theme?: Theme | Array<Theme>,\n render: RenderFunction,\n mount: MountFunction,\n beforeRenderHooks?: Array<BeforeRenderHook>,\n ErrorFallbackComponent?: ComponentType<FallbackProps>,\n};\n\n/*\n * deserialize serialized data from the server to provide a smooth dehydration.\n */\nconst parseDataToJSON = (data: string) => {\n try {\n return JSON.parse(data);\n } catch (error) {\n throw new JsonParseException(`Error parsing content ${data}`);\n }\n};\n\nconst getDataFromServer = () => {\n const dataElement = document.querySelector(\n 'script[type=\"application/json\"][data-app-state=\"app-json\"]',\n );\n\n if (!dataElement) {\n throw new Error(\"Error loading state, json not found\");\n } else if (dataElement.textContent.trim() === \"\") {\n return {};\n }\n\n return parseDataToJSON(dataElement.textContent);\n};\n\n/**\n */\nexport const setUnhandledRejectionEvent = (store: ReduxStore) => {\n window.onunhandledrejection = (event) => {\n if (event.detail) {\n return setImmediate(() => {\n const errorMessage = event.detail.reason.message.toString();\n\n store.dispatch(showXHRErrorNotification(errorMessage));\n throw event.detail.reason;\n });\n }\n\n return event;\n };\n};\n\n/**\n */\nexport const setupClient = (\n customReducers: CustomReducers = {},\n beforeRenderHooks: ?Array<BeforeRenderHook>,\n): { store: ReduxStore, routerHistory: RouterHistory } => {\n if (typeof window.contextPath === \"undefined\") {\n throw new Error(\"Missing contextPath on window object\");\n }\n\n const data = getDataFromServer();\n\n // remove all resources from cache\n Cache.clear(\"^res:\");\n\n // $FlowExpectedError\n const browserHistory: RouterHistory = createBrowserHistory({\n basename: getBasePath(),\n });\n const { routerHistory, store } = configureStore(\n browserHistory,\n customReducers,\n rehydrate(data),\n );\n\n setAllContentInDataSetting(store.getState());\n setLoginPreferences(store.getState());\n\n // load existing cache from other browser tabs\n Cache.loadOtherBrowserTabs(() => {\n if (Cache.getItem(\"auth\")) {\n store.dispatch(loginSuccess());\n }\n });\n\n if (has(data, \"error.name\")) {\n const error = new FetchException(data?.error?.response);\n store.dispatch(handleError(error));\n }\n\n if (Cache.getItem(\"auth\")) {\n store.dispatch(loginSuccess());\n }\n\n // listen to history change and update the redux router store\n routerHistory.listen((location, action) => {\n store.dispatch(locationChange(location, action));\n });\n\n setUnhandledRejectionEvent(store);\n\n if (document.body) {\n document.body.className = \"js\";\n }\n\n if (beforeRenderHooks) {\n handleBeforeRenderHooks(beforeRenderHooks, { store });\n }\n\n return { store, routerHistory };\n};\n\n/**\n */\nexport const addContentLoadedEvent = (\n store: ReduxStore,\n routerHistory: RouterHistory,\n theme?: Theme | Array<Theme>,\n render: RenderFunction,\n ErrorFallbackComponent?: ComponentType<FallbackProps>,\n mount: MountFunction,\n) => {\n window.addEventListener(\"DOMContentLoaded\", () => {\n const applicationNode = document.querySelector(\"#application\");\n if (!applicationNode) {\n throw new Error(\n \"No DOM element with id application found to attach client to\",\n );\n }\n\n mount(\n applicationNode,\n <Init\n store={store}\n routerHistory={routerHistory}\n contextPath={window.contextPath}\n theme={theme}\n ErrorFallbackComponent={ErrorFallbackComponent}\n >\n {render()}\n </Init>,\n );\n });\n};\n\n/**\n */\nconst mountClient = (\n applicationNode: Element,\n element: ReactElement<ElementType>,\n) => {\n const isSSR = applicationNode.querySelector(\".application\");\n if (isSSR) {\n hydrate(element, applicationNode);\n } else {\n render(element, applicationNode);\n }\n};\n\n/**\n * Mount the webapplication to the DOM, setup redux store and caches, add unhandledRejectionEvent, used client side when JavaScript is enabled.\n */\nexport const client = ({\n customReducers,\n theme,\n render,\n beforeRenderHooks,\n ErrorFallbackComponent,\n mount,\n}: Props) => {\n const { store, routerHistory } = setupClient(\n customReducers,\n beforeRenderHooks,\n );\n\n addContentLoadedEvent(\n store,\n routerHistory,\n theme,\n render,\n ErrorFallbackComponent,\n mount ?? mountClient,\n );\n};\n"],"mappings":";AACA;AACA,SAASA,OAAO,EAAEC,MAAM,QAAQ,WAAW;AAE3C,SAASC,GAAG,QAAQ,0BAA0B;AAC9C,OAAOC,YAAY,MAAM,cAAc;AAEvC,OAAOC,KAAK,MAAM,wBAAwB;AAE1C,SAASC,oBAAoB,QAAQ,SAAS;AAC9C,OAAOC,cAAc,MAAM,+BAA+B;AAE1D,OAAOC,SAAS,MAAM,aAAa;AACnC,SAASC,WAAW,QAAQ,uBAAuB;AAEnD,SACEC,0BAA0B,EAC1BC,mBAAmB,QACd,8BAA8B;AACrC,SAASC,wBAAwB,QAAQ,+BAA+B;AAExE,SAASC,WAAW,QAAQ,wBAAwB;AACpD,SAASC,YAAY,QAAQ,yBAAyB;AAEtD,SAASC,cAAc,QAAQ,gCAAgC;AAE/D,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,eAAe;AAElE,SAASC,IAAI,QAAQ,QAAQ;AAE7B,SAASC,uBAAuB,QAAQ,kCAAkC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA2B3E;AACA;AACA;AACA,MAAMC,eAAe,GAAIC,IAAY,IAAK;EACxC,IAAI;IACF,OAAOC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC;EACzB,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,MAAM,IAAIV,kBAAkB,CAAE,yBAAwBO,IAAK,EAAC,CAAC;EAC/D;AACF,CAAC;AAED,MAAMI,iBAAiB,GAAGA,CAAA,KAAM;EAAA,IAAAC,QAAA;EAC9B,MA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AAEzC,KAAK;IAAEoB;EAAc,CAAC,GAAGV,WAAW,CAC1CC,cAAc,EACdI,iBACF,CAAC;EAEDe,qBAAqB,CACnB9B,KAAK,EACLoB,aAAa,EACbW,KAAK,EACLlE,MAAM,EACNmE,sBAAsB,EACtBC,KAAK,IAAII,WACX,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"client.js","names":["hydrate","render","has","setImmediate","Cache","xhr","createBrowserHistory","configureStore","rehydrate","getBasePath","getSetting","setAllContentInDataSetting","setLoginPreferences","showXHRErrorNotification","handleError","loginSuccess","locationChange","replace","JsonParseException","FetchException","Init","handleBeforeRenderHooks","UnauthorizedException","jsx","_jsx","parseDataToJSON","data","JSON","parse","error","getDataFromServer","_context","dataElement","document","querySelector","Error","_trimInstanceProperty","textContent","call","setUnhandledRejectionEvent","store","window","onunhandledrejection","event","detail","errorMessage","reason","message","toString","dispatch","handleRedirectURI","urlParams","_URLSearchParams","location","search","redirectURI","get","url","catch","e","LOGIN_PATH","from","pathname","modal","setupClient","customReducers","arguments","length","undefined","beforeRenderHooks","contextPath","clear","browserHistory","basename","routerHistory","getState","loadOtherBrowserTabs","getItem","response","listen","action","body","className","addContentLoadedEvent","theme","ErrorFallbackComponent","mount","addEventListener","applicationNode","children","mountClient","element","isSSR","client","_ref"],"sources":["../../src/react-client/client.js"],"sourcesContent":["// @flow\n// eslint-disable-next-line react/no-deprecated\nimport { hydrate, render } from \"react-dom\";\n\nimport { has } from \"../utils/helpers/objects\";\nimport setImmediate from \"setimmediate\";\n\nimport Cache from \"../utils/browser/Cache\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport { createBrowserHistory } from \"history\";\nimport configureStore from \"../redux/store/configureStore\";\n\nimport rehydrate from \"./rehydrate\";\nimport { getBasePath, getSetting } from \"../constants/Settings\";\n\nimport {\n setAllContentInDataSetting,\n setLoginPreferences,\n} from \"../redux/actions/Preferences\";\nimport { showXHRErrorNotification } from \"../redux/actions/Notification\";\n\nimport { handleError } from \"../redux/actions/Error\";\nimport { loginSuccess } from \"../redux/actions/SignIn\";\n\nimport { locationChange, replace } from \"../redux/_router/RouterActions\";\n\nimport { JsonParseException, FetchException } from \"../exceptions\";\n\nimport { Init } from \"./Init\";\n\nimport { handleBeforeRenderHooks } from \"../redux/store/beforeRenderHooks\";\n\nimport UnauthorizedException from \"../exceptions/UnauthorizedException\";\n\nimport type {\n ComponentType,\n Element as ReactElement,\n ElementType,\n} from \"react\";\nimport type { Theme } from \"../react-theme/types\";\nimport type { CustomReducers, ReduxStore } from \"../redux/types\";\nimport type { RouterHistory } from \"react-router\";\nimport type { BeforeRenderHook } from \"../redux/store/beforeRenderHooks\";\nimport type { Props as FallbackProps } from \"../react/ErrorBoundaryFallback\";\n\ntype RenderFunction = () => ReactElement<ElementType>;\ntype MountFunction = (\n applicationNode: Element,\n element: ReactElement<ElementType>,\n) => void;\ntype Props = {\n customReducers?: CustomReducers,\n theme?: Theme | Array<Theme>,\n render: RenderFunction,\n mount: MountFunction,\n beforeRenderHooks?: Array<BeforeRenderHook>,\n ErrorFallbackComponent?: ComponentType<FallbackProps>,\n};\n\n/*\n * deserialize serialized data from the server to provide a smooth dehydration.\n */\nconst parseDataToJSON = (data: string) => {\n try {\n return JSON.parse(data);\n } catch (error) {\n throw new JsonParseException(`Error parsing content ${data}`);\n }\n};\n\nconst getDataFromServer = () => {\n const dataElement = document.querySelector(\n 'script[type=\"application/json\"][data-app-state=\"app-json\"]',\n );\n\n if (!dataElement) {\n throw new Error(\"Error loading state, json not found\");\n } else if (dataElement.textContent.trim() === \"\") {\n return {};\n }\n\n return parseDataToJSON(dataElement.textContent);\n};\n\n/**\n */\nexport const setUnhandledRejectionEvent = (store: ReduxStore) => {\n window.onunhandledrejection = (event) => {\n if (event.detail) {\n return setImmediate(() => {\n const errorMessage = event.detail.reason.message.toString();\n\n store.dispatch(showXHRErrorNotification(errorMessage));\n throw event.detail.reason;\n });\n }\n\n return event;\n };\n};\n\n/**\n * The redirectURI querystring parameter is available when the server is redirecting an unauthorized deep link\n * @param store\n */\nconst handleRedirectURI = (store: ReduxStore) => {\n const urlParams = new URLSearchParams(window.location.search);\n const redirectURI = urlParams.get(\"redirectURI\");\n if (redirectURI) {\n xhr({ url: `${getBasePath()}${redirectURI}` }).catch((e) => {\n if (e instanceof UnauthorizedException) {\n const LOGIN_PATH = getSetting(\"LOGIN_PATH\", \"/signin\");\n store.dispatch(\n replace(LOGIN_PATH, {\n from: { pathname: redirectURI },\n modal: false,\n }),\n );\n }\n });\n }\n};\n\n/**\n */\nexport const setupClient = (\n customReducers: CustomReducers = {},\n beforeRenderHooks: ?Array<BeforeRenderHook>,\n): { store: ReduxStore, routerHistory: RouterHistory } => {\n if (typeof window.contextPath === \"undefined\") {\n throw new Error(\"Missing contextPath on window object\");\n }\n\n const data = getDataFromServer();\n\n // remove all resources from cache\n Cache.clear(\"^res:\");\n\n // $FlowExpectedError\n const browserHistory: RouterHistory = createBrowserHistory({\n basename: getBasePath(),\n });\n const { routerHistory, store } = configureStore(\n browserHistory,\n customReducers,\n rehydrate(data),\n );\n\n handleRedirectURI(store);\n\n setAllContentInDataSetting(store.getState());\n setLoginPreferences(store.getState());\n\n // load existing cache from other browser tabs\n Cache.loadOtherBrowserTabs(() => {\n if (Cache.getItem(\"auth\")) {\n store.dispatch(loginSuccess());\n }\n });\n\n if (has(data, \"error.name\")) {\n const error = new FetchException(data?.error?.response);\n store.dispatch(handleError(error));\n }\n\n if (Cache.getItem(\"auth\")) {\n store.dispatch(loginSuccess());\n }\n\n // listen to history change and update the redux router store\n routerHistory.listen((location, action) => {\n store.dispatch(locationChange(location, action));\n });\n\n setUnhandledRejectionEvent(store);\n\n if (document.body) {\n document.body.className = \"js\";\n }\n\n if (beforeRenderHooks) {\n handleBeforeRenderHooks(beforeRenderHooks, { store });\n }\n\n return { store, routerHistory };\n};\n\n/**\n */\nexport const addContentLoadedEvent = (\n store: ReduxStore,\n routerHistory: RouterHistory,\n theme?: Theme | Array<Theme>,\n render: RenderFunction,\n ErrorFallbackComponent?: ComponentType<FallbackProps>,\n mount: MountFunction,\n) => {\n window.addEventListener(\"DOMContentLoaded\", () => {\n const applicationNode = document.querySelector(\"#application\");\n if (!applicationNode) {\n throw new Error(\n \"No DOM element with id application found to attach client to\",\n );\n }\n\n mount(\n applicationNode,\n <Init\n store={store}\n routerHistory={routerHistory}\n contextPath={window.contextPath}\n theme={theme}\n ErrorFallbackComponent={ErrorFallbackComponent}\n >\n {render()}\n </Init>,\n );\n });\n};\n\n/**\n */\nconst mountClient = (\n applicationNode: Element,\n element: ReactElement<ElementType>,\n) => {\n const isSSR = applicationNode.querySelector(\".application\");\n if (isSSR) {\n hydrate(element, applicationNode);\n } else {\n render(element, applicationNode);\n }\n};\n\n/**\n * Mount the webapplication to the DOM, setup redux store and caches, add unhandledRejectionEvent, used client side when JavaScript is enabled.\n */\nexport const client = ({\n customReducers,\n theme,\n render,\n beforeRenderHooks,\n ErrorFallbackComponent,\n mount,\n}: Props) => {\n const { store, routerHistory } = setupClient(\n customReducers,\n beforeRenderHooks,\n );\n\n addContentLoadedEvent(\n store,\n routerHistory,\n theme,\n render,\n ErrorFallbackComponent,\n mount ?? mountClient,\n );\n};\n"],"mappings":";;AACA;AACA,SAASA,OAAO,EAAEC,MAAM,QAAQ,WAAW;AAE3C,SAASC,GAAG,QAAQ,0BAA0B;AAC9C,OAAOC,YAAY,MAAM,cAAc;AAEvC,OAAOC,KAAK,MAAM,wBAAwB;AAE1C,OAAOC,GAAG,MAAM,oBAAoB;AAEpC,SAASC,oBAAoB,QAAQ,SAAS;AAC9C,OAAOC,cAAc,MAAM,+BAA+B;AAE1D,OAAOC,SAAS,MAAM,aAAa;AACnC,SAASC,WAAW,EAAEC,UAAU,QAAQ,uBAAuB;AAE/D,SACEC,0BAA0B,EAC1BC,mBAAmB,QACd,8BAA8B;AACrC,SAASC,wBAAwB,QAAQ,+BAA+B;AAExE,SAASC,WAAW,QAAQ,wBAAwB;AACpD,SAASC,YAAY,QAAQ,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ACK,CAAC,GAAAQ,IAAA;EACN,MAAM;IAAEtD,KAAK;IAAEkC;EAAc,CAAC,GAAGV,WAAW,CAC1CC,cAAc,EACdI,iBACF,CAAC;EAEDc,qBAAqB,CACnB3C,KAAK,EACLkC,aAAa,EACbU,KAAK,EACLnF,MAAM,EACNoF,sBAAsB,EACtBC,KAAK,IAAII,WACX,CAAC;AACH,CAAC"}
@@ -1,19 +1,14 @@
1
- import he from "he";
1
+ import { encode } from "html-entities";
2
2
  import { IllegalArgumentException } from "../../exceptions";
3
3
  /**
4
4
  * Translates html entities to their correct decimal equivalent
5
5
  * When path is only one deep better use optional chaining
6
6
  */
7
7
  const properEntityEncoding = html => {
8
- const htmlDecoded = he.decode(html, {
9
- decimal: true,
10
- allowUnsafeSymbols: true
8
+ return encode(html, {
9
+ mode: "nonAsciiPrintableOnly",
10
+ level: "xml"
11
11
  });
12
- const htmlEncoded = he.encode(htmlDecoded, {
13
- decimal: true,
14
- allowUnsafeSymbols: true
15
- });
16
- return htmlEncoded;
17
12
  };
18
13
 
19
14
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeHtml.js","names":["he","IllegalArgumentException","properEntityEncoding","html","htmlDecoded","decode","decimal","allowUnsafeSymbols","htmlEncoded","encode","removeUnwantedHtml","options","arguments","length","undefined","allowedTags","correctEntityHtml","htmlWithoutAttributes","replace","htmlWithCorrectBR","Array","isArray","join","pattern","regex","RegExp"],"sources":["../../../src/utils/helpers/sanitizeHtml.js"],"sourcesContent":["// @flow\nimport he from \"he\";\n\nimport { IllegalArgumentException } from \"../../exceptions\";\n\ntype removeUnwantedHtmlOptions = {\n allowedTags?: Array<string>,\n};\n\n/**\n * Translates html entities to their correct decimal equivalent\n * When path is only one deep better use optional chaining\n */\nconst properEntityEncoding = (html: string) => {\n const htmlDecoded = he.decode(html, {\n decimal: true,\n allowUnsafeSymbols: true,\n });\n\n const htmlEncoded = he.encode(htmlDecoded, {\n decimal: true,\n allowUnsafeSymbols: true,\n });\n\n return htmlEncoded;\n};\n\n/**\n * removes unwanted html, this might result in incorrect html, as it removes all html that we don't except,\n * like <b style=\"font-weight: 400\">bold</b> will result in bold</b>\n */\nconst removeUnwantedHtml = (\n html: string,\n options: removeUnwantedHtmlOptions = {\n allowedTags: [\"p\", \"br\", \"b\", \"i\", \"u\", \"strike\"],\n },\n): string => {\n if (typeof html !== \"string\") {\n throw new IllegalArgumentException(\"sanitizeHTML method expects a string\");\n }\n\n const correctEntityHtml = properEntityEncoding(html);\n\n // remove attributes from html elements\n const htmlWithoutAttributes = correctEntityHtml.replace(\n /<(\\w+)(.|[\\r\\n])*?>/gi,\n \"<$1>\",\n );\n\n const htmlWithCorrectBR = htmlWithoutAttributes.replace(\n /<br\\s*>/gi,\n \"<br />\",\n );\n\n // remove not allowed tags\n const allowedTags = Array.isArray(options.allowedTags)\n ? options.allowedTags.join(\"|\")\n : \"\";\n const pattern = `<(?!\\\\/?(${allowedTags})(>|\\\\s\\\\/))[^<]+?>`;\n const regex = new RegExp(pattern, \"gi\");\n\n return htmlWithCorrectBR.replace(regex, \"\");\n};\n\nexport { removeUnwantedHtml };\n"],"mappings":"AACA,OAAOA,EAAE,MAAM,IAAI;AAEnB,SAASC,wBAAwB,QAAQ,kBAAkB;AAM3D;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAC7C,MAAMC,WAAW,GAAGJ,EAAE,CAACK,MAAM,CAACF,IAAI,EAAE;IAClCG,OAAO,EAAE,IAAI;IACbC,kBAAkB,EAAE;EACtB,CAAC,CAAC;EAEF,MAAMC,WAAW,GAAGR,EAAE,CAACS,MAAM,CAACL,WAAW,EAAE;IACzCE,OAAO,EAAE,IAAI;IACbC,kBAAkB,EAAE;EACtB,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAME,kBAAkB,GAAG,SAAAA,CACzBP,IAAY,EAID;EAAA,IAHXQ,OAAkC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACnCG,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ;EAClD,CAAC;EAED,IAAI,OAAOZ,IAAI,KAAK,QAAQ,EAAE;IAC5B,MAAM,IAAIF,wBAAwB,CAAC,sCAAsC,CAAC;EAC5E;EAEA,MAAMe,iBAAiB,GAAGd,oBAAoB,CAACC,IAAI,CAAC;;EAEpD;EACA,MAAMc,qBAAqB,GAAGD,iBAAiB,CAACE,OAAO,CACrD,uBAAuB,EACvB,MACF,CAAC;EAED,MAAMC,iBAAiB,GAAGF,qBAAqB,CAACC,OAAO,CACrD,WAAW,EACX,QACF,CAAC;;EAED;EACA,MAAMH,WAAW,GAAGK,KAAK,CAACC,OAAO,CAACV,OAAO,CAACI,WAAW,CAAC,GAClDJ,OAAO,CAACI,WAAW,CAACO,IAAI,CAAC,GAAG,CAAC,GAC7B,EAAE;EACN,MAAMC,OAAO,GAAI,YAAWR,WAAY,qBAAoB;EAC5D,MAAMS,KAAK,GAAG,IAAIC,MAAM,CAACF,OAAO,EAAE,IAAI,CAAC;EAEvC,OAAOJ,iBAAiB,CAACD,OAAO,CAACM,KAAK,EAAE,EAAE,CAAC;AAC7C,CAAC;AAED,SAASd,kBAAkB"}
1
+ {"version":3,"file":"sanitizeHtml.js","names":["encode","IllegalArgumentException","properEntityEncoding","html","mode","level","removeUnwantedHtml","options","arguments","length","undefined","allowedTags","correctEntityHtml","htmlWithoutAttributes","replace","htmlWithCorrectBR","Array","isArray","join","pattern","regex","RegExp"],"sources":["../../../src/utils/helpers/sanitizeHtml.js"],"sourcesContent":["// @flow\nimport { encode } from \"html-entities\";\n\nimport { IllegalArgumentException } from \"../../exceptions\";\n\ntype removeUnwantedHtmlOptions = {\n allowedTags?: Array<string>,\n};\n\n/**\n * Translates html entities to their correct decimal equivalent\n * When path is only one deep better use optional chaining\n */\nconst properEntityEncoding = (html: string) => {\n return encode(html, { mode: \"nonAsciiPrintableOnly\", level: \"xml\" });\n};\n\n/**\n * removes unwanted html, this might result in incorrect html, as it removes all html that we don't except,\n * like <b style=\"font-weight: 400\">bold</b> will result in bold</b>\n */\nconst removeUnwantedHtml = (\n html: string,\n options: removeUnwantedHtmlOptions = {\n allowedTags: [\"p\", \"br\", \"b\", \"i\", \"u\", \"strike\"],\n },\n): string => {\n if (typeof html !== \"string\") {\n throw new IllegalArgumentException(\"sanitizeHTML method expects a string\");\n }\n\n const correctEntityHtml = properEntityEncoding(html);\n\n // remove attributes from html elements\n const htmlWithoutAttributes = correctEntityHtml.replace(\n /<(\\w+)(.|[\\r\\n])*?>/gi,\n \"<$1>\",\n );\n\n const htmlWithCorrectBR = htmlWithoutAttributes.replace(\n /<br\\s*>/gi,\n \"<br />\",\n );\n\n // remove not allowed tags\n const allowedTags = Array.isArray(options.allowedTags)\n ? options.allowedTags.join(\"|\")\n : \"\";\n const pattern = `<(?!\\\\/?(${allowedTags})(>|\\\\s\\\\/))[^<]+?>`;\n const regex = new RegExp(pattern, \"gi\");\n\n return htmlWithCorrectBR.replace(regex, \"\");\n};\n\nexport { removeUnwantedHtml };\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,eAAe;AAEtC,SAASC,wBAAwB,QAAQ,kBAAkB;AAM3D;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAC7C,OAAOH,MAAM,CAACG,IAAI,EAAE;IAAEC,IAAI,EAAE,uBAAuB;IAAEC,KAAK,EAAE;EAAM,CAAC,CAAC;AACtE,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,SAAAA,CACzBH,IAAY,EAID;EAAA,IAHXI,OAAkC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACnCG,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ;EAClD,CAAC;EAED,IAAI,OAAOR,IAAI,KAAK,QAAQ,EAAE;IAC5B,MAAM,IAAIF,wBAAwB,CAAC,sCAAsC,CAAC;EAC5E;EAEA,MAAMW,iBAAiB,GAAGV,oBAAoB,CAACC,IAAI,CAAC;;EAEpD;EACA,MAAMU,qBAAqB,GAAGD,iBAAiB,CAACE,OAAO,CACrD,uBAAuB,EACvB,MACF,CAAC;EAED,MAAMC,iBAAiB,GAAGF,qBAAqB,CAACC,OAAO,CACrD,WAAW,EACX,QACF,CAAC;;EAED;EACA,MAAMH,WAAW,GAAGK,KAAK,CAACC,OAAO,CAACV,OAAO,CAACI,WAAW,CAAC,GAClDJ,OAAO,CAACI,WAAW,CAACO,IAAI,CAAC,GAAG,CAAC,GAC7B,EAAE;EACN,MAAMC,OAAO,GAAI,YAAWR,WAAY,qBAAoB;EAC5D,MAAMS,KAAK,GAAG,IAAIC,MAAM,CAACF,OAAO,EAAE,IAAI,CAAC;EAEvC,OAAOJ,iBAAiB,CAACD,OAAO,CAACM,KAAK,EAAE,EAAE,CAAC;AAC7C,CAAC;AAED,SAASd,kBAAkB"}
@@ -73,7 +73,7 @@ class StringFilterModel extends _BaseFilterModel.default {
73
73
  update(attribute, value) {
74
74
  this._isValid = true;
75
75
  this._inputvalue = typeof value !== "string" ? value.toString() : value;
76
- if (this.operator === "exactly" || this.operator === "isNot") {
76
+ if (this.shouldHandleFormat()) {
77
77
  var _context, _context2;
78
78
  const values = this.isMultiple ? (0, _map.default)(_context = this._inputvalue.split(",")).call(_context, val => (0, _trim.default)(val).call(val)) : [(0, _trim.default)(_context2 = this._inputvalue).call(_context2)];
79
79
  const outputValues = [];
@@ -101,7 +101,7 @@ class StringFilterModel extends _BaseFilterModel.default {
101
101
  /**
102
102
  */
103
103
  formatValue(value) {
104
- if (this.operator === "exactly" || this.operator === "isNot") {
104
+ if (this.shouldHandleFormat()) {
105
105
  return this.attribute.formatValue(value);
106
106
  }
107
107
  return value;
@@ -131,11 +131,17 @@ class StringFilterModel extends _BaseFilterModel.default {
131
131
  if (value == null || value.toString() === "") {
132
132
  return "";
133
133
  }
134
- if ((this.operator === "exactly" || this.operator === "isNot") && (this.isIBAN() || this.isZipcode() || this.isBSN())) {
134
+ if (this.shouldHandleFormat()) {
135
135
  return value.replace(/[^a-z0-9,]/gi, "");
136
136
  }
137
137
  return value;
138
138
  }
139
+
140
+ /**
141
+ */
142
+ shouldHandleFormat() {
143
+ return (this.operator === "exactly" || this.operator === "isNot") && (this.isIBAN() || this.isZipcode() || this.isBSN());
144
+ }
139
145
  }
140
146
  exports.default = StringFilterModel;
141
147
  //# sourceMappingURL=StringFilterModel.js.map
@@ -74,7 +74,7 @@ export default class StringFilterModel extends BaseFilterModel {
74
74
  this._isValid = true;
75
75
  this._inputvalue = typeof value !== "string" ? value.toString() : value;
76
76
 
77
- if (this.operator === "exactly" || this.operator === "isNot") {
77
+ if (this.shouldHandleFormat()) {
78
78
  const values = this.isMultiple
79
79
  ? this._inputvalue.split(",").map((val) => val.trim())
80
80
  : [this._inputvalue.trim()];
@@ -106,7 +106,7 @@ export default class StringFilterModel extends BaseFilterModel {
106
106
  /**
107
107
  */
108
108
  formatValue(value: string): string {
109
- if (this.operator === "exactly" || this.operator === "isNot") {
109
+ if (this.shouldHandleFormat()) {
110
110
  return this.attribute.formatValue(value);
111
111
  }
112
112
  return value;
@@ -137,13 +137,19 @@ export default class StringFilterModel extends BaseFilterModel {
137
137
  return "";
138
138
  }
139
139
 
140
- if (
141
- (this.operator === "exactly" || this.operator === "isNot") &&
142
- (this.isIBAN() || this.isZipcode() || this.isBSN())
143
- ) {
140
+ if (this.shouldHandleFormat()) {
144
141
  return value.replace(/[^a-z0-9,]/gi, "");
145
142
  }
146
143
 
147
144
  return value;
148
145
  }
146
+
147
+ /**
148
+ */
149
+ shouldHandleFormat(): boolean {
150
+ return (
151
+ (this.operator === "exactly" || this.operator === "isNot") &&
152
+ (this.isIBAN() || this.isZipcode() || this.isBSN())
153
+ );
154
+ }
149
155
  }
@@ -1 +1 @@
1
- {"version":3,"file":"StringFilterModel.js","names":["_BaseFilterModel","_interopRequireDefault","require","StringFilterModel","BaseFilterModel","constructor","data","contributions","_defineProperty2","default","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","operator","_context","_context2","values","isMultiple","_map","split","call","val","_trim","outputValues","formattedValue","formatValue","push","validate","join","getContribution","isBSN","layouthint","has","isIBAN","isZipcode","replace","exports"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.removeFormat(this.value),\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._isValid = true;\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.operator === \"exactly\" || this.operator === \"isNot\") {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n\n /**\n */\n isBSN(): boolean {\n return this.layouthint.has(\"bsn\");\n }\n\n /**\n */\n isIBAN(): boolean {\n return this.layouthint.has(\"iban\");\n }\n\n /**\n */\n isZipcode(): boolean {\n return this.layouthint.has(\"zipcode\");\n }\n\n /**\n */\n removeFormat(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n if (\n (this.operator === \"exactly\" || this.operator === \"isNot\") &&\n (this.isIBAN() || this.isZipcode() || this.isBSN())\n ) {\n return value.replace(/[^a-z0-9,]/gi, \"\");\n }\n\n return value;\n }\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACe,MAAMC,iBAAiB,SAASC,wBAAe,CAAC;EAK7D;AACF;EACEC,WAAWA,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAC/C,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,oBAPT,IAAI;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAStB,IAAI,CAACC,MAAM,CAAC,IAAI,CAACC,SAAS,EAAEL,IAAI,CAACM,KAAK,IAAI,EAAE,CAAC;;IAE7C;IACA,IAAI,CAACC,WAAW,GAAG,IAAI,CAACC,MAAM,IAAI,EAAE;EACtC;;EAEA;AACF;AACA;EACE,IAAIC,MAAMA,CAAA,EAA4C;IACpD,IAAI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AU;IACnC,IAAIA,KAAK,IAAI,IAAI,IAAIA,KAAK,CAACW,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;MAC5C,OAAO,EAAE;IACX;IAEA,IACE,CAAC,IAAI,CAACC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAACA,QAAQ,KAAK,OAAO,MACxD,IAAI,CAACoB,MAAM,CAAC,CAAC,IAAI,IAAI,CAACC,SAAS,CAAC,CAAC,IAAI,IAAI,CAACJ,KAAK,CAAC,CAAC,CAAC,EACnD;MACA,OAAO7B,KAAK,CAACkC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;IAC1C;IAEA,OAAOlC,KAAK;EACd;AACF;AAACmC,OAAA,CAAAtC,OAAA,GAAAN,iBAAA"}
1
+ {"version":3,"file":"StringFilterModel.js","names":["_BaseFilterModel","_interopRequireDefault","require","StringFilterModel","BaseFilterModel","constructor","data","contributions","_defineProperty2","default","update","attribute","value","_inputvalue","_value","params","param","name","removeFormat","inputvalue","reset","isValid","_isValid","toString","shouldHandleFormat","_context","_context2","values","isMultiple","_map","split","call","val","_trim","outputValues","formattedValue","formatValue","push","validate","join","operator","getContribution","isBSN","layouthint","has","isIBAN","isZipcode","replace","exports"],"sources":["../../../src/models/filters/StringFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"./BaseFilterModel\";\n\nimport type { AttributeType, FilterType } from \"../types\";\n\n/**\n * StringFilterModel can handle string filters with multiple setting\n */\nexport default class StringFilterModel extends BaseFilterModel {\n _isValid: boolean = true;\n _value: string | null;\n _inputvalue: string;\n\n /**\n */\n constructor(data: Object, contributions: Object) {\n super(data, contributions);\n\n this.update(this.attribute, data.value ?? \"\");\n\n // when formatted value set this to initial input value\n this._inputvalue = this._value ?? \"\";\n }\n\n /**\n * Retrieve the parameters with its value for this filter\n */\n get params(): Array<{ name: string, value: ?string }> {\n if (!this.param) {\n return [];\n }\n\n return [\n {\n name: this.param,\n value: this.removeFormat(this.value),\n },\n ];\n }\n\n /**\n * Getting the value of the filter\n */\n get value(): string | null {\n return this._value;\n }\n\n /**\n */\n get inputvalue(): string {\n return this._inputvalue;\n }\n\n /**\n * Reset the value of this filter to undefined\n */\n reset(): FilterType {\n this._inputvalue = \"\";\n this._value = null;\n\n return this;\n }\n\n /**\n */\n get isValid(): boolean {\n return this._isValid;\n }\n\n /**\n * Update this filter with input name and value\n */\n update(attribute: AttributeType, value: string) {\n this._isValid = true;\n this._inputvalue = typeof value !== \"string\" ? value.toString() : value;\n\n if (this.shouldHandleFormat()) {\n const values = this.isMultiple\n ? this._inputvalue.split(\",\").map((val) => val.trim())\n : [this._inputvalue.trim()];\n\n const outputValues = [];\n for (const val of values) {\n const formattedValue = this.formatValue(val);\n if (formattedValue !== \"\") {\n outputValues.push(formattedValue);\n\n if (!this.attribute.validate(formattedValue)) {\n this._isValid = false;\n }\n }\n }\n\n this._value = outputValues.join(\",\");\n } else {\n this._value = value;\n }\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n formatValue(value: string): string {\n if (this.shouldHandleFormat()) {\n return this.attribute.formatValue(value);\n }\n return value;\n }\n\n /**\n */\n isBSN(): boolean {\n return this.layouthint.has(\"bsn\");\n }\n\n /**\n */\n isIBAN(): boolean {\n return this.layouthint.has(\"iban\");\n }\n\n /**\n */\n isZipcode(): boolean {\n return this.layouthint.has(\"zipcode\");\n }\n\n /**\n */\n removeFormat(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n if (this.shouldHandleFormat()) {\n return value.replace(/[^a-z0-9,]/gi, \"\");\n }\n\n return value;\n }\n\n /**\n */\n shouldHandleFormat(): boolean {\n return (\n (this.operator === \"exactly\" || this.operator === \"isNot\") &&\n (this.isIBAN() || this.isZipcode() || this.isBSN())\n );\n }\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA;AACA;AACA;AACe,MAAMC,iBAAiB,SAASC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C;IAC1C;IACA,OAAOA,KAAK;EACd;;EAEA;AACF;EACE8B,KAAKA,CAAA,EAAY;IACf,OAAO,IAAI,CAACC,UAAU,CAACC,GAAG,CAAC,KAAK,CAAC;EACnC;;EAEA;AACF;EACEC,MAAMA,CAAA,EAAY;IAChB,OAAO,IAAI,CAACF,UAAU,CAACC,GAAG,CAAC,MAAM,CAAC;EACpC;;EAEA;AACF;EACEE,SAASA,CAAA,EAAY;IACnB,OAAO,IAAI,CAACH,UAAU,CAACC,GAAG,CAAC,SAAS,CAAC;EACvC;;EAEA;AACF;EACE1B,YAAYA,CAACN,KAAc,EAAU;IACnC,IAAIA,KAAK,IAAI,IAAI,IAAIA,KAAK,CAACW,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;MAC5C,OAAO,EAAE;IACX;IAEA,IAAI,IAAI,CAACC,kBAAkB,CAAC,CAAC,EAAE;MAC7B,OAAOZ,KAAK,CAACmC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;IAC1C;IAEA,OAAOnC,KAAK;EACd;;EAEA;AACF;EACEY,kBAAkBA,CAAA,EAAY;IAC5B,OACE,CAAC,IAAI,CAACgB,QAAQ,KAAK,SAAS,IAAI,IAAI,CAACA,QAAQ,KAAK,OAAO,MACxD,IAAI,CAACK,MAAM,CAAC,CAAC,IAAI,IAAI,CAACC,SAAS,CAAC,CAAC,IAAI,IAAI,CAACJ,KAAK,CAAC,CAAC,CAAC;EAEvD;AACF;AAACM,OAAA,CAAAvC,OAAA,GAAAN,iBAAA"}
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.setupClient = exports.setUnhandledRejectionEvent = exports.client = exports.addContentLoadedEvent = void 0;
8
8
  var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
9
+ var _urlSearchParams = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/url-search-params"));
9
10
  var _reactDom = require("react-dom");
10
11
  var _objects = require("../utils/helpers/objects");
11
12
  var _setimmediate = _interopRequireDefault(require("setimmediate"));
12
13
  var _Cache = _interopRequireDefault(require("../utils/browser/Cache"));
14
+ var _xhr = _interopRequireDefault(require("../utils/fetch/xhr"));
13
15
  var _history = require("history");
14
16
  var _configureStore = _interopRequireDefault(require("../redux/store/configureStore"));
15
17
  var _rehydrate = _interopRequireDefault(require("./rehydrate"));
@@ -22,6 +24,7 @@ var _RouterActions = require("../redux/_router/RouterActions");
22
24
  var _exceptions = require("../exceptions");
23
25
  var _Init = require("./Init");
24
26
  var _beforeRenderHooks = require("../redux/store/beforeRenderHooks");
27
+ var _UnauthorizedException = _interopRequireDefault(require("../exceptions/UnauthorizedException"));
25
28
  var _jsxRuntime = require("react/jsx-runtime");
26
29
  // eslint-disable-next-line react/no-deprecated
27
30
  /*
@@ -61,8 +64,32 @@ const setUnhandledRejectionEvent = store => {
61
64
  };
62
65
 
63
66
  /**
67
+ * The redirectURI querystring parameter is available when the server is redirecting an unauthorized deep link
68
+ * @param store
64
69
  */
65
70
  exports.setUnhandledRejectionEvent = setUnhandledRejectionEvent;
71
+ const handleRedirectURI = store => {
72
+ const urlParams = new _urlSearchParams.default(window.location.search);
73
+ const redirectURI = urlParams.get("redirectURI");
74
+ if (redirectURI) {
75
+ (0, _xhr.default)({
76
+ url: `${(0, _Settings.getBasePath)()}${redirectURI}`
77
+ }).catch(e => {
78
+ if (e instanceof _UnauthorizedException.default) {
79
+ const LOGIN_PATH = (0, _Settings.getSetting)("LOGIN_PATH", "/signin");
80
+ store.dispatch((0, _RouterActions.replace)(LOGIN_PATH, {
81
+ from: {
82
+ pathname: redirectURI
83
+ },
84
+ modal: false
85
+ }));
86
+ }
87
+ });
88
+ }
89
+ };
90
+
91
+ /**
92
+ */
66
93
  const setupClient = function () {
67
94
  let customReducers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
68
95
  let beforeRenderHooks = arguments.length > 1 ? arguments[1] : undefined;
@@ -82,6 +109,7 @@ const setupClient = function () {
82
109
  routerHistory,
83
110
  store
84
111
  } = (0, _configureStore.default)(browserHistory, customReducers, (0, _rehydrate.default)(data));
112
+ handleRedirectURI(store);
85
113
  (0, _Preferences.setAllContentInDataSetting)(store.getState());
86
114
  (0, _Preferences.setLoginPreferences)(store.getState());
87
115
 
@@ -7,11 +7,13 @@ import setImmediate from "setimmediate";
7
7
 
8
8
  import Cache from "../utils/browser/Cache";
9
9
 
10
+ import xhr from "../utils/fetch/xhr";
11
+
10
12
  import { createBrowserHistory } from "history";
11
13
  import configureStore from "../redux/store/configureStore";
12
14
 
13
15
  import rehydrate from "./rehydrate";
14
- import { getBasePath } from "../constants/Settings";
16
+ import { getBasePath, getSetting } from "../constants/Settings";
15
17
 
16
18
  import {
17
19
  setAllContentInDataSetting,
@@ -22,7 +24,7 @@ import { showXHRErrorNotification } from "../redux/actions/Notification";
22
24
  import { handleError } from "../redux/actions/Error";
23
25
  import { loginSuccess } from "../redux/actions/SignIn";
24
26
 
25
- import { locationChange } from "../redux/_router/RouterActions";
27
+ import { locationChange, replace } from "../redux/_router/RouterActions";
26
28
 
27
29
  import { JsonParseException, FetchException } from "../exceptions";
28
30
 
@@ -30,6 +32,8 @@ import { Init } from "./Init";
30
32
 
31
33
  import { handleBeforeRenderHooks } from "../redux/store/beforeRenderHooks";
32
34
 
35
+ import UnauthorizedException from "../exceptions/UnauthorizedException";
36
+
33
37
  import type {
34
38
  ComponentType,
35
39
  Element as ReactElement,
@@ -97,6 +101,28 @@ export const setUnhandledRejectionEvent = (store: ReduxStore) => {
97
101
  };
98
102
  };
99
103
 
104
+ /**
105
+ * The redirectURI querystring parameter is available when the server is redirecting an unauthorized deep link
106
+ * @param store
107
+ */
108
+ const handleRedirectURI = (store: ReduxStore) => {
109
+ const urlParams = new URLSearchParams(window.location.search);
110
+ const redirectURI = urlParams.get("redirectURI");
111
+ if (redirectURI) {
112
+ xhr({ url: `${getBasePath()}${redirectURI}` }).catch((e) => {
113
+ if (e instanceof UnauthorizedException) {
114
+ const LOGIN_PATH = getSetting("LOGIN_PATH", "/signin");
115
+ store.dispatch(
116
+ replace(LOGIN_PATH, {
117
+ from: { pathname: redirectURI },
118
+ modal: false,
119
+ }),
120
+ );
121
+ }
122
+ });
123
+ }
124
+ };
125
+
100
126
  /**
101
127
  */
102
128
  export const setupClient = (
@@ -122,6 +148,8 @@ export const setupClient = (
122
148
  rehydrate(data),
123
149
  );
124
150
 
151
+ handleRedirectURI(store);
152
+
125
153
  setAllContentInDataSetting(store.getState());
126
154
  setLoginPreferences(store.getState());
127
155
 
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["_reactDom","require","_objects","_setimmediate","_interopRequireDefault","_Cache","_history","_configureStore","_rehydrate","_Settings","_Preferences","_Notification","_Error","_SignIn","_RouterActions","_exceptions","_Init","_beforeRenderHooks","_jsxRuntime","parseDataToJSON","data","JSON","parse","error","JsonParseException","getDataFromServer","_context","dataElement","document","querySelector","Error","_trim","default","textContent","call","setUnhandledRejectionEvent","store","window","onunhandledrejection","event","detail","setImmediate","errorMessage","reason","message","toString","dispatch","showXHRErrorNotification","exports","setupClient","customReducers","arguments","length","undefined","beforeRenderHooks","contextPath","Cache","clear","browserHistory","createBrowserHistory","basename","getBasePath","routerHistory","configureStore","rehydrate","setAllContentInDataSetting","getState","setLoginPreferences","loadOtherBrowserTabs","getItem","loginSuccess","has","FetchException","response","handleError","listen","location","action","locationChange","body","className","handleBeforeRenderHooks","addContentLoadedEvent","theme","render","ErrorFallbackComponent","mount","addEventListener","applicationNode","jsx","Init","children","mountClient","element","isSSR","hydrate","client","_ref"],"sources":["../../src/react-client/client.js"],"sourcesContent":["// @flow\n// eslint-disable-next-line react/no-deprecated\nimport { hydrate, render } from \"react-dom\";\n\nimport { has } from \"../utils/helpers/objects\";\nimport setImmediate from \"setimmediate\";\n\nimport Cache from \"../utils/browser/Cache\";\n\nimport { createBrowserHistory } from \"history\";\nimport configureStore from \"../redux/store/configureStore\";\n\nimport rehydrate from \"./rehydrate\";\nimport { getBasePath } from \"../constants/Settings\";\n\nimport {\n setAllContentInDataSetting,\n setLoginPreferences,\n} from \"../redux/actions/Preferences\";\nimport { showXHRErrorNotification } from \"../redux/actions/Notification\";\n\nimport { handleError } from \"../redux/actions/Error\";\nimport { loginSuccess } from \"../redux/actions/SignIn\";\n\nimport { locationChange } from \"../redux/_router/RouterActions\";\n\nimport { JsonParseException, FetchException } from \"../exceptions\";\n\nimport { Init } from \"./Init\";\n\nimport { handleBeforeRenderHooks } from \"../redux/store/beforeRenderHooks\";\n\nimport type {\n ComponentType,\n Element as ReactElement,\n ElementType,\n} from \"react\";\nimport type { Theme } from \"../react-theme/types\";\nimport type { CustomReducers, ReduxStore } from \"../redux/types\";\nimport type { RouterHistory } from \"react-router\";\nimport type { BeforeRenderHook } from \"../redux/store/beforeRenderHooks\";\nimport type { Props as FallbackProps } from \"../react/ErrorBoundaryFallback\";\n\ntype RenderFunction = () => ReactElement<ElementType>;\ntype MountFunction = (\n applicationNode: Element,\n element: ReactElement<ElementType>,\n) => void;\ntype Props = {\n customReducers?: CustomReducers,\n theme?: Theme | Array<Theme>,\n render: RenderFunction,\n mount: MountFunction,\n beforeRenderHooks?: Array<BeforeRenderHook>,\n ErrorFallbackComponent?: ComponentType<FallbackProps>,\n};\n\n/*\n * deserialize serialized data from the server to provide a smooth dehydration.\n */\nconst parseDataToJSON = (data: string) => {\n try {\n return JSON.parse(data);\n } catch (error) {\n throw new JsonParseException(`Error parsing content ${data}`);\n }\n};\n\nconst getDataFromServer = () => {\n const dataElement = document.querySelector(\n 'script[type=\"application/json\"][data-app-state=\"app-json\"]',\n );\n\n if (!dataElement) {\n throw new Error(\"Error loading state, json not found\");\n } else if (dataElement.textContent.trim() === \"\") {\n return {};\n }\n\n return parseDataToJSON(dataElement.textContent);\n};\n\n/**\n */\nexport const setUnhandledRejectionEvent = (store: ReduxStore) => {\n window.onunhandledrejection = (event) => {\n if (event.detail) {\n return setImmediate(() => {\n const errorMessage = event.detail.reason.message.toString();\n\n store.dispatch(showXHRErrorNotification(errorMessage));\n throw event.detail.reason;\n });\n }\n\n return event;\n };\n};\n\n/**\n */\nexport const setupClient = (\n customReducers: CustomReducers = {},\n beforeRenderHooks: ?Array<BeforeRenderHook>,\n): { store: ReduxStore, routerHistory: RouterHistory } => {\n if (typeof window.contextPath === \"undefined\") {\n throw new Error(\"Missing contextPath on window object\");\n }\n\n const data = getDataFromServer();\n\n // remove all resources from cache\n Cache.clear(\"^res:\");\n\n // $FlowExpectedError\n const browserHistory: RouterHistory = createBrowserHistory({\n basename: getBasePath(),\n });\n const { routerHistory, store } = configureStore(\n browserHistory,\n customReducers,\n rehydrate(data),\n );\n\n setAllContentInDataSetting(store.getState());\n setLoginPreferences(store.getState());\n\n // load existing cache from other browser tabs\n Cache.loadOtherBrowserTabs(() => {\n if (Cache.getItem(\"auth\")) {\n store.dispatch(loginSuccess());\n }\n });\n\n if (has(data, \"error.name\")) {\n const error = new FetchException(data?.error?.response);\n store.dispatch(handleError(error));\n }\n\n if (Cache.getItem(\"auth\")) {\n store.dispatch(loginSuccess());\n }\n\n // listen to history change and update the redux router store\n routerHistory.listen((location, action) => {\n store.dispatch(locationChange(location, action));\n });\n\n setUnhandledRejectionEvent(store);\n\n if (document.body) {\n document.body.className = \"js\";\n }\n\n if (beforeRenderHooks) {\n handleBeforeRenderHooks(beforeRenderHooks, { store });\n }\n\n return { store, routerHistory };\n};\n\n/**\n */\nexport const addContentLoadedEvent = (\n store: ReduxStore,\n routerHistory: RouterHistory,\n theme?: Theme | Array<Theme>,\n render: RenderFunction,\n ErrorFallbackComponent?: ComponentType<FallbackProps>,\n mount: MountFunction,\n) => {\n window.addEventListener(\"DOMContentLoaded\", () => {\n const applicationNode = document.querySelector(\"#application\");\n if (!applicationNode) {\n throw new Error(\n \"No DOM element with id application found to attach client to\",\n );\n }\n\n mount(\n applicationNode,\n <Init\n store={store}\n routerHistory={routerHistory}\n contextPath={window.contextPath}\n theme={theme}\n ErrorFallbackComponent={ErrorFallbackComponent}\n >\n {render()}\n </Init>,\n );\n });\n};\n\n/**\n */\nconst mountClient = (\n applicationNode: Element,\n element: ReactElement<ElementType>,\n) => {\n const isSSR = applicationNode.querySelector(\".application\");\n if (isSSR) {\n hydrate(element, applicationNode);\n } else {\n render(element, applicationNode);\n }\n};\n\n/**\n * Mount the webapplication to the DOM, setup redux store and caches, add unhandledRejectionEvent, used client side when JavaScript is enabled.\n */\nexport const client = ({\n customReducers,\n theme,\n render,\n beforeRenderHooks,\n ErrorFallbackComponent,\n mount,\n}: Props) => {\n const { store, routerHistory } = setupClient(\n customReducers,\n beforeRenderHooks,\n );\n\n addContentLoadedEvent(\n store,\n routerHistory,\n theme,\n render,\n ErrorFallbackComponent,\n mount ?? mountClient,\n );\n};\n"],"mappings":";;;;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAD,sBAAA,CAAAH,OAAA;AAEA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAH,sBAAA,CAAAH,OAAA;AAEA,IAAAO,UAAA,GAAAJ,sBAAA,CAAAH,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AAEA,IAAAS,YAAA,GAAAT,OAAA;AAIA,IAAAU,aAAA,GAAAV,OAAA;AAEA,IAAAW,MAAA,GAAAX,OAAA;AACA,IAAAY,OAAA,GAAAZ,OAAA;AAEA,IAAAa,cAAA,GAAAb,OAAA;AAEA,IAAAc,WAAA,GAAAd,OAAA;AAEA,IAAAe,KAAA,GAAAf,OAAA;AAEA,IAAAgB,kBAAA,GAAAhB,OAAA;AAA2E,IAAAiB,WAAA,GAAAjB,OAAA;AA7B3E;AAwDA;AACA;AACA;AACA,MAAMkB,eAAe,GAAIC,IAAY,IAAK;EACxC,IAAI;IACF,OAAOC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC;EACz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ClBJ,eAAwB,EACxBK,OAAkC,KAC/B;EACH,MAAMC,KAAK,GAAGN,eAAe,CAAC3D,aAAa,CAAC,cAAc,CAAC;EAC3D,IAAIiE,KAAK,EAAE;IACT,IAAAC,iBAAO,EAACF,OAAO,EAAEL,eAAe,CAAC;EACnC,CAAC,MAAM;IACL,IAAAJ,gBAAM,EAACS,OAAO,EAAEL,eAAe,CAAC;EAClC;AACF,CAAC;;AAED;AACA;AACA;AACO,MAAMQ,MAAM,GAAGC,IAAA,IAOT;EAAA,IAPU;IACrB/C,cAAc;IACdiC,KAAK;IACLC,MAAM;IACN9B,iBAAiB;IACjB+B,sBAAsB;IACtBC;EACK,CAAC,GAAAW,IAAA;EACN,MAAM;IAAE7D,KAAK;IAAE0B;EAAc,CAAC,GAAGb,WAAW,CAC1CC,cAAc,EACdI,iBACF,CAAC;EAED4B,qBAAqB,CACnB9C,KAAK,EACL0B,aAAa,EACbqB,KAAK,EACLC,MAAM,EACNC,sBAAsB,EACtBC,KAAK,IAAIM,WACX,CAAC;AACH,CAAC;AAAC5C,OAAA,CAAAgD,MAAA,GAAAA,MAAA"}
1
+ {"version":3,"file":"client.js","names":["_reactDom","require","_objects","_setimmediate","_interopRequireDefault","_Cache","_xhr","_history","_configureStore","_rehydrate","_Settings","_Preferences","_Notification","_Error","_SignIn","_RouterActions","_exceptions","_Init","_beforeRenderHooks","_UnauthorizedException","_jsxRuntime","parseDataToJSON","data","JSON","parse","error","JsonParseException","getDataFromServer","_context","dataElement","document","querySelector","Error","_trim","default","textContent","call","setUnhandledRejectionEvent","store","window","onunhandledrejection","event","detail","setImmediate","errorMessage","reason","message","toString","dispatch","showXHRErrorNotification","exports","handleRedirectURI","urlParams","_urlSearchParams","location","search","redirectURI","get","xhr","url","getBasePath","catch","e","UnauthorizedException","LOGIN_PATH","getSetting","replace","from","pathname","modal","setupClient","customReducers","arguments","length","undefined","beforeRenderHooks","contextPath","Cache","clear","browserHistory","createBrowserHistory","basename","routerHistory","configureStore","rehydrate","setAllContentInDataSetting","getState","setLoginPreferences","loadOtherBrowserTabs","getItem","loginSuccess","has","FetchException","response","handleError","listen","action","locationChange","body","className","handleBeforeRenderHooks","addContentLoadedEvent","theme","render","ErrorFallbackComponent","mount","addEventListener","applicationNode","jsx","Init","children","mountClient","element","isSSR","hydrate","client","_ref"],"sources":["../../src/react-client/client.js"],"sourcesContent":["// @flow\n// eslint-disable-next-line react/no-deprecated\nimport { hydrate, render } from \"react-dom\";\n\nimport { has } from \"../utils/helpers/objects\";\nimport setImmediate from \"setimmediate\";\n\nimport Cache from \"../utils/browser/Cache\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport { createBrowserHistory } from \"history\";\nimport configureStore from \"../redux/store/configureStore\";\n\nimport rehydrate from \"./rehydrate\";\nimport { getBasePath, getSetting } from \"../constants/Settings\";\n\nimport {\n setAllContentInDataSetting,\n setLoginPreferences,\n} from \"../redux/actions/Preferences\";\nimport { showXHRErrorNotification } from \"../redux/actions/Notification\";\n\nimport { handleError } from \"../redux/actions/Error\";\nimport { loginSuccess } from \"../redux/actions/SignIn\";\n\nimport { locationChange, replace } from \"../redux/_router/RouterActions\";\n\nimport { JsonParseException, FetchException } from \"../exceptions\";\n\nimport { Init } from \"./Init\";\n\nimport { handleBeforeRenderHooks } from \"../redux/store/beforeRenderHooks\";\n\nimport UnauthorizedException from \"../exceptions/UnauthorizedException\";\n\nimport type {\n ComponentType,\n Element as ReactElement,\n ElementType,\n} from \"react\";\nimport type { Theme } from \"../react-theme/types\";\nimport type { CustomReducers, ReduxStore } from \"../redux/types\";\nimport type { RouterHistory } from \"react-router\";\nimport type { BeforeRenderHook } from \"../redux/store/beforeRenderHooks\";\nimport type { Props as FallbackProps } from \"../react/ErrorBoundaryFallback\";\n\ntype RenderFunction = () => ReactElement<ElementType>;\ntype MountFunction = (\n applicationNode: Element,\n element: ReactElement<ElementType>,\n) => void;\ntype Props = {\n customReducers?: CustomReducers,\n theme?: Theme | Array<Theme>,\n render: RenderFunction,\n mount: MountFunction,\n beforeRenderHooks?: Array<BeforeRenderHook>,\n ErrorFallbackComponent?: ComponentType<FallbackProps>,\n};\n\n/*\n * deserialize serialized data from the server to provide a smooth dehydration.\n */\nconst parseDataToJSON = (data: string) => {\n try {\n return JSON.parse(data);\n } catch (error) {\n throw new JsonParseException(`Error parsing content ${data}`);\n }\n};\n\nconst getDataFromServer = () => {\n const dataElement = document.querySelector(\n 'script[type=\"application/json\"][data-app-state=\"app-json\"]',\n );\n\n if (!dataElement) {\n throw new Error(\"Error loading state, json not found\");\n } else if (dataElement.textContent.trim() === \"\") {\n return {};\n }\n\n return parseDataToJSON(dataElement.textContent);\n};\n\n/**\n */\nexport const setUnhandledRejectionEvent = (store: ReduxStore) => {\n window.onunhandledrejection = (event) => {\n if (event.detail) {\n return setImmediate(() => {\n const errorMessage = event.detail.reason.message.toString();\n\n store.dispatch(showXHRErrorNotification(errorMessage));\n throw event.detail.reason;\n });\n }\n\n return event;\n };\n};\n\n/**\n * The redirectURI querystring parameter is available when the server is redirecting an unauthorized deep link\n * @param store\n */\nconst handleRedirectURI = (store: ReduxStore) => {\n const urlParams = new URLSearchParams(window.location.search);\n const redirectURI = urlParams.get(\"redirectURI\");\n if (redirectURI) {\n xhr({ url: `${getBasePath()}${redirectURI}` }).catch((e) => {\n if (e instanceof UnauthorizedException) {\n const LOGIN_PATH = getSetting(\"LOGIN_PATH\", \"/signin\");\n store.dispatch(\n replace(LOGIN_PATH, {\n from: { pathname: redirectURI },\n modal: false,\n }),\n );\n }\n });\n }\n};\n\n/**\n */\nexport const setupClient = (\n customReducers: CustomReducers = {},\n beforeRenderHooks: ?Array<BeforeRenderHook>,\n): { store: ReduxStore, routerHistory: RouterHistory } => {\n if (typeof window.contextPath === \"undefined\") {\n throw new Error(\"Missing contextPath on window object\");\n }\n\n const data = getDataFromServer();\n\n // remove all resources from cache\n Cache.clear(\"^res:\");\n\n // $FlowExpectedError\n const browserHistory: RouterHistory = createBrowserHistory({\n basename: getBasePath(),\n });\n const { routerHistory, store } = configureStore(\n browserHistory,\n customReducers,\n rehydrate(data),\n );\n\n handleRedirectURI(store);\n\n setAllContentInDataSetting(store.getState());\n setLoginPreferences(store.getState());\n\n // load existing cache from other browser tabs\n Cache.loadOtherBrowserTabs(() => {\n if (Cache.getItem(\"auth\")) {\n store.dispatch(loginSuccess());\n }\n });\n\n if (has(data, \"error.name\")) {\n const error = new FetchException(data?.error?.response);\n store.dispatch(handleError(error));\n }\n\n if (Cache.getItem(\"auth\")) {\n store.dispatch(loginSuccess());\n }\n\n // listen to history change and update the redux router store\n routerHistory.listen((location, action) => {\n store.dispatch(locationChange(location, action));\n });\n\n setUnhandledRejectionEvent(store);\n\n if (document.body) {\n document.body.className = \"js\";\n }\n\n if (beforeRenderHooks) {\n handleBeforeRenderHooks(beforeRenderHooks, { store });\n }\n\n return { store, routerHistory };\n};\n\n/**\n */\nexport const addContentLoadedEvent = (\n store: ReduxStore,\n routerHistory: RouterHistory,\n theme?: Theme | Array<Theme>,\n render: RenderFunction,\n ErrorFallbackComponent?: ComponentType<FallbackProps>,\n mount: MountFunction,\n) => {\n window.addEventListener(\"DOMContentLoaded\", () => {\n const applicationNode = document.querySelector(\"#application\");\n if (!applicationNode) {\n throw new Error(\n \"No DOM element with id application found to attach client to\",\n );\n }\n\n mount(\n applicationNode,\n <Init\n store={store}\n routerHistory={routerHistory}\n contextPath={window.contextPath}\n theme={theme}\n ErrorFallbackComponent={ErrorFallbackComponent}\n >\n {render()}\n </Init>,\n );\n });\n};\n\n/**\n */\nconst mountClient = (\n applicationNode: Element,\n element: ReactElement<ElementType>,\n) => {\n const isSSR = applicationNode.querySelector(\".application\");\n if (isSSR) {\n hydrate(element, applicationNode);\n } else {\n render(element, applicationNode);\n }\n};\n\n/**\n * Mount the webapplication to the DOM, setup redux store and caches, add unhandledRejectionEvent, used client side when JavaScript is enabled.\n */\nexport const client = ({\n customReducers,\n theme,\n render,\n beforeRenderHooks,\n ErrorFallbackComponent,\n mount,\n}: Props) => {\n const { store, routerHistory } = setupClient(\n customReducers,\n beforeRenderHooks,\n );\n\n addContentLoadedEvent(\n store,\n routerHistory,\n theme,\n render,\n ErrorFallbackComponent,\n mount ?? mountClient,\n );\n};\n"],"mappings":";;;;;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAD,sBAAA,CAAAH,OAAA;AAEA,IAAAK,IAAA,GAAAF,sBAAA,CAAAH,OAAA;AAEA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAJ,sBAAA,CAAAH,OAAA;AAEA,IAAAQ,UAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,SAAA,GAAAT,OAAA;AAEA,IAAAU,YAAA,GAAAV,OAAA;AAIA,IAAAW,aAAA,GAAAX,OAAA;AAEA,IAAAY,MAAA,GAAAZ,OAAA;AACA,IAAAa,OAAA,GAAAb,OAAA;AAEA,IAAAc,cAAA,GAAAd,OAAA;AAEA,IAAAe,WAAA,GAAAf,OAAA;AAEA,IAAAgB,KAAA,GAAAhB,OAAA;AAEA,IAAAiB,kBAAA,GAAAjB,OAAA;AAEA,IAAAkB,sBAAA,GAAAf,sBAAA,CAAAH,OAAA;AAAwE,IAAAmB,WAAA,GAAAnB,OAAA;AAjCxE;AA4DA;AACA;AACA;AACA,MAAMoB,eAAe,GAAIC,IAAY,IAAK;EACxC,IAAI;IACF,OAAOC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC;EACzB,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,MAAM,IAAIC,8BAAkB,CAAE,yBAAwBJ,IAAK,EAAC,CAAC;EAC/D;AACF,CAAC;AAED,MAAMK,iBAAiB,GAAGA,CAAA,KAAM;EAAA,IAAAC,QAAA;EAC9B,MAAMC,WAAW,GAAGC,QAAQ,CAACC,aAAa,CACxC,4DACF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e("sanitizeHTML", () => {
29
29
  ).toBe("<p>String <b>not allowed attribute</b> string</p>");
30
30
  });
31
31
 
32
- it("Can convert html entities to numerical entities", () => {
32
+ it("Should keep escaped html", () => {
33
33
  expect(
34
- removeUnwantedHtml("f&ouml;o &hearts; b&aring;r &#x1D306; baz"),
35
- ).toBe("f&#246;o &#9829; b&#229;r &#119558; baz");
34
+ removeUnwantedHtml(
35
+ "<p>Keep &lt;cite&gt;cite tag&lt;/cite&gt; and remove <cite>real cite tag</cite>",
36
+ ),
37
+ ).toBe(
38
+ "<p>Keep &lt;cite&gt;cite tag&lt;/cite&gt; and remove real cite tag",
39
+ );
36
40
  });
37
41
 
38
- it("Can encode special charcaters to numerical characters", () => {
42
+ it("Can encode special characters to numerical characters", () => {
39
43
  expect(removeUnwantedHtml("<p>foo © bar ≠ baz 𝌆 qux bla</p>")).toBe(
40
44
  "<p>foo &#169; bar &#8800; baz &#119558; qux bla</p>",
41
45
  );
@@ -1,26 +1,20 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.removeUnwantedHtml = void 0;
8
- var _he = _interopRequireDefault(require("he"));
7
+ var _htmlEntities = require("html-entities");
9
8
  var _exceptions = require("../../exceptions");
10
9
  /**
11
10
  * Translates html entities to their correct decimal equivalent
12
11
  * When path is only one deep better use optional chaining
13
12
  */
14
13
  const properEntityEncoding = html => {
15
- const htmlDecoded = _he.default.decode(html, {
16
- decimal: true,
17
- allowUnsafeSymbols: true
14
+ return (0, _htmlEntities.encode)(html, {
15
+ mode: "nonAsciiPrintableOnly",
16
+ level: "xml"
18
17
  });
19
- const htmlEncoded = _he.default.encode(htmlDecoded, {
20
- decimal: true,
21
- allowUnsafeSymbols: true
22
- });
23
- return htmlEncoded;
24
18
  };
25
19
 
26
20
  /**
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import he from "he";
2
+ import { encode } from "html-entities";
3
3
 
4
4
  import { IllegalArgumentException } from "../../exceptions";
5
5
 
@@ -12,17 +12,7 @@ type removeUnwantedHtmlOptions = {
12
12
  * When path is only one deep better use optional chaining
13
13
  */
14
14
  const properEntityEncoding = (html: string) => {
15
- const htmlDecoded = he.decode(html, {
16
- decimal: true,
17
- allowUnsafeSymbols: true,
18
- });
19
-
20
- const htmlEncoded = he.encode(htmlDecoded, {
21
- decimal: true,
22
- allowUnsafeSymbols: true,
23
- });
24
-
25
- return htmlEncoded;
15
+ return encode(html, { mode: "nonAsciiPrintableOnly", level: "xml" });
26
16
  };
27
17
 
28
18
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeHtml.js","names":["_he","_interopRequireDefault","require","_exceptions","properEntityEncoding","html","htmlDecoded","he","decode","decimal","allowUnsafeSymbols","htmlEncoded","encode","removeUnwantedHtml","options","arguments","length","undefined","allowedTags","IllegalArgumentException","correctEntityHtml","htmlWithoutAttributes","replace","htmlWithCorrectBR","Array","isArray","join","pattern","regex","RegExp","exports"],"sources":["../../../src/utils/helpers/sanitizeHtml.js"],"sourcesContent":["// @flow\nimport he from \"he\";\n\nimport { IllegalArgumentException } from \"../../exceptions\";\n\ntype removeUnwantedHtmlOptions = {\n allowedTags?: Array<string>,\n};\n\n/**\n * Translates html entities to their correct decimal equivalent\n * When path is only one deep better use optional chaining\n */\nconst properEntityEncoding = (html: string) => {\n const htmlDecoded = he.decode(html, {\n decimal: true,\n allowUnsafeSymbols: true,\n });\n\n const htmlEncoded = he.encode(htmlDecoded, {\n decimal: true,\n allowUnsafeSymbols: true,\n });\n\n return htmlEncoded;\n};\n\n/**\n * removes unwanted html, this might result in incorrect html, as it removes all html that we don't except,\n * like <b style=\"font-weight: 400\">bold</b> will result in bold</b>\n */\nconst removeUnwantedHtml = (\n html: string,\n options: removeUnwantedHtmlOptions = {\n allowedTags: [\"p\", \"br\", \"b\", \"i\", \"u\", \"strike\"],\n },\n): string => {\n if (typeof html !== \"string\") {\n throw new IllegalArgumentException(\"sanitizeHTML method expects a string\");\n }\n\n const correctEntityHtml = properEntityEncoding(html);\n\n // remove attributes from html elements\n const htmlWithoutAttributes = correctEntityHtml.replace(\n /<(\\w+)(.|[\\r\\n])*?>/gi,\n \"<$1>\",\n );\n\n const htmlWithCorrectBR = htmlWithoutAttributes.replace(\n /<br\\s*>/gi,\n \"<br />\",\n );\n\n // remove not allowed tags\n const allowedTags = Array.isArray(options.allowedTags)\n ? options.allowedTags.join(\"|\")\n : \"\";\n const pattern = `<(?!\\\\/?(${allowedTags})(>|\\\\s\\\\/))[^<]+?>`;\n const regex = new RegExp(pattern, \"gi\");\n\n return htmlWithCorrectBR.replace(regex, \"\");\n};\n\nexport { removeUnwantedHtml };\n"],"mappings":";;;;;;;AACA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AAMA;AACA;AACA;AACA;AACA,MAAME,oBAAoB,GAAIC,IAAY,IAAK;EAC7C,MAAMC,WAAW,GAAGC,WAAE,CAACC,MAAM,CAACH,IAAI,EAAE;IAClCI,OAAO,EAAE,IAAI;IACbC,kBAAkB,EAAE;EACtB,CAAC,CAAC;EAEF,MAAMC,WAAW,GAAGJ,WAAE,CAACK,MAAM,CAACN,WAAW,EAAE;IACzCG,OAAO,EAAE,IAAI;IACbC,kBAAkB,EAAE;EACtB,CAAC,CAAC;EAEF,OAAOC,WAAW;AACpB,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAME,kBAAkB,GAAG,SAAAA,CACzBR,IAAY,EAID;EAAA,IAHXS,OAAkC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACnCG,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ;EAClD,CAAC;EAED,IAAI,OAAOb,IAAI,KAAK,QAAQ,EAAE;IAC5B,MAAM,IAAIc,oCAAwB,CAAC,sCAAsC,CAAC;EAC5E;EAEA,MAAMC,iBAAiB,GAAGhB,oBAAoB,CAACC,IAAI,CAAC;;EAEpD;EACA,MAAMgB,qBAAqB,GAAGD,iBAAiB,CAACE,OAAO,CACrD,uBAAuB,EACvB,MACF,CAAC;EAED,MAAMC,iBAAiB,GAAGF,qBAAqB,CAACC,OAAO,CACrD,WAAW,EACX,QACF,CAAC;;EAED;EACA,MAAMJ,WAAW,GAAGM,KAAK,CAACC,OAAO,CAACX,OAAO,CAACI,WAAW,CAAC,GAClDJ,OAAO,CAACI,WAAW,CAACQ,IAAI,CAAC,GAAG,CAAC,GAC7B,EAAE;EACN,MAAMC,OAAO,GAAI,YAAWT,WAAY,qBAAoB;EAC5D,MAAMU,KAAK,GAAG,IAAIC,MAAM,CAACF,OAAO,EAAE,IAAI,CAAC;EAEvC,OAAOJ,iBAAiB,CAACD,OAAO,CAACM,KAAK,EAAE,EAAE,CAAC;AAC7C,CAAC;AAACE,OAAA,CAAAjB,kBAAA,GAAAA,kBAAA"}
1
+ {"version":3,"file":"sanitizeHtml.js","names":["_htmlEntities","require","_exceptions","properEntityEncoding","html","encode","mode","level","removeUnwantedHtml","options","arguments","length","undefined","allowedTags","IllegalArgumentException","correctEntityHtml","htmlWithoutAttributes","replace","htmlWithCorrectBR","Array","isArray","join","pattern","regex","RegExp","exports"],"sources":["../../../src/utils/helpers/sanitizeHtml.js"],"sourcesContent":["// @flow\nimport { encode } from \"html-entities\";\n\nimport { IllegalArgumentException } from \"../../exceptions\";\n\ntype removeUnwantedHtmlOptions = {\n allowedTags?: Array<string>,\n};\n\n/**\n * Translates html entities to their correct decimal equivalent\n * When path is only one deep better use optional chaining\n */\nconst properEntityEncoding = (html: string) => {\n return encode(html, { mode: \"nonAsciiPrintableOnly\", level: \"xml\" });\n};\n\n/**\n * removes unwanted html, this might result in incorrect html, as it removes all html that we don't except,\n * like <b style=\"font-weight: 400\">bold</b> will result in bold</b>\n */\nconst removeUnwantedHtml = (\n html: string,\n options: removeUnwantedHtmlOptions = {\n allowedTags: [\"p\", \"br\", \"b\", \"i\", \"u\", \"strike\"],\n },\n): string => {\n if (typeof html !== \"string\") {\n throw new IllegalArgumentException(\"sanitizeHTML method expects a string\");\n }\n\n const correctEntityHtml = properEntityEncoding(html);\n\n // remove attributes from html elements\n const htmlWithoutAttributes = correctEntityHtml.replace(\n /<(\\w+)(.|[\\r\\n])*?>/gi,\n \"<$1>\",\n );\n\n const htmlWithCorrectBR = htmlWithoutAttributes.replace(\n /<br\\s*>/gi,\n \"<br />\",\n );\n\n // remove not allowed tags\n const allowedTags = Array.isArray(options.allowedTags)\n ? options.allowedTags.join(\"|\")\n : \"\";\n const pattern = `<(?!\\\\/?(${allowedTags})(>|\\\\s\\\\/))[^<]+?>`;\n const regex = new RegExp(pattern, \"gi\");\n\n return htmlWithCorrectBR.replace(regex, \"\");\n};\n\nexport { removeUnwantedHtml };\n"],"mappings":";;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AAMA;AACA;AACA;AACA;AACA,MAAME,oBAAoB,GAAIC,IAAY,IAAK;EAC7C,OAAO,IAAAC,oBAAM,EAACD,IAAI,EAAE;IAAEE,IAAI,EAAE,uBAAuB;IAAEC,KAAK,EAAE;EAAM,CAAC,CAAC;AACtE,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,SAAAA,CACzBJ,IAAY,EAID;EAAA,IAHXK,OAAkC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACnCG,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ;EAClD,CAAC;EAED,IAAI,OAAOT,IAAI,KAAK,QAAQ,EAAE;IAC5B,MAAM,IAAIU,oCAAwB,CAAC,sCAAsC,CAAC;EAC5E;EAEA,MAAMC,iBAAiB,GAAGZ,oBAAoB,CAACC,IAAI,CAAC;;EAEpD;EACA,MAAMY,qBAAqB,GAAGD,iBAAiB,CAACE,OAAO,CACrD,uBAAuB,EACvB,MACF,CAAC;EAED,MAAMC,iBAAiB,GAAGF,qBAAqB,CAACC,OAAO,CACrD,WAAW,EACX,QACF,CAAC;;EAED;EACA,MAAMJ,WAAW,GAAGM,KAAK,CAACC,OAAO,CAACX,OAAO,CAACI,WAAW,CAAC,GAClDJ,OAAO,CAACI,WAAW,CAACQ,IAAI,CAAC,GAAG,CAAC,GAC7B,EAAE;EACN,MAAMC,OAAO,GAAI,YAAWT,WAAY,qBAAoB;EAC5D,MAAMU,KAAK,GAAG,IAAIC,MAAM,CAACF,OAAO,EAAE,IAAI,CAAC;EAEvC,OAAOJ,iBAAiB,CAACD,OAAO,CAACM,KAAK,EAAE,EAAE,CAAC;AAC7C,CAAC;AAACE,OAAA,CAAAjB,kBAAA,GAAAA,kBAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.33.0-beta.7",
3
+ "version": "1.34.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",
@@ -82,14 +82,15 @@
82
82
  "styled-components": "^5.0.0"
83
83
  },
84
84
  "dependencies": {
85
- "@babel/runtime-corejs3": "^7.22.11",
85
+ "@babel/runtime-corejs3": "^7.22.15",
86
86
  "big.js": "^6.2.1",
87
87
  "date-fns": "^2.30.0",
88
88
  "deepmerge": "^4.3.1",
89
89
  "dequal": "^2.0.3",
90
90
  "file-size": "^1.0.0",
91
91
  "format-message": "^6.2.4",
92
- "he": "^1.2.0",
92
+ "glob": "^10.3.4",
93
+ "html-entities": "^2.4.0",
93
94
  "iban": "^0.0.14",
94
95
  "js-cookie": "^3.0.5",
95
96
  "klona": "^2.0.6",
@@ -98,50 +99,49 @@
98
99
  "setimmediate": "^1.0.5"
99
100
  },
100
101
  "devDependencies": {
101
- "@babel/cli": "^7.22.10",
102
- "@babel/core": "^7.22.11",
103
- "@babel/eslint-parser": "^7.22.11",
102
+ "@babel/cli": "^7.22.15",
103
+ "@babel/core": "^7.22.17",
104
+ "@babel/eslint-parser": "^7.22.15",
104
105
  "@babel/eslint-plugin": "^7.22.10",
105
106
  "@babel/plugin-proposal-class-properties": "^7.18.6",
106
107
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
107
- "@babel/plugin-transform-runtime": "^7.22.10",
108
- "@babel/preset-env": "^7.22.10",
109
- "@babel/preset-flow": "^7.22.5",
110
- "@babel/preset-react": "^7.22.5",
108
+ "@babel/plugin-transform-runtime": "^7.22.15",
109
+ "@babel/preset-env": "^7.22.15",
110
+ "@babel/preset-flow": "^7.22.15",
111
+ "@babel/preset-react": "^7.22.15",
111
112
  "@commitlint/cli": "^17.7.1",
112
113
  "@commitlint/config-conventional": "^17.7.0",
113
114
  "@testing-library/react": "^14.0.0",
114
115
  "auditjs": "^4.0.41",
115
- "babel-jest": "^29.6.4",
116
+ "babel-jest": "^29.7.0",
116
117
  "babel-plugin-styled-components": "^2.1.4",
117
118
  "cherry-pick": "^0.5.0",
118
119
  "commit-and-tag-version": "^11.2.3",
119
120
  "cross-env": "^7.0.3",
120
121
  "documentation": "^14.0.2",
121
- "eslint": "^8.48.0",
122
+ "eslint": "^8.49.0",
122
123
  "eslint-config-prettier": "^9.0.0",
123
124
  "eslint-plugin-babel": "^5.3.1",
124
125
  "eslint-plugin-ft-flow": "^3.0.0",
125
126
  "eslint-plugin-import": "^2.28.1",
126
127
  "eslint-plugin-jest": "^27.2.3",
127
- "eslint-plugin-jsdoc": "^46.5.0",
128
+ "eslint-plugin-jsdoc": "^46.6.0",
128
129
  "eslint-plugin-react": "^7.33.2",
129
130
  "eslint-plugin-react-hooks": "^4.5.0",
130
131
  "eslint-plugin-you-dont-need-lodash-underscore": "^6.13.0",
131
132
  "flow-bin": "^0.200.1",
132
133
  "flow-copy-source": "^2.0.9",
133
134
  "flow-typed": "^3.9.0",
134
- "glob": "^10.3.3",
135
135
  "history": "^4.0.0",
136
136
  "husky": "^8.0.3",
137
- "jest": "^29.6.4",
138
- "jest-environment-jsdom": "^29.6.4",
137
+ "jest": "^29.7.0",
138
+ "jest-environment-jsdom": "^29.7.0",
139
139
  "jest-junit": "^16.0.0",
140
140
  "jest-sonar-reporter": "^2.0.0",
141
141
  "jscodeshift": "^0.15.0",
142
142
  "lint-staged": "^13.2.3",
143
143
  "polished": "^4.0.0",
144
- "prettier": "^3.0.2",
144
+ "prettier": "^3.0.3",
145
145
  "react": "^18.0.0",
146
146
  "react-dom": "^18.0.0",
147
147
  "react-helmet-async": "^1.0.0",
@@ -74,7 +74,7 @@ export default class StringFilterModel extends BaseFilterModel {
74
74
  this._isValid = true;
75
75
  this._inputvalue = typeof value !== "string" ? value.toString() : value;
76
76
 
77
- if (this.operator === "exactly" || this.operator === "isNot") {
77
+ if (this.shouldHandleFormat()) {
78
78
  const values = this.isMultiple
79
79
  ? this._inputvalue.split(",").map((val) => val.trim())
80
80
  : [this._inputvalue.trim()];
@@ -106,7 +106,7 @@ export default class StringFilterModel extends BaseFilterModel {
106
106
  /**
107
107
  */
108
108
  formatValue(value: string): string {
109
- if (this.operator === "exactly" || this.operator === "isNot") {
109
+ if (this.shouldHandleFormat()) {
110
110
  return this.attribute.formatValue(value);
111
111
  }
112
112
  return value;
@@ -137,13 +137,19 @@ export default class StringFilterModel extends BaseFilterModel {
137
137
  return "";
138
138
  }
139
139
 
140
- if (
141
- (this.operator === "exactly" || this.operator === "isNot") &&
142
- (this.isIBAN() || this.isZipcode() || this.isBSN())
143
- ) {
140
+ if (this.shouldHandleFormat()) {
144
141
  return value.replace(/[^a-z0-9,]/gi, "");
145
142
  }
146
143
 
147
144
  return value;
148
145
  }
146
+
147
+ /**
148
+ */
149
+ shouldHandleFormat(): boolean {
150
+ return (
151
+ (this.operator === "exactly" || this.operator === "isNot") &&
152
+ (this.isIBAN() || this.isZipcode() || this.isBSN())
153
+ );
154
+ }
149
155
  }
@@ -7,11 +7,13 @@ import setImmediate from "setimmediate";
7
7
 
8
8
  import Cache from "../utils/browser/Cache";
9
9
 
10
+ import xhr from "../utils/fetch/xhr";
11
+
10
12
  import { createBrowserHistory } from "history";
11
13
  import configureStore from "../redux/store/configureStore";
12
14
 
13
15
  import rehydrate from "./rehydrate";
14
- import { getBasePath } from "../constants/Settings";
16
+ import { getBasePath, getSetting } from "../constants/Settings";
15
17
 
16
18
  import {
17
19
  setAllContentInDataSetting,
@@ -22,7 +24,7 @@ import { showXHRErrorNotification } from "../redux/actions/Notification";
22
24
  import { handleError } from "../redux/actions/Error";
23
25
  import { loginSuccess } from "../redux/actions/SignIn";
24
26
 
25
- import { locationChange } from "../redux/_router/RouterActions";
27
+ import { locationChange, replace } from "../redux/_router/RouterActions";
26
28
 
27
29
  import { JsonParseException, FetchException } from "../exceptions";
28
30
 
@@ -30,6 +32,8 @@ import { Init } from "./Init";
30
32
 
31
33
  import { handleBeforeRenderHooks } from "../redux/store/beforeRenderHooks";
32
34
 
35
+ import UnauthorizedException from "../exceptions/UnauthorizedException";
36
+
33
37
  import type {
34
38
  ComponentType,
35
39
  Element as ReactElement,
@@ -97,6 +101,28 @@ export const setUnhandledRejectionEvent = (store: ReduxStore) => {
97
101
  };
98
102
  };
99
103
 
104
+ /**
105
+ * The redirectURI querystring parameter is available when the server is redirecting an unauthorized deep link
106
+ * @param store
107
+ */
108
+ const handleRedirectURI = (store: ReduxStore) => {
109
+ const urlParams = new URLSearchParams(window.location.search);
110
+ const redirectURI = urlParams.get("redirectURI");
111
+ if (redirectURI) {
112
+ xhr({ url: `${getBasePath()}${redirectURI}` }).catch((e) => {
113
+ if (e instanceof UnauthorizedException) {
114
+ const LOGIN_PATH = getSetting("LOGIN_PATH", "/signin");
115
+ store.dispatch(
116
+ replace(LOGIN_PATH, {
117
+ from: { pathname: redirectURI },
118
+ modal: false,
119
+ }),
120
+ );
121
+ }
122
+ });
123
+ }
124
+ };
125
+
100
126
  /**
101
127
  */
102
128
  export const setupClient = (
@@ -122,6 +148,8 @@ export const setupClient = (
122
148
  rehydrate(data),
123
149
  );
124
150
 
151
+ handleRedirectURI(store);
152
+
125
153
  setAllContentInDataSetting(store.getState());
126
154
  setLoginPreferences(store.getState());
127
155
 
@@ -29,13 +29,17 @@ describe("sanitizeHTML", () => {
29
29
  ).toBe("<p>String <b>not allowed attribute</b> string</p>");
30
30
  });
31
31
 
32
- it("Can convert html entities to numerical entities", () => {
32
+ it("Should keep escaped html", () => {
33
33
  expect(
34
- removeUnwantedHtml("f&ouml;o &hearts; b&aring;r &#x1D306; baz"),
35
- ).toBe("f&#246;o &#9829; b&#229;r &#119558; baz");
34
+ removeUnwantedHtml(
35
+ "<p>Keep &lt;cite&gt;cite tag&lt;/cite&gt; and remove <cite>real cite tag</cite>",
36
+ ),
37
+ ).toBe(
38
+ "<p>Keep &lt;cite&gt;cite tag&lt;/cite&gt; and remove real cite tag",
39
+ );
36
40
  });
37
41
 
38
- it("Can encode special charcaters to numerical characters", () => {
42
+ it("Can encode special characters to numerical characters", () => {
39
43
  expect(removeUnwantedHtml("<p>foo © bar ≠ baz 𝌆 qux bla</p>")).toBe(
40
44
  "<p>foo &#169; bar &#8800; baz &#119558; qux bla</p>",
41
45
  );
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import he from "he";
2
+ import { encode } from "html-entities";
3
3
 
4
4
  import { IllegalArgumentException } from "../../exceptions";
5
5
 
@@ -12,17 +12,7 @@ type removeUnwantedHtmlOptions = {
12
12
  * When path is only one deep better use optional chaining
13
13
  */
14
14
  const properEntityEncoding = (html: string) => {
15
- const htmlDecoded = he.decode(html, {
16
- decimal: true,
17
- allowUnsafeSymbols: true,
18
- });
19
-
20
- const htmlEncoded = he.encode(htmlDecoded, {
21
- decimal: true,
22
- allowUnsafeSymbols: true,
23
- });
24
-
25
- return htmlEncoded;
15
+ return encode(html, { mode: "nonAsciiPrintableOnly", level: "xml" });
26
16
  };
27
17
 
28
18
  /**