Skip to content

Commit 02a1d37

Browse files
authored
Merge pull request #2361 from contentstack/v2-beta-to-v2-beta-dev
V2 beta to v2 beta dev
2 parents 72234d7 + 814dcf3 commit 02a1d37

24 files changed

Lines changed: 417 additions & 272 deletions

File tree

.talismanrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fileignoreconfig:
22
- filename: pnpm-lock.yaml
3-
checksum: f0d2b2bc5a7b24b2cd8ba12d8ccaa119d74cf73c9462ae0ddd1e1685d03967c9
3+
checksum: f20d4336b379ba896f0092ed8dd03df2c6e5bc34fe200e58002efc2c77fd9359
44
- filename: package-lock.json
5-
checksum: ed904450857be36b3792ab8650a9ba91ae2f55e67db945915743d1316593a573
5+
checksum: b41714137255ba498375116ae9410e04af150d75ba323c8dbaeb8995564a4677
66
- filename: packages/contentstack-audit/test/unit/mock/contents/composable_studio/environments/environments.json
77
checksum: 0402604e5919a7e38ecb5ff0916d6ae5ab7d98fe78ff6ac9eba8a9b8130af34d
88
- filename: packages/contentstack-utilities/src/helpers.ts
@@ -21,4 +21,8 @@ fileignoreconfig:
2121
checksum: 4fc97ff582d6dff9a54b3a50dfa3cbb5febd38a55aeb8737034b97188ad543ba
2222
- filename: packages/contentstack-utilities/test/unit/logger.test.ts
2323
checksum: a1939dea16166b1893a248179524a76f2ed20b04b99c83bd1a5a13fcf6f0dadc
24+
- filename: packages/contentstack-clone/README.md
25+
checksum: 8580ab3f52a079a6411c27cbaad66e3a70d9ac5ea59fc429a8f17c95d09399f8
26+
- filename: packages/contentstack/README.md
27+
checksum: 72850c976661f2912b5bca39734de09d56c311c2266fc67696c45ed3fb0b7511
2428
version: "1.0"

package-lock.json

Lines changed: 89 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-auth/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-auth/2.0.0-beta.1 darwin-arm64 node-v24.12.0
21+
@contentstack/cli-auth/2.0.0-beta.3 darwin-arm64 node-v24.12.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-auth",
33
"description": "Contentstack CLI plugin for authentication activities",
4-
"version": "2.0.0-beta.2",
4+
"version": "2.0.0-beta.3",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"scripts": {

packages/contentstack-auth/src/utils/auth-handler.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cliux, log, handleAndLogError, messageHandler } from '@contentstack/cli-utilities';
1+
import { cliux, log, messageHandler } from '@contentstack/cli-utilities';
22
import { User } from '../interfaces';
33
import { askOTPChannel, askOTP } from './interactive';
44

@@ -118,25 +118,26 @@ class AuthHandler {
118118
if (result.user) {
119119
log.debug('Login successful, user found', { module: 'auth-handler', userEmail: result.user.email });
120120
resolve(result.user as User);
121-
} else if (result.error_code === 294) {
122-
const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
123-
121+
} else {
122+
log.debug('Login failed: no user found.', { module: 'auth-handler', result });
123+
reject(new Error(messageHandler.parse('CLI_AUTH_LOGIN_NO_USER')));
124+
}
125+
})
126+
.catch(async (error: any) => {
127+
if (error.errorCode === 294) {
124128
try {
129+
const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
125130
resolve(await this.login(email, password, tfToken));
126131
} catch (error) {
127132
log.debug('Login with TFA token failed.', { module: 'auth-handler', error });
128133
cliux.print('CLI_AUTH_2FA_FAILED', { color: 'red' });
129134
reject(error);
130135
}
131136
} else {
132-
log.debug('Login failed: no user found.', { module: 'auth-handler', result });
133-
reject(new Error(messageHandler.parse('CLI_AUTH_LOGIN_NO_USER')));
137+
log.debug('Login API call failed.', { module: 'auth-handler', error: error?.errorMessage || error });
138+
cliux.print('CLI_AUTH_LOGIN_FAILED', { color: 'yellow' });
139+
reject(error);
134140
}
135-
})
136-
.catch((error: any) => {
137-
log.debug('Login API call failed.', { module: 'auth-handler', error: error?.errorMessage || error });
138-
cliux.print('CLI_AUTH_LOGIN_FAILED', { color: 'yellow' });
139-
handleAndLogError(error, { module: 'auth-handler' });
140141
});
141142
} else {
142143
const hasEmail = !!email;
@@ -203,7 +204,7 @@ class AuthHandler {
203204
.catch((error: Error) => {
204205
log.debug('Token validation failed.', { module: 'auth-handler', error: error.message });
205206
cliux.print('CLI_AUTH_TOKEN_VALIDATION_FAILED', { color: 'yellow' });
206-
handleAndLogError(error, { module: 'auth-handler' });
207+
reject(error);
207208
});
208209
} else {
209210
log.debug('Token validation failed: no auth token provided.', { module: 'auth-handler' });
@@ -213,4 +214,4 @@ class AuthHandler {
213214
}
214215
}
215216

216-
export default new AuthHandler();
217+
export default new AuthHandler();

packages/contentstack-auth/src/utils/mfa-handler.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cliux, configHandler, NodeCrypto, log, handleAndLogError, messageHandler } from '@contentstack/cli-utilities';
1+
import { cliux, NodeCrypto, log, messageHandler } from '@contentstack/cli-utilities';
22
import { authenticator } from 'otplib';
33
import { askOTP } from './interactive';
44

@@ -87,20 +87,6 @@ class MFAHandler {
8787
}
8888
}
8989

90-
if (!secret) {
91-
log.debug('Checking stored MFA secret', { module: 'mfa-handler' });
92-
const mfaConfig = configHandler.get('mfa');
93-
if (mfaConfig?.secret) {
94-
try {
95-
secret = this.encrypter.decrypt(mfaConfig.secret);
96-
source = 'stored configuration';
97-
} catch (error) {
98-
log.debug('Failed to decrypt stored MFA secret', { module: 'mfa-handler', error });
99-
handleAndLogError(error, { module: 'mfa-handler' }, messageHandler.parse('CLI_AUTH_MFA_DECRYPT_FAILED'));
100-
}
101-
}
102-
}
103-
10490
if (secret) {
10591
try {
10692
const code = this.generateMFACode(secret);

packages/contentstack-auth/test/integration/auth.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('contentstack-auth plugin test', () => {
9797
mockClient.login.resetHistory();
9898

9999
mockClient.login
100-
.onFirstCall().resolves({ error_code: 294 })
100+
.onFirstCall().rejects({ errorCode: 294 })
101101
.onSecondCall().resolves({ user: { email: credentials.email, authtoken: 'test-token' } });
102102

103103
await authHandler.login(credentials.email, credentials.password);

packages/contentstack-auth/test/unit/auth-handler.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ describe('Auth Handler', function () {
3232
return Promise.reject(new Error('Invalid 2FA code'));
3333
}
3434
} else {
35-
return Promise.resolve({ error_code: 294 });
35+
// Handler expects 2FA required as a rejection (catch path checks error.errorCode === 294)
36+
return Promise.reject({ errorCode: 294 });
3637
}
3738
}
3839
return Promise.resolve({ user });

packages/contentstack-auth/test/utils/auth-handler.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ describe('Auth Handler', function () {
3232
return Promise.reject(new Error('Invalid 2FA code'));
3333
}
3434
} else {
35-
return Promise.resolve({ error_code: 294 });
35+
// Handler expects 2FA required as a rejection (catch path checks error.errorCode === 294)
36+
return Promise.reject({ errorCode: 294 });
3637
}
3738
}
3839
return Promise.resolve({ user });

packages/contentstack-auth/test/utils/mfa-handler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('MFAHandler', () => {
4444
expect(authenticator.verify({ token: code, secret: validSecret })).to.be.true;
4545
});
4646

47-
it('should fallback to stored configuration when environment variable is not set', async () => {
47+
it.skip('should fallback to stored configuration when environment variable is not set', async () => {
4848
const encryptedSecret = 'encrypted-secret';
4949
configStub.returns({ secret: encryptedSecret });
5050
encrypterStub.decrypt.returns(validSecret);

0 commit comments

Comments
 (0)