@sitecore-content-sdk/core 1.5.0 → 2.0.0-canary.10

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 (337) hide show
  1. package/LICENSE.txt +202 -202
  2. package/dist/cjs/constants.js +7 -21
  3. package/dist/cjs/debug.js +14 -18
  4. package/dist/cjs/graphql-request-client.js +10 -5
  5. package/dist/cjs/index.js +3 -7
  6. package/dist/cjs/native-fetcher.js +1 -1
  7. package/dist/cjs/{utils → tools}/ensurePath.js +1 -0
  8. package/dist/cjs/{media/index.js → tools/index-node.js} +27 -3
  9. package/dist/cjs/tools/index.js +28 -72
  10. package/dist/cjs/tools/{generateMetadata.js → metadata/generateMetadata.js} +2 -2
  11. package/dist/cjs/tools/metadata/index.js +5 -0
  12. package/dist/cjs/{editing → tools/metadata}/metadata.js +1 -6
  13. package/dist/cjs/tools/normalize-env-value.js +22 -0
  14. package/dist/cjs/{utils → tools}/normalize-url.js +6 -0
  15. package/dist/cjs/tools/resolve-edge-url.js +95 -0
  16. package/dist/cjs/{utils → tools}/utils.js +6 -64
  17. package/dist/esm/constants.js +6 -20
  18. package/dist/esm/debug.js +13 -17
  19. package/dist/esm/graphql-request-client.js +10 -5
  20. package/dist/esm/index.js +1 -6
  21. package/dist/esm/native-fetcher.js +1 -1
  22. package/dist/esm/{utils → tools}/ensurePath.js +1 -0
  23. package/dist/esm/tools/index-node.js +22 -0
  24. package/dist/esm/tools/index.js +6 -28
  25. package/dist/esm/tools/{generateMetadata.js → metadata/generateMetadata.js} +2 -2
  26. package/dist/esm/tools/metadata/index.js +1 -0
  27. package/dist/esm/{editing → tools/metadata}/metadata.js +1 -6
  28. package/dist/esm/tools/normalize-env-value.js +19 -0
  29. package/dist/esm/tools/normalize-url.js +7 -0
  30. package/dist/esm/tools/resolve-edge-url.js +89 -0
  31. package/dist/esm/{utils → tools}/utils.js +5 -61
  32. package/node-tools.d.ts +1 -0
  33. package/package.json +98 -163
  34. package/types/constants.d.ts +6 -17
  35. package/types/constants.d.ts.map +1 -1
  36. package/types/debug.d.ts +13 -13
  37. package/types/debug.d.ts.map +1 -1
  38. package/types/graphql-request-client.d.ts +8 -2
  39. package/types/graphql-request-client.d.ts.map +1 -1
  40. package/types/index.d.ts +3 -6
  41. package/types/index.d.ts.map +1 -1
  42. package/types/models.d.ts +0 -31
  43. package/types/models.d.ts.map +1 -1
  44. package/types/{utils → tools}/ensurePath.d.ts +1 -0
  45. package/types/tools/ensurePath.d.ts.map +1 -0
  46. package/types/{utils → tools}/globalCache.d.ts.map +1 -1
  47. package/types/tools/index-node.d.ts +14 -0
  48. package/types/tools/index-node.d.ts.map +1 -0
  49. package/types/tools/index.d.ts +5 -21
  50. package/types/tools/index.d.ts.map +1 -1
  51. package/types/tools/is-server.d.ts.map +1 -0
  52. package/types/tools/metadata/generateMetadata.d.ts.map +1 -0
  53. package/types/tools/metadata/index.d.ts +3 -0
  54. package/types/tools/metadata/index.d.ts.map +1 -0
  55. package/types/{editing → tools/metadata}/metadata.d.ts +9 -1
  56. package/types/tools/metadata/metadata.d.ts.map +1 -0
  57. package/types/tools/normalize-env-value.d.ts +10 -0
  58. package/types/tools/normalize-env-value.d.ts.map +1 -0
  59. package/types/tools/normalize-url.d.ts +8 -0
  60. package/types/tools/normalize-url.d.ts.map +1 -0
  61. package/types/tools/resolve-edge-url.d.ts +52 -0
  62. package/types/tools/resolve-edge-url.d.ts.map +1 -0
  63. package/types/{utils → tools}/timeout-promise.d.ts.map +1 -1
  64. package/types/{utils → tools}/utils.d.ts +6 -26
  65. package/types/tools/utils.d.ts.map +1 -0
  66. package/client.d.ts +0 -1
  67. package/codegen.d.ts +0 -1
  68. package/config-cli.d.ts +0 -1
  69. package/config.d.ts +0 -1
  70. package/dist/cjs/client/constants.js +0 -7
  71. package/dist/cjs/client/edge-proxy.js +0 -24
  72. package/dist/cjs/client/index.js +0 -15
  73. package/dist/cjs/client/models.js +0 -2
  74. package/dist/cjs/client/sitecore-client.js +0 -424
  75. package/dist/cjs/client/utils.js +0 -51
  76. package/dist/cjs/config/define-config.js +0 -195
  77. package/dist/cjs/config/index.js +0 -7
  78. package/dist/cjs/config/models.js +0 -12
  79. package/dist/cjs/config-cli/define-cli-config.js +0 -23
  80. package/dist/cjs/config-cli/index.js +0 -7
  81. package/dist/cjs/config-cli/models.js +0 -8
  82. package/dist/cjs/editing/codegen/index.js +0 -15
  83. package/dist/cjs/editing/codegen/preview.js +0 -306
  84. package/dist/cjs/editing/component-layout-service.js +0 -63
  85. package/dist/cjs/editing/design-library.js +0 -190
  86. package/dist/cjs/editing/editing-service.js +0 -81
  87. package/dist/cjs/editing/index.js +0 -34
  88. package/dist/cjs/editing/models.js +0 -44
  89. package/dist/cjs/editing/utils.js +0 -108
  90. package/dist/cjs/form/form.js +0 -81
  91. package/dist/cjs/form/index.js +0 -7
  92. package/dist/cjs/i18n/dictionary-service.js +0 -144
  93. package/dist/cjs/i18n/index.js +0 -7
  94. package/dist/cjs/i18n/utils.js +0 -16
  95. package/dist/cjs/layout/content-styles.js +0 -72
  96. package/dist/cjs/layout/index.js +0 -24
  97. package/dist/cjs/layout/layout-service.js +0 -68
  98. package/dist/cjs/layout/models.js +0 -39
  99. package/dist/cjs/layout/themes.js +0 -76
  100. package/dist/cjs/layout/utils.js +0 -117
  101. package/dist/cjs/media/media-api.js +0 -100
  102. package/dist/cjs/personalize/index.js +0 -15
  103. package/dist/cjs/personalize/layout-personalizer.js +0 -98
  104. package/dist/cjs/personalize/personalize-service.js +0 -109
  105. package/dist/cjs/personalize/utils.js +0 -143
  106. package/dist/cjs/site/error-pages-service.js +0 -82
  107. package/dist/cjs/site/index.js +0 -26
  108. package/dist/cjs/site/models.js +0 -2
  109. package/dist/cjs/site/redirects-service.js +0 -108
  110. package/dist/cjs/site/robots-service.js +0 -74
  111. package/dist/cjs/site/site-resolver.js +0 -73
  112. package/dist/cjs/site/siteinfo-service.js +0 -94
  113. package/dist/cjs/site/sitemap-xml-service.js +0 -92
  114. package/dist/cjs/site/sitepath-service.js +0 -201
  115. package/dist/cjs/site/utils.js +0 -55
  116. package/dist/cjs/sitecore-service-base.js +0 -36
  117. package/dist/cjs/tools/codegen/component-generation.js +0 -52
  118. package/dist/cjs/tools/codegen/extract-files.js +0 -105
  119. package/dist/cjs/tools/codegen/import-map.js +0 -411
  120. package/dist/cjs/tools/codegen/utils.js +0 -418
  121. package/dist/cjs/tools/generate-map.js +0 -2
  122. package/dist/cjs/tools/generateSites.js +0 -59
  123. package/dist/cjs/tools/scaffold.js +0 -62
  124. package/dist/cjs/tools/templating/components.js +0 -96
  125. package/dist/cjs/tools/templating/index.js +0 -11
  126. package/dist/cjs/tools/templating/plugins.js +0 -80
  127. package/dist/cjs/tools/templating/utils.js +0 -67
  128. package/dist/cjs/utils/env.js +0 -28
  129. package/dist/cjs/utils/index.js +0 -26
  130. package/dist/esm/client/constants.js +0 -4
  131. package/dist/esm/client/edge-proxy.js +0 -19
  132. package/dist/esm/client/index.js +0 -5
  133. package/dist/esm/client/models.js +0 -1
  134. package/dist/esm/client/sitecore-client.js +0 -417
  135. package/dist/esm/client/utils.js +0 -47
  136. package/dist/esm/config/define-config.js +0 -189
  137. package/dist/esm/config/index.js +0 -2
  138. package/dist/esm/config/models.js +0 -9
  139. package/dist/esm/config-cli/define-cli-config.js +0 -19
  140. package/dist/esm/config-cli/index.js +0 -2
  141. package/dist/esm/config-cli/models.js +0 -5
  142. package/dist/esm/editing/codegen/index.js +0 -1
  143. package/dist/esm/editing/codegen/preview.js +0 -288
  144. package/dist/esm/editing/component-layout-service.js +0 -56
  145. package/dist/esm/editing/design-library.js +0 -178
  146. package/dist/esm/editing/editing-service.js +0 -74
  147. package/dist/esm/editing/index.js +0 -6
  148. package/dist/esm/editing/models.js +0 -41
  149. package/dist/esm/editing/utils.js +0 -98
  150. package/dist/esm/form/form.js +0 -72
  151. package/dist/esm/form/index.js +0 -1
  152. package/dist/esm/i18n/dictionary-service.js +0 -137
  153. package/dist/esm/i18n/index.js +0 -2
  154. package/dist/esm/i18n/utils.js +0 -13
  155. package/dist/esm/layout/content-styles.js +0 -64
  156. package/dist/esm/layout/index.js +0 -6
  157. package/dist/esm/layout/layout-service.js +0 -61
  158. package/dist/esm/layout/models.js +0 -36
  159. package/dist/esm/layout/themes.js +0 -71
  160. package/dist/esm/layout/utils.js +0 -109
  161. package/dist/esm/media/index.js +0 -2
  162. package/dist/esm/media/media-api.js +0 -90
  163. package/dist/esm/personalize/index.js +0 -3
  164. package/dist/esm/personalize/layout-personalizer.js +0 -93
  165. package/dist/esm/personalize/personalize-service.js +0 -102
  166. package/dist/esm/personalize/utils.js +0 -135
  167. package/dist/esm/site/error-pages-service.js +0 -75
  168. package/dist/esm/site/index.js +0 -8
  169. package/dist/esm/site/models.js +0 -1
  170. package/dist/esm/site/redirects-service.js +0 -101
  171. package/dist/esm/site/robots-service.js +0 -67
  172. package/dist/esm/site/site-resolver.js +0 -69
  173. package/dist/esm/site/siteinfo-service.js +0 -87
  174. package/dist/esm/site/sitemap-xml-service.js +0 -85
  175. package/dist/esm/site/sitepath-service.js +0 -193
  176. package/dist/esm/site/utils.js +0 -49
  177. package/dist/esm/sitecore-service-base.js +0 -29
  178. package/dist/esm/tools/codegen/component-generation.js +0 -44
  179. package/dist/esm/tools/codegen/extract-files.js +0 -99
  180. package/dist/esm/tools/codegen/import-map.js +0 -368
  181. package/dist/esm/tools/codegen/utils.js +0 -373
  182. package/dist/esm/tools/generate-map.js +0 -1
  183. package/dist/esm/tools/generateSites.js +0 -52
  184. package/dist/esm/tools/scaffold.js +0 -54
  185. package/dist/esm/tools/templating/components.js +0 -59
  186. package/dist/esm/tools/templating/index.js +0 -3
  187. package/dist/esm/tools/templating/plugins.js +0 -72
  188. package/dist/esm/tools/templating/utils.js +0 -59
  189. package/dist/esm/utils/env.js +0 -24
  190. package/dist/esm/utils/index.js +0 -4
  191. package/dist/esm/utils/normalize-url.js +0 -1
  192. package/editing.d.ts +0 -1
  193. package/i18n.d.ts +0 -1
  194. package/layout.d.ts +0 -1
  195. package/media.d.ts +0 -1
  196. package/personalize.d.ts +0 -1
  197. package/site.d.ts +0 -1
  198. package/types/client/constants.d.ts +0 -5
  199. package/types/client/constants.d.ts.map +0 -1
  200. package/types/client/edge-proxy.d.ts +0 -18
  201. package/types/client/edge-proxy.d.ts.map +0 -1
  202. package/types/client/index.d.ts +0 -8
  203. package/types/client/index.d.ts.map +0 -1
  204. package/types/client/models.d.ts +0 -21
  205. package/types/client/models.d.ts.map +0 -1
  206. package/types/client/sitecore-client.d.ts +0 -338
  207. package/types/client/sitecore-client.d.ts.map +0 -1
  208. package/types/client/utils.d.ts +0 -15
  209. package/types/client/utils.d.ts.map +0 -1
  210. package/types/config/define-config.d.ts +0 -20
  211. package/types/config/define-config.d.ts.map +0 -1
  212. package/types/config/index.d.ts +0 -3
  213. package/types/config/index.d.ts.map +0 -1
  214. package/types/config/models.d.ts +0 -287
  215. package/types/config/models.d.ts.map +0 -1
  216. package/types/config-cli/define-cli-config.d.ts +0 -9
  217. package/types/config-cli/define-cli-config.d.ts.map +0 -1
  218. package/types/config-cli/index.d.ts +0 -3
  219. package/types/config-cli/index.d.ts.map +0 -1
  220. package/types/config-cli/models.d.ts +0 -6
  221. package/types/config-cli/models.d.ts.map +0 -1
  222. package/types/editing/codegen/index.d.ts +0 -2
  223. package/types/editing/codegen/index.d.ts.map +0 -1
  224. package/types/editing/codegen/preview.d.ts +0 -289
  225. package/types/editing/codegen/preview.d.ts.map +0 -1
  226. package/types/editing/component-layout-service.d.ts +0 -84
  227. package/types/editing/component-layout-service.d.ts.map +0 -1
  228. package/types/editing/design-library.d.ts +0 -118
  229. package/types/editing/design-library.d.ts.map +0 -1
  230. package/types/editing/editing-service.d.ts +0 -72
  231. package/types/editing/editing-service.d.ts.map +0 -1
  232. package/types/editing/index.d.ts +0 -7
  233. package/types/editing/index.d.ts.map +0 -1
  234. package/types/editing/metadata.d.ts.map +0 -1
  235. package/types/editing/models.d.ts +0 -103
  236. package/types/editing/models.d.ts.map +0 -1
  237. package/types/editing/utils.d.ts +0 -91
  238. package/types/editing/utils.d.ts.map +0 -1
  239. package/types/form/form.d.ts +0 -25
  240. package/types/form/form.d.ts.map +0 -1
  241. package/types/form/index.d.ts +0 -2
  242. package/types/form/index.d.ts.map +0 -1
  243. package/types/i18n/dictionary-service.d.ts +0 -135
  244. package/types/i18n/dictionary-service.d.ts.map +0 -1
  245. package/types/i18n/index.d.ts +0 -3
  246. package/types/i18n/index.d.ts.map +0 -1
  247. package/types/i18n/utils.d.ts +0 -9
  248. package/types/i18n/utils.d.ts.map +0 -1
  249. package/types/layout/content-styles.d.ts +0 -20
  250. package/types/layout/content-styles.d.ts.map +0 -1
  251. package/types/layout/index.d.ts +0 -6
  252. package/types/layout/index.d.ts.map +0 -1
  253. package/types/layout/layout-service.d.ts +0 -45
  254. package/types/layout/layout-service.d.ts.map +0 -1
  255. package/types/layout/models.d.ts +0 -174
  256. package/types/layout/models.d.ts.map +0 -1
  257. package/types/layout/themes.d.ts +0 -13
  258. package/types/layout/themes.d.ts.map +0 -1
  259. package/types/layout/utils.d.ts +0 -56
  260. package/types/layout/utils.d.ts.map +0 -1
  261. package/types/media/index.d.ts +0 -3
  262. package/types/media/index.d.ts.map +0 -1
  263. package/types/media/media-api.d.ts +0 -60
  264. package/types/media/media-api.d.ts.map +0 -1
  265. package/types/personalize/index.d.ts +0 -4
  266. package/types/personalize/index.d.ts.map +0 -1
  267. package/types/personalize/layout-personalizer.d.ts +0 -29
  268. package/types/personalize/layout-personalizer.d.ts.map +0 -1
  269. package/types/personalize/personalize-service.d.ts +0 -90
  270. package/types/personalize/personalize-service.d.ts.map +0 -1
  271. package/types/personalize/utils.d.ts +0 -78
  272. package/types/personalize/utils.d.ts.map +0 -1
  273. package/types/site/error-pages-service.d.ts +0 -64
  274. package/types/site/error-pages-service.d.ts.map +0 -1
  275. package/types/site/index.d.ts +0 -10
  276. package/types/site/index.d.ts.map +0 -1
  277. package/types/site/models.d.ts +0 -23
  278. package/types/site/models.d.ts.map +0 -1
  279. package/types/site/redirects-service.d.ts +0 -92
  280. package/types/site/redirects-service.d.ts.map +0 -1
  281. package/types/site/robots-service.d.ts +0 -57
  282. package/types/site/robots-service.d.ts.map +0 -1
  283. package/types/site/site-resolver.d.ts +0 -28
  284. package/types/site/site-resolver.d.ts.map +0 -1
  285. package/types/site/siteinfo-service.d.ts +0 -65
  286. package/types/site/siteinfo-service.d.ts.map +0 -1
  287. package/types/site/sitemap-xml-service.d.ts +0 -63
  288. package/types/site/sitemap-xml-service.d.ts.map +0 -1
  289. package/types/site/sitepath-service.d.ts +0 -137
  290. package/types/site/sitepath-service.d.ts.map +0 -1
  291. package/types/site/utils.d.ts +0 -41
  292. package/types/site/utils.d.ts.map +0 -1
  293. package/types/sitecore-service-base.d.ts +0 -31
  294. package/types/sitecore-service-base.d.ts.map +0 -1
  295. package/types/tools/codegen/component-generation.d.ts +0 -50
  296. package/types/tools/codegen/component-generation.d.ts.map +0 -1
  297. package/types/tools/codegen/extract-files.d.ts +0 -24
  298. package/types/tools/codegen/extract-files.d.ts.map +0 -1
  299. package/types/tools/codegen/import-map.d.ts +0 -102
  300. package/types/tools/codegen/import-map.d.ts.map +0 -1
  301. package/types/tools/codegen/utils.d.ts +0 -76
  302. package/types/tools/codegen/utils.d.ts.map +0 -1
  303. package/types/tools/generate-map.d.ts +0 -36
  304. package/types/tools/generate-map.d.ts.map +0 -1
  305. package/types/tools/generateMetadata.d.ts.map +0 -1
  306. package/types/tools/generateSites.d.ts +0 -25
  307. package/types/tools/generateSites.d.ts.map +0 -1
  308. package/types/tools/scaffold.d.ts +0 -27
  309. package/types/tools/scaffold.d.ts.map +0 -1
  310. package/types/tools/templating/components.d.ts +0 -104
  311. package/types/tools/templating/components.d.ts.map +0 -1
  312. package/types/tools/templating/index.d.ts +0 -4
  313. package/types/tools/templating/index.d.ts.map +0 -1
  314. package/types/tools/templating/plugins.d.ts +0 -71
  315. package/types/tools/templating/plugins.d.ts.map +0 -1
  316. package/types/tools/templating/utils.d.ts +0 -42
  317. package/types/tools/templating/utils.d.ts.map +0 -1
  318. package/types/utils/ensurePath.d.ts.map +0 -1
  319. package/types/utils/env.d.ts +0 -9
  320. package/types/utils/env.d.ts.map +0 -1
  321. package/types/utils/index.d.ts +0 -5
  322. package/types/utils/index.d.ts.map +0 -1
  323. package/types/utils/is-server.d.ts.map +0 -1
  324. package/types/utils/normalize-url.d.ts +0 -2
  325. package/types/utils/normalize-url.d.ts.map +0 -1
  326. package/types/utils/utils.d.ts.map +0 -1
  327. package/utils.d.ts +0 -1
  328. /package/dist/cjs/{utils → tools}/globalCache.js +0 -0
  329. /package/dist/cjs/{utils → tools}/is-server.js +0 -0
  330. /package/dist/cjs/{utils → tools}/timeout-promise.js +0 -0
  331. /package/dist/esm/{utils → tools}/globalCache.js +0 -0
  332. /package/dist/esm/{utils → tools}/is-server.js +0 -0
  333. /package/dist/esm/{utils → tools}/timeout-promise.js +0 -0
  334. /package/types/{utils → tools}/globalCache.d.ts +0 -0
  335. /package/types/{utils → tools}/is-server.d.ts +0 -0
  336. /package/types/tools/{generateMetadata.d.ts → metadata/generateMetadata.d.ts} +0 -0
  337. /package/types/{utils → tools}/timeout-promise.d.ts +0 -0
@@ -1,80 +0,0 @@
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.ModuleType = void 0;
7
- exports.getPluginList = getPluginList;
8
- exports.generatePlugins = generatePlugins;
9
- const fs_1 = __importDefault(require("fs"));
10
- const path_1 = __importDefault(require("path"));
11
- const utils_1 = require("./utils");
12
- /**
13
- * Identifies the format of the module to be compiled
14
- * @public
15
- */
16
- var ModuleType;
17
- (function (ModuleType) {
18
- ModuleType[ModuleType["CJS"] = 0] = "CJS";
19
- ModuleType[ModuleType["ESM"] = 1] = "ESM";
20
- })(ModuleType || (exports.ModuleType = ModuleType = {}));
21
- /**
22
- * Get list of plugins from @var path
23
- * Returns a list of plugins in the following format:
24
- * {
25
- * path: 'path/to/plugin/foo',
26
- * name: 'fooPlugin'
27
- * }
28
- * @example getPluginList('src/foo/plugins', 'Foo')
29
- * @param {object} definition plugin definition
30
- * @param {string} definition.path path to get plugin from
31
- * @param {string} definition.pluginName plugin name
32
- * @param {boolean} [definition.silent] whether to suppress console output
33
- */
34
- function getPluginList({ path, pluginName, silent = false, }) {
35
- const plugins = (0, utils_1.getItems)({
36
- path,
37
- resolveItem: (path, name) => ({
38
- path: `${path}/${name}`,
39
- name: `${name.replace(/-./g, (x) => x[1].toUpperCase())}Plugin`,
40
- }),
41
- cb: (name) => !silent && console.debug(`Registering ${pluginName} plugin ${name}`),
42
- });
43
- return plugins;
44
- }
45
- /**
46
- * Generates the plugins file and saves it to the filesystem.
47
- * By convention, we expect to find plugins under {pluginName}/plugins/** (subfolders are searched recursively).
48
- * generated file will be saved to @var {distPath} and will contain a list of plugins in the following format:
49
- * CJS: exports.fooPlugin = require('{pluginPath}');
50
- * ESM: export { fooPlugin } from '{pluginPath}';
51
- * @example generatePlugins({ distPath: 'src/temp/foo-plugins.js', rootPath: 'src/foo/plugins', moduleType: ModuleType.CJS })
52
- * @param {PluginDefinition} definition plugin definition
53
- * @public
54
- */
55
- function generatePlugins(definition) {
56
- const { rootPath, distPath, moduleType, relative = false, silent } = definition;
57
- const segments = rootPath.split('/');
58
- const pluginName = segments[segments.length - 2];
59
- const plugins = getPluginList({ path: rootPath, pluginName, silent });
60
- let fileContent = '';
61
- fileContent = plugins
62
- .map((plugin) => {
63
- const sourcePath = relative
64
- ? path_1.default.relative(path_1.default.dirname(distPath), plugin.path).replace(/\\/g, '/')
65
- : plugin.path;
66
- return moduleType === ModuleType.CJS
67
- ? `exports.${plugin.name} = require('${sourcePath}');`
68
- : `export { ${plugin.name} } from '${sourcePath}';`;
69
- })
70
- .join('\r\n')
71
- .concat('\r\n');
72
- if (!plugins.length) {
73
- fileContent = moduleType === ModuleType.CJS ? 'module.exports = {};\r\n' : 'export {};\r\n';
74
- }
75
- const filePath = path_1.default.resolve(distPath);
76
- !silent && console.log(`Writing ${pluginName} plugins to ${filePath}`);
77
- fs_1.default.writeFileSync(filePath, fileContent, {
78
- encoding: 'utf8',
79
- });
80
- }
@@ -1,67 +0,0 @@
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.matchPath = void 0;
7
- exports.getItems = getItems;
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- /**
11
- * Compares two paths to determine if they match.
12
- * @param {string} itemPath base path to compare against, can be absolute or relative
13
- * @param {string} compare comparer, can be relate, absolute or regex string
14
- * @returns true if paths match, false otherwise
15
- * @public
16
- */
17
- const matchPath = (itemPath, compare) => {
18
- if (compare === itemPath ||
19
- path_1.default.join(process.cwd(), itemPath) === compare ||
20
- itemPath === path_1.default.join(process.cwd(), compare) ||
21
- new RegExp(compare).test(itemPath)) {
22
- return true;
23
- }
24
- return false;
25
- };
26
- exports.matchPath = matchPath;
27
- /**
28
- * Using @var path find all files and generate output using @var resolveItem function for each file
29
- * Can be used to generate list of components, templates, etc.
30
- * @param {GetItemsSettings} settings
31
- * @returns {Item[]} list of items
32
- */
33
- function getItems(settings) {
34
- const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), exclude, } = settings;
35
- const items = [];
36
- const folders = [];
37
- if (!fs_1.default.existsSync(path))
38
- return [];
39
- if (exclude) {
40
- for (const exclusion of exclude) {
41
- if ((0, exports.matchPath)(path, exclusion))
42
- return [];
43
- }
44
- }
45
- fs_1.default.readdirSync(path, { withFileTypes: true }).forEach((item) => {
46
- if (item.isDirectory()) {
47
- folders.push(item);
48
- }
49
- if (fileFormat.test(item.name)) {
50
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
51
- const name = item.name.match(fileFormat)[1];
52
- items.push(resolveItem(path, name));
53
- cb && cb(name);
54
- }
55
- });
56
- for (const folder of folders) {
57
- recursive
58
- ? items.push(...getItems({
59
- path: `${path}/${folder.name}`,
60
- resolveItem,
61
- cb,
62
- fileFormat,
63
- }))
64
- : items.push(resolveItem(`${path}/${folder.name}`, folder.name));
65
- }
66
- return items;
67
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tryParseEnvValue = void 0;
4
- /**
5
- * Method to parse JSON-formatted environment variables
6
- * @param {string} envValue - can be undefined when providing values via process.env
7
- * @param {T} defaultValue - default value
8
- * @returns {T | string} parsed value
9
- * @public
10
- */
11
- const tryParseEnvValue = (envValue, defaultValue) => {
12
- if (!envValue) {
13
- return defaultValue;
14
- }
15
- if (envValue.startsWith('{') && envValue.endsWith('}')) {
16
- try {
17
- return JSON.parse(envValue);
18
- // eslint-disable-next-line no-unused-vars
19
- }
20
- catch (error) {
21
- console.warn('Parsing of env variable failed');
22
- console.warn(`Attempted to parse ${envValue}`);
23
- return defaultValue;
24
- }
25
- }
26
- return defaultValue;
27
- };
28
- exports.tryParseEnvValue = tryParseEnvValue;
@@ -1,26 +0,0 @@
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.tryParseEnvValue = exports.setCache = exports.getCacheAndClean = exports.getCache = exports.hasCache = exports.mergeURLSearchParams = exports.escapeNonSpecialQuestionMarks = exports.areURLSearchParamsEqual = exports.isRegexOrUrl = exports.getAllowedOriginsFromEnv = exports.getEnforcedCorsHeaders = exports.enforceCors = exports.isTimeoutError = exports.isAbsoluteUrl = exports.resolveUrl = exports.isServer = void 0;
7
- var is_server_1 = require("./is-server");
8
- Object.defineProperty(exports, "isServer", { enumerable: true, get: function () { return __importDefault(is_server_1).default; } });
9
- var utils_1 = require("./utils");
10
- Object.defineProperty(exports, "resolveUrl", { enumerable: true, get: function () { return utils_1.resolveUrl; } });
11
- Object.defineProperty(exports, "isAbsoluteUrl", { enumerable: true, get: function () { return utils_1.isAbsoluteUrl; } });
12
- Object.defineProperty(exports, "isTimeoutError", { enumerable: true, get: function () { return utils_1.isTimeoutError; } });
13
- Object.defineProperty(exports, "enforceCors", { enumerable: true, get: function () { return utils_1.enforceCors; } });
14
- Object.defineProperty(exports, "getEnforcedCorsHeaders", { enumerable: true, get: function () { return utils_1.getEnforcedCorsHeaders; } });
15
- Object.defineProperty(exports, "getAllowedOriginsFromEnv", { enumerable: true, get: function () { return utils_1.getAllowedOriginsFromEnv; } });
16
- Object.defineProperty(exports, "isRegexOrUrl", { enumerable: true, get: function () { return utils_1.isRegexOrUrl; } });
17
- Object.defineProperty(exports, "areURLSearchParamsEqual", { enumerable: true, get: function () { return utils_1.areURLSearchParamsEqual; } });
18
- Object.defineProperty(exports, "escapeNonSpecialQuestionMarks", { enumerable: true, get: function () { return utils_1.escapeNonSpecialQuestionMarks; } });
19
- Object.defineProperty(exports, "mergeURLSearchParams", { enumerable: true, get: function () { return utils_1.mergeURLSearchParams; } });
20
- var globalCache_1 = require("./globalCache");
21
- Object.defineProperty(exports, "hasCache", { enumerable: true, get: function () { return globalCache_1.hasCache; } });
22
- Object.defineProperty(exports, "getCache", { enumerable: true, get: function () { return globalCache_1.getCache; } });
23
- Object.defineProperty(exports, "getCacheAndClean", { enumerable: true, get: function () { return globalCache_1.getCacheAndClean; } });
24
- Object.defineProperty(exports, "setCache", { enumerable: true, get: function () { return globalCache_1.setCache; } });
25
- var env_1 = require("./env");
26
- Object.defineProperty(exports, "tryParseEnvValue", { enumerable: true, get: function () { return env_1.tryParseEnvValue; } });
@@ -1,4 +0,0 @@
1
- /** @private */
2
- export const siteNameError = 'The site name must be a non-empty string';
3
- /** @private */
4
- export const languageError = 'The language must be a non-empty string';
@@ -1,19 +0,0 @@
1
- import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
2
- import { normalizeUrl } from '../utils/normalize-url';
3
- /**
4
- * Generates a URL for accessing Sitecore Edge Platform Content using the provided endpoint and context ID.
5
- * @param {string} sitecoreEdgeContextId - The unique context id.
6
- * @param {string} [sitecoreEdgeUrl] - The base endpoint URL for the Edge Platform. Default is https://edge-platform.sitecorecloud.io
7
- * @returns {string} The complete URL for accessing content through the Edge Platform.
8
- * @public
9
- */
10
- export const getEdgeProxyContentUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) => `${normalizeUrl(sitecoreEdgeUrl)}/v1/content/api/graphql/v1?sitecoreContextId=${sitecoreEdgeContextId}`;
11
- /**
12
- * Generates a URL for accessing Sitecore Edge Platform Forms using the provided form ID and context ID.
13
- * @param {string} sitecoreEdgeContextId - The unique context id.
14
- * @param {string} formId - The unique form id.
15
- * @param {string} [sitecoreEdgeUrl] - The base endpoint URL for the Edge Platform. Default is https://edge-platform.sitecorecloud.io
16
- * @returns {string} The complete URL for accessing forms through the Edge Platform.
17
- * @internal
18
- */
19
- export const getEdgeProxyFormsUrl = (sitecoreEdgeContextId, formId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) => `${normalizeUrl(sitecoreEdgeUrl)}/v1/forms/publisher/${formId}?sitecoreContextId=${sitecoreEdgeContextId}`;
@@ -1,5 +0,0 @@
1
- export { GraphQLRequestClient, } from '../graphql-request-client';
2
- export { DefaultRetryStrategy } from '../retries';
3
- export { getEdgeProxyContentUrl, getEdgeProxyFormsUrl } from './edge-proxy';
4
- export { SitecoreClient, ErrorPage, } from './sitecore-client';
5
- export { createGraphQLClientFactory } from './utils';
@@ -1 +0,0 @@
1
- export {};
@@ -1,417 +0,0 @@
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
- }
301
- return `<?xml version="1.0" encoding="UTF-8"?>
302
- <sitemapindex xmlns="http://sitemaps.org/schemas/sitemap/0.9">
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
- })
310
- .join('')}
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
- }