UNPKG

mya-cli

Version:

MYA - AI-Powered Stock & Options Analysis CLI Tool

233 lines (232 loc) 7.03 kB
/** * MYA API Backend - Multi-User Architecture with RabbitMQ + Cloudflare KV * Main entry point for the backend API * * This module provides the core functionality for the MYA trading intelligence platform, * including user authentication, session management, and analysis request processing. * * Last updated: July 7, 2025 */ import { HybridUserContextManager } from './utils/hybrid-user-context.js'; declare global { interface KVNamespace { get(key: string): Promise<string | null>; put(key: string, value: string, options?: { expirationTtl?: number; }): Promise<void>; delete(key: string): Promise<void>; list(options?: { prefix?: string; }): Promise<{ keys: { name: string; }[]; }>; } } /** * Application configuration */ interface AppConfig { apiUrl: string; kvNamespace: KVNamespace; environment: string; env?: any; } /** * Global services for multi-user support */ declare let hybridContextManager: HybridUserContextManager; /** * Initialize application services */ export declare function initializeServices(config: AppConfig): Promise<void>; /** * Process authentication request * Initiates the authentication flow by sending an OTP to the user's email * * @param email - User's email address * @param _userAgent - User agent string (unused, kept for API compatibility) * @param _ipAddress - IP address (unused, kept for API compatibility) * @param env - Optional environment object for Worker contexts * @returns Authentication result with method ID for OTP verification */ export declare function processAuth(email: string, _userAgent: string, _ipAddress: string, env?: any): Promise<{ success: boolean; method_id: string; methodId: string; user_id: string; error?: undefined; details?: undefined; } | { success: boolean; error: string; details: string; method_id?: undefined; methodId?: undefined; user_id?: undefined; }>; /** * Verify OTP and create session * Completes the authentication flow by verifying the OTP code and creating a user session * * @param methodId - Method ID from the authentication process * @param code - OTP code entered by the user * @param email - User's email address * @param _userAgent - User agent string (unused, kept for API compatibility) * @param _ipAddress - IP address (unused, kept for API compatibility) * @returns Session creation result with user and session details */ export declare function verifyOtpAndCreateSession(methodId: string, code: string, email: string, _userAgent: string, _ipAddress: string, env?: unknown): Promise<{ success: boolean; error: string; userId?: undefined; machineId?: undefined; sessionToken?: undefined; sessionJwt?: undefined; expiresAt?: undefined; } | { success: boolean; userId: string; machineId: string; sessionToken: string; sessionJwt: string | undefined; expiresAt: number; error?: undefined; }>; /** * Validate session */ export declare function validateSession(userId: string, machineId: string, sessionToken: string): Promise<{ valid: boolean; error: string; session?: undefined; } | { valid: boolean; session: import("./utils/hybrid-user-context.js").UserContext | null; error?: undefined; }>; /** * Submit analysis request to queue * Queues an analysis request for processing based on the specified type * * @param userId - Unique user identifier * @param machineId - Unique machine identifier * @param analysisType - Type of analysis (double, analyze, earnings, announcements) * @param parameters - Additional parameters for the analysis * @returns Submission result with request ID for tracking */ export declare function submitAnalysisRequest(userId: string, machineId: string, analysisType: string, parameters: Record<string, unknown>): Promise<{ success: boolean; requestId: string; status: string; error?: undefined; } | { success: boolean; error: string; requestId?: undefined; status?: undefined; }>; /** * Get analysis result * Retrieves the result of a previously submitted analysis request * * @param requestId - Unique request identifier * @param userId - Unique user identifier * @returns Analysis result or status information */ export declare function getAnalysisResult(requestId: string, userId: string): Promise<{ requestId: string; userId: string; status: string; message: string; success?: undefined; error?: undefined; } | { success: boolean; error: string; requestId?: undefined; userId?: undefined; status?: undefined; message?: undefined; }>; /** * Process analysis request (for worker/processor) * Internal function to process queued analysis requests * * @param request - Analysis request object from the queue * @returns Processing result */ export declare function processAnalysisRequest(request: unknown): Promise<import("./utils/simple-queue.js").AnalysisResponse>; /** * Start processing analysis requests (for worker processes) * Initiates the background processing of queued analysis requests * * @returns Promise that resolves when processing starts */ export declare function startProcessingRequests(): Promise<void>; /** * Wait for analysis result * Polls for an analysis result until completion or timeout * * @param requestId - Unique request identifier * @param userId - Unique user identifier * @param timeoutMs - Timeout in milliseconds (default: 180 seconds for cache warming + analysis) * @returns Analysis result when ready */ export declare function waitForAnalysisResult(requestId: string, userId: string, timeoutMs?: number): Promise<unknown>; /** * Logout user */ export declare function logoutUser(userId: string, machineId: string): Promise<{ success: boolean; error?: undefined; } | { success: boolean; error: string; }>; /** * Get user status */ export declare function getUserStatus(userId: string, machineId: string): Promise<{ authenticated: boolean; userId?: undefined; email?: undefined; machineId?: undefined; expiresAt?: undefined; permissions?: undefined; error?: undefined; } | { authenticated: boolean; userId: string; email: string; machineId: string; expiresAt: number; permissions: string[]; error?: undefined; } | { authenticated: boolean; error: string; userId?: undefined; email?: undefined; machineId?: undefined; expiresAt?: undefined; permissions?: undefined; }>; /** * Get service statistics */ export declare function getServiceStats(): Promise<{ queue: Record<string, unknown>; sessions: Record<string, unknown>; error?: undefined; } | { error: string; queue?: undefined; sessions?: undefined; }>; /** * Cleanup resources */ export declare function cleanup(): Promise<void>; export { hybridContextManager };