@sitecore-content-sdk/core 0.3.0-canary.2 → 0.3.0-canary.20

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 (52) hide show
  1. package/config-cli.d.ts +1 -0
  2. package/config-cli.js +1 -0
  3. package/dist/cjs/client/sitecore-client.js +3 -7
  4. package/dist/cjs/client/utils.js +7 -0
  5. package/dist/cjs/config/define-config.js +57 -17
  6. package/dist/cjs/config/index.js +1 -3
  7. package/dist/cjs/config-cli/index.js +5 -0
  8. package/dist/cjs/editing/design-library.js +10 -0
  9. package/dist/cjs/editing/index.js +3 -1
  10. package/dist/cjs/editing/models.js +9 -1
  11. package/dist/cjs/editing/rest-component-layout-service.js +31 -45
  12. package/dist/cjs/site/graphql-robots-service.js +1 -0
  13. package/dist/cjs/tools/generate-map.js +2 -0
  14. package/dist/cjs/tools/templating/components.js +53 -12
  15. package/dist/cjs/tools/templating/index.js +3 -1
  16. package/dist/cjs/tools/templating/utils.js +25 -1
  17. package/dist/esm/client/sitecore-client.js +3 -7
  18. package/dist/esm/client/utils.js +7 -0
  19. package/dist/esm/config/define-config.js +56 -17
  20. package/dist/esm/config/index.js +0 -1
  21. package/dist/esm/config-cli/index.js +1 -0
  22. package/dist/esm/editing/design-library.js +9 -0
  23. package/dist/esm/editing/index.js +2 -2
  24. package/dist/esm/editing/models.js +8 -0
  25. package/dist/esm/editing/rest-component-layout-service.js +28 -45
  26. package/dist/esm/site/graphql-robots-service.js +1 -0
  27. package/dist/esm/tools/generate-map.js +1 -0
  28. package/dist/esm/tools/templating/components.js +20 -12
  29. package/dist/esm/tools/templating/index.js +1 -0
  30. package/dist/esm/tools/templating/utils.js +23 -1
  31. package/package.json +3 -2
  32. package/types/config/define-config.d.ts +7 -1
  33. package/types/config/index.d.ts +0 -1
  34. package/types/config/models.d.ts +16 -0
  35. package/types/{config → config-cli}/define-cli-config.d.ts +1 -1
  36. package/types/config-cli/index.d.ts +1 -0
  37. package/types/editing/design-library.d.ts +7 -0
  38. package/types/editing/index.d.ts +2 -2
  39. package/types/editing/models.d.ts +10 -3
  40. package/types/editing/rest-component-layout-service.d.ts +28 -58
  41. package/types/native-fetcher.d.ts +0 -7
  42. package/types/site/graphql-robots-service.d.ts +1 -0
  43. package/types/tools/generate-map.d.ts +18 -0
  44. package/types/tools/index.d.ts +1 -0
  45. package/types/tools/templating/components.d.ts +16 -9
  46. package/types/tools/templating/index.d.ts +2 -1
  47. package/types/tools/templating/utils.d.ts +8 -0
  48. package/dist/cjs/data-fetcher.js +0 -22
  49. package/dist/esm/data-fetcher.js +0 -17
  50. package/types/data-fetcher.d.ts +0 -34
  51. /package/dist/cjs/{config → config-cli}/define-cli-config.js +0 -0
  52. /package/dist/esm/{config → config-cli}/define-cli-config.js +0 -0
@@ -0,0 +1 @@
1
+ export * from './types/config-cli/index';
package/config-cli.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/config-cli/index');
@@ -182,7 +182,7 @@ class SitecoreClient {
182
182
  if (!this.initOptions.api.local) {
183
183
  throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
184
184
  }
185
- const { itemId, componentUid, site, language, renderingId, dataSourceId, version, } = designLibData;
185
+ const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode, } = designLibData;
186
186
  const componentData = await this.componentService.fetchComponentData({
187
187
  siteName: site,
188
188
  itemId,
@@ -191,6 +191,7 @@ class SitecoreClient {
191
191
  renderingId,
192
192
  dataSourceId,
193
193
  version,
194
+ mode,
194
195
  });
195
196
  const dictionaryData = await this.editingService.fetchDictionaryData({
196
197
  siteName: site,
@@ -319,12 +320,7 @@ class SitecoreClient {
319
320
  return new site_1.GraphQLErrorPagesService(Object.assign(Object.assign({}, this.initOptions), { language: this.initOptions.defaultLanguage, clientFactory: this.clientFactory }));
320
321
  }
321
322
  getComponentService() {
322
- var _a, _b;
323
- return new editing_1.RestComponentLayoutService({
324
- apiHost: (_a = this.initOptions.api.local) === null || _a === void 0 ? void 0 : _a.apiHost,
325
- apiKey: (_b = this.initOptions.api.local) === null || _b === void 0 ? void 0 : _b.apiKey,
326
- siteName: this.initOptions.defaultSite,
327
- });
323
+ return new editing_1.RestComponentLayoutService(this.initOptions.api.edge);
328
324
  }
329
325
  getSitePathService() {
330
326
  return new site_1.GraphQLSitePathService({
@@ -22,6 +22,13 @@ const createGraphQLClientFactory = (options) => {
22
22
  apiKey: options.api.local.apiKey,
23
23
  };
24
24
  }
25
+ else if (typeof window !== 'undefined') {
26
+ // In browser, create a client that won't be used for real requests
27
+ console.warn('GraphQL client created without proper configuration - client-side requests may fail');
28
+ clientConfig = {
29
+ endpoint: '/api/graphql', // Dummy endpoint for browser initialization
30
+ };
31
+ }
25
32
  else {
26
33
  throw new Error('Please configure and use either your sitecoreEdgeContextId, or your graphQLEndpoint and sitecoreApiKey.');
27
34
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineConfig = exports.getFallbackConfig = void 0;
4
+ exports.deepMerge = deepMerge;
4
5
  const constants_1 = require("../constants");
5
6
  const retries_1 = require("../retries");
6
7
  /**
@@ -57,17 +58,45 @@ const getFallbackConfig = () => ({
57
58
  });
58
59
  exports.getFallbackConfig = getFallbackConfig;
59
60
  /**
60
- * Merges two SitecoreConfig objects
61
+ * Deep merge utility that skips undefined or empty string values in the override.
62
+ * @param {T} base base value
63
+ * @param {DeepPartial<T>} [override] override value
64
+ */
65
+ function deepMerge(base, override) {
66
+ if (!override)
67
+ return base;
68
+ const result = Object.assign({}, base);
69
+ for (const key in override) {
70
+ if (!Object.prototype.hasOwnProperty.call(override, key))
71
+ continue;
72
+ const typedKey = key;
73
+ const baseValue = base[typedKey];
74
+ const overrideValue = override[typedKey];
75
+ // Skip undefined and empty string overrides
76
+ if (overrideValue === undefined || overrideValue === '') {
77
+ continue;
78
+ }
79
+ if (typeof overrideValue === 'object' &&
80
+ overrideValue !== null &&
81
+ !Array.isArray(overrideValue) &&
82
+ Object.getPrototypeOf(overrideValue) === Object.prototype) {
83
+ result[typedKey] = deepMerge(baseValue, overrideValue);
84
+ }
85
+ else {
86
+ result[typedKey] = overrideValue;
87
+ }
88
+ }
89
+ return result;
90
+ }
91
+ /**
92
+ * Resolves sitecore config based on base config and overrides
61
93
  * @param {SitecoreConfig} base base sitecore config object
62
94
  * @param {SitecoreConfig} override override sitecore config object
63
- * @returns merged SitecoreConfig object
95
+ * @returns resolved SitecoreConfig object
64
96
  */
65
- const deepMerge = (base, override) => {
66
- var _a, _b, _c, _d, _e;
67
- const result = Object.assign(Object.assign(Object.assign({}, base), override), { api: {
68
- 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),
69
- 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),
70
- }, 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) });
97
+ const resolveConfig = (base, override) => {
98
+ var _a;
99
+ const result = deepMerge(base, override);
71
100
  if (Number.isNaN(result.personalize.cdpTimeout) || !result.personalize.cdpTimeout) {
72
101
  result.personalize.cdpTimeout = base.personalize.cdpTimeout;
73
102
  }
@@ -75,19 +104,29 @@ const deepMerge = (base, override) => {
75
104
  result.personalize.edgeTimeout = base.personalize.edgeTimeout;
76
105
  }
77
106
  // fallback in case only one context provided
78
- if (((_e = result.api.edge) === null || _e === void 0 ? void 0 : _e.clientContextId) && !result.api.edge.contextId) {
107
+ if (((_a = result.api.edge) === null || _a === void 0 ? void 0 : _a.clientContextId) && !result.api.edge.contextId) {
79
108
  result.api.edge.contextId = result.api.edge.clientContextId;
80
109
  }
81
110
  return result;
82
111
  };
83
112
  const validateConfig = (config) => {
84
113
  var _a, _b, _c, _d, _e, _f, _g, _h;
85
- if (!((_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId) &&
86
- (!((_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))) {
87
- // consider client-side usecase
88
- if (!((_h = (_g = config.api) === null || _g === void 0 ? void 0 : _g.edge) === null || _h === void 0 ? void 0 : _h.clientContextId)) {
89
- throw new Error('Configuration error: either context ID or API key and host must be specified in sitecore.config');
90
- }
114
+ // Skip validation in browser - only validate on server side
115
+ if (typeof window !== 'undefined') {
116
+ return; // We're in the browser, skip validation
117
+ }
118
+ const hasEdgeContextId = !!((_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId);
119
+ const hasLocalApi = !!(((_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));
120
+ const hasClientContextId = !!((_h = (_g = config.api) === null || _g === void 0 ? void 0 : _g.edge) === null || _h === void 0 ? void 0 : _h.clientContextId);
121
+ // Only validate on server-side where we have access to server env vars
122
+ if (!hasEdgeContextId && !hasLocalApi && !hasClientContextId) {
123
+ throw new Error('Configuration error: at least one API configuration must be specified: ' +
124
+ 'contextId (server-side), clientContextId (client-side), or local API settings (apiHost + apiKey)');
125
+ }
126
+ // Warn if middleware features might not work
127
+ if (!hasEdgeContextId && !hasClientContextId && hasLocalApi) {
128
+ console.warn('Warning: Redirects and Personalization middleware require Edge API configuration. ' +
129
+ 'Please ensure that either an Edge context ID (for server-side) or a client context ID (for client-side) is provided in your configuration');
91
130
  }
92
131
  };
93
132
  /**
@@ -96,7 +135,8 @@ const validateConfig = (config) => {
96
135
  * @returns {SitecoreConfig} full sitecore configuration to use in application
97
136
  */
98
137
  const defineConfig = (config) => {
99
- validateConfig(config);
100
- return deepMerge((0, exports.getFallbackConfig)(), config);
138
+ const resolvedConfig = resolveConfig((0, exports.getFallbackConfig)(), config);
139
+ validateConfig(resolvedConfig);
140
+ return resolvedConfig;
101
141
  };
102
142
  exports.defineConfig = defineConfig;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineCliConfig = exports.defineConfig = exports.ComponentTemplateType = void 0;
3
+ exports.defineConfig = exports.ComponentTemplateType = void 0;
4
4
  var models_1 = require("./models");
5
5
  Object.defineProperty(exports, "ComponentTemplateType", { enumerable: true, get: function () { return models_1.ComponentTemplateType; } });
6
6
  var define_config_1 = require("./define-config");
7
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,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineCliConfig = void 0;
4
+ var define_cli_config_1 = require("./define-cli-config");
5
+ Object.defineProperty(exports, "defineCliConfig", { enumerable: true, get: function () { return define_cli_config_1.defineCliConfig; } });
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateComponentHandler = exports.addComponentUpdateHandler = exports.DesignLibraryStatus = exports.DESIGN_LIBRARY_STATUS_EVENT_NAME = void 0;
4
4
  exports.getDesignLibraryStatusEvent = getDesignLibraryStatusEvent;
5
5
  exports.getDesignLibraryScriptLink = getDesignLibraryScriptLink;
6
+ exports.isDesignLibraryMode = isDesignLibraryMode;
6
7
  const constants_1 = require("../constants");
7
8
  const normalize_url_1 = require("../utils/normalize-url");
9
+ const models_1 = require("./models");
8
10
  /**
9
11
  * Event to be sent when report status to design library
10
12
  */
@@ -113,3 +115,11 @@ function getDesignLibraryStatusEvent(status, uid) {
113
115
  function getDesignLibraryScriptLink(sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) {
114
116
  return `${(0, normalize_url_1.normalizeUrl)(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
115
117
  }
118
+ /**
119
+ * Checks if the given mode is a Design Library mode.
120
+ * @param {unknown} mode - The mode to check.
121
+ * @returns {boolean} True if the mode is a Design Library mode, false otherwise.
122
+ */
123
+ function isDesignLibraryMode(mode) {
124
+ return mode === models_1.DesignLibraryMode.Normal || mode === models_1.DesignLibraryMode.Metadata;
125
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDesignLibraryScriptLink = exports.getDesignLibraryStatusEvent = exports.DesignLibraryStatus = exports.addComponentUpdateHandler = exports.MetadataKind = exports.LayoutKind = exports.RestComponentLayoutService = exports.PREVIEW_KEY = exports.PAGES_EDITING_MARKER = exports.QUERY_PARAM_EDITING_SECRET = exports.EDITING_ALLOWED_ORIGINS = exports.getJssPagesClientData = exports.resetEditorChromes = exports.isEditorActive = exports.PagesEditor = exports.DEFAULT_PLACEHOLDER_UID = exports.GraphQLEditingService = void 0;
3
+ exports.isDesignLibraryMode = exports.getDesignLibraryScriptLink = exports.getDesignLibraryStatusEvent = exports.DesignLibraryStatus = exports.addComponentUpdateHandler = exports.DesignLibraryMode = exports.MetadataKind = exports.LayoutKind = exports.RestComponentLayoutService = exports.PREVIEW_KEY = exports.PAGES_EDITING_MARKER = exports.QUERY_PARAM_EDITING_SECRET = exports.EDITING_ALLOWED_ORIGINS = exports.getJssPagesClientData = exports.resetEditorChromes = exports.isEditorActive = exports.PagesEditor = exports.DEFAULT_PLACEHOLDER_UID = exports.GraphQLEditingService = void 0;
4
4
  var graphql_editing_service_1 = require("./graphql-editing-service");
5
5
  Object.defineProperty(exports, "GraphQLEditingService", { enumerable: true, get: function () { return graphql_editing_service_1.GraphQLEditingService; } });
6
6
  var utils_1 = require("./utils");
@@ -18,8 +18,10 @@ Object.defineProperty(exports, "RestComponentLayoutService", { enumerable: true,
18
18
  var models_1 = require("./models");
19
19
  Object.defineProperty(exports, "LayoutKind", { enumerable: true, get: function () { return models_1.LayoutKind; } });
20
20
  Object.defineProperty(exports, "MetadataKind", { enumerable: true, get: function () { return models_1.MetadataKind; } });
21
+ Object.defineProperty(exports, "DesignLibraryMode", { enumerable: true, get: function () { return models_1.DesignLibraryMode; } });
21
22
  var design_library_1 = require("./design-library");
22
23
  Object.defineProperty(exports, "addComponentUpdateHandler", { enumerable: true, get: function () { return design_library_1.addComponentUpdateHandler; } });
23
24
  Object.defineProperty(exports, "DesignLibraryStatus", { enumerable: true, get: function () { return design_library_1.DesignLibraryStatus; } });
24
25
  Object.defineProperty(exports, "getDesignLibraryStatusEvent", { enumerable: true, get: function () { return design_library_1.getDesignLibraryStatusEvent; } });
25
26
  Object.defineProperty(exports, "getDesignLibraryScriptLink", { enumerable: true, get: function () { return design_library_1.getDesignLibraryScriptLink; } });
27
+ Object.defineProperty(exports, "isDesignLibraryMode", { enumerable: true, get: function () { return design_library_1.isDesignLibraryMode; } });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MetadataKind = exports.LayoutKind = void 0;
3
+ exports.DesignLibraryMode = exports.MetadataKind = exports.LayoutKind = void 0;
4
4
  /**
5
5
  * Represents the Editing Layout variant.
6
6
  * - shared - shared layout
@@ -21,3 +21,11 @@ var MetadataKind;
21
21
  MetadataKind["Open"] = "open";
22
22
  MetadataKind["Close"] = "close";
23
23
  })(MetadataKind || (exports.MetadataKind = MetadataKind = {}));
24
+ /** Represents the mode of the Design Library */
25
+ var DesignLibraryMode;
26
+ (function (DesignLibraryMode) {
27
+ /** Normal mode */
28
+ DesignLibraryMode["Normal"] = "library";
29
+ /** Metadata mode */
30
+ DesignLibraryMode["Metadata"] = "library-metadata";
31
+ })(DesignLibraryMode || (exports.DesignLibraryMode = DesignLibraryMode = {}));
@@ -1,47 +1,35 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.RestComponentLayoutService = void 0;
4
- const __1 = require("..");
5
- const data_fetcher_1 = require("../data-fetcher");
7
+ const native_fetcher_1 = require("../native-fetcher");
8
+ const debug_1 = __importDefault(require("../debug"));
9
+ const constants_1 = require("../constants");
10
+ const utils_1 = require("../utils");
11
+ const models_1 = require("./models");
6
12
  /**
7
- * REST service that enables Design Library functioality
8
- * Makes a request to /sitecore/api/layout/component in 'library' mode in Pages.
13
+ * REST service that enables design Library functionality
9
14
  * Returns layoutData for one single rendered component
10
15
  */
11
16
  class RestComponentLayoutService {
12
17
  constructor(config) {
13
18
  this.config = config;
14
- this.getFetcher = (req, res) => {
15
- return this.config.dataFetcherResolver
16
- ? this.config.dataFetcherResolver(req, res)
17
- : this.getDefaultFetcher(req);
18
- };
19
- /**
20
- * Provides default @see NativeDataFetcher data fetcher
21
- * @param {IncomingMessage} [req] Request instance
22
- * @returns default fetcher
23
- */
24
- this.getDefaultFetcher = (req) => {
25
- var _a;
26
- const config = {
27
- debugger: __1.debug.editing,
28
- };
29
- const nativeFetcher = new __1.NativeDataFetcher(config);
30
- const headers = req && Object.assign(Object.assign({}, req.headers), (((_a = req.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress) ? { 'X-Forwarded-For': req.socket.remoteAddress } : {}));
31
- const fetcher = (url, data) => {
32
- data = Object.assign(Object.assign({}, data), { headers: headers });
33
- return nativeFetcher.fetch(url, data);
34
- };
35
- return fetcher;
36
- };
37
19
  }
38
- fetchComponentData(params, req, res) {
39
- params.siteName = params.siteName || this.config.siteName;
40
- const querystringParams = this.getComponentFetchParams(params);
41
- __1.debug.layout('fetching component with uid %s for %s %s %s', params.componentUid, params.itemId, params.language, params.siteName);
42
- const fetcher = this.getFetcher(req, res);
43
- const fetchUrl = this.resolveLayoutServiceUrl('component');
44
- return (0, data_fetcher_1.fetchData)(fetchUrl, fetcher, querystringParams).catch((error) => {
20
+ fetchComponentData(params) {
21
+ const config = { debugger: debug_1.default.layout };
22
+ const fetcher = new native_fetcher_1.NativeDataFetcher(config);
23
+ debug_1.default.layout('fetching component with uid %s for %s %s %s %s', params.componentUid, params.itemId, params.language, params.siteName, params.dataSourceId);
24
+ const fetchUrl = this.getFetchUrl(params);
25
+ return fetcher
26
+ .get(fetchUrl, {
27
+ headers: {
28
+ sc_editMode: `${params.mode === models_1.DesignLibraryMode.Metadata}`,
29
+ },
30
+ })
31
+ .then((response) => response.data)
32
+ .catch((error) => {
45
33
  var _a;
46
34
  if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
47
35
  return error.response.data;
@@ -49,19 +37,10 @@ class RestComponentLayoutService {
49
37
  throw error;
50
38
  });
51
39
  }
52
- /**
53
- * Resolves layout service url
54
- * @param {string} apiType which layout service API to call ('render' or 'placeholder')
55
- * @returns the layout service url
56
- */
57
- resolveLayoutServiceUrl(apiType) {
58
- const { apiHost = '', configurationName = 'jss' } = this.config;
59
- return `${apiHost}/sitecore/api/layout/${apiType}/${configurationName}`;
60
- }
61
40
  getComponentFetchParams(params) {
62
41
  // exclude undefined params with this one simple trick
63
42
  return JSON.parse(JSON.stringify({
64
- sc_apikey: this.config.apiKey,
43
+ sitecoreContextId: this.config.contextId,
65
44
  item: params.itemId,
66
45
  uid: params.componentUid,
67
46
  dataSourceId: params.dataSourceId,
@@ -69,8 +48,15 @@ class RestComponentLayoutService {
69
48
  version: params.version,
70
49
  sc_site: params.siteName,
71
50
  sc_lang: params.language || 'en',
72
- sc_mode: params.editMode,
73
51
  }));
74
52
  }
53
+ /**
54
+ * Get the fetch URL for the partial layout data endpoint
55
+ * @param {ComponentLayoutRequestParams} params - The parameters for the request
56
+ * @returns {string} The fetch URL for the component data
57
+ */
58
+ getFetchUrl(params) {
59
+ return (0, utils_1.resolveUrl)(`${this.config.edgeUrl || constants_1.SITECORE_EDGE_URL_DEFAULT}/layout/component`, this.getComponentFetchParams(params));
60
+ }
75
61
  }
76
62
  exports.RestComponentLayoutService = RestComponentLayoutService;
@@ -33,6 +33,7 @@ class GraphQLRobotsService {
33
33
  }
34
34
  /**
35
35
  * Fetch a data of robots.txt from API
36
+ * @param {FetchOptions} fetchOptions - The fetch options to be used for the request.
36
37
  * @returns text of robots.txt
37
38
  * @throws {Error} if the siteName is empty.
38
39
  */
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.getComponentList = getComponentList;
4
- const utils_1 = require("./utils");
37
+ const glob = __importStar(require("glob"));
38
+ const componentNamePattern = /^[\/]*(.+[\/\\])*(.+)\.[jt]sx?$/;
39
+ const componentPathPattern = /^([\/]*.+[\/\\].+)\..+$/;
5
40
  /**
6
41
  * Get list of components from @var path
7
42
  * Returns a list of components in the following format:
@@ -10,17 +45,23 @@ const utils_1 = require("./utils");
10
45
  * componentName: 'ComponentName',
11
46
  * moduleName: 'ComponentName'
12
47
  * }
13
- * @param {string} path path to search
48
+ * @param {string[]} paths paths to search
49
+ * @param {string[]} [exclude] paths and glob patterns to exclude from final result
14
50
  */
15
- function getComponentList(path) {
16
- const components = (0, utils_1.getItems)({
17
- path,
18
- resolveItem: (path, name) => ({
19
- path: `${path}/${name}`,
20
- componentName: name,
21
- moduleName: name.replace(/[^\w]+/g, ''),
22
- }),
23
- cb: (name) => console.debug(`Registering Content SDK component ${name}`),
24
- });
51
+ function getComponentList(paths, exclude) {
52
+ const components = paths.reduce((result, path) => {
53
+ const globPath = glob.hasMagic(path, { magicalBraces: true }) || path.match(componentNamePattern)
54
+ ? path
55
+ : path.replace(/\/$/, '').concat('/*.{js,jsx,ts,tsx}');
56
+ return result.concat(...glob.sync(globPath, { ignore: exclude }).map((filePath) => {
57
+ const name = filePath.match(componentNamePattern)[2];
58
+ console.debug(`Registering Content SDK component ${name}`);
59
+ return {
60
+ path: filePath.match(componentPathPattern)[1].replace(/\\/g, '/'), // use forward slashes for consistency
61
+ componentName: name,
62
+ moduleName: name.replace(/[^\w]+/g, ''),
63
+ };
64
+ }));
65
+ }, []);
25
66
  return components;
26
67
  }
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModuleType = exports.generatePlugins = exports.getComponentList = void 0;
3
+ exports.matchPath = exports.ModuleType = exports.generatePlugins = exports.getComponentList = void 0;
4
4
  var components_1 = require("./components");
5
5
  Object.defineProperty(exports, "getComponentList", { enumerable: true, get: function () { return components_1.getComponentList; } });
6
6
  var plugins_1 = require("./plugins");
7
7
  Object.defineProperty(exports, "generatePlugins", { enumerable: true, get: function () { return plugins_1.generatePlugins; } });
8
8
  Object.defineProperty(exports, "ModuleType", { enumerable: true, get: function () { return plugins_1.ModuleType; } });
9
+ var utils_1 = require("./utils");
10
+ Object.defineProperty(exports, "matchPath", { enumerable: true, get: function () { return utils_1.matchPath; } });
@@ -3,8 +3,26 @@ 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.matchPath = void 0;
6
7
  exports.getItems = getItems;
7
8
  const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * Compares two paths to determine if they match.
12
+ * @param {string} itemPath base path to compare against, can be absolute or relative
13
+ * @param {string} compare comparer, can be relate, absolute or regex string
14
+ * @returns true if paths match, false otherwise
15
+ */
16
+ const matchPath = (itemPath, compare) => {
17
+ if (compare === itemPath ||
18
+ path_1.default.join(process.cwd(), itemPath) === compare ||
19
+ itemPath === path_1.default.join(process.cwd(), compare) ||
20
+ new RegExp(compare).test(itemPath)) {
21
+ return true;
22
+ }
23
+ return false;
24
+ };
25
+ exports.matchPath = matchPath;
8
26
  /**
9
27
  * Using @var path find all files and generate output using @var resolveItem function for each file
10
28
  * Can be used to generate list of components, templates, etc.
@@ -12,11 +30,17 @@ const fs_1 = __importDefault(require("fs"));
12
30
  * @returns {Item[]} list of items
13
31
  */
14
32
  function getItems(settings) {
15
- const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), } = settings;
33
+ const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), exclude, } = settings;
16
34
  const items = [];
17
35
  const folders = [];
18
36
  if (!fs_1.default.existsSync(path))
19
37
  return [];
38
+ if (exclude) {
39
+ for (const exclusion of exclude) {
40
+ if ((0, exports.matchPath)(path, exclusion))
41
+ return [];
42
+ }
43
+ }
20
44
  fs_1.default.readdirSync(path, { withFileTypes: true }).forEach((item) => {
21
45
  if (item.isDirectory()) {
22
46
  folders.push(item);
@@ -179,7 +179,7 @@ export class SitecoreClient {
179
179
  if (!this.initOptions.api.local) {
180
180
  throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
181
181
  }
182
- const { itemId, componentUid, site, language, renderingId, dataSourceId, version, } = designLibData;
182
+ const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode, } = designLibData;
183
183
  const componentData = await this.componentService.fetchComponentData({
184
184
  siteName: site,
185
185
  itemId,
@@ -188,6 +188,7 @@ export class SitecoreClient {
188
188
  renderingId,
189
189
  dataSourceId,
190
190
  version,
191
+ mode,
191
192
  });
192
193
  const dictionaryData = await this.editingService.fetchDictionaryData({
193
194
  siteName: site,
@@ -316,12 +317,7 @@ export class SitecoreClient {
316
317
  return new GraphQLErrorPagesService(Object.assign(Object.assign({}, this.initOptions), { language: this.initOptions.defaultLanguage, clientFactory: this.clientFactory }));
317
318
  }
318
319
  getComponentService() {
319
- var _a, _b;
320
- return new RestComponentLayoutService({
321
- apiHost: (_a = this.initOptions.api.local) === null || _a === void 0 ? void 0 : _a.apiHost,
322
- apiKey: (_b = this.initOptions.api.local) === null || _b === void 0 ? void 0 : _b.apiKey,
323
- siteName: this.initOptions.defaultSite,
324
- });
320
+ return new RestComponentLayoutService(this.initOptions.api.edge);
325
321
  }
326
322
  getSitePathService() {
327
323
  return new GraphQLSitePathService({
@@ -19,6 +19,13 @@ export const createGraphQLClientFactory = (options) => {
19
19
  apiKey: options.api.local.apiKey,
20
20
  };
21
21
  }
22
+ else if (typeof window !== 'undefined') {
23
+ // In browser, create a client that won't be used for real requests
24
+ console.warn('GraphQL client created without proper configuration - client-side requests may fail');
25
+ clientConfig = {
26
+ endpoint: '/api/graphql', // Dummy endpoint for browser initialization
27
+ };
28
+ }
22
29
  else {
23
30
  throw new Error('Please configure and use either your sitecoreEdgeContextId, or your graphQLEndpoint and sitecoreApiKey.');
24
31
  }