Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,12 @@ jobs:
node-version: '22.x'
cache: 'pnpm' # optional but recommended

# - name: Temporarily disable contentstack package
# run: mv packages/contentstack/package.json packages/contentstack/package.json.disabled || true

- name: Install Dependencies (Excluding Contentstack)
run: pnpm install --no-frozen-lockfile

- name: Build all plugins (Excluding Contentstack)
run: |
NODE_ENV=PREPACK_MODE pnpm -r --sort run build

# - name: Restore contentstack package
# run: mv packages/contentstack/package.json.disabled packages/contentstack/package.json || true

- name: Run tests for Contentstack Command
working-directory: ./packages/contentstack-command
run: npm run test:unit

- name: Run tests for Contentstack Config
working-directory: ./packages/contentstack-config
run: npm run test:unit

- name: Run tests for Contentstack Auth
working-directory: ./packages/contentstack-auth
run: NODE_ENV=PREPACK_MODE npm run test:unit
- name: Run tests
run: NODE_ENV=PREPACK_MODE pnpm test
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fileignoreconfig:
- filename: .github/workflows/release.yml
checksum: 73807361b1a862dc882846ac75fefca49e3c734db032e9aa80158f2a686bea13
- filename: pnpm-lock.yaml
checksum: 45b77e385a0b13c82ba125dcdc82d27a360132ff6edda801cd8b75943996c310
checksum: c94a1596f3e28753b0564c2d344eb3ffeb1a5064fbd45e3288975ef6c7113771
- filename: packages/contentstack-auth/src/commands/auth/logout.ts
checksum: 20ff708d5a0ee56eb8786b19df07b49dacaddfa1deafe99c0397716c7865726d
version: '1.0'
3 changes: 2 additions & 1 deletion packages/contentstack-auth/.nycrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"inlcude": [
"lib/**/*.js"
]
],
"concurrency": 1
}
2 changes: 1 addition & 1 deletion packages/contentstack-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-auth/1.8.0-beta.0 darwin-arm64 node-v22.13.1
@contentstack/cli-auth/1.8.0-beta.0 darwin-arm64 node-v24.13.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
11 changes: 4 additions & 7 deletions packages/contentstack-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
"postpack": "rm -f oclif.manifest.json",
"prepack": "pnpm compile && oclif manifest && oclif readme",
"version": "oclif readme && git add README.md",
"test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"pretest": "tsc -p test",
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"posttest": "npm run lint",
"lint": "eslint src/**/*.ts",
"format": "eslint src/**/*.ts --fix",
"test:integration": "mocha --forbid-only \"test/integration/*.test.ts\"",
"test:unit": "mocha --forbid-only \"test/unit/**/*.test.ts\"",
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
"pretest": "tsc -p test",
"test": "NODE_OPTIONS=--no-warnings nyc --concurrency=1 --extension .ts mocha --exit --forbid-only \"test/unit/**/*.test.ts\"",
"test:report": "NODE_OPTIONS=--no-warnings nyc --concurrency=1 --extension .ts mocha --exit --forbid-only \"test/unit/**/*.test.ts\"",
"posttest": "npm run lint"
},
"dependencies": {
"@contentstack/cli-command": "~1.8.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-auth/src/utils/auth-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cliux, log, handleAndLogError, messageHandler } from '@contentstack/cli-utilities';
import { cliux, log, messageHandler } from '@contentstack/cli-utilities';
import { User } from '../interfaces';
import { askOTPChannel, askOTP } from './interactive';

Expand Down
30 changes: 27 additions & 3 deletions packages/contentstack-auth/src/utils/mfa-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { cliux, configHandler, NodeCrypto, log, handleAndLogError, messageHandler } from '@contentstack/cli-utilities';
import { cliux, configHandler, NodeCrypto, log } from '@contentstack/cli-utilities';
import { authenticator } from 'otplib';
import { askOTP } from './interactive';

/**
* @class
Expand Down Expand Up @@ -66,7 +65,7 @@ class MFAHandler {
* @returns Promise<string> The MFA code
* @throws Error if MFA code generation fails
*/
async getMFACode(): Promise<string> {
async getMFACode(): Promise<string | undefined> {
log.debug('Getting MFA code', { module: 'mfa-handler' });
let secret: string | undefined;
let source: string;
Expand All @@ -87,6 +86,21 @@ class MFAHandler {
}
}

if (!secret) {
const stored = configHandler.get('mfa') as { secret?: string } | undefined;
if (stored?.secret) {
try {
const decrypted = this.encrypter.decrypt(stored.secret);
if (decrypted && this.isValidBase32(decrypted.toUpperCase())) {
secret = decrypted;
source = 'stored configuration';
}
} catch {
log.debug('Failed to decrypt stored MFA secret', { module: 'mfa-handler' });
}
}
}

if (secret) {
try {
const code = this.generateMFACode(secret);
Expand All @@ -102,6 +116,16 @@ class MFAHandler {
);
}
}
return undefined;
}

/**
* Validates if a string is a valid 6-digit MFA code format
* @param code The code to validate
* @returns true if valid format, false otherwise
*/
isValidMFACode(code: string): boolean {
return /^\d{6}$/.test(code);
}

}
Expand Down
155 changes: 0 additions & 155 deletions packages/contentstack-auth/test/integration/auth.test.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/contentstack-auth/test/integration/config.json

This file was deleted.

68 changes: 0 additions & 68 deletions packages/contentstack-auth/test/integration/helper.ts

This file was deleted.

Loading
Loading