@testivai/common
v0.1.21
Published
Shared utilities for TestivAI SDKs and CLI
Maintainers
Readme
@testivai/common
Shared utilities for TestivAI SDKs and CLI.
Overview
This package contains common functionality used by:
@testivai/cli- The TestivAI command-line interface@testivai/witness-playwright- The Playwright SDK
Features
- Core API Client: HTTP communication with TestivAI Core API
- Authentication: Credential storage and retrieval
- Configuration: Loading and parsing
testivai.config.ts - Types: Shared TypeScript type definitions
Installation
npm install @testivai/commonUsage
import {
CoreApiClient,
getApiKey,
loadConfig,
TestivaiConfig
} from '@testivai/common';
// Get API key from environment or stored credentials
const apiKey = getApiKey();
// Create API client
const client = new CoreApiClient(apiKey);
// Validate the API key
const result = await client.validateApiKey();
console.log(result.valid); // true or false
// Load configuration
const config = await loadConfig();
console.log(config.outputDir); // './visual-tests'API Reference
CoreApiClient
const client = new CoreApiClient(apiKey: string, baseUrl?: string);
// Validate API key
await client.validateApiKey(): Promise<ApiKeyValidationResponse>
// Submit visual check
await client.submitVisualCheck(data: CaptureData): Promise<VisualCheckResult>
// Get test run status
await client.getTestRunStatus(testRunId: string): Promise<VisualCheckResult>Authentication
// Get API key (from env var or stored credentials)
getApiKey(): string | null
// Check if authenticated
isAuthenticated(): boolean
// Save credentials
saveCredentials(credentials: StoredCredentials): void
// Load credentials
loadCredentials(): StoredCredentials | null
// Delete credentials
deleteCredentials(): voidConfiguration
// Load config from file (or return defaults)
await loadConfig(configPath?: string): Promise<TestivaiConfig>
// Check if config file exists
configExists(dir?: string): boolean
// Find config file path
findConfigFile(startDir?: string): string | null
// Get resolved output directory
getOutputDir(config: TestivaiConfig, baseDir?: string): stringLicense
MIT
