@enonic/nextjs-adapter 3.2.2 → 3.3.0-B2

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 (410) hide show
  1. package/{baseMappings.js → dist/baseMappings.js} +9 -9
  2. package/dist/baseMappings.js.map +1 -0
  3. package/dist/client/getClientHydratedHtml.jsx.map +1 -0
  4. package/dist/client.js.map +1 -0
  5. package/{common → dist/common}/ComponentRegistry.js +1 -1
  6. package/dist/common/ComponentRegistry.js.map +1 -0
  7. package/dist/common/UrlProcessor.js.map +1 -0
  8. package/dist/common/constants.js.map +1 -0
  9. package/{common → dist/common}/env.js +1 -1
  10. package/dist/common/env.js.map +1 -0
  11. package/dist/guillotine/applyProcessors.js.map +1 -0
  12. package/dist/guillotine/buildComponentTree.js.map +1 -0
  13. package/{guillotine → dist/guillotine}/buildErrorResponse.js +3 -3
  14. package/dist/guillotine/buildErrorResponse.js.map +1 -0
  15. package/{guillotine → dist/guillotine}/buildPage.js +1 -1
  16. package/dist/guillotine/buildPage.js.map +1 -0
  17. package/{guillotine → dist/guillotine}/collectComponentDescriptors.d.ts +1 -1
  18. package/{guillotine → dist/guillotine}/collectComponentDescriptors.js +4 -4
  19. package/dist/guillotine/collectComponentDescriptors.js.map +1 -0
  20. package/{guillotine → dist/guillotine}/combineMultipleQueries.js +1 -1
  21. package/dist/guillotine/combineMultipleQueries.js.map +1 -0
  22. package/{guillotine → dist/guillotine}/createMetaData.d.ts +1 -1
  23. package/{guillotine → dist/guillotine}/createMetaData.js +2 -2
  24. package/dist/guillotine/createMetaData.js.map +1 -0
  25. package/{guillotine → dist/guillotine}/fetchContent.js +10 -10
  26. package/dist/guillotine/fetchContent.js.map +1 -0
  27. package/{guillotine → dist/guillotine}/fetchContentData.js +2 -2
  28. package/dist/guillotine/fetchContentData.js.map +1 -0
  29. package/dist/guillotine/fetchContentPathsForAllLocales.js.map +1 -0
  30. package/{guillotine → dist/guillotine}/fetchContentPathsForLocale.js +4 -4
  31. package/dist/guillotine/fetchContentPathsForLocale.js.map +1 -0
  32. package/{guillotine → dist/guillotine}/fetchFromApi.js +7 -7
  33. package/dist/guillotine/fetchFromApi.js.map +1 -0
  34. package/{guillotine → dist/guillotine}/fetchGuillotine.js +6 -6
  35. package/dist/guillotine/fetchGuillotine.js.map +1 -0
  36. package/{guillotine → dist/guillotine}/fetchMetaData.js +4 -4
  37. package/dist/guillotine/fetchMetaData.js.map +1 -0
  38. package/{guillotine → dist/guillotine}/getCleanContentPathArrayOrThrow400.js +1 -1
  39. package/dist/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -0
  40. package/dist/guillotine/getComponentConfig.js.map +1 -0
  41. package/dist/guillotine/getContentAndComponentPaths.js.map +1 -0
  42. package/dist/guillotine/getMetaData.js.map +1 -0
  43. package/{guillotine → dist/guillotine}/getParentRegion.js +1 -1
  44. package/dist/guillotine/getParentRegion.js.map +1 -0
  45. package/{guillotine → dist/guillotine}/getQueryAndVariables.js +2 -2
  46. package/dist/guillotine/getQueryAndVariables.js.map +1 -0
  47. package/dist/guillotine/metadata/configQuery.js.map +1 -0
  48. package/dist/guillotine/metadata/richTextQuery.js.map +1 -0
  49. package/{guillotine → dist/guillotine}/parseComponentPath.js +3 -3
  50. package/dist/guillotine/parseComponentPath.js.map +1 -0
  51. package/dist/guillotine/prefixFragmentCmpPath.js.map +1 -0
  52. package/dist/guillotine/processComponentConfig.js.map +1 -0
  53. package/dist/guillotine/restrictComponentsToPath.js.map +1 -0
  54. package/dist/guillotine/validateData.js.map +1 -0
  55. package/dist/guillotine/validateNotFound.js.map +1 -0
  56. package/dist/guillotine/validateShortcut.js.map +1 -0
  57. package/{i18n → dist/i18n}/LocaleContext.d.ts +1 -1
  58. package/{i18n → dist/i18n}/LocaleContext.jsx +3 -3
  59. package/dist/i18n/LocaleContext.jsx.map +1 -0
  60. package/dist/i18n/i18n.js.map +1 -0
  61. package/{index.d.ts → dist/index.d.ts} +3 -3
  62. package/{index.js → dist/index.js} +3 -3
  63. package/dist/index.js.map +1 -0
  64. package/dist/query/Shortcut.js.map +1 -0
  65. package/dist/server/getServerRenderedHtml.js.map +1 -0
  66. package/dist/server.js.map +1 -0
  67. package/{types → dist/types}/component.js.map +1 -1
  68. package/{types → dist/types}/componentProps.d.ts +2 -1
  69. package/dist/types/componentProps.js.map +1 -0
  70. package/{types → dist/types}/guillotine.d.ts +1 -1
  71. package/{types → dist/types}/guillotine.js.map +1 -1
  72. package/dist/types/i18n.js.map +1 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/types/next.js.map +1 -0
  75. package/dist/types/util.js.map +1 -0
  76. package/dist/utils/addLineNumbers.js.map +1 -0
  77. package/{utils → dist/utils}/buildGuillotineRequestHeaders.d.ts +1 -1
  78. package/{utils → dist/utils}/buildGuillotineRequestHeaders.js +3 -3
  79. package/dist/utils/buildGuillotineRequestHeaders.js.map +1 -0
  80. package/dist/utils/commonChars.js.map +1 -0
  81. package/dist/utils/enonicLog.js.map +1 -0
  82. package/dist/utils/fixDoubleSlashes.js.map +1 -0
  83. package/dist/utils/getAllLocales.js.map +1 -0
  84. package/dist/utils/getContentApiUrl.js.map +1 -0
  85. package/dist/utils/getLocaleMapping.js.map +1 -0
  86. package/dist/utils/getLocaleMappingByLocale.js.map +1 -0
  87. package/dist/utils/getLocaleMappingByProjectId.js.map +1 -0
  88. package/{utils → dist/utils}/getLocaleMappings.js +1 -1
  89. package/dist/utils/getLocaleMappings.js.map +1 -0
  90. package/{utils → dist/utils}/getRenderMode.js +1 -1
  91. package/dist/utils/getRenderMode.js.map +1 -0
  92. package/dist/utils/getRequestLocaleInfo.js.map +1 -0
  93. package/dist/utils/getXpBaseUrl.js.map +1 -0
  94. package/dist/utils/indent.js.map +1 -0
  95. package/dist/utils/sanitizeGraphqlName.js.map +1 -0
  96. package/{views → dist/views}/BaseComponent.d.ts +1 -1
  97. package/{views → dist/views}/BaseComponent.jsx +5 -5
  98. package/dist/views/BaseComponent.jsx.map +1 -0
  99. package/{views → dist/views}/BaseContent.jsx +1 -1
  100. package/dist/views/BaseContent.jsx.map +1 -0
  101. package/dist/views/BaseLayout.jsx.map +1 -0
  102. package/dist/views/BaseMacro.jsx.map +1 -0
  103. package/dist/views/BasePage.jsx.map +1 -0
  104. package/dist/views/BasePart.jsx.map +1 -0
  105. package/dist/views/Empty.jsx.map +1 -0
  106. package/dist/views/Fragment.jsx.map +1 -0
  107. package/dist/views/MainView.jsx.map +1 -0
  108. package/{views → dist/views}/PropsView.jsx +1 -1
  109. package/dist/views/PropsView.jsx.map +1 -0
  110. package/dist/views/Region.jsx.map +1 -0
  111. package/dist/views/RichTextView.jsx +65 -0
  112. package/dist/views/RichTextView.jsx.map +1 -0
  113. package/dist/views/SingleComponent.jsx.map +1 -0
  114. package/dist/views/StaticContent.jsx.map +1 -0
  115. package/dist/views/Text.jsx.map +1 -0
  116. package/dist/views/macros/DefaultMacro.jsx.map +1 -0
  117. package/dist/views/macros/DisableMacro.jsx.map +1 -0
  118. package/package.json +49 -42
  119. package/baseMappings.js.map +0 -1
  120. package/client/getClientHydratedHtml.jsx.map +0 -1
  121. package/client.js.map +0 -1
  122. package/common/ComponentRegistry.js.map +0 -1
  123. package/common/UrlProcessor.js.map +0 -1
  124. package/common/constants.js.map +0 -1
  125. package/common/env.js.map +0 -1
  126. package/guillotine/applyProcessors.js.map +0 -1
  127. package/guillotine/buildComponentTree.js.map +0 -1
  128. package/guillotine/buildErrorResponse.js.map +0 -1
  129. package/guillotine/buildPage.js.map +0 -1
  130. package/guillotine/collectComponentDescriptors.js.map +0 -1
  131. package/guillotine/combineMultipleQueries.js.map +0 -1
  132. package/guillotine/createMetaData.js.map +0 -1
  133. package/guillotine/fetchContent.js.map +0 -1
  134. package/guillotine/fetchContentData.js.map +0 -1
  135. package/guillotine/fetchContentPathsForAllLocales.js.map +0 -1
  136. package/guillotine/fetchContentPathsForLocale.js.map +0 -1
  137. package/guillotine/fetchFromApi.js.map +0 -1
  138. package/guillotine/fetchGuillotine.js.map +0 -1
  139. package/guillotine/fetchMetaData.js.map +0 -1
  140. package/guillotine/getCleanContentPathArrayOrThrow400.js.map +0 -1
  141. package/guillotine/getComponentConfig.js.map +0 -1
  142. package/guillotine/getContentAndComponentPaths.js.map +0 -1
  143. package/guillotine/getMetaData.js.map +0 -1
  144. package/guillotine/getParentRegion.js.map +0 -1
  145. package/guillotine/getQueryAndVariables.js.map +0 -1
  146. package/guillotine/metadata/configQuery.js.map +0 -1
  147. package/guillotine/metadata/richTextQuery.js.map +0 -1
  148. package/guillotine/parseComponentPath.js.map +0 -1
  149. package/guillotine/prefixFragmentCmpPath.js.map +0 -1
  150. package/guillotine/processComponentConfig.js.map +0 -1
  151. package/guillotine/restrictComponentsToPath.js.map +0 -1
  152. package/guillotine/validateData.js.map +0 -1
  153. package/guillotine/validateNotFound.js.map +0 -1
  154. package/guillotine/validateShortcut.js.map +0 -1
  155. package/i18n/LocaleContext.jsx.map +0 -1
  156. package/i18n/i18n.js.map +0 -1
  157. package/index.js.map +0 -1
  158. package/query/Shortcut.js.map +0 -1
  159. package/server/getServerRenderedHtml.js.map +0 -1
  160. package/server.js.map +0 -1
  161. package/src/baseMappings.ts +0 -53
  162. package/src/client/getClientHydratedHtml.tsx +0 -12
  163. package/src/client.ts +0 -2
  164. package/src/common/ComponentRegistry.ts +0 -162
  165. package/src/common/UrlProcessor.ts +0 -172
  166. package/src/common/constants.ts +0 -92
  167. package/src/common/env.ts +0 -41
  168. package/src/guillotine/applyProcessors.ts +0 -38
  169. package/src/guillotine/buildComponentTree.ts +0 -57
  170. package/src/guillotine/buildErrorResponse.ts +0 -35
  171. package/src/guillotine/buildPage.ts +0 -15
  172. package/src/guillotine/collectComponentDescriptors.ts +0 -63
  173. package/src/guillotine/combineMultipleQueries.ts +0 -75
  174. package/src/guillotine/createMetaData.ts +0 -72
  175. package/src/guillotine/fetchContent.ts +0 -246
  176. package/src/guillotine/fetchContentData.ts +0 -37
  177. package/src/guillotine/fetchContentPathsForAllLocales.ts +0 -21
  178. package/src/guillotine/fetchContentPathsForLocale.ts +0 -43
  179. package/src/guillotine/fetchFromApi.ts +0 -76
  180. package/src/guillotine/fetchGuillotine.ts +0 -76
  181. package/src/guillotine/fetchMetaData.ts +0 -31
  182. package/src/guillotine/getCleanContentPathArrayOrThrow400.ts +0 -22
  183. package/src/guillotine/getComponentConfig.ts +0 -7
  184. package/src/guillotine/getContentAndComponentPaths.ts +0 -11
  185. package/src/guillotine/getMetaData.ts +0 -74
  186. package/src/guillotine/getParentRegion.ts +0 -54
  187. package/src/guillotine/getQueryAndVariables.ts +0 -52
  188. package/src/guillotine/metadata/configQuery.ts +0 -46
  189. package/src/guillotine/metadata/richTextQuery.ts +0 -49
  190. package/src/guillotine/parseComponentPath.ts +0 -29
  191. package/src/guillotine/prefixFragmentCmpPath.ts +0 -13
  192. package/src/guillotine/processComponentConfig.ts +0 -38
  193. package/src/guillotine/restrictComponentsToPath.ts +0 -48
  194. package/src/guillotine/validateData.ts +0 -11
  195. package/src/guillotine/validateNotFound.ts +0 -20
  196. package/src/guillotine/validateShortcut.ts +0 -43
  197. package/src/i18n/LocaleContext.tsx +0 -59
  198. package/src/i18n/i18n.ts +0 -57
  199. package/src/index.ts +0 -42
  200. package/src/query/Shortcut.ts +0 -18
  201. package/src/server/getServerRenderedHtml.ts +0 -3
  202. package/src/server.ts +0 -5
  203. package/src/types/component.ts +0 -131
  204. package/src/types/componentProps.ts +0 -142
  205. package/src/types/guillotine.ts +0 -428
  206. package/src/types/i18n.ts +0 -8
  207. package/src/types/index.ts +0 -62
  208. package/src/types/next.ts +0 -7
  209. package/src/types/util.ts +0 -5
  210. package/src/utils/addLineNumbers.ts +0 -3
  211. package/src/utils/buildGuillotineRequestHeaders.ts +0 -32
  212. package/src/utils/commonChars.ts +0 -16
  213. package/src/utils/enonicLog.ts +0 -28
  214. package/src/utils/fixDoubleSlashes.ts +0 -3
  215. package/src/utils/getAllLocales.ts +0 -6
  216. package/src/utils/getContentApiUrl.ts +0 -20
  217. package/src/utils/getLocaleMapping.ts +0 -24
  218. package/src/utils/getLocaleMappingByLocale.ts +0 -19
  219. package/src/utils/getLocaleMappingByProjectId.ts +0 -21
  220. package/src/utils/getLocaleMappings.ts +0 -36
  221. package/src/utils/getRenderMode.ts +0 -14
  222. package/src/utils/getRequestLocaleInfo.ts +0 -30
  223. package/src/utils/getXpBaseUrl.ts +0 -12
  224. package/src/utils/indent.ts +0 -4
  225. package/src/utils/sanitizeGraphqlName.ts +0 -11
  226. package/src/views/BaseComponent.tsx +0 -156
  227. package/src/views/BaseContent.tsx +0 -47
  228. package/src/views/BaseLayout.tsx +0 -33
  229. package/src/views/BaseMacro.tsx +0 -105
  230. package/src/views/BasePage.tsx +0 -42
  231. package/src/views/BasePart.tsx +0 -34
  232. package/src/views/Empty.tsx +0 -5
  233. package/src/views/Fragment.tsx +0 -41
  234. package/src/views/MainView.tsx +0 -22
  235. package/src/views/PropsView.tsx +0 -38
  236. package/src/views/Region.tsx +0 -76
  237. package/src/views/RichTextView.tsx +0 -63
  238. package/src/views/SingleComponent.tsx +0 -19
  239. package/src/views/StaticContent.tsx +0 -39
  240. package/src/views/Text.tsx +0 -19
  241. package/src/views/macros/DefaultMacro.tsx +0 -9
  242. package/src/views/macros/DisableMacro.tsx +0 -8
  243. package/types/componentProps.js.map +0 -1
  244. package/types/i18n.js.map +0 -1
  245. package/types/index.js.map +0 -1
  246. package/types/next.js.map +0 -1
  247. package/types/util.js.map +0 -1
  248. package/utils/addLineNumbers.js.map +0 -1
  249. package/utils/buildGuillotineRequestHeaders.js.map +0 -1
  250. package/utils/commonChars.js.map +0 -1
  251. package/utils/enonicLog.js.map +0 -1
  252. package/utils/fixDoubleSlashes.js.map +0 -1
  253. package/utils/getAllLocales.js.map +0 -1
  254. package/utils/getContentApiUrl.js.map +0 -1
  255. package/utils/getLocaleMapping.js.map +0 -1
  256. package/utils/getLocaleMappingByLocale.js.map +0 -1
  257. package/utils/getLocaleMappingByProjectId.js.map +0 -1
  258. package/utils/getLocaleMappings.js.map +0 -1
  259. package/utils/getRenderMode.js.map +0 -1
  260. package/utils/getRequestLocaleInfo.js.map +0 -1
  261. package/utils/getXpBaseUrl.js.map +0 -1
  262. package/utils/indent.js.map +0 -1
  263. package/utils/sanitizeGraphqlName.js.map +0 -1
  264. package/views/BaseComponent.jsx.map +0 -1
  265. package/views/BaseContent.jsx.map +0 -1
  266. package/views/BaseLayout.jsx.map +0 -1
  267. package/views/BaseMacro.jsx.map +0 -1
  268. package/views/BasePage.jsx.map +0 -1
  269. package/views/BasePart.jsx.map +0 -1
  270. package/views/Empty.jsx.map +0 -1
  271. package/views/Fragment.jsx.map +0 -1
  272. package/views/MainView.jsx.map +0 -1
  273. package/views/PropsView.jsx.map +0 -1
  274. package/views/Region.jsx.map +0 -1
  275. package/views/RichTextView.jsx +0 -39
  276. package/views/RichTextView.jsx.map +0 -1
  277. package/views/SingleComponent.jsx.map +0 -1
  278. package/views/StaticContent.jsx.map +0 -1
  279. package/views/Text.jsx.map +0 -1
  280. package/views/macros/DefaultMacro.jsx.map +0 -1
  281. package/views/macros/DisableMacro.jsx.map +0 -1
  282. /package/{baseMappings.d.ts → dist/baseMappings.d.ts} +0 -0
  283. /package/{client → dist/client}/getClientHydratedHtml.d.ts +0 -0
  284. /package/{client → dist/client}/getClientHydratedHtml.jsx +0 -0
  285. /package/{client.d.ts → dist/client.d.ts} +0 -0
  286. /package/{client.js → dist/client.js} +0 -0
  287. /package/{common → dist/common}/ComponentRegistry.d.ts +0 -0
  288. /package/{common → dist/common}/UrlProcessor.d.ts +0 -0
  289. /package/{common → dist/common}/UrlProcessor.js +0 -0
  290. /package/{common → dist/common}/constants.d.ts +0 -0
  291. /package/{common → dist/common}/constants.js +0 -0
  292. /package/{common → dist/common}/env.d.ts +0 -0
  293. /package/{guillotine → dist/guillotine}/applyProcessors.d.ts +0 -0
  294. /package/{guillotine → dist/guillotine}/applyProcessors.js +0 -0
  295. /package/{guillotine → dist/guillotine}/buildComponentTree.d.ts +0 -0
  296. /package/{guillotine → dist/guillotine}/buildComponentTree.js +0 -0
  297. /package/{guillotine → dist/guillotine}/buildErrorResponse.d.ts +0 -0
  298. /package/{guillotine → dist/guillotine}/buildPage.d.ts +0 -0
  299. /package/{guillotine → dist/guillotine}/combineMultipleQueries.d.ts +0 -0
  300. /package/{guillotine → dist/guillotine}/fetchContent.d.ts +0 -0
  301. /package/{guillotine → dist/guillotine}/fetchContentData.d.ts +0 -0
  302. /package/{guillotine → dist/guillotine}/fetchContentPathsForAllLocales.d.ts +0 -0
  303. /package/{guillotine → dist/guillotine}/fetchContentPathsForAllLocales.js +0 -0
  304. /package/{guillotine → dist/guillotine}/fetchContentPathsForLocale.d.ts +0 -0
  305. /package/{guillotine → dist/guillotine}/fetchFromApi.d.ts +0 -0
  306. /package/{guillotine → dist/guillotine}/fetchGuillotine.d.ts +0 -0
  307. /package/{guillotine → dist/guillotine}/fetchMetaData.d.ts +0 -0
  308. /package/{guillotine → dist/guillotine}/getCleanContentPathArrayOrThrow400.d.ts +0 -0
  309. /package/{guillotine → dist/guillotine}/getComponentConfig.d.ts +0 -0
  310. /package/{guillotine → dist/guillotine}/getComponentConfig.js +0 -0
  311. /package/{guillotine → dist/guillotine}/getContentAndComponentPaths.d.ts +0 -0
  312. /package/{guillotine → dist/guillotine}/getContentAndComponentPaths.js +0 -0
  313. /package/{guillotine → dist/guillotine}/getMetaData.d.ts +0 -0
  314. /package/{guillotine → dist/guillotine}/getMetaData.js +0 -0
  315. /package/{guillotine → dist/guillotine}/getParentRegion.d.ts +0 -0
  316. /package/{guillotine → dist/guillotine}/getQueryAndVariables.d.ts +0 -0
  317. /package/{guillotine → dist/guillotine}/metadata/configQuery.d.ts +0 -0
  318. /package/{guillotine → dist/guillotine}/metadata/configQuery.js +0 -0
  319. /package/{guillotine → dist/guillotine}/metadata/richTextQuery.d.ts +0 -0
  320. /package/{guillotine → dist/guillotine}/metadata/richTextQuery.js +0 -0
  321. /package/{guillotine → dist/guillotine}/parseComponentPath.d.ts +0 -0
  322. /package/{guillotine → dist/guillotine}/prefixFragmentCmpPath.d.ts +0 -0
  323. /package/{guillotine → dist/guillotine}/prefixFragmentCmpPath.js +0 -0
  324. /package/{guillotine → dist/guillotine}/processComponentConfig.d.ts +0 -0
  325. /package/{guillotine → dist/guillotine}/processComponentConfig.js +0 -0
  326. /package/{guillotine → dist/guillotine}/restrictComponentsToPath.d.ts +0 -0
  327. /package/{guillotine → dist/guillotine}/restrictComponentsToPath.js +0 -0
  328. /package/{guillotine → dist/guillotine}/validateData.d.ts +0 -0
  329. /package/{guillotine → dist/guillotine}/validateData.js +0 -0
  330. /package/{guillotine → dist/guillotine}/validateNotFound.d.ts +0 -0
  331. /package/{guillotine → dist/guillotine}/validateNotFound.js +0 -0
  332. /package/{guillotine → dist/guillotine}/validateShortcut.d.ts +0 -0
  333. /package/{guillotine → dist/guillotine}/validateShortcut.js +0 -0
  334. /package/{i18n → dist/i18n}/i18n.d.ts +0 -0
  335. /package/{i18n → dist/i18n}/i18n.js +0 -0
  336. /package/{query → dist/query}/Shortcut.d.ts +0 -0
  337. /package/{query → dist/query}/Shortcut.js +0 -0
  338. /package/{server → dist/server}/getServerRenderedHtml.d.ts +0 -0
  339. /package/{server → dist/server}/getServerRenderedHtml.js +0 -0
  340. /package/{server.d.ts → dist/server.d.ts} +0 -0
  341. /package/{server.js → dist/server.js} +0 -0
  342. /package/{types → dist/types}/component.d.ts +0 -0
  343. /package/{types → dist/types}/component.js +0 -0
  344. /package/{types → dist/types}/componentProps.js +0 -0
  345. /package/{types → dist/types}/guillotine.js +0 -0
  346. /package/{types → dist/types}/i18n.d.ts +0 -0
  347. /package/{types → dist/types}/i18n.js +0 -0
  348. /package/{types → dist/types}/index.d.ts +0 -0
  349. /package/{types → dist/types}/index.js +0 -0
  350. /package/{types → dist/types}/next.d.ts +0 -0
  351. /package/{types → dist/types}/next.js +0 -0
  352. /package/{types → dist/types}/util.d.ts +0 -0
  353. /package/{types → dist/types}/util.js +0 -0
  354. /package/{utils → dist/utils}/addLineNumbers.d.ts +0 -0
  355. /package/{utils → dist/utils}/addLineNumbers.js +0 -0
  356. /package/{utils → dist/utils}/commonChars.d.ts +0 -0
  357. /package/{utils → dist/utils}/commonChars.js +0 -0
  358. /package/{utils → dist/utils}/enonicLog.d.ts +0 -0
  359. /package/{utils → dist/utils}/enonicLog.js +0 -0
  360. /package/{utils → dist/utils}/fixDoubleSlashes.d.ts +0 -0
  361. /package/{utils → dist/utils}/fixDoubleSlashes.js +0 -0
  362. /package/{utils → dist/utils}/getAllLocales.d.ts +0 -0
  363. /package/{utils → dist/utils}/getAllLocales.js +0 -0
  364. /package/{utils → dist/utils}/getContentApiUrl.d.ts +0 -0
  365. /package/{utils → dist/utils}/getContentApiUrl.js +0 -0
  366. /package/{utils → dist/utils}/getLocaleMapping.d.ts +0 -0
  367. /package/{utils → dist/utils}/getLocaleMapping.js +0 -0
  368. /package/{utils → dist/utils}/getLocaleMappingByLocale.d.ts +0 -0
  369. /package/{utils → dist/utils}/getLocaleMappingByLocale.js +0 -0
  370. /package/{utils → dist/utils}/getLocaleMappingByProjectId.d.ts +0 -0
  371. /package/{utils → dist/utils}/getLocaleMappingByProjectId.js +0 -0
  372. /package/{utils → dist/utils}/getLocaleMappings.d.ts +0 -0
  373. /package/{utils → dist/utils}/getRenderMode.d.ts +0 -0
  374. /package/{utils → dist/utils}/getRequestLocaleInfo.d.ts +0 -0
  375. /package/{utils → dist/utils}/getRequestLocaleInfo.js +0 -0
  376. /package/{utils → dist/utils}/getXpBaseUrl.d.ts +0 -0
  377. /package/{utils → dist/utils}/getXpBaseUrl.js +0 -0
  378. /package/{utils → dist/utils}/indent.d.ts +0 -0
  379. /package/{utils → dist/utils}/indent.js +0 -0
  380. /package/{utils → dist/utils}/sanitizeGraphqlName.d.ts +0 -0
  381. /package/{utils → dist/utils}/sanitizeGraphqlName.js +0 -0
  382. /package/{views → dist/views}/BaseContent.d.ts +0 -0
  383. /package/{views → dist/views}/BaseLayout.d.ts +0 -0
  384. /package/{views → dist/views}/BaseLayout.jsx +0 -0
  385. /package/{views → dist/views}/BaseMacro.d.ts +0 -0
  386. /package/{views → dist/views}/BaseMacro.jsx +0 -0
  387. /package/{views → dist/views}/BasePage.d.ts +0 -0
  388. /package/{views → dist/views}/BasePage.jsx +0 -0
  389. /package/{views → dist/views}/BasePart.d.ts +0 -0
  390. /package/{views → dist/views}/BasePart.jsx +0 -0
  391. /package/{views → dist/views}/Empty.d.ts +0 -0
  392. /package/{views → dist/views}/Empty.jsx +0 -0
  393. /package/{views → dist/views}/Fragment.d.ts +0 -0
  394. /package/{views → dist/views}/Fragment.jsx +0 -0
  395. /package/{views → dist/views}/MainView.d.ts +0 -0
  396. /package/{views → dist/views}/MainView.jsx +0 -0
  397. /package/{views → dist/views}/PropsView.d.ts +0 -0
  398. /package/{views → dist/views}/Region.d.ts +0 -0
  399. /package/{views → dist/views}/Region.jsx +0 -0
  400. /package/{views → dist/views}/RichTextView.d.ts +0 -0
  401. /package/{views → dist/views}/SingleComponent.d.ts +0 -0
  402. /package/{views → dist/views}/SingleComponent.jsx +0 -0
  403. /package/{views → dist/views}/StaticContent.d.ts +0 -0
  404. /package/{views → dist/views}/StaticContent.jsx +0 -0
  405. /package/{views → dist/views}/Text.d.ts +0 -0
  406. /package/{views → dist/views}/Text.jsx +0 -0
  407. /package/{views → dist/views}/macros/DefaultMacro.d.ts +0 -0
  408. /package/{views → dist/views}/macros/DefaultMacro.jsx +0 -0
  409. /package/{views → dist/views}/macros/DisableMacro.d.ts +0 -0
  410. /package/{views → dist/views}/macros/DisableMacro.jsx +0 -0
@@ -1,75 +0,0 @@
1
- import type {
2
- ComponentDescriptor,
3
- QueryAndVariables,
4
- } from '../types';
5
-
6
-
7
- const ALIAS_PREFIX = 'request';
8
-
9
- const GRAPHQL_FRAGMENTS_REGEXP = /fragment\s+.+\s+on\s+.+\s*{[\s\w{}().,:"'`]+}/;
10
-
11
- const GUILLOTINE_QUERY_REGEXP = /^\s*query\s*(?:\((.*)*\))?\s*{\s*guillotine\s*{((?:.|\s)+)}\s*}\s*$/;
12
-
13
-
14
- export function combineMultipleQueries(queriesWithVars: ComponentDescriptor[]): QueryAndVariables {
15
- const queries: string[] = [];
16
- const fragments: string[] = [];
17
- const superVars: Record<string,any> = {};
18
- const superParams: string[] = [];
19
-
20
- queriesWithVars.forEach((componentDescriptor: ComponentDescriptor, index: number) => {
21
- const queryAndVars = componentDescriptor.queryAndVariables;
22
- if (!queryAndVars) {
23
- return;
24
- }
25
-
26
- // Extract fragments first if exist
27
- let q = queryAndVars.query;
28
- let match = q.match(GRAPHQL_FRAGMENTS_REGEXP);
29
- if (match?.length === 1) {
30
- // extract a fragment to put it at root level
31
- fragments.push(match[0]);
32
- // remove it from query because queries are going to get wrapped
33
- q = q.replace(match[0], '');
34
- }
35
-
36
- // Extract graphql query and its params and add prefixes to exclude collisions with other queries
37
- match = q.match(GUILLOTINE_QUERY_REGEXP) || ['']; // Fall back to empty string if no match
38
- const args = match[1];
39
- let query = match[2];
40
-
41
- if (args) {
42
- args.split(',').forEach(originalParamString => {
43
- const [originalKey, originalVal] = originalParamString.trim().split(':');
44
- const [prefixedKey, prefixedVal] = [`$${ALIAS_PREFIX}${index}_${originalKey.substr(1)}`, originalVal];
45
- superParams.push(`${prefixedKey}:${prefixedVal}`);
46
- // also update param references in query itself !
47
- // query = query.replaceAll(originalKey, prefixedKey);
48
- // replaceAll is not supported in older nodejs versions
49
- const origKeyPattern = new RegExp(originalKey.replace(/\$/g, '\\$'), 'g');
50
- query = query.replace(origKeyPattern, prefixedKey);
51
- });
52
- }
53
-
54
- if (query?.length) {
55
- queries.push(`${ALIAS_PREFIX}${index}:guillotine {${query}}`);
56
- }
57
-
58
- // Update variables with the same prefixes
59
- Object.entries(queryAndVars.variables || {}).forEach(entry => {
60
- superVars[`${ALIAS_PREFIX}${index}_${entry[0]}`] = entry[1];
61
- });
62
- });
63
-
64
- // Compose the super query
65
- const superQuery = `query ${superParams.length ? `(${superParams.join(', ')})` : ''} {
66
- ${queries.join('\n')}
67
- }
68
- ${fragments.join('\n')}
69
- `;
70
-
71
- return {
72
- query: superQuery,
73
- variables: superVars,
74
- };
75
- }
@@ -1,72 +0,0 @@
1
- import type {MetaData, PageComponent} from '../types';
2
-
3
-
4
- import {RENDER_MODE, XP_REQUEST_TYPE} from '../common/constants';
5
- import {ComponentRegistry} from '../common/ComponentRegistry';
6
-
7
-
8
- export function createMetaData({
9
- apiUrl,
10
- baseUrl,
11
- components = [], // Optional NOTE: Doesn't handle null
12
- contentPath,
13
- contentType,
14
- contentId,
15
- defaultLocale,
16
- locale,
17
- pageCmp, // Optional
18
- renderMode,
19
- requestedComponentPath,
20
- requestType,
21
- }: {
22
- apiUrl: string
23
- baseUrl: string
24
- components?: PageComponent[]
25
- contentPath: string
26
- contentId: string
27
- contentType: string
28
- defaultLocale: string
29
- locale: string
30
- pageCmp?: PageComponent
31
- renderMode: RENDER_MODE
32
- requestedComponentPath: string | undefined
33
- requestType: XP_REQUEST_TYPE
34
- }): MetaData {
35
- // .meta will be visible in final rendered inline props.
36
- // Only adding some .meta attributes here on certain conditions
37
- // (instead of always adding them and letting them be visible as false/undefined etc)
38
- const meta: MetaData = {
39
- apiUrl,
40
- baseUrl,
41
- canRender: false,
42
- catchAll: false, // catchAll only refers to content type catch-all
43
- defaultLocale,
44
- locale,
45
- id: contentId,
46
- path: contentPath,
47
- renderMode: renderMode,
48
- requestType: requestType,
49
- type: contentType,
50
- };
51
-
52
- if (requestedComponentPath) {
53
- meta.requestedComponent = components.find(cmp => cmp.path === requestedComponentPath);
54
- }
55
-
56
- const pageDesc = pageCmp?.page?.descriptor;
57
- const typeDef = ComponentRegistry.getContentType(contentType);
58
- if (typeDef?.view && !typeDef.catchAll) {
59
- meta.canRender = true;
60
- } else if (requestType === XP_REQUEST_TYPE.COMPONENT) {
61
- // always render a single component (show missing if not implemented)
62
- meta.canRender = true;
63
- } else if (pageDesc) {
64
- // always render a page if there is a descriptor (show missing if not implemented)
65
- meta.canRender = true;
66
- } else if (typeDef?.view) {
67
- meta.canRender = true;
68
- meta.catchAll = true;
69
- }
70
-
71
- return meta;
72
- }
@@ -1,246 +0,0 @@
1
- import type {ComponentDescriptor, Context, FetchContentResult} from '../types';
2
-
3
- import {draftMode, headers} from 'next/headers';
4
- import {ComponentRegistry} from '../common/ComponentRegistry';
5
- import {
6
- PAGE_TEMPLATE_CONTENTTYPE_NAME,
7
- PAGE_TEMPLATE_FOLDER,
8
- RENDER_MODE,
9
- XP_COMPONENT_TYPE,
10
- XP_REQUEST_TYPE,
11
- } from '../common/constants';
12
- import {APP_NAME, APP_NAME_DASHED, IS_DEV_MODE} from '../common/env';
13
- import {getContentApiUrl} from '../utils/getContentApiUrl';
14
- import {getLocaleMapping} from '../utils/getLocaleMapping';
15
- import {getRenderMode} from '../utils/getRenderMode';
16
- import {getXpBaseUrl} from '../utils/getXpBaseUrl';
17
- import {getRequestLocaleInfo} from '../utils/getRequestLocaleInfo';
18
- import {buildGuillotineRequestHeaders} from '../utils/buildGuillotineRequestHeaders';
19
-
20
- import {buildPage} from './buildPage';
21
- import {fetchMetaData} from './fetchMetaData';
22
- import {getCleanContentPathArrayOrThrow400} from './getCleanContentPathArrayOrThrow400';
23
- import {buildErrorResponse} from './buildErrorResponse';
24
- import {getContentAndComponentPaths} from './getContentAndComponentPaths';
25
- import {restrictComponentsToPath} from './restrictComponentsToPath';
26
- import {processComponentConfig} from './processComponentConfig';
27
- import {getQueryAndVariables} from './getQueryAndVariables';
28
- import {collectComponentDescriptors} from './collectComponentDescriptors';
29
- import {combineMultipleQueries} from './combineMultipleQueries';
30
- import {fetchContentData} from './fetchContentData';
31
- import {applyProcessors} from './applyProcessors';
32
- import {createMetaData} from './createMetaData';
33
-
34
-
35
- /**
36
- * Default fetchContent function, built with params from imports.
37
- * It runs custom content-type-specific guillotine calls against an XP guillotine endpoint, returns content data, error and some meta data
38
- * Sends one query to the guillotine API and asks for content type, then uses the type to select a second query and variables, which is sent to the API and fetches content data.
39
- * @param context object from Next, contains .query info
40
- * @returns FetchContentResult object: {data?: T, error?: {code, message}}
41
- */
42
- export async function fetchContent(context: Context): Promise<FetchContentResult> {
43
- const {locale, locales, defaultLocale} = getRequestLocaleInfo(context);
44
- const {isEnabled} = await draftMode();
45
-
46
- // we only want to read headers in draft mode, because they bail out static generation
47
- if (isEnabled) {
48
- const allHeaders = await headers();
49
-
50
- if (!context.headers) {
51
- context.headers = new Headers();
52
- }
53
- allHeaders.forEach((value, key) => {
54
- context.headers.set(key, value);
55
- });
56
- }
57
-
58
- const outHeaders = buildGuillotineRequestHeaders({
59
- context,
60
- defaultLocale,
61
- locale,
62
- locales,
63
- });
64
- const xpBaseUrl = getXpBaseUrl(context);
65
- const contentApiUrl = getContentApiUrl(context);
66
- const mapping = getLocaleMapping(context);
67
- const renderMode = getRenderMode(context);
68
- let requestType = XP_REQUEST_TYPE.TYPE;
69
- const requestContentPath = getCleanContentPathArrayOrThrow400(context.contentPath);
70
-
71
- try {
72
- const [siteRelativeContentPath, componentPath] = getContentAndComponentPaths(requestContentPath);
73
- if (componentPath) {
74
- // set component request type because url contains component path
75
- requestType = XP_REQUEST_TYPE.COMPONENT;
76
- }
77
-
78
- // ///////////// FIRST GUILLOTINE CALL FOR METADATA /////////////////
79
- const metaResult = await fetchMetaData(contentApiUrl, '${site}/' + siteRelativeContentPath, mapping, outHeaders);
80
- // ///////////////////////////////////////////////////////////////////////
81
-
82
- const {_id, _path, type} = metaResult.meta || {};
83
- const contentPath = _path || siteRelativeContentPath;
84
-
85
- const errorResponse = buildErrorResponse(requestType, renderMode, contentApiUrl, xpBaseUrl, locale, defaultLocale, requestContentPath, _id);
86
-
87
- if (metaResult.error) {
88
- console.error(metaResult.error);
89
- return errorResponse(metaResult.error.code, metaResult.error.message);
90
- }
91
-
92
- if (!metaResult.meta) {
93
- return errorResponse('404', 'No meta data found for content, most likely content does not exist');
94
- } else if (!type) {
95
- return errorResponse('500', "Server responded with incomplete meta data: missing content 'type' attribute.");
96
-
97
- } else if (
98
- renderMode === RENDER_MODE.NEXT
99
- && !IS_DEV_MODE
100
- && (
101
- type === PAGE_TEMPLATE_CONTENTTYPE_NAME ||
102
- type === PAGE_TEMPLATE_FOLDER
103
- )) {
104
- return errorResponse('404', `Content type [${type}] is not accessible in ${renderMode} mode`);
105
- }
106
-
107
- const components = restrictComponentsToPath(type, metaResult.meta.components, componentPath);
108
- if (componentPath && !components.length) {
109
- // component was not found
110
- return errorResponse('404', `Component ${componentPath} was not found`);
111
- }
112
-
113
- if (requestType !== XP_REQUEST_TYPE.COMPONENT && components.length > 0) {
114
- requestType = XP_REQUEST_TYPE.PAGE;
115
- }
116
-
117
- // ////////////////////////////////////////////////// Content type established. Proceed to data call:
118
-
119
- const allDescriptors: ComponentDescriptor[] = [];
120
-
121
- // Add the content type query at all cases
122
- const contentTypeDef = ComponentRegistry.getContentType(type);
123
- const pageCmp = (components || []).find(cmp => cmp.type === XP_COMPONENT_TYPE.PAGE);
124
- if (pageCmp) {
125
- processComponentConfig(APP_NAME, APP_NAME_DASHED, pageCmp);
126
- }
127
-
128
- const contentQueryAndVars = getQueryAndVariables(type, contentPath, context, contentTypeDef?.query, pageCmp?.page?.config);
129
- if (contentQueryAndVars) {
130
- allDescriptors.push({
131
- type: contentTypeDef,
132
- queryAndVariables: contentQueryAndVars,
133
- });
134
- }
135
-
136
- const commonQueryAndVars = getQueryAndVariables(type, contentPath, context, ComponentRegistry.getCommonQuery(),
137
- pageCmp?.page?.config);
138
- if (commonQueryAndVars) {
139
- allDescriptors.push({
140
- type: contentTypeDef,
141
- queryAndVariables: commonQueryAndVars,
142
- });
143
- }
144
-
145
- if (components?.length && ComponentRegistry) {
146
- for (const cmp of (components || [])) {
147
- processComponentConfig(APP_NAME, APP_NAME_DASHED, cmp);
148
- }
149
- // Collect component queries if defined
150
- const componentDescriptors = collectComponentDescriptors({
151
- components,
152
- xpContentPath: contentPath,
153
- context,
154
- });
155
- if (componentDescriptors.length) {
156
- allDescriptors.push(...componentDescriptors);
157
- }
158
- }
159
-
160
- const {query, variables} = combineMultipleQueries(allDescriptors);
161
- if (!query.trim()) {
162
- return errorResponse('400', `Missing or empty query override for content type ${type}`);
163
- }
164
-
165
- // /////////////// SECOND GUILLOTINE CALL FOR DATA //////////////////////
166
- const contentResults = await fetchContentData(contentApiUrl, contentPath, mapping, query, variables, outHeaders);
167
- // ///////////////////////////////////////////////////////////////////////////
168
-
169
- if (contentResults.error) {
170
- console.error(contentResults.error);
171
- return errorResponse(contentResults.error.code, contentResults.error.message);
172
- }
173
-
174
- // Apply processors to every component
175
- const datas = await applyProcessors(allDescriptors, contentResults, context);
176
-
177
- // Unwind the data back to components
178
-
179
- let contentData = null, common = null;
180
- let startFrom = 0;
181
- if (contentQueryAndVars) {
182
- const item = datas[startFrom];
183
- contentData = item.status === 'fulfilled' ? item.value : item.reason;
184
- startFrom++;
185
- }
186
- if (commonQueryAndVars) {
187
- const item = datas[startFrom];
188
- common = item.status === 'fulfilled' ? item.value : item.reason;
189
- startFrom++;
190
- }
191
-
192
- for (let i = startFrom; i < datas.length; i++) {
193
- // component descriptors hold references to components
194
- // that will later be used for creating page regions
195
- const datum = datas[i];
196
- if (datum.status === 'rejected') {
197
- let reason = datum.reason;
198
- if (reason instanceof Error) {
199
- reason = reason.message;
200
- } else if (typeof reason !== 'string') {
201
- reason = String(reason);
202
- }
203
- allDescriptors[i].component.error = reason;
204
- } else {
205
- allDescriptors[i].component.data = datum.value;
206
- }
207
- }
208
-
209
- const page = buildPage(type, components);
210
- const meta = createMetaData({
211
- apiUrl: contentApiUrl,
212
- baseUrl: xpBaseUrl,
213
- components,
214
- contentPath: siteRelativeContentPath,
215
- contentType: type,
216
- contentId: _id,
217
- defaultLocale,
218
- locale,
219
- pageCmp: page,
220
- renderMode,
221
- requestedComponentPath: componentPath,
222
- requestType,
223
- });
224
-
225
- return {
226
- data: contentData,
227
- common,
228
- meta,
229
- page,
230
- };
231
- } catch (e: any) {
232
- console.error(e);
233
-
234
- let error;
235
- try {
236
- error = JSON.parse(e.message);
237
- } catch (e2) {
238
- error = {
239
- code: 'Local',
240
- message: e.message,
241
- };
242
- }
243
- const errorResponse = buildErrorResponse(requestType, renderMode, contentApiUrl, xpBaseUrl, locale, defaultLocale, requestContentPath);
244
- return errorResponse(error.code, error.message);
245
- }
246
- }
@@ -1,37 +0,0 @@
1
- import type {
2
- ContentApiBaseBody,
3
- ContentApiBaseBodyVariables,
4
- ContentResult,
5
- LocaleMapping,
6
- GuillotineRequestHeaders,
7
- } from '../types';
8
-
9
- import {fetchGuillotine} from './fetchGuillotine';
10
-
11
-
12
- export const fetchContentData = async <Content = Record<string, unknown>>(
13
- contentApiUrl: string,
14
- xpContentPath: string,
15
- mapping: LocaleMapping,
16
- query: string,
17
- variables?: ContentApiBaseBodyVariables,
18
- headers?: GuillotineRequestHeaders,
19
- ): Promise<ContentResult> => {
20
- const body: ContentApiBaseBody = {query};
21
- if (variables && Object.keys(variables).length > 0) {
22
- body.variables = variables;
23
- }
24
- const contentResults = await fetchGuillotine<ContentResult<Content>>(contentApiUrl, mapping, {
25
- body,
26
- headers,
27
- });
28
-
29
- if (contentResults.error) {
30
- return contentResults;
31
- } else {
32
- return {
33
- // omit the aliases and return values
34
- contents: Object.values(contentResults),
35
- };
36
- }
37
- };
@@ -1,21 +0,0 @@
1
- import type {ContentPathItem} from '../types';
2
-
3
- import {GET_STATIC_PATHS_QUERY} from '../common/constants';
4
- import {getLocaleMappings} from '../utils/getLocaleMappings';
5
- import {fetchContentPathsForLocale} from './fetchContentPathsForLocale';
6
-
7
-
8
- export async function fetchContentPathsForAllLocales(
9
- path: string,
10
- query: string = GET_STATIC_PATHS_QUERY,
11
- countPerLocale = 999,
12
- ): Promise<ContentPathItem[]> {
13
- const promises = Object.values(getLocaleMappings()).map(
14
- config => fetchContentPathsForLocale(
15
- path, config, query, countPerLocale,
16
- ),
17
- );
18
- return Promise.all(promises).then(results => {
19
- return results.reduce((all, localePaths) => all.concat(localePaths), []);
20
- });
21
- }
@@ -1,43 +0,0 @@
1
- import type {ContentApiBaseBody, ContentPathItem, GuillotineResult, LocaleMapping} from '../types';
2
-
3
-
4
- import {GET_STATIC_PATHS_QUERY} from '../common/constants';
5
- import {getContentApiUrl} from '../utils/getContentApiUrl';
6
- import {fetchGuillotine} from './fetchGuillotine';
7
-
8
-
9
- export async function fetchContentPathsForLocale(
10
- path: string,
11
- config: LocaleMapping,
12
- query: string = GET_STATIC_PATHS_QUERY,
13
- count = 999,
14
- ): Promise<ContentPathItem[]> {
15
- const contentApiUrl = getContentApiUrl({
16
- contentPath: path,
17
- locale: config.locale,
18
- });
19
- const body: ContentApiBaseBody = {
20
- query,
21
- variables: {
22
- path,
23
- pathRegex: `/content${config.site}/*`,
24
- count,
25
- },
26
- };
27
- return fetchGuillotine<ContentPathItem[]>(contentApiUrl, config, {body}).then((
28
- results: GuillotineResult,
29
- ) => {
30
- return results.guillotine.queryDsl.reduce((
31
- prev: ContentPathItem[],
32
- child: any,
33
- ) => {
34
- const regexp = new RegExp(`^/${child.site?._name ? `${child.site._name}/?` : ''}`);
35
- const contentPath = child._path.replace(regexp, '');
36
- prev.push({
37
- contentPath: contentPath.split('/'),
38
- locale: config.locale,
39
- });
40
- return prev;
41
- }, []);
42
- });
43
- }
@@ -1,76 +0,0 @@
1
- import type {FetchOptions, GuillotineResponse, GuillotineResponseJson, LocaleMapping} from '../types';
2
-
3
- /** Generic fetch */
4
- export async function fetchFromApi<Data = Record<string, unknown>>(
5
- apiUrl: string,
6
- mapping: LocaleMapping,
7
- options?: FetchOptions,
8
- ): Promise<GuillotineResponseJson> {
9
-
10
- const opts = {
11
- method: options?.method || 'POST',
12
- body: options?.body ? JSON.stringify(options?.body) : null,
13
- headers: mergeHeaders(mapping, options?.headers),
14
- next: options?.next,
15
- cache: options?.cache,
16
- };
17
-
18
- let res: GuillotineResponse<Data>;
19
- try {
20
- res = await fetch(apiUrl, opts as RequestInit);
21
- } catch (e: any) {
22
- console.warn(apiUrl, e);
23
- throw new Error(JSON.stringify({
24
- code: 'API',
25
- message: e.message,
26
- }));
27
- }
28
-
29
- if (!res.ok) {
30
- throw new Error(JSON.stringify({
31
- code: res.status,
32
- message: `Data fetching failed (message: '${await res.text()}')`,
33
- }));
34
- }
35
-
36
- let json: GuillotineResponseJson<Data>;
37
- try {
38
- json = await res.json();
39
- } catch (e) {
40
- throw new Error(JSON.stringify({
41
- code: 500,
42
- message: `API call completed but with non-JSON data: ${JSON.stringify(await res.text())}`,
43
- }));
44
- }
45
-
46
- if (!json) {
47
- throw new Error(JSON.stringify({
48
- code: 500,
49
- message: `API call completed but with unexpectedly empty data: ${JSON.stringify(await res.text())}`,
50
- }));
51
- }
52
-
53
- if (Array.isArray(json)) {
54
- throw new Error(JSON.stringify({
55
- code: 500,
56
- message: `API call completed but with unexpected array data: ${JSON.stringify(json)}`,
57
- }));
58
- }
59
-
60
- return json;
61
- }
62
-
63
- function mergeHeaders(mapping: LocaleMapping, headers?: HeadersInit): Headers {
64
- const newHeaders = new Headers({
65
- 'Accept': 'application/json',
66
- 'Content-Type': 'application/json',
67
- });
68
- if (headers) {
69
- Object.keys(headers).forEach((headersKey) => {
70
- newHeaders.set(headersKey, headers[headersKey]);
71
- });
72
- }
73
- // append last to make sure it is not overwritten
74
- newHeaders.set('X-Guillotine-SiteKey', mapping.site);
75
- return newHeaders;
76
- }
@@ -1,76 +0,0 @@
1
- import type {FetchOptions, GuillotineResult, LocaleMapping} from '../types';
2
- import gqlmin from 'gqlmin';
3
-
4
- import {fetchFromApi} from './fetchFromApi';
5
-
6
- const XP_ERROR_PATTERN = '/_/error/';
7
-
8
- /** Guillotine-specialized fetch, using the generic fetch above */
9
- export async function fetchGuillotine<Data = Record<string, unknown>>(
10
- contentApiUrl: string,
11
- mapping: LocaleMapping,
12
- options?: FetchOptions,
13
- ): Promise<GuillotineResult> {
14
- const body = options?.body;
15
- const path = body?.variables?.path;
16
-
17
- if (typeof body.query !== 'string' || !body.query.trim()) {
18
- return {
19
- error: {
20
- code: '400',
21
- message: `Invalid or missing query. JSON.stringify(query) = ${JSON.stringify(body.query)}`,
22
- },
23
- };
24
- } else {
25
- // special case for not sending XP generated error paths to guillotine
26
- const pathArr = path?.split(XP_ERROR_PATTERN);
27
- if (pathArr?.length === 2) {
28
- return {
29
- error: {
30
- code: pathArr[1],
31
- message: `XP error URL detected`,
32
- },
33
- }
34
- } else {
35
- // Minify the query to avoid hitting 200k space limit
36
- body.query = gqlmin(body.query);
37
- }
38
- }
39
-
40
- const pathMessage = path ? JSON.stringify(path) : '';
41
- return await fetchFromApi<Data>(
42
- contentApiUrl,
43
- mapping,
44
- options,
45
- )
46
- .then(json => {
47
- let errors: any[] = json.errors; // fetchFromApi ensures json is an object
48
-
49
- if (errors) {
50
- if (!Array.isArray(errors)) {
51
- errors = [errors];
52
- }
53
- console.error(`${errors.length} error(s) when fetching data from: ${contentApiUrl}`);
54
- errors.forEach(error => {
55
- console.error(error);
56
- });
57
-
58
- return {
59
- error: {
60
- code: '500',
61
- message: `Server responded with ${errors.length} error(s), probably from guillotine - see log.`,
62
- },
63
- };
64
- }
65
-
66
- return json.data;
67
- })
68
- .catch((err) => {
69
- console.warn(`Client-side error when trying to fetch data ${pathMessage}`, err);
70
- try {
71
- return {error: JSON.parse(err.message)};
72
- } catch (e2) {
73
- return {error: {code: 'Client-side error', message: err.message}};
74
- }
75
- });
76
- }
@@ -1,31 +0,0 @@
1
- import type {ContentApiBaseBody, MetaResult, LocaleMapping, GuillotineRequestHeaders} from '../types';
2
-
3
-
4
- import {getMetaQuery, pageFragmentQuery} from './getMetaData';
5
- import {fetchGuillotine} from './fetchGuillotine';
6
-
7
-
8
- export const fetchMetaData = async (
9
- contentApiUrl: string,
10
- xpContentPath: string,
11
- mapping: LocaleMapping,
12
- headers?: GuillotineRequestHeaders,
13
- ): Promise<MetaResult> => {
14
- const body: ContentApiBaseBody = {
15
- query: getMetaQuery(pageFragmentQuery()),
16
- variables: {
17
- path: xpContentPath,
18
- },
19
- };
20
- const metaResult = await fetchGuillotine<MetaResult>(contentApiUrl, mapping, {
21
- body,
22
- headers,
23
- });
24
- if (metaResult.error) {
25
- return metaResult;
26
- } else {
27
- return {
28
- meta: metaResult?.guillotine?.get,
29
- };
30
- }
31
- };