@insforge/sdk 1.0.5-dev.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1627,12 +1627,11 @@ var Realtime = class {
1627
1627
  * If connected, triggers reconnect to apply new token immediately
1628
1628
  */
1629
1629
  onTokenChange() {
1630
- const session = this.tokenManager.getSession();
1631
- const token = session?.accessToken ?? this.anonKey;
1630
+ const token = this.tokenManager.getAccessToken() ?? this.anonKey;
1632
1631
  if (this.socket) {
1633
1632
  this.socket.auth = token ? { token } : {};
1634
1633
  }
1635
- if (this.socket?.connected) {
1634
+ if (this.socket && (this.socket.connected || this.connectPromise)) {
1636
1635
  this.socket.disconnect();
1637
1636
  this.socket.connect();
1638
1637
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/auth.ts","../src/modules/database-postgrest.ts","../src/modules/storage.ts","../src/modules/ai.ts","../src/modules/functions.ts","../src/modules/realtime.ts","../src/modules/email.ts","../src/client.ts"],"sourcesContent":["/**\n * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service\n * \n * @packageDocumentation\n */\n\n// Main client\nexport { InsForgeClient } from './client';\n\n// Types\nexport type {\n InsForgeConfig,\n InsForgeConfig as ClientOptions, // Alias for compatibility\n TokenStorage,\n AuthSession,\n ApiError,\n} from './types';\n\nexport { InsForgeError } from './types';\n\n// Re-export shared schemas that SDK users will need\nexport type {\n UserSchema,\n CreateUserRequest,\n CreateSessionRequest,\n AuthErrorResponse,\n} from '@insforge/shared-schemas';\n\n// Re-export auth module for advanced usage\nexport { Auth } from './modules/auth';\n\n// Re-export database module (using postgrest-js)\nexport { Database } from './modules/database-postgrest';\n// Note: QueryBuilder is no longer exported as we use postgrest-js QueryBuilder internally\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\n\n// Re-export AI module\nexport { AI } from './modules/ai';\n\n// Re-export Functions module\nexport { Functions } from './modules/functions';\nexport type { FunctionInvokeOptions } from './modules/functions';\n\n// Re-export Emails module (Resend-compatible API)\nexport { Emails } from './modules/email';\nexport type { SendEmailOptions, SendEmailResponse } from './modules/email';\n\n// Re-export Realtime module and types\nexport { Realtime } from './modules/realtime';\nexport type {\n RealtimeErrorPayload,\n SubscribeResponse,\n SocketMessage,\n ConnectionState,\n EventCallback,\n} from './modules/realtime';\n\n// Re-export utilities for advanced usage\nexport { HttpClient } from './lib/http-client';\nexport { TokenManager } from './lib/token-manager';\n\n// Factory function for creating clients (Supabase-style)\nimport { InsForgeClient } from './client';\nimport { InsForgeConfig } from './types';\n\nexport function createClient(config: InsForgeConfig): InsForgeClient {\n return new InsForgeClient(config);\n}\n\n// Default export for convenience\nexport default InsForgeClient;\n","/**\n * InsForge SDK Types - only SDK-specific types here\n * Use @insforge/shared-schemas directly for API types\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\n\nexport interface InsForgeConfig {\n /**\n * The base URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n baseUrl?: string;\n\n /**\n * Anonymous API key (optional)\n * Used for public/unauthenticated requests when no user token is set\n */\n anonKey?: string;\n\n /**\n * Edge Function Token (optional)\n * Use this when running in edge functions/serverless with a user's JWT token\n * This token will be used for all authenticated requests\n */\n edgeFunctionToken?: string;\n\n /**\n * Custom fetch implementation (useful for Node.js environments)\n */\n fetch?: typeof fetch;\n\n /**\n * Storage adapter for persisting tokens\n */\n storage?: TokenStorage;\n\n /**\n * Whether to automatically refresh tokens before they expire\n * @default true\n */\n autoRefreshToken?: boolean;\n\n /**\n * Whether to persist session in storage\n * @default true\n */\n persistSession?: boolean;\n\n /**\n * Custom headers to include with every request\n */\n headers?: Record<string, string>;\n}\n\nexport interface TokenStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport interface AuthSession {\n user: UserSchema;\n accessToken: string;\n expiresAt?: Date;\n}\n\nexport interface ApiError {\n error: string;\n message: string;\n statusCode: number;\n nextActions?: string;\n}\n\nexport class InsForgeError extends Error {\n public statusCode: number;\n public error: string;\n public nextActions?: string;\n\n constructor(message: string, statusCode: number, error: string, nextActions?: string) {\n super(message);\n this.name = 'InsForgeError';\n this.statusCode = statusCode;\n this.error = error;\n this.nextActions = nextActions;\n }\n\n static fromApiError(apiError: ApiError): InsForgeError {\n return new InsForgeError(\n apiError.message,\n apiError.statusCode,\n apiError.error,\n apiError.nextActions\n );\n }\n}","import { InsForgeConfig, ApiError, InsForgeError } from '../types';\n\nexport interface RequestOptions extends RequestInit {\n params?: Record<string, string>;\n}\n\nexport class HttpClient {\n public readonly baseUrl: string;\n public readonly fetch: typeof fetch;\n private defaultHeaders: Record<string, string>;\n private anonKey: string | undefined;\n private userToken: string | null = null;\n\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.baseUrl || 'http://localhost:7130';\n // Properly bind fetch to maintain its context\n this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : undefined as any);\n this.anonKey = config.anonKey;\n this.defaultHeaders = {\n ...config.headers,\n };\n\n if (!this.fetch) {\n throw new Error(\n 'Fetch is not available. Please provide a fetch implementation in the config.'\n );\n }\n }\n\n private buildUrl(path: string, params?: Record<string, string>): string {\n const url = new URL(path, this.baseUrl);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n // For select parameter, preserve the exact formatting by normalizing whitespace\n // This ensures PostgREST relationship queries work correctly\n if (key === 'select') {\n // Normalize multiline select strings for PostgREST:\n // 1. Replace all whitespace (including newlines) with single space\n // 2. Remove spaces inside parentheses for proper PostgREST syntax\n // 3. Keep spaces after commas at the top level for readability\n let normalizedValue = value.replace(/\\s+/g, ' ').trim();\n\n // Fix spaces around parentheses and inside them\n normalizedValue = normalizedValue\n .replace(/\\s*\\(\\s*/g, '(') // Remove spaces around opening parens\n .replace(/\\s*\\)\\s*/g, ')') // Remove spaces around closing parens\n .replace(/\\(\\s+/g, '(') // Remove spaces after opening parens\n .replace(/\\s+\\)/g, ')') // Remove spaces before closing parens\n .replace(/,\\s+(?=[^()]*\\))/g, ','); // Remove spaces after commas inside parens\n \n url.searchParams.append(key, normalizedValue);\n } else {\n url.searchParams.append(key, value);\n }\n });\n }\n return url.toString();\n }\n\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { params, headers = {}, body, ...fetchOptions } = options;\n \n const url = this.buildUrl(path, params);\n \n const requestHeaders: Record<string, string> = {\n ...this.defaultHeaders,\n };\n \n // Set Authorization header: prefer user token, fallback to anon key\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n requestHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n \n // Handle body serialization\n let processedBody: any;\n if (body !== undefined) {\n // Check if body is FormData (for file uploads)\n if (typeof FormData !== 'undefined' && body instanceof FormData) {\n // Don't set Content-Type for FormData, let browser set it with boundary\n processedBody = body;\n } else {\n // JSON body\n if (method !== 'GET') {\n requestHeaders['Content-Type'] = 'application/json;charset=UTF-8';\n }\n processedBody = JSON.stringify(body);\n }\n }\n \n Object.assign(requestHeaders, headers);\n \n const response = await this.fetch(url, {\n method,\n headers: requestHeaders,\n body: processedBody,\n ...fetchOptions,\n });\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n // Try to parse JSON response\n let data: any;\n const contentType = response.headers.get('content-type');\n // Check for any JSON content type (including PostgREST's vnd.pgrst.object+json)\n if (contentType?.includes('json')) {\n data = await response.json();\n } else {\n // For non-JSON responses, return text\n data = await response.text();\n }\n\n // Handle errors\n if (!response.ok) {\n if (data && typeof data === 'object' && 'error' in data) {\n // Add the HTTP status code if not already in the data\n if (!data.statusCode && !data.status) {\n data.statusCode = response.status;\n }\n const error = InsForgeError.fromApiError(data as ApiError);\n // Preserve all additional fields from the error response\n Object.keys(data).forEach(key => {\n if (key !== 'error' && key !== 'message' && key !== 'statusCode') {\n (error as any)[key] = data[key];\n }\n });\n throw error;\n }\n throw new InsForgeError(\n `Request failed: ${response.statusText}`,\n response.status,\n 'REQUEST_FAILED'\n );\n }\n\n return data as T;\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n post<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n put<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n setAuthToken(token: string | null) {\n this.userToken = token;\n }\n\n getHeaders(): Record<string, string> {\n const headers = { ...this.defaultHeaders };\n \n // Include Authorization header if token is available (same logic as request method)\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n headers['Authorization'] = `Bearer ${authToken}`;\n }\n \n return headers;\n }\n}","/**\n * Token Manager for InsForge SDK\n * \n * Simple token storage that supports two modes:\n * - Memory mode (new backend): tokens stored in memory only, more secure\n * - Storage mode (legacy backend): tokens persisted in localStorage\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\nimport type { AuthSession, TokenStorage } from '../types';\n\n// localStorage keys\nexport const TOKEN_KEY = 'insforge-auth-token';\nexport const USER_KEY = 'insforge-auth-user';\n\n// CSRF token cookie name\nexport const CSRF_TOKEN_COOKIE = 'insforge_csrf_token';\n\n/**\n * Get CSRF token from cookie\n * Used to include in X-CSRF-Token header for refresh requests\n */\nexport function getCsrfToken(): string | null {\n if (typeof document === 'undefined') return null;\n const match = document.cookie\n .split(';')\n .find(c => c.trim().startsWith(`${CSRF_TOKEN_COOKIE}=`));\n if (!match) return null;\n return match.split('=')[1] || null;\n}\n\n/**\n * Set CSRF token cookie\n * Called after login/register/refresh to store the CSRF token\n */\nexport function setCsrfToken(token: string): void {\n if (typeof document === 'undefined') return;\n const maxAge = 7 * 24 * 60 * 60; // 7 days (same as refresh token)\n const secure = (typeof window !== 'undefined' && window.location.protocol === 'https:') ? '; Secure' : '';\n document.cookie = `${CSRF_TOKEN_COOKIE}=${encodeURIComponent(token)}; path=/; max-age=${maxAge}; SameSite=Lax${secure}`;\n}\n\n/**\n * Clear CSRF token cookie\n * Called on logout\n */\nexport function clearCsrfToken(): void {\n if (typeof document === 'undefined') return;\n const secure = (typeof window !== 'undefined' && window.location.protocol === 'https:') ? '; Secure' : '';\n document.cookie = `${CSRF_TOKEN_COOKIE}=; path=/; max-age=0; SameSite=Lax${secure}`;\n}\n\nexport class TokenManager {\n // In-memory storage\n private accessToken: string | null = null;\n private user: UserSchema | null = null;\n\n // Persistent storage (for legacy backend)\n private storage: TokenStorage;\n\n // Mode: 'memory' (new backend) or 'storage' (legacy backend, default)\n private _mode: 'memory' | 'storage' = 'storage';\n\n // Callback for token changes (used by realtime to reconnect with new token)\n onTokenChange: (() => void) | null = null;\n\n constructor(storage?: TokenStorage) {\n if (storage) {\n // Use provided storage\n this.storage = storage;\n } else if (typeof window !== 'undefined' && window.localStorage) {\n // Browser: use localStorage\n this.storage = window.localStorage;\n } else {\n // Node.js: use in-memory storage\n const store = new Map<string, string>();\n this.storage = {\n getItem: (key: string) => store.get(key) || null,\n setItem: (key: string, value: string) => { store.set(key, value); },\n removeItem: (key: string) => { store.delete(key); }\n };\n }\n }\n\n /**\n * Get current mode\n */\n get mode(): 'memory' | 'storage' {\n return this._mode;\n }\n\n /**\n * Set mode to memory (new backend with cookies + memory)\n */\n setMemoryMode(): void {\n if (this._mode === 'storage') {\n // Clear localStorage when switching from storage to memory mode\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n }\n this._mode = 'memory';\n }\n\n /**\n * Set mode to storage (legacy backend with localStorage)\n * Also loads existing session from localStorage\n */\n setStorageMode(): void {\n this._mode = 'storage';\n this.loadFromStorage();\n }\n\n /**\n * Load session from localStorage\n */\n private loadFromStorage(): void {\n const token = this.storage.getItem(TOKEN_KEY) as string | null;\n const userStr = this.storage.getItem(USER_KEY) as string | null;\n\n if (token && userStr) {\n try {\n this.accessToken = token;\n this.user = JSON.parse(userStr);\n } catch {\n this.clearSession();\n }\n }\n }\n\n /**\n * Save session (memory always, localStorage only in storage mode)\n */\n saveSession(session: AuthSession): void {\n const tokenChanged = session.accessToken !== this.accessToken;\n this.accessToken = session.accessToken;\n this.user = session.user;\n\n // Persist to localStorage in storage mode\n if (this._mode === 'storage') {\n this.storage.setItem(TOKEN_KEY, session.accessToken);\n this.storage.setItem(USER_KEY, JSON.stringify(session.user));\n }\n\n if (tokenChanged && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Get current session\n */\n getSession(): AuthSession | null {\n this.loadFromStorage();\n if (!this.accessToken || !this.user) return null;\n return {\n accessToken: this.accessToken,\n user: this.user,\n };\n }\n\n /**\n * Get access token\n */\n getAccessToken(): string | null {\n this.loadFromStorage();\n return this.accessToken;\n }\n\n /**\n * Set access token\n */\n setAccessToken(token: string): void {\n const tokenChanged = token !== this.accessToken;\n this.accessToken = token;\n if (this._mode === 'storage') {\n this.storage.setItem(TOKEN_KEY, token);\n }\n if (tokenChanged && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Get user\n */\n getUser(): UserSchema | null {\n return this.user;\n }\n\n /**\n * Set user\n */\n setUser(user: UserSchema): void {\n this.user = user;\n if (this._mode === 'storage') {\n this.storage.setItem(USER_KEY, JSON.stringify(user));\n }\n }\n\n /**\n * Clear session (both memory and localStorage)\n */\n clearSession(): void {\n const hadToken = this.accessToken !== null;\n this.accessToken = null;\n this.user = null;\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n\n if (hadToken && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Check if there's a session in localStorage (for legacy detection)\n */\n hasStoredSession(): boolean {\n const token = this.storage.getItem(TOKEN_KEY);\n return !!token;\n }\n}","/**\n * Auth module for InsForge SDK\n * Uses shared schemas for type safety\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager, getCsrfToken, setCsrfToken, clearCsrfToken } from '../lib/token-manager';\nimport { AuthSession, InsForgeError } from '../types';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\n GetPublicAuthConfigResponse,\n OAuthProvidersSchema,\n SendVerificationEmailRequest,\n SendResetPasswordEmailRequest,\n ExchangeResetPasswordTokenRequest,\n VerifyEmailRequest,\n VerifyEmailResponse,\n UserSchema,\n GetProfileResponse,\n} from '@insforge/shared-schemas';\n\n/**\n * Check if current environment is a hosted auth environment\n * Returns true for:\n * - localhost with port 7130 (hosted auth app dev)\n * - https://*.insforge.app (hosted auth app production)\n */\nfunction isHostedAuthEnvironment(): boolean {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const { hostname, port, protocol } = window.location;\n\n // Check for localhost:7130\n if (hostname === 'localhost' && port === '7130') {\n return true;\n }\n\n // Check for https://*.insforge.app\n if (protocol === 'https:' && hostname.endsWith('.insforge.app')) {\n return true;\n }\n\n return false;\n}\n\nexport class Auth {\n constructor(\n private http: HttpClient,\n private tokenManager: TokenManager\n ) {\n // Auto-detect OAuth callback parameters in the URL\n this.detectAuthCallback();\n }\n\n /**\n * Automatically detect and handle OAuth callback parameters in the URL\n * This runs after initialization to seamlessly complete the OAuth flow\n * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)\n */\n private detectAuthCallback(): void {\n // Only run in browser environment\n if (typeof window === 'undefined') return;\n\n try {\n const params = new URLSearchParams(window.location.search);\n // Backend returns: access_token, user_id, email, name (optional), csrf_token\n const accessToken = params.get('access_token');\n const userId = params.get('user_id');\n const email = params.get('email');\n const name = params.get('name');\n const csrfToken = params.get('csrf_token');\n\n // Check if we have OAuth callback parameters\n if (accessToken && userId && email) {\n if (csrfToken) {\n this.tokenManager.setMemoryMode();\n setCsrfToken(csrfToken);\n }\n // TODO: Use PKCE in future\n // Create session with the data from backend\n const session: AuthSession = {\n accessToken,\n user: {\n id: userId,\n email: email,\n profile: { name: name || '' },\n metadata: null,\n // These fields are not provided by backend OAuth callback\n // They'll be populated when calling getCurrentUser()\n emailVerified: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n },\n };\n\n // Save session and set auth token\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(accessToken);\n\n // Clean up the URL to remove sensitive parameters\n const url = new URL(window.location.href);\n url.searchParams.delete('access_token');\n url.searchParams.delete('user_id');\n url.searchParams.delete('email');\n url.searchParams.delete('name');\n url.searchParams.delete('csrf_token');\n\n // Also handle error case from backend (line 581)\n if (params.has('error')) {\n url.searchParams.delete('error');\n }\n\n // Replace URL without adding to browser history\n window.history.replaceState({}, document.title, url.toString());\n }\n } catch (error) {\n // Silently continue - don't break initialization\n console.debug('OAuth callback detection skipped:', error);\n }\n }\n\n /**\n * Sign up a new user\n */\n async signUp(request: CreateUserRequest): Promise<{\n data: CreateUserResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateUserResponse>('/api/auth/users', request);\n\n // Save session internally only if both accessToken and user exist\n if (response.accessToken && response.user && !isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n error instanceof Error ? error.message : 'An unexpected error occurred during sign up',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with email and password\n */\n async signInWithPassword(request: CreateSessionRequest): Promise<{\n data: CreateSessionResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateSessionResponse>('/api/auth/sessions', request);\n\n if (!isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred during sign in',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with OAuth provider\n */\n async signInWithOAuth(options: {\n provider: OAuthProvidersSchema;\n redirectTo?: string;\n skipBrowserRedirect?: boolean;\n }): Promise<{\n data: { url?: string; provider?: string };\n error: InsForgeError | null;\n }> {\n try {\n const { provider, redirectTo, skipBrowserRedirect } = options;\n\n const params = redirectTo\n ? { redirect_uri: redirectTo }\n : undefined;\n\n const endpoint = `/api/auth/oauth/${provider}`;\n const response = await this.http.get<GetOauthUrlResponse>(endpoint, { params });\n\n // Automatically redirect in browser unless told not to\n if (typeof window !== 'undefined' && !skipBrowserRedirect) {\n window.location.href = response.authUrl;\n return { data: {}, error: null };\n }\n\n return {\n data: {\n url: response.authUrl,\n provider\n },\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: {}, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: {},\n error: new InsForgeError(\n 'An unexpected error occurred during OAuth initialization',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign out the current user\n */\n async signOut(): Promise<{ error: InsForgeError | null }> {\n try {\n // Try to call backend logout to clear httpOnly refresh cookie\n // This may fail for legacy backends, but that's ok\n try {\n await this.http.post('/api/auth/logout', undefined, { credentials: 'include' });\n } catch {\n // Ignore errors - legacy backend may not have this endpoint\n }\n\n // Clear local session and cookies\n this.tokenManager.clearSession();\n this.http.setAuthToken(null);\n clearCsrfToken();\n\n return { error: null };\n } catch (error) {\n return {\n error: new InsForgeError(\n 'Failed to sign out',\n 500,\n 'SIGNOUT_ERROR'\n )\n };\n }\n }\n\n\n /**\n * Get all public authentication configuration (OAuth + Email)\n * Returns both OAuth providers and email authentication settings in one request\n * This is a public endpoint that doesn't require authentication\n * \n * @returns Complete public authentication configuration including OAuth providers and email auth settings\n * \n * @example\n * ```ts\n * const { data, error } = await insforge.auth.getPublicAuthConfig();\n * if (data) {\n * console.log(`OAuth providers: ${data.oauth.data.length}`);\n * console.log(`Password min length: ${data.email.passwordMinLength}`);\n * }\n * ```\n */\n async getPublicAuthConfig(): Promise<{\n data: GetPublicAuthConfigResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.get<GetPublicAuthConfigResponse>('/api/auth/public-config');\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching public authentication configuration',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n\n /**\n * Get the current user with full profile information\n * Returns both auth info (id, email, role) and profile data (dynamic fields from users table)\n */\n async getCurrentUser(): Promise<{\n data: {\n user: UserSchema;\n } | null;\n error: any | null;\n }> {\n try {\n // Check if we have a stored user\n const user = this.tokenManager.getUser();\n\n if (user) {\n return { data: { user }, error: null };\n }\n const accessToken = this.tokenManager.getAccessToken();\n if (!accessToken) {\n return { data: null, error: null };\n }\n\n // Call the API for auth info\n this.http.setAuthToken(accessToken);\n const authResponse = await this.http.get<GetCurrentSessionResponse>('/api/auth/sessions/current');\n\n return {\n data: {\n user: authResponse.user,\n },\n error: null\n };\n } catch (error) {\n // If unauthorized, clear session\n if (error instanceof InsForgeError && error.statusCode === 401) {\n await this.signOut();\n return { data: null, error: null };\n }\n\n // Pass through all other errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching user',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get any user's profile by ID\n * Returns profile information from the users table\n */\n async getProfile(userId: string): Promise<{\n data: GetProfileResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.get<GetProfileResponse>(`/api/auth/profiles/${userId}`);\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged (includes 404 NOT_FOUND, 400 INVALID_INPUT)\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching user profile',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get the current session (only session data, no API call)\n * Returns the stored JWT token and basic user info from local storage\n */\n async getCurrentSession(): Promise<{\n data: { session: AuthSession | null };\n error: InsForgeError | null;\n }> {\n try {\n // Step 1: Check if we already have session in memory\n const session = this.tokenManager.getSession();\n if (session) {\n this.http.setAuthToken(session.accessToken);\n return { data: { session }, error: null };\n }\n\n // Step 2: In browser, try to refresh using httpOnly cookie\n if (typeof window !== 'undefined') {\n try {\n const csrfToken = getCsrfToken();\n const response = await this.http.post<{\n accessToken: string;\n user?: UserSchema;\n csrfToken?: string\n }>(\n '/api/auth/refresh',\n undefined,\n {\n headers: csrfToken ? { 'X-CSRF-Token': csrfToken } : {},\n credentials: 'include',\n }\n );\n\n if (response.accessToken) {\n this.tokenManager.setMemoryMode();\n this.tokenManager.setAccessToken(response.accessToken);\n this.http.setAuthToken(response.accessToken);\n\n if (response.user) {\n this.tokenManager.setUser(response.user);\n }\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n\n return {\n data: { session: this.tokenManager.getSession() },\n error: null\n };\n }\n } catch (error) {\n if (error instanceof InsForgeError) {\n if (error.statusCode === 404) {\n // Legacy backend - try localStorage\n this.tokenManager.setStorageMode();\n const session = this.tokenManager.getSession();\n if (session) {\n return { data: { session }, error: null };\n }\n return { data: { session: null }, error: null };\n }\n // 401/403 or other errors - not logged in\n return { data: { session: null }, error: error };\n }\n }\n }\n\n // Not logged in\n return { data: { session: null }, error: null };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: { session: null }, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: { session: null },\n error: new InsForgeError(\n 'An unexpected error occurred while getting session',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Set/Update the current user's profile\n * Updates profile information in the users table (supports any dynamic fields)\n * Requires authentication\n */\n async setProfile(profile: Record<string, unknown>): Promise<{\n data: GetProfileResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.patch<GetProfileResponse>(\n '/api/auth/profiles/current',\n { profile }\n );\n\n // Update the local session/user with the new profile data\n const currentUser = this.tokenManager.getUser();\n if (currentUser && response.profile !== undefined) {\n this.tokenManager.setUser({\n ...currentUser,\n profile: response.profile,\n });\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged (includes 401 AUTH_INVALID_CREDENTIALS, 400 INVALID_INPUT)\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while updating user profile',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Send email verification (code or link based on config)\n *\n * Send email verification using the method configured in auth settings (verifyEmailMethod).\n * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.\n * Prevents user enumeration by returning success even if email doesn't exist.\n */\n async sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{\n data: { success: boolean; message: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ success: boolean; message: string }>(\n '/api/auth/email/send-verification',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while sending verification code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Send password reset (code or link based on config)\n *\n * Send password reset email using the method configured in auth settings (resetPasswordMethod).\n * When method is 'code', sends a 6-digit numeric code for two-step flow.\n * When method is 'link', sends a magic link.\n * Prevents user enumeration by returning success even if email doesn't exist.\n */\n async sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{\n data: { success: boolean; message: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ success: boolean; message: string }>(\n '/api/auth/email/send-reset-password',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while sending password reset code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Exchange reset password code for reset token\n *\n * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):\n * 1. Verify the 6-digit code sent to user's email\n * 2. Return a reset token that can be used to actually reset the password\n *\n * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).\n */\n async exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{\n data: { token: string; expiresAt: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ token: string; expiresAt: string }>(\n '/api/auth/email/exchange-reset-password-token',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while verifying reset code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Reset password with token\n *\n * Reset user password with a token. The token can be:\n * - Magic link token (64-character hex token from send-reset-password when method is 'link')\n * - Reset token (from exchange-reset-password-token after code verification when method is 'code')\n *\n * Both token types use RESET_PASSWORD purpose and are verified the same way.\n *\n * Flow summary:\n * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)\n * - Link method: send-reset-password → reset-password (with link token directly)\n */\n async resetPassword(request: { newPassword: string; otp: string }): Promise<{\n data: { message: string; redirectTo?: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ message: string; redirectTo?: string }>(\n '/api/auth/email/reset-password',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while resetting password',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Verify email with code or link\n *\n * Verify email address using the method configured in auth settings (verifyEmailMethod):\n * - Code verification: Provide both `email` and `otp` (6-digit numeric code)\n * - Link verification: Provide only `otp` (64-character hex token from magic link)\n *\n * Successfully verified users will receive a session token.\n *\n * The email verification link sent to users always points to the backend API endpoint.\n * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.\n * Otherwise, a default success page is displayed.\n */\n async verifyEmail(request: VerifyEmailRequest): Promise<{\n data: VerifyEmailResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<VerifyEmailResponse>(\n '/api/auth/email/verify',\n request\n );\n\n // Save session if we got a token\n if (!isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while verifying email',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n}","/**\n * Database module using @supabase/postgrest-js\n * Complete replacement for custom QueryBuilder with full PostgREST features\n */\n\nimport { PostgrestClient } from '@supabase/postgrest-js';\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\n\n\n/**\n * Custom fetch that transforms URLs and adds auth\n */\nfunction createInsForgePostgrestFetch(\n httpClient: HttpClient,\n tokenManager: TokenManager\n): typeof fetch {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const url = typeof input === 'string' ? input : input.toString();\n const urlObj = new URL(url);\n \n // Extract table name from pathname\n // postgrest-js sends: http://dummy/tablename?params\n // We need: http://localhost:7130/api/database/records/tablename?params\n const tableName = urlObj.pathname.slice(1); // Remove leading /\n \n // Build InsForge URL\n const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;\n \n // Get auth token from TokenManager or HttpClient\n const token = tokenManager.getAccessToken();\n const httpHeaders = httpClient.getHeaders();\n const authToken = token || httpHeaders['Authorization']?.replace('Bearer ', '');\n \n // Prepare headers\n const headers = new Headers(init?.headers);\n if (authToken && !headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${authToken}`);\n }\n \n // Make the actual request using native fetch\n const response = await fetch(insforgeUrl, {\n ...init,\n headers\n });\n \n return response;\n };\n}\n\n/**\n * Database client using postgrest-js\n * Drop-in replacement with FULL PostgREST capabilities\n */\nexport class Database {\n private postgrest: PostgrestClient<any, any, any>;\n \n constructor(httpClient: HttpClient, tokenManager: TokenManager) {\n // Create postgrest client with custom fetch\n this.postgrest = new PostgrestClient<any, any, any>('http://dummy', {\n fetch: createInsForgePostgrestFetch(httpClient, tokenManager),\n headers: {}\n });\n }\n \n /**\n * Create a query builder for a table\n * \n * @example\n * // Basic query\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId);\n * \n * // With count (Supabase style!)\n * const { data, error, count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact' })\n * .range(0, 9);\n * \n * // Just get count, no data\n * const { count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact', head: true });\n * \n * // Complex queries with OR\n * const { data } = await client.database\n * .from('posts')\n * .select('*, users!inner(*)')\n * .or('status.eq.active,status.eq.pending');\n * \n * // All features work:\n * - Nested selects\n * - Foreign key expansion \n * - OR/AND/NOT conditions\n * - Count with head\n * - Range pagination\n * - Upserts\n */\n from(table: string) {\n // Return postgrest query builder with all features\n return this.postgrest.from(table);\n }\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n}\n\ninterface UploadStrategy {\n method: 'direct' | 'presigned';\n uploadUrl: string;\n fields?: Record<string, string>;\n key: string;\n confirmRequired: boolean;\n confirmUrl?: string;\n expiresAt?: Date;\n}\n\ninterface DownloadStrategy {\n method: 'direct' | 'presigned';\n url: string;\n expiresAt?: Date;\n}\n\n/**\n * Storage bucket operations\n */\nexport class StorageBucket {\n constructor(\n private bucketName: string,\n private http: HttpClient\n ) {}\n\n /**\n * Upload a file with a specific key\n * Uses the upload strategy from backend (direct or presigned)\n * @param path - The object key/path\n * @param file - File or Blob to upload\n */\n async upload(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'PUT',\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * Uses the upload strategy from backend (direct or presigned)\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const filename = file instanceof File ? file.name : 'file';\n \n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'POST',\n `/api/storage/buckets/${this.bucketName}/objects`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Internal method to handle presigned URL uploads\n */\n private async uploadWithPresignedUrl(\n strategy: UploadStrategy,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Upload to presigned URL (e.g., S3)\n const formData = new FormData();\n \n // Add all fields from the presigned URL\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be the last field for S3\n formData.append('file', file);\n\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n throw new InsForgeError(\n `Upload to storage failed: ${uploadResponse.statusText}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Confirm upload with backend if required\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n }\n );\n\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, return basic file info\n return {\n data: {\n key: strategy.key,\n bucket: this.bucketName,\n size: file.size,\n mimeType: file.type || 'application/octet-stream',\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n } as StorageFileSchema,\n error: null\n };\n } catch (error) {\n throw error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n );\n }\n }\n\n /**\n * Download a file\n * Uses the download strategy from backend (direct or presigned)\n * @param path - The object key/path\n * Returns the file as a Blob\n */\n async download(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n // Get download strategy from backend - this is required\n const strategyResponse = await this.http.post<DownloadStrategy>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n { expiresIn: 3600 }\n );\n\n // Use URL from strategy\n const downloadUrl = strategyResponse.url;\n \n // Download from the URL\n const headers: HeadersInit = {};\n \n // Only add auth header for direct downloads (not presigned URLs)\n if (strategyResponse.method === 'direct') {\n Object.assign(headers, this.http.getHeaders());\n }\n \n const response = await fetch(downloadUrl, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n try {\n const error = await response.json();\n throw InsForgeError.fromApiError(error);\n } catch {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\n );\n }\n }\n\n const blob = await response.blob();\n return { data: blob, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Get public URL for a file\n * @param path - The object key/path\n */\n getPublicUrl(path: string): string {\n return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n }\n\n /**\n * List objects in the bucket\n * @param prefix - Filter by key prefix\n * @param search - Search in file names\n * @param limit - Maximum number of results (default: 100, max: 1000)\n * @param offset - Number of results to skip\n */\n async list(options?: {\n prefix?: string;\n search?: string;\n limit?: number;\n offset?: number;\n }): Promise<StorageResponse<ListObjectsResponseSchema>> {\n try {\n const params: Record<string, string> = {};\n \n if (options?.prefix) params.prefix = options.prefix;\n if (options?.search) params.search = options.search;\n if (options?.limit) params.limit = options.limit.toString();\n if (options?.offset) params.offset = options.offset.toString();\n\n const response = await this.http.get<ListObjectsResponseSchema>(\n `/api/storage/buckets/${this.bucketName}/objects`,\n { params }\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'List failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Delete a file\n * @param path - The object key/path\n */\n async remove(path: string): Promise<StorageResponse<{ message: string }>> {\n try {\n const response = await this.http.delete<{ message: string }>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Delete failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n}\n\n/**\n * Storage module for file operations\n */\nexport class Storage {\n constructor(private http: HttpClient) {}\n\n /**\n * Get a bucket instance for operations\n * @param bucketName - Name of the bucket\n */\n from(bucketName: string): StorageBucket {\n return new StorageBucket(bucketName, this.http);\n }\n}","/**\n * AI Module for Insforge SDK\n * Response format roughly matches OpenAI SDK for compatibility\n *\n * The backend handles all the complexity of different AI providers\n * and returns a unified format. This SDK transforms responses to match OpenAI-like format.\n */\n\nimport { HttpClient } from \"../lib/http-client\";\nimport {\n ChatCompletionRequest,\n ChatCompletionResponse,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@insforge/shared-schemas\";\n\nexport class AI {\n public readonly chat: Chat;\n public readonly images: Images;\n\n constructor(private http: HttpClient) {\n this.chat = new Chat(http);\n this.images = new Images(http);\n }\n}\n\nclass Chat {\n public readonly completions: ChatCompletions;\n\n constructor(http: HttpClient) {\n this.completions = new ChatCompletions(http);\n }\n}\n\nclass ChatCompletions {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a chat completion - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const completion = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Hello!' }]\n * });\n * console.log(completion.choices[0].message.content);\n *\n * // With images\n * const response = await client.ai.chat.completions.create({\n * model: 'gpt-4-vision',\n * messages: [{\n * role: 'user',\n * content: 'What is in this image?',\n * images: [{ url: 'https://example.com/image.jpg' }]\n * }]\n * });\n *\n * // Streaming - returns async iterable\n * const stream = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * stream: true\n * });\n *\n * for await (const chunk of stream) {\n * if (chunk.choices[0]?.delta?.content) {\n * process.stdout.write(chunk.choices[0].delta.content);\n * }\n * }\n * ```\n */\n async create(params: ChatCompletionRequest): Promise<any> {\n // Backend already expects camelCase, no transformation needed\n const backendParams = {\n model: params.model,\n messages: params.messages,\n temperature: params.temperature,\n maxTokens: params.maxTokens,\n topP: params.topP,\n stream: params.stream,\n };\n\n // For streaming, return an async iterable that yields OpenAI-like chunks\n if (params.stream) {\n const headers = this.http.getHeaders();\n headers[\"Content-Type\"] = \"application/json\";\n\n const response = await this.http.fetch(\n `${this.http.baseUrl}/api/ai/chat/completion`,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(backendParams),\n }\n );\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(error.error || \"Stream request failed\");\n }\n\n // Return async iterable that parses SSE and transforms to OpenAI-like format\n return this.parseSSEStream(response, params.model);\n }\n\n // Non-streaming: transform response to OpenAI-like format\n const response: ChatCompletionResponse = await this.http.post(\n \"/api/ai/chat/completion\",\n backendParams\n );\n\n // Transform to OpenAI-like format\n const content = response.text || \"\";\n\n return {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: response.metadata?.model,\n choices: [\n {\n index: 0,\n message: {\n role: \"assistant\",\n content,\n },\n finish_reason: \"stop\",\n },\n ],\n usage: response.metadata?.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n },\n };\n }\n\n /**\n * Parse SSE stream into async iterable of OpenAI-like chunks\n */\n private async *parseSSEStream(\n response: Response,\n model: string\n ): AsyncIterableIterator<any> {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() || \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const dataStr = line.slice(6).trim();\n if (dataStr) {\n try {\n const data = JSON.parse(dataStr);\n\n // Transform to OpenAI-like streaming format\n if (data.chunk || data.content) {\n yield {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [\n {\n index: 0,\n delta: {\n content: data.chunk || data.content,\n },\n finish_reason: data.done ? \"stop\" : null,\n },\n ],\n };\n }\n\n // If we received the done signal, we can stop\n if (data.done) {\n reader.releaseLock();\n return;\n }\n } catch (e) {\n // Skip invalid JSON\n console.warn(\"Failed to parse SSE data:\", dataStr);\n }\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nclass Images {\n constructor(private http: HttpClient) {}\n\n /**\n * Generate images - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Text-to-image\n * const response = await client.ai.images.generate({\n * model: 'dall-e-3',\n * prompt: 'A sunset over mountains',\n * });\n * console.log(response.images[0].url);\n *\n * // Image-to-image (with input images)\n * const response = await client.ai.images.generate({\n * model: 'stable-diffusion-xl',\n * prompt: 'Transform this into a watercolor painting',\n * images: [\n * { url: 'https://example.com/input.jpg' },\n * // or base64-encoded Data URI:\n * { url: 'data:image/jpeg;base64,/9j/4AAQ...' }\n * ]\n * });\n * ```\n */\n async generate(params: ImageGenerationRequest): Promise<any> {\n const response: ImageGenerationResponse = await this.http.post(\n \"/api/ai/image/generation\",\n params\n );\n \n // Build data array based on response content\n let data: Array<{ b64_json?: string; content?: string }> = [];\n \n if (response.images && response.images.length > 0) {\n // Has images - extract base64 and include text\n data = response.images.map(img => ({\n b64_json: img.imageUrl.replace(/^data:image\\/\\w+;base64,/, ''),\n content: response.text\n }));\n } else if (response.text) {\n // Text-only response\n data = [{ content: response.text }];\n }\n \n // Return OpenAI-compatible format\n return {\n created: Math.floor(Date.now() / 1000),\n data,\n ...(response.metadata?.usage && {\n usage: {\n total_tokens: response.metadata.usage.totalTokens || 0,\n input_tokens: response.metadata.usage.promptTokens || 0,\n output_tokens: response.metadata.usage.completionTokens || 0,\n }\n })\n };\n }\n}\n","import { HttpClient } from '../lib/http-client';\n\nexport interface FunctionInvokeOptions {\n /**\n * The body of the request\n */\n body?: any;\n \n /**\n * Custom headers to send with the request\n */\n headers?: Record<string, string>;\n \n /**\n * HTTP method (default: POST)\n */\n method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n}\n\n/**\n * Edge Functions client for invoking serverless functions\n * \n * @example\n * ```typescript\n * // Invoke a function with JSON body\n * const { data, error } = await client.functions.invoke('hello-world', {\n * body: { name: 'World' }\n * });\n * \n * // GET request\n * const { data, error } = await client.functions.invoke('get-data', {\n * method: 'GET'\n * });\n * ```\n */\nexport class Functions {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Invokes an Edge Function\n * @param slug The function slug to invoke\n * @param options Request options\n */\n async invoke<T = any>(\n slug: string,\n options: FunctionInvokeOptions = {}\n ): Promise<{ data: T | null; error: Error | null }> {\n try {\n const { method = 'POST', body, headers = {} } = options;\n \n // Simple path: /functions/{slug}\n const path = `/functions/${slug}`;\n \n // Use the HTTP client's request method\n const data = await this.http.request<T>(\n method,\n path,\n { body, headers }\n );\n \n return { data, error: null };\n } catch (error: any) {\n // The HTTP client throws InsForgeError with all properties from the response\n // including error, message, details, statusCode, etc.\n // We need to preserve all of that information\n return { \n data: null, \n error: error // Pass through the full error object with all properties\n };\n }\n }\n}","import { io, Socket } from 'socket.io-client';\nimport type { SubscribeResponse, RealtimeErrorPayload, SocketMessage } from '@insforge/shared-schemas';\nimport { TokenManager } from '../lib/token-manager';\n\nexport type { SubscribeResponse, RealtimeErrorPayload, SocketMessage };\n\nexport type ConnectionState = 'disconnected' | 'connecting' | 'connected';\n\nexport type EventCallback<T = unknown> = (payload: T) => void;\n\nconst CONNECT_TIMEOUT = 10000;\n\n/**\n * Realtime module for subscribing to channels and handling real-time events\n *\n * @example\n * ```typescript\n * const { realtime } = client;\n *\n * // Connect to the realtime server\n * await realtime.connect();\n *\n * // Subscribe to a channel\n * const response = await realtime.subscribe('orders:123');\n * if (!response.ok) {\n * console.error('Failed to subscribe:', response.error);\n * }\n *\n * // Listen for specific events\n * realtime.on('order_updated', (payload) => {\n * console.log('Order updated:', payload);\n * });\n *\n * // Listen for connection events\n * realtime.on('connect', () => console.log('Connected!'));\n * realtime.on('connect_error', (err) => console.error('Connection failed:', err));\n * realtime.on('disconnect', (reason) => console.log('Disconnected:', reason));\n * realtime.on('error', (error) => console.error('Realtime error:', error));\n *\n * // Publish a message to a channel\n * await realtime.publish('orders:123', 'status_changed', { status: 'shipped' });\n *\n * // Unsubscribe and disconnect when done\n * realtime.unsubscribe('orders:123');\n * realtime.disconnect();\n * ```\n */\nexport class Realtime {\n private baseUrl: string;\n private tokenManager: TokenManager;\n private socket: Socket | null = null;\n private connectPromise: Promise<void> | null = null;\n private subscribedChannels: Set<string> = new Set();\n private eventListeners: Map<string, Set<EventCallback>> = new Map();\n private anonKey?: string;\n\n constructor(baseUrl: string, tokenManager: TokenManager, anonKey?: string) {\n this.baseUrl = baseUrl;\n this.tokenManager = tokenManager;\n this.anonKey = anonKey;\n\n // Handle token changes (e.g., after refresh)\n this.tokenManager.onTokenChange = () => this.onTokenChange();\n }\n\n private notifyListeners(event: string, payload?: unknown): void {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n for (const cb of listeners) {\n try {\n cb(payload);\n } catch (err) {\n console.error(`Error in ${event} callback:`, err);\n }\n }\n }\n\n /**\n * Connect to the realtime server\n * @returns Promise that resolves when connected\n */\n connect(): Promise<void> {\n // Already connected\n if (this.socket?.connected) {\n return Promise.resolve();\n }\n\n // Connection already in progress, return existing promise\n if (this.connectPromise) {\n return this.connectPromise;\n }\n\n this.connectPromise = new Promise((resolve, reject) => {\n const session = this.tokenManager.getSession();\n const token = session?.accessToken ?? this.anonKey;\n \n\n this.socket = io(this.baseUrl, {\n transports: ['websocket'],\n auth: token ? { token } : undefined,\n });\n\n let initialConnection = true;\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n const cleanup = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n timeoutId = setTimeout(() => {\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n this.socket?.disconnect();\n this.socket = null;\n reject(new Error(`Connection timeout after ${CONNECT_TIMEOUT}ms`));\n }\n }, CONNECT_TIMEOUT);\n\n this.socket.on('connect', () => {\n cleanup();\n // Re-subscribe to channels on every connect (initial + reconnects)\n for (const channel of this.subscribedChannels) {\n this.socket!.emit('realtime:subscribe', { channel });\n }\n this.notifyListeners('connect');\n\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n resolve();\n }\n });\n\n this.socket.on('connect_error', (error: Error) => {\n cleanup();\n this.notifyListeners('connect_error', error);\n\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n reject(error);\n }\n });\n\n this.socket.on('disconnect', (reason: string) => {\n this.notifyListeners('disconnect', reason);\n });\n\n this.socket.on('realtime:error', (error: RealtimeErrorPayload) => {\n this.notifyListeners('error', error);\n });\n\n // Route custom events to listeners (onAny doesn't catch socket reserved events)\n this.socket.onAny((event: string, message: SocketMessage) => {\n if (event === 'realtime:error') return; // Already handled above\n this.notifyListeners(event, message);\n });\n });\n\n return this.connectPromise;\n }\n\n /**\n * Disconnect from the realtime server\n */\n disconnect(): void {\n if (this.socket) {\n this.socket.disconnect();\n this.socket = null;\n }\n this.subscribedChannels.clear();\n }\n\n /**\n * Handle token changes (e.g., after auth refresh)\n * Updates socket auth so reconnects use the new token\n * If connected, triggers reconnect to apply new token immediately\n */\n private onTokenChange(): void {\n const session = this.tokenManager.getSession();\n const token = session?.accessToken ?? this.anonKey;\n\n // Always update auth so socket.io auto-reconnect uses new token\n if (this.socket) {\n this.socket.auth = token ? { token } : {};\n }\n\n // Trigger reconnect if currently connected\n if (this.socket?.connected) {\n this.socket.disconnect();\n this.socket.connect();\n // Note: on('connect') handler automatically re-subscribes to channels\n }\n }\n\n /**\n * Check if connected to the realtime server\n */\n get isConnected(): boolean {\n return this.socket?.connected ?? false;\n }\n\n /**\n * Get the current connection state\n */\n get connectionState(): ConnectionState {\n if (!this.socket) return 'disconnected';\n if (this.socket.connected) return 'connected';\n return 'connecting';\n }\n\n /**\n * Get the socket ID (if connected)\n */\n get socketId(): string | undefined {\n return this.socket?.id;\n }\n\n /**\n * Subscribe to a channel\n *\n * Automatically connects if not already connected.\n *\n * @param channel - Channel name (e.g., 'orders:123', 'broadcast')\n * @returns Promise with the subscription response\n */\n async subscribe(channel: string): Promise<SubscribeResponse> {\n // Already subscribed, return success\n if (this.subscribedChannels.has(channel)) {\n return { ok: true, channel };\n }\n\n // Auto-connect if not connected\n if (!this.socket?.connected) {\n try {\n await this.connect();\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Connection failed';\n return { ok: false, channel, error: { code: 'CONNECTION_FAILED', message } };\n }\n }\n\n return new Promise((resolve) => {\n this.socket!.emit('realtime:subscribe', { channel }, (response: SubscribeResponse) => {\n if (response.ok) {\n this.subscribedChannels.add(channel);\n }\n resolve(response);\n });\n });\n }\n\n /**\n * Unsubscribe from a channel (fire-and-forget)\n *\n * @param channel - Channel name to unsubscribe from\n */\n unsubscribe(channel: string): void {\n this.subscribedChannels.delete(channel);\n\n if (this.socket?.connected) {\n this.socket.emit('realtime:unsubscribe', { channel });\n }\n }\n\n /**\n * Publish a message to a channel\n *\n * @param channel - Channel name\n * @param event - Event name\n * @param payload - Message payload\n */\n async publish<T = unknown>(channel: string, event: string, payload: T): Promise<void> {\n if (!this.socket?.connected) {\n throw new Error('Not connected to realtime server. Call connect() first.');\n }\n\n this.socket!.emit('realtime:publish', { channel, event, payload });\n }\n\n /**\n * Listen for events\n *\n * Reserved event names:\n * - 'connect' - Fired when connected to the server\n * - 'connect_error' - Fired when connection fails (payload: Error)\n * - 'disconnect' - Fired when disconnected (payload: reason string)\n * - 'error' - Fired when a realtime error occurs (payload: RealtimeErrorPayload)\n *\n * All other events receive a `SocketMessage` payload with metadata.\n *\n * @param event - Event name to listen for\n * @param callback - Callback function when event is received\n */\n on<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n if (!this.eventListeners.has(event)) {\n this.eventListeners.set(event, new Set());\n }\n this.eventListeners.get(event)!.add(callback as EventCallback);\n }\n\n /**\n * Remove a listener for a specific event\n *\n * @param event - Event name\n * @param callback - The callback function to remove\n */\n off<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n const listeners = this.eventListeners.get(event);\n if (listeners) {\n listeners.delete(callback as EventCallback);\n if (listeners.size === 0) {\n this.eventListeners.delete(event);\n }\n }\n }\n\n /**\n * Listen for an event only once, then automatically remove the listener\n *\n * @param event - Event name to listen for\n * @param callback - Callback function when event is received\n */\n once<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n const wrapper: EventCallback<T> = (payload: T) => {\n this.off(event, wrapper);\n callback(payload);\n };\n this.on(event, wrapper);\n }\n\n /**\n * Get all currently subscribed channels\n *\n * @returns Array of channel names\n */\n getSubscribedChannels(): string[] {\n return Array.from(this.subscribedChannels);\n }\n}\n","import { HttpClient } from '../lib/http-client';\nimport type { SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';\n\nexport type { SendRawEmailRequest as SendEmailOptions, SendEmailResponse } from '@insforge/shared-schemas';\n\n/**\n * Emails client for sending custom emails\n *\n * @example\n * ```typescript\n * // Send a simple email\n * const { data, error } = await client.emails.send({\n * to: 'user@example.com',\n * subject: 'Welcome!',\n * html: '<h1>Welcome to our platform</h1>'\n * });\n *\n * if (error) {\n * console.error('Failed to send:', error.message);\n * return;\n * }\n * // Email sent successfully - data is {} (empty object)\n *\n * // Send to multiple recipients with CC\n * const { data, error } = await client.emails.send({\n * to: ['user1@example.com', 'user2@example.com'],\n * cc: 'manager@example.com',\n * subject: 'Team Update',\n * html: '<p>Here is the latest update...</p>',\n * replyTo: 'support@example.com'\n * });\n * ```\n */\nexport class Emails {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Send a custom HTML email\n * @param options Email options including recipients, subject, and HTML content\n */\n async send(\n options: SendRawEmailRequest\n ): Promise<{ data: SendEmailResponse | null; error: Error | null }> {\n try {\n const data = await this.http.post<SendEmailResponse>(\n '/api/email/send-raw',\n options\n );\n\n return { data, error: null };\n } catch (error: unknown) {\n const normalizedError = error instanceof Error ? error : new Error(String(error));\n return { data: null, error: normalizedError };\n }\n }\n}\n","import { InsForgeConfig } from './types';\nimport { HttpClient } from './lib/http-client';\nimport { TokenManager } from './lib/token-manager';\nimport { Auth } from './modules/auth';\nimport { Database } from './modules/database-postgrest';\nimport { Storage } from './modules/storage';\nimport { AI } from './modules/ai';\nimport { Functions } from './modules/functions';\nimport { Realtime } from './modules/realtime';\nimport { Emails } from './modules/email';\n\n/**\n * Main InsForge SDK Client\n * \n * @example\n * ```typescript\n * import { InsForgeClient } from '@insforge/sdk';\n * \n * const client = new InsForgeClient({\n * baseUrl: 'http://localhost:7130'\n * });\n * \n * // Authentication\n * const { data, error } = await client.auth.signUp({\n * email: 'user@example.com',\n * password: 'password123',\n * name: 'John Doe'\n * });\n * \n * // Database operations\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', session.user.id)\n * .order('created_at', { ascending: false })\n * .limit(10);\n * \n * // Insert data\n * const { data: newPost } = await client.database\n * .from('posts')\n * .insert({ title: 'Hello', content: 'World' })\n * .single();\n * \n * // Invoke edge functions\n * const { data, error } = await client.functions.invoke('my-function', {\n * body: { message: 'Hello from SDK' }\n * });\n * ```\n */\nexport class InsForgeClient {\n private http: HttpClient;\n private tokenManager: TokenManager;\n public readonly auth: Auth;\n public readonly database: Database;\n public readonly storage: Storage;\n public readonly ai: AI;\n public readonly functions: Functions;\n public readonly realtime: Realtime;\n public readonly emails: Emails;\n\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n\n // Check for edge function token\n if (config.edgeFunctionToken) {\n this.http.setAuthToken(config.edgeFunctionToken);\n // Save to token manager so getCurrentUser() works\n this.tokenManager.saveSession({\n accessToken: config.edgeFunctionToken,\n user: {} as any, // Will be populated by getCurrentUser()\n });\n }\n\n // Check for existing session\n // In secure mode: try to refresh to get access token\n // In local mode: check localStorage\n const existingSession = this.tokenManager.getSession();\n if (existingSession?.accessToken) {\n this.http.setAuthToken(existingSession.accessToken);\n }\n\n this.auth = new Auth(this.http, this.tokenManager);\n this.database = new Database(this.http, this.tokenManager);\n this.storage = new Storage(this.http);\n this.ai = new AI(this.http);\n this.functions = new Functions(this.http);\n this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);\n this.emails = new Emails(this.http);\n }\n\n /**\n * Get the underlying HTTP client for custom requests\n * \n * @example\n * ```typescript\n * const httpClient = client.getHttpClient();\n * const customData = await httpClient.get('/api/custom-endpoint');\n * ```\n */\n getHttpClient(): HttpClient {\n return this.http;\n }\n\n /**\n * Future modules will be added here:\n * - database: Database operations\n * - storage: File storage operations\n * - functions: Serverless functions\n * - tables: Table management\n * - metadata: Backend metadata\n */\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0EO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,OAAe,aAAsB;AACpF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,OAAO,aAAa,UAAmC;AACrD,WAAO,IAAI;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AACF;;;ACzFO,IAAM,aAAN,MAAiB;AAAA,EAOtB,YAAY,QAAwB;AAFpC,S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,MAAM,MAAM,OAAO,gBAAgB;AAAA,IAC9C;AAAA,EACF;AACF;;;ACVO,IAAM,iBAAN,MAAqB;AAAA,EAW1B,YAAY,SAAyB,CAAC,GAAG;AACvC,SAAK,OAAO,IAAI,WAAW,MAAM;AACjC,SAAK,eAAe,IAAI,aAAa,OAAO,OAAO;AAGnD,QAAI,OAAO,mBAAmB;AAC5B,WAAK,KAAK,aAAa,OAAO,iBAAiB;AAE/C,WAAK,aAAa,YAAY;AAAA,QAC5B,aAAa,OAAO;AAAA,QACpB,MAAM,CAAC;AAAA;AAAA,MACT,CAAC;AAAA,IACH;AAKA,UAAM,kBAAkB,KAAK,aAAa,WAAW;AACrD,QAAI,iBAAiB,aAAa;AAChC,WAAK,KAAK,aAAa,gBAAgB,WAAW;AAAA,IACpD;AAEA,SAAK,OAAO,IAAI,KAAK,KAAK,MAAM,KAAK,YAAY;AACjD,SAAK,WAAW,IAAI,SAAS,KAAK,MAAM,KAAK,YAAY;AACzD,SAAK,UAAU,IAAI,QAAQ,KAAK,IAAI;AACpC,SAAK,KAAK,IAAI,GAAG,KAAK,IAAI;AAC1B,SAAK,YAAY,IAAI,UAAU,KAAK,IAAI;AACxC,SAAK,WAAW,IAAI,SAAS,KAAK,KAAK,SAAS,KAAK,cAAc,OAAO,OAAO;AACjF,SAAK,SAAS,IAAI,OAAO,KAAK,IAAI;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,gBAA4B;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUF;;;AX5CO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":["session","response"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/auth.ts","../src/modules/database-postgrest.ts","../src/modules/storage.ts","../src/modules/ai.ts","../src/modules/functions.ts","../src/modules/realtime.ts","../src/modules/email.ts","../src/client.ts"],"sourcesContent":["/**\n * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service\n * \n * @packageDocumentation\n */\n\n// Main client\nexport { InsForgeClient } from './client';\n\n// Types\nexport type {\n InsForgeConfig,\n InsForgeConfig as ClientOptions, // Alias for compatibility\n TokenStorage,\n AuthSession,\n ApiError,\n} from './types';\n\nexport { InsForgeError } from './types';\n\n// Re-export shared schemas that SDK users will need\nexport type {\n UserSchema,\n CreateUserRequest,\n CreateSessionRequest,\n AuthErrorResponse,\n} from '@insforge/shared-schemas';\n\n// Re-export auth module for advanced usage\nexport { Auth } from './modules/auth';\n\n// Re-export database module (using postgrest-js)\nexport { Database } from './modules/database-postgrest';\n// Note: QueryBuilder is no longer exported as we use postgrest-js QueryBuilder internally\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\n\n// Re-export AI module\nexport { AI } from './modules/ai';\n\n// Re-export Functions module\nexport { Functions } from './modules/functions';\nexport type { FunctionInvokeOptions } from './modules/functions';\n\n// Re-export Emails module (Resend-compatible API)\nexport { Emails } from './modules/email';\nexport type { SendEmailOptions, SendEmailResponse } from './modules/email';\n\n// Re-export Realtime module and types\nexport { Realtime } from './modules/realtime';\nexport type {\n RealtimeErrorPayload,\n SubscribeResponse,\n SocketMessage,\n ConnectionState,\n EventCallback,\n} from './modules/realtime';\n\n// Re-export utilities for advanced usage\nexport { HttpClient } from './lib/http-client';\nexport { TokenManager } from './lib/token-manager';\n\n// Factory function for creating clients (Supabase-style)\nimport { InsForgeClient } from './client';\nimport { InsForgeConfig } from './types';\n\nexport function createClient(config: InsForgeConfig): InsForgeClient {\n return new InsForgeClient(config);\n}\n\n// Default export for convenience\nexport default InsForgeClient;\n","/**\n * InsForge SDK Types - only SDK-specific types here\n * Use @insforge/shared-schemas directly for API types\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\n\nexport interface InsForgeConfig {\n /**\n * The base URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n baseUrl?: string;\n\n /**\n * Anonymous API key (optional)\n * Used for public/unauthenticated requests when no user token is set\n */\n anonKey?: string;\n\n /**\n * Edge Function Token (optional)\n * Use this when running in edge functions/serverless with a user's JWT token\n * This token will be used for all authenticated requests\n */\n edgeFunctionToken?: string;\n\n /**\n * Custom fetch implementation (useful for Node.js environments)\n */\n fetch?: typeof fetch;\n\n /**\n * Storage adapter for persisting tokens\n */\n storage?: TokenStorage;\n\n /**\n * Whether to automatically refresh tokens before they expire\n * @default true\n */\n autoRefreshToken?: boolean;\n\n /**\n * Whether to persist session in storage\n * @default true\n */\n persistSession?: boolean;\n\n /**\n * Custom headers to include with every request\n */\n headers?: Record<string, string>;\n}\n\nexport interface TokenStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport interface AuthSession {\n user: UserSchema;\n accessToken: string;\n expiresAt?: Date;\n}\n\nexport interface ApiError {\n error: string;\n message: string;\n statusCode: number;\n nextActions?: string;\n}\n\nexport class InsForgeError extends Error {\n public statusCode: number;\n public error: string;\n public nextActions?: string;\n\n constructor(message: string, statusCode: number, error: string, nextActions?: string) {\n super(message);\n this.name = 'InsForgeError';\n this.statusCode = statusCode;\n this.error = error;\n this.nextActions = nextActions;\n }\n\n static fromApiError(apiError: ApiError): InsForgeError {\n return new InsForgeError(\n apiError.message,\n apiError.statusCode,\n apiError.error,\n apiError.nextActions\n );\n }\n}","import { InsForgeConfig, ApiError, InsForgeError } from '../types';\n\nexport interface RequestOptions extends RequestInit {\n params?: Record<string, string>;\n}\n\nexport class HttpClient {\n public readonly baseUrl: string;\n public readonly fetch: typeof fetch;\n private defaultHeaders: Record<string, string>;\n private anonKey: string | undefined;\n private userToken: string | null = null;\n\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.baseUrl || 'http://localhost:7130';\n // Properly bind fetch to maintain its context\n this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : undefined as any);\n this.anonKey = config.anonKey;\n this.defaultHeaders = {\n ...config.headers,\n };\n\n if (!this.fetch) {\n throw new Error(\n 'Fetch is not available. Please provide a fetch implementation in the config.'\n );\n }\n }\n\n private buildUrl(path: string, params?: Record<string, string>): string {\n const url = new URL(path, this.baseUrl);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n // For select parameter, preserve the exact formatting by normalizing whitespace\n // This ensures PostgREST relationship queries work correctly\n if (key === 'select') {\n // Normalize multiline select strings for PostgREST:\n // 1. Replace all whitespace (including newlines) with single space\n // 2. Remove spaces inside parentheses for proper PostgREST syntax\n // 3. Keep spaces after commas at the top level for readability\n let normalizedValue = value.replace(/\\s+/g, ' ').trim();\n\n // Fix spaces around parentheses and inside them\n normalizedValue = normalizedValue\n .replace(/\\s*\\(\\s*/g, '(') // Remove spaces around opening parens\n .replace(/\\s*\\)\\s*/g, ')') // Remove spaces around closing parens\n .replace(/\\(\\s+/g, '(') // Remove spaces after opening parens\n .replace(/\\s+\\)/g, ')') // Remove spaces before closing parens\n .replace(/,\\s+(?=[^()]*\\))/g, ','); // Remove spaces after commas inside parens\n \n url.searchParams.append(key, normalizedValue);\n } else {\n url.searchParams.append(key, value);\n }\n });\n }\n return url.toString();\n }\n\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { params, headers = {}, body, ...fetchOptions } = options;\n \n const url = this.buildUrl(path, params);\n \n const requestHeaders: Record<string, string> = {\n ...this.defaultHeaders,\n };\n \n // Set Authorization header: prefer user token, fallback to anon key\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n requestHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n \n // Handle body serialization\n let processedBody: any;\n if (body !== undefined) {\n // Check if body is FormData (for file uploads)\n if (typeof FormData !== 'undefined' && body instanceof FormData) {\n // Don't set Content-Type for FormData, let browser set it with boundary\n processedBody = body;\n } else {\n // JSON body\n if (method !== 'GET') {\n requestHeaders['Content-Type'] = 'application/json;charset=UTF-8';\n }\n processedBody = JSON.stringify(body);\n }\n }\n \n Object.assign(requestHeaders, headers);\n \n const response = await this.fetch(url, {\n method,\n headers: requestHeaders,\n body: processedBody,\n ...fetchOptions,\n });\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n // Try to parse JSON response\n let data: any;\n const contentType = response.headers.get('content-type');\n // Check for any JSON content type (including PostgREST's vnd.pgrst.object+json)\n if (contentType?.includes('json')) {\n data = await response.json();\n } else {\n // For non-JSON responses, return text\n data = await response.text();\n }\n\n // Handle errors\n if (!response.ok) {\n if (data && typeof data === 'object' && 'error' in data) {\n // Add the HTTP status code if not already in the data\n if (!data.statusCode && !data.status) {\n data.statusCode = response.status;\n }\n const error = InsForgeError.fromApiError(data as ApiError);\n // Preserve all additional fields from the error response\n Object.keys(data).forEach(key => {\n if (key !== 'error' && key !== 'message' && key !== 'statusCode') {\n (error as any)[key] = data[key];\n }\n });\n throw error;\n }\n throw new InsForgeError(\n `Request failed: ${response.statusText}`,\n response.status,\n 'REQUEST_FAILED'\n );\n }\n\n return data as T;\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n post<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n put<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n setAuthToken(token: string | null) {\n this.userToken = token;\n }\n\n getHeaders(): Record<string, string> {\n const headers = { ...this.defaultHeaders };\n \n // Include Authorization header if token is available (same logic as request method)\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n headers['Authorization'] = `Bearer ${authToken}`;\n }\n \n return headers;\n }\n}","/**\n * Token Manager for InsForge SDK\n * \n * Simple token storage that supports two modes:\n * - Memory mode (new backend): tokens stored in memory only, more secure\n * - Storage mode (legacy backend): tokens persisted in localStorage\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\nimport type { AuthSession, TokenStorage } from '../types';\n\n// localStorage keys\nexport const TOKEN_KEY = 'insforge-auth-token';\nexport const USER_KEY = 'insforge-auth-user';\n\n// CSRF token cookie name\nexport const CSRF_TOKEN_COOKIE = 'insforge_csrf_token';\n\n/**\n * Get CSRF token from cookie\n * Used to include in X-CSRF-Token header for refresh requests\n */\nexport function getCsrfToken(): string | null {\n if (typeof document === 'undefined') return null;\n const match = document.cookie\n .split(';')\n .find(c => c.trim().startsWith(`${CSRF_TOKEN_COOKIE}=`));\n if (!match) return null;\n return match.split('=')[1] || null;\n}\n\n/**\n * Set CSRF token cookie\n * Called after login/register/refresh to store the CSRF token\n */\nexport function setCsrfToken(token: string): void {\n if (typeof document === 'undefined') return;\n const maxAge = 7 * 24 * 60 * 60; // 7 days (same as refresh token)\n const secure = (typeof window !== 'undefined' && window.location.protocol === 'https:') ? '; Secure' : '';\n document.cookie = `${CSRF_TOKEN_COOKIE}=${encodeURIComponent(token)}; path=/; max-age=${maxAge}; SameSite=Lax${secure}`;\n}\n\n/**\n * Clear CSRF token cookie\n * Called on logout\n */\nexport function clearCsrfToken(): void {\n if (typeof document === 'undefined') return;\n const secure = (typeof window !== 'undefined' && window.location.protocol === 'https:') ? '; Secure' : '';\n document.cookie = `${CSRF_TOKEN_COOKIE}=; path=/; max-age=0; SameSite=Lax${secure}`;\n}\n\nexport class TokenManager {\n // In-memory storage\n private accessToken: string | null = null;\n private user: UserSchema | null = null;\n\n // Persistent storage (for legacy backend)\n private storage: TokenStorage;\n\n // Mode: 'memory' (new backend) or 'storage' (legacy backend, default)\n private _mode: 'memory' | 'storage' = 'storage';\n\n // Callback for token changes (used by realtime to reconnect with new token)\n onTokenChange: (() => void) | null = null;\n\n constructor(storage?: TokenStorage) {\n if (storage) {\n // Use provided storage\n this.storage = storage;\n } else if (typeof window !== 'undefined' && window.localStorage) {\n // Browser: use localStorage\n this.storage = window.localStorage;\n } else {\n // Node.js: use in-memory storage\n const store = new Map<string, string>();\n this.storage = {\n getItem: (key: string) => store.get(key) || null,\n setItem: (key: string, value: string) => { store.set(key, value); },\n removeItem: (key: string) => { store.delete(key); }\n };\n }\n }\n\n /**\n * Get current mode\n */\n get mode(): 'memory' | 'storage' {\n return this._mode;\n }\n\n /**\n * Set mode to memory (new backend with cookies + memory)\n */\n setMemoryMode(): void {\n if (this._mode === 'storage') {\n // Clear localStorage when switching from storage to memory mode\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n }\n this._mode = 'memory';\n }\n\n /**\n * Set mode to storage (legacy backend with localStorage)\n * Also loads existing session from localStorage\n */\n setStorageMode(): void {\n this._mode = 'storage';\n this.loadFromStorage();\n }\n\n /**\n * Load session from localStorage\n */\n private loadFromStorage(): void {\n const token = this.storage.getItem(TOKEN_KEY) as string | null;\n const userStr = this.storage.getItem(USER_KEY) as string | null;\n\n if (token && userStr) {\n try {\n this.accessToken = token;\n this.user = JSON.parse(userStr);\n } catch {\n this.clearSession();\n }\n }\n }\n\n /**\n * Save session (memory always, localStorage only in storage mode)\n */\n saveSession(session: AuthSession): void {\n const tokenChanged = session.accessToken !== this.accessToken;\n this.accessToken = session.accessToken;\n this.user = session.user;\n\n // Persist to localStorage in storage mode\n if (this._mode === 'storage') {\n this.storage.setItem(TOKEN_KEY, session.accessToken);\n this.storage.setItem(USER_KEY, JSON.stringify(session.user));\n }\n\n if (tokenChanged && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Get current session\n */\n getSession(): AuthSession | null {\n this.loadFromStorage();\n if (!this.accessToken || !this.user) return null;\n return {\n accessToken: this.accessToken,\n user: this.user,\n };\n }\n\n /**\n * Get access token\n */\n getAccessToken(): string | null {\n this.loadFromStorage();\n return this.accessToken;\n }\n\n /**\n * Set access token\n */\n setAccessToken(token: string): void {\n const tokenChanged = token !== this.accessToken;\n this.accessToken = token;\n if (this._mode === 'storage') {\n this.storage.setItem(TOKEN_KEY, token);\n }\n if (tokenChanged && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Get user\n */\n getUser(): UserSchema | null {\n return this.user;\n }\n\n /**\n * Set user\n */\n setUser(user: UserSchema): void {\n this.user = user;\n if (this._mode === 'storage') {\n this.storage.setItem(USER_KEY, JSON.stringify(user));\n }\n }\n\n /**\n * Clear session (both memory and localStorage)\n */\n clearSession(): void {\n const hadToken = this.accessToken !== null;\n this.accessToken = null;\n this.user = null;\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n\n if (hadToken && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Check if there's a session in localStorage (for legacy detection)\n */\n hasStoredSession(): boolean {\n const token = this.storage.getItem(TOKEN_KEY);\n return !!token;\n }\n}","/**\n * Auth module for InsForge SDK\n * Uses shared schemas for type safety\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager, getCsrfToken, setCsrfToken, clearCsrfToken } from '../lib/token-manager';\nimport { AuthSession, InsForgeError } from '../types';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\n GetPublicAuthConfigResponse,\n OAuthProvidersSchema,\n SendVerificationEmailRequest,\n SendResetPasswordEmailRequest,\n ExchangeResetPasswordTokenRequest,\n VerifyEmailRequest,\n VerifyEmailResponse,\n UserSchema,\n GetProfileResponse,\n} from '@insforge/shared-schemas';\n\n/**\n * Check if current environment is a hosted auth environment\n * Returns true for:\n * - localhost with port 7130 (hosted auth app dev)\n * - https://*.insforge.app (hosted auth app production)\n */\nfunction isHostedAuthEnvironment(): boolean {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const { hostname, port, protocol } = window.location;\n\n // Check for localhost:7130\n if (hostname === 'localhost' && port === '7130') {\n return true;\n }\n\n // Check for https://*.insforge.app\n if (protocol === 'https:' && hostname.endsWith('.insforge.app')) {\n return true;\n }\n\n return false;\n}\n\nexport class Auth {\n constructor(\n private http: HttpClient,\n private tokenManager: TokenManager\n ) {\n // Auto-detect OAuth callback parameters in the URL\n this.detectAuthCallback();\n }\n\n /**\n * Automatically detect and handle OAuth callback parameters in the URL\n * This runs after initialization to seamlessly complete the OAuth flow\n * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)\n */\n private detectAuthCallback(): void {\n // Only run in browser environment\n if (typeof window === 'undefined') return;\n\n try {\n const params = new URLSearchParams(window.location.search);\n // Backend returns: access_token, user_id, email, name (optional), csrf_token\n const accessToken = params.get('access_token');\n const userId = params.get('user_id');\n const email = params.get('email');\n const name = params.get('name');\n const csrfToken = params.get('csrf_token');\n\n // Check if we have OAuth callback parameters\n if (accessToken && userId && email) {\n if (csrfToken) {\n this.tokenManager.setMemoryMode();\n setCsrfToken(csrfToken);\n }\n // TODO: Use PKCE in future\n // Create session with the data from backend\n const session: AuthSession = {\n accessToken,\n user: {\n id: userId,\n email: email,\n profile: { name: name || '' },\n metadata: null,\n // These fields are not provided by backend OAuth callback\n // They'll be populated when calling getCurrentUser()\n emailVerified: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n },\n };\n\n // Save session and set auth token\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(accessToken);\n\n // Clean up the URL to remove sensitive parameters\n const url = new URL(window.location.href);\n url.searchParams.delete('access_token');\n url.searchParams.delete('user_id');\n url.searchParams.delete('email');\n url.searchParams.delete('name');\n url.searchParams.delete('csrf_token');\n\n // Also handle error case from backend (line 581)\n if (params.has('error')) {\n url.searchParams.delete('error');\n }\n\n // Replace URL without adding to browser history\n window.history.replaceState({}, document.title, url.toString());\n }\n } catch (error) {\n // Silently continue - don't break initialization\n console.debug('OAuth callback detection skipped:', error);\n }\n }\n\n /**\n * Sign up a new user\n */\n async signUp(request: CreateUserRequest): Promise<{\n data: CreateUserResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateUserResponse>('/api/auth/users', request);\n\n // Save session internally only if both accessToken and user exist\n if (response.accessToken && response.user && !isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n error instanceof Error ? error.message : 'An unexpected error occurred during sign up',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with email and password\n */\n async signInWithPassword(request: CreateSessionRequest): Promise<{\n data: CreateSessionResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateSessionResponse>('/api/auth/sessions', request);\n\n if (!isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred during sign in',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with OAuth provider\n */\n async signInWithOAuth(options: {\n provider: OAuthProvidersSchema;\n redirectTo?: string;\n skipBrowserRedirect?: boolean;\n }): Promise<{\n data: { url?: string; provider?: string };\n error: InsForgeError | null;\n }> {\n try {\n const { provider, redirectTo, skipBrowserRedirect } = options;\n\n const params = redirectTo\n ? { redirect_uri: redirectTo }\n : undefined;\n\n const endpoint = `/api/auth/oauth/${provider}`;\n const response = await this.http.get<GetOauthUrlResponse>(endpoint, { params });\n\n // Automatically redirect in browser unless told not to\n if (typeof window !== 'undefined' && !skipBrowserRedirect) {\n window.location.href = response.authUrl;\n return { data: {}, error: null };\n }\n\n return {\n data: {\n url: response.authUrl,\n provider\n },\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: {}, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: {},\n error: new InsForgeError(\n 'An unexpected error occurred during OAuth initialization',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign out the current user\n */\n async signOut(): Promise<{ error: InsForgeError | null }> {\n try {\n // Try to call backend logout to clear httpOnly refresh cookie\n // This may fail for legacy backends, but that's ok\n try {\n await this.http.post('/api/auth/logout', undefined, { credentials: 'include' });\n } catch {\n // Ignore errors - legacy backend may not have this endpoint\n }\n\n // Clear local session and cookies\n this.tokenManager.clearSession();\n this.http.setAuthToken(null);\n clearCsrfToken();\n\n return { error: null };\n } catch (error) {\n return {\n error: new InsForgeError(\n 'Failed to sign out',\n 500,\n 'SIGNOUT_ERROR'\n )\n };\n }\n }\n\n\n /**\n * Get all public authentication configuration (OAuth + Email)\n * Returns both OAuth providers and email authentication settings in one request\n * This is a public endpoint that doesn't require authentication\n * \n * @returns Complete public authentication configuration including OAuth providers and email auth settings\n * \n * @example\n * ```ts\n * const { data, error } = await insforge.auth.getPublicAuthConfig();\n * if (data) {\n * console.log(`OAuth providers: ${data.oauth.data.length}`);\n * console.log(`Password min length: ${data.email.passwordMinLength}`);\n * }\n * ```\n */\n async getPublicAuthConfig(): Promise<{\n data: GetPublicAuthConfigResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.get<GetPublicAuthConfigResponse>('/api/auth/public-config');\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching public authentication configuration',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n\n /**\n * Get the current user with full profile information\n * Returns both auth info (id, email, role) and profile data (dynamic fields from users table)\n */\n async getCurrentUser(): Promise<{\n data: {\n user: UserSchema;\n } | null;\n error: any | null;\n }> {\n try {\n // Check if we have a stored user\n const user = this.tokenManager.getUser();\n\n if (user) {\n return { data: { user }, error: null };\n }\n const accessToken = this.tokenManager.getAccessToken();\n if (!accessToken) {\n return { data: null, error: null };\n }\n\n // Call the API for auth info\n this.http.setAuthToken(accessToken);\n const authResponse = await this.http.get<GetCurrentSessionResponse>('/api/auth/sessions/current');\n\n return {\n data: {\n user: authResponse.user,\n },\n error: null\n };\n } catch (error) {\n // If unauthorized, clear session\n if (error instanceof InsForgeError && error.statusCode === 401) {\n await this.signOut();\n return { data: null, error: null };\n }\n\n // Pass through all other errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching user',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get any user's profile by ID\n * Returns profile information from the users table\n */\n async getProfile(userId: string): Promise<{\n data: GetProfileResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.get<GetProfileResponse>(`/api/auth/profiles/${userId}`);\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged (includes 404 NOT_FOUND, 400 INVALID_INPUT)\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching user profile',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get the current session (only session data, no API call)\n * Returns the stored JWT token and basic user info from local storage\n */\n async getCurrentSession(): Promise<{\n data: { session: AuthSession | null };\n error: InsForgeError | null;\n }> {\n try {\n // Step 1: Check if we already have session in memory\n const session = this.tokenManager.getSession();\n if (session) {\n this.http.setAuthToken(session.accessToken);\n return { data: { session }, error: null };\n }\n\n // Step 2: In browser, try to refresh using httpOnly cookie\n if (typeof window !== 'undefined') {\n try {\n const csrfToken = getCsrfToken();\n const response = await this.http.post<{\n accessToken: string;\n user?: UserSchema;\n csrfToken?: string\n }>(\n '/api/auth/refresh',\n undefined,\n {\n headers: csrfToken ? { 'X-CSRF-Token': csrfToken } : {},\n credentials: 'include',\n }\n );\n\n if (response.accessToken) {\n this.tokenManager.setMemoryMode();\n this.tokenManager.setAccessToken(response.accessToken);\n this.http.setAuthToken(response.accessToken);\n\n if (response.user) {\n this.tokenManager.setUser(response.user);\n }\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n\n return {\n data: { session: this.tokenManager.getSession() },\n error: null\n };\n }\n } catch (error) {\n if (error instanceof InsForgeError) {\n if (error.statusCode === 404) {\n // Legacy backend - try localStorage\n this.tokenManager.setStorageMode();\n const session = this.tokenManager.getSession();\n if (session) {\n return { data: { session }, error: null };\n }\n return { data: { session: null }, error: null };\n }\n // 401/403 or other errors - not logged in\n return { data: { session: null }, error: error };\n }\n }\n }\n\n // Not logged in\n return { data: { session: null }, error: null };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: { session: null }, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: { session: null },\n error: new InsForgeError(\n 'An unexpected error occurred while getting session',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Set/Update the current user's profile\n * Updates profile information in the users table (supports any dynamic fields)\n * Requires authentication\n */\n async setProfile(profile: Record<string, unknown>): Promise<{\n data: GetProfileResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.patch<GetProfileResponse>(\n '/api/auth/profiles/current',\n { profile }\n );\n\n // Update the local session/user with the new profile data\n const currentUser = this.tokenManager.getUser();\n if (currentUser && response.profile !== undefined) {\n this.tokenManager.setUser({\n ...currentUser,\n profile: response.profile,\n });\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged (includes 401 AUTH_INVALID_CREDENTIALS, 400 INVALID_INPUT)\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while updating user profile',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Send email verification (code or link based on config)\n *\n * Send email verification using the method configured in auth settings (verifyEmailMethod).\n * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.\n * Prevents user enumeration by returning success even if email doesn't exist.\n */\n async sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{\n data: { success: boolean; message: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ success: boolean; message: string }>(\n '/api/auth/email/send-verification',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while sending verification code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Send password reset (code or link based on config)\n *\n * Send password reset email using the method configured in auth settings (resetPasswordMethod).\n * When method is 'code', sends a 6-digit numeric code for two-step flow.\n * When method is 'link', sends a magic link.\n * Prevents user enumeration by returning success even if email doesn't exist.\n */\n async sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{\n data: { success: boolean; message: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ success: boolean; message: string }>(\n '/api/auth/email/send-reset-password',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while sending password reset code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Exchange reset password code for reset token\n *\n * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):\n * 1. Verify the 6-digit code sent to user's email\n * 2. Return a reset token that can be used to actually reset the password\n *\n * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).\n */\n async exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{\n data: { token: string; expiresAt: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ token: string; expiresAt: string }>(\n '/api/auth/email/exchange-reset-password-token',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while verifying reset code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Reset password with token\n *\n * Reset user password with a token. The token can be:\n * - Magic link token (64-character hex token from send-reset-password when method is 'link')\n * - Reset token (from exchange-reset-password-token after code verification when method is 'code')\n *\n * Both token types use RESET_PASSWORD purpose and are verified the same way.\n *\n * Flow summary:\n * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)\n * - Link method: send-reset-password → reset-password (with link token directly)\n */\n async resetPassword(request: { newPassword: string; otp: string }): Promise<{\n data: { message: string; redirectTo?: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ message: string; redirectTo?: string }>(\n '/api/auth/email/reset-password',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while resetting password',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Verify email with code or link\n *\n * Verify email address using the method configured in auth settings (verifyEmailMethod):\n * - Code verification: Provide both `email` and `otp` (6-digit numeric code)\n * - Link verification: Provide only `otp` (64-character hex token from magic link)\n *\n * Successfully verified users will receive a session token.\n *\n * The email verification link sent to users always points to the backend API endpoint.\n * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.\n * Otherwise, a default success page is displayed.\n */\n async verifyEmail(request: VerifyEmailRequest): Promise<{\n data: VerifyEmailResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<VerifyEmailResponse>(\n '/api/auth/email/verify',\n request\n );\n\n // Save session if we got a token\n if (!isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while verifying email',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n}","/**\n * Database module using @supabase/postgrest-js\n * Complete replacement for custom QueryBuilder with full PostgREST features\n */\n\nimport { PostgrestClient } from '@supabase/postgrest-js';\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\n\n\n/**\n * Custom fetch that transforms URLs and adds auth\n */\nfunction createInsForgePostgrestFetch(\n httpClient: HttpClient,\n tokenManager: TokenManager\n): typeof fetch {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const url = typeof input === 'string' ? input : input.toString();\n const urlObj = new URL(url);\n \n // Extract table name from pathname\n // postgrest-js sends: http://dummy/tablename?params\n // We need: http://localhost:7130/api/database/records/tablename?params\n const tableName = urlObj.pathname.slice(1); // Remove leading /\n \n // Build InsForge URL\n const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;\n \n // Get auth token from TokenManager or HttpClient\n const token = tokenManager.getAccessToken();\n const httpHeaders = httpClient.getHeaders();\n const authToken = token || httpHeaders['Authorization']?.replace('Bearer ', '');\n \n // Prepare headers\n const headers = new Headers(init?.headers);\n if (authToken && !headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${authToken}`);\n }\n \n // Make the actual request using native fetch\n const response = await fetch(insforgeUrl, {\n ...init,\n headers\n });\n \n return response;\n };\n}\n\n/**\n * Database client using postgrest-js\n * Drop-in replacement with FULL PostgREST capabilities\n */\nexport class Database {\n private postgrest: PostgrestClient<any, any, any>;\n \n constructor(httpClient: HttpClient, tokenManager: TokenManager) {\n // Create postgrest client with custom fetch\n this.postgrest = new PostgrestClient<any, any, any>('http://dummy', {\n fetch: createInsForgePostgrestFetch(httpClient, tokenManager),\n headers: {}\n });\n }\n \n /**\n * Create a query builder for a table\n * \n * @example\n * // Basic query\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId);\n * \n * // With count (Supabase style!)\n * const { data, error, count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact' })\n * .range(0, 9);\n * \n * // Just get count, no data\n * const { count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact', head: true });\n * \n * // Complex queries with OR\n * const { data } = await client.database\n * .from('posts')\n * .select('*, users!inner(*)')\n * .or('status.eq.active,status.eq.pending');\n * \n * // All features work:\n * - Nested selects\n * - Foreign key expansion \n * - OR/AND/NOT conditions\n * - Count with head\n * - Range pagination\n * - Upserts\n */\n from(table: string) {\n // Return postgrest query builder with all features\n return this.postgrest.from(table);\n }\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n}\n\ninterface UploadStrategy {\n method: 'direct' | 'presigned';\n uploadUrl: string;\n fields?: Record<string, string>;\n key: string;\n confirmRequired: boolean;\n confirmUrl?: string;\n expiresAt?: Date;\n}\n\ninterface DownloadStrategy {\n method: 'direct' | 'presigned';\n url: string;\n expiresAt?: Date;\n}\n\n/**\n * Storage bucket operations\n */\nexport class StorageBucket {\n constructor(\n private bucketName: string,\n private http: HttpClient\n ) {}\n\n /**\n * Upload a file with a specific key\n * Uses the upload strategy from backend (direct or presigned)\n * @param path - The object key/path\n * @param file - File or Blob to upload\n */\n async upload(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'PUT',\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * Uses the upload strategy from backend (direct or presigned)\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const filename = file instanceof File ? file.name : 'file';\n \n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'POST',\n `/api/storage/buckets/${this.bucketName}/objects`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Internal method to handle presigned URL uploads\n */\n private async uploadWithPresignedUrl(\n strategy: UploadStrategy,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Upload to presigned URL (e.g., S3)\n const formData = new FormData();\n \n // Add all fields from the presigned URL\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be the last field for S3\n formData.append('file', file);\n\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n throw new InsForgeError(\n `Upload to storage failed: ${uploadResponse.statusText}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Confirm upload with backend if required\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n }\n );\n\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, return basic file info\n return {\n data: {\n key: strategy.key,\n bucket: this.bucketName,\n size: file.size,\n mimeType: file.type || 'application/octet-stream',\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n } as StorageFileSchema,\n error: null\n };\n } catch (error) {\n throw error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n );\n }\n }\n\n /**\n * Download a file\n * Uses the download strategy from backend (direct or presigned)\n * @param path - The object key/path\n * Returns the file as a Blob\n */\n async download(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n // Get download strategy from backend - this is required\n const strategyResponse = await this.http.post<DownloadStrategy>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n { expiresIn: 3600 }\n );\n\n // Use URL from strategy\n const downloadUrl = strategyResponse.url;\n \n // Download from the URL\n const headers: HeadersInit = {};\n \n // Only add auth header for direct downloads (not presigned URLs)\n if (strategyResponse.method === 'direct') {\n Object.assign(headers, this.http.getHeaders());\n }\n \n const response = await fetch(downloadUrl, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n try {\n const error = await response.json();\n throw InsForgeError.fromApiError(error);\n } catch {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\n );\n }\n }\n\n const blob = await response.blob();\n return { data: blob, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Get public URL for a file\n * @param path - The object key/path\n */\n getPublicUrl(path: string): string {\n return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n }\n\n /**\n * List objects in the bucket\n * @param prefix - Filter by key prefix\n * @param search - Search in file names\n * @param limit - Maximum number of results (default: 100, max: 1000)\n * @param offset - Number of results to skip\n */\n async list(options?: {\n prefix?: string;\n search?: string;\n limit?: number;\n offset?: number;\n }): Promise<StorageResponse<ListObjectsResponseSchema>> {\n try {\n const params: Record<string, string> = {};\n \n if (options?.prefix) params.prefix = options.prefix;\n if (options?.search) params.search = options.search;\n if (options?.limit) params.limit = options.limit.toString();\n if (options?.offset) params.offset = options.offset.toString();\n\n const response = await this.http.get<ListObjectsResponseSchema>(\n `/api/storage/buckets/${this.bucketName}/objects`,\n { params }\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'List failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Delete a file\n * @param path - The object key/path\n */\n async remove(path: string): Promise<StorageResponse<{ message: string }>> {\n try {\n const response = await this.http.delete<{ message: string }>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Delete failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n}\n\n/**\n * Storage module for file operations\n */\nexport class Storage {\n constructor(private http: HttpClient) {}\n\n /**\n * Get a bucket instance for operations\n * @param bucketName - Name of the bucket\n */\n from(bucketName: string): StorageBucket {\n return new StorageBucket(bucketName, this.http);\n }\n}","/**\n * AI Module for Insforge SDK\n * Response format roughly matches OpenAI SDK for compatibility\n *\n * The backend handles all the complexity of different AI providers\n * and returns a unified format. This SDK transforms responses to match OpenAI-like format.\n */\n\nimport { HttpClient } from \"../lib/http-client\";\nimport {\n ChatCompletionRequest,\n ChatCompletionResponse,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@insforge/shared-schemas\";\n\nexport class AI {\n public readonly chat: Chat;\n public readonly images: Images;\n\n constructor(private http: HttpClient) {\n this.chat = new Chat(http);\n this.images = new Images(http);\n }\n}\n\nclass Chat {\n public readonly completions: ChatCompletions;\n\n constructor(http: HttpClient) {\n this.completions = new ChatCompletions(http);\n }\n}\n\nclass ChatCompletions {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a chat completion - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const completion = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Hello!' }]\n * });\n * console.log(completion.choices[0].message.content);\n *\n * // With images\n * const response = await client.ai.chat.completions.create({\n * model: 'gpt-4-vision',\n * messages: [{\n * role: 'user',\n * content: 'What is in this image?',\n * images: [{ url: 'https://example.com/image.jpg' }]\n * }]\n * });\n *\n * // Streaming - returns async iterable\n * const stream = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * stream: true\n * });\n *\n * for await (const chunk of stream) {\n * if (chunk.choices[0]?.delta?.content) {\n * process.stdout.write(chunk.choices[0].delta.content);\n * }\n * }\n * ```\n */\n async create(params: ChatCompletionRequest): Promise<any> {\n // Backend already expects camelCase, no transformation needed\n const backendParams = {\n model: params.model,\n messages: params.messages,\n temperature: params.temperature,\n maxTokens: params.maxTokens,\n topP: params.topP,\n stream: params.stream,\n };\n\n // For streaming, return an async iterable that yields OpenAI-like chunks\n if (params.stream) {\n const headers = this.http.getHeaders();\n headers[\"Content-Type\"] = \"application/json\";\n\n const response = await this.http.fetch(\n `${this.http.baseUrl}/api/ai/chat/completion`,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(backendParams),\n }\n );\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(error.error || \"Stream request failed\");\n }\n\n // Return async iterable that parses SSE and transforms to OpenAI-like format\n return this.parseSSEStream(response, params.model);\n }\n\n // Non-streaming: transform response to OpenAI-like format\n const response: ChatCompletionResponse = await this.http.post(\n \"/api/ai/chat/completion\",\n backendParams\n );\n\n // Transform to OpenAI-like format\n const content = response.text || \"\";\n\n return {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: response.metadata?.model,\n choices: [\n {\n index: 0,\n message: {\n role: \"assistant\",\n content,\n },\n finish_reason: \"stop\",\n },\n ],\n usage: response.metadata?.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n },\n };\n }\n\n /**\n * Parse SSE stream into async iterable of OpenAI-like chunks\n */\n private async *parseSSEStream(\n response: Response,\n model: string\n ): AsyncIterableIterator<any> {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() || \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const dataStr = line.slice(6).trim();\n if (dataStr) {\n try {\n const data = JSON.parse(dataStr);\n\n // Transform to OpenAI-like streaming format\n if (data.chunk || data.content) {\n yield {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [\n {\n index: 0,\n delta: {\n content: data.chunk || data.content,\n },\n finish_reason: data.done ? \"stop\" : null,\n },\n ],\n };\n }\n\n // If we received the done signal, we can stop\n if (data.done) {\n reader.releaseLock();\n return;\n }\n } catch (e) {\n // Skip invalid JSON\n console.warn(\"Failed to parse SSE data:\", dataStr);\n }\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nclass Images {\n constructor(private http: HttpClient) {}\n\n /**\n * Generate images - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Text-to-image\n * const response = await client.ai.images.generate({\n * model: 'dall-e-3',\n * prompt: 'A sunset over mountains',\n * });\n * console.log(response.images[0].url);\n *\n * // Image-to-image (with input images)\n * const response = await client.ai.images.generate({\n * model: 'stable-diffusion-xl',\n * prompt: 'Transform this into a watercolor painting',\n * images: [\n * { url: 'https://example.com/input.jpg' },\n * // or base64-encoded Data URI:\n * { url: 'data:image/jpeg;base64,/9j/4AAQ...' }\n * ]\n * });\n * ```\n */\n async generate(params: ImageGenerationRequest): Promise<any> {\n const response: ImageGenerationResponse = await this.http.post(\n \"/api/ai/image/generation\",\n params\n );\n \n // Build data array based on response content\n let data: Array<{ b64_json?: string; content?: string }> = [];\n \n if (response.images && response.images.length > 0) {\n // Has images - extract base64 and include text\n data = response.images.map(img => ({\n b64_json: img.imageUrl.replace(/^data:image\\/\\w+;base64,/, ''),\n content: response.text\n }));\n } else if (response.text) {\n // Text-only response\n data = [{ content: response.text }];\n }\n \n // Return OpenAI-compatible format\n return {\n created: Math.floor(Date.now() / 1000),\n data,\n ...(response.metadata?.usage && {\n usage: {\n total_tokens: response.metadata.usage.totalTokens || 0,\n input_tokens: response.metadata.usage.promptTokens || 0,\n output_tokens: response.metadata.usage.completionTokens || 0,\n }\n })\n };\n }\n}\n","import { HttpClient } from '../lib/http-client';\n\nexport interface FunctionInvokeOptions {\n /**\n * The body of the request\n */\n body?: any;\n \n /**\n * Custom headers to send with the request\n */\n headers?: Record<string, string>;\n \n /**\n * HTTP method (default: POST)\n */\n method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n}\n\n/**\n * Edge Functions client for invoking serverless functions\n * \n * @example\n * ```typescript\n * // Invoke a function with JSON body\n * const { data, error } = await client.functions.invoke('hello-world', {\n * body: { name: 'World' }\n * });\n * \n * // GET request\n * const { data, error } = await client.functions.invoke('get-data', {\n * method: 'GET'\n * });\n * ```\n */\nexport class Functions {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Invokes an Edge Function\n * @param slug The function slug to invoke\n * @param options Request options\n */\n async invoke<T = any>(\n slug: string,\n options: FunctionInvokeOptions = {}\n ): Promise<{ data: T | null; error: Error | null }> {\n try {\n const { method = 'POST', body, headers = {} } = options;\n \n // Simple path: /functions/{slug}\n const path = `/functions/${slug}`;\n \n // Use the HTTP client's request method\n const data = await this.http.request<T>(\n method,\n path,\n { body, headers }\n );\n \n return { data, error: null };\n } catch (error: any) {\n // The HTTP client throws InsForgeError with all properties from the response\n // including error, message, details, statusCode, etc.\n // We need to preserve all of that information\n return { \n data: null, \n error: error // Pass through the full error object with all properties\n };\n }\n }\n}","import { io, Socket } from 'socket.io-client';\nimport type { SubscribeResponse, RealtimeErrorPayload, SocketMessage } from '@insforge/shared-schemas';\nimport { TokenManager } from '../lib/token-manager';\n\nexport type { SubscribeResponse, RealtimeErrorPayload, SocketMessage };\n\nexport type ConnectionState = 'disconnected' | 'connecting' | 'connected';\n\nexport type EventCallback<T = unknown> = (payload: T) => void;\n\nconst CONNECT_TIMEOUT = 10000;\n\n/**\n * Realtime module for subscribing to channels and handling real-time events\n *\n * @example\n * ```typescript\n * const { realtime } = client;\n *\n * // Connect to the realtime server\n * await realtime.connect();\n *\n * // Subscribe to a channel\n * const response = await realtime.subscribe('orders:123');\n * if (!response.ok) {\n * console.error('Failed to subscribe:', response.error);\n * }\n *\n * // Listen for specific events\n * realtime.on('order_updated', (payload) => {\n * console.log('Order updated:', payload);\n * });\n *\n * // Listen for connection events\n * realtime.on('connect', () => console.log('Connected!'));\n * realtime.on('connect_error', (err) => console.error('Connection failed:', err));\n * realtime.on('disconnect', (reason) => console.log('Disconnected:', reason));\n * realtime.on('error', (error) => console.error('Realtime error:', error));\n *\n * // Publish a message to a channel\n * await realtime.publish('orders:123', 'status_changed', { status: 'shipped' });\n *\n * // Unsubscribe and disconnect when done\n * realtime.unsubscribe('orders:123');\n * realtime.disconnect();\n * ```\n */\nexport class Realtime {\n private baseUrl: string;\n private tokenManager: TokenManager;\n private socket: Socket | null = null;\n private connectPromise: Promise<void> | null = null;\n private subscribedChannels: Set<string> = new Set();\n private eventListeners: Map<string, Set<EventCallback>> = new Map();\n private anonKey?: string;\n\n constructor(baseUrl: string, tokenManager: TokenManager, anonKey?: string) {\n this.baseUrl = baseUrl;\n this.tokenManager = tokenManager;\n this.anonKey = anonKey;\n\n // Handle token changes (e.g., after refresh)\n this.tokenManager.onTokenChange = () => this.onTokenChange();\n }\n\n private notifyListeners(event: string, payload?: unknown): void {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n for (const cb of listeners) {\n try {\n cb(payload);\n } catch (err) {\n console.error(`Error in ${event} callback:`, err);\n }\n }\n }\n\n /**\n * Connect to the realtime server\n * @returns Promise that resolves when connected\n */\n connect(): Promise<void> {\n // Already connected\n if (this.socket?.connected) {\n return Promise.resolve();\n }\n\n // Connection already in progress, return existing promise\n if (this.connectPromise) {\n return this.connectPromise;\n }\n\n this.connectPromise = new Promise((resolve, reject) => {\n const session = this.tokenManager.getSession();\n const token = session?.accessToken ?? this.anonKey;\n \n\n this.socket = io(this.baseUrl, {\n transports: ['websocket'],\n auth: token ? { token } : undefined,\n });\n\n let initialConnection = true;\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n const cleanup = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n timeoutId = setTimeout(() => {\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n this.socket?.disconnect();\n this.socket = null;\n reject(new Error(`Connection timeout after ${CONNECT_TIMEOUT}ms`));\n }\n }, CONNECT_TIMEOUT);\n\n this.socket.on('connect', () => {\n cleanup();\n // Re-subscribe to channels on every connect (initial + reconnects)\n for (const channel of this.subscribedChannels) {\n this.socket!.emit('realtime:subscribe', { channel });\n }\n this.notifyListeners('connect');\n\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n resolve();\n }\n });\n\n this.socket.on('connect_error', (error: Error) => {\n cleanup();\n this.notifyListeners('connect_error', error);\n\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n reject(error);\n }\n });\n\n this.socket.on('disconnect', (reason: string) => {\n this.notifyListeners('disconnect', reason);\n });\n\n this.socket.on('realtime:error', (error: RealtimeErrorPayload) => {\n this.notifyListeners('error', error);\n });\n\n // Route custom events to listeners (onAny doesn't catch socket reserved events)\n this.socket.onAny((event: string, message: SocketMessage) => {\n if (event === 'realtime:error') return; // Already handled above\n this.notifyListeners(event, message);\n });\n });\n\n return this.connectPromise;\n }\n\n /**\n * Disconnect from the realtime server\n */\n disconnect(): void {\n if (this.socket) {\n this.socket.disconnect();\n this.socket = null;\n }\n this.subscribedChannels.clear();\n }\n\n /**\n * Handle token changes (e.g., after auth refresh)\n * Updates socket auth so reconnects use the new token\n * If connected, triggers reconnect to apply new token immediately\n */\n private onTokenChange(): void {\n const token = this.tokenManager.getAccessToken() ?? this.anonKey;\n\n // Always update auth so socket.io auto-reconnect uses new token\n if (this.socket) {\n this.socket.auth = token ? { token } : {};\n }\n\n // Trigger reconnect if connected OR connecting (to avoid completing with stale token)\n if (this.socket && (this.socket.connected || this.connectPromise)) {\n this.socket.disconnect();\n this.socket.connect();\n // Note: on('connect') handler automatically re-subscribes to channels\n }\n }\n\n /**\n * Check if connected to the realtime server\n */\n get isConnected(): boolean {\n return this.socket?.connected ?? false;\n }\n\n /**\n * Get the current connection state\n */\n get connectionState(): ConnectionState {\n if (!this.socket) return 'disconnected';\n if (this.socket.connected) return 'connected';\n return 'connecting';\n }\n\n /**\n * Get the socket ID (if connected)\n */\n get socketId(): string | undefined {\n return this.socket?.id;\n }\n\n /**\n * Subscribe to a channel\n *\n * Automatically connects if not already connected.\n *\n * @param channel - Channel name (e.g., 'orders:123', 'broadcast')\n * @returns Promise with the subscription response\n */\n async subscribe(channel: string): Promise<SubscribeResponse> {\n // Already subscribed, return success\n if (this.subscribedChannels.has(channel)) {\n return { ok: true, channel };\n }\n\n // Auto-connect if not connected\n if (!this.socket?.connected) {\n try {\n await this.connect();\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Connection failed';\n return { ok: false, channel, error: { code: 'CONNECTION_FAILED', message } };\n }\n }\n\n return new Promise((resolve) => {\n this.socket!.emit('realtime:subscribe', { channel }, (response: SubscribeResponse) => {\n if (response.ok) {\n this.subscribedChannels.add(channel);\n }\n resolve(response);\n });\n });\n }\n\n /**\n * Unsubscribe from a channel (fire-and-forget)\n *\n * @param channel - Channel name to unsubscribe from\n */\n unsubscribe(channel: string): void {\n this.subscribedChannels.delete(channel);\n\n if (this.socket?.connected) {\n this.socket.emit('realtime:unsubscribe', { channel });\n }\n }\n\n /**\n * Publish a message to a channel\n *\n * @param channel - Channel name\n * @param event - Event name\n * @param payload - Message payload\n */\n async publish<T = unknown>(channel: string, event: string, payload: T): Promise<void> {\n if (!this.socket?.connected) {\n throw new Error('Not connected to realtime server. Call connect() first.');\n }\n\n this.socket!.emit('realtime:publish', { channel, event, payload });\n }\n\n /**\n * Listen for events\n *\n * Reserved event names:\n * - 'connect' - Fired when connected to the server\n * - 'connect_error' - Fired when connection fails (payload: Error)\n * - 'disconnect' - Fired when disconnected (payload: reason string)\n * - 'error' - Fired when a realtime error occurs (payload: RealtimeErrorPayload)\n *\n * All other events receive a `SocketMessage` payload with metadata.\n *\n * @param event - Event name to listen for\n * @param callback - Callback function when event is received\n */\n on<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n if (!this.eventListeners.has(event)) {\n this.eventListeners.set(event, new Set());\n }\n this.eventListeners.get(event)!.add(callback as EventCallback);\n }\n\n /**\n * Remove a listener for a specific event\n *\n * @param event - Event name\n * @param callback - The callback function to remove\n */\n off<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n const listeners = this.eventListeners.get(event);\n if (listeners) {\n listeners.delete(callback as EventCallback);\n if (listeners.size === 0) {\n this.eventListeners.delete(event);\n }\n }\n }\n\n /**\n * Listen for an event only once, then automatically remove the listener\n *\n * @param event - Event name to listen for\n * @param callback - Callback function when event is received\n */\n once<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n const wrapper: EventCallback<T> = (payload: T) => {\n this.off(event, wrapper);\n callback(payload);\n };\n this.on(event, wrapper);\n }\n\n /**\n * Get all currently subscribed channels\n *\n * @returns Array of channel names\n */\n getSubscribedChannels(): string[] {\n return Array.from(this.subscribedChannels);\n }\n}\n","import { HttpClient } from '../lib/http-client';\nimport type { SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';\n\nexport type { SendRawEmailRequest as SendEmailOptions, SendEmailResponse } from '@insforge/shared-schemas';\n\n/**\n * Emails client for sending custom emails\n *\n * @example\n * ```typescript\n * // Send a simple email\n * const { data, error } = await client.emails.send({\n * to: 'user@example.com',\n * subject: 'Welcome!',\n * html: '<h1>Welcome to our platform</h1>'\n * });\n *\n * if (error) {\n * console.error('Failed to send:', error.message);\n * return;\n * }\n * // Email sent successfully - data is {} (empty object)\n *\n * // Send to multiple recipients with CC\n * const { data, error } = await client.emails.send({\n * to: ['user1@example.com', 'user2@example.com'],\n * cc: 'manager@example.com',\n * subject: 'Team Update',\n * html: '<p>Here is the latest update...</p>',\n * replyTo: 'support@example.com'\n * });\n * ```\n */\nexport class Emails {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Send a custom HTML email\n * @param options Email options including recipients, subject, and HTML content\n */\n async send(\n options: SendRawEmailRequest\n ): Promise<{ data: SendEmailResponse | null; error: Error | null }> {\n try {\n const data = await this.http.post<SendEmailResponse>(\n '/api/email/send-raw',\n options\n );\n\n return { data, error: null };\n } catch (error: unknown) {\n const normalizedError = error instanceof Error ? error : new Error(String(error));\n return { data: null, error: normalizedError };\n }\n }\n}\n","import { InsForgeConfig } from './types';\nimport { HttpClient } from './lib/http-client';\nimport { TokenManager } from './lib/token-manager';\nimport { Auth } from './modules/auth';\nimport { Database } from './modules/database-postgrest';\nimport { Storage } from './modules/storage';\nimport { AI } from './modules/ai';\nimport { Functions } from './modules/functions';\nimport { Realtime } from './modules/realtime';\nimport { Emails } from './modules/email';\n\n/**\n * Main InsForge SDK Client\n * \n * @example\n * ```typescript\n * import { InsForgeClient } from '@insforge/sdk';\n * \n * const client = new InsForgeClient({\n * baseUrl: 'http://localhost:7130'\n * });\n * \n * // Authentication\n * const { data, error } = await client.auth.signUp({\n * email: 'user@example.com',\n * password: 'password123',\n * name: 'John Doe'\n * });\n * \n * // Database operations\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', session.user.id)\n * .order('created_at', { ascending: false })\n * .limit(10);\n * \n * // Insert data\n * const { data: newPost } = await client.database\n * .from('posts')\n * .insert({ title: 'Hello', content: 'World' })\n * .single();\n * \n * // Invoke edge functions\n * const { data, error } = await client.functions.invoke('my-function', {\n * body: { message: 'Hello from SDK' }\n * });\n * ```\n */\nexport class InsForgeClient {\n private http: HttpClient;\n private tokenManager: TokenManager;\n public readonly auth: Auth;\n public readonly database: Database;\n public readonly storage: Storage;\n public readonly ai: AI;\n public readonly functions: Functions;\n public readonly realtime: Realtime;\n public readonly emails: Emails;\n\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n\n // Check for edge function token\n if (config.edgeFunctionToken) {\n this.http.setAuthToken(config.edgeFunctionToken);\n // Save to token manager so getCurrentUser() works\n this.tokenManager.saveSession({\n accessToken: config.edgeFunctionToken,\n user: {} as any, // Will be populated by getCurrentUser()\n });\n }\n\n // Check for existing session\n // In secure mode: try to refresh to get access token\n // In local mode: check localStorage\n const existingSession = this.tokenManager.getSession();\n if (existingSession?.accessToken) {\n this.http.setAuthToken(existingSession.accessToken);\n }\n\n this.auth = new Auth(this.http, this.tokenManager);\n this.database = new Database(this.http, this.tokenManager);\n this.storage = new Storage(this.http);\n this.ai = new AI(this.http);\n this.functions = new Functions(this.http);\n this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);\n this.emails = new Emails(this.http);\n }\n\n /**\n * Get the underlying HTTP client for custom requests\n * \n * @example\n * ```typescript\n * const httpClient = client.getHttpClient();\n * const customData = await httpClient.get('/api/custom-endpoint');\n * ```\n */\n getHttpClient(): HttpClient {\n return this.http;\n }\n\n /**\n * Future modules will be added here:\n * - database: Database operations\n * - storage: File storage operations\n * - functions: Serverless functions\n * - tables: Table management\n * - metadata: Backend metadata\n */\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0EO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,OAAe,aAAsB;AACpF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,OAAO,aAAa,UAAmC;AACrD,WAAO,IAAI;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AACF;;;ACzFO,IAAM,aAAN,MAAiB;AAAA,EAOtB,YAAY,QAAwB;AAFpC,SAAQ,YAA2B;AAGjC,SAAK,UAAU,OAAO,WAAW;AAEjC,SAAK,QAAQ,OAAO,UAAU,WAAW,QAAQ,WAAW,MAAM,KAAK,UAAU,IAAI;AACrF,SAAK,UAAU,OAAO;AACtB,SAAK,iBAAiB;AAAA,MACpB,GAAG,OAAO;AAAA,IACZ;AAEA,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,SAAS,MAAc,QAAyC;AACtE,UAAM,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO;AACtC,QAAI,QAAQ;AACV,aAAO,QAAQ,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAG/C,YAAI,QAAQ,UAAU;AAKpB,cAAI,kBAAkB,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAGtD,4BAAkB,gBACf,QAAQ,aAAa,GAAG,EACxB,QAAQ,aAAa,GAAG,EACxB,QAAQ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I,QAAQ,KAAK,IAAI;AACpC,SAAK,KAAK,IAAI,GAAG,KAAK,IAAI;AAC1B,SAAK,YAAY,IAAI,UAAU,KAAK,IAAI;AACxC,SAAK,WAAW,IAAI,SAAS,KAAK,KAAK,SAAS,KAAK,cAAc,OAAO,OAAO;AACjF,SAAK,SAAS,IAAI,OAAO,KAAK,IAAI;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,gBAA4B;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUF;;;AX5CO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":["session","response"]}
package/dist/index.mjs CHANGED
@@ -1588,12 +1588,11 @@ var Realtime = class {
1588
1588
  * If connected, triggers reconnect to apply new token immediately
1589
1589
  */
1590
1590
  onTokenChange() {
1591
- const session = this.tokenManager.getSession();
1592
- const token = session?.accessToken ?? this.anonKey;
1591
+ const token = this.tokenManager.getAccessToken() ?? this.anonKey;
1593
1592
  if (this.socket) {
1594
1593
  this.socket.auth = token ? { token } : {};
1595
1594
  }
1596
- if (this.socket?.connected) {
1595
+ if (this.socket && (this.socket.connected || this.connectPromise)) {
1597
1596
  this.socket.disconnect();
1598
1597
  this.socket.connect();
1599
1598
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/auth.ts","../src/modules/database-postgrest.ts","../src/modules/storage.ts","../src/modules/ai.ts","../src/modules/functions.ts","../src/modules/realtime.ts","../src/modules/email.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["/**\n * InsForge SDK Types - only SDK-specific types here\n * Use @insforge/shared-schemas directly for API types\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\n\nexport interface InsForgeConfig {\n /**\n * The base URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n baseUrl?: string;\n\n /**\n * Anonymous API key (optional)\n * Used for public/unauthenticated requests when no user token is set\n */\n anonKey?: string;\n\n /**\n * Edge Function Token (optional)\n * Use this when running in edge functions/serverless with a user's JWT token\n * This token will be used for all authenticated requests\n */\n edgeFunctionToken?: string;\n\n /**\n * Custom fetch implementation (useful for Node.js environments)\n */\n fetch?: typeof fetch;\n\n /**\n * Storage adapter for persisting tokens\n */\n storage?: TokenStorage;\n\n /**\n * Whether to automatically refresh tokens before they expire\n * @default true\n */\n autoRefreshToken?: boolean;\n\n /**\n * Whether to persist session in storage\n * @default true\n */\n persistSession?: boolean;\n\n /**\n * Custom headers to include with every request\n */\n headers?: Record<string, string>;\n}\n\nexport interface TokenStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport interface AuthSession {\n user: UserSchema;\n accessToken: string;\n expiresAt?: Date;\n}\n\nexport interface ApiError {\n error: string;\n message: string;\n statusCode: number;\n nextActions?: string;\n}\n\nexport class InsForgeError extends Error {\n public statusCode: number;\n public error: string;\n public nextActions?: string;\n\n constructor(message: string, statusCode: number, error: string, nextActions?: string) {\n super(message);\n this.name = 'InsForgeError';\n this.statusCode = statusCode;\n this.error = error;\n this.nextActions = nextActions;\n }\n\n static fromApiError(apiError: ApiError): InsForgeError {\n return new InsForgeError(\n apiError.message,\n apiError.statusCode,\n apiError.error,\n apiError.nextActions\n );\n }\n}","import { InsForgeConfig, ApiError, InsForgeError } from '../types';\n\nexport interface RequestOptions extends RequestInit {\n params?: Record<string, string>;\n}\n\nexport class HttpClient {\n public readonly baseUrl: string;\n public readonly fetch: typeof fetch;\n private defaultHeaders: Record<string, string>;\n private anonKey: string | undefined;\n private userToken: string | null = null;\n\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.baseUrl || 'http://localhost:7130';\n // Properly bind fetch to maintain its context\n this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : undefined as any);\n this.anonKey = config.anonKey;\n this.defaultHeaders = {\n ...config.headers,\n };\n\n if (!this.fetch) {\n throw new Error(\n 'Fetch is not available. Please provide a fetch implementation in the config.'\n );\n }\n }\n\n private buildUrl(path: string, params?: Record<string, string>): string {\n const url = new URL(path, this.baseUrl);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n // For select parameter, preserve the exact formatting by normalizing whitespace\n // This ensures PostgREST relationship queries work correctly\n if (key === 'select') {\n // Normalize multiline select strings for PostgREST:\n // 1. Replace all whitespace (including newlines) with single space\n // 2. Remove spaces inside parentheses for proper PostgREST syntax\n // 3. Keep spaces after commas at the top level for readability\n let normalizedValue = value.replace(/\\s+/g, ' ').trim();\n\n // Fix spaces around parentheses and inside them\n normalizedValue = normalizedValue\n .replace(/\\s*\\(\\s*/g, '(') // Remove spaces around opening parens\n .replace(/\\s*\\)\\s*/g, ')') // Remove spaces around closing parens\n .replace(/\\(\\s+/g, '(') // Remove spaces after opening parens\n .replace(/\\s+\\)/g, ')') // Remove spaces before closing parens\n .replace(/,\\s+(?=[^()]*\\))/g, ','); // Remove spaces after commas inside parens\n \n url.searchParams.append(key, normalizedValue);\n } else {\n url.searchParams.append(key, value);\n }\n });\n }\n return url.toString();\n }\n\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { params, headers = {}, body, ...fetchOptions } = options;\n \n const url = this.buildUrl(path, params);\n \n const requestHeaders: Record<string, string> = {\n ...this.defaultHeaders,\n };\n \n // Set Authorization header: prefer user token, fallback to anon key\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n requestHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n \n // Handle body serialization\n let processedBody: any;\n if (body !== undefined) {\n // Check if body is FormData (for file uploads)\n if (typeof FormData !== 'undefined' && body instanceof FormData) {\n // Don't set Content-Type for FormData, let browser set it with boundary\n processedBody = body;\n } else {\n // JSON body\n if (method !== 'GET') {\n requestHeaders['Content-Type'] = 'application/json;charset=UTF-8';\n }\n processedBody = JSON.stringify(body);\n }\n }\n \n Object.assign(requestHeaders, headers);\n \n const response = await this.fetch(url, {\n method,\n headers: requestHeaders,\n body: processedBody,\n ...fetchOptions,\n });\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n // Try to parse JSON response\n let data: any;\n const contentType = response.headers.get('content-type');\n // Check for any JSON content type (including PostgREST's vnd.pgrst.object+json)\n if (contentType?.includes('json')) {\n data = await response.json();\n } else {\n // For non-JSON responses, return text\n data = await response.text();\n }\n\n // Handle errors\n if (!response.ok) {\n if (data && typeof data === 'object' && 'error' in data) {\n // Add the HTTP status code if not already in the data\n if (!data.statusCode && !data.status) {\n data.statusCode = response.status;\n }\n const error = InsForgeError.fromApiError(data as ApiError);\n // Preserve all additional fields from the error response\n Object.keys(data).forEach(key => {\n if (key !== 'error' && key !== 'message' && key !== 'statusCode') {\n (error as any)[key] = data[key];\n }\n });\n throw error;\n }\n throw new InsForgeError(\n `Request failed: ${response.statusText}`,\n response.status,\n 'REQUEST_FAILED'\n );\n }\n\n return data as T;\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n post<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n put<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n setAuthToken(token: string | null) {\n this.userToken = token;\n }\n\n getHeaders(): Record<string, string> {\n const headers = { ...this.defaultHeaders };\n \n // Include Authorization header if token is available (same logic as request method)\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n headers['Authorization'] = `Bearer ${authToken}`;\n }\n \n return headers;\n }\n}","/**\n * Token Manager for InsForge SDK\n * \n * Simple token storage that supports two modes:\n * - Memory mode (new backend): tokens stored in memory only, more secure\n * - Storage mode (legacy backend): tokens persisted in localStorage\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\nimport type { AuthSession, TokenStorage } from '../types';\n\n// localStorage keys\nexport const TOKEN_KEY = 'insforge-auth-token';\nexport const USER_KEY = 'insforge-auth-user';\n\n// CSRF token cookie name\nexport const CSRF_TOKEN_COOKIE = 'insforge_csrf_token';\n\n/**\n * Get CSRF token from cookie\n * Used to include in X-CSRF-Token header for refresh requests\n */\nexport function getCsrfToken(): string | null {\n if (typeof document === 'undefined') return null;\n const match = document.cookie\n .split(';')\n .find(c => c.trim().startsWith(`${CSRF_TOKEN_COOKIE}=`));\n if (!match) return null;\n return match.split('=')[1] || null;\n}\n\n/**\n * Set CSRF token cookie\n * Called after login/register/refresh to store the CSRF token\n */\nexport function setCsrfToken(token: string): void {\n if (typeof document === 'undefined') return;\n const maxAge = 7 * 24 * 60 * 60; // 7 days (same as refresh token)\n const secure = (typeof window !== 'undefined' && window.location.protocol === 'https:') ? '; Secure' : '';\n document.cookie = `${CSRF_TOKEN_COOKIE}=${encodeURIComponent(token)}; path=/; max-age=${maxAge}; SameSite=Lax${secure}`;\n}\n\n/**\n * Clear CSRF token cookie\n * Called on logout\n */\nexport function clearCsrfToken(): void {\n if (typeof document === 'undefined') return;\n const secure = (typeof window !== 'undefined' && window.location.protocol === 'https:') ? '; Secure' : '';\n document.cookie = `${CSRF_TOKEN_COOKIE}=; path=/; max-age=0; SameSite=Lax${secure}`;\n}\n\nexport class TokenManager {\n // In-memory storage\n private accessToken: string | null = null;\n private user: UserSchema | null = null;\n\n // Persistent storage (for legacy backend)\n private storage: TokenStorage;\n\n // Mode: 'memory' (new backend) or 'storage' (legacy backend, default)\n private _mode: 'memory' | 'storage' = 'storage';\n\n // Callback for token changes (used by realtime to reconnect with new token)\n onTokenChange: (() => void) | null = null;\n\n constructor(storage?: TokenStorage) {\n if (storage) {\n // Use provided storage\n this.storage = storage;\n } else if (typeof window !== 'undefined' && window.localStorage) {\n // Browser: use localStorage\n this.storage = window.localStorage;\n } else {\n // Node.js: use in-memory storage\n const store = new Map<string, string>();\n this.storage = {\n getItem: (key: string) => store.get(key) || null,\n setItem: (key: string, value: string) => { store.set(key, value); },\n removeItem: (key: string) => { store.delete(key); }\n };\n }\n }\n\n /**\n * Get current mode\n */\n get mode(): 'memory' | 'storage' {\n return this._mode;\n }\n\n /**\n * Set mode to memory (new backend with cookies + memory)\n */\n setMemoryMode(): void {\n if (this._mode === 'storage') {\n // Clear localStorage when switching from storage to memory mode\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n }\n this._mode = 'memory';\n }\n\n /**\n * Set mode to storage (legacy backend with localStorage)\n * Also loads existing session from localStorage\n */\n setStorageMode(): void {\n this._mode = 'storage';\n this.loadFromStorage();\n }\n\n /**\n * Load session from localStorage\n */\n private loadFromStorage(): void {\n const token = this.storage.getItem(TOKEN_KEY) as string | null;\n const userStr = this.storage.getItem(USER_KEY) as string | null;\n\n if (token && userStr) {\n try {\n this.accessToken = token;\n this.user = JSON.parse(userStr);\n } catch {\n this.clearSession();\n }\n }\n }\n\n /**\n * Save session (memory always, localStorage only in storage mode)\n */\n saveSession(session: AuthSession): void {\n const tokenChanged = session.accessToken !== this.accessToken;\n this.accessToken = session.accessToken;\n this.user = session.user;\n\n // Persist to localStorage in storage mode\n if (this._mode === 'storage') {\n this.storage.setItem(TOKEN_KEY, session.accessToken);\n this.storage.setItem(USER_KEY, JSON.stringify(session.user));\n }\n\n if (tokenChanged && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Get current session\n */\n getSession(): AuthSession | null {\n this.loadFromStorage();\n if (!this.accessToken || !this.user) return null;\n return {\n accessToken: this.accessToken,\n user: this.user,\n };\n }\n\n /**\n * Get access token\n */\n getAccessToken(): string | null {\n this.loadFromStorage();\n return this.accessToken;\n }\n\n /**\n * Set access token\n */\n setAccessToken(token: string): void {\n const tokenChanged = token !== this.accessToken;\n this.accessToken = token;\n if (this._mode === 'storage') {\n this.storage.setItem(TOKEN_KEY, token);\n }\n if (tokenChanged && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Get user\n */\n getUser(): UserSchema | null {\n return this.user;\n }\n\n /**\n * Set user\n */\n setUser(user: UserSchema): void {\n this.user = user;\n if (this._mode === 'storage') {\n this.storage.setItem(USER_KEY, JSON.stringify(user));\n }\n }\n\n /**\n * Clear session (both memory and localStorage)\n */\n clearSession(): void {\n const hadToken = this.accessToken !== null;\n this.accessToken = null;\n this.user = null;\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n\n if (hadToken && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Check if there's a session in localStorage (for legacy detection)\n */\n hasStoredSession(): boolean {\n const token = this.storage.getItem(TOKEN_KEY);\n return !!token;\n }\n}","/**\n * Auth module for InsForge SDK\n * Uses shared schemas for type safety\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager, getCsrfToken, setCsrfToken, clearCsrfToken } from '../lib/token-manager';\nimport { AuthSession, InsForgeError } from '../types';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\n GetPublicAuthConfigResponse,\n OAuthProvidersSchema,\n SendVerificationEmailRequest,\n SendResetPasswordEmailRequest,\n ExchangeResetPasswordTokenRequest,\n VerifyEmailRequest,\n VerifyEmailResponse,\n UserSchema,\n GetProfileResponse,\n} from '@insforge/shared-schemas';\n\n/**\n * Check if current environment is a hosted auth environment\n * Returns true for:\n * - localhost with port 7130 (hosted auth app dev)\n * - https://*.insforge.app (hosted auth app production)\n */\nfunction isHostedAuthEnvironment(): boolean {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const { hostname, port, protocol } = window.location;\n\n // Check for localhost:7130\n if (hostname === 'localhost' && port === '7130') {\n return true;\n }\n\n // Check for https://*.insforge.app\n if (protocol === 'https:' && hostname.endsWith('.insforge.app')) {\n return true;\n }\n\n return false;\n}\n\nexport class Auth {\n constructor(\n private http: HttpClient,\n private tokenManager: TokenManager\n ) {\n // Auto-detect OAuth callback parameters in the URL\n this.detectAuthCallback();\n }\n\n /**\n * Automatically detect and handle OAuth callback parameters in the URL\n * This runs after initialization to seamlessly complete the OAuth flow\n * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)\n */\n private detectAuthCallback(): void {\n // Only run in browser environment\n if (typeof window === 'undefined') return;\n\n try {\n const params = new URLSearchParams(window.location.search);\n // Backend returns: access_token, user_id, email, name (optional), csrf_token\n const accessToken = params.get('access_token');\n const userId = params.get('user_id');\n const email = params.get('email');\n const name = params.get('name');\n const csrfToken = params.get('csrf_token');\n\n // Check if we have OAuth callback parameters\n if (accessToken && userId && email) {\n if (csrfToken) {\n this.tokenManager.setMemoryMode();\n setCsrfToken(csrfToken);\n }\n // TODO: Use PKCE in future\n // Create session with the data from backend\n const session: AuthSession = {\n accessToken,\n user: {\n id: userId,\n email: email,\n profile: { name: name || '' },\n metadata: null,\n // These fields are not provided by backend OAuth callback\n // They'll be populated when calling getCurrentUser()\n emailVerified: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n },\n };\n\n // Save session and set auth token\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(accessToken);\n\n // Clean up the URL to remove sensitive parameters\n const url = new URL(window.location.href);\n url.searchParams.delete('access_token');\n url.searchParams.delete('user_id');\n url.searchParams.delete('email');\n url.searchParams.delete('name');\n url.searchParams.delete('csrf_token');\n\n // Also handle error case from backend (line 581)\n if (params.has('error')) {\n url.searchParams.delete('error');\n }\n\n // Replace URL without adding to browser history\n window.history.replaceState({}, document.title, url.toString());\n }\n } catch (error) {\n // Silently continue - don't break initialization\n console.debug('OAuth callback detection skipped:', error);\n }\n }\n\n /**\n * Sign up a new user\n */\n async signUp(request: CreateUserRequest): Promise<{\n data: CreateUserResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateUserResponse>('/api/auth/users', request);\n\n // Save session internally only if both accessToken and user exist\n if (response.accessToken && response.user && !isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n error instanceof Error ? error.message : 'An unexpected error occurred during sign up',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with email and password\n */\n async signInWithPassword(request: CreateSessionRequest): Promise<{\n data: CreateSessionResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateSessionResponse>('/api/auth/sessions', request);\n\n if (!isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred during sign in',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with OAuth provider\n */\n async signInWithOAuth(options: {\n provider: OAuthProvidersSchema;\n redirectTo?: string;\n skipBrowserRedirect?: boolean;\n }): Promise<{\n data: { url?: string; provider?: string };\n error: InsForgeError | null;\n }> {\n try {\n const { provider, redirectTo, skipBrowserRedirect } = options;\n\n const params = redirectTo\n ? { redirect_uri: redirectTo }\n : undefined;\n\n const endpoint = `/api/auth/oauth/${provider}`;\n const response = await this.http.get<GetOauthUrlResponse>(endpoint, { params });\n\n // Automatically redirect in browser unless told not to\n if (typeof window !== 'undefined' && !skipBrowserRedirect) {\n window.location.href = response.authUrl;\n return { data: {}, error: null };\n }\n\n return {\n data: {\n url: response.authUrl,\n provider\n },\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: {}, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: {},\n error: new InsForgeError(\n 'An unexpected error occurred during OAuth initialization',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign out the current user\n */\n async signOut(): Promise<{ error: InsForgeError | null }> {\n try {\n // Try to call backend logout to clear httpOnly refresh cookie\n // This may fail for legacy backends, but that's ok\n try {\n await this.http.post('/api/auth/logout', undefined, { credentials: 'include' });\n } catch {\n // Ignore errors - legacy backend may not have this endpoint\n }\n\n // Clear local session and cookies\n this.tokenManager.clearSession();\n this.http.setAuthToken(null);\n clearCsrfToken();\n\n return { error: null };\n } catch (error) {\n return {\n error: new InsForgeError(\n 'Failed to sign out',\n 500,\n 'SIGNOUT_ERROR'\n )\n };\n }\n }\n\n\n /**\n * Get all public authentication configuration (OAuth + Email)\n * Returns both OAuth providers and email authentication settings in one request\n * This is a public endpoint that doesn't require authentication\n * \n * @returns Complete public authentication configuration including OAuth providers and email auth settings\n * \n * @example\n * ```ts\n * const { data, error } = await insforge.auth.getPublicAuthConfig();\n * if (data) {\n * console.log(`OAuth providers: ${data.oauth.data.length}`);\n * console.log(`Password min length: ${data.email.passwordMinLength}`);\n * }\n * ```\n */\n async getPublicAuthConfig(): Promise<{\n data: GetPublicAuthConfigResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.get<GetPublicAuthConfigResponse>('/api/auth/public-config');\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching public authentication configuration',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n\n /**\n * Get the current user with full profile information\n * Returns both auth info (id, email, role) and profile data (dynamic fields from users table)\n */\n async getCurrentUser(): Promise<{\n data: {\n user: UserSchema;\n } | null;\n error: any | null;\n }> {\n try {\n // Check if we have a stored user\n const user = this.tokenManager.getUser();\n\n if (user) {\n return { data: { user }, error: null };\n }\n const accessToken = this.tokenManager.getAccessToken();\n if (!accessToken) {\n return { data: null, error: null };\n }\n\n // Call the API for auth info\n this.http.setAuthToken(accessToken);\n const authResponse = await this.http.get<GetCurrentSessionResponse>('/api/auth/sessions/current');\n\n return {\n data: {\n user: authResponse.user,\n },\n error: null\n };\n } catch (error) {\n // If unauthorized, clear session\n if (error instanceof InsForgeError && error.statusCode === 401) {\n await this.signOut();\n return { data: null, error: null };\n }\n\n // Pass through all other errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching user',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get any user's profile by ID\n * Returns profile information from the users table\n */\n async getProfile(userId: string): Promise<{\n data: GetProfileResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.get<GetProfileResponse>(`/api/auth/profiles/${userId}`);\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged (includes 404 NOT_FOUND, 400 INVALID_INPUT)\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching user profile',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get the current session (only session data, no API call)\n * Returns the stored JWT token and basic user info from local storage\n */\n async getCurrentSession(): Promise<{\n data: { session: AuthSession | null };\n error: InsForgeError | null;\n }> {\n try {\n // Step 1: Check if we already have session in memory\n const session = this.tokenManager.getSession();\n if (session) {\n this.http.setAuthToken(session.accessToken);\n return { data: { session }, error: null };\n }\n\n // Step 2: In browser, try to refresh using httpOnly cookie\n if (typeof window !== 'undefined') {\n try {\n const csrfToken = getCsrfToken();\n const response = await this.http.post<{\n accessToken: string;\n user?: UserSchema;\n csrfToken?: string\n }>(\n '/api/auth/refresh',\n undefined,\n {\n headers: csrfToken ? { 'X-CSRF-Token': csrfToken } : {},\n credentials: 'include',\n }\n );\n\n if (response.accessToken) {\n this.tokenManager.setMemoryMode();\n this.tokenManager.setAccessToken(response.accessToken);\n this.http.setAuthToken(response.accessToken);\n\n if (response.user) {\n this.tokenManager.setUser(response.user);\n }\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n\n return {\n data: { session: this.tokenManager.getSession() },\n error: null\n };\n }\n } catch (error) {\n if (error instanceof InsForgeError) {\n if (error.statusCode === 404) {\n // Legacy backend - try localStorage\n this.tokenManager.setStorageMode();\n const session = this.tokenManager.getSession();\n if (session) {\n return { data: { session }, error: null };\n }\n return { data: { session: null }, error: null };\n }\n // 401/403 or other errors - not logged in\n return { data: { session: null }, error: error };\n }\n }\n }\n\n // Not logged in\n return { data: { session: null }, error: null };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: { session: null }, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: { session: null },\n error: new InsForgeError(\n 'An unexpected error occurred while getting session',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Set/Update the current user's profile\n * Updates profile information in the users table (supports any dynamic fields)\n * Requires authentication\n */\n async setProfile(profile: Record<string, unknown>): Promise<{\n data: GetProfileResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.patch<GetProfileResponse>(\n '/api/auth/profiles/current',\n { profile }\n );\n\n // Update the local session/user with the new profile data\n const currentUser = this.tokenManager.getUser();\n if (currentUser && response.profile !== undefined) {\n this.tokenManager.setUser({\n ...currentUser,\n profile: response.profile,\n });\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged (includes 401 AUTH_INVALID_CREDENTIALS, 400 INVALID_INPUT)\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while updating user profile',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Send email verification (code or link based on config)\n *\n * Send email verification using the method configured in auth settings (verifyEmailMethod).\n * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.\n * Prevents user enumeration by returning success even if email doesn't exist.\n */\n async sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{\n data: { success: boolean; message: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ success: boolean; message: string }>(\n '/api/auth/email/send-verification',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while sending verification code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Send password reset (code or link based on config)\n *\n * Send password reset email using the method configured in auth settings (resetPasswordMethod).\n * When method is 'code', sends a 6-digit numeric code for two-step flow.\n * When method is 'link', sends a magic link.\n * Prevents user enumeration by returning success even if email doesn't exist.\n */\n async sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{\n data: { success: boolean; message: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ success: boolean; message: string }>(\n '/api/auth/email/send-reset-password',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while sending password reset code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Exchange reset password code for reset token\n *\n * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):\n * 1. Verify the 6-digit code sent to user's email\n * 2. Return a reset token that can be used to actually reset the password\n *\n * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).\n */\n async exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{\n data: { token: string; expiresAt: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ token: string; expiresAt: string }>(\n '/api/auth/email/exchange-reset-password-token',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while verifying reset code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Reset password with token\n *\n * Reset user password with a token. The token can be:\n * - Magic link token (64-character hex token from send-reset-password when method is 'link')\n * - Reset token (from exchange-reset-password-token after code verification when method is 'code')\n *\n * Both token types use RESET_PASSWORD purpose and are verified the same way.\n *\n * Flow summary:\n * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)\n * - Link method: send-reset-password → reset-password (with link token directly)\n */\n async resetPassword(request: { newPassword: string; otp: string }): Promise<{\n data: { message: string; redirectTo?: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ message: string; redirectTo?: string }>(\n '/api/auth/email/reset-password',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while resetting password',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Verify email with code or link\n *\n * Verify email address using the method configured in auth settings (verifyEmailMethod):\n * - Code verification: Provide both `email` and `otp` (6-digit numeric code)\n * - Link verification: Provide only `otp` (64-character hex token from magic link)\n *\n * Successfully verified users will receive a session token.\n *\n * The email verification link sent to users always points to the backend API endpoint.\n * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.\n * Otherwise, a default success page is displayed.\n */\n async verifyEmail(request: VerifyEmailRequest): Promise<{\n data: VerifyEmailResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<VerifyEmailResponse>(\n '/api/auth/email/verify',\n request\n );\n\n // Save session if we got a token\n if (!isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while verifying email',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n}","/**\n * Database module using @supabase/postgrest-js\n * Complete replacement for custom QueryBuilder with full PostgREST features\n */\n\nimport { PostgrestClient } from '@supabase/postgrest-js';\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\n\n\n/**\n * Custom fetch that transforms URLs and adds auth\n */\nfunction createInsForgePostgrestFetch(\n httpClient: HttpClient,\n tokenManager: TokenManager\n): typeof fetch {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const url = typeof input === 'string' ? input : input.toString();\n const urlObj = new URL(url);\n \n // Extract table name from pathname\n // postgrest-js sends: http://dummy/tablename?params\n // We need: http://localhost:7130/api/database/records/tablename?params\n const tableName = urlObj.pathname.slice(1); // Remove leading /\n \n // Build InsForge URL\n const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;\n \n // Get auth token from TokenManager or HttpClient\n const token = tokenManager.getAccessToken();\n const httpHeaders = httpClient.getHeaders();\n const authToken = token || httpHeaders['Authorization']?.replace('Bearer ', '');\n \n // Prepare headers\n const headers = new Headers(init?.headers);\n if (authToken && !headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${authToken}`);\n }\n \n // Make the actual request using native fetch\n const response = await fetch(insforgeUrl, {\n ...init,\n headers\n });\n \n return response;\n };\n}\n\n/**\n * Database client using postgrest-js\n * Drop-in replacement with FULL PostgREST capabilities\n */\nexport class Database {\n private postgrest: PostgrestClient<any, any, any>;\n \n constructor(httpClient: HttpClient, tokenManager: TokenManager) {\n // Create postgrest client with custom fetch\n this.postgrest = new PostgrestClient<any, any, any>('http://dummy', {\n fetch: createInsForgePostgrestFetch(httpClient, tokenManager),\n headers: {}\n });\n }\n \n /**\n * Create a query builder for a table\n * \n * @example\n * // Basic query\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId);\n * \n * // With count (Supabase style!)\n * const { data, error, count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact' })\n * .range(0, 9);\n * \n * // Just get count, no data\n * const { count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact', head: true });\n * \n * // Complex queries with OR\n * const { data } = await client.database\n * .from('posts')\n * .select('*, users!inner(*)')\n * .or('status.eq.active,status.eq.pending');\n * \n * // All features work:\n * - Nested selects\n * - Foreign key expansion \n * - OR/AND/NOT conditions\n * - Count with head\n * - Range pagination\n * - Upserts\n */\n from(table: string) {\n // Return postgrest query builder with all features\n return this.postgrest.from(table);\n }\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n}\n\ninterface UploadStrategy {\n method: 'direct' | 'presigned';\n uploadUrl: string;\n fields?: Record<string, string>;\n key: string;\n confirmRequired: boolean;\n confirmUrl?: string;\n expiresAt?: Date;\n}\n\ninterface DownloadStrategy {\n method: 'direct' | 'presigned';\n url: string;\n expiresAt?: Date;\n}\n\n/**\n * Storage bucket operations\n */\nexport class StorageBucket {\n constructor(\n private bucketName: string,\n private http: HttpClient\n ) {}\n\n /**\n * Upload a file with a specific key\n * Uses the upload strategy from backend (direct or presigned)\n * @param path - The object key/path\n * @param file - File or Blob to upload\n */\n async upload(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'PUT',\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * Uses the upload strategy from backend (direct or presigned)\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const filename = file instanceof File ? file.name : 'file';\n \n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'POST',\n `/api/storage/buckets/${this.bucketName}/objects`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Internal method to handle presigned URL uploads\n */\n private async uploadWithPresignedUrl(\n strategy: UploadStrategy,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Upload to presigned URL (e.g., S3)\n const formData = new FormData();\n \n // Add all fields from the presigned URL\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be the last field for S3\n formData.append('file', file);\n\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n throw new InsForgeError(\n `Upload to storage failed: ${uploadResponse.statusText}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Confirm upload with backend if required\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n }\n );\n\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, return basic file info\n return {\n data: {\n key: strategy.key,\n bucket: this.bucketName,\n size: file.size,\n mimeType: file.type || 'application/octet-stream',\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n } as StorageFileSchema,\n error: null\n };\n } catch (error) {\n throw error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n );\n }\n }\n\n /**\n * Download a file\n * Uses the download strategy from backend (direct or presigned)\n * @param path - The object key/path\n * Returns the file as a Blob\n */\n async download(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n // Get download strategy from backend - this is required\n const strategyResponse = await this.http.post<DownloadStrategy>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n { expiresIn: 3600 }\n );\n\n // Use URL from strategy\n const downloadUrl = strategyResponse.url;\n \n // Download from the URL\n const headers: HeadersInit = {};\n \n // Only add auth header for direct downloads (not presigned URLs)\n if (strategyResponse.method === 'direct') {\n Object.assign(headers, this.http.getHeaders());\n }\n \n const response = await fetch(downloadUrl, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n try {\n const error = await response.json();\n throw InsForgeError.fromApiError(error);\n } catch {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\n );\n }\n }\n\n const blob = await response.blob();\n return { data: blob, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Get public URL for a file\n * @param path - The object key/path\n */\n getPublicUrl(path: string): string {\n return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n }\n\n /**\n * List objects in the bucket\n * @param prefix - Filter by key prefix\n * @param search - Search in file names\n * @param limit - Maximum number of results (default: 100, max: 1000)\n * @param offset - Number of results to skip\n */\n async list(options?: {\n prefix?: string;\n search?: string;\n limit?: number;\n offset?: number;\n }): Promise<StorageResponse<ListObjectsResponseSchema>> {\n try {\n const params: Record<string, string> = {};\n \n if (options?.prefix) params.prefix = options.prefix;\n if (options?.search) params.search = options.search;\n if (options?.limit) params.limit = options.limit.toString();\n if (options?.offset) params.offset = options.offset.toString();\n\n const response = await this.http.get<ListObjectsResponseSchema>(\n `/api/storage/buckets/${this.bucketName}/objects`,\n { params }\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'List failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Delete a file\n * @param path - The object key/path\n */\n async remove(path: string): Promise<StorageResponse<{ message: string }>> {\n try {\n const response = await this.http.delete<{ message: string }>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Delete failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n}\n\n/**\n * Storage module for file operations\n */\nexport class Storage {\n constructor(private http: HttpClient) {}\n\n /**\n * Get a bucket instance for operations\n * @param bucketName - Name of the bucket\n */\n from(bucketName: string): StorageBucket {\n return new StorageBucket(bucketName, this.http);\n }\n}","/**\n * AI Module for Insforge SDK\n * Response format roughly matches OpenAI SDK for compatibility\n *\n * The backend handles all the complexity of different AI providers\n * and returns a unified format. This SDK transforms responses to match OpenAI-like format.\n */\n\nimport { HttpClient } from \"../lib/http-client\";\nimport {\n ChatCompletionRequest,\n ChatCompletionResponse,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@insforge/shared-schemas\";\n\nexport class AI {\n public readonly chat: Chat;\n public readonly images: Images;\n\n constructor(private http: HttpClient) {\n this.chat = new Chat(http);\n this.images = new Images(http);\n }\n}\n\nclass Chat {\n public readonly completions: ChatCompletions;\n\n constructor(http: HttpClient) {\n this.completions = new ChatCompletions(http);\n }\n}\n\nclass ChatCompletions {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a chat completion - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const completion = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Hello!' }]\n * });\n * console.log(completion.choices[0].message.content);\n *\n * // With images\n * const response = await client.ai.chat.completions.create({\n * model: 'gpt-4-vision',\n * messages: [{\n * role: 'user',\n * content: 'What is in this image?',\n * images: [{ url: 'https://example.com/image.jpg' }]\n * }]\n * });\n *\n * // Streaming - returns async iterable\n * const stream = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * stream: true\n * });\n *\n * for await (const chunk of stream) {\n * if (chunk.choices[0]?.delta?.content) {\n * process.stdout.write(chunk.choices[0].delta.content);\n * }\n * }\n * ```\n */\n async create(params: ChatCompletionRequest): Promise<any> {\n // Backend already expects camelCase, no transformation needed\n const backendParams = {\n model: params.model,\n messages: params.messages,\n temperature: params.temperature,\n maxTokens: params.maxTokens,\n topP: params.topP,\n stream: params.stream,\n };\n\n // For streaming, return an async iterable that yields OpenAI-like chunks\n if (params.stream) {\n const headers = this.http.getHeaders();\n headers[\"Content-Type\"] = \"application/json\";\n\n const response = await this.http.fetch(\n `${this.http.baseUrl}/api/ai/chat/completion`,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(backendParams),\n }\n );\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(error.error || \"Stream request failed\");\n }\n\n // Return async iterable that parses SSE and transforms to OpenAI-like format\n return this.parseSSEStream(response, params.model);\n }\n\n // Non-streaming: transform response to OpenAI-like format\n const response: ChatCompletionResponse = await this.http.post(\n \"/api/ai/chat/completion\",\n backendParams\n );\n\n // Transform to OpenAI-like format\n const content = response.text || \"\";\n\n return {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: response.metadata?.model,\n choices: [\n {\n index: 0,\n message: {\n role: \"assistant\",\n content,\n },\n finish_reason: \"stop\",\n },\n ],\n usage: response.metadata?.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n },\n };\n }\n\n /**\n * Parse SSE stream into async iterable of OpenAI-like chunks\n */\n private async *parseSSEStream(\n response: Response,\n model: string\n ): AsyncIterableIterator<any> {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() || \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const dataStr = line.slice(6).trim();\n if (dataStr) {\n try {\n const data = JSON.parse(dataStr);\n\n // Transform to OpenAI-like streaming format\n if (data.chunk || data.content) {\n yield {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [\n {\n index: 0,\n delta: {\n content: data.chunk || data.content,\n },\n finish_reason: data.done ? \"stop\" : null,\n },\n ],\n };\n }\n\n // If we received the done signal, we can stop\n if (data.done) {\n reader.releaseLock();\n return;\n }\n } catch (e) {\n // Skip invalid JSON\n console.warn(\"Failed to parse SSE data:\", dataStr);\n }\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nclass Images {\n constructor(private http: HttpClient) {}\n\n /**\n * Generate images - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Text-to-image\n * const response = await client.ai.images.generate({\n * model: 'dall-e-3',\n * prompt: 'A sunset over mountains',\n * });\n * console.log(response.images[0].url);\n *\n * // Image-to-image (with input images)\n * const response = await client.ai.images.generate({\n * model: 'stable-diffusion-xl',\n * prompt: 'Transform this into a watercolor painting',\n * images: [\n * { url: 'https://example.com/input.jpg' },\n * // or base64-encoded Data URI:\n * { url: 'data:image/jpeg;base64,/9j/4AAQ...' }\n * ]\n * });\n * ```\n */\n async generate(params: ImageGenerationRequest): Promise<any> {\n const response: ImageGenerationResponse = await this.http.post(\n \"/api/ai/image/generation\",\n params\n );\n \n // Build data array based on response content\n let data: Array<{ b64_json?: string; content?: string }> = [];\n \n if (response.images && response.images.length > 0) {\n // Has images - extract base64 and include text\n data = response.images.map(img => ({\n b64_json: img.imageUrl.replace(/^data:image\\/\\w+;base64,/, ''),\n content: response.text\n }));\n } else if (response.text) {\n // Text-only response\n data = [{ content: response.text }];\n }\n \n // Return OpenAI-compatible format\n return {\n created: Math.floor(Date.now() / 1000),\n data,\n ...(response.metadata?.usage && {\n usage: {\n total_tokens: response.metadata.usage.totalTokens || 0,\n input_tokens: response.metadata.usage.promptTokens || 0,\n output_tokens: response.metadata.usage.completionTokens || 0,\n }\n })\n };\n }\n}\n","import { HttpClient } from '../lib/http-client';\n\nexport interface FunctionInvokeOptions {\n /**\n * The body of the request\n */\n body?: any;\n \n /**\n * Custom headers to send with the request\n */\n headers?: Record<string, string>;\n \n /**\n * HTTP method (default: POST)\n */\n method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n}\n\n/**\n * Edge Functions client for invoking serverless functions\n * \n * @example\n * ```typescript\n * // Invoke a function with JSON body\n * const { data, error } = await client.functions.invoke('hello-world', {\n * body: { name: 'World' }\n * });\n * \n * // GET request\n * const { data, error } = await client.functions.invoke('get-data', {\n * method: 'GET'\n * });\n * ```\n */\nexport class Functions {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Invokes an Edge Function\n * @param slug The function slug to invoke\n * @param options Request options\n */\n async invoke<T = any>(\n slug: string,\n options: FunctionInvokeOptions = {}\n ): Promise<{ data: T | null; error: Error | null }> {\n try {\n const { method = 'POST', body, headers = {} } = options;\n \n // Simple path: /functions/{slug}\n const path = `/functions/${slug}`;\n \n // Use the HTTP client's request method\n const data = await this.http.request<T>(\n method,\n path,\n { body, headers }\n );\n \n return { data, error: null };\n } catch (error: any) {\n // The HTTP client throws InsForgeError with all properties from the response\n // including error, message, details, statusCode, etc.\n // We need to preserve all of that information\n return { \n data: null, \n error: error // Pass through the full error object with all properties\n };\n }\n }\n}","import { io, Socket } from 'socket.io-client';\nimport type { SubscribeResponse, RealtimeErrorPayload, SocketMessage } from '@insforge/shared-schemas';\nimport { TokenManager } from '../lib/token-manager';\n\nexport type { SubscribeResponse, RealtimeErrorPayload, SocketMessage };\n\nexport type ConnectionState = 'disconnected' | 'connecting' | 'connected';\n\nexport type EventCallback<T = unknown> = (payload: T) => void;\n\nconst CONNECT_TIMEOUT = 10000;\n\n/**\n * Realtime module for subscribing to channels and handling real-time events\n *\n * @example\n * ```typescript\n * const { realtime } = client;\n *\n * // Connect to the realtime server\n * await realtime.connect();\n *\n * // Subscribe to a channel\n * const response = await realtime.subscribe('orders:123');\n * if (!response.ok) {\n * console.error('Failed to subscribe:', response.error);\n * }\n *\n * // Listen for specific events\n * realtime.on('order_updated', (payload) => {\n * console.log('Order updated:', payload);\n * });\n *\n * // Listen for connection events\n * realtime.on('connect', () => console.log('Connected!'));\n * realtime.on('connect_error', (err) => console.error('Connection failed:', err));\n * realtime.on('disconnect', (reason) => console.log('Disconnected:', reason));\n * realtime.on('error', (error) => console.error('Realtime error:', error));\n *\n * // Publish a message to a channel\n * await realtime.publish('orders:123', 'status_changed', { status: 'shipped' });\n *\n * // Unsubscribe and disconnect when done\n * realtime.unsubscribe('orders:123');\n * realtime.disconnect();\n * ```\n */\nexport class Realtime {\n private baseUrl: string;\n private tokenManager: TokenManager;\n private socket: Socket | null = null;\n private connectPromise: Promise<void> | null = null;\n private subscribedChannels: Set<string> = new Set();\n private eventListeners: Map<string, Set<EventCallback>> = new Map();\n private anonKey?: string;\n\n constructor(baseUrl: string, tokenManager: TokenManager, anonKey?: string) {\n this.baseUrl = baseUrl;\n this.tokenManager = tokenManager;\n this.anonKey = anonKey;\n\n // Handle token changes (e.g., after refresh)\n this.tokenManager.onTokenChange = () => this.onTokenChange();\n }\n\n private notifyListeners(event: string, payload?: unknown): void {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n for (const cb of listeners) {\n try {\n cb(payload);\n } catch (err) {\n console.error(`Error in ${event} callback:`, err);\n }\n }\n }\n\n /**\n * Connect to the realtime server\n * @returns Promise that resolves when connected\n */\n connect(): Promise<void> {\n // Already connected\n if (this.socket?.connected) {\n return Promise.resolve();\n }\n\n // Connection already in progress, return existing promise\n if (this.connectPromise) {\n return this.connectPromise;\n }\n\n this.connectPromise = new Promise((resolve, reject) => {\n const session = this.tokenManager.getSession();\n const token = session?.accessToken ?? this.anonKey;\n \n\n this.socket = io(this.baseUrl, {\n transports: ['websocket'],\n auth: token ? { token } : undefined,\n });\n\n let initialConnection = true;\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n const cleanup = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n timeoutId = setTimeout(() => {\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n this.socket?.disconnect();\n this.socket = null;\n reject(new Error(`Connection timeout after ${CONNECT_TIMEOUT}ms`));\n }\n }, CONNECT_TIMEOUT);\n\n this.socket.on('connect', () => {\n cleanup();\n // Re-subscribe to channels on every connect (initial + reconnects)\n for (const channel of this.subscribedChannels) {\n this.socket!.emit('realtime:subscribe', { channel });\n }\n this.notifyListeners('connect');\n\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n resolve();\n }\n });\n\n this.socket.on('connect_error', (error: Error) => {\n cleanup();\n this.notifyListeners('connect_error', error);\n\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n reject(error);\n }\n });\n\n this.socket.on('disconnect', (reason: string) => {\n this.notifyListeners('disconnect', reason);\n });\n\n this.socket.on('realtime:error', (error: RealtimeErrorPayload) => {\n this.notifyListeners('error', error);\n });\n\n // Route custom events to listeners (onAny doesn't catch socket reserved events)\n this.socket.onAny((event: string, message: SocketMessage) => {\n if (event === 'realtime:error') return; // Already handled above\n this.notifyListeners(event, message);\n });\n });\n\n return this.connectPromise;\n }\n\n /**\n * Disconnect from the realtime server\n */\n disconnect(): void {\n if (this.socket) {\n this.socket.disconnect();\n this.socket = null;\n }\n this.subscribedChannels.clear();\n }\n\n /**\n * Handle token changes (e.g., after auth refresh)\n * Updates socket auth so reconnects use the new token\n * If connected, triggers reconnect to apply new token immediately\n */\n private onTokenChange(): void {\n const session = this.tokenManager.getSession();\n const token = session?.accessToken ?? this.anonKey;\n\n // Always update auth so socket.io auto-reconnect uses new token\n if (this.socket) {\n this.socket.auth = token ? { token } : {};\n }\n\n // Trigger reconnect if currently connected\n if (this.socket?.connected) {\n this.socket.disconnect();\n this.socket.connect();\n // Note: on('connect') handler automatically re-subscribes to channels\n }\n }\n\n /**\n * Check if connected to the realtime server\n */\n get isConnected(): boolean {\n return this.socket?.connected ?? false;\n }\n\n /**\n * Get the current connection state\n */\n get connectionState(): ConnectionState {\n if (!this.socket) return 'disconnected';\n if (this.socket.connected) return 'connected';\n return 'connecting';\n }\n\n /**\n * Get the socket ID (if connected)\n */\n get socketId(): string | undefined {\n return this.socket?.id;\n }\n\n /**\n * Subscribe to a channel\n *\n * Automatically connects if not already connected.\n *\n * @param channel - Channel name (e.g., 'orders:123', 'broadcast')\n * @returns Promise with the subscription response\n */\n async subscribe(channel: string): Promise<SubscribeResponse> {\n // Already subscribed, return success\n if (this.subscribedChannels.has(channel)) {\n return { ok: true, channel };\n }\n\n // Auto-connect if not connected\n if (!this.socket?.connected) {\n try {\n await this.connect();\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Connection failed';\n return { ok: false, channel, error: { code: 'CONNECTION_FAILED', message } };\n }\n }\n\n return new Promise((resolve) => {\n this.socket!.emit('realtime:subscribe', { channel }, (response: SubscribeResponse) => {\n if (response.ok) {\n this.subscribedChannels.add(channel);\n }\n resolve(response);\n });\n });\n }\n\n /**\n * Unsubscribe from a channel (fire-and-forget)\n *\n * @param channel - Channel name to unsubscribe from\n */\n unsubscribe(channel: string): void {\n this.subscribedChannels.delete(channel);\n\n if (this.socket?.connected) {\n this.socket.emit('realtime:unsubscribe', { channel });\n }\n }\n\n /**\n * Publish a message to a channel\n *\n * @param channel - Channel name\n * @param event - Event name\n * @param payload - Message payload\n */\n async publish<T = unknown>(channel: string, event: string, payload: T): Promise<void> {\n if (!this.socket?.connected) {\n throw new Error('Not connected to realtime server. Call connect() first.');\n }\n\n this.socket!.emit('realtime:publish', { channel, event, payload });\n }\n\n /**\n * Listen for events\n *\n * Reserved event names:\n * - 'connect' - Fired when connected to the server\n * - 'connect_error' - Fired when connection fails (payload: Error)\n * - 'disconnect' - Fired when disconnected (payload: reason string)\n * - 'error' - Fired when a realtime error occurs (payload: RealtimeErrorPayload)\n *\n * All other events receive a `SocketMessage` payload with metadata.\n *\n * @param event - Event name to listen for\n * @param callback - Callback function when event is received\n */\n on<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n if (!this.eventListeners.has(event)) {\n this.eventListeners.set(event, new Set());\n }\n this.eventListeners.get(event)!.add(callback as EventCallback);\n }\n\n /**\n * Remove a listener for a specific event\n *\n * @param event - Event name\n * @param callback - The callback function to remove\n */\n off<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n const listeners = this.eventListeners.get(event);\n if (listeners) {\n listeners.delete(callback as EventCallback);\n if (listeners.size === 0) {\n this.eventListeners.delete(event);\n }\n }\n }\n\n /**\n * Listen for an event only once, then automatically remove the listener\n *\n * @param event - Event name to listen for\n * @param callback - Callback function when event is received\n */\n once<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n const wrapper: EventCallback<T> = (payload: T) => {\n this.off(event, wrapper);\n callback(payload);\n };\n this.on(event, wrapper);\n }\n\n /**\n * Get all currently subscribed channels\n *\n * @returns Array of channel names\n */\n getSubscribedChannels(): string[] {\n return Array.from(this.subscribedChannels);\n }\n}\n","import { HttpClient } from '../lib/http-client';\nimport type { SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';\n\nexport type { SendRawEmailRequest as SendEmailOptions, SendEmailResponse } from '@insforge/shared-schemas';\n\n/**\n * Emails client for sending custom emails\n *\n * @example\n * ```typescript\n * // Send a simple email\n * const { data, error } = await client.emails.send({\n * to: 'user@example.com',\n * subject: 'Welcome!',\n * html: '<h1>Welcome to our platform</h1>'\n * });\n *\n * if (error) {\n * console.error('Failed to send:', error.message);\n * return;\n * }\n * // Email sent successfully - data is {} (empty object)\n *\n * // Send to multiple recipients with CC\n * const { data, error } = await client.emails.send({\n * to: ['user1@example.com', 'user2@example.com'],\n * cc: 'manager@example.com',\n * subject: 'Team Update',\n * html: '<p>Here is the latest update...</p>',\n * replyTo: 'support@example.com'\n * });\n * ```\n */\nexport class Emails {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Send a custom HTML email\n * @param options Email options including recipients, subject, and HTML content\n */\n async send(\n options: SendRawEmailRequest\n ): Promise<{ data: SendEmailResponse | null; error: Error | null }> {\n try {\n const data = await this.http.post<SendEmailResponse>(\n '/api/email/send-raw',\n options\n );\n\n return { data, error: null };\n } catch (error: unknown) {\n const normalizedError = error instanceof Error ? error : new Error(String(error));\n return { data: null, error: normalizedError };\n }\n }\n}\n","import { InsForgeConfig } from './types';\nimport { HttpClient } from './lib/http-client';\nimport { TokenManager } from './lib/token-manager';\nimport { Auth } from './modules/auth';\nimport { Database } from './modules/database-postgrest';\nimport { Storage } from './modules/storage';\nimport { AI } from './modules/ai';\nimport { Functions } from './modules/functions';\nimport { Realtime } from './modules/realtime';\nimport { Emails } from './modules/email';\n\n/**\n * Main InsForge SDK Client\n * \n * @example\n * ```typescript\n * import { InsForgeClient } from '@insforge/sdk';\n * \n * const client = new InsForgeClient({\n * baseUrl: 'http://localhost:7130'\n * });\n * \n * // Authentication\n * const { data, error } = await client.auth.signUp({\n * email: 'user@example.com',\n * password: 'password123',\n * name: 'John Doe'\n * });\n * \n * // Database operations\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', session.user.id)\n * .order('created_at', { ascending: false })\n * .limit(10);\n * \n * // Insert data\n * const { data: newPost } = await client.database\n * .from('posts')\n * .insert({ title: 'Hello', content: 'World' })\n * .single();\n * \n * // Invoke edge functions\n * const { data, error } = await client.functions.invoke('my-function', {\n * body: { message: 'Hello from SDK' }\n * });\n * ```\n */\nexport class InsForgeClient {\n private http: HttpClient;\n private tokenManager: TokenManager;\n public readonly auth: Auth;\n public readonly database: Database;\n public readonly storage: Storage;\n public readonly ai: AI;\n public readonly functions: Functions;\n public readonly realtime: Realtime;\n public readonly emails: Emails;\n\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n\n // Check for edge function token\n if (config.edgeFunctionToken) {\n this.http.setAuthToken(config.edgeFunctionToken);\n // Save to token manager so getCurrentUser() works\n this.tokenManager.saveSession({\n accessToken: config.edgeFunctionToken,\n user: {} as any, // Will be populated by getCurrentUser()\n });\n }\n\n // Check for existing session\n // In secure mode: try to refresh to get access token\n // In local mode: check localStorage\n const existingSession = this.tokenManager.getSession();\n if (existingSession?.accessToken) {\n this.http.setAuthToken(existingSession.accessToken);\n }\n\n this.auth = new Auth(this.http, this.tokenManager);\n this.database = new Database(this.http, this.tokenManager);\n this.storage = new Storage(this.http);\n this.ai = new AI(this.http);\n this.functions = new Functions(this.http);\n this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);\n this.emails = new Emails(this.http);\n }\n\n /**\n * Get the underlying HTTP client for custom requests\n * \n * @example\n * ```typescript\n * const httpClient = client.getHttpClient();\n * const customData = await httpClient.get('/api/custom-endpoint');\n * ```\n */\n getHttpClient(): HttpClient {\n return this.http;\n }\n\n /**\n * Future modules will be added here:\n * - database: Database operations\n * - storage: File storage operations\n * - functions: Serverless functions\n * - tables: Table management\n * - metadata: Backend metadata\n */\n}\n","/**\n * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service\n * \n * @packageDocumentation\n */\n\n// Main client\nexport { InsForgeClient } from './client';\n\n// Types\nexport type {\n InsForgeConfig,\n InsForgeConfig as ClientOptions, // Alias for compatibility\n TokenStorage,\n AuthSession,\n ApiError,\n} from './types';\n\nexport { InsForgeError } from './types';\n\n// Re-export shared schemas that SDK users will need\nexport type {\n UserSchema,\n CreateUserRequest,\n CreateSessionRequest,\n AuthErrorResponse,\n} from '@insforge/shared-schemas';\n\n// Re-export auth module for advanced usage\nexport { Auth } from './modules/auth';\n\n// Re-export database module (using postgrest-js)\nexport { Database } from './modules/database-postgrest';\n// Note: QueryBuilder is no longer exported as we use postgrest-js QueryBuilder internally\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\n\n// Re-export AI module\nexport { AI } from './modules/ai';\n\n// Re-export Functions module\nexport { Functions } from './modules/functions';\nexport type { FunctionInvokeOptions } from './modules/functions';\n\n// Re-export Emails module (Resend-compatible API)\nexport { Emails } from './modules/email';\nexport type { SendEmailOptions, SendEmailResponse } from './modules/email';\n\n// Re-export Realtime module and types\nexport { Realtime } from './modules/realtime';\nexport type {\n RealtimeErrorPayload,\n SubscribeResponse,\n SocketMessage,\n ConnectionState,\n EventCallback,\n} from './modules/realtime';\n\n// Re-export utilities for advanced usage\nexport { HttpClient } from './lib/http-client';\nexport { TokenManager } from './lib/token-manager';\n\n// Factory function for creating clients (Supabase-style)\nimport { InsForgeClient } from './client';\nimport { InsForgeConfig } from './types';\n\nexport function createClient(config: InsForgeConfig): InsForgeClient {\n return new InsForgeClient(config);\n}\n\n// Default export for convenience\nexport default InsForgeClient;\n"],"mappings":";AA0EO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,OAAe,aAAsB;AACpF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,c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AAA;AAAA;AAUF;;;AC5CO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":["session","response"]}
1
+ {"version":3,"sources":["../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/auth.ts","../src/modules/database-postgrest.ts","../src/modules/storage.ts","../src/modules/ai.ts","../src/modules/functions.ts","../src/modules/realtime.ts","../src/modules/email.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["/**\n * InsForge SDK Types - only SDK-specific types here\n * Use @insforge/shared-schemas directly for API types\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\n\nexport interface InsForgeConfig {\n /**\n * The base URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n baseUrl?: string;\n\n /**\n * Anonymous API key (optional)\n * Used for public/unauthenticated requests when no user token is set\n */\n anonKey?: string;\n\n /**\n * Edge Function Token (optional)\n * Use this when running in edge functions/serverless with a user's JWT token\n * This token will be used for all authenticated requests\n */\n edgeFunctionToken?: string;\n\n /**\n * Custom fetch implementation (useful for Node.js environments)\n */\n fetch?: typeof fetch;\n\n /**\n * Storage adapter for persisting tokens\n */\n storage?: TokenStorage;\n\n /**\n * Whether to automatically refresh tokens before they expire\n * @default true\n */\n autoRefreshToken?: boolean;\n\n /**\n * Whether to persist session in storage\n * @default true\n */\n persistSession?: boolean;\n\n /**\n * Custom headers to include with every request\n */\n headers?: Record<string, string>;\n}\n\nexport interface TokenStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport interface AuthSession {\n user: UserSchema;\n accessToken: string;\n expiresAt?: Date;\n}\n\nexport interface ApiError {\n error: string;\n message: string;\n statusCode: number;\n nextActions?: string;\n}\n\nexport class InsForgeError extends Error {\n public statusCode: number;\n public error: string;\n public nextActions?: string;\n\n constructor(message: string, statusCode: number, error: string, nextActions?: string) {\n super(message);\n this.name = 'InsForgeError';\n this.statusCode = statusCode;\n this.error = error;\n this.nextActions = nextActions;\n }\n\n static fromApiError(apiError: ApiError): InsForgeError {\n return new InsForgeError(\n apiError.message,\n apiError.statusCode,\n apiError.error,\n apiError.nextActions\n );\n }\n}","import { InsForgeConfig, ApiError, InsForgeError } from '../types';\n\nexport interface RequestOptions extends RequestInit {\n params?: Record<string, string>;\n}\n\nexport class HttpClient {\n public readonly baseUrl: string;\n public readonly fetch: typeof fetch;\n private defaultHeaders: Record<string, string>;\n private anonKey: string | undefined;\n private userToken: string | null = null;\n\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.baseUrl || 'http://localhost:7130';\n // Properly bind fetch to maintain its context\n this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : undefined as any);\n this.anonKey = config.anonKey;\n this.defaultHeaders = {\n ...config.headers,\n };\n\n if (!this.fetch) {\n throw new Error(\n 'Fetch is not available. Please provide a fetch implementation in the config.'\n );\n }\n }\n\n private buildUrl(path: string, params?: Record<string, string>): string {\n const url = new URL(path, this.baseUrl);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n // For select parameter, preserve the exact formatting by normalizing whitespace\n // This ensures PostgREST relationship queries work correctly\n if (key === 'select') {\n // Normalize multiline select strings for PostgREST:\n // 1. Replace all whitespace (including newlines) with single space\n // 2. Remove spaces inside parentheses for proper PostgREST syntax\n // 3. Keep spaces after commas at the top level for readability\n let normalizedValue = value.replace(/\\s+/g, ' ').trim();\n\n // Fix spaces around parentheses and inside them\n normalizedValue = normalizedValue\n .replace(/\\s*\\(\\s*/g, '(') // Remove spaces around opening parens\n .replace(/\\s*\\)\\s*/g, ')') // Remove spaces around closing parens\n .replace(/\\(\\s+/g, '(') // Remove spaces after opening parens\n .replace(/\\s+\\)/g, ')') // Remove spaces before closing parens\n .replace(/,\\s+(?=[^()]*\\))/g, ','); // Remove spaces after commas inside parens\n \n url.searchParams.append(key, normalizedValue);\n } else {\n url.searchParams.append(key, value);\n }\n });\n }\n return url.toString();\n }\n\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { params, headers = {}, body, ...fetchOptions } = options;\n \n const url = this.buildUrl(path, params);\n \n const requestHeaders: Record<string, string> = {\n ...this.defaultHeaders,\n };\n \n // Set Authorization header: prefer user token, fallback to anon key\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n requestHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n \n // Handle body serialization\n let processedBody: any;\n if (body !== undefined) {\n // Check if body is FormData (for file uploads)\n if (typeof FormData !== 'undefined' && body instanceof FormData) {\n // Don't set Content-Type for FormData, let browser set it with boundary\n processedBody = body;\n } else {\n // JSON body\n if (method !== 'GET') {\n requestHeaders['Content-Type'] = 'application/json;charset=UTF-8';\n }\n processedBody = JSON.stringify(body);\n }\n }\n \n Object.assign(requestHeaders, headers);\n \n const response = await this.fetch(url, {\n method,\n headers: requestHeaders,\n body: processedBody,\n ...fetchOptions,\n });\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n // Try to parse JSON response\n let data: any;\n const contentType = response.headers.get('content-type');\n // Check for any JSON content type (including PostgREST's vnd.pgrst.object+json)\n if (contentType?.includes('json')) {\n data = await response.json();\n } else {\n // For non-JSON responses, return text\n data = await response.text();\n }\n\n // Handle errors\n if (!response.ok) {\n if (data && typeof data === 'object' && 'error' in data) {\n // Add the HTTP status code if not already in the data\n if (!data.statusCode && !data.status) {\n data.statusCode = response.status;\n }\n const error = InsForgeError.fromApiError(data as ApiError);\n // Preserve all additional fields from the error response\n Object.keys(data).forEach(key => {\n if (key !== 'error' && key !== 'message' && key !== 'statusCode') {\n (error as any)[key] = data[key];\n }\n });\n throw error;\n }\n throw new InsForgeError(\n `Request failed: ${response.statusText}`,\n response.status,\n 'REQUEST_FAILED'\n );\n }\n\n return data as T;\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n post<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n put<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n setAuthToken(token: string | null) {\n this.userToken = token;\n }\n\n getHeaders(): Record<string, string> {\n const headers = { ...this.defaultHeaders };\n \n // Include Authorization header if token is available (same logic as request method)\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n headers['Authorization'] = `Bearer ${authToken}`;\n }\n \n return headers;\n }\n}","/**\n * Token Manager for InsForge SDK\n * \n * Simple token storage that supports two modes:\n * - Memory mode (new backend): tokens stored in memory only, more secure\n * - Storage mode (legacy backend): tokens persisted in localStorage\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\nimport type { AuthSession, TokenStorage } from '../types';\n\n// localStorage keys\nexport const TOKEN_KEY = 'insforge-auth-token';\nexport const USER_KEY = 'insforge-auth-user';\n\n// CSRF token cookie name\nexport const CSRF_TOKEN_COOKIE = 'insforge_csrf_token';\n\n/**\n * Get CSRF token from cookie\n * Used to include in X-CSRF-Token header for refresh requests\n */\nexport function getCsrfToken(): string | null {\n if (typeof document === 'undefined') return null;\n const match = document.cookie\n .split(';')\n .find(c => c.trim().startsWith(`${CSRF_TOKEN_COOKIE}=`));\n if (!match) return null;\n return match.split('=')[1] || null;\n}\n\n/**\n * Set CSRF token cookie\n * Called after login/register/refresh to store the CSRF token\n */\nexport function setCsrfToken(token: string): void {\n if (typeof document === 'undefined') return;\n const maxAge = 7 * 24 * 60 * 60; // 7 days (same as refresh token)\n const secure = (typeof window !== 'undefined' && window.location.protocol === 'https:') ? '; Secure' : '';\n document.cookie = `${CSRF_TOKEN_COOKIE}=${encodeURIComponent(token)}; path=/; max-age=${maxAge}; SameSite=Lax${secure}`;\n}\n\n/**\n * Clear CSRF token cookie\n * Called on logout\n */\nexport function clearCsrfToken(): void {\n if (typeof document === 'undefined') return;\n const secure = (typeof window !== 'undefined' && window.location.protocol === 'https:') ? '; Secure' : '';\n document.cookie = `${CSRF_TOKEN_COOKIE}=; path=/; max-age=0; SameSite=Lax${secure}`;\n}\n\nexport class TokenManager {\n // In-memory storage\n private accessToken: string | null = null;\n private user: UserSchema | null = null;\n\n // Persistent storage (for legacy backend)\n private storage: TokenStorage;\n\n // Mode: 'memory' (new backend) or 'storage' (legacy backend, default)\n private _mode: 'memory' | 'storage' = 'storage';\n\n // Callback for token changes (used by realtime to reconnect with new token)\n onTokenChange: (() => void) | null = null;\n\n constructor(storage?: TokenStorage) {\n if (storage) {\n // Use provided storage\n this.storage = storage;\n } else if (typeof window !== 'undefined' && window.localStorage) {\n // Browser: use localStorage\n this.storage = window.localStorage;\n } else {\n // Node.js: use in-memory storage\n const store = new Map<string, string>();\n this.storage = {\n getItem: (key: string) => store.get(key) || null,\n setItem: (key: string, value: string) => { store.set(key, value); },\n removeItem: (key: string) => { store.delete(key); }\n };\n }\n }\n\n /**\n * Get current mode\n */\n get mode(): 'memory' | 'storage' {\n return this._mode;\n }\n\n /**\n * Set mode to memory (new backend with cookies + memory)\n */\n setMemoryMode(): void {\n if (this._mode === 'storage') {\n // Clear localStorage when switching from storage to memory mode\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n }\n this._mode = 'memory';\n }\n\n /**\n * Set mode to storage (legacy backend with localStorage)\n * Also loads existing session from localStorage\n */\n setStorageMode(): void {\n this._mode = 'storage';\n this.loadFromStorage();\n }\n\n /**\n * Load session from localStorage\n */\n private loadFromStorage(): void {\n const token = this.storage.getItem(TOKEN_KEY) as string | null;\n const userStr = this.storage.getItem(USER_KEY) as string | null;\n\n if (token && userStr) {\n try {\n this.accessToken = token;\n this.user = JSON.parse(userStr);\n } catch {\n this.clearSession();\n }\n }\n }\n\n /**\n * Save session (memory always, localStorage only in storage mode)\n */\n saveSession(session: AuthSession): void {\n const tokenChanged = session.accessToken !== this.accessToken;\n this.accessToken = session.accessToken;\n this.user = session.user;\n\n // Persist to localStorage in storage mode\n if (this._mode === 'storage') {\n this.storage.setItem(TOKEN_KEY, session.accessToken);\n this.storage.setItem(USER_KEY, JSON.stringify(session.user));\n }\n\n if (tokenChanged && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Get current session\n */\n getSession(): AuthSession | null {\n this.loadFromStorage();\n if (!this.accessToken || !this.user) return null;\n return {\n accessToken: this.accessToken,\n user: this.user,\n };\n }\n\n /**\n * Get access token\n */\n getAccessToken(): string | null {\n this.loadFromStorage();\n return this.accessToken;\n }\n\n /**\n * Set access token\n */\n setAccessToken(token: string): void {\n const tokenChanged = token !== this.accessToken;\n this.accessToken = token;\n if (this._mode === 'storage') {\n this.storage.setItem(TOKEN_KEY, token);\n }\n if (tokenChanged && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Get user\n */\n getUser(): UserSchema | null {\n return this.user;\n }\n\n /**\n * Set user\n */\n setUser(user: UserSchema): void {\n this.user = user;\n if (this._mode === 'storage') {\n this.storage.setItem(USER_KEY, JSON.stringify(user));\n }\n }\n\n /**\n * Clear session (both memory and localStorage)\n */\n clearSession(): void {\n const hadToken = this.accessToken !== null;\n this.accessToken = null;\n this.user = null;\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n\n if (hadToken && this.onTokenChange) {\n this.onTokenChange();\n }\n }\n\n /**\n * Check if there's a session in localStorage (for legacy detection)\n */\n hasStoredSession(): boolean {\n const token = this.storage.getItem(TOKEN_KEY);\n return !!token;\n }\n}","/**\n * Auth module for InsForge SDK\n * Uses shared schemas for type safety\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager, getCsrfToken, setCsrfToken, clearCsrfToken } from '../lib/token-manager';\nimport { AuthSession, InsForgeError } from '../types';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\n GetPublicAuthConfigResponse,\n OAuthProvidersSchema,\n SendVerificationEmailRequest,\n SendResetPasswordEmailRequest,\n ExchangeResetPasswordTokenRequest,\n VerifyEmailRequest,\n VerifyEmailResponse,\n UserSchema,\n GetProfileResponse,\n} from '@insforge/shared-schemas';\n\n/**\n * Check if current environment is a hosted auth environment\n * Returns true for:\n * - localhost with port 7130 (hosted auth app dev)\n * - https://*.insforge.app (hosted auth app production)\n */\nfunction isHostedAuthEnvironment(): boolean {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const { hostname, port, protocol } = window.location;\n\n // Check for localhost:7130\n if (hostname === 'localhost' && port === '7130') {\n return true;\n }\n\n // Check for https://*.insforge.app\n if (protocol === 'https:' && hostname.endsWith('.insforge.app')) {\n return true;\n }\n\n return false;\n}\n\nexport class Auth {\n constructor(\n private http: HttpClient,\n private tokenManager: TokenManager\n ) {\n // Auto-detect OAuth callback parameters in the URL\n this.detectAuthCallback();\n }\n\n /**\n * Automatically detect and handle OAuth callback parameters in the URL\n * This runs after initialization to seamlessly complete the OAuth flow\n * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)\n */\n private detectAuthCallback(): void {\n // Only run in browser environment\n if (typeof window === 'undefined') return;\n\n try {\n const params = new URLSearchParams(window.location.search);\n // Backend returns: access_token, user_id, email, name (optional), csrf_token\n const accessToken = params.get('access_token');\n const userId = params.get('user_id');\n const email = params.get('email');\n const name = params.get('name');\n const csrfToken = params.get('csrf_token');\n\n // Check if we have OAuth callback parameters\n if (accessToken && userId && email) {\n if (csrfToken) {\n this.tokenManager.setMemoryMode();\n setCsrfToken(csrfToken);\n }\n // TODO: Use PKCE in future\n // Create session with the data from backend\n const session: AuthSession = {\n accessToken,\n user: {\n id: userId,\n email: email,\n profile: { name: name || '' },\n metadata: null,\n // These fields are not provided by backend OAuth callback\n // They'll be populated when calling getCurrentUser()\n emailVerified: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n },\n };\n\n // Save session and set auth token\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(accessToken);\n\n // Clean up the URL to remove sensitive parameters\n const url = new URL(window.location.href);\n url.searchParams.delete('access_token');\n url.searchParams.delete('user_id');\n url.searchParams.delete('email');\n url.searchParams.delete('name');\n url.searchParams.delete('csrf_token');\n\n // Also handle error case from backend (line 581)\n if (params.has('error')) {\n url.searchParams.delete('error');\n }\n\n // Replace URL without adding to browser history\n window.history.replaceState({}, document.title, url.toString());\n }\n } catch (error) {\n // Silently continue - don't break initialization\n console.debug('OAuth callback detection skipped:', error);\n }\n }\n\n /**\n * Sign up a new user\n */\n async signUp(request: CreateUserRequest): Promise<{\n data: CreateUserResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateUserResponse>('/api/auth/users', request);\n\n // Save session internally only if both accessToken and user exist\n if (response.accessToken && response.user && !isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n error instanceof Error ? error.message : 'An unexpected error occurred during sign up',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with email and password\n */\n async signInWithPassword(request: CreateSessionRequest): Promise<{\n data: CreateSessionResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateSessionResponse>('/api/auth/sessions', request);\n\n if (!isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred during sign in',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with OAuth provider\n */\n async signInWithOAuth(options: {\n provider: OAuthProvidersSchema;\n redirectTo?: string;\n skipBrowserRedirect?: boolean;\n }): Promise<{\n data: { url?: string; provider?: string };\n error: InsForgeError | null;\n }> {\n try {\n const { provider, redirectTo, skipBrowserRedirect } = options;\n\n const params = redirectTo\n ? { redirect_uri: redirectTo }\n : undefined;\n\n const endpoint = `/api/auth/oauth/${provider}`;\n const response = await this.http.get<GetOauthUrlResponse>(endpoint, { params });\n\n // Automatically redirect in browser unless told not to\n if (typeof window !== 'undefined' && !skipBrowserRedirect) {\n window.location.href = response.authUrl;\n return { data: {}, error: null };\n }\n\n return {\n data: {\n url: response.authUrl,\n provider\n },\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: {}, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: {},\n error: new InsForgeError(\n 'An unexpected error occurred during OAuth initialization',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign out the current user\n */\n async signOut(): Promise<{ error: InsForgeError | null }> {\n try {\n // Try to call backend logout to clear httpOnly refresh cookie\n // This may fail for legacy backends, but that's ok\n try {\n await this.http.post('/api/auth/logout', undefined, { credentials: 'include' });\n } catch {\n // Ignore errors - legacy backend may not have this endpoint\n }\n\n // Clear local session and cookies\n this.tokenManager.clearSession();\n this.http.setAuthToken(null);\n clearCsrfToken();\n\n return { error: null };\n } catch (error) {\n return {\n error: new InsForgeError(\n 'Failed to sign out',\n 500,\n 'SIGNOUT_ERROR'\n )\n };\n }\n }\n\n\n /**\n * Get all public authentication configuration (OAuth + Email)\n * Returns both OAuth providers and email authentication settings in one request\n * This is a public endpoint that doesn't require authentication\n * \n * @returns Complete public authentication configuration including OAuth providers and email auth settings\n * \n * @example\n * ```ts\n * const { data, error } = await insforge.auth.getPublicAuthConfig();\n * if (data) {\n * console.log(`OAuth providers: ${data.oauth.data.length}`);\n * console.log(`Password min length: ${data.email.passwordMinLength}`);\n * }\n * ```\n */\n async getPublicAuthConfig(): Promise<{\n data: GetPublicAuthConfigResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.get<GetPublicAuthConfigResponse>('/api/auth/public-config');\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching public authentication configuration',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n\n /**\n * Get the current user with full profile information\n * Returns both auth info (id, email, role) and profile data (dynamic fields from users table)\n */\n async getCurrentUser(): Promise<{\n data: {\n user: UserSchema;\n } | null;\n error: any | null;\n }> {\n try {\n // Check if we have a stored user\n const user = this.tokenManager.getUser();\n\n if (user) {\n return { data: { user }, error: null };\n }\n const accessToken = this.tokenManager.getAccessToken();\n if (!accessToken) {\n return { data: null, error: null };\n }\n\n // Call the API for auth info\n this.http.setAuthToken(accessToken);\n const authResponse = await this.http.get<GetCurrentSessionResponse>('/api/auth/sessions/current');\n\n return {\n data: {\n user: authResponse.user,\n },\n error: null\n };\n } catch (error) {\n // If unauthorized, clear session\n if (error instanceof InsForgeError && error.statusCode === 401) {\n await this.signOut();\n return { data: null, error: null };\n }\n\n // Pass through all other errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching user',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get any user's profile by ID\n * Returns profile information from the users table\n */\n async getProfile(userId: string): Promise<{\n data: GetProfileResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.get<GetProfileResponse>(`/api/auth/profiles/${userId}`);\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged (includes 404 NOT_FOUND, 400 INVALID_INPUT)\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while fetching user profile',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get the current session (only session data, no API call)\n * Returns the stored JWT token and basic user info from local storage\n */\n async getCurrentSession(): Promise<{\n data: { session: AuthSession | null };\n error: InsForgeError | null;\n }> {\n try {\n // Step 1: Check if we already have session in memory\n const session = this.tokenManager.getSession();\n if (session) {\n this.http.setAuthToken(session.accessToken);\n return { data: { session }, error: null };\n }\n\n // Step 2: In browser, try to refresh using httpOnly cookie\n if (typeof window !== 'undefined') {\n try {\n const csrfToken = getCsrfToken();\n const response = await this.http.post<{\n accessToken: string;\n user?: UserSchema;\n csrfToken?: string\n }>(\n '/api/auth/refresh',\n undefined,\n {\n headers: csrfToken ? { 'X-CSRF-Token': csrfToken } : {},\n credentials: 'include',\n }\n );\n\n if (response.accessToken) {\n this.tokenManager.setMemoryMode();\n this.tokenManager.setAccessToken(response.accessToken);\n this.http.setAuthToken(response.accessToken);\n\n if (response.user) {\n this.tokenManager.setUser(response.user);\n }\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n\n return {\n data: { session: this.tokenManager.getSession() },\n error: null\n };\n }\n } catch (error) {\n if (error instanceof InsForgeError) {\n if (error.statusCode === 404) {\n // Legacy backend - try localStorage\n this.tokenManager.setStorageMode();\n const session = this.tokenManager.getSession();\n if (session) {\n return { data: { session }, error: null };\n }\n return { data: { session: null }, error: null };\n }\n // 401/403 or other errors - not logged in\n return { data: { session: null }, error: error };\n }\n }\n }\n\n // Not logged in\n return { data: { session: null }, error: null };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: { session: null }, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: { session: null },\n error: new InsForgeError(\n 'An unexpected error occurred while getting session',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Set/Update the current user's profile\n * Updates profile information in the users table (supports any dynamic fields)\n * Requires authentication\n */\n async setProfile(profile: Record<string, unknown>): Promise<{\n data: GetProfileResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.patch<GetProfileResponse>(\n '/api/auth/profiles/current',\n { profile }\n );\n\n // Update the local session/user with the new profile data\n const currentUser = this.tokenManager.getUser();\n if (currentUser && response.profile !== undefined) {\n this.tokenManager.setUser({\n ...currentUser,\n profile: response.profile,\n });\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged (includes 401 AUTH_INVALID_CREDENTIALS, 400 INVALID_INPUT)\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while updating user profile',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Send email verification (code or link based on config)\n *\n * Send email verification using the method configured in auth settings (verifyEmailMethod).\n * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.\n * Prevents user enumeration by returning success even if email doesn't exist.\n */\n async sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{\n data: { success: boolean; message: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ success: boolean; message: string }>(\n '/api/auth/email/send-verification',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while sending verification code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Send password reset (code or link based on config)\n *\n * Send password reset email using the method configured in auth settings (resetPasswordMethod).\n * When method is 'code', sends a 6-digit numeric code for two-step flow.\n * When method is 'link', sends a magic link.\n * Prevents user enumeration by returning success even if email doesn't exist.\n */\n async sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{\n data: { success: boolean; message: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ success: boolean; message: string }>(\n '/api/auth/email/send-reset-password',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while sending password reset code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Exchange reset password code for reset token\n *\n * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):\n * 1. Verify the 6-digit code sent to user's email\n * 2. Return a reset token that can be used to actually reset the password\n *\n * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).\n */\n async exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{\n data: { token: string; expiresAt: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ token: string; expiresAt: string }>(\n '/api/auth/email/exchange-reset-password-token',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while verifying reset code',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Reset password with token\n *\n * Reset user password with a token. The token can be:\n * - Magic link token (64-character hex token from send-reset-password when method is 'link')\n * - Reset token (from exchange-reset-password-token after code verification when method is 'code')\n *\n * Both token types use RESET_PASSWORD purpose and are verified the same way.\n *\n * Flow summary:\n * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)\n * - Link method: send-reset-password → reset-password (with link token directly)\n */\n async resetPassword(request: { newPassword: string; otp: string }): Promise<{\n data: { message: string; redirectTo?: string } | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<{ message: string; redirectTo?: string }>(\n '/api/auth/email/reset-password',\n request\n );\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while resetting password',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Verify email with code or link\n *\n * Verify email address using the method configured in auth settings (verifyEmailMethod):\n * - Code verification: Provide both `email` and `otp` (6-digit numeric code)\n * - Link verification: Provide only `otp` (64-character hex token from magic link)\n *\n * Successfully verified users will receive a session token.\n *\n * The email verification link sent to users always points to the backend API endpoint.\n * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.\n * Otherwise, a default success page is displayed.\n */\n async verifyEmail(request: VerifyEmailRequest): Promise<{\n data: VerifyEmailResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<VerifyEmailResponse>(\n '/api/auth/email/verify',\n request\n );\n\n // Save session if we got a token\n if (!isHostedAuthEnvironment()) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n if (response.csrfToken) {\n setCsrfToken(response.csrfToken);\n }\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n\n // Generic fallback for unexpected errors\n return {\n data: null,\n error: new InsForgeError(\n 'An unexpected error occurred while verifying email',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n}","/**\n * Database module using @supabase/postgrest-js\n * Complete replacement for custom QueryBuilder with full PostgREST features\n */\n\nimport { PostgrestClient } from '@supabase/postgrest-js';\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\n\n\n/**\n * Custom fetch that transforms URLs and adds auth\n */\nfunction createInsForgePostgrestFetch(\n httpClient: HttpClient,\n tokenManager: TokenManager\n): typeof fetch {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const url = typeof input === 'string' ? input : input.toString();\n const urlObj = new URL(url);\n \n // Extract table name from pathname\n // postgrest-js sends: http://dummy/tablename?params\n // We need: http://localhost:7130/api/database/records/tablename?params\n const tableName = urlObj.pathname.slice(1); // Remove leading /\n \n // Build InsForge URL\n const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;\n \n // Get auth token from TokenManager or HttpClient\n const token = tokenManager.getAccessToken();\n const httpHeaders = httpClient.getHeaders();\n const authToken = token || httpHeaders['Authorization']?.replace('Bearer ', '');\n \n // Prepare headers\n const headers = new Headers(init?.headers);\n if (authToken && !headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${authToken}`);\n }\n \n // Make the actual request using native fetch\n const response = await fetch(insforgeUrl, {\n ...init,\n headers\n });\n \n return response;\n };\n}\n\n/**\n * Database client using postgrest-js\n * Drop-in replacement with FULL PostgREST capabilities\n */\nexport class Database {\n private postgrest: PostgrestClient<any, any, any>;\n \n constructor(httpClient: HttpClient, tokenManager: TokenManager) {\n // Create postgrest client with custom fetch\n this.postgrest = new PostgrestClient<any, any, any>('http://dummy', {\n fetch: createInsForgePostgrestFetch(httpClient, tokenManager),\n headers: {}\n });\n }\n \n /**\n * Create a query builder for a table\n * \n * @example\n * // Basic query\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId);\n * \n * // With count (Supabase style!)\n * const { data, error, count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact' })\n * .range(0, 9);\n * \n * // Just get count, no data\n * const { count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact', head: true });\n * \n * // Complex queries with OR\n * const { data } = await client.database\n * .from('posts')\n * .select('*, users!inner(*)')\n * .or('status.eq.active,status.eq.pending');\n * \n * // All features work:\n * - Nested selects\n * - Foreign key expansion \n * - OR/AND/NOT conditions\n * - Count with head\n * - Range pagination\n * - Upserts\n */\n from(table: string) {\n // Return postgrest query builder with all features\n return this.postgrest.from(table);\n }\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n}\n\ninterface UploadStrategy {\n method: 'direct' | 'presigned';\n uploadUrl: string;\n fields?: Record<string, string>;\n key: string;\n confirmRequired: boolean;\n confirmUrl?: string;\n expiresAt?: Date;\n}\n\ninterface DownloadStrategy {\n method: 'direct' | 'presigned';\n url: string;\n expiresAt?: Date;\n}\n\n/**\n * Storage bucket operations\n */\nexport class StorageBucket {\n constructor(\n private bucketName: string,\n private http: HttpClient\n ) {}\n\n /**\n * Upload a file with a specific key\n * Uses the upload strategy from backend (direct or presigned)\n * @param path - The object key/path\n * @param file - File or Blob to upload\n */\n async upload(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'PUT',\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * Uses the upload strategy from backend (direct or presigned)\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const filename = file instanceof File ? file.name : 'file';\n \n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'POST',\n `/api/storage/buckets/${this.bucketName}/objects`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Internal method to handle presigned URL uploads\n */\n private async uploadWithPresignedUrl(\n strategy: UploadStrategy,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Upload to presigned URL (e.g., S3)\n const formData = new FormData();\n \n // Add all fields from the presigned URL\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be the last field for S3\n formData.append('file', file);\n\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n throw new InsForgeError(\n `Upload to storage failed: ${uploadResponse.statusText}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Confirm upload with backend if required\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n }\n );\n\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, return basic file info\n return {\n data: {\n key: strategy.key,\n bucket: this.bucketName,\n size: file.size,\n mimeType: file.type || 'application/octet-stream',\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n } as StorageFileSchema,\n error: null\n };\n } catch (error) {\n throw error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n );\n }\n }\n\n /**\n * Download a file\n * Uses the download strategy from backend (direct or presigned)\n * @param path - The object key/path\n * Returns the file as a Blob\n */\n async download(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n // Get download strategy from backend - this is required\n const strategyResponse = await this.http.post<DownloadStrategy>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n { expiresIn: 3600 }\n );\n\n // Use URL from strategy\n const downloadUrl = strategyResponse.url;\n \n // Download from the URL\n const headers: HeadersInit = {};\n \n // Only add auth header for direct downloads (not presigned URLs)\n if (strategyResponse.method === 'direct') {\n Object.assign(headers, this.http.getHeaders());\n }\n \n const response = await fetch(downloadUrl, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n try {\n const error = await response.json();\n throw InsForgeError.fromApiError(error);\n } catch {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\n );\n }\n }\n\n const blob = await response.blob();\n return { data: blob, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Get public URL for a file\n * @param path - The object key/path\n */\n getPublicUrl(path: string): string {\n return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n }\n\n /**\n * List objects in the bucket\n * @param prefix - Filter by key prefix\n * @param search - Search in file names\n * @param limit - Maximum number of results (default: 100, max: 1000)\n * @param offset - Number of results to skip\n */\n async list(options?: {\n prefix?: string;\n search?: string;\n limit?: number;\n offset?: number;\n }): Promise<StorageResponse<ListObjectsResponseSchema>> {\n try {\n const params: Record<string, string> = {};\n \n if (options?.prefix) params.prefix = options.prefix;\n if (options?.search) params.search = options.search;\n if (options?.limit) params.limit = options.limit.toString();\n if (options?.offset) params.offset = options.offset.toString();\n\n const response = await this.http.get<ListObjectsResponseSchema>(\n `/api/storage/buckets/${this.bucketName}/objects`,\n { params }\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'List failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Delete a file\n * @param path - The object key/path\n */\n async remove(path: string): Promise<StorageResponse<{ message: string }>> {\n try {\n const response = await this.http.delete<{ message: string }>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Delete failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n}\n\n/**\n * Storage module for file operations\n */\nexport class Storage {\n constructor(private http: HttpClient) {}\n\n /**\n * Get a bucket instance for operations\n * @param bucketName - Name of the bucket\n */\n from(bucketName: string): StorageBucket {\n return new StorageBucket(bucketName, this.http);\n }\n}","/**\n * AI Module for Insforge SDK\n * Response format roughly matches OpenAI SDK for compatibility\n *\n * The backend handles all the complexity of different AI providers\n * and returns a unified format. This SDK transforms responses to match OpenAI-like format.\n */\n\nimport { HttpClient } from \"../lib/http-client\";\nimport {\n ChatCompletionRequest,\n ChatCompletionResponse,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@insforge/shared-schemas\";\n\nexport class AI {\n public readonly chat: Chat;\n public readonly images: Images;\n\n constructor(private http: HttpClient) {\n this.chat = new Chat(http);\n this.images = new Images(http);\n }\n}\n\nclass Chat {\n public readonly completions: ChatCompletions;\n\n constructor(http: HttpClient) {\n this.completions = new ChatCompletions(http);\n }\n}\n\nclass ChatCompletions {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a chat completion - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const completion = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Hello!' }]\n * });\n * console.log(completion.choices[0].message.content);\n *\n * // With images\n * const response = await client.ai.chat.completions.create({\n * model: 'gpt-4-vision',\n * messages: [{\n * role: 'user',\n * content: 'What is in this image?',\n * images: [{ url: 'https://example.com/image.jpg' }]\n * }]\n * });\n *\n * // Streaming - returns async iterable\n * const stream = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * stream: true\n * });\n *\n * for await (const chunk of stream) {\n * if (chunk.choices[0]?.delta?.content) {\n * process.stdout.write(chunk.choices[0].delta.content);\n * }\n * }\n * ```\n */\n async create(params: ChatCompletionRequest): Promise<any> {\n // Backend already expects camelCase, no transformation needed\n const backendParams = {\n model: params.model,\n messages: params.messages,\n temperature: params.temperature,\n maxTokens: params.maxTokens,\n topP: params.topP,\n stream: params.stream,\n };\n\n // For streaming, return an async iterable that yields OpenAI-like chunks\n if (params.stream) {\n const headers = this.http.getHeaders();\n headers[\"Content-Type\"] = \"application/json\";\n\n const response = await this.http.fetch(\n `${this.http.baseUrl}/api/ai/chat/completion`,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(backendParams),\n }\n );\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(error.error || \"Stream request failed\");\n }\n\n // Return async iterable that parses SSE and transforms to OpenAI-like format\n return this.parseSSEStream(response, params.model);\n }\n\n // Non-streaming: transform response to OpenAI-like format\n const response: ChatCompletionResponse = await this.http.post(\n \"/api/ai/chat/completion\",\n backendParams\n );\n\n // Transform to OpenAI-like format\n const content = response.text || \"\";\n\n return {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: response.metadata?.model,\n choices: [\n {\n index: 0,\n message: {\n role: \"assistant\",\n content,\n },\n finish_reason: \"stop\",\n },\n ],\n usage: response.metadata?.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n },\n };\n }\n\n /**\n * Parse SSE stream into async iterable of OpenAI-like chunks\n */\n private async *parseSSEStream(\n response: Response,\n model: string\n ): AsyncIterableIterator<any> {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() || \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const dataStr = line.slice(6).trim();\n if (dataStr) {\n try {\n const data = JSON.parse(dataStr);\n\n // Transform to OpenAI-like streaming format\n if (data.chunk || data.content) {\n yield {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [\n {\n index: 0,\n delta: {\n content: data.chunk || data.content,\n },\n finish_reason: data.done ? \"stop\" : null,\n },\n ],\n };\n }\n\n // If we received the done signal, we can stop\n if (data.done) {\n reader.releaseLock();\n return;\n }\n } catch (e) {\n // Skip invalid JSON\n console.warn(\"Failed to parse SSE data:\", dataStr);\n }\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nclass Images {\n constructor(private http: HttpClient) {}\n\n /**\n * Generate images - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Text-to-image\n * const response = await client.ai.images.generate({\n * model: 'dall-e-3',\n * prompt: 'A sunset over mountains',\n * });\n * console.log(response.images[0].url);\n *\n * // Image-to-image (with input images)\n * const response = await client.ai.images.generate({\n * model: 'stable-diffusion-xl',\n * prompt: 'Transform this into a watercolor painting',\n * images: [\n * { url: 'https://example.com/input.jpg' },\n * // or base64-encoded Data URI:\n * { url: 'data:image/jpeg;base64,/9j/4AAQ...' }\n * ]\n * });\n * ```\n */\n async generate(params: ImageGenerationRequest): Promise<any> {\n const response: ImageGenerationResponse = await this.http.post(\n \"/api/ai/image/generation\",\n params\n );\n \n // Build data array based on response content\n let data: Array<{ b64_json?: string; content?: string }> = [];\n \n if (response.images && response.images.length > 0) {\n // Has images - extract base64 and include text\n data = response.images.map(img => ({\n b64_json: img.imageUrl.replace(/^data:image\\/\\w+;base64,/, ''),\n content: response.text\n }));\n } else if (response.text) {\n // Text-only response\n data = [{ content: response.text }];\n }\n \n // Return OpenAI-compatible format\n return {\n created: Math.floor(Date.now() / 1000),\n data,\n ...(response.metadata?.usage && {\n usage: {\n total_tokens: response.metadata.usage.totalTokens || 0,\n input_tokens: response.metadata.usage.promptTokens || 0,\n output_tokens: response.metadata.usage.completionTokens || 0,\n }\n })\n };\n }\n}\n","import { HttpClient } from '../lib/http-client';\n\nexport interface FunctionInvokeOptions {\n /**\n * The body of the request\n */\n body?: any;\n \n /**\n * Custom headers to send with the request\n */\n headers?: Record<string, string>;\n \n /**\n * HTTP method (default: POST)\n */\n method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n}\n\n/**\n * Edge Functions client for invoking serverless functions\n * \n * @example\n * ```typescript\n * // Invoke a function with JSON body\n * const { data, error } = await client.functions.invoke('hello-world', {\n * body: { name: 'World' }\n * });\n * \n * // GET request\n * const { data, error } = await client.functions.invoke('get-data', {\n * method: 'GET'\n * });\n * ```\n */\nexport class Functions {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Invokes an Edge Function\n * @param slug The function slug to invoke\n * @param options Request options\n */\n async invoke<T = any>(\n slug: string,\n options: FunctionInvokeOptions = {}\n ): Promise<{ data: T | null; error: Error | null }> {\n try {\n const { method = 'POST', body, headers = {} } = options;\n \n // Simple path: /functions/{slug}\n const path = `/functions/${slug}`;\n \n // Use the HTTP client's request method\n const data = await this.http.request<T>(\n method,\n path,\n { body, headers }\n );\n \n return { data, error: null };\n } catch (error: any) {\n // The HTTP client throws InsForgeError with all properties from the response\n // including error, message, details, statusCode, etc.\n // We need to preserve all of that information\n return { \n data: null, \n error: error // Pass through the full error object with all properties\n };\n }\n }\n}","import { io, Socket } from 'socket.io-client';\nimport type { SubscribeResponse, RealtimeErrorPayload, SocketMessage } from '@insforge/shared-schemas';\nimport { TokenManager } from '../lib/token-manager';\n\nexport type { SubscribeResponse, RealtimeErrorPayload, SocketMessage };\n\nexport type ConnectionState = 'disconnected' | 'connecting' | 'connected';\n\nexport type EventCallback<T = unknown> = (payload: T) => void;\n\nconst CONNECT_TIMEOUT = 10000;\n\n/**\n * Realtime module for subscribing to channels and handling real-time events\n *\n * @example\n * ```typescript\n * const { realtime } = client;\n *\n * // Connect to the realtime server\n * await realtime.connect();\n *\n * // Subscribe to a channel\n * const response = await realtime.subscribe('orders:123');\n * if (!response.ok) {\n * console.error('Failed to subscribe:', response.error);\n * }\n *\n * // Listen for specific events\n * realtime.on('order_updated', (payload) => {\n * console.log('Order updated:', payload);\n * });\n *\n * // Listen for connection events\n * realtime.on('connect', () => console.log('Connected!'));\n * realtime.on('connect_error', (err) => console.error('Connection failed:', err));\n * realtime.on('disconnect', (reason) => console.log('Disconnected:', reason));\n * realtime.on('error', (error) => console.error('Realtime error:', error));\n *\n * // Publish a message to a channel\n * await realtime.publish('orders:123', 'status_changed', { status: 'shipped' });\n *\n * // Unsubscribe and disconnect when done\n * realtime.unsubscribe('orders:123');\n * realtime.disconnect();\n * ```\n */\nexport class Realtime {\n private baseUrl: string;\n private tokenManager: TokenManager;\n private socket: Socket | null = null;\n private connectPromise: Promise<void> | null = null;\n private subscribedChannels: Set<string> = new Set();\n private eventListeners: Map<string, Set<EventCallback>> = new Map();\n private anonKey?: string;\n\n constructor(baseUrl: string, tokenManager: TokenManager, anonKey?: string) {\n this.baseUrl = baseUrl;\n this.tokenManager = tokenManager;\n this.anonKey = anonKey;\n\n // Handle token changes (e.g., after refresh)\n this.tokenManager.onTokenChange = () => this.onTokenChange();\n }\n\n private notifyListeners(event: string, payload?: unknown): void {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n for (const cb of listeners) {\n try {\n cb(payload);\n } catch (err) {\n console.error(`Error in ${event} callback:`, err);\n }\n }\n }\n\n /**\n * Connect to the realtime server\n * @returns Promise that resolves when connected\n */\n connect(): Promise<void> {\n // Already connected\n if (this.socket?.connected) {\n return Promise.resolve();\n }\n\n // Connection already in progress, return existing promise\n if (this.connectPromise) {\n return this.connectPromise;\n }\n\n this.connectPromise = new Promise((resolve, reject) => {\n const session = this.tokenManager.getSession();\n const token = session?.accessToken ?? this.anonKey;\n \n\n this.socket = io(this.baseUrl, {\n transports: ['websocket'],\n auth: token ? { token } : undefined,\n });\n\n let initialConnection = true;\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n const cleanup = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n timeoutId = setTimeout(() => {\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n this.socket?.disconnect();\n this.socket = null;\n reject(new Error(`Connection timeout after ${CONNECT_TIMEOUT}ms`));\n }\n }, CONNECT_TIMEOUT);\n\n this.socket.on('connect', () => {\n cleanup();\n // Re-subscribe to channels on every connect (initial + reconnects)\n for (const channel of this.subscribedChannels) {\n this.socket!.emit('realtime:subscribe', { channel });\n }\n this.notifyListeners('connect');\n\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n resolve();\n }\n });\n\n this.socket.on('connect_error', (error: Error) => {\n cleanup();\n this.notifyListeners('connect_error', error);\n\n if (initialConnection) {\n initialConnection = false;\n this.connectPromise = null;\n reject(error);\n }\n });\n\n this.socket.on('disconnect', (reason: string) => {\n this.notifyListeners('disconnect', reason);\n });\n\n this.socket.on('realtime:error', (error: RealtimeErrorPayload) => {\n this.notifyListeners('error', error);\n });\n\n // Route custom events to listeners (onAny doesn't catch socket reserved events)\n this.socket.onAny((event: string, message: SocketMessage) => {\n if (event === 'realtime:error') return; // Already handled above\n this.notifyListeners(event, message);\n });\n });\n\n return this.connectPromise;\n }\n\n /**\n * Disconnect from the realtime server\n */\n disconnect(): void {\n if (this.socket) {\n this.socket.disconnect();\n this.socket = null;\n }\n this.subscribedChannels.clear();\n }\n\n /**\n * Handle token changes (e.g., after auth refresh)\n * Updates socket auth so reconnects use the new token\n * If connected, triggers reconnect to apply new token immediately\n */\n private onTokenChange(): void {\n const token = this.tokenManager.getAccessToken() ?? this.anonKey;\n\n // Always update auth so socket.io auto-reconnect uses new token\n if (this.socket) {\n this.socket.auth = token ? { token } : {};\n }\n\n // Trigger reconnect if connected OR connecting (to avoid completing with stale token)\n if (this.socket && (this.socket.connected || this.connectPromise)) {\n this.socket.disconnect();\n this.socket.connect();\n // Note: on('connect') handler automatically re-subscribes to channels\n }\n }\n\n /**\n * Check if connected to the realtime server\n */\n get isConnected(): boolean {\n return this.socket?.connected ?? false;\n }\n\n /**\n * Get the current connection state\n */\n get connectionState(): ConnectionState {\n if (!this.socket) return 'disconnected';\n if (this.socket.connected) return 'connected';\n return 'connecting';\n }\n\n /**\n * Get the socket ID (if connected)\n */\n get socketId(): string | undefined {\n return this.socket?.id;\n }\n\n /**\n * Subscribe to a channel\n *\n * Automatically connects if not already connected.\n *\n * @param channel - Channel name (e.g., 'orders:123', 'broadcast')\n * @returns Promise with the subscription response\n */\n async subscribe(channel: string): Promise<SubscribeResponse> {\n // Already subscribed, return success\n if (this.subscribedChannels.has(channel)) {\n return { ok: true, channel };\n }\n\n // Auto-connect if not connected\n if (!this.socket?.connected) {\n try {\n await this.connect();\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Connection failed';\n return { ok: false, channel, error: { code: 'CONNECTION_FAILED', message } };\n }\n }\n\n return new Promise((resolve) => {\n this.socket!.emit('realtime:subscribe', { channel }, (response: SubscribeResponse) => {\n if (response.ok) {\n this.subscribedChannels.add(channel);\n }\n resolve(response);\n });\n });\n }\n\n /**\n * Unsubscribe from a channel (fire-and-forget)\n *\n * @param channel - Channel name to unsubscribe from\n */\n unsubscribe(channel: string): void {\n this.subscribedChannels.delete(channel);\n\n if (this.socket?.connected) {\n this.socket.emit('realtime:unsubscribe', { channel });\n }\n }\n\n /**\n * Publish a message to a channel\n *\n * @param channel - Channel name\n * @param event - Event name\n * @param payload - Message payload\n */\n async publish<T = unknown>(channel: string, event: string, payload: T): Promise<void> {\n if (!this.socket?.connected) {\n throw new Error('Not connected to realtime server. Call connect() first.');\n }\n\n this.socket!.emit('realtime:publish', { channel, event, payload });\n }\n\n /**\n * Listen for events\n *\n * Reserved event names:\n * - 'connect' - Fired when connected to the server\n * - 'connect_error' - Fired when connection fails (payload: Error)\n * - 'disconnect' - Fired when disconnected (payload: reason string)\n * - 'error' - Fired when a realtime error occurs (payload: RealtimeErrorPayload)\n *\n * All other events receive a `SocketMessage` payload with metadata.\n *\n * @param event - Event name to listen for\n * @param callback - Callback function when event is received\n */\n on<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n if (!this.eventListeners.has(event)) {\n this.eventListeners.set(event, new Set());\n }\n this.eventListeners.get(event)!.add(callback as EventCallback);\n }\n\n /**\n * Remove a listener for a specific event\n *\n * @param event - Event name\n * @param callback - The callback function to remove\n */\n off<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n const listeners = this.eventListeners.get(event);\n if (listeners) {\n listeners.delete(callback as EventCallback);\n if (listeners.size === 0) {\n this.eventListeners.delete(event);\n }\n }\n }\n\n /**\n * Listen for an event only once, then automatically remove the listener\n *\n * @param event - Event name to listen for\n * @param callback - Callback function when event is received\n */\n once<T = SocketMessage>(event: string, callback: EventCallback<T>): void {\n const wrapper: EventCallback<T> = (payload: T) => {\n this.off(event, wrapper);\n callback(payload);\n };\n this.on(event, wrapper);\n }\n\n /**\n * Get all currently subscribed channels\n *\n * @returns Array of channel names\n */\n getSubscribedChannels(): string[] {\n return Array.from(this.subscribedChannels);\n }\n}\n","import { HttpClient } from '../lib/http-client';\nimport type { SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';\n\nexport type { SendRawEmailRequest as SendEmailOptions, SendEmailResponse } from '@insforge/shared-schemas';\n\n/**\n * Emails client for sending custom emails\n *\n * @example\n * ```typescript\n * // Send a simple email\n * const { data, error } = await client.emails.send({\n * to: 'user@example.com',\n * subject: 'Welcome!',\n * html: '<h1>Welcome to our platform</h1>'\n * });\n *\n * if (error) {\n * console.error('Failed to send:', error.message);\n * return;\n * }\n * // Email sent successfully - data is {} (empty object)\n *\n * // Send to multiple recipients with CC\n * const { data, error } = await client.emails.send({\n * to: ['user1@example.com', 'user2@example.com'],\n * cc: 'manager@example.com',\n * subject: 'Team Update',\n * html: '<p>Here is the latest update...</p>',\n * replyTo: 'support@example.com'\n * });\n * ```\n */\nexport class Emails {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Send a custom HTML email\n * @param options Email options including recipients, subject, and HTML content\n */\n async send(\n options: SendRawEmailRequest\n ): Promise<{ data: SendEmailResponse | null; error: Error | null }> {\n try {\n const data = await this.http.post<SendEmailResponse>(\n '/api/email/send-raw',\n options\n );\n\n return { data, error: null };\n } catch (error: unknown) {\n const normalizedError = error instanceof Error ? error : new Error(String(error));\n return { data: null, error: normalizedError };\n }\n }\n}\n","import { InsForgeConfig } from './types';\nimport { HttpClient } from './lib/http-client';\nimport { TokenManager } from './lib/token-manager';\nimport { Auth } from './modules/auth';\nimport { Database } from './modules/database-postgrest';\nimport { Storage } from './modules/storage';\nimport { AI } from './modules/ai';\nimport { Functions } from './modules/functions';\nimport { Realtime } from './modules/realtime';\nimport { Emails } from './modules/email';\n\n/**\n * Main InsForge SDK Client\n * \n * @example\n * ```typescript\n * import { InsForgeClient } from '@insforge/sdk';\n * \n * const client = new InsForgeClient({\n * baseUrl: 'http://localhost:7130'\n * });\n * \n * // Authentication\n * const { data, error } = await client.auth.signUp({\n * email: 'user@example.com',\n * password: 'password123',\n * name: 'John Doe'\n * });\n * \n * // Database operations\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', session.user.id)\n * .order('created_at', { ascending: false })\n * .limit(10);\n * \n * // Insert data\n * const { data: newPost } = await client.database\n * .from('posts')\n * .insert({ title: 'Hello', content: 'World' })\n * .single();\n * \n * // Invoke edge functions\n * const { data, error } = await client.functions.invoke('my-function', {\n * body: { message: 'Hello from SDK' }\n * });\n * ```\n */\nexport class InsForgeClient {\n private http: HttpClient;\n private tokenManager: TokenManager;\n public readonly auth: Auth;\n public readonly database: Database;\n public readonly storage: Storage;\n public readonly ai: AI;\n public readonly functions: Functions;\n public readonly realtime: Realtime;\n public readonly emails: Emails;\n\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n\n // Check for edge function token\n if (config.edgeFunctionToken) {\n this.http.setAuthToken(config.edgeFunctionToken);\n // Save to token manager so getCurrentUser() works\n this.tokenManager.saveSession({\n accessToken: config.edgeFunctionToken,\n user: {} as any, // Will be populated by getCurrentUser()\n });\n }\n\n // Check for existing session\n // In secure mode: try to refresh to get access token\n // In local mode: check localStorage\n const existingSession = this.tokenManager.getSession();\n if (existingSession?.accessToken) {\n this.http.setAuthToken(existingSession.accessToken);\n }\n\n this.auth = new Auth(this.http, this.tokenManager);\n this.database = new Database(this.http, this.tokenManager);\n this.storage = new Storage(this.http);\n this.ai = new AI(this.http);\n this.functions = new Functions(this.http);\n this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);\n this.emails = new Emails(this.http);\n }\n\n /**\n * Get the underlying HTTP client for custom requests\n * \n * @example\n * ```typescript\n * const httpClient = client.getHttpClient();\n * const customData = await httpClient.get('/api/custom-endpoint');\n * ```\n */\n getHttpClient(): HttpClient {\n return this.http;\n }\n\n /**\n * Future modules will be added here:\n * - database: Database operations\n * - storage: File storage operations\n * - functions: Serverless functions\n * - tables: Table management\n * - metadata: Backend metadata\n */\n}\n","/**\n * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service\n * \n * @packageDocumentation\n */\n\n// Main client\nexport { InsForgeClient } from './client';\n\n// Types\nexport type {\n InsForgeConfig,\n InsForgeConfig as ClientOptions, // Alias for compatibility\n TokenStorage,\n AuthSession,\n ApiError,\n} from './types';\n\nexport { InsForgeError } from './types';\n\n// Re-export shared schemas that SDK users will need\nexport type {\n UserSchema,\n CreateUserRequest,\n CreateSessionRequest,\n AuthErrorResponse,\n} from '@insforge/shared-schemas';\n\n// Re-export auth module for advanced usage\nexport { Auth } from './modules/auth';\n\n// Re-export database module (using postgrest-js)\nexport { Database } from './modules/database-postgrest';\n// Note: QueryBuilder is no longer exported as we use postgrest-js QueryBuilder internally\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\n\n// Re-export AI module\nexport { AI } from './modules/ai';\n\n// Re-export Functions module\nexport { Functions } from './modules/functions';\nexport type { FunctionInvokeOptions } from './modules/functions';\n\n// Re-export Emails module (Resend-compatible API)\nexport { Emails } from './modules/email';\nexport type { SendEmailOptions, SendEmailResponse } from './modules/email';\n\n// Re-export Realtime module and types\nexport { Realtime } from './modules/realtime';\nexport type {\n RealtimeErrorPayload,\n SubscribeResponse,\n SocketMessage,\n ConnectionState,\n EventCallback,\n} from './modules/realtime';\n\n// Re-export utilities for advanced usage\nexport { HttpClient } from './lib/http-client';\nexport { TokenManager } from './lib/token-manager';\n\n// Factory function for creating clients (Supabase-style)\nimport { InsForgeClient } from './client';\nimport { InsForgeConfig } from './types';\n\nexport function createClient(config: InsForgeConfig): InsForgeClient {\n return new InsForgeClient(config);\n}\n\n// Default export for convenience\nexport default InsForgeClient;\n"],"mappings":";AA0EO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,OAAe,aAAsB;AACpF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,OAAO,aAAa,UAAmC;AACrD,WAAO,IAAI;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AACF;;;ACzFO,IAAM,aAAN,MAAiB;AAAA,EAOtB,YAAY,QAAwB;AAFpC,SAAQ,YAA2B;AAGjC,SAAK,UAAU,OAAO,WAAW;AAEjC,SAAK,QAAQ,OAAO,UAAU,WAAW,QAAQ,WAAW,MAAM,KAAK,UAAU,IAAI;AACrF,SAAK,UAAU,OAAO;AACtB,SAAK,iBAAiB;AAAA,MACpB,GAAG,OAAO;AAAA,IACZ;AAEA,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,SAAS,MAAc,QAAyC;AACtE,UAAM,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO;AACtC,QAAI,QAAQ;AACV,aAAO,QAAQ,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAG/C,YAAI,QAAQ,UAAU;AAKpB,cAAI,kBAAkB,MAAM,QAAQ,QA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AI,KAAK,KAAK,MAAM,KAAK,YAAY;AACjD,SAAK,WAAW,IAAI,SAAS,KAAK,MAAM,KAAK,YAAY;AACzD,SAAK,UAAU,IAAI,QAAQ,KAAK,IAAI;AACpC,SAAK,KAAK,IAAI,GAAG,KAAK,IAAI;AAC1B,SAAK,YAAY,IAAI,UAAU,KAAK,IAAI;AACxC,SAAK,WAAW,IAAI,SAAS,KAAK,KAAK,SAAS,KAAK,cAAc,OAAO,OAAO;AACjF,SAAK,SAAS,IAAI,OAAO,KAAK,IAAI;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,gBAA4B;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUF;;;AC5CO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":["session","response"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insforge/sdk",
3
- "version": "1.0.5-dev.4",
3
+ "version": "1.0.5",
4
4
  "description": "Official JavaScript/TypeScript client for InsForge Backend-as-a-Service platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",