@sitecore-content-sdk/content 1.5.0-canary.5

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