@sitecore-content-sdk/core 1.1.0-canary.21 → 1.1.0-canary.23

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.
@@ -149,7 +149,7 @@ class SitecoreClient {
149
149
  return null;
150
150
  }
151
151
  // If we're in Pages preview (editing) mode, prefetch the editing data
152
- const { site, itemId, language, version, variantIds, layoutKind, mode, } = previewData;
152
+ const { site, itemId, language, version, variantIds, layoutKind, mode } = previewData;
153
153
  const data = await this.editingService.fetchEditingData({
154
154
  itemId,
155
155
  language,
@@ -181,7 +181,7 @@ class SitecoreClient {
181
181
  if (!this.initOptions.api.local) {
182
182
  throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
183
183
  }
184
- const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode, } = designLibData;
184
+ const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode } = designLibData;
185
185
  const componentData = await this.componentService.fetchComponentData({
186
186
  siteName: site,
187
187
  itemId,
@@ -272,6 +272,7 @@ class SitecoreClient {
272
272
  throw new Error('REDIRECT_404');
273
273
  }
274
274
  return xmlResponse.data;
275
+ // eslint-disable-next-line no-unused-vars
275
276
  }
276
277
  catch (error) {
277
278
  throw new Error('REDIRECT_404');
@@ -16,8 +16,8 @@ const getFallbackConfig = () => ({
16
16
  edgeUrl: process.env.SITECORE_EDGE_URL || constants_1.SITECORE_EDGE_URL_DEFAULT,
17
17
  },
18
18
  local: {
19
- apiKey: '',
20
- apiHost: '',
19
+ apiKey: process.env.SITECORE_API_KEY || process.env.NEXT_PUBLIC_SITECORE_API_KEY || '',
20
+ apiHost: process.env.SITECORE_API_HOST || process.env.NEXT_PUBLIC_SITECORE_API_HOST || '',
21
21
  path: '/sitecore/api/graph/edge',
22
22
  },
23
23
  },
@@ -106,28 +106,31 @@ const resolveConfig = (base, override) => {
106
106
  return result;
107
107
  };
108
108
  const validateConfig = (config) => {
109
- var _a, _b, _c, _d;
109
+ var _a, _b, _c, _d, _e, _f, _g, _h;
110
110
  const isBrowser = typeof window !== 'undefined';
111
111
  const hasEdgeContextId = !!((_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId);
112
112
  const hasClientContextId = !!((_d = (_c = config.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.clientContextId);
113
- // Server-side check
114
- if (typeof window === 'undefined') {
115
- if (!hasEdgeContextId) {
116
- throw new Error(`Configuration error: a server-side Edge contextId (api.edge.contextId) is required.
117
- Supplying only clientContextId or local-API credentials is not sufficient`);
113
+ const hasLocalCreds = !!((_f = (_e = config.api) === null || _e === void 0 ? void 0 : _e.local) === null || _f === void 0 ? void 0 : _f.apiHost) && !!((_h = (_g = config.api) === null || _g === void 0 ? void 0 : _g.local) === null || _h === void 0 ? void 0 : _h.apiKey);
114
+ // Server-side: allow Edge OR Local; clientContextId alone is NOT sufficient
115
+ if (!isBrowser) {
116
+ if (!hasEdgeContextId && !hasLocalCreds) {
117
+ throw new Error('Configuration error: provide either Edge contextId (api.edge.contextId) or local credentials (api.local.apiHost + api.local.apiKey).');
118
118
  }
119
- if (!hasClientContextId) {
119
+ if (hasEdgeContextId && !hasClientContextId) {
120
120
  // eslint-disable-next-line no-console
121
- console.warn(`Warning: only a server-side contextId is provided.
122
- If your app makes client-side requests, they will fail unless you also set a clientContextId.`);
121
+ if (process.env.NODE_ENV === 'development') {
122
+ console.warn('Warning: only a server-side edge contextId is provided. Client-side requests will require api.edge.clientContextId or a proxy.');
123
+ }
123
124
  }
124
125
  return; // validation complete on the server
125
126
  }
126
127
  // Browser-side warning (runs only if contextId exists but clientContextId is missing)
127
128
  if (isBrowser && !hasClientContextId) {
128
129
  // eslint-disable-next-line no-console
129
- console.warn(`Warning: clientContextId is missing. The browser will use contextId instead.
130
- Client Side functionalities (like Tracking and Personalization) may be limited.`);
130
+ if (process.env.NODE_ENV === 'development') {
131
+ console.warn(`Warning: clientContextId is missing. The browser will use contextId instead.
132
+ Client Side functionalities (like Tracking and Personalization) may be limited.`);
133
+ }
131
134
  }
132
135
  };
133
136
  /**
package/dist/cjs/debug.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.enableDebug = void 0;
8
+ /* eslint-disable import/no-anonymous-default-export */
8
9
  const debug_1 = __importDefault(require("debug"));
9
10
  const is_server_1 = __importDefault(require("./utils/is-server"));
10
11
  const rootNamespace = 'content-sdk';
@@ -40,10 +40,7 @@ class SiteResolver {
40
40
  // First collect unique hostnames.
41
41
  // For sites with same hostname defined, priority is given to the first encountered.
42
42
  this.sites.forEach((site) => {
43
- const hostnames = site.hostName
44
- .replace(/\s/g, '')
45
- .toLocaleLowerCase()
46
- .split(DELIMITERS);
43
+ const hostnames = site.hostName.replace(/\s/g, '').toLocaleLowerCase().split(DELIMITERS);
47
44
  hostnames.forEach((hostname) => {
48
45
  if (!map.has(hostname)) {
49
46
  map.set(hostname, site);
@@ -14,6 +14,7 @@ const tryParseEnvValue = (envValue, defaultValue) => {
14
14
  if (envValue.startsWith('{') && envValue.endsWith('}')) {
15
15
  try {
16
16
  return JSON.parse(envValue);
17
+ // eslint-disable-next-line no-unused-vars
17
18
  }
18
19
  catch (error) {
19
20
  console.warn('Parsing of env variable failed');
@@ -74,12 +74,7 @@ exports.isTimeoutError = isTimeoutError;
74
74
  * @returns {string} modified string that can be used as regexp input
75
75
  */
76
76
  const convertToWildcardRegex = (pattern) => {
77
- return ('^' +
78
- pattern
79
- .replace(/\//g, '\\/')
80
- .replace(/\./g, '\\.')
81
- .replace(/\*/g, '.*') +
82
- '$');
77
+ return '^' + pattern.replace(/\//g, '\\/').replace(/\./g, '\\.').replace(/\*/g, '.*') + '$';
83
78
  };
84
79
  /**
85
80
  * Gets allowed origins from JSS_ALLOWED_ORIGINS env variable
@@ -146,7 +146,7 @@ export class SitecoreClient {
146
146
  return null;
147
147
  }
148
148
  // If we're in Pages preview (editing) mode, prefetch the editing data
149
- const { site, itemId, language, version, variantIds, layoutKind, mode, } = previewData;
149
+ const { site, itemId, language, version, variantIds, layoutKind, mode } = previewData;
150
150
  const data = await this.editingService.fetchEditingData({
151
151
  itemId,
152
152
  language,
@@ -178,7 +178,7 @@ export class SitecoreClient {
178
178
  if (!this.initOptions.api.local) {
179
179
  throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
180
180
  }
181
- const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode, } = designLibData;
181
+ const { itemId, componentUid, site, language, renderingId, dataSourceId, version, mode } = designLibData;
182
182
  const componentData = await this.componentService.fetchComponentData({
183
183
  siteName: site,
184
184
  itemId,
@@ -269,6 +269,7 @@ export class SitecoreClient {
269
269
  throw new Error('REDIRECT_404');
270
270
  }
271
271
  return xmlResponse.data;
272
+ // eslint-disable-next-line no-unused-vars
272
273
  }
273
274
  catch (error) {
274
275
  throw new Error('REDIRECT_404');
@@ -12,8 +12,8 @@ export const getFallbackConfig = () => ({
12
12
  edgeUrl: process.env.SITECORE_EDGE_URL || SITECORE_EDGE_URL_DEFAULT,
13
13
  },
14
14
  local: {
15
- apiKey: '',
16
- apiHost: '',
15
+ apiKey: process.env.SITECORE_API_KEY || process.env.NEXT_PUBLIC_SITECORE_API_KEY || '',
16
+ apiHost: process.env.SITECORE_API_HOST || process.env.NEXT_PUBLIC_SITECORE_API_HOST || '',
17
17
  path: '/sitecore/api/graph/edge',
18
18
  },
19
19
  },
@@ -101,28 +101,31 @@ const resolveConfig = (base, override) => {
101
101
  return result;
102
102
  };
103
103
  const validateConfig = (config) => {
104
- var _a, _b, _c, _d;
104
+ var _a, _b, _c, _d, _e, _f, _g, _h;
105
105
  const isBrowser = typeof window !== 'undefined';
106
106
  const hasEdgeContextId = !!((_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId);
107
107
  const hasClientContextId = !!((_d = (_c = config.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.clientContextId);
108
- // Server-side check
109
- if (typeof window === 'undefined') {
110
- if (!hasEdgeContextId) {
111
- throw new Error(`Configuration error: a server-side Edge contextId (api.edge.contextId) is required.
112
- Supplying only clientContextId or local-API credentials is not sufficient`);
108
+ const hasLocalCreds = !!((_f = (_e = config.api) === null || _e === void 0 ? void 0 : _e.local) === null || _f === void 0 ? void 0 : _f.apiHost) && !!((_h = (_g = config.api) === null || _g === void 0 ? void 0 : _g.local) === null || _h === void 0 ? void 0 : _h.apiKey);
109
+ // Server-side: allow Edge OR Local; clientContextId alone is NOT sufficient
110
+ if (!isBrowser) {
111
+ if (!hasEdgeContextId && !hasLocalCreds) {
112
+ throw new Error('Configuration error: provide either Edge contextId (api.edge.contextId) or local credentials (api.local.apiHost + api.local.apiKey).');
113
113
  }
114
- if (!hasClientContextId) {
114
+ if (hasEdgeContextId && !hasClientContextId) {
115
115
  // eslint-disable-next-line no-console
116
- console.warn(`Warning: only a server-side contextId is provided.
117
- If your app makes client-side requests, they will fail unless you also set a clientContextId.`);
116
+ if (process.env.NODE_ENV === 'development') {
117
+ console.warn('Warning: only a server-side edge contextId is provided. Client-side requests will require api.edge.clientContextId or a proxy.');
118
+ }
118
119
  }
119
120
  return; // validation complete on the server
120
121
  }
121
122
  // Browser-side warning (runs only if contextId exists but clientContextId is missing)
122
123
  if (isBrowser && !hasClientContextId) {
123
124
  // eslint-disable-next-line no-console
124
- console.warn(`Warning: clientContextId is missing. The browser will use contextId instead.
125
- Client Side functionalities (like Tracking and Personalization) may be limited.`);
125
+ if (process.env.NODE_ENV === 'development') {
126
+ console.warn(`Warning: clientContextId is missing. The browser will use contextId instead.
127
+ Client Side functionalities (like Tracking and Personalization) may be limited.`);
128
+ }
126
129
  }
127
130
  };
128
131
  /**
package/dist/esm/debug.js CHANGED
@@ -1,4 +1,5 @@
1
1
  var _a;
2
+ /* eslint-disable import/no-anonymous-default-export */
2
3
  import debug from 'debug';
3
4
  import isServer from './utils/is-server';
4
5
  const rootNamespace = 'content-sdk';
@@ -37,10 +37,7 @@ export class SiteResolver {
37
37
  // First collect unique hostnames.
38
38
  // For sites with same hostname defined, priority is given to the first encountered.
39
39
  this.sites.forEach((site) => {
40
- const hostnames = site.hostName
41
- .replace(/\s/g, '')
42
- .toLocaleLowerCase()
43
- .split(DELIMITERS);
40
+ const hostnames = site.hostName.replace(/\s/g, '').toLocaleLowerCase().split(DELIMITERS);
44
41
  hostnames.forEach((hostname) => {
45
42
  if (!map.has(hostname)) {
46
43
  map.set(hostname, site);
@@ -11,6 +11,7 @@ export const tryParseEnvValue = (envValue, defaultValue) => {
11
11
  if (envValue.startsWith('{') && envValue.endsWith('}')) {
12
12
  try {
13
13
  return JSON.parse(envValue);
14
+ // eslint-disable-next-line no-unused-vars
14
15
  }
15
16
  catch (error) {
16
17
  console.warn('Parsing of env variable failed');
@@ -65,12 +65,7 @@ export const isTimeoutError = (error) => {
65
65
  * @returns {string} modified string that can be used as regexp input
66
66
  */
67
67
  const convertToWildcardRegex = (pattern) => {
68
- return ('^' +
69
- pattern
70
- .replace(/\//g, '\\/')
71
- .replace(/\./g, '\\.')
72
- .replace(/\*/g, '.*') +
73
- '$');
68
+ return '^' + pattern.replace(/\//g, '\\/').replace(/\./g, '\\.').replace(/\*/g, '.*') + '$';
74
69
  };
75
70
  /**
76
71
  * Gets allowed origins from JSS_ALLOWED_ORIGINS env variable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "1.1.0-canary.21",
3
+ "version": "1.1.0-canary.23",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@sitecore-cloudsdk/events": "^0.5.1",
38
+ "@stylistic/eslint-plugin": "^5.2.2",
38
39
  "@types/chai": "^5.2.2",
39
40
  "@types/chai-spies": "^1.0.6",
40
41
  "@types/chai-string": "^1.4.5",
@@ -47,16 +48,22 @@
47
48
  "@types/sinon": "^17.0.4",
48
49
  "@types/sinon-chai": "^4.0.0",
49
50
  "@types/url-parse": "1.4.11",
51
+ "@typescript-eslint/eslint-plugin": "8.39.0",
52
+ "@typescript-eslint/parser": "8.39.0",
50
53
  "chai": "^4.4.1",
51
54
  "chai-spies": "^1.1.0",
52
55
  "chai-string": "^1.6.0",
53
56
  "del-cli": "^6.0.0",
54
- "eslint": "^8.56.0",
55
- "eslint-plugin-jsdoc": "50.6.11",
57
+ "eslint": "^9.32.0",
58
+ "eslint-config-prettier": "^10.1.8",
59
+ "eslint-plugin-import": "2.32.0",
60
+ "eslint-plugin-jsdoc": "52.0.3",
61
+ "eslint-plugin-prettier": "^4.0.0",
56
62
  "jsdom": "^26.1.0",
57
63
  "mocha": "^11.2.2",
58
64
  "nock": "14.0.0-beta.7",
59
65
  "nyc": "^17.1.0",
66
+ "prettier": "^2.8.0",
60
67
  "proxyquire": "^2.1.3",
61
68
  "sinon": "^20.0.0",
62
69
  "tslib": "^2.8.1",
@@ -78,7 +85,7 @@
78
85
  },
79
86
  "description": "",
80
87
  "types": "types/index.d.ts",
81
- "gitHead": "ddb30f9f3bca1aa3f3f54e1af9eb5b15a5987e43",
88
+ "gitHead": "b24ee0d69b7c21e804009407b01c535d0ba3ea91",
82
89
  "files": [
83
90
  "dist",
84
91
  "types",