@dr.pogodin/react-utils 1.25.6 → 1.26.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 (290) hide show
  1. package/babel.config.js +3 -1
  2. package/bin/build.js +18 -4
  3. package/build/development/client/getInj.js +9 -8
  4. package/build/development/client/getInj.js.map +1 -1
  5. package/build/development/client/index.js +6 -3
  6. package/build/development/client/index.js.map +1 -1
  7. package/build/development/client/init.js +4 -0
  8. package/build/development/client/init.js.map +1 -1
  9. package/build/development/index.js +166 -38
  10. package/build/development/index.js.map +1 -1
  11. package/build/development/server/Cache.js +13 -13
  12. package/build/development/server/Cache.js.map +1 -1
  13. package/build/development/server/index.js +16 -23
  14. package/build/development/server/index.js.map +1 -1
  15. package/build/development/server/renderer.js +56 -43
  16. package/build/development/server/renderer.js.map +1 -1
  17. package/build/development/server/server.js +9 -5
  18. package/build/development/server/server.js.map +1 -1
  19. package/build/development/server/utils/errors.js +12 -9
  20. package/build/development/server/utils/errors.js.map +1 -1
  21. package/build/development/server/utils/index.js +2 -2
  22. package/build/development/server/utils/index.js.map +1 -1
  23. package/build/development/shared/components/Button/index.js +7 -5
  24. package/build/development/shared/components/Button/index.js.map +1 -1
  25. package/build/development/shared/components/Checkbox/index.js +24 -26
  26. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  27. package/build/development/shared/components/Dropdown/index.js +24 -17
  28. package/build/development/shared/components/Dropdown/index.js.map +1 -1
  29. package/build/development/shared/components/GenericLink/index.js +44 -37
  30. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  31. package/build/development/shared/components/Input/index.js +7 -7
  32. package/build/development/shared/components/Input/index.js.map +1 -1
  33. package/build/development/shared/components/Link.js +10 -9
  34. package/build/development/shared/components/Link.js.map +1 -1
  35. package/build/development/shared/components/MetaTags.js +22 -18
  36. package/build/development/shared/components/MetaTags.js.map +1 -1
  37. package/build/development/shared/components/Modal/index.js +16 -16
  38. package/build/development/shared/components/Modal/index.js.map +1 -1
  39. package/build/development/shared/components/NavLink.js +10 -9
  40. package/build/development/shared/components/NavLink.js.map +1 -1
  41. package/build/development/shared/components/PageLayout/index.js +16 -18
  42. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  43. package/build/development/shared/components/ScalableRect/index.js +27 -7
  44. package/build/development/shared/components/ScalableRect/index.js.map +1 -1
  45. package/build/development/shared/components/Throbber/index.js +14 -22
  46. package/build/development/shared/components/Throbber/index.js.map +1 -1
  47. package/build/development/shared/components/WithTooltip/Tooltip.js +19 -21
  48. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  49. package/build/development/shared/components/WithTooltip/index.js +11 -10
  50. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  51. package/build/development/shared/components/YouTubeVideo/index.js +15 -13
  52. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  53. package/build/development/shared/components/index.js +2 -2
  54. package/build/development/shared/components/index.js.map +1 -1
  55. package/build/development/shared/utils/config.js.map +1 -1
  56. package/build/development/shared/utils/globalState.js +15 -0
  57. package/build/development/shared/utils/globalState.js.map +1 -0
  58. package/build/development/shared/utils/index.js +13 -10
  59. package/build/development/shared/utils/index.js.map +1 -1
  60. package/build/development/shared/utils/isomorphy/buildInfo.js +7 -3
  61. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  62. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  63. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  64. package/build/development/shared/utils/jest/E2eSsrEnv.js +35 -28
  65. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  66. package/build/development/shared/utils/jest/global.js +17 -0
  67. package/build/development/shared/utils/jest/global.js.map +1 -0
  68. package/build/development/shared/utils/jest/index.js +17 -9
  69. package/build/development/shared/utils/jest/index.js.map +1 -1
  70. package/build/development/shared/utils/splitComponent.js +25 -34
  71. package/build/development/shared/utils/splitComponent.js.map +1 -1
  72. package/build/development/shared/utils/time.js +16 -12
  73. package/build/development/shared/utils/time.js.map +1 -1
  74. package/build/development/shared/utils/webpack.js +3 -3
  75. package/build/development/shared/utils/webpack.js.map +1 -1
  76. package/build/development/web.bundle.js +92 -82
  77. package/build/production/client/getInj.js +1 -1
  78. package/build/production/client/getInj.js.map +1 -1
  79. package/build/production/client/index.js +4 -4
  80. package/build/production/client/index.js.map +1 -1
  81. package/build/production/client/init.js +3 -1
  82. package/build/production/client/init.js.map +1 -1
  83. package/build/production/index.js +1 -1
  84. package/build/production/index.js.map +1 -1
  85. package/build/production/server/Cache.js +7 -8
  86. package/build/production/server/Cache.js.map +1 -1
  87. package/build/production/server/index.js +5 -4
  88. package/build/production/server/index.js.map +1 -1
  89. package/build/production/server/renderer.js +32 -30
  90. package/build/production/server/renderer.js.map +1 -1
  91. package/build/production/server/server.js +7 -5
  92. package/build/production/server/server.js.map +1 -1
  93. package/build/production/server/utils/errors.js +9 -10
  94. package/build/production/server/utils/errors.js.map +1 -1
  95. package/build/production/server/utils/index.js +1 -1
  96. package/build/production/server/utils/index.js.map +1 -1
  97. package/build/production/shared/components/Button/index.js +3 -3
  98. package/build/production/shared/components/Button/index.js.map +1 -1
  99. package/build/production/shared/components/Checkbox/index.js +11 -11
  100. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  101. package/build/production/shared/components/Dropdown/index.js +11 -11
  102. package/build/production/shared/components/Dropdown/index.js.map +1 -1
  103. package/build/production/shared/components/GenericLink/index.js +25 -20
  104. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  105. package/build/production/shared/components/Input/index.js +7 -7
  106. package/build/production/shared/components/Input/index.js.map +1 -1
  107. package/build/production/shared/components/Link.js +2 -2
  108. package/build/production/shared/components/Link.js.map +1 -1
  109. package/build/production/shared/components/MetaTags.js +10 -10
  110. package/build/production/shared/components/MetaTags.js.map +1 -1
  111. package/build/production/shared/components/Modal/index.js +2 -2
  112. package/build/production/shared/components/Modal/index.js.map +1 -1
  113. package/build/production/shared/components/NavLink.js +1 -1
  114. package/build/production/shared/components/NavLink.js.map +1 -1
  115. package/build/production/shared/components/PageLayout/index.js +2 -2
  116. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  117. package/build/production/shared/components/ScalableRect/index.js +7 -3
  118. package/build/production/shared/components/ScalableRect/index.js.map +1 -1
  119. package/build/production/shared/components/Throbber/index.js +2 -2
  120. package/build/production/shared/components/Throbber/index.js.map +1 -1
  121. package/build/production/shared/components/WithTooltip/Tooltip.js +13 -13
  122. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  123. package/build/production/shared/components/WithTooltip/index.js +3 -3
  124. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  125. package/build/production/shared/components/YouTubeVideo/index.js +7 -7
  126. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  127. package/build/production/shared/components/index.js +1 -1
  128. package/build/production/shared/components/index.js.map +1 -1
  129. package/build/production/shared/utils/config.js.map +1 -1
  130. package/build/production/shared/utils/globalState.js +3 -0
  131. package/build/production/shared/utils/globalState.js.map +1 -0
  132. package/build/production/shared/utils/index.js +2 -2
  133. package/build/production/shared/utils/index.js.map +1 -1
  134. package/build/production/shared/utils/isomorphy/buildInfo.js +7 -4
  135. package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
  136. package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
  137. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  138. package/build/production/shared/utils/jest/E2eSsrEnv.js +9 -9
  139. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  140. package/build/production/shared/utils/jest/global.js +2 -0
  141. package/build/production/shared/utils/jest/global.js.map +1 -0
  142. package/build/production/shared/utils/jest/index.js +5 -5
  143. package/build/production/shared/utils/jest/index.js.map +1 -1
  144. package/build/production/shared/utils/splitComponent.js +16 -16
  145. package/build/production/shared/utils/splitComponent.js.map +1 -1
  146. package/build/production/shared/utils/time.js +12 -8
  147. package/build/production/shared/utils/time.js.map +1 -1
  148. package/build/production/shared/utils/webpack.js +3 -3
  149. package/build/production/shared/utils/webpack.js.map +1 -1
  150. package/build/production/web.bundle.js +1 -1
  151. package/build/production/web.bundle.js.map +1 -1
  152. package/build/types-code/client/getInj.d.ts +3 -0
  153. package/build/types-code/client/index.d.ts +11 -0
  154. package/build/types-code/client/init.d.ts +9 -0
  155. package/build/types-code/index.d.ts +10 -0
  156. package/build/types-code/server/Cache.d.ts +37 -0
  157. package/build/types-code/server/index.d.ts +145 -0
  158. package/build/types-code/server/renderer.d.ts +106 -0
  159. package/build/types-code/server/server.d.ts +41 -0
  160. package/build/types-code/server/utils/errors.d.ts +104 -0
  161. package/build/types-code/server/utils/index.d.ts +1 -0
  162. package/build/types-code/shared/components/Button/index.d.ts +27 -0
  163. package/build/types-code/shared/components/Checkbox/index.d.ts +21 -0
  164. package/build/types-code/shared/components/Dropdown/index.d.ts +23 -0
  165. package/build/types-code/shared/components/GenericLink/index.d.ts +61 -0
  166. package/build/types-code/shared/components/Input/index.d.ts +11 -0
  167. package/build/types-code/shared/components/Link.d.ts +12 -0
  168. package/build/types-code/shared/components/MetaTags.d.ts +68 -0
  169. package/build/types-code/shared/components/Modal/index.d.ts +26 -0
  170. package/build/types-code/shared/components/NavLink.d.ts +5 -0
  171. package/build/types-code/shared/components/PageLayout/index.d.ts +16 -0
  172. package/build/types-code/shared/components/ScalableRect/index.d.ts +19 -0
  173. package/build/types-code/shared/components/Throbber/index.d.ts +9 -0
  174. package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +23 -0
  175. package/build/types-code/shared/components/WithTooltip/index.d.ts +17 -0
  176. package/build/types-code/shared/components/YouTubeVideo/index.d.ts +13 -0
  177. package/build/types-code/shared/components/index.d.ts +16 -0
  178. package/build/types-code/shared/utils/config.d.ts +2 -0
  179. package/build/types-code/shared/utils/globalState.d.ts +20 -0
  180. package/build/types-code/shared/utils/index.d.ts +52 -0
  181. package/build/types-code/shared/utils/isomorphy/buildInfo.d.ts +23 -0
  182. package/build/types-code/shared/utils/isomorphy/environment-check.d.ts +11 -0
  183. package/build/types-code/shared/utils/isomorphy/index.d.ts +20 -0
  184. package/build/types-code/shared/utils/jest/E2eSsrEnv.d.ts +31 -0
  185. package/build/types-code/shared/utils/jest/global.d.ts +12 -0
  186. package/build/types-code/shared/utils/jest/index.d.ts +85 -0
  187. package/build/types-code/shared/utils/splitComponent.d.ts +41 -0
  188. package/build/types-code/shared/utils/time.d.ts +62 -0
  189. package/build/types-code/shared/utils/webpack.d.ts +18 -0
  190. package/build/types-scss/__tests__/js/config/publicPath support/__assets__/style.scss.d.ts +1 -0
  191. package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
  192. package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
  193. package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
  194. package/build/types-scss/__tests__/js/shared/components/NavLink/styles.scss.d.ts +1 -0
  195. package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
  196. package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
  197. package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
  198. package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
  199. package/build/types-scss/__tests__/ts/config/publicPath support/__assets__/style.scss.d.ts +1 -0
  200. package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
  201. package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
  202. package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
  203. package/build/types-scss/__tests__/ts/shared/components/NavLink/styles.scss.d.ts +1 -0
  204. package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
  205. package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
  206. package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
  207. package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
  208. package/build/types-scss/src/shared/components/Button/style.scss.d.ts +6 -0
  209. package/build/types-scss/src/shared/components/Checkbox/theme.scss.d.ts +6 -0
  210. package/build/types-scss/src/shared/components/Dropdown/theme.scss.d.ts +9 -0
  211. package/build/types-scss/src/shared/components/GenericLink/style.scss.d.ts +1 -0
  212. package/build/types-scss/src/shared/components/Input/theme.scss.d.ts +6 -0
  213. package/build/types-scss/src/shared/components/Modal/base-theme.scss.d.ts +5 -0
  214. package/build/types-scss/src/shared/components/PageLayout/base-theme.scss.d.ts +6 -0
  215. package/build/types-scss/src/shared/components/ScalableRect/style.scss.d.ts +2 -0
  216. package/build/types-scss/src/shared/components/Throbber/theme.scss.d.ts +6 -0
  217. package/build/types-scss/src/shared/components/WithTooltip/default-theme.scss.d.ts +7 -0
  218. package/build/types-scss/src/shared/components/YouTubeVideo/base.scss.d.ts +5 -0
  219. package/build/types-scss/src/shared/components/YouTubeVideo/throbber.scss.d.ts +4 -0
  220. package/config/eslint/jest.json +3 -2
  221. package/config/eslint/typescript.js +34 -0
  222. package/config/jest/default.js +3 -3
  223. package/package.json +74 -32
  224. package/src/client/getInj.ts +43 -0
  225. package/src/client/index.tsx +40 -0
  226. package/src/client/init.ts +47 -0
  227. package/src/index.ts +58 -0
  228. package/src/server/Cache.ts +68 -0
  229. package/src/server/index.ts +230 -0
  230. package/src/server/renderer.tsx +604 -0
  231. package/src/server/server.ts +309 -0
  232. package/src/server/utils/errors.ts +135 -0
  233. package/src/server/utils/index.ts +3 -0
  234. package/src/shared/components/Button/index.tsx +146 -0
  235. package/src/shared/components/Button/style.scss +53 -0
  236. package/src/shared/components/Checkbox/index.tsx +71 -0
  237. package/src/shared/components/Checkbox/theme.scss +43 -0
  238. package/src/shared/components/Dropdown/index.tsx +144 -0
  239. package/src/shared/components/Dropdown/theme.scss +63 -0
  240. package/src/shared/components/GenericLink/index.tsx +157 -0
  241. package/src/shared/components/GenericLink/style.scss +3 -0
  242. package/src/shared/components/Input/index.tsx +59 -0
  243. package/src/shared/components/Input/theme.scss +27 -0
  244. package/src/shared/components/Link.tsx +21 -0
  245. package/src/shared/components/MetaTags.tsx +170 -0
  246. package/src/shared/components/Modal/base-theme.scss +38 -0
  247. package/src/shared/components/Modal/index.tsx +144 -0
  248. package/src/shared/components/Modal/styles.scss +5 -0
  249. package/src/shared/components/NavLink.tsx +13 -0
  250. package/src/shared/components/PageLayout/base-theme.scss +30 -0
  251. package/src/shared/components/PageLayout/index.tsx +76 -0
  252. package/src/shared/components/ScalableRect/index.tsx +84 -0
  253. package/src/shared/components/ScalableRect/style.scss +10 -0
  254. package/src/shared/components/Throbber/index.tsx +43 -0
  255. package/src/shared/components/Throbber/theme.scss +26 -0
  256. package/src/shared/components/WithTooltip/Tooltip.tsx +353 -0
  257. package/src/shared/components/WithTooltip/default-theme.scss +36 -0
  258. package/src/shared/components/WithTooltip/index.tsx +204 -0
  259. package/src/shared/components/YouTubeVideo/base.scss +13 -0
  260. package/src/shared/components/YouTubeVideo/index.tsx +96 -0
  261. package/src/shared/components/YouTubeVideo/throbber.scss +11 -0
  262. package/src/shared/components/index.ts +17 -0
  263. package/src/shared/utils/config.ts +21 -0
  264. package/src/shared/utils/globalState.ts +29 -0
  265. package/src/shared/utils/index.ts +105 -0
  266. package/src/shared/utils/isomorphy/buildInfo.ts +54 -0
  267. package/src/shared/utils/isomorphy/environment-check.ts +18 -0
  268. package/src/shared/utils/isomorphy/index.ts +38 -0
  269. package/src/shared/utils/jest/E2eSsrEnv.ts +250 -0
  270. package/src/shared/utils/jest/global.ts +19 -0
  271. package/src/shared/utils/jest/index.tsx +157 -0
  272. package/src/shared/utils/splitComponent.tsx +255 -0
  273. package/src/shared/utils/time.ts +118 -0
  274. package/src/shared/utils/webpack.ts +45 -0
  275. package/src/styles/_global/reset.css +52 -0
  276. package/src/styles/global.scss +11 -0
  277. package/tsconfig.configs.json +18 -0
  278. package/tsconfig.json +27 -0
  279. package/tsconfig.types.json +53 -0
  280. package/typed-scss-modules.config.ts +9 -0
  281. package/types.d.ts +37 -0
  282. package/{webpack.config.js → webpack.config.ts} +7 -3
  283. package/config/babel/node-ssr.js +0 -85
  284. package/config/babel/webpack.js +0 -123
  285. package/config/webpack/app-base.js +0 -330
  286. package/config/webpack/app-development.js +0 -80
  287. package/config/webpack/app-production.js +0 -60
  288. package/config/webpack/lib-base.js +0 -155
  289. package/config/webpack/lib-development.js +0 -45
  290. package/config/webpack/lib-production.js +0 -44
@@ -4,7 +4,7 @@
4
4
  // Safeguard is needed here, because the server-side version of Docusaurus docs
5
5
  // is compiled (at least now) with settings suggesting it is a client-side
6
6
  // environment, but there is no document.
7
- let inj=typeof document!=="undefined"&&document.querySelector("meta[itemprop=\"drpruinj\"]");if(inj){inj.remove();const{key}=(0,_buildInfo.getBuildInfo)();inj=_forge.default.util.decode64(inj.content);const d=_forge.default.cipher.createDecipher("AES-CBC",key);d.start({iv:inj.slice(0,key.length)});d.update(_forge.default.util.createBuffer(inj.slice(key.length)));d.finish();inj=_forge.default.util.decodeUtf8(d.output.data);inj=eval(`(${inj})`);// eslint-disable-line no-eval
7
+ let inj={};const metaElement=typeof document!=="undefined"?document.querySelector("meta[itemprop=\"drpruinj\"]"):null;if(metaElement){metaElement.remove();let data=_forge.default.util.decode64(metaElement.content);const{key}=(0,_buildInfo.getBuildInfo)();const d=_forge.default.cipher.createDecipher("AES-CBC",key);d.start({iv:data.slice(0,key.length)});d.update(_forge.default.util.createBuffer(data.slice(key.length)));d.finish();data=_forge.default.util.decodeUtf8(d.output.data);inj=eval(`(${data})`);// eslint-disable-line no-eval
8
8
  }else{// Otherwise, a bunch of dependent stuff will easily fail in non-standard
9
9
  // environments, where no client-side initialization is performed. Like tests,
10
10
  // Docusaurus examples, etc.
@@ -1 +1 @@
1
- {"version":3,"file":"getInj.js","names":["_forge","_interopRequireDefault","require","_buildInfo","inj","document","querySelector","remove","key","getBuildInfo","forge","util","decode64","content","d","cipher","createDecipher","start","iv","slice","length","update","createBuffer","finish","decodeUtf8","output","data","eval","getInj"],"sources":["../../../src/client/getInj.js"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\n// Note: this way, only required part of \"node-forge\": AES, and some utils,\n// is bundled into client-side code.\nimport forge from 'node-forge/lib/forge';\nimport 'node-forge/lib/aes';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\n// Safeguard is needed here, because the server-side version of Docusaurus docs\n// is compiled (at least now) with settings suggesting it is a client-side\n// environment, but there is no document.\nlet inj = typeof document !== 'undefined'\n && document.querySelector('meta[itemprop=\"drpruinj\"]');\n\nif (inj) {\n inj.remove();\n const { key } = getBuildInfo();\n inj = forge.util.decode64(inj.content);\n const d = forge.cipher.createDecipher('AES-CBC', key);\n d.start({ iv: inj.slice(0, key.length) });\n d.update(forge.util.createBuffer(inj.slice(key.length)));\n d.finish();\n inj = forge.util.decodeUtf8(d.output.data);\n inj = eval(`(${inj})`); // eslint-disable-line no-eval\n} else {\n // Otherwise, a bunch of dependent stuff will easily fail in non-standard\n // environments, where no client-side initialization is performed. Like tests,\n // Docusaurus examples, etc.\n inj = {};\n}\n\nexport default function getInj() {\n return inj;\n}\n"],"mappings":"gLAMA,IAAAA,MAAA,CAAAC,sBAAA,CAAAC,OAAA,0BACAA,OAAA,uBAEA,IAAAC,UAAA,CAAAD,OAAA,wCATA;AAEA,sBAEA;AACA;AAMA;AACA;AACA;AACA,GAAI,CAAAE,GAAG,CAAG,MAAO,CAAAC,QAAQ,GAAK,WAAW,EACpCA,QAAQ,CAACC,aAAa,CAAC,6BAA2B,CAAC,CAExD,GAAIF,GAAG,CAAE,CACPA,GAAG,CAACG,MAAM,CAAC,CAAC,CACZ,KAAM,CAAEC,GAAI,CAAC,CAAG,GAAAC,uBAAY,EAAC,CAAC,CAC9BL,GAAG,CAAGM,cAAK,CAACC,IAAI,CAACC,QAAQ,CAACR,GAAG,CAACS,OAAO,CAAC,CACtC,KAAM,CAAAC,CAAC,CAAGJ,cAAK,CAACK,MAAM,CAACC,cAAc,CAAC,SAAS,CAAER,GAAG,CAAC,CACrDM,CAAC,CAACG,KAAK,CAAC,CAAEC,EAAE,CAAEd,GAAG,CAACe,KAAK,CAAC,CAAC,CAAEX,GAAG,CAACY,MAAM,CAAE,CAAC,CAAC,CACzCN,CAAC,CAACO,MAAM,CAACX,cAAK,CAACC,IAAI,CAACW,YAAY,CAAClB,GAAG,CAACe,KAAK,CAACX,GAAG,CAACY,MAAM,CAAC,CAAC,CAAC,CACxDN,CAAC,CAACS,MAAM,CAAC,CAAC,CACVnB,GAAG,CAAGM,cAAK,CAACC,IAAI,CAACa,UAAU,CAACV,CAAC,CAACW,MAAM,CAACC,IAAI,CAAC,CAC1CtB,GAAG,CAAGuB,IAAI,CAAE,IAAGvB,GAAI,GAAE,CAAC,CAAE;AAC1B,CAAC,IAAM,CACL;AACA;AACA;AACAA,GAAG,CAAG,CAAC,CACT,CAEe,QAAS,CAAAwB,MAAMA,CAAA,CAAG,CAC/B,MAAO,CAAAxB,GACT"}
1
+ {"version":3,"file":"getInj.js","names":["_forge","_interopRequireDefault","require","_buildInfo","inj","metaElement","document","querySelector","remove","data","forge","util","decode64","content","key","getBuildInfo","d","cipher","createDecipher","start","iv","slice","length","update","createBuffer","finish","decodeUtf8","output","eval","getInj"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\n// Note: this way, only required part of \"node-forge\": AES, and some utils,\n// is bundled into client-side code.\nimport forge from 'node-forge/lib/forge';\nimport 'node-forge/lib/aes';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\n// Safeguard is needed here, because the server-side version of Docusaurus docs\n// is compiled (at least now) with settings suggesting it is a client-side\n// environment, but there is no document.\nlet inj: InjT = {};\n\nconst metaElement: HTMLMetaElement | null = typeof document !== 'undefined'\n ? document.querySelector('meta[itemprop=\"drpruinj\"]') : null;\n\nif (metaElement) {\n metaElement.remove();\n let data = forge.util.decode64(metaElement.content);\n\n const { key } = getBuildInfo();\n const d = forge.cipher.createDecipher('AES-CBC', key);\n d.start({ iv: data.slice(0, key.length) });\n d.update(forge.util.createBuffer(data.slice(key.length)));\n d.finish();\n\n data = forge.util.decodeUtf8(d.output.data);\n inj = eval(`(${data})`); // eslint-disable-line no-eval\n} else {\n // Otherwise, a bunch of dependent stuff will easily fail in non-standard\n // environments, where no client-side initialization is performed. Like tests,\n // Docusaurus examples, etc.\n inj = {};\n}\n\nexport default function getInj(): InjT {\n return inj;\n}\n"],"mappings":"gLAMA,IAAAA,MAAA,CAAAC,sBAAA,CAAAC,OAAA,0BACAA,OAAA,uBAIA,IAAAC,UAAA,CAAAD,OAAA,wCAXA;AAEA,sBAEA;AACA;AAQA;AACA;AACA;AACA,GAAI,CAAAE,GAAS,CAAG,CAAC,CAAC,CAElB,KAAM,CAAAC,WAAmC,CAAG,MAAO,CAAAC,QAAQ,GAAK,WAAW,CACvEA,QAAQ,CAACC,aAAa,CAAC,6BAA2B,CAAC,CAAG,IAAI,CAE9D,GAAIF,WAAW,CAAE,CACfA,WAAW,CAACG,MAAM,CAAC,CAAC,CACpB,GAAI,CAAAC,IAAI,CAAGC,cAAK,CAACC,IAAI,CAACC,QAAQ,CAACP,WAAW,CAACQ,OAAO,CAAC,CAEnD,KAAM,CAAEC,GAAI,CAAC,CAAG,GAAAC,uBAAY,EAAC,CAAC,CAC9B,KAAM,CAAAC,CAAC,CAAGN,cAAK,CAACO,MAAM,CAACC,cAAc,CAAC,SAAS,CAAEJ,GAAG,CAAC,CACrDE,CAAC,CAACG,KAAK,CAAC,CAAEC,EAAE,CAAEX,IAAI,CAACY,KAAK,CAAC,CAAC,CAAEP,GAAG,CAACQ,MAAM,CAAE,CAAC,CAAC,CAC1CN,CAAC,CAACO,MAAM,CAACb,cAAK,CAACC,IAAI,CAACa,YAAY,CAACf,IAAI,CAACY,KAAK,CAACP,GAAG,CAACQ,MAAM,CAAC,CAAC,CAAC,CACzDN,CAAC,CAACS,MAAM,CAAC,CAAC,CAEVhB,IAAI,CAAGC,cAAK,CAACC,IAAI,CAACe,UAAU,CAACV,CAAC,CAACW,MAAM,CAAClB,IAAI,CAAC,CAC3CL,GAAG,CAAGwB,IAAI,CAAE,IAAGnB,IAAK,GAAE,CAAC,CAAE;AAC3B,CAAC,IAAM,CACL;AACA;AACA;AACAL,GAAG,CAAG,CAAC,CACT,CAEe,QAAS,CAAAyB,MAAMA,CAAA,CAAS,CACrC,MAAO,CAAAzB,GACT"}
@@ -1,7 +1,7 @@
1
- "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=Launch;var _reactGlobalState=require("@dr.pogodin/react-global-state");var _client=require("react-dom/client");var _reactRouterDom=require("react-router-dom");var _getInj=_interopRequireDefault(require("./getInj"));var _jsxRuntime=require("react/jsx-runtime");// Initialization of client-side code.
1
+ "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=Launch;require("react");var _reactGlobalState=require("@dr.pogodin/react-global-state");var _client=require("react-dom/client");var _reactRouterDom=require("react-router-dom");var _getInj=_interopRequireDefault(require("./getInj"));var _jsxRuntime=require("react/jsx-runtime");// Initialization of client-side code.
2
2
  /* global document */ /**
3
3
  * Prepares and launches the app at client side.
4
- * @param {object} Application Root application component
5
- * @param {object} [options={}] Optional. Additional settings.
6
- */function Launch(Application){let options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};const container=document.getElementById("react-view");const scene=/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider,{initialState:(0,_getInj.default)().ISTATE,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactRouterDom.BrowserRouter,{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(Application,{})})});if(options.dontHydrate){const root=(0,_client.createRoot)(container);root.render(scene)}else(0,_client.hydrateRoot)(container,scene)}
4
+ * @param Application Root application component
5
+ * @param [options={}] Optional. Additional settings.
6
+ */function Launch(Application){let options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};const container=document.getElementById("react-view");if(!container)throw Error("Failed to find container for React app");const scene=/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider,{initialState:(0,_getInj.default)().ISTATE,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactRouterDom.BrowserRouter,{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(Application,{})})});if(options.dontHydrate){const root=(0,_client.createRoot)(container);root.render(scene)}else(0,_client.hydrateRoot)(container,scene)}
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_reactGlobalState","require","_client","_reactRouterDom","_getInj","_interopRequireDefault","_jsxRuntime","Launch","Application","options","arguments","length","undefined","container","document","getElementById","scene","jsx","GlobalStateProvider","initialState","getInj","ISTATE","children","BrowserRouter","dontHydrate","root","createRoot","render","hydrateRoot"],"sources":["../../../src/client/index.jsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\n\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router-dom';\n\nimport getInj from './getInj';\n\n/**\n * Prepares and launches the app at client side.\n * @param {object} Application Root application component\n * @param {object} [options={}] Optional. Additional settings.\n */\nexport default function Launch(Application, options = {}) {\n const container = document.getElementById('react-view');\n const scene = (\n <GlobalStateProvider initialState={getInj().ISTATE}>\n <BrowserRouter>\n <Application />\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":"gLAGA,IAAAA,iBAAA,CAAAC,OAAA,mCAEA,IAAAC,OAAA,CAAAD,OAAA,qBACA,IAAAE,eAAA,CAAAF,OAAA,qBAEA,IAAAG,OAAA,CAAAC,sBAAA,CAAAJ,OAAA,cAA8B,IAAAK,WAAA,CAAAL,OAAA,sBAR9B;AACA,sBASA;AACA;AACA;AACA;AACA,GACe,QAAS,CAAAM,MAAMA,CAACC,WAAW,CAAgB,IAAd,CAAAC,OAAO,CAAAC,SAAA,CAAAC,MAAA,IAAAD,SAAA,MAAAE,SAAA,CAAAF,SAAA,IAAG,CAAC,CAAC,CACtD,KAAM,CAAAG,SAAS,CAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC,CACvD,KAAM,CAAAC,KAAK,cACT,GAAAV,WAAA,CAAAW,GAAA,EAACjB,iBAAA,CAAAkB,mBAAmB,EAACC,YAAY,CAAE,GAAAC,eAAM,EAAC,CAAC,CAACC,MAAO,CAAAC,QAAA,cACjD,GAAAhB,WAAA,CAAAW,GAAA,EAACd,eAAA,CAAAoB,aAAa,EAAAD,QAAA,cACZ,GAAAhB,WAAA,CAAAW,GAAA,EAACT,WAAW,GAAE,CAAC,CACF,CAAC,CACG,CACtB,CAED,GAAIC,OAAO,CAACe,WAAW,CAAE,CACvB,KAAM,CAAAC,IAAI,CAAG,GAAAC,kBAAU,EAACb,SAAS,CAAC,CAClCY,IAAI,CAACE,MAAM,CAACX,KAAK,CACnB,CAAC,IAAM,GAAAY,mBAAW,EAACf,SAAS,CAAEG,KAAK,CACrC"}
1
+ {"version":3,"file":"index.js","names":["require","_reactGlobalState","_client","_reactRouterDom","_getInj","_interopRequireDefault","_jsxRuntime","Launch","Application","options","arguments","length","undefined","container","document","getElementById","Error","scene","jsx","GlobalStateProvider","initialState","getInj","ISTATE","children","BrowserRouter","dontHydrate","root","createRoot","render","hydrateRoot"],"sources":["../../../src/client/index.tsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport { type ComponentType } from 'react';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\n\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router-dom';\n\nimport getInj from './getInj';\n\ntype OptionsT = {\n dontHydrate?: boolean;\n};\n\n/**\n * Prepares and launches the app at client side.\n * @param Application Root application component\n * @param [options={}] Optional. Additional settings.\n */\nexport default function Launch(\n Application: ComponentType,\n options: OptionsT = {},\n) {\n const container = document.getElementById('react-view');\n if (!container) throw Error('Failed to find container for React app');\n const scene = (\n <GlobalStateProvider initialState={getInj().ISTATE}>\n <BrowserRouter>\n <Application />\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":"gLAGAA,OAAA,UAEA,IAAAC,iBAAA,CAAAD,OAAA,mCAEA,IAAAE,OAAA,CAAAF,OAAA,qBACA,IAAAG,eAAA,CAAAH,OAAA,qBAEA,IAAAI,OAAA,CAAAC,sBAAA,CAAAL,OAAA,cAA8B,IAAAM,WAAA,CAAAN,OAAA,sBAV9B;AACA,sBAeA;AACA;AACA;AACA;AACA,GACe,QAAS,CAAAO,MAAMA,CAC5BC,WAA0B,CAE1B,IADA,CAAAC,OAAiB,CAAAC,SAAA,CAAAC,MAAA,IAAAD,SAAA,MAAAE,SAAA,CAAAF,SAAA,IAAG,CAAC,CAAC,CAEtB,KAAM,CAAAG,SAAS,CAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC,CACvD,GAAI,CAACF,SAAS,CAAE,KAAM,CAAAG,KAAK,CAAC,wCAAwC,CAAC,CACrE,KAAM,CAAAC,KAAK,cACT,GAAAX,WAAA,CAAAY,GAAA,EAACjB,iBAAA,CAAAkB,mBAAmB,EAACC,YAAY,CAAE,GAAAC,eAAM,EAAC,CAAC,CAACC,MAAO,CAAAC,QAAA,cACjD,GAAAjB,WAAA,CAAAY,GAAA,EAACf,eAAA,CAAAqB,aAAa,EAAAD,QAAA,cACZ,GAAAjB,WAAA,CAAAY,GAAA,EAACV,WAAW,GAAE,CAAC,CACF,CAAC,CACG,CACtB,CAED,GAAIC,OAAO,CAACgB,WAAW,CAAE,CACvB,KAAM,CAAAC,IAAI,CAAG,GAAAC,kBAAU,EAACd,SAAS,CAAC,CAClCa,IAAI,CAACE,MAAM,CAACX,KAAK,CACnB,CAAC,IAAM,GAAAY,mBAAW,EAAChB,SAAS,CAAEI,KAAK,CACrC"}
@@ -1,6 +1,8 @@
1
1
  "use strict";var _buildInfo=require("../shared/utils/isomorphy/buildInfo");/**
2
2
  * Initialization of client-side environment.
3
- */ /* global BUILD_INFO, window */const buildInfo=(0,_buildInfo.getBuildInfo)();if(process.env.NODE_ENV!=="production"){console.warn("Dev mode: \"BUILD_INFO\" attached to the global \"window\"");// eslint-disable-next-line no-underscore-dangle
3
+ */ /* global BUILD_INFO, window */const buildInfo=(0,_buildInfo.getBuildInfo)();// TODO: Should be moved into buildInfo module?
4
+ if(process.env.NODE_ENV!=="production"){// eslint-disable-next-line no-console
5
+ console.warn("Dev mode: \"BUILD_INFO\" attached to the global \"window\"");// eslint-disable-next-line no-underscore-dangle
4
6
  window.__DEV_BUILD_INFO__=BUILD_INFO}/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */ /* eslint-disable no-console */const{useServiceWorker}=buildInfo;if(useServiceWorker){const{navigator}=window;if("serviceWorker"in navigator){window.addEventListener("load",async()=>{try{// Note: no matter the "publicPath", we want to serve the service worker
5
7
  // from the web app root, to allow it control any and all pages of the
6
8
  // web app (otherwise, it will be restricted to the scope of its path).
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","names":["_buildInfo","require","buildInfo","getBuildInfo","process","env","NODE_ENV","console","warn","window","__DEV_BUILD_INFO__","BUILD_INFO","useServiceWorker","navigator","addEventListener","reg","serviceWorker","register","log","err"],"sources":["../../../src/client/init.js"],"sourcesContent":["/**\n * Initialization of client-side environment.\n */\n\n/* global BUILD_INFO, window */\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nconst buildInfo = getBuildInfo();\n\nif (process.env.NODE_ENV !== 'production') {\n console.warn('Dev mode: \"BUILD_INFO\" attached to the global \"window\"');\n // eslint-disable-next-line no-underscore-dangle\n window.__DEV_BUILD_INFO__ = BUILD_INFO;\n}\n\n/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */\n/* eslint-disable no-console */\nconst { useServiceWorker } = buildInfo;\nif (useServiceWorker) {\n const { navigator } = window;\n if ('serviceWorker' in navigator) {\n window.addEventListener('load', async () => {\n try {\n // Note: no matter the \"publicPath\", we want to serve the service worker\n // from the web app root, to allow it control any and all pages of the\n // web app (otherwise, it will be restricted to the scope of its path).\n // The server takes it into account.\n const reg = await navigator\n .serviceWorker.register('/__service-worker.js');\n console.log('SW registered:', reg);\n } catch (err) {\n console.log('SW registration failed:', err);\n }\n });\n }\n}\n/* eslint-enable no-console */\n"],"mappings":"aAMA,IAAAA,UAAA,CAAAC,OAAA,wCANA;AACA;AACA,GAFA,CAIA,+BAIA,KAAM,CAAAC,SAAS,CAAG,GAAAC,uBAAY,EAAC,CAAC,CAEhC,GAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,GAAK,YAAY,CAAE,CACzCC,OAAO,CAACC,IAAI,CAAC,4DAAwD,CAAC,CACtE;AACAC,MAAM,CAACC,kBAAkB,CAAGC,UAC9B,CAEA,0EACA,+BACA,KAAM,CAAEC,gBAAiB,CAAC,CAAGV,SAAS,CACtC,GAAIU,gBAAgB,CAAE,CACpB,KAAM,CAAEC,SAAU,CAAC,CAAGJ,MAAM,CAC5B,GAAI,eAAe,EAAI,CAAAI,SAAS,CAAE,CAChCJ,MAAM,CAACK,gBAAgB,CAAC,MAAM,CAAE,SAAY,CAC1C,GAAI,CACF;AACA;AACA;AACA;AACA,KAAM,CAAAC,GAAG,CAAG,KAAM,CAAAF,SAAS,CACxBG,aAAa,CAACC,QAAQ,CAAC,sBAAsB,CAAC,CACjDV,OAAO,CAACW,GAAG,CAAC,gBAAgB,CAAEH,GAAG,CACnC,CAAE,MAAOI,GAAG,CAAE,CACZZ,OAAO,CAACW,GAAG,CAAC,yBAAyB,CAAEC,GAAG,CAC5C,CACF,CAAC,CACH,CACF,CACA"}
1
+ {"version":3,"file":"init.js","names":["_buildInfo","require","buildInfo","getBuildInfo","process","env","NODE_ENV","console","warn","window","__DEV_BUILD_INFO__","BUILD_INFO","useServiceWorker","navigator","addEventListener","reg","serviceWorker","register","log","err"],"sources":["../../../src/client/init.ts"],"sourcesContent":["/**\n * Initialization of client-side environment.\n */\n\n/* global BUILD_INFO, window */\n\nimport { type BuildInfoT, getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nconst buildInfo = getBuildInfo();\n\n// TODO: Should be moved into buildInfo module?\ndeclare global {\n interface Window {\n // eslint-disable-next-line @typescript-eslint/naming-convention, no-underscore-dangle\n __DEV_BUILD_INFO__: BuildInfoT | undefined;\n }\n}\n\nif (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('Dev mode: \"BUILD_INFO\" attached to the global \"window\"');\n // eslint-disable-next-line no-underscore-dangle\n window.__DEV_BUILD_INFO__ = BUILD_INFO;\n}\n\n/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */\n/* eslint-disable no-console */\nconst { useServiceWorker } = buildInfo;\nif (useServiceWorker) {\n const { navigator } = window;\n if ('serviceWorker' in navigator) {\n window.addEventListener('load', async () => {\n try {\n // Note: no matter the \"publicPath\", we want to serve the service worker\n // from the web app root, to allow it control any and all pages of the\n // web app (otherwise, it will be restricted to the scope of its path).\n // The server takes it into account.\n const reg = await navigator\n .serviceWorker.register('/__service-worker.js');\n console.log('SW registered:', reg);\n } catch (err) {\n console.log('SW registration failed:', err);\n }\n });\n }\n}\n/* eslint-enable no-console */\n"],"mappings":"aAMA,IAAAA,UAAA,CAAAC,OAAA,wCANA;AACA;AACA,GAFA,CAIA,+BAIA,KAAM,CAAAC,SAAS,CAAG,GAAAC,uBAAY,EAAC,CAAC,CAEhC;AAQA,GAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,GAAK,YAAY,CAAE,CACzC;AACAC,OAAO,CAACC,IAAI,CAAC,4DAAwD,CAAC,CACtE;AACAC,MAAM,CAACC,kBAAkB,CAAGC,UAC9B,CAEA,0EACA,+BACA,KAAM,CAAEC,gBAAiB,CAAC,CAAGV,SAAS,CACtC,GAAIU,gBAAgB,CAAE,CACpB,KAAM,CAAEC,SAAU,CAAC,CAAGJ,MAAM,CAC5B,GAAI,eAAe,EAAI,CAAAI,SAAS,CAAE,CAChCJ,MAAM,CAACK,gBAAgB,CAAC,MAAM,CAAE,SAAY,CAC1C,GAAI,CACF;AACA;AACA;AACA;AACA,KAAM,CAAAC,GAAG,CAAG,KAAM,CAAAF,SAAS,CACxBG,aAAa,CAACC,QAAQ,CAAC,sBAAsB,CAAC,CACjDV,OAAO,CAACW,GAAG,CAAC,gBAAgB,CAAEH,GAAG,CACnC,CAAE,MAAOI,GAAG,CAAE,CACZZ,OAAO,CAACW,GAAG,CAAC,yBAAyB,CAAEC,GAAG,CAC5C,CACF,CAAC,CACH,CACF,CACA"}
@@ -1,2 +1,2 @@
1
- "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});var _exportNames={client:true,server:true,api:true,PT:true,getGlobalState:true,getSsrContext:true,GlobalStateProvider:true,useAsyncCollection:true,useAsyncData:true,useGlobalState:true};Object.defineProperty(exports,"GlobalStateProvider",{enumerable:true,get:function(){return _reactGlobalState.GlobalStateProvider}});exports.PT=void 0;Object.defineProperty(exports,"api",{enumerable:true,get:function(){return _axios.default}});exports.client=void 0;Object.defineProperty(exports,"getGlobalState",{enumerable:true,get:function(){return _reactGlobalState.getGlobalState}});Object.defineProperty(exports,"getSsrContext",{enumerable:true,get:function(){return _reactGlobalState.getSsrContext}});exports.server=void 0;Object.defineProperty(exports,"useAsyncCollection",{enumerable:true,get:function(){return _reactGlobalState.useAsyncCollection}});Object.defineProperty(exports,"useAsyncData",{enumerable:true,get:function(){return _reactGlobalState.useAsyncData}});Object.defineProperty(exports,"useGlobalState",{enumerable:true,get:function(){return _reactGlobalState.useGlobalState}});var _utils=require("./shared/utils");Object.keys(_utils).forEach(function(key){if(key==="default"||key==="__esModule")return;if(Object.prototype.hasOwnProperty.call(_exportNames,key))return;if(key in exports&&exports[key]===_utils[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _utils[key]}})});var _axios=_interopRequireDefault(require("axios"));var _PT=_interopRequireWildcard(require("prop-types"));exports.PT=_PT;var _reactGlobalState=require("@dr.pogodin/react-global-state");var _components=require("./shared/components");Object.keys(_components).forEach(function(key){if(key==="default"||key==="__esModule")return;if(Object.prototype.hasOwnProperty.call(_exportNames,key))return;if(key in exports&&exports[key]===_components[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _components[key]}})});function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}const server=exports.server=_utils.webpack.requireWeak("./server",__dirname);const client=exports.client=server?undefined:require("./client").default;
1
+ "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"Barrier",{enumerable:true,get:function(){return _utils.Barrier}});Object.defineProperty(exports,"BaseModal",{enumerable:true,get:function(){return _components.BaseModal}});Object.defineProperty(exports,"Button",{enumerable:true,get:function(){return _components.Button}});Object.defineProperty(exports,"Checkbox",{enumerable:true,get:function(){return _components.Checkbox}});Object.defineProperty(exports,"Dropdown",{enumerable:true,get:function(){return _components.Dropdown}});Object.defineProperty(exports,"Emitter",{enumerable:true,get:function(){return _utils.Emitter}});Object.defineProperty(exports,"GlobalStateProvider",{enumerable:true,get:function(){return _reactGlobalState.GlobalStateProvider}});Object.defineProperty(exports,"Input",{enumerable:true,get:function(){return _components.Input}});Object.defineProperty(exports,"JU",{enumerable:true,get:function(){return _utils.JU}});Object.defineProperty(exports,"Link",{enumerable:true,get:function(){return _components.Link}});Object.defineProperty(exports,"MetaTags",{enumerable:true,get:function(){return _components.MetaTags}});Object.defineProperty(exports,"Modal",{enumerable:true,get:function(){return _components.Modal}});Object.defineProperty(exports,"NavLink",{enumerable:true,get:function(){return _components.NavLink}});exports.PT=void 0;Object.defineProperty(exports,"PageLayout",{enumerable:true,get:function(){return _components.PageLayout}});Object.defineProperty(exports,"Rgs",{enumerable:true,get:function(){return _reactGlobalState.default}});Object.defineProperty(exports,"ScalableRect",{enumerable:true,get:function(){return _components.ScalableRect}});Object.defineProperty(exports,"Semaphore",{enumerable:true,get:function(){return _utils.Semaphore}});Object.defineProperty(exports,"ThemeProvider",{enumerable:true,get:function(){return _utils.ThemeProvider}});Object.defineProperty(exports,"Throbber",{enumerable:true,get:function(){return _components.Throbber}});Object.defineProperty(exports,"WithTooltip",{enumerable:true,get:function(){return _components.WithTooltip}});Object.defineProperty(exports,"YouTubeVideo",{enumerable:true,get:function(){return _components.YouTubeVideo}});Object.defineProperty(exports,"api",{enumerable:true,get:function(){return _axios.default}});exports.client=void 0;Object.defineProperty(exports,"config",{enumerable:true,get:function(){return _utils.config}});Object.defineProperty(exports,"getGlobalState",{enumerable:true,get:function(){return _reactGlobalState.getGlobalState}});Object.defineProperty(exports,"getSsrContext",{enumerable:true,get:function(){return _utils.getSsrContext}});Object.defineProperty(exports,"isomorphy",{enumerable:true,get:function(){return _utils.isomorphy}});exports.server=void 0;Object.defineProperty(exports,"splitComponent",{enumerable:true,get:function(){return _utils.splitComponent}});Object.defineProperty(exports,"themed",{enumerable:true,get:function(){return _utils.themed}});Object.defineProperty(exports,"time",{enumerable:true,get:function(){return _utils.time}});Object.defineProperty(exports,"useAsyncCollection",{enumerable:true,get:function(){return _reactGlobalState.useAsyncCollection}});Object.defineProperty(exports,"useAsyncData",{enumerable:true,get:function(){return _reactGlobalState.useAsyncData}});Object.defineProperty(exports,"useGlobalState",{enumerable:true,get:function(){return _reactGlobalState.useGlobalState}});Object.defineProperty(exports,"webpack",{enumerable:true,get:function(){return _utils.webpack}});Object.defineProperty(exports,"withRetries",{enumerable:true,get:function(){return _utils.withRetries}});var _utils=require("./shared/utils");var _axios=_interopRequireDefault(require("axios"));var _PT=_interopRequireWildcard(require("prop-types"));exports.PT=_PT;var _reactGlobalState=_interopRequireWildcard(require("@dr.pogodin/react-global-state"));var _components=require("./shared/components");function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap,t=new WeakMap;return(_getRequireWildcardCache=function(e){return e?t:r})(e)}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u]}return n.default=e,t&&t.set(e,n),n}const server=exports.server=_utils.webpack.requireWeak("./server",__dirname);const client=exports.client=server?undefined:require("./client").default;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_utils","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_axios","_interopRequireDefault","_PT","_interopRequireWildcard","PT","_reactGlobalState","_components","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","desc","set","server","webpack","requireWeak","__dirname","client","undefined"],"sources":["../../src/index.js"],"sourcesContent":["import 'styles/global.scss';\n\nimport { webpack } from 'utils';\n\nconst server = webpack.requireWeak('./server', __dirname);\n\nconst client = server ? undefined : require('./client').default;\n\nexport { default as api } from 'axios';\nexport * as PT from 'prop-types';\n\nexport {\n getGlobalState,\n getSsrContext,\n GlobalStateProvider,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n} from '@dr.pogodin/react-global-state';\n\nexport * from 'components';\nexport * from 'utils';\n\nexport { client, server };\n"],"mappings":"stCAEA,IAAAA,MAAA,CAAAC,OAAA,mBAmBAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,UAAAC,GAAA,KAAAA,GAAA,cAAAA,GAAA,0BAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,CAAAJ,GAAA,YAAAA,GAAA,IAAAK,OAAA,EAAAA,OAAA,CAAAL,GAAA,IAAAL,MAAA,CAAAK,GAAA,SAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,CAAAL,GAAA,EAAAO,UAAA,MAAAC,GAAA,SAAAA,CAAA,SAAAb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AAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAkB,GAAA,CAAArB,GAAA,OAAA6B,IAAA,CAAAF,qBAAA,CAAA9B,MAAA,CAAA+B,wBAAA,CAAAP,GAAA,CAAArB,GAAA,UAAA6B,IAAA,GAAAA,IAAA,CAAArB,GAAA,EAAAqB,IAAA,CAAAC,GAAA,GAAAjC,MAAA,CAAAS,cAAA,CAAAoB,MAAA,CAAA1B,GAAA,CAAA6B,IAAA,OAAAH,MAAA,CAAA1B,GAAA,EAAAqB,GAAA,CAAArB,GAAA,IAAA0B,MAAA,CAAAH,OAAA,CAAAF,GAAA,IAAAG,KAAA,EAAAA,KAAA,CAAAM,GAAA,CAAAT,GAAA,CAAAK,MAAA,SAAAA,MAAA,CAhB3B,KAAM,CAAAK,MAAM,CAAA1B,OAAA,CAAA0B,MAAA,CAAGC,cAAO,CAACC,WAAW,YAAaC,SAAS,CAAC,CAEzD,KAAM,CAAAC,MAAM,CAAA9B,OAAA,CAAA8B,MAAA,CAAGJ,MAAM,CAAGK,SAAS,CAAGxC,OAAO,WAAW,CAAC,CAAC2B,OAAO"}
1
+ {"version":3,"file":"index.js","names":["_utils","require","_axios","_interopRequireDefault","_PT","_interopRequireWildcard","exports","PT","_reactGlobalState","_components","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","server","webpack","requireWeak","__dirname","client","undefined"],"sources":["../../src/index.ts"],"sourcesContent":["import 'styles/global.scss';\n\nimport { webpack } from 'utils';\n\nimport type ServerT from './server';\n\nconst server = webpack.requireWeak('./server', __dirname) as (typeof ServerT) | null;\n\nconst client = server ? undefined : require('./client').default;\n\nexport { default as api } from 'axios';\nexport * as PT from 'prop-types';\n\nexport {\n default as Rgs,\n type API as RgsApi,\n getGlobalState,\n GlobalStateProvider,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n} from '@dr.pogodin/react-global-state';\n\nexport {\n BaseModal,\n Button,\n Checkbox,\n Dropdown,\n Input,\n Link,\n PageLayout,\n MetaTags,\n Modal,\n NavLink,\n ScalableRect,\n Throbber,\n WithTooltip,\n YouTubeVideo,\n} from 'components';\n\nexport {\n type Theme,\n config,\n Barrier,\n Emitter,\n isomorphy,\n getSsrContext,\n JU,\n Semaphore,\n splitComponent,\n themed,\n ThemeProvider,\n time,\n webpack,\n withRetries,\n} from 'utils';\n\nexport { client, server };\n"],"mappings":"6sHAEA,IAAAA,MAAA,CAAAC,OAAA,mBAQA,IAAAC,MAAA,CAAAC,sBAAA,CAAAF,OAAA,WAAuC,IAAAG,GAAA,CAAAC,uBAAA,CAAAJ,OAAA,gBAAAK,OAAA,CAAAC,EAAA,CAAAH,GAAA,CAGvC,IAAAI,iBAAA,CAAAH,uBAAA,CAAAJ,OAAA,oCAUA,IAAAQ,WAAA,CAAAR,OAAA,wBAeoB,SAAAS,yBAAAC,CAAA,wBAAAC,OAAA,iBAAAC,CAAA,KAAAD,OAAA,CAAAE,CAAA,KAAAF,OAAA,QAAAF,wBAAA,SAAAA,CAAAC,CAAA,SAAAA,CAAA,CAAAG,CAAA,CAAAD,CAAA,GAAAF,CAAA,WAAAN,wBAAAM,CAAA,CAAAE,CAAA,MAAAA,CAAA,EAAAF,CAAA,EAAAA,CAAA,CAAAI,UAAA,QAAAJ,CAAA,WAAAA,CAAA,mBAAAA,CAAA,qBAAAA,CAAA,QAAAK,OAAA,CAAAL,CAAA,MAAAG,CAAA,CAAAJ,wBAAA,CAAAG,CAAA,KAAAC,CAAA,EAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,SAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,MAAAQ,CAAA,EAAAC,SAAA,OAAAC,CAAA,CAAAC,MAAA,CAAAC,cAAA,EAAAD,MAAA,CAAAE,wBAAA,SAAAC,CAAA,IAAAd,CAAA,gBAAAc,CAAA,EAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,CAAAc,CAAA,OAAAI,CAAA,CAAAR,CAAA,CAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,CAAAc,CAAA,OAAAI,CAAA,GAAAA,CAAA,CAAAX,GAAA,EAAAW,CAAA,CAAAC,GAAA,EAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,CAAAM,CAAA,CAAAI,CAAA,EAAAV,CAAA,CAAAM,CAAA,EAAAd,CAAA,CAAAc,CAAA,SAAAN,CAAA,CAAAH,OAAA,CAAAL,CAAA,CAAAG,CAAA,EAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,CAAAQ,CAAA,EAAAA,CAAA,CAhCpB,KAAM,CAAAY,MAAM,CAAAzB,OAAA,CAAAyB,MAAA,CAAGC,cAAO,CAACC,WAAW,YAAaC,SAAS,CAA4B,CAEpF,KAAM,CAAAC,MAAM,CAAA7B,OAAA,CAAA6B,MAAA,CAAGJ,MAAM,CAAGK,SAAS,CAAGnC,OAAO,WAAW,CAAC,CAACe,OAAO"}
@@ -1,18 +1,17 @@
1
1
  "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;/**
2
2
  * Implements the static cache.
3
- * @ignore
4
3
  */class Cache{constructor(maxSize){this.private={items:{},maxSize,size:0}}/**
5
4
  * Cache lookup.
6
- * @ignore
7
- * @param {string} key Item key to look for.
8
- * @param {number} [maxage=Number.MAX_VALUE] Optional. The maximum age of
5
+ * @param key Item key to look for.
6
+ * @param [maxage=Number.MAX_VALUE] Optional. The maximum age of
9
7
  * cached item to serve. Default to infinite.
10
- * @returns {string} Cached item, or null if the item is absent in cache,
8
+ * @returns Cached item, or null if the item is absent in cache,
11
9
  * or stale.
12
10
  */get({key,maxage=Number.MAX_VALUE}){const item=this.private.items[key];return item&&Date.now()-item.timestamp<maxage?item.data:null}/**
13
11
  * Adds item to cache.
14
12
  * @ignore
15
- * @param {string} data Item to add.
16
- * @param {string} key Key to store the item at.
17
- */add(data,key){const p=this.private;const old=p.items[key];if(old)p.size-=old.data.length;p.items[key]={data,timestamp:Date.now()};p.size+=data.length;if(p.size>p.maxSize){const items=Object.entries(p.items);items.sort((a,b)=>a[1].timestamp-b[1].timestamp);for(let i=0;i<items.length;++i){const item=items[i];delete p.items[item[0]];p.size-=item[1].data.length;if(p.size<p.maxSize/2)break}}}}exports.default=Cache;
13
+ * @param data Item to add.
14
+ * @param key Key to store the item at.
15
+ * @param size Byte size of the item.
16
+ */add(data,key,size){const p=this.private;const old=p.items[key];if(old)p.size-=old.size;p.items[key]={data,size,timestamp:Date.now()};p.size+=size;if(p.size>p.maxSize){const items=Object.entries(p.items);items.sort((a,b)=>a[1].timestamp-b[1].timestamp);for(let i=0;i<items.length;++i){const[itemKey,item]=items[i];delete p.items[itemKey];p.size-=item.size;if(p.size<p.maxSize/2)break}}}}exports.default=Cache;
18
17
  //# sourceMappingURL=Cache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cache.js","names":["Cache","constructor","maxSize","private","items","size","get","key","maxage","Number","MAX_VALUE","item","Date","now","timestamp","data","add","p","old","length","Object","entries","sort","a","b","i","exports","default"],"sources":["../../../src/server/Cache.js"],"sourcesContent":["/**\n * Implements the static cache.\n * @ignore\n */\nexport default class Cache {\n constructor(maxSize) {\n this.private = {\n items: {},\n maxSize,\n size: 0,\n };\n }\n\n /**\n * Cache lookup.\n * @ignore\n * @param {string} key Item key to look for.\n * @param {number} [maxage=Number.MAX_VALUE] Optional. The maximum age of\n * cached item to serve. Default to infinite.\n * @returns {string} Cached item, or null if the item is absent in cache,\n * or stale.\n */\n get({ key, maxage = Number.MAX_VALUE }) {\n const item = this.private.items[key];\n return item && Date.now() - item.timestamp < maxage ? item.data : null;\n }\n\n /**\n * Adds item to cache.\n * @ignore\n * @param {string} data Item to add.\n * @param {string} key Key to store the item at.\n */\n add(data, key) {\n const p = this.private;\n const old = p.items[key];\n if (old) p.size -= old.data.length;\n p.items[key] = { data, timestamp: Date.now() };\n p.size += data.length;\n if (p.size > p.maxSize) {\n const items = Object.entries(p.items);\n items.sort((a, b) => a[1].timestamp - b[1].timestamp);\n for (let i = 0; i < items.length; ++i) {\n const item = items[i];\n delete p.items[item[0]];\n p.size -= item[1].data.length;\n if (p.size < p.maxSize / 2) break;\n }\n }\n }\n}\n"],"mappings":"6FAAA;AACA;AACA;AACA,GACe,KAAM,CAAAA,KAAM,CACzBC,WAAWA,CAACC,OAAO,CAAE,CACnB,IAAI,CAACC,OAAO,CAAG,CACbC,KAAK,CAAE,CAAC,CAAC,CACTF,OAAO,CACPG,IAAI,CAAE,CACR,CACF,CAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KACEC,GAAGA,CAAC,CAAEC,GAAG,CAAEC,MAAM,CAAGC,MAAM,CAACC,SAAU,CAAC,CAAE,CACtC,KAAM,CAAAC,IAAI,CAAG,IAAI,CAACR,OAAO,CAACC,KAAK,CAACG,GAAG,CAAC,CACpC,MAAO,CAAAI,IAAI,EAAIC,IAAI,CAACC,GAAG,CAAC,CAAC,CAAGF,IAAI,CAACG,SAAS,CAAGN,MAAM,CAAGG,IAAI,CAACI,IAAI,CAAG,IACpE,CAEA;AACF;AACA;AACA;AACA;AACA,KACEC,GAAGA,CAACD,IAAI,CAAER,GAAG,CAAE,CACb,KAAM,CAAAU,CAAC,CAAG,IAAI,CAACd,OAAO,CACtB,KAAM,CAAAe,GAAG,CAAGD,CAAC,CAACb,KAAK,CAACG,GAAG,CAAC,CACxB,GAAIW,GAAG,CAAED,CAAC,CAACZ,IAAI,EAAIa,GAAG,CAACH,IAAI,CAACI,MAAM,CAClCF,CAAC,CAACb,KAAK,CAACG,GAAG,CAAC,CAAG,CAAEQ,IAAI,CAAED,SAAS,CAAEF,IAAI,CAACC,GAAG,CAAC,CAAE,CAAC,CAC9CI,CAAC,CAACZ,IAAI,EAAIU,IAAI,CAACI,MAAM,CACrB,GAAIF,CAAC,CAACZ,IAAI,CAAGY,CAAC,CAACf,OAAO,CAAE,CACtB,KAAM,CAAAE,KAAK,CAAGgB,MAAM,CAACC,OAAO,CAACJ,CAAC,CAACb,KAAK,CAAC,CACrCA,KAAK,CAACkB,IAAI,CAAC,CAACC,CAAC,CAAEC,CAAC,GAAKD,CAAC,CAAC,CAAC,CAAC,CAACT,SAAS,CAAGU,CAAC,CAAC,CAAC,CAAC,CAACV,SAAS,CAAC,CACrD,IAAK,GAAI,CAAAW,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGrB,KAAK,CAACe,MAAM,CAAE,EAAEM,CAAC,CAAE,CACrC,KAAM,CAAAd,IAAI,CAAGP,KAAK,CAACqB,CAAC,CAAC,CACrB,MAAO,CAAAR,CAAC,CAACb,KAAK,CAACO,IAAI,CAAC,CAAC,CAAC,CAAC,CACvBM,CAAC,CAACZ,IAAI,EAAIM,IAAI,CAAC,CAAC,CAAC,CAACI,IAAI,CAACI,MAAM,CAC7B,GAAIF,CAAC,CAACZ,IAAI,CAAGY,CAAC,CAACf,OAAO,CAAG,CAAC,CAAE,KAC9B,CACF,CACF,CACF,CAACwB,OAAA,CAAAC,OAAA,CAAA3B,KAAA"}
1
+ {"version":3,"file":"Cache.js","names":["Cache","constructor","maxSize","private","items","size","get","key","maxage","Number","MAX_VALUE","item","Date","now","timestamp","data","add","p","old","Object","entries","sort","a","b","i","length","itemKey","exports","default"],"sources":["../../../src/server/Cache.ts"],"sourcesContent":["/**\n * Implements the static cache.\n */\nexport default class Cache<DatumT> {\n private: {\n items: {\n [key: string]: {\n data: DatumT;\n size: number;\n timestamp: number;\n }\n };\n maxSize: number;\n size: number;\n };\n\n constructor(maxSize: number) {\n this.private = {\n items: {},\n maxSize,\n size: 0,\n };\n }\n\n /**\n * Cache lookup.\n * @param key Item key to look for.\n * @param [maxage=Number.MAX_VALUE] Optional. The maximum age of\n * cached item to serve. Default to infinite.\n * @returns Cached item, or null if the item is absent in cache,\n * or stale.\n */\n get({\n key,\n maxage = Number.MAX_VALUE,\n }: {\n key: string;\n maxage?: number;\n }): DatumT | null {\n const item = this.private.items[key];\n return item && Date.now() - item.timestamp < maxage ? item.data : null;\n }\n\n /**\n * Adds item to cache.\n * @ignore\n * @param data Item to add.\n * @param key Key to store the item at.\n * @param size Byte size of the item.\n */\n add(data: DatumT, key: string, size: number) {\n const p = this.private;\n const old = p.items[key];\n if (old) p.size -= old.size;\n p.items[key] = { data, size, timestamp: Date.now() };\n p.size += size;\n if (p.size > p.maxSize) {\n const items = Object.entries(p.items);\n items.sort((a, b) => a[1].timestamp - b[1].timestamp);\n for (let i = 0; i < items.length; ++i) {\n const [itemKey, item] = items[i];\n delete p.items[itemKey];\n p.size -= item.size;\n if (p.size < p.maxSize / 2) break;\n }\n }\n }\n}\n"],"mappings":"6FAAA;AACA;AACA,GACe,KAAM,CAAAA,KAAc,CAajCC,WAAWA,CAACC,OAAe,CAAE,CAC3B,IAAI,CAACC,OAAO,CAAG,CACbC,KAAK,CAAE,CAAC,CAAC,CACTF,OAAO,CACPG,IAAI,CAAE,CACR,CACF,CAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA,KACEC,GAAGA,CAAC,CACFC,GAAG,CACHC,MAAM,CAAGC,MAAM,CAACC,SAIlB,CAAC,CAAiB,CAChB,KAAM,CAAAC,IAAI,CAAG,IAAI,CAACR,OAAO,CAACC,KAAK,CAACG,GAAG,CAAC,CACpC,MAAO,CAAAI,IAAI,EAAIC,IAAI,CAACC,GAAG,CAAC,CAAC,CAAGF,IAAI,CAACG,SAAS,CAAGN,MAAM,CAAGG,IAAI,CAACI,IAAI,CAAG,IACpE,CAEA;AACF;AACA;AACA;AACA;AACA;AACA,KACEC,GAAGA,CAACD,IAAY,CAAER,GAAW,CAAEF,IAAY,CAAE,CAC3C,KAAM,CAAAY,CAAC,CAAG,IAAI,CAACd,OAAO,CACtB,KAAM,CAAAe,GAAG,CAAGD,CAAC,CAACb,KAAK,CAACG,GAAG,CAAC,CACxB,GAAIW,GAAG,CAAED,CAAC,CAACZ,IAAI,EAAIa,GAAG,CAACb,IAAI,CAC3BY,CAAC,CAACb,KAAK,CAACG,GAAG,CAAC,CAAG,CAAEQ,IAAI,CAAEV,IAAI,CAAES,SAAS,CAAEF,IAAI,CAACC,GAAG,CAAC,CAAE,CAAC,CACpDI,CAAC,CAACZ,IAAI,EAAIA,IAAI,CACd,GAAIY,CAAC,CAACZ,IAAI,CAAGY,CAAC,CAACf,OAAO,CAAE,CACtB,KAAM,CAAAE,KAAK,CAAGe,MAAM,CAACC,OAAO,CAACH,CAAC,CAACb,KAAK,CAAC,CACrCA,KAAK,CAACiB,IAAI,CAAC,CAACC,CAAC,CAAEC,CAAC,GAAKD,CAAC,CAAC,CAAC,CAAC,CAACR,SAAS,CAAGS,CAAC,CAAC,CAAC,CAAC,CAACT,SAAS,CAAC,CACrD,IAAK,GAAI,CAAAU,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGpB,KAAK,CAACqB,MAAM,CAAE,EAAED,CAAC,CAAE,CACrC,KAAM,CAACE,OAAO,CAAEf,IAAI,CAAC,CAAGP,KAAK,CAACoB,CAAC,CAAC,CAChC,MAAO,CAAAP,CAAC,CAACb,KAAK,CAACsB,OAAO,CAAC,CACvBT,CAAC,CAACZ,IAAI,EAAIM,IAAI,CAACN,IAAI,CACnB,GAAIY,CAAC,CAACZ,IAAI,CAAGY,CAAC,CAACf,OAAO,CAAG,CAAC,CAAE,KAC9B,CACF,CACF,CACF,CAACyB,OAAA,CAAAC,OAAA,CAAA5B,KAAA"}
@@ -1,8 +1,7 @@
1
- "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});var _exportNames={getDefaultCspSettings:true};exports.default=void 0;Object.defineProperty(exports,"getDefaultCspSettings",{enumerable:true,get:function(){return _server.getDefaultCspSettings}});require("source-map-support/register");var _http=_interopRequireDefault(require("http"));var _https=_interopRequireDefault(require("https"));var _lodash=require("lodash");require("raf/polyfill");var _server=_interopRequireWildcard(require("./server"));var _renderer=require("./renderer");var _utils=require("./utils");Object.keys(_utils).forEach(function(key){if(key==="default"||key==="__esModule")return;if(Object.prototype.hasOwnProperty.call(_exportNames,key))return;if(key in exports&&exports[key]===_utils[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _utils[key]}})});function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}/* Polyfill required by ReactJS. */ /**
1
+ "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=launchServer;Object.defineProperty(exports,"errors",{enumerable:true,get:function(){return _utils.errors}});Object.defineProperty(exports,"getDefaultCspSettings",{enumerable:true,get:function(){return _server.getDefaultCspSettings}});require("source-map-support/register");var _http=_interopRequireDefault(require("http"));var _https=_interopRequireDefault(require("https"));var _lodash=require("lodash");require("raf/polyfill");require("webpack");var _server=_interopRequireWildcard(require("./server"));var _renderer=require("./renderer");var _utils=require("./utils");function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap,t=new WeakMap;return(_getRequireWildcardCache=function(e){return e?t:r})(e)}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u]}return n.default=e,t&&t.set(e,n),n}/* Polyfill required by ReactJS. */ /**
2
2
  * Normalizes a port into a number, string, or false.
3
3
  * TODO: Drop this function?
4
- * @ignore
5
- * @param {String} value Port name or number.
4
+ * @param value Port name or number.
6
5
  * @return Port number (Number), name (String), or false.
7
6
  */function normalizePort(value){const port=(0,_lodash.toNumber)(value);if((0,_lodash.isFinite)(port))return port;/* port number */if(!(0,_lodash.isNumber)(port))return value;/* named pipe */return false}/**
8
7
  * Creates and launches web-server for ReactJS application. Allows zero
@@ -122,5 +121,7 @@
122
121
  * defaults to 1 second.
123
122
  * @return {Promise<{ expressServer: object, httpServer: object }>} Resolves to
124
123
  * an object with created Express and HTTP servers.
125
- */async function launch(webpackConfig,options){/* Options normalization. */const ops=options?(0,_lodash.cloneDeep)(options):{};ops.port=normalizePort(ops.port||process.env.PORT||3000);(0,_lodash.defaults)(ops,{httpsRedirect:true});if(ops.logger===undefined){ops.logger=(0,_renderer.newDefaultLogger)({defaultLogLevel:ops.defaultLoggerLogLevel})}/* Creates servers, resolves and sets the port. */const expressServer=await(0,_server.default)(webpackConfig,ops);let httpServer;if(ops.https){httpServer=_https.default.createServer({cert:ops.https.cert,key:ops.https.key},expressServer)}else httpServer=_http.default.createServer(expressServer);/* Sets error handler for HTTP(S) server. */httpServer.on("error",error=>{if(error.syscall!=="listen")throw error;const bind=(0,_lodash.isString)(ops.port)?`Pipe ${ops.port}`:`Port ${ops.port}`;/* Human-readable message for some specific listen errors. */switch(error.code){case"EACCES":ops.logger.error(`${bind} requires elevated privileges`);return process.exit(1);case"EADDRINUSE":ops.logger.error(`${bind} is already in use`);return process.exit(1);default:throw error}});/* Listening event handler for HTTP(S) server. */httpServer.on("listening",()=>{const addr=httpServer.address();const bind=(0,_lodash.isString)(addr)?`pipe ${addr}`:`port ${addr.port}`;ops.logger.info(`Server listening on ${bind} in ${process.env.NODE_ENV} mode`)});httpServer.listen(ops.port);return{expressServer,httpServer}}launch.SCRIPT_LOCATIONS=_renderer.SCRIPT_LOCATIONS;var _default=exports.default=launch;
124
+ */async function launchServer(webpackConfig,options){/* Options normalization. */const ops=options?(0,_lodash.cloneDeep)(options):{};ops.port=normalizePort(ops.port||process.env.PORT||3000);(0,_lodash.defaults)(ops,{httpsRedirect:true});// TODO: Need a separate type for normalized options, which guarantees
125
+ // the logger is set!
126
+ if(ops.logger===undefined){ops.logger=(0,_renderer.newDefaultLogger)({defaultLogLevel:ops.defaultLoggerLogLevel})}/* Creates servers, resolves and sets the port. */const expressServer=await(0,_server.default)(webpackConfig,ops);let httpServer;if(ops.https){httpServer=_https.default.createServer({cert:ops.https.cert,key:ops.https.key},expressServer)}else httpServer=_http.default.createServer(expressServer);/* Sets error handler for HTTP(S) server. */httpServer.on("error",error=>{if(error.syscall!=="listen")throw error;const bind=(0,_lodash.isString)(ops.port)?`Pipe ${ops.port}`:`Port ${ops.port}`;/* Human-readable message for some specific listen errors. */switch(error.code){case"EACCES":ops.logger.error(`${bind} requires elevated privileges`);return process.exit(1);case"EADDRINUSE":ops.logger.error(`${bind} is already in use`);return process.exit(1);default:throw error}});/* Listening event handler for HTTP(S) server. */httpServer.on("listening",()=>{const addr=httpServer.address();const bind=(0,_lodash.isString)(addr)?`pipe ${addr}`:`port ${addr.port}`;ops.logger.info(`Server listening on ${bind} in ${process.env.NODE_ENV} mode`)});httpServer.listen(ops.port);return{expressServer,httpServer}}launchServer.SCRIPT_LOCATIONS=_renderer.SCRIPT_LOCATIONS;
126
127
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["require","_http","_interopRequireDefault","_https","_lodash","_server","_interopRequireWildcard","_renderer","_utils","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","desc","set","normalizePort","value","port","toNumber","isFinite","isNumber","launch","webpackConfig","options","ops","cloneDeep","process","env","PORT","defaults","httpsRedirect","logger","undefined","newDefaultLogger","defaultLogLevel","defaultLoggerLogLevel","expressServer","serverFactory","httpServer","https","createServer","cert","http","on","error","syscall","bind","isString","code","exit","addr","address","info","NODE_ENV","listen","SCRIPT_LOCATIONS","_default"],"sources":["../../../src/server/index.js"],"sourcesContent":["import 'source-map-support/register';\n\nimport http from 'http';\nimport https from 'https';\n\nimport {\n cloneDeep,\n defaults,\n isFinite,\n isNumber,\n isString,\n toNumber,\n} from 'lodash';\n\n/* Polyfill required by ReactJS. */\nimport 'raf/polyfill';\n\nimport serverFactory from './server';\nimport { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';\n\nexport { getDefaultCspSettings } from './server';\nexport * from './utils';\n\n/**\n * Normalizes a port into a number, string, or false.\n * TODO: Drop this function?\n * @ignore\n * @param {String} value Port name or number.\n * @return Port number (Number), name (String), or false.\n */\nfunction normalizePort(value) {\n const port = toNumber(value);\n if (isFinite(port)) return port; /* port number */\n if (!isNumber(port)) return value; /* named pipe */\n return false;\n}\n\n/**\n * Creates and launches web-server for ReactJS application. Allows zero\n * or detailed configuration, supports server-side rendering,\n * and development tools, including Hot Module Reloading (HMR).\n *\n * NOTE: Many of options defined below are passed down to the server and\n * renderer factories, and their declared default values are set in those\n * factories, rather than here.\n *\n * @param {object} webpackConfig Webpack configuration used to build\n * the frontend bundle. In production mode the server will read out of it\n * `context`, `publicPath`, and a few other parameters, necessary to locate\n * and serve the app bundle. In development mode the server will use entire\n * provided config to build the app bundle in memory, and further watch and\n * update it via HMR.\n * @param {object} [options] Additional parameters.\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {function} [options.beforeExpressJsError] Asynchronous callback\n * (`(server) => Promise<boolean>`) to be executed just before the default error\n * handler is added to ExpressJS server. If the callback is provided and its\n * result resolves to a truthy value, `react-utils` won't attach the default\n * error handler.\n * @param {function} [options.beforeExpressJsSetup] Asynchronous callback\n * (`(server) => Promise) to be executed right after ExpressJS server creation,\n * before any configuration is performed.\n * @param {BeforeRenderHook} [options.beforeRender] The hook to run just before\n * the server-side rendering. For each incoming request, it will be executed\n * just before the HTML markup is generated at the server. It allows to load\n * and provide the data necessary for server-side rendering, and also to inject\n * additional configuration and scripts into the generated HTML code.\n * @param {boolean} [options.noCsp] Set `true` to disable\n * Content-Security-Policy (CSP) headers altogether.\n * @param {function} [options.cspSettingsHook] A hook allowing\n * to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n * settings for [helmet](https://github.com/helmetjs/helmet)'s\n * `contentSecurityPolicy` middleware on per-request basis.\n *\n * If provided it should be a with signature: \\\n * `(defaultSettings: object, req: object)` &rArr; `object` \\\n * which gets the default settings (also used without the hook),\n * and the incoming request object. The hook response will be passed\n * as options to the helmet `contentSecurityPolicy` middleware.\n *\n * Currently, the default settings is the following object in production\n * environment:\n * ```js\n * {\n * directives: {\n * defaultSrc: [\"'self'\"],\n * baseUri: [\"'self'\"],\n * blockAllMixedContent: [],\n * fontSrc: [\"'self'\", 'https:', 'data:'],\n * frameAncestors: [\"'self'\"],\n * frameSrc: [\"'self'\", 'https://*.youtube.com'],\n * imgSrc: [\"'self'\", 'data:'],\n * objectSrc: [\"'none'\"],\n * scriptSrc: [\"'self'\", \"'unsafe-eval'\", `'nonce-UNIQUE_NONCE_VALUE'`],\n * scriptSrcAttr: [\"'none'\"],\n * styleSrc: [\"'self'\", 'https:', \"'unsafe-inline'\"],\n * upgradeInsecureRequests: [] // Removed in dev mode.\n * }\n * }\n * ```\n * It matches the default value used by Helmet with a few updates:\n * - YouTube host is whitelisted in the `frameSrc` directive to ensure\n * the {@link YouTubeVideo} component works.\n * - An unique per-request nonce is added to `scriptSrc` directive to\n * whitelist auxiliary scripts injected by react-utils. The actual nonce\n * value can be fetched by host code via `.nonce` field of `req` argument\n * of `.beforeRender` hook.\n * - `upgradeInsecureRequests` directive is removed in development mode,\n * to simplify local testing with http requests.\n * @param {string} [options.defaultLoggerLogLevel='info'] Log level for\n * the default logger, which is created if no `logger` option provided.\n * @param {boolean} [options.devMode] Pass in `true` to start the server in\n * development mode.\n * @param {string} [options.favicon] Path to the favicon to use by the server.\n * By default no favicon is used.\n * @param {object} [options.https] If provided, HTTPS server will be started,\n * instead of HTTP otherwise. The object should provide SSL certificate and key\n * via two string fields: `cert`, and `key`.\n * @param {string} [options.https.cert] SSL Certificate.\n * @param {string} [options.https.key] SSL key.\n * @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable\n * automatic redirection of all incoming HTTP requests to HTTPS.\n *\n * To smoothly use it at `localhost` you need to run the server in HTTPS mode,\n * and also properly create and install a self-signed SSL sertificate on your\n * system. This article is helpful:\n * [How to get HTTPS working on your local development environment in 5 minutes](https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec)\n * @param {Logger} [options.logger] The logger to use at server side.\n * By default [`winston`](https://www.npmjs.com/package/winston) logger\n * with console transport is used. The logger you provide, or the default\n * `winston` logger otherwise, will be attached to the created ExpressJS server\n * object.\n * @param {function} [options.onExpressJsSetup] An async callback\n * (`(server) => Promise`) to be triggered when most of the server\n * configuration is completed, just before the server-side renderer,\n * and the default error handler are attached. You can use it to mount\n * custom API routes. The server-side logger can be accessed as `server.logger`.\n * @param {number|string} [options.port=3000] The port to start the server on.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` &ndash; the cache key for the response;\n * - `maxage?: number` &ndash; the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @return {Promise<{ expressServer: object, httpServer: object }>} Resolves to\n * an object with created Express and HTTP servers.\n */\nasync function launch(webpackConfig, options) {\n /* Options normalization. */\n const ops = options ? cloneDeep(options) : {};\n ops.port = normalizePort(ops.port || process.env.PORT || 3000);\n defaults(ops, { httpsRedirect: true });\n\n if (ops.logger === undefined) {\n ops.logger = newDefaultLogger({\n defaultLogLevel: ops.defaultLoggerLogLevel,\n });\n }\n\n /* Creates servers, resolves and sets the port. */\n const expressServer = await serverFactory(webpackConfig, ops);\n\n let httpServer;\n if (ops.https) {\n httpServer = https.createServer({\n cert: ops.https.cert,\n key: ops.https.key,\n }, expressServer);\n } else httpServer = http.createServer(expressServer);\n\n /* Sets error handler for HTTP(S) server. */\n httpServer.on('error', (error) => {\n if (error.syscall !== 'listen') throw error;\n const bind = isString(ops.port) ? `Pipe ${ops.port}` : `Port ${ops.port}`;\n\n /* Human-readable message for some specific listen errors. */\n switch (error.code) {\n case 'EACCES':\n ops.logger.error(`${bind} requires elevated privileges`);\n return process.exit(1);\n case 'EADDRINUSE':\n ops.logger.error(`${bind} is already in use`);\n return process.exit(1);\n default:\n throw error;\n }\n });\n\n /* Listening event handler for HTTP(S) server. */\n httpServer.on('listening', () => {\n const addr = httpServer.address();\n const bind = isString(addr) ? `pipe ${addr}` : `port ${addr.port}`;\n ops.logger.info(`Server listening on ${bind} in ${\n process.env.NODE_ENV} mode`);\n });\n\n httpServer.listen(ops.port);\n\n return {\n expressServer,\n httpServer,\n };\n}\n\nlaunch.SCRIPT_LOCATIONS = SC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K,QAAQ,CAAE,KAAM,CAAAD,KAAK,CAC3C,KAAM,CAAAE,IAAI,CAAG,GAAAC,gBAAQ,EAACvB,GAAG,CAACP,IAAI,CAAC,CAAI,QAAOO,GAAG,CAACP,IAAK,EAAC,CAAI,QAAOO,GAAG,CAACP,IAAK,EAAC,CAEzE,6DACA,OAAQ2B,KAAK,CAACI,IAAI,EAChB,IAAK,QAAQ,CACXxB,GAAG,CAACO,MAAM,CAACa,KAAK,CAAE,GAAEE,IAAK,+BAA8B,CAAC,CACxD,MAAO,CAAApB,OAAO,CAACuB,IAAI,CAAC,CAAC,CAAC,CACxB,IAAK,YAAY,CACfzB,GAAG,CAACO,MAAM,CAACa,KAAK,CAAE,GAAEE,IAAK,oBAAmB,CAAC,CAC7C,MAAO,CAAApB,OAAO,CAACuB,IAAI,CAAC,CAAC,CAAC,CACxB,QACE,KAAM,CAAAL,KACV,CACF,CAAC,CAAC,CAEF,iDACAN,UAAU,CAACK,EAAE,CAAC,WAAW,CAAE,IAAM,CAC/B,KAAM,CAAAO,IAAI,CAAGZ,UAAU,CAACa,OAAO,CAAC,CAAC,CACjC,KAAM,CAAAL,IAAI,CAAG,GAAAC,gBAAQ,EAACG,IAAI,CAAC,CAAI,QAAOA,IAAK,EAAC,CAAI,QAAOA,IAAI,CAACjC,IAAK,EAAC,CAClEO,GAAG,CAACO,MAAM,CAACqB,IAAI,CAAE,uBAAsBN,IAAK,OAC1CpB,OAAO,CAACC,GAAG,CAAC0B,QAAS,OAAM,CAC/B,CAAC,CAAC,CAEFf,UAAU,CAACgB,MAAM,CAAC9B,GAAG,CAACP,IAAI,CAAC,CAE3B,MAAO,CACLmB,aAAa,CACbE,UACF,CACF,CAEAjB,MAAM,CAACkC,gBAAgB,CAAGA,0BAAgB,CAAC,IAAAC,QAAA,CAAA5D,OAAA,CAAAW,OAAA,CAE5Bc,MAAM"}
1
+ {"version":3,"file":"index.js","names":["require","_http","_interopRequireDefault","_https","_lodash","_server","_interopRequireWildcard","_renderer","_utils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","normalizePort","value","port","toNumber","isFinite","isNumber","launchServer","webpackConfig","options","ops","cloneDeep","process","env","PORT","defaults","httpsRedirect","logger","undefined","newDefaultLogger","defaultLogLevel","defaultLoggerLogLevel","expressServer","serverFactory","httpServer","https","createServer","cert","key","http","on","error","syscall","bind","isString","code","exit","addr","address","info","NODE_ENV","listen","SCRIPT_LOCATIONS"],"sources":["../../../src/server/index.ts"],"sourcesContent":["import 'source-map-support/register';\n\nimport http from 'http';\nimport https from 'https';\n\nimport {\n cloneDeep,\n defaults,\n isFinite,\n isNumber,\n isString,\n toNumber,\n} from 'lodash';\n\n/* Polyfill required by ReactJS. */\nimport 'raf/polyfill';\n\nimport { type Configuration } from 'webpack';\n\nimport serverFactory, { type OptionsT as ServerOptionsT } from './server';\nimport { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';\n\nexport {\n getDefaultCspSettings,\n} from './server';\n\nexport { errors } from './utils';\n\n/**\n * Normalizes a port into a number, string, or false.\n * TODO: Drop this function?\n * @param value Port name or number.\n * @return Port number (Number), name (String), or false.\n */\nfunction normalizePort(value: number | string) {\n const port = toNumber(value);\n if (isFinite(port)) return port; /* port number */\n if (!isNumber(port)) return value; /* named pipe */\n return false;\n}\n\ntype OptionsT = ServerOptionsT & {\n https?: {\n cert: string;\n key: string;\n },\n\n // TODO: Should we limit it to number | string, and throw if it is different value?\n port?: false | number | string;\n};\n\n/**\n * Creates and launches web-server for ReactJS application. Allows zero\n * or detailed configuration, supports server-side rendering,\n * and development tools, including Hot Module Reloading (HMR).\n *\n * NOTE: Many of options defined below are passed down to the server and\n * renderer factories, and their declared default values are set in those\n * factories, rather than here.\n *\n * @param {object} webpackConfig Webpack configuration used to build\n * the frontend bundle. In production mode the server will read out of it\n * `context`, `publicPath`, and a few other parameters, necessary to locate\n * and serve the app bundle. In development mode the server will use entire\n * provided config to build the app bundle in memory, and further watch and\n * update it via HMR.\n * @param {object} [options] Additional parameters.\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {function} [options.beforeExpressJsError] Asynchronous callback\n * (`(server) => Promise<boolean>`) to be executed just before the default error\n * handler is added to ExpressJS server. If the callback is provided and its\n * result resolves to a truthy value, `react-utils` won't attach the default\n * error handler.\n * @param {function} [options.beforeExpressJsSetup] Asynchronous callback\n * (`(server) => Promise) to be executed right after ExpressJS server creation,\n * before any configuration is performed.\n * @param {BeforeRenderHook} [options.beforeRender] The hook to run just before\n * the server-side rendering. For each incoming request, it will be executed\n * just before the HTML markup is generated at the server. It allows to load\n * and provide the data necessary for server-side rendering, and also to inject\n * additional configuration and scripts into the generated HTML code.\n * @param {boolean} [options.noCsp] Set `true` to disable\n * Content-Security-Policy (CSP) headers altogether.\n * @param {function} [options.cspSettingsHook] A hook allowing\n * to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n * settings for [helmet](https://github.com/helmetjs/helmet)'s\n * `contentSecurityPolicy` middleware on per-request basis.\n *\n * If provided it should be a with signature: \\\n * `(defaultSettings: object, req: object)` &rArr; `object` \\\n * which gets the default settings (also used without the hook),\n * and the incoming request object. The hook response will be passed\n * as options to the helmet `contentSecurityPolicy` middleware.\n *\n * Currently, the default settings is the following object in production\n * environment:\n * ```js\n * {\n * directives: {\n * defaultSrc: [\"'self'\"],\n * baseUri: [\"'self'\"],\n * blockAllMixedContent: [],\n * fontSrc: [\"'self'\", 'https:', 'data:'],\n * frameAncestors: [\"'self'\"],\n * frameSrc: [\"'self'\", 'https://*.youtube.com'],\n * imgSrc: [\"'self'\", 'data:'],\n * objectSrc: [\"'none'\"],\n * scriptSrc: [\"'self'\", \"'unsafe-eval'\", `'nonce-UNIQUE_NONCE_VALUE'`],\n * scriptSrcAttr: [\"'none'\"],\n * styleSrc: [\"'self'\", 'https:', \"'unsafe-inline'\"],\n * upgradeInsecureRequests: [] // Removed in dev mode.\n * }\n * }\n * ```\n * It matches the default value used by Helmet with a few updates:\n * - YouTube host is whitelisted in the `frameSrc` directive to ensure\n * the {@link YouTubeVideo} component works.\n * - An unique per-request nonce is added to `scriptSrc` directive to\n * whitelist auxiliary scripts injected by react-utils. The actual nonce\n * value can be fetched by host code via `.nonce` field of `req` argument\n * of `.beforeRender` hook.\n * - `upgradeInsecureRequests` directive is removed in development mode,\n * to simplify local testing with http requests.\n * @param {string} [options.defaultLoggerLogLevel='info'] Log level for\n * the default logger, which is created if no `logger` option provided.\n * @param {boolean} [options.devMode] Pass in `true` to start the server in\n * development mode.\n * @param {string} [options.favicon] Path to the favicon to use by the server.\n * By default no favicon is used.\n * @param {object} [options.https] If provided, HTTPS server will be started,\n * instead of HTTP otherwise. The object should provide SSL certificate and key\n * via two string fields: `cert`, and `key`.\n * @param {string} [options.https.cert] SSL Certificate.\n * @param {string} [options.https.key] SSL key.\n * @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable\n * automatic redirection of all incoming HTTP requests to HTTPS.\n *\n * To smoothly use it at `localhost` you need to run the server in HTTPS mode,\n * and also properly create and install a self-signed SSL sertificate on your\n * system. This article is helpful:\n * [How to get HTTPS working on your local development environment in 5 minutes](https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec)\n * @param {Logger} [options.logger] The logger to use at server side.\n * By default [`winston`](https://www.npmjs.com/package/winston) logger\n * with console transport is used. The logger you provide, or the default\n * `winston` logger otherwise, will be attached to the created ExpressJS server\n * object.\n * @param {function} [options.onExpressJsSetup] An async callback\n * (`(server) => Promise`) to be triggered when most of the server\n * configuration is completed, just before the server-side renderer,\n * and the default error handler are attached. You can use it to mount\n * custom API routes. The server-side logger can be accessed as `server.logger`.\n * @param {number|string} [options.port=3000] The port to start the server on.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` &ndash; the cache key for the response;\n * - `maxage?: number` &ndash; the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @return {Promise<{ expressServer: object, httpServer: object }>} Resolves to\n * an object with created Express and HTTP servers.\n */\nexport default async function launchServer(webpackConfig: Configuration, options: OptionsT) {\n /* Options normalization. */\n const ops = options ? cloneDeep(options) : {};\n ops.port = normalizePort(ops.port || process.env.PORT || 3000);\n defaults(ops, { httpsRedirect: true });\n\n // TODO: Need a separate type for normalized options, which guarantees\n // the logger is set!\n if (ops.logger === undefined) {\n ops.logger = newDefaultLogger({\n defaultLogLevel: ops.defaultLoggerLogLevel,\n });\n }\n\n /* Creates servers, resolves and sets the port. */\n const expressServer = await serverFactory(webpackConfig, ops);\n\n let httpServer: http.Server;\n if (ops.https) {\n httpServer = https.createServer({\n cert: ops.https.cert,\n key: ops.https.key,\n }, expressServer);\n } else httpServer = http.createServer(expressServer);\n\n /* Sets error handler for HTTP(S) server. */\n httpServer.on('error', (error: Error) => {\n if ((error as any).syscall !== 'listen') throw error;\n const bind = isString(ops.port) ? `Pipe ${ops.port}` : `Port ${ops.port}`;\n\n /* Human-readable message for some specific listen errors. */\n switch ((error as any).code) {\n case 'EACCES':\n ops.logger!.error(`${bind} requires elevated privileges`);\n return process.exit(1);\n case 'EADDRINUSE':\n ops.logger!.error(`${bind} is already in use`);\n return process.exit(1);\n default:\n throw error;\n }\n });\n\n /* Listening event handler for HTTP(S) server. */\n httpServer.on('listening', () => {\n const addr = httpServer.address()!;\n const bind = isString(addr) ? `pipe ${addr}` : `port ${addr.port}`;\n ops.logger!.info(`Server listening on ${bind} in ${\n process.env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AAX,GAAA,EAAAW,CAAA,CAAAC,GAAA,EAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,CAAAM,CAAA,CAAAI,CAAA,EAAAV,CAAA,CAAAM,CAAA,EAAAd,CAAA,CAAAc,CAAA,SAAAN,CAAA,CAAAH,OAAA,CAAAL,CAAA,CAAAG,CAAA,EAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,CAAAQ,CAAA,EAAAA,CAAA,CAZjC,oCAcA;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,CAAAY,aAAaA,CAACC,KAAsB,CAAE,CAC7C,KAAM,CAAAC,IAAI,CAAG,GAAAC,gBAAQ,EAACF,KAAK,CAAC,CAC5B,GAAI,GAAAG,gBAAQ,EAACF,IAAI,CAAC,CAAE,MAAO,CAAAA,IAAI,CAAE,iBACjC,GAAI,CAAC,GAAAG,gBAAQ,EAACH,IAAI,CAAC,CAAE,MAAO,CAAAD,KAAK,CAAE,gBACnC,MAAO,MACT,CAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACe,cAAe,CAAAK,YAAYA,CAACC,aAA4B,CAAEC,OA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AACO,MAAM,CAAEc,KAAK,CAAE,GAAEE,IAAK,+BAA8B,CAAC,CACzD,MAAO,CAAArB,OAAO,CAACwB,IAAI,CAAC,CAAC,CAAC,CACxB,IAAK,YAAY,CACf1B,GAAG,CAACO,MAAM,CAAEc,KAAK,CAAE,GAAEE,IAAK,oBAAmB,CAAC,CAC9C,MAAO,CAAArB,OAAO,CAACwB,IAAI,CAAC,CAAC,CAAC,CACxB,QACE,KAAM,CAAAL,KACV,CACF,CAAC,CAAC,CAEF,iDACAP,UAAU,CAACM,EAAE,CAAC,WAAW,CAAE,IAAM,CAC/B,KAAM,CAAAO,IAAI,CAAGb,UAAU,CAACc,OAAO,CAAC,CAAE,CAClC,KAAM,CAAAL,IAAI,CAAG,GAAAC,gBAAQ,EAACG,IAAI,CAAC,CAAI,QAAOA,IAAK,EAAC,CAAI,QAAOA,IAAI,CAAClC,IAAK,EAAC,CAClEO,GAAG,CAACO,MAAM,CAAEsB,IAAI,CAAE,uBAAsBN,IAAK,OAC3CrB,OAAO,CAACC,GAAG,CAAC2B,QAAS,OAAM,CAC/B,CAAC,CAAC,CAEFhB,UAAU,CAACiB,MAAM,CAAC/B,GAAG,CAACP,IAAI,CAAC,CAE3B,MAAO,CACLmB,aAAa,CACbE,UACF,CACF,CAEAjB,YAAY,CAACmC,gBAAgB,CAAGA,0BAAgB"}
@@ -1,28 +1,29 @@
1
- "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.SCRIPT_LOCATIONS=void 0;exports.default=factory;exports.isBrotliAcceptable=isBrotliAcceptable;exports.newDefaultLogger=newDefaultLogger;var _fs=_interopRequireDefault(require("fs"));var _path=_interopRequireDefault(require("path"));var _stream=require("stream");var _zlib=require("zlib");var _winston=_interopRequireDefault(require("winston"));var _reactGlobalState=require("@dr.pogodin/react-global-state");var _jsUtils=require("@dr.pogodin/js-utils");var _lodash=require("lodash");var _config=_interopRequireDefault(require("config"));var _nodeForge=_interopRequireDefault(require("node-forge"));var _server=require("react-dom/server");var _reactHelmet=require("react-helmet");var _server2=require("react-router-dom/server");var _serializeJavascript=_interopRequireDefault(require("serialize-javascript"));var _buildInfo=require("../shared/utils/isomorphy/buildInfo");var _Cache=_interopRequireDefault(require("./Cache"));var _jsxRuntime=require("react/jsx-runtime");/**
1
+ "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.SCRIPT_LOCATIONS=void 0;exports.default=factory;exports.isBrotliAcceptable=isBrotliAcceptable;exports.newDefaultLogger=newDefaultLogger;var _fs=_interopRequireDefault(require("fs"));var _path=_interopRequireDefault(require("path"));require("express");require("react");var _stream=require("stream");var _zlib=require("zlib");var _winston=_interopRequireDefault(require("winston"));var _reactGlobalState=require("@dr.pogodin/react-global-state");var _jsUtils=require("@dr.pogodin/js-utils");var _lodash=require("lodash");var _config=_interopRequireDefault(require("config"));var _nodeForge=_interopRequireDefault(require("node-forge"));var _server=require("react-dom/server");var _reactHelmet=require("react-helmet");var _server2=require("react-router-dom/server");var _serializeJavascript=_interopRequireDefault(require("serialize-javascript"));var _buildInfo=require("../shared/utils/isomorphy/buildInfo");require("../shared/utils/globalState");require("webpack");var _Cache=_interopRequireDefault(require("./Cache"));var _jsxRuntime=require("react/jsx-runtime");/**
2
2
  * ExpressJS middleware for server-side rendering of a ReactJS app.
3
- */const sanitizedConfig=(0,_lodash.omit)(_config.default,"SECRET");const SCRIPT_LOCATIONS=exports.SCRIPT_LOCATIONS={BODY_OPEN:"BODY_OPEN",DEFAULT:"DEFAULT",HEAD_OPEN:"HEAD_OPEN"};/**
3
+ */const sanitizedConfig=(0,_lodash.omit)(_config.default,"SECRET");// Note: These type definitions for logger are copied from Winston logger,
4
+ // then simplified to make it easier to fit an alternative logger into this
5
+ // interface.
6
+ // eslint-disable-next-line @typescript-eslint/naming-convention
7
+ let SCRIPT_LOCATIONS=exports.SCRIPT_LOCATIONS=/*#__PURE__*/function(SCRIPT_LOCATIONS){SCRIPT_LOCATIONS["BODY_OPEN"]="BODY_OPEN";SCRIPT_LOCATIONS["DEFAULT"]="DEFAULT";SCRIPT_LOCATIONS["HEAD_OPEN"]="HEAD_OPEN";return SCRIPT_LOCATIONS}({});class ServerSsrContext extends _reactGlobalState.SsrContext{chunks=[];status=200;constructor(req,chunkGroups,initialState){super((0,_lodash.cloneDeep)(initialState)||{});this.chunkGroups=chunkGroups;this.req=req}}/**
4
8
  * Reads build-time information about the app. This information is generated
5
9
  * by our standard Webpack config for apps, and it is written into
6
10
  * ".build-info" file in the context folder specified in Webpack config.
7
11
  * At the moment, that file contains build timestamp and a random 32-bit key,
8
12
  * suitable for cryptographical use.
9
- * @ignore
10
- * @param {String} context Webpack context path used during the build.
11
- * @return {Object} Resolves to the build-time information.
12
- */function getBuildInfo(context){const url=_path.default.resolve(context,".build-info");return JSON.parse(_fs.default.readFileSync(url))}/**
13
+ * @param context Webpack context path used during the build.
14
+ * @return Resolves to the build-time information.
15
+ */function getBuildInfo(context){const url=_path.default.resolve(context,".build-info");return JSON.parse(_fs.default.readFileSync(url,"utf8"))}/**
13
16
  * Attempts to read from disk the named chunk groups mapping generated
14
17
  * by Webpack during the compilation.
15
18
  * It will not work for development builds, where these stats should be captured
16
19
  * via compilator callback.
17
- * @ignore
18
- * @param {string} buildDir
19
- * @return {object}
20
- */function readChunkGroupsJson(buildDir){const url=_path.default.resolve(buildDir,"__chunk_groups__.json");let res;try{res=JSON.parse(_fs.default.readFileSync(url))}catch(err){res=null}return res}/**
20
+ * @param buildDir
21
+ * @return
22
+ */function readChunkGroupsJson(buildDir){const url=_path.default.resolve(buildDir,"__chunk_groups__.json");let res;try{res=JSON.parse(_fs.default.readFileSync(url,"utf8"))}catch(err){res=null}return res}/**
21
23
  * Prepares a new Cipher for data encryption.
22
- * @ignore
23
- * @param {String} key Encryption key (32-bit random key is expected, see
24
+ * @param key Encryption key (32-bit random key is expected, see
24
25
  * node-forge documentation, in case of doubts).
25
- * @return {Promise} Resolves to the object with two fields:
26
+ * @return Resolves to the object with two fields:
26
27
  * 1. cipher - a new Cipher, ready for encryption;
27
28
  * 2. iv - initial vector used by the cipher.
28
29
  */function prepareCipher(key){return new Promise((resolve,reject)=>{_nodeForge.default.random.getBytes(32,(err,iv)=>{if(err)reject(err);else{const cipher=_nodeForge.default.cipher.createCipher("AES-CBC",key);cipher.start({iv});resolve({cipher,iv})}})})}/**
@@ -51,26 +52,26 @@
51
52
  * @return {object}
52
53
  */function newDefaultLogger({defaultLogLevel="info"}={}){const{format,transports}=_winston.default;return _winston.default.createLogger({level:defaultLogLevel,format:format.combine(format.splat(),format.timestamp(),format.colorize(),format.printf(({level,message,timestamp,stack,...rest})=>{let res=`${level}\t(at ${timestamp}):\t${message}`;if(Object.keys(rest).length){res+=`\n${JSON.stringify(rest,null,2)}`}if(stack)res+=`\n${stack}`;return res})),transports:[new transports.Console]})}/**
53
54
  * Creates the middleware.
54
- * @param {object} webpackConfig
55
- * @param {object} options Additional options:
56
- * @param {Component} [options.Application] The root ReactJS component of
55
+ * @param webpackConfig
56
+ * @param options Additional options:
57
+ * @param [options.Application] The root ReactJS component of
57
58
  * the app to use for the server-side rendering. When not provided
58
59
  * the server-side rendering is disabled.
59
- * @param {object} [options.buildInfo] "Build info" object to use. If provided,
60
+ * @param [options.buildInfo] "Build info" object to use. If provided,
60
61
  * it will be used, instead of trying to load from the filesystem the one
61
62
  * generated by the Webpack build. It is intended for test environments,
62
63
  * where passing this stuff via file system is no bueno.
63
- * @param {boolean} [options.favicon] `true` will include favicon
64
+ * @param [options.favicon] `true` will include favicon
64
65
  * link into the rendered HTML templates.
65
- * @param {boolean} [options.noCsp] `true` means that no
66
+ * @param [options.noCsp] `true` means that no
66
67
  * Content-Security-Policy (CSP) is used by server, thus the renderer
67
68
  * may cut a few corners.
68
- * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.
69
- * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,
69
+ * @param [options.maxSsrRounds=10] Maximum number of SSR rounds.
70
+ * @param [options.ssrTimeout=1000] SSR timeout in milliseconds,
70
71
  * defaults to 1 second.
71
- * @param {number} [options.staticCacheSize=1.e7] The maximum
72
+ * @param [options.staticCacheSize=1.e7] The maximum
72
73
  * static cache size in bytes. Defaults to ~10 MB.
73
- * @param {function} [options.staticCacheController] When given, it activates,
74
+ * @param [options.staticCacheController] When given, it activates,
74
75
  * and controls the static caching of generated HTML markup. When this function
75
76
  * is provided, on each incoming request it is triggered with the request
76
77
  * passed in as the argument. To attempt to serve the response from the cache
@@ -78,7 +79,7 @@
78
79
  * - `key: string` &ndash; the cache key for the response;
79
80
  * - `maxage?: number` &ndash; the maximum age of cached result in ms.
80
81
  * If undefined - infinite age is assumed.
81
- * @return {function} Created middleware.
82
+ * @return Created middleware.
82
83
  */function factory(webpackConfig,options){const ops=(0,_lodash.defaults)((0,_lodash.clone)(options),{beforeRender:()=>Promise.resolve({}),maxSsrRounds:10,ssrTimeout:1000,staticCacheSize:1.e7});// Note: in normal use the default logger is created and set in the root
83
84
  // server function, and this initialization is for testing uses, where
84
85
  // renderer is imported directly.
@@ -91,12 +92,13 @@ const regex=new RegExp(buffer.nonce,"g");h=h.replace(regex,req.nonce)}if(status!
91
92
  // These data come from the Webpack compilation, either from the stats
92
93
  // attached to the request (in dev mode), or from a file output during
93
94
  // the build (in prod mode).
94
- let chunkGroups;const webpackStats=(0,_lodash.get)(res.locals,"webpack.devMiddleware.stats");if(webpackStats){chunkGroups=(0,_lodash.mapValues)(webpackStats.toJson({all:false,chunkGroups:true}).namedChunkGroups,item=>item.assets.map(({name})=>name))}else if(CHUNK_GROUPS)chunkGroups=CHUNK_GROUPS;else chunkGroups={};/* Optional server-side rendering. */let App=ops.Application;const ssrContext={req,state:(0,_lodash.cloneDeep)(initialState||{}),// Array of chunk names encountered during the rendering.
95
- chunks:[],chunkGroups};let stream;if(App){const ssrStart=Date.now();const renderPass=async()=>{ssrContext.chunks=[];return new Promise((resolve,reject)=>{const pipeableStream=(0,_server.renderToPipeableStream)(/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider,{initialState:ssrContext.state,ssrContext:ssrContext,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_server2.StaticRouter,{location:req.url,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(App,{})})}),{onAllReady:()=>resolve(pipeableStream),onError:reject})})};let ssrRound=0;let bailed=false;for(;ssrRound<ops.maxSsrRounds;++ssrRound){stream=await renderPass();// eslint-disable-line no-await-in-loop
95
+ let chunkGroups;const webpackStats=(0,_lodash.get)(res.locals,"webpack.devMiddleware.stats");if(webpackStats){chunkGroups=(0,_lodash.mapValues)(webpackStats.toJson({all:false,chunkGroups:true}).namedChunkGroups,item=>item.assets.map(({name})=>name))}else if(CHUNK_GROUPS)chunkGroups=CHUNK_GROUPS;else chunkGroups={};/* Optional server-side rendering. */const App=ops.Application;let appHtmlMarkup="";const ssrContext=new ServerSsrContext(req,chunkGroups,initialState);let stream;if(App){const ssrStart=Date.now();// TODO: Somehow, without it TS does not realise that
96
+ // App has been checked to exist.
97
+ const App2=App;const renderPass=async()=>{ssrContext.chunks=[];return new Promise((resolve,reject)=>{const pipeableStream=(0,_server.renderToPipeableStream)(/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider,{initialState:ssrContext.state,ssrContext:ssrContext,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_server2.StaticRouter,{location:req.url,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(App2,{})})}),{onAllReady:()=>resolve(pipeableStream),onError:reject})})};let ssrRound=0;let bailed=false;for(;ssrRound<ops.maxSsrRounds;++ssrRound){stream=await renderPass();// eslint-disable-line no-await-in-loop
96
98
  if(!ssrContext.dirty)break;/* eslint-disable no-await-in-loop */const timeout=ops.ssrTimeout+ssrStart-Date.now();bailed=timeout<=0||!(await Promise.race([Promise.allSettled(ssrContext.pending),(0,_jsUtils.timer)(timeout).then(()=>false)]));if(bailed)break;/* eslint-enable no-await-in-loop */}let logMsg;if(ssrContext.dirty){// NOTE: In the case of incomplete SSR one more round is necessary
97
99
  // to ensure the correct hydration when some pending promises have
98
100
  // resolved and placed their data into the initial global state.
99
- stream=await renderPass();logMsg=bailed?`SSR timed out after ${ops.ssrTimeout} second(s)`:`SSR bailed out after ${ops.maxSsrRounds} round(s)`}else logMsg=`SSR completed in ${ssrRound+1} round(s)`;ops.logger.log(ssrContext.dirty?"warn":"info",logMsg);App="";stream.pipe(new _stream.Writable({write:(chunk,_,done)=>{App+=chunk.toString();done()}}));/* This takes care about server-side rendering of page title and meta tags
101
+ stream=await renderPass();logMsg=bailed?`SSR timed out after ${ops.ssrTimeout} second(s)`:`SSR bailed out after ${ops.maxSsrRounds} round(s)`}else logMsg=`SSR completed in ${ssrRound+1} round(s)`;ops.logger.log(ssrContext.dirty?"warn":"info",logMsg);stream.pipe(new _stream.Writable({write:(chunk,_,done)=>{appHtmlMarkup+=chunk.toString();done()}}));/* This takes care about server-side rendering of page title and meta tags
100
102
  * (still demands injection into HTML template, which happens below). */helmet=_reactHelmet.Helmet.renderStatic()}/* Encrypts data to be injected into HTML.
101
103
  * Keep in mind, that this encryption is no way secure: as the JS bundle
102
104
  * contains decryption key and is able to decode it at the client side.
@@ -130,14 +132,14 @@ stream=await renderPass();logMsg=bailed?`SSR timed out after ${ops.ssrTimeout} s
130
132
  </head>
131
133
  <body>
132
134
  ${grouppedExtraScripts[SCRIPT_LOCATIONS.BODY_OPEN]}
133
- <div id="react-view">${App||""}</div>
135
+ <div id="react-view">${appHtmlMarkup}</div>
134
136
  ${scriptChunkString}
135
137
  ${grouppedExtraScripts[SCRIPT_LOCATIONS.DEFAULT]}
136
138
  </body>
137
139
  </html>`;const status=ssrContext.status||200;if(status!==200)res.status(status);if(cacheRef&&status<500){// Note: waiting for the caching to complete is not strictly necessary,
138
140
  // but it greately simplifies testing, and error reporting.
139
- await new Promise((done,failed)=>{(0,_zlib.brotliCompress)(html,(error,buffer)=>{if(error)failed(error);else{buffer.nonce=req.nonce;// eslint-disable-line no-param-reassign
140
- cache.add({buffer,status},cacheRef.key);done()}})})}// Note: as caching code above may throw in some cases, sending response
141
+ await new Promise((done,failed)=>{(0,_zlib.brotliCompress)(html,(error,buffer)=>{const b=buffer;if(error)failed(error);else{b.nonce=req.nonce;// eslint-disable-line no-param-reassign
142
+ cache.add({buffer:b,status},cacheRef.key,buffer.length);done()}})})}// Note: as caching code above may throw in some cases, sending response
141
143
  // before it completes will likely hide the error, making it difficult
142
144
  // to debug. Thus, at least for now, lets send response after it.
143
145
  res.send(html)}catch(error){next(error)}}}