@contentstack/cli-auth 2.0.0-beta.1 → 2.0.0-beta.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Contentstack
3
+ Copyright (c) 2026 Contentstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.1 linux-x64 node-v22.21.1
21
+ @contentstack/cli-auth/2.0.0-beta.3 linux-x64 node-v22.22.0
22
22
  $ csdx --help [COMMAND]
23
23
  USAGE
24
24
  $ csdx COMMAND
@@ -9,8 +9,10 @@ class BaseCommand extends cli_command_1.Command {
9
9
  * plugins, registering the configuration, and initializing the logger.
10
10
  */
11
11
  async init() {
12
+ var _a, _b;
12
13
  await super.init();
13
- this.contextDetails = Object.assign({}, this.createExportContext());
14
+ // this.contextDetails = { ...this.createExportContext() };
15
+ this.contextDetails = Object.assign({}, (0, cli_utilities_1.createLogContext)(((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.command) || 'auth', '', cli_utilities_1.configHandler.get('authenticationMethod')));
14
16
  }
15
17
  /**
16
18
  * The catch function is used to handle errors from a command, either by adding custom logic or
@@ -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 if (result.error_code === 294) {
110
- const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
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 failed: no user found.', { module: 'auth-handler', result });
122
- reject(new Error(cli_utilities_1.messageHandler.parse('CLI_AUTH_LOGIN_NO_USER')));
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 {
@@ -188,7 +190,7 @@ class AuthHandler {
188
190
  .catch((error) => {
189
191
  cli_utilities_1.log.debug('Token validation failed.', { module: 'auth-handler', error: error.message });
190
192
  cli_utilities_1.cliux.print('CLI_AUTH_TOKEN_VALIDATION_FAILED', { color: 'yellow' });
191
- (0, cli_utilities_1.handleAndLogError)(error, { module: 'auth-handler' });
193
+ reject(error);
192
194
  });
193
195
  }
194
196
  else {
@@ -75,20 +75,6 @@ class MFAHandler {
75
75
  source = 'environment variable';
76
76
  }
77
77
  }
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
78
  if (secret) {
93
79
  try {
94
80
  const code = this.generateMFACode(secret);
@@ -359,5 +359,5 @@
359
359
  ]
360
360
  }
361
361
  },
362
- "version": "2.0.0-beta.1"
362
+ "version": "2.0.0-beta.3"
363
363
  }
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.1",
4
+ "version": "2.0.0-beta.3",
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.7.0",
26
- "@contentstack/cli-utilities": "~1.15.0",
25
+ "@contentstack/cli-command": "~1.7.2",
26
+ "@contentstack/cli-utilities": "~1.17.0",
27
27
  "@oclif/core": "^4.3.0",
28
28
  "@oclif/plugin-help": "^6.2.28",
29
29
  "otplib": "^12.0.1"
@@ -36,7 +36,7 @@
36
36
  "@types/mkdirp": "^1.0.2",
37
37
  "@types/mocha": "^8.2.3",
38
38
  "@types/node": "^14.18.63",
39
- "@types/sinon": "^10.0.20",
39
+ "@types/sinon": "^21.0.0",
40
40
  "chai": "^4.5.0",
41
41
  "dotenv": "^16.4.7",
42
42
  "eslint": "^8.57.1",
@@ -45,7 +45,7 @@
45
45
  "mocha": "10.8.2",
46
46
  "nyc": "^15.1.0",
47
47
  "oclif": "^4.17.46",
48
- "sinon": "^19.0.5",
48
+ "sinon": "^21.0.1",
49
49
  "ts-node": "^10.9.2",
50
50
  "typescript": "^4.9.5"
51
51
  },