@contentstack/cli-auth 1.7.2 → 1.7.3
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 +0 -28
- 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 -27
- 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/1.7.
|
|
21
|
+
@contentstack/cli-auth/1.7.3 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;
|
|
@@ -171,33 +171,5 @@ class AuthHandler {
|
|
|
171
171
|
}
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Validate token
|
|
176
|
-
* @param {string} authtoken
|
|
177
|
-
* @returns {Promise} Promise object returns response object from Contentstack
|
|
178
|
-
*/
|
|
179
|
-
async validateAuthtoken(authtoken) {
|
|
180
|
-
cli_utilities_1.log.debug('Starting token validation.', { module: 'auth-handler', hasAuthToken: !!authtoken });
|
|
181
|
-
return new Promise((resolve, reject) => {
|
|
182
|
-
if (authtoken) {
|
|
183
|
-
cli_utilities_1.log.debug('Making token validation API call.', { module: 'auth-handler' });
|
|
184
|
-
this._client
|
|
185
|
-
.getUser()
|
|
186
|
-
.then((user) => {
|
|
187
|
-
cli_utilities_1.log.debug('Token validation successful.', { module: 'auth-handler', user });
|
|
188
|
-
resolve(user);
|
|
189
|
-
})
|
|
190
|
-
.catch((error) => {
|
|
191
|
-
cli_utilities_1.log.debug('Token validation failed.', { module: 'auth-handler', error: error.message });
|
|
192
|
-
cli_utilities_1.cliux.print('CLI_AUTH_TOKEN_VALIDATION_FAILED', { color: 'yellow' });
|
|
193
|
-
reject(error);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
cli_utilities_1.log.debug('Token validation failed: no auth token provided.', { module: 'auth-handler' });
|
|
198
|
-
reject(new Error(cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKEN_VALIDATION_NO_TOKEN')));
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
174
|
}
|
|
203
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
|
|
@@ -89,31 +88,5 @@ class MFAHandler {
|
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Gets MFA code through manual user input
|
|
94
|
-
* @returns Promise<string> The MFA code
|
|
95
|
-
* @throws Error if code format is invalid
|
|
96
|
-
*/
|
|
97
|
-
async getManualMFACode() {
|
|
98
|
-
try {
|
|
99
|
-
const code = await (0, interactive_1.askOTP)();
|
|
100
|
-
if (!/^\d{6}$/.test(code)) {
|
|
101
|
-
throw new Error(cli_utilities_1.messageHandler.parse('CLI_AUTH_MFA_INVALID_CODE'));
|
|
102
|
-
}
|
|
103
|
-
return code;
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
cli_utilities_1.log.debug('Failed to get MFA code', { module: 'mfa-handler', error });
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Validates an MFA code format
|
|
112
|
-
* @param code The MFA code to validate
|
|
113
|
-
* @returns boolean True if valid, false otherwise
|
|
114
|
-
*/
|
|
115
|
-
isValidMFACode(code) {
|
|
116
|
-
return /^\d{6}$/.test(code);
|
|
117
|
-
}
|
|
118
91
|
}
|
|
119
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": "1.7.
|
|
4
|
+
"version": "1.7.3",
|
|
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;
|