@sitecore-content-sdk/core 0.1.0 → 0.2.0-beta.10
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/sitecore-client.js +33 -11
- package/dist/cjs/config/define-config.js +5 -5
- package/dist/cjs/constants.js +3 -1
- package/dist/cjs/content/content-client.js +148 -0
- package/dist/cjs/content/index.js +13 -0
- package/dist/cjs/content/locales.js +32 -0
- package/dist/cjs/content/taxonomies.js +78 -0
- package/dist/cjs/content/utils.js +16 -0
- package/dist/cjs/debug.js +1 -0
- package/dist/cjs/index.js +3 -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/utils.js +5 -3
- package/dist/esm/client/sitecore-client.js +33 -11
- package/dist/esm/config/define-config.js +5 -5
- package/dist/esm/constants.js +2 -0
- package/dist/esm/content/content-client.js +141 -0
- package/dist/esm/content/index.js +4 -0
- package/dist/esm/content/locales.js +29 -0
- package/dist/esm/content/taxonomies.js +75 -0
- package/dist/esm/content/utils.js +13 -0
- package/dist/esm/debug.js +1 -0
- package/dist/esm/index.js +2 -0
- 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/utils.js +5 -3
- package/package.json +18 -18
- package/types/client/index.d.ts +1 -1
- package/types/client/models.d.ts +17 -1
- package/types/client/sitecore-client.d.ts +50 -22
- 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 +92 -0
- package/types/content/index.d.ts +4 -0
- package/types/content/locales.d.ts +38 -0
- package/types/content/taxonomies.d.ts +125 -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/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');
|
|
@@ -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 =
|
|
27
|
-
|
|
28
|
-
this.
|
|
29
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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',
|
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,148 @@
|
|
|
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
|
+
const taxonomies_1 = require("./taxonomies");
|
|
12
|
+
/**
|
|
13
|
+
* Class representing a client for interacting with the Content API.
|
|
14
|
+
*/
|
|
15
|
+
class ContentClient {
|
|
16
|
+
constructor({ url, tenant, environment, preview = false, token }) {
|
|
17
|
+
this.endpoint = (0, utils_1.getContentUrl)({
|
|
18
|
+
environment,
|
|
19
|
+
preview,
|
|
20
|
+
tenant,
|
|
21
|
+
url,
|
|
22
|
+
});
|
|
23
|
+
this.graphqlClient = new graphql_request_client_1.GraphQLRequestClient(this.endpoint, {
|
|
24
|
+
headers: {
|
|
25
|
+
Authorization: `Bearer ${token}`,
|
|
26
|
+
},
|
|
27
|
+
debugger: debug_1.default.content,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 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.
|
|
32
|
+
* @param {Partial<ContentClientOptions>} [options] - client configuration options
|
|
33
|
+
* @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.
|
|
34
|
+
* @param {string} [options.tenant] - Tenant name. If not provided, it will be read from the SITECORE_CS_TENANT environment variable
|
|
35
|
+
* @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'
|
|
36
|
+
* @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
|
|
37
|
+
* @param {string} [options.token] - Token for authentication. If not provided, it will be read from the SITECORE_CS_TOKEN environment variable.
|
|
38
|
+
* @returns {ContentClient} ContentClient instance
|
|
39
|
+
* @throws {Error} If tenant or token is not provided
|
|
40
|
+
*/
|
|
41
|
+
static createClient({ url, tenant, environment, preview, token, } = {}) {
|
|
42
|
+
const options = {
|
|
43
|
+
url: url || process.env.SITECORE_CS_URL,
|
|
44
|
+
tenant: tenant || process.env.SITECORE_CS_TENANT || '',
|
|
45
|
+
environment: environment || process.env.SITECORE_CS_ENVIRONMENT || 'main',
|
|
46
|
+
preview: preview || process.env.SITECORE_CS_PREVIEW === 'true',
|
|
47
|
+
token: token || process.env.SITECORE_CS_TOKEN || '',
|
|
48
|
+
};
|
|
49
|
+
if (!options.tenant) {
|
|
50
|
+
throw new Error('Tenant is required to be provided as an argument or as a SITECORE_CS_TENANT environment variable');
|
|
51
|
+
}
|
|
52
|
+
if (!options.token) {
|
|
53
|
+
throw new Error('Token is required to be provided as an argument or as a SITECORE_CS_TOKEN environment variable');
|
|
54
|
+
}
|
|
55
|
+
return new ContentClient(options);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Execute graphql request
|
|
59
|
+
* @param {string | DocumentNode} query graphql query
|
|
60
|
+
* @param {object} variables variables for the query
|
|
61
|
+
* @param {FetchOptions} options options for configuring the request
|
|
62
|
+
* @returns {T} response data
|
|
63
|
+
*/
|
|
64
|
+
async get(query, variables = {}, options = {}) {
|
|
65
|
+
debug_1.default.content('fetching content data');
|
|
66
|
+
return this.graphqlClient.request(query, variables, options);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the locale information for a given locale ID.
|
|
70
|
+
* @param {string} id - The unique identifier of the locale item.
|
|
71
|
+
* @returns A promise that resolves to the locale information associated with the specified locale ID.
|
|
72
|
+
*/
|
|
73
|
+
async getLocale(id) {
|
|
74
|
+
var _a;
|
|
75
|
+
debug_1.default.content('Getting locale for id: %s', id);
|
|
76
|
+
const response = await this.get(locales_1.GET_LOCALE_QUERY, { id });
|
|
77
|
+
return ((_a = response.locale) === null || _a === void 0 ? void 0 : _a.system) || null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves all available locales from the content service.
|
|
81
|
+
* @returns A promise that resolves to an array of locales.
|
|
82
|
+
*/
|
|
83
|
+
async getLocales() {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
debug_1.default.content('Getting all locales');
|
|
86
|
+
const response = await this.get(locales_1.GET_LOCALES_QUERY);
|
|
87
|
+
return (_b = (_a = response === null || response === void 0 ? void 0 : response.manyLocale) === null || _a === void 0 ? void 0 : _a.map((entry) => entry.system)) !== null && _b !== void 0 ? _b : [];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves all available taxonomies with optional pagination support.
|
|
91
|
+
* @param {object} [options] - Optional pagination options.
|
|
92
|
+
* @param {number} [options.pageSize] - Limits the number of taxonomies returned per page. Defaults to the API's default
|
|
93
|
+
* @param {string} [options.after] - Cursor for pagination; use the `cursor` returned from the previous call to fetch the next page.
|
|
94
|
+
* @returns A promise that resolves to an object containing taxonomies, their terms, and pagination info.
|
|
95
|
+
*/
|
|
96
|
+
async getTaxonomies(options) {
|
|
97
|
+
var _a, _b, _c, _d, _e;
|
|
98
|
+
debug_1.default.content('Getting taxonomies (pageSize: %s, after: %s)', (_a = options === null || options === void 0 ? void 0 : options.pageSize) !== null && _a !== void 0 ? _a : 'API Default', (_b = options === null || options === void 0 ? void 0 : options.after) !== null && _b !== void 0 ? _b : '');
|
|
99
|
+
const variables = {
|
|
100
|
+
pageSize: options === null || options === void 0 ? void 0 : options.pageSize,
|
|
101
|
+
after: (_c = options === null || options === void 0 ? void 0 : options.after) !== null && _c !== void 0 ? _c : '',
|
|
102
|
+
};
|
|
103
|
+
const response = await this.get(taxonomies_1.GET_TAXONOMIES_QUERY, variables);
|
|
104
|
+
const data = response === null || response === void 0 ? void 0 : response.manyTaxonomy;
|
|
105
|
+
return {
|
|
106
|
+
results: ((_d = data === null || data === void 0 ? void 0 : data.results) !== null && _d !== void 0 ? _d : []).map((taxonomy) => {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
return ({
|
|
109
|
+
system: taxonomy.system,
|
|
110
|
+
terms: (_b = (_a = taxonomy.terms) === null || _a === void 0 ? void 0 : _a.results) !== null && _b !== void 0 ? _b : [],
|
|
111
|
+
});
|
|
112
|
+
}),
|
|
113
|
+
cursor: data === null || data === void 0 ? void 0 : data.cursor,
|
|
114
|
+
hasMore: (_e = data === null || data === void 0 ? void 0 : data.hasMore) !== null && _e !== void 0 ? _e : false,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Retrieves a taxonomy by its ID, with optional pagination support for its terms.
|
|
119
|
+
* @param {object} options - Options for fetching the taxonomy.
|
|
120
|
+
* @param {string} options.id - The unique identifier of the taxonomy.
|
|
121
|
+
* @param {object} [options.terms] - Optional pagination options for terms.
|
|
122
|
+
* @param {number} [options.terms.pageSize] - Optional. Limits the number of terms returned per page.
|
|
123
|
+
* @param {string} [options.terms.after] - Optional. Cursor for pagination. Used to fetch the next page of terms.
|
|
124
|
+
* @returns A promise that resolves to the taxonomy object, including pagination metadata (`hasMore`, `cursor`) for its terms. Returns `null` if the taxonomy is not found.
|
|
125
|
+
*/
|
|
126
|
+
async getTaxonomy({ id, terms, }) {
|
|
127
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
128
|
+
debug_1.default.content('Getting taxonomy for id: %s (termsPageSize: %s, termsAfter: %s)', id, (_a = terms === null || terms === void 0 ? void 0 : terms.pageSize) !== null && _a !== void 0 ? _a : 'API Default', (_b = terms === null || terms === void 0 ? void 0 : terms.after) !== null && _b !== void 0 ? _b : '');
|
|
129
|
+
const variables = {
|
|
130
|
+
id,
|
|
131
|
+
termsPageSize: terms === null || terms === void 0 ? void 0 : terms.pageSize,
|
|
132
|
+
termsAfter: terms === null || terms === void 0 ? void 0 : terms.after,
|
|
133
|
+
};
|
|
134
|
+
const response = await this.get(taxonomies_1.GET_TAXONOMY_QUERY, variables);
|
|
135
|
+
const taxonomy = response === null || response === void 0 ? void 0 : response.taxonomy;
|
|
136
|
+
if (!taxonomy)
|
|
137
|
+
return null;
|
|
138
|
+
return {
|
|
139
|
+
system: taxonomy.system,
|
|
140
|
+
terms: {
|
|
141
|
+
results: (_d = (_c = taxonomy.terms) === null || _c === void 0 ? void 0 : _c.results) !== null && _d !== void 0 ? _d : [],
|
|
142
|
+
cursor: (_e = taxonomy.terms) === null || _e === void 0 ? void 0 : _e.cursor,
|
|
143
|
+
hasMore: (_g = (_f = taxonomy.terms) === null || _f === void 0 ? void 0 : _f.hasMore) !== null && _g !== void 0 ? _g : false,
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.ContentClient = ContentClient;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContentUrl = exports.GET_TAXONOMIES_QUERY = exports.GET_TAXONOMY_QUERY = 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 taxonomies_1 = require("./taxonomies");
|
|
10
|
+
Object.defineProperty(exports, "GET_TAXONOMY_QUERY", { enumerable: true, get: function () { return taxonomies_1.GET_TAXONOMY_QUERY; } });
|
|
11
|
+
Object.defineProperty(exports, "GET_TAXONOMIES_QUERY", { enumerable: true, get: function () { return taxonomies_1.GET_TAXONOMIES_QUERY; } });
|
|
12
|
+
var utils_1 = require("./utils");
|
|
13
|
+
Object.defineProperty(exports, "getContentUrl", { enumerable: true, get: function () { return utils_1.getContentUrl; } });
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
system {
|
|
14
|
+
id
|
|
15
|
+
label
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
/**
|
|
21
|
+
* GraphQL query to retrieve all available locales.
|
|
22
|
+
*/
|
|
23
|
+
exports.GET_LOCALES_QUERY = `
|
|
24
|
+
query GetAllLocales {
|
|
25
|
+
manyLocale {
|
|
26
|
+
system {
|
|
27
|
+
id
|
|
28
|
+
label
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET_TAXONOMY_QUERY = exports.GET_TAXONOMIES_QUERY = void 0;
|
|
4
|
+
// --- GraphQL queries ---
|
|
5
|
+
/**
|
|
6
|
+
* GraphQL query to retrieve all taxonomies with optional pagination for taxonomies only.
|
|
7
|
+
*
|
|
8
|
+
* Variables:
|
|
9
|
+
* - pageSize: The number of taxonomies to retrieve per page.
|
|
10
|
+
* - after: The cursor for fetching the next page of taxonomies.
|
|
11
|
+
*/
|
|
12
|
+
exports.GET_TAXONOMIES_QUERY = `
|
|
13
|
+
query GetAllTaxonomies(
|
|
14
|
+
$pageSize: Int
|
|
15
|
+
$after: String
|
|
16
|
+
) {
|
|
17
|
+
manyTaxonomy(minimumPageSize: $pageSize, after: $after) {
|
|
18
|
+
cursor
|
|
19
|
+
hasMore
|
|
20
|
+
results {
|
|
21
|
+
terms {
|
|
22
|
+
cursor
|
|
23
|
+
hasMore
|
|
24
|
+
results {
|
|
25
|
+
id
|
|
26
|
+
name
|
|
27
|
+
label
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
system {
|
|
31
|
+
id
|
|
32
|
+
name
|
|
33
|
+
version
|
|
34
|
+
label
|
|
35
|
+
createdAt
|
|
36
|
+
createdBy
|
|
37
|
+
updatedAt
|
|
38
|
+
updatedBy
|
|
39
|
+
publishStatus
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
/**
|
|
46
|
+
* GraphQL query to retrieve a specific taxonomy by its ID, with optional pagination for its terms.
|
|
47
|
+
*
|
|
48
|
+
* Variables:
|
|
49
|
+
* - id: The unique ID of the taxonomy to retrieve.
|
|
50
|
+
* - termsPageSize: The number of terms to retrieve per page.
|
|
51
|
+
* - termsAfter: The cursor for fetching the next page of terms.
|
|
52
|
+
*/
|
|
53
|
+
exports.GET_TAXONOMY_QUERY = `
|
|
54
|
+
query GetTaxonomyById($id: ID!, $termsPageSize: Int, $termsAfter: String) {
|
|
55
|
+
taxonomy(id: $id) {
|
|
56
|
+
terms(minimumPageSize: $termsPageSize, after: $termsAfter) {
|
|
57
|
+
cursor
|
|
58
|
+
hasMore
|
|
59
|
+
results {
|
|
60
|
+
id
|
|
61
|
+
name
|
|
62
|
+
label
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
system {
|
|
66
|
+
id
|
|
67
|
+
name
|
|
68
|
+
version
|
|
69
|
+
label
|
|
70
|
+
createdAt
|
|
71
|
+
createdBy
|
|
72
|
+
updatedAt
|
|
73
|
+
updatedBy
|
|
74
|
+
publishStatus
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
@@ -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`),
|
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; } });
|
|
@@ -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 {
|