@sitecore-content-sdk/core 0.2.0-canary.32 → 0.2.0-canary.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.js +1 -3
- package/dist/cjs/debug.js +0 -1
- package/dist/cjs/tools/index.js +1 -3
- package/dist/esm/constants.js +0 -2
- package/dist/esm/debug.js +0 -1
- package/dist/esm/tools/index.js +0 -1
- package/package.json +3 -3
- package/types/constants.d.ts +0 -2
- package/types/debug.d.ts +0 -1
- package/types/tools/index.d.ts +0 -1
- package/content.d.ts +0 -1
- package/content.js +0 -1
- package/dist/cjs/content/content-client.js +0 -87
- package/dist/cjs/content/index.js +0 -10
- package/dist/cjs/content/locales.js +0 -28
- package/dist/cjs/content/utils.js +0 -16
- package/dist/cjs/tools/auth/fetch-bearer-token.js +0 -41
- package/dist/esm/content/content-client.js +0 -80
- package/dist/esm/content/index.js +0 -3
- package/dist/esm/content/locales.js +0 -25
- package/dist/esm/content/utils.js +0 -13
- package/dist/esm/tools/auth/fetch-bearer-token.js +0 -34
- package/types/content/content-client.d.ts +0 -57
- package/types/content/index.d.ts +0 -3
- package/types/content/locales.d.ts +0 -32
- package/types/content/utils.d.ts +0 -15
- package/types/tools/auth/fetch-bearer-token.d.ts +0 -13
package/dist/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
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,5 +11,3 @@ 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';
|
package/dist/cjs/debug.js
CHANGED
|
@@ -29,7 +29,6 @@ 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`),
|
|
33
32
|
form: (0, debug_1.default)(`${rootNamespace}:form`),
|
|
34
33
|
http: (0, debug_1.default)(`${rootNamespace}:http`),
|
|
35
34
|
layout: (0, debug_1.default)(`${rootNamespace}:layout`),
|
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.
|
|
17
|
+
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,5 +22,3 @@ 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/esm/constants.js
CHANGED
|
@@ -8,5 +8,3 @@ 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';
|
package/dist/esm/debug.js
CHANGED
|
@@ -22,7 +22,6 @@ export const enableDebug = (namespaces) => debug.enable(namespaces);
|
|
|
22
22
|
*/
|
|
23
23
|
export default {
|
|
24
24
|
common: debug(`${rootNamespace}:common`),
|
|
25
|
-
content: debug(`${rootNamespace}:content`),
|
|
26
25
|
form: debug(`${rootNamespace}:form`),
|
|
27
26
|
http: debug(`${rootNamespace}:http`),
|
|
28
27
|
layout: debug(`${rootNamespace}:layout`),
|
package/dist/esm/tools/index.js
CHANGED
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.35",
|
|
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/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
|
|
18
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/core --entryPoints src/index.ts --entryPoints src/config/index.ts --entryPoints src/client/index.ts --entryPoints src/i18n/index.ts --entryPoints src/layout/index.ts --entryPoints src/media/index.ts --entryPoints src/personalize/index.ts --entryPoints src/site/index.ts --entryPoints src/tracking/index.ts --entryPoints src/utils/index.ts --entryPoints src/editing/index.ts --entryPoints src/tools/index.ts --githubPages false"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=22"
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"description": "",
|
|
79
79
|
"types": "types/index.d.ts",
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "e1ce87887d0063d8d8e535f6ac410ebaddd3b3c7",
|
|
81
81
|
"files": [
|
|
82
82
|
"dist",
|
|
83
83
|
"types",
|
package/types/constants.d.ts
CHANGED
|
@@ -5,5 +5,3 @@ 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";
|
package/types/debug.d.ts
CHANGED
package/types/tools/index.d.ts
CHANGED
package/content.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './types/content/index';
|
package/content.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/cjs/content/index');
|
|
@@ -1,87 +0,0 @@
|
|
|
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;
|
|
@@ -1,10 +0,0 @@
|
|
|
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; } });
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
`;
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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;
|
|
@@ -1,80 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
`;
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
}
|
package/types/content/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the response structure for a query that retrieves a locale.
|
|
3
|
-
*/
|
|
4
|
-
export interface LocaleQueryResponse {
|
|
5
|
-
locale: Locale | null;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Represents the response structure for a query that retrieves multiple locales.
|
|
9
|
-
*/
|
|
10
|
-
export interface LocalesQueryResponse {
|
|
11
|
-
manyLocale: Locale[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Represents a locale with an id and a label.
|
|
15
|
-
*/
|
|
16
|
-
export type Locale = {
|
|
17
|
-
/** The unique identifier for the locale. */
|
|
18
|
-
id: string;
|
|
19
|
-
/** The display name or label for the locale. */
|
|
20
|
-
label: string;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* GraphQL query to retrieve a specific locale by its ID.
|
|
24
|
-
*
|
|
25
|
-
* Variables:
|
|
26
|
-
* - id: The ID of the locale to retrieve.
|
|
27
|
-
*/
|
|
28
|
-
export declare const GET_LOCALE_QUERY = "\n query GetLocaleById ($id: ID!) {\n locale(id: $id) {\n id\n label\n }\n }\n";
|
|
29
|
-
/**
|
|
30
|
-
* GraphQL query to retrieve all available locales.
|
|
31
|
-
*/
|
|
32
|
-
export declare const GET_LOCALES_QUERY = "\n query GetAllLocales{\n manyLocale {\n id\n label\n }\n }\n";
|
package/types/content/utils.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the Content graphql endpoint url
|
|
3
|
-
* @param {object} params Parameters
|
|
4
|
-
* @param {string} [params.url] Content base graphql endpoint url
|
|
5
|
-
* @param {string} params.tenant Tenant name
|
|
6
|
-
* @param {string} params.environment Environment name
|
|
7
|
-
* @param {boolean} params.preview Indicates if preview mode is enabled
|
|
8
|
-
* @returns {string} Content graphql endpoint url
|
|
9
|
-
*/
|
|
10
|
-
export declare function getContentUrl({ url, tenant, environment, preview, }: {
|
|
11
|
-
url?: string;
|
|
12
|
-
tenant: string;
|
|
13
|
-
environment: string;
|
|
14
|
-
preview: boolean;
|
|
15
|
-
}): string;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type FetchBearerTokenOptions = {
|
|
2
|
-
clientId: string;
|
|
3
|
-
clientSecret: string;
|
|
4
|
-
audience?: string;
|
|
5
|
-
endpoint?: string;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Connects to M2M endpoint and fetches the bearer token
|
|
9
|
-
* Uses client_id and client_secret from environment variables
|
|
10
|
-
* @param {FetchBearerTokenOptions} options client id, secret, and other parameters for connection to m2m endpoint
|
|
11
|
-
* @returns {string} bearer token string
|
|
12
|
-
*/
|
|
13
|
-
export declare const fetchBearerToken: (options: FetchBearerTokenOptions) => Promise<any>;
|