@contentstack/cli-auth 2.0.0-beta.2 → 2.0.0-beta.4
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/utils/auth-handler.d.ts +0 -6
- package/lib/utils/auth-handler.js +11 -37
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +1 -2
- package/lib/utils/mfa-handler.d.ts +0 -12
- package/lib/utils/mfa-handler.js +0 -41
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
- package/lib/utils/tokens-validation.d.ts +0 -15
- package/lib/utils/tokens-validation.js +0 -67
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/2.0.0-beta.
|
|
21
|
+
@contentstack/cli-auth/2.0.0-beta.4 linux-x64 node-v22.22.0
|
|
22
22
|
$ csdx --help [COMMAND]
|
|
23
23
|
USAGE
|
|
24
24
|
$ csdx COMMAND
|
|
@@ -37,12 +37,6 @@ declare class AuthHandler {
|
|
|
37
37
|
* @returns {Promise} Promise object returns response object from Contentstack
|
|
38
38
|
*/
|
|
39
39
|
logout(authtoken: string): Promise<object>;
|
|
40
|
-
/**
|
|
41
|
-
* Validate token
|
|
42
|
-
* @param {string} authtoken
|
|
43
|
-
* @returns {Promise} Promise object returns response object from Contentstack
|
|
44
|
-
*/
|
|
45
|
-
validateAuthtoken(authtoken: string): Promise<object>;
|
|
46
40
|
}
|
|
47
41
|
declare const _default: AuthHandler;
|
|
48
42
|
export default _default;
|
|
@@ -106,9 +106,15 @@ class AuthHandler {
|
|
|
106
106
|
cli_utilities_1.log.debug('Login successful, user found', { module: 'auth-handler', userEmail: result.user.email });
|
|
107
107
|
resolve(result.user);
|
|
108
108
|
}
|
|
109
|
-
else
|
|
110
|
-
|
|
109
|
+
else {
|
|
110
|
+
cli_utilities_1.log.debug('Login failed: no user found.', { module: 'auth-handler', result });
|
|
111
|
+
reject(new Error(cli_utilities_1.messageHandler.parse('CLI_AUTH_LOGIN_NO_USER')));
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
.catch(async (error) => {
|
|
115
|
+
if (error.errorCode === 294) {
|
|
111
116
|
try {
|
|
117
|
+
const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
|
|
112
118
|
resolve(await this.login(email, password, tfToken));
|
|
113
119
|
}
|
|
114
120
|
catch (error) {
|
|
@@ -118,14 +124,10 @@ class AuthHandler {
|
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
else {
|
|
121
|
-
cli_utilities_1.log.debug('Login
|
|
122
|
-
|
|
127
|
+
cli_utilities_1.log.debug('Login API call failed.', { module: 'auth-handler', error: (error === null || error === void 0 ? void 0 : error.errorMessage) || error });
|
|
128
|
+
cli_utilities_1.cliux.print('CLI_AUTH_LOGIN_FAILED', { color: 'yellow' });
|
|
129
|
+
reject(error);
|
|
123
130
|
}
|
|
124
|
-
})
|
|
125
|
-
.catch((error) => {
|
|
126
|
-
cli_utilities_1.log.debug('Login API call failed.', { module: 'auth-handler', error: (error === null || error === void 0 ? void 0 : error.errorMessage) || error });
|
|
127
|
-
cli_utilities_1.cliux.print('CLI_AUTH_LOGIN_FAILED', { color: 'yellow' });
|
|
128
|
-
(0, cli_utilities_1.handleAndLogError)(error, { module: 'auth-handler' });
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
133
|
else {
|
|
@@ -169,33 +171,5 @@ class AuthHandler {
|
|
|
169
171
|
}
|
|
170
172
|
});
|
|
171
173
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Validate token
|
|
174
|
-
* @param {string} authtoken
|
|
175
|
-
* @returns {Promise} Promise object returns response object from Contentstack
|
|
176
|
-
*/
|
|
177
|
-
async validateAuthtoken(authtoken) {
|
|
178
|
-
cli_utilities_1.log.debug('Starting token validation.', { module: 'auth-handler', hasAuthToken: !!authtoken });
|
|
179
|
-
return new Promise((resolve, reject) => {
|
|
180
|
-
if (authtoken) {
|
|
181
|
-
cli_utilities_1.log.debug('Making token validation API call.', { module: 'auth-handler' });
|
|
182
|
-
this._client
|
|
183
|
-
.getUser()
|
|
184
|
-
.then((user) => {
|
|
185
|
-
cli_utilities_1.log.debug('Token validation successful.', { module: 'auth-handler', user });
|
|
186
|
-
resolve(user);
|
|
187
|
-
})
|
|
188
|
-
.catch((error) => {
|
|
189
|
-
cli_utilities_1.log.debug('Token validation failed.', { module: 'auth-handler', error: error.message });
|
|
190
|
-
cli_utilities_1.cliux.print('CLI_AUTH_TOKEN_VALIDATION_FAILED', { color: 'yellow' });
|
|
191
|
-
(0, cli_utilities_1.handleAndLogError)(error, { module: 'auth-handler' });
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
cli_utilities_1.log.debug('Token validation failed: no auth token provided.', { module: 'auth-handler' });
|
|
196
|
-
reject(new Error(cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKEN_VALIDATION_NO_TOKEN')));
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
174
|
}
|
|
201
175
|
exports.default = new AuthHandler();
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.interactive = exports.mfaHandler = exports.authHandler = void 0;
|
|
4
4
|
var auth_handler_1 = require("./auth-handler");
|
|
5
5
|
Object.defineProperty(exports, "authHandler", { enumerable: true, get: function () { return auth_handler_1.default; } });
|
|
6
6
|
var mfa_handler_1 = require("./mfa-handler");
|
|
7
7
|
Object.defineProperty(exports, "mfaHandler", { enumerable: true, get: function () { return mfa_handler_1.default; } });
|
|
8
8
|
exports.interactive = require("./interactive");
|
|
9
|
-
exports.tokenValidation = require("./tokens-validation");
|
|
@@ -24,18 +24,6 @@ declare class MFAHandler {
|
|
|
24
24
|
* @throws Error if MFA code generation fails
|
|
25
25
|
*/
|
|
26
26
|
getMFACode(): Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
* Gets MFA code through manual user input
|
|
29
|
-
* @returns Promise<string> The MFA code
|
|
30
|
-
* @throws Error if code format is invalid
|
|
31
|
-
*/
|
|
32
|
-
getManualMFACode(): Promise<string>;
|
|
33
|
-
/**
|
|
34
|
-
* Validates an MFA code format
|
|
35
|
-
* @param code The MFA code to validate
|
|
36
|
-
* @returns boolean True if valid, false otherwise
|
|
37
|
-
*/
|
|
38
|
-
isValidMFACode(code: string): boolean;
|
|
39
27
|
}
|
|
40
28
|
declare const _default: MFAHandler;
|
|
41
29
|
export default _default;
|
package/lib/utils/mfa-handler.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
4
|
const otplib_1 = require("otplib");
|
|
5
|
-
const interactive_1 = require("./interactive");
|
|
6
5
|
/**
|
|
7
6
|
* @class
|
|
8
7
|
* MFA handler for managing multi-factor authentication
|
|
@@ -75,20 +74,6 @@ class MFAHandler {
|
|
|
75
74
|
source = 'environment variable';
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
if (!secret) {
|
|
79
|
-
cli_utilities_1.log.debug('Checking stored MFA secret', { module: 'mfa-handler' });
|
|
80
|
-
const mfaConfig = cli_utilities_1.configHandler.get('mfa');
|
|
81
|
-
if (mfaConfig === null || mfaConfig === void 0 ? void 0 : mfaConfig.secret) {
|
|
82
|
-
try {
|
|
83
|
-
secret = this.encrypter.decrypt(mfaConfig.secret);
|
|
84
|
-
source = 'stored configuration';
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
cli_utilities_1.log.debug('Failed to decrypt stored MFA secret', { module: 'mfa-handler', error });
|
|
88
|
-
(0, cli_utilities_1.handleAndLogError)(error, { module: 'mfa-handler' }, cli_utilities_1.messageHandler.parse('CLI_AUTH_MFA_DECRYPT_FAILED'));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
77
|
if (secret) {
|
|
93
78
|
try {
|
|
94
79
|
const code = this.generateMFACode(secret);
|
|
@@ -103,31 +88,5 @@ class MFAHandler {
|
|
|
103
88
|
}
|
|
104
89
|
}
|
|
105
90
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Gets MFA code through manual user input
|
|
108
|
-
* @returns Promise<string> The MFA code
|
|
109
|
-
* @throws Error if code format is invalid
|
|
110
|
-
*/
|
|
111
|
-
async getManualMFACode() {
|
|
112
|
-
try {
|
|
113
|
-
const code = await (0, interactive_1.askOTP)();
|
|
114
|
-
if (!/^\d{6}$/.test(code)) {
|
|
115
|
-
throw new Error(cli_utilities_1.messageHandler.parse('CLI_AUTH_MFA_INVALID_CODE'));
|
|
116
|
-
}
|
|
117
|
-
return code;
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
cli_utilities_1.log.debug('Failed to get MFA code', { module: 'mfa-handler', error });
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Validates an MFA code format
|
|
126
|
-
* @param code The MFA code to validate
|
|
127
|
-
* @returns boolean True if valid, false otherwise
|
|
128
|
-
*/
|
|
129
|
-
isValidMFACode(code) {
|
|
130
|
-
return /^\d{6}$/.test(code);
|
|
131
|
-
}
|
|
132
91
|
}
|
|
133
92
|
exports.default = new MFAHandler();
|
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": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.4",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"scripts": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@contentstack/cli-command": "~1.7.2",
|
|
26
|
-
"@contentstack/cli-utilities": "~1.17.
|
|
26
|
+
"@contentstack/cli-utilities": "~1.17.1",
|
|
27
27
|
"@oclif/core": "^4.3.0",
|
|
28
28
|
"@oclif/plugin-help": "^6.2.28",
|
|
29
29
|
"otplib": "^12.0.1"
|
|
@@ -81,4 +81,4 @@
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
"repository": "contentstack/cli"
|
|
84
|
-
}
|
|
84
|
+
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validate environment
|
|
3
|
-
* @param contentStackClient
|
|
4
|
-
* @param apiKey
|
|
5
|
-
* @param environment
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare const validateEnvironment: (contentStackClient: any, apiKey: string, environment: string) => Promise<any>;
|
|
9
|
-
/**
|
|
10
|
-
* Validate API key
|
|
11
|
-
* @param contentStackClient
|
|
12
|
-
* @param apiKey
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare const validateAPIKey: (contentStackClient: any, apiKey: string) => Promise<any>;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateAPIKey = exports.validateEnvironment = void 0;
|
|
4
|
-
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
|
-
/**
|
|
6
|
-
* Validate environment
|
|
7
|
-
* @param contentStackClient
|
|
8
|
-
* @param apiKey
|
|
9
|
-
* @param environment
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
const validateEnvironment = async (contentStackClient, apiKey, environment) => {
|
|
13
|
-
cli_utilities_1.log.debug('Starting environment validation.', { module: 'tokens-validation', apiKeyStatus: apiKey ? 'provided' : 'not-provided', environment });
|
|
14
|
-
let result;
|
|
15
|
-
try {
|
|
16
|
-
cli_utilities_1.log.debug('Making environment validation API call.', { module: 'tokens-validation', environment });
|
|
17
|
-
const validationResult = await contentStackClient.Stack({ api_key: apiKey }).environment(environment).fetch();
|
|
18
|
-
cli_utilities_1.log.debug('Environment validation API response received.', { module: 'tokens-validation', validationResult });
|
|
19
|
-
if (validationResult.name === environment) {
|
|
20
|
-
cli_utilities_1.log.debug('Environment validation successful.', { module: 'tokens-validation', environment, validationResult });
|
|
21
|
-
result = { valid: true, message: validationResult };
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
cli_utilities_1.log.debug('Environment validation failed: name mismatch.', { module: 'tokens-validation', expected: environment, actual: validationResult.name });
|
|
25
|
-
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME') };
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
cli_utilities_1.log.debug('Environment validation API call failed.', { module: 'tokens-validation', error: error.message, environment });
|
|
30
|
-
(0, cli_utilities_1.handleAndLogError)(error, { apiKey, environment });
|
|
31
|
-
result = { valid: false, message: 'CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME' };
|
|
32
|
-
}
|
|
33
|
-
cli_utilities_1.log.debug('Environment validation completed.', { module: 'tokens-validation', result });
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
exports.validateEnvironment = validateEnvironment;
|
|
37
|
-
/**
|
|
38
|
-
* Validate API key
|
|
39
|
-
* @param contentStackClient
|
|
40
|
-
* @param apiKey
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
const validateAPIKey = async (contentStackClient, apiKey) => {
|
|
44
|
-
cli_utilities_1.log.debug('Starting API key validation.', { module: 'tokens-validation', apiKeyStatus: apiKey ? 'provided' : 'not-provided' });
|
|
45
|
-
let result;
|
|
46
|
-
try {
|
|
47
|
-
cli_utilities_1.log.debug('Making API key validation API call.', { module: 'tokens-validation' });
|
|
48
|
-
const validateAPIKeyResult = await contentStackClient.stack({ api_key: apiKey }).fetch();
|
|
49
|
-
cli_utilities_1.log.debug('API key validation API response received.', { module: 'tokens-validation', validateAPIKeyResult });
|
|
50
|
-
if (validateAPIKeyResult.api_key === apiKey) {
|
|
51
|
-
cli_utilities_1.log.debug('API key validation successful.', { module: 'tokens-validation', apiKey: validateAPIKeyResult.api_key });
|
|
52
|
-
result = { valid: true, message: validateAPIKeyResult };
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
cli_utilities_1.log.debug('API key validation failed: key mismatch.', { module: 'tokens-validation', expected: apiKey, actual: validateAPIKeyResult.api_key });
|
|
56
|
-
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
cli_utilities_1.log.debug('API key validation API call failed.', { module: 'tokens-validation', error: error.message });
|
|
61
|
-
(0, cli_utilities_1.handleAndLogError)(error, { apiKey });
|
|
62
|
-
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') };
|
|
63
|
-
}
|
|
64
|
-
cli_utilities_1.log.debug('API key validation completed.', { module: 'tokens-validation', result });
|
|
65
|
-
return result;
|
|
66
|
-
};
|
|
67
|
-
exports.validateAPIKey = validateAPIKey;
|