@enonic/nextjs-adapter 3.3.0-B1 → 3.3.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 (296) hide show
  1. package/dist/baseMappings.d.ts +1 -0
  2. package/{src/baseMappings.ts → dist/baseMappings.js} +4 -14
  3. package/dist/baseMappings.js.map +1 -0
  4. package/dist/client/getClientHydratedHtml.d.ts +1 -0
  5. package/{src/client/getClientHydratedHtml.tsx → dist/client/getClientHydratedHtml.jsx} +3 -6
  6. package/dist/client/getClientHydratedHtml.jsx.map +1 -0
  7. package/dist/client.d.ts +1 -0
  8. package/dist/client.js +3 -0
  9. package/dist/client.js.map +1 -0
  10. package/dist/common/ComponentRegistry.d.ts +34 -0
  11. package/dist/common/ComponentRegistry.js +121 -0
  12. package/dist/common/ComponentRegistry.js.map +1 -0
  13. package/dist/common/UrlProcessor.d.ts +25 -0
  14. package/{src/common/UrlProcessor.ts → dist/common/UrlProcessor.js} +49 -70
  15. package/dist/common/UrlProcessor.js.map +1 -0
  16. package/dist/common/constants.d.ts +51 -0
  17. package/{src/common/constants.ts → dist/common/constants.js} +38 -44
  18. package/dist/common/constants.js.map +1 -0
  19. package/dist/common/env.d.ts +12 -0
  20. package/{src/common/env.ts → dist/common/env.js} +3 -14
  21. package/dist/common/env.js.map +1 -0
  22. package/dist/guillotine/applyProcessors.d.ts +2 -0
  23. package/dist/guillotine/applyProcessors.js +33 -0
  24. package/dist/guillotine/applyProcessors.js.map +1 -0
  25. package/dist/guillotine/buildComponentTree.d.ts +2 -0
  26. package/{src/guillotine/buildComponentTree.ts → dist/guillotine/buildComponentTree.js} +13 -25
  27. package/dist/guillotine/buildComponentTree.js.map +1 -0
  28. package/dist/guillotine/buildErrorResponse.d.ts +3 -0
  29. package/{src/guillotine/buildErrorResponse.ts → dist/guillotine/buildErrorResponse.js} +2 -10
  30. package/dist/guillotine/buildErrorResponse.js.map +1 -0
  31. package/dist/guillotine/buildPage.d.ts +2 -0
  32. package/dist/guillotine/buildPage.js +10 -0
  33. package/dist/guillotine/buildPage.js.map +1 -0
  34. package/dist/guillotine/collectComponentDescriptors.d.ts +6 -0
  35. package/{src/guillotine/collectComponentDescriptors.ts → dist/guillotine/collectComponentDescriptors.js} +13 -26
  36. package/dist/guillotine/collectComponentDescriptors.js.map +1 -0
  37. package/dist/guillotine/combineMultipleQueries.d.ts +2 -0
  38. package/{src/guillotine/combineMultipleQueries.ts → dist/guillotine/combineMultipleQueries.js} +9 -23
  39. package/dist/guillotine/combineMultipleQueries.js.map +1 -0
  40. package/dist/guillotine/createMetaData.d.ts +18 -0
  41. package/dist/guillotine/createMetaData.js +45 -0
  42. package/dist/guillotine/createMetaData.js.map +1 -0
  43. package/dist/guillotine/fetchContent.d.ts +9 -0
  44. package/dist/guillotine/fetchContent.js +222 -0
  45. package/dist/guillotine/fetchContent.js.map +1 -0
  46. package/dist/guillotine/fetchContentData.d.ts +2 -0
  47. package/dist/guillotine/fetchContentData.js +30 -0
  48. package/dist/guillotine/fetchContentData.js.map +1 -0
  49. package/dist/guillotine/fetchContentPathsForAllLocales.d.ts +2 -0
  50. package/dist/guillotine/fetchContentPathsForAllLocales.js +21 -0
  51. package/dist/guillotine/fetchContentPathsForAllLocales.js.map +1 -0
  52. package/dist/guillotine/fetchContentPathsForLocale.d.ts +2 -0
  53. package/dist/guillotine/fetchContentPathsForLocale.js +42 -0
  54. package/dist/guillotine/fetchContentPathsForLocale.js.map +1 -0
  55. package/dist/guillotine/fetchFromApi.d.ts +3 -0
  56. package/dist/guillotine/fetchFromApi.js +76 -0
  57. package/dist/guillotine/fetchFromApi.js.map +1 -0
  58. package/dist/guillotine/fetchGuillotine.d.ts +3 -0
  59. package/dist/guillotine/fetchGuillotine.js +75 -0
  60. package/dist/guillotine/fetchGuillotine.js.map +1 -0
  61. package/dist/guillotine/fetchMetaData.d.ts +2 -0
  62. package/dist/guillotine/fetchMetaData.js +33 -0
  63. package/dist/guillotine/fetchMetaData.js.map +1 -0
  64. package/dist/guillotine/getCleanContentPathArrayOrThrow400.d.ts +2 -0
  65. package/{src/guillotine/getCleanContentPathArrayOrThrow400.ts → dist/guillotine/getCleanContentPathArrayOrThrow400.js} +7 -9
  66. package/dist/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -0
  67. package/dist/guillotine/getComponentConfig.d.ts +2 -0
  68. package/{src/guillotine/getComponentConfig.ts → dist/guillotine/getComponentConfig.js} +3 -5
  69. package/dist/guillotine/getComponentConfig.js.map +1 -0
  70. package/dist/guillotine/getContentAndComponentPaths.d.ts +1 -0
  71. package/{src/guillotine/getContentAndComponentPaths.ts → dist/guillotine/getContentAndComponentPaths.js} +6 -5
  72. package/dist/guillotine/getContentAndComponentPaths.js.map +1 -0
  73. package/dist/guillotine/getMetaData.d.ts +2 -0
  74. package/{src/guillotine/getMetaData.ts → dist/guillotine/getMetaData.js} +11 -18
  75. package/dist/guillotine/getMetaData.js.map +1 -0
  76. package/dist/guillotine/getParentRegion.d.ts +2 -0
  77. package/{src/guillotine/getParentRegion.ts → dist/guillotine/getParentRegion.js} +9 -23
  78. package/dist/guillotine/getParentRegion.js.map +1 -0
  79. package/dist/guillotine/getQueryAndVariables.d.ts +2 -0
  80. package/{src/guillotine/getQueryAndVariables.ts → dist/guillotine/getQueryAndVariables.js} +7 -23
  81. package/dist/guillotine/getQueryAndVariables.js.map +1 -0
  82. package/dist/guillotine/metadata/configQuery.d.ts +2 -0
  83. package/dist/guillotine/metadata/configQuery.js +36 -0
  84. package/dist/guillotine/metadata/configQuery.js.map +1 -0
  85. package/dist/guillotine/metadata/richTextQuery.d.ts +1 -0
  86. package/{src/guillotine/metadata/richTextQuery.ts → dist/guillotine/metadata/richTextQuery.js} +6 -8
  87. package/dist/guillotine/metadata/richTextQuery.js.map +1 -0
  88. package/dist/guillotine/parseComponentPath.d.ts +2 -0
  89. package/{src/guillotine/parseComponentPath.ts → dist/guillotine/parseComponentPath.js} +4 -8
  90. package/dist/guillotine/parseComponentPath.js.map +1 -0
  91. package/dist/guillotine/prefixFragmentCmpPath.d.ts +1 -0
  92. package/{src/guillotine/prefixFragmentCmpPath.ts → dist/guillotine/prefixFragmentCmpPath.js} +5 -5
  93. package/dist/guillotine/prefixFragmentCmpPath.js.map +1 -0
  94. package/dist/guillotine/processComponentConfig.d.ts +2 -0
  95. package/{src/guillotine/processComponentConfig.ts → dist/guillotine/processComponentConfig.js} +4 -12
  96. package/dist/guillotine/processComponentConfig.js.map +1 -0
  97. package/dist/guillotine/restrictComponentsToPath.d.ts +2 -0
  98. package/{src/guillotine/restrictComponentsToPath.ts → dist/guillotine/restrictComponentsToPath.js} +9 -19
  99. package/dist/guillotine/restrictComponentsToPath.js.map +1 -0
  100. package/dist/guillotine/validateData.d.ts +2 -0
  101. package/dist/guillotine/validateData.js +7 -0
  102. package/dist/guillotine/validateData.js.map +1 -0
  103. package/dist/guillotine/validateNotFound.d.ts +2 -0
  104. package/{src/guillotine/validateNotFound.ts → dist/guillotine/validateNotFound.js} +5 -9
  105. package/dist/guillotine/validateNotFound.js.map +1 -0
  106. package/dist/guillotine/validateShortcut.d.ts +2 -0
  107. package/{src/guillotine/validateShortcut.ts → dist/guillotine/validateShortcut.js} +12 -20
  108. package/dist/guillotine/validateShortcut.js.map +1 -0
  109. package/dist/i18n/LocaleContext.d.ts +7 -0
  110. package/dist/i18n/LocaleContext.jsx +50 -0
  111. package/dist/i18n/LocaleContext.jsx.map +1 -0
  112. package/dist/i18n/i18n.d.ts +12 -0
  113. package/dist/i18n/i18n.js +59 -0
  114. package/dist/i18n/i18n.js.map +1 -0
  115. package/dist/index.d.ts +14 -0
  116. package/dist/index.js +14 -0
  117. package/dist/index.js.map +1 -0
  118. package/dist/query/Shortcut.d.ts +1 -0
  119. package/{src/query/Shortcut.ts → dist/query/Shortcut.js} +1 -0
  120. package/dist/query/Shortcut.js.map +1 -0
  121. package/dist/server/getServerRenderedHtml.d.ts +1 -0
  122. package/dist/server/getServerRenderedHtml.js +4 -0
  123. package/dist/server/getServerRenderedHtml.js.map +1 -0
  124. package/dist/server.d.ts +5 -0
  125. package/dist/server.js +6 -0
  126. package/dist/server.js.map +1 -0
  127. package/{src/types/component.ts → dist/types/component.d.ts} +23 -62
  128. package/dist/types/component.js +2 -0
  129. package/dist/types/component.js.map +1 -0
  130. package/dist/types/componentProps.d.ts +107 -0
  131. package/dist/types/componentProps.js +2 -0
  132. package/dist/types/componentProps.js.map +1 -0
  133. package/dist/types/guillotine.d.ts +344 -0
  134. package/dist/types/guillotine.js +2 -0
  135. package/dist/types/guillotine.js.map +1 -0
  136. package/dist/types/i18n.d.ts +7 -0
  137. package/dist/types/i18n.js +2 -0
  138. package/dist/types/i18n.js.map +1 -0
  139. package/{src/types/index.ts → dist/types/index.d.ts} +19 -34
  140. package/dist/types/index.js +3 -0
  141. package/dist/types/index.js.map +1 -0
  142. package/dist/types/next.d.ts +6 -0
  143. package/dist/types/next.js +2 -0
  144. package/dist/types/next.js.map +1 -0
  145. package/dist/types/util.d.ts +3 -0
  146. package/dist/types/util.js +3 -0
  147. package/dist/types/util.js.map +1 -0
  148. package/dist/utils/addLineNumbers.d.ts +1 -0
  149. package/dist/utils/addLineNumbers.js +4 -0
  150. package/dist/utils/addLineNumbers.js.map +1 -0
  151. package/dist/utils/buildGuillotineRequestHeaders.d.ts +7 -0
  152. package/dist/utils/buildGuillotineRequestHeaders.js +16 -0
  153. package/dist/utils/buildGuillotineRequestHeaders.js.map +1 -0
  154. package/dist/utils/commonChars.d.ts +1 -0
  155. package/{src/utils/commonChars.ts → dist/utils/commonChars.js} +5 -4
  156. package/dist/utils/commonChars.js.map +1 -0
  157. package/dist/utils/enonicLog.d.ts +5 -0
  158. package/dist/utils/enonicLog.js +23 -0
  159. package/dist/utils/enonicLog.js.map +1 -0
  160. package/dist/utils/fixDoubleSlashes.d.ts +1 -0
  161. package/dist/utils/fixDoubleSlashes.js +4 -0
  162. package/dist/utils/fixDoubleSlashes.js.map +1 -0
  163. package/dist/utils/getAllLocales.d.ts +1 -0
  164. package/dist/utils/getAllLocales.js +5 -0
  165. package/dist/utils/getAllLocales.js.map +1 -0
  166. package/dist/utils/getContentApiUrl.d.ts +2 -0
  167. package/dist/utils/getContentApiUrl.js +15 -0
  168. package/dist/utils/getContentApiUrl.js.map +1 -0
  169. package/dist/utils/getLocaleMapping.d.ts +2 -0
  170. package/dist/utils/getLocaleMapping.js +19 -0
  171. package/dist/utils/getLocaleMapping.js.map +1 -0
  172. package/dist/utils/getLocaleMappingByLocale.d.ts +2 -0
  173. package/dist/utils/getLocaleMappingByLocale.js +13 -0
  174. package/dist/utils/getLocaleMappingByLocale.js.map +1 -0
  175. package/dist/utils/getLocaleMappingByProjectId.d.ts +2 -0
  176. package/dist/utils/getLocaleMappingByProjectId.js +16 -0
  177. package/dist/utils/getLocaleMappingByProjectId.js.map +1 -0
  178. package/dist/utils/getLocaleMappings.d.ts +2 -0
  179. package/{src/utils/getLocaleMappings.ts → dist/utils/getLocaleMappings.js} +8 -14
  180. package/dist/utils/getLocaleMappings.js.map +1 -0
  181. package/dist/utils/getRenderMode.d.ts +3 -0
  182. package/dist/utils/getRenderMode.js +8 -0
  183. package/dist/utils/getRenderMode.js.map +1 -0
  184. package/dist/utils/getRequestLocaleInfo.d.ts +6 -0
  185. package/{src/utils/getRequestLocaleInfo.ts → dist/utils/getRequestLocaleInfo.js} +12 -13
  186. package/dist/utils/getRequestLocaleInfo.js.map +1 -0
  187. package/dist/utils/getXpBaseUrl.d.ts +2 -0
  188. package/dist/utils/getXpBaseUrl.js +8 -0
  189. package/dist/utils/getXpBaseUrl.js.map +1 -0
  190. package/dist/utils/indent.d.ts +1 -0
  191. package/dist/utils/indent.js +5 -0
  192. package/dist/utils/indent.js.map +1 -0
  193. package/dist/utils/sanitizeGraphqlName.d.ts +1 -0
  194. package/{src/utils/sanitizeGraphqlName.ts → dist/utils/sanitizeGraphqlName.js} +3 -2
  195. package/dist/utils/sanitizeGraphqlName.js.map +1 -0
  196. package/dist/views/BaseComponent.d.ts +20 -0
  197. package/{src/views/BaseComponent.tsx → dist/views/BaseComponent.jsx} +49 -76
  198. package/dist/views/BaseComponent.jsx.map +1 -0
  199. package/dist/views/BaseContent.d.ts +3 -0
  200. package/dist/views/BaseContent.jsx +38 -0
  201. package/dist/views/BaseContent.jsx.map +1 -0
  202. package/dist/views/BaseLayout.d.ts +3 -0
  203. package/dist/views/BaseLayout.jsx +24 -0
  204. package/dist/views/BaseLayout.jsx.map +1 -0
  205. package/dist/views/BaseMacro.d.ts +6 -0
  206. package/{src/views/BaseMacro.tsx → dist/views/BaseMacro.jsx} +37 -42
  207. package/dist/views/BaseMacro.jsx.map +1 -0
  208. package/dist/views/BasePage.d.ts +3 -0
  209. package/dist/views/BasePage.jsx +34 -0
  210. package/dist/views/BasePage.jsx.map +1 -0
  211. package/dist/views/BasePart.d.ts +3 -0
  212. package/dist/views/BasePart.jsx +24 -0
  213. package/dist/views/BasePart.jsx.map +1 -0
  214. package/dist/views/Empty.d.ts +2 -0
  215. package/{src/views/Empty.tsx → dist/views/Empty.jsx} +1 -2
  216. package/dist/views/Empty.jsx.map +1 -0
  217. package/dist/views/Fragment.d.ts +3 -0
  218. package/dist/views/Fragment.jsx +30 -0
  219. package/dist/views/Fragment.jsx.map +1 -0
  220. package/dist/views/MainView.d.ts +3 -0
  221. package/dist/views/MainView.jsx +14 -0
  222. package/dist/views/MainView.jsx.map +1 -0
  223. package/dist/views/PropsView.d.ts +2 -0
  224. package/dist/views/PropsView.jsx +21 -0
  225. package/dist/views/PropsView.jsx.map +1 -0
  226. package/dist/views/Region.d.ts +6 -0
  227. package/{src/views/Region.tsx → dist/views/Region.jsx} +17 -41
  228. package/dist/views/Region.jsx.map +1 -0
  229. package/dist/views/RichTextView.d.ts +3 -0
  230. package/dist/views/RichTextView.jsx +65 -0
  231. package/dist/views/RichTextView.jsx.map +1 -0
  232. package/dist/views/SingleComponent.d.ts +4 -0
  233. package/dist/views/SingleComponent.jsx +10 -0
  234. package/dist/views/SingleComponent.jsx.map +1 -0
  235. package/dist/views/StaticContent.d.ts +10 -0
  236. package/dist/views/StaticContent.jsx +37 -0
  237. package/dist/views/StaticContent.jsx.map +1 -0
  238. package/dist/views/Text.d.ts +8 -0
  239. package/dist/views/Text.jsx +4 -0
  240. package/dist/views/Text.jsx.map +1 -0
  241. package/dist/views/macros/DefaultMacro.d.ts +3 -0
  242. package/dist/views/macros/DefaultMacro.jsx +4 -0
  243. package/dist/views/macros/DefaultMacro.jsx.map +1 -0
  244. package/dist/views/macros/DisableMacro.d.ts +3 -0
  245. package/dist/views/macros/DisableMacro.jsx +3 -0
  246. package/dist/views/macros/DisableMacro.jsx.map +1 -0
  247. package/package.json +20 -32
  248. package/src/client.ts +0 -2
  249. package/src/common/ComponentRegistry.ts +0 -159
  250. package/src/guillotine/applyProcessors.ts +0 -34
  251. package/src/guillotine/buildPage.ts +0 -15
  252. package/src/guillotine/createMetaData.ts +0 -72
  253. package/src/guillotine/fetchContent.ts +0 -240
  254. package/src/guillotine/fetchContentData.ts +0 -31
  255. package/src/guillotine/fetchContentPathsForAllLocales.ts +0 -21
  256. package/src/guillotine/fetchContentPathsForLocale.ts +0 -43
  257. package/src/guillotine/fetchFromApi.ts +0 -76
  258. package/src/guillotine/fetchGuillotine.ts +0 -76
  259. package/src/guillotine/fetchMetaData.ts +0 -31
  260. package/src/guillotine/metadata/configQuery.ts +0 -46
  261. package/src/guillotine/validateData.ts +0 -11
  262. package/src/i18n/LocaleContext.tsx +0 -59
  263. package/src/i18n/i18n.ts +0 -57
  264. package/src/index.ts +0 -42
  265. package/src/server/getServerRenderedHtml.ts +0 -3
  266. package/src/server.ts +0 -5
  267. package/src/types/componentProps.ts +0 -143
  268. package/src/types/guillotine.ts +0 -428
  269. package/src/types/i18n.ts +0 -8
  270. package/src/types/next.ts +0 -7
  271. package/src/types/util.ts +0 -5
  272. package/src/utils/addLineNumbers.ts +0 -3
  273. package/src/utils/buildGuillotineRequestHeaders.ts +0 -29
  274. package/src/utils/enonicLog.ts +0 -28
  275. package/src/utils/fixDoubleSlashes.ts +0 -3
  276. package/src/utils/getAllLocales.ts +0 -6
  277. package/src/utils/getContentApiUrl.ts +0 -20
  278. package/src/utils/getLocaleMapping.ts +0 -24
  279. package/src/utils/getLocaleMappingByLocale.ts +0 -19
  280. package/src/utils/getLocaleMappingByProjectId.ts +0 -21
  281. package/src/utils/getRenderMode.ts +0 -11
  282. package/src/utils/getXpBaseUrl.ts +0 -12
  283. package/src/utils/indent.ts +0 -4
  284. package/src/views/BaseContent.tsx +0 -47
  285. package/src/views/BaseLayout.tsx +0 -33
  286. package/src/views/BasePage.tsx +0 -42
  287. package/src/views/BasePart.tsx +0 -34
  288. package/src/views/Fragment.tsx +0 -41
  289. package/src/views/MainView.tsx +0 -22
  290. package/src/views/PropsView.tsx +0 -38
  291. package/src/views/RichTextView.tsx +0 -106
  292. package/src/views/SingleComponent.tsx +0 -19
  293. package/src/views/StaticContent.tsx +0 -39
  294. package/src/views/Text.tsx +0 -19
  295. package/src/views/macros/DefaultMacro.tsx +0 -9
  296. package/src/views/macros/DisableMacro.tsx +0 -8
@@ -1,31 +0,0 @@
1
- import type {ContentApiBaseBody, ContentApiBaseBodyVariables, ContentResult, LocaleMapping, GuillotineRequestHeaders} from '../types';
2
-
3
- import {fetchGuillotine} from './fetchGuillotine';
4
-
5
-
6
- export const fetchContentData = async <Content = Record<string, unknown>>(
7
- contentApiUrl: string,
8
- xpContentPath: string,
9
- mapping: LocaleMapping,
10
- query: string,
11
- variables?: ContentApiBaseBodyVariables,
12
- headers?: GuillotineRequestHeaders
13
- ): Promise<ContentResult> => {
14
- const body: ContentApiBaseBody = {query};
15
- if (variables && Object.keys(variables).length > 0) {
16
- body.variables = variables;
17
- }
18
- const contentResults = await fetchGuillotine<ContentResult<Content>>(contentApiUrl, mapping, {
19
- body,
20
- headers
21
- });
22
-
23
- if (contentResults.error) {
24
- return contentResults;
25
- } else {
26
- return {
27
- // omit the aliases and return values
28
- contents: Object.values(contentResults)
29
- };
30
- }
31
- };
@@ -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
- };
@@ -1,46 +0,0 @@
1
- import type {ComponentDefinition} from '../../types';
2
-
3
-
4
- import {sanitizeGraphqlName} from '../../utils/sanitizeGraphqlName';
5
-
6
-
7
- export const configQuery = (
8
- list: [string, ComponentDefinition][],
9
- includeAppName = true,
10
- canUseConfigAsJson = true
11
- ): string => {
12
- const hasQueryList = list?.filter(([key, def]) => def.configQuery) || [];
13
- if (hasQueryList.length === 0) {
14
- return canUseConfigAsJson ? 'configAsJson' : '';
15
- }
16
-
17
- const configsByApp: Record<string,string[]> = {};
18
- hasQueryList
19
- .forEach((entry) => {
20
- const nameParts = entry[0].split(':');
21
- if (nameParts.length === 2) {
22
- const sanitizedAppName = sanitizeGraphqlName(nameParts[0]);
23
- let existingConfigs = configsByApp[sanitizedAppName];
24
- if (!existingConfigs) {
25
- existingConfigs = [];
26
- configsByApp[sanitizedAppName] = existingConfigs;
27
- }
28
- existingConfigs.push(`${sanitizeGraphqlName(nameParts[1])}${entry[1].configQuery}`);
29
- }
30
- });
31
-
32
- // Still query for configAsJson if at least one item has no configQuery defined
33
- const configAsJsonQuery = canUseConfigAsJson && hasQueryList.length < list.length ? 'configAsJson' : '';
34
-
35
- if (!includeAppName) {
36
- return `${configAsJsonQuery}
37
- config {
38
- ${Object.values(configsByApp).reduce((arr, curr) => arr.concat(curr), []).join('\n')}
39
- }`;
40
- } else {
41
- return `${configAsJsonQuery}
42
- config {
43
- ${Object.entries(configsByApp).map(entry => entry[0] + '{\n' + entry[1].join('\n') + '\n}')}
44
- }`;
45
- }
46
- };
@@ -1,11 +0,0 @@
1
- import type {FetchContentResult} from '../types';
2
-
3
-
4
- import {validateNotFound} from './validateNotFound';
5
- import {validateShortcut} from './validateShortcut';
6
-
7
-
8
- export function validateData(props: FetchContentResult): void {
9
- validateNotFound(props);
10
- validateShortcut(props);
11
- }
@@ -1,59 +0,0 @@
1
- 'use client';
2
- import type {Dict, LocaleContextType} from '../types';
3
-
4
- import React, {createContext, useContext, useEffect, useState} from 'react';
5
- import {getPhrase, loadPhrases} from './i18n';
6
-
7
-
8
- const LocaleContext = createContext<LocaleContextType>({
9
- dictionary: {},
10
- locale: '',
11
- localize: (key: string, ...args: any[]) => key,
12
- setLocale: (locale: string) => Promise.resolve({})
13
- });
14
-
15
- export const useLocaleContext = () => useContext(LocaleContext);
16
-
17
- export const LocaleContextProvider = ({
18
- children,
19
- locale: localeProps = ''
20
- }: {
21
- children: any
22
- locale?: string
23
- }) => {
24
- const [currentLocale, setLocaleState] = useState(localeProps);
25
- const [dictionary, setPhrasesState] = useState<Dict>({});
26
- const [isLoaded, setLoadedState] = useState(false);
27
-
28
- const setLocale = async (locale: string): Promise<Dict> => {
29
- setLocaleState(locale);
30
- setLoadedState(false);
31
-
32
- return loadPhrases(locale).then((phrases) => {
33
- setPhrasesState(phrases);
34
- setLoadedState(true);
35
- return phrases;
36
- });
37
- };
38
-
39
- useEffect(() => {
40
- if (localeProps) {
41
- void setLocale(localeProps); // void to avoid @typescript-eslint/no-floating-promises
42
- }
43
- }, []);
44
-
45
- const localize = (key: string, ...args: any[]) => {
46
- return isLoaded ? getPhrase(currentLocale, dictionary, key, ...args) : key;
47
- };
48
-
49
- return (
50
- <LocaleContext.Provider value={{
51
- setLocale,
52
- locale: currentLocale,
53
- dictionary,
54
- localize
55
- }}>
56
- {children}
57
- </LocaleContext.Provider>
58
- );
59
- };
package/src/i18n/i18n.ts DELETED
@@ -1,57 +0,0 @@
1
- import type {Dict} from '../types';
2
-
3
-
4
- export class I18n {
5
- private static locale = '';
6
- private static dictionary: Dict = {};
7
- private static isLoaded = false;
8
-
9
- public static async setLocale(locale: string): Promise<Dict> {
10
- this.locale = locale;
11
- this.isLoaded = false;
12
-
13
- return loadPhrases(locale).then((phrases) => {
14
- this.dictionary = phrases;
15
- this.isLoaded = true;
16
- return phrases;
17
- });
18
- }
19
-
20
- public static localize(key: string, ...args: any[]): string {
21
- return this.isLoaded ? getPhrase(this.locale, this.dictionary, key, ...args) : key;
22
- }
23
-
24
- public static getLocale() {
25
- return this.locale;
26
- }
27
-
28
- public static getDictionary() {
29
- return this.dictionary;
30
- }
31
- }
32
-
33
- export const loadPhrases = async (locale: string): Promise<Dict> => {
34
- return import(`@phrases/${locale}.json`)
35
- .then((module) => module.default)
36
- .catch((e) => {
37
- console.error(`Failed to load phrases for locale "${locale}"`, e);
38
- return {};
39
- });
40
- };
41
-
42
- export const getPhrase = (locale: string, dict: Dict, key: string, ...args: any[]) => {
43
- const template = dict[key];
44
- if (!template) {
45
- console.warn(`Missing localization phrase for locale "${locale}": <${key}>`);
46
- return `<${key}>`;
47
- }
48
- if (args.length) {
49
- let index = -1;
50
- return template.replace(/{(\d+)?}/g, (match, digit) => {
51
- index++;
52
- return args[digit || index] ?? match;
53
- });
54
- }
55
- return template;
56
- };
57
-
package/src/index.ts DELETED
@@ -1,42 +0,0 @@
1
- export {
2
- APP_NAME,
3
- APP_NAME_DASHED,
4
- APP_NAME_UNDERSCORED,
5
- IS_DEV_MODE
6
- } from './common/env';
7
-
8
- export type * from './types';
9
-
10
- export {ComponentRegistry} from './common/ComponentRegistry';
11
-
12
- export {
13
- CATCH_ALL,
14
- JSESSIONID_HEADER,
15
- PORTAL_COMPONENT_ATTRIBUTE,
16
- PORTAL_REGION_ATTRIBUTE,
17
- PROJECT_ID_HEADER,
18
- RENDER_MODE,
19
- RENDER_MODE_HEADER,
20
- XP_BASE_URL_HEADER,
21
- XP_COMPONENT_TYPE,
22
- XP_REQUEST_TYPE
23
- } from './common/constants';
24
-
25
-
26
- export {richTextQuery} from './guillotine/metadata/richTextQuery';
27
- export {validateData} from './guillotine/validateData';
28
-
29
- export {I18n} from './i18n/i18n';
30
-
31
- export {getContentApiUrl} from './utils/getContentApiUrl';
32
- export {getLocaleMapping} from './utils/getLocaleMapping';
33
- export {getLocaleMappingByProjectId} from './utils/getLocaleMappingByProjectId';
34
- export {getLocaleMappingByLocale} from './utils/getLocaleMappingByLocale';
35
- export {getRequestLocaleInfo} from './utils/getRequestLocaleInfo';
36
- export {sanitizeGraphqlName} from './utils/sanitizeGraphqlName';
37
-
38
- export {
39
- UrlProcessor,
40
- getAsset,
41
- getUrl
42
- } from './common/UrlProcessor';
@@ -1,3 +0,0 @@
1
- export function getServerRenderedHtml(component: React.ReactNode): string {
2
- return require('react-dom/server').renderToString(component);
3
- }
package/src/server.ts DELETED
@@ -1,5 +0,0 @@
1
- export {fetchContent} from './guillotine/fetchContent';
2
- export {fetchContentPathsForAllLocales} from './guillotine/fetchContentPathsForAllLocales';
3
- export {fetchContentPathsForLocale} from './guillotine/fetchContentPathsForLocale';
4
- export {fetchFromApi} from './guillotine/fetchFromApi';
5
- export {fetchGuillotine} from './guillotine/fetchGuillotine';
@@ -1,143 +0,0 @@
1
- import {DOMNode} from 'html-react-parser';
2
- import type {RENDER_MODE, XP_REQUEST_TYPE} from '../common/constants';
3
- import type {
4
- FragmentData,
5
- LayoutData,
6
- MacroConfig,
7
- MacroData,
8
- PageComponent,
9
- PageData,
10
- PartData,
11
- RichTextData,
12
- RegionTree
13
- } from './component';
14
- import type {ReactNode} from 'react';
15
-
16
-
17
- export interface BaseComponentProps {
18
- component: PageComponent;
19
- meta: MetaData;
20
- common?: any; // Content is passed down for optional consumption in componentviews.
21
- // TODO: Use a react contextprovider instead of "manually" passing everything down
22
- }
23
-
24
- export interface BaseLayoutProps {
25
- component?: LayoutData;
26
- path: string;
27
- regions?: RegionTree;
28
- common?: any;
29
- meta: MetaData;
30
- }
31
-
32
- export interface BaseMacroProps {
33
- children: ReactNode;
34
- data: Omit<MacroData, 'ref'>;
35
- meta: MetaData;
36
- renderInEditMode?: boolean;
37
- }
38
-
39
- export interface BasePageProps {
40
- component?: PageData;
41
- path?: string;
42
- common?: any;
43
- data?: any;
44
- error?: string;
45
- meta: MetaData;
46
- }
47
-
48
- export interface BasePartProps {
49
- component?: PartData;
50
- path: string;
51
- common?: any;
52
- data?: any;
53
- error?: string;
54
- meta: MetaData;
55
- }
56
-
57
- export interface FragmentProps {
58
- page?: PageData;
59
- component?: FragmentData;
60
- common?: any;
61
- meta: MetaData;
62
- }
63
-
64
- export interface LayoutProps {
65
- layout: LayoutData;
66
- path: string;
67
- common: any;
68
- meta: MetaData;
69
- }
70
-
71
- export interface MacroProps {
72
- name: string;
73
- children: string | React.ReactNode;
74
- config: MacroConfig;
75
- meta: MetaData;
76
- }
77
-
78
- export interface MetaData {
79
- id: string,
80
- type: string,
81
- path: string,
82
- requestType: XP_REQUEST_TYPE,
83
- renderMode: RENDER_MODE,
84
- requestedComponent?: PageComponent,
85
- canRender: boolean,
86
- catchAll: boolean,
87
- apiUrl: string,
88
- baseUrl: string,
89
- locale: string,
90
- defaultLocale: string
91
- }
92
-
93
- export interface PageProps {
94
- page: PageData;
95
- path: string;
96
- data?: any;
97
- common?: any; // Content is passed down to componentviews. TODO: Use a react contextprovider instead?
98
- meta: MetaData;
99
- }
100
-
101
- export interface PartProps {
102
- part: PartData
103
- path: string
104
- data?: any
105
- // Content is passed down to componentviews. TODO: Use a react contextprovider instead?
106
- common?: any
107
- meta: MetaData
108
- }
109
-
110
- export interface RegionProps {
111
- name: string
112
- components?: PageComponent[]
113
- className?: string
114
- // Content is passed down for optional consumption in componentviews. TODO: Use a react contextprovider instead?
115
- common?: any
116
- meta: MetaData
117
- }
118
-
119
- export interface RegionsProps {
120
- page: PageData | null;
121
- name?: string;
122
- // Content is passed down for optional consumption in componentviews. TODO: Use a react contextprovider instead?
123
- common?: any;
124
- meta: MetaData;
125
- }
126
-
127
- export type Replacer = (
128
- domNode: DOMNode,
129
- data: RichTextData,
130
- meta: MetaData,
131
- renderMacroInEditMode: boolean
132
- ) => ReplacerResult;
133
-
134
- export type ReplacerResult = JSX.Element | DOMNode;
135
-
136
- export interface RichTextViewProps {
137
- data: RichTextData
138
- meta: MetaData
139
- className?: string
140
- tag?: string
141
- renderMacroInEditMode?: boolean
142
- customReplacer?: Replacer
143
- }