@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,135 +0,0 @@
1
- /** @internal */
2
- export const DEFAULT_VARIANT = '_default';
3
- /** @internal */
4
- export const VARIANT_PREFIX = '_variantId_';
5
- /**
6
- * Get a personalized rewrite path for given pathname
7
- * @param {string} pathname the pathname
8
- * @param {string[]} variantIds the variantIds to include in the rewrite
9
- * @returns {string} the rewrite path
10
- * @public
11
- */
12
- export function getPersonalizedRewrite(pathname, variantIds) {
13
- const path = pathname.endsWith('/') ? pathname.slice(0, -1) : pathname;
14
- return `${path}${variantIds.map((variantId) => `/${VARIANT_PREFIX}${variantId}`).join('')}`;
15
- }
16
- /**
17
- * Get personalize data from the rewrite path
18
- * @param {string} pathname the pathname
19
- * @returns {PersonalizedRewriteData} the personalize data from the rewrite
20
- * @public
21
- */
22
- export function getPersonalizedRewriteData(pathname) {
23
- const segments = pathname.split('/');
24
- const variantIds = [];
25
- segments.forEach((segment) => {
26
- const result = segment.match(`${VARIANT_PREFIX}(.*$)`);
27
- if (result) {
28
- variantIds.push(result[1]);
29
- }
30
- });
31
- return getGroomedVariantIds(variantIds);
32
- }
33
- /**
34
- * Parses a list of variantIds and divides into layout and component variants
35
- * @param {string[]} variantIds the list of variant IDs for a page
36
- * @returns {PersonalizedRewriteData} object with variant IDs sorted
37
- * @public
38
- */
39
- export function getGroomedVariantIds(variantIds) {
40
- const data = {
41
- variantId: DEFAULT_VARIANT,
42
- componentVariantIds: [],
43
- };
44
- variantIds.forEach((variantId) => {
45
- var _a;
46
- if (variantId.includes('_')) {
47
- // Component-level personalization in format "<ComponentID>_<VariantID>"
48
- // There can be multiple
49
- (_a = data.componentVariantIds) === null || _a === void 0 ? void 0 : _a.push(variantId);
50
- }
51
- else {
52
- // Embedded (page-level) personalization in format "<VariantID>"
53
- // There should be only one
54
- data.variantId = variantId;
55
- }
56
- });
57
- return data;
58
- }
59
- /**
60
- * Normalize a personalized rewrite path (remove personalize data)
61
- * @param {string} pathname the pathname
62
- * @returns {string} the pathname with personalize data removed
63
- * @public
64
- */
65
- export function normalizePersonalizedRewrite(pathname) {
66
- if (!pathname.includes(VARIANT_PREFIX)) {
67
- return pathname;
68
- }
69
- let segments = pathname.split('/');
70
- segments = segments.filter((segment) => !segment.includes(VARIANT_PREFIX));
71
- const result = segments.join('/');
72
- // return root path if all segments were personalize data
73
- return result ? result : '/';
74
- }
75
- /**
76
- * Static utility class for Sitecore CDP
77
- * @public
78
- */
79
- export class CdpHelper {
80
- /**
81
- * Gets the page variant id for CDP in the required format
82
- * @param {string} pageId the page id
83
- * @param {string} language the language
84
- * @param {string} variantId the variant id
85
- * @param {string} [scope] the scope value
86
- * @returns {string} the formatted page variant id
87
- */
88
- static getPageVariantId(pageId, language, variantId, scope) {
89
- const formattedPageId = pageId.replace(/[{}-]/g, '');
90
- const formattedLanguage = language.replace('-', '_');
91
- const scopeId = scope ? `${this.normalizeScope(scope)}_` : '';
92
- let formattedVariantId = variantId;
93
- if (!variantId || variantId === DEFAULT_VARIANT) {
94
- formattedVariantId = 'default';
95
- }
96
- return `${scopeId}${formattedPageId}_${formattedLanguage}_${formattedVariantId}`.toLowerCase();
97
- }
98
- /**
99
- * Gets the friendly id for (page-level) Embedded Personalization in the required format `embedded_[<scope>_]<id>_<lang>`
100
- * @param {string} pageId the page id
101
- * @param {string} language the language
102
- * @param {string} [scope] the scope value
103
- * @returns {string} the friendly id
104
- */
105
- static getPageFriendlyId(pageId, language, scope) {
106
- const formattedPageId = pageId.replace(/[{}-]/g, '');
107
- const formattedLanguage = language.replace('-', '_');
108
- const scopeId = scope ? `${this.normalizeScope(scope)}_` : '';
109
- return `embedded_${scopeId}${formattedPageId}_${formattedLanguage}`.toLowerCase();
110
- }
111
- /**
112
- * Gets the friendly id for Component A/B Testing in the required format `component_[<scope>_]<pageId>_<componentId>_<language>*`
113
- * @param {string} pageId the page id
114
- * @param {string} componentId the component id
115
- * @param {string} language the language
116
- * @param {string} [scope] the scope value
117
- * @returns {string} the friendly id
118
- */
119
- static getComponentFriendlyId(pageId, componentId, language, scope) {
120
- const formattedPageId = pageId.replace(/[{}-]/g, '');
121
- const formattedComponentId = componentId.replace(/[{}-]/g, '');
122
- const formattedLanguage = language.replace('-', '_');
123
- const scopeId = scope ? `${this.normalizeScope(scope)}_` : '';
124
- return `component_${scopeId}${formattedPageId}_${formattedComponentId}_${formattedLanguage}*`.toLowerCase();
125
- }
126
- /**
127
- * Normalizes the scope from the given string value
128
- * Removes all non-alphanumeric characters
129
- * @param {string} [scope] the scope value
130
- * @returns {string} normalized scope value
131
- */
132
- static normalizeScope(scope) {
133
- return (scope === null || scope === void 0 ? void 0 : scope.replace(/[^a-zA-Z0-9]+/g, '')) || '';
134
- }
135
- }
@@ -1,75 +0,0 @@
1
- import { siteNameError } from '../constants';
2
- import debug from '../debug';
3
- // The default query for request error handling
4
- const defaultQuery = /* GraphQL */ `
5
- query ErrorPagesQuery($siteName: String!, $language: String!) {
6
- site {
7
- siteInfo(site: $siteName) {
8
- errorHandling(language: $language) {
9
- notFoundPage {
10
- rendered
11
- }
12
- notFoundPagePath
13
- serverErrorPage {
14
- rendered
15
- }
16
- serverErrorPagePath
17
- }
18
- }
19
- }
20
- }
21
- `;
22
- /**
23
- * Service that fetch the error pages data using Sitecore's GraphQL API.
24
- * @public
25
- */
26
- export class ErrorPagesService {
27
- /**
28
- * Creates an instance of graphQL error pages service with the provided options
29
- * @param {ErrorPagesServiceConfig} options instance
30
- */
31
- constructor(options) {
32
- this.options = options;
33
- this.graphQLClient = this.getGraphQLClient();
34
- }
35
- get query() {
36
- return defaultQuery;
37
- }
38
- /**
39
- * Fetch list of error pages for the site
40
- * @param {string} siteName The site name
41
- * @param {string} locale The language
42
- * @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
43
- * @returns {ErrorPages} list of url's error pages
44
- * @throws {Error} if the siteName is empty.
45
- */
46
- async fetchErrorPages(siteName, locale, fetchOptions) {
47
- const language = locale || this.options.language;
48
- if (!siteName) {
49
- throw new Error(siteNameError);
50
- }
51
- return this.graphQLClient.request(this.query, {
52
- siteName,
53
- language,
54
- }, fetchOptions)
55
- .then((result) => result.site.siteInfo ? result.site.siteInfo.errorHandling : null)
56
- .catch((e) => Promise.reject(e));
57
- }
58
- /**
59
- * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
60
- * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
61
- * want to use something else.
62
- * @returns {GraphQLClient} implementation
63
- */
64
- getGraphQLClient() {
65
- var _a, _b;
66
- if (!this.options.clientFactory) {
67
- throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
68
- }
69
- return this.options.clientFactory({
70
- debugger: debug.errorpages,
71
- retries: (_a = this.options.retries) === null || _a === void 0 ? void 0 : _a.count,
72
- retryStrategy: (_b = this.options.retries) === null || _b === void 0 ? void 0 : _b.retryStrategy,
73
- });
74
- }
75
- }
@@ -1,8 +0,0 @@
1
- export { RobotsService } from './robots-service';
2
- export { REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, RedirectsService, } from './redirects-service';
3
- export { SitemapXmlService, } from './sitemap-xml-service';
4
- export { ErrorPagesService } from './error-pages-service';
5
- export { SiteInfoService } from './siteinfo-service';
6
- export { SitePathService } from './sitepath-service';
7
- export { getSiteRewrite, getSiteRewriteData, normalizeSiteRewrite, SITE_PREFIX, SITE_KEY, } from './utils';
8
- export { SiteResolver } from './site-resolver';
@@ -1 +0,0 @@
1
- export {};
@@ -1,101 +0,0 @@
1
- import { siteNameError } from '../constants';
2
- import debug from '../debug';
3
- import { MemoryCacheClient } from '../cache-client';
4
- /**
5
- * Redirect type for 301 redirects
6
- * @public
7
- */
8
- export const REDIRECT_TYPE_301 = 'REDIRECT_301';
9
- /**
10
- * Redirect type for 302 redirects
11
- * @public
12
- */
13
- export const REDIRECT_TYPE_302 = 'REDIRECT_302';
14
- /**
15
- * Redirect type for server transfer
16
- * @public
17
- */
18
- export const REDIRECT_TYPE_SERVER_TRANSFER = 'SERVER_TRANSFER';
19
- // The default query for request redirects of site
20
- const defaultQuery = /* GraphQL */ `
21
- query RedirectsQuery($siteName: String!) {
22
- site {
23
- siteInfo(site: $siteName) {
24
- redirects {
25
- pattern
26
- target
27
- redirectType
28
- isQueryStringPreserved
29
- locale
30
- }
31
- }
32
- }
33
- }
34
- `;
35
- /**
36
- * The RedirectsService class is used to query the Content SDK redirects using Graphql endpoint
37
- * @public
38
- */
39
- export class RedirectsService {
40
- /**
41
- * Creates an instance of graphQL redirects service with the provided options
42
- * @param {RedirectsServiceConfig} options instance
43
- */
44
- constructor(options) {
45
- this.options = options;
46
- this.graphQLClient = this.getGraphQLClient();
47
- this.cache = this.getCacheClient();
48
- }
49
- get query() {
50
- return defaultQuery;
51
- }
52
- /**
53
- * Fetch an array of redirects from API
54
- * @param {string} siteName site name
55
- * @returns Promise<RedirectInfo[]>
56
- * @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
57
- * @throws {Error} if the siteName is empty.
58
- */
59
- async fetchRedirects(siteName, fetchOptions) {
60
- var _a, _b;
61
- if (!siteName) {
62
- throw new Error(siteNameError);
63
- }
64
- const cacheKey = `redirects-${siteName}`;
65
- let data = this.cache.getCacheValue(cacheKey);
66
- if (!data) {
67
- data = await this.graphQLClient.request(this.query, {
68
- siteName,
69
- }, fetchOptions);
70
- this.cache.setCacheValue(cacheKey, data);
71
- }
72
- return ((_b = (_a = data === null || data === void 0 ? void 0 : data.site) === null || _a === void 0 ? void 0 : _a.siteInfo) === null || _b === void 0 ? void 0 : _b.redirects) || [];
73
- }
74
- /**
75
- * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
76
- * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
77
- * want to use something else.
78
- * @returns {GraphQLClient} implementation
79
- */
80
- getGraphQLClient() {
81
- if (!this.options.clientFactory) {
82
- throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
83
- }
84
- return this.options.clientFactory({
85
- debugger: debug.redirects,
86
- fetch: this.options.fetch,
87
- });
88
- }
89
- /**
90
- * Gets cache client implementation
91
- * Override this method if custom cache needs to be used
92
- * @returns CacheClient instance
93
- */
94
- getCacheClient() {
95
- var _a, _b;
96
- return new MemoryCacheClient({
97
- cacheEnabled: (_a = this.options.cacheEnabled) !== null && _a !== void 0 ? _a : true,
98
- cacheTimeout: (_b = this.options.cacheTimeout) !== null && _b !== void 0 ? _b : 10,
99
- });
100
- }
101
- }
@@ -1,67 +0,0 @@
1
- import { siteNameError } from '../constants';
2
- import debug from '../debug';
3
- // The default query for request robots.txt
4
- const defaultQuery = /* GraphQL */ `
5
- query RobotsQuery($siteName: String!) {
6
- site {
7
- siteInfo(site: $siteName) {
8
- robots
9
- }
10
- }
11
- }
12
- `;
13
- /**
14
- * Service that fetch the robots.txt data using Sitecore's GraphQL API.
15
- * @public
16
- */
17
- export class RobotsService {
18
- /**
19
- * Creates an instance of graphQL robots.txt service with the provided options
20
- * @param {RobotsServiceConfig} options instance
21
- */
22
- constructor(options) {
23
- this.options = options;
24
- this.graphQLClient = this.getGraphQLClient();
25
- }
26
- get query() {
27
- return defaultQuery;
28
- }
29
- /**
30
- * Fetch a data of robots.txt from API
31
- * @param {FetchOptions} fetchOptions - The fetch options to be used for the request.
32
- * @returns text of robots.txt
33
- * @throws {Error} if the siteName is empty.
34
- */
35
- async fetchRobots(fetchOptions) {
36
- const siteName = this.options.siteName;
37
- if (!siteName) {
38
- throw new Error(siteNameError);
39
- }
40
- const robotsResult = this.graphQLClient.request(this.query, {
41
- siteName,
42
- }, fetchOptions);
43
- try {
44
- return robotsResult.then((result) => {
45
- var _a, _b;
46
- return (_b = (_a = result === null || result === void 0 ? void 0 : result.site) === null || _a === void 0 ? void 0 : _a.siteInfo) === null || _b === void 0 ? void 0 : _b.robots;
47
- });
48
- }
49
- catch (e) {
50
- return Promise.reject(e);
51
- }
52
- }
53
- /**
54
- * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
55
- * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
56
- * want to use something else.
57
- * @returns {GraphQLClient} implementation
58
- */
59
- getGraphQLClient() {
60
- if (!this.options.clientFactory) {
61
- throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
62
- }
63
- return this.options.clientFactory({
64
- debugger: debug.robots,
65
- });
66
- }
67
- }
@@ -1,69 +0,0 @@
1
- // Delimiters for multi-value hostnames
2
- const DELIMITERS = /\||,|;/g;
3
- /**
4
- * Resolves site based on the provided host or site name
5
- * @public
6
- */
7
- export class SiteResolver {
8
- /**
9
- * @param {SiteInfo[]} sites Array of sites to be used in resolution
10
- */
11
- constructor(sites) {
12
- this.sites = sites;
13
- /**
14
- * Resolve site by host name
15
- * @param {string} hostName the host name
16
- * @returns {SiteInfo} the resolved site
17
- * @throws {Error} if a matching site is not found
18
- */
19
- this.getByHost = (hostName) => {
20
- for (const [hostname, site] of this.getHostMap()) {
21
- if (this.matchesPattern(hostName, hostname)) {
22
- return site;
23
- }
24
- }
25
- throw new Error(`Could not resolve site for host ${hostName}`);
26
- };
27
- /**
28
- * Resolve site by site name
29
- * @param {string} siteName the site name
30
- * @returns {SiteInfo} the resolved site or undefined if not found
31
- */
32
- this.getByName = (siteName) => {
33
- const siteInfo = this.sites.find((info) => info.name.toLocaleLowerCase() === siteName.toLocaleLowerCase());
34
- return siteInfo;
35
- };
36
- this.getHostMap = () => {
37
- const map = new Map();
38
- // First collect unique hostnames.
39
- // For sites with same hostname defined, priority is given to the first encountered.
40
- this.sites.forEach((site) => {
41
- const hostnames = site.hostName.replace(/\s/g, '').toLocaleLowerCase().split(DELIMITERS);
42
- hostnames.forEach((hostname) => {
43
- if (!map.has(hostname)) {
44
- map.set(hostname, site);
45
- }
46
- });
47
- });
48
- // Now order by specificity.
49
- // This equivalates to sorting from longest to shortest with the assumption
50
- // that your match is less specific as wildcards are introduced.
51
- // E.g. order.eu.site.com → *.eu.site.com → *.site.com → *
52
- // In case of a tie (e.g. *.site.com vs i.site.com), prefer one with less wildcards.
53
- return new Map(Array.from(map).sort((a, b) => {
54
- if (a[0].length === b[0].length) {
55
- return (a[0].match(/\*/g) || []).length - (b[0].match(/\*/g) || []).length;
56
- }
57
- return b[0].length - a[0].length;
58
- }));
59
- };
60
- }
61
- // b[0].match(/\*/g) || []).length
62
- matchesPattern(hostname, pattern) {
63
- // dots should be treated as chars
64
- // stars should be treated as wildcards
65
- const regExpPattern = pattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
66
- const regExp = new RegExp(`^${regExpPattern}$`, 'gi');
67
- return !!hostname.match(regExp);
68
- }
69
- }
@@ -1,87 +0,0 @@
1
- import debug from '../debug';
2
- import { MemoryCacheClient } from '../cache-client';
3
- const siteQuery = /* GraphQL */ `
4
- query {
5
- site {
6
- siteInfoCollection {
7
- name
8
- hostName: hostname
9
- language
10
- }
11
- }
12
- }
13
- `;
14
- /**
15
- * Service to fetch site information
16
- * @public
17
- */
18
- export class SiteInfoService {
19
- /**
20
- * Creates an instance of graphQL service to retrieve site configuration list from Sitecore
21
- * @param {SiteInfoServiceConfig} config instance
22
- */
23
- constructor(config) {
24
- this.config = config;
25
- this.graphQLClient = this.getGraphQLClient();
26
- this.cache = this.getCacheClient();
27
- }
28
- /**
29
- * site query is available on XM Cloud and XP 10.4+
30
- */
31
- get siteQuery() {
32
- return siteQuery;
33
- }
34
- async fetchSiteInfo(fetchOptions) {
35
- var _a, _b;
36
- const cachedResult = this.cache.getCacheValue(this.getCacheKey());
37
- if (cachedResult) {
38
- return cachedResult;
39
- }
40
- if (process.env.SITECORE) {
41
- debug.multisite('Skipping site information fetch (building on XM Cloud)');
42
- return [];
43
- }
44
- const response = await this.graphQLClient.request(this.siteQuery, {}, fetchOptions);
45
- const results = (_b = (_a = response === null || response === void 0 ? void 0 : response.site) === null || _a === void 0 ? void 0 : _a.siteInfoCollection) === null || _b === void 0 ? void 0 : _b.reduce((result, current) => {
46
- // filter out built in website
47
- current.name !== 'website' &&
48
- result.push({
49
- name: current.name,
50
- hostName: current.hostName,
51
- language: current.language,
52
- });
53
- return result;
54
- }, []);
55
- this.cache.setCacheValue(this.getCacheKey(), results);
56
- return results;
57
- }
58
- /**
59
- * Gets cache client implementation
60
- * Override this method if custom cache needs to be used
61
- * @returns CacheClient instance
62
- */
63
- getCacheClient() {
64
- var _a, _b;
65
- return new MemoryCacheClient({
66
- cacheEnabled: (_a = this.config.cacheEnabled) !== null && _a !== void 0 ? _a : true,
67
- cacheTimeout: (_b = this.config.cacheTimeout) !== null && _b !== void 0 ? _b : 10,
68
- });
69
- }
70
- /**
71
- * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
72
- * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
73
- * want to use something else.
74
- * @returns {GraphQLClient} implementation
75
- */
76
- getGraphQLClient() {
77
- if (!this.config.clientFactory) {
78
- throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
79
- }
80
- return this.config.clientFactory({
81
- debugger: debug.multisite,
82
- });
83
- }
84
- getCacheKey() {
85
- return 'siteinfo-service-cache';
86
- }
87
- }
@@ -1,85 +0,0 @@
1
- import { siteNameError } from '../constants';
2
- import debug from '../debug';
3
- const PREFIX_NAME_SITEMAP = 'sitemap';
4
- // The default query for request sitemaps
5
- const defaultQuery = /* GraphQL */ `
6
- query SitemapQuery($siteName: String!) {
7
- site {
8
- siteInfo(site: $siteName) {
9
- sitemap
10
- }
11
- }
12
- }
13
- `;
14
- /**
15
- * Service that fetch the sitemaps data using Sitecore's GraphQL API.
16
- * @public
17
- */
18
- export class SitemapXmlService {
19
- /**
20
- * Creates an instance of graphQL sitemaps service with the provided options
21
- * @param {SitemapXmlServiceConfig} options instance
22
- */
23
- constructor(options) {
24
- this.options = options;
25
- this.graphQLClient = this.getGraphQLClient();
26
- }
27
- get query() {
28
- return defaultQuery;
29
- }
30
- /**
31
- * Fetch list of sitemaps for the site
32
- * @returns {string[]} list of sitemap paths
33
- * @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
34
- * @throws {Error} if the siteName is empty.
35
- */
36
- async fetchSitemaps(fetchOptions) {
37
- const siteName = this.options.siteName;
38
- if (!siteName) {
39
- throw new Error(siteNameError);
40
- }
41
- const sitemapResult = this.graphQLClient.request(this.query, {
42
- siteName,
43
- }, fetchOptions);
44
- try {
45
- return sitemapResult.then((result) => result.site.siteInfo.sitemap);
46
- }
47
- catch (e) {
48
- return Promise.reject(e);
49
- }
50
- }
51
- /**
52
- * Get sitemap file path for sitemap id
53
- * @param {string} id the sitemap id (can be empty for default 'sitemap.xml' file)
54
- * @returns {string | undefined} the sitemap file path or undefined if one doesn't exist
55
- */
56
- async getSitemap(id) {
57
- let searchSitemap;
58
- if (id === undefined) {
59
- return undefined;
60
- }
61
- else if (id === '') {
62
- searchSitemap = `${PREFIX_NAME_SITEMAP}.xml`;
63
- }
64
- else {
65
- const normalizedId = id.startsWith('-') ? id.slice(1) : id;
66
- searchSitemap = `${PREFIX_NAME_SITEMAP}-${normalizedId}.xml`;
67
- }
68
- const sitemaps = await this.fetchSitemaps();
69
- return sitemaps.find((sitemap) => sitemap.includes(searchSitemap));
70
- }
71
- /**
72
- * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
73
- * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
74
- * want to use something else.
75
- * @returns {GraphQLClient} implementation
76
- */
77
- getGraphQLClient() {
78
- if (!this.options.clientFactory) {
79
- throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
80
- }
81
- return this.options.clientFactory({
82
- debugger: debug.sitemap,
83
- });
84
- }
85
- }