@sitecore-content-sdk/core 1.3.0-canary.9 → 1.4.0-canary.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/cache-client.js +55 -54
  3. package/dist/cjs/client/constants.js +7 -7
  4. package/dist/cjs/client/edge-proxy.js +24 -22
  5. package/dist/cjs/client/index.js +15 -15
  6. package/dist/cjs/client/models.js +2 -2
  7. package/dist/cjs/client/sitecore-client.js +421 -419
  8. package/dist/cjs/client/utils.js +47 -46
  9. package/dist/cjs/config/define-config.js +194 -193
  10. package/dist/cjs/config/index.js +7 -7
  11. package/dist/cjs/config/models.js +12 -11
  12. package/dist/cjs/config-cli/define-cli-config.js +23 -22
  13. package/dist/cjs/config-cli/index.js +7 -7
  14. package/dist/cjs/config-cli/models.js +8 -7
  15. package/dist/cjs/constants.js +49 -17
  16. package/dist/cjs/debug.js +48 -46
  17. package/dist/cjs/editing/codegen/index.js +14 -9
  18. package/dist/cjs/editing/codegen/preview.js +277 -193
  19. package/dist/cjs/editing/component-layout-service.js +62 -61
  20. package/dist/cjs/editing/design-library.js +183 -126
  21. package/dist/cjs/editing/editing-service.js +75 -74
  22. package/dist/cjs/editing/index.js +33 -27
  23. package/dist/cjs/editing/metadata.js +42 -42
  24. package/dist/cjs/editing/models.js +44 -38
  25. package/dist/cjs/editing/utils.js +108 -90
  26. package/dist/cjs/form/form.js +81 -78
  27. package/dist/cjs/form/index.js +7 -7
  28. package/dist/cjs/graphql-request-client.js +108 -107
  29. package/dist/cjs/i18n/dictionary-service.js +122 -121
  30. package/dist/cjs/i18n/index.js +7 -7
  31. package/dist/cjs/i18n/utils.js +16 -15
  32. package/dist/cjs/index.js +60 -60
  33. package/dist/cjs/layout/content-styles.js +72 -71
  34. package/dist/cjs/layout/index.js +24 -24
  35. package/dist/cjs/layout/layout-service.js +62 -57
  36. package/dist/cjs/layout/models.js +39 -34
  37. package/dist/cjs/layout/themes.js +76 -75
  38. package/dist/cjs/layout/utils.js +117 -110
  39. package/dist/cjs/media/index.js +38 -38
  40. package/dist/cjs/media/media-api.js +100 -96
  41. package/dist/cjs/models.js +2 -2
  42. package/dist/cjs/native-fetcher.js +194 -179
  43. package/dist/cjs/personalize/index.js +15 -15
  44. package/dist/cjs/personalize/layout-personalizer.js +98 -97
  45. package/dist/cjs/personalize/personalize-service.js +98 -94
  46. package/dist/cjs/personalize/utils.js +143 -136
  47. package/dist/cjs/retries.js +43 -42
  48. package/dist/cjs/site/error-pages-service.js +65 -64
  49. package/dist/cjs/site/index.js +26 -26
  50. package/dist/cjs/site/models.js +2 -2
  51. package/dist/cjs/site/redirects-service.js +94 -81
  52. package/dist/cjs/site/robots-service.js +66 -65
  53. package/dist/cjs/site/site-resolver.js +73 -72
  54. package/dist/cjs/site/siteinfo-service.js +84 -80
  55. package/dist/cjs/site/sitemap-xml-service.js +84 -83
  56. package/dist/cjs/site/sitepath-service.js +165 -164
  57. package/dist/cjs/site/utils.js +55 -47
  58. package/dist/cjs/sitecore-service-base.js +36 -36
  59. package/dist/cjs/tools/auth/flow.js +65 -64
  60. package/dist/cjs/tools/auth/index.js +5 -5
  61. package/dist/cjs/tools/auth/models.js +2 -2
  62. package/dist/cjs/tools/auth/tenant-store.js +38 -38
  63. package/dist/cjs/tools/codegen/component-generation.js +52 -50
  64. package/dist/cjs/tools/codegen/extract-files.js +105 -107
  65. package/dist/cjs/tools/codegen/import-map.js +401 -349
  66. package/dist/cjs/tools/codegen/utils.js +418 -418
  67. package/dist/cjs/tools/generate-map.js +2 -2
  68. package/dist/cjs/tools/generateMetadata.js +36 -35
  69. package/dist/cjs/tools/generateSites.js +59 -58
  70. package/dist/cjs/tools/index.js +75 -73
  71. package/dist/cjs/tools/scaffold.js +60 -59
  72. package/dist/cjs/tools/templating/components.js +96 -266
  73. package/dist/cjs/tools/templating/index.js +11 -14
  74. package/dist/cjs/tools/templating/plugins.js +80 -78
  75. package/dist/cjs/tools/templating/utils.js +67 -66
  76. package/dist/cjs/utils/ensurePath.js +20 -20
  77. package/dist/cjs/utils/env.js +28 -27
  78. package/dist/cjs/utils/globalCache.js +55 -0
  79. package/dist/cjs/utils/index.js +26 -21
  80. package/dist/cjs/utils/is-server.js +11 -10
  81. package/dist/cjs/utils/normalize-url.js +5 -5
  82. package/dist/cjs/utils/timeout-promise.js +31 -31
  83. package/dist/cjs/utils/utils.js +254 -229
  84. package/dist/esm/cache-client.js +51 -50
  85. package/dist/esm/client/constants.js +4 -4
  86. package/dist/esm/client/edge-proxy.js +19 -17
  87. package/dist/esm/client/index.js +5 -5
  88. package/dist/esm/client/models.js +1 -1
  89. package/dist/esm/client/sitecore-client.js +414 -412
  90. package/dist/esm/client/utils.js +43 -42
  91. package/dist/esm/config/define-config.js +188 -187
  92. package/dist/esm/config/index.js +2 -2
  93. package/dist/esm/config/models.js +9 -8
  94. package/dist/esm/config-cli/define-cli-config.js +19 -18
  95. package/dist/esm/config-cli/index.js +2 -2
  96. package/dist/esm/config-cli/models.js +5 -4
  97. package/dist/esm/constants.js +46 -14
  98. package/dist/esm/debug.js +41 -39
  99. package/dist/esm/editing/codegen/index.js +1 -1
  100. package/dist/esm/editing/codegen/preview.js +263 -185
  101. package/dist/esm/editing/component-layout-service.js +55 -54
  102. package/dist/esm/editing/design-library.js +171 -117
  103. package/dist/esm/editing/editing-service.js +68 -67
  104. package/dist/esm/editing/index.js +6 -5
  105. package/dist/esm/editing/metadata.js +39 -39
  106. package/dist/esm/editing/models.js +41 -35
  107. package/dist/esm/editing/utils.js +98 -80
  108. package/dist/esm/form/form.js +72 -69
  109. package/dist/esm/form/index.js +1 -1
  110. package/dist/esm/graphql-request-client.js +101 -100
  111. package/dist/esm/i18n/dictionary-service.js +115 -114
  112. package/dist/esm/i18n/index.js +2 -2
  113. package/dist/esm/i18n/utils.js +13 -12
  114. package/dist/esm/index.js +13 -13
  115. package/dist/esm/layout/content-styles.js +64 -63
  116. package/dist/esm/layout/index.js +6 -6
  117. package/dist/esm/layout/layout-service.js +55 -50
  118. package/dist/esm/layout/models.js +36 -31
  119. package/dist/esm/layout/themes.js +71 -70
  120. package/dist/esm/layout/utils.js +109 -102
  121. package/dist/esm/media/index.js +2 -2
  122. package/dist/esm/media/media-api.js +90 -86
  123. package/dist/esm/models.js +1 -1
  124. package/dist/esm/native-fetcher.js +187 -172
  125. package/dist/esm/personalize/index.js +3 -3
  126. package/dist/esm/personalize/layout-personalizer.js +93 -92
  127. package/dist/esm/personalize/personalize-service.js +91 -87
  128. package/dist/esm/personalize/utils.js +135 -128
  129. package/dist/esm/retries.js +39 -38
  130. package/dist/esm/site/error-pages-service.js +58 -57
  131. package/dist/esm/site/index.js +8 -8
  132. package/dist/esm/site/models.js +1 -1
  133. package/dist/esm/site/redirects-service.js +87 -74
  134. package/dist/esm/site/robots-service.js +59 -58
  135. package/dist/esm/site/site-resolver.js +69 -68
  136. package/dist/esm/site/siteinfo-service.js +77 -73
  137. package/dist/esm/site/sitemap-xml-service.js +77 -76
  138. package/dist/esm/site/sitepath-service.js +157 -156
  139. package/dist/esm/site/utils.js +49 -41
  140. package/dist/esm/sitecore-service-base.js +29 -29
  141. package/dist/esm/tools/auth/flow.js +62 -61
  142. package/dist/esm/tools/auth/index.js +1 -1
  143. package/dist/esm/tools/auth/models.js +1 -1
  144. package/dist/esm/tools/auth/tenant-store.js +35 -35
  145. package/dist/esm/tools/codegen/component-generation.js +44 -42
  146. package/dist/esm/tools/codegen/extract-files.js +99 -101
  147. package/dist/esm/tools/codegen/import-map.js +358 -306
  148. package/dist/esm/tools/codegen/utils.js +373 -373
  149. package/dist/esm/tools/generate-map.js +1 -1
  150. package/dist/esm/tools/generateMetadata.js +29 -28
  151. package/dist/esm/tools/generateSites.js +52 -51
  152. package/dist/esm/tools/index.js +28 -27
  153. package/dist/esm/tools/scaffold.js +52 -51
  154. package/dist/esm/tools/templating/components.js +59 -223
  155. package/dist/esm/tools/templating/index.js +3 -3
  156. package/dist/esm/tools/templating/plugins.js +72 -70
  157. package/dist/esm/tools/templating/utils.js +59 -58
  158. package/dist/esm/utils/ensurePath.js +13 -13
  159. package/dist/esm/utils/env.js +24 -23
  160. package/dist/esm/utils/globalCache.js +49 -0
  161. package/dist/esm/utils/index.js +4 -3
  162. package/dist/esm/utils/is-server.js +9 -8
  163. package/dist/esm/utils/normalize-url.js +1 -1
  164. package/dist/esm/utils/timeout-promise.js +28 -28
  165. package/dist/esm/utils/utils.js +238 -213
  166. package/package.json +73 -5
  167. package/types/cache-client.d.ts +68 -64
  168. package/types/cache-client.d.ts.map +1 -0
  169. package/types/client/constants.d.ts +5 -4
  170. package/types/client/constants.d.ts.map +1 -0
  171. package/types/client/edge-proxy.d.ts +18 -15
  172. package/types/client/edge-proxy.d.ts.map +1 -0
  173. package/types/client/index.d.ts +8 -7
  174. package/types/client/index.d.ts.map +1 -0
  175. package/types/client/models.d.ts +21 -19
  176. package/types/client/models.d.ts.map +1 -0
  177. package/types/client/sitecore-client.d.ts +338 -327
  178. package/types/client/sitecore-client.d.ts.map +1 -0
  179. package/types/client/utils.d.ts +15 -9
  180. package/types/client/utils.d.ts.map +1 -0
  181. package/types/config/define-config.d.ts +20 -18
  182. package/types/config/define-config.d.ts.map +1 -0
  183. package/types/config/index.d.ts +3 -2
  184. package/types/config/index.d.ts.map +1 -0
  185. package/types/config/models.d.ts +287 -268
  186. package/types/config/models.d.ts.map +1 -0
  187. package/types/config-cli/define-cli-config.d.ts +9 -7
  188. package/types/config-cli/define-cli-config.d.ts.map +1 -0
  189. package/types/config-cli/index.d.ts +3 -2
  190. package/types/config-cli/index.d.ts.map +1 -0
  191. package/types/config-cli/models.d.ts +6 -4
  192. package/types/config-cli/models.d.ts.map +1 -0
  193. package/types/constants.d.ts +44 -11
  194. package/types/constants.d.ts.map +1 -0
  195. package/types/debug.d.ts +35 -28
  196. package/types/debug.d.ts.map +1 -0
  197. package/types/editing/codegen/index.d.ts +2 -1
  198. package/types/editing/codegen/index.d.ts.map +1 -0
  199. package/types/editing/codegen/preview.d.ts +256 -195
  200. package/types/editing/codegen/preview.d.ts.map +1 -0
  201. package/types/editing/component-layout-service.d.ts +84 -80
  202. package/types/editing/component-layout-service.d.ts.map +1 -0
  203. package/types/editing/design-library.d.ts +111 -63
  204. package/types/editing/design-library.d.ts.map +1 -0
  205. package/types/editing/editing-service.d.ts +72 -62
  206. package/types/editing/editing-service.d.ts.map +1 -0
  207. package/types/editing/index.d.ts +7 -6
  208. package/types/editing/index.d.ts.map +1 -0
  209. package/types/editing/metadata.d.ts +8 -7
  210. package/types/editing/metadata.d.ts.map +1 -0
  211. package/types/editing/models.d.ts +103 -92
  212. package/types/editing/models.d.ts.map +1 -0
  213. package/types/editing/utils.d.ts +91 -74
  214. package/types/editing/utils.d.ts.map +1 -0
  215. package/types/form/form.d.ts +25 -21
  216. package/types/form/form.d.ts.map +1 -0
  217. package/types/form/index.d.ts +2 -1
  218. package/types/form/index.d.ts.map +1 -0
  219. package/types/graphql-request-client.d.ts +112 -105
  220. package/types/graphql-request-client.d.ts.map +1 -0
  221. package/types/i18n/dictionary-service.d.ts +135 -131
  222. package/types/i18n/dictionary-service.d.ts.map +1 -0
  223. package/types/i18n/index.d.ts +3 -2
  224. package/types/i18n/index.d.ts.map +1 -0
  225. package/types/i18n/utils.d.ts +9 -7
  226. package/types/i18n/utils.d.ts.map +1 -0
  227. package/types/index.d.ts +13 -12
  228. package/types/index.d.ts.map +1 -0
  229. package/types/layout/content-styles.d.ts +20 -18
  230. package/types/layout/content-styles.d.ts.map +1 -0
  231. package/types/layout/index.d.ts +6 -5
  232. package/types/layout/index.d.ts.map +1 -0
  233. package/types/layout/layout-service.d.ts +45 -35
  234. package/types/layout/layout-service.d.ts.map +1 -0
  235. package/types/layout/models.d.ts +174 -151
  236. package/types/layout/models.d.ts.map +1 -0
  237. package/types/layout/themes.d.ts +13 -11
  238. package/types/layout/themes.d.ts.map +1 -0
  239. package/types/layout/utils.d.ts +56 -41
  240. package/types/layout/utils.d.ts.map +1 -0
  241. package/types/media/index.d.ts +3 -2
  242. package/types/media/index.d.ts.map +1 -0
  243. package/types/media/media-api.d.ts +60 -55
  244. package/types/media/media-api.d.ts.map +1 -0
  245. package/types/models.d.ts +94 -84
  246. package/types/models.d.ts.map +1 -0
  247. package/types/native-fetcher.d.ts +124 -114
  248. package/types/native-fetcher.d.ts.map +1 -0
  249. package/types/personalize/index.d.ts +4 -3
  250. package/types/personalize/index.d.ts.map +1 -0
  251. package/types/personalize/layout-personalizer.d.ts +29 -27
  252. package/types/personalize/layout-personalizer.d.ts.map +1 -0
  253. package/types/personalize/personalize-service.d.ts +90 -80
  254. package/types/personalize/personalize-service.d.ts.map +1 -0
  255. package/types/personalize/utils.d.ts +78 -69
  256. package/types/personalize/utils.d.ts.map +1 -0
  257. package/types/retries.d.ts +26 -24
  258. package/types/retries.d.ts.map +1 -0
  259. package/types/site/error-pages-service.d.ts +64 -57
  260. package/types/site/error-pages-service.d.ts.map +1 -0
  261. package/types/site/index.d.ts +10 -9
  262. package/types/site/index.d.ts.map +1 -0
  263. package/types/site/models.d.ts +23 -18
  264. package/types/site/models.d.ts.map +1 -0
  265. package/types/site/redirects-service.d.ts +92 -69
  266. package/types/site/redirects-service.d.ts.map +1 -0
  267. package/types/site/robots-service.d.ts +57 -50
  268. package/types/site/robots-service.d.ts.map +1 -0
  269. package/types/site/site-resolver.d.ts +28 -26
  270. package/types/site/site-resolver.d.ts.map +1 -0
  271. package/types/site/siteinfo-service.d.ts +65 -52
  272. package/types/site/siteinfo-service.d.ts.map +1 -0
  273. package/types/site/sitemap-xml-service.d.ts +63 -56
  274. package/types/site/sitemap-xml-service.d.ts.map +1 -0
  275. package/types/site/sitepath-service.d.ts +137 -134
  276. package/types/site/sitepath-service.d.ts.map +1 -0
  277. package/types/site/utils.d.ts +41 -28
  278. package/types/site/utils.d.ts.map +1 -0
  279. package/types/sitecore-service-base.d.ts +31 -30
  280. package/types/sitecore-service-base.d.ts.map +1 -0
  281. package/types/tools/auth/flow.d.ts +29 -27
  282. package/types/tools/auth/flow.d.ts.map +1 -0
  283. package/types/tools/auth/index.d.ts +2 -1
  284. package/types/tools/auth/index.d.ts.map +1 -0
  285. package/types/tools/auth/models.d.ts +35 -33
  286. package/types/tools/auth/models.d.ts.map +1 -0
  287. package/types/tools/auth/tenant-store.d.ts +12 -11
  288. package/types/tools/auth/tenant-store.d.ts.map +1 -0
  289. package/types/tools/codegen/component-generation.d.ts +50 -47
  290. package/types/tools/codegen/component-generation.d.ts.map +1 -0
  291. package/types/tools/codegen/extract-files.d.ts +24 -22
  292. package/types/tools/codegen/extract-files.d.ts.map +1 -0
  293. package/types/tools/codegen/import-map.d.ts +103 -70
  294. package/types/tools/codegen/import-map.d.ts.map +1 -0
  295. package/types/tools/codegen/utils.d.ts +76 -75
  296. package/types/tools/codegen/utils.d.ts.map +1 -0
  297. package/types/tools/generate-map.d.ts +36 -26
  298. package/types/tools/generate-map.d.ts.map +1 -0
  299. package/types/tools/generateMetadata.d.ts +24 -22
  300. package/types/tools/generateMetadata.d.ts.map +1 -0
  301. package/types/tools/generateSites.d.ts +25 -22
  302. package/types/tools/generateSites.d.ts.map +1 -0
  303. package/types/tools/index.d.ts +22 -20
  304. package/types/tools/index.d.ts.map +1 -0
  305. package/types/tools/scaffold.d.ts +27 -25
  306. package/types/tools/scaffold.d.ts.map +1 -0
  307. package/types/tools/templating/components.d.ts +104 -103
  308. package/types/tools/templating/components.d.ts.map +1 -0
  309. package/types/tools/templating/index.d.ts +4 -3
  310. package/types/tools/templating/index.d.ts.map +1 -0
  311. package/types/tools/templating/plugins.d.ts +71 -67
  312. package/types/tools/templating/plugins.d.ts.map +1 -0
  313. package/types/tools/templating/utils.d.ts +42 -40
  314. package/types/tools/templating/utils.d.ts.map +1 -0
  315. package/types/utils/ensurePath.d.ts +7 -6
  316. package/types/utils/ensurePath.d.ts.map +1 -0
  317. package/types/utils/env.d.ts +9 -7
  318. package/types/utils/env.d.ts.map +1 -0
  319. package/types/utils/globalCache.d.ts +37 -0
  320. package/types/utils/globalCache.d.ts.map +1 -0
  321. package/types/utils/index.d.ts +5 -3
  322. package/types/utils/index.d.ts.map +1 -0
  323. package/types/utils/is-server.d.ts +8 -6
  324. package/types/utils/is-server.d.ts.map +1 -0
  325. package/types/utils/normalize-url.d.ts +2 -1
  326. package/types/utils/normalize-url.d.ts.map +1 -0
  327. package/types/utils/timeout-promise.d.ts +18 -17
  328. package/types/utils/timeout-promise.d.ts.map +1 -0
  329. package/types/utils/utils.d.ts +104 -79
  330. package/types/utils/utils.d.ts.map +1 -0
  331. package/client.js +0 -1
  332. package/codegen.js +0 -1
  333. package/config-cli.js +0 -1
  334. package/config.js +0 -1
  335. package/editing.js +0 -1
  336. package/i18n.js +0 -1
  337. package/layout.js +0 -1
  338. package/media.js +0 -1
  339. package/personalize.js +0 -1
  340. package/site.js +0 -1
  341. package/tools.js +0 -1
  342. package/utils.js +0 -1
@@ -1,55 +1,56 @@
1
- import { NativeDataFetcher } from '../native-fetcher';
2
- import debug from '../debug';
3
- import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
4
- import { resolveUrl } from '../utils';
5
- import { DesignLibraryMode } from './models';
6
- /**
7
- * REST service that enables Design Library functionality.
8
- * Returns layout data for a single rendered component.
9
- */
10
- export class ComponentLayoutService {
11
- constructor(config) {
12
- this.config = config;
13
- }
14
- fetchComponentData(params, fetchOptions) {
15
- const fetcher = new NativeDataFetcher({ debugger: debug.layout });
16
- debug.layout('fetching component with uid %s for %s %s %s %s', params.componentUid, params.itemId, params.language, params.siteName, params.dataSourceId);
17
- return fetcher
18
- .get(this.getFetchUrl(params), Object.assign(Object.assign({}, fetchOptions), { headers: Object.assign(Object.assign({}, fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.headers), { sc_editMode: `${params.mode === DesignLibraryMode.Metadata}` }) }))
19
- .then((response) => response.data)
20
- .catch((error) => {
21
- var _a;
22
- if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
23
- return error.response.data;
24
- }
25
- throw error;
26
- });
27
- }
28
- getComponentFetchParams(params) {
29
- // Choose the correct Edge ID per environment
30
- const sitecoreContextId = this.config.contextId || this.config.clientContextId;
31
- if (!sitecoreContextId) {
1
+ import { NativeDataFetcher } from '../native-fetcher';
2
+ import debug from '../debug';
3
+ import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
4
+ import { resolveUrl } from '../utils';
5
+ import { DesignLibraryMode } from './models';
6
+ /**
7
+ * REST service that enables Design Library functionality.
8
+ * Returns layout data for a single rendered component.
9
+ * @public
10
+ */
11
+ export class ComponentLayoutService {
12
+ constructor(config) {
13
+ this.config = config;
14
+ }
15
+ fetchComponentData(params, fetchOptions) {
16
+ const fetcher = new NativeDataFetcher({ debugger: debug.layout });
17
+ debug.layout('fetching component with uid %s for %s %s %s %s', params.componentUid, params.itemId, params.language, params.siteName, params.dataSourceId);
18
+ return fetcher
19
+ .get(this.getFetchUrl(params), Object.assign(Object.assign({}, fetchOptions), { headers: Object.assign(Object.assign({}, fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.headers), { sc_editMode: `${params.mode === DesignLibraryMode.Metadata}` }) }))
20
+ .then((response) => response.data)
21
+ .catch((error) => {
22
+ var _a;
23
+ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
24
+ return error.response.data;
25
+ }
26
+ throw error;
27
+ });
28
+ }
29
+ getComponentFetchParams(params) {
30
+ // Choose the correct Edge ID per environment
31
+ const sitecoreContextId = this.config.contextId || this.config.clientContextId;
32
+ if (!sitecoreContextId) {
32
33
  throw new Error(`ComponentLayoutService misconfigured: contextId is missing.
33
- Provide contextId on the server, and clientContextId in the browser if you need to full client-side functionality.`);
34
- }
35
- // strip undefined fields
36
- return JSON.parse(JSON.stringify({
37
- sitecoreContextId,
38
- item: params.itemId,
39
- uid: params.componentUid,
40
- dataSourceId: params.dataSourceId,
41
- renderingItemId: params.renderingId,
42
- version: params.version,
43
- sc_site: params.siteName,
44
- sc_lang: params.language || 'en',
45
- }));
46
- }
47
- /**
48
- * Get the fetch URL for the partial layout data endpoint
49
- * @param {ComponentLayoutRequestParams} params - The parameters for the request
50
- * @returns {string} The fetch URL for the component data
51
- */
52
- getFetchUrl(params) {
53
- return resolveUrl(`${this.config.edgeUrl || SITECORE_EDGE_URL_DEFAULT}/layout/component`, this.getComponentFetchParams(params));
54
- }
55
- }
34
+ Provide contextId on the server, and clientContextId in the browser if you need to full client-side functionality.`);
35
+ }
36
+ // strip undefined fields
37
+ return JSON.parse(JSON.stringify({
38
+ sitecoreContextId,
39
+ item: params.itemId,
40
+ uid: params.componentUid,
41
+ dataSourceId: params.dataSourceId,
42
+ renderingItemId: params.renderingId,
43
+ version: params.version,
44
+ sc_site: params.siteName,
45
+ sc_lang: params.language || 'en',
46
+ }));
47
+ }
48
+ /**
49
+ * Get the fetch URL for the partial layout data endpoint
50
+ * @param {ComponentLayoutRequestParams} params - The parameters for the request
51
+ * @returns {string} The fetch URL for the component data
52
+ */
53
+ getFetchUrl(params) {
54
+ return resolveUrl(`${this.config.edgeUrl || SITECORE_EDGE_URL_DEFAULT}/layout/component`, this.getComponentFetchParams(params));
55
+ }
56
+ }
@@ -1,117 +1,171 @@
1
- import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
2
- import { normalizeUrl } from '../utils/normalize-url';
3
- import { DesignLibraryMode } from './models';
4
- /**
5
- * Event to be sent when report status to design library
6
- */
7
- const DESIGN_LIBRARY_STATUS_EVENT_NAME = 'component:status';
8
- /**
9
- * Enumeration of statuses for the design library.
10
- */
11
- export var DesignLibraryStatus;
12
- (function (DesignLibraryStatus) {
13
- DesignLibraryStatus["READY"] = "ready";
14
- DesignLibraryStatus["RENDERED"] = "rendered";
15
- })(DesignLibraryStatus || (DesignLibraryStatus = {}));
16
- /**
17
- * Adds the browser-side event handler for 'component:update' message used in Design Library
18
- * The event should update a component on page by uid, with fields and params from event args
19
- * @param {ComponentRendering} rootComponent root component displayed for Design Library page
20
- * @param {Function} successCallback callback to be called after successful component update
21
- */
22
- export const addComponentUpdateHandler = (rootComponent, successCallback) => {
23
- if (!window)
24
- return;
25
- const handler = (e) => updateComponentHandler(e, rootComponent, successCallback);
26
- window.addEventListener('message', handler);
27
- // the power to remove handler outside of this function, if needed
28
- const unsubscribe = () => {
29
- window.removeEventListener('message', handler);
30
- };
31
- return unsubscribe;
32
- };
33
- export const validateOrigin = (event) => {
34
- // TODO: use `EDITING_ALLOWED_ORIGINS.concat(getAllowedOriginsFromEnv())` later
35
- // nextjs's JSS_ALLOWED_ORIGINS is not available on the client, need to use NEXT_PUBLIC_ variable, but it's a breaking change for Deploy
36
- const allowedOrigins = ['*'];
37
- return allowedOrigins.some((origin) => origin === event.origin ||
38
- new RegExp('^' + origin.replace('.', '\\.').replace(/\*/g, '.*') + '$').test(event.origin));
39
- };
40
- export const updateComponentHandler = (e, rootComponent, successCallback) => {
41
- var _a;
42
- const eventArgs = e.data;
43
- if (!e.origin || !eventArgs || eventArgs.name !== 'component:update') {
44
- // avoid extra noise in logs
45
- if (!validateOrigin(e)) {
46
- console.debug('Component Library: event skipped: message %s from origin %s', eventArgs.name, e.origin);
47
- }
48
- return;
49
- }
50
- if (!((_a = eventArgs.details) === null || _a === void 0 ? void 0 : _a.uid)) {
51
- console.debug('Received component:update event without uid, aborting event handler...');
52
- return;
53
- }
54
- const findComponent = (root) => {
55
- var _a, _b;
56
- if (((_a = root.uid) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = eventArgs.details) === null || _b === void 0 ? void 0 : _b.uid.toLowerCase()))
57
- return root;
58
- if (root.placeholders) {
59
- for (const plhName of Object.keys(root.placeholders)) {
60
- for (const rendering of root.placeholders[plhName]) {
61
- const result = findComponent(rendering);
62
- if (result)
63
- return result;
64
- }
65
- }
66
- }
67
- return null;
68
- };
69
- const updateComponent = findComponent(rootComponent);
70
- if (updateComponent) {
71
- console.debug('Found component with uid %s to update. Update fields: %o. Update params: %o.', eventArgs.details.uid, eventArgs.details.fields, eventArgs.details.params);
72
- if (eventArgs.details.fields) {
73
- updateComponent.fields = Object.assign(Object.assign({}, updateComponent.fields), eventArgs.details.fields);
74
- }
75
- if (eventArgs.details.params) {
76
- updateComponent.params = Object.assign(Object.assign({}, updateComponent.params), eventArgs.details.params);
77
- }
78
- if (successCallback)
79
- successCallback(rootComponent);
80
- }
81
- else {
82
- console.debug('Rendering with uid %s not found', eventArgs.details.uid);
83
- }
84
- // strictly for testing
85
- return rootComponent;
86
- };
87
- /**
88
- * Generates a DesignLibraryStatusEvent with the given status and uid.
89
- * @param {DesignLibraryStatus} status - The status of rendering.
90
- * @param {string} uid - The unique identifier for the event.
91
- * @returns An object representing the DesignLibraryStatusEvent.
92
- */
93
- export function getDesignLibraryStatusEvent(status, uid) {
94
- return {
95
- name: DESIGN_LIBRARY_STATUS_EVENT_NAME,
96
- message: {
97
- status,
98
- uid,
99
- },
100
- };
101
- }
102
- /**
103
- * Generates the URL for the design library script link.
104
- * @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
105
- * @returns The full URL to the design library script.
106
- */
107
- export function getDesignLibraryScriptLink(sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
108
- return `${normalizeUrl(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
109
- }
110
- /**
111
- * Checks if the given mode is a Design Library mode.
112
- * @param {unknown} mode - The mode to check.
113
- * @returns {boolean} True if the mode is a Design Library mode, false otherwise.
114
- */
115
- export function isDesignLibraryMode(mode) {
116
- return mode === DesignLibraryMode.Normal || mode === DesignLibraryMode.Metadata;
117
- }
1
+ import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
2
+ import { normalizeUrl } from '../utils/normalize-url';
3
+ import { DesignLibraryMode } from './models';
4
+ /**
5
+ * Event to be sent when report status to design library
6
+ */
7
+ const DESIGN_LIBRARY_STATUS_EVENT_NAME = 'component:status';
8
+ /**
9
+ * Prefix for component update cache keys
10
+ * @internal
11
+ */
12
+ export const COMPONENT_UPDATE_CACHE_KEY_PREFIX = 'component-update-';
13
+ /**
14
+ * Enumeration of statuses for the design library.
15
+ * @internal
16
+ */
17
+ export var DesignLibraryStatus;
18
+ (function (DesignLibraryStatus) {
19
+ DesignLibraryStatus["READY"] = "ready";
20
+ DesignLibraryStatus["RENDERED"] = "rendered";
21
+ })(DesignLibraryStatus || (DesignLibraryStatus = {}));
22
+ /**
23
+ * Adds the browser-side event handler for 'component:update' message used in Design Library
24
+ * The event should update a component on page by uid, with fields and params from event args
25
+ * @param {ComponentRendering} rootComponent root component displayed for Design Library page
26
+ * @param {Function} successCallback callback to be called after successful component update
27
+ * @internal
28
+ */
29
+ export const addComponentUpdateHandler = (rootComponent, successCallback) => {
30
+ if (!window)
31
+ return;
32
+ const handler = (e) => updateComponentHandler(e, rootComponent, successCallback);
33
+ window.addEventListener('message', handler);
34
+ // the power to remove handler outside of this function, if needed
35
+ const unsubscribe = () => {
36
+ window.removeEventListener('message', handler);
37
+ };
38
+ return unsubscribe;
39
+ };
40
+ export const validateOrigin = (event) => {
41
+ // TODO: use `EDITING_ALLOWED_ORIGINS.concat(getAllowedOriginsFromEnv())` later
42
+ // nextjs's JSS_ALLOWED_ORIGINS is not available on the client, need to use NEXT_PUBLIC_ variable, but it's a breaking change for Deploy
43
+ const allowedOrigins = ['*'];
44
+ return allowedOrigins.some((origin) => origin === event.origin ||
45
+ new RegExp('^' + origin.replace('.', '\\.').replace(/\*/g, '.*') + '$').test(event.origin));
46
+ };
47
+ /**
48
+ * Validates that a MessageEvent has the expected event name and required data.
49
+ * Logs debug information when validation fails due to invalid origin.
50
+ * @param {MessageEvent} e - The message event to validate.
51
+ * @param {string} eventName - The expected event name to match against e.data.name.
52
+ * @returns {boolean} True if the event has a valid origin, data object, and matching event name; otherwise false.
53
+ */
54
+ export const validateEvent = (e, eventName) => {
55
+ if (!e.origin || !e.data || e.data.name !== eventName) {
56
+ // avoid extra noise in logs
57
+ if (!validateOrigin(e)) {
58
+ console.debug('Component Library: event skipped - invalid origin: message %s from origin %s', e.data.name, e.origin);
59
+ }
60
+ return false;
61
+ }
62
+ return true;
63
+ };
64
+ export const updateComponentHandler = (e, rootComponent, successCallback) => {
65
+ var _a;
66
+ const eventArgs = e.data;
67
+ if (!e.origin || !eventArgs || eventArgs.name !== 'component:update') {
68
+ // avoid extra noise in logs
69
+ if (!validateOrigin(e)) {
70
+ console.debug('Component Library: event skipped: message %s from origin %s', eventArgs.name, e.origin);
71
+ }
72
+ return;
73
+ }
74
+ if (!((_a = eventArgs.details) === null || _a === void 0 ? void 0 : _a.uid)) {
75
+ console.debug('Received component:update event without uid, aborting event handler...');
76
+ return;
77
+ }
78
+ const findComponent = (root) => {
79
+ var _a, _b;
80
+ if (((_a = root.uid) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = eventArgs.details) === null || _b === void 0 ? void 0 : _b.uid.toLowerCase()))
81
+ return root;
82
+ if (root.placeholders) {
83
+ for (const plhName of Object.keys(root.placeholders)) {
84
+ for (const rendering of root.placeholders[plhName]) {
85
+ const result = findComponent(rendering);
86
+ if (result)
87
+ return result;
88
+ }
89
+ }
90
+ }
91
+ return null;
92
+ };
93
+ const componentToUpdate = findComponent(rootComponent);
94
+ if (componentToUpdate) {
95
+ console.debug('Found component with uid %s to update. Update fields: %o. Update params: %o.', eventArgs.details.uid, eventArgs.details.fields, eventArgs.details.params);
96
+ updateComponent(componentToUpdate, eventArgs.details.fields, eventArgs.details.params);
97
+ if (successCallback)
98
+ successCallback(rootComponent);
99
+ }
100
+ else {
101
+ console.debug('Rendering with uid %s not found', eventArgs.details.uid);
102
+ }
103
+ // strictly for testing
104
+ return rootComponent;
105
+ };
106
+ /**
107
+ * Updates a component's fields and params with the provided values.
108
+ * @param {ComponentRendering<ComponentFields>} component - The component to update.
109
+ * @param {ComponentFields | undefined} fields - The fields to merge into the component.
110
+ * @param {ComponentParams | undefined} params - The params to merge into the component.
111
+ * @internal
112
+ */
113
+ export const updateComponent = (component, fields, params) => {
114
+ if (fields) {
115
+ component.fields = Object.assign(Object.assign({}, component.fields), fields);
116
+ }
117
+ if (params) {
118
+ component.params = Object.assign(Object.assign({}, component.params), params);
119
+ }
120
+ };
121
+ /**
122
+ * Generates a DesignLibraryStatusEvent with the given status and uid.
123
+ * @param {DesignLibraryStatus} status - The status of rendering.
124
+ * @param {string} uid - The unique identifier for the event.
125
+ * @returns An object representing the DesignLibraryStatusEvent.
126
+ * @internal
127
+ */
128
+ export function getDesignLibraryStatusEvent(status, uid) {
129
+ return {
130
+ name: DESIGN_LIBRARY_STATUS_EVENT_NAME,
131
+ message: {
132
+ status,
133
+ uid,
134
+ },
135
+ };
136
+ }
137
+ /**
138
+ * Generates the URL for the design library script link.
139
+ * @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
140
+ * @returns The full URL to the design library script.
141
+ * @internal
142
+ */
143
+ export function getDesignLibraryScriptLink(sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
144
+ return `${normalizeUrl(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
145
+ }
146
+ /**
147
+ * Checks if the given mode is a Design Library mode.
148
+ * @param {unknown} mode - The mode to check.
149
+ * @returns {boolean} True if the mode is a Design Library mode, false otherwise.
150
+ * @internal
151
+ */
152
+ export function isDesignLibraryMode(mode) {
153
+ return mode === DesignLibraryMode.Normal || mode === DesignLibraryMode.Metadata;
154
+ }
155
+ /**
156
+ * Sends an event to the Design Library
157
+ * @param {DesignLibraryEvent} evt - The event object to send.
158
+ * @internal
159
+ */
160
+ export const postToDesignLibrary = (evt) => {
161
+ if (typeof window === 'undefined')
162
+ return;
163
+ const target = window.parent && window.parent !== window ? window.parent : window;
164
+ try {
165
+ console.log('Component Library: sending event', evt.name, evt);
166
+ target.postMessage(evt, '*');
167
+ }
168
+ catch (err) {
169
+ console.error('Component Library: postMessage failed', err, evt);
170
+ }
171
+ };
@@ -1,73 +1,74 @@
1
- import debug from '../debug';
2
- import { LayoutKind } from './models';
3
- /**
4
- * GraphQL query for fetching editing data.
5
- */
1
+ import debug from '../debug';
2
+ import { LayoutKind } from './models';
3
+ /**
4
+ * GraphQL query for fetching editing data.
5
+ */
6
6
  export const query = /* GraphQL */ `
7
7
  query EditingQuery($itemId: String!, $language: String!, $version: String) {
8
8
  item(path: $itemId, language: $language, version: $version) {
9
9
  rendered
10
10
  }
11
11
  }
12
- `;
13
- /**
14
- * Service for fetching editing data from Sitecore using the Sitecore's GraphQL API.
15
- * Expected to be used in XMCloud Pages preview (editing) Metadata Edit Mode.
16
- */
17
- export class EditingService {
18
- /**
19
- * Fetch layout data using the Sitecore GraphQL endpoint.
20
- * @param {EditingServiceConfig} serviceConfig configuration
21
- */
22
- constructor(serviceConfig) {
23
- this.serviceConfig = serviceConfig;
24
- this.graphQLClient = this.getGraphQLClient();
25
- }
26
- /**
27
- * Fetches editing data. Provides the layout data and dictionary phrases
28
- * @param {object} variables - The parameters for fetching editing data.
29
- * @param {string} variables.itemId - The item id (path) to fetch layout data for.
30
- * @param {string} variables.language - The language to fetch layout data for.
31
- * @param {string} variables.mode - The editing mode to fetch layout data for.
32
- * @param {string} [variables.version] - The version of the item (optional).
33
- * @param {LayoutKind} [variables.layoutKind] - The final or shared layout variant.
34
- * @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
35
- * @returns {Promise} The layout data and dictionary phrases.
36
- */
37
- async fetchEditingData({ itemId, language, version, layoutKind = LayoutKind.Final, mode }, fetchOptions) {
38
- var _a;
39
- debug.editing('fetching editing data for %s %s %s %s', itemId, language, version, layoutKind);
40
- if (!language) {
41
- throw new RangeError('The language must be a non-empty string');
42
- }
43
- const editModeHeader = mode === 'edit' ? 'true' : 'false';
44
- const editingData = await this.graphQLClient.request(query, {
45
- itemId,
46
- version,
47
- language,
48
- }, Object.assign(Object.assign({}, fetchOptions), { headers: {
49
- sc_layoutKind: layoutKind,
50
- sc_editMode: editModeHeader,
51
- } }));
52
- return {
53
- layoutData: ((_a = editingData === null || editingData === void 0 ? void 0 : editingData.item) === null || _a === void 0 ? void 0 : _a.rendered) || {
54
- sitecore: {
55
- context: { pageEditing: true, language },
56
- route: null,
57
- },
58
- },
59
- };
60
- }
61
- /**
62
- * Gets a GraphQL client that can make requests to the API.
63
- * @returns {GraphQLClient} implementation
64
- */
65
- getGraphQLClient() {
66
- if (!this.serviceConfig.clientFactory) {
67
- throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
68
- }
69
- return this.serviceConfig.clientFactory({
70
- debugger: debug.editing,
71
- });
72
- }
73
- }
12
+ `;
13
+ /**
14
+ * Service for fetching editing data from Sitecore using the Sitecore's GraphQL API.
15
+ * Expected to be used in XMCloud Pages preview (editing) Metadata Edit Mode.
16
+ * @public
17
+ */
18
+ export class EditingService {
19
+ /**
20
+ * Fetch layout data using the Sitecore GraphQL endpoint.
21
+ * @param {EditingServiceConfig} serviceConfig configuration
22
+ */
23
+ constructor(serviceConfig) {
24
+ this.serviceConfig = serviceConfig;
25
+ this.graphQLClient = this.getGraphQLClient();
26
+ }
27
+ /**
28
+ * Fetches editing data. Provides the layout data and dictionary phrases
29
+ * @param {object} variables - The parameters for fetching editing data.
30
+ * @param {string} variables.itemId - The item id (path) to fetch layout data for.
31
+ * @param {string} variables.language - The language to fetch layout data for.
32
+ * @param {string} variables.mode - The editing mode to fetch layout data for.
33
+ * @param {string} [variables.version] - The version of the item (optional).
34
+ * @param {LayoutKind} [variables.layoutKind] - The final or shared layout variant.
35
+ * @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
36
+ * @returns {Promise} The layout data and dictionary phrases.
37
+ */
38
+ async fetchEditingData({ itemId, language, version, layoutKind = LayoutKind.Final, mode }, fetchOptions) {
39
+ var _a;
40
+ debug.editing('fetching editing data for %s %s %s %s', itemId, language, version, layoutKind);
41
+ if (!language) {
42
+ throw new RangeError('The language must be a non-empty string');
43
+ }
44
+ const editModeHeader = mode === 'edit' ? 'true' : 'false';
45
+ const editingData = await this.graphQLClient.request(query, {
46
+ itemId,
47
+ version,
48
+ language,
49
+ }, Object.assign(Object.assign({}, fetchOptions), { headers: {
50
+ sc_layoutKind: layoutKind,
51
+ sc_editMode: editModeHeader,
52
+ } }));
53
+ return {
54
+ layoutData: ((_a = editingData === null || editingData === void 0 ? void 0 : editingData.item) === null || _a === void 0 ? void 0 : _a.rendered) || {
55
+ sitecore: {
56
+ context: { pageEditing: true, language },
57
+ route: null,
58
+ },
59
+ },
60
+ };
61
+ }
62
+ /**
63
+ * Gets a GraphQL client that can make requests to the API.
64
+ * @returns {GraphQLClient} implementation
65
+ */
66
+ getGraphQLClient() {
67
+ if (!this.serviceConfig.clientFactory) {
68
+ throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
69
+ }
70
+ return this.serviceConfig.clientFactory({
71
+ debugger: debug.editing,
72
+ });
73
+ }
74
+ }
@@ -1,5 +1,6 @@
1
- export { EditingService } from './editing-service';
2
- export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChromes, getContentSdkPagesClientData, EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, PAGES_EDITING_MARKER, PREVIEW_KEY, } from './utils';
3
- export { ComponentLayoutService } from './component-layout-service';
4
- export { LayoutKind, MetadataKind, DesignLibraryMode, } from './models';
5
- export { addComponentUpdateHandler, DesignLibraryStatus, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, isDesignLibraryMode, } from './design-library';
1
+ export { EditingService } from './editing-service';
2
+ export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChromes, getContentSdkPagesClientData, EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, INVALID_SECRET_HTML_MESSAGE, PAGES_EDITING_MARKER, PREVIEW_KEY, } from './utils';
3
+ export { ComponentLayoutService, } from './component-layout-service';
4
+ export { DesignLibraryVariantGeneration, } from './models';
5
+ export { LayoutKind, MetadataKind, DesignLibraryMode, } from './models';
6
+ export { addComponentUpdateHandler, DesignLibraryStatus, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, isDesignLibraryMode, postToDesignLibrary, COMPONENT_UPDATE_CACHE_KEY_PREFIX, updateComponent, } from './design-library';