@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
@@ -15,16 +15,19 @@ import { setLocales } from "../redux/_i18n/I18nActions";
15
15
  import { setServerPreference, setThemePreference, setPreference, setAllContentInDataSetting, setLoginPreferences } from "../redux/actions/Preferences";
16
16
  import { getSetting } from "../constants/Settings";
17
17
  import { IllegalArgumentException } from "../exceptions";
18
+ import { initModels } from "../redux";
19
+ import { getLocale } from "../redux/selectors/i18n";
20
+ import ModularUIRequest from "../modularui/ModularUIRequest";
18
21
  /**
19
22
  */
20
- const createReduxStore = (requestHref, customReducers) => {
23
+ const createReduxStore = (requestHref, customReducers, initialState) => {
21
24
  // $FlowExpectedError
22
25
  const history = createMemoryHistory({
23
26
  initialEntries: [requestHref.toString()]
24
27
  });
25
28
  const {
26
29
  store
27
- } = configureStore(history, customReducers);
30
+ } = configureStore(history, customReducers, initialState);
28
31
  return store;
29
32
  };
30
33
 
@@ -116,6 +119,24 @@ const setConfigurationTheme = store => {
116
119
  }
117
120
  };
118
121
 
122
+ /**
123
+ */
124
+ const setApplication = store => {
125
+ try {
126
+ const locale = getLocale(store.getState());
127
+ const application = new ModularUIRequest("/", {
128
+ locale: locale
129
+ }).fetchSync();
130
+ store.dispatch(initModels([{
131
+ key: `application(/)(${locale})`,
132
+ model: application
133
+ }]));
134
+ } catch (e) {
135
+ // eslint-disable-next-line no-console
136
+ console.info("Could not load webapplication on server");
137
+ }
138
+ };
139
+
119
140
  /**
120
141
  */
121
142
  const handleErrors = store => {
@@ -131,16 +152,21 @@ const dehydrate = store => {
131
152
  const state = store.getState();
132
153
  const modularui = {};
133
154
  for (const key in state.modularui) {
134
- const status = state.modularui[key].status;
135
- const model = state.modularui[key].model;
155
+ const {
156
+ status,
157
+ model,
158
+ lastModification
159
+ } = state.modularui[key];
136
160
  if (model) {
137
161
  modularui[key] = {
138
162
  status,
163
+ lastModification,
139
164
  model: model.dehydrate()
140
165
  };
141
166
  } else {
142
167
  modularui[key] = {
143
168
  status,
169
+ lastModification,
144
170
  model: undefined
145
171
  };
146
172
  }
@@ -169,5 +195,5 @@ const createHead = (sheet, UUID, helmetContext) => {
169
195
  meta
170
196
  };
171
197
  };
172
- export { createReduxStore, setI18n, setServerPreferences, setConfigurationTheme, createHead, handleErrors, dehydrate };
198
+ export { createReduxStore, setI18n, setApplication, setServerPreferences, setConfigurationTheme, createHead, handleErrors, dehydrate };
173
199
  //# sourceMappingURL=serverUtil.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serverUtil.js","names":["createMemoryHistory","has","deepmerge","configureStore","availableLocales","Locales","getPreferredLocale","setLocales","setServerPreference","setThemePreference","setPreference","setAllContentInDataSetting","setLoginPreferences","getSetting","IllegalArgumentException","createReduxStore","requestHref","customReducers","history","initialEntries","toString","store","setI18n","locales","request","Array","isArray","mergedLocales","locale","code","customLocale","custLocale","forEach","some","push","enabledLocales","localesInstance","preferredLocale","dispatch","setServerPreferencesFromArray","serverPreferences","serverPreference","name","defaultValue","type","setServerPreferences","preferencesProvider","isStudioContext","setConfigurationTheme","configTheme","configFileLocation","getLayoutConfigFileLocation","configFilePath","dataFetcher","fetch","Error","handleErrors","state","getState","error","shouldThrowOnServer","dehydrate","modularui","key","status","model","undefined","filteredState","replace","createHead","sheet","UUID","helmetContext","style","getStyleTags","meta","helmet"],"sources":["../../src/react-server/serverUtil.js"],"sourcesContent":["// @flow\nimport { createMemoryHistory } from \"history\";\nimport { has } from \"../utils/helpers/objects\";\nimport deepmerge from \"deepmerge\";\n\nimport configureStore from \"../redux/store/configureStore\";\n\nimport { availableLocales } from \"../i18n/Locales\";\nimport Locales from \"../i18n/Locales\";\n\nimport { getPreferredLocale } from \"./requestInformation\";\nimport { setLocales } from \"../redux/_i18n/I18nActions\";\n\nimport {\n setServerPreference,\n setThemePreference,\n setPreference,\n setAllContentInDataSetting,\n setLoginPreferences,\n} from \"../redux/actions/Preferences\";\n\nimport { getSetting } from \"../constants/Settings\";\n\nimport { IllegalArgumentException } from \"../exceptions\";\n\nimport type { LocaleConfiguration } from \"../i18n/types\";\nimport type { ReduxStore } from \"../redux/types\";\nimport type Href from \"../models/href/Href\";\nimport type { RouterHistory } from \"react-router\";\n\nexport type PreferenceValue = {\n name: string,\n defaultValue?: string | null,\n type?: string,\n};\n\n/**\n */\nconst createReduxStore = (\n requestHref: Href,\n customReducers: Object\n): ReduxStore => {\n // $FlowExpectedError\n const history: RouterHistory = createMemoryHistory({\n initialEntries: [requestHref.toString()],\n });\n\n const { store } = configureStore(history, customReducers);\n\n return store;\n};\n\n/**\n */\nconst setI18n = (\n store: ReduxStore,\n locales: Array<LocaleConfiguration> = [],\n request: HttpServletRequestJava\n) => {\n if (!Array.isArray(locales)) {\n throw new IllegalArgumentException(\"locales must be an array of objects\");\n }\n if (!request) {\n throw new IllegalArgumentException(\"missing request argument\");\n }\n\n const mergedLocales = availableLocales.map((locale) => {\n const code = locale.code;\n const customLocale = locales.find((custLocale) => custLocale.code === code);\n\n if (customLocale) {\n return deepmerge(locale, customLocale);\n }\n\n return locale;\n });\n\n locales.forEach((customLocale) => {\n if (!mergedLocales.some((locale) => locale.code === customLocale.code)) {\n mergedLocales.push(customLocale);\n }\n });\n\n const enabledLocales = mergedLocales.filter((locale: LocaleConfiguration) =>\n getSetting(\"ENABLED_LOCALES\").includes(locale.code)\n );\n\n const localesInstance = new Locales(enabledLocales);\n const preferredLocale = getPreferredLocale(request, localesInstance);\n store.dispatch(setLocales(localesInstance, preferredLocale ?? \"en\"));\n};\n\nconst setServerPreferencesFromArray = (\n store: ReduxStore,\n serverPreferences: Array<string | PreferenceValue>\n) => {\n serverPreferences.forEach((serverPreference) => {\n if (typeof serverPreference === \"object\") {\n const { name, defaultValue, type } = serverPreference;\n store.dispatch(setServerPreference(name, defaultValue, type));\n } else {\n store.dispatch(setServerPreference(serverPreference, null));\n }\n });\n};\n\n/**\n * Server preferences can be suplied by an array of preference names,\n * or an array of objects which has the name, an optional default value and an optional type.<br>\n * When the type is set to string, a comma separated value is not converted to an array:\n *\n * @example\n * // value becomes an array [default1, default2]\n * { name: \"prefName\", defaultValue: \"default1, default2\" }\n * // value remains a string \"default1, default2\"\n * { name: \"prefName\", defaultValue: \"default1, default2\", type: \"string\" }\n *\n * @param store\n * @param serverPreferences\n */\nconst setServerPreferences = (\n store: ReduxStore,\n serverPreferences: Array<string | PreferenceValue>\n) => {\n if (Array.isArray(serverPreferences)) {\n setServerPreferencesFromArray(store, serverPreferences);\n }\n\n store.dispatch(setAllContentInDataSetting());\n store.dispatch(setLoginPreferences());\n\n if (\n preferencesProvider &&\n preferencesProvider.isStudioContext &&\n preferencesProvider.isStudioContext()\n ) {\n store.dispatch(setPreference(\"isStudioContext\", true));\n }\n};\n\n/**\n */\nconst setConfigurationTheme = (store: ReduxStore) => {\n let configTheme = null;\n\n const configFileLocation = preferencesProvider.getLayoutConfigFileLocation();\n if (typeof configFileLocation === \"string\") {\n const configFilePath = configFileLocation.startsWith(\"/\")\n ? `/resource${configFileLocation}`\n : `/resource/${configFileLocation}`;\n\n configTheme = dataFetcher.fetch(configFilePath);\n\n if (configTheme) {\n store.dispatch(setThemePreference(configTheme));\n } else {\n throw new Error(\n `Could not read theme configuration file from: ${configFilePath}`\n );\n }\n }\n};\n\n/**\n */\nconst handleErrors = (store: ReduxStore) => {\n const state = store.getState();\n\n if (\n state.error &&\n (state.error.shouldThrowOnServer ||\n !has(state.error, \"shouldThrowOnServer\"))\n ) {\n throw state.error;\n }\n};\n\n/**\n */\nconst dehydrate = (store: ReduxStore): string => {\n const state = store.getState();\n\n const modularui: { [key: string]: { status: string, model: ?Object } } = {};\n for (const key in state.modularui) {\n const status = state.modularui[key].status;\n const model = state.modularui[key].model;\n\n if (model) {\n modularui[key] = {\n status,\n model: model.dehydrate(),\n };\n } else {\n modularui[key] = {\n status,\n model: undefined,\n };\n }\n }\n\n const filteredState = {\n ...state,\n modularui,\n };\n\n return JSON.stringify(filteredState).replace(/</g, \"\\\\u003c\");\n};\n\n/**\n */\nconst createHead = (\n sheet: any,\n UUID: string,\n helmetContext?: Object\n): Object => {\n const style = sheet.getStyleTags();\n const meta = helmetContext ? [...helmetContext.helmet.meta] : [];\n\n if (helmetContext) {\n return {\n ...helmetContext.helmet,\n style,\n meta,\n };\n }\n\n return {\n style,\n meta,\n };\n};\n\nexport {\n createReduxStore,\n setI18n,\n setServerPreferences,\n setConfigurationTheme,\n createHead,\n handleErrors,\n dehyd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AE;IACjB,OAAO;MACL,GAAGA,aAAa,CAACI,MAAM;MACvBH,KAAK;MACLE;IACF,CAAC;EACH;EAEA,OAAO;IACLF,KAAK;IACLE;EACF,CAAC;AACH,CAAC;AAED,SACE5D,gBAAgB,EAChBO,OAAO,EACPuB,oBAAoB,EACpBG,qBAAqB,EACrBqB,UAAU,EACVb,YAAY,EACZK,SAAS"}
1
+ {"version":3,"file":"serverUtil.js","names":["createMemoryHistory","has","deepmerge","configureStore","availableLocales","Locales","getPreferredLocale","setLocales","setServerPreference","setThemePreference","setPreference","setAllContentInDataSetting","setLoginPreferences","getSetting","IllegalArgumentException","initModels","getLocale","ModularUIRequest","createReduxStore","requestHref","customReducers","initialState","history","initialEntries","toString","store","setI18n","locales","request","Array","isArray","mergedLocales","locale","code","customLocale","custLocale","forEach","some","push","enabledLocales","localesInstance","preferredLocale","dispatch","setServerPreferencesFromArray","serverPreferences","serverPreference","name","defaultValue","type","setServerPreferences","preferencesProvider","isStudioContext","setConfigurationTheme","configTheme","configFileLocation","getLayoutConfigFileLocation","configFilePath","dataFetcher","fetch","Error","setApplication","getState","application","fetchSync","key","model","e","console","info","handleErrors","state","error","shouldThrowOnServer","dehydrate","modularui","status","lastModification","undefined","filteredState","replace","createHead","sheet","UUID","helmetContext","style","getStyleTags","meta","helmet"],"sources":["../../src/react-server/serverUtil.js"],"sourcesContent":["// @flow\nimport { createMemoryHistory } from \"history\";\nimport { has } from \"../utils/helpers/objects\";\nimport deepmerge from \"deepmerge\";\n\nimport configureStore from \"../redux/store/configureStore\";\n\nimport { availableLocales } from \"../i18n/Locales\";\nimport Locales from \"../i18n/Locales\";\n\nimport { getPreferredLocale } from \"./requestInformation\";\nimport { setLocales } from \"../redux/_i18n/I18nActions\";\n\nimport {\n setServerPreference,\n setThemePreference,\n setPreference,\n setAllContentInDataSetting,\n setLoginPreferences,\n} from \"../redux/actions/Preferences\";\n\nimport { getSetting } from \"../constants/Settings\";\n\nimport { IllegalArgumentException } from \"../exceptions\";\n\nimport { initModels } from \"../redux\";\nimport { getLocale } from \"../redux/selectors/i18n\";\n\nimport ModularUIRequest from \"../modularui/ModularUIRequest\";\n\nimport type { LocaleConfiguration } from \"../i18n/types\";\nimport type { ReduxState, ReduxStore } from \"../redux/types\";\nimport type Href from \"../models/href/Href\";\nimport type { RouterHistory } from \"react-router\";\n\nexport type PreferenceValue = {\n name: string,\n defaultValue?: string | null,\n type?: string,\n};\n\n/**\n */\nconst createReduxStore = (\n requestHref: Href,\n customReducers: Object,\n initialState?: $Shape<ReduxState>\n): ReduxStore => {\n // $FlowExpectedError\n const history: RouterHistory = createMemoryHistory({\n initialEntries: [requestHref.toString()],\n });\n\n const { store } = configureStore(history, customReducers, initialState);\n\n return store;\n};\n\n/**\n */\nconst setI18n = (\n store: ReduxStore,\n locales: Array<LocaleConfiguration> = [],\n request: HttpServletRequestJava\n) => {\n if (!Array.isArray(locales)) {\n throw new IllegalArgumentException(\"locales must be an array of objects\");\n }\n if (!request) {\n throw new IllegalArgumentException(\"missing request argument\");\n }\n\n const mergedLocales = availableLocales.map((locale) => {\n const code = locale.code;\n const customLocale = locales.find((custLocale) => custLocale.code === code);\n\n if (customLocale) {\n return deepmerge(locale, customLocale);\n }\n\n return locale;\n });\n\n locales.forEach((customLocale) => {\n if (!mergedLocales.some((locale) => locale.code === customLocale.code)) {\n mergedLocales.push(customLocale);\n }\n });\n\n const enabledLocales = mergedLocales.filter((locale: LocaleConfiguration) =>\n getSetting(\"ENABLED_LOCALES\").includes(locale.code)\n );\n\n const localesInstance = new Locales(enabledLocales);\n const preferredLocale = getPreferredLocale(request, localesInstance);\n store.dispatch(setLocales(localesInstance, preferredLocale ?? \"en\"));\n};\n\nconst setServerPreferencesFromArray = (\n store: ReduxStore,\n serverPreferences: Array<string | PreferenceValue>\n) => {\n serverPreferences.forEach((serverPreference) => {\n if (typeof serverPreference === \"object\") {\n const { name, defaultValue, type } = serverPreference;\n store.dispatch(setServerPreference(name, defaultValue, type));\n } else {\n store.dispatch(setServerPreference(serverPreference, null));\n }\n });\n};\n\n/**\n * Server preferences can be suplied by an array of preference names,\n * or an array of objects which has the name, an optional default value and an optional type.<br>\n * When the type is set to string, a comma separated value is not converted to an array:\n *\n * @example\n * // value becomes an array [default1, default2]\n * { name: \"prefName\", defaultValue: \"default1, default2\" }\n * // value remains a string \"default1, default2\"\n * { name: \"prefName\", defaultValue: \"default1, default2\", type: \"string\" }\n *\n * @param store\n * @param serverPreferences\n */\nconst setServerPreferences = (\n store: ReduxStore,\n serverPreferences: Array<string | PreferenceValue>\n) => {\n if (Array.isArray(serverPreferences)) {\n setServerPreferencesFromArray(store, serverPreferences);\n }\n\n store.dispatch(setAllContentInDataSetting());\n store.dispatch(setLoginPreferences());\n\n if (\n preferencesProvider &&\n preferencesProvider.isStudioContext &&\n preferencesProvider.isStudioContext()\n ) {\n store.dispatch(setPreference(\"isStudioContext\", true));\n }\n};\n\n/**\n */\nconst setConfigurationTheme = (store: ReduxStore) => {\n let configTheme = null;\n\n const configFileLocation = preferencesProvider.getLayoutConfigFileLocation();\n if (typeof configFileLocation === \"string\") {\n const configFilePath = configFileLocation.startsWith(\"/\")\n ? `/resource${configFileLocation}`\n : `/resource/${configFileLocation}`;\n\n configTheme = dataFetcher.fetch(configFilePath);\n\n if (configTheme) {\n store.dispatch(setThemePreference(configTheme));\n } else {\n throw new Error(\n `Could not read theme configuration file from: ${configFilePath}`\n );\n }\n }\n};\n\n/**\n */\nconst setApplication = (store: ReduxStore) => {\n try {\n const locale = getLocale(store.getState());\n const application = new ModularUIRequest(\"/\", {\n locale: locale,\n }).fetchSync();\n\n store.dispatch(\n initModels([\n {\n key: `application(/)(${locale})`,\n model: application,\n },\n ])\n );\n } catch (e) {\n // eslint-disable-next-line no-console\n console.info(\"Could not load webapplication on server\");\n }\n};\n\n/**\n */\nconst handleErrors = (store: ReduxStore) => {\n const state = store.getState();\n\n if (\n state.error &&\n (state.error.shouldThrowOnServer ||\n !has(state.error, \"shouldThrowOnServer\"))\n ) {\n throw state.error;\n }\n};\n\n/**\n */\nconst dehydrate = (store: ReduxStore): string => {\n const state = store.getState();\n\n const modularui: {\n [key: string]: { status: string, lastModification: number, model: ?Object },\n } = {};\n\n for (const key in state.modularui) {\n const { status, model, lastModification } = state.modularui[key];\n\n if (model) {\n modularui[key] = {\n status,\n lastModification,\n model: model.dehydrate(),\n };\n } else {\n modularui[key] = {\n status,\n lastModification,\n model: undefined,\n };\n }\n }\n\n const filteredState = {\n ...state,\n modularui,\n };\n\n return JSON.stringify(filteredState).replace(/</g, \"\\\\u003c\");\n};\n\n/**\n */\nconst createHead = (\n sheet: any,\n UUID: string,\n helmetContext?: Object\n): Object => {\n const style = sheet.getStyleTags();\n const meta = helmetContext ? [...helmetContext.helmet.meta] : [];\n\n if (helmetContext) {\n return {\n ...helmetContext.helmet,\n style,\n meta,\n };\n }\n\n return {\n style,\n meta,\n };\n};\n\nexport {\n createReduxStore,\n setI18n,\n setApplication,\n setServerPreferences,\n setConfigurationTheme,\n createHead,\n handleErrors,\n dehydrate,\n};\n"],"mappings":";;;;;;AACA,SAASA,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,GAAG,QAAQ,0BAA0B;AAC9C,OAAOC,SAAS,MAAM,WAAW;AAEjC,OAAOC,cAAc,MAAM,+BAA+B;AAE1D,SAASC,gBAAgB,QAAQ,iBAAiB;AAClD,OAAOC,OAAO,MAAM,iBAAiB;AAErC,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,UAAU,QAAQ,4BAA4B;AAEvD,SACEC,mBAAmB,EACnBC,kBAAkB,EAClBC,aAAa,EACbC,0BAA0B,EAC1BC,mBAAmB,QACd,8BAA8B;AAErC,SAASC,UAAU,QAAQ,uBAAuB;AAElD,SAASC,wBAAwB,QAAQ,eAAe;AAExD,SAASC,UAAU,QAAQ,UAAU;AACrC,SAASC,SAAS,QAAQ,yBAAyB;AAEnD,OAAOC,gBAAgB,MAAM,+BAA+B;AAa5D;AACA;AACA,MAAMC,gB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EAEhE,IAAIH,aAAa,EAAE;IACjB,OAAO;MACL,GAAGA,aAAa,CAACI,MAAM;MACvBH,KAAK;MACLE;IACF,CAAC;EACH;EAEA,OAAO;IACLF,KAAK;IACLE;EACF,CAAC;AACH,CAAC;AAED,SACEpE,gBAAgB,EAChBQ,OAAO,EACPkC,cAAc,EACdX,oBAAoB,EACpBG,qBAAqB,EACrB4B,UAAU,EACVX,YAAY,EACZI,SAAS"}
@@ -18,6 +18,13 @@ export const setModel = (key, model) => {
18
18
  };
19
19
  };
20
20
 
21
+ /**
22
+ */
23
+ export const initModels = models => ({
24
+ type: "MODULARUI/INIT",
25
+ payload: models
26
+ });
27
+
21
28
  /**
22
29
  */
23
30
  export const updateModel = model => ({
@@ -1 +1 @@
1
- {"version":3,"file":"ModularUIActions.js","names":["HTTP_METHODS","MODULARUI_STATUS","Href","ErrorResponse","finishProgress","startProgress","handleError","setModel","key","model","connectKey","type","payload","updateModel","removeModelByKey","resetModularUI","updateStatus","status","loadModelSuccessAction","modelToUpdate","clonedModel","clone","update","Error","loadModel","href","options","method","GET","data","locale","childmodels","targetModel","forceTargetModel","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","dispatch","LOADING","loadModelPromise","resolve","then","response","FINISHED","catch","reloadModel","selfhref","isReload"],"sources":["../../../src/redux/_modularui/ModularUIActions.js"],"sourcesContent":["// @flow\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../../constants/Constants\";\nimport Href from \"../../models/href/Href\";\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\nimport { finishProgress, startProgress } from \"../actions/ProgressIndicator\";\nimport { handleError } from \"../actions/Error\";\n\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { Dispatch, ThunkAction } from \"../types\";\nimport type {\n ModularUIAction,\n SetModelAction,\n UpdateModelAction,\n RemoveModelByKeyAction,\n ResetModularUIAction,\n UpdateStatusAction,\n} from \"./types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\n/**\n */\nexport const setModel = (\n key: string,\n model: ModularUIModel\n): SetModelAction => {\n // set key on model for later reference\n model.connectKey = key;\n return {\n type: \"MODULARUI/SET\",\n payload: {\n key,\n model,\n },\n };\n};\n\n/**\n */\nexport const updateModel = (model: ModularUIModel): UpdateModelAction => ({\n type: \"MODULARUI/UPDATE\",\n payload: model,\n});\n\n/**\n */\nexport const removeModelByKey = (key: string): RemoveModelByKeyAction => ({\n type: \"MODULARUI/REMOVE_KEY\",\n payload: key,\n});\n\n/**\n * Removes all models except the application model from the modular ui reducer\n */\nexport const resetModularUI = (): ResetModularUIAction => ({\n type: \"MODULARUI/RESET\",\n});\n\n/**\n */\nexport const updateStatus = (\n key: string,\n status: $Keys<typeof MODULARUI_STATUS>\n): UpdateStatusAction => ({\n type: \"MODULARUI/STATUS\",\n payload: { key, status },\n});\n\n/**\n */\nconst loadModelSuccessAction = (\n key: string,\n model: ModularUIModel,\n modelToUpdate: ?ModularUIModel\n): UpdateModelAction | SetModelAction => {\n if (modelToUpdate) {\n // $FlowFixMe[prop-missing]\n if (typeof modelToUpdate[\"update\"] === \"function\") {\n const clonedModel = modelToUpdate.clone();\n clonedModel.update(model);\n\n return updateModel(clonedModel);\n }\n\n throw new Error(\n `loadModel action: updateModel is set as option for ${key}, but the model is missing an update methode`\n );\n }\n\n return setModel(key, model);\n};\n\n/**\n * This action is handled by the modularui middleware\n */\nexport const loadModel = (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions\n): ModularUIAction => ({\n type: \"MODULARUI/FETCH\",\n payload: {\n href: href instanceof Href ? href : new Href(href),\n method: options?.method ?? HTTP_METHODS.GET,\n data: options?.data,\n locale: options?.locale ?? \"en\",\n childmodels: options?.childmodels,\n targetModel: options?.targetModel,\n forceTargetModel: options?.forceTargetModel,\n /**\n */\n successAction: (model) =>\n loadModelSuccessAction(key, model, options?.updateModel),\n /**\n */\n errorAction: (error) => {\n const errorResponse = new ErrorResponse(error, key);\n if (errorResponse.isChangePassword) {\n return {\n type: \"NO_ACTION\",\n };\n } else if (errorResponse.isResourceNotFoundAfterReload) {\n return removeModelByKey(key);\n }\n\n return updateStatus(key, MODULARUI_STATUS.ERROR);\n },\n },\n});\n\n/**\n */\nexport const loadModularUI =\n (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions\n ): ThunkAction =>\n (dispatch: Dispatch) => {\n dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));\n dispatch(startProgress());\n\n const loadModelPromise = dispatch(loadModel(key, href, options));\n\n return Promise.resolve(loadModelPromise)\n .then((response) => {\n if (response?.type === \"FINISH_PROGRESS\") {\n dispatch(updateStatus(key, MODULARUI_STATUS.FINISHED));\n }\n\n return dispatch(finishProgress());\n })\n .catch((error) => dispatch(handleError(error)));\n };\n\n/**\n */\nexport const reloadModel = (\n model: ModularUIModel,\n options?: RequestModularUIOptions\n): ThunkAction =>\n loadModularUI(model.connectKey, model.selfhref, {\n ...options,\n isReload: true,\n });\n"],"mappings":";AACA,SAASA,YAAY,EAAEC,gBAAgB,QAAQ,2BAA2B;AAC1E,OAAOC,IAAI,MAAM,wBAAwB;AACzC,OAAOC,aAAa,MAAM,kCAAkC;AAC5D,SAASC,cAAc,EAAEC,aAAa,QAAQ,8BAA8B;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAc9C;AACA;AACA,OAAO,MAAMC,QAAQ,GAAG,CACtBC,GAAW,EACXC,KAAqB,KACF;EACnB;EACAA,KAAK,CAACC,UAAU,GAAGF,GAAG;EACtB,OAAO;IACLG,IAAI,EAAE,eAAe;IACrBC,OAAO,EAAE;MACPJ,GAAG;MACHC;IACF;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,OAAO,MAAMI,WAAW,GAAIJ,KAAqB,KAAyB;EACxEE,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMK,gBAAgB,GAAIN,GAAW,KAA8B;EACxEG,IAAI,EAAE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W,CAAC8B,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;;AAEH;AACA;AACA,OAAO,MAAMc,WAAW,GAAG,CACzBzC,KAAqB,EACrBiB,OAAiC,KAEjCe,aAAa,CAAChC,KAAK,CAACC,UAAU,EAAED,KAAK,CAAC0C,QAAQ,EAAE;EAC9C,GAAGzB,OAAO;EACV0B,QAAQ,EAAE;AACZ,CAAC,CAAC"}
1
+ {"version":3,"file":"ModularUIActions.js","names":["HTTP_METHODS","MODULARUI_STATUS","Href","ErrorResponse","finishProgress","startProgress","handleError","setModel","key","model","connectKey","type","payload","initModels","models","updateModel","removeModelByKey","resetModularUI","updateStatus","status","loadModelSuccessAction","modelToUpdate","clonedModel","clone","update","Error","loadModel","href","options","method","GET","data","locale","childmodels","targetModel","forceTargetModel","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","dispatch","LOADING","loadModelPromise","resolve","then","response","FINISHED","catch","reloadModel","selfhref","isReload"],"sources":["../../../src/redux/_modularui/ModularUIActions.js"],"sourcesContent":["// @flow\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../../constants/Constants\";\nimport Href from \"../../models/href/Href\";\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\nimport { finishProgress, startProgress } from \"../actions/ProgressIndicator\";\nimport { handleError } from \"../actions/Error\";\n\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { Dispatch, ThunkAction } from \"../types\";\nimport type {\n ModularUIAction,\n SetModelAction,\n InitModelAction,\n UpdateModelAction,\n RemoveModelByKeyAction,\n ResetModularUIAction,\n UpdateStatusAction,\n} from \"./types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\n/**\n */\nexport const setModel = (\n key: string,\n model: ModularUIModel\n): SetModelAction => {\n // set key on model for later reference\n model.connectKey = key;\n return {\n type: \"MODULARUI/SET\",\n payload: {\n key,\n model,\n },\n };\n};\n\n/**\n */\nexport const initModels = (\n models: Array<{ key: string, model: ModularUIModel }>\n): InitModelAction => ({\n type: \"MODULARUI/INIT\",\n payload: models,\n});\n\n/**\n */\nexport const updateModel = (model: ModularUIModel): UpdateModelAction => ({\n type: \"MODULARUI/UPDATE\",\n payload: model,\n});\n\n/**\n */\nexport const removeModelByKey = (key: string): RemoveModelByKeyAction => ({\n type: \"MODULARUI/REMOVE_KEY\",\n payload: key,\n});\n\n/**\n * Removes all models except the application model from the modular ui reducer\n */\nexport const resetModularUI = (): ResetModularUIAction => ({\n type: \"MODULARUI/RESET\",\n});\n\n/**\n */\nexport const updateStatus = (\n key: string,\n status: $Keys<typeof MODULARUI_STATUS>\n): UpdateStatusAction => ({\n type: \"MODULARUI/STATUS\",\n payload: { key, status },\n});\n\n/**\n */\nconst loadModelSuccessAction = (\n key: string,\n model: ModularUIModel,\n modelToUpdate: ?ModularUIModel\n): UpdateModelAction | SetModelAction => {\n if (modelToUpdate) {\n // $FlowFixMe[prop-missing]\n if (typeof modelToUpdate[\"update\"] === \"function\") {\n const clonedModel = modelToUpdate.clone();\n clonedModel.update(model);\n\n return updateModel(clonedModel);\n }\n\n throw new Error(\n `loadModel action: updateModel is set as option for ${key}, but the model is missing an update methode`\n );\n }\n\n return setModel(key, model);\n};\n\n/**\n * This action is handled by the modularui middleware\n */\nexport const loadModel = (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions\n): ModularUIAction => ({\n type: \"MODULARUI/FETCH\",\n payload: {\n href: href instanceof Href ? href : new Href(href),\n method: options?.method ?? HTTP_METHODS.GET,\n data: options?.data,\n locale: options?.locale ?? \"en\",\n childmodels: options?.childmodels,\n targetModel: options?.targetModel,\n forceTargetModel: options?.forceTargetModel,\n /**\n */\n successAction: (model) =>\n loadModelSuccessAction(key, model, options?.updateModel),\n /**\n */\n errorAction: (error) => {\n const errorResponse = new ErrorResponse(error, key);\n if (errorResponse.isChangePassword) {\n return {\n type: \"NO_ACTION\",\n };\n } else if (errorResponse.isResourceNotFoundAfterReload) {\n return removeModelByKey(key);\n }\n\n return updateStatus(key, MODULARUI_STATUS.ERROR);\n },\n },\n});\n\n/**\n */\nexport const loadModularUI =\n (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions\n ): ThunkAction =>\n (dispatch: Dispatch) => {\n dispatch(updateStatus(key, MODULARUI_STATUS.LOADING));\n dispatch(startProgress());\n\n const loadModelPromise = dispatch(loadModel(key, href, options));\n\n return Promise.resolve(loadModelPromise)\n .then((response) => {\n if (response?.type === \"FINISH_PROGRESS\") {\n dispatch(updateStatus(key, MODULARUI_STATUS.FINISHED));\n }\n\n return dispatch(finishProgress());\n })\n .catch((error) => dispatch(handleError(error)));\n };\n\n/**\n */\nexport const reloadModel = (\n model: ModularUIModel,\n options?: RequestModularUIOptions\n): ThunkAction =>\n loadModularUI(model.connectKey, model.selfhref, {\n ...options,\n isReload: true,\n });\n"],"mappings":";AACA,SAASA,YAAY,EAAEC,gBAAgB,QAAQ,2BAA2B;AAC1E,OAAOC,IAAI,MAAM,wBAAwB;AACzC,OAAOC,aAAa,MAAM,kCAAkC;AAC5D,SAASC,cAAc,EAAEC,aAAa,QAAQ,8BAA8B;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAe9C;AACA;AACA,OAAO,MAAMC,QAAQ,GAAG,CACtBC,GAAW,EACXC,KAAqB,KACF;EACnB;EACAA,KAAK,CAACC,UAAU,GAAGF,GAAG;EACtB,OAAO;IACLG,IAAI,EAAE,eAAe;IACrBC,OAAO,EAAE;MACPJ,GAAG;MACHC;IACF;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,OAAO,MAAMI,UAAU,GACrBC,MAAqD,KAChC;EACrBH,IAAI,EAAE,gBAAgB;EACtBC,OAAO,EAAEE;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMC,WAAW,GAAIN,KAAqB,KAAyB;EACxEE,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMO,gBAAgB,GAAIR,GA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,KAAK,IAAKM,QAAQ,CAACtC,WAAW,CAACgC,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;;AAEH;AACA;AACA,OAAO,MAAMc,WAAW,GAAG,CACzB3C,KAAqB,EACrBmB,OAAiC,KAEjCe,aAAa,CAAClC,KAAK,CAACC,UAAU,EAAED,KAAK,CAAC4C,QAAQ,EAAE;EAC9C,GAAGzB,OAAO;EACV0B,QAAQ,EAAE;AACZ,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ModularUIMiddleware.js","names":["ModularUIRequest","HTTP_METHODS","startProgress","finishProgress","handleError","createRequest","modularui","request","href","method","GET","data","locale","childmodels","isReload","targetModel","forceTargetModel","responseHandler","next","dispatch","successAction","model","successResult","then","result","catch","error","Error","errorHandler","errorAction","err","errorResult","handleFetch","action","requestOptions","payload","modularuiRequest","fetch","modularUIMiddleware","api","type","getState","i18n"],"sources":["../../../src/redux/_modularui/ModularUIMiddleware.js"],"sourcesContent":["// @flow\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\nimport { HTTP_METHODS } from \"../../constants/Constants\";\n\nimport { startProgress, finishProgress } from \"../actions/ProgressIndicator\";\n\nimport { handleError } from \"../actions/Error\";\n\nimport type { Middleware, MiddlewareAPI } from \"redux\";\nimport type {\n ReduxAction,\n ReduxState,\n Dispatch,\n PossibleAction,\n} from \"../types\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { ModularUIAction, SuccessAction, ErrorAction } from \"./types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\ntype RequestOptions = {\n href: Href,\n method?: $Keys<typeof HTTP_METHODS>,\n data?: string | { [key: string]: string },\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n isReload?: boolean,\n};\n\n/**\n * Symbol key that carries API call info interpreted by this Redux middleware.\n */\nconst createRequest = (modularui: RequestOptions): ModularUIRequest => {\n const request = new ModularUIRequest(modularui.href, {\n method: modularui.method || HTTP_METHODS.GET,\n data: modularui.data || {},\n locale: modularui.locale,\n childmodels: modularui.childmodels ?? true,\n isReload: modularui.isReload,\n });\n\n if (modularui.targetModel) {\n request.targetModel = modularui.targetModel;\n request.forceTargetModel = modularui.forceTargetModel ?? false;\n }\n\n return request;\n};\n\n/**\n */\nconst responseHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n successAction: SuccessAction,\n model: ModularUIModel\n) => {\n if (successAction) {\n const successResult = successAction(model);\n\n if (successResult instanceof Promise) {\n successResult\n .then((result) => {\n dispatch(result);\n })\n .catch((error) => {\n next(handleError(error));\n });\n } else {\n try {\n dispatch(successResult);\n } catch (error) {\n throw new Error(\n `Result of successResult is not a valid redux action: ${error}`\n );\n }\n }\n }\n\n return next(finishProgress());\n};\n\n/**\n */\nconst errorHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n errorAction: ?ErrorAction,\n err: any\n) => {\n dispatch(finishProgress());\n\n if (errorAction) {\n const errorResult = errorAction(err);\n\n if (errorResult instanceof Promise) {\n errorResult.then((result) => dispatch(result));\n } else {\n dispatch(errorResult);\n }\n }\n\n return next(handleError(err));\n};\n\n/**\n */\nconst handleFetch = (\n action: ModularUIAction,\n locale: string,\n dispatch: Dispatch,\n next: Dispatch\n) => {\n dispatch(startProgress());\n\n const { successAction, errorAction, ...requestOptions } = action.payload;\n requestOptions.locale = locale;\n\n const modularuiRequest = createRequest(requestOptions);\n\n return modularuiRequest\n .fetch()\n .then((model) => responseHandler(next, dispatch, successAction, model))\n .catch((error) => errorHandler(next, dispatch, errorAction, error));\n};\n\n/**\n */\nexport const modularUIMiddleware: Middleware<\n ReduxState,\n ReduxAction,\n Dispatch\n> =\n (api: MiddlewareAPI<ReduxState, ReduxAction, Dispatch>) =>\n (next: Dispatch) =>\n (action: PossibleAction) => {\n if (action.type === \"MODULARUI/FETCH\") {\n return handleFetch(\n // $FlowExpectedError[incompatible-exact]\n action,\n api.getState().i18n.locale,\n api.dispatch,\n next\n );\n }\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,GACEC,GAAqD,IACrDrB,IAAc,IACde,MAAsB,IAAK;EAC1B,IAAIA,MAAM,CAACO,IAAI,KAAK,iBAAiB,EAAE;IACrC,OAAOR,WAAW;IAChB;IACAC,MAAM,EACNM,GAAG,CAACE,QAAQ,EAAE,CAACC,IAAI,CAAC9B,MAAM,EAC1B2B,GAAG,CAACpB,QAAQ,EACZD,IAAI,CACL;EACH;EAEA,OAAOA,IAAI,CAACe,MAAM,CAAC;AACrB,CAAC"}
1
+ {"version":3,"file":"ModularUIMiddleware.js","names":["ModularUIRequest","HTTP_METHODS","startProgress","finishProgress","handleError","createRequest","modularui","request","href","method","GET","data","locale","childmodels","isReload","targetModel","forceTargetModel","responseHandler","next","dispatch","successAction","model","successResult","then","result","catch","error","Error","errorHandler","errorAction","err","errorResult","handleFetch","action","requestOptions","payload","modularuiRequest","fetch","modularUIMiddleware","api","type","getState","i18n"],"sources":["../../../src/redux/_modularui/ModularUIMiddleware.js"],"sourcesContent":["// @flow\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\nimport { HTTP_METHODS } from \"../../constants/Constants\";\n\nimport { startProgress, finishProgress } from \"../actions/ProgressIndicator\";\n\nimport { handleError } from \"../actions/Error\";\n\nimport type { Middleware, MiddlewareAPI } from \"redux\";\nimport type {\n ReduxAction,\n ReduxState,\n Dispatch,\n PossibleAction,\n} from \"../types\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { ModularUIAction, SuccessAction, ErrorAction } from \"./types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\ntype RequestOptions = {\n href: Href,\n method?: $Keys<typeof HTTP_METHODS>,\n data?: any,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n isReload?: boolean,\n};\n\n/**\n * Symbol key that carries API call info interpreted by this Redux middleware.\n */\nconst createRequest = (modularui: RequestOptions): ModularUIRequest => {\n const request = new ModularUIRequest(modularui.href, {\n method: modularui.method || HTTP_METHODS.GET,\n data: modularui.data || {},\n locale: modularui.locale,\n childmodels: modularui.childmodels ?? true,\n isReload: modularui.isReload,\n });\n\n if (modularui.targetModel) {\n request.targetModel = modularui.targetModel;\n request.forceTargetModel = modularui.forceTargetModel ?? false;\n }\n\n return request;\n};\n\n/**\n */\nconst responseHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n successAction: SuccessAction,\n model: ModularUIModel\n) => {\n if (successAction) {\n const successResult = successAction(model);\n\n if (successResult instanceof Promise) {\n successResult\n .then((result) => {\n dispatch(result);\n })\n .catch((error) => {\n next(handleError(error));\n });\n } else {\n try {\n dispatch(successResult);\n } catch (error) {\n throw new Error(\n `Result of successResult is not a valid redux action: ${error}`\n );\n }\n }\n }\n\n return next(finishProgress());\n};\n\n/**\n */\nconst errorHandler = (\n next: Dispatch,\n dispatch: Dispatch,\n errorAction: ?ErrorAction,\n err: any\n) => {\n dispatch(finishProgress());\n\n if (errorAction) {\n const errorResult = errorAction(err);\n\n if (errorResult instanceof Promise) {\n errorResult.then((result) => dispatch(result));\n } else {\n dispatch(errorResult);\n }\n }\n\n return next(handleError(err));\n};\n\n/**\n */\nconst handleFetch = (\n action: ModularUIAction,\n locale: string,\n dispatch: Dispatch,\n next: Dispatch\n) => {\n dispatch(startProgress());\n\n const { successAction, errorAction, ...requestOptions } = action.payload;\n requestOptions.locale = locale;\n\n const modularuiRequest = createRequest(requestOptions);\n\n return modularuiRequest\n .fetch()\n .then((model) => responseHandler(next, dispatch, successAction, model))\n .catch((error) => errorHandler(next, dispatch, errorAction, error));\n};\n\n/**\n */\nexport const modularUIMiddleware: Middleware<\n ReduxState,\n ReduxAction,\n Dispatch\n> =\n (api: MiddlewareAPI<ReduxState, ReduxAction, Dispatch>) =>\n (next: Dispatch) =>\n (action: PossibleAction) => {\n if (action.type === \"MODULARUI/FETCH\") {\n return handleFetch(\n // $FlowExpectedError[incompatible-exact]\n action,\n api.getState().i18n.locale,\n api.dispatch,\n next\n );\n }\n\n return next(action);\n };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,IACrDrB,IAAc,IACde,MAAsB,IAAK;EAC1B,IAAIA,MAAM,CAACO,IAAI,KAAK,iBAAiB,EAAE;IACrC,OAAOR,WAAW;IAChB;IACAC,MAAM,EACNM,GAAG,CAACE,QAAQ,EAAE,CAACC,IAAI,CAAC9B,MAAM,EAC1B2B,GAAG,CAACpB,QAAQ,EACZD,IAAI,CACL;EACH;EAEA,OAAOA,IAAI,CAACe,MAAM,CAAC;AACrB,CAAC"}
@@ -1,6 +1,6 @@
1
+ import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
1
2
  import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
2
3
  import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
3
- import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
4
4
  import { IllegalArgumentException } from "../../exceptions";
5
5
  import { MODULARUI_STATUS } from "../../constants/Constants";
6
6
  import { ApplicationModel } from "../../models";
@@ -48,6 +48,24 @@ const setModel = (state, _ref2) => {
48
48
  throw new IllegalArgumentException("No model for setModel");
49
49
  };
50
50
 
51
+ /**
52
+ */
53
+ const initModularUI = (state, models) => {
54
+ const newState = _Object$assign({}, state);
55
+ models.forEach(_ref3 => {
56
+ let {
57
+ key,
58
+ model
59
+ } = _ref3;
60
+ newState[key] = {
61
+ status: MODULARUI_STATUS.FINISHED,
62
+ lastModification: Date.now(),
63
+ model
64
+ };
65
+ });
66
+ return newState;
67
+ };
68
+
51
69
  /**
52
70
  */
53
71
  const getModelKey = (state, model) => {
@@ -105,6 +123,8 @@ export const ModularUIReducer = function () {
105
123
  return state;
106
124
  }
107
125
  switch (action.type) {
126
+ case "MODULARUI/INIT":
127
+ return initModularUI(state, action.payload);
108
128
  case "MODULARUI/RESET":
109
129
  return resetModularUI(state);
110
130
  case "MODULARUI/STATUS":
@@ -1 +1 @@
1
- {"version":3,"file":"ModularUIReducer.js","names":["IllegalArgumentException","MODULARUI_STATUS","ApplicationModel","updateStatus","state","key","status","LOADING","lastModification","Date","now","setModel","model","getModelKey","connectKey","updateModel","modelKey","Error","removeKey","newState","resetModularUI","initialState","ModularUIReducer","action","type","payload"],"sources":["../../../src/redux/_modularui/ModularUIReducer.js"],"sourcesContent":["// @flow\nimport { IllegalArgumentException } from \"../../exceptions\";\nimport { MODULARUI_STATUS } from \"../../constants/Constants\";\nimport { ApplicationModel } from \"../../models\";\n\nimport type { Reducer } from \"redux\";\nimport type { ReduxAction } from \"../types\";\nimport type { ModularUIState } from \"./types\";\nimport type { ModularUIModel } from \"../../models\";\n\n/**\n */\nconst updateStatus = (\n state: ModularUIState,\n { key, status }: { key: string, status: $Keys<typeof MODULARUI_STATUS> }\n) => {\n // model should always be available when status is not loading\n if (status !== MODULARUI_STATUS.LOADING && !state[key]) {\n return state;\n }\n\n return {\n ...state,\n [key]: {\n ...state[key],\n status,\n lastModification: Date.now(),\n },\n };\n};\n\n/**\n */\nconst setModel = (\n state: ModularUIState,\n { key, model }: { key: string, model: ?ModularUIModel }\n) => {\n if (!state[key]) {\n return state;\n }\n\n if (model) {\n return {\n ...state,\n [key]: {\n ...state[key],\n model,\n lastModification: Date.now(),\n },\n };\n }\n\n throw new IllegalArgumentException(\"No model for setModel\");\n};\n\n/**\n */\nconst getModelKey = (state: ModularUIState, model: ModularUIModel) =>\n Object.keys(state).find((key) => {\n const connectKey = state[key]?.model?.connectKey ?? \"\";\n return connectKey === model.connectKey;\n });\n\n/**\n */\nconst updateModel = (state: ModularUIState, model: ModularUIModel) => {\n const modelKey = getModelKey(state, model);\n\n if (modelKey) {\n return setModel(state, { key: modelKey, model });\n }\n\n throw new Error(\n `ModularUIReducer: Cannot update model with key ${model.connectKey}`\n );\n};\n\n/**\n */\nconst removeKey = (modelKey: string, state: ModularUIState): ModularUIState => {\n const newState = Object.assign({}, state);\n delete newState[modelKey];\n return newState;\n};\n\n/**\n * Remove all but application models\n */\nconst resetModularUI = (state: ModularUIState) => {\n const newState: ModularUIState = {};\n\n for (const key in state) {\n if (state[key].model instanceof ApplicationModel) {\n newState[key] = { ...state[key] };\n }\n }\n\n return newState;\n};\n\nconst initialState: ModularUIState = {};\n\n/**\n * Modular UI Reducer\n */\nexport const ModularUIReducer: Reducer<ModularUIState, ReduxAction> = (\n state = initialState,\n action\n) => {\n if (!action) {\n return state;\n }\n\n switch (action.type) {\n case \"MODULARUI/RESET\":\n return resetModularUI(state);\n\n case \"MODULARUI/STATUS\":\n return updateStatus(state, action.payload);\n\n case \"MODULARUI/SET\":\n return setModel(state, action.payload);\n\n case \"MODULARUI/UPDATE\":\n return updateModel(state, action.payload);\n\n case \"MODULARUI/REMOVE_KEY\":\n return removeKey(action.payload, state);\n\n default:\n return state;\n }\n};\n"],"mappings":";;;AACA,SAASA,wBAAwB,QAAQ,kBAAkB;AAC3D,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,gBAAgB,QAAQ,cAAc;AAO/C;AACA;AACA,MAAMC,YAAY,GAAG,CACnBC,KAAqB,WAElB;EAAA,IADH;IAAEC,GAAG;IAAEC;EAAgE,CAAC;EAExE;EACA,IAAIA,MAAM,KAAKL,gBAAgB,CAACM,OAAO,IAAI,CAACH,KAAK,CAACC,GAAG,CAAC,EAAE;IACtD,OAAOD,KAAK;EACd;EAEA,OAAO;IACL,GAAGA,KAAK;IACR,CAACC,GAAG,GAAG;MACL,GAAGD,KAAK,CAACC,GAAG,CAAC;MACbC,MAAM;MACNE,gBAAgB,EAAEC,IAAI,CAACC,GAAG;IAC5B;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,MAAMC,QAAQ,GAAG,CACfP,KAAqB,YAElB;EAAA,IADH;IAAEC,GAAG;IAAEO;EAA+C,CAAC;EAEvD,IAAI,CAACR,KAAK,CAACC,GAAG,CAAC,EAAE;IACf,OAAOD,KAAK;EACd;EAEA,IAAIQ,KAAK,EAAE;IACT,OAAO;MACL,GAAGR,KAAK;MACR,CAACC,GAAG,GAAG;QACL,GAAGD,KAAK,CAACC,GAAG,CAAC;QAC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,KAAK,CAACC,GAAG;MAAE,CAAC;IACnC;EACF;EAEA,OAAOc,QAAQ;AACjB,CAAC;AAED,MAAME,YAA4B,GAAG,CAAC,CAAC;;AAEvC;AACA;AACA;AACA,OAAO,MAAMC,gBAAsD,GAAG,YAGjE;EAAA,IAFHlB,KAAK,uEAAGiB,YAAY;EAAA,IACpBE,MAAM;EAEN,IAAI,CAACA,MAAM,EAAE;IACX,OAAOnB,KAAK;EACd;EAEA,QAAQmB,MAAM,CAACC,IAAI;IACjB,KAAK,iBAAiB;MACpB,OAAOJ,cAAc,CAAChB,KAAK,CAAC;IAE9B,KAAK,kBAAkB;MACrB,OAAOD,YAAY,CAACC,KAAK,EAAEmB,MAAM,CAACE,OAAO,CAAC;IAE5C,KAAK,eAAe;MAClB,OAAOd,QAAQ,CAACP,KAAK,EAAEmB,MAAM,CAACE,OAAO,CAAC;IAExC,KAAK,kBAAkB;MACrB,OAAOV,WAAW,CAACX,KAAK,EAAEmB,MAAM,CAACE,OAAO,CAAC;IAE3C,KAAK,sBAAsB;MACzB,OAAOP,SAAS,CAACK,MAAM,CAACE,OAAO,EAAErB,KAAK,CAAC;IAEzC;MACE,OAAOA,KAAK;EAAC;AAEnB,CAAC"}
1
+ {"version":3,"file":"ModularUIReducer.js","names":["IllegalArgumentException","MODULARUI_STATUS","ApplicationModel","updateStatus","state","key","status","LOADING","lastModification","Date","now","setModel","model","initModularUI","models","newState","forEach","FINISHED","getModelKey","connectKey","updateModel","modelKey","Error","removeKey","resetModularUI","initialState","ModularUIReducer","action","type","payload"],"sources":["../../../src/redux/_modularui/ModularUIReducer.js"],"sourcesContent":["// @flow\nimport { IllegalArgumentException } from \"../../exceptions\";\nimport { MODULARUI_STATUS } from \"../../constants/Constants\";\nimport { ApplicationModel } from \"../../models\";\n\nimport type { Reducer } from \"redux\";\nimport type { ReduxAction } from \"../types\";\nimport type { ModularUIState } from \"./types\";\nimport type { ModularUIModel } from \"../../models\";\n\n/**\n */\nconst updateStatus = (\n state: ModularUIState,\n { key, status }: { key: string, status: $Keys<typeof MODULARUI_STATUS> }\n) => {\n // model should always be available when status is not loading\n if (status !== MODULARUI_STATUS.LOADING && !state[key]) {\n return state;\n }\n\n return {\n ...state,\n [key]: {\n ...state[key],\n status,\n lastModification: Date.now(),\n },\n };\n};\n\n/**\n */\nconst setModel = (\n state: ModularUIState,\n { key, model }: { key: string, model: ?ModularUIModel }\n) => {\n if (!state[key]) {\n return state;\n }\n\n if (model) {\n return {\n ...state,\n [key]: {\n ...state[key],\n model,\n lastModification: Date.now(),\n },\n };\n }\n\n throw new IllegalArgumentException(\"No model for setModel\");\n};\n\n/**\n */\nconst initModularUI = (\n state: ModularUIState,\n models: Array<{ key: string, model: ModularUIModel }>\n) => {\n const newState = Object.assign({}, state);\n\n models.forEach(({ key, model }) => {\n newState[key] = {\n status: MODULARUI_STATUS.FINISHED,\n lastModification: Date.now(),\n model,\n };\n });\n\n return newState;\n};\n\n/**\n */\nconst getModelKey = (state: ModularUIState, model: ModularUIModel) =>\n Object.keys(state).find((key) => {\n const connectKey = state[key]?.model?.connectKey ?? \"\";\n return connectKey === model.connectKey;\n });\n\n/**\n */\nconst updateModel = (state: ModularUIState, model: ModularUIModel) => {\n const modelKey = getModelKey(state, model);\n\n if (modelKey) {\n return setModel(state, { key: modelKey, model });\n }\n\n throw new Error(\n `ModularUIReducer: Cannot update model with key ${model.connectKey}`\n );\n};\n\n/**\n */\nconst removeKey = (modelKey: string, state: ModularUIState): ModularUIState => {\n const newState = Object.assign({}, state);\n delete newState[modelKey];\n return newState;\n};\n\n/**\n * Remove all but application models\n */\nconst resetModularUI = (state: ModularUIState) => {\n const newState: ModularUIState = {};\n\n for (const key in state) {\n if (state[key].model instanceof ApplicationModel) {\n newState[key] = { ...state[key] };\n }\n }\n\n return newState;\n};\n\nconst initialState: ModularUIState = {};\n\n/**\n * Modular UI Reducer\n */\nexport const ModularUIReducer: Reducer<ModularUIState, ReduxAction> = (\n state = initialState,\n action\n) => {\n if (!action) {\n return state;\n }\n\n switch (action.type) {\n case \"MODULARUI/INIT\":\n return initModularUI(state, action.payload);\n\n case \"MODULARUI/RESET\":\n return resetModularUI(state);\n\n case \"MODULARUI/STATUS\":\n return updateStatus(state, action.payload);\n\n case \"MODULARUI/SET\":\n return setModel(state, action.payload);\n\n case \"MODULARUI/UPDATE\":\n return updateModel(state, action.payload);\n\n case \"MODULARUI/REMOVE_KEY\":\n return removeKey(action.payload, state);\n\n default:\n return state;\n }\n};\n"],"mappings":";;;AACA,SAASA,wBAAwB,QAAQ,kBAAkB;AAC3D,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,gBAAgB,QAAQ,cAAc;AAO/C;AACA;AACA,MAAMC,YAAY,GAAG,CACnBC,KAAqB,WAElB;EAAA,IADH;IAAEC,GAAG;IAAEC;EAAgE,CAAC;EAExE;EACA,IAAIA,MAAM,KAAKL,gBAAgB,CAACM,OAAO,IAAI,CAACH,KAAK,CAACC,GAAG,CAAC,EAAE;IACtD,OAAOD,KAAK;EACd;EAEA,OAAO;IACL,GAAGA,KAAK;IACR,CAACC,GAAG,GAAG;MACL,GAAGD,KAAK,CAACC,GAAG,CAAC;MACbC,MAAM;MACNE,gBAAgB,EAAEC,IAAI,CAACC,GAAG;IAC5B;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,MAAMC,QAAQ,GAAG,CACfP,KAAqB,YAElB;EAAA,IADH;IAAEC,GAAG;IAAEO;EAA+C,CAAC;EAEvD,IAAI,CAACR,KAAK,CAACC,GAAG,CAAC,EAAE;IACf,OAAOD,KAAK;EACd;EAEA,IAAIQ,KAAK,EAAE;IACT,OAAO;MACL,GAAGR,KAAK;MACR,CAACC,GAAG,GAAG;QACL,GAAGD,KAAK,CAACC,GAAG,CAAC;QACbO,KAAK;QACLJ,gBAAgB,EAAEC,IAAI,CAACC,GAAG;MAC5B;IACF,CAAC;EACH;EAEA,MAAM,IAAIV,wBAAwB,CAAC,uBAAuB,CAAC;AAC7D,CAAC;;A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AQ;AACjB,CAAC;;AAED;AACA;AACA;AACA,MAAMS,cAAc,GAAIpB,KAAqB,IAAK;EAChD,MAAMW,QAAwB,GAAG,CAAC,CAAC;EAEnC,KAAK,MAAMV,GAAG,IAAID,KAAK,EAAE;IACvB,IAAIA,KAAK,CAACC,GAAG,CAAC,CAACO,KAAK,YAAYV,gBAAgB,EAAE;MAChDa,QAAQ,CAACV,GAAG,CAAC,GAAG;QAAE,GAAGD,KAAK,CAACC,GAAG;MAAE,CAAC;IACnC;EACF;EAEA,OAAOU,QAAQ;AACjB,CAAC;AAED,MAAMU,YAA4B,GAAG,CAAC,CAAC;;AAEvC;AACA;AACA;AACA,OAAO,MAAMC,gBAAsD,GAAG,YAGjE;EAAA,IAFHtB,KAAK,uEAAGqB,YAAY;EAAA,IACpBE,MAAM;EAEN,IAAI,CAACA,MAAM,EAAE;IACX,OAAOvB,KAAK;EACd;EAEA,QAAQuB,MAAM,CAACC,IAAI;IACjB,KAAK,gBAAgB;MACnB,OAAOf,aAAa,CAACT,KAAK,EAAEuB,MAAM,CAACE,OAAO,CAAC;IAE7C,KAAK,iBAAiB;MACpB,OAAOL,cAAc,CAACpB,KAAK,CAAC;IAE9B,KAAK,kBAAkB;MACrB,OAAOD,YAAY,CAACC,KAAK,EAAEuB,MAAM,CAACE,OAAO,CAAC;IAE5C,KAAK,eAAe;MAClB,OAAOlB,QAAQ,CAACP,KAAK,EAAEuB,MAAM,CAACE,OAAO,CAAC;IAExC,KAAK,kBAAkB;MACrB,OAAOT,WAAW,CAAChB,KAAK,EAAEuB,MAAM,CAACE,OAAO,CAAC;IAE3C,KAAK,sBAAsB;MACzB,OAAON,SAAS,CAACI,MAAM,CAACE,OAAO,EAAEzB,KAAK,CAAC;IAEzC;MACE,OAAOA,KAAK;EAAC;AAEnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/redux/_modularui/types.js"],"sourcesContent":["// @flow\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { FetchException } from \"../../exceptions\";\nimport type { NoAction } from \"../types\";\nimport typeof {\n HTTP_METHODS,\n MODULARUI_STATUS,\n} from \"../../constants/Constants\";\nimport type { ComponentType } from \"react\";\nimport type { TargetModel } from \"../../modularui/types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\nexport type ModularUIOptions = {\n propName?: string,\n removeOnUnmount?: boolean,\n ...RequestModularUIOptions,\n};\n\nexport type ModelEntry = {\n +status: string,\n +model: ModularUIModel,\n +lastModification: number,\n};\n\nexport type ModularUIState = {\n [string]: ModelEntry,\n ...\n};\n\nexport type SetModelAction = {\n type: \"MODULARUI/SET\",\n payload: {\n key: string,\n model: ?ModularUIModel,\n },\n};\n\nexport type UpdateModelAction = {\n type: \"MODULARUI/UPDATE\",\n payload: ModularUIModel,\n};\n\nexport type SuccessAction = (\n model: ModularUIModel\n) => UpdateModelAction | SetModelAction;\n\nexport type ErrorAction = (\n error: FetchException\n) => UpdateStatusAction | RemoveModelByKeyAction | NoAction;\n\nexport type ModularUIAction = {\n type: \"MODULARUI/FETCH\",\n payload: {\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n data?: string | { [key: string]: string },\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n successAction: (\n model: ModularUIModel\n ) => UpdateModelAction | SetModelAction,\n errorAction?: ErrorAction,\n },\n};\n\nexport type RemoveModelByKeyAction = {\n type: \"MODULARUI/REMOVE_KEY\",\n payload: string,\n};\n\nexport type ResetModularUIAction = {\n type: \"MODULARUI/RESET\",\n};\n\nexport type UpdateStatusAction = {\n type: \"MODULARUI/STATUS\",\n payload: {\n key: string,\n status: $Keys<MODULARUI_STATUS>,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>\n) => ComponentType<any>;\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/redux/_modularui/types.js"],"sourcesContent":["// @flow\nimport type { ModularUIModel } from \"../../models/types\";\nimport type Href from \"../../models/href/Href\";\nimport type { FetchException } from \"../../exceptions\";\nimport type { NoAction } from \"../types\";\nimport typeof {\n HTTP_METHODS,\n MODULARUI_STATUS,\n} from \"../../constants/Constants\";\nimport type { ComponentType } from \"react\";\nimport type { TargetModel } from \"../../modularui/types\";\nimport type { RequestModularUIOptions } from \"../../utils/fetch/types\";\n\nexport type ModularUIOptions = {\n propName?: string,\n removeOnUnmount?: boolean,\n ...RequestModularUIOptions,\n};\n\nexport type ModelEntry = {\n +status: string,\n +model: ModularUIModel,\n +lastModification: number,\n};\n\nexport type ModularUIState = {\n [string]: ModelEntry,\n ...\n};\n\nexport type SetModelAction = {\n type: \"MODULARUI/SET\",\n payload: {\n key: string,\n model: ?ModularUIModel,\n },\n};\n\nexport type InitModelAction = {\n type: \"MODULARUI/INIT\",\n payload: Array<{\n key: string,\n model: ModularUIModel,\n }>,\n};\n\nexport type UpdateModelAction = {\n type: \"MODULARUI/UPDATE\",\n payload: ModularUIModel,\n};\n\nexport type SuccessAction = (\n model: ModularUIModel\n) => UpdateModelAction | SetModelAction;\n\nexport type ErrorAction = (\n error: FetchException\n) => UpdateStatusAction | RemoveModelByKeyAction | NoAction;\n\nexport type ModularUIAction = {\n type: \"MODULARUI/FETCH\",\n payload: {\n href: Href,\n method?: $Keys<HTTP_METHODS>,\n data?: any,\n locale: string,\n childmodels?: boolean,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n successAction: (\n model: ModularUIModel\n ) => UpdateModelAction | SetModelAction,\n errorAction?: ErrorAction,\n },\n};\n\nexport type RemoveModelByKeyAction = {\n type: \"MODULARUI/REMOVE_KEY\",\n payload: string,\n};\n\nexport type ResetModularUIAction = {\n type: \"MODULARUI/RESET\",\n};\n\nexport type UpdateStatusAction = {\n type: \"MODULARUI/STATUS\",\n payload: {\n key: string,\n status: $Keys<MODULARUI_STATUS>,\n },\n};\n\nexport type ModularUIConnector = (\n Component: ComponentType<any>\n) => ComponentType<any>;\n"],"mappings":""}
@@ -18,7 +18,7 @@ const configureStore = (history, customReducers, initialState) => {
18
18
  const middleware = applyMiddleware(modularUIMiddleware, routerMiddleware(history), thunk);
19
19
  const enhancers = composeEnhancers(middleware);
20
20
  const store = createReduxStore(combinedReducers, initialState, enhancers);
21
- if (!initialState) {
21
+ if (!initialState?.router) {
22
22
  store.dispatch(locationChange(history.location, "PUSH"));
23
23
  }
24
24
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"configureStore.js","names":["applyMiddleware","compose","combineReducers","createStore","createReduxStore","thunk","routerMiddleware","modularUIMiddleware","createReducer","locationChange","configureStore","history","customReducers","initialState","composeEnhancers","process","env","NODE_ENV","window","__REDUX_DEVTOOLS_EXTENSION_COMPOSE__","combinedReducers","middleware","enhancers","store","dispatch","location"],"sources":["../../../src/redux/store/configureStore.js"],"sourcesContent":["// @flow\nimport {\n applyMiddleware,\n compose,\n combineReducers,\n createStore as createReduxStore,\n} from \"redux\";\nimport thunk from \"redux-thunk\";\n\nimport { routerMiddleware } from \"../_router/RouterMiddleware\";\nimport { modularUIMiddleware } from \"../_modularui/ModularUIMiddleware\";\n\nimport { createReducer } from \"../reducers/createReducer\";\nimport { locationChange } from \"../_router/RouterActions\";\n\nimport type { RouterHistory } from \"react-router\";\nimport type { ReduxAction, ReduxState, ReduxStore } from \"../types\";\nimport type { Reducer } from \"redux\";\n\n/**\n */\nconst configureStore = (\n history: RouterHistory,\n customReducers?: Object,\n initialState?: $Shape<ReduxState>\n): { history: RouterHistory, store: ReduxStore } => {\n let composeEnhancers = compose;\n\n if (process.env.NODE_ENV !== \"production\" && typeof window !== \"undefined\") {\n composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;\n }\n\n const combinedReducers: Reducer<ReduxState, ReduxAction> = combineReducers({\n ...customReducers,\n ...createReducer(),\n });\n\n const middleware = applyMiddleware(\n modularUIMiddleware,\n routerMiddleware(history),\n thunk\n );\n\n const enhancers = composeEnhancers(middleware);\n\n const store: ReduxStore = createReduxStore(\n combinedReducers,\n initialState,\n enhancers\n );\n\n if (!initialState) {\n store.dispatch(locationChange(history.location, \"PUSH\"));\n }\n return { history, store };\n};\n\nexport default configureStore;\n"],"mappings":"AACA,SACEA,eAAe,EACfC,OAAO,EACPC,eAAe,EACfC,WAAW,IAAIC,gBAAgB,QAC1B,OAAO;AACd,OAAOC,KAAK,MAAM,aAAa;AAE/B,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,mBAAmB,QAAQ,mCAAmC;AAEvE,SAASC,aAAa,QAAQ,2BAA2B;AACzD,SAASC,cAAc,QAAQ,0BAA0B;AAMzD;AACA;AACA,MAAMC,cAAc,GAAG,CACrBC,OAAsB,EACtBC,cAAuB,EACvBC,YAAiC,KACiB;EAClD,IAAIC,gBAAgB,GAAGb,OAAO;EAE9B,IAAIc,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IAC1EJ,gBAAgB,GAAGI,MAAM,CAACC,oCAAoC,IAAIlB,OAAO;EAC3E;EAEA,MAAMmB,gBAAkD,GAAGlB,eAAe,CAAC;IACzE,GAAGU,cAAc;IACjB,GAAGJ,aAAa;EAClB,CAAC,CAAC;EAEF,MAAMa,UAAU,GAAGrB,eAAe,CAChCO,mBAAmB,EACnBD,gBAAgB,CAACK,OAAO,CAAC,EACzBN,KAAK,CACN;EAED,MAAMiB,SAAS,GAAGR,gBAAgB,CAACO,UAAU,CAAC;EAE9C,MAAME,KAAiB,GAAGnB,gBAAgB,CACxCgB,gBAAgB,EAChBP,YAAY,EACZS,SAAS,CACV;EAED,IAAI,CAACT,YAAY,EAAE;IACjBU,KAAK,CAACC,QAAQ,CAACf,cAAc,CAACE,OAAO,CAACc,QAAQ,EAAE,MAAM,CAAC,CAAC;EAC1D;EACA,OAAO;IAAEd,OAAO;IAAEY;EAAM,CAAC;AAC3B,CAAC;AAED,eAAeb,cAAc"}
1
+ {"version":3,"file":"configureStore.js","names":["applyMiddleware","compose","combineReducers","createStore","createReduxStore","thunk","routerMiddleware","modularUIMiddleware","createReducer","locationChange","configureStore","history","customReducers","initialState","composeEnhancers","process","env","NODE_ENV","window","__REDUX_DEVTOOLS_EXTENSION_COMPOSE__","combinedReducers","middleware","enhancers","store","router","dispatch","location"],"sources":["../../../src/redux/store/configureStore.js"],"sourcesContent":["// @flow\nimport {\n applyMiddleware,\n compose,\n combineReducers,\n createStore as createReduxStore,\n} from \"redux\";\nimport thunk from \"redux-thunk\";\n\nimport { routerMiddleware } from \"../_router/RouterMiddleware\";\nimport { modularUIMiddleware } from \"../_modularui/ModularUIMiddleware\";\n\nimport { createReducer } from \"../reducers/createReducer\";\nimport { locationChange } from \"../_router/RouterActions\";\n\nimport type { RouterHistory } from \"react-router\";\nimport type { ReduxAction, ReduxState, ReduxStore } from \"../types\";\nimport type { Reducer } from \"redux\";\n\n/**\n */\nconst configureStore = (\n history: RouterHistory,\n customReducers?: Object,\n initialState?: $Shape<ReduxState>\n): { history: RouterHistory, store: ReduxStore } => {\n let composeEnhancers = compose;\n\n if (process.env.NODE_ENV !== \"production\" && typeof window !== \"undefined\") {\n composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;\n }\n\n const combinedReducers: Reducer<ReduxState, ReduxAction> = combineReducers({\n ...customReducers,\n ...createReducer(),\n });\n\n const middleware = applyMiddleware(\n modularUIMiddleware,\n routerMiddleware(history),\n thunk\n );\n\n const enhancers = composeEnhancers(middleware);\n\n const store: ReduxStore = createReduxStore(\n combinedReducers,\n initialState,\n enhancers\n );\n\n if (!initialState?.router) {\n store.dispatch(locationChange(history.location, \"PUSH\"));\n }\n return { history, store };\n};\n\nexport default configureStore;\n"],"mappings":"AACA,SACEA,eAAe,EACfC,OAAO,EACPC,eAAe,EACfC,WAAW,IAAIC,gBAAgB,QAC1B,OAAO;AACd,OAAOC,KAAK,MAAM,aAAa;AAE/B,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,mBAAmB,QAAQ,mCAAmC;AAEvE,SAASC,aAAa,QAAQ,2BAA2B;AACzD,SAASC,cAAc,QAAQ,0BAA0B;AAMzD;AACA;AACA,MAAMC,cAAc,GAAG,CACrBC,OAAsB,EACtBC,cAAuB,EACvBC,YAAiC,KACiB;EAClD,IAAIC,gBAAgB,GAAGb,OAAO;EAE9B,IAAIc,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IAC1EJ,gBAAgB,GAAGI,MAAM,CAACC,oCAAoC,IAAIlB,OAAO;EAC3E;EAEA,MAAMmB,gBAAkD,GAAGlB,eAAe,CAAC;IACzE,GAAGU,cAAc;IACjB,GAAGJ,aAAa;EAClB,CAAC,CAAC;EAEF,MAAMa,UAAU,GAAGrB,eAAe,CAChCO,mBAAmB,EACnBD,gBAAgB,CAACK,OAAO,CAAC,EACzBN,KAAK,CACN;EAED,MAAMiB,SAAS,GAAGR,gBAAgB,CAACO,UAAU,CAAC;EAE9C,MAAME,KAAiB,GAAGnB,gBAAgB,CACxCgB,gBAAgB,EAChBP,YAAY,EACZS,SAAS,CACV;EAED,IAAI,CAACT,YAAY,EAAEW,MAAM,EAAE;IACzBD,KAAK,CAACE,QAAQ,CAAChB,cAAc,CAACE,OAAO,CAACe,QAAQ,EAAE,MAAM,CAAC,CAAC;EAC1D;EACA,OAAO;IAAEf,OAAO;IAAEY;EAAM,CAAC;AAC3B,CAAC;AAED,eAAeb,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../src/redux/types.js"],"sourcesContent":["// @flow\nimport type { Store, DispatchAPI } from \"redux\";\n\nimport type ErrorResponse from \"../models/error/ErrorResponse\";\n\nimport type FormModel from \"../models/form/FormModel\";\nimport typeof {\n NOTIFICATION_TYPES,\n AUTOSAVE_STATUS,\n} from \"../constants/Constants\";\n\nimport type { MessageObject } from \"../i18n/types\";\nimport type {\n I18nState,\n UpdateLocaleAction,\n SetLocalesAction,\n} from \"./_i18n/types\";\nimport type {\n ModularUIState,\n ModularUIAction,\n UpdateStatusAction,\n SetModelAction,\n UpdateModelAction,\n RemoveModelByKeyAction,\n ResetModularUIAction,\n} from \"./_modularui/types\";\nimport type {\n RouterState,\n LocationChangeAction,\n PushAction,\n ReplaceAction,\n GoAction,\n GoBackAction,\n GoForwardAction,\n} from \"./_router/types\";\n\nexport type PreferenceValue =\n | null\n | string\n | boolean\n | { [key: string]: any }\n | Array<PreferenceValue>;\n\nexport type UpdateFormOptions = {\n autosubmit: boolean,\n autosave: boolean,\n forceUpdate?: boolean,\n /** Default true: Activate/deactivate the form object validate by an update */\n validate?: boolean,\n};\n\nexport type NoAction = {\n type: \"NO_ACTION\",\n};\n\nexport type SaveErrorAction = {\n type: \"SAVE_ERROR\",\n payload: ErrorResponse,\n};\n\nexport type ShowModalAction = {\n type: \"SHOW_MODAL\",\n payload: string,\n};\n\nexport type CloseModalAction = {\n type: \"CLOSE_MODAL\",\n payload: string,\n};\n\nexport type DismissNotificationAction = {\n type: \"DISMISS_NOTIFICATION\",\n};\nexport type ShowNotificationAction = {\n type: \"SHOW_NOTIFICATION\",\n payload: {\n type: $Keys<NOTIFICATION_TYPES>,\n message: MessageObject,\n error: ?ErrorResponse,\n },\n};\n\nexport type SetPreferenceAction = {\n type: \"SET_PREFERENCE\",\n payload: { [name: string]: PreferenceValue },\n};\nexport type SetPreferencesAction = {\n type: \"SET_PREFERENCES\",\n payload: { [name: string]: PreferenceValue },\n};\n\nexport type StartProgressAction = {\n type: \"START_PROGRESS\",\n};\nexport type FinishProgressAction = {\n type: \"FINISH_PROGRESS\",\n};\nexport type ResetProgressAction = {\n type: \"RESET_PROGRESS\",\n};\nexport type UpdateProgressAction = {\n type: \"UPDATE_PROGRESS\",\n payload: { percentComplete: number },\n};\n\nexport type SendAuthenticationErrorAction = {\n type: \"AUTHENTICATION_ERROR\",\n payload: string,\n};\n\nexport type ResetAuthErrorsAction = {\n type: \"AUTHENTICATION_RESET_ERRORS\",\n};\n\nexport type LoginSuccessAction = {\n type: \"AUTHENTICATION_SUCCESS\",\n};\n\nexport type ChangePasswordAction = {\n type: \"CHANGE_PASSWORD\",\n};\n\nexport type LogoutSuccessAction = {\n type: \"AUTHENTICATION_LOGOUT\",\n};\n\nexport type UpdateAutosaveAction = {\n type: \"UPDATE_AUTOSAVE_STATUS\",\n payload: {\n status: $Keys<AUTOSAVE_STATUS>,\n model: FormModel,\n },\n};\n\nexport type ReduxAction =\n | UpdateStatusAction\n | SetModelAction\n | UpdateModelAction\n | RemoveModelByKeyAction\n | ResetModularUIAction\n | SaveErrorAction\n | UpdateLocaleAction\n | SetLocalesAction\n | ShowModalAction\n | CloseModalAction\n | DismissNotificationAction\n | ShowNotificationAction\n | SetPreferenceAction\n | SetPreferencesAction\n | StartProgressAction\n | FinishProgressAction\n | ResetProgressAction\n | UpdateProgressAction\n | ResetAuthErrorsAction\n | SendAuthenticationErrorAction\n | LoginSuccessAction\n | ChangePasswordAction\n | LogoutSuccessAction\n | UpdateAutosaveAction\n | LocationChangeAction\n | PushAction\n | ReplaceAction\n | GoAction\n | GoBackAction\n | GoForwardAction\n | ModularUIAction\n | NoAction;\n\n// Redux state\nexport type AuthState = {\n +mustChangePassword: boolean,\n +error: ?string,\n};\n\nexport type ErrorState = null | ErrorResponse;\n\nexport type ModalState = {\n +key: string,\n +visible: boolean,\n +size?: string,\n};\n\nexport type ModalsState = {\n +modals: Array<ModalState>,\n};\n\nexport type NotificationState = {\n +render: boolean,\n +messageType: string | null,\n +message: MessageObject | null,\n +error: ?ErrorResponse | null,\n};\n\nexport type PreferencesState = {\n +[name: string]: PreferenceValue,\n};\n\nexport type ProgressIndicatorState = {\n +count: number,\n +timestamp: number,\n +percentComplete: number,\n};\n\nexport type ReduxState = {\n +router: RouterState,\n +modularui: ModularUIState,\n +i18n: I18nState,\n +auth: AuthState,\n +error: ErrorState,\n +modals: ModalsState,\n +notification: NotificationState,\n +progressindicator: ProgressIndicatorState,\n +preferences: PreferencesState,\n ...\n};\n\nexport type GetState = () => ReduxState;\nexport type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;\nexport type PromiseAction = Promise<PossibleAction>;\nexport type Dispatch = DispatchAPI<PossibleAction>;\nexport type ReduxStore = Store<ReduxState, ReduxAction, Dispatch>;\n\nexport type PossibleAction = ReduxAction | ThunkAction | PromiseAction;\n\nexport type CustomReducers = { [reducerKey: string]: any };\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/redux/types.js"],"sourcesContent":["// @flow\nimport type { Store, DispatchAPI } from \"redux\";\n\nimport type ErrorResponse from \"../models/error/ErrorResponse\";\n\nimport type FormModel from \"../models/form/FormModel\";\nimport typeof {\n NOTIFICATION_TYPES,\n AUTOSAVE_STATUS,\n} from \"../constants/Constants\";\n\nimport type { MessageObject } from \"../i18n/types\";\nimport type {\n I18nState,\n UpdateLocaleAction,\n SetLocalesAction,\n} from \"./_i18n/types\";\nimport type {\n ModularUIState,\n ModularUIAction,\n UpdateStatusAction,\n SetModelAction,\n UpdateModelAction,\n RemoveModelByKeyAction,\n ResetModularUIAction,\n InitModelAction,\n} from \"./_modularui/types\";\nimport type {\n RouterState,\n LocationChangeAction,\n PushAction,\n ReplaceAction,\n GoAction,\n GoBackAction,\n GoForwardAction,\n} from \"./_router/types\";\n\nexport type PreferenceValue =\n | null\n | string\n | boolean\n | { [key: string]: any }\n | Array<PreferenceValue>;\n\nexport type UpdateFormOptions = {\n autosubmit: boolean,\n autosave: boolean,\n forceUpdate?: boolean,\n /** Default true: Activate/deactivate the form object validate by an update */\n validate?: boolean,\n};\n\nexport type NoAction = {\n type: \"NO_ACTION\",\n};\n\nexport type SaveErrorAction = {\n type: \"SAVE_ERROR\",\n payload: ErrorResponse,\n};\n\nexport type ShowModalAction = {\n type: \"SHOW_MODAL\",\n payload: string,\n};\n\nexport type CloseModalAction = {\n type: \"CLOSE_MODAL\",\n payload: string,\n};\n\nexport type DismissNotificationAction = {\n type: \"DISMISS_NOTIFICATION\",\n};\nexport type ShowNotificationAction = {\n type: \"SHOW_NOTIFICATION\",\n payload: {\n type: $Keys<NOTIFICATION_TYPES>,\n message: MessageObject,\n error: ?ErrorResponse,\n },\n};\n\nexport type SetPreferenceAction = {\n type: \"SET_PREFERENCE\",\n payload: { [name: string]: PreferenceValue },\n};\nexport type SetPreferencesAction = {\n type: \"SET_PREFERENCES\",\n payload: { [name: string]: PreferenceValue },\n};\n\nexport type StartProgressAction = {\n type: \"START_PROGRESS\",\n};\nexport type FinishProgressAction = {\n type: \"FINISH_PROGRESS\",\n};\nexport type ResetProgressAction = {\n type: \"RESET_PROGRESS\",\n};\nexport type UpdateProgressAction = {\n type: \"UPDATE_PROGRESS\",\n payload: { percentComplete: number },\n};\n\nexport type SendAuthenticationErrorAction = {\n type: \"AUTHENTICATION_ERROR\",\n payload: string,\n};\n\nexport type ResetAuthErrorsAction = {\n type: \"AUTHENTICATION_RESET_ERRORS\",\n};\n\nexport type LoginSuccessAction = {\n type: \"AUTHENTICATION_SUCCESS\",\n};\n\nexport type ChangePasswordAction = {\n type: \"CHANGE_PASSWORD\",\n};\n\nexport type LogoutSuccessAction = {\n type: \"AUTHENTICATION_LOGOUT\",\n};\n\nexport type UpdateAutosaveAction = {\n type: \"UPDATE_AUTOSAVE_STATUS\",\n payload: {\n status: $Keys<AUTOSAVE_STATUS>,\n model: FormModel,\n },\n};\n\nexport type ReduxAction =\n | UpdateStatusAction\n | SetModelAction\n | InitModelAction\n | UpdateModelAction\n | RemoveModelByKeyAction\n | ResetModularUIAction\n | SaveErrorAction\n | UpdateLocaleAction\n | SetLocalesAction\n | ShowModalAction\n | CloseModalAction\n | DismissNotificationAction\n | ShowNotificationAction\n | SetPreferenceAction\n | SetPreferencesAction\n | StartProgressAction\n | FinishProgressAction\n | ResetProgressAction\n | UpdateProgressAction\n | ResetAuthErrorsAction\n | SendAuthenticationErrorAction\n | LoginSuccessAction\n | ChangePasswordAction\n | LogoutSuccessAction\n | UpdateAutosaveAction\n | LocationChangeAction\n | PushAction\n | ReplaceAction\n | GoAction\n | GoBackAction\n | GoForwardAction\n | ModularUIAction\n | NoAction;\n\n// Redux state\nexport type AuthState = {\n +mustChangePassword: boolean,\n +error: ?string,\n};\n\nexport type ErrorState = null | ErrorResponse;\n\nexport type ModalState = {\n +key: string,\n +visible: boolean,\n +size?: string,\n};\n\nexport type ModalsState = {\n +modals: Array<ModalState>,\n};\n\nexport type NotificationState = {\n +render: boolean,\n +messageType: string | null,\n +message: MessageObject | null,\n +error: ?ErrorResponse | null,\n};\n\nexport type PreferencesState = {\n +[name: string]: PreferenceValue,\n};\n\nexport type ProgressIndicatorState = {\n +count: number,\n +timestamp: number,\n +percentComplete: number,\n};\n\nexport type ReduxState = {\n +router: RouterState,\n +modularui: ModularUIState,\n +i18n: I18nState,\n +auth: AuthState,\n +error: ErrorState,\n +modals: ModalsState,\n +notification: NotificationState,\n +progressindicator: ProgressIndicatorState,\n +preferences: PreferencesState,\n ...\n};\n\nexport type GetState = () => ReduxState;\nexport type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;\nexport type PromiseAction = Promise<PossibleAction>;\nexport type Dispatch = DispatchAPI<PossibleAction>;\nexport type ReduxStore = Store<ReduxState, ReduxAction, Dispatch>;\n\nexport type PossibleAction = ReduxAction | ThunkAction | PromiseAction;\n\nexport type CustomReducers = { [reducerKey: string]: any };\n"],"mappings":""}
@@ -1,16 +1,16 @@
1
1
  import Cookies from "js-cookie";
2
- import { BASE } from "../../constants/Constants";
2
+ import { getBasePath } from "../../constants/Settings";
3
3
  /**
4
4
  */
5
- const getCookie = name => {
5
+ export const getCookie = name => {
6
6
  return Cookies.get(name);
7
7
  };
8
8
 
9
9
  /**
10
10
  */
11
- const setCookie = (name, value, options) => {
11
+ export const setCookie = (name, value, options) => {
12
12
  const attributes = {
13
- path: BASE
13
+ path: getBasePath()
14
14
  };
15
15
  attributes.expires = options?.days;
16
16
  attributes.sameSite = options?.sameSite ?? "Strict";
@@ -20,10 +20,9 @@ const setCookie = (name, value, options) => {
20
20
 
21
21
  /**
22
22
  */
23
- const clearCookie = name => {
23
+ export const clearCookie = name => {
24
24
  Cookies.remove(name, {
25
- path: BASE
25
+ path: getBasePath()
26
26
  });
27
27
  };
28
- export { getCookie, setCookie, clearCookie };
29
28
  //# sourceMappingURL=Cookies.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cookies.js","names":["Cookies","BASE","getCookie","name","get","setCookie","value","options","attributes","path","expires","days","sameSite","secure","set","clearCookie","remove"],"sources":["../../../src/utils/browser/Cookies.js"],"sourcesContent":["// @flow\nimport Cookies from \"js-cookie\";\n\nimport { BASE } from \"../../constants/Constants\";\n\ntype CookieOptions = {\n days?: number,\n sameSite?: \"None\" | \"Lax\" | \"Strict\",\n secure?: boolean,\n};\n\ntype CookieAttributes = {\n path: string,\n expires?: number,\n sameSite?: string,\n secure?: boolean,\n};\n\n/**\n */\nconst getCookie = (name: string): null | string => {\n return Cookies.get(name);\n};\n\n/**\n */\nconst setCookie = (name: string, value: any, options?: CookieOptions) => {\n const attributes: CookieAttributes = { path: BASE };\n attributes.expires = options?.days;\n attributes.sameSite = options?.sameSite ?? \"Strict\";\n attributes.secure = options?.secure;\n\n Cookies.set(name, value, attributes);\n};\n\n/**\n */\nconst clearCookie = (name: string) => {\n Cookies.remove(name, { path: BASE });\n};\n\nexport { getCookie, setCookie, clearCookie };\n"],"mappings":"AACA,OAAOA,OAAO,MAAM,WAAW;AAE/B,SAASC,IAAI,QAAQ,2BAA2B;AAehD;AACA;AACA,MAAMC,SAAS,GAAIC,IAAY,IAAoB;EACjD,OAAOH,OAAO,CAACI,GAAG,CAACD,IAAI,CAAC;AAC1B,CAAC;;AAED;AACA;AACA,MAAME,SAAS,GAAG,CAACF,IAAY,EAAEG,KAAU,EAAEC,OAAuB,KAAK;EACvE,MAAMC,UAA4B,GAAG;IAAEC,IAAI,EAAER;EAAK,CAAC;EACnDO,UAAU,CAACE,OAAO,GAAGH,OAAO,EAAEI,IAAI;EAClCH,UAAU,CAACI,QAAQ,GAAGL,OAAO,EAAEK,QAAQ,IAAI,QAAQ;EACnDJ,UAAU,CAACK,MAAM,GAAGN,OAAO,EAAEM,MAAM;EAEnCb,OAAO,CAACc,GAAG,CAACX,IAAI,EAAEG,KAAK,EAAEE,UAAU,CAAC;AACtC,CAAC;;AAED;AACA;AACA,MAAMO,WAAW,GAAIZ,IAAY,IAAK;EACpCH,OAAO,CAACgB,MAAM,CAACb,IAAI,EAAE;IAAEM,IAAI,EAAER;EAAK,CAAC,CAAC;AACtC,CAAC;AAED,SAASC,SAAS,EAAEG,SAAS,EAAEU,WAAW"}
1
+ {"version":3,"file":"Cookies.js","names":["Cookies","getBasePath","getCookie","name","get","setCookie","value","options","attributes","path","expires","days","sameSite","secure","set","clearCookie","remove"],"sources":["../../../src/utils/browser/Cookies.js"],"sourcesContent":["// @flow\nimport Cookies from \"js-cookie\";\n\nimport { getBasePath } from \"../../constants/Settings\";\n\ntype CookieOptions = {\n days?: number,\n sameSite?: \"None\" | \"Lax\" | \"Strict\",\n secure?: boolean,\n};\n\ntype CookieAttributes = {\n path: string,\n expires?: number,\n sameSite?: string,\n secure?: boolean,\n};\n\n/**\n */\nexport const getCookie = (name: string): null | string => {\n return Cookies.get(name);\n};\n\n/**\n */\nexport const setCookie = (\n name: string,\n value: any,\n options?: CookieOptions\n) => {\n const attributes: CookieAttributes = { path: getBasePath() };\n attributes.expires = options?.days;\n attributes.sameSite = options?.sameSite ?? \"Strict\";\n attributes.secure = options?.secure;\n\n Cookies.set(name, value, attributes);\n};\n\n/**\n */\nexport const clearCookie = (name: string) => {\n Cookies.remove(name, { path: getBasePath() });\n};\n"],"mappings":"AACA,OAAOA,OAAO,MAAM,WAAW;AAE/B,SAASC,WAAW,QAAQ,0BAA0B;AAetD;AACA;AACA,OAAO,MAAMC,SAAS,GAAIC,IAAY,IAAoB;EACxD,OAAOH,OAAO,CAACI,GAAG,CAACD,IAAI,CAAC;AAC1B,CAAC;;AAED;AACA;AACA,OAAO,MAAME,SAAS,GAAG,CACvBF,IAAY,EACZG,KAAU,EACVC,OAAuB,KACpB;EACH,MAAMC,UAA4B,GAAG;IAAEC,IAAI,EAAER,WAAW;EAAG,CAAC;EAC5DO,UAAU,CAACE,OAAO,GAAGH,OAAO,EAAEI,IAAI;EAClCH,UAAU,CAACI,QAAQ,GAAGL,OAAO,EAAEK,QAAQ,IAAI,QAAQ;EACnDJ,UAAU,CAACK,MAAM,GAAGN,OAAO,EAAEM,MAAM;EAEnCb,OAAO,CAACc,GAAG,CAACX,IAAI,EAAEG,KAAK,EAAEE,UAAU,CAAC;AACtC,CAAC;;AAED;AACA;AACA,OAAO,MAAMO,WAAW,GAAIZ,IAAY,IAAK;EAC3CH,OAAO,CAACgB,MAAM,CAACb,IAAI,EAAE;IAAEM,IAAI,EAAER,WAAW;EAAG,CAAC,CAAC;AAC/C,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
2
  import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
3
- import { BASE } from "../../constants/Constants";
3
+ import { getBasePath } from "../../constants/Settings";
4
4
  import { FetchException } from "../../exceptions";
5
5
  /**
6
6
  * Fetch data from server (uses nashorn and datafetcher).
@@ -8,7 +8,7 @@ import { FetchException } from "../../exceptions";
8
8
  export default function serverFetch(args) {
9
9
  var _context;
10
10
  // remove contextPath of url, when the request is internal the context path is not needed
11
- const urlNoBase = _includesInstanceProperty(_context = args.url).call(_context, "http") ? args.url : args.url.replace(BASE, "");
11
+ const urlNoBase = _includesInstanceProperty(_context = args.url).call(_context, "http") ? args.url : args.url.replace(getBasePath(), "");
12
12
  const params = args.params ? args.params.replace("includeContext=true", "") : "";
13
13
  const url = params === "" ? urlNoBase : `${urlNoBase}?${params}`;
14
14
  const data = dataFetcher.fetch(url, args);
@@ -1 +1 @@
1
- {"version":3,"file":"serverFetch.js","names":["BASE","FetchException","serverFetch","args","urlNoBase","url","replace","params","data","dataFetcher","fetch","jsonData","JSON","parse","error","reject","resolve"],"sources":["../../../src/utils/fetch/serverFetch.js"],"sourcesContent":["// @flow\nimport { BASE } from \"../../constants/Constants\";\nimport { FetchException } from \"../../exceptions\";\n\nimport type { RequestOptions } from \"./types\";\n\n/**\n * Fetch data from server (uses nashorn and datafetcher).\n */\nexport default function serverFetch(args: RequestOptions): Promise<any> {\n // remove contextPath of url, when the request is internal the context path is not needed\n const urlNoBase = args.url.includes(\"http\")\n ? args.url\n : args.url.replace(BASE, \"\");\n const params = args.params\n ? args.params.replace(\"includeContext=true\", \"\")\n : \"\";\n const url = params === \"\" ? urlNoBase : `${urlNoBase}?${params}`;\n\n const data = dataFetcher.fetch(url, args);\n\n try {\n const jsonData = JSON.parse(data);\n\n if (jsonData.error) {\n return Promise.reject(new FetchException(jsonData, null, args));\n }\n\n return Promise.resolve(jsonData);\n } catch (error) {\n return Promise.reject(error);\n }\n}\n"],"mappings":";;AACA,SAASA,IAAI,QAAQ,2BAA2B;AAChD,SAASC,cAAc,QAAQ,kBAAkB;AAIjD;AACA;AACA;AACA,eAAe,SAASC,WAAW,CAACC,IAAoB,EAAgB;EAAA;EACtE;EACA,MAAMC,SAAS,GAAG,qCAAAD,IAAI,CAACE,GAAG,iBAAU,MAAM,CAAC,GACvCF,IAAI,CAACE,GAAG,GACRF,IAAI,CAACE,GAAG,CAACC,OAAO,CAACN,IAAI,EAAE,EAAE,CAAC;EAC9B,MAAMO,MAAM,GAAGJ,IAAI,CAACI,MAAM,GACtBJ,IAAI,CAACI,MAAM,CAACD,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,GAC9C,EAAE;EACN,MAAMD,GAAG,GAAGE,MAAM,KAAK,EAAE,GAAGH,SAAS,GAAI,GAAEA,SAAU,IAAGG,MAAO,EAAC;EAEhE,MAAMC,IAAI,GAAGC,WAAW,CAACC,KAAK,CAACL,GAAG,EAAEF,IAAI,CAAC;EAEzC,IAAI;IACF,MAAMQ,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACL,IAAI,CAAC;IAEjC,IAAIG,QAAQ,CAACG,KAAK,EAAE;MAClB,OAAO,SAAQC,MAAM,CAAC,IAAId,cAAc,CAACU,QAAQ,EAAE,IAAI,EAAER,IAAI,CAAC,CAAC;IACjE;IAEA,OAAO,SAAQa,OAAO,CAACL,QAAQ,CAAC;EAClC,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,OAAO,SAAQC,MAAM,CAACD,KAAK,CAAC;EAC9B;AACF"}
1
+ {"version":3,"file":"serverFetch.js","names":["getBasePath","FetchException","serverFetch","args","urlNoBase","url","replace","params","data","dataFetcher","fetch","jsonData","JSON","parse","error","reject","resolve"],"sources":["../../../src/utils/fetch/serverFetch.js"],"sourcesContent":["// @flow\nimport { getBasePath } from \"../../constants/Settings\";\nimport { FetchException } from \"../../exceptions\";\n\nimport type { RequestOptions } from \"./types\";\n\n/**\n * Fetch data from server (uses nashorn and datafetcher).\n */\nexport default function serverFetch(args: RequestOptions): Promise<any> {\n // remove contextPath of url, when the request is internal the context path is not needed\n const urlNoBase = args.url.includes(\"http\")\n ? args.url\n : args.url.replace(getBasePath(), \"\");\n const params = args.params\n ? args.params.replace(\"includeContext=true\", \"\")\n : \"\";\n const url = params === \"\" ? urlNoBase : `${urlNoBase}?${params}`;\n\n const data = dataFetcher.fetch(url, args);\n\n try {\n const jsonData = JSON.parse(data);\n\n if (jsonData.error) {\n return Promise.reject(new FetchException(jsonData, null, args));\n }\n\n return Promise.resolve(jsonData);\n } catch (error) {\n return Promise.reject(error);\n }\n}\n"],"mappings":";;AACA,SAASA,WAAW,QAAQ,0BAA0B;AACtD,SAASC,cAAc,QAAQ,kBAAkB;AAIjD;AACA;AACA;AACA,eAAe,SAASC,WAAW,CAACC,IAAoB,EAAgB;EAAA;EACtE;EACA,MAAMC,SAAS,GAAG,qCAAAD,IAAI,CAACE,GAAG,iBAAU,MAAM,CAAC,GACvCF,IAAI,CAACE,GAAG,GACRF,IAAI,CAACE,GAAG,CAACC,OAAO,CAACN,WAAW,EAAE,EAAE,EAAE,CAAC;EACvC,MAAMO,MAAM,GAAGJ,IAAI,CAACI,MAAM,GACtBJ,IAAI,CAACI,MAAM,CAACD,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,GAC9C,EAAE;EACN,MAAMD,GAAG,GAAGE,MAAM,KAAK,EAAE,GAAGH,SAAS,GAAI,GAAEA,SAAU,IAAGG,MAAO,EAAC;EAEhE,MAAMC,IAAI,GAAGC,WAAW,CAACC,KAAK,CAACL,GAAG,EAAEF,IAAI,CAAC;EAEzC,IAAI;IACF,MAAMQ,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACL,IAAI,CAAC;IAEjC,IAAIG,QAAQ,CAACG,KAAK,EAAE;MAClB,OAAO,SAAQC,MAAM,CAAC,IAAId,cAAc,CAACU,QAAQ,EAAE,IAAI,EAAER,IAAI,CAAC,CAAC;IACjE;IAEA,OAAO,SAAQa,OAAO,CAACL,QAAQ,CAAC;EAClC,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,OAAO,SAAQC,MAAM,CAACD,KAAK,CAAC;EAC9B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/utils/fetch/types.js"],"sourcesContent":["// @flow\nimport typeof { HTTP_METHODS } from \"../../constants/Constants\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\nexport type RequestURLOptions = {\n url: string,\n};\n\nexport type RequestBaseOptions = {\n method?: $Keys<HTTP_METHODS>,\n params?: string,\n data?: string | { [key: string]: string },\n timeout?: number,\n responseType?: string,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n includeContext?: boolean,\n locale?: string,\n cache?: boolean,\n isReload?: boolean,\n};\n\nexport type RequestOptions = { ...RequestURLOptions, ...RequestBaseOptions };\n\nexport type RequestModularUIOptions = {\n ...RequestBaseOptions,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n updateModel?: ModularUIModel,\n childmodels?: boolean,\n isValidationRequest?: boolean,\n removeOnUnmount?: boolean,\n};\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/utils/fetch/types.js"],"sourcesContent":["// @flow\nimport typeof { HTTP_METHODS } from \"../../constants/Constants\";\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { TargetModel } from \"../../modularui/types\";\n\nexport type RequestURLOptions = {\n url: string,\n};\n\nexport type RequestBaseOptions = {\n method?: $Keys<HTTP_METHODS>,\n params?: string,\n data?: any,\n timeout?: number,\n responseType?: string,\n headers?: {\n [headerName: string]: string,\n Accept?: string,\n \"Accept-Language\"?: string,\n \"Content-Type\"?: string,\n \"x-filename\"?: string,\n \"x-filesize\"?: string,\n },\n events?: { [eventName: string]: () => void },\n onProgress?: ProgressEventHandler,\n includeContext?: boolean,\n locale?: string,\n cache?: boolean,\n isReload?: boolean,\n};\n\nexport type RequestOptions = { ...RequestURLOptions, ...RequestBaseOptions };\n\nexport type RequestModularUIOptions = {\n ...RequestBaseOptions,\n targetModel?: TargetModel,\n forceTargetModel?: boolean,\n updateModel?: ModularUIModel,\n childmodels?: boolean,\n isValidationRequest?: boolean,\n removeOnUnmount?: boolean,\n};\n"],"mappings":""}
@@ -1,6 +1,7 @@
1
1
  import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
2
2
  import { isPlainObject } from "../helpers/objects";
3
- import { IS_SYNC, USE_CACHE } from "../../constants/Constants";
3
+ import { IS_SYNC } from "../../constants/Constants";
4
+ import { cacheContributions } from "../../constants";
4
5
  import serverFetch from "./serverFetch";
5
6
  import xhr from "./xhr";
6
7
  import Cache from "../browser/Cache";
@@ -37,7 +38,7 @@ const waitForCachedItem = cacheKey => {
37
38
  * @private
38
39
  */
39
40
  const browserFetch = args => {
40
- if (USE_CACHE && args.cache) {
41
+ if (cacheContributions() && args.cache) {
41
42
  const cacheKey = Cache.createResourceKey(args);
42
43
  if (Cache.hasItem(cacheKey)) {
43
44
  const cacheItem = Cache.getItem(cacheKey);
@@ -52,7 +53,7 @@ const browserFetch = args => {
52
53
  Cache.addItem(cacheKey, IS_FETCHING);
53
54
  }
54
55
  return xhr(args).then(response => {
55
- if (USE_CACHE && args.cache) {
56
+ if (cacheContributions() && args.cache) {
56
57
  const cacheKey = Cache.createResourceKey(args);
57
58
  Cache.addItem(cacheKey, response);
58
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"universalFetch.js","names":["isPlainObject","IS_SYNC","USE_CACHE","serverFetch","xhr","Cache","IS_FETCHING","waitForCachedItem","cacheKey","TIMEOUT","CHECK_TIMEOUT","resolve","reject","check","getItem","cachedItem","Error","setTimeout","browserFetch","args","cache","createResourceKey","hasItem","cacheItem","addItem","then","response","universalFetch","locale","headers","includeContext","url"],"sources":["../../../src/utils/fetch/universalFetch.js"],"sourcesContent":["// @flow\nimport { isPlainObject } from \"../helpers/objects\";\n\nimport { IS_SYNC, USE_CACHE } from \"../../constants/Constants\";\nimport serverFetch from \"./serverFetch\";\nimport xhr from \"./xhr\";\nimport Cache from \"../browser/Cache\";\n\nimport type { RequestOptions } from \"./types\";\n\ntype CachedResponse = any;\n\nconst IS_FETCHING = \"is-fetching\";\n\n/**\n * Checks each x ms if a cache item is set after fetching the item.\n * @private\n */\nconst waitForCachedItem = (cacheKey: string) => {\n let TIMEOUT = 3000;\n const CHECK_TIMEOUT = 100;\n\n return new Promise<CachedResponse>((resolve, reject) => {\n const check = () => {\n if (Cache.getItem(cacheKey) !== IS_FETCHING) {\n const cachedItem = Cache.getItem(cacheKey);\n if (cachedItem != null) {\n resolve(cachedItem);\n } else {\n reject(new Error(\"Empty cached item\"));\n }\n } else if (TIMEOUT <= 0) {\n reject(new Error(\"Empty cached item\"));\n } else {\n TIMEOUT = TIMEOUT - CHECK_TIMEOUT;\n setTimeout(check, CHECK_TIMEOUT);\n }\n };\n\n setTimeout(check, CHECK_TIMEOUT);\n });\n};\n\n/**\n * @private\n */\nconst browserFetch = (args: RequestOptions) => {\n if (USE_CACHE && args.cache) {\n const cacheKey = Cache.createResourceKey(args);\n\n if (Cache.hasItem(cacheKey)) {\n const cacheItem = Cache.getItem(cacheKey);\n\n if (cacheItem != null) {\n if (cacheItem === IS_FETCHING) {\n return waitForCachedItem(cacheKey);\n } else if (isPlainObject(cacheItem)) {\n return Promise.resolve(cacheItem);\n }\n }\n }\n\n Cache.addItem(cacheKey, IS_FETCHING);\n }\n\n return xhr(args).then((response) => {\n if (USE_CACHE && args.cache) {\n const cacheKey = Cache.createResourceKey(args);\n\n Cache.addItem(cacheKey, response);\n }\n\n return response;\n });\n};\n\n/**\n * Request data from server, uses server datafetcher or xhr in browser.\n */\nconst universalFetch = (\n args: RequestOptions\n): Promise<CachedResponse> | Promise<any> => {\n // Set locale as Accept-Language header\n if (args.locale) {\n args.headers = {\n \"Accept-Language\": args.locale,\n };\n }\n\n if (args.includeContext) {\n args.url = `${args.url}?includeContext=true`;\n }\n\n // server side no access to the browser cache apis, no cache available\n if (IS_SYNC) {\n return serverFetch(args);\n }\n\n return browserFetch(args);\n};\n\nexport default universalFetch;\n"],"mappings":";AACA,SAASA,aAAa,QAAQ,oBAAoB;AAElD,SAASC,OAAO,EAAEC,SAAS,QAAQ,2BAA2B;AAC9D,OAAOC,WAAW,MAAM,eAAe;AACvC,OAAOC,GAAG,MAAM,OAAO;AACvB,OAAOC,KAAK,MAAM,kBAAkB;AAMpC,MAAMC,WAAW,GAAG,aAAa;;AAEjC;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAIC,QAAgB,IAAK;EAC9C,IAAIC,OAAO,GAAG,IAAI;EAClB,MAAMC,aAAa,GAAG,GAAG;EAEzB,OAAO,aAA4B,CAACC,OAAO,EAAEC,MAA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C;EAEA,OAAOF,GAAG,CAACe,IAAI,CAAC,CAACM,IAAI,CAAEC,QAAQ,IAAK;IAClC,IAAIxB,SAAS,IAAIiB,IAAI,CAACC,KAAK,EAAE;MAC3B,MAAMZ,QAAQ,GAAGH,KAAK,CAACgB,iBAAiB,CAACF,IAAI,CAAC;MAE9Cd,KAAK,CAACmB,OAAO,CAAChB,QAAQ,EAAEkB,QAAQ,CAAC;IACnC;IAEA,OAAOA,QAAQ;EACjB,CAAC,CAAC;AACJ,CAAC;;AAED;AACA;AACA;AACA,MAAMC,cAAc,GAClBR,IAAoB,IACuB;EAC3C;EACA,IAAIA,IAAI,CAACS,MAAM,EAAE;IACfT,IAAI,CAACU,OAAO,GAAG;MACb,iBAAiB,EAAEV,IAAI,CAACS;IAC1B,CAAC;EACH;EAEA,IAAIT,IAAI,CAACW,cAAc,EAAE;IACvBX,IAAI,CAACY,GAAG,GAAI,GAAEZ,IAAI,CAACY,GAAI,sBAAqB;EAC9C;;EAEA;EACA,IAAI9B,OAAO,EAAE;IACX,OAAOE,WAAW,CAACgB,IAAI,CAAC;EAC1B;EAEA,OAAOD,YAAY,CAACC,IAAI,CAAC;AAC3B,CAAC;AAED,eAAeQ,cAAc"}
1
+ {"version":3,"file":"universalFetch.js","names":["isPlainObject","IS_SYNC","cacheContributions","serverFetch","xhr","Cache","IS_FETCHING","waitForCachedItem","cacheKey","TIMEOUT","CHECK_TIMEOUT","resolve","reject","check","getItem","cachedItem","Error","setTimeout","browserFetch","args","cache","createResourceKey","hasItem","cacheItem","addItem","then","response","universalFetch","locale","headers","includeContext","url"],"sources":["../../../src/utils/fetch/universalFetch.js"],"sourcesContent":["// @flow\nimport { isPlainObject } from \"../helpers/objects\";\n\nimport { IS_SYNC } from \"../../constants/Constants\";\nimport { cacheContributions } from \"../../constants\";\n\nimport serverFetch from \"./serverFetch\";\nimport xhr from \"./xhr\";\nimport Cache from \"../browser/Cache\";\n\nimport type { RequestOptions } from \"./types\";\n\ntype CachedResponse = any;\n\nconst IS_FETCHING = \"is-fetching\";\n\n/**\n * Checks each x ms if a cache item is set after fetching the item.\n * @private\n */\nconst waitForCachedItem = (cacheKey: string) => {\n let TIMEOUT = 3000;\n const CHECK_TIMEOUT = 100;\n\n return new Promise<CachedResponse>((resolve, reject) => {\n const check = () => {\n if (Cache.getItem(cacheKey) !== IS_FETCHING) {\n const cachedItem = Cache.getItem(cacheKey);\n if (cachedItem != null) {\n resolve(cachedItem);\n } else {\n reject(new Error(\"Empty cached item\"));\n }\n } else if (TIMEOUT <= 0) {\n reject(new Error(\"Empty cached item\"));\n } else {\n TIMEOUT = TIMEOUT - CHECK_TIMEOUT;\n setTimeout(check, CHECK_TIMEOUT);\n }\n };\n\n setTimeout(check, CHECK_TIMEOUT);\n });\n};\n\n/**\n * @private\n */\nconst browserFetch = (args: RequestOptions) => {\n if (cacheContributions() && args.cache) {\n const cacheKey = Cache.createResourceKey(args);\n\n if (Cache.hasItem(cacheKey)) {\n const cacheItem = Cache.getItem(cacheKey);\n\n if (cacheItem != null) {\n if (cacheItem === IS_FETCHING) {\n return waitForCachedItem(cacheKey);\n } else if (isPlainObject(cacheItem)) {\n return Promise.resolve(cacheItem);\n }\n }\n }\n\n Cache.addItem(cacheKey, IS_FETCHING);\n }\n\n return xhr(args).then((response) => {\n if (cacheContributions() && args.cache) {\n const cacheKey = Cache.createResourceKey(args);\n\n Cache.addItem(cacheKey, response);\n }\n\n return response;\n });\n};\n\n/**\n * Request data from server, uses server datafetcher or xhr in browser.\n */\nconst universalFetch = (\n args: RequestOptions\n): Promise<CachedResponse> | Promise<any> => {\n // Set locale as Accept-Language header\n if (args.locale) {\n args.headers = {\n \"Accept-Language\": args.locale,\n };\n }\n\n if (args.includeContext) {\n args.url = `${args.url}?includeContext=true`;\n }\n\n // server side no access to the browser cache apis, no cache available\n if (IS_SYNC) {\n return serverFetch(args);\n }\n\n return browserFetch(args);\n};\n\nexport default universalFetch;\n"],"mappings":";AACA,SAASA,aAAa,QAAQ,oBA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