@sitecore-content-sdk/core 0.2.0-canary.3 → 0.2.0-canary.30
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/content.d.ts +1 -0
- package/content.js +1 -0
- package/dist/cjs/client/graphql-edge-proxy.js +3 -3
- package/dist/cjs/client/sitecore-client.js +25 -5
- package/dist/cjs/config/define-config.js +5 -5
- package/dist/cjs/constants.js +3 -1
- package/dist/cjs/content/content-client.js +87 -0
- package/dist/cjs/content/index.js +10 -0
- package/dist/cjs/content/locales.js +28 -0
- package/dist/cjs/content/utils.js +16 -0
- package/dist/cjs/debug.js +1 -0
- package/dist/cjs/editing/design-library.js +2 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/layout/content-styles.js +2 -1
- package/dist/cjs/layout/themes.js +2 -1
- package/dist/cjs/site/graphql-robots-service.js +2 -2
- package/dist/cjs/tools/auth/fetch-bearer-token.js +41 -0
- package/dist/cjs/tools/index.js +3 -1
- package/dist/cjs/utils/normalize-url.js +5 -0
- package/dist/cjs/utils/utils.js +5 -3
- package/dist/esm/client/graphql-edge-proxy.js +1 -1
- package/dist/esm/client/sitecore-client.js +25 -5
- package/dist/esm/config/define-config.js +5 -5
- package/dist/esm/constants.js +2 -0
- package/dist/esm/content/content-client.js +80 -0
- package/dist/esm/content/index.js +3 -0
- package/dist/esm/content/locales.js +25 -0
- package/dist/esm/content/utils.js +13 -0
- package/dist/esm/debug.js +1 -0
- package/dist/esm/editing/design-library.js +2 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/layout/content-styles.js +2 -1
- package/dist/esm/layout/themes.js +2 -1
- package/dist/esm/site/graphql-robots-service.js +2 -2
- package/dist/esm/tools/auth/fetch-bearer-token.js +34 -0
- package/dist/esm/tools/index.js +1 -0
- package/dist/esm/utils/normalize-url.js +1 -0
- package/dist/esm/utils/utils.js +5 -3
- package/package.json +18 -18
- package/types/client/sitecore-client.d.ts +43 -14
- package/types/config/index.d.ts +1 -1
- package/types/config/models.d.ts +7 -2
- package/types/constants.d.ts +2 -0
- package/types/content/content-client.d.ts +57 -0
- package/types/content/index.d.ts +3 -0
- package/types/content/locales.d.ts +32 -0
- package/types/content/utils.d.ts +15 -0
- package/types/debug.d.ts +1 -0
- package/types/index.d.ts +2 -0
- package/types/site/graphql-robots-service.d.ts +2 -2
- package/types/tools/auth/fetch-bearer-token.d.ts +13 -0
- package/types/tools/index.d.ts +1 -0
- package/types/utils/normalize-url.d.ts +1 -0
- package/form.d.ts +0 -1
- package/form.js +0 -1
package/content.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/content/index';
|
package/content.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/content/index');
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEdgeProxyFormsUrl = exports.getEdgeProxyContentUrl = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
|
-
const
|
|
5
|
+
const normalize_url_1 = require("../utils/normalize-url");
|
|
6
6
|
/**
|
|
7
7
|
* Generates a URL for accessing Sitecore Edge Platform Content using the provided endpoint and context ID.
|
|
8
8
|
* @param {string} sitecoreEdgeContextId - The unique context id.
|
|
9
9
|
* @param {string} [sitecoreEdgeUrl] - The base endpoint URL for the Edge Platform. Default is https://edge-platform.sitecorecloud.io
|
|
10
10
|
* @returns {string} The complete URL for accessing content through the Edge Platform.
|
|
11
11
|
*/
|
|
12
|
-
const getEdgeProxyContentUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => `${normalizeUrl(sitecoreEdgeUrl)}/v1/content/api/graphql/v1?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
12
|
+
const getEdgeProxyContentUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => `${(0, normalize_url_1.normalizeUrl)(sitecoreEdgeUrl)}/v1/content/api/graphql/v1?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
13
13
|
exports.getEdgeProxyContentUrl = getEdgeProxyContentUrl;
|
|
14
14
|
/**
|
|
15
15
|
* Generates a URL for accessing Sitecore Edge Platform Forms using the provided form ID and context ID.
|
|
@@ -18,5 +18,5 @@ exports.getEdgeProxyContentUrl = getEdgeProxyContentUrl;
|
|
|
18
18
|
* @param {string} [sitecoreEdgeUrl] - The base endpoint URL for the Edge Platform. Default is https://edge-platform.sitecorecloud.io
|
|
19
19
|
* @returns {string} The complete URL for accessing forms through the Edge Platform.
|
|
20
20
|
*/
|
|
21
|
-
const getEdgeProxyFormsUrl = (sitecoreEdgeContextId, formId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => `${normalizeUrl(sitecoreEdgeUrl)}/v1/forms/publisher/${formId}?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
21
|
+
const getEdgeProxyFormsUrl = (sitecoreEdgeContextId, formId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => `${(0, normalize_url_1.normalizeUrl)(sitecoreEdgeUrl)}/v1/forms/publisher/${formId}?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
22
22
|
exports.getEdgeProxyFormsUrl = getEdgeProxyFormsUrl;
|
|
@@ -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
|
|
@@ -59,7 +60,7 @@ class SitecoreClient {
|
|
|
59
60
|
* Get page details for a route, with layout and other details
|
|
60
61
|
* @param {string} path route path
|
|
61
62
|
* @param {PageOptions} [pageOptions] site, language and personalization variant details for route
|
|
62
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
63
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
63
64
|
* @returns {Page | null} page details
|
|
64
65
|
*/
|
|
65
66
|
async getPage(path, pageOptions, fetchOptions) {
|
|
@@ -115,7 +116,7 @@ class SitecoreClient {
|
|
|
115
116
|
/**
|
|
116
117
|
* Retrieves dictionary phrases for a given site and locale.
|
|
117
118
|
* @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
|
|
119
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
119
120
|
* @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
|
|
120
121
|
*/
|
|
121
122
|
async getDictionary(routeOptions, fetchOptions) {
|
|
@@ -126,7 +127,7 @@ class SitecoreClient {
|
|
|
126
127
|
/**
|
|
127
128
|
* Retrieves error pages for a given site and locale.
|
|
128
129
|
* @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
|
|
130
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
130
131
|
* @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
|
|
131
132
|
*/
|
|
132
133
|
async getErrorPages(routeOptions, fetchOptions) {
|
|
@@ -137,7 +138,7 @@ class SitecoreClient {
|
|
|
137
138
|
/**
|
|
138
139
|
* Retrieves preview page and layout details
|
|
139
140
|
* @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
|
|
140
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
141
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
141
142
|
* @returns {Page} preview page details
|
|
142
143
|
*/
|
|
143
144
|
async getPreview(previewData, fetchOptions) {
|
|
@@ -171,7 +172,7 @@ class SitecoreClient {
|
|
|
171
172
|
/**
|
|
172
173
|
* Get design library page details for Design Library mode of your app
|
|
173
174
|
* @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
|
|
174
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
175
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
175
176
|
* @returns {Page} preview page for Design Library
|
|
176
177
|
*/
|
|
177
178
|
async getDesignLibraryData(designLibData, fetchOptions) {
|
|
@@ -256,6 +257,19 @@ class SitecoreClient {
|
|
|
256
257
|
.join('')}
|
|
257
258
|
</sitemapindex>`;
|
|
258
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Retrieves the robots.txt content for a given site name.
|
|
262
|
+
*
|
|
263
|
+
* @param {string} siteName - The name of the site to retrieve the robots.txt for.
|
|
264
|
+
* @param {FetchOptions} [fetchOptions] - Optional fetch options.
|
|
265
|
+
* @returns {Promise<string | null>} A promise that resolves to the robots.txt content,
|
|
266
|
+
* or null if no content is found.
|
|
267
|
+
*/
|
|
268
|
+
async getRobots(siteName, fetchOptions) {
|
|
269
|
+
const robotsService = this.getRobotsService(siteName || this.initOptions.defaultSite);
|
|
270
|
+
const content = await robotsService.fetchRobots(fetchOptions);
|
|
271
|
+
return content || null;
|
|
272
|
+
}
|
|
259
273
|
/**
|
|
260
274
|
* Factory methods for creating dependencies
|
|
261
275
|
* Subclasses can override these to provide custom implementations.
|
|
@@ -266,6 +280,12 @@ class SitecoreClient {
|
|
|
266
280
|
siteName,
|
|
267
281
|
});
|
|
268
282
|
}
|
|
283
|
+
getRobotsService(siteName) {
|
|
284
|
+
return new graphql_robots_service_1.GraphQLRobotsService({
|
|
285
|
+
clientFactory: this.clientFactory,
|
|
286
|
+
siteName,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
269
289
|
getBaseServiceOptions() {
|
|
270
290
|
return {
|
|
271
291
|
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',
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HIDDEN_RENDERING_NAME = exports.SITECORE_EDGE_URL_DEFAULT = exports.siteNameError = exports.SitecoreTemplateId = void 0;
|
|
3
|
+
exports.DEFAULT_SITECORE_AUTH_AUDIENCE = exports.DEFAULT_SITECORE_AUTH_ENDPOINT = exports.HIDDEN_RENDERING_NAME = exports.SITECORE_EDGE_URL_DEFAULT = exports.siteNameError = exports.SitecoreTemplateId = void 0;
|
|
4
4
|
var SitecoreTemplateId;
|
|
5
5
|
(function (SitecoreTemplateId) {
|
|
6
6
|
// /sitecore/templates/Foundation/JavaScript Services/App
|
|
@@ -11,3 +11,5 @@ var SitecoreTemplateId;
|
|
|
11
11
|
exports.siteNameError = 'The siteName cannot be empty';
|
|
12
12
|
exports.SITECORE_EDGE_URL_DEFAULT = 'https://edge-platform.sitecorecloud.io';
|
|
13
13
|
exports.HIDDEN_RENDERING_NAME = 'Hidden Rendering';
|
|
14
|
+
exports.DEFAULT_SITECORE_AUTH_ENDPOINT = 'https://auth.sitecorecloud.io/oauth/token';
|
|
15
|
+
exports.DEFAULT_SITECORE_AUTH_AUDIENCE = 'https://api.sitecorecloud.io';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ContentClient = void 0;
|
|
7
|
+
const graphql_request_client_1 = require("../graphql-request-client");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
10
|
+
const locales_1 = require("./locales");
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a client for interacting with the Content API.
|
|
13
|
+
*/
|
|
14
|
+
class ContentClient {
|
|
15
|
+
constructor({ url, tenant, environment, preview = false, token }) {
|
|
16
|
+
this.endpoint = (0, utils_1.getContentUrl)({
|
|
17
|
+
environment,
|
|
18
|
+
preview,
|
|
19
|
+
tenant,
|
|
20
|
+
url,
|
|
21
|
+
});
|
|
22
|
+
this.graphqlClient = new graphql_request_client_1.GraphQLRequestClient(this.endpoint, {
|
|
23
|
+
headers: {
|
|
24
|
+
Authorization: `Bearer ${token}`,
|
|
25
|
+
},
|
|
26
|
+
debugger: debug_1.default.content,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Factory method for creating a ContentClient instance. This method allows you to create a client with the values populated from environment variables or provided as arguments.
|
|
31
|
+
* @param {Partial<ContentClientOptions>} [options] - client configuration options
|
|
32
|
+
* @param {string} [options.url] - Content base graphql endpoint url. If not provided, it will be read from the SITECORE_CS_URL environment variable. Otherwise, it defaults to https://cs-graphqlapi-staging.sitecore-staging.cloud.
|
|
33
|
+
* @param {string} [options.tenant] - Tenant name. If not provided, it will be read from the SITECORE_CS_TENANT environment variable
|
|
34
|
+
* @param {string} [options.environment] - Environment name. If not provided, it will be read from the SITECORE_CS_ENVIRONMENT environment variable. Otherwise, it defaults to 'main'
|
|
35
|
+
* @param {boolean} [options.preview] - Indicates if preview mode is enabled. If not provided, it will be read from the SITECORE_CS_PREVIEW environment variable. Otherwise, it defaults to false
|
|
36
|
+
* @param {string} [options.token] - Token for authentication. If not provided, it will be read from the SITECORE_CS_TOKEN environment variable.
|
|
37
|
+
* @returns {ContentClient} ContentClient instance
|
|
38
|
+
* @throws {Error} If tenant or token is not provided
|
|
39
|
+
*/
|
|
40
|
+
static createClient({ url, tenant, environment, preview, token, } = {}) {
|
|
41
|
+
const options = {
|
|
42
|
+
url: url || process.env.SITECORE_CS_URL,
|
|
43
|
+
tenant: tenant || process.env.SITECORE_CS_TENANT || '',
|
|
44
|
+
environment: environment || process.env.SITECORE_CS_ENVIRONMENT || 'main',
|
|
45
|
+
preview: preview || process.env.SITECORE_CS_PREVIEW === 'true',
|
|
46
|
+
token: token || process.env.SITECORE_CS_TOKEN || '',
|
|
47
|
+
};
|
|
48
|
+
if (!options.tenant) {
|
|
49
|
+
throw new Error('Tenant is required to be provided as an argument or as a SITECORE_CS_TENANT environment variable');
|
|
50
|
+
}
|
|
51
|
+
if (!options.token) {
|
|
52
|
+
throw new Error('Token is required to be provided as an argument or as a SITECORE_CS_TOKEN environment variable');
|
|
53
|
+
}
|
|
54
|
+
return new ContentClient(options);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Execute graphql request
|
|
58
|
+
* @param {string | DocumentNode} query graphql query
|
|
59
|
+
* @param {object} variables variables for the query
|
|
60
|
+
* @param {FetchOptions} options options for configuring the request
|
|
61
|
+
* @returns {T} response data
|
|
62
|
+
*/
|
|
63
|
+
async get(query, variables = {}, options = {}) {
|
|
64
|
+
debug_1.default.content('fetching content data');
|
|
65
|
+
return this.graphqlClient.request(query, variables, options);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves the locale information for a given locale ID.
|
|
69
|
+
* @param {string} id - The unique identifier of the locale item.
|
|
70
|
+
* @returns A promise that resolves to the locale information associated with the specified locale ID.
|
|
71
|
+
*/
|
|
72
|
+
async getLocale(id) {
|
|
73
|
+
debug_1.default.content('Getting locale for id: %s', id);
|
|
74
|
+
const response = await this.get(locales_1.GET_LOCALE_QUERY, { id });
|
|
75
|
+
return response.locale;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves all available locales from the content service.
|
|
79
|
+
* @returns A promise that resolves to an array of locales.
|
|
80
|
+
*/
|
|
81
|
+
async getLocales() {
|
|
82
|
+
debug_1.default.content('Getting all locales');
|
|
83
|
+
const response = await this.get(locales_1.GET_LOCALES_QUERY);
|
|
84
|
+
return response.manyLocale;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ContentClient = ContentClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContentUrl = exports.GET_LOCALES_QUERY = exports.GET_LOCALE_QUERY = exports.ContentClient = void 0;
|
|
4
|
+
var content_client_1 = require("./content-client");
|
|
5
|
+
Object.defineProperty(exports, "ContentClient", { enumerable: true, get: function () { return content_client_1.ContentClient; } });
|
|
6
|
+
var locales_1 = require("./locales");
|
|
7
|
+
Object.defineProperty(exports, "GET_LOCALE_QUERY", { enumerable: true, get: function () { return locales_1.GET_LOCALE_QUERY; } });
|
|
8
|
+
Object.defineProperty(exports, "GET_LOCALES_QUERY", { enumerable: true, get: function () { return locales_1.GET_LOCALES_QUERY; } });
|
|
9
|
+
var utils_1 = require("./utils");
|
|
10
|
+
Object.defineProperty(exports, "getContentUrl", { enumerable: true, get: function () { return utils_1.getContentUrl; } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET_LOCALES_QUERY = exports.GET_LOCALE_QUERY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* GraphQL query to retrieve a specific locale by its ID.
|
|
6
|
+
*
|
|
7
|
+
* Variables:
|
|
8
|
+
* - id: The ID of the locale to retrieve.
|
|
9
|
+
*/
|
|
10
|
+
exports.GET_LOCALE_QUERY = `
|
|
11
|
+
query GetLocaleById ($id: ID!) {
|
|
12
|
+
locale(id: $id) {
|
|
13
|
+
id
|
|
14
|
+
label
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
/**
|
|
19
|
+
* GraphQL query to retrieve all available locales.
|
|
20
|
+
*/
|
|
21
|
+
exports.GET_LOCALES_QUERY = `
|
|
22
|
+
query GetAllLocales{
|
|
23
|
+
manyLocale {
|
|
24
|
+
id
|
|
25
|
+
label
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContentUrl = getContentUrl;
|
|
4
|
+
const normalize_url_1 = require("../utils/normalize-url");
|
|
5
|
+
/**
|
|
6
|
+
* Get the Content graphql endpoint url
|
|
7
|
+
* @param {object} params Parameters
|
|
8
|
+
* @param {string} [params.url] Content base graphql endpoint url
|
|
9
|
+
* @param {string} params.tenant Tenant name
|
|
10
|
+
* @param {string} params.environment Environment name
|
|
11
|
+
* @param {boolean} params.preview Indicates if preview mode is enabled
|
|
12
|
+
* @returns {string} Content graphql endpoint url
|
|
13
|
+
*/
|
|
14
|
+
function getContentUrl({ url = 'https://cs-graphqlapi-staging.sitecore-staging.cloud', tenant, environment, preview, }) {
|
|
15
|
+
return `${(0, normalize_url_1.normalizeUrl)(url)}/api/graphql/v1/${tenant}/${environment}?preview=${preview}`;
|
|
16
|
+
}
|
package/dist/cjs/debug.js
CHANGED
|
@@ -29,6 +29,7 @@ exports.enableDebug = enableDebug;
|
|
|
29
29
|
*/
|
|
30
30
|
exports.default = {
|
|
31
31
|
common: (0, debug_1.default)(`${rootNamespace}:common`),
|
|
32
|
+
content: (0, debug_1.default)(`${rootNamespace}:content`),
|
|
32
33
|
form: (0, debug_1.default)(`${rootNamespace}:form`),
|
|
33
34
|
http: (0, debug_1.default)(`${rootNamespace}:http`),
|
|
34
35
|
layout: (0, debug_1.default)(`${rootNamespace}:layout`),
|
|
@@ -4,6 +4,7 @@ exports.updateComponentHandler = exports.addComponentUpdateHandler = exports.Des
|
|
|
4
4
|
exports.getDesignLibraryStatusEvent = getDesignLibraryStatusEvent;
|
|
5
5
|
exports.getDesignLibraryScriptLink = getDesignLibraryScriptLink;
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
|
+
const normalize_url_1 = require("../utils/normalize-url");
|
|
7
8
|
/**
|
|
8
9
|
* Event to be sent when report status to design library
|
|
9
10
|
*/
|
|
@@ -110,5 +111,5 @@ function getDesignLibraryStatusEvent(status, uid) {
|
|
|
110
111
|
* @returns The full URL to the design library script.
|
|
111
112
|
*/
|
|
112
113
|
function getDesignLibraryScriptLink(sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) {
|
|
113
|
-
return `${sitecoreEdgeUrl}/v1/files/designlibrary/lib/rh-lib-script.js`;
|
|
114
|
+
return `${(0, normalize_url_1.normalizeUrl)(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
|
|
114
115
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -38,9 +38,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
39
|
};
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.defineConfig = exports.constants = exports.NativeDataFetcher = exports.ClientError = exports.MemoryCacheClient = exports.DefaultRetryStrategy = exports.GraphQLRequestClient = exports.enableDebug = exports.debug = void 0;
|
|
41
|
+
exports.defineConfig = exports.form = exports.constants = exports.NativeDataFetcher = exports.ClientError = exports.MemoryCacheClient = exports.DefaultRetryStrategy = exports.GraphQLRequestClient = exports.enableDebug = exports.debug = void 0;
|
|
42
42
|
const constants = __importStar(require("./constants"));
|
|
43
43
|
exports.constants = constants;
|
|
44
|
+
const form = __importStar(require("./form"));
|
|
45
|
+
exports.form = form;
|
|
44
46
|
var debug_1 = require("./debug");
|
|
45
47
|
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return __importDefault(debug_1).default; } });
|
|
46
48
|
Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return debug_1.enableDebug; } });
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.traverseComponent = exports.traverseField = exports.traversePlaceholder = exports.getContentStylesheetUrl = exports.getContentStylesheetLink = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
|
+
const normalize_url_1 = require("../utils/normalize-url");
|
|
5
6
|
/**
|
|
6
7
|
* Regular expression to check if the content styles are used in the field value
|
|
7
8
|
*/
|
|
@@ -26,7 +27,7 @@ const getContentStylesheetLink = (layoutData, sitecoreEdgeContextId, sitecoreEdg
|
|
|
26
27
|
};
|
|
27
28
|
};
|
|
28
29
|
exports.getContentStylesheetLink = getContentStylesheetLink;
|
|
29
|
-
const getContentStylesheetUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => `${sitecoreEdgeUrl}/v1/files/pages/styles/content-styles.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
30
|
+
const getContentStylesheetUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => `${(0, normalize_url_1.normalizeUrl)(sitecoreEdgeUrl)}/v1/files/pages/styles/content-styles.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
30
31
|
exports.getContentStylesheetUrl = getContentStylesheetUrl;
|
|
31
32
|
const traversePlaceholder = (components, config) => {
|
|
32
33
|
if (config.loadStyles)
|
|
@@ -4,6 +4,7 @@ exports.getStylesheetUrl = void 0;
|
|
|
4
4
|
exports.getDesignLibraryStylesheetLinks = getDesignLibraryStylesheetLinks;
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
|
+
const normalize_url_1 = require("../utils/normalize-url");
|
|
7
8
|
/**
|
|
8
9
|
* Pattern for library ids
|
|
9
10
|
* @example -library--foo
|
|
@@ -27,7 +28,7 @@ function getDesignLibraryStylesheetLinks(layoutData, sitecoreEdgeContextId, site
|
|
|
27
28
|
}));
|
|
28
29
|
}
|
|
29
30
|
const getStylesheetUrl = (id, sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => {
|
|
30
|
-
return `${sitecoreEdgeUrl}/v1/files/components/styles/${id}.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
31
|
+
return `${(0, normalize_url_1.normalizeUrl)(sitecoreEdgeUrl)}/v1/files/components/styles/${id}.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
31
32
|
};
|
|
32
33
|
exports.getStylesheetUrl = getStylesheetUrl;
|
|
33
34
|
/**
|
|
@@ -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;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetchBearerToken = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
9
|
+
/**
|
|
10
|
+
* Connects to M2M endpoint and fetches the bearer token
|
|
11
|
+
* Uses client_id and client_secret from environment variables
|
|
12
|
+
* @param {FetchBearerTokenOptions} options client id, secret, and other parameters for connection to m2m endpoint
|
|
13
|
+
* @returns {string} bearer token string
|
|
14
|
+
*/
|
|
15
|
+
const fetchBearerToken = async (options) => {
|
|
16
|
+
const { clientId, clientSecret } = options;
|
|
17
|
+
const audience = options.audience || constants_1.DEFAULT_SITECORE_AUTH_AUDIENCE;
|
|
18
|
+
const endpoint = options.endpoint || constants_1.DEFAULT_SITECORE_AUTH_ENDPOINT;
|
|
19
|
+
try {
|
|
20
|
+
// TODO:adjust when M2M endpoint is live
|
|
21
|
+
const authenticateResponse = await fetch(endpoint, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
headers: {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
},
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
client_id: clientId,
|
|
28
|
+
client_secret: clientSecret,
|
|
29
|
+
audience: audience,
|
|
30
|
+
grant_type: 'client_credentials',
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
const jsonResponse = await authenticateResponse.json();
|
|
34
|
+
return jsonResponse.access_token;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error(chalk_1.default.red('Error authenticating with Sitecore Auth endpoint:', error));
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.fetchBearerToken = fetchBearerToken;
|
package/dist/cjs/tools/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.scaffoldComponent = exports.generateMetadata = exports.generateSites = void 0;
|
|
17
|
+
exports.fetchBearerToken = exports.scaffoldComponent = exports.generateMetadata = exports.generateSites = void 0;
|
|
18
18
|
var generateSites_1 = require("./generateSites");
|
|
19
19
|
Object.defineProperty(exports, "generateSites", { enumerable: true, get: function () { return generateSites_1.generateSites; } });
|
|
20
20
|
var generateMetadata_1 = require("./generateMetadata");
|
|
@@ -22,3 +22,5 @@ Object.defineProperty(exports, "generateMetadata", { enumerable: true, get: func
|
|
|
22
22
|
var scaffold_1 = require("./scaffold");
|
|
23
23
|
Object.defineProperty(exports, "scaffoldComponent", { enumerable: true, get: function () { return scaffold_1.scaffoldComponent; } });
|
|
24
24
|
__exportStar(require("./templating"), exports);
|
|
25
|
+
var fetch_bearer_token_1 = require("./auth/fetch-bearer-token");
|
|
26
|
+
Object.defineProperty(exports, "fetchBearerToken", { enumerable: true, get: function () { return fetch_bearer_token_1.fetchBearerToken; } });
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -173,7 +173,7 @@ exports.areURLSearchParamsEqual = areURLSearchParamsEqual;
|
|
|
173
173
|
* @returns {string} - The modified string or regex with non-special "?" characters escaped.
|
|
174
174
|
*/
|
|
175
175
|
const escapeNonSpecialQuestionMarks = (input) => {
|
|
176
|
-
const regexPattern = /(
|
|
176
|
+
const regexPattern = /(\\)?\?/g; // Match "?" that may or may not be preceded by a backslash
|
|
177
177
|
const negativeLookaheadPattern = /\(\?!$/; // Detect the start of a Negative Lookahead pattern
|
|
178
178
|
const specialRegexSymbols = /[.*+)\[\]|\(]$/; // Check for special regex symbols before "?"
|
|
179
179
|
let result = '';
|
|
@@ -182,12 +182,14 @@ const escapeNonSpecialQuestionMarks = (input) => {
|
|
|
182
182
|
while ((match = regexPattern.exec(input)) !== null) {
|
|
183
183
|
const index = match.index; // Position of the "?" in the string
|
|
184
184
|
const before = input.slice(lastIndex, index); // Context before the "?"
|
|
185
|
+
// Check if "?" is preceded by a backslash (escaped)
|
|
186
|
+
const isEscaped = match[1] !== undefined; // match[1] is the backslash group
|
|
185
187
|
// Check if "?" is part of a Negative Lookahead
|
|
186
188
|
const isNegativeLookahead = negativeLookaheadPattern.test(before.slice(-3));
|
|
187
189
|
// Check if "?" follows a special regex symbol
|
|
188
190
|
const isSpecialRegexSymbol = specialRegexSymbols.test(before.slice(-1));
|
|
189
|
-
if (isNegativeLookahead || isSpecialRegexSymbol) {
|
|
190
|
-
// If it's a special
|
|
191
|
+
if (isEscaped || isNegativeLookahead || isSpecialRegexSymbol) {
|
|
192
|
+
// If it's escaped, part of a Negative Lookahead, or follows a special regex symbol, keep the "?" as is
|
|
191
193
|
result += input.slice(lastIndex, index + 1);
|
|
192
194
|
}
|
|
193
195
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
|
|
2
|
-
|
|
2
|
+
import { normalizeUrl } from '../utils/normalize-url';
|
|
3
3
|
/**
|
|
4
4
|
* Generates a URL for accessing Sitecore Edge Platform Content using the provided endpoint and context ID.
|
|
5
5
|
* @param {string} sitecoreEdgeContextId - The unique context id.
|
|
@@ -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
|
|
@@ -56,7 +57,7 @@ export class SitecoreClient {
|
|
|
56
57
|
* Get page details for a route, with layout and other details
|
|
57
58
|
* @param {string} path route path
|
|
58
59
|
* @param {PageOptions} [pageOptions] site, language and personalization variant details for route
|
|
59
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
60
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
60
61
|
* @returns {Page | null} page details
|
|
61
62
|
*/
|
|
62
63
|
async getPage(path, pageOptions, fetchOptions) {
|
|
@@ -112,7 +113,7 @@ export class SitecoreClient {
|
|
|
112
113
|
/**
|
|
113
114
|
* Retrieves dictionary phrases for a given site and locale.
|
|
114
115
|
* @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
|
|
116
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
116
117
|
* @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
|
|
117
118
|
*/
|
|
118
119
|
async getDictionary(routeOptions, fetchOptions) {
|
|
@@ -123,7 +124,7 @@ export class SitecoreClient {
|
|
|
123
124
|
/**
|
|
124
125
|
* Retrieves error pages for a given site and locale.
|
|
125
126
|
* @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
|
|
127
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
127
128
|
* @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
|
|
128
129
|
*/
|
|
129
130
|
async getErrorPages(routeOptions, fetchOptions) {
|
|
@@ -134,7 +135,7 @@ export class SitecoreClient {
|
|
|
134
135
|
/**
|
|
135
136
|
* Retrieves preview page and layout details
|
|
136
137
|
* @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
|
|
137
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
138
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
138
139
|
* @returns {Page} preview page details
|
|
139
140
|
*/
|
|
140
141
|
async getPreview(previewData, fetchOptions) {
|
|
@@ -168,7 +169,7 @@ export class SitecoreClient {
|
|
|
168
169
|
/**
|
|
169
170
|
* Get design library page details for Design Library mode of your app
|
|
170
171
|
* @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
|
|
171
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
172
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
172
173
|
* @returns {Page} preview page for Design Library
|
|
173
174
|
*/
|
|
174
175
|
async getDesignLibraryData(designLibData, fetchOptions) {
|
|
@@ -253,6 +254,19 @@ export class SitecoreClient {
|
|
|
253
254
|
.join('')}
|
|
254
255
|
</sitemapindex>`;
|
|
255
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Retrieves the robots.txt content for a given site name.
|
|
259
|
+
*
|
|
260
|
+
* @param {string} siteName - The name of the site to retrieve the robots.txt for.
|
|
261
|
+
* @param {FetchOptions} [fetchOptions] - Optional fetch options.
|
|
262
|
+
* @returns {Promise<string | null>} A promise that resolves to the robots.txt content,
|
|
263
|
+
* or null if no content is found.
|
|
264
|
+
*/
|
|
265
|
+
async getRobots(siteName, fetchOptions) {
|
|
266
|
+
const robotsService = this.getRobotsService(siteName || this.initOptions.defaultSite);
|
|
267
|
+
const content = await robotsService.fetchRobots(fetchOptions);
|
|
268
|
+
return content || null;
|
|
269
|
+
}
|
|
256
270
|
/**
|
|
257
271
|
* Factory methods for creating dependencies
|
|
258
272
|
* Subclasses can override these to provide custom implementations.
|
|
@@ -263,6 +277,12 @@ export class SitecoreClient {
|
|
|
263
277
|
siteName,
|
|
264
278
|
});
|
|
265
279
|
}
|
|
280
|
+
getRobotsService(siteName) {
|
|
281
|
+
return new GraphQLRobotsService({
|
|
282
|
+
clientFactory: this.clientFactory,
|
|
283
|
+
siteName,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
266
286
|
getBaseServiceOptions() {
|
|
267
287
|
return {
|
|
268
288
|
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',
|
package/dist/esm/constants.js
CHANGED
|
@@ -8,3 +8,5 @@ export var SitecoreTemplateId;
|
|
|
8
8
|
export const siteNameError = 'The siteName cannot be empty';
|
|
9
9
|
export const SITECORE_EDGE_URL_DEFAULT = 'https://edge-platform.sitecorecloud.io';
|
|
10
10
|
export const HIDDEN_RENDERING_NAME = 'Hidden Rendering';
|
|
11
|
+
export const DEFAULT_SITECORE_AUTH_ENDPOINT = 'https://auth.sitecorecloud.io/oauth/token';
|
|
12
|
+
export const DEFAULT_SITECORE_AUTH_AUDIENCE = 'https://api.sitecorecloud.io';
|