@beinformed/ui 1.25.6 → 1.27.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/esm/constants/Constants.js +9 -35
  3. package/esm/constants/Constants.js.map +1 -1
  4. package/esm/constants/Settings.js +47 -1
  5. package/esm/constants/Settings.js.map +1 -1
  6. package/esm/hooks/useAuthentication.js +7 -6
  7. package/esm/hooks/useAuthentication.js.map +1 -1
  8. package/esm/models/application/ApplicationModel.js +2 -3
  9. package/esm/models/application/ApplicationModel.js.map +1 -1
  10. package/esm/models/attributes/ChoiceAttributeOptionCollection.js +3 -12
  11. package/esm/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
  12. package/esm/models/attributes/UploadAttributeModel.js +15 -3
  13. package/esm/models/attributes/UploadAttributeModel.js.map +1 -1
  14. package/esm/models/error/ErrorModel.js +11 -0
  15. package/esm/models/error/ErrorModel.js.map +1 -1
  16. package/esm/models/href/Href.js +4 -4
  17. package/esm/models/href/Href.js.map +1 -1
  18. package/esm/modularui/Authenticate.js +6 -6
  19. package/esm/modularui/Authenticate.js.map +1 -1
  20. package/esm/modularui/CaptchaRequest.js +46 -0
  21. package/esm/modularui/CaptchaRequest.js.map +1 -0
  22. package/esm/modularui/ModularUIRequest.js +48 -6
  23. package/esm/modularui/ModularUIRequest.js.map +1 -1
  24. package/esm/modularui/UploadRequest.js +104 -0
  25. package/esm/modularui/UploadRequest.js.map +1 -0
  26. package/esm/modularui/index.js +2 -0
  27. package/esm/modularui/index.js.map +1 -1
  28. package/esm/react-client/client.js +2 -2
  29. package/esm/react-client/client.js.map +1 -1
  30. package/esm/react-server/contextPath.js +2 -2
  31. package/esm/react-server/contextPath.js.map +1 -1
  32. package/esm/react-server/renderSSRComplete.js +5 -4
  33. package/esm/react-server/renderSSRComplete.js.map +1 -1
  34. package/esm/react-server/renderSSRMinimal.js +2 -2
  35. package/esm/react-server/renderSSRMinimal.js.map +1 -1
  36. package/esm/react-server/serverNoSSR.js +2 -1
  37. package/esm/react-server/serverNoSSR.js.map +1 -1
  38. package/esm/react-server/serverUtil.js +31 -5
  39. package/esm/react-server/serverUtil.js.map +1 -1
  40. package/esm/redux/_modularui/ModularUIActions.js +7 -0
  41. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  42. package/esm/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  43. package/esm/redux/_modularui/ModularUIReducer.js +21 -1
  44. package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
  45. package/esm/redux/_modularui/types.js.map +1 -1
  46. package/esm/redux/store/configureStore.js +1 -1
  47. package/esm/redux/store/configureStore.js.map +1 -1
  48. package/esm/redux/types.js.map +1 -1
  49. package/esm/utils/browser/Cookies.js +6 -7
  50. package/esm/utils/browser/Cookies.js.map +1 -1
  51. package/esm/utils/fetch/serverFetch.js +2 -2
  52. package/esm/utils/fetch/serverFetch.js.map +1 -1
  53. package/esm/utils/fetch/types.js.map +1 -1
  54. package/esm/utils/fetch/universalFetch.js +4 -3
  55. package/esm/utils/fetch/universalFetch.js.map +1 -1
  56. package/esm/utils/fetch/xhr.js.map +1 -1
  57. package/esm/utils/helpers/checkResource.js +0 -3
  58. package/esm/utils/helpers/checkResource.js.map +1 -1
  59. package/esm/utils/helpers/index.js +8 -0
  60. package/esm/utils/helpers/index.js.map +1 -0
  61. package/esm/utils/helpers/repositoryResource.js +18 -0
  62. package/esm/utils/helpers/repositoryResource.js.map +1 -0
  63. package/esm/utils/index.js +1 -6
  64. package/esm/utils/index.js.map +1 -1
  65. package/lib/constants/Constants.js +13 -42
  66. package/lib/constants/Constants.js.flow +9 -41
  67. package/lib/constants/Constants.js.map +1 -1
  68. package/lib/constants/Settings.js +53 -1
  69. package/lib/constants/Settings.js.flow +60 -0
  70. package/lib/constants/Settings.js.map +1 -1
  71. package/lib/hooks/useAuthentication.js +6 -5
  72. package/lib/hooks/useAuthentication.js.flow +9 -8
  73. package/lib/hooks/useAuthentication.js.map +1 -1
  74. package/lib/models/application/ApplicationModel.js +1 -1
  75. package/lib/models/application/ApplicationModel.js.flow +3 -2
  76. package/lib/models/application/ApplicationModel.js.map +1 -1
  77. package/lib/models/attributes/ChoiceAttributeOptionCollection.js +3 -12
  78. package/lib/models/attributes/ChoiceAttributeOptionCollection.js.flow +3 -17
  79. package/lib/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
  80. package/lib/models/attributes/UploadAttributeModel.js +15 -3
  81. package/lib/models/attributes/UploadAttributeModel.js.flow +21 -0
  82. package/lib/models/attributes/UploadAttributeModel.js.map +1 -1
  83. package/lib/models/error/ErrorModel.js +11 -0
  84. package/lib/models/error/ErrorModel.js.flow +12 -1
  85. package/lib/models/error/ErrorModel.js.map +1 -1
  86. package/lib/models/href/Href.js +6 -6
  87. package/lib/models/href/Href.js.flow +4 -4
  88. package/lib/models/href/Href.js.map +1 -1
  89. package/lib/models/href/__tests__/Href.spec.js.flow +2 -3
  90. package/lib/modularui/Authenticate.js +4 -4
  91. package/lib/modularui/Authenticate.js.flow +6 -5
  92. package/lib/modularui/Authenticate.js.map +1 -1
  93. package/lib/modularui/CaptchaRequest.js +54 -0
  94. package/lib/modularui/CaptchaRequest.js.flow +45 -0
  95. package/lib/modularui/CaptchaRequest.js.map +1 -0
  96. package/lib/modularui/ModularUIRequest.js +46 -4
  97. package/lib/modularui/ModularUIRequest.js.flow +49 -10
  98. package/lib/modularui/ModularUIRequest.js.map +1 -1
  99. package/lib/modularui/UploadRequest.js +112 -0
  100. package/lib/modularui/UploadRequest.js.flow +125 -0
  101. package/lib/modularui/UploadRequest.js.map +1 -0
  102. package/lib/modularui/index.js +14 -0
  103. package/lib/modularui/index.js.flow +2 -0
  104. package/lib/modularui/index.js.map +1 -1
  105. package/lib/react-client/client.js +2 -2
  106. package/lib/react-client/client.js.flow +2 -2
  107. package/lib/react-client/client.js.map +1 -1
  108. package/lib/react-server/contextPath.js +2 -2
  109. package/lib/react-server/contextPath.js.flow +2 -2
  110. package/lib/react-server/contextPath.js.map +1 -1
  111. package/lib/react-server/renderSSRComplete.js +5 -4
  112. package/lib/react-server/renderSSRComplete.js.flow +6 -4
  113. package/lib/react-server/renderSSRComplete.js.map +1 -1
  114. package/lib/react-server/renderSSRMinimal.js +2 -2
  115. package/lib/react-server/renderSSRMinimal.js.flow +2 -2
  116. package/lib/react-server/renderSSRMinimal.js.map +1 -1
  117. package/lib/react-server/serverNoSSR.js +1 -0
  118. package/lib/react-server/serverNoSSR.js.flow +5 -0
  119. package/lib/react-server/serverNoSSR.js.map +1 -1
  120. package/lib/react-server/serverUtil.js +32 -5
  121. package/lib/react-server/serverUtil.js.flow +40 -6
  122. package/lib/react-server/serverUtil.js.map +1 -1
  123. package/lib/redux/_modularui/ModularUIActions.js +9 -1
  124. package/lib/redux/_modularui/ModularUIActions.js.flow +10 -0
  125. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  126. package/lib/redux/_modularui/ModularUIMiddleware.js.flow +1 -1
  127. package/lib/redux/_modularui/ModularUIMiddleware.js.map +1 -1
  128. package/lib/redux/_modularui/ModularUIReducer.js +21 -1
  129. package/lib/redux/_modularui/ModularUIReducer.js.flow +22 -0
  130. package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
  131. package/lib/redux/_modularui/types.js.flow +9 -1
  132. package/lib/redux/_modularui/types.js.map +1 -1
  133. package/lib/redux/store/configureStore.js +1 -1
  134. package/lib/redux/store/configureStore.js.flow +1 -1
  135. package/lib/redux/store/configureStore.js.map +1 -1
  136. package/lib/redux/types.js.flow +2 -0
  137. package/lib/redux/types.js.map +1 -1
  138. package/lib/utils/browser/Cookies.js +3 -3
  139. package/lib/utils/browser/Cookies.js.flow +10 -8
  140. package/lib/utils/browser/Cookies.js.map +1 -1
  141. package/lib/utils/fetch/serverFetch.js +2 -2
  142. package/lib/utils/fetch/serverFetch.js.flow +2 -2
  143. package/lib/utils/fetch/serverFetch.js.map +1 -1
  144. package/lib/utils/fetch/types.js.flow +1 -1
  145. package/lib/utils/fetch/types.js.map +1 -1
  146. package/lib/utils/fetch/universalFetch.js +3 -2
  147. package/lib/utils/fetch/universalFetch.js.flow +5 -3
  148. package/lib/utils/fetch/universalFetch.js.map +1 -1
  149. package/lib/utils/fetch/xhr.js.flow +1 -1
  150. package/lib/utils/fetch/xhr.js.map +1 -1
  151. package/lib/utils/helpers/checkResource.js +0 -3
  152. package/lib/utils/helpers/checkResource.js.flow +0 -2
  153. package/lib/utils/helpers/checkResource.js.map +1 -1
  154. package/lib/utils/helpers/index.js +90 -0
  155. package/lib/utils/helpers/index.js.flow +8 -0
  156. package/lib/utils/helpers/index.js.map +1 -0
  157. package/lib/utils/helpers/repositoryResource.js +25 -0
  158. package/lib/utils/helpers/repositoryResource.js.flow +20 -0
  159. package/lib/utils/helpers/repositoryResource.js.map +1 -0
  160. package/lib/utils/index.js +4 -60
  161. package/lib/utils/index.js.flow +1 -6
  162. package/lib/utils/index.js.map +1 -1
  163. package/package.json +1 -1
  164. package/src/constants/Constants.js +9 -41
  165. package/src/constants/Settings.js +60 -0
  166. package/src/hooks/useAuthentication.js +9 -8
  167. package/src/models/application/ApplicationModel.js +3 -2
  168. package/src/models/attributes/ChoiceAttributeOptionCollection.js +3 -17
  169. package/src/models/attributes/UploadAttributeModel.js +21 -0
  170. package/src/models/error/ErrorModel.js +12 -1
  171. package/src/models/href/Href.js +4 -4
  172. package/src/models/href/__tests__/Href.spec.js +2 -3
  173. package/src/modularui/Authenticate.js +6 -5
  174. package/src/modularui/CaptchaRequest.js +45 -0
  175. package/src/modularui/ModularUIRequest.js +49 -10
  176. package/src/modularui/UploadRequest.js +125 -0
  177. package/src/modularui/index.js +2 -0
  178. package/src/react-client/client.js +2 -2
  179. package/src/react-server/contextPath.js +2 -2
  180. package/src/react-server/renderSSRComplete.js +6 -4
  181. package/src/react-server/renderSSRMinimal.js +2 -2
  182. package/src/react-server/serverNoSSR.js +5 -0
  183. package/src/react-server/serverUtil.js +40 -6
  184. package/src/redux/_modularui/ModularUIActions.js +10 -0
  185. package/src/redux/_modularui/ModularUIMiddleware.js +1 -1
  186. package/src/redux/_modularui/ModularUIReducer.js +22 -0
  187. package/src/redux/_modularui/types.js +9 -1
  188. package/src/redux/store/configureStore.js +1 -1
  189. package/src/redux/types.js +2 -0
  190. package/src/utils/browser/Cookies.js +10 -8
  191. package/src/utils/fetch/serverFetch.js +2 -2
  192. package/src/utils/fetch/types.js +1 -1
  193. package/src/utils/fetch/universalFetch.js +5 -3
  194. package/src/utils/fetch/xhr.js +1 -1
  195. package/src/utils/helpers/checkResource.js +0 -2
  196. package/src/utils/helpers/index.js +8 -0
  197. package/src/utils/helpers/repositoryResource.js +20 -0
  198. package/src/utils/index.js +1 -6
  199. package/types/constants/Constants.d.ts +8 -24
  200. package/types/constants/Settings.d.ts +12 -0
  201. package/types/models/attributes/ChoiceAttributeOptionCollection.d.ts +0 -3
  202. package/types/models/attributes/UploadAttributeModel.d.ts +6 -0
  203. package/types/models/error/ErrorModel.d.ts +5 -0
  204. package/types/models/href/Href.d.ts +1 -1
  205. package/types/modularui/CaptchaRequest.d.ts +17 -0
  206. package/types/modularui/ModularUIRequest.d.ts +13 -0
  207. package/types/modularui/UploadRequest.d.ts +29 -0
  208. package/types/modularui/index.d.ts +2 -0
  209. package/types/redux/_modularui/types.d.ts +9 -3
  210. package/types/redux/types.d.ts +1 -1
  211. package/types/utils/browser/Cookies.d.ts +0 -6
  212. package/types/utils/fetch/types.d.ts +2 -3
  213. package/types/utils/helpers/index.d.ts +7 -0
  214. package/types/utils/helpers/repositoryResource.d.ts +1 -0
  215. package/types/utils/index.d.ts +1 -6
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import { BASE, CONTENT_PATH, HTTP_METHODS } from "../../constants/Constants";
2
+ import { getBasePath, HTTP_METHODS, CONTENT_PATH } from "../../constants";
3
3
 
4
4
  import Parameter from "../parameter/Parameter";
5
5
  import { IllegalArgumentException } from "../../exceptions";
@@ -341,14 +341,14 @@ class Href {
341
341
  }
342
342
 
343
343
  /**
344
- * Retrieve the path combined with the BASE of the application, e.g. /BeInformed
344
+ * Retrieve the path combined with the base path (context-path) of the application, e.g. /BeInformed
345
345
  */
346
346
  get absolutepath(): string {
347
347
  if (this.isExternal) {
348
348
  return this.path;
349
349
  }
350
350
 
351
- return BASE + this.path;
351
+ return getBasePath() + this.path;
352
352
  }
353
353
 
354
354
  /**
@@ -433,7 +433,7 @@ class Href {
433
433
  * Indicates if the link is a content link
434
434
  */
435
435
  get isContent(): boolean {
436
- return this.absolutepath.startsWith(CONTENT_PATH);
436
+ return this.absolutepath.startsWith(`${getBasePath()}${CONTENT_PATH}`);
437
437
  }
438
438
 
439
439
  /**
@@ -1,4 +1,4 @@
1
- import { BASE, APPLICATION_PATH } from "../../../constants";
1
+ import { getBasePath } from "../../../constants";
2
2
  import Href from "../Href";
3
3
 
4
4
  describe("href spec", () => {
@@ -140,8 +140,7 @@ describe("href spec", () => {
140
140
  });
141
141
 
142
142
  it("a tab can have the same uri as the contextPath", () => {
143
- expect(BASE).toBe("/BeInformed");
144
- expect(APPLICATION_PATH).toBe("/BeInformed/");
143
+ expect(getBasePath()).toBe("/BeInformed");
145
144
 
146
145
  const tabHref = new Href("/BeInformed");
147
146
 
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import { BASE, HTTP_METHODS } from "../constants/Constants";
2
+ import { HTTP_METHODS } from "../constants/Constants";
3
3
 
4
4
  import universalFetch from "../utils/fetch/universalFetch";
5
5
  import Cache from "../utils/browser/Cache";
@@ -11,6 +11,7 @@ import {
11
11
  loginPasswordField,
12
12
  loginUsernameField,
13
13
  logoutPath,
14
+ getBasePath,
14
15
  } from "../constants";
15
16
 
16
17
  /**
@@ -57,7 +58,7 @@ class Authenticate {
57
58
  */
58
59
  requestLogin(): Promise<any> {
59
60
  return universalFetch({
60
- url: `${BASE}/login`,
61
+ url: `${getBasePath()}/login`,
61
62
  method: HTTP_METHODS.GET,
62
63
  headers: {
63
64
  Accept: "application/json",
@@ -104,9 +105,9 @@ class Authenticate {
104
105
  switch (this.authenticationType) {
105
106
  case "PAC4J_BASIC":
106
107
  case "PAC4J_FORM":
107
- return `${BASE}${loginPath()}`;
108
+ return `${getBasePath()}${loginPath()}`;
108
109
  default:
109
- return `${BASE}/j_security_check`;
110
+ return `${getBasePath()}/j_security_check`;
110
111
  }
111
112
  }
112
113
 
@@ -161,7 +162,7 @@ class Authenticate {
161
162
  */
162
163
  logout(): Promise<any> {
163
164
  return universalFetch({
164
- url: `${BASE}${logoutPath()}`,
165
+ url: `${getBasePath()}${logoutPath()}`,
165
166
  }).then((response) => {
166
167
  // clear cache because of cached contributions
167
168
  Cache.clear();
@@ -0,0 +1,45 @@
1
+ // @flow
2
+ import xhr from "../utils/fetch/xhr";
3
+ import { getCaptchaPath, HTTP_METHODS } from "../constants";
4
+
5
+ type CaptchaResponse = {
6
+ tokenId: string,
7
+ image: any,
8
+ valid: boolean,
9
+ };
10
+
11
+ /**
12
+ */
13
+ class CaptchaRequest {
14
+ #tokenId: string;
15
+
16
+ /**
17
+ */
18
+ init(): Promise<CaptchaResponse> {
19
+ return xhr({
20
+ url: getCaptchaPath(),
21
+ }).then((response) => {
22
+ this.#tokenId = response.tokenId;
23
+
24
+ return response;
25
+ });
26
+ }
27
+
28
+ /**
29
+ */
30
+ send(answer: string): Promise<CaptchaResponse> {
31
+ return xhr({
32
+ url: getCaptchaPath(),
33
+ method: HTTP_METHODS.POST,
34
+ data: {
35
+ tokenId: this.#tokenId ?? "",
36
+ answer: answer ?? "",
37
+ },
38
+ }).catch((error) => {
39
+ this.#tokenId = error.response.tokenId;
40
+ return error.response;
41
+ });
42
+ }
43
+ }
44
+
45
+ export default CaptchaRequest;
@@ -1,15 +1,11 @@
1
1
  // @flow
2
2
  import deepmerge from "deepmerge";
3
3
 
4
- import {
5
- BASE,
6
- HTTP_METHODS,
7
- TIMEVERSION_FILTER_NAME,
8
- } from "../constants/Constants";
4
+ import { HTTP_METHODS, TIMEVERSION_FILTER_NAME } from "../constants/Constants";
9
5
 
10
6
  import { HIDE_WHEN_EMPTY } from "../constants/LayoutHints";
11
7
 
12
- import { getSetting } from "../constants/Settings";
8
+ import { getBasePath, getSetting } from "../constants/Settings";
13
9
 
14
10
  import Href from "../models/href/Href";
15
11
 
@@ -49,6 +45,8 @@ class ModularUIRequest {
49
45
 
50
46
  _progressEvent: ProgressEventHandler;
51
47
 
48
+ #basePath: string = "/BeInformed";
49
+
52
50
  /**
53
51
  */
54
52
  constructor(
@@ -61,6 +59,8 @@ class ModularUIRequest {
61
59
  );
62
60
  }
63
61
 
62
+ this.#basePath = getBasePath();
63
+
64
64
  this.options = options;
65
65
 
66
66
  this._response = new ModularUIResponse();
@@ -331,7 +331,7 @@ class ModularUIRequest {
331
331
  }
332
332
 
333
333
  return universalFetch({
334
- url: `${BASE}${this.contributionsHref}`,
334
+ url: `${this.#basePath}${this.contributionsHref}`,
335
335
  cache: true,
336
336
  locale: this.options.locale,
337
337
  });
@@ -342,7 +342,7 @@ class ModularUIRequest {
342
342
  fetchDataService(): Promise<any> {
343
343
  return universalFetch({
344
344
  ...this.requestOptions,
345
- url: `${BASE}${this.href.path}`,
345
+ url: `${this.#basePath}${this.href.path}`,
346
346
  params: this.href.getQuerystringForModularUI(),
347
347
  locale: this.options.locale,
348
348
  onProgress: this.onProgress,
@@ -519,7 +519,7 @@ class ModularUIRequest {
519
519
 
520
520
  return universalFetch({
521
521
  ...this.requestOptions,
522
- url: `${BASE}${href}`,
522
+ url: `${this.#basePath}${href}`,
523
523
  })
524
524
  .then((response: Object) => {
525
525
  if (isPlainObject(response)) {
@@ -587,7 +587,7 @@ class ModularUIRequest {
587
587
  const validationHref = this.href.setParameter("commit", "false");
588
588
  return universalFetch({
589
589
  ...this.requestOptions,
590
- url: `${BASE}${this.href.path}`,
590
+ url: `${this.#basePath}${this.href.path}`,
591
591
  params: validationHref.getQuerystringForModularUI(),
592
592
  data: this.getDynamicValidationData(model),
593
593
  }).then((data) => {
@@ -763,6 +763,45 @@ class ModularUIRequest {
763
763
  return form.update(response);
764
764
  });
765
765
  }
766
+
767
+ /**
768
+ * Simplified synchronous version of fetch (returns the model, not a Promise)
769
+ * This can be used on the server to retrieve a model. It only loads the request url and it's child models
770
+ */
771
+ fetchSync(): ModularUIModel {
772
+ const options = { headers: { "Accept-Language": this.locale } };
773
+
774
+ const dataString = dataFetcher.fetch(this.href.toString(), options);
775
+ if (dataString == null) {
776
+ throw new Error(`No data received for ${this.href.toString()}`);
777
+ }
778
+
779
+ this.processDataService(JSON.parse(dataString));
780
+
781
+ const contributionsString = dataFetcher.fetch(
782
+ this.contributionsHref.toString(),
783
+ options
784
+ );
785
+ if (contributionsString == null) {
786
+ throw new Error(
787
+ `No constributions received for ${this.contributionsHref.toString()}`
788
+ );
789
+ }
790
+ this.processContributionsService(JSON.parse(contributionsString));
791
+
792
+ const model = this.createModel();
793
+
794
+ const childModelLinks = model.getInitialChildModelLinks();
795
+
796
+ const childModels = childModelLinks.map((childModelLink) => {
797
+ return new ModularUIRequest(childModelLink.href, {
798
+ locale: this.locale,
799
+ }).fetchSync();
800
+ });
801
+ model.addChildModels(childModels);
802
+
803
+ return model;
804
+ }
766
805
  }
767
806
 
768
807
  export default ModularUIRequest;
@@ -0,0 +1,125 @@
1
+ // @flow
2
+ import { getUploadPath, HTTP_METHODS } from "../constants";
3
+
4
+ import xhr from "../utils/fetch/xhr";
5
+
6
+ import type {
7
+ FilesizeConstraintsType,
8
+ FiletypeConstraintsType,
9
+ } from "../models";
10
+ import ErrorModel from "../models/error/ErrorModel";
11
+
12
+ type ProgressHandler = (file: File, uploadInfo: Object) => void;
13
+
14
+ type UploadResponse = {
15
+ token: string,
16
+ };
17
+
18
+ /**
19
+ * Upload a file to the upload file service of Be Informed
20
+ */
21
+ class UploadRequest {
22
+ #uploadConstraints: {
23
+ fileTypes: FiletypeConstraintsType,
24
+ maxFileSize: FilesizeConstraintsType,
25
+ };
26
+ #progressHandler: ProgressHandler;
27
+
28
+ constructor(
29
+ uploadConstraints: {
30
+ fileTypes: FiletypeConstraintsType,
31
+ maxFileSize: FilesizeConstraintsType,
32
+ },
33
+ progressHandler: ProgressHandler
34
+ ) {
35
+ this.#uploadConstraints = uploadConstraints;
36
+ this.#progressHandler = progressHandler;
37
+ }
38
+
39
+ /**
40
+ */
41
+ getFileExtension(file: File): string {
42
+ return file.name.split(".").pop().toLowerCase();
43
+ }
44
+
45
+ /**
46
+ */
47
+ isNotAllowedFileType(file: File): boolean {
48
+ const allowedFileTypes = this.#uploadConstraints.fileTypes;
49
+
50
+ if (allowedFileTypes.length > 0) {
51
+ const fileExtension = this.getFileExtension(file);
52
+
53
+ return !allowedFileTypes.some((fileType) =>
54
+ fileType.extensions.includes(fileExtension)
55
+ );
56
+ }
57
+
58
+ return false;
59
+ }
60
+
61
+ /**
62
+ */
63
+ exceedsMaxFileSize(file: File): boolean {
64
+ const maxFileSize = this.#uploadConstraints?.maxFileSize?.fileSize ?? -1;
65
+ return maxFileSize > -1 && file.size > maxFileSize;
66
+ }
67
+
68
+ /**
69
+ */
70
+ uploadFile(file: File): Promise<UploadResponse> {
71
+ const maxFileSize = this.#uploadConstraints?.maxFileSize?.fileSize ?? -1;
72
+
73
+ if (this.exceedsMaxFileSize(file)) {
74
+ this.#progressHandler(file, { error: "errorExceedsMaxFileSize" });
75
+ return Promise.reject(
76
+ new ErrorModel(
77
+ "Constraint.File.MaxFileSizeExceeded",
78
+ "Maximum file upload size is ${max-filesize}",
79
+ {
80
+ "max-filesize": maxFileSize,
81
+ },
82
+ true
83
+ )
84
+ );
85
+ }
86
+
87
+ if (this.isNotAllowedFileType(file)) {
88
+ this.#progressHandler(file, { error: "errorExtensionNotAllowed" });
89
+ return Promise.reject(
90
+ new ErrorModel(
91
+ "Constraint.File.InvalidExtension",
92
+ "Allowed extensions are: ${extensions}",
93
+ {
94
+ extension: this.getFileExtension(file),
95
+ extensions: this.#uploadConstraints.fileTypes.join(", "),
96
+ },
97
+ true
98
+ )
99
+ );
100
+ }
101
+
102
+ return xhr({
103
+ url: getUploadPath(),
104
+ method: HTTP_METHODS.POST,
105
+ headers: {
106
+ "Content-Type": file.type,
107
+ "x-filename": encodeURIComponent(file.name),
108
+ "x-filesize": file.size.toString(),
109
+ },
110
+ onProgress: (e: ProgressEvent) => {
111
+ if (this.#progressHandler && e.lengthComputable) {
112
+ this.#progressHandler(file, {
113
+ progress: Math.ceil((e.loaded / e.total) * 100),
114
+ });
115
+ }
116
+ },
117
+ data: file,
118
+ }).then((response) => {
119
+ this.#progressHandler(file, { progress: 100, token: response.token });
120
+ return response;
121
+ });
122
+ }
123
+ }
124
+
125
+ export default UploadRequest;
@@ -2,3 +2,5 @@
2
2
  export { default as Authenticate } from "./Authenticate";
3
3
  export { default as ModularUIRequest } from "./ModularUIRequest";
4
4
  export { default as ModularUIResponse } from "./ModularUIResponse";
5
+ export { default as UploadRequest } from "./UploadRequest";
6
+ export { default as CaptchaRequest } from "./CaptchaRequest";
@@ -17,7 +17,7 @@ import { createBrowserHistory } from "history";
17
17
  import configureStore from "../redux/store/configureStore";
18
18
 
19
19
  import rehydrate from "./rehydrate";
20
- import { BASE } from "../constants/Constants";
20
+ import { getBasePath } from "../constants/Settings";
21
21
 
22
22
  import {
23
23
  setAllContentInDataSetting,
@@ -87,7 +87,7 @@ const client = (props: Props) => {
87
87
 
88
88
  // $FlowExpectedError
89
89
  const browserHistory: RouterHistory = createBrowserHistory({
90
- basename: BASE,
90
+ basename: getBasePath(),
91
91
  });
92
92
  const { history, store } = configureStore(
93
93
  browserHistory,
@@ -1,8 +1,8 @@
1
1
  // @flow
2
- import { BASE } from "../constants/Constants";
2
+ import { getBasePath } from "../constants/Settings";
3
3
 
4
4
  (function x() {
5
- __webpack_public_path__ = `${BASE}/`; // NOSONAR
5
+ __webpack_public_path__ = `${getBasePath()}/`; // NOSONAR
6
6
  })();
7
7
 
8
8
  export {};
@@ -10,7 +10,7 @@ import { ServerStyleSheet, StyleSheetManager } from "styled-components";
10
10
  import createSSRComplete from "./createSSRComplete";
11
11
  import htmlpage from "./htmlpage";
12
12
 
13
- import { BASE } from "../constants/Constants";
13
+ import { getBasePath } from "../constants/Settings";
14
14
 
15
15
  import ThemeProvider from "../react-theme/ThemeProvider";
16
16
  import ErrorBoundary from "../react/ErrorBoundary";
@@ -52,6 +52,8 @@ const renderSSRComplete = ({
52
52
  // $FlowFixMe[prop-missing]
53
53
  const location: Location = requestHref.toLocation();
54
54
 
55
+ const basePath = getBasePath();
56
+
55
57
  return createSSRComplete(store, () =>
56
58
  renderToString(
57
59
  <Provider store={store}>
@@ -60,7 +62,7 @@ const renderSSRComplete = ({
60
62
  <HelmetProvider context={helmetContext}>
61
63
  <ErrorBoundary>
62
64
  <Router
63
- basename={BASE}
65
+ basename={basePath}
64
66
  location={location}
65
67
  context={routerContext}
66
68
  >
@@ -77,7 +79,7 @@ const renderSSRComplete = ({
77
79
  handleErrors(store);
78
80
  const head = createHead(sheet, UUID, helmetContext);
79
81
  return template({
80
- contextPath: BASE,
82
+ contextPath: basePath,
81
83
  html: appHTML,
82
84
  head,
83
85
  state: dehydrate(store),
@@ -86,7 +88,7 @@ const renderSSRComplete = ({
86
88
  })
87
89
  .catch((error) =>
88
90
  template({
89
- contextPath: BASE,
91
+ contextPath: basePath,
90
92
  html: renderToString(
91
93
  <StyleSheetManager sheet={sheet.instance}>
92
94
  <ThemeProvider theme={theme}>
@@ -6,7 +6,7 @@ import { Provider } from "react-redux";
6
6
  import { ServerStyleSheet, StyleSheetManager } from "styled-components";
7
7
  import ThemeProvider from "../react-theme/ThemeProvider";
8
8
 
9
- import { BASE } from "../constants/Constants";
9
+ import { getBasePath } from "../constants/Settings";
10
10
 
11
11
  import { createHead, dehydrate } from "./serverUtil";
12
12
  import htmlpage from "./htmlpage";
@@ -43,7 +43,7 @@ const renderSSRMinimal = ({
43
43
 
44
44
  const head = createHead(sheet, UUID);
45
45
  return template({
46
- contextPath: BASE,
46
+ contextPath: getBasePath(),
47
47
  html: appHTML,
48
48
  head,
49
49
  state: dehydrate(store),
@@ -7,6 +7,7 @@ import { getFullRequestHref } from "./requestInformation";
7
7
  import {
8
8
  createReduxStore,
9
9
  setI18n,
10
+ setApplication,
10
11
  setServerPreferences,
11
12
  setConfigurationTheme,
12
13
  handleErrors,
@@ -23,6 +24,7 @@ import type { BeforeRenderHook } from "../redux/store/beforeRenderHooks";
23
24
  import type { PreferenceValue } from "./serverUtil";
24
25
  import type { LocaleConfiguration } from "../i18n/types";
25
26
  import type { Theme } from "../react-theme/types";
27
+
26
28
  type serverProps = {
27
29
  request: HttpServletRequestJava,
28
30
  locales?: Array<LocaleConfiguration>,
@@ -50,6 +52,7 @@ const serverNoSSR = ({
50
52
  __webpack_nonce__ = UUID; // NOSONAR
51
53
 
52
54
  const requestHref = getFullRequestHref(request);
55
+
53
56
  const store = createReduxStore(requestHref, customReducers);
54
57
 
55
58
  setServerPreferences(store, serverPreferences);
@@ -63,6 +66,8 @@ const serverNoSSR = ({
63
66
 
64
67
  setI18n(store, locales, request);
65
68
 
69
+ setApplication(store);
70
+
66
71
  handleErrors(store);
67
72
 
68
73
  handleBeforeRenderHooks(beforeRenderHooks, { store, request });
@@ -23,8 +23,13 @@ import { getSetting } from "../constants/Settings";
23
23
 
24
24
  import { IllegalArgumentException } from "../exceptions";
25
25
 
26
+ import { initModels } from "../redux";
27
+ import { getLocale } from "../redux/selectors/i18n";
28
+
29
+ import ModularUIRequest from "../modularui/ModularUIRequest";
30
+
26
31
  import type { LocaleConfiguration } from "../i18n/types";
27
- import type { ReduxStore } from "../redux/types";
32
+ import type { ReduxState, ReduxStore } from "../redux/types";
28
33
  import type Href from "../models/href/Href";
29
34
  import type { RouterHistory } from "react-router";
30
35
 
@@ -38,14 +43,15 @@ export type PreferenceValue = {
38
43
  */
39
44
  const createReduxStore = (
40
45
  requestHref: Href,
41
- customReducers: Object
46
+ customReducers: Object,
47
+ initialState?: $Shape<ReduxState>
42
48
  ): ReduxStore => {
43
49
  // $FlowExpectedError
44
50
  const history: RouterHistory = createMemoryHistory({
45
51
  initialEntries: [requestHref.toString()],
46
52
  });
47
53
 
48
- const { store } = configureStore(history, customReducers);
54
+ const { store } = configureStore(history, customReducers, initialState);
49
55
 
50
56
  return store;
51
57
  };
@@ -161,6 +167,29 @@ const setConfigurationTheme = (store: ReduxStore) => {
161
167
  }
162
168
  };
163
169
 
170
+ /**
171
+ */
172
+ const setApplication = (store: ReduxStore) => {
173
+ try {
174
+ const locale = getLocale(store.getState());
175
+ const application = new ModularUIRequest("/", {
176
+ locale: locale,
177
+ }).fetchSync();
178
+
179
+ store.dispatch(
180
+ initModels([
181
+ {
182
+ key: `application(/)(${locale})`,
183
+ model: application,
184
+ },
185
+ ])
186
+ );
187
+ } catch (e) {
188
+ // eslint-disable-next-line no-console
189
+ console.info("Could not load webapplication on server");
190
+ }
191
+ };
192
+
164
193
  /**
165
194
  */
166
195
  const handleErrors = (store: ReduxStore) => {
@@ -180,19 +209,23 @@ const handleErrors = (store: ReduxStore) => {
180
209
  const dehydrate = (store: ReduxStore): string => {
181
210
  const state = store.getState();
182
211
 
183
- const modularui: { [key: string]: { status: string, model: ?Object } } = {};
212
+ const modularui: {
213
+ [key: string]: { status: string, lastModification: number, model: ?Object },
214
+ } = {};
215
+
184
216
  for (const key in state.modularui) {
185
- const status = state.modularui[key].status;
186
- const model = state.modularui[key].model;
217
+ const { status, model, lastModification } = state.modularui[key];
187
218
 
188
219
  if (model) {
189
220
  modularui[key] = {
190
221
  status,
222
+ lastModification,
191
223
  model: model.dehydrate(),
192
224
  };
193
225
  } else {
194
226
  modularui[key] = {
195
227
  status,
228
+ lastModification,
196
229
  model: undefined,
197
230
  };
198
231
  }
@@ -233,6 +266,7 @@ const createHead = (
233
266
  export {
234
267
  createReduxStore,
235
268
  setI18n,
269
+ setApplication,
236
270
  setServerPreferences,
237
271
  setConfigurationTheme,
238
272
  createHead,
@@ -10,6 +10,7 @@ import type { Dispatch, ThunkAction } from "../types";
10
10
  import type {
11
11
  ModularUIAction,
12
12
  SetModelAction,
13
+ InitModelAction,
13
14
  UpdateModelAction,
14
15
  RemoveModelByKeyAction,
15
16
  ResetModularUIAction,
@@ -34,6 +35,15 @@ export const setModel = (
34
35
  };
35
36
  };
36
37
 
38
+ /**
39
+ */
40
+ export const initModels = (
41
+ models: Array<{ key: string, model: ModularUIModel }>
42
+ ): InitModelAction => ({
43
+ type: "MODULARUI/INIT",
44
+ payload: models,
45
+ });
46
+
37
47
  /**
38
48
  */
39
49
  export const updateModel = (model: ModularUIModel): UpdateModelAction => ({
@@ -21,7 +21,7 @@ import type { TargetModel } from "../../modularui/types";
21
21
  type RequestOptions = {
22
22
  href: Href,
23
23
  method?: $Keys<typeof HTTP_METHODS>,
24
- data?: string | { [key: string]: string },
24
+ data?: any,
25
25
  locale: string,
26
26
  childmodels?: boolean,
27
27
  targetModel?: TargetModel,
@@ -53,6 +53,25 @@ const setModel = (
53
53
  throw new IllegalArgumentException("No model for setModel");
54
54
  };
55
55
 
56
+ /**
57
+ */
58
+ const initModularUI = (
59
+ state: ModularUIState,
60
+ models: Array<{ key: string, model: ModularUIModel }>
61
+ ) => {
62
+ const newState = Object.assign({}, state);
63
+
64
+ models.forEach(({ key, model }) => {
65
+ newState[key] = {
66
+ status: MODULARUI_STATUS.FINISHED,
67
+ lastModification: Date.now(),
68
+ model,
69
+ };
70
+ });
71
+
72
+ return newState;
73
+ };
74
+
56
75
  /**
57
76
  */
58
77
  const getModelKey = (state: ModularUIState, model: ModularUIModel) =>
@@ -112,6 +131,9 @@ export const ModularUIReducer: Reducer<ModularUIState, ReduxAction> = (
112
131
  }
113
132
 
114
133
  switch (action.type) {
134
+ case "MODULARUI/INIT":
135
+ return initModularUI(state, action.payload);
136
+
115
137
  case "MODULARUI/RESET":
116
138
  return resetModularUI(state);
117
139