@sitecore-content-sdk/core 0.2.0-beta.13 → 0.2.0-beta.15
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 +3 -2
- package/dist/cjs/tools/auth/flow.js +70 -0
- package/dist/cjs/tools/auth/index.js +20 -0
- package/dist/cjs/tools/auth/models.js +2 -0
- package/dist/cjs/tools/auth/renewal.js +82 -0
- package/dist/cjs/tools/auth/tenant-state.js +110 -0
- package/dist/cjs/tools/auth/tenant-store.js +243 -0
- package/dist/cjs/tools/index.js +26 -3
- package/dist/esm/constants.js +2 -1
- package/dist/esm/tools/auth/flow.js +67 -0
- package/dist/esm/tools/auth/index.js +4 -0
- package/dist/esm/tools/auth/models.js +1 -0
- package/dist/esm/tools/auth/renewal.js +77 -0
- package/dist/esm/tools/auth/tenant-state.js +73 -0
- package/dist/esm/tools/auth/tenant-store.js +206 -0
- package/dist/esm/tools/index.js +3 -1
- package/package.json +2 -2
- package/types/constants.d.ts +2 -1
- package/types/tools/auth/flow.d.ts +27 -0
- package/types/tools/auth/index.d.ts +4 -0
- package/types/tools/auth/models.d.ts +94 -0
- package/types/tools/auth/renewal.d.ts +22 -0
- package/types/tools/auth/tenant-state.d.ts +21 -0
- package/types/tools/auth/tenant-store.d.ts +63 -0
- package/types/tools/index.d.ts +3 -1
- package/dist/cjs/tools/auth/fetch-bearer-token.js +0 -43
- package/dist/esm/tools/auth/fetch-bearer-token.js +0 -36
- package/types/tools/auth/fetch-bearer-token.d.ts +0 -13
|
@@ -1,43 +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
|
-
const authenticateResponse = await fetch(endpoint, {
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers: {
|
|
23
|
-
'Content-Type': 'application/json',
|
|
24
|
-
},
|
|
25
|
-
body: JSON.stringify({
|
|
26
|
-
client_id: clientId,
|
|
27
|
-
client_secret: clientSecret,
|
|
28
|
-
audience: audience,
|
|
29
|
-
grant_type: 'client_credentials',
|
|
30
|
-
}),
|
|
31
|
-
});
|
|
32
|
-
if (!authenticateResponse.ok) {
|
|
33
|
-
throw new Error(`Authentication failed with status: ${authenticateResponse.status}`);
|
|
34
|
-
}
|
|
35
|
-
const jsonResponse = await authenticateResponse.json();
|
|
36
|
-
return jsonResponse.access_token;
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
console.error(chalk_1.default.red('Error authenticating with Sitecore Auth endpoint:', error));
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
exports.fetchBearerToken = fetchBearerToken;
|
|
@@ -1,36 +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
|
-
const authenticateResponse = await fetch(endpoint, {
|
|
15
|
-
method: 'POST',
|
|
16
|
-
headers: {
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify({
|
|
20
|
-
client_id: clientId,
|
|
21
|
-
client_secret: clientSecret,
|
|
22
|
-
audience: audience,
|
|
23
|
-
grant_type: 'client_credentials',
|
|
24
|
-
}),
|
|
25
|
-
});
|
|
26
|
-
if (!authenticateResponse.ok) {
|
|
27
|
-
throw new Error(`Authentication failed with status: ${authenticateResponse.status}`);
|
|
28
|
-
}
|
|
29
|
-
const jsonResponse = await authenticateResponse.json();
|
|
30
|
-
return jsonResponse.access_token;
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
console.error(chalk.red('Error authenticating with Sitecore Auth endpoint:', error));
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
@@ -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>;
|