@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,91 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getActiveTenant = getActiveTenant;
37
+ exports.setActiveTenant = setActiveTenant;
38
+ exports.clearActiveTenant = clearActiveTenant;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const os = __importStar(require("os"));
42
+ const configDir = path.join(os.homedir(), '.sitecore', 'sitecore-tools');
43
+ const settingsFile = path.join(configDir, 'settings.json');
44
+ /**
45
+ * Gets the ID of the currently active tenant from settings.json.
46
+ * @returns The active tenant ID if present, otherwise null.
47
+ */
48
+ function getActiveTenant() {
49
+ var _a;
50
+ if (!fs.existsSync(settingsFile)) {
51
+ return null;
52
+ }
53
+ try {
54
+ const content = fs.readFileSync(settingsFile, 'utf-8');
55
+ const data = JSON.parse(content);
56
+ return (_a = data.activeTenant) !== null && _a !== void 0 ? _a : null;
57
+ }
58
+ catch (error) {
59
+ console.error(`\n Failed to read active tenant: ${error.message}`);
60
+ return null;
61
+ }
62
+ }
63
+ /**
64
+ * Sets the currently active tenant by writing to settings.json.
65
+ * @param {string} tenantId - The tenant ID to set as active.
66
+ */
67
+ function setActiveTenant(tenantId) {
68
+ try {
69
+ if (!fs.existsSync(configDir)) {
70
+ fs.mkdirSync(configDir, { recursive: true });
71
+ }
72
+ const data = { activeTenant: tenantId };
73
+ fs.writeFileSync(settingsFile, JSON.stringify(data, null, 2));
74
+ }
75
+ catch (error) {
76
+ console.error(`\n Failed to set active tenant '${tenantId}': ${error.message}`);
77
+ }
78
+ }
79
+ /**
80
+ * Clears the currently active tenant from settings.json by deleting the file.
81
+ */
82
+ function clearActiveTenant() {
83
+ try {
84
+ if (fs.existsSync(settingsFile)) {
85
+ fs.unlinkSync(settingsFile);
86
+ }
87
+ }
88
+ catch (error) {
89
+ console.error(`\n Failed to clear active tenant: ${error.message}`);
90
+ }
91
+ }
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.writeTenantAuthInfo = writeTenantAuthInfo;
46
+ exports.readTenantAuthInfo = readTenantAuthInfo;
47
+ exports.writeTenantInfo = writeTenantInfo;
48
+ exports.readTenantInfo = readTenantInfo;
49
+ exports.deleteTenantAuthInfo = deleteTenantAuthInfo;
50
+ exports.getAllTenantsInfo = getAllTenantsInfo;
51
+ exports.decodeJwtPayload = decodeJwtPayload;
52
+ const fs = __importStar(require("fs"));
53
+ const path = __importStar(require("path"));
54
+ const os = __importStar(require("os"));
55
+ const CLAIMS = 'https://auth.sitecorecloud.io/claims';
56
+ const rootDir = path.join(os.homedir(), '.sitecore', 'sitecore-tools');
57
+ /**
58
+ * Get the full path to the tenant-specific folder.
59
+ * @param {string} tenantId - The tenant ID.
60
+ * @returns The absolute path to the tenant directory.
61
+ */
62
+ function getTenantPath(tenantId) {
63
+ return path.join(rootDir, tenantId);
64
+ }
65
+ /**
66
+ * Write the authentication configuration for a tenant.
67
+ * @param {string} tenantId - The tenant ID.
68
+ * @param {TenantAuth} authInfo - The tenant's auth data.
69
+ */
70
+ function writeTenantAuthInfo(tenantId, authInfo) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ try {
73
+ const dir = getTenantPath(tenantId);
74
+ fs.mkdirSync(dir, { recursive: true });
75
+ fs.writeFileSync(path.join(dir, 'auth.json'), JSON.stringify(authInfo, null, 2));
76
+ }
77
+ catch (error) {
78
+ console.error(`\n Failed to write auth.json for tenant '${tenantId}': ${error.message}`);
79
+ }
80
+ });
81
+ }
82
+ /**
83
+ * Read the authentication configuration for a tenant.
84
+ * @param {string} tenantId - The tenant ID.
85
+ * @returns Parsed auth config or null if not found or failed to read.
86
+ */
87
+ function readTenantAuthInfo(tenantId) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const filePath = path.join(getTenantPath(tenantId), 'auth.json');
90
+ if (!fs.existsSync(filePath))
91
+ return null;
92
+ try {
93
+ const raw = fs.readFileSync(filePath, 'utf-8');
94
+ return JSON.parse(raw);
95
+ }
96
+ catch (error) {
97
+ console.error(`\n Failed to read auth.json for tenant '${tenantId}': ${error.message}`);
98
+ return null;
99
+ }
100
+ });
101
+ }
102
+ /**
103
+ * Write the public metadata information for a tenant.
104
+ * @param {TenantInfo} info - The tenant info object.
105
+ */
106
+ function writeTenantInfo(info) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ try {
109
+ const dir = getTenantPath(info.tenantId);
110
+ fs.mkdirSync(dir, { recursive: true });
111
+ fs.writeFileSync(path.join(dir, 'info.json'), JSON.stringify(info, null, 2));
112
+ }
113
+ catch (error) {
114
+ console.error(`\n Failed to write info.json for tenant '${info.tenantId}': ${error.message}`);
115
+ }
116
+ });
117
+ }
118
+ /**
119
+ * Read the public metadata information for a tenant.
120
+ * @param {string} tenantId - The tenant ID.
121
+ * @returns Parsed tenant info or null if not found or failed to read.
122
+ */
123
+ function readTenantInfo(tenantId) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const infoFilePath = path.join(getTenantPath(tenantId), 'info.json');
126
+ if (!fs.existsSync(infoFilePath)) {
127
+ return null;
128
+ }
129
+ try {
130
+ const content = fs.readFileSync(infoFilePath, 'utf-8');
131
+ return JSON.parse(content);
132
+ }
133
+ catch (error) {
134
+ console.error(`\n Failed to read info.json for tenant '${tenantId}': ${error.message}`);
135
+ return null;
136
+ }
137
+ });
138
+ }
139
+ /**
140
+ * Deletes the stored auth.json file for the given tenant.
141
+ * @param {string} tenantId - The tenant ID.
142
+ */
143
+ function deleteTenantAuthInfo(tenantId) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ const filePath = path.join(getTenantPath(tenantId), 'auth.json');
146
+ try {
147
+ if (fs.existsSync(filePath)) {
148
+ fs.unlinkSync(filePath);
149
+ }
150
+ }
151
+ catch (error) {
152
+ console.error(`\n Failed to delete auth.json for tenant '${tenantId}': ${error.message}`);
153
+ }
154
+ });
155
+ }
156
+ /**
157
+ * Scans the CLI root directory and returns all valid tenant infos.
158
+ * @returns A list of TenantInfo objects found in {tenant-id}/info.json files.
159
+ */
160
+ function getAllTenantsInfo() {
161
+ if (!fs.existsSync(rootDir))
162
+ return [];
163
+ const subDirs = fs
164
+ .readdirSync(rootDir)
165
+ .filter((entry) => fs.statSync(path.join(rootDir, entry)).isDirectory());
166
+ const tenants = [];
167
+ for (const dir of subDirs) {
168
+ const infoPath = path.join(rootDir, dir, 'info.json');
169
+ if (fs.existsSync(infoPath)) {
170
+ try {
171
+ const content = fs.readFileSync(infoPath, 'utf-8');
172
+ const data = JSON.parse(content);
173
+ if (data.tenantId && data.tenantName && data.organizationId && data.clientId) {
174
+ tenants.push({
175
+ tenantId: data.tenantId,
176
+ tenantName: data.tenantName,
177
+ organizationId: data.organizationId,
178
+ clientId: data.clientId,
179
+ authority: data.authority,
180
+ audience: data.audience,
181
+ baseUrl: data.baseUrl,
182
+ });
183
+ }
184
+ }
185
+ catch (error) {
186
+ console.error('\n Failed to read tenant info file', error.message);
187
+ }
188
+ }
189
+ }
190
+ return tenants;
191
+ }
192
+ /**
193
+ * Decodes a JWT without verifying its signature.
194
+ * @param {string} token - The access token string.
195
+ * @returns Decoded payload object or null if invalid.
196
+ */
197
+ function decodeJwtPayload(token) {
198
+ try {
199
+ const base64Payload = token.split('.')[1];
200
+ const payload = Buffer.from(base64Payload, 'base64').toString('utf-8');
201
+ const decoded = JSON.parse(payload);
202
+ return {
203
+ tokenTenantId: decoded === null || decoded === void 0 ? void 0 : decoded[`${CLAIMS}/tenant_id`],
204
+ tokenOrgId: decoded === null || decoded === void 0 ? void 0 : decoded[`${CLAIMS}/org_id`],
205
+ tokenTenantName: decoded === null || decoded === void 0 ? void 0 : decoded[`${CLAIMS}/tenant_name`],
206
+ };
207
+ }
208
+ catch (error) {
209
+ console.error('\n Failed to decode access token:', error.message);
210
+ return null;
211
+ }
212
+ }
package/dist/esm/cli.js CHANGED
@@ -42,18 +42,22 @@ export default function cli(commands) {
42
42
  }
43
43
  }
44
44
  }
45
- appCommands.command({
45
+ appCommands
46
+ .command({
46
47
  command: '*',
47
48
  handler: (argv) => {
48
49
  if (argv._.length > 0) {
49
- console.error(`Command not found: "${argv._[0]}". Use --help to see available commands.`);
50
+ console.error(`Command not found: "${argv._[0]}"`);
50
51
  }
51
52
  else {
52
- console.error('No command provided. Use --help to see available commands.');
53
+ console.error('No command provided');
53
54
  }
55
+ yargs.showHelp();
54
56
  process.exit(1);
55
57
  },
56
- });
58
+ })
59
+ .demandCommand(1, 'You need to specify a command to run')
60
+ .strict();
57
61
  yield appCommands.argv;
58
62
  });
59
63
  }
@@ -0,0 +1,23 @@
1
+ import { login } from './login';
2
+ import { logout } from './logout';
3
+ import { status } from './status';
4
+ import { list } from './list';
5
+ /**
6
+ * Registers the `auth` command group and its subcommands (`login`, `logout`, `status`, `list`) with Yargs.
7
+ * @param {Argv} yargs - The Yargs instance used to define CLI commands.
8
+ * @returns The configured Yargs command group for authentication operations.
9
+ */
10
+ export function builder(yargs) {
11
+ return yargs.command({
12
+ command: 'auth',
13
+ describe: 'Performs authentication for content services',
14
+ builder: (_yargs) => {
15
+ return _yargs
16
+ .command([login, logout, status, list])
17
+ .strict()
18
+ .demandCommand(1, 'You need to specify a command to run')
19
+ .help();
20
+ },
21
+ handler: () => { },
22
+ });
23
+ }
@@ -0,0 +1,33 @@
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 { getAllTenantsInfo } from '../../utils/auth/tenant-store';
11
+ export const list = {
12
+ command: 'list',
13
+ describe: 'List all known tenants',
14
+ handler: () => __awaiter(void 0, void 0, void 0, function* () {
15
+ const tenants = getAllTenantsInfo();
16
+ if (tenants.length === 0) {
17
+ console.log('\n No tenant information found.');
18
+ return;
19
+ }
20
+ console.log('\n Known tenants:\n');
21
+ tenants.forEach((tenant, index) => {
22
+ console.log(`Tenant ${index + 1}:`);
23
+ console.log(` Tenant ID : ${tenant.tenantId}`);
24
+ console.log(` Tenant Name : ${tenant.tenantName || 'N/A'}`);
25
+ console.log(` Organization ID : ${tenant.organizationId}`);
26
+ console.log(` Client ID : ${tenant.clientId}`);
27
+ console.log(` Authority : ${tenant.authority || 'N/A'}`);
28
+ console.log(` Audience : ${tenant.audience || 'N/A'}`);
29
+ console.log(` Base URL : ${tenant.baseUrl || 'N/A'}`);
30
+ console.log();
31
+ });
32
+ }),
33
+ };
@@ -0,0 +1,109 @@
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 { clientCredentialsFlow, AUTH0_DOMAIN, AUDIENCE, BASE_URL } from '../../utils/auth/flow';
11
+ import { writeTenantAuthInfo, writeTenantInfo } from '../../utils/auth/tenant-store';
12
+ import { setActiveTenant } from '../../utils/auth/tenant-state';
13
+ export const login = {
14
+ command: 'login',
15
+ describe: 'Login into a tenant',
16
+ builder: (yargs) => yargs
17
+ .option('clientId', {
18
+ type: 'string',
19
+ requiresArg: true,
20
+ demandOption: true,
21
+ describe: 'Client ID for authentication',
22
+ })
23
+ .option('clientSecret', {
24
+ type: 'string',
25
+ demandOption: false,
26
+ describe: 'Client secret for authentication',
27
+ })
28
+ .option('tenantId', {
29
+ type: 'string',
30
+ demandOption: false,
31
+ describe: 'Tenant ID to login into.',
32
+ })
33
+ .option('organizationId', {
34
+ type: 'string',
35
+ demandOption: false,
36
+ describe: 'Organization ID to authenticate against.',
37
+ })
38
+ .option('authority', {
39
+ type: 'string',
40
+ demandOption: false,
41
+ describe: 'OAuth 2.0 authority URL for authentication.',
42
+ })
43
+ .option('audience', {
44
+ type: 'string',
45
+ demandOption: false,
46
+ describe: 'Intended recipient of the token, usually the API base URL.',
47
+ })
48
+ .option('baseUrl', {
49
+ type: 'string',
50
+ demandOption: false,
51
+ describe: 'Base URL for the API, used to construct the audience.',
52
+ })
53
+ .group([
54
+ 'clientId',
55
+ 'clientSecret',
56
+ 'tenantId',
57
+ 'organizationId',
58
+ 'authority',
59
+ 'audience',
60
+ 'baseUrl',
61
+ ], 'Login Options:'),
62
+ handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
63
+ const { clientId } = argv;
64
+ let authResult, tenantId, organizationId, tenantName;
65
+ if (argv.clientSecret) {
66
+ try {
67
+ const authData = yield clientCredentialsFlow({
68
+ clientId,
69
+ clientSecret: argv.clientSecret,
70
+ organizationId: argv.organizationId,
71
+ tenantId: argv.tenantId,
72
+ audience: argv.audience,
73
+ authority: argv.authority,
74
+ baseUrl: argv.baseUrl,
75
+ });
76
+ authResult = authData.data;
77
+ tenantId = authData.tokenTenantId;
78
+ organizationId = authData.tokenOrgId;
79
+ tenantName = authData.tokenTenantName;
80
+ }
81
+ catch (err) {
82
+ console.error(`\n Login failed: ${err.message}`);
83
+ process.exit(1);
84
+ }
85
+ }
86
+ else {
87
+ // TODO: Implement Device Authorization Flow when clientSecret is not provided.
88
+ console.log('\n Please provide client secret for authentication.');
89
+ process.exit(1);
90
+ }
91
+ yield writeTenantAuthInfo(tenantId, {
92
+ clientSecret: argv.clientSecret,
93
+ access_token: authResult.access_token,
94
+ expires_in: authResult.expires_in,
95
+ expires_at: new Date(Date.now() + authResult.expires_in * 1000).toISOString(),
96
+ });
97
+ yield writeTenantInfo({
98
+ tenantId,
99
+ organizationId,
100
+ clientId,
101
+ tenantName,
102
+ authority: argv.authority || AUTH0_DOMAIN,
103
+ audience: argv.audience || AUDIENCE,
104
+ baseUrl: argv.baseUrl || BASE_URL,
105
+ });
106
+ setActiveTenant(tenantId);
107
+ console.info(`\n Logged in successfully to tenant ${tenantId}.`);
108
+ }),
109
+ };
@@ -0,0 +1,25 @@
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 '../../utils/auth/tenant-state';
11
+ import { deleteTenantAuthInfo } from '../../utils/auth/tenant-store';
12
+ export const logout = {
13
+ command: 'logout',
14
+ describe: 'Logout from the active tenant',
15
+ handler: () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const tenantId = getActiveTenant();
17
+ if (!tenantId) {
18
+ console.error('\n No active tenant found. Please login first.');
19
+ return;
20
+ }
21
+ clearActiveTenant();
22
+ deleteTenantAuthInfo(tenantId);
23
+ console.info(`\n Logged out from tenant ${tenantId}`);
24
+ }),
25
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
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 { readTenantInfo } from '../../utils/auth/tenant-store';
11
+ import { renewAuthIfExpired } from '../../utils/auth/renewal';
12
+ export const status = {
13
+ command: 'status',
14
+ describe: 'Show current status of active tenant',
15
+ handler: () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const context = yield renewAuthIfExpired();
17
+ if (!context) {
18
+ console.log('\n No valid authentication found. Please login.');
19
+ return;
20
+ }
21
+ const tenantInfo = yield readTenantInfo(context.tenantId);
22
+ console.log('\n Active tenant:');
23
+ console.log(` Tenant ID : ${context.tenantId}`);
24
+ console.log(` Tenant Name : ${(tenantInfo === null || tenantInfo === void 0 ? void 0 : tenantInfo.tenantName) || 'N/A'}`);
25
+ console.log(` Organization ID : ${tenantInfo === null || tenantInfo === void 0 ? void 0 : tenantInfo.organizationId}`);
26
+ console.log(` Client ID : ${tenantInfo === null || tenantInfo === void 0 ? void 0 : tenantInfo.clientId}`);
27
+ console.log(` Authority : ${(tenantInfo === null || tenantInfo === void 0 ? void 0 : tenantInfo.authority) || 'N/A'}`);
28
+ console.log(` Audience : ${(tenantInfo === null || tenantInfo === void 0 ? void 0 : tenantInfo.audience) || 'N/A'}`);
29
+ console.log(` Base URL : ${(tenantInfo === null || tenantInfo === void 0 ? void 0 : tenantInfo.baseUrl) || 'N/A'}`);
30
+ }),
31
+ };
@@ -1,5 +1,6 @@
1
1
  // commands available when running from an app location (with CLI installed to local node_modules)
2
2
  // e.g. setup, deploy
3
- import * as build from './build';
4
- import * as scaffold from './scaffold';
5
- export { build, scaffold };
3
+ import * as project from './project';
4
+ import * as auth from './auth';
5
+ export { project };
6
+ export { auth };
@@ -7,9 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import loadCliConfig from '../utils/load-config';
10
+ import loadCliConfig from '../../utils/load-config';
11
11
  export const command = 'build';
12
- export const describe = 'Handles build time automation';
12
+ export const describe = 'Performs build time automation';
13
13
  export const builder = {
14
14
  config: {
15
15
  requiresArg: false,
@@ -0,0 +1,19 @@
1
+ import * as scaffold from './scaffold';
2
+ /**
3
+ * @param {Argv} yargs
4
+ */
5
+ export function builder(yargs) {
6
+ return yargs.command({
7
+ command: 'component',
8
+ describe: 'Performs component level operations',
9
+ builder: (_yargs) => {
10
+ _yargs = _yargs
11
+ .command([scaffold])
12
+ .strict()
13
+ .demandCommand(1, 'You need to specify a command to run');
14
+ _yargs = scaffold.builder(_yargs);
15
+ return _yargs;
16
+ },
17
+ handler: () => { },
18
+ });
19
+ }
@@ -1,11 +1,11 @@
1
1
  import { scaffoldComponent } from '@sitecore-content-sdk/core/tools';
2
- import loadCliConfig from '../utils/load-config';
2
+ import loadCliConfig from '../../../utils/load-config';
3
3
  import { ComponentTemplateType } from '@sitecore-content-sdk/core/config';
4
4
  /**
5
5
  * @param {Argv} yargs
6
6
  */
7
7
  export function builder(yargs) {
8
- return yargs.command('scaffold <componentName>', 'Scaffolds a new component. Use `sitecore-tools scaffold --help` for available options.', args, handler);
8
+ return yargs.command('scaffold <componentName>', 'Scaffolds a new component', args, handler);
9
9
  }
10
10
  /**
11
11
  * @param {Argv} yargs
@@ -0,0 +1,20 @@
1
+ import * as build from './build';
2
+ import * as component from './component';
3
+ /**
4
+ * @param {Argv} yargs
5
+ */
6
+ export function builder(yargs) {
7
+ return yargs.command({
8
+ command: 'project',
9
+ describe: 'Performs project level operations',
10
+ builder: (_yargs) => {
11
+ _yargs = _yargs
12
+ .command([build, component])
13
+ .strict()
14
+ .demandCommand(1, 'You need to specify a command to run');
15
+ _yargs = component.builder(_yargs);
16
+ return _yargs;
17
+ },
18
+ handler: () => { },
19
+ });
20
+ }