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

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.
@@ -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
  /**
@@ -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/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.22",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "description": "",
80
80
  "types": "types/index.d.ts",
81
- "gitHead": "ddb30f9f3bca1aa3f3f54e1af9eb5b15a5987e43",
81
+ "gitHead": "96b2770210d5294a54b8c0ea0a0994c7f7149727",
82
82
  "files": [
83
83
  "dist",
84
84
  "types",