@contentstack/cli-auth 1.7.2 → 2.0.0-beta.2

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 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.2 linux-x64 node-v22.22.0
21
+ @contentstack/cli-auth/2.0.0-beta.2 linux-x64 node-v22.22.0
22
22
  $ csdx --help [COMMAND]
23
23
  USAGE
24
24
  $ csdx COMMAND
@@ -141,12 +141,12 @@ USAGE
141
141
 
142
142
  FLAGS
143
143
  -a, --alias=<value> Alias (name) you want to assign to the token
144
- -d, --delivery Set this flag to save delivery token
145
144
  -e, --environment=<value> Environment name for delivery token
146
145
  -k, --stack-api-key=<value> Stack API Key
147
- -m, --management Set this flag to save management token
148
- -t, --token=<value> [env: TOKEN] Add the token name
149
146
  -y, --yes Use this flag to skip confirmation
147
+ --delivery Set this flag to save delivery token
148
+ --management Set this flag to save management token
149
+ --token=<value> [env: TOKEN] Add the token name
150
150
 
151
151
  DESCRIPTION
152
152
  Adds management/delivery tokens to your session to use it with other CLI commands
@@ -45,7 +45,6 @@ class BaseCommand extends cli_command_1.Command {
45
45
  command: ((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.command) || 'auth',
46
46
  module: '',
47
47
  userId: cli_utilities_1.configHandler.get('userUid') || '',
48
- email: cli_utilities_1.configHandler.get('email') || '',
49
48
  sessionId: (_c = this.context) === null || _c === void 0 ? void 0 : _c.sessionId,
50
49
  apiKey: apiKey || '',
51
50
  orgId: cli_utilities_1.configHandler.get('oauthOrgUid') || '',
@@ -73,13 +73,5 @@ LogoutCommand.flags = {
73
73
  required: false,
74
74
  default: false,
75
75
  }),
76
- force: cli_utilities_1.flags.boolean({
77
- char: 'f',
78
- description: 'Force log out by skipping the confirmation.',
79
- required: false,
80
- hidden: true,
81
- default: false,
82
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-f', '--force'], ['-y', '--yes']),
83
- }),
84
76
  };
85
77
  LogoutCommand.aliases = ['logout'];
@@ -24,7 +24,7 @@ class TokensAddCommand extends base_command_1.BaseCommand {
24
24
  skipAliasReplaceConfirmation }));
25
25
  if (!isDelivery && !isManagement && !Boolean(environment)) {
26
26
  cli_utilities_1.log.debug('No token type specified, requesting user input', this.contextDetails);
27
- let tokenType = await (0, interactive_1.askTokenType)();
27
+ const tokenType = await (0, interactive_1.askTokenType)();
28
28
  isDelivery = tokenType === 'delivery';
29
29
  isManagement = tokenType === 'management';
30
30
  cli_utilities_1.log.debug(`Token type selected: ${tokenType}`, this.contextDetails);
@@ -140,16 +140,12 @@ TokensAddCommand.examples = [
140
140
  TokensAddCommand.flags = {
141
141
  alias: cli_utilities_1.Flags.string({ char: 'a', description: 'Alias (name) you want to assign to the token' }),
142
142
  delivery: cli_utilities_1.flags.boolean({
143
- char: 'd',
144
143
  description: 'Set this flag to save delivery token',
145
144
  exclusive: ['management'],
146
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-d'], ['--delivery']),
147
145
  }),
148
146
  management: cli_utilities_1.flags.boolean({
149
- char: 'm',
150
147
  description: 'Set this flag to save management token',
151
148
  exclusive: ['delivery', 'environment'],
152
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-m'], ['--management']),
153
149
  }),
154
150
  environment: cli_utilities_1.flags.string({
155
151
  char: 'e',
@@ -159,22 +155,8 @@ TokensAddCommand.flags = {
159
155
  'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API Key' }),
160
156
  yes: cli_utilities_1.flags.boolean({ char: 'y', description: 'Use this flag to skip confirmation' }),
161
157
  token: cli_utilities_1.flags.string({
162
- char: 't',
163
158
  description: 'Add the token name',
164
159
  env: 'TOKEN',
165
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-t'], ['--token']),
166
- }),
167
- //To be deprecated
168
- 'api-key': cli_utilities_1.flags.string({
169
- description: 'API Key',
170
- hidden: true,
171
- parse: (0, cli_utilities_1.printFlagDeprecation)(['api-key'], ['-k', 'stack-api-key']),
172
- }),
173
- force: cli_utilities_1.flags.boolean({
174
- char: 'f',
175
- hidden: true,
176
- description: 'Force adding',
177
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-f', '--force'], ['-y', '--yes']),
178
160
  }),
179
161
  branch: cli_utilities_1.flags.string({
180
162
  required: false,
@@ -22,7 +22,7 @@ export interface Context {
22
22
  command: string;
23
23
  module: string;
24
24
  userId: string | undefined;
25
- email: string | undefined;
25
+ email?: string | undefined;
26
26
  sessionId: string | undefined;
27
27
  clientId?: string | undefined;
28
28
  apiKey: string;
@@ -106,15 +106,9 @@ 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
- 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) {
109
+ else if (result.error_code === 294) {
110
+ const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
116
111
  try {
117
- const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
118
112
  resolve(await this.login(email, password, tfToken));
119
113
  }
120
114
  catch (error) {
@@ -124,10 +118,14 @@ class AuthHandler {
124
118
  }
125
119
  }
126
120
  else {
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);
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')));
130
123
  }
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' });
131
129
  });
132
130
  }
133
131
  else {
@@ -190,7 +188,7 @@ class AuthHandler {
190
188
  .catch((error) => {
191
189
  cli_utilities_1.log.debug('Token validation failed.', { module: 'auth-handler', error: error.message });
192
190
  cli_utilities_1.cliux.print('CLI_AUTH_TOKEN_VALIDATION_FAILED', { color: 'yellow' });
193
- reject(error);
191
+ (0, cli_utilities_1.handleAndLogError)(error, { module: 'auth-handler' });
194
192
  });
195
193
  }
196
194
  else {
@@ -75,6 +75,20 @@ 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
+ }
78
92
  if (secret) {
79
93
  try {
80
94
  const code = this.generateMFACode(secret);
@@ -84,15 +84,6 @@
84
84
  "required": false,
85
85
  "allowNo": false,
86
86
  "type": "boolean"
87
- },
88
- "force": {
89
- "char": "f",
90
- "description": "Force log out by skipping the confirmation.",
91
- "hidden": true,
92
- "name": "force",
93
- "required": false,
94
- "allowNo": false,
95
- "type": "boolean"
96
87
  }
97
88
  },
98
89
  "hasDynamicHelp": false,
@@ -162,7 +153,6 @@
162
153
  "type": "option"
163
154
  },
164
155
  "delivery": {
165
- "char": "d",
166
156
  "description": "Set this flag to save delivery token",
167
157
  "exclusive": [
168
158
  "management"
@@ -172,7 +162,6 @@
172
162
  "type": "boolean"
173
163
  },
174
164
  "management": {
175
- "char": "m",
176
165
  "description": "Set this flag to save management token",
177
166
  "exclusive": [
178
167
  "delivery",
@@ -209,7 +198,6 @@
209
198
  "type": "boolean"
210
199
  },
211
200
  "token": {
212
- "char": "t",
213
201
  "description": "Add the token name",
214
202
  "env": "TOKEN",
215
203
  "name": "token",
@@ -217,22 +205,6 @@
217
205
  "multiple": false,
218
206
  "type": "option"
219
207
  },
220
- "api-key": {
221
- "description": "API Key",
222
- "hidden": true,
223
- "name": "api-key",
224
- "hasDynamicHelp": false,
225
- "multiple": false,
226
- "type": "option"
227
- },
228
- "force": {
229
- "char": "f",
230
- "description": "Force adding",
231
- "hidden": true,
232
- "name": "force",
233
- "allowNo": false,
234
- "type": "boolean"
235
- },
236
208
  "branch": {
237
209
  "description": "Branch name",
238
210
  "hidden": true,
@@ -387,5 +359,5 @@
387
359
  ]
388
360
  }
389
361
  },
390
- "version": "1.7.2"
362
+ "version": "2.0.0-beta.2"
391
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": "1.7.2",
4
+ "version": "2.0.0-beta.2",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "scripts": {