@sitecore-content-sdk/core 0.1.0-beta.34 → 0.1.0-beta.36
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.
- package/dist/cjs/client/sitecore-client.js +12 -14
- package/dist/cjs/config/define-config.js +0 -3
- package/dist/cjs/editing/design-library.js +10 -0
- package/dist/cjs/editing/index.js +2 -1
- package/dist/cjs/site/graphql-sitemap-xml-service.js +2 -1
- package/dist/esm/client/sitecore-client.js +12 -14
- package/dist/esm/config/define-config.js +0 -3
- package/dist/esm/editing/design-library.js +9 -0
- package/dist/esm/editing/index.js +1 -1
- package/dist/esm/site/graphql-sitemap-xml-service.js +2 -1
- package/package.json +2 -2
- package/types/client/sitecore-client.d.ts +3 -2
- package/types/config/models.d.ts +1 -0
- package/types/editing/design-library.d.ts +6 -0
- package/types/editing/index.d.ts +1 -1
|
@@ -22,7 +22,6 @@ class SitecoreClient {
|
|
|
22
22
|
this.initOptions = initOptions;
|
|
23
23
|
this.clientFactory = this.getClientFactory();
|
|
24
24
|
this.siteResolver = this.getSiteResolver();
|
|
25
|
-
this.sitemapXmlService = this.getGraphqlSitemapXMLService();
|
|
26
25
|
const baseServiceOptions = this.getBaseServiceOptions();
|
|
27
26
|
this.layoutService = this.getLayoutService(baseServiceOptions);
|
|
28
27
|
this.dictionaryService = this.getDictionaryService(baseServiceOptions);
|
|
@@ -219,26 +218,25 @@ class SitecoreClient {
|
|
|
219
218
|
* @throws {Error} Throws 'REDIRECT_404' if requested sitemap is not found
|
|
220
219
|
*/
|
|
221
220
|
async getSiteMap(reqOptions, fetchOptions) {
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
221
|
+
const { reqHost, reqProtocol, id, siteName } = reqOptions;
|
|
222
|
+
// create sitemap graphql service
|
|
223
|
+
const sitemapXmlService = this.getGraphqlSitemapXMLService(siteName || this.initOptions.defaultSite);
|
|
224
|
+
// The id is present if url has sitemap-{n}.xml type.
|
|
225
|
+
// The id can be null if it's index sitemap.xml request
|
|
226
|
+
const sitemapPath = await sitemapXmlService.getSitemap(id);
|
|
227
|
+
// regular sitemap
|
|
226
228
|
if (sitemapPath) {
|
|
227
|
-
const isAbsoluteUrl = sitemapPath.match(ABSOLUTE_URL_REGEXP);
|
|
228
|
-
const sitemapUrl = isAbsoluteUrl
|
|
229
|
-
? sitemapPath
|
|
230
|
-
: `${this.initOptions.api.local.apiHost}${sitemapPath}`;
|
|
231
229
|
try {
|
|
232
230
|
const fetcher = new native_fetcher_1.NativeDataFetcher();
|
|
233
|
-
const xmlResponse = await fetcher.fetch(
|
|
231
|
+
const xmlResponse = await fetcher.fetch(sitemapPath);
|
|
234
232
|
return xmlResponse.data;
|
|
235
233
|
}
|
|
236
234
|
catch (error) {
|
|
237
235
|
throw new Error('REDIRECT_404');
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
|
-
//
|
|
241
|
-
const sitemaps = await
|
|
238
|
+
// index /sitemap.xml that includes links to all sitemaps
|
|
239
|
+
const sitemaps = await sitemapXmlService.fetchSitemaps(fetchOptions);
|
|
242
240
|
if (!sitemaps.length) {
|
|
243
241
|
throw new Error('REDIRECT_404');
|
|
244
242
|
}
|
|
@@ -258,10 +256,10 @@ class SitecoreClient {
|
|
|
258
256
|
* Factory methods for creating dependencies
|
|
259
257
|
* Subclasses can override these to provide custom implementations.
|
|
260
258
|
*/
|
|
261
|
-
getGraphqlSitemapXMLService() {
|
|
259
|
+
getGraphqlSitemapXMLService(siteName) {
|
|
262
260
|
return new site_1.GraphQLSitemapXmlService({
|
|
263
261
|
clientFactory: this.clientFactory,
|
|
264
|
-
siteName
|
|
262
|
+
siteName,
|
|
265
263
|
});
|
|
266
264
|
}
|
|
267
265
|
getBaseServiceOptions() {
|
|
@@ -90,9 +90,6 @@ const validateConfig = (config) => {
|
|
|
90
90
|
throw new Error('Configuration error: either context ID or API key and host must be specified in sitecore.config');
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
if (!config.defaultSite) {
|
|
94
|
-
throw new Error('Configuration error: defaultSite value should be defined in sitecore.config');
|
|
95
|
-
}
|
|
96
93
|
};
|
|
97
94
|
/**
|
|
98
95
|
* Accepts a SitecoreConfigInput object and returns full sitecore configuration
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateComponentHandler = exports.addComponentUpdateHandler = exports.DesignLibraryStatus = exports.DESIGN_LIBRARY_STATUS_EVENT_NAME = void 0;
|
|
4
4
|
exports.getDesignLibraryStatusEvent = getDesignLibraryStatusEvent;
|
|
5
|
+
exports.getDesignLibraryScriptLink = getDesignLibraryScriptLink;
|
|
6
|
+
const constants_1 = require("../constants");
|
|
5
7
|
/**
|
|
6
8
|
* Event to be sent when report status to design library
|
|
7
9
|
*/
|
|
@@ -102,3 +104,11 @@ function getDesignLibraryStatusEvent(status, uid) {
|
|
|
102
104
|
},
|
|
103
105
|
};
|
|
104
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Generates the URL for the design library script link.
|
|
109
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
110
|
+
* @returns The full URL to the design library script.
|
|
111
|
+
*/
|
|
112
|
+
function getDesignLibraryScriptLink(sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) {
|
|
113
|
+
return `${sitecoreEdgeUrl}/v1/files/designlibrary/lib/rh-lib-script.js`;
|
|
114
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDesignLibraryStatusEvent = exports.DesignLibraryStatus = exports.addComponentUpdateHandler = exports.MetadataKind = exports.LayoutKind = exports.RestComponentLayoutService = exports.PAGES_EDITING_MARKER = exports.QUERY_PARAM_EDITING_SECRET = exports.EDITING_ALLOWED_ORIGINS = exports.getJssPagesClientData = exports.resetEditorChromes = exports.isEditorActive = exports.PagesEditor = exports.DEFAULT_PLACEHOLDER_UID = exports.GraphQLEditingService = void 0;
|
|
3
|
+
exports.getDesignLibraryScriptLink = exports.getDesignLibraryStatusEvent = exports.DesignLibraryStatus = exports.addComponentUpdateHandler = exports.MetadataKind = exports.LayoutKind = exports.RestComponentLayoutService = exports.PAGES_EDITING_MARKER = exports.QUERY_PARAM_EDITING_SECRET = exports.EDITING_ALLOWED_ORIGINS = exports.getJssPagesClientData = exports.resetEditorChromes = exports.isEditorActive = exports.PagesEditor = exports.DEFAULT_PLACEHOLDER_UID = exports.GraphQLEditingService = void 0;
|
|
4
4
|
var graphql_editing_service_1 = require("./graphql-editing-service");
|
|
5
5
|
Object.defineProperty(exports, "GraphQLEditingService", { enumerable: true, get: function () { return graphql_editing_service_1.GraphQLEditingService; } });
|
|
6
6
|
var utils_1 = require("./utils");
|
|
@@ -21,3 +21,4 @@ var design_library_1 = require("./design-library");
|
|
|
21
21
|
Object.defineProperty(exports, "addComponentUpdateHandler", { enumerable: true, get: function () { return design_library_1.addComponentUpdateHandler; } });
|
|
22
22
|
Object.defineProperty(exports, "DesignLibraryStatus", { enumerable: true, get: function () { return design_library_1.DesignLibraryStatus; } });
|
|
23
23
|
Object.defineProperty(exports, "getDesignLibraryStatusEvent", { enumerable: true, get: function () { return design_library_1.getDesignLibraryStatusEvent; } });
|
|
24
|
+
Object.defineProperty(exports, "getDesignLibraryScriptLink", { enumerable: true, get: function () { return design_library_1.getDesignLibraryScriptLink; } });
|
|
@@ -59,7 +59,8 @@ class GraphQLSitemapXmlService {
|
|
|
59
59
|
* @returns {string | undefined} the sitemap file path or undefined if one doesn't exist
|
|
60
60
|
*/
|
|
61
61
|
async getSitemap(id) {
|
|
62
|
-
const
|
|
62
|
+
const normalizedId = (id === null || id === void 0 ? void 0 : id.startsWith('-')) ? id.slice(1) : id || '';
|
|
63
|
+
const searchSitemap = `${PREFIX_NAME_SITEMAP}${normalizedId ? `-${normalizedId}` : ''}.xml`;
|
|
63
64
|
const sitemaps = await this.fetchSitemaps();
|
|
64
65
|
return sitemaps.find((sitemap) => sitemap.includes(searchSitemap));
|
|
65
66
|
}
|
|
@@ -19,7 +19,6 @@ export class SitecoreClient {
|
|
|
19
19
|
this.initOptions = initOptions;
|
|
20
20
|
this.clientFactory = this.getClientFactory();
|
|
21
21
|
this.siteResolver = this.getSiteResolver();
|
|
22
|
-
this.sitemapXmlService = this.getGraphqlSitemapXMLService();
|
|
23
22
|
const baseServiceOptions = this.getBaseServiceOptions();
|
|
24
23
|
this.layoutService = this.getLayoutService(baseServiceOptions);
|
|
25
24
|
this.dictionaryService = this.getDictionaryService(baseServiceOptions);
|
|
@@ -216,26 +215,25 @@ export class SitecoreClient {
|
|
|
216
215
|
* @throws {Error} Throws 'REDIRECT_404' if requested sitemap is not found
|
|
217
216
|
*/
|
|
218
217
|
async getSiteMap(reqOptions, fetchOptions) {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
218
|
+
const { reqHost, reqProtocol, id, siteName } = reqOptions;
|
|
219
|
+
// create sitemap graphql service
|
|
220
|
+
const sitemapXmlService = this.getGraphqlSitemapXMLService(siteName || this.initOptions.defaultSite);
|
|
221
|
+
// The id is present if url has sitemap-{n}.xml type.
|
|
222
|
+
// The id can be null if it's index sitemap.xml request
|
|
223
|
+
const sitemapPath = await sitemapXmlService.getSitemap(id);
|
|
224
|
+
// regular sitemap
|
|
223
225
|
if (sitemapPath) {
|
|
224
|
-
const isAbsoluteUrl = sitemapPath.match(ABSOLUTE_URL_REGEXP);
|
|
225
|
-
const sitemapUrl = isAbsoluteUrl
|
|
226
|
-
? sitemapPath
|
|
227
|
-
: `${this.initOptions.api.local.apiHost}${sitemapPath}`;
|
|
228
226
|
try {
|
|
229
227
|
const fetcher = new NativeDataFetcher();
|
|
230
|
-
const xmlResponse = await fetcher.fetch(
|
|
228
|
+
const xmlResponse = await fetcher.fetch(sitemapPath);
|
|
231
229
|
return xmlResponse.data;
|
|
232
230
|
}
|
|
233
231
|
catch (error) {
|
|
234
232
|
throw new Error('REDIRECT_404');
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
|
-
//
|
|
238
|
-
const sitemaps = await
|
|
235
|
+
// index /sitemap.xml that includes links to all sitemaps
|
|
236
|
+
const sitemaps = await sitemapXmlService.fetchSitemaps(fetchOptions);
|
|
239
237
|
if (!sitemaps.length) {
|
|
240
238
|
throw new Error('REDIRECT_404');
|
|
241
239
|
}
|
|
@@ -255,10 +253,10 @@ export class SitecoreClient {
|
|
|
255
253
|
* Factory methods for creating dependencies
|
|
256
254
|
* Subclasses can override these to provide custom implementations.
|
|
257
255
|
*/
|
|
258
|
-
getGraphqlSitemapXMLService() {
|
|
256
|
+
getGraphqlSitemapXMLService(siteName) {
|
|
259
257
|
return new GraphQLSitemapXmlService({
|
|
260
258
|
clientFactory: this.clientFactory,
|
|
261
|
-
siteName
|
|
259
|
+
siteName,
|
|
262
260
|
});
|
|
263
261
|
}
|
|
264
262
|
getBaseServiceOptions() {
|
|
@@ -86,9 +86,6 @@ const validateConfig = (config) => {
|
|
|
86
86
|
throw new Error('Configuration error: either context ID or API key and host must be specified in sitecore.config');
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
if (!config.defaultSite) {
|
|
90
|
-
throw new Error('Configuration error: defaultSite value should be defined in sitecore.config');
|
|
91
|
-
}
|
|
92
89
|
};
|
|
93
90
|
/**
|
|
94
91
|
* Accepts a SitecoreConfigInput object and returns full sitecore configuration
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
|
|
1
2
|
/**
|
|
2
3
|
* Event to be sent when report status to design library
|
|
3
4
|
*/
|
|
@@ -96,3 +97,11 @@ export function getDesignLibraryStatusEvent(status, uid) {
|
|
|
96
97
|
},
|
|
97
98
|
};
|
|
98
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Generates the URL for the design library script link.
|
|
102
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
103
|
+
* @returns The full URL to the design library script.
|
|
104
|
+
*/
|
|
105
|
+
export function getDesignLibraryScriptLink(sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
|
|
106
|
+
return `${sitecoreEdgeUrl}/v1/files/designlibrary/lib/rh-lib-script.js`;
|
|
107
|
+
}
|
|
@@ -2,4 +2,4 @@ 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, } from './utils';
|
|
3
3
|
export { RestComponentLayoutService, } from './rest-component-layout-service';
|
|
4
4
|
export { LayoutKind, MetadataKind, } from './models';
|
|
5
|
-
export { addComponentUpdateHandler, DesignLibraryStatus, getDesignLibraryStatusEvent, } from './design-library';
|
|
5
|
+
export { addComponentUpdateHandler, DesignLibraryStatus, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, } from './design-library';
|
|
@@ -53,7 +53,8 @@ export class GraphQLSitemapXmlService {
|
|
|
53
53
|
* @returns {string | undefined} the sitemap file path or undefined if one doesn't exist
|
|
54
54
|
*/
|
|
55
55
|
async getSitemap(id) {
|
|
56
|
-
const
|
|
56
|
+
const normalizedId = (id === null || id === void 0 ? void 0 : id.startsWith('-')) ? id.slice(1) : id || '';
|
|
57
|
+
const searchSitemap = `${PREFIX_NAME_SITEMAP}${normalizedId ? `-${normalizedId}` : ''}.xml`;
|
|
57
58
|
const sitemaps = await this.fetchSitemaps();
|
|
58
59
|
return sitemaps.find((sitemap) => sitemap.includes(searchSitemap));
|
|
59
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/core",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.36",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"description": "",
|
|
79
79
|
"types": "types/index.d.ts",
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "1a28b6590a0f8ef4d9e897f057f47abb01976998",
|
|
81
81
|
"files": [
|
|
82
82
|
"dist",
|
|
83
83
|
"types",
|
|
@@ -36,6 +36,8 @@ export type SitemapXmlOptions = {
|
|
|
36
36
|
reqProtocol: string | string[];
|
|
37
37
|
/** Optional sitemap identifier when requesting a specific sitemap */
|
|
38
38
|
id?: string;
|
|
39
|
+
/** The site name to resolve the sitemap for */
|
|
40
|
+
siteName?: string;
|
|
39
41
|
};
|
|
40
42
|
/**
|
|
41
43
|
* Contract for the Sitecore Client implementations
|
|
@@ -121,7 +123,6 @@ export declare class SitecoreClient implements BaseSitecoreClient {
|
|
|
121
123
|
protected errorPagesService: GraphQLErrorPagesService;
|
|
122
124
|
protected componentService: RestComponentLayoutService;
|
|
123
125
|
protected sitePathService: GraphQLSitePathService;
|
|
124
|
-
protected sitemapXmlService: GraphQLSitemapXmlService;
|
|
125
126
|
/**
|
|
126
127
|
* Init SitecoreClient
|
|
127
128
|
* @param {SitecoreClientInit} initOptions initOptions for the client, containing site and Sitecore connection details
|
|
@@ -206,7 +207,7 @@ export declare class SitecoreClient implements BaseSitecoreClient {
|
|
|
206
207
|
* Factory methods for creating dependencies
|
|
207
208
|
* Subclasses can override these to provide custom implementations.
|
|
208
209
|
*/
|
|
209
|
-
protected getGraphqlSitemapXMLService(): GraphQLSitemapXmlService;
|
|
210
|
+
protected getGraphqlSitemapXMLService(siteName: string): GraphQLSitemapXmlService;
|
|
210
211
|
protected getBaseServiceOptions(): BaseServiceOptions;
|
|
211
212
|
protected getClientFactory(): GraphQLRequestClientFactory;
|
|
212
213
|
protected getSiteResolver(): SiteResolver;
|
package/types/config/models.d.ts
CHANGED
|
@@ -46,3 +46,9 @@ export declare const updateComponentHandler: (e: MessageEvent, rootComponent: Co
|
|
|
46
46
|
* @returns An object representing the DesignLibraryStatusEvent.
|
|
47
47
|
*/
|
|
48
48
|
export declare function getDesignLibraryStatusEvent(status: DesignLibraryStatus, uid: string): DesignLibraryStatusEvent;
|
|
49
|
+
/**
|
|
50
|
+
* Generates the URL for the design library script link.
|
|
51
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
52
|
+
* @returns The full URL to the design library script.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getDesignLibraryScriptLink(sitecoreEdgeUrl?: string): string;
|
package/types/editing/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChrome
|
|
|
3
3
|
export { RestComponentLayoutService, ComponentLayoutRequestParams, } from './rest-component-layout-service';
|
|
4
4
|
export { EditingRenderQueryParams, RenderComponentQueryParams } from './models';
|
|
5
5
|
export { LayoutKind, MetadataKind, EditingPreviewData, DesignLibraryRenderPreviewData, } from './models';
|
|
6
|
-
export { addComponentUpdateHandler, DesignLibraryStatus, DesignLibraryStatusEvent, getDesignLibraryStatusEvent, } from './design-library';
|
|
6
|
+
export { addComponentUpdateHandler, DesignLibraryStatus, DesignLibraryStatusEvent, getDesignLibraryStatusEvent, getDesignLibraryScriptLink, } from './design-library';
|