UNPKG

magically-sdk

Version:

Official SDK for Magically - Build mobile apps with AI

81 lines (74 loc) 2.27 kB
// Magically SDK - Sentry-style Global Instance Pattern import { MagicallySDK } from './MagicallySDK'; import { SDKConfig } from './types'; // Global instance (like Sentry) let globalInstance: MagicallySDK | null = null; /** * Initialize Magically SDK with configuration * Call this once at app startup (like Sentry.init()) */ export function init(config?: SDKConfig): void { globalInstance = new MagicallySDK(config); } /** * Create a new Magically client (Supabase-like pattern) * Useful for edge functions and multiple instances */ export function createClient(config?: SDKConfig): MagicallySDK { return new MagicallySDK(config); } // Default export - global instance accessor (like Sentry) const magically = { get auth() { if (!globalInstance) throw new Error('Magically SDK not initialized. Call init() first.'); return globalInstance.auth; }, get data() { if (!globalInstance) throw new Error('Magically SDK not initialized. Call init() first.'); return globalInstance.data; }, get llm() { if (!globalInstance) throw new Error('Magically SDK not initialized. Call init() first.'); return globalInstance.llm; }, get files() { if (!globalInstance) throw new Error('Magically SDK not initialized. Call init() first.'); return globalInstance.files; }, get functions() { if (!globalInstance) throw new Error('Magically SDK not initialized. Call init() first.'); return globalInstance.functions; } }; // Export classes for advanced usage export { MagicallySDK } from './MagicallySDK'; export { MagicallyAuth } from './MagicallyAuth'; export { MagicallyData } from './MagicallyData'; export { MagicallyLLM } from './MagicallyLLM'; export { MagicallyFiles } from './MagicallyFiles'; export { MagicallyFunctions } from './MagicallyFunctions'; // Export types export type { User, AuthState, DataQueryOptions, DataQueryResult, DataInsertOptions, StandardFields, LLMMessage, InvokeOptions, ChatOptions, ImageOptions, InvokeTextResponse, ChatResponse, SingleImageResponse, MultipleImageResponse, ModelsResponse, FileUploadOptions, FileListOptions, UploadedFile, FileListResponse, SDKConfig, AuthCallbackMessage } from './types'; export default magically;