@contentstack/cli-auth 1.3.13 → 1.3.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/README.md +1 -1
- package/lib/base-command.d.ts +33 -0
- package/lib/base-command.js +41 -0
- package/lib/commands/auth/login.d.ts +2 -2
- package/lib/commands/auth/login.js +5 -5
- package/lib/commands/auth/logout.d.ts +2 -2
- package/lib/commands/auth/logout.js +4 -4
- package/lib/commands/auth/tokens/add.d.ts +2 -2
- package/lib/commands/auth/tokens/add.js +6 -8
- package/lib/commands/auth/tokens/index.d.ts +2 -2
- package/lib/commands/auth/tokens/index.js +3 -3
- package/lib/commands/auth/tokens/remove.d.ts +2 -2
- package/lib/commands/auth/tokens/remove.js +7 -4
- package/lib/commands/auth/whoami.d.ts +2 -2
- package/lib/commands/auth/whoami.js +4 -4
- package/lib/utils/auth-handler.d.ts +3 -0
- package/lib/utils/auth-handler.js +13 -6
- package/lib/utils/tokens-validation.js +7 -4
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
|
|
|
18
18
|
$ csdx COMMAND
|
|
19
19
|
running command...
|
|
20
20
|
$ csdx (--version)
|
|
21
|
-
@contentstack/cli-auth/1.3.
|
|
21
|
+
@contentstack/cli-auth/1.3.15 linux-x64 node-v18.18.2
|
|
22
22
|
$ csdx --help [COMMAND]
|
|
23
23
|
USAGE
|
|
24
24
|
$ csdx COMMAND
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Command } from '@contentstack/cli-command';
|
|
2
|
+
import { Interfaces, LoggerService } from '@contentstack/cli-utilities';
|
|
3
|
+
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
|
|
4
|
+
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>;
|
|
5
|
+
export declare abstract class BaseCommand<T extends typeof Command> extends Command {
|
|
6
|
+
logger: LoggerService;
|
|
7
|
+
protected args: Args<T>;
|
|
8
|
+
protected flags: Flags<T>;
|
|
9
|
+
/**
|
|
10
|
+
* The `init` function initializes the command by parsing arguments and flags, registering search
|
|
11
|
+
* plugins, registering the configuration, and initializing the logger.
|
|
12
|
+
*/
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* The catch function is used to handle errors from a command, either by adding custom logic or
|
|
16
|
+
* returning the parent class error handling.
|
|
17
|
+
* @param err - The `err` parameter is of type `Error & { exitCode?: number }`. This means that it is
|
|
18
|
+
* an object that extends the `Error` class and may also have an optional property `exitCode` of type
|
|
19
|
+
* `number`.
|
|
20
|
+
* @returns The parent class error handling is being returned.
|
|
21
|
+
*/
|
|
22
|
+
protected catch(err: Error & {
|
|
23
|
+
exitCode?: number;
|
|
24
|
+
}): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* The `finally` function is called after the `run` and `catch` functions, regardless of whether or not
|
|
27
|
+
* an error occurred.
|
|
28
|
+
* @param {Error | undefined} _ - The parameter "_" represents an error object or undefined.
|
|
29
|
+
* @returns The `finally` method is returning the result of calling the `finally` method of the
|
|
30
|
+
* superclass, which is a promise.
|
|
31
|
+
*/
|
|
32
|
+
protected finally(_: Error | undefined): Promise<any>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseCommand = void 0;
|
|
4
|
+
const cli_command_1 = require("@contentstack/cli-command");
|
|
5
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
|
+
class BaseCommand extends cli_command_1.Command {
|
|
7
|
+
/**
|
|
8
|
+
* The `init` function initializes the command by parsing arguments and flags, registering search
|
|
9
|
+
* plugins, registering the configuration, and initializing the logger.
|
|
10
|
+
*/
|
|
11
|
+
async init() {
|
|
12
|
+
await super.init();
|
|
13
|
+
// Init logger
|
|
14
|
+
this.logger = new cli_utilities_1.LoggerService(process.cwd(), 'cli-log');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The catch function is used to handle errors from a command, either by adding custom logic or
|
|
18
|
+
* returning the parent class error handling.
|
|
19
|
+
* @param err - The `err` parameter is of type `Error & { exitCode?: number }`. This means that it is
|
|
20
|
+
* an object that extends the `Error` class and may also have an optional property `exitCode` of type
|
|
21
|
+
* `number`.
|
|
22
|
+
* @returns The parent class error handling is being returned.
|
|
23
|
+
*/
|
|
24
|
+
async catch(err) {
|
|
25
|
+
// add any custom logic to handle errors from the command
|
|
26
|
+
// or simply return the parent class error handling
|
|
27
|
+
return super.catch(err);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The `finally` function is called after the `run` and `catch` functions, regardless of whether or not
|
|
31
|
+
* an error occurred.
|
|
32
|
+
* @param {Error | undefined} _ - The parameter "_" represents an error object or undefined.
|
|
33
|
+
* @returns The `finally` method is returning the result of calling the `finally` method of the
|
|
34
|
+
* superclass, which is a promise.
|
|
35
|
+
*/
|
|
36
|
+
async finally(_) {
|
|
37
|
+
// called after run and catch regardless of whether or not the command errored
|
|
38
|
+
return super.finally(_);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.BaseCommand = BaseCommand;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from '@contentstack/cli-command';
|
|
2
1
|
import { FlagInput } from '@contentstack/cli-utilities';
|
|
3
|
-
|
|
2
|
+
import { BaseCommand } from '../../base-command';
|
|
3
|
+
export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
|
|
4
4
|
static run: any;
|
|
5
5
|
static description: string;
|
|
6
6
|
static examples: string[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cli_command_1 = require("@contentstack/cli-command");
|
|
4
3
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
4
|
const utils_1 = require("../../utils");
|
|
6
|
-
|
|
5
|
+
const base_command_1 = require("../../base-command");
|
|
6
|
+
class LoginCommand extends base_command_1.BaseCommand {
|
|
7
7
|
async run() {
|
|
8
8
|
try {
|
|
9
9
|
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.cmaHost, skipTokenValidity: true });
|
|
@@ -17,7 +17,7 @@ class LoginCommand extends cli_command_1.Command {
|
|
|
17
17
|
else {
|
|
18
18
|
const username = (loginFlags === null || loginFlags === void 0 ? void 0 : loginFlags.username) || (await utils_1.interactive.askUsername());
|
|
19
19
|
const password = (loginFlags === null || loginFlags === void 0 ? void 0 : loginFlags.password) || (await utils_1.interactive.askPassword());
|
|
20
|
-
|
|
20
|
+
this.logger.debug('username', username);
|
|
21
21
|
await this.login(username, password);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -36,7 +36,7 @@ class LoginCommand extends cli_command_1.Command {
|
|
|
36
36
|
errorMessage = error;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
this.logger.error('login failed', errorMessage);
|
|
40
40
|
cli_utilities_1.cliux.error('CLI_AUTH_LOGIN_FAILED');
|
|
41
41
|
cli_utilities_1.cliux.error(errorMessage);
|
|
42
42
|
process.exit();
|
|
@@ -49,7 +49,7 @@ class LoginCommand extends cli_command_1.Command {
|
|
|
49
49
|
throw new cli_utilities_1.CLIError('Failed to login - invalid response');
|
|
50
50
|
}
|
|
51
51
|
await cli_utilities_1.authHandler.setConfigData('basicAuth', user);
|
|
52
|
-
|
|
52
|
+
this.logger.info('successfully logged in');
|
|
53
53
|
cli_utilities_1.cliux.success('CLI_AUTH_LOGIN_SUCCESS');
|
|
54
54
|
}
|
|
55
55
|
catch (error) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from '@contentstack/cli-command';
|
|
2
1
|
import { FlagInput } from '@contentstack/cli-utilities';
|
|
3
|
-
|
|
2
|
+
import { BaseCommand } from '../../base-command';
|
|
3
|
+
export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {
|
|
4
4
|
static run: any;
|
|
5
5
|
static description: string;
|
|
6
6
|
static examples: string[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cli_command_1 = require("@contentstack/cli-command");
|
|
4
3
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
4
|
const utils_1 = require("../../utils");
|
|
6
|
-
|
|
5
|
+
const base_command_1 = require("../../base-command");
|
|
6
|
+
class LogoutCommand extends base_command_1.BaseCommand {
|
|
7
7
|
async run() {
|
|
8
8
|
const { flags: logoutFlags } = await this.parse(LogoutCommand);
|
|
9
9
|
let confirm = logoutFlags.force === true || logoutFlags.yes === true;
|
|
@@ -26,7 +26,7 @@ class LogoutCommand extends cli_command_1.Command {
|
|
|
26
26
|
await cli_utilities_1.authHandler.oauthLogout();
|
|
27
27
|
}
|
|
28
28
|
cli_utilities_1.cliux.loader('');
|
|
29
|
-
|
|
29
|
+
this.logger.info('successfully logged out');
|
|
30
30
|
cli_utilities_1.cliux.success('CLI_AUTH_LOGOUT_SUCCESS');
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
@@ -48,7 +48,7 @@ class LogoutCommand extends cli_command_1.Command {
|
|
|
48
48
|
errorMessage = error;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
this.logger.error('Logout failed', errorMessage);
|
|
52
52
|
cli_utilities_1.cliux.print('CLI_AUTH_LOGOUT_FAILED', { color: 'yellow' });
|
|
53
53
|
cli_utilities_1.cliux.print(errorMessage, { color: 'red' });
|
|
54
54
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from '@contentstack/cli-command';
|
|
2
1
|
import { FlagInput } from '@contentstack/cli-utilities';
|
|
3
|
-
|
|
2
|
+
import { BaseCommand } from '../../../base-command';
|
|
3
|
+
export default class TokensAddCommand extends BaseCommand<typeof TokensAddCommand> {
|
|
4
4
|
static description: string;
|
|
5
5
|
static examples: string[];
|
|
6
6
|
static flags: FlagInput;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cli_command_1 = require("@contentstack/cli-command");
|
|
4
3
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
4
|
const interactive_1 = require("../../../utils/interactive");
|
|
6
|
-
|
|
5
|
+
const base_command_1 = require("../../../base-command");
|
|
6
|
+
class TokensAddCommand extends base_command_1.BaseCommand {
|
|
7
7
|
async run() {
|
|
8
|
-
// @ts-ignore
|
|
9
8
|
const { flags: addTokenFlags } = await this.parse(TokensAddCommand);
|
|
10
9
|
let isAliasExist = false;
|
|
11
10
|
const skipAliasReplaceConfirmation = addTokenFlags.force || addTokenFlags.yes;
|
|
@@ -15,7 +14,6 @@ class TokensAddCommand extends cli_command_1.Command {
|
|
|
15
14
|
let isDelivery = addTokenFlags.delivery;
|
|
16
15
|
let isManagement = addTokenFlags.management;
|
|
17
16
|
let environment = addTokenFlags.environment;
|
|
18
|
-
let branch = addTokenFlags.branch;
|
|
19
17
|
const configKeyTokens = 'tokens';
|
|
20
18
|
if (!isDelivery && !isManagement && !Boolean(environment)) {
|
|
21
19
|
let tokenType = await (0, interactive_1.askTokenType)();
|
|
@@ -23,7 +21,7 @@ class TokensAddCommand extends cli_command_1.Command {
|
|
|
23
21
|
isManagement = tokenType === 'management';
|
|
24
22
|
}
|
|
25
23
|
const type = isDelivery || Boolean(environment) ? 'delivery' : 'management';
|
|
26
|
-
|
|
24
|
+
this.logger.info(`adding ${type} token`);
|
|
27
25
|
try {
|
|
28
26
|
if (!alias) {
|
|
29
27
|
alias = await cli_utilities_1.cliux.inquire({ type: 'input', message: 'CLI_AUTH_TOKENS_ADD_ASK_TOKEN_ALIAS', name: 'alias' });
|
|
@@ -36,7 +34,7 @@ class TokensAddCommand extends cli_command_1.Command {
|
|
|
36
34
|
name: 'confirm',
|
|
37
35
|
});
|
|
38
36
|
if (!shouldAliasReplace) {
|
|
39
|
-
|
|
37
|
+
this.logger.info('Exiting from the process of replacing the token');
|
|
40
38
|
cli_utilities_1.cliux.print('CLI_AUTH_EXIT_PROCESS');
|
|
41
39
|
return;
|
|
42
40
|
}
|
|
@@ -79,7 +77,7 @@ class TokensAddCommand extends cli_command_1.Command {
|
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
catch (error) {
|
|
82
|
-
|
|
80
|
+
this.logger.error('token add error', error.message);
|
|
83
81
|
cli_utilities_1.cliux.print('CLI_AUTH_TOKENS_ADD_FAILED', { color: 'yellow' });
|
|
84
82
|
cli_utilities_1.cliux.error(error.message.message ? error.message.message : error.message);
|
|
85
83
|
}
|
|
@@ -101,7 +99,7 @@ TokensAddCommand.examples = [
|
|
|
101
99
|
'$ csdx auth:tokens:add --alias <alias> --stack-api-key <stack api key> --delivery -e <environment> --token <delivery token>',
|
|
102
100
|
];
|
|
103
101
|
TokensAddCommand.flags = {
|
|
104
|
-
alias: cli_utilities_1.
|
|
102
|
+
alias: cli_utilities_1.Flags.string({ char: 'a', description: 'Name of the token alias' }),
|
|
105
103
|
delivery: cli_utilities_1.flags.boolean({
|
|
106
104
|
char: 'd',
|
|
107
105
|
description: 'Set this flag to save delivery token',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class TokensListCommand extends
|
|
1
|
+
import { BaseCommand } from '../../../base-command';
|
|
2
|
+
export default class TokensListCommand extends BaseCommand<typeof TokensListCommand> {
|
|
3
3
|
static aliases: string[];
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static description: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cli_command_1 = require("@contentstack/cli-command");
|
|
4
3
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
|
-
|
|
4
|
+
const base_command_1 = require("../../../base-command");
|
|
5
|
+
class TokensListCommand extends base_command_1.BaseCommand {
|
|
6
6
|
async run() {
|
|
7
7
|
try {
|
|
8
8
|
const managementTokens = cli_utilities_1.configHandler.get('tokens');
|
|
@@ -41,7 +41,7 @@ class TokensListCommand extends cli_command_1.Command {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
catch (error) {
|
|
44
|
-
|
|
44
|
+
this.logger.error('Token list error', error.message);
|
|
45
45
|
cli_utilities_1.cliux.print('CLI_AUTH_TOKENS_LIST_FAILED', { color: 'yellow' });
|
|
46
46
|
cli_utilities_1.cliux.print(error.message, { color: 'red' });
|
|
47
47
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from '@contentstack/cli-command';
|
|
2
1
|
import { FlagInput } from '@contentstack/cli-utilities';
|
|
3
|
-
|
|
2
|
+
import { BaseCommand } from '../../../base-command';
|
|
3
|
+
export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemoveCommand> {
|
|
4
4
|
static description: string;
|
|
5
5
|
static examples: string[];
|
|
6
6
|
static flags: FlagInput;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cli_command_1 = require("@contentstack/cli-command");
|
|
4
3
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
|
-
|
|
4
|
+
const base_command_1 = require("../../../base-command");
|
|
5
|
+
class TokensRemoveCommand extends base_command_1.BaseCommand {
|
|
6
6
|
async run() {
|
|
7
7
|
const { flags: removeTokenFlags } = await this.parse(TokensRemoveCommand);
|
|
8
8
|
const alias = removeTokenFlags.alias;
|
|
@@ -29,18 +29,21 @@ class TokensRemoveCommand extends cli_command_1.Command {
|
|
|
29
29
|
type: 'checkbox',
|
|
30
30
|
choices: tokenOptions,
|
|
31
31
|
});
|
|
32
|
-
cli_utilities_1.logger.debug('selected tokens', selectedTokens);
|
|
33
32
|
if (selectedTokens.length === 0) {
|
|
34
33
|
return;
|
|
35
34
|
}
|
|
35
|
+
selectedTokens.forEach((ele) => {
|
|
36
|
+
this.logger.info('selected tokens', ele);
|
|
37
|
+
});
|
|
36
38
|
selectedTokens.forEach((element) => {
|
|
37
39
|
const selectedToken = element.split(':')[0];
|
|
38
40
|
cli_utilities_1.configHandler.delete(`tokens.${selectedToken}`);
|
|
39
41
|
cli_utilities_1.cliux.success('CLI_AUTH_TOKENS_REMOVE_SUCCESS');
|
|
42
|
+
this.logger.info('Token removed successfully !!', element);
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
45
|
catch (error) {
|
|
43
|
-
|
|
46
|
+
this.logger.error('Token remove error', error.message);
|
|
44
47
|
cli_utilities_1.cliux.print('CLI_AUTH_TOKENS_REMOVE_FAILED', { color: 'yellow' });
|
|
45
48
|
cli_utilities_1.cliux.print(error.message, { color: 'red' });
|
|
46
49
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class WhoamiCommand extends
|
|
1
|
+
import { BaseCommand } from '../../base-command';
|
|
2
|
+
export default class WhoamiCommand extends BaseCommand<typeof WhoamiCommand> {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static aliases: string[];
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cli_command_1 = require("@contentstack/cli-command");
|
|
4
3
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
|
-
|
|
4
|
+
const base_command_1 = require("../../base-command");
|
|
5
|
+
class WhoamiCommand extends base_command_1.BaseCommand {
|
|
6
6
|
async run() {
|
|
7
7
|
try {
|
|
8
8
|
if (this.email) {
|
|
9
9
|
cli_utilities_1.cliux.print('CLI_AUTH_WHOAMI_LOGGED_IN_AS', { color: 'white' });
|
|
10
10
|
cli_utilities_1.cliux.print(this.email, { color: 'green' });
|
|
11
|
-
|
|
11
|
+
this.logger.info('Currently logged in user', this.email);
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
14
|
cli_utilities_1.cliux.error('CLI_AUTH_WHOAMI_FAILED');
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
catch (error) {
|
|
18
|
-
|
|
18
|
+
this.logger.error('whoami error', error.message);
|
|
19
19
|
cli_utilities_1.cliux.print('CLI_AUTH_WHOAMI_FAILED', { color: 'yellow' });
|
|
20
20
|
cli_utilities_1.cliux.print(error.message, { color: 'red' });
|
|
21
21
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { User } from '../interfaces';
|
|
2
|
+
import { LoggerService } from '@contentstack/cli-utilities';
|
|
2
3
|
/**
|
|
3
4
|
* @class
|
|
4
5
|
* Auth handler
|
|
@@ -6,8 +7,10 @@ import { User } from '../interfaces';
|
|
|
6
7
|
declare class AuthHandler {
|
|
7
8
|
private _client;
|
|
8
9
|
private _host;
|
|
10
|
+
logger: LoggerService;
|
|
9
11
|
set client(contentStackClient: any);
|
|
10
12
|
set host(contentStackHost: any);
|
|
13
|
+
initLog(): void;
|
|
11
14
|
/**
|
|
12
15
|
*
|
|
13
16
|
*
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
4
|
const interactive_1 = require("./interactive");
|
|
5
|
+
const cli_utilities_2 = require("@contentstack/cli-utilities");
|
|
5
6
|
/**
|
|
6
7
|
* @class
|
|
7
8
|
* Auth handler
|
|
@@ -13,6 +14,9 @@ class AuthHandler {
|
|
|
13
14
|
set host(contentStackHost) {
|
|
14
15
|
this._host = contentStackHost;
|
|
15
16
|
}
|
|
17
|
+
initLog() {
|
|
18
|
+
this.logger = new cli_utilities_2.LoggerService(process.cwd(), 'cli-log');
|
|
19
|
+
}
|
|
16
20
|
/**
|
|
17
21
|
*
|
|
18
22
|
*
|
|
@@ -23,6 +27,7 @@ class AuthHandler {
|
|
|
23
27
|
* TBD: take out the otp implementation from login and create a new method/function to handle otp
|
|
24
28
|
*/
|
|
25
29
|
async login(email, password, tfaToken) {
|
|
30
|
+
this.initLog();
|
|
26
31
|
return new Promise((resolve, reject) => {
|
|
27
32
|
if (email && password) {
|
|
28
33
|
const loginPayload = { email, password };
|
|
@@ -32,7 +37,7 @@ class AuthHandler {
|
|
|
32
37
|
this._client
|
|
33
38
|
.login(loginPayload)
|
|
34
39
|
.then(async (result) => {
|
|
35
|
-
|
|
40
|
+
this.logger.debug('login result', result);
|
|
36
41
|
if (result.user) {
|
|
37
42
|
resolve(result.user);
|
|
38
43
|
}
|
|
@@ -45,7 +50,7 @@ class AuthHandler {
|
|
|
45
50
|
cli_utilities_1.cliux.print('CLI_AUTH_LOGIN_SECURITY_CODE_SEND_SUCCESS');
|
|
46
51
|
}
|
|
47
52
|
catch (error) {
|
|
48
|
-
|
|
53
|
+
this.logger.error('Failed to send the security code', error);
|
|
49
54
|
reject(new cli_utilities_1.CLIError({ message: 'Failed to login - failed to send the security code' }));
|
|
50
55
|
return;
|
|
51
56
|
}
|
|
@@ -55,7 +60,7 @@ class AuthHandler {
|
|
|
55
60
|
resolve(await this.login(email, password, tfToken));
|
|
56
61
|
}
|
|
57
62
|
catch (error) {
|
|
58
|
-
|
|
63
|
+
this.logger.error('Failed to login with tfa token', error);
|
|
59
64
|
reject(new cli_utilities_1.CLIError({ message: 'Failed to login with the tf token' }));
|
|
60
65
|
}
|
|
61
66
|
}
|
|
@@ -64,7 +69,7 @@ class AuthHandler {
|
|
|
64
69
|
}
|
|
65
70
|
})
|
|
66
71
|
.catch((error) => {
|
|
67
|
-
|
|
72
|
+
this.logger.error('Failed to login', error);
|
|
68
73
|
reject(new cli_utilities_1.CLIError({ message: error.errorMessage }));
|
|
69
74
|
});
|
|
70
75
|
}
|
|
@@ -79,6 +84,7 @@ class AuthHandler {
|
|
|
79
84
|
* @returns {Promise} Promise object returns response object from Contentstack
|
|
80
85
|
*/
|
|
81
86
|
async logout(authtoken) {
|
|
87
|
+
this.initLog();
|
|
82
88
|
return new Promise((resolve, reject) => {
|
|
83
89
|
if (authtoken) {
|
|
84
90
|
this._client
|
|
@@ -87,7 +93,7 @@ class AuthHandler {
|
|
|
87
93
|
return resolve(response);
|
|
88
94
|
})
|
|
89
95
|
.catch((error) => {
|
|
90
|
-
|
|
96
|
+
this.logger.error('Failed to logout', error);
|
|
91
97
|
return reject(new cli_utilities_1.CLIError({ message: 'Failed to logout - ' + error.message }));
|
|
92
98
|
});
|
|
93
99
|
}
|
|
@@ -102,13 +108,14 @@ class AuthHandler {
|
|
|
102
108
|
* @returns {Promise} Promise object returns response object from Contentstack
|
|
103
109
|
*/
|
|
104
110
|
async validateAuthtoken(authtoken) {
|
|
111
|
+
this.initLog();
|
|
105
112
|
return new Promise((resolve, reject) => {
|
|
106
113
|
if (authtoken) {
|
|
107
114
|
this._client
|
|
108
115
|
.getUser()
|
|
109
116
|
.then((user) => resolve(user))
|
|
110
117
|
.catch((error) => {
|
|
111
|
-
|
|
118
|
+
this.logger.error('Failed to validate token', error);
|
|
112
119
|
reject(new cli_utilities_1.CLIError({ message: 'Failed to validate token - ' + error.message }));
|
|
113
120
|
});
|
|
114
121
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateAPIKey = exports.validateEnvironment = void 0;
|
|
4
4
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
|
+
const cli_utilities_2 = require("@contentstack/cli-utilities");
|
|
5
6
|
/**
|
|
6
7
|
* Validate environment
|
|
7
8
|
* @param contentStackClient
|
|
@@ -10,10 +11,11 @@ const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
|
10
11
|
* @returns
|
|
11
12
|
*/
|
|
12
13
|
const validateEnvironment = async (contentStackClient, apiKey, environment) => {
|
|
14
|
+
const newLogger = new cli_utilities_2.LoggerService(process.cwd(), 'cli-log');
|
|
13
15
|
let result;
|
|
14
16
|
try {
|
|
15
17
|
const validationResult = await contentStackClient.Stack({ api_key: apiKey }).environment(environment).fetch();
|
|
16
|
-
|
|
18
|
+
newLogger.debug('environment validation result', validationResult);
|
|
17
19
|
if (validationResult.name === environment) {
|
|
18
20
|
result = { valid: true, message: validationResult };
|
|
19
21
|
}
|
|
@@ -22,7 +24,7 @@ const validateEnvironment = async (contentStackClient, apiKey, environment) => {
|
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
catch (error) {
|
|
25
|
-
|
|
27
|
+
newLogger.error('validate environment error', error);
|
|
26
28
|
result = { valid: false, message: 'CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME' };
|
|
27
29
|
}
|
|
28
30
|
return result;
|
|
@@ -35,10 +37,11 @@ exports.validateEnvironment = validateEnvironment;
|
|
|
35
37
|
* @returns
|
|
36
38
|
*/
|
|
37
39
|
const validateAPIKey = async (contentStackClient, apiKey) => {
|
|
40
|
+
const newLogger = new cli_utilities_2.LoggerService(process.cwd(), 'cli-log');
|
|
38
41
|
let result;
|
|
39
42
|
try {
|
|
40
43
|
const validateAPIKeyResult = await contentStackClient.stack({ api_key: apiKey }).fetch();
|
|
41
|
-
|
|
44
|
+
newLogger.debug('api key validation result', validateAPIKeyResult);
|
|
42
45
|
if (validateAPIKeyResult.api_key === apiKey) {
|
|
43
46
|
result = { valid: true, message: validateAPIKeyResult };
|
|
44
47
|
}
|
|
@@ -47,7 +50,7 @@ const validateAPIKey = async (contentStackClient, apiKey) => {
|
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
catch (error) {
|
|
50
|
-
|
|
53
|
+
newLogger.error('validate api key error', error);
|
|
51
54
|
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') };
|
|
52
55
|
}
|
|
53
56
|
return result;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-auth",
|
|
3
3
|
"description": "Contentstack CLI plugin for authentication activities",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.15",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"scripts": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@contentstack/cli-command": "~1.2.
|
|
26
|
-
"@contentstack/cli-utilities": "~1.5.
|
|
25
|
+
"@contentstack/cli-command": "~1.2.13",
|
|
26
|
+
"@contentstack/cli-utilities": "~1.5.4",
|
|
27
27
|
"chalk": "^4.0.0",
|
|
28
28
|
"debug": "^4.1.1",
|
|
29
29
|
"inquirer": "8.2.4",
|