@sitecore-content-sdk/content 2.0.0-canary.8 → 2.0.0
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.
- package/LICENSE.txt +202 -202
- package/dist/cjs/client/sitecore-client.js +3 -5
- package/dist/cjs/config/define-config.js +4 -4
- package/dist/cjs/constants.js +1 -5
- package/dist/cjs/editing/codegen/index.js +2 -2
- package/dist/cjs/editing/codegen/preview.js +43 -15
- package/dist/cjs/editing/component-layout-service.js +2 -2
- package/dist/cjs/editing/design-library.js +26 -18
- package/dist/cjs/form/form.js +7 -5
- package/dist/cjs/i18n/dictionary-service.js +4 -6
- package/dist/cjs/site/error-pages-service.js +3 -2
- package/dist/cjs/site/redirects-service.js +2 -2
- package/dist/cjs/site/robots-service.js +3 -2
- package/dist/cjs/site/site-resolver.js +3 -1
- package/dist/cjs/site/sitemap-xml-service.js +3 -2
- package/dist/cjs/site/sitepath-service.js +5 -4
- package/dist/cjs/tools/codegen/component-generation.js +3 -3
- package/dist/cjs/tools/codegen/extract-files.js +4 -3
- package/dist/cjs/tools/codegen/import-map.js +7 -13
- package/dist/cjs/tools/codegen/utils.js +2 -1
- package/dist/cjs/tools/generateSites.js +4 -2
- package/dist/esm/client/sitecore-client.js +4 -6
- package/dist/esm/config/define-config.js +5 -5
- package/dist/esm/constants.js +0 -4
- package/dist/esm/editing/codegen/index.js +1 -1
- package/dist/esm/editing/codegen/preview.js +43 -15
- package/dist/esm/editing/component-layout-service.js +2 -2
- package/dist/esm/editing/design-library.js +24 -17
- package/dist/esm/form/form.js +6 -4
- package/dist/esm/i18n/dictionary-service.js +4 -6
- package/dist/esm/site/error-pages-service.js +3 -2
- package/dist/esm/site/redirects-service.js +3 -3
- package/dist/esm/site/robots-service.js +3 -2
- package/dist/esm/site/site-resolver.js +3 -1
- package/dist/esm/site/sitemap-xml-service.js +3 -2
- package/dist/esm/site/sitepath-service.js +4 -3
- package/dist/esm/tools/codegen/component-generation.js +3 -3
- package/dist/esm/tools/codegen/extract-files.js +5 -4
- package/dist/esm/tools/codegen/import-map.js +7 -13
- package/dist/esm/tools/codegen/utils.js +3 -2
- package/dist/esm/tools/generateSites.js +4 -2
- package/package.json +5 -5
- package/types/client/sitecore-client.d.ts.map +1 -1
- package/types/config/define-config.d.ts.map +1 -1
- package/types/constants.d.ts +0 -4
- package/types/constants.d.ts.map +1 -1
- package/types/editing/codegen/index.d.ts +1 -1
- package/types/editing/codegen/index.d.ts.map +1 -1
- package/types/editing/codegen/preview.d.ts +42 -9
- package/types/editing/codegen/preview.d.ts.map +1 -1
- package/types/editing/component-layout-service.d.ts.map +1 -1
- package/types/editing/design-library.d.ts +7 -0
- package/types/editing/design-library.d.ts.map +1 -1
- package/types/form/form.d.ts.map +1 -1
- package/types/i18n/dictionary-service.d.ts +0 -2
- package/types/i18n/dictionary-service.d.ts.map +1 -1
- package/types/site/error-pages-service.d.ts.map +1 -1
- package/types/site/redirects-service.d.ts.map +1 -1
- package/types/site/robots-service.d.ts.map +1 -1
- package/types/site/site-resolver.d.ts.map +1 -1
- package/types/site/sitemap-xml-service.d.ts.map +1 -1
- package/types/site/sitepath-service.d.ts +0 -1
- package/types/site/sitepath-service.d.ts.map +1 -1
- package/types/tools/codegen/component-generation.d.ts.map +1 -1
- package/types/tools/codegen/extract-files.d.ts.map +1 -1
- package/types/tools/codegen/import-map.d.ts.map +1 -1
- package/types/tools/codegen/utils.d.ts.map +1 -1
- package/types/tools/generateSites.d.ts.map +1 -1
|
@@ -8,6 +8,7 @@ const core_1 = require("@sitecore-content-sdk/core");
|
|
|
8
8
|
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
9
9
|
const debug_1 = __importDefault(require("../debug"));
|
|
10
10
|
const models_1 = require("./models");
|
|
11
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
11
12
|
/**
|
|
12
13
|
* REST service that enables Design Library functionality.
|
|
13
14
|
* Returns layout data for a single rendered component.
|
|
@@ -21,8 +22,7 @@ class ComponentLayoutService {
|
|
|
21
22
|
// Choose the correct Edge ID per environment
|
|
22
23
|
const sitecoreContextId = this.config.contextId || this.config.clientContextId;
|
|
23
24
|
if (!sitecoreContextId) {
|
|
24
|
-
throw new Error(
|
|
25
|
-
Provide contextId on the server, and clientContextId in the browser if you need to full client-side functionality.`);
|
|
25
|
+
throw new Error(ERROR_MESSAGES.MV_001);
|
|
26
26
|
}
|
|
27
27
|
const fetcher = new core_1.NativeDataFetcher({ debugger: debug_1.default.layout });
|
|
28
28
|
debug_1.default.layout('fetching component with uid %s for %s %s %s %s', params.componentUid, params.itemId, params.language, params.siteName, params.dataSourceId);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.postToDesignLibrary = exports.updateComponent = exports.updateComponentHandler = exports.validateEvent = exports.validateOrigin = exports.addComponentUpdateHandler = exports.DesignLibraryStatus = exports.COMPONENT_PREVIEW_CACHE_KEY_PREFIX = exports.COMPONENT_UPDATE_CACHE_KEY_PREFIX = void 0;
|
|
3
|
+
exports.postToDesignLibrary = exports.updateComponent = exports.findComponent = exports.updateComponentHandler = exports.validateEvent = exports.validateOrigin = exports.addComponentUpdateHandler = exports.DesignLibraryStatus = exports.COMPONENT_PREVIEW_CACHE_KEY_PREFIX = exports.COMPONENT_UPDATE_CACHE_KEY_PREFIX = void 0;
|
|
4
4
|
exports.getDesignLibraryStatusEvent = getDesignLibraryStatusEvent;
|
|
5
5
|
exports.getDesignLibraryScriptLink = getDesignLibraryScriptLink;
|
|
6
6
|
exports.isDesignLibraryMode = isDesignLibraryMode;
|
|
7
7
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
8
|
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
9
9
|
const models_1 = require("./models");
|
|
10
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
10
11
|
/**
|
|
11
12
|
* Event to be sent when report status to design library
|
|
12
13
|
*/
|
|
@@ -89,22 +90,7 @@ const updateComponentHandler = (e, rootComponent, successCallback) => {
|
|
|
89
90
|
console.debug('Received component:update event without uid, aborting event handler...');
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
|
-
const
|
|
93
|
-
var _a, _b;
|
|
94
|
-
if (((_a = root.uid) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = eventArgs.details) === null || _b === void 0 ? void 0 : _b.uid.toLowerCase()))
|
|
95
|
-
return root;
|
|
96
|
-
if (root.placeholders) {
|
|
97
|
-
for (const plhName of Object.keys(root.placeholders)) {
|
|
98
|
-
for (const rendering of root.placeholders[plhName]) {
|
|
99
|
-
const result = findComponent(rendering);
|
|
100
|
-
if (result)
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
};
|
|
107
|
-
const componentToUpdate = findComponent(rootComponent);
|
|
93
|
+
const componentToUpdate = (0, exports.findComponent)(rootComponent, eventArgs.details.uid);
|
|
108
94
|
if (componentToUpdate) {
|
|
109
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);
|
|
110
96
|
(0, exports.updateComponent)(componentToUpdate, eventArgs.details.fields, eventArgs.details.params);
|
|
@@ -118,6 +104,28 @@ const updateComponentHandler = (e, rootComponent, successCallback) => {
|
|
|
118
104
|
return rootComponent;
|
|
119
105
|
};
|
|
120
106
|
exports.updateComponentHandler = updateComponentHandler;
|
|
107
|
+
/**
|
|
108
|
+
* Recursively searches for a component with the specified UID within the given root component and its placeholders.
|
|
109
|
+
* @param {ComponentRendering} root - The root component to start the search from.
|
|
110
|
+
* @param {string} uid - The unique identifier of the component to find.
|
|
111
|
+
* @returns {ComponentRendering | null} The component with the specified UID if found; otherwise, null.
|
|
112
|
+
*/
|
|
113
|
+
const findComponent = (root, uid) => {
|
|
114
|
+
var _a;
|
|
115
|
+
if (((_a = root.uid) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === uid.toLowerCase())
|
|
116
|
+
return root;
|
|
117
|
+
if (root.placeholders) {
|
|
118
|
+
for (const plhName of Object.keys(root.placeholders)) {
|
|
119
|
+
for (const rendering of root.placeholders[plhName]) {
|
|
120
|
+
const result = (0, exports.findComponent)(rendering, uid);
|
|
121
|
+
if (result)
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
};
|
|
128
|
+
exports.findComponent = findComponent;
|
|
121
129
|
/**
|
|
122
130
|
* Updates a component's fields and params with the provided values.
|
|
123
131
|
* @param {ComponentRendering<ComponentFields>} component - The component to update.
|
|
@@ -185,7 +193,7 @@ const postToDesignLibrary = (evt) => {
|
|
|
185
193
|
target.postMessage(evt, '*');
|
|
186
194
|
}
|
|
187
195
|
catch (err) {
|
|
188
|
-
console.error(
|
|
196
|
+
console.error(`Component Library: postMessage failed. ${ERROR_MESSAGES.CONTACT_SUPPORT}`, err, evt);
|
|
189
197
|
}
|
|
190
198
|
};
|
|
191
199
|
exports.postToDesignLibrary = postToDesignLibrary;
|
package/dist/cjs/form/form.js
CHANGED
|
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.subscribeToFormSubmitEvent = exports.executeScriptElements = exports.loadForm = void 0;
|
|
7
|
-
const
|
|
7
|
+
const events_1 = require("@sitecore-content-sdk/events");
|
|
8
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
9
|
const client_1 = require("../client");
|
|
9
10
|
const debug_1 = __importDefault(require("../debug"));
|
|
11
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
10
12
|
/**
|
|
11
13
|
* Fetches the form markup from the Sitecore Edge service and renders it in the component's template.
|
|
12
14
|
* @param {string} contextId - The unique identifier of the current context
|
|
@@ -16,7 +18,7 @@ const debug_1 = __importDefault(require("../debug"));
|
|
|
16
18
|
*/
|
|
17
19
|
const loadForm = async (contextId, formId, edgeUrl) => {
|
|
18
20
|
if (!contextId) {
|
|
19
|
-
debug_1.default.form(
|
|
21
|
+
debug_1.default.form(`${ERROR_MESSAGES.MV_001}. Form was not able to render.`);
|
|
20
22
|
return '';
|
|
21
23
|
}
|
|
22
24
|
const url = (0, client_1.getEdgeProxyFormsUrl)(contextId, formId, edgeUrl);
|
|
@@ -27,14 +29,14 @@ const loadForm = async (contextId, formId, edgeUrl) => {
|
|
|
27
29
|
cache: 'no-cache',
|
|
28
30
|
});
|
|
29
31
|
if (rsp.status !== 200) {
|
|
30
|
-
throw new Error(
|
|
32
|
+
throw new Error(`Failed to fetch form data. ${ERROR_MESSAGES.CONTACT_SUPPORT}`);
|
|
31
33
|
}
|
|
32
34
|
const content = await rsp.text();
|
|
33
35
|
debug_1.default.form(`Form data fetch response: ${content}`);
|
|
34
36
|
return content;
|
|
35
37
|
}
|
|
36
38
|
catch (error) {
|
|
37
|
-
debug_1.default.form(`Form '${formId}' was not able to render`, error);
|
|
39
|
+
debug_1.default.form(`Form '${formId}' was not able to render. ${ERROR_MESSAGES.CONTACT_SUPPORT}`, error);
|
|
38
40
|
throw error;
|
|
39
41
|
}
|
|
40
42
|
};
|
|
@@ -74,7 +76,7 @@ const subscribeToFormSubmitEvent = (formElement, componentId) => {
|
|
|
74
76
|
const { formId, name } = e.detail;
|
|
75
77
|
if (formId && name) {
|
|
76
78
|
debug_1.default.form('Sending form event', formId, name);
|
|
77
|
-
(0,
|
|
79
|
+
(0, events_1.form)(formId, name, (componentId === null || componentId === void 0 ? void 0 : componentId.replace(/-/g, '')) || '');
|
|
78
80
|
}
|
|
79
81
|
}));
|
|
80
82
|
};
|
|
@@ -3,12 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DictionaryService =
|
|
6
|
+
exports.DictionaryService = void 0;
|
|
7
7
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
8
|
const debug_1 = __importDefault(require("../debug"));
|
|
10
|
-
|
|
11
|
-
exports.queryError = 'Valid value for rootItemId not provided and failed to auto-resolve app root item.';
|
|
9
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
12
10
|
/** @default */
|
|
13
11
|
const siteQuery = /* GraphQL */ `
|
|
14
12
|
query DictionarySiteQuery(
|
|
@@ -71,10 +69,10 @@ class DictionaryService {
|
|
|
71
69
|
let hasNext = true;
|
|
72
70
|
let after = '';
|
|
73
71
|
if (!site) {
|
|
74
|
-
throw new RangeError(
|
|
72
|
+
throw new RangeError(ERROR_MESSAGES.MV_002);
|
|
75
73
|
}
|
|
76
74
|
if (!language) {
|
|
77
|
-
throw new RangeError(
|
|
75
|
+
throw new RangeError(ERROR_MESSAGES.MV_009);
|
|
78
76
|
}
|
|
79
77
|
while (hasNext) {
|
|
80
78
|
const fetchResponse = await this.graphQLClient.request(siteQuery, {
|
|
@@ -4,8 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ErrorPagesService = void 0;
|
|
7
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
7
8
|
const debug_1 = __importDefault(require("../debug"));
|
|
8
|
-
const
|
|
9
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
9
10
|
// The default query for request error handling
|
|
10
11
|
const defaultQuery = /* GraphQL */ `
|
|
11
12
|
query ErrorPagesQuery($siteName: String!, $language: String!) {
|
|
@@ -52,7 +53,7 @@ class ErrorPagesService {
|
|
|
52
53
|
async fetchErrorPages(siteName, locale, fetchOptions) {
|
|
53
54
|
const language = locale || this.options.language;
|
|
54
55
|
if (!siteName) {
|
|
55
|
-
throw new Error(
|
|
56
|
+
throw new Error(ERROR_MESSAGES.MV_002);
|
|
56
57
|
}
|
|
57
58
|
return this.graphQLClient.request(this.query, {
|
|
58
59
|
siteName,
|
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RedirectsService = exports.REDIRECT_TYPE_SERVER_TRANSFER = exports.REDIRECT_TYPE_302 = exports.REDIRECT_TYPE_301 = void 0;
|
|
7
7
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
8
|
const debug_1 = __importDefault(require("../debug"));
|
|
9
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
10
10
|
/**
|
|
11
11
|
* Redirect type for 301 redirects
|
|
12
12
|
* @public
|
|
@@ -66,7 +66,7 @@ class RedirectsService {
|
|
|
66
66
|
async fetchRedirects(siteName, fetchOptions) {
|
|
67
67
|
var _a, _b;
|
|
68
68
|
if (!siteName) {
|
|
69
|
-
throw new Error(
|
|
69
|
+
throw new Error(ERROR_MESSAGES.MV_002);
|
|
70
70
|
}
|
|
71
71
|
const cacheKey = `redirects-${siteName}`;
|
|
72
72
|
let data = this.cache.getCacheValue(cacheKey);
|
|
@@ -4,8 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RobotsService = void 0;
|
|
7
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
7
8
|
const debug_1 = __importDefault(require("../debug"));
|
|
8
|
-
const
|
|
9
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
9
10
|
// The default query for request robots.txt
|
|
10
11
|
const defaultQuery = /* GraphQL */ `
|
|
11
12
|
query RobotsQuery($siteName: String!) {
|
|
@@ -41,7 +42,7 @@ class RobotsService {
|
|
|
41
42
|
async fetchRobots(fetchOptions) {
|
|
42
43
|
const siteName = this.options.siteName;
|
|
43
44
|
if (!siteName) {
|
|
44
|
-
throw new Error(
|
|
45
|
+
throw new Error(ERROR_MESSAGES.MV_002);
|
|
45
46
|
}
|
|
46
47
|
const robotsResult = this.graphQLClient.request(this.query, {
|
|
47
48
|
siteName,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SiteResolver = void 0;
|
|
4
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
5
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
4
6
|
// Delimiters for multi-value hostnames
|
|
5
7
|
const DELIMITERS = /\||,|;/g;
|
|
6
8
|
/**
|
|
@@ -25,7 +27,7 @@ class SiteResolver {
|
|
|
25
27
|
return site;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
|
-
throw new Error(
|
|
30
|
+
throw new Error(ERROR_MESSAGES.IE_007(hostName));
|
|
29
31
|
};
|
|
30
32
|
/**
|
|
31
33
|
* Resolve site by site name
|
|
@@ -4,8 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SitemapXmlService = void 0;
|
|
7
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
7
8
|
const debug_1 = __importDefault(require("../debug"));
|
|
8
|
-
const
|
|
9
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
9
10
|
const PREFIX_NAME_SITEMAP = 'sitemap';
|
|
10
11
|
// The default query for request sitemaps
|
|
11
12
|
const defaultQuery = /* GraphQL */ `
|
|
@@ -42,7 +43,7 @@ class SitemapXmlService {
|
|
|
42
43
|
async fetchSitemaps(fetchOptions) {
|
|
43
44
|
const siteName = this.options.siteName;
|
|
44
45
|
if (!siteName) {
|
|
45
|
-
throw new Error(
|
|
46
|
+
throw new Error(ERROR_MESSAGES.MV_002);
|
|
46
47
|
}
|
|
47
48
|
const sitemapResult = this.graphQLClient.request(this.query, {
|
|
48
49
|
siteName,
|
|
@@ -3,21 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SitePathService = exports.sitesError = exports.
|
|
6
|
+
exports.SitePathService = exports.sitesError = exports.languageError = void 0;
|
|
7
7
|
exports.getSiteEmptyError = getSiteEmptyError;
|
|
8
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
9
|
const personalize_1 = require("../personalize");
|
|
9
10
|
const site_1 = require("../site");
|
|
10
11
|
const debug_1 = __importDefault(require("../debug"));
|
|
12
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
11
13
|
/** @private */
|
|
12
14
|
exports.languageError = 'The list of languages cannot be empty';
|
|
13
|
-
exports.siteError = 'The service needs a site name';
|
|
14
15
|
exports.sitesError = 'The list of sites cannot be empty';
|
|
15
16
|
/**
|
|
16
17
|
* @param {string} siteName to inject into error text
|
|
17
18
|
* @private
|
|
18
19
|
*/
|
|
19
20
|
function getSiteEmptyError(siteName) {
|
|
20
|
-
return
|
|
21
|
+
return ERROR_MESSAGES.IV_007(siteName);
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* GQL query made dynamic based whether personalization is enabled or not
|
|
@@ -110,7 +111,7 @@ class SitePathService {
|
|
|
110
111
|
});
|
|
111
112
|
const paths = new Array();
|
|
112
113
|
if (!languages.length) {
|
|
113
|
-
throw new RangeError(
|
|
114
|
+
throw new RangeError(ERROR_MESSAGES.MV_009);
|
|
114
115
|
}
|
|
115
116
|
// Get all sites
|
|
116
117
|
if (!sites || !sites.length) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getComponentSpec = exports.getComponentSpecUrl = void 0;
|
|
4
4
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
5
|
-
const { SITECORE_EDGE_PLATFORM_URL_DEFAULT } = core_1.constants;
|
|
5
|
+
const { SITECORE_EDGE_PLATFORM_URL_DEFAULT, ERROR_MESSAGES } = core_1.constants;
|
|
6
6
|
/**
|
|
7
7
|
* Gets the component spec url.
|
|
8
8
|
* @param {GetComponentSpecParams} params - The parameters for getting the component spec url.
|
|
@@ -35,14 +35,14 @@ const getComponentSpec = async ({ componentId, edgeUrl = SITECORE_EDGE_PLATFORM_
|
|
|
35
35
|
throw new Error('The token is incorrect or expired or the component ID is incorrect.');
|
|
36
36
|
}
|
|
37
37
|
if (!response.ok) {
|
|
38
|
-
throw new Error(`Failed to fetch component ${componentId}`);
|
|
38
|
+
throw new Error(`Failed to fetch component ${componentId}. ${ERROR_MESSAGES.CONTACT_SUPPORT}`);
|
|
39
39
|
}
|
|
40
40
|
const spec = await response.json();
|
|
41
41
|
core_1.debug.common('Component spec fetched successfully for %s: %o', componentId, spec);
|
|
42
42
|
return spec;
|
|
43
43
|
}
|
|
44
44
|
catch (error) {
|
|
45
|
-
core_1.debug.common(
|
|
45
|
+
core_1.debug.common(`Failed to fetch component spec: ${String(error)}. ${ERROR_MESSAGES.CONTACT_SUPPORT}`);
|
|
46
46
|
throw error;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
@@ -11,6 +11,7 @@ const node_tools_1 = require("@sitecore-content-sdk/core/node-tools");
|
|
|
11
11
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
12
12
|
const path_1 = __importDefault(require("path"));
|
|
13
13
|
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
14
15
|
/**
|
|
15
16
|
* Extracts components from the app folder and sends them to XMCloud.
|
|
16
17
|
* @param {ExtractFilesConfig} args - Config for components extraction
|
|
@@ -38,7 +39,7 @@ function _extractFiles(args = {}) {
|
|
|
38
39
|
const renderingHost = process.env.SITECORE_RENDERINGHOST_NAME;
|
|
39
40
|
return async ({ scConfig }) => {
|
|
40
41
|
if (!scConfig) {
|
|
41
|
-
throw new Error(
|
|
42
|
+
throw new Error(ERROR_MESSAGES.MV_008);
|
|
42
43
|
}
|
|
43
44
|
if ((args.customValidateDeployContext && !args.customValidateDeployContext()) ||
|
|
44
45
|
!(0, utils_1.validateDeployContext)()) {
|
|
@@ -56,7 +57,7 @@ function _extractFiles(args = {}) {
|
|
|
56
57
|
const targetUrl = scConfig.api.edge.edgeUrl;
|
|
57
58
|
const { accessToken } = await node_tools_1.auth.clientCredentialsFlow(authParams);
|
|
58
59
|
if (!accessToken) {
|
|
59
|
-
console.error(chalk_1.default.red(
|
|
60
|
+
console.error(chalk_1.default.red(`Failed to get access token, aborting code extraction. ${ERROR_MESSAGES.CONTACT_SUPPORT}`));
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
63
|
// Resolve files from component-map
|
|
@@ -97,7 +98,7 @@ function _extractFiles(args = {}) {
|
|
|
97
98
|
.join('\r\n')}`));
|
|
98
99
|
}
|
|
99
100
|
catch (error) {
|
|
100
|
-
console.warn(chalk_1.default.yellow(
|
|
101
|
+
console.warn(chalk_1.default.yellow(`Error during code extraction:`, error, error.stack, ERROR_MESSAGES.CONTACT_SUPPORT));
|
|
101
102
|
}
|
|
102
103
|
};
|
|
103
104
|
}
|
|
@@ -44,6 +44,8 @@ const core_1 = require("@sitecore-content-sdk/core");
|
|
|
44
44
|
const templating_1 = require("./../templating");
|
|
45
45
|
const crypto_1 = __importDefault(require("crypto"));
|
|
46
46
|
const utils_1 = require("./utils");
|
|
47
|
+
const core_2 = require("@sitecore-content-sdk/core");
|
|
48
|
+
const { ERROR_MESSAGES } = core_2.constants;
|
|
47
49
|
let _getComponentList = templating_1.getComponentList;
|
|
48
50
|
const aliasImport = /^([a-zA-Z0-9]+) as .+$/;
|
|
49
51
|
const unitMocks = ({ getComponentListStub, }) => {
|
|
@@ -252,19 +254,11 @@ const prepImportMaps = async (paths, separateMaps) => {
|
|
|
252
254
|
? componentPath
|
|
253
255
|
: path_1.default.resolve(appPath, componentPath);
|
|
254
256
|
// read the start of the file that may be 'use client'
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
const stream = fs_1.default.createReadStream(fullPath, { end: 12 });
|
|
258
|
-
stream
|
|
259
|
-
.on('data', async (chunk) => {
|
|
260
|
-
readBuffer += chunk.toString();
|
|
261
|
-
})
|
|
262
|
-
.on('close', () => resolve(readBuffer))
|
|
263
|
-
.on('error', () => resolve(''));
|
|
264
|
-
});
|
|
265
|
-
if (!firstLine)
|
|
257
|
+
const fileContent = await fs_1.default.promises.readFile(fullPath, 'utf8');
|
|
258
|
+
if (!fileContent)
|
|
266
259
|
continue;
|
|
267
|
-
if
|
|
260
|
+
// check if 'use client' directive is present, ignoring any comments or whitespace before it
|
|
261
|
+
if (fileContent.match(/^(?:\s|\/\/[^\n]*\n|\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\/)*['"]use client['"]/)) {
|
|
268
262
|
clientPaths.push(fullPath);
|
|
269
263
|
}
|
|
270
264
|
else {
|
|
@@ -286,7 +280,7 @@ const writeImportMap = (args) => {
|
|
|
286
280
|
const defaultTemplate = args.defaultTemplate || exports.defaultMapTemplate;
|
|
287
281
|
const clientTemplate = args.clientTemplate || exports.defaultMapTemplate;
|
|
288
282
|
if (!scConfig) {
|
|
289
|
-
throw new Error(
|
|
283
|
+
throw new Error(ERROR_MESSAGES.MV_008);
|
|
290
284
|
}
|
|
291
285
|
if (scConfig.disableCodeGeneration) {
|
|
292
286
|
core_1.debug.common('Skipping import map generation. Code generation functionality is disabled.');
|
|
@@ -46,6 +46,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
46
46
|
const ts = __importStar(require("typescript"));
|
|
47
47
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
48
48
|
const module_1 = require("module");
|
|
49
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
49
50
|
/**
|
|
50
51
|
* Parse the generated component-map file and return all referenced modules
|
|
51
52
|
* per map entry (handles both single identifiers and spread objects).
|
|
@@ -384,7 +385,7 @@ async function _sendCode({ file, token, targetUrl, }) {
|
|
|
384
385
|
}
|
|
385
386
|
}
|
|
386
387
|
catch (error) {
|
|
387
|
-
console.error(chalk_1.default.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}`));
|
|
388
|
+
console.error(chalk_1.default.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}. ${ERROR_MESSAGES.CONTACT_SUPPORT}`));
|
|
388
389
|
return null;
|
|
389
390
|
}
|
|
390
391
|
return file.path;
|
|
@@ -8,9 +8,11 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const node_tools_1 = require("@sitecore-content-sdk/core/node-tools");
|
|
11
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
11
12
|
const site_1 = require("../site");
|
|
12
13
|
const client_1 = require("../client");
|
|
13
14
|
const debug_1 = __importDefault(require("../debug"));
|
|
15
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
14
16
|
const DEFAULT_SITES_DIST_PATH = '.sitecore/sites.json';
|
|
15
17
|
/**
|
|
16
18
|
* Generates site information and writes it to a specified destination path.
|
|
@@ -21,7 +23,7 @@ const DEFAULT_SITES_DIST_PATH = '.sitecore/sites.json';
|
|
|
21
23
|
const generateSites = ({ destinationPath } = {}) => {
|
|
22
24
|
return async ({ scConfig }) => {
|
|
23
25
|
if (!scConfig) {
|
|
24
|
-
throw new Error(
|
|
26
|
+
throw new Error(ERROR_MESSAGES.MV_008);
|
|
25
27
|
}
|
|
26
28
|
let sites = [];
|
|
27
29
|
const sitesFilePath = path_1.default.resolve(destinationPath !== null && destinationPath !== void 0 ? destinationPath : DEFAULT_SITES_DIST_PATH);
|
|
@@ -40,7 +42,7 @@ const generateSites = ({ destinationPath } = {}) => {
|
|
|
40
42
|
sites = await siteInfoService.fetchSiteInfo();
|
|
41
43
|
}
|
|
42
44
|
catch (error) {
|
|
43
|
-
console.error(chalk_1.default.red(
|
|
45
|
+
console.error(chalk_1.default.red(`Failed to fetch site information. ${ERROR_MESSAGES.CONTACT_SUPPORT}`));
|
|
44
46
|
throw error;
|
|
45
47
|
}
|
|
46
48
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeDataFetcher, debug, } from '@sitecore-content-sdk/core';
|
|
1
|
+
import { NativeDataFetcher, debug, constants, } from '@sitecore-content-sdk/core';
|
|
2
2
|
import { resolveEdgeUrlForStaticFiles, resolveExperienceEdgeUrl, } from '@sitecore-content-sdk/core/tools';
|
|
3
3
|
import { DictionaryService } from '../i18n';
|
|
4
4
|
import { getDesignLibraryStylesheetLinks, getContentStylesheetLink, LayoutService, LayoutServicePageState, rewriteEdgeHostInResponse, getDefaultMediaUrlTransformer, applyMediaUrlRewrite, } from '../layout';
|
|
@@ -9,6 +9,7 @@ import { createGraphQLClientFactory } from './utils';
|
|
|
9
9
|
import { RobotsService } from '../site/robots-service';
|
|
10
10
|
import { DesignLibraryVariantGeneration } from '../editing/models';
|
|
11
11
|
import { EditingService, ComponentLayoutService, DesignLibraryMode, } from '../editing';
|
|
12
|
+
const { ERROR_MESSAGES } = constants;
|
|
12
13
|
/**
|
|
13
14
|
* Error page codes
|
|
14
15
|
* @public
|
|
@@ -176,7 +177,7 @@ export class SitecoreClient {
|
|
|
176
177
|
mode,
|
|
177
178
|
}, fetchOptions);
|
|
178
179
|
if (!data) {
|
|
179
|
-
throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(previewData)}`);
|
|
180
|
+
throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(previewData)}. ${ERROR_MESSAGES.CONTACT_SUPPORT}`);
|
|
180
181
|
}
|
|
181
182
|
let layout = data.layoutData;
|
|
182
183
|
const personalizeData = getGroomedVariantIds(variantIds);
|
|
@@ -198,9 +199,6 @@ export class SitecoreClient {
|
|
|
198
199
|
*/
|
|
199
200
|
async getDesignLibraryData(designLibData, fetchOptions) {
|
|
200
201
|
var _a;
|
|
201
|
-
if (!this.initOptions.api.local) {
|
|
202
|
-
throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
|
|
203
|
-
}
|
|
204
202
|
const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode, generation, } = designLibData;
|
|
205
203
|
const componentData = await this.componentService.fetchComponentData(Object.assign({ siteName: site, itemId,
|
|
206
204
|
language,
|
|
@@ -210,7 +208,7 @@ export class SitecoreClient {
|
|
|
210
208
|
version,
|
|
211
209
|
mode }, (generation ? { generation } : {})), fetchOptions);
|
|
212
210
|
if (!componentData) {
|
|
213
|
-
throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(designLibData)}`);
|
|
211
|
+
throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(designLibData)}. ${ERROR_MESSAGES.CONTACT_SUPPORT}`);
|
|
214
212
|
}
|
|
215
213
|
const layout = this.applyContentRewrite(componentData);
|
|
216
214
|
const page = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DefaultRetryStrategy } from '@sitecore-content-sdk/core';
|
|
1
|
+
import { constants, DefaultRetryStrategy } from '@sitecore-content-sdk/core';
|
|
2
2
|
import { resolveEdgeUrl } from '@sitecore-content-sdk/core/tools';
|
|
3
3
|
import { SITECORE_CLI_MODE_ENV_VAR } from '../config-cli';
|
|
4
|
+
const { ERROR_MESSAGES } = constants;
|
|
4
5
|
/**
|
|
5
6
|
* Provides default initial values for SitecoreConfig
|
|
6
7
|
* @returns default config
|
|
@@ -115,12 +116,12 @@ const validateApiConfiguration = (config) => {
|
|
|
115
116
|
// Server-side: allow Edge OR Local; clientContextId alone is NOT sufficient
|
|
116
117
|
if (!isBrowser) {
|
|
117
118
|
if (!hasEdgeContextId && !hasLocalCreds) {
|
|
118
|
-
throw new Error(
|
|
119
|
+
throw new Error(ERROR_MESSAGES.MV_007);
|
|
119
120
|
}
|
|
120
121
|
if (hasEdgeContextId && !hasClientContextId) {
|
|
121
122
|
// eslint-disable-next-line no-console
|
|
122
123
|
if (process.env.NODE_ENV === 'development') {
|
|
123
|
-
console.warn(
|
|
124
|
+
console.warn(ERROR_MESSAGES.MV_006);
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
return; // validation complete on the server
|
|
@@ -129,8 +130,7 @@ const validateApiConfiguration = (config) => {
|
|
|
129
130
|
if (isBrowser && !hasClientContextId) {
|
|
130
131
|
// eslint-disable-next-line no-console
|
|
131
132
|
if (process.env.NODE_ENV === 'development') {
|
|
132
|
-
console.warn(
|
|
133
|
-
Client Side functionalities (like Tracking and Personalization) may be limited.`);
|
|
133
|
+
console.warn(ERROR_MESSAGES.MV_006);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
};
|
package/dist/esm/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { addComponentPreviewHandler, addServerComponentPreviewHandler,
|
|
1
|
+
export { addComponentPreviewHandler, addServerComponentPreviewHandler, getDesignLibraryErrorEvent, getDesignLibraryComponentPropsEvent, getDesignLibraryImportMapEvent, getImportMapInfo, addStyleElement, createComponentInstance, sendErrorEvent, DesignLibraryPreviewError, fetchGeneratedComponentFromCache, } from './preview';
|