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