@sitecore-content-sdk/core 1.3.0-canary.9 → 1.4.0-canary.2

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 (342) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/cache-client.js +55 -54
  3. package/dist/cjs/client/constants.js +7 -7
  4. package/dist/cjs/client/edge-proxy.js +24 -22
  5. package/dist/cjs/client/index.js +15 -15
  6. package/dist/cjs/client/models.js +2 -2
  7. package/dist/cjs/client/sitecore-client.js +421 -419
  8. package/dist/cjs/client/utils.js +47 -46
  9. package/dist/cjs/config/define-config.js +194 -193
  10. package/dist/cjs/config/index.js +7 -7
  11. package/dist/cjs/config/models.js +12 -11
  12. package/dist/cjs/config-cli/define-cli-config.js +23 -22
  13. package/dist/cjs/config-cli/index.js +7 -7
  14. package/dist/cjs/config-cli/models.js +8 -7
  15. package/dist/cjs/constants.js +49 -17
  16. package/dist/cjs/debug.js +48 -46
  17. package/dist/cjs/editing/codegen/index.js +14 -9
  18. package/dist/cjs/editing/codegen/preview.js +277 -193
  19. package/dist/cjs/editing/component-layout-service.js +62 -61
  20. package/dist/cjs/editing/design-library.js +183 -126
  21. package/dist/cjs/editing/editing-service.js +75 -74
  22. package/dist/cjs/editing/index.js +33 -27
  23. package/dist/cjs/editing/metadata.js +42 -42
  24. package/dist/cjs/editing/models.js +44 -38
  25. package/dist/cjs/editing/utils.js +108 -90
  26. package/dist/cjs/form/form.js +81 -78
  27. package/dist/cjs/form/index.js +7 -7
  28. package/dist/cjs/graphql-request-client.js +108 -107
  29. package/dist/cjs/i18n/dictionary-service.js +122 -121
  30. package/dist/cjs/i18n/index.js +7 -7
  31. package/dist/cjs/i18n/utils.js +16 -15
  32. package/dist/cjs/index.js +60 -60
  33. package/dist/cjs/layout/content-styles.js +72 -71
  34. package/dist/cjs/layout/index.js +24 -24
  35. package/dist/cjs/layout/layout-service.js +62 -57
  36. package/dist/cjs/layout/models.js +39 -34
  37. package/dist/cjs/layout/themes.js +76 -75
  38. package/dist/cjs/layout/utils.js +117 -110
  39. package/dist/cjs/media/index.js +38 -38
  40. package/dist/cjs/media/media-api.js +100 -96
  41. package/dist/cjs/models.js +2 -2
  42. package/dist/cjs/native-fetcher.js +194 -179
  43. package/dist/cjs/personalize/index.js +15 -15
  44. package/dist/cjs/personalize/layout-personalizer.js +98 -97
  45. package/dist/cjs/personalize/personalize-service.js +98 -94
  46. package/dist/cjs/personalize/utils.js +143 -136
  47. package/dist/cjs/retries.js +43 -42
  48. package/dist/cjs/site/error-pages-service.js +65 -64
  49. package/dist/cjs/site/index.js +26 -26
  50. package/dist/cjs/site/models.js +2 -2
  51. package/dist/cjs/site/redirects-service.js +94 -81
  52. package/dist/cjs/site/robots-service.js +66 -65
  53. package/dist/cjs/site/site-resolver.js +73 -72
  54. package/dist/cjs/site/siteinfo-service.js +84 -80
  55. package/dist/cjs/site/sitemap-xml-service.js +84 -83
  56. package/dist/cjs/site/sitepath-service.js +165 -164
  57. package/dist/cjs/site/utils.js +55 -47
  58. package/dist/cjs/sitecore-service-base.js +36 -36
  59. package/dist/cjs/tools/auth/flow.js +65 -64
  60. package/dist/cjs/tools/auth/index.js +5 -5
  61. package/dist/cjs/tools/auth/models.js +2 -2
  62. package/dist/cjs/tools/auth/tenant-store.js +38 -38
  63. package/dist/cjs/tools/codegen/component-generation.js +52 -50
  64. package/dist/cjs/tools/codegen/extract-files.js +105 -107
  65. package/dist/cjs/tools/codegen/import-map.js +401 -349
  66. package/dist/cjs/tools/codegen/utils.js +418 -418
  67. package/dist/cjs/tools/generate-map.js +2 -2
  68. package/dist/cjs/tools/generateMetadata.js +36 -35
  69. package/dist/cjs/tools/generateSites.js +59 -58
  70. package/dist/cjs/tools/index.js +75 -73
  71. package/dist/cjs/tools/scaffold.js +60 -59
  72. package/dist/cjs/tools/templating/components.js +96 -266
  73. package/dist/cjs/tools/templating/index.js +11 -14
  74. package/dist/cjs/tools/templating/plugins.js +80 -78
  75. package/dist/cjs/tools/templating/utils.js +67 -66
  76. package/dist/cjs/utils/ensurePath.js +20 -20
  77. package/dist/cjs/utils/env.js +28 -27
  78. package/dist/cjs/utils/globalCache.js +55 -0
  79. package/dist/cjs/utils/index.js +26 -21
  80. package/dist/cjs/utils/is-server.js +11 -10
  81. package/dist/cjs/utils/normalize-url.js +5 -5
  82. package/dist/cjs/utils/timeout-promise.js +31 -31
  83. package/dist/cjs/utils/utils.js +254 -229
  84. package/dist/esm/cache-client.js +51 -50
  85. package/dist/esm/client/constants.js +4 -4
  86. package/dist/esm/client/edge-proxy.js +19 -17
  87. package/dist/esm/client/index.js +5 -5
  88. package/dist/esm/client/models.js +1 -1
  89. package/dist/esm/client/sitecore-client.js +414 -412
  90. package/dist/esm/client/utils.js +43 -42
  91. package/dist/esm/config/define-config.js +188 -187
  92. package/dist/esm/config/index.js +2 -2
  93. package/dist/esm/config/models.js +9 -8
  94. package/dist/esm/config-cli/define-cli-config.js +19 -18
  95. package/dist/esm/config-cli/index.js +2 -2
  96. package/dist/esm/config-cli/models.js +5 -4
  97. package/dist/esm/constants.js +46 -14
  98. package/dist/esm/debug.js +41 -39
  99. package/dist/esm/editing/codegen/index.js +1 -1
  100. package/dist/esm/editing/codegen/preview.js +263 -185
  101. package/dist/esm/editing/component-layout-service.js +55 -54
  102. package/dist/esm/editing/design-library.js +171 -117
  103. package/dist/esm/editing/editing-service.js +68 -67
  104. package/dist/esm/editing/index.js +6 -5
  105. package/dist/esm/editing/metadata.js +39 -39
  106. package/dist/esm/editing/models.js +41 -35
  107. package/dist/esm/editing/utils.js +98 -80
  108. package/dist/esm/form/form.js +72 -69
  109. package/dist/esm/form/index.js +1 -1
  110. package/dist/esm/graphql-request-client.js +101 -100
  111. package/dist/esm/i18n/dictionary-service.js +115 -114
  112. package/dist/esm/i18n/index.js +2 -2
  113. package/dist/esm/i18n/utils.js +13 -12
  114. package/dist/esm/index.js +13 -13
  115. package/dist/esm/layout/content-styles.js +64 -63
  116. package/dist/esm/layout/index.js +6 -6
  117. package/dist/esm/layout/layout-service.js +55 -50
  118. package/dist/esm/layout/models.js +36 -31
  119. package/dist/esm/layout/themes.js +71 -70
  120. package/dist/esm/layout/utils.js +109 -102
  121. package/dist/esm/media/index.js +2 -2
  122. package/dist/esm/media/media-api.js +90 -86
  123. package/dist/esm/models.js +1 -1
  124. package/dist/esm/native-fetcher.js +187 -172
  125. package/dist/esm/personalize/index.js +3 -3
  126. package/dist/esm/personalize/layout-personalizer.js +93 -92
  127. package/dist/esm/personalize/personalize-service.js +91 -87
  128. package/dist/esm/personalize/utils.js +135 -128
  129. package/dist/esm/retries.js +39 -38
  130. package/dist/esm/site/error-pages-service.js +58 -57
  131. package/dist/esm/site/index.js +8 -8
  132. package/dist/esm/site/models.js +1 -1
  133. package/dist/esm/site/redirects-service.js +87 -74
  134. package/dist/esm/site/robots-service.js +59 -58
  135. package/dist/esm/site/site-resolver.js +69 -68
  136. package/dist/esm/site/siteinfo-service.js +77 -73
  137. package/dist/esm/site/sitemap-xml-service.js +77 -76
  138. package/dist/esm/site/sitepath-service.js +157 -156
  139. package/dist/esm/site/utils.js +49 -41
  140. package/dist/esm/sitecore-service-base.js +29 -29
  141. package/dist/esm/tools/auth/flow.js +62 -61
  142. package/dist/esm/tools/auth/index.js +1 -1
  143. package/dist/esm/tools/auth/models.js +1 -1
  144. package/dist/esm/tools/auth/tenant-store.js +35 -35
  145. package/dist/esm/tools/codegen/component-generation.js +44 -42
  146. package/dist/esm/tools/codegen/extract-files.js +99 -101
  147. package/dist/esm/tools/codegen/import-map.js +358 -306
  148. package/dist/esm/tools/codegen/utils.js +373 -373
  149. package/dist/esm/tools/generate-map.js +1 -1
  150. package/dist/esm/tools/generateMetadata.js +29 -28
  151. package/dist/esm/tools/generateSites.js +52 -51
  152. package/dist/esm/tools/index.js +28 -27
  153. package/dist/esm/tools/scaffold.js +52 -51
  154. package/dist/esm/tools/templating/components.js +59 -223
  155. package/dist/esm/tools/templating/index.js +3 -3
  156. package/dist/esm/tools/templating/plugins.js +72 -70
  157. package/dist/esm/tools/templating/utils.js +59 -58
  158. package/dist/esm/utils/ensurePath.js +13 -13
  159. package/dist/esm/utils/env.js +24 -23
  160. package/dist/esm/utils/globalCache.js +49 -0
  161. package/dist/esm/utils/index.js +4 -3
  162. package/dist/esm/utils/is-server.js +9 -8
  163. package/dist/esm/utils/normalize-url.js +1 -1
  164. package/dist/esm/utils/timeout-promise.js +28 -28
  165. package/dist/esm/utils/utils.js +238 -213
  166. package/package.json +73 -5
  167. package/types/cache-client.d.ts +68 -64
  168. package/types/cache-client.d.ts.map +1 -0
  169. package/types/client/constants.d.ts +5 -4
  170. package/types/client/constants.d.ts.map +1 -0
  171. package/types/client/edge-proxy.d.ts +18 -15
  172. package/types/client/edge-proxy.d.ts.map +1 -0
  173. package/types/client/index.d.ts +8 -7
  174. package/types/client/index.d.ts.map +1 -0
  175. package/types/client/models.d.ts +21 -19
  176. package/types/client/models.d.ts.map +1 -0
  177. package/types/client/sitecore-client.d.ts +338 -327
  178. package/types/client/sitecore-client.d.ts.map +1 -0
  179. package/types/client/utils.d.ts +15 -9
  180. package/types/client/utils.d.ts.map +1 -0
  181. package/types/config/define-config.d.ts +20 -18
  182. package/types/config/define-config.d.ts.map +1 -0
  183. package/types/config/index.d.ts +3 -2
  184. package/types/config/index.d.ts.map +1 -0
  185. package/types/config/models.d.ts +287 -268
  186. package/types/config/models.d.ts.map +1 -0
  187. package/types/config-cli/define-cli-config.d.ts +9 -7
  188. package/types/config-cli/define-cli-config.d.ts.map +1 -0
  189. package/types/config-cli/index.d.ts +3 -2
  190. package/types/config-cli/index.d.ts.map +1 -0
  191. package/types/config-cli/models.d.ts +6 -4
  192. package/types/config-cli/models.d.ts.map +1 -0
  193. package/types/constants.d.ts +44 -11
  194. package/types/constants.d.ts.map +1 -0
  195. package/types/debug.d.ts +35 -28
  196. package/types/debug.d.ts.map +1 -0
  197. package/types/editing/codegen/index.d.ts +2 -1
  198. package/types/editing/codegen/index.d.ts.map +1 -0
  199. package/types/editing/codegen/preview.d.ts +256 -195
  200. package/types/editing/codegen/preview.d.ts.map +1 -0
  201. package/types/editing/component-layout-service.d.ts +84 -80
  202. package/types/editing/component-layout-service.d.ts.map +1 -0
  203. package/types/editing/design-library.d.ts +111 -63
  204. package/types/editing/design-library.d.ts.map +1 -0
  205. package/types/editing/editing-service.d.ts +72 -62
  206. package/types/editing/editing-service.d.ts.map +1 -0
  207. package/types/editing/index.d.ts +7 -6
  208. package/types/editing/index.d.ts.map +1 -0
  209. package/types/editing/metadata.d.ts +8 -7
  210. package/types/editing/metadata.d.ts.map +1 -0
  211. package/types/editing/models.d.ts +103 -92
  212. package/types/editing/models.d.ts.map +1 -0
  213. package/types/editing/utils.d.ts +91 -74
  214. package/types/editing/utils.d.ts.map +1 -0
  215. package/types/form/form.d.ts +25 -21
  216. package/types/form/form.d.ts.map +1 -0
  217. package/types/form/index.d.ts +2 -1
  218. package/types/form/index.d.ts.map +1 -0
  219. package/types/graphql-request-client.d.ts +112 -105
  220. package/types/graphql-request-client.d.ts.map +1 -0
  221. package/types/i18n/dictionary-service.d.ts +135 -131
  222. package/types/i18n/dictionary-service.d.ts.map +1 -0
  223. package/types/i18n/index.d.ts +3 -2
  224. package/types/i18n/index.d.ts.map +1 -0
  225. package/types/i18n/utils.d.ts +9 -7
  226. package/types/i18n/utils.d.ts.map +1 -0
  227. package/types/index.d.ts +13 -12
  228. package/types/index.d.ts.map +1 -0
  229. package/types/layout/content-styles.d.ts +20 -18
  230. package/types/layout/content-styles.d.ts.map +1 -0
  231. package/types/layout/index.d.ts +6 -5
  232. package/types/layout/index.d.ts.map +1 -0
  233. package/types/layout/layout-service.d.ts +45 -35
  234. package/types/layout/layout-service.d.ts.map +1 -0
  235. package/types/layout/models.d.ts +174 -151
  236. package/types/layout/models.d.ts.map +1 -0
  237. package/types/layout/themes.d.ts +13 -11
  238. package/types/layout/themes.d.ts.map +1 -0
  239. package/types/layout/utils.d.ts +56 -41
  240. package/types/layout/utils.d.ts.map +1 -0
  241. package/types/media/index.d.ts +3 -2
  242. package/types/media/index.d.ts.map +1 -0
  243. package/types/media/media-api.d.ts +60 -55
  244. package/types/media/media-api.d.ts.map +1 -0
  245. package/types/models.d.ts +94 -84
  246. package/types/models.d.ts.map +1 -0
  247. package/types/native-fetcher.d.ts +124 -114
  248. package/types/native-fetcher.d.ts.map +1 -0
  249. package/types/personalize/index.d.ts +4 -3
  250. package/types/personalize/index.d.ts.map +1 -0
  251. package/types/personalize/layout-personalizer.d.ts +29 -27
  252. package/types/personalize/layout-personalizer.d.ts.map +1 -0
  253. package/types/personalize/personalize-service.d.ts +90 -80
  254. package/types/personalize/personalize-service.d.ts.map +1 -0
  255. package/types/personalize/utils.d.ts +78 -69
  256. package/types/personalize/utils.d.ts.map +1 -0
  257. package/types/retries.d.ts +26 -24
  258. package/types/retries.d.ts.map +1 -0
  259. package/types/site/error-pages-service.d.ts +64 -57
  260. package/types/site/error-pages-service.d.ts.map +1 -0
  261. package/types/site/index.d.ts +10 -9
  262. package/types/site/index.d.ts.map +1 -0
  263. package/types/site/models.d.ts +23 -18
  264. package/types/site/models.d.ts.map +1 -0
  265. package/types/site/redirects-service.d.ts +92 -69
  266. package/types/site/redirects-service.d.ts.map +1 -0
  267. package/types/site/robots-service.d.ts +57 -50
  268. package/types/site/robots-service.d.ts.map +1 -0
  269. package/types/site/site-resolver.d.ts +28 -26
  270. package/types/site/site-resolver.d.ts.map +1 -0
  271. package/types/site/siteinfo-service.d.ts +65 -52
  272. package/types/site/siteinfo-service.d.ts.map +1 -0
  273. package/types/site/sitemap-xml-service.d.ts +63 -56
  274. package/types/site/sitemap-xml-service.d.ts.map +1 -0
  275. package/types/site/sitepath-service.d.ts +137 -134
  276. package/types/site/sitepath-service.d.ts.map +1 -0
  277. package/types/site/utils.d.ts +41 -28
  278. package/types/site/utils.d.ts.map +1 -0
  279. package/types/sitecore-service-base.d.ts +31 -30
  280. package/types/sitecore-service-base.d.ts.map +1 -0
  281. package/types/tools/auth/flow.d.ts +29 -27
  282. package/types/tools/auth/flow.d.ts.map +1 -0
  283. package/types/tools/auth/index.d.ts +2 -1
  284. package/types/tools/auth/index.d.ts.map +1 -0
  285. package/types/tools/auth/models.d.ts +35 -33
  286. package/types/tools/auth/models.d.ts.map +1 -0
  287. package/types/tools/auth/tenant-store.d.ts +12 -11
  288. package/types/tools/auth/tenant-store.d.ts.map +1 -0
  289. package/types/tools/codegen/component-generation.d.ts +50 -47
  290. package/types/tools/codegen/component-generation.d.ts.map +1 -0
  291. package/types/tools/codegen/extract-files.d.ts +24 -22
  292. package/types/tools/codegen/extract-files.d.ts.map +1 -0
  293. package/types/tools/codegen/import-map.d.ts +103 -70
  294. package/types/tools/codegen/import-map.d.ts.map +1 -0
  295. package/types/tools/codegen/utils.d.ts +76 -75
  296. package/types/tools/codegen/utils.d.ts.map +1 -0
  297. package/types/tools/generate-map.d.ts +36 -26
  298. package/types/tools/generate-map.d.ts.map +1 -0
  299. package/types/tools/generateMetadata.d.ts +24 -22
  300. package/types/tools/generateMetadata.d.ts.map +1 -0
  301. package/types/tools/generateSites.d.ts +25 -22
  302. package/types/tools/generateSites.d.ts.map +1 -0
  303. package/types/tools/index.d.ts +22 -20
  304. package/types/tools/index.d.ts.map +1 -0
  305. package/types/tools/scaffold.d.ts +27 -25
  306. package/types/tools/scaffold.d.ts.map +1 -0
  307. package/types/tools/templating/components.d.ts +104 -103
  308. package/types/tools/templating/components.d.ts.map +1 -0
  309. package/types/tools/templating/index.d.ts +4 -3
  310. package/types/tools/templating/index.d.ts.map +1 -0
  311. package/types/tools/templating/plugins.d.ts +71 -67
  312. package/types/tools/templating/plugins.d.ts.map +1 -0
  313. package/types/tools/templating/utils.d.ts +42 -40
  314. package/types/tools/templating/utils.d.ts.map +1 -0
  315. package/types/utils/ensurePath.d.ts +7 -6
  316. package/types/utils/ensurePath.d.ts.map +1 -0
  317. package/types/utils/env.d.ts +9 -7
  318. package/types/utils/env.d.ts.map +1 -0
  319. package/types/utils/globalCache.d.ts +37 -0
  320. package/types/utils/globalCache.d.ts.map +1 -0
  321. package/types/utils/index.d.ts +5 -3
  322. package/types/utils/index.d.ts.map +1 -0
  323. package/types/utils/is-server.d.ts +8 -6
  324. package/types/utils/is-server.d.ts.map +1 -0
  325. package/types/utils/normalize-url.d.ts +2 -1
  326. package/types/utils/normalize-url.d.ts.map +1 -0
  327. package/types/utils/timeout-promise.d.ts +18 -17
  328. package/types/utils/timeout-promise.d.ts.map +1 -0
  329. package/types/utils/utils.d.ts +104 -79
  330. package/types/utils/utils.d.ts.map +1 -0
  331. package/client.js +0 -1
  332. package/codegen.js +0 -1
  333. package/config-cli.js +0 -1
  334. package/config.js +0 -1
  335. package/editing.js +0 -1
  336. package/i18n.js +0 -1
  337. package/layout.js +0 -1
  338. package/media.js +0 -1
  339. package/personalize.js +0 -1
  340. package/site.js +0 -1
  341. package/tools.js +0 -1
  342. package/utils.js +0 -1
@@ -1,415 +1,417 @@
1
- import { EditingService, ComponentLayoutService, DesignLibraryMode, } from '../editing';
2
- import { DictionaryService } from '../i18n';
3
- import { getDesignLibraryStylesheetLinks, getContentStylesheetLink, LayoutService, LayoutServicePageState, } from '../layout';
4
- import { getGroomedVariantIds } from '../personalize/utils';
5
- import { personalizeLayout } from '../personalize/layout-personalizer';
6
- import { ErrorPagesService, SitePathService, SitemapXmlService } from '../site';
7
- import { createGraphQLClientFactory } from './utils';
8
- import { NativeDataFetcher } from '../native-fetcher';
9
- import { RobotsService } from '../site/robots-service';
10
- import { DesignLibraryVariantGeneration } from '../editing/models';
11
- import debug from '../debug';
12
- /**
13
- * Error page codes
14
- */
15
- export var ErrorPage;
16
- (function (ErrorPage) {
17
- ErrorPage["NotFound"] = "404";
18
- ErrorPage["InternalServerError"] = "500";
19
- })(ErrorPage || (ErrorPage = {}));
20
- /**
21
- * This is a generic content client that can be used by any framework.
22
- * Use it to retrieve pages, preview data, dictionary and other data
23
- */
24
- export class SitecoreClient {
25
- /**
26
- * Init SitecoreClient
27
- * @param {SitecoreClientInit} initOptions initOptions for the client, containing site and Sitecore connection details
28
- */
29
- constructor(initOptions) {
30
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
31
- this.initOptions = initOptions;
32
- this.clientFactory = this.getClientFactory();
33
- this.graphQLClient = this.clientFactory({
34
- debugger: debug.http,
35
- });
36
- const baseServiceOptions = this.getBaseServiceOptions();
37
- this.layoutService =
38
- (_b = (_a = initOptions.custom) === null || _a === void 0 ? void 0 : _a.layoutService) !== null && _b !== void 0 ? _b : this.getLayoutService(baseServiceOptions);
39
- this.dictionaryService =
40
- (_d = (_c = initOptions.custom) === null || _c === void 0 ? void 0 : _c.dictionaryService) !== null && _d !== void 0 ? _d : this.getDictionaryService(baseServiceOptions);
41
- this.editingService = (_f = (_e = initOptions.custom) === null || _e === void 0 ? void 0 : _e.editingService) !== null && _f !== void 0 ? _f : this.getEditingService();
42
- this.errorPagesService = (_h = (_g = initOptions.custom) === null || _g === void 0 ? void 0 : _g.errorPagesService) !== null && _h !== void 0 ? _h : this.getErrorPagesService();
43
- this.sitePathService = (_k = (_j = initOptions.custom) === null || _j === void 0 ? void 0 : _j.sitePathService) !== null && _k !== void 0 ? _k : this.getSitePathService();
44
- this.componentService = this.getComponentService();
45
- }
46
- /**
47
- * Normalize path regardless of type
48
- * @param {string | string[]} path string or string array path
49
- * @returns {string} string path
50
- */
51
- parsePath(path) {
52
- // join array path, while clearing extra slashes and ensure first slash
53
- return typeof path === 'string'
54
- ? path.startsWith('/')
55
- ? path
56
- : `/${path}`
57
- : `/${path
58
- .filter((part) => part !== '/')
59
- .map((part) => part.replace(/^\/+/, '').replace(/\/+$/, ''))
60
- .join('/')}`;
61
- }
62
- /**
63
- * Execute a raw GraphQL request using the client's configured GraphQL Edge endpoint.
64
- * This is a thin pass-through to the underlying {@link GraphQLClient.request},
65
- * @param {string | DocumentNode} query GraphQL query
66
- * @param {Record<string, unknown>} [variables] Optional variables bag
67
- * @param {FetchOptions} [fetchOptions] Optional fetch overrides (e.g. fetch, headers)
68
- */
69
- getData(query, variables, fetchOptions) {
70
- return this.graphQLClient.request(query, variables, fetchOptions);
71
- }
72
- /**
73
- * Get page details for a route, with layout and other details
74
- * @param {string} path route path
75
- * @param {PageOptions} [pageOptions] site, language and personalization variant details for route
76
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
77
- * @returns {Page | null} page details
78
- */
79
- async getPage(path, pageOptions, fetchOptions) {
80
- var _a, _b, _c, _d;
81
- const computedPath = this.parsePath(path);
82
- const locale = (_a = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.locale) !== null && _a !== void 0 ? _a : this.initOptions.defaultLanguage;
83
- const site = (_b = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.site) !== null && _b !== void 0 ? _b : this.initOptions.defaultSite;
84
- // Fetch layout data, passing on req/res for SSR
85
- const layout = await this.layoutService.fetchLayoutData(computedPath, {
86
- locale,
87
- site,
88
- }, fetchOptions);
89
- if (!layout.sitecore.route) {
90
- return null;
91
- }
92
- else {
93
- // Initialize links to be inserted on the page
94
- if ((_c = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.personalize) === null || _c === void 0 ? void 0 : _c.variantId) {
95
- // Modify layoutData to use specific variant(s) instead of default
96
- // This will also set the variantId on the Sitecore context so that it is accessible here
97
- personalizeLayout(layout, pageOptions.personalize.variantId, pageOptions.personalize.componentVariantIds);
98
- }
99
- return {
100
- layout,
101
- siteName: ((_d = layout.sitecore.context.site) === null || _d === void 0 ? void 0 : _d.name) || site,
102
- locale,
103
- mode: this.getPageMode(LayoutServicePageState.Normal),
104
- };
105
- }
106
- }
107
- /**
108
- * Retrieves the head `<link>` elements for Sitecore styles and themes.
109
- * @param {LayoutServiceData} layoutData - The layout data containing styles and themes.
110
- * @param {object} [options] - Optional configuration for enabling styles and themes.
111
- * @param {boolean} [options.enableStyles] - Whether to include content styles.
112
- * @param {boolean} [options.enableThemes] - Whether to include theme styles.
113
- * @returns {HTMLLink[]} An array of `<link>` elements for stylesheets.
114
- */
115
- getHeadLinks(layoutData, options = {}) {
116
- const { enableStyles = true, enableThemes = true } = options;
117
- const { contextId: serverContextId, clientContextId, edgeUrl } = this.initOptions.api.edge;
118
- const headLinks = [];
119
- const contextId = serverContextId || clientContextId;
120
- if (enableStyles) {
121
- const contentStyles = getContentStylesheetLink(layoutData, contextId, edgeUrl);
122
- if (contentStyles)
123
- headLinks.push(contentStyles);
124
- }
125
- if (enableThemes) {
126
- headLinks.push(...getDesignLibraryStylesheetLinks(layoutData, contextId, edgeUrl));
127
- }
128
- return headLinks;
129
- }
130
- /**
131
- * Retrieves dictionary phrases for a given site and locale.
132
- * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
133
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
134
- * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
135
- */
136
- async getDictionary(routeOptions, fetchOptions) {
137
- const locale = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.locale) || this.initOptions.defaultLanguage;
138
- const site = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.site) || this.initOptions.defaultSite;
139
- return await this.dictionaryService.fetchDictionaryData(locale, site, fetchOptions);
140
- }
141
- /**
142
- * Retrieves error pages for a given site and locale.
143
- * @param {RouteOptions} routeOptions - Route options containing language and site name to load error pages
144
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
145
- * @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
146
- */
147
- async getErrorPages(routeOptions, fetchOptions) {
148
- const locale = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.locale) || this.initOptions.defaultLanguage;
149
- const site = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.site) || this.initOptions.defaultSite;
150
- return await this.errorPagesService.fetchErrorPages(site, locale, fetchOptions);
151
- }
152
- /**
153
- * Retrieves preview page and layout details
154
- * @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
155
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
156
- * @returns {Page} preview page details
157
- */
158
- async getPreview(previewData, fetchOptions) {
159
- var _a;
160
- if (!previewData) {
161
- console.error('Preview data missing');
162
- return null;
163
- }
164
- // If we're in Pages preview (editing) mode, prefetch the editing data
165
- const { site, itemId, language, version, layoutKind, mode } = previewData;
166
- const variantIds = Array.isArray(previewData.variantIds)
167
- ? previewData.variantIds
168
- : previewData.variantIds.split(',');
169
- const data = await this.editingService.fetchEditingData({
170
- itemId,
171
- language,
172
- version,
173
- layoutKind,
174
- mode,
175
- }, fetchOptions);
176
- if (!data) {
177
- throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(previewData)}`);
178
- }
179
- const page = {
180
- locale: language,
181
- layout: data.layoutData,
182
- siteName: ((_a = data.layoutData.sitecore.context.site) === null || _a === void 0 ? void 0 : _a.name) || site,
183
- mode: this.getPageMode(mode),
184
- };
185
- const personalizeData = getGroomedVariantIds(variantIds);
186
- personalizeLayout(page.layout, personalizeData.variantId, personalizeData.componentVariantIds);
187
- return page;
188
- }
189
- /**
190
- * Get design library page details for Design Library mode of your app
191
- * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
192
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
193
- * @returns {Page} preview page for Design Library
194
- */
195
- async getDesignLibraryData(designLibData, fetchOptions) {
196
- var _a;
197
- if (!this.initOptions.api.local) {
198
- throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
199
- }
200
- const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode, generation, } = designLibData;
201
- const componentData = await this.componentService.fetchComponentData(Object.assign({ siteName: site, itemId,
202
- language,
203
- componentUid,
204
- renderingId,
205
- dataSourceId,
206
- version,
207
- mode }, (generation ? { generation } : {})), fetchOptions);
208
- if (!componentData) {
209
- throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(designLibData)}`);
210
- }
211
- const page = {
212
- locale: designLibData.language,
213
- layout: componentData,
214
- siteName: ((_a = componentData.sitecore.context.site) === null || _a === void 0 ? void 0 : _a.name) || site,
215
- mode: this.getPageMode(mode, generation),
216
- };
217
- return page;
218
- }
219
- /**
220
- * Get error page details for a given error code
221
- * @param {ErrorPage} code - The error code to get the error page for
222
- * @param {Partial<RouteOptions>} pageOptions - The page options to get the error page for
223
- * @param {FetchOptions} [fetchOptions] - Additional fetch fetch options to override GraphQL requests
224
- * @returns {Promise<Page | null>} A promise that resolves to the error page details or null if not found
225
- */
226
- async getErrorPage(code, pageOptions, fetchOptions) {
227
- var _a, _b;
228
- const locale = (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.locale) || this.initOptions.defaultLanguage;
229
- const site = (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.site) || this.initOptions.defaultSite;
230
- const result = await this.getErrorPages({
231
- site,
232
- locale,
233
- }, fetchOptions);
234
- let layout = null;
235
- switch (code) {
236
- case ErrorPage.NotFound:
237
- layout = ((_a = result === null || result === void 0 ? void 0 : result.notFoundPage) === null || _a === void 0 ? void 0 : _a.rendered) || null;
238
- break;
239
- case ErrorPage.InternalServerError:
240
- layout = ((_b = result === null || result === void 0 ? void 0 : result.serverErrorPage) === null || _b === void 0 ? void 0 : _b.rendered) || null;
241
- break;
242
- default:
243
- return null;
244
- }
245
- if (!layout) {
246
- return null;
247
- }
248
- return {
249
- layout,
250
- locale,
251
- mode: this.getPageMode(LayoutServicePageState.Normal),
252
- siteName: site,
253
- };
254
- }
255
- /**
256
- * Retrieves the static paths for pages based on the given languages.
257
- * @param {string[]} sites - An array of site names to fetch routes for.
258
- * @param {string[]} [languages] - An optional array of language codes to generate paths for.
259
- * @param {FetchOptions} [fetchOptions] - Additional fetch options.
260
- * @returns {Promise<StaticPath[]>} A promise that resolves to an array of static paths.
261
- */
262
- async getPagePaths(sites, languages, fetchOptions) {
263
- return this.sitePathService.fetchSiteRoutes(sites, languages || [], fetchOptions);
264
- }
265
- /**
266
- * Retrieves sitemap XML content - either a specific sitemap or the index of all sitemaps.
267
- * @param {SitemapXmlOptions} reqOptions - Options for sitemap retrieval
268
- * @param {FetchOptions} [fetchOptions] - Additional fetch options.
269
- * @returns {Promise<string>} Promise resolving to the sitemap XML content as string
270
- * @throws {Error} Throws 'REDIRECT_404' if requested sitemap is not found
271
- */
272
- async getSiteMap(reqOptions, fetchOptions) {
273
- const { reqHost, reqProtocol, id, siteName } = reqOptions;
274
- // create sitemap graphql service
275
- const sitemapXmlService = this.getGraphqlSitemapXMLService(siteName || this.initOptions.defaultSite);
276
- // The id is present if url has sitemap-{n}.xml type.
277
- // The id can be null if it's index sitemap.xml request
278
- const sitemapPath = await sitemapXmlService.getSitemap(id);
279
- // regular sitemap
280
- if (sitemapPath) {
281
- try {
282
- const fetcher = new NativeDataFetcher();
283
- const xmlResponse = await fetcher.fetch(sitemapPath);
284
- if (!xmlResponse.data) {
285
- throw new Error('REDIRECT_404');
286
- }
287
- return xmlResponse.data;
288
- // eslint-disable-next-line no-unused-vars
289
- }
290
- catch (error) {
291
- throw new Error('REDIRECT_404');
292
- }
293
- }
294
- // index /sitemap.xml that includes links to all sitemaps
295
- const sitemaps = await sitemapXmlService.fetchSitemaps(fetchOptions);
296
- if (!sitemaps.length) {
297
- throw new Error('REDIRECT_404');
298
- }
1
+ import { EditingService, ComponentLayoutService, DesignLibraryMode, } from '../editing';
2
+ import { DictionaryService } from '../i18n';
3
+ import { getDesignLibraryStylesheetLinks, getContentStylesheetLink, LayoutService, LayoutServicePageState, } from '../layout';
4
+ import { getGroomedVariantIds } from '../personalize/utils';
5
+ import { personalizeLayout } from '../personalize/layout-personalizer';
6
+ import { ErrorPagesService, SitePathService, SitemapXmlService } from '../site';
7
+ import { createGraphQLClientFactory } from './utils';
8
+ import { NativeDataFetcher } from '../native-fetcher';
9
+ import { RobotsService } from '../site/robots-service';
10
+ import { DesignLibraryVariantGeneration } from '../editing/models';
11
+ import debug from '../debug';
12
+ /**
13
+ * Error page codes
14
+ * @public
15
+ */
16
+ export var ErrorPage;
17
+ (function (ErrorPage) {
18
+ ErrorPage["NotFound"] = "404";
19
+ ErrorPage["InternalServerError"] = "500";
20
+ })(ErrorPage || (ErrorPage = {}));
21
+ /**
22
+ * This is a generic content client that can be used by any framework.
23
+ * Use it to retrieve pages, preview data, dictionary and other data
24
+ * @public
25
+ */
26
+ export class SitecoreClient {
27
+ /**
28
+ * Init SitecoreClient
29
+ * @param {SitecoreClientInit} initOptions initOptions for the client, containing site and Sitecore connection details
30
+ */
31
+ constructor(initOptions) {
32
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
33
+ this.initOptions = initOptions;
34
+ this.clientFactory = this.getClientFactory();
35
+ this.graphQLClient = this.clientFactory({
36
+ debugger: debug.http,
37
+ });
38
+ const baseServiceOptions = this.getBaseServiceOptions();
39
+ this.layoutService =
40
+ (_b = (_a = initOptions.custom) === null || _a === void 0 ? void 0 : _a.layoutService) !== null && _b !== void 0 ? _b : this.getLayoutService(baseServiceOptions);
41
+ this.dictionaryService =
42
+ (_d = (_c = initOptions.custom) === null || _c === void 0 ? void 0 : _c.dictionaryService) !== null && _d !== void 0 ? _d : this.getDictionaryService(baseServiceOptions);
43
+ this.editingService = (_f = (_e = initOptions.custom) === null || _e === void 0 ? void 0 : _e.editingService) !== null && _f !== void 0 ? _f : this.getEditingService();
44
+ this.errorPagesService = (_h = (_g = initOptions.custom) === null || _g === void 0 ? void 0 : _g.errorPagesService) !== null && _h !== void 0 ? _h : this.getErrorPagesService();
45
+ this.sitePathService = (_k = (_j = initOptions.custom) === null || _j === void 0 ? void 0 : _j.sitePathService) !== null && _k !== void 0 ? _k : this.getSitePathService();
46
+ this.componentService = this.getComponentService();
47
+ }
48
+ /**
49
+ * Normalize path regardless of type
50
+ * @param {string | string[]} path string or string array path
51
+ * @returns {string} string path
52
+ */
53
+ parsePath(path) {
54
+ // join array path, while clearing extra slashes and ensure first slash
55
+ return typeof path === 'string'
56
+ ? path.startsWith('/')
57
+ ? path
58
+ : `/${path}`
59
+ : `/${path
60
+ .filter((part) => part !== '/')
61
+ .map((part) => part.replace(/^\/+/, '').replace(/\/+$/, ''))
62
+ .join('/')}`;
63
+ }
64
+ /**
65
+ * Execute a raw GraphQL request using the client's configured GraphQL Edge endpoint.
66
+ * This is a thin pass-through to the underlying {@link GraphQLClient.request},
67
+ * @param {string | DocumentNode} query GraphQL query
68
+ * @param {Record<string, unknown>} [variables] Optional variables bag
69
+ * @param {FetchOptions} [fetchOptions] Optional fetch overrides (e.g. fetch, headers)
70
+ */
71
+ getData(query, variables, fetchOptions) {
72
+ return this.graphQLClient.request(query, variables, fetchOptions);
73
+ }
74
+ /**
75
+ * Get page details for a route, with layout and other details
76
+ * @param {string} path route path
77
+ * @param {PageOptions} [pageOptions] site, language and personalization variant details for route
78
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
79
+ * @returns {Page | null} page details
80
+ */
81
+ async getPage(path, pageOptions, fetchOptions) {
82
+ var _a, _b, _c, _d;
83
+ const computedPath = this.parsePath(path);
84
+ const locale = (_a = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.locale) !== null && _a !== void 0 ? _a : this.initOptions.defaultLanguage;
85
+ const site = (_b = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.site) !== null && _b !== void 0 ? _b : this.initOptions.defaultSite;
86
+ // Fetch layout data, passing on req/res for SSR
87
+ const layout = await this.layoutService.fetchLayoutData(computedPath, {
88
+ locale,
89
+ site,
90
+ }, fetchOptions);
91
+ if (!layout.sitecore.route) {
92
+ return null;
93
+ }
94
+ else {
95
+ // Initialize links to be inserted on the page
96
+ if ((_c = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.personalize) === null || _c === void 0 ? void 0 : _c.variantId) {
97
+ // Modify layoutData to use specific variant(s) instead of default
98
+ // This will also set the variantId on the Sitecore context so that it is accessible here
99
+ personalizeLayout(layout, pageOptions.personalize.variantId, pageOptions.personalize.componentVariantIds);
100
+ }
101
+ return {
102
+ layout,
103
+ siteName: ((_d = layout.sitecore.context.site) === null || _d === void 0 ? void 0 : _d.name) || site,
104
+ locale,
105
+ mode: this.getPageMode(LayoutServicePageState.Normal),
106
+ };
107
+ }
108
+ }
109
+ /**
110
+ * Retrieves the head `<link>` elements for Sitecore styles and themes.
111
+ * @param {LayoutServiceData} layoutData - The layout data containing styles and themes.
112
+ * @param {object} [options] - Optional configuration for enabling styles and themes.
113
+ * @param {boolean} [options.enableStyles] - Whether to include content styles.
114
+ * @param {boolean} [options.enableThemes] - Whether to include theme styles.
115
+ * @returns {HTMLLink[]} An array of `<link>` elements for stylesheets.
116
+ */
117
+ getHeadLinks(layoutData, options = {}) {
118
+ const { enableStyles = true, enableThemes = true } = options;
119
+ const { contextId: serverContextId, clientContextId, edgeUrl } = this.initOptions.api.edge;
120
+ const headLinks = [];
121
+ const contextId = serverContextId || clientContextId;
122
+ if (enableStyles) {
123
+ const contentStyles = getContentStylesheetLink(layoutData, contextId, edgeUrl);
124
+ if (contentStyles)
125
+ headLinks.push(contentStyles);
126
+ }
127
+ if (enableThemes) {
128
+ headLinks.push(...getDesignLibraryStylesheetLinks(layoutData, contextId, edgeUrl));
129
+ }
130
+ return headLinks;
131
+ }
132
+ /**
133
+ * Retrieves dictionary phrases for a given site and locale.
134
+ * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
135
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
136
+ * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
137
+ */
138
+ async getDictionary(routeOptions, fetchOptions) {
139
+ const locale = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.locale) || this.initOptions.defaultLanguage;
140
+ const site = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.site) || this.initOptions.defaultSite;
141
+ return await this.dictionaryService.fetchDictionaryData(locale, site, fetchOptions);
142
+ }
143
+ /**
144
+ * Retrieves error pages for a given site and locale.
145
+ * @param {RouteOptions} routeOptions - Route options containing language and site name to load error pages
146
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
147
+ * @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
148
+ */
149
+ async getErrorPages(routeOptions, fetchOptions) {
150
+ const locale = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.locale) || this.initOptions.defaultLanguage;
151
+ const site = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.site) || this.initOptions.defaultSite;
152
+ return await this.errorPagesService.fetchErrorPages(site, locale, fetchOptions);
153
+ }
154
+ /**
155
+ * Retrieves preview page and layout details
156
+ * @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
157
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
158
+ * @returns {Page} preview page details
159
+ */
160
+ async getPreview(previewData, fetchOptions) {
161
+ var _a;
162
+ if (!previewData) {
163
+ console.error('Preview data missing');
164
+ return null;
165
+ }
166
+ // If we're in Pages preview (editing) mode, prefetch the editing data
167
+ const { site, itemId, language, version, layoutKind, mode } = previewData;
168
+ const variantIds = Array.isArray(previewData.variantIds)
169
+ ? previewData.variantIds
170
+ : previewData.variantIds.split(',');
171
+ const data = await this.editingService.fetchEditingData({
172
+ itemId,
173
+ language,
174
+ version,
175
+ layoutKind,
176
+ mode,
177
+ }, fetchOptions);
178
+ if (!data) {
179
+ throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(previewData)}`);
180
+ }
181
+ const page = {
182
+ locale: language,
183
+ layout: data.layoutData,
184
+ siteName: ((_a = data.layoutData.sitecore.context.site) === null || _a === void 0 ? void 0 : _a.name) || site,
185
+ mode: this.getPageMode(mode),
186
+ };
187
+ const personalizeData = getGroomedVariantIds(variantIds);
188
+ personalizeLayout(page.layout, personalizeData.variantId, personalizeData.componentVariantIds);
189
+ return page;
190
+ }
191
+ /**
192
+ * Get design library page details for Design Library mode of your app
193
+ * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
194
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
195
+ * @returns {Page} preview page for Design Library
196
+ */
197
+ async getDesignLibraryData(designLibData, fetchOptions) {
198
+ var _a;
199
+ if (!this.initOptions.api.local) {
200
+ throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
201
+ }
202
+ const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode, generation, } = designLibData;
203
+ const componentData = await this.componentService.fetchComponentData(Object.assign({ siteName: site, itemId,
204
+ language,
205
+ componentUid,
206
+ renderingId,
207
+ dataSourceId,
208
+ version,
209
+ mode }, (generation ? { generation } : {})), fetchOptions);
210
+ if (!componentData) {
211
+ throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(designLibData)}`);
212
+ }
213
+ const page = {
214
+ locale: designLibData.language,
215
+ layout: componentData,
216
+ siteName: ((_a = componentData.sitecore.context.site) === null || _a === void 0 ? void 0 : _a.name) || site,
217
+ mode: this.getPageMode(mode, generation),
218
+ };
219
+ return page;
220
+ }
221
+ /**
222
+ * Get error page details for a given error code
223
+ * @param {ErrorPage} code - The error code to get the error page for
224
+ * @param {Partial<RouteOptions>} pageOptions - The page options to get the error page for
225
+ * @param {FetchOptions} [fetchOptions] - Additional fetch fetch options to override GraphQL requests
226
+ * @returns {Promise<Page | null>} A promise that resolves to the error page details or null if not found
227
+ */
228
+ async getErrorPage(code, pageOptions, fetchOptions) {
229
+ var _a, _b;
230
+ const locale = (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.locale) || this.initOptions.defaultLanguage;
231
+ const site = (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.site) || this.initOptions.defaultSite;
232
+ const result = await this.getErrorPages({
233
+ site,
234
+ locale,
235
+ }, fetchOptions);
236
+ let layout = null;
237
+ switch (code) {
238
+ case ErrorPage.NotFound:
239
+ layout = ((_a = result === null || result === void 0 ? void 0 : result.notFoundPage) === null || _a === void 0 ? void 0 : _a.rendered) || null;
240
+ break;
241
+ case ErrorPage.InternalServerError:
242
+ layout = ((_b = result === null || result === void 0 ? void 0 : result.serverErrorPage) === null || _b === void 0 ? void 0 : _b.rendered) || null;
243
+ break;
244
+ default:
245
+ return null;
246
+ }
247
+ if (!layout) {
248
+ return null;
249
+ }
250
+ return {
251
+ layout,
252
+ locale,
253
+ mode: this.getPageMode(LayoutServicePageState.Normal),
254
+ siteName: site,
255
+ };
256
+ }
257
+ /**
258
+ * Retrieves the static paths for pages based on the given languages.
259
+ * @param {string[]} sites - An array of site names to fetch routes for.
260
+ * @param {string[]} [languages] - An optional array of language codes to generate paths for.
261
+ * @param {FetchOptions} [fetchOptions] - Additional fetch options.
262
+ * @returns {Promise<StaticPath[]>} A promise that resolves to an array of static paths.
263
+ */
264
+ async getPagePaths(sites, languages, fetchOptions) {
265
+ return this.sitePathService.fetchSiteRoutes(sites, languages || [], fetchOptions);
266
+ }
267
+ /**
268
+ * Retrieves sitemap XML content - either a specific sitemap or the index of all sitemaps.
269
+ * @param {SitemapXmlOptions} reqOptions - Options for sitemap retrieval
270
+ * @param {FetchOptions} [fetchOptions] - Additional fetch options.
271
+ * @returns {Promise<string>} Promise resolving to the sitemap XML content as string
272
+ * @throws {Error} Throws 'REDIRECT_404' if requested sitemap is not found
273
+ */
274
+ async getSiteMap(reqOptions, fetchOptions) {
275
+ const { reqHost, reqProtocol, id, siteName } = reqOptions;
276
+ // create sitemap graphql service
277
+ const sitemapXmlService = this.getGraphqlSitemapXMLService(siteName || this.initOptions.defaultSite);
278
+ // The id is present if url has sitemap-{n}.xml type.
279
+ // The id can be null if it's index sitemap.xml request
280
+ const sitemapPath = await sitemapXmlService.getSitemap(id);
281
+ // regular sitemap
282
+ if (sitemapPath) {
283
+ try {
284
+ const fetcher = new NativeDataFetcher();
285
+ const xmlResponse = await fetcher.fetch(sitemapPath);
286
+ if (!xmlResponse.data) {
287
+ throw new Error('REDIRECT_404');
288
+ }
289
+ return xmlResponse.data;
290
+ // eslint-disable-next-line no-unused-vars
291
+ }
292
+ catch (error) {
293
+ throw new Error('REDIRECT_404');
294
+ }
295
+ }
296
+ // index /sitemap.xml that includes links to all sitemaps
297
+ const sitemaps = await sitemapXmlService.fetchSitemaps(fetchOptions);
298
+ if (!sitemaps.length) {
299
+ throw new Error('REDIRECT_404');
300
+ }
299
301
  return `<?xml version="1.0" encoding="UTF-8"?>
300
302
  <sitemapindex xmlns="http://sitemaps.org/schemas/sitemap/0.9">
301
- ${sitemaps
302
- .map((item) => {
303
- const parseUrl = item.split('/');
304
- const lastSegment = parseUrl[parseUrl.length - 1];
305
- const escapedUrl = `${reqProtocol}://${reqHost}/${lastSegment}`.replace(/&/g, '&amp;');
306
- return `<sitemap><loc>${escapedUrl}</loc></sitemap>`;
307
- })
303
+ ${sitemaps
304
+ .map((item) => {
305
+ const parseUrl = item.split('/');
306
+ const lastSegment = parseUrl[parseUrl.length - 1];
307
+ const escapedUrl = `${reqProtocol}://${reqHost}/${lastSegment}`.replace(/&/g, '&amp;');
308
+ return `<sitemap><loc>${escapedUrl}</loc></sitemap>`;
309
+ })
308
310
  .join('')}
309
- </sitemapindex>`;
310
- }
311
- /**
312
- * Retrieves the robots.txt content for a given site name.
313
- * @param {string} siteName - The name of the site to retrieve the robots.txt for.
314
- * @param {FetchOptions} [fetchOptions] - Optional fetch options.
315
- * @returns {Promise<string | null>} A promise that resolves to the robots.txt content,
316
- * or null if no content is found.
317
- */
318
- async getRobots(siteName, fetchOptions) {
319
- const robotsService = this.getRobotsService(siteName || this.initOptions.defaultSite);
320
- const content = await robotsService.fetchRobots(fetchOptions);
321
- return content || null;
322
- }
323
- /**
324
- * Factory methods for creating dependencies
325
- * Subclasses can override these to provide custom implementations.
326
- */
327
- getGraphqlSitemapXMLService(siteName) {
328
- return new SitemapXmlService({
329
- clientFactory: this.clientFactory,
330
- siteName,
331
- });
332
- }
333
- getRobotsService(siteName) {
334
- return new RobotsService({
335
- clientFactory: this.clientFactory,
336
- siteName,
337
- });
338
- }
339
- getBaseServiceOptions() {
340
- return {
341
- defaultSite: this.initOptions.defaultSite,
342
- clientFactory: this.clientFactory,
343
- retries: this.initOptions.retries,
344
- };
345
- }
346
- /**
347
- * Get page mode based on mode name
348
- * @param {PageModeName} mode - The mode name to get the page mode for
349
- * @param { DesignLibraryVariantGeneration} generation - The variant generation mode, if applicable
350
- * @returns {PageMode} The page mode
351
- */
352
- getPageMode(mode, generation) {
353
- const pageMode = {
354
- name: mode,
355
- isNormal: false,
356
- isPreview: false,
357
- isEditing: false,
358
- isDesignLibrary: false,
359
- designLibrary: { isVariantGeneration: false },
360
- };
361
- switch (mode) {
362
- case LayoutServicePageState.Normal:
363
- pageMode.isNormal = true;
364
- break;
365
- case LayoutServicePageState.Preview:
366
- pageMode.isPreview = true;
367
- break;
368
- case LayoutServicePageState.Edit:
369
- pageMode.isEditing = true;
370
- break;
371
- case DesignLibraryMode.Normal:
372
- pageMode.isDesignLibrary = true;
373
- break;
374
- case DesignLibraryMode.Metadata:
375
- pageMode.isDesignLibrary = true;
376
- pageMode.isEditing = true;
377
- break;
378
- default:
379
- break;
380
- }
381
- if (pageMode.isDesignLibrary && generation === DesignLibraryVariantGeneration.Variant) {
382
- pageMode.designLibrary.isVariantGeneration = true;
383
- pageMode.isEditing = true;
384
- }
385
- return pageMode;
386
- }
387
- getClientFactory() {
388
- const graphQLOptions = {
389
- api: this.initOptions.api,
390
- retries: this.initOptions.retries.count,
391
- retryStrategy: this.initOptions.retries.retryStrategy,
392
- };
393
- return createGraphQLClientFactory(graphQLOptions);
394
- }
395
- getLayoutService(baseOptions) {
396
- return new LayoutService(Object.assign(Object.assign({}, baseOptions), { formatLayoutQuery: this.initOptions.layout.formatLayoutQuery }));
397
- }
398
- getDictionaryService(baseOptions) {
399
- return new DictionaryService(Object.assign(Object.assign({}, baseOptions), { cacheEnabled: this.initOptions.dictionary.caching.enabled, cacheTimeout: this.initOptions.dictionary.caching.timeout }));
400
- }
401
- getEditingService() {
402
- return new EditingService({ clientFactory: this.clientFactory });
403
- }
404
- getErrorPagesService() {
405
- return new ErrorPagesService(Object.assign(Object.assign({}, this.initOptions), { language: this.initOptions.defaultLanguage, clientFactory: this.clientFactory }));
406
- }
407
- getComponentService() {
408
- return new ComponentLayoutService(this.initOptions.api.edge);
409
- }
410
- getSitePathService() {
411
- return new SitePathService({
412
- clientFactory: this.clientFactory,
413
- });
414
- }
415
- }
311
+ </sitemapindex>`;
312
+ }
313
+ /**
314
+ * Retrieves the robots.txt content for a given site name.
315
+ * @param {string} siteName - The name of the site to retrieve the robots.txt for.
316
+ * @param {FetchOptions} [fetchOptions] - Optional fetch options.
317
+ * @returns {Promise<string | null>} A promise that resolves to the robots.txt content,
318
+ * or null if no content is found.
319
+ */
320
+ async getRobots(siteName, fetchOptions) {
321
+ const robotsService = this.getRobotsService(siteName || this.initOptions.defaultSite);
322
+ const content = await robotsService.fetchRobots(fetchOptions);
323
+ return content || null;
324
+ }
325
+ /**
326
+ * Factory methods for creating dependencies
327
+ * Subclasses can override these to provide custom implementations.
328
+ */
329
+ getGraphqlSitemapXMLService(siteName) {
330
+ return new SitemapXmlService({
331
+ clientFactory: this.clientFactory,
332
+ siteName,
333
+ });
334
+ }
335
+ getRobotsService(siteName) {
336
+ return new RobotsService({
337
+ clientFactory: this.clientFactory,
338
+ siteName,
339
+ });
340
+ }
341
+ getBaseServiceOptions() {
342
+ return {
343
+ defaultSite: this.initOptions.defaultSite,
344
+ clientFactory: this.clientFactory,
345
+ retries: this.initOptions.retries,
346
+ };
347
+ }
348
+ /**
349
+ * Get page mode based on mode name
350
+ * @param {PageModeName} mode - The mode name to get the page mode for
351
+ * @param { DesignLibraryVariantGeneration} generation - The variant generation mode, if applicable
352
+ * @returns {PageMode} The page mode
353
+ */
354
+ getPageMode(mode, generation) {
355
+ const pageMode = {
356
+ name: mode,
357
+ isNormal: false,
358
+ isPreview: false,
359
+ isEditing: false,
360
+ isDesignLibrary: false,
361
+ designLibrary: { isVariantGeneration: false },
362
+ };
363
+ switch (mode) {
364
+ case LayoutServicePageState.Normal:
365
+ pageMode.isNormal = true;
366
+ break;
367
+ case LayoutServicePageState.Preview:
368
+ pageMode.isPreview = true;
369
+ break;
370
+ case LayoutServicePageState.Edit:
371
+ pageMode.isEditing = true;
372
+ break;
373
+ case DesignLibraryMode.Normal:
374
+ pageMode.isDesignLibrary = true;
375
+ break;
376
+ case DesignLibraryMode.Metadata:
377
+ pageMode.isDesignLibrary = true;
378
+ pageMode.isEditing = true;
379
+ break;
380
+ default:
381
+ break;
382
+ }
383
+ if (pageMode.isDesignLibrary && generation === DesignLibraryVariantGeneration.Variant) {
384
+ pageMode.designLibrary.isVariantGeneration = true;
385
+ pageMode.isEditing = true;
386
+ }
387
+ return pageMode;
388
+ }
389
+ getClientFactory() {
390
+ const graphQLOptions = {
391
+ api: this.initOptions.api,
392
+ retries: this.initOptions.retries.count,
393
+ retryStrategy: this.initOptions.retries.retryStrategy,
394
+ };
395
+ return createGraphQLClientFactory(graphQLOptions);
396
+ }
397
+ getLayoutService(baseOptions) {
398
+ return new LayoutService(Object.assign(Object.assign({}, baseOptions), { formatLayoutQuery: this.initOptions.layout.formatLayoutQuery }));
399
+ }
400
+ getDictionaryService(baseOptions) {
401
+ return new DictionaryService(Object.assign(Object.assign({}, baseOptions), { cacheEnabled: this.initOptions.dictionary.caching.enabled, cacheTimeout: this.initOptions.dictionary.caching.timeout }));
402
+ }
403
+ getEditingService() {
404
+ return new EditingService({ clientFactory: this.clientFactory });
405
+ }
406
+ getErrorPagesService() {
407
+ return new ErrorPagesService(Object.assign(Object.assign({}, this.initOptions), { language: this.initOptions.defaultLanguage, clientFactory: this.clientFactory }));
408
+ }
409
+ getComponentService() {
410
+ return new ComponentLayoutService(this.initOptions.api.edge);
411
+ }
412
+ getSitePathService() {
413
+ return new SitePathService({
414
+ clientFactory: this.clientFactory,
415
+ });
416
+ }
417
+ }