@sitecore-content-sdk/core 0.1.0-beta.3 → 0.1.0-beta.31

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 (173) hide show
  1. package/client.d.ts +1 -0
  2. package/client.js +1 -0
  3. package/config.d.ts +1 -0
  4. package/config.js +1 -0
  5. package/dist/cjs/client/constants.js +7 -0
  6. package/dist/cjs/{graphql → client}/index.js +7 -6
  7. package/dist/cjs/client/models.js +2 -0
  8. package/dist/cjs/client/sitecore-client.js +261 -0
  9. package/dist/cjs/client/utils.js +30 -0
  10. package/dist/cjs/config/define-cli-config.js +22 -0
  11. package/dist/cjs/config/define-config.js +106 -0
  12. package/dist/cjs/config/index.js +9 -0
  13. package/dist/cjs/config/models.js +11 -0
  14. package/dist/cjs/data-fetcher.js +3 -14
  15. package/dist/cjs/debug.js +1 -0
  16. package/dist/cjs/editing/{component-library.js → design-library.js} +17 -17
  17. package/dist/cjs/editing/graphql-editing-service.js +62 -69
  18. package/dist/cjs/editing/index.js +5 -5
  19. package/dist/cjs/editing/metadata.js +40 -0
  20. package/dist/cjs/editing/rest-component-layout-service.js +1 -1
  21. package/dist/cjs/form/form.js +78 -0
  22. package/dist/cjs/form/index.js +7 -0
  23. package/dist/cjs/graphql-request-client.js +46 -91
  24. package/dist/cjs/i18n/graphql-dictionary-service.js +70 -63
  25. package/dist/cjs/i18n/index.js +1 -3
  26. package/dist/cjs/index.js +5 -2
  27. package/dist/cjs/layout/content-styles.js +1 -1
  28. package/dist/cjs/layout/graphql-layout-service.js +17 -40
  29. package/dist/cjs/layout/index.js +2 -2
  30. package/dist/cjs/layout/layout-service.js +2 -1
  31. package/dist/cjs/layout/themes.js +3 -3
  32. package/dist/cjs/native-fetcher.js +55 -76
  33. package/dist/cjs/personalize/graphql-personalize-service.js +27 -36
  34. package/dist/cjs/personalize/index.js +2 -1
  35. package/dist/cjs/retries.js +42 -0
  36. package/dist/cjs/site/graphql-error-pages-service.js +17 -25
  37. package/dist/cjs/site/graphql-redirects-service.js +15 -25
  38. package/dist/cjs/site/graphql-robots-service.js +16 -27
  39. package/dist/cjs/site/graphql-siteinfo-service.js +22 -39
  40. package/dist/cjs/site/{graphql-sitemap-service.js → graphql-sitemap-xml-service.js} +19 -31
  41. package/dist/cjs/site/graphql-sitepath-service.js +199 -0
  42. package/dist/cjs/site/index.js +6 -3
  43. package/dist/cjs/site/models.js +2 -0
  44. package/dist/cjs/sitecore-service-base.js +36 -0
  45. package/dist/cjs/tools/generateMetadata.js +35 -0
  46. package/dist/cjs/tools/generateSites.js +54 -0
  47. package/dist/cjs/tools/index.js +24 -0
  48. package/dist/cjs/tools/scaffold.js +61 -0
  49. package/dist/cjs/tools/templating/components.js +26 -0
  50. package/dist/cjs/tools/templating/index.js +8 -0
  51. package/dist/cjs/tools/templating/plugins.js +78 -0
  52. package/dist/cjs/tools/templating/utils.js +42 -0
  53. package/dist/cjs/utils/ensurePath.js +20 -0
  54. package/dist/esm/client/constants.js +4 -0
  55. package/dist/esm/client/index.js +5 -0
  56. package/dist/esm/client/models.js +1 -0
  57. package/dist/esm/client/sitecore-client.js +257 -0
  58. package/dist/esm/client/utils.js +26 -0
  59. package/dist/esm/config/define-cli-config.js +18 -0
  60. package/dist/esm/config/define-config.js +101 -0
  61. package/dist/esm/config/index.js +3 -0
  62. package/dist/esm/config/models.js +8 -0
  63. package/dist/esm/data-fetcher.js +3 -14
  64. package/dist/esm/debug.js +1 -0
  65. package/dist/esm/editing/{component-library.js → design-library.js} +15 -15
  66. package/dist/esm/editing/graphql-editing-service.js +62 -69
  67. package/dist/esm/editing/index.js +2 -2
  68. package/dist/esm/editing/metadata.js +37 -0
  69. package/dist/esm/editing/rest-component-layout-service.js +1 -1
  70. package/dist/esm/form/form.js +69 -0
  71. package/dist/esm/form/index.js +1 -0
  72. package/dist/esm/graphql-request-client.js +44 -88
  73. package/dist/esm/i18n/graphql-dictionary-service.js +70 -63
  74. package/dist/esm/i18n/index.js +0 -1
  75. package/dist/esm/index.js +3 -1
  76. package/dist/esm/layout/content-styles.js +1 -1
  77. package/dist/esm/layout/graphql-layout-service.js +17 -40
  78. package/dist/esm/layout/index.js +1 -1
  79. package/dist/esm/layout/layout-service.js +2 -1
  80. package/dist/esm/layout/themes.js +2 -2
  81. package/dist/esm/native-fetcher.js +55 -76
  82. package/dist/esm/personalize/graphql-personalize-service.js +27 -36
  83. package/dist/esm/personalize/index.js +1 -1
  84. package/dist/esm/retries.js +38 -0
  85. package/dist/esm/site/graphql-error-pages-service.js +17 -25
  86. package/dist/esm/site/graphql-redirects-service.js +15 -25
  87. package/dist/esm/site/graphql-robots-service.js +16 -27
  88. package/dist/esm/site/graphql-siteinfo-service.js +22 -39
  89. package/dist/esm/site/{graphql-sitemap-service.js → graphql-sitemap-xml-service.js} +19 -31
  90. package/dist/esm/site/graphql-sitepath-service.js +191 -0
  91. package/dist/esm/site/index.js +4 -3
  92. package/dist/esm/site/models.js +1 -0
  93. package/dist/esm/sitecore-service-base.js +29 -0
  94. package/dist/esm/tools/generateMetadata.js +28 -0
  95. package/dist/esm/tools/generateSites.js +47 -0
  96. package/dist/esm/tools/index.js +4 -0
  97. package/dist/esm/tools/scaffold.js +53 -0
  98. package/dist/esm/tools/templating/components.js +23 -0
  99. package/dist/esm/tools/templating/index.js +2 -0
  100. package/dist/esm/tools/templating/plugins.js +70 -0
  101. package/dist/esm/tools/templating/utils.js +36 -0
  102. package/dist/esm/utils/ensurePath.js +13 -0
  103. package/form.d.ts +1 -0
  104. package/form.js +1 -0
  105. package/package.json +12 -3
  106. package/tools.d.ts +1 -0
  107. package/tools.js +1 -0
  108. package/types/client/constants.d.ts +4 -0
  109. package/types/client/index.d.ts +7 -0
  110. package/types/client/models.d.ts +5 -0
  111. package/types/client/sitecore-client.d.ts +192 -0
  112. package/types/client/utils.d.ts +9 -0
  113. package/types/config/define-cli-config.d.ts +7 -0
  114. package/types/config/define-config.d.ts +12 -0
  115. package/types/config/index.d.ts +3 -0
  116. package/types/config/models.d.ts +240 -0
  117. package/types/debug.d.ts +1 -0
  118. package/types/editing/{component-library.d.ts → design-library.d.ts} +13 -13
  119. package/types/editing/graphql-editing-service.d.ts +19 -13
  120. package/types/editing/index.d.ts +2 -2
  121. package/types/editing/metadata.d.ts +5 -0
  122. package/types/editing/models.d.ts +27 -0
  123. package/types/editing/rest-component-layout-service.d.ts +2 -2
  124. package/types/editing/utils.d.ts +1 -1
  125. package/types/form/form.d.ts +21 -0
  126. package/types/form/index.d.ts +1 -0
  127. package/types/graphql-request-client.d.ts +5 -59
  128. package/types/i18n/graphql-dictionary-service.d.ts +71 -18
  129. package/types/i18n/index.d.ts +1 -2
  130. package/types/index.d.ts +4 -2
  131. package/types/layout/graphql-layout-service.d.ts +10 -32
  132. package/types/layout/index.d.ts +2 -3
  133. package/types/layout/layout-service.d.ts +5 -15
  134. package/types/layout/models.d.ts +7 -0
  135. package/types/layout/themes.d.ts +2 -2
  136. package/types/models.d.ts +78 -0
  137. package/types/personalize/index.d.ts +1 -1
  138. package/types/retries.d.ts +24 -0
  139. package/types/site/graphql-error-pages-service.d.ts +7 -7
  140. package/types/site/graphql-redirects-service.d.ts +3 -2
  141. package/types/site/graphql-robots-service.d.ts +1 -1
  142. package/types/site/graphql-siteinfo-service.d.ts +3 -21
  143. package/types/site/{graphql-sitemap-service.d.ts → graphql-sitemap-xml-service.d.ts} +3 -2
  144. package/types/site/graphql-sitepath-service.d.ts +135 -0
  145. package/types/site/index.d.ts +5 -3
  146. package/types/site/models.d.ts +18 -0
  147. package/types/site/site-resolver.d.ts +1 -1
  148. package/types/sitecore-service-base.d.ts +30 -0
  149. package/types/tools/generateMetadata.d.ts +17 -0
  150. package/types/tools/generateSites.d.ts +23 -0
  151. package/types/tools/index.d.ts +4 -0
  152. package/types/tools/scaffold.d.ts +25 -0
  153. package/types/tools/templating/components.d.ts +29 -0
  154. package/types/tools/templating/index.d.ts +2 -0
  155. package/types/tools/templating/plugins.d.ts +67 -0
  156. package/types/tools/templating/utils.d.ts +32 -0
  157. package/types/utils/ensurePath.d.ts +6 -0
  158. package/dist/cjs/graphql/app-root-query.js +0 -73
  159. package/dist/cjs/graphql/search-service.js +0 -61
  160. package/dist/cjs/i18n/dictionary-service.js +0 -45
  161. package/dist/esm/graphql/app-root-query.js +0 -69
  162. package/dist/esm/graphql/index.js +0 -4
  163. package/dist/esm/graphql/search-service.js +0 -57
  164. package/dist/esm/i18n/dictionary-service.js +0 -41
  165. package/graphql.d.ts +0 -1
  166. package/graphql.js +0 -1
  167. package/types/graphql/app-root-query.d.ts +0 -32
  168. package/types/graphql/index.d.ts +0 -4
  169. package/types/graphql/search-service.d.ts +0 -95
  170. package/types/i18n/dictionary-service.d.ts +0 -56
  171. /package/dist/cjs/{graphql → client}/graphql-edge-proxy.js +0 -0
  172. /package/dist/esm/{graphql → client}/graphql-edge-proxy.js +0 -0
  173. /package/types/{graphql → client}/graphql-edge-proxy.d.ts +0 -0
package/client.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/client/index';
package/client.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/client/index');
package/config.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/config/index';
package/config.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/config/index');
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.languageError = exports.siteNameError = void 0;
4
+ /** @private */
5
+ exports.siteNameError = 'The site name must be a non-empty string';
6
+ /** @private */
7
+ exports.languageError = 'The language must be a non-empty string';
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEdgeProxyFormsUrl = exports.getEdgeProxyContentUrl = exports.SearchQueryService = exports.GraphQLRequestClient = exports.DefaultRetryStrategy = exports.getAppRootId = void 0;
4
- var app_root_query_1 = require("./app-root-query");
5
- Object.defineProperty(exports, "getAppRootId", { enumerable: true, get: function () { return app_root_query_1.getAppRootId; } });
3
+ exports.createGraphQLClientFactory = exports.SitecoreClient = exports.getEdgeProxyFormsUrl = exports.getEdgeProxyContentUrl = exports.DefaultRetryStrategy = exports.GraphQLRequestClient = void 0;
6
4
  var graphql_request_client_1 = require("../graphql-request-client");
7
- Object.defineProperty(exports, "DefaultRetryStrategy", { enumerable: true, get: function () { return graphql_request_client_1.DefaultRetryStrategy; } });
8
5
  Object.defineProperty(exports, "GraphQLRequestClient", { enumerable: true, get: function () { return graphql_request_client_1.GraphQLRequestClient; } });
9
- var search_service_1 = require("./search-service");
10
- Object.defineProperty(exports, "SearchQueryService", { enumerable: true, get: function () { return search_service_1.SearchQueryService; } });
6
+ var retries_1 = require("../retries");
7
+ Object.defineProperty(exports, "DefaultRetryStrategy", { enumerable: true, get: function () { return retries_1.DefaultRetryStrategy; } });
11
8
  var graphql_edge_proxy_1 = require("./graphql-edge-proxy");
12
9
  Object.defineProperty(exports, "getEdgeProxyContentUrl", { enumerable: true, get: function () { return graphql_edge_proxy_1.getEdgeProxyContentUrl; } });
13
10
  Object.defineProperty(exports, "getEdgeProxyFormsUrl", { enumerable: true, get: function () { return graphql_edge_proxy_1.getEdgeProxyFormsUrl; } });
11
+ var sitecore_client_1 = require("./sitecore-client");
12
+ Object.defineProperty(exports, "SitecoreClient", { enumerable: true, get: function () { return sitecore_client_1.SitecoreClient; } });
13
+ var utils_1 = require("./utils");
14
+ Object.defineProperty(exports, "createGraphQLClientFactory", { enumerable: true, get: function () { return utils_1.createGraphQLClientFactory; } });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SitecoreClient = void 0;
4
+ const editing_1 = require("../editing");
5
+ const i18n_1 = require("../i18n");
6
+ const layout_1 = require("../layout");
7
+ const utils_1 = require("../personalize/utils");
8
+ const layout_personalizer_1 = require("../personalize/layout-personalizer");
9
+ const site_1 = require("../site");
10
+ const utils_2 = require("./utils");
11
+ /**
12
+ * This is a generic content client that can be used by any framework.
13
+ * Use it to retrieve pages, preview data, dictionary and other data
14
+ */
15
+ class SitecoreClient {
16
+ /**
17
+ * Init SitecoreClient
18
+ * @param {SitecoreClientInit} initOptions initOptions for the client, containing site and Sitecore connection details
19
+ */
20
+ constructor(initOptions) {
21
+ this.initOptions = initOptions;
22
+ this.clientFactory = this.getClientFactory();
23
+ this.siteResolver = this.getSiteResolver();
24
+ const baseServiceOptions = this.getBaseServiceOptions();
25
+ this.layoutService = this.getLayoutService(baseServiceOptions);
26
+ this.dictionaryService = this.getDictionaryService(baseServiceOptions);
27
+ this.editingService = this.getEditingService();
28
+ this.errorPagesService = this.getErrorPagesService();
29
+ this.componentService = this.getComponentService();
30
+ this.sitePathService = this.getSitePathService();
31
+ }
32
+ /**
33
+ * Resolve site by hostname
34
+ * @param {string} hostname site hostname
35
+ * @returns {SiteInfo} site details matching the hostname
36
+ */
37
+ resolveSite(hostname) {
38
+ const site = this.siteResolver.getByHost(hostname);
39
+ return site;
40
+ }
41
+ /**
42
+ * Normalize path regardless of type
43
+ * @param {string | string[]} path string or string array path
44
+ * @returns {string} string path
45
+ */
46
+ parsePath(path) {
47
+ // join array path, while clearing extra slashes and ensure first slash
48
+ return typeof path === 'string'
49
+ ? path.startsWith('/')
50
+ ? path
51
+ : `/${path}`
52
+ : `/${path
53
+ .filter((part) => part !== '/')
54
+ .map((part) => part.replace(/^\/+/, '').replace(/\/+$/, ''))
55
+ .join('/')}`;
56
+ }
57
+ /**
58
+ * Get page details for a route, with layout and other details
59
+ * @param {string} path route path
60
+ * @param {PageOptions} [pageOptions] site, language and personalization variant details for route
61
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
62
+ * @returns {Page | null} page details
63
+ */
64
+ async getPage(path, pageOptions, fetchOptions) {
65
+ var _a, _b, _c;
66
+ const computedPath = this.parsePath(path);
67
+ const locale = (_a = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.locale) !== null && _a !== void 0 ? _a : this.initOptions.defaultLanguage;
68
+ const site = (_b = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.site) !== null && _b !== void 0 ? _b : this.initOptions.defaultSite;
69
+ // Fetch layout data, passing on req/res for SSR
70
+ const layout = await this.layoutService.fetchLayoutData(computedPath, {
71
+ locale,
72
+ site,
73
+ }, fetchOptions);
74
+ if (!layout.sitecore.route) {
75
+ return null;
76
+ }
77
+ else {
78
+ const siteInfo = this.siteResolver.getByName(site);
79
+ // Initialize links to be inserted on the page
80
+ if ((_c = pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.personalize) === null || _c === void 0 ? void 0 : _c.variantId) {
81
+ // Modify layoutData to use specific variant(s) instead of default
82
+ // This will also set the variantId on the Sitecore context so that it is accessible here
83
+ (0, layout_personalizer_1.personalizeLayout)(layout, pageOptions.personalize.variantId, pageOptions.personalize.componentVariantIds);
84
+ }
85
+ return {
86
+ layout,
87
+ site: siteInfo,
88
+ locale,
89
+ };
90
+ }
91
+ }
92
+ /**
93
+ * Retrieves the head `<link>` elements for Sitecore styles and themes.
94
+ * @param {LayoutServiceData} layoutData - The layout data containing styles and themes.
95
+ * @param {object} [options] - Optional configuration for enabling styles and themes.
96
+ * @param {boolean} [options.enableStyles] - Whether to include content styles.
97
+ * @param {boolean} [options.enableThemes] - Whether to include theme styles.
98
+ * @returns {HTMLLink[]} An array of `<link>` elements for stylesheets.
99
+ */
100
+ getHeadLinks(layoutData, options = {}) {
101
+ const { enableStyles = true, enableThemes = true } = options;
102
+ const { contextId, edgeUrl } = this.initOptions.api.edge;
103
+ const headLinks = [];
104
+ if (enableStyles) {
105
+ const contentStyles = (0, layout_1.getContentStylesheetLink)(layoutData, contextId, edgeUrl);
106
+ if (contentStyles)
107
+ headLinks.push(contentStyles);
108
+ }
109
+ if (enableThemes) {
110
+ headLinks.push(...(0, layout_1.getDesignLibraryStylesheetLinks)(layoutData, contextId, edgeUrl));
111
+ }
112
+ return headLinks;
113
+ }
114
+ /**
115
+ * Retrieves dictionary phrases for a given site and locale.
116
+ * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
117
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
118
+ * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
119
+ */
120
+ async getDictionary(routeOptions, fetchOptions) {
121
+ const locale = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.locale) || this.initOptions.defaultLanguage;
122
+ const site = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.site) || this.initOptions.defaultSite;
123
+ return await this.dictionaryService.fetchDictionaryData(locale, site, fetchOptions);
124
+ }
125
+ /**
126
+ * Retrieves error pages for a given site and locale.
127
+ * @param {RouteOptions} routeOptions - Route options containing language and site name to load error pages
128
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
129
+ * @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
130
+ */
131
+ async getErrorPages(routeOptions, fetchOptions) {
132
+ const locale = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.locale) || this.initOptions.defaultLanguage;
133
+ const site = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.site) || this.initOptions.defaultSite;
134
+ return await this.errorPagesService.fetchErrorPages(site, locale, fetchOptions);
135
+ }
136
+ /**
137
+ * Retrieves preview page and layout details
138
+ * @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
139
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
140
+ * @returns {Page} preview page details
141
+ */
142
+ async getPreview(previewData, fetchOptions) {
143
+ if (!previewData) {
144
+ console.error('Preview data missing');
145
+ return null;
146
+ }
147
+ // If we're in Pages preview (editing) mode, prefetch the editing data
148
+ const { site, itemId, language, version, variantIds, layoutKind, } = previewData;
149
+ const data = await this.editingService.fetchEditingData({
150
+ siteName: site,
151
+ itemId,
152
+ language,
153
+ version,
154
+ layoutKind,
155
+ }, fetchOptions);
156
+ if (!data) {
157
+ throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(previewData)}`);
158
+ }
159
+ const page = {
160
+ locale: language,
161
+ layout: data.layoutData,
162
+ dictionary: data.dictionary,
163
+ site: data.layoutData.sitecore.context.site,
164
+ };
165
+ const personalizeData = (0, utils_1.getGroomedVariantIds)(variantIds);
166
+ (0, layout_personalizer_1.personalizeLayout)(page.layout, personalizeData.variantId, personalizeData.componentVariantIds);
167
+ return page;
168
+ }
169
+ /**
170
+ * Get design library page details for Design Library mode of your app
171
+ * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
172
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
173
+ * @returns {Page} preview page for Design Library
174
+ */
175
+ async getDesignLibraryData(designLibData, fetchOptions) {
176
+ if (!this.initOptions.api.local) {
177
+ throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
178
+ }
179
+ const { itemId, componentUid, site, language, renderingId, dataSourceId, version, } = designLibData;
180
+ const componentData = await this.componentService.fetchComponentData({
181
+ siteName: site,
182
+ itemId,
183
+ language,
184
+ componentUid,
185
+ renderingId,
186
+ dataSourceId,
187
+ version,
188
+ });
189
+ const dictionaryData = await this.editingService.fetchDictionaryData({
190
+ siteName: site,
191
+ language,
192
+ }, fetchOptions);
193
+ if (!componentData) {
194
+ throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(designLibData)}`);
195
+ }
196
+ const page = {
197
+ locale: designLibData.language,
198
+ layout: componentData,
199
+ dictionary: dictionaryData,
200
+ };
201
+ return page;
202
+ }
203
+ /**
204
+ * Retrieves the static paths for pages based on the given languages.
205
+ * @param {string[]} [languages] - An optional array of language codes to generate paths for.
206
+ * @param {FetchOptions} [fetchOptions] - Additional fetch options.
207
+ * @returns {Promise<StaticPath[]>} A promise that resolves to an array of static paths.
208
+ */
209
+ async getPagePaths(languages, fetchOptions) {
210
+ return this.sitePathService.fetchSiteRoutes(languages || [], fetchOptions);
211
+ }
212
+ /**
213
+ * Factory methods for creating dependencies
214
+ * Subclasses can override these to provide custom implementations.
215
+ */
216
+ getBaseServiceOptions() {
217
+ return {
218
+ defaultSite: this.initOptions.defaultSite,
219
+ clientFactory: this.clientFactory,
220
+ retries: this.initOptions.retries,
221
+ };
222
+ }
223
+ getClientFactory() {
224
+ const graphQLOptions = {
225
+ api: this.initOptions.api,
226
+ retries: this.initOptions.retries.count,
227
+ retryStrategy: this.initOptions.retries.retryStrategy,
228
+ };
229
+ return (0, utils_2.createGraphQLClientFactory)(graphQLOptions);
230
+ }
231
+ getSiteResolver() {
232
+ return new site_1.SiteResolver(this.initOptions.sites);
233
+ }
234
+ getLayoutService(baseOptions) {
235
+ return new layout_1.GraphQLLayoutService(Object.assign(Object.assign({}, baseOptions), { formatLayoutQuery: this.initOptions.layout.formatLayoutQuery }));
236
+ }
237
+ getDictionaryService(baseOptions) {
238
+ return new i18n_1.GraphQLDictionaryService(Object.assign(Object.assign({}, baseOptions), { cacheEnabled: this.initOptions.dictionary.caching.enabled, cacheTimeout: this.initOptions.dictionary.caching.timeout }));
239
+ }
240
+ getEditingService() {
241
+ return new editing_1.GraphQLEditingService({ clientFactory: this.clientFactory });
242
+ }
243
+ getErrorPagesService() {
244
+ return new site_1.GraphQLErrorPagesService(Object.assign(Object.assign({}, this.initOptions), { language: this.initOptions.defaultLanguage, clientFactory: this.clientFactory }));
245
+ }
246
+ getComponentService() {
247
+ var _a, _b;
248
+ return new editing_1.RestComponentLayoutService({
249
+ apiHost: (_a = this.initOptions.api.local) === null || _a === void 0 ? void 0 : _a.apiHost,
250
+ apiKey: (_b = this.initOptions.api.local) === null || _b === void 0 ? void 0 : _b.apiKey,
251
+ siteName: this.initOptions.defaultSite,
252
+ });
253
+ }
254
+ getSitePathService() {
255
+ return new site_1.GraphQLSitePathService({
256
+ clientFactory: this.clientFactory,
257
+ sites: this.siteResolver.sites,
258
+ });
259
+ }
260
+ }
261
+ exports.SitecoreClient = SitecoreClient;
@@ -0,0 +1,30 @@
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 graphql_edge_proxy_1 = require("./graphql-edge-proxy");
6
+ /**
7
+ * Creates a new GraphQLRequestClientFactory instance
8
+ * @param {GraphQLClientOptions} options jss config
9
+ * @returns GraphQLRequestClientFactory instance
10
+ */
11
+ const createGraphQLClientFactory = (options) => {
12
+ var _a, _b, _c, _d, _e, _f;
13
+ let clientConfig;
14
+ if ((_b = (_a = options.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId) {
15
+ clientConfig = {
16
+ endpoint: (0, graphql_edge_proxy_1.getEdgeProxyContentUrl)(options.api.edge.contextId, options.api.edge.edgeUrl),
17
+ };
18
+ }
19
+ else if (((_d = (_c = options.api) === null || _c === void 0 ? void 0 : _c.local) === null || _d === void 0 ? void 0 : _d.apiKey) && ((_f = (_e = options.api) === null || _e === void 0 ? void 0 : _e.local) === null || _f === void 0 ? void 0 : _f.apiHost)) {
20
+ clientConfig = {
21
+ endpoint: `${options.api.local.apiHost}${options.api.local.path}`,
22
+ apiKey: options.api.local.apiKey,
23
+ };
24
+ }
25
+ else {
26
+ throw new Error('Please configure and use either your sitecoreEdgeContextId, or your graphQLEndpoint and sitecoreApiKey.');
27
+ }
28
+ return graphql_request_client_1.GraphQLRequestClient.createClientFactory(Object.assign(Object.assign({}, clientConfig), options));
29
+ };
30
+ exports.createGraphQLClientFactory = createGraphQLClientFactory;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineCliConfig = void 0;
4
+ const validateConfig = (cliConfig) => {
5
+ var _a, _b, _c, _d;
6
+ if (!((_b = (_a = cliConfig.build) === null || _a === void 0 ? void 0 : _a.commands) === null || _b === void 0 ? void 0 : _b.length)) {
7
+ throw new Error('Configuration error: build commands should be defined in sitecore.cli.config');
8
+ }
9
+ if (!((_d = (_c = cliConfig.scaffold) === null || _c === void 0 ? void 0 : _c.templates) === null || _d === void 0 ? void 0 : _d.length)) {
10
+ throw new Error('Configuration error: scaffold templates should be defined in sitecore.cli.config');
11
+ }
12
+ };
13
+ /**
14
+ * Accepts a `SitecoreCliConfigInput` object and returns Sitecore Content SDK CLI configuration, updated with required default values
15
+ * @param {SitecoreCliConfigInput} cliConfig the cli configuration provided by the application
16
+ * @returns {SitecoreCliConfig} full sitecore cli configuration to use with cli
17
+ */
18
+ const defineCliConfig = (cliConfig) => {
19
+ validateConfig(cliConfig);
20
+ return cliConfig;
21
+ };
22
+ exports.defineCliConfig = defineCliConfig;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineConfig = exports.getFallbackConfig = void 0;
4
+ const constants_1 = require("../constants");
5
+ const retries_1 = require("../retries");
6
+ /**
7
+ * Provides default initial values for SitecoreConfig
8
+ * @returns default config
9
+ */
10
+ const getFallbackConfig = () => ({
11
+ api: {
12
+ edge: {
13
+ contextId: '',
14
+ clientContextId: '',
15
+ edgeUrl: constants_1.SITECORE_EDGE_URL_DEFAULT,
16
+ },
17
+ local: {
18
+ apiKey: '',
19
+ apiHost: '',
20
+ path: '/sitecore/api/graph/edge',
21
+ },
22
+ },
23
+ editingSecret: 'editing-secret-missing',
24
+ retries: {
25
+ count: 3,
26
+ retryStrategy: new retries_1.DefaultRetryStrategy({
27
+ statusCodes: [429, 502, 503, 504, 520, 521, 522, 523, 524],
28
+ }),
29
+ },
30
+ redirects: {
31
+ enabled: process.env.NODE_ENV !== 'development',
32
+ locales: ['en'],
33
+ },
34
+ multisite: {
35
+ enabled: true,
36
+ defaultHostname: '',
37
+ useCookieResolution: () => false,
38
+ },
39
+ personalize: {
40
+ enabled: process.env.NODE_ENV !== 'development',
41
+ edgeTimeout: 400,
42
+ cdpTimeout: 400,
43
+ scope: '',
44
+ channel: 'WEB',
45
+ currency: 'USD',
46
+ },
47
+ defaultSite: '',
48
+ defaultLanguage: 'en',
49
+ layout: {
50
+ formatLayoutQuery: null,
51
+ },
52
+ dictionary: {
53
+ caching: {
54
+ enabled: true,
55
+ timeout: 60,
56
+ },
57
+ },
58
+ });
59
+ exports.getFallbackConfig = getFallbackConfig;
60
+ /**
61
+ * Merges two SitecoreConfig objects
62
+ * @param {SitecoreConfig} base base sitecore config object
63
+ * @param {SitecoreConfig} override override sitecore config object
64
+ * @returns merged SitecoreConfig object
65
+ */
66
+ const deepMerge = (base, override) => {
67
+ var _a, _b, _c, _d, _e;
68
+ const result = Object.assign(Object.assign(Object.assign({}, base), override), { api: {
69
+ edge: Object.assign(Object.assign({}, (_a = base.api) === null || _a === void 0 ? void 0 : _a.edge), (_b = override.api) === null || _b === void 0 ? void 0 : _b.edge),
70
+ local: Object.assign(Object.assign({}, (_c = base.api) === null || _c === void 0 ? void 0 : _c.local), (_d = override.api) === null || _d === void 0 ? void 0 : _d.local),
71
+ }, retries: Object.assign(Object.assign({}, base.retries), override.retries), layout: Object.assign(Object.assign({}, base.layout), override.layout), multisite: Object.assign(Object.assign({}, base.multisite), override.multisite), personalize: Object.assign(Object.assign({}, base.personalize), override.personalize), redirects: Object.assign(Object.assign({}, base.redirects), override.redirects), dictionary: Object.assign(Object.assign({}, base.dictionary), override.dictionary) });
72
+ if (Number.isNaN(result.personalize.cdpTimeout) || !result.personalize.cdpTimeout) {
73
+ result.personalize.cdpTimeout = base.personalize.cdpTimeout;
74
+ }
75
+ if (Number.isNaN(result.personalize.edgeTimeout) || !result.personalize.edgeTimeout) {
76
+ result.personalize.edgeTimeout = base.personalize.edgeTimeout;
77
+ }
78
+ // fallback in case only one context provided
79
+ if (((_e = result.api.edge) === null || _e === void 0 ? void 0 : _e.clientContextId) && !result.api.edge.contextId) {
80
+ result.api.edge.contextId = result.api.edge.clientContextId;
81
+ }
82
+ return result;
83
+ };
84
+ const validateConfig = (config) => {
85
+ var _a, _b, _c, _d, _e, _f, _g, _h;
86
+ if (!((_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId) &&
87
+ (!((_d = (_c = config === null || config === void 0 ? void 0 : config.api) === null || _c === void 0 ? void 0 : _c.local) === null || _d === void 0 ? void 0 : _d.apiHost) || !((_f = (_e = config === null || config === void 0 ? void 0 : config.api) === null || _e === void 0 ? void 0 : _e.local) === null || _f === void 0 ? void 0 : _f.apiKey))) {
88
+ // consider client-side usecase
89
+ if (!((_h = (_g = config.api) === null || _g === void 0 ? void 0 : _g.edge) === null || _h === void 0 ? void 0 : _h.clientContextId)) {
90
+ throw new Error('Configuration error: either context ID or API key and host must be specified in sitecore.config');
91
+ }
92
+ }
93
+ if (!config.defaultSite) {
94
+ throw new Error('Configuration error: defaultSite value should be defined in sitecore.config');
95
+ }
96
+ };
97
+ /**
98
+ * Accepts a SitecoreConfigInput object and returns full sitecore configuration
99
+ * @param {SitecoreConfigInput} config override values to be written over default config settings
100
+ * @returns {SitecoreConfig} full sitecore configuration to use in application
101
+ */
102
+ const defineConfig = (config) => {
103
+ validateConfig(config);
104
+ return deepMerge((0, exports.getFallbackConfig)(), config);
105
+ };
106
+ exports.defineConfig = defineConfig;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineCliConfig = 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; } });
8
+ var define_cli_config_1 = require("./define-cli-config");
9
+ Object.defineProperty(exports, "defineCliConfig", { enumerable: true, get: function () { return define_cli_config_1.defineCliConfig; } });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentTemplateType = void 0;
4
+ /**
5
+ * Enumeration of the default component templates.
6
+ */
7
+ var ComponentTemplateType;
8
+ (function (ComponentTemplateType) {
9
+ ComponentTemplateType["BYOC"] = "byoc";
10
+ ComponentTemplateType["DEFAULT"] = "default";
11
+ })(ComponentTemplateType || (exports.ComponentTemplateType = ComponentTemplateType = {}));
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ResponseError = void 0;
13
4
  exports.fetchData = fetchData;
@@ -25,9 +16,7 @@ exports.ResponseError = ResponseError;
25
16
  * @param {HttpDataFetcher<T> | NativeDataFetcherFunction<T>} fetcher the fetcher to use to perform the request
26
17
  * @param {ParsedUrlQueryInput} params the query string parameters to send with the request
27
18
  */
28
- function fetchData(url_1, fetcher_1) {
29
- return __awaiter(this, arguments, void 0, function* (url, fetcher, params = {}) {
30
- const response = yield fetcher((0, utils_1.resolveUrl)(url, params));
31
- return response.data;
32
- });
19
+ async function fetchData(url, fetcher, params = {}) {
20
+ const response = await fetcher((0, utils_1.resolveUrl)(url, params));
21
+ return response.data;
33
22
  }
package/dist/cjs/debug.js CHANGED
@@ -29,6 +29,7 @@ exports.enableDebug = enableDebug;
29
29
  */
30
30
  exports.default = {
31
31
  common: (0, debug_1.default)(`${rootNamespace}:common`),
32
+ form: (0, debug_1.default)(`${rootNamespace}:form`),
32
33
  http: (0, debug_1.default)(`${rootNamespace}:http`),
33
34
  layout: (0, debug_1.default)(`${rootNamespace}:layout`),
34
35
  dictionary: (0, debug_1.default)(`${rootNamespace}:dictionary`),
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateComponentHandler = exports.addComponentUpdateHandler = exports.ComponentLibraryStatus = exports.COMPONENT_LIBRARY_STATUS_EVENT_NAME = void 0;
4
- exports.getComponentLibraryStatusEvent = getComponentLibraryStatusEvent;
3
+ exports.updateComponentHandler = exports.addComponentUpdateHandler = exports.DesignLibraryStatus = exports.DESIGN_LIBRARY_STATUS_EVENT_NAME = void 0;
4
+ exports.getDesignLibraryStatusEvent = getDesignLibraryStatusEvent;
5
5
  /**
6
- * Event to be sent when report status to component library
6
+ * Event to be sent when report status to design library
7
7
  */
8
- exports.COMPONENT_LIBRARY_STATUS_EVENT_NAME = 'component:status';
8
+ exports.DESIGN_LIBRARY_STATUS_EVENT_NAME = 'component:status';
9
9
  /**
10
- * Enumeration of statuses for the component library.
10
+ * Enumeration of statuses for the design library.
11
11
  */
12
- var ComponentLibraryStatus;
13
- (function (ComponentLibraryStatus) {
14
- ComponentLibraryStatus["READY"] = "ready";
15
- ComponentLibraryStatus["RENDERED"] = "rendered";
16
- })(ComponentLibraryStatus || (exports.ComponentLibraryStatus = ComponentLibraryStatus = {}));
12
+ var DesignLibraryStatus;
13
+ (function (DesignLibraryStatus) {
14
+ DesignLibraryStatus["READY"] = "ready";
15
+ DesignLibraryStatus["RENDERED"] = "rendered";
16
+ })(DesignLibraryStatus || (exports.DesignLibraryStatus = DesignLibraryStatus = {}));
17
17
  /**
18
- * Adds the browser-side event handler for 'component:update' message used in Component Library
18
+ * Adds the browser-side event handler for 'component:update' message used in Design Library
19
19
  * The event should update a component on page by uid, with fields and params from event args
20
- * @param {ComponentRendering} rootComponent root component displayed for Component Library page
20
+ * @param {ComponentRendering} rootComponent root component displayed for Design Library page
21
21
  * @param {Function} successCallback callback to be called after successful component update
22
22
  */
23
23
  const addComponentUpdateHandler = (rootComponent, successCallback) => {
@@ -88,14 +88,14 @@ const updateComponentHandler = (e, rootComponent, successCallback) => {
88
88
  };
89
89
  exports.updateComponentHandler = updateComponentHandler;
90
90
  /**
91
- * Generates a ComponentLibraryStatusEvent with the given status and uid.
92
- * @param {ComponentLibraryStatus} status - The status of rendering.
91
+ * Generates a DesignLibraryStatusEvent with the given status and uid.
92
+ * @param {DesignLibraryStatus} status - The status of rendering.
93
93
  * @param {string} uid - The unique identifier for the event.
94
- * @returns An object representing the ComponentLibraryStatusEvent.
94
+ * @returns An object representing the DesignLibraryStatusEvent.
95
95
  */
96
- function getComponentLibraryStatusEvent(status, uid) {
96
+ function getDesignLibraryStatusEvent(status, uid) {
97
97
  return {
98
- name: exports.COMPONENT_LIBRARY_STATUS_EVENT_NAME,
98
+ name: exports.DESIGN_LIBRARY_STATUS_EVENT_NAME,
99
99
  message: {
100
100
  status,
101
101
  uid,