/** * EthicalZen SDK v2.0 - Simplified API * * The simplest way to add AI safety guardrails to your application. * * @example Quick Start * ```typescript * const { EthicalZen } = require('@ethicalzen/sdk'); * * const ez = new EthicalZen('your-api-key'); * * const response = await ez.call('https://api.openai.com/v1/chat/completions', { * model: 'gpt-4', * messages: [{ role: 'user', content: 'Hello' }] * }); * ``` */ import { AxiosInstance } from 'axios'; /** * Configuration options for EthicalZen */ export interface EthicalZenOptions { /** Gateway URL (auto-detected if not provided) */ gateway?: string; /** Default certificate for guardrail enforcement */ certificate?: string; /** Request timeout in milliseconds (default: 30000) */ timeout?: number; /** Failure mode: 'block' | 'log' | 'pass' (default: 'block') */ onError?: 'block' | 'log' | 'pass'; } /** * Options for individual API calls */ export interface CallOptions { /** HTTP method (default: 'POST') */ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** Additional headers to include */ headers?: Record; /** Override default certificate for this call */ certificate?: string; /** Request timeout override */ timeout?: number; } /** * Options for Express middleware */ export interface MiddlewareOptions { /** Certificate for guardrail enforcement */ certificate?: string; /** When to validate: 'request' | 'response' | 'both' (default: 'response') */ validate?: 'request' | 'response' | 'both'; /** Failure mode: 'block' | 'log' | 'pass' (default: 'block') */ onError?: 'block' | 'log' | 'pass'; /** Custom violation handler */ onViolation?: (violations: any[], req: any, res: any) => void; } /** * EthicalZen - The main SDK class * * Initialize once with your API key, then use throughout your application. * * @example Basic Usage * ```typescript * const ez = new EthicalZen('ez-api-key-xxx'); * * // Make protected API calls * const response = await ez.call('https://api.openai.com/v1/chat/completions', { * model: 'gpt-4', * messages: [{ role: 'user', content: 'Hello' }] * }); * ``` * * @example With Certificate * ```typescript * const ez = new EthicalZen('ez-api-key-xxx', { * certificate: 'hipaa-compliant-v1' * }); * ``` * * @example Express Middleware * ```typescript * const ez = new EthicalZen('ez-api-key-xxx'); * app.use(ez.middleware()); * ``` */ export declare class EthicalZen { private apiKey; private gatewayURL; private defaultCertificate?; private timeout; private onError; private axiosClient; private tenantId?; /** * Create a new EthicalZen instance * * @param apiKey - Your EthicalZen API key (starts with 'ez-' or 'sk-') * @param options - Optional configuration */ constructor(apiKey: string, options?: EthicalZenOptions); /** * Auto-detect gateway URL based on environment */ private detectGateway; /** * Extract tenant ID from API key format */ private extractTenantFromKey; /** * Intercept requests to add EthicalZen headers and route through gateway */ private interceptRequest; /** * Handle errors from gateway */ private handleError; /** * Make a protected API call through EthicalZen gateway * * @param url - Target URL (e.g., 'https://api.openai.com/v1/chat/completions') * @param data - Request body (for POST/PUT/PATCH) * @param options - Call options * @returns Response data from target service * * @example * ```typescript * const response = await ez.call('https://api.openai.com/v1/chat/completions', { * model: 'gpt-4', * messages: [{ role: 'user', content: 'Hello' }] * }); * ``` */ call(url: string, data?: any, options?: CallOptions): Promise; /** * Make a GET request through EthicalZen */ get(url: string, options?: CallOptions): Promise; /** * Make a POST request through EthicalZen */ post(url: string, data?: any, options?: CallOptions): Promise; /** * Make a PUT request through EthicalZen */ put(url: string, data?: any, options?: CallOptions): Promise; /** * Make a DELETE request through EthicalZen */ delete(url: string, options?: CallOptions): Promise; /** * Get an axios-compatible client for advanced usage * * @param options - Optional certificate override * @returns Axios instance configured for EthicalZen * * @example * ```typescript * const client = ez.getClient({ certificate: 'my-cert' }); * const response = await client.post('https://api.openai.com/v1/...', data); * ``` */ getClient(options?: { certificate?: string; }): AxiosInstance; /** * Express middleware for automatic request/response validation * * @param options - Middleware options * @returns Express middleware function * * @example * ```typescript * const ez = new EthicalZen('ez-api-key'); * * // Protect all routes * app.use(ez.middleware()); * * // Or protect specific routes * app.post('/chat', ez.middleware({ certificate: 'chat-cert' }), handler); * ``` */ middleware(options?: MiddlewareOptions): (req: any, res: any, next: any) => Promise; /** * Validate a payload directly (for manual validation) */ validatePayload(payload: any, certificate?: string, type?: 'input' | 'output'): Promise<{ passed: boolean; violations: any[]; }>; /** * Get current configuration */ getConfig(): { gateway: string; certificate: string | undefined; timeout: number; onError: "block" | "log" | "pass"; }; /** * Update configuration */ configure(options: Partial): void; } /** * Convenience function to create an EthicalZen instance * * @param apiKey - Your EthicalZen API key * @returns EthicalZen instance * * @example * ```typescript * const ez = protect('your-api-key'); * const response = await ez.call('https://api.openai.com/...', data); * ``` */ export declare function protect(apiKey: string, options?: EthicalZenOptions): EthicalZen; export default EthicalZen; //# sourceMappingURL=ethicalzen.d.ts.map