@sitecore-content-sdk/core 0.1.0-beta.19 → 0.1.0-beta.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.
@@ -28,8 +28,6 @@ class SitecoreClient {
28
28
  this.errorPagesService = this.getErrorPagesService();
29
29
  this.componentService = this.getComponentService();
30
30
  this.sitePathService = this.getSitePathService();
31
- this.siteResolver = new site_1.SiteResolver(initOptions.sites);
32
- this.editingService = new editing_1.GraphQLEditingService({ clientFactory: this.clientFactory });
33
31
  }
34
32
  /**
35
33
  * Resolve site by hostname
@@ -115,13 +113,13 @@ class SitecoreClient {
115
113
  }
116
114
  /**
117
115
  * Retrieves dictionary phrases for a given site and locale.
118
- * @param {PageOptions} pageOptions - Route options containing language and site name to load dictionary for
116
+ * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
119
117
  * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
120
118
  * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
121
119
  */
122
- async getDictionary(pageOptions, fetchOptions) {
123
- const locale = (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.locale) || this.initOptions.defaultLanguage;
124
- const site = (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.site) || this.initOptions.defaultSite;
120
+ async getDictionary(routeOptions, fetchOptions) {
121
+ const locale = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.locale) || this.initOptions.defaultLanguage;
122
+ const site = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.site) || this.initOptions.defaultSite;
125
123
  return await this.dictionaryService.fetchDictionaryData(locale, site, fetchOptions);
126
124
  }
127
125
  /**
@@ -161,7 +159,6 @@ class SitecoreClient {
161
159
  const page = {
162
160
  locale: language,
163
161
  layout: data.layoutData,
164
- headLinks: this.getHeadLinks(data.layoutData),
165
162
  dictionary: data.dictionary,
166
163
  site: data.layoutData.sitecore.context.site,
167
164
  };
@@ -199,7 +196,6 @@ class SitecoreClient {
199
196
  const page = {
200
197
  locale: componentLibData.language,
201
198
  layout: componentData,
202
- headLinks: this.getHeadLinks(componentData),
203
199
  dictionary: dictionaryData,
204
200
  };
205
201
  return page;
@@ -5,7 +5,7 @@ const graphql_request_client_1 = require("../graphql-request-client");
5
5
  const graphql_edge_proxy_1 = require("./graphql-edge-proxy");
6
6
  /**
7
7
  * Creates a new GraphQLRequestClientFactory instance
8
- * @param {FetchOptions} options jss config
8
+ * @param {GraphQLClientOptions} options jss config
9
9
  * @returns GraphQLRequestClientFactory instance
10
10
  */
11
11
  const createGraphQLClientFactory = (options) => {
@@ -73,7 +73,8 @@ class GraphQLRequestClient {
73
73
  timeout: this.timeout,
74
74
  });
75
75
  const startTimestamp = Date.now();
76
- const fetchWithOptionalTimeout = [this.client.request(query, variables, options === null || options === void 0 ? void 0 : options.headers)];
76
+ const headers = Object.assign(Object.assign({}, this.headers), options === null || options === void 0 ? void 0 : options.headers);
77
+ const fetchWithOptionalTimeout = [this.client.request(query, variables, headers)];
77
78
  if (this.timeout) {
78
79
  this.abortTimeout = new timeout_promise_1.default(this.timeout);
79
80
  fetchWithOptionalTimeout.push(this.abortTimeout.start);
@@ -25,8 +25,6 @@ export class SitecoreClient {
25
25
  this.errorPagesService = this.getErrorPagesService();
26
26
  this.componentService = this.getComponentService();
27
27
  this.sitePathService = this.getSitePathService();
28
- this.siteResolver = new SiteResolver(initOptions.sites);
29
- this.editingService = new GraphQLEditingService({ clientFactory: this.clientFactory });
30
28
  }
31
29
  /**
32
30
  * Resolve site by hostname
@@ -112,13 +110,13 @@ export class SitecoreClient {
112
110
  }
113
111
  /**
114
112
  * Retrieves dictionary phrases for a given site and locale.
115
- * @param {PageOptions} pageOptions - Route options containing language and site name to load dictionary for
113
+ * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
116
114
  * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
117
115
  * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
118
116
  */
119
- async getDictionary(pageOptions, fetchOptions) {
120
- const locale = (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.locale) || this.initOptions.defaultLanguage;
121
- const site = (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.site) || this.initOptions.defaultSite;
117
+ async getDictionary(routeOptions, fetchOptions) {
118
+ const locale = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.locale) || this.initOptions.defaultLanguage;
119
+ const site = (routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.site) || this.initOptions.defaultSite;
122
120
  return await this.dictionaryService.fetchDictionaryData(locale, site, fetchOptions);
123
121
  }
124
122
  /**
@@ -158,7 +156,6 @@ export class SitecoreClient {
158
156
  const page = {
159
157
  locale: language,
160
158
  layout: data.layoutData,
161
- headLinks: this.getHeadLinks(data.layoutData),
162
159
  dictionary: data.dictionary,
163
160
  site: data.layoutData.sitecore.context.site,
164
161
  };
@@ -196,7 +193,6 @@ export class SitecoreClient {
196
193
  const page = {
197
194
  locale: componentLibData.language,
198
195
  layout: componentData,
199
- headLinks: this.getHeadLinks(componentData),
200
196
  dictionary: dictionaryData,
201
197
  };
202
198
  return page;
@@ -2,7 +2,7 @@ import { GraphQLRequestClient } from '../graphql-request-client';
2
2
  import { getEdgeProxyContentUrl } from './graphql-edge-proxy';
3
3
  /**
4
4
  * Creates a new GraphQLRequestClientFactory instance
5
- * @param {FetchOptions} options jss config
5
+ * @param {GraphQLClientOptions} options jss config
6
6
  * @returns GraphQLRequestClientFactory instance
7
7
  */
8
8
  export const createGraphQLClientFactory = (options) => {
@@ -67,7 +67,8 @@ export class GraphQLRequestClient {
67
67
  timeout: this.timeout,
68
68
  });
69
69
  const startTimestamp = Date.now();
70
- const fetchWithOptionalTimeout = [this.client.request(query, variables, options === null || options === void 0 ? void 0 : options.headers)];
70
+ const headers = Object.assign(Object.assign({}, this.headers), options === null || options === void 0 ? void 0 : options.headers);
71
+ const fetchWithOptionalTimeout = [this.client.request(query, variables, headers)];
71
72
  if (this.timeout) {
72
73
  this.abortTimeout = new TimeoutPromise(this.timeout);
73
74
  fetchWithOptionalTimeout.push(this.abortTimeout.start);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "0.1.0-beta.19",
3
+ "version": "0.1.0-beta.20",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -15,7 +15,7 @@
15
15
  "test": "mocha \"./src/**/*.test.ts\"",
16
16
  "prepublishOnly": "npm run build",
17
17
  "coverage": "nyc npm test",
18
- "generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/core --entryPoints src/index.ts --entryPoints src/config/index.ts --entryPoints src/graphql/index.ts --entryPoints src/i18n/index.ts --entryPoints src/layout/index.ts --entryPoints src/media/index.ts --entryPoints src/personalize/index.ts --entryPoints src/site/index.ts --entryPoints src/tracking/index.ts --entryPoints src/utils/index.ts --entryPoints src/editing/index.ts --entryPoints src/tools/index.ts --githubPages false"
18
+ "generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/core --entryPoints src/index.ts --entryPoints src/config/index.ts --entryPoints src/client/index.ts --entryPoints src/i18n/index.ts --entryPoints src/layout/index.ts --entryPoints src/media/index.ts --entryPoints src/personalize/index.ts --entryPoints src/site/index.ts --entryPoints src/tracking/index.ts --entryPoints src/utils/index.ts --entryPoints src/editing/index.ts --entryPoints src/tools/index.ts --githubPages false"
19
19
  },
20
20
  "engines": {
21
21
  "node": ">=22"
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "description": "",
69
69
  "types": "types/index.d.ts",
70
- "gitHead": "a7c2c7af7497eb791b942e04f36a36feb06c9ea0",
70
+ "gitHead": "2e40659cd4f0858c509c8df228bf93f5b6d5c110",
71
71
  "files": [
72
72
  "dist",
73
73
  "types",
@@ -30,12 +30,57 @@ export type PageOptions = Partial<RouteOptions> & {
30
30
  * Contract for the Sitecore Client implementations
31
31
  */
32
32
  export interface BaseSitecoreClient {
33
+ /**
34
+ * Resolves site by request hostaname
35
+ * @param {string} hostname incoming request host name
36
+ * @returns {SiteInfo} site details including name, language and hostname
37
+ */
33
38
  resolveSite(hostname: string): SiteInfo;
39
+ /**
40
+ * Retrieves page layoutData and returns page details like language, layoutData and site info for current request
41
+ * @param {string} path current request path
42
+ * @param {PageOptions} pageOptions additional overrides like language, site name and personalization variants
43
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
44
+ * @returns {Page | null} page details when page layout is found and null when not
45
+ */
34
46
  getPage(path: string | string[], pageOptions?: PageOptions, fetchOptions?: FetchOptions): Promise<Page | null>;
35
- getDictionary(pageOptions?: PageOptions, fetchOptions?: FetchOptions): Promise<DictionaryPhrases>;
47
+ /**
48
+ * Get dictionary data for a given site and locale.
49
+ * Can retrieve dictionary phrases for default site and language when page options not provided
50
+ * @param {RouteOptions} [routeOptions] language and site to load dictionary data for
51
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
52
+ */
53
+ getDictionary(routeOptions?: Partial<RouteOptions>, fetchOptions?: FetchOptions): Promise<DictionaryPhrases>;
54
+ /**
55
+ * Get error pages configured by SXA for a given site and locale
56
+ * @param {RouteOptions} [routeOptions] language and site to load error pages for
57
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
58
+ */
36
59
  getErrorPages(routeOptions?: RouteOptions, fetchOptions?: FetchOptions): Promise<ErrorPages | null>;
60
+ /**
61
+ * Get preview layout details based on details from EditingPreviewData input
62
+ * @param {EditingPreviewData | undefined} previewData preview details like route, site, language etc used to retrieve preview page and layout
63
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
64
+ */
37
65
  getPreview(previewData: EditingPreviewData | undefined, fetchOptions?: FetchOptions): Promise<Page | null>;
66
+ /**
67
+ * Get route paths for all pages in the site. Can be used for static site generation.
68
+ * @param {string[]} [languages] languages to fetch routes in
69
+ * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
70
+ */
38
71
  getPagePaths(languages?: string[], fetchOptions?: FetchOptions): Promise<StaticPath[]>;
72
+ /**
73
+ * Retrieves the links to be loaded in app's <head> element for each page.
74
+ * @param {LayoutServiceData} layoutData - The layout data containing styles and themes.
75
+ * @param {object} [options] - Optional configuration for enabling styles and themes.
76
+ * @param {boolean} [options.enableStyles] - Whether to include content styles.
77
+ * @param {boolean} [options.enableThemes] - Whether to include theme styles.
78
+ * @returns {HTMLLink[]} An array of `<link>` elements.
79
+ */
80
+ getHeadLinks(layoutData: LayoutServiceData, options: {
81
+ enableStyles?: boolean;
82
+ enableThemes?: boolean;
83
+ }): HTMLLink[];
39
84
  }
40
85
  export interface BaseServiceOptions {
41
86
  defaultSite: string;
@@ -98,11 +143,11 @@ export declare class SitecoreClient implements BaseSitecoreClient {
98
143
  }): HTMLLink[];
99
144
  /**
100
145
  * Retrieves dictionary phrases for a given site and locale.
101
- * @param {PageOptions} pageOptions - Route options containing language and site name to load dictionary for
146
+ * @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
102
147
  * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
103
148
  * @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
104
149
  */
105
- getDictionary(pageOptions?: PageOptions, fetchOptions?: FetchOptions): Promise<DictionaryPhrases>;
150
+ getDictionary(routeOptions?: Partial<RouteOptions>, fetchOptions?: FetchOptions): Promise<DictionaryPhrases>;
106
151
  /**
107
152
  * Retrieves error pages for a given site and locale.
108
153
  * @param {RouteOptions} routeOptions - Route options containing language and site name to load error pages
@@ -3,7 +3,7 @@ import { FetchOptions } from '../models';
3
3
  export type GraphQLClientOptions = Pick<SitecoreConfigInput, 'api'> & FetchOptions;
4
4
  /**
5
5
  * Creates a new GraphQLRequestClientFactory instance
6
- * @param {FetchOptions} options jss config
6
+ * @param {GraphQLClientOptions} options jss config
7
7
  * @returns GraphQLRequestClientFactory instance
8
8
  */
9
9
  export declare const createGraphQLClientFactory: (options: GraphQLClientOptions) => import("../graphql-request-client").GraphQLRequestClientFactory;
package/types/models.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Debugger } from 'debug';
2
- import { SitecoreConfigInput } from './config';
3
2
  /**
4
3
  * Html <link> tag data model
5
4
  */
@@ -61,7 +60,7 @@ export interface PageInfo {
61
60
  */
62
61
  hasNext: boolean;
63
62
  }
64
- export type FetchOptions = Partial<Pick<SitecoreConfigInput, 'api'>> & {
63
+ export type FetchOptions = {
65
64
  /**
66
65
  * Number of retries GraphQL client will attempt on request error
67
66
  */