@sitecore-content-sdk/cli 0.2.0-beta.17 → 0.2.0-beta.19

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.
@@ -5,6 +5,7 @@ const login_1 = require("./login");
5
5
  const logout_1 = require("./logout");
6
6
  const status_1 = require("./status");
7
7
  const list_1 = require("./list");
8
+ const switch_1 = require("./switch");
8
9
  /**
9
10
  * Registers the `auth` command group and its subcommands (`login`, `logout`, `status`, `list`) with Yargs.
10
11
  * @param {Argv} yargs - The Yargs instance used to define CLI commands.
@@ -16,7 +17,7 @@ function builder(yargs) {
16
17
  describe: 'Performs authentication for content services',
17
18
  builder: (_yargs) => {
18
19
  return _yargs
19
- .command([login_1.login, logout_1.logout, status_1.status, list_1.list])
20
+ .command([login_1.login, logout_1.logout, status_1.status, list_1.list, switch_1.switchTenant])
20
21
  .strict()
21
22
  .demandCommand(1, 'You need to specify a command to run')
22
23
  .help();
@@ -12,11 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.logout = exports.unitMock = void 0;
13
13
  const tools_1 = require("@sitecore-content-sdk/core/tools");
14
14
  let { deleteTenantAuthInfo, getActiveTenant, clearActiveTenant, deleteKey } = tools_1.auth;
15
- const unitMock = (formModule) => {
16
- deleteTenantAuthInfo = formModule.deleteTenantAuthInfo || deleteTenantAuthInfo;
17
- getActiveTenant = formModule.getActiveTenant || getActiveTenant;
18
- clearActiveTenant = formModule.clearActiveTenant || clearActiveTenant;
19
- deleteKey = formModule.deleteKey || deleteKey;
15
+ const unitMock = (authModule) => {
16
+ deleteTenantAuthInfo = authModule.deleteTenantAuthInfo || deleteTenantAuthInfo;
17
+ getActiveTenant = authModule.getActiveTenant || getActiveTenant;
18
+ clearActiveTenant = authModule.clearActiveTenant || clearActiveTenant;
19
+ deleteKey = authModule.deleteKey || deleteKey;
20
20
  };
21
21
  exports.unitMock = unitMock;
22
22
  exports.logout = {
@@ -12,10 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.status = exports.unitMock = void 0;
13
13
  const tools_1 = require("@sitecore-content-sdk/core/tools");
14
14
  let { readTenantInfo, validateAndRenewAuthIfExpired } = tools_1.auth;
15
- const unitMock = (formModule) => {
16
- readTenantInfo = formModule.readTenantInfo || readTenantInfo;
15
+ const unitMock = (authModule) => {
16
+ readTenantInfo = authModule.readTenantInfo || readTenantInfo;
17
17
  validateAndRenewAuthIfExpired =
18
- formModule.validateAndRenewAuthIfExpired || validateAndRenewAuthIfExpired;
18
+ authModule.validateAndRenewAuthIfExpired || validateAndRenewAuthIfExpired;
19
19
  };
20
20
  exports.unitMock = unitMock;
21
21
  exports.status = {
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.switchTenant = exports.unitMock = void 0;
13
+ const tools_1 = require("@sitecore-content-sdk/core/tools");
14
+ let { readTenantAuthInfo, validateAndRenewAuthIfExpired, setActiveTenant } = tools_1.auth;
15
+ const unitMock = (authModule) => {
16
+ readTenantAuthInfo = authModule.readTenantAuthInfo || readTenantAuthInfo;
17
+ setActiveTenant = authModule.setActiveTenant || setActiveTenant;
18
+ validateAndRenewAuthIfExpired =
19
+ authModule.validateAndRenewAuthIfExpired || validateAndRenewAuthIfExpired;
20
+ };
21
+ exports.unitMock = unitMock;
22
+ exports.switchTenant = {
23
+ command: 'switch <tenantId>',
24
+ describe: 'Switch into another tenant that you have logged into previously',
25
+ builder: (yargs) => yargs.positional('tenantId', {
26
+ positional: true,
27
+ demandOption: true,
28
+ type: 'string',
29
+ describe: 'Tenant ID to switch into.',
30
+ }),
31
+ handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
32
+ const tenantId = argv.tenantId;
33
+ const currentContext = yield validateAndRenewAuthIfExpired();
34
+ if (!currentContext) {
35
+ console.error('\nNo valid authentication found. Please login.');
36
+ return;
37
+ }
38
+ if (currentContext.tenantId === tenantId) {
39
+ console.log(`Already in tenant: ${tenantId}`);
40
+ return;
41
+ }
42
+ const newTenantInfo = yield readTenantAuthInfo(tenantId);
43
+ if (!newTenantInfo) {
44
+ console.error(`Tenant info for ID '${tenantId}' not found in local storage.`);
45
+ console.error('Please ensure you have logged into the tenant by running the auth login command');
46
+ return;
47
+ }
48
+ setActiveTenant(tenantId);
49
+ const tenantContext = validateAndRenewAuthIfExpired();
50
+ if (!tenantContext) {
51
+ console.error(`Failed to switch to tenant '${tenantId}', remaining in tenant '${currentContext.tenantId}'.`);
52
+ setActiveTenant(currentContext.tenantId);
53
+ return;
54
+ }
55
+ console.log(`Switched to tenant: ${tenantId}`);
56
+ }),
57
+ };
@@ -2,6 +2,7 @@ import { login } from './login';
2
2
  import { logout } from './logout';
3
3
  import { status } from './status';
4
4
  import { list } from './list';
5
+ import { switchTenant } from './switch';
5
6
  /**
6
7
  * Registers the `auth` command group and its subcommands (`login`, `logout`, `status`, `list`) with Yargs.
7
8
  * @param {Argv} yargs - The Yargs instance used to define CLI commands.
@@ -13,7 +14,7 @@ export function builder(yargs) {
13
14
  describe: 'Performs authentication for content services',
14
15
  builder: (_yargs) => {
15
16
  return _yargs
16
- .command([login, logout, status, list])
17
+ .command([login, logout, status, list, switchTenant])
17
18
  .strict()
18
19
  .demandCommand(1, 'You need to specify a command to run')
19
20
  .help();
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { auth } from '@sitecore-content-sdk/core/tools';
11
11
  let { deleteTenantAuthInfo, getActiveTenant, clearActiveTenant, deleteKey } = auth;
12
- export const unitMock = (formModule) => {
13
- deleteTenantAuthInfo = formModule.deleteTenantAuthInfo || deleteTenantAuthInfo;
14
- getActiveTenant = formModule.getActiveTenant || getActiveTenant;
15
- clearActiveTenant = formModule.clearActiveTenant || clearActiveTenant;
16
- deleteKey = formModule.deleteKey || deleteKey;
12
+ export const unitMock = (authModule) => {
13
+ deleteTenantAuthInfo = authModule.deleteTenantAuthInfo || deleteTenantAuthInfo;
14
+ getActiveTenant = authModule.getActiveTenant || getActiveTenant;
15
+ clearActiveTenant = authModule.clearActiveTenant || clearActiveTenant;
16
+ deleteKey = authModule.deleteKey || deleteKey;
17
17
  };
18
18
  export const logout = {
19
19
  command: 'logout',
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { auth } from '@sitecore-content-sdk/core/tools';
11
11
  let { readTenantInfo, validateAndRenewAuthIfExpired } = auth;
12
- export const unitMock = (formModule) => {
13
- readTenantInfo = formModule.readTenantInfo || readTenantInfo;
12
+ export const unitMock = (authModule) => {
13
+ readTenantInfo = authModule.readTenantInfo || readTenantInfo;
14
14
  validateAndRenewAuthIfExpired =
15
- formModule.validateAndRenewAuthIfExpired || validateAndRenewAuthIfExpired;
15
+ authModule.validateAndRenewAuthIfExpired || validateAndRenewAuthIfExpired;
16
16
  };
17
17
  export const status = {
18
18
  command: 'status',
@@ -0,0 +1,53 @@
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 { auth } from '@sitecore-content-sdk/core/tools';
11
+ let { readTenantAuthInfo, validateAndRenewAuthIfExpired, setActiveTenant } = auth;
12
+ export const unitMock = (authModule) => {
13
+ readTenantAuthInfo = authModule.readTenantAuthInfo || readTenantAuthInfo;
14
+ setActiveTenant = authModule.setActiveTenant || setActiveTenant;
15
+ validateAndRenewAuthIfExpired =
16
+ authModule.validateAndRenewAuthIfExpired || validateAndRenewAuthIfExpired;
17
+ };
18
+ export const switchTenant = {
19
+ command: 'switch <tenantId>',
20
+ describe: 'Switch into another tenant that you have logged into previously',
21
+ builder: (yargs) => yargs.positional('tenantId', {
22
+ positional: true,
23
+ demandOption: true,
24
+ type: 'string',
25
+ describe: 'Tenant ID to switch into.',
26
+ }),
27
+ handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const tenantId = argv.tenantId;
29
+ const currentContext = yield validateAndRenewAuthIfExpired();
30
+ if (!currentContext) {
31
+ console.error('\nNo valid authentication found. Please login.');
32
+ return;
33
+ }
34
+ if (currentContext.tenantId === tenantId) {
35
+ console.log(`Already in tenant: ${tenantId}`);
36
+ return;
37
+ }
38
+ const newTenantInfo = yield readTenantAuthInfo(tenantId);
39
+ if (!newTenantInfo) {
40
+ console.error(`Tenant info for ID '${tenantId}' not found in local storage.`);
41
+ console.error('Please ensure you have logged into the tenant by running the auth login command');
42
+ return;
43
+ }
44
+ setActiveTenant(tenantId);
45
+ const tenantContext = validateAndRenewAuthIfExpired();
46
+ if (!tenantContext) {
47
+ console.error(`Failed to switch to tenant '${tenantId}', remaining in tenant '${currentContext.tenantId}'.`);
48
+ setActiveTenant(currentContext.tenantId);
49
+ return;
50
+ }
51
+ console.log(`Switched to tenant: ${tenantId}`);
52
+ }),
53
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/cli",
3
- "version": "0.2.0-beta.17",
3
+ "version": "0.2.0-beta.19",
4
4
  "description": "Sitecore Content SDK CLI",
5
5
  "main": "dist/cjs/cli.js",
6
6
  "module": "dist/esm/cli.js",
@@ -34,7 +34,7 @@
34
34
  "url": "https://github.com/sitecore/content-sdk/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@sitecore-content-sdk/core": "0.2.0-beta.17",
37
+ "@sitecore-content-sdk/core": "0.2.0-beta.19",
38
38
  "dotenv": "^16.5.0",
39
39
  "dotenv-expand": "^12.0.2",
40
40
  "resolve": "^1.22.10",
@@ -60,7 +60,7 @@
60
60
  "ts-node": "^10.9.1",
61
61
  "typescript": "~5.8.3"
62
62
  },
63
- "gitHead": "040c17b860375d6692dde718e9e5dec9f4a09c04",
63
+ "gitHead": "b473bb4c64d68b18f5dad7e08faa95311f24c2b9",
64
64
  "files": [
65
65
  "dist",
66
66
  "types"
@@ -1,3 +1,3 @@
1
1
  import { CommandModule } from 'yargs';
2
- export declare const unitMock: (formModule: any) => void;
2
+ export declare const unitMock: (authModule: any) => void;
3
3
  export declare const logout: CommandModule;
@@ -1,3 +1,3 @@
1
1
  import { CommandModule } from 'yargs';
2
- export declare const unitMock: (formModule: any) => void;
2
+ export declare const unitMock: (authModule: any) => void;
3
3
  export declare const status: CommandModule;
@@ -0,0 +1,5 @@
1
+ import { CommandModule } from 'yargs';
2
+ import { TenantInfo } from '@sitecore-content-sdk/core/tools';
3
+ export declare const unitMock: (authModule: any) => void;
4
+ export type SwitchArgs = Pick<TenantInfo, 'tenantId'>;
5
+ export declare const switchTenant: CommandModule<object, SwitchArgs>;