import type { createDatabase } from "@prodobit/database"; import type { CreateIntegrationKeyRequest, UpdateIntegrationKeyRequest, IntegrationKeyQuery, UsageStatsQuery, SetRateLimitRequest } from "@prodobit/types"; /** * Integration Service * Manages API keys, scopes, rate limits, and usage logging */ export declare class IntegrationService { private db; constructor(db: ReturnType); /** * Generate a new API key */ private generateApiKey; /** * Create a new API key for a tenant */ createApiKey(tenantId: string, data: CreateIntegrationKeyRequest, createdBy?: string): Promise<{ id: string; tenantId: string; name: string; apiKey: string; keyPrefix: string; environment: string; status: string; scopes: string[]; metadata: Record | undefined; expiresAt: Date | null; insertedAt: Date; updatedAt: Date; }>; /** * Create default rate limits for a new key */ private createDefaultRateLimits; /** * Validate that scopes exist and are public */ private validateScopes; /** * List API keys for a tenant */ listApiKeys(tenantId: string, query?: IntegrationKeyQuery): Promise<{ id: string; name: string; status: string; insertedAt: Date; updatedAt: Date; deletedAt: Date | null; tenantId: string; metadata: Record | null; expiresAt: Date | null; createdBy: string | null; keyPrefix: string; environment: string; scopes: string[]; lastUsedAt: Date | null; }[]>; /** * Get a single API key by ID */ getApiKeyById(keyId: string, tenantId: string): Promise<{ id: string; name: string; status: string; insertedAt: Date; updatedAt: Date; deletedAt: Date | null; tenantId: string; metadata: Record | null; expiresAt: Date | null; createdBy: string | null; keyPrefix: string; environment: string; scopes: string[]; lastUsedAt: Date | null; } | undefined>; /** * Update an API key */ updateApiKey(keyId: string, tenantId: string, data: UpdateIntegrationKeyRequest): Promise<{ id: string; tenantId: string; name: string; key: string; keyPrefix: string; environment: string; status: string; scopes: string[]; metadata: Record | null; lastUsedAt: Date | null; expiresAt: Date | null; createdBy: string | null; insertedAt: Date; updatedAt: Date; deletedAt: Date | null; }>; /** * Revoke an API key */ revokeApiKey(keyId: string, tenantId: string): Promise<{ id: string; tenantId: string; name: string; key: string; keyPrefix: string; environment: string; status: string; scopes: string[]; metadata: Record | null; lastUsedAt: Date | null; expiresAt: Date | null; createdBy: string | null; insertedAt: Date; updatedAt: Date; deletedAt: Date | null; }>; /** * Delete an API key */ deleteApiKey(keyId: string, tenantId: string): Promise; /** * Verify an API key and return key data */ verifyApiKey(rawKey: string): Promise<{ id: string; tenantId: string; scopes: string[]; environment: string; } | null>; /** * Get available scopes (public scopes that can be granted) */ getAvailableScopes(): Promise<{ id: string; description: string; insertedAt: Date; updatedAt: Date; resource: string; action: string; scope: string; module: string; endpoint: string | null; isPublic: boolean; }[]>; /** * Create or update scopes (admin function) */ upsertScope(data: { module: string; resource: string; action: string; scope: string; endpoint?: string; description: string; isPublic?: boolean; }): Promise<{ id: string; description: string; insertedAt: Date; updatedAt: Date; resource: string; action: string; scope: string; module: string; endpoint: string | null; isPublic: boolean; }>; /** * Log API usage */ logUsage(data: { keyId: string; tenantId: string; method: string; path: string; statusCode: number; responseTime?: number; ipAddress?: string; userAgent?: string; errorMessage?: string; metadata?: Record; }): Promise; /** * Get usage statistics for a key */ getUsageStats(query: UsageStatsQuery): Promise<{ keyId: string; totalRequests: number; successfulRequests: number; failedRequests: number; averageResponseTime: number; requestsByStatus: Record; requestsByEndpoint: Record; timeRange: { start: Date; end: Date; range: "week" | "month" | "hour" | "day"; }; }>; /** * Check and enforce rate limits */ checkRateLimit(keyId: string): Promise<{ allowed: boolean; limit?: { type: string; max: number; current: number; resetAt: Date; }; }>; /** * Calculate next reset time based on limit type */ private calculateNextReset; /** * Set or update rate limit for a key */ setRateLimit(keyId: string, data: SetRateLimitRequest): Promise<{ id: string; insertedAt: Date; updatedAt: Date; keyId: string; limitType: string; maxRequests: number; currentCount: number; resetAt: Date; }>; /** * Get rate limits for a key */ getRateLimits(keyId: string): Promise<{ id: string; keyId: string; limitType: string; maxRequests: number; currentCount: number; resetAt: Date; insertedAt: Date; updatedAt: Date; }[]>; } //# sourceMappingURL=service.d.ts.map