@sitecore-content-sdk/core 0.2.0-beta.6 → 0.2.0-beta.7

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.
@@ -9,6 +9,7 @@ const layout_personalizer_1 = require("../personalize/layout-personalizer");
9
9
  const site_1 = require("../site");
10
10
  const utils_2 = require("./utils");
11
11
  const native_fetcher_1 = require("../native-fetcher");
12
+ const graphql_robots_service_1 = require("../site/graphql-robots-service");
12
13
  /**
13
14
  * This is a generic content client that can be used by any framework.
14
15
  * Use it to retrieve pages, preview data, dictionary and other data
@@ -19,16 +20,19 @@ class SitecoreClient {
19
20
  * @param {SitecoreClientInit} initOptions initOptions for the client, containing site and Sitecore connection details
20
21
  */
21
22
  constructor(initOptions) {
23
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
22
24
  this.initOptions = initOptions;
23
25
  this.clientFactory = this.getClientFactory();
24
- this.siteResolver = this.getSiteResolver();
26
+ this.siteResolver = (_b = (_a = initOptions.custom) === null || _a === void 0 ? void 0 : _a.siteResolver) !== null && _b !== void 0 ? _b : this.getSiteResolver();
25
27
  const baseServiceOptions = this.getBaseServiceOptions();
26
- this.layoutService = this.getLayoutService(baseServiceOptions);
27
- this.dictionaryService = this.getDictionaryService(baseServiceOptions);
28
- this.editingService = this.getEditingService();
29
- this.errorPagesService = this.getErrorPagesService();
28
+ this.layoutService =
29
+ (_d = (_c = initOptions.custom) === null || _c === void 0 ? void 0 : _c.layoutService) !== null && _d !== void 0 ? _d : this.getLayoutService(baseServiceOptions);
30
+ this.dictionaryService =
31
+ (_f = (_e = initOptions.custom) === null || _e === void 0 ? void 0 : _e.dictionaryService) !== null && _f !== void 0 ? _f : this.getDictionaryService(baseServiceOptions);
32
+ this.editingService = (_h = (_g = initOptions.custom) === null || _g === void 0 ? void 0 : _g.editingService) !== null && _h !== void 0 ? _h : this.getEditingService();
33
+ this.errorPagesService = (_k = (_j = initOptions.custom) === null || _j === void 0 ? void 0 : _j.errorPagesService) !== null && _k !== void 0 ? _k : this.getErrorPagesService();
34
+ this.sitePathService = (_m = (_l = initOptions.custom) === null || _l === void 0 ? void 0 : _l.sitePathService) !== null && _m !== void 0 ? _m : this.getSitePathService();
30
35
  this.componentService = this.getComponentService();
31
- this.sitePathService = this.getSitePathService();
32
36
  }
33
37
  /**
34
38
  * Resolve site by hostname
@@ -59,7 +63,7 @@ class SitecoreClient {
59
63
  * Get page details for a route, with layout and other details
60
64
  * @param {string} path route path
61
65
  * @param {PageOptions} [pageOptions] site, language and personalization variant details for route
62
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
66
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
63
67
  * @returns {Page | null} page details
64
68
  */
65
69
  async getPage(path, pageOptions, fetchOptions) {
@@ -115,7 +119,7 @@ class SitecoreClient {
115
119
  /**
116
120
  * Retrieves dictionary phrases for a given site and locale.
117
121
  * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
118
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
122
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
119
123
  * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
120
124
  */
121
125
  async getDictionary(routeOptions, fetchOptions) {
@@ -126,7 +130,7 @@ class SitecoreClient {
126
130
  /**
127
131
  * Retrieves error pages for a given site and locale.
128
132
  * @param {RouteOptions} routeOptions - Route options containing language and site name to load error pages
129
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
133
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
130
134
  * @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
131
135
  */
132
136
  async getErrorPages(routeOptions, fetchOptions) {
@@ -137,7 +141,7 @@ class SitecoreClient {
137
141
  /**
138
142
  * Retrieves preview page and layout details
139
143
  * @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
140
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
144
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
141
145
  * @returns {Page} preview page details
142
146
  */
143
147
  async getPreview(previewData, fetchOptions) {
@@ -171,7 +175,7 @@ class SitecoreClient {
171
175
  /**
172
176
  * Get design library page details for Design Library mode of your app
173
177
  * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
174
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
178
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
175
179
  * @returns {Page} preview page for Design Library
176
180
  */
177
181
  async getDesignLibraryData(designLibData, fetchOptions) {
@@ -256,6 +260,18 @@ class SitecoreClient {
256
260
  .join('')}
257
261
  </sitemapindex>`;
258
262
  }
263
+ /**
264
+ * Retrieves the robots.txt content for a given site name.
265
+ * @param {string} siteName - The name of the site to retrieve the robots.txt for.
266
+ * @param {FetchOptions} [fetchOptions] - Optional fetch options.
267
+ * @returns {Promise<string | null>} A promise that resolves to the robots.txt content,
268
+ * or null if no content is found.
269
+ */
270
+ async getRobots(siteName, fetchOptions) {
271
+ const robotsService = this.getRobotsService(siteName || this.initOptions.defaultSite);
272
+ const content = await robotsService.fetchRobots(fetchOptions);
273
+ return content || null;
274
+ }
259
275
  /**
260
276
  * Factory methods for creating dependencies
261
277
  * Subclasses can override these to provide custom implementations.
@@ -266,6 +282,12 @@ class SitecoreClient {
266
282
  siteName,
267
283
  });
268
284
  }
285
+ getRobotsService(siteName) {
286
+ return new graphql_robots_service_1.GraphQLRobotsService({
287
+ clientFactory: this.clientFactory,
288
+ siteName,
289
+ });
290
+ }
269
291
  getBaseServiceOptions() {
270
292
  return {
271
293
  defaultSite: this.initOptions.defaultSite,
@@ -10,9 +10,9 @@ const retries_1 = require("../retries");
10
10
  const getFallbackConfig = () => ({
11
11
  api: {
12
12
  edge: {
13
- contextId: '',
13
+ contextId: process.env.SITECORE_EDGE_CONTEXT_ID || '',
14
14
  clientContextId: '',
15
- edgeUrl: constants_1.SITECORE_EDGE_URL_DEFAULT,
15
+ edgeUrl: process.env.SITECORE_EDGE_URL || constants_1.SITECORE_EDGE_URL_DEFAULT,
16
16
  },
17
17
  local: {
18
18
  apiKey: '',
@@ -20,7 +20,7 @@ const getFallbackConfig = () => ({
20
20
  path: '/sitecore/api/graph/edge',
21
21
  },
22
22
  },
23
- editingSecret: 'editing-secret-missing',
23
+ editingSecret: process.env.JSS_EDITING_SECRET || 'editing-secret-missing',
24
24
  retries: {
25
25
  count: 3,
26
26
  retryStrategy: new retries_1.DefaultRetryStrategy({
@@ -37,8 +37,8 @@ const getFallbackConfig = () => ({
37
37
  },
38
38
  personalize: {
39
39
  enabled: process.env.NODE_ENV !== 'development',
40
- edgeTimeout: 400,
41
- cdpTimeout: 400,
40
+ edgeTimeout: parseInt(process.env.PERSONALIZE_MIDDLEWARE_EDGE_TIMEOUT, 10) || 400,
41
+ cdpTimeout: parseInt(process.env.PERSONALIZE_MIDDLEWARE_CDP_TIMEOUT, 10) || 400,
42
42
  scope: '',
43
43
  channel: 'WEB',
44
44
  currency: 'USD',
@@ -66,8 +66,7 @@ class ContentClient {
66
66
  }
67
67
  /**
68
68
  * Retrieves the locale information for a given locale ID.
69
- *
70
- * @param id - The unique identifier of the locale item.
69
+ * @param {string} id - The unique identifier of the locale item.
71
70
  * @returns A promise that resolves to the locale information associated with the specified locale ID.
72
71
  */
73
72
  async getLocale(id) {
@@ -77,7 +76,6 @@ class ContentClient {
77
76
  }
78
77
  /**
79
78
  * Retrieves all available locales from the content service.
80
- *
81
79
  * @returns A promise that resolves to an array of locales.
82
80
  */
83
81
  async getLocales() {
@@ -36,14 +36,14 @@ class GraphQLRobotsService {
36
36
  * @returns text of robots.txt
37
37
  * @throws {Error} if the siteName is empty.
38
38
  */
39
- async fetchRobots() {
39
+ async fetchRobots(fetchOptions) {
40
40
  const siteName = this.options.siteName;
41
41
  if (!siteName) {
42
42
  throw new Error(constants_1.siteNameError);
43
43
  }
44
44
  const robotsResult = this.graphQLClient.request(this.query, {
45
45
  siteName,
46
- });
46
+ }, fetchOptions);
47
47
  try {
48
48
  return robotsResult.then((result) => {
49
49
  var _a, _b;
@@ -6,6 +6,7 @@ import { personalizeLayout } from '../personalize/layout-personalizer';
6
6
  import { SiteResolver, GraphQLErrorPagesService, GraphQLSitePathService, GraphQLSitemapXmlService, } from '../site';
7
7
  import { createGraphQLClientFactory } from './utils';
8
8
  import { NativeDataFetcher } from '../native-fetcher';
9
+ import { GraphQLRobotsService } from '../site/graphql-robots-service';
9
10
  /**
10
11
  * This is a generic content client that can be used by any framework.
11
12
  * Use it to retrieve pages, preview data, dictionary and other data
@@ -16,16 +17,19 @@ export class SitecoreClient {
16
17
  * @param {SitecoreClientInit} initOptions initOptions for the client, containing site and Sitecore connection details
17
18
  */
18
19
  constructor(initOptions) {
20
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
19
21
  this.initOptions = initOptions;
20
22
  this.clientFactory = this.getClientFactory();
21
- this.siteResolver = this.getSiteResolver();
23
+ this.siteResolver = (_b = (_a = initOptions.custom) === null || _a === void 0 ? void 0 : _a.siteResolver) !== null && _b !== void 0 ? _b : this.getSiteResolver();
22
24
  const baseServiceOptions = this.getBaseServiceOptions();
23
- this.layoutService = this.getLayoutService(baseServiceOptions);
24
- this.dictionaryService = this.getDictionaryService(baseServiceOptions);
25
- this.editingService = this.getEditingService();
26
- this.errorPagesService = this.getErrorPagesService();
25
+ this.layoutService =
26
+ (_d = (_c = initOptions.custom) === null || _c === void 0 ? void 0 : _c.layoutService) !== null && _d !== void 0 ? _d : this.getLayoutService(baseServiceOptions);
27
+ this.dictionaryService =
28
+ (_f = (_e = initOptions.custom) === null || _e === void 0 ? void 0 : _e.dictionaryService) !== null && _f !== void 0 ? _f : this.getDictionaryService(baseServiceOptions);
29
+ this.editingService = (_h = (_g = initOptions.custom) === null || _g === void 0 ? void 0 : _g.editingService) !== null && _h !== void 0 ? _h : this.getEditingService();
30
+ this.errorPagesService = (_k = (_j = initOptions.custom) === null || _j === void 0 ? void 0 : _j.errorPagesService) !== null && _k !== void 0 ? _k : this.getErrorPagesService();
31
+ this.sitePathService = (_m = (_l = initOptions.custom) === null || _l === void 0 ? void 0 : _l.sitePathService) !== null && _m !== void 0 ? _m : this.getSitePathService();
27
32
  this.componentService = this.getComponentService();
28
- this.sitePathService = this.getSitePathService();
29
33
  }
30
34
  /**
31
35
  * Resolve site by hostname
@@ -56,7 +60,7 @@ export class SitecoreClient {
56
60
  * Get page details for a route, with layout and other details
57
61
  * @param {string} path route path
58
62
  * @param {PageOptions} [pageOptions] site, language and personalization variant details for route
59
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
63
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
60
64
  * @returns {Page | null} page details
61
65
  */
62
66
  async getPage(path, pageOptions, fetchOptions) {
@@ -112,7 +116,7 @@ export class SitecoreClient {
112
116
  /**
113
117
  * Retrieves dictionary phrases for a given site and locale.
114
118
  * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
115
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
119
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
116
120
  * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
117
121
  */
118
122
  async getDictionary(routeOptions, fetchOptions) {
@@ -123,7 +127,7 @@ export class SitecoreClient {
123
127
  /**
124
128
  * Retrieves error pages for a given site and locale.
125
129
  * @param {RouteOptions} routeOptions - Route options containing language and site name to load error pages
126
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
130
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
127
131
  * @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
128
132
  */
129
133
  async getErrorPages(routeOptions, fetchOptions) {
@@ -134,7 +138,7 @@ export class SitecoreClient {
134
138
  /**
135
139
  * Retrieves preview page and layout details
136
140
  * @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
137
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
141
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
138
142
  * @returns {Page} preview page details
139
143
  */
140
144
  async getPreview(previewData, fetchOptions) {
@@ -168,7 +172,7 @@ export class SitecoreClient {
168
172
  /**
169
173
  * Get design library page details for Design Library mode of your app
170
174
  * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
171
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
175
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
172
176
  * @returns {Page} preview page for Design Library
173
177
  */
174
178
  async getDesignLibraryData(designLibData, fetchOptions) {
@@ -253,6 +257,18 @@ export class SitecoreClient {
253
257
  .join('')}
254
258
  </sitemapindex>`;
255
259
  }
260
+ /**
261
+ * Retrieves the robots.txt content for a given site name.
262
+ * @param {string} siteName - The name of the site to retrieve the robots.txt for.
263
+ * @param {FetchOptions} [fetchOptions] - Optional fetch options.
264
+ * @returns {Promise<string | null>} A promise that resolves to the robots.txt content,
265
+ * or null if no content is found.
266
+ */
267
+ async getRobots(siteName, fetchOptions) {
268
+ const robotsService = this.getRobotsService(siteName || this.initOptions.defaultSite);
269
+ const content = await robotsService.fetchRobots(fetchOptions);
270
+ return content || null;
271
+ }
256
272
  /**
257
273
  * Factory methods for creating dependencies
258
274
  * Subclasses can override these to provide custom implementations.
@@ -263,6 +279,12 @@ export class SitecoreClient {
263
279
  siteName,
264
280
  });
265
281
  }
282
+ getRobotsService(siteName) {
283
+ return new GraphQLRobotsService({
284
+ clientFactory: this.clientFactory,
285
+ siteName,
286
+ });
287
+ }
266
288
  getBaseServiceOptions() {
267
289
  return {
268
290
  defaultSite: this.initOptions.defaultSite,
@@ -7,9 +7,9 @@ import { DefaultRetryStrategy } from '../retries';
7
7
  export const getFallbackConfig = () => ({
8
8
  api: {
9
9
  edge: {
10
- contextId: '',
10
+ contextId: process.env.SITECORE_EDGE_CONTEXT_ID || '',
11
11
  clientContextId: '',
12
- edgeUrl: SITECORE_EDGE_URL_DEFAULT,
12
+ edgeUrl: process.env.SITECORE_EDGE_URL || SITECORE_EDGE_URL_DEFAULT,
13
13
  },
14
14
  local: {
15
15
  apiKey: '',
@@ -17,7 +17,7 @@ export const getFallbackConfig = () => ({
17
17
  path: '/sitecore/api/graph/edge',
18
18
  },
19
19
  },
20
- editingSecret: 'editing-secret-missing',
20
+ editingSecret: process.env.JSS_EDITING_SECRET || 'editing-secret-missing',
21
21
  retries: {
22
22
  count: 3,
23
23
  retryStrategy: new DefaultRetryStrategy({
@@ -34,8 +34,8 @@ export const getFallbackConfig = () => ({
34
34
  },
35
35
  personalize: {
36
36
  enabled: process.env.NODE_ENV !== 'development',
37
- edgeTimeout: 400,
38
- cdpTimeout: 400,
37
+ edgeTimeout: parseInt(process.env.PERSONALIZE_MIDDLEWARE_EDGE_TIMEOUT, 10) || 400,
38
+ cdpTimeout: parseInt(process.env.PERSONALIZE_MIDDLEWARE_CDP_TIMEOUT, 10) || 400,
39
39
  scope: '',
40
40
  channel: 'WEB',
41
41
  currency: 'USD',
@@ -60,8 +60,7 @@ export class ContentClient {
60
60
  }
61
61
  /**
62
62
  * Retrieves the locale information for a given locale ID.
63
- *
64
- * @param id - The unique identifier of the locale item.
63
+ * @param {string} id - The unique identifier of the locale item.
65
64
  * @returns A promise that resolves to the locale information associated with the specified locale ID.
66
65
  */
67
66
  async getLocale(id) {
@@ -71,7 +70,6 @@ export class ContentClient {
71
70
  }
72
71
  /**
73
72
  * Retrieves all available locales from the content service.
74
- *
75
73
  * @returns A promise that resolves to an array of locales.
76
74
  */
77
75
  async getLocales() {
@@ -30,14 +30,14 @@ export class GraphQLRobotsService {
30
30
  * @returns text of robots.txt
31
31
  * @throws {Error} if the siteName is empty.
32
32
  */
33
- async fetchRobots() {
33
+ async fetchRobots(fetchOptions) {
34
34
  const siteName = this.options.siteName;
35
35
  if (!siteName) {
36
36
  throw new Error(siteNameError);
37
37
  }
38
38
  const robotsResult = this.graphQLClient.request(this.query, {
39
39
  siteName,
40
- });
40
+ }, fetchOptions);
41
41
  try {
42
42
  return robotsResult.then((result) => {
43
43
  var _a, _b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "0.2.0-beta.6",
3
+ "version": "0.2.0-beta.7",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -34,42 +34,42 @@
34
34
  "url": "https://github.com/sitecore/content-sdk/issues"
35
35
  },
36
36
  "devDependencies": {
37
- "@sitecore-cloudsdk/events": "^0.5.0",
38
- "@types/chai": "^5.0.1",
37
+ "@sitecore-cloudsdk/events": "^0.5.1",
38
+ "@types/chai": "^5.2.2",
39
39
  "@types/chai-spies": "^1.0.6",
40
40
  "@types/chai-string": "^1.4.5",
41
41
  "@types/debug": "^4.1.12",
42
42
  "@types/jsdom": "^21.1.7",
43
43
  "@types/memory-cache": "^0.2.6",
44
- "@types/mocha": "^10.0.1",
45
- "@types/node": "^22.12.0",
44
+ "@types/mocha": "^10.0.10",
45
+ "@types/node": "^22.15.14",
46
46
  "@types/proxyquire": "^1.3.31",
47
- "@types/sinon": "^17.0.3",
47
+ "@types/sinon": "^17.0.4",
48
48
  "@types/sinon-chai": "^4.0.0",
49
49
  "@types/url-parse": "1.4.11",
50
- "chai": "^4.2.0",
50
+ "chai": "^4.4.1",
51
51
  "chai-spies": "^1.1.0",
52
- "chai-string": "^1.5.0",
52
+ "chai-string": "^1.6.0",
53
53
  "del-cli": "^6.0.0",
54
54
  "eslint": "^8.56.0",
55
- "eslint-plugin-jsdoc": "48.7.0",
56
- "jsdom": "^26.0.0",
57
- "mocha": "^11.1.0",
55
+ "eslint-plugin-jsdoc": "50.6.11",
56
+ "jsdom": "^26.1.0",
57
+ "mocha": "^11.2.2",
58
58
  "nock": "14.0.0-beta.7",
59
59
  "nyc": "^17.1.0",
60
60
  "proxyquire": "^2.1.3",
61
61
  "sinon": "^20.0.0",
62
62
  "tslib": "^2.8.1",
63
- "tsx": "^4.19.2",
64
- "typescript": "~5.7.3"
63
+ "tsx": "^4.19.4",
64
+ "typescript": "~5.8.3"
65
65
  },
66
66
  "peerDependencies": {
67
- "@sitecore-cloudsdk/events": "^0.5.0"
67
+ "@sitecore-cloudsdk/events": "^0.5.1"
68
68
  },
69
69
  "dependencies": {
70
70
  "chalk": "^4.1.2",
71
71
  "debug": "^4.4.0",
72
- "graphql": "^16.10.0",
72
+ "graphql": "^16.11.0",
73
73
  "graphql-request": "^6.1.0",
74
74
  "memory-cache": "^0.2.0",
75
75
  "sinon-chai": "^4.0.0",
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "description": "",
79
79
  "types": "types/index.d.ts",
80
- "gitHead": "a56ee0c0a3897b5f9915329e20469fa427ee13a8",
80
+ "gitHead": "72e0db1a8d4142e567d6849f3d98e39b7826e6d9",
81
81
  "files": [
82
82
  "dist",
83
83
  "types",
@@ -4,4 +4,4 @@ export { RetryStrategy, PageInfo, FetchOptions } from '../models';
4
4
  export { getEdgeProxyContentUrl, getEdgeProxyFormsUrl } from './graphql-edge-proxy';
5
5
  export { SitecoreClient, Page, PageOptions, SitemapXmlOptions } from './sitecore-client';
6
6
  export { SitecoreClientInit } from './models';
7
- export { createGraphQLClientFactory } from './utils';
7
+ export { createGraphQLClientFactory, GraphQLClientOptions } from './utils';
@@ -1,5 +1,21 @@
1
1
  import { SitecoreConfig } from '../config';
2
- import { SiteInfo } from '../site';
2
+ import { GraphQLEditingService } from '../editing/graphql-editing-service';
3
+ import { RestComponentLayoutService } from '../editing/rest-component-layout-service';
4
+ import { GraphQLDictionaryService } from '../i18n/graphql-dictionary-service';
5
+ import { GraphQLLayoutService } from '../layout/graphql-layout-service';
6
+ import { GraphQLErrorPagesService, GraphQLSitePathService, SiteInfo, SiteResolver } from '../site';
7
+ /**
8
+ * Init options for Sitecore Client that allows you to override services too
9
+ */
3
10
  export type SitecoreClientInit = Omit<SitecoreConfig, 'multisite' | 'redirects' | 'personalize'> & {
4
11
  sites: SiteInfo[];
12
+ custom?: {
13
+ layoutService?: GraphQLLayoutService;
14
+ dictionaryService?: GraphQLDictionaryService;
15
+ siteResolver?: SiteResolver;
16
+ editingService?: GraphQLEditingService;
17
+ errorPagesService?: GraphQLErrorPagesService;
18
+ componentService?: RestComponentLayoutService;
19
+ sitePathService?: GraphQLSitePathService;
20
+ };
5
21
  };
@@ -6,6 +6,7 @@ import { HTMLLink, FetchOptions, StaticPath, RetryStrategy } from '../models';
6
6
  import { PersonalizedRewriteData } from '../personalize/utils';
7
7
  import { ErrorPages, SiteInfo, SiteResolver, GraphQLErrorPagesService, GraphQLSitePathService, GraphQLSitemapXmlService } from '../site';
8
8
  import { SitecoreClientInit } from './models';
9
+ import { GraphQLRobotsService } from '../site/graphql-robots-service';
9
10
  /**
10
11
  * Represent a Page model returned from Edge endpoint
11
12
  */
@@ -39,6 +40,15 @@ export type SitemapXmlOptions = {
39
40
  /** The site name to resolve the sitemap for */
40
41
  siteName?: string;
41
42
  };
43
+ /**
44
+ * Options for fetching robots.txt content.
45
+ */
46
+ export type RobotsOptions = {
47
+ /**
48
+ * The name of the site for which to fetch robots.txt content.
49
+ */
50
+ siteName: string;
51
+ };
42
52
  /**
43
53
  * Contract for the Sitecore Client implementations
44
54
  */
@@ -53,33 +63,34 @@ export interface BaseSitecoreClient {
53
63
  * Retrieves page layoutData and returns page details like language, layoutData and site info for current request
54
64
  * @param {string} path current request path
55
65
  * @param {PageOptions} pageOptions additional overrides like language, site name and personalization variants
56
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
66
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
57
67
  * @returns {Page | null} page details when page layout is found and null when not
58
68
  */
59
69
  getPage(path: string | string[], pageOptions?: PageOptions, fetchOptions?: FetchOptions): Promise<Page | null>;
60
70
  /**
61
- * Get dictionary data for a given site and locale.
62
- * Can retrieve dictionary phrases for default site and language when page options not provided
63
- * @param {RouteOptions} [routeOptions] language and site to load dictionary data for
64
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
71
+ * Retrieves the robots.txt content for a given site name.
72
+ * @param {string} siteName - The name of the site for which to fetch robots.txt content.
73
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
74
+ * @returns {Promise<string>} A promise that resolves to the robots.txt content.
65
75
  */
76
+ getRobots(siteName: string, fetchOptions?: FetchOptions): Promise<string | null>;
66
77
  getDictionary(routeOptions?: Partial<RouteOptions>, fetchOptions?: FetchOptions): Promise<DictionaryPhrases>;
67
78
  /**
68
79
  * Get error pages configured by SXA for a given site and locale
69
80
  * @param {RouteOptions} [routeOptions] language and site to load error pages for
70
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
81
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
71
82
  */
72
83
  getErrorPages(routeOptions?: RouteOptions, fetchOptions?: FetchOptions): Promise<ErrorPages | null>;
73
84
  /**
74
85
  * Get preview layout details based on details from EditingPreviewData input
75
86
  * @param {EditingPreviewData | undefined} previewData preview details like route, site, language etc used to retrieve preview page and layout
76
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
87
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
77
88
  */
78
89
  getPreview(previewData: EditingPreviewData | undefined, fetchOptions?: FetchOptions): Promise<Page | null>;
79
90
  /**
80
91
  * Get route paths for all pages in the site. Can be used for static site generation.
81
92
  * @param {string[]} [languages] languages to fetch routes in
82
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
93
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
83
94
  */
84
95
  getPagePaths(languages?: string[], fetchOptions?: FetchOptions): Promise<StaticPath[]>;
85
96
  /**
@@ -97,9 +108,17 @@ export interface BaseSitecoreClient {
97
108
  /**
98
109
  * Retrieves sitemap XML content - either a specific sitemap or the index of all sitemaps.
99
110
  * @param { SitemapRequestConfig} reqOptions - Configuration for sitemap retrieval
111
+ * @param {FetchOptions} [fetchOptions] - Additional fetchOptions Additional fetch options to override GraphQL requests
100
112
  * @returns {Promise<string>} Promise resolving to the sitemap XML content as string
101
113
  */
102
- getSiteMap(reqOptions: SitemapXmlOptions): Promise<string>;
114
+ getSiteMap(reqOptions: SitemapXmlOptions, fetchOptions?: FetchOptions): Promise<string>;
115
+ /**
116
+ * Retrieves the robots.txt content for a given site name.
117
+ * @param {string} siteName - The name of the site for which to fetch robots.txt content.
118
+ * @param {FetchOptions} fetchOptions Additional fetch options to override GraphQL requests
119
+ * @returns {Promise<string>} A promise that resolves to the robots.txt content.
120
+ */
121
+ getRobots(siteName: string, fetchOptions?: FetchOptions): Promise<string | null>;
103
122
  }
104
123
  export interface BaseServiceOptions {
105
124
  defaultSite: string;
@@ -144,7 +163,7 @@ export declare class SitecoreClient implements BaseSitecoreClient {
144
163
  * Get page details for a route, with layout and other details
145
164
  * @param {string} path route path
146
165
  * @param {PageOptions} [pageOptions] site, language and personalization variant details for route
147
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
166
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
148
167
  * @returns {Page | null} page details
149
168
  */
150
169
  getPage(path: string | string[], pageOptions?: PageOptions, fetchOptions?: FetchOptions): Promise<Page | null>;
@@ -163,28 +182,28 @@ export declare class SitecoreClient implements BaseSitecoreClient {
163
182
  /**
164
183
  * Retrieves dictionary phrases for a given site and locale.
165
184
  * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
166
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
185
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
167
186
  * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
168
187
  */
169
188
  getDictionary(routeOptions?: Partial<RouteOptions>, fetchOptions?: FetchOptions): Promise<DictionaryPhrases>;
170
189
  /**
171
190
  * Retrieves error pages for a given site and locale.
172
191
  * @param {RouteOptions} routeOptions - Route options containing language and site name to load error pages
173
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
192
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
174
193
  * @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
175
194
  */
176
195
  getErrorPages(routeOptions?: RouteOptions, fetchOptions?: FetchOptions): Promise<ErrorPages | null>;
177
196
  /**
178
197
  * Retrieves preview page and layout details
179
198
  * @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
180
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
199
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
181
200
  * @returns {Page} preview page details
182
201
  */
183
202
  getPreview(previewData: EditingPreviewData | undefined, fetchOptions?: FetchOptions): Promise<Page | null>;
184
203
  /**
185
204
  * Get design library page details for Design Library mode of your app
186
205
  * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
187
- * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
206
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
188
207
  * @returns {Page} preview page for Design Library
189
208
  */
190
209
  getDesignLibraryData(designLibData: DesignLibraryRenderPreviewData, fetchOptions?: FetchOptions): Promise<Page>;
@@ -203,18 +222,27 @@ export declare class SitecoreClient implements BaseSitecoreClient {
203
222
  * @throws {Error} Throws 'REDIRECT_404' if requested sitemap is not found
204
223
  */
205
224
  getSiteMap(reqOptions: SitemapXmlOptions, fetchOptions?: FetchOptions): Promise<string>;
225
+ /**
226
+ * Retrieves the robots.txt content for a given site name.
227
+ * @param {string} siteName - The name of the site to retrieve the robots.txt for.
228
+ * @param {FetchOptions} [fetchOptions] - Optional fetch options.
229
+ * @returns {Promise<string | null>} A promise that resolves to the robots.txt content,
230
+ * or null if no content is found.
231
+ */
232
+ getRobots(siteName: string, fetchOptions?: FetchOptions): Promise<string | null>;
206
233
  /**
207
234
  * Factory methods for creating dependencies
208
235
  * Subclasses can override these to provide custom implementations.
209
236
  */
210
237
  protected getGraphqlSitemapXMLService(siteName: string): GraphQLSitemapXmlService;
238
+ protected getRobotsService(siteName: string): GraphQLRobotsService;
211
239
  protected getBaseServiceOptions(): BaseServiceOptions;
212
- protected getClientFactory(): GraphQLRequestClientFactory;
213
- protected getSiteResolver(): SiteResolver;
214
- protected getLayoutService(baseOptions: BaseServiceOptions): GraphQLLayoutService;
215
- protected getDictionaryService(baseOptions: BaseServiceOptions): GraphQLDictionaryService;
216
- protected getEditingService(): GraphQLEditingService;
217
- protected getErrorPagesService(): GraphQLErrorPagesService;
218
- protected getComponentService(): RestComponentLayoutService;
219
- protected getSitePathService(): GraphQLSitePathService;
240
+ private getClientFactory;
241
+ private getSiteResolver;
242
+ private getLayoutService;
243
+ private getDictionaryService;
244
+ private getEditingService;
245
+ private getErrorPagesService;
246
+ private getComponentService;
247
+ private getSitePathService;
220
248
  }
@@ -1,3 +1,3 @@
1
- export { SitecoreConfig, SitecoreConfigInput, SitecoreCliConfig, SitecoreCliConfigInput, ScaffoldTemplate, ComponentTemplateType, } from './models';
1
+ export { SitecoreConfig, SitecoreConfigInput, SitecoreCliConfig, SitecoreCliConfigInput, ScaffoldTemplate, ComponentTemplateType, DeepRequired, } from './models';
2
2
  export { defineConfig } from './define-config';
3
3
  export { defineCliConfig } from './define-cli-config';
@@ -13,7 +13,7 @@ export type SitecoreConfigInput = {
13
13
  * API settings required to connect to Sitecore.
14
14
  * Both edge and local set can be specified as JSS app will use API Key for component library
15
15
  */
16
- api: {
16
+ api?: {
17
17
  /**
18
18
  * Edge endpoint credentials for Sitecore connection. Will be used to connect to SaaS XMCloud instance
19
19
  */
@@ -55,7 +55,7 @@ export type SitecoreConfigInput = {
55
55
  * The default and fallback locale for your site.
56
56
  * Ensure it aligns with the framework-specific settings used in your application.
57
57
  */
58
- defaultLanguage: string;
58
+ defaultLanguage?: string;
59
59
  /**
60
60
  * Your default site name. When using the multisite feature this variable defines the fallback site.
61
61
  * @default empty string
@@ -63,6 +63,7 @@ export type SitecoreConfigInput = {
63
63
  defaultSite?: string;
64
64
  /**
65
65
  * Editing secret required to support Sitecore editing and preview functionality.
66
+ * by default set by the JSS_EDITING_SECRET environment variable
66
67
  */
67
68
  editingSecret?: string;
68
69
  /**
@@ -132,10 +133,14 @@ export type SitecoreConfigInput = {
132
133
  enabled?: boolean;
133
134
  /**
134
135
  * Configuration for your Sitecore Experience Edge endpoint
136
+ * by default set by the PERSONALIZE_MIDDLEWARE_EDGE_TIMEOUT environment variable
137
+ * if not set, will use the default value of 400ms
135
138
  */
136
139
  edgeTimeout?: number;
137
140
  /**
138
141
  * Configuration for your Sitecore CDP endpoint
142
+ * by default set by the PERSONALIZE_MIDDLEWARE_CDP_TIMEOUT environment variable
143
+ * if not set, will use the default value of 400ms
139
144
  */
140
145
  cdpTimeout?: number;
141
146
  /**
@@ -45,14 +45,12 @@ export declare class ContentClient {
45
45
  get<T>(query: string | DocumentNode, variables?: Record<string, unknown>, options?: FetchOptions): Promise<T>;
46
46
  /**
47
47
  * Retrieves the locale information for a given locale ID.
48
- *
49
- * @param id - The unique identifier of the locale item.
48
+ * @param {string} id - The unique identifier of the locale item.
50
49
  * @returns A promise that resolves to the locale information associated with the specified locale ID.
51
50
  */
52
51
  getLocale(id: string): Promise<import("./locales").Locale | null>;
53
52
  /**
54
53
  * Retrieves all available locales from the content service.
55
- *
56
54
  * @returns A promise that resolves to an array of locales.
57
55
  */
58
56
  getLocales(): Promise<import("./locales").Locale[]>;
@@ -1,4 +1,4 @@
1
- import { GraphQLClient } from '../client';
1
+ import { FetchOptions, GraphQLClient } from '../client';
2
2
  import { GraphQLRequestClientFactory } from '../graphql-request-client';
3
3
  export type GraphQLRobotsServiceConfig = {
4
4
  /**
@@ -38,7 +38,7 @@ export declare class GraphQLRobotsService {
38
38
  * @returns text of robots.txt
39
39
  * @throws {Error} if the siteName is empty.
40
40
  */
41
- fetchRobots(): Promise<string>;
41
+ fetchRobots(fetchOptions?: FetchOptions): Promise<string>;
42
42
  /**
43
43
  * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
44
44
  * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you