refactor: centralize constants, add error classes, and DRY test utilities

- Create src/errors.js with custom error classes (RateLimitError, AuthError, ApiError, etc.)
- Create src/utils/helpers.js with shared utilities (formatDuration, sleep)
- Create tests/helpers/http-client.cjs with shared test utilities (~250 lines deduped)
- Centralize OAuth config and other constants in src/constants.js
- Add JSDoc types to all major exported functions
- Refactor all test files to use shared http-client utilities
- Update CLAUDE.md with new architecture documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Badri Narayanan S
2025-12-24 18:11:45 +05:30
parent 712da8f7f2
commit 0edc718672
16 changed files with 641 additions and 626 deletions

View File

@@ -1,26 +1,22 @@
/**
* Token Extractor Module
* Extracts OAuth tokens from Antigravity's SQLite database
*
*
* The database is automatically updated by Antigravity when tokens refresh,
* so this approach doesn't require any manual intervention.
*/
import { execSync } from 'child_process';
import { homedir } from 'os';
import { join } from 'path';
import { TOKEN_REFRESH_INTERVAL_MS, ANTIGRAVITY_AUTH_PORT } from './constants.js';
import {
TOKEN_REFRESH_INTERVAL_MS,
ANTIGRAVITY_AUTH_PORT,
ANTIGRAVITY_DB_PATH
} from './constants.js';
// Cache for the extracted token
let cachedToken = null;
let tokenExtractedAt = null;
// Antigravity's SQLite database path
const ANTIGRAVITY_DB_PATH = join(
homedir(),
'Library/Application Support/Antigravity/User/globalStorage/state.vscdb'
);
/**
* Extract token from Antigravity's SQLite database
* This is the preferred method as the DB is auto-updated