@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
@@ -53,17 +53,45 @@ export const getFallbackConfig = () => ({
53
53
  },
54
54
  });
55
55
  /**
56
- * Merges two SitecoreConfig objects
56
+ * Deep merge utility that skips undefined or empty string values in the override.
57
+ * @param {T} base base value
58
+ * @param {DeepPartial<T>} [override] override value
59
+ */
60
+ export function deepMerge(base, override) {
61
+ if (!override)
62
+ return base;
63
+ const result = Object.assign({}, base);
64
+ for (const key in override) {
65
+ if (!Object.prototype.hasOwnProperty.call(override, key))
66
+ continue;
67
+ const typedKey = key;
68
+ const baseValue = base[typedKey];
69
+ const overrideValue = override[typedKey];
70
+ // Skip undefined and empty string overrides
71
+ if (overrideValue === undefined || overrideValue === '') {
72
+ continue;
73
+ }
74
+ if (typeof overrideValue === 'object' &&
75
+ overrideValue !== null &&
76
+ !Array.isArray(overrideValue) &&
77
+ Object.getPrototypeOf(overrideValue) === Object.prototype) {
78
+ result[typedKey] = deepMerge(baseValue, overrideValue);
79
+ }
80
+ else {
81
+ result[typedKey] = overrideValue;
82
+ }
83
+ }
84
+ return result;
85
+ }
86
+ /**
87
+ * Resolves sitecore config based on base config and overrides
57
88
  * @param {SitecoreConfig} base base sitecore config object
58
89
  * @param {SitecoreConfig} override override sitecore config object
59
- * @returns merged SitecoreConfig object
90
+ * @returns resolved SitecoreConfig object
60
91
  */
61
- const deepMerge = (base, override) => {
62
- var _a, _b, _c, _d, _e;
63
- const result = Object.assign(Object.assign(Object.assign({}, base), override), { api: {
64
- 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),
65
- 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),
66
- }, 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) });
92
+ const resolveConfig = (base, override) => {
93
+ var _a;
94
+ const result = deepMerge(base, override);
67
95
  if (Number.isNaN(result.personalize.cdpTimeout) || !result.personalize.cdpTimeout) {
68
96
  result.personalize.cdpTimeout = base.personalize.cdpTimeout;
69
97
  }
@@ -71,19 +99,29 @@ const deepMerge = (base, override) => {
71
99
  result.personalize.edgeTimeout = base.personalize.edgeTimeout;
72
100
  }
73
101
  // fallback in case only one context provided
74
- if (((_e = result.api.edge) === null || _e === void 0 ? void 0 : _e.clientContextId) && !result.api.edge.contextId) {
102
+ if (((_a = result.api.edge) === null || _a === void 0 ? void 0 : _a.clientContextId) && !result.api.edge.contextId) {
75
103
  result.api.edge.contextId = result.api.edge.clientContextId;
76
104
  }
77
105
  return result;
78
106
  };
79
107
  const validateConfig = (config) => {
80
108
  var _a, _b, _c, _d, _e, _f, _g, _h;
81
- if (!((_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId) &&
82
- (!((_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))) {
83
- // consider client-side usecase
84
- if (!((_h = (_g = config.api) === null || _g === void 0 ? void 0 : _g.edge) === null || _h === void 0 ? void 0 : _h.clientContextId)) {
85
- throw new Error('Configuration error: either context ID or API key and host must be specified in sitecore.config');
86
- }
109
+ // Skip validation in browser - only validate on server side
110
+ if (typeof window !== 'undefined') {
111
+ return; // We're in the browser, skip validation
112
+ }
113
+ const hasEdgeContextId = !!((_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId);
114
+ 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));
115
+ const hasClientContextId = !!((_h = (_g = config.api) === null || _g === void 0 ? void 0 : _g.edge) === null || _h === void 0 ? void 0 : _h.clientContextId);
116
+ // Only validate on server-side where we have access to server env vars
117
+ if (!hasEdgeContextId && !hasLocalApi && !hasClientContextId) {
118
+ throw new Error('Configuration error: at least one API configuration must be specified: ' +
119
+ 'contextId (server-side), clientContextId (client-side), or local API settings (apiHost + apiKey)');
120
+ }
121
+ // Warn if middleware features might not work
122
+ if (!hasEdgeContextId && !hasClientContextId && hasLocalApi) {
123
+ console.warn('Warning: Redirects and Personalization middleware require Edge API configuration. ' +
124
+ 'Please ensure that either an Edge context ID (for server-side) or a client context ID (for client-side) is provided in your configuration');
87
125
  }
88
126
  };
89
127
  /**
@@ -92,6 +130,7 @@ const validateConfig = (config) => {
92
130
  * @returns {SitecoreConfig} full sitecore configuration to use in application
93
131
  */
94
132
  export const defineConfig = (config) => {
95
- validateConfig(config);
96
- return deepMerge(getFallbackConfig(), config);
133
+ const resolvedConfig = resolveConfig(getFallbackConfig(), config);
134
+ validateConfig(resolvedConfig);
135
+ return resolvedConfig;
97
136
  };
@@ -1,3 +1,2 @@
1
1
  export { ComponentTemplateType, } from './models';
2
2
  export { defineConfig } from './define-config';
3
- export { defineCliConfig } from './define-cli-config';
@@ -0,0 +1 @@
1
+ export { defineCliConfig } from './define-cli-config';
@@ -1,5 +1,6 @@
1
1
  import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
2
2
  import { normalizeUrl } from '../utils/normalize-url';
3
+ import { DesignLibraryMode } from './models';
3
4
  /**
4
5
  * Event to be sent when report status to design library
5
6
  */
@@ -106,3 +107,11 @@ export function getDesignLibraryStatusEvent(status, uid) {
106
107
  export function getDesignLibraryScriptLink(sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
107
108
  return `${normalizeUrl(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
108
109
  }
110
+ /**
111
+ * Checks if the given mode is a Design Library mode.
112
+ * @param {unknown} mode - The mode to check.
113
+ * @returns {boolean} True if the mode is a Design Library mode, false otherwise.
114
+ */
115
+ export function isDesignLibraryMode(mode) {
116
+ return mode === DesignLibraryMode.Normal || mode === DesignLibraryMode.Metadata;
117
+ }
@@ -1,5 +1,5 @@
1
1
  export { GraphQLEditingService } from './graphql-editing-service';
2
2
  export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChromes, getJssPagesClientData, EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, PAGES_EDITING_MARKER, PREVIEW_KEY, } from './utils';
3
3
  export { RestComponentLayoutService, } from './rest-component-layout-service';
4
- export { LayoutKind, MetadataKind, } from './models';
5
- export { addComponentUpdateHandler, DesignLibraryStatus, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, } from './design-library';
4
+ export { LayoutKind, MetadataKind, DesignLibraryMode, } from './models';
5
+ export { addComponentUpdateHandler, DesignLibraryStatus, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, isDesignLibraryMode, } from './design-library';
@@ -18,3 +18,11 @@ export var MetadataKind;
18
18
  MetadataKind["Open"] = "open";
19
19
  MetadataKind["Close"] = "close";
20
20
  })(MetadataKind || (MetadataKind = {}));
21
+ /** Represents the mode of the Design Library */
22
+ export var DesignLibraryMode;
23
+ (function (DesignLibraryMode) {
24
+ /** Normal mode */
25
+ DesignLibraryMode["Normal"] = "library";
26
+ /** Metadata mode */
27
+ DesignLibraryMode["Metadata"] = "library-metadata";
28
+ })(DesignLibraryMode || (DesignLibraryMode = {}));
@@ -1,44 +1,29 @@
1
- import { debug, NativeDataFetcher } from '..';
2
- import { fetchData } from '../data-fetcher';
1
+ import { NativeDataFetcher } from '../native-fetcher';
2
+ import debug from '../debug';
3
+ import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
4
+ import { resolveUrl } from '../utils';
5
+ import { DesignLibraryMode } from './models';
3
6
  /**
4
- * REST service that enables Design Library functioality
5
- * Makes a request to /sitecore/api/layout/component in 'library' mode in Pages.
7
+ * REST service that enables design Library functionality
6
8
  * Returns layoutData for one single rendered component
7
9
  */
8
10
  export class RestComponentLayoutService {
9
11
  constructor(config) {
10
12
  this.config = config;
11
- this.getFetcher = (req, res) => {
12
- return this.config.dataFetcherResolver
13
- ? this.config.dataFetcherResolver(req, res)
14
- : this.getDefaultFetcher(req);
15
- };
16
- /**
17
- * Provides default @see NativeDataFetcher data fetcher
18
- * @param {IncomingMessage} [req] Request instance
19
- * @returns default fetcher
20
- */
21
- this.getDefaultFetcher = (req) => {
22
- var _a;
23
- const config = {
24
- debugger: debug.editing,
25
- };
26
- const nativeFetcher = new NativeDataFetcher(config);
27
- 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 } : {}));
28
- const fetcher = (url, data) => {
29
- data = Object.assign(Object.assign({}, data), { headers: headers });
30
- return nativeFetcher.fetch(url, data);
31
- };
32
- return fetcher;
33
- };
34
13
  }
35
- fetchComponentData(params, req, res) {
36
- params.siteName = params.siteName || this.config.siteName;
37
- const querystringParams = this.getComponentFetchParams(params);
38
- debug.layout('fetching component with uid %s for %s %s %s', params.componentUid, params.itemId, params.language, params.siteName);
39
- const fetcher = this.getFetcher(req, res);
40
- const fetchUrl = this.resolveLayoutServiceUrl('component');
41
- return fetchData(fetchUrl, fetcher, querystringParams).catch((error) => {
14
+ fetchComponentData(params) {
15
+ const config = { debugger: debug.layout };
16
+ const fetcher = new NativeDataFetcher(config);
17
+ debug.layout('fetching component with uid %s for %s %s %s %s', params.componentUid, params.itemId, params.language, params.siteName, params.dataSourceId);
18
+ const fetchUrl = this.getFetchUrl(params);
19
+ return fetcher
20
+ .get(fetchUrl, {
21
+ headers: {
22
+ sc_editMode: `${params.mode === DesignLibraryMode.Metadata}`,
23
+ },
24
+ })
25
+ .then((response) => response.data)
26
+ .catch((error) => {
42
27
  var _a;
43
28
  if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
44
29
  return error.response.data;
@@ -46,19 +31,10 @@ export class RestComponentLayoutService {
46
31
  throw error;
47
32
  });
48
33
  }
49
- /**
50
- * Resolves layout service url
51
- * @param {string} apiType which layout service API to call ('render' or 'placeholder')
52
- * @returns the layout service url
53
- */
54
- resolveLayoutServiceUrl(apiType) {
55
- const { apiHost = '', configurationName = 'jss' } = this.config;
56
- return `${apiHost}/sitecore/api/layout/${apiType}/${configurationName}`;
57
- }
58
34
  getComponentFetchParams(params) {
59
35
  // exclude undefined params with this one simple trick
60
36
  return JSON.parse(JSON.stringify({
61
- sc_apikey: this.config.apiKey,
37
+ sitecoreContextId: this.config.contextId,
62
38
  item: params.itemId,
63
39
  uid: params.componentUid,
64
40
  dataSourceId: params.dataSourceId,
@@ -66,7 +42,14 @@ export class RestComponentLayoutService {
66
42
  version: params.version,
67
43
  sc_site: params.siteName,
68
44
  sc_lang: params.language || 'en',
69
- sc_mode: params.editMode,
70
45
  }));
71
46
  }
47
+ /**
48
+ * Get the fetch URL for the partial layout data endpoint
49
+ * @param {ComponentLayoutRequestParams} params - The parameters for the request
50
+ * @returns {string} The fetch URL for the component data
51
+ */
52
+ getFetchUrl(params) {
53
+ return resolveUrl(`${this.config.edgeUrl || SITECORE_EDGE_URL_DEFAULT}/layout/component`, this.getComponentFetchParams(params));
54
+ }
72
55
  }
@@ -27,6 +27,7 @@ export class GraphQLRobotsService {
27
27
  }
28
28
  /**
29
29
  * Fetch a data of robots.txt from API
30
+ * @param {FetchOptions} fetchOptions - The fetch options to be used for the request.
30
31
  * @returns text of robots.txt
31
32
  * @throws {Error} if the siteName is empty.
32
33
  */
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,6 @@
1
- import { getItems } from './utils';
1
+ import * as glob from 'glob';
2
+ const componentNamePattern = /^[\/]*(.+[\/\\])*(.+)\.[jt]sx?$/;
3
+ const componentPathPattern = /^([\/]*.+[\/\\].+)\..+$/;
2
4
  /**
3
5
  * Get list of components from @var path
4
6
  * Returns a list of components in the following format:
@@ -7,17 +9,23 @@ import { getItems } from './utils';
7
9
  * componentName: 'ComponentName',
8
10
  * moduleName: 'ComponentName'
9
11
  * }
10
- * @param {string} path path to search
12
+ * @param {string[]} paths paths to search
13
+ * @param {string[]} [exclude] paths and glob patterns to exclude from final result
11
14
  */
12
- export function getComponentList(path) {
13
- const components = getItems({
14
- path,
15
- resolveItem: (path, name) => ({
16
- path: `${path}/${name}`,
17
- componentName: name,
18
- moduleName: name.replace(/[^\w]+/g, ''),
19
- }),
20
- cb: (name) => console.debug(`Registering Content SDK component ${name}`),
21
- });
15
+ export function getComponentList(paths, exclude) {
16
+ const components = paths.reduce((result, path) => {
17
+ const globPath = glob.hasMagic(path, { magicalBraces: true }) || path.match(componentNamePattern)
18
+ ? path
19
+ : path.replace(/\/$/, '').concat('/*.{js,jsx,ts,tsx}');
20
+ return result.concat(...glob.sync(globPath, { ignore: exclude }).map((filePath) => {
21
+ const name = filePath.match(componentNamePattern)[2];
22
+ console.debug(`Registering Content SDK component ${name}`);
23
+ return {
24
+ path: filePath.match(componentPathPattern)[1].replace(/\\/g, '/'), // use forward slashes for consistency
25
+ componentName: name,
26
+ moduleName: name.replace(/[^\w]+/g, ''),
27
+ };
28
+ }));
29
+ }, []);
22
30
  return components;
23
31
  }
@@ -1,2 +1,3 @@
1
1
  export { getComponentList } from './components';
2
2
  export { generatePlugins, ModuleType } from './plugins';
3
+ export { matchPath } from './utils';
@@ -1,4 +1,20 @@
1
1
  import fs from 'fs';
2
+ import path from 'path';
3
+ /**
4
+ * Compares two paths to determine if they match.
5
+ * @param {string} itemPath base path to compare against, can be absolute or relative
6
+ * @param {string} compare comparer, can be relate, absolute or regex string
7
+ * @returns true if paths match, false otherwise
8
+ */
9
+ export const matchPath = (itemPath, compare) => {
10
+ if (compare === itemPath ||
11
+ path.join(process.cwd(), itemPath) === compare ||
12
+ itemPath === path.join(process.cwd(), compare) ||
13
+ new RegExp(compare).test(itemPath)) {
14
+ return true;
15
+ }
16
+ return false;
17
+ };
2
18
  /**
3
19
  * Using @var path find all files and generate output using @var resolveItem function for each file
4
20
  * Can be used to generate list of components, templates, etc.
@@ -6,11 +22,17 @@ import fs from 'fs';
6
22
  * @returns {Item[]} list of items
7
23
  */
8
24
  export function getItems(settings) {
9
- const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), } = settings;
25
+ const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), exclude, } = settings;
10
26
  const items = [];
11
27
  const folders = [];
12
28
  if (!fs.existsSync(path))
13
29
  return [];
30
+ if (exclude) {
31
+ for (const exclusion of exclude) {
32
+ if (matchPath(path, exclusion))
33
+ return [];
34
+ }
35
+ }
14
36
  fs.readdirSync(path, { withFileTypes: true }).forEach((item) => {
15
37
  if (item.isDirectory()) {
16
38
  folders.push(item);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "0.3.0-canary.2",
3
+ "version": "0.3.0-canary.20",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -69,6 +69,7 @@
69
69
  "dependencies": {
70
70
  "chalk": "^4.1.2",
71
71
  "debug": "^4.4.0",
72
+ "glob": "^11.0.2",
72
73
  "graphql": "^16.11.0",
73
74
  "graphql-request": "^6.1.0",
74
75
  "memory-cache": "^0.2.0",
@@ -77,7 +78,7 @@
77
78
  },
78
79
  "description": "",
79
80
  "types": "types/index.d.ts",
80
- "gitHead": "8243c78fad6aa9456ac8cb726ac0a90c72589506",
81
+ "gitHead": "9e6d00a485580af695ac93b4403d84b9eda6c0fe",
81
82
  "files": [
82
83
  "dist",
83
84
  "types",
@@ -1,9 +1,15 @@
1
- import { SitecoreConfig, SitecoreConfigInput } from './models';
1
+ import { DeepPartial, SitecoreConfig, SitecoreConfigInput } from './models';
2
2
  /**
3
3
  * Provides default initial values for SitecoreConfig
4
4
  * @returns default config
5
5
  */
6
6
  export declare const getFallbackConfig: () => SitecoreConfig;
7
+ /**
8
+ * Deep merge utility that skips undefined or empty string values in the override.
9
+ * @param {T} base base value
10
+ * @param {DeepPartial<T>} [override] override value
11
+ */
12
+ export declare function deepMerge<T>(base: T, override?: DeepPartial<T>): T;
7
13
  /**
8
14
  * Accepts a SitecoreConfigInput object and returns full sitecore configuration
9
15
  * @param {SitecoreConfigInput} config override values to be written over default config settings
@@ -1,3 +1,2 @@
1
1
  export { SitecoreConfig, SitecoreConfigInput, SitecoreCliConfig, SitecoreCliConfigInput, ScaffoldTemplate, ComponentTemplateType, DeepRequired, } from './models';
2
2
  export { defineConfig } from './define-config';
3
- export { defineCliConfig } from './define-cli-config';
@@ -1,10 +1,17 @@
1
1
  import { RetryStrategy } from '../models';
2
+ import { GenerateMapFunction, GenerateMapArgs } from '../tools';
2
3
  /**
3
4
  * Utility type to make every property in a type required
4
5
  */
5
6
  export type DeepRequired<T> = Required<{
6
7
  [K in keyof T]: T[K] extends Required<T[K]> ? T[K] : DeepRequired<T[K]>;
7
8
  }>;
9
+ /**
10
+ * Utility type to make all properties in a type optional, recursively.
11
+ */
12
+ export type DeepPartial<T> = {
13
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
14
+ };
8
15
  /**
9
16
  * Type to be used as config input in sitecore.config
10
17
  */
@@ -199,6 +206,15 @@ export type SitecoreCliConfigInput = {
199
206
  */
200
207
  templates?: ScaffoldTemplate[];
201
208
  };
209
+ /**
210
+ * Configuration for the `sitecore-tools component generate-map` cli command
211
+ */
212
+ componentMap?: GenerateMapArgs & {
213
+ /**
214
+ * Function implementationt for generating a component map.
215
+ */
216
+ generator?: GenerateMapFunction;
217
+ };
202
218
  };
203
219
  /**
204
220
  * Final sitecore cli config type used required by the cli
@@ -1,4 +1,4 @@
1
- import { SitecoreCliConfig, SitecoreCliConfigInput } from './models';
1
+ import { SitecoreCliConfig, SitecoreCliConfigInput } from '../config/models';
2
2
  /**
3
3
  * Accepts a `SitecoreCliConfigInput` object and returns Sitecore Content SDK CLI configuration, updated with required default values
4
4
  * @param {SitecoreCliConfigInput} cliConfig the cli configuration provided by the application
@@ -0,0 +1 @@
1
+ export { defineCliConfig } from './define-cli-config';
@@ -1,4 +1,5 @@
1
1
  import { ComponentRendering, Field, GenericFieldValue } from '../layout/models';
2
+ import { DesignLibraryMode } from './models';
2
3
  /**
3
4
  * Event to be sent when report status to design library
4
5
  */
@@ -52,3 +53,9 @@ export declare function getDesignLibraryStatusEvent(status: DesignLibraryStatus,
52
53
  * @returns The full URL to the design library script.
53
54
  */
54
55
  export declare function getDesignLibraryScriptLink(sitecoreEdgeUrl?: string): string;
56
+ /**
57
+ * Checks if the given mode is a Design Library mode.
58
+ * @param {unknown} mode - The mode to check.
59
+ * @returns {boolean} True if the mode is a Design Library mode, false otherwise.
60
+ */
61
+ export declare function isDesignLibraryMode(mode: unknown): mode is DesignLibraryMode;
@@ -2,5 +2,5 @@ export { GraphQLEditingService } from './graphql-editing-service';
2
2
  export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChromes, Metadata, getJssPagesClientData, EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, PAGES_EDITING_MARKER, ComponentUpdateEventArgs, PREVIEW_KEY, } from './utils';
3
3
  export { RestComponentLayoutService, ComponentLayoutRequestParams, } from './rest-component-layout-service';
4
4
  export { EditingRenderQueryParams, RenderComponentQueryParams } from './models';
5
- export { LayoutKind, MetadataKind, EditingPreviewData, DesignLibraryRenderPreviewData, } from './models';
6
- export { addComponentUpdateHandler, DesignLibraryStatus, DesignLibraryStatusEvent, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, } from './design-library';
5
+ export { LayoutKind, MetadataKind, EditingPreviewData, DesignLibraryRenderPreviewData, DesignLibraryMode, } from './models';
6
+ export { addComponentUpdateHandler, DesignLibraryStatus, DesignLibraryStatusEvent, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, isDesignLibraryMode, } from './design-library';
@@ -11,7 +11,7 @@ export interface EditingRenderQueryParams {
11
11
  sc_itemid: string;
12
12
  sc_site: string;
13
13
  route: string;
14
- mode: Exclude<LayoutServicePageState, 'normal'> | 'library';
14
+ mode: Exclude<LayoutServicePageState, 'normal'> | DesignLibraryMode;
15
15
  sc_layoutKind?: LayoutKind;
16
16
  sc_variant?: string;
17
17
  sc_version?: string;
@@ -28,7 +28,7 @@ export interface RenderComponentQueryParams {
28
28
  sc_renderingId: string;
29
29
  sc_uid: string;
30
30
  sc_site: string;
31
- mode: 'library';
31
+ mode: DesignLibraryMode;
32
32
  sc_variant?: string;
33
33
  sc_version?: string;
34
34
  }
@@ -62,6 +62,13 @@ export type EditingPreviewData = {
62
62
  version?: string;
63
63
  layoutKind?: LayoutKind;
64
64
  };
65
+ /** Represents the mode of the Design Library */
66
+ export declare enum DesignLibraryMode {
67
+ /** Normal mode */
68
+ Normal = "library",
69
+ /** Metadata mode */
70
+ Metadata = "library-metadata"
71
+ }
65
72
  /**
66
73
  * Data for Design Library rendering mode
67
74
  */
@@ -71,7 +78,7 @@ export interface DesignLibraryRenderPreviewData {
71
78
  renderingId: string;
72
79
  componentUid: string;
73
80
  language: string;
74
- mode?: 'library';
81
+ mode?: DesignLibraryMode;
75
82
  variant?: string;
76
83
  version?: string;
77
84
  dataSourceId?: string;
@@ -1,41 +1,5 @@
1
- import { LayoutServiceData, EditMode } from '../layout/models';
2
- import { IncomingMessage, ServerResponse } from 'http';
3
- import { HttpDataFetcher } from '../data-fetcher';
4
- /**
5
- * Data fetcher resolver in order to provide custom data fetcher
6
- * @param {IncomingMessage} [req] Request instance
7
- * @param {ServerResponse} [res] Response instance
8
- */
9
- export type DataFetcherResolver = <T>(req?: IncomingMessage, res?: ServerResponse) => HttpDataFetcher<T>;
10
- export type RestLayoutServiceConfig = {
11
- /**
12
- * Your Sitecore instance hostname that is the backend for JSS
13
- */
14
- apiHost: string;
15
- /**
16
- * The Sitecore SSC API key your app uses
17
- */
18
- apiKey: string;
19
- /**
20
- * The JSS application name
21
- */
22
- siteName: string;
23
- /**
24
- * Enables/disables analytics tracking for the Layout Service invocation (default is true).
25
- * More than likely, this would be set to false for SSG/hybrid implementations, and the
26
- * JSS tracker would instead be used on the client-side
27
- * @default true
28
- */
29
- tracking?: boolean;
30
- /**
31
- * Function that handles fetching API data
32
- */
33
- dataFetcherResolver?: DataFetcherResolver;
34
- /**
35
- * Layout Service "named" configuration
36
- */
37
- configurationName?: string;
38
- };
1
+ import { LayoutServiceData } from '../layout/models';
2
+ import { DesignLibraryMode } from './models';
39
3
  /**
40
4
  * Params for requesting component data from service in Design Library mode
41
5
  */
@@ -66,35 +30,41 @@ export interface ComponentLayoutRequestParams {
66
30
  */
67
31
  version?: string;
68
32
  /**
69
- * edit mode to be rendered component in. Component is rendered in normal mode by default
33
+ * site name to be used as context for rendering the component
70
34
  */
71
- editMode?: EditMode;
35
+ siteName: string;
72
36
  /**
73
- * site name to be used as context for rendering the component
37
+ * mode to be used for rendering the component
74
38
  */
75
- siteName?: string;
39
+ mode?: DesignLibraryMode;
76
40
  }
77
41
  /**
78
- * REST service that enables Design Library functioality
79
- * Makes a request to /sitecore/api/layout/component in 'library' mode in Pages.
80
- * Returns layoutData for one single rendered component
42
+ * Config for the RestComponentLayoutService
81
43
  */
82
- export declare class RestComponentLayoutService {
83
- private config;
84
- constructor(config: RestLayoutServiceConfig);
85
- fetchComponentData(params: ComponentLayoutRequestParams, req?: IncomingMessage, res?: ServerResponse): Promise<LayoutServiceData>;
86
- protected getFetcher: (req?: IncomingMessage, res?: ServerResponse) => HttpDataFetcher<LayoutServiceData> | ((url: string, data?: RequestInit) => Promise<import("..").NativeDataFetcherResponse<LayoutServiceData>>);
44
+ export interface RestComponentLayoutServiceConfig {
87
45
  /**
88
- * Resolves layout service url
89
- * @param {string} apiType which layout service API to call ('render' or 'placeholder')
90
- * @returns the layout service url
46
+ * A unified identifier used to connect and retrieve data from XM Cloud instance
91
47
  */
92
- protected resolveLayoutServiceUrl(apiType: string): string;
48
+ contextId: string;
93
49
  /**
94
- * Provides default @see NativeDataFetcher data fetcher
95
- * @param {IncomingMessage} [req] Request instance
96
- * @returns default fetcher
50
+ * XM Cloud endpoint that the app will communicate and retrieve data from
51
+ * @default https://edge-platform.sitecorecloud.io
97
52
  */
98
- protected getDefaultFetcher: <T>(req?: IncomingMessage) => (url: string, data?: RequestInit) => Promise<import("..").NativeDataFetcherResponse<T>>;
53
+ edgeUrl?: string;
54
+ }
55
+ /**
56
+ * REST service that enables design Library functionality
57
+ * Returns layoutData for one single rendered component
58
+ */
59
+ export declare class RestComponentLayoutService {
60
+ private config;
61
+ constructor(config: RestComponentLayoutServiceConfig);
62
+ fetchComponentData(params: ComponentLayoutRequestParams): Promise<LayoutServiceData>;
99
63
  protected getComponentFetchParams(params: ComponentLayoutRequestParams): any;
64
+ /**
65
+ * Get the fetch URL for the partial layout data endpoint
66
+ * @param {ComponentLayoutRequestParams} params - The parameters for the request
67
+ * @returns {string} The fetch URL for the component data
68
+ */
69
+ private getFetchUrl;
100
70
  }
@@ -33,13 +33,6 @@ export interface NativeDataFetcherResponse<T> {
33
33
  export type NativeDataFetcherError = Error & {
34
34
  response: NativeDataFetcherResponse<unknown>;
35
35
  };
36
- /**
37
- * A function that fetches data from a given URL and returns a `NativeDataFetcherResponse`.
38
- * @param {string} url The URL to request (can include query string parameters).
39
- * @param {unknown} [data] Optional data to send with the request (e.g., for POST or PUT requests).
40
- * @returns {Promise<NativeDataFetcherResponse<T>>} A promise that resolves to a `NativeDataFetcherResponse<T>`,
41
- */
42
- export type NativeDataFetcherFunction<T> = (url: string, data?: RequestInit) => Promise<NativeDataFetcherResponse<T>>;
43
36
  export type NativeDataFetcherConfig = NativeDataFetcherOptions & RequestInit;
44
37
  export declare class NativeDataFetcher {
45
38
  protected config: NativeDataFetcherConfig;
@@ -35,6 +35,7 @@ export declare class GraphQLRobotsService {
35
35
  protected get query(): string;
36
36
  /**
37
37
  * Fetch a data of robots.txt from API
38
+ * @param {FetchOptions} fetchOptions - The fetch options to be used for the request.
38
39
  * @returns text of robots.txt
39
40
  * @throws {Error} if the siteName is empty.
40
41
  */