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