@sitecore-content-sdk/cli 0.2.0-beta.1 → 0.2.0-beta.11

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.
Files changed (50) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/bin/sitecore-tools.js +6 -4
  3. package/dist/cjs/cli.js +8 -4
  4. package/dist/cjs/scripts/auth/index.js +26 -0
  5. package/dist/cjs/scripts/auth/list.js +36 -0
  6. package/dist/cjs/scripts/auth/login.js +112 -0
  7. package/dist/cjs/scripts/auth/logout.js +28 -0
  8. package/dist/cjs/scripts/auth/models.js +2 -0
  9. package/dist/cjs/scripts/auth/status.js +34 -0
  10. package/dist/cjs/scripts/index.js +5 -5
  11. package/dist/cjs/scripts/{build.js → project/build.js} +2 -2
  12. package/dist/cjs/scripts/project/component/index.js +55 -0
  13. package/dist/cjs/scripts/{scaffold.js → project/component/scaffold.js} +2 -2
  14. package/dist/cjs/scripts/project/index.js +56 -0
  15. package/dist/cjs/utils/auth/flow.js +72 -0
  16. package/dist/cjs/utils/auth/renewal.js +95 -0
  17. package/dist/cjs/utils/auth/tenant-state.js +91 -0
  18. package/dist/cjs/utils/auth/tenant-store.js +212 -0
  19. package/dist/esm/cli.js +8 -4
  20. package/dist/esm/scripts/auth/index.js +23 -0
  21. package/dist/esm/scripts/auth/list.js +33 -0
  22. package/dist/esm/scripts/auth/login.js +109 -0
  23. package/dist/esm/scripts/auth/logout.js +25 -0
  24. package/dist/esm/scripts/auth/models.js +1 -0
  25. package/dist/esm/scripts/auth/status.js +31 -0
  26. package/dist/esm/scripts/index.js +4 -3
  27. package/dist/esm/scripts/{build.js → project/build.js} +2 -2
  28. package/dist/esm/scripts/project/component/index.js +19 -0
  29. package/dist/esm/scripts/{scaffold.js → project/component/scaffold.js} +2 -2
  30. package/dist/esm/scripts/project/index.js +20 -0
  31. package/dist/esm/utils/auth/flow.js +68 -0
  32. package/dist/esm/utils/auth/renewal.js +90 -0
  33. package/dist/esm/utils/auth/tenant-state.js +53 -0
  34. package/dist/esm/utils/auth/tenant-store.js +170 -0
  35. package/package.json +14 -15
  36. package/types/scripts/auth/index.d.ts +7 -0
  37. package/types/scripts/auth/list.d.ts +2 -0
  38. package/types/scripts/auth/login.d.ts +3 -0
  39. package/types/scripts/auth/logout.d.ts +2 -0
  40. package/types/scripts/auth/models.d.ts +94 -0
  41. package/types/scripts/auth/status.d.ts +2 -0
  42. package/types/scripts/index.d.ts +4 -3
  43. package/types/scripts/{build.d.ts → project/build.d.ts} +1 -1
  44. package/types/scripts/project/component/index.d.ts +5 -0
  45. package/types/scripts/project/index.d.ts +5 -0
  46. package/types/utils/auth/flow.d.ts +24 -0
  47. package/types/utils/auth/renewal.d.ts +22 -0
  48. package/types/utils/auth/tenant-state.d.ts +14 -0
  49. package/types/utils/auth/tenant-store.d.ts +40 -0
  50. /package/types/scripts/{scaffold.d.ts → project/component/scaffold.d.ts} +0 -0
@@ -0,0 +1,68 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { decodeJwtPayload } from './tenant-store';
11
+ export const AUTH0_DOMAIN = 'https://auth.sitecorecloud.io';
12
+ export const AUDIENCE = 'https://api.sitecorecloud.io';
13
+ export const BASE_URL = 'https://edge-platform.sitecorecloud.io/cs/api';
14
+ const GRANT_TYPE = 'client_credentials';
15
+ /**
16
+ * Performs the OAuth 2.0 client credentials flow to obtain a JWT access token
17
+ * from the Sitecore Identity Provider using the provided client credentials.
18
+ * @param {object} [args] - The arguments for client credentials flow
19
+ * @param {string} [args.clientId] - The client ID registered with Sitecore Identity
20
+ * @param {string} [args.clientSecret] - The client secret associated with the client ID
21
+ * @param {string} [args.organizationId] - The ID of the organization the client belongs to
22
+ * @param {string} [args.tenantId] - The tenant ID representing the specific Sitecore environment
23
+ * @param {string} [args.audience] - The API audience the token is intended for. Defaults to `AUDIENCE`
24
+ * @param {string} [args.authority] - The auth server base URL. Defaults to `AUTH0_DOMAIN`
25
+ * @param {string} [args.baseUrl] - The base URL for the API, used to construct the audience
26
+ * @returns A Promise that resolves to the access token response (including access token, token type, expiry, etc.)
27
+ * @throws Will log and exit the process if the request fails or returns a non-OK status
28
+ */
29
+ export function clientCredentialsFlow(_a) {
30
+ return __awaiter(this, arguments, void 0, function* ({ clientId, clientSecret, organizationId, tenantId, audience = AUDIENCE, authority = AUTH0_DOMAIN, baseUrl = BASE_URL, }) {
31
+ const params = new URLSearchParams({
32
+ client_id: clientId,
33
+ client_secret: clientSecret !== null && clientSecret !== void 0 ? clientSecret : '',
34
+ organization_id: organizationId !== null && organizationId !== void 0 ? organizationId : '',
35
+ tenant_id: tenantId !== null && tenantId !== void 0 ? tenantId : '',
36
+ audience,
37
+ grant_type: GRANT_TYPE,
38
+ baseUrl: baseUrl !== null && baseUrl !== void 0 ? baseUrl : '',
39
+ });
40
+ try {
41
+ const response = yield fetch(`${authority}/oauth/token`, {
42
+ method: 'POST',
43
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
44
+ body: params.toString(),
45
+ });
46
+ const data = yield response.json();
47
+ if (!response.ok) {
48
+ throw new Error(data.error_description || data.error || 'Error during client credentials flow');
49
+ }
50
+ const decodedPayload = decodeJwtPayload(data.access_token) || {};
51
+ if (!(decodedPayload === null || decodedPayload === void 0 ? void 0 : decodedPayload.tokenTenantId) || !decodedPayload.tokenOrgId) {
52
+ throw new Error('\n Token is missing required claims tenant_id or org_id.');
53
+ }
54
+ const { tokenTenantId, tokenOrgId, tokenTenantName } = decodedPayload;
55
+ if (tenantId && tenantId !== tokenTenantId) {
56
+ throw new Error('\n Mismatch: Provided tenant ID does not match claims tenant ID.');
57
+ }
58
+ if (organizationId && organizationId !== tokenOrgId) {
59
+ throw new Error('\n Mismatch: Provided organization ID does not match claims organization ID.');
60
+ }
61
+ return { data, tokenOrgId, tokenTenantId, tokenTenantName };
62
+ }
63
+ catch (error) {
64
+ console.error('\n Error during client credentials flow:', error instanceof Error ? error.message : error);
65
+ throw error;
66
+ }
67
+ });
68
+ }
@@ -0,0 +1,90 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getActiveTenant, clearActiveTenant } from './tenant-state';
11
+ import { clientCredentialsFlow } from './flow';
12
+ import { writeTenantAuthInfo, readTenantAuthInfo, deleteTenantAuthInfo, readTenantInfo, } from './tenant-store';
13
+ /**
14
+ * Validates whether a given auth config is still valid (i.e., not expired).
15
+ * @param {TenantAuth} authInfo - The tenant auth configuration.
16
+ * @returns True if the token is still valid, false if expired.
17
+ */
18
+ export function validateAuthInfo(authInfo) {
19
+ const now = new Date();
20
+ const expiry = new Date(authInfo.expires_at);
21
+ return now < expiry;
22
+ }
23
+ /**
24
+ * Renews the token for a given tenant using stored credentials.
25
+ * @param {TenantAuth} authInfo - Current authentication info for the tenant.
26
+ * @param {TenantInfo} tenantInfo - Public metadata about the tenant (e.g., clientId).
27
+ * @returns Promise<void>
28
+ * @throws If credentials are missing or renewal fails.
29
+ */
30
+ export function renewClientToken(authInfo, tenantInfo) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const result = yield clientCredentialsFlow({
33
+ clientId: tenantInfo.clientId,
34
+ clientSecret: authInfo.clientSecret,
35
+ organizationId: tenantInfo.organizationId,
36
+ tenantId: tenantInfo.tenantId,
37
+ audience: tenantInfo.audience,
38
+ authority: tenantInfo.authority,
39
+ baseUrl: tenantInfo.baseUrl,
40
+ });
41
+ const tenantId = tenantInfo.tenantId;
42
+ yield writeTenantAuthInfo(tenantId, {
43
+ clientSecret: authInfo.clientSecret,
44
+ access_token: result.data.access_token,
45
+ expires_in: result.data.expires_in,
46
+ expires_at: new Date(Date.now() + result.data.expires_in * 1000).toISOString(),
47
+ });
48
+ console.info(`\n Token for tenant ${tenantId} renewed.`);
49
+ });
50
+ }
51
+ /**
52
+ * Ensures a valid token exists, renews it if expired.
53
+ * Returns tenant context if successful, otherwise null.
54
+ */
55
+ export function renewAuthIfExpired() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const tenantId = getActiveTenant();
58
+ if (!tenantId)
59
+ return null;
60
+ const authInfo = yield readTenantAuthInfo(tenantId);
61
+ if (!authInfo)
62
+ return null;
63
+ const isValid = validateAuthInfo(authInfo);
64
+ if (isValid) {
65
+ return { tenantId };
66
+ }
67
+ const tenantInfo = yield readTenantInfo(tenantId);
68
+ if (!tenantInfo)
69
+ return null;
70
+ console.info(`\n Token for tenant ${tenantId} is expired. Renewing...`);
71
+ try {
72
+ if (authInfo.clientSecret) {
73
+ yield renewClientToken(authInfo, tenantInfo);
74
+ }
75
+ else {
76
+ // <TODO>: Implement Device auth token renewal.
77
+ throw new Error('\n Please use clientSecret for authentication.');
78
+ }
79
+ return { tenantId };
80
+ }
81
+ catch (err) {
82
+ console.error(`\n Failed to renew token for tenant '${tenantId}'`);
83
+ console.warn(`\n Cleaning up stale authentication data for tenant '${tenantId}'...`);
84
+ yield deleteTenantAuthInfo(tenantId);
85
+ clearActiveTenant();
86
+ console.info('\n You will need to login again to re-authenticate.');
87
+ process.exit(1);
88
+ }
89
+ });
90
+ }
@@ -0,0 +1,53 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as os from 'os';
4
+ const configDir = path.join(os.homedir(), '.sitecore', 'sitecore-tools');
5
+ const settingsFile = path.join(configDir, 'settings.json');
6
+ /**
7
+ * Gets the ID of the currently active tenant from settings.json.
8
+ * @returns The active tenant ID if present, otherwise null.
9
+ */
10
+ export function getActiveTenant() {
11
+ var _a;
12
+ if (!fs.existsSync(settingsFile)) {
13
+ return null;
14
+ }
15
+ try {
16
+ const content = fs.readFileSync(settingsFile, 'utf-8');
17
+ const data = JSON.parse(content);
18
+ return (_a = data.activeTenant) !== null && _a !== void 0 ? _a : null;
19
+ }
20
+ catch (error) {
21
+ console.error(`\n Failed to read active tenant: ${error.message}`);
22
+ return null;
23
+ }
24
+ }
25
+ /**
26
+ * Sets the currently active tenant by writing to settings.json.
27
+ * @param {string} tenantId - The tenant ID to set as active.
28
+ */
29
+ export function setActiveTenant(tenantId) {
30
+ try {
31
+ if (!fs.existsSync(configDir)) {
32
+ fs.mkdirSync(configDir, { recursive: true });
33
+ }
34
+ const data = { activeTenant: tenantId };
35
+ fs.writeFileSync(settingsFile, JSON.stringify(data, null, 2));
36
+ }
37
+ catch (error) {
38
+ console.error(`\n Failed to set active tenant '${tenantId}': ${error.message}`);
39
+ }
40
+ }
41
+ /**
42
+ * Clears the currently active tenant from settings.json by deleting the file.
43
+ */
44
+ export function clearActiveTenant() {
45
+ try {
46
+ if (fs.existsSync(settingsFile)) {
47
+ fs.unlinkSync(settingsFile);
48
+ }
49
+ }
50
+ catch (error) {
51
+ console.error(`\n Failed to clear active tenant: ${error.message}`);
52
+ }
53
+ }
@@ -0,0 +1,170 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as fs from 'fs';
11
+ import * as path from 'path';
12
+ import * as os from 'os';
13
+ const CLAIMS = 'https://auth.sitecorecloud.io/claims';
14
+ const rootDir = path.join(os.homedir(), '.sitecore', 'sitecore-tools');
15
+ /**
16
+ * Get the full path to the tenant-specific folder.
17
+ * @param {string} tenantId - The tenant ID.
18
+ * @returns The absolute path to the tenant directory.
19
+ */
20
+ function getTenantPath(tenantId) {
21
+ return path.join(rootDir, tenantId);
22
+ }
23
+ /**
24
+ * Write the authentication configuration for a tenant.
25
+ * @param {string} tenantId - The tenant ID.
26
+ * @param {TenantAuth} authInfo - The tenant's auth data.
27
+ */
28
+ export function writeTenantAuthInfo(tenantId, authInfo) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ try {
31
+ const dir = getTenantPath(tenantId);
32
+ fs.mkdirSync(dir, { recursive: true });
33
+ fs.writeFileSync(path.join(dir, 'auth.json'), JSON.stringify(authInfo, null, 2));
34
+ }
35
+ catch (error) {
36
+ console.error(`\n Failed to write auth.json for tenant '${tenantId}': ${error.message}`);
37
+ }
38
+ });
39
+ }
40
+ /**
41
+ * Read the authentication configuration for a tenant.
42
+ * @param {string} tenantId - The tenant ID.
43
+ * @returns Parsed auth config or null if not found or failed to read.
44
+ */
45
+ export function readTenantAuthInfo(tenantId) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const filePath = path.join(getTenantPath(tenantId), 'auth.json');
48
+ if (!fs.existsSync(filePath))
49
+ return null;
50
+ try {
51
+ const raw = fs.readFileSync(filePath, 'utf-8');
52
+ return JSON.parse(raw);
53
+ }
54
+ catch (error) {
55
+ console.error(`\n Failed to read auth.json for tenant '${tenantId}': ${error.message}`);
56
+ return null;
57
+ }
58
+ });
59
+ }
60
+ /**
61
+ * Write the public metadata information for a tenant.
62
+ * @param {TenantInfo} info - The tenant info object.
63
+ */
64
+ export function writeTenantInfo(info) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ try {
67
+ const dir = getTenantPath(info.tenantId);
68
+ fs.mkdirSync(dir, { recursive: true });
69
+ fs.writeFileSync(path.join(dir, 'info.json'), JSON.stringify(info, null, 2));
70
+ }
71
+ catch (error) {
72
+ console.error(`\n Failed to write info.json for tenant '${info.tenantId}': ${error.message}`);
73
+ }
74
+ });
75
+ }
76
+ /**
77
+ * Read the public metadata information for a tenant.
78
+ * @param {string} tenantId - The tenant ID.
79
+ * @returns Parsed tenant info or null if not found or failed to read.
80
+ */
81
+ export function readTenantInfo(tenantId) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ const infoFilePath = path.join(getTenantPath(tenantId), 'info.json');
84
+ if (!fs.existsSync(infoFilePath)) {
85
+ return null;
86
+ }
87
+ try {
88
+ const content = fs.readFileSync(infoFilePath, 'utf-8');
89
+ return JSON.parse(content);
90
+ }
91
+ catch (error) {
92
+ console.error(`\n Failed to read info.json for tenant '${tenantId}': ${error.message}`);
93
+ return null;
94
+ }
95
+ });
96
+ }
97
+ /**
98
+ * Deletes the stored auth.json file for the given tenant.
99
+ * @param {string} tenantId - The tenant ID.
100
+ */
101
+ export function deleteTenantAuthInfo(tenantId) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ const filePath = path.join(getTenantPath(tenantId), 'auth.json');
104
+ try {
105
+ if (fs.existsSync(filePath)) {
106
+ fs.unlinkSync(filePath);
107
+ }
108
+ }
109
+ catch (error) {
110
+ console.error(`\n Failed to delete auth.json for tenant '${tenantId}': ${error.message}`);
111
+ }
112
+ });
113
+ }
114
+ /**
115
+ * Scans the CLI root directory and returns all valid tenant infos.
116
+ * @returns A list of TenantInfo objects found in {tenant-id}/info.json files.
117
+ */
118
+ export function getAllTenantsInfo() {
119
+ if (!fs.existsSync(rootDir))
120
+ return [];
121
+ const subDirs = fs
122
+ .readdirSync(rootDir)
123
+ .filter((entry) => fs.statSync(path.join(rootDir, entry)).isDirectory());
124
+ const tenants = [];
125
+ for (const dir of subDirs) {
126
+ const infoPath = path.join(rootDir, dir, 'info.json');
127
+ if (fs.existsSync(infoPath)) {
128
+ try {
129
+ const content = fs.readFileSync(infoPath, 'utf-8');
130
+ const data = JSON.parse(content);
131
+ if (data.tenantId && data.tenantName && data.organizationId && data.clientId) {
132
+ tenants.push({
133
+ tenantId: data.tenantId,
134
+ tenantName: data.tenantName,
135
+ organizationId: data.organizationId,
136
+ clientId: data.clientId,
137
+ authority: data.authority,
138
+ audience: data.audience,
139
+ baseUrl: data.baseUrl,
140
+ });
141
+ }
142
+ }
143
+ catch (error) {
144
+ console.error('\n Failed to read tenant info file', error.message);
145
+ }
146
+ }
147
+ }
148
+ return tenants;
149
+ }
150
+ /**
151
+ * Decodes a JWT without verifying its signature.
152
+ * @param {string} token - The access token string.
153
+ * @returns Decoded payload object or null if invalid.
154
+ */
155
+ export function decodeJwtPayload(token) {
156
+ try {
157
+ const base64Payload = token.split('.')[1];
158
+ const payload = Buffer.from(base64Payload, 'base64').toString('utf-8');
159
+ const decoded = JSON.parse(payload);
160
+ return {
161
+ tokenTenantId: decoded === null || decoded === void 0 ? void 0 : decoded[`${CLAIMS}/tenant_id`],
162
+ tokenOrgId: decoded === null || decoded === void 0 ? void 0 : decoded[`${CLAIMS}/org_id`],
163
+ tokenTenantName: decoded === null || decoded === void 0 ? void 0 : decoded[`${CLAIMS}/tenant_name`],
164
+ };
165
+ }
166
+ catch (error) {
167
+ console.error('\n Failed to decode access token:', error.message);
168
+ return null;
169
+ }
170
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/cli",
3
- "version": "0.2.0-beta.1",
3
+ "version": "0.2.0-beta.11",
4
4
  "description": "Sitecore Content SDK CLI",
5
5
  "main": "dist/cjs/cli.js",
6
6
  "module": "dist/esm/cli.js",
@@ -34,34 +34,33 @@
34
34
  "url": "https://github.com/sitecore/content-sdk/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@sitecore-content-sdk/core": "0.2.0-beta.1",
38
- "dotenv": "^16.4.7",
39
- "dotenv-expand": "^12.0.1",
37
+ "@sitecore-content-sdk/core": "0.2.0-beta.11",
38
+ "dotenv": "^16.5.0",
39
+ "dotenv-expand": "^12.0.2",
40
40
  "resolve": "^1.22.10",
41
41
  "tmp": "^0.2.3",
42
- "tsx": "^4.19.3",
42
+ "tsx": "^4.19.4",
43
43
  "yargs": "^17.7.2"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/chai": "^4.2.4",
46
+ "@types/chai": "^5.2.2",
47
47
  "@types/mocha": "^10.0.10",
48
- "@types/node": "^22.13.0",
48
+ "@types/node": "^22.15.13",
49
49
  "@types/resolve": "^1.20.6",
50
- "@types/sinon": "^10.0.13",
50
+ "@types/sinon": "^17.0.4",
51
51
  "@types/tmp": "^0.2.6",
52
52
  "@types/yargs": "^17.0.33",
53
- "chai": "^4.3.7",
54
- "cross-env": "^7.0.3",
55
- "del-cli": "^5.0.0",
53
+ "chai": "^4.4.1",
54
+ "del-cli": "^6.0.0",
56
55
  "eslint": "^8.56.0",
57
- "mocha": "^11.1.0",
56
+ "mocha": "^11.2.2",
58
57
  "nyc": "^17.1.0",
59
58
  "proxyquire": "^2.1.3",
60
- "sinon": "^19.0.2",
59
+ "sinon": "^20.0.0",
61
60
  "ts-node": "^10.9.1",
62
- "typescript": "~5.7.3"
61
+ "typescript": "~5.8.3"
63
62
  },
64
- "gitHead": "8e550fe21d487b1d8d2004b33bda0b131a3d094a",
63
+ "gitHead": "6333d92ea071db49f8467e4c6259c6a82ae3a69f",
65
64
  "files": [
66
65
  "dist",
67
66
  "types"
@@ -0,0 +1,7 @@
1
+ import { Argv } from 'yargs';
2
+ /**
3
+ * Registers the `auth` command group and its subcommands (`login`, `logout`, `status`, `list`) with Yargs.
4
+ * @param {Argv} yargs - The Yargs instance used to define CLI commands.
5
+ * @returns The configured Yargs command group for authentication operations.
6
+ */
7
+ export declare function builder(yargs: Argv): Argv<{}>;
@@ -0,0 +1,2 @@
1
+ import { CommandModule } from 'yargs';
2
+ export declare const list: CommandModule;
@@ -0,0 +1,3 @@
1
+ import { CommandModule } from 'yargs';
2
+ import { TenantArgs } from './models';
3
+ export declare const login: CommandModule<object, TenantArgs>;
@@ -0,0 +1,2 @@
1
+ import { CommandModule } from 'yargs';
2
+ export declare const logout: CommandModule;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * CLI arguments used for authentication and tenant identification.
3
+ */
4
+ export interface TenantArgs {
5
+ /**
6
+ * OAuth2 client ID used to identify the application
7
+ */
8
+ clientId: string;
9
+ /**
10
+ * Client secret used for client credentials flow
11
+ */
12
+ clientSecret?: string;
13
+ /**
14
+ * Organization ID associated with the tenant
15
+ */
16
+ organizationId?: string;
17
+ /**
18
+ * Tenant ID used for scoping the login
19
+ */
20
+ tenantId?: string;
21
+ /**
22
+ * OAuth2 audience (e.g., API base URL the token is intended for)
23
+ */
24
+ audience?: string;
25
+ /**
26
+ * Auth authority/issuer URL (e.g., Sitecore identity endpoint)
27
+ */
28
+ authority?: string;
29
+ /**
30
+ * Base URL for the target Sitecore Content Management API
31
+ */
32
+ baseUrl?: string;
33
+ }
34
+ export interface TenantSettings {
35
+ /**
36
+ * Currently active tenant ID tracked by the CLI
37
+ */
38
+ activeTenant?: string;
39
+ }
40
+ /**
41
+ * Auth configuration stored per tenant for accessing Sitecore APIs.
42
+ */
43
+ export interface TenantAuth {
44
+ /**
45
+ * Access token issued by the identity provider
46
+ */
47
+ access_token: string;
48
+ /**
49
+ * Token expiration duration in seconds
50
+ */
51
+ expires_in: number;
52
+ /**
53
+ * Exact ISO timestamp when the token expires
54
+ */
55
+ expires_at: string;
56
+ /**
57
+ * Secret used for client credentials flow and re-authenticate
58
+ */
59
+ clientSecret?: string;
60
+ refresh_token?: string;
61
+ }
62
+ /**
63
+ * Public metadata for a known tenant.
64
+ */
65
+ export interface TenantInfo {
66
+ /**
67
+ * Unique ID of the tenant
68
+ */
69
+ tenantId: string;
70
+ /**
71
+ * Human-readable name of the tenant
72
+ */
73
+ tenantName: string;
74
+ /**
75
+ * Organization ID the tenant belongs to
76
+ */
77
+ organizationId: string;
78
+ /**
79
+ * Client ID associated with this tenant's authentication
80
+ */
81
+ clientId: string;
82
+ /**
83
+ * OAuth2 audience (e.g., API base URL the token is intended for)
84
+ */
85
+ audience: string;
86
+ /**
87
+ * Auth authority/issuer URL (e.g., Sitecore identity endpoint)
88
+ */
89
+ authority: string;
90
+ /**
91
+ * Base URL for the target Sitecore Content Management API
92
+ */
93
+ baseUrl: string;
94
+ }
@@ -0,0 +1,2 @@
1
+ import { CommandModule } from 'yargs';
2
+ export declare const status: CommandModule;
@@ -1,3 +1,4 @@
1
- import * as build from './build';
2
- import * as scaffold from './scaffold';
3
- export { build, scaffold };
1
+ import * as project from './project';
2
+ import * as auth from './auth';
3
+ export { project };
4
+ export { auth };
@@ -1,5 +1,5 @@
1
1
  export declare const command = "build";
2
- export declare const describe = "Handles build time automation";
2
+ export declare const describe = "Performs build time automation";
3
3
  export declare const builder: {
4
4
  config: {
5
5
  requiresArg: boolean;
@@ -0,0 +1,5 @@
1
+ import { Argv } from 'yargs';
2
+ /**
3
+ * @param {Argv} yargs
4
+ */
5
+ export declare function builder(yargs: Argv): Argv<{}>;
@@ -0,0 +1,5 @@
1
+ import { Argv } from 'yargs';
2
+ /**
3
+ * @param {Argv} yargs
4
+ */
5
+ export declare function builder(yargs: Argv): Argv<{}>;
@@ -0,0 +1,24 @@
1
+ import { TenantArgs } from '../../scripts/auth/models';
2
+ export declare const AUTH0_DOMAIN = "https://auth.sitecorecloud.io";
3
+ export declare const AUDIENCE = "https://api.sitecorecloud.io";
4
+ export declare const BASE_URL = "https://edge-platform.sitecorecloud.io/cs/api";
5
+ /**
6
+ * Performs the OAuth 2.0 client credentials flow to obtain a JWT access token
7
+ * from the Sitecore Identity Provider using the provided client credentials.
8
+ * @param {object} [args] - The arguments for client credentials flow
9
+ * @param {string} [args.clientId] - The client ID registered with Sitecore Identity
10
+ * @param {string} [args.clientSecret] - The client secret associated with the client ID
11
+ * @param {string} [args.organizationId] - The ID of the organization the client belongs to
12
+ * @param {string} [args.tenantId] - The tenant ID representing the specific Sitecore environment
13
+ * @param {string} [args.audience] - The API audience the token is intended for. Defaults to `AUDIENCE`
14
+ * @param {string} [args.authority] - The auth server base URL. Defaults to `AUTH0_DOMAIN`
15
+ * @param {string} [args.baseUrl] - The base URL for the API, used to construct the audience
16
+ * @returns A Promise that resolves to the access token response (including access token, token type, expiry, etc.)
17
+ * @throws Will log and exit the process if the request fails or returns a non-OK status
18
+ */
19
+ export declare function clientCredentialsFlow({ clientId, clientSecret, organizationId, tenantId, audience, authority, baseUrl, }: TenantArgs): Promise<{
20
+ data: any;
21
+ tokenOrgId: any;
22
+ tokenTenantId: any;
23
+ tokenTenantName: any;
24
+ }>;
@@ -0,0 +1,22 @@
1
+ import { TenantAuth, TenantInfo } from './../../scripts/auth/models';
2
+ /**
3
+ * Validates whether a given auth config is still valid (i.e., not expired).
4
+ * @param {TenantAuth} authInfo - The tenant auth configuration.
5
+ * @returns True if the token is still valid, false if expired.
6
+ */
7
+ export declare function validateAuthInfo(authInfo: TenantAuth): boolean;
8
+ /**
9
+ * Renews the token for a given tenant using stored credentials.
10
+ * @param {TenantAuth} authInfo - Current authentication info for the tenant.
11
+ * @param {TenantInfo} tenantInfo - Public metadata about the tenant (e.g., clientId).
12
+ * @returns Promise<void>
13
+ * @throws If credentials are missing or renewal fails.
14
+ */
15
+ export declare function renewClientToken(authInfo: TenantAuth, tenantInfo: TenantInfo): Promise<void>;
16
+ /**
17
+ * Ensures a valid token exists, renews it if expired.
18
+ * Returns tenant context if successful, otherwise null.
19
+ */
20
+ export declare function renewAuthIfExpired(): Promise<{
21
+ tenantId: string;
22
+ } | null>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Gets the ID of the currently active tenant from settings.json.
3
+ * @returns The active tenant ID if present, otherwise null.
4
+ */
5
+ export declare function getActiveTenant(): string | null;
6
+ /**
7
+ * Sets the currently active tenant by writing to settings.json.
8
+ * @param {string} tenantId - The tenant ID to set as active.
9
+ */
10
+ export declare function setActiveTenant(tenantId: string): void;
11
+ /**
12
+ * Clears the currently active tenant from settings.json by deleting the file.
13
+ */
14
+ export declare function clearActiveTenant(): void;