@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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { GraphQLRequestClient } from '../graphql-request-client';
|
|
2
|
+
import { getContentUrl } from './utils';
|
|
3
|
+
import debug from '../debug';
|
|
4
|
+
import { GET_LOCALE_QUERY, GET_LOCALES_QUERY, } from './locales';
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a client for interacting with the Content API.
|
|
7
|
+
*/
|
|
8
|
+
export class ContentClient {
|
|
9
|
+
constructor({ url, tenant, environment, preview = false, token }) {
|
|
10
|
+
this.endpoint = getContentUrl({
|
|
11
|
+
environment,
|
|
12
|
+
preview,
|
|
13
|
+
tenant,
|
|
14
|
+
url,
|
|
15
|
+
});
|
|
16
|
+
this.graphqlClient = new GraphQLRequestClient(this.endpoint, {
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${token}`,
|
|
19
|
+
},
|
|
20
|
+
debugger: debug.content,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 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.
|
|
25
|
+
* @param {Partial<ContentClientOptions>} [options] - client configuration options
|
|
26
|
+
* @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.
|
|
27
|
+
* @param {string} [options.tenant] - Tenant name. If not provided, it will be read from the SITECORE_CS_TENANT environment variable
|
|
28
|
+
* @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'
|
|
29
|
+
* @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
|
|
30
|
+
* @param {string} [options.token] - Token for authentication. If not provided, it will be read from the SITECORE_CS_TOKEN environment variable.
|
|
31
|
+
* @returns {ContentClient} ContentClient instance
|
|
32
|
+
* @throws {Error} If tenant or token is not provided
|
|
33
|
+
*/
|
|
34
|
+
static createClient({ url, tenant, environment, preview, token, } = {}) {
|
|
35
|
+
const options = {
|
|
36
|
+
url: url || process.env.SITECORE_CS_URL,
|
|
37
|
+
tenant: tenant || process.env.SITECORE_CS_TENANT || '',
|
|
38
|
+
environment: environment || process.env.SITECORE_CS_ENVIRONMENT || 'main',
|
|
39
|
+
preview: preview || process.env.SITECORE_CS_PREVIEW === 'true',
|
|
40
|
+
token: token || process.env.SITECORE_CS_TOKEN || '',
|
|
41
|
+
};
|
|
42
|
+
if (!options.tenant) {
|
|
43
|
+
throw new Error('Tenant is required to be provided as an argument or as a SITECORE_CS_TENANT environment variable');
|
|
44
|
+
}
|
|
45
|
+
if (!options.token) {
|
|
46
|
+
throw new Error('Token is required to be provided as an argument or as a SITECORE_CS_TOKEN environment variable');
|
|
47
|
+
}
|
|
48
|
+
return new ContentClient(options);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Execute graphql request
|
|
52
|
+
* @param {string | DocumentNode} query graphql query
|
|
53
|
+
* @param {object} variables variables for the query
|
|
54
|
+
* @param {FetchOptions} options options for configuring the request
|
|
55
|
+
* @returns {T} response data
|
|
56
|
+
*/
|
|
57
|
+
async get(query, variables = {}, options = {}) {
|
|
58
|
+
debug.content('fetching content data');
|
|
59
|
+
return this.graphqlClient.request(query, variables, options);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves the locale information for a given locale ID.
|
|
63
|
+
* @param {string} id - The unique identifier of the locale item.
|
|
64
|
+
* @returns A promise that resolves to the locale information associated with the specified locale ID.
|
|
65
|
+
*/
|
|
66
|
+
async getLocale(id) {
|
|
67
|
+
debug.content('Getting locale for id: %s', id);
|
|
68
|
+
const response = await this.get(GET_LOCALE_QUERY, { id });
|
|
69
|
+
return response.locale;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves all available locales from the content service.
|
|
73
|
+
* @returns A promise that resolves to an array of locales.
|
|
74
|
+
*/
|
|
75
|
+
async getLocales() {
|
|
76
|
+
debug.content('Getting all locales');
|
|
77
|
+
const response = await this.get(GET_LOCALES_QUERY);
|
|
78
|
+
return response.manyLocale;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL query to retrieve a specific locale by its ID.
|
|
3
|
+
*
|
|
4
|
+
* Variables:
|
|
5
|
+
* - id: The ID of the locale to retrieve.
|
|
6
|
+
*/
|
|
7
|
+
export const GET_LOCALE_QUERY = `
|
|
8
|
+
query GetLocaleById ($id: ID!) {
|
|
9
|
+
locale(id: $id) {
|
|
10
|
+
id
|
|
11
|
+
label
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
/**
|
|
16
|
+
* GraphQL query to retrieve all available locales.
|
|
17
|
+
*/
|
|
18
|
+
export const GET_LOCALES_QUERY = `
|
|
19
|
+
query GetAllLocales{
|
|
20
|
+
manyLocale {
|
|
21
|
+
id
|
|
22
|
+
label
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { normalizeUrl } from '../utils/normalize-url';
|
|
2
|
+
/**
|
|
3
|
+
* Get the Content graphql endpoint url
|
|
4
|
+
* @param {object} params Parameters
|
|
5
|
+
* @param {string} [params.url] Content base graphql endpoint url
|
|
6
|
+
* @param {string} params.tenant Tenant name
|
|
7
|
+
* @param {string} params.environment Environment name
|
|
8
|
+
* @param {boolean} params.preview Indicates if preview mode is enabled
|
|
9
|
+
* @returns {string} Content graphql endpoint url
|
|
10
|
+
*/
|
|
11
|
+
export function getContentUrl({ url = 'https://cs-graphqlapi-staging.sitecore-staging.cloud', tenant, environment, preview, }) {
|
|
12
|
+
return `${normalizeUrl(url)}/api/graphql/v1/${tenant}/${environment}?preview=${preview}`;
|
|
13
|
+
}
|
package/dist/esm/debug.js
CHANGED
|
@@ -22,6 +22,7 @@ export const enableDebug = (namespaces) => debug.enable(namespaces);
|
|
|
22
22
|
*/
|
|
23
23
|
export default {
|
|
24
24
|
common: debug(`${rootNamespace}:common`),
|
|
25
|
+
content: debug(`${rootNamespace}:content`),
|
|
25
26
|
form: debug(`${rootNamespace}:form`),
|
|
26
27
|
http: debug(`${rootNamespace}:http`),
|
|
27
28
|
layout: debug(`${rootNamespace}:layout`),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
|
|
2
|
+
import { normalizeUrl } from '../utils/normalize-url';
|
|
2
3
|
/**
|
|
3
4
|
* Event to be sent when report status to design library
|
|
4
5
|
*/
|
|
@@ -103,5 +104,5 @@ export function getDesignLibraryStatusEvent(status, uid) {
|
|
|
103
104
|
* @returns The full URL to the design library script.
|
|
104
105
|
*/
|
|
105
106
|
export function getDesignLibraryScriptLink(sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
|
|
106
|
-
return `${sitecoreEdgeUrl}/v1/files/designlibrary/lib/rh-lib-script.js`;
|
|
107
|
+
return `${normalizeUrl(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
|
|
107
108
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// NOTE: all imports are now named as to not make breaking changes
|
|
2
2
|
// and to keep react-native working with cjs modules.
|
|
3
3
|
import * as constants from './constants';
|
|
4
|
+
import * as form from './form';
|
|
4
5
|
export { default as debug, enableDebug } from './debug';
|
|
5
6
|
export { GraphQLRequestClient, } from './graphql-request-client';
|
|
6
7
|
export { DefaultRetryStrategy } from './retries';
|
|
@@ -8,4 +9,5 @@ export { MemoryCacheClient } from './cache-client';
|
|
|
8
9
|
export { ClientError } from 'graphql-request';
|
|
9
10
|
export { NativeDataFetcher, } from './native-fetcher';
|
|
10
11
|
export { constants };
|
|
12
|
+
export { form };
|
|
11
13
|
export { defineConfig } from './config';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
|
|
2
|
+
import { normalizeUrl } from '../utils/normalize-url';
|
|
2
3
|
/**
|
|
3
4
|
* Regular expression to check if the content styles are used in the field value
|
|
4
5
|
*/
|
|
@@ -22,7 +23,7 @@ export const getContentStylesheetLink = (layoutData, sitecoreEdgeContextId, site
|
|
|
22
23
|
rel: 'stylesheet',
|
|
23
24
|
};
|
|
24
25
|
};
|
|
25
|
-
export const getContentStylesheetUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) => `${sitecoreEdgeUrl}/v1/files/pages/styles/content-styles.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
26
|
+
export const getContentStylesheetUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) => `${normalizeUrl(sitecoreEdgeUrl)}/v1/files/pages/styles/content-styles.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
26
27
|
export const traversePlaceholder = (components, config) => {
|
|
27
28
|
if (config.loadStyles)
|
|
28
29
|
return;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getFieldValue } from '.';
|
|
2
2
|
import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
|
|
3
|
+
import { normalizeUrl } from '../utils/normalize-url';
|
|
3
4
|
/**
|
|
4
5
|
* Pattern for library ids
|
|
5
6
|
* @example -library--foo
|
|
@@ -23,7 +24,7 @@ export function getDesignLibraryStylesheetLinks(layoutData, sitecoreEdgeContextI
|
|
|
23
24
|
}));
|
|
24
25
|
}
|
|
25
26
|
export const getStylesheetUrl = (id, sitecoreEdgeContextId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) => {
|
|
26
|
-
return `${sitecoreEdgeUrl}/v1/files/components/styles/${id}.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
27
|
+
return `${normalizeUrl(sitecoreEdgeUrl)}/v1/files/components/styles/${id}.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* Traverse placeholder and components to add library ids
|
|
@@ -30,14 +30,14 @@ export class GraphQLRobotsService {
|
|
|
30
30
|
* @returns text of robots.txt
|
|
31
31
|
* @throws {Error} if the siteName is empty.
|
|
32
32
|
*/
|
|
33
|
-
async fetchRobots() {
|
|
33
|
+
async fetchRobots(fetchOptions) {
|
|
34
34
|
const siteName = this.options.siteName;
|
|
35
35
|
if (!siteName) {
|
|
36
36
|
throw new Error(siteNameError);
|
|
37
37
|
}
|
|
38
38
|
const robotsResult = this.graphQLClient.request(this.query, {
|
|
39
39
|
siteName,
|
|
40
|
-
});
|
|
40
|
+
}, fetchOptions);
|
|
41
41
|
try {
|
|
42
42
|
return robotsResult.then((result) => {
|
|
43
43
|
var _a, _b;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { DEFAULT_SITECORE_AUTH_AUDIENCE, DEFAULT_SITECORE_AUTH_ENDPOINT } from '../../constants';
|
|
3
|
+
/**
|
|
4
|
+
* Connects to M2M endpoint and fetches the bearer token
|
|
5
|
+
* Uses client_id and client_secret from environment variables
|
|
6
|
+
* @param {FetchBearerTokenOptions} options client id, secret, and other parameters for connection to m2m endpoint
|
|
7
|
+
* @returns {string} bearer token string
|
|
8
|
+
*/
|
|
9
|
+
export const fetchBearerToken = async (options) => {
|
|
10
|
+
const { clientId, clientSecret } = options;
|
|
11
|
+
const audience = options.audience || DEFAULT_SITECORE_AUTH_AUDIENCE;
|
|
12
|
+
const endpoint = options.endpoint || DEFAULT_SITECORE_AUTH_ENDPOINT;
|
|
13
|
+
try {
|
|
14
|
+
// TODO:adjust when M2M endpoint is live
|
|
15
|
+
const authenticateResponse = await fetch(endpoint, {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify({
|
|
21
|
+
client_id: clientId,
|
|
22
|
+
client_secret: clientSecret,
|
|
23
|
+
audience: audience,
|
|
24
|
+
grant_type: 'client_credentials',
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
const jsonResponse = await authenticateResponse.json();
|
|
28
|
+
return jsonResponse.access_token;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error(chalk.red('Error authenticating with Sitecore Auth endpoint:', error));
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
package/dist/esm/tools/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const normalizeUrl = (url) => (url.endsWith('/') ? url.slice(0, -1) : url);
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -160,7 +160,7 @@ export const areURLSearchParamsEqual = (params1, params2) => {
|
|
|
160
160
|
* @returns {string} - The modified string or regex with non-special "?" characters escaped.
|
|
161
161
|
*/
|
|
162
162
|
export const escapeNonSpecialQuestionMarks = (input) => {
|
|
163
|
-
const regexPattern = /(
|
|
163
|
+
const regexPattern = /(\\)?\?/g; // Match "?" that may or may not be preceded by a backslash
|
|
164
164
|
const negativeLookaheadPattern = /\(\?!$/; // Detect the start of a Negative Lookahead pattern
|
|
165
165
|
const specialRegexSymbols = /[.*+)\[\]|\(]$/; // Check for special regex symbols before "?"
|
|
166
166
|
let result = '';
|
|
@@ -169,12 +169,14 @@ export const escapeNonSpecialQuestionMarks = (input) => {
|
|
|
169
169
|
while ((match = regexPattern.exec(input)) !== null) {
|
|
170
170
|
const index = match.index; // Position of the "?" in the string
|
|
171
171
|
const before = input.slice(lastIndex, index); // Context before the "?"
|
|
172
|
+
// Check if "?" is preceded by a backslash (escaped)
|
|
173
|
+
const isEscaped = match[1] !== undefined; // match[1] is the backslash group
|
|
172
174
|
// Check if "?" is part of a Negative Lookahead
|
|
173
175
|
const isNegativeLookahead = negativeLookaheadPattern.test(before.slice(-3));
|
|
174
176
|
// Check if "?" follows a special regex symbol
|
|
175
177
|
const isSpecialRegexSymbol = specialRegexSymbols.test(before.slice(-1));
|
|
176
|
-
if (isNegativeLookahead || isSpecialRegexSymbol) {
|
|
177
|
-
// If it's a special
|
|
178
|
+
if (isEscaped || isNegativeLookahead || isSpecialRegexSymbol) {
|
|
179
|
+
// If it's escaped, part of a Negative Lookahead, or follows a special regex symbol, keep the "?" as is
|
|
178
180
|
result += input.slice(lastIndex, index + 1);
|
|
179
181
|
}
|
|
180
182
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/core",
|
|
3
|
-
"version": "0.2.0-canary.
|
|
3
|
+
"version": "0.2.0-canary.30",
|
|
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/
|
|
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 src/content/index.ts --githubPages false"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=22"
|
|
@@ -34,42 +34,42 @@
|
|
|
34
34
|
"url": "https://github.com/sitecore/content-sdk/issues"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@sitecore-cloudsdk/events": "^0.5.
|
|
38
|
-
"@types/chai": "^5.
|
|
37
|
+
"@sitecore-cloudsdk/events": "^0.5.1",
|
|
38
|
+
"@types/chai": "^5.2.2",
|
|
39
39
|
"@types/chai-spies": "^1.0.6",
|
|
40
40
|
"@types/chai-string": "^1.4.5",
|
|
41
41
|
"@types/debug": "^4.1.12",
|
|
42
42
|
"@types/jsdom": "^21.1.7",
|
|
43
43
|
"@types/memory-cache": "^0.2.6",
|
|
44
|
-
"@types/mocha": "^10.0.
|
|
45
|
-
"@types/node": "^22.
|
|
44
|
+
"@types/mocha": "^10.0.10",
|
|
45
|
+
"@types/node": "^22.15.14",
|
|
46
46
|
"@types/proxyquire": "^1.3.31",
|
|
47
|
-
"@types/sinon": "^17.0.
|
|
47
|
+
"@types/sinon": "^17.0.4",
|
|
48
48
|
"@types/sinon-chai": "^4.0.0",
|
|
49
49
|
"@types/url-parse": "1.4.11",
|
|
50
|
-
"chai": "^4.
|
|
50
|
+
"chai": "^4.4.1",
|
|
51
51
|
"chai-spies": "^1.1.0",
|
|
52
|
-
"chai-string": "^1.
|
|
52
|
+
"chai-string": "^1.6.0",
|
|
53
53
|
"del-cli": "^6.0.0",
|
|
54
54
|
"eslint": "^8.56.0",
|
|
55
|
-
"eslint-plugin-jsdoc": "
|
|
56
|
-
"jsdom": "^26.
|
|
57
|
-
"mocha": "^11.
|
|
55
|
+
"eslint-plugin-jsdoc": "50.6.11",
|
|
56
|
+
"jsdom": "^26.1.0",
|
|
57
|
+
"mocha": "^11.2.2",
|
|
58
58
|
"nock": "14.0.0-beta.7",
|
|
59
59
|
"nyc": "^17.1.0",
|
|
60
60
|
"proxyquire": "^2.1.3",
|
|
61
|
-
"sinon": "^
|
|
61
|
+
"sinon": "^20.0.0",
|
|
62
62
|
"tslib": "^2.8.1",
|
|
63
|
-
"tsx": "^4.19.
|
|
64
|
-
"typescript": "~5.
|
|
63
|
+
"tsx": "^4.19.4",
|
|
64
|
+
"typescript": "~5.8.3"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@sitecore-cloudsdk/events": "^0.5.
|
|
67
|
+
"@sitecore-cloudsdk/events": "^0.5.1"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"chalk": "^4.1.2",
|
|
71
71
|
"debug": "^4.4.0",
|
|
72
|
-
"graphql": "^16.
|
|
72
|
+
"graphql": "^16.11.0",
|
|
73
73
|
"graphql-request": "^6.1.0",
|
|
74
74
|
"memory-cache": "^0.2.0",
|
|
75
75
|
"sinon-chai": "^4.0.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"description": "",
|
|
79
79
|
"types": "types/index.d.ts",
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "e13108ffd37e83ce84c60597c9c4dd699033a600",
|
|
81
81
|
"files": [
|
|
82
82
|
"dist",
|
|
83
83
|
"types",
|
|
@@ -6,6 +6,7 @@ import { HTMLLink, FetchOptions, StaticPath, RetryStrategy } from '../models';
|
|
|
6
6
|
import { PersonalizedRewriteData } from '../personalize/utils';
|
|
7
7
|
import { ErrorPages, SiteInfo, SiteResolver, GraphQLErrorPagesService, GraphQLSitePathService, GraphQLSitemapXmlService } from '../site';
|
|
8
8
|
import { SitecoreClientInit } from './models';
|
|
9
|
+
import { GraphQLRobotsService } from '../site/graphql-robots-service';
|
|
9
10
|
/**
|
|
10
11
|
* Represent a Page model returned from Edge endpoint
|
|
11
12
|
*/
|
|
@@ -39,6 +40,15 @@ export type SitemapXmlOptions = {
|
|
|
39
40
|
/** The site name to resolve the sitemap for */
|
|
40
41
|
siteName?: string;
|
|
41
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Options for fetching robots.txt content.
|
|
45
|
+
*/
|
|
46
|
+
export type RobotsOptions = {
|
|
47
|
+
/**
|
|
48
|
+
* The name of the site for which to fetch robots.txt content.
|
|
49
|
+
*/
|
|
50
|
+
siteName: string;
|
|
51
|
+
};
|
|
42
52
|
/**
|
|
43
53
|
* Contract for the Sitecore Client implementations
|
|
44
54
|
*/
|
|
@@ -53,33 +63,34 @@ export interface BaseSitecoreClient {
|
|
|
53
63
|
* Retrieves page layoutData and returns page details like language, layoutData and site info for current request
|
|
54
64
|
* @param {string} path current request path
|
|
55
65
|
* @param {PageOptions} pageOptions additional overrides like language, site name and personalization variants
|
|
56
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
66
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
57
67
|
* @returns {Page | null} page details when page layout is found and null when not
|
|
58
68
|
*/
|
|
59
69
|
getPage(path: string | string[], pageOptions?: PageOptions, fetchOptions?: FetchOptions): Promise<Page | null>;
|
|
60
70
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* @param {
|
|
64
|
-
* @
|
|
71
|
+
* Retrieves the robots.txt content for a given site name.
|
|
72
|
+
* @param {string} siteName - The name of the site for which to fetch robots.txt content.
|
|
73
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
74
|
+
* @returns {Promise<string>} A promise that resolves to the robots.txt content.
|
|
65
75
|
*/
|
|
76
|
+
getRobots(siteName: string, fetchOptions?: FetchOptions): Promise<string | null>;
|
|
66
77
|
getDictionary(routeOptions?: Partial<RouteOptions>, fetchOptions?: FetchOptions): Promise<DictionaryPhrases>;
|
|
67
78
|
/**
|
|
68
79
|
* Get error pages configured by SXA for a given site and locale
|
|
69
80
|
* @param {RouteOptions} [routeOptions] language and site to load error pages for
|
|
70
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
81
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
71
82
|
*/
|
|
72
83
|
getErrorPages(routeOptions?: RouteOptions, fetchOptions?: FetchOptions): Promise<ErrorPages | null>;
|
|
73
84
|
/**
|
|
74
85
|
* Get preview layout details based on details from EditingPreviewData input
|
|
75
86
|
* @param {EditingPreviewData | undefined} previewData preview details like route, site, language etc used to retrieve preview page and layout
|
|
76
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
87
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
77
88
|
*/
|
|
78
89
|
getPreview(previewData: EditingPreviewData | undefined, fetchOptions?: FetchOptions): Promise<Page | null>;
|
|
79
90
|
/**
|
|
80
91
|
* Get route paths for all pages in the site. Can be used for static site generation.
|
|
81
92
|
* @param {string[]} [languages] languages to fetch routes in
|
|
82
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
93
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
83
94
|
*/
|
|
84
95
|
getPagePaths(languages?: string[], fetchOptions?: FetchOptions): Promise<StaticPath[]>;
|
|
85
96
|
/**
|
|
@@ -97,9 +108,17 @@ export interface BaseSitecoreClient {
|
|
|
97
108
|
/**
|
|
98
109
|
* Retrieves sitemap XML content - either a specific sitemap or the index of all sitemaps.
|
|
99
110
|
* @param { SitemapRequestConfig} reqOptions - Configuration for sitemap retrieval
|
|
111
|
+
* @param {FetchOptions} [fetchOptions] - Additional fetchOptions Additional fetch options to override GraphQL requests
|
|
100
112
|
* @returns {Promise<string>} Promise resolving to the sitemap XML content as string
|
|
101
113
|
*/
|
|
102
|
-
getSiteMap(reqOptions: SitemapXmlOptions): Promise<string>;
|
|
114
|
+
getSiteMap(reqOptions: SitemapXmlOptions, fetchOptions?: FetchOptions): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Retrieves the robots.txt content for a given site name.
|
|
117
|
+
* @param {string} siteName - The name of the site for which to fetch robots.txt content.
|
|
118
|
+
* @param {FetchOptions} fetchOptions Additional fetch options to override GraphQL requests
|
|
119
|
+
* @returns {Promise<string>} A promise that resolves to the robots.txt content.
|
|
120
|
+
*/
|
|
121
|
+
getRobots(siteName: string, fetchOptions?: FetchOptions): Promise<string | null>;
|
|
103
122
|
}
|
|
104
123
|
export interface BaseServiceOptions {
|
|
105
124
|
defaultSite: string;
|
|
@@ -144,7 +163,7 @@ export declare class SitecoreClient implements BaseSitecoreClient {
|
|
|
144
163
|
* Get page details for a route, with layout and other details
|
|
145
164
|
* @param {string} path route path
|
|
146
165
|
* @param {PageOptions} [pageOptions] site, language and personalization variant details for route
|
|
147
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
166
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
148
167
|
* @returns {Page | null} page details
|
|
149
168
|
*/
|
|
150
169
|
getPage(path: string | string[], pageOptions?: PageOptions, fetchOptions?: FetchOptions): Promise<Page | null>;
|
|
@@ -163,28 +182,28 @@ export declare class SitecoreClient implements BaseSitecoreClient {
|
|
|
163
182
|
/**
|
|
164
183
|
* Retrieves dictionary phrases for a given site and locale.
|
|
165
184
|
* @param {RouteOptions} routeOptions - Route options containing language and site name to load dictionary for
|
|
166
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
185
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
167
186
|
* @returns {DictionaryPhrases} A promise that resolves to the dictionary phrases.
|
|
168
187
|
*/
|
|
169
188
|
getDictionary(routeOptions?: Partial<RouteOptions>, fetchOptions?: FetchOptions): Promise<DictionaryPhrases>;
|
|
170
189
|
/**
|
|
171
190
|
* Retrieves error pages for a given site and locale.
|
|
172
191
|
* @param {RouteOptions} routeOptions - Route options containing language and site name to load error pages
|
|
173
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
192
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
174
193
|
* @returns {ErrorPages | null} A promise that resolves to the error pages or null if not found.
|
|
175
194
|
*/
|
|
176
195
|
getErrorPages(routeOptions?: RouteOptions, fetchOptions?: FetchOptions): Promise<ErrorPages | null>;
|
|
177
196
|
/**
|
|
178
197
|
* Retrieves preview page and layout details
|
|
179
198
|
* @param {EditingPreviewData | undefined} previewData - The editing preview data for metadata mode.
|
|
180
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
199
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
181
200
|
* @returns {Page} preview page details
|
|
182
201
|
*/
|
|
183
202
|
getPreview(previewData: EditingPreviewData | undefined, fetchOptions?: FetchOptions): Promise<Page | null>;
|
|
184
203
|
/**
|
|
185
204
|
* Get design library page details for Design Library mode of your app
|
|
186
205
|
* @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
|
|
187
|
-
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
206
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests
|
|
188
207
|
* @returns {Page} preview page for Design Library
|
|
189
208
|
*/
|
|
190
209
|
getDesignLibraryData(designLibData: DesignLibraryRenderPreviewData, fetchOptions?: FetchOptions): Promise<Page>;
|
|
@@ -203,11 +222,21 @@ export declare class SitecoreClient implements BaseSitecoreClient {
|
|
|
203
222
|
* @throws {Error} Throws 'REDIRECT_404' if requested sitemap is not found
|
|
204
223
|
*/
|
|
205
224
|
getSiteMap(reqOptions: SitemapXmlOptions, fetchOptions?: FetchOptions): Promise<string>;
|
|
225
|
+
/**
|
|
226
|
+
* Retrieves the robots.txt content for a given site name.
|
|
227
|
+
*
|
|
228
|
+
* @param {string} siteName - The name of the site to retrieve the robots.txt for.
|
|
229
|
+
* @param {FetchOptions} [fetchOptions] - Optional fetch options.
|
|
230
|
+
* @returns {Promise<string | null>} A promise that resolves to the robots.txt content,
|
|
231
|
+
* or null if no content is found.
|
|
232
|
+
*/
|
|
233
|
+
getRobots(siteName: string, fetchOptions?: FetchOptions): Promise<string | null>;
|
|
206
234
|
/**
|
|
207
235
|
* Factory methods for creating dependencies
|
|
208
236
|
* Subclasses can override these to provide custom implementations.
|
|
209
237
|
*/
|
|
210
238
|
protected getGraphqlSitemapXMLService(siteName: string): GraphQLSitemapXmlService;
|
|
239
|
+
protected getRobotsService(siteName: string): GraphQLRobotsService;
|
|
211
240
|
protected getBaseServiceOptions(): BaseServiceOptions;
|
|
212
241
|
protected getClientFactory(): GraphQLRequestClientFactory;
|
|
213
242
|
protected getSiteResolver(): SiteResolver;
|
package/types/config/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { SitecoreConfig, SitecoreConfigInput, SitecoreCliConfig, SitecoreCliConfigInput, ScaffoldTemplate, ComponentTemplateType, } from './models';
|
|
1
|
+
export { SitecoreConfig, SitecoreConfigInput, SitecoreCliConfig, SitecoreCliConfigInput, ScaffoldTemplate, ComponentTemplateType, DeepRequired, } from './models';
|
|
2
2
|
export { defineConfig } from './define-config';
|
|
3
3
|
export { defineCliConfig } from './define-cli-config';
|
package/types/config/models.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type SitecoreConfigInput = {
|
|
|
13
13
|
* API settings required to connect to Sitecore.
|
|
14
14
|
* Both edge and local set can be specified as JSS app will use API Key for component library
|
|
15
15
|
*/
|
|
16
|
-
api
|
|
16
|
+
api?: {
|
|
17
17
|
/**
|
|
18
18
|
* Edge endpoint credentials for Sitecore connection. Will be used to connect to SaaS XMCloud instance
|
|
19
19
|
*/
|
|
@@ -55,7 +55,7 @@ export type SitecoreConfigInput = {
|
|
|
55
55
|
* The default and fallback locale for your site.
|
|
56
56
|
* Ensure it aligns with the framework-specific settings used in your application.
|
|
57
57
|
*/
|
|
58
|
-
defaultLanguage
|
|
58
|
+
defaultLanguage?: string;
|
|
59
59
|
/**
|
|
60
60
|
* Your default site name. When using the multisite feature this variable defines the fallback site.
|
|
61
61
|
* @default empty string
|
|
@@ -63,6 +63,7 @@ export type SitecoreConfigInput = {
|
|
|
63
63
|
defaultSite?: string;
|
|
64
64
|
/**
|
|
65
65
|
* Editing secret required to support Sitecore editing and preview functionality.
|
|
66
|
+
* by default set by the JSS_EDITING_SECRET environment variable
|
|
66
67
|
*/
|
|
67
68
|
editingSecret?: string;
|
|
68
69
|
/**
|
|
@@ -132,10 +133,14 @@ export type SitecoreConfigInput = {
|
|
|
132
133
|
enabled?: boolean;
|
|
133
134
|
/**
|
|
134
135
|
* Configuration for your Sitecore Experience Edge endpoint
|
|
136
|
+
* by default set by the PERSONALIZE_MIDDLEWARE_EDGE_TIMEOUT environment variable
|
|
137
|
+
* if not set, will use the default value of 400ms
|
|
135
138
|
*/
|
|
136
139
|
edgeTimeout?: number;
|
|
137
140
|
/**
|
|
138
141
|
* Configuration for your Sitecore CDP endpoint
|
|
142
|
+
* by default set by the PERSONALIZE_MIDDLEWARE_CDP_TIMEOUT environment variable
|
|
143
|
+
* if not set, will use the default value of 400ms
|
|
139
144
|
*/
|
|
140
145
|
cdpTimeout?: number;
|
|
141
146
|
/**
|
package/types/constants.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export declare enum SitecoreTemplateId {
|
|
|
5
5
|
export declare const siteNameError = "The siteName cannot be empty";
|
|
6
6
|
export declare const SITECORE_EDGE_URL_DEFAULT = "https://edge-platform.sitecorecloud.io";
|
|
7
7
|
export declare const HIDDEN_RENDERING_NAME = "Hidden Rendering";
|
|
8
|
+
export declare const DEFAULT_SITECORE_AUTH_ENDPOINT = "https://auth.sitecorecloud.io/oauth/token";
|
|
9
|
+
export declare const DEFAULT_SITECORE_AUTH_AUDIENCE = "https://api.sitecorecloud.io";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DocumentNode } from 'graphql';
|
|
2
|
+
import { GraphQLRequestClient } from '../graphql-request-client';
|
|
3
|
+
import { FetchOptions } from '../models';
|
|
4
|
+
/**
|
|
5
|
+
* Interface representing the options for the ContentClient.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContentClientOptions {
|
|
8
|
+
/** The base URL for the Content API. */
|
|
9
|
+
url?: string;
|
|
10
|
+
/** The tenant name. */
|
|
11
|
+
tenant: string;
|
|
12
|
+
/** The environment name. */
|
|
13
|
+
environment: string;
|
|
14
|
+
/** Indicates if preview mode is enabled. */
|
|
15
|
+
preview?: boolean;
|
|
16
|
+
/** The authentication token. */
|
|
17
|
+
token: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Class representing a client for interacting with the Content API.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ContentClient {
|
|
23
|
+
endpoint: string;
|
|
24
|
+
graphqlClient: GraphQLRequestClient;
|
|
25
|
+
constructor({ url, tenant, environment, preview, token }: ContentClientOptions);
|
|
26
|
+
/**
|
|
27
|
+
* 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.
|
|
28
|
+
* @param {Partial<ContentClientOptions>} [options] - client configuration options
|
|
29
|
+
* @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.
|
|
30
|
+
* @param {string} [options.tenant] - Tenant name. If not provided, it will be read from the SITECORE_CS_TENANT environment variable
|
|
31
|
+
* @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'
|
|
32
|
+
* @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
|
|
33
|
+
* @param {string} [options.token] - Token for authentication. If not provided, it will be read from the SITECORE_CS_TOKEN environment variable.
|
|
34
|
+
* @returns {ContentClient} ContentClient instance
|
|
35
|
+
* @throws {Error} If tenant or token is not provided
|
|
36
|
+
*/
|
|
37
|
+
static createClient({ url, tenant, environment, preview, token, }?: Partial<ContentClientOptions>): ContentClient;
|
|
38
|
+
/**
|
|
39
|
+
* Execute graphql request
|
|
40
|
+
* @param {string | DocumentNode} query graphql query
|
|
41
|
+
* @param {object} variables variables for the query
|
|
42
|
+
* @param {FetchOptions} options options for configuring the request
|
|
43
|
+
* @returns {T} response data
|
|
44
|
+
*/
|
|
45
|
+
get<T>(query: string | DocumentNode, variables?: Record<string, unknown>, options?: FetchOptions): Promise<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the locale information for a given locale ID.
|
|
48
|
+
* @param {string} id - The unique identifier of the locale item.
|
|
49
|
+
* @returns A promise that resolves to the locale information associated with the specified locale ID.
|
|
50
|
+
*/
|
|
51
|
+
getLocale(id: string): Promise<import("./locales").Locale | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves all available locales from the content service.
|
|
54
|
+
* @returns A promise that resolves to an array of locales.
|
|
55
|
+
*/
|
|
56
|
+
getLocales(): Promise<import("./locales").Locale[]>;
|
|
57
|
+
}
|