@archlast/client 0.0.1
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/LICENSE +21 -0
- package/README.md +60 -0
- package/dist/admin/index.cjs +93 -0
- package/dist/admin/index.cjs.map +1 -0
- package/dist/admin/index.d.cts +51 -0
- package/dist/admin/index.d.ts +51 -0
- package/dist/admin/index.js +59 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/auth/index.cjs +174 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +128 -0
- package/dist/auth/index.d.ts +128 -0
- package/dist/auth/index.js +141 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/client.cjs +677 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +84 -0
- package/dist/client.d.ts +84 -0
- package/dist/client.js +642 -0
- package/dist/client.js.map +1 -0
- package/dist/function-reference.cjs +50 -0
- package/dist/function-reference.cjs.map +1 -0
- package/dist/function-reference.d.cts +22 -0
- package/dist/function-reference.d.ts +22 -0
- package/dist/function-reference.js +24 -0
- package/dist/function-reference.js.map +1 -0
- package/dist/index.cjs +1163 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1111 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +455 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +137 -0
- package/dist/react.d.ts +137 -0
- package/dist/react.js +410 -0
- package/dist/react.js.map +1 -0
- package/dist/storage/index.cjs +150 -0
- package/dist/storage/index.cjs.map +1 -0
- package/dist/storage/index.d.cts +59 -0
- package/dist/storage/index.d.ts +59 -0
- package/dist/storage/index.js +117 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/trpc.cjs +66 -0
- package/dist/trpc.cjs.map +1 -0
- package/dist/trpc.d.cts +59 -0
- package/dist/trpc.d.ts +59 -0
- package/dist/trpc.js +41 -0
- package/dist/trpc.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/auth/index.ts","../src/storage/index.ts","../src/admin/index.ts"],"sourcesContent":["import { ArchlastAuthClient } from \"./auth/index\";\nimport { StorageClient } from \"./storage/index\";\nimport { AdminClient } from \"./admin/index\";\n\nexport interface ArchlastClientOptions {\n autoConnect?: boolean;\n isAdmin?: boolean;\n /**\n * Better-Auth API key for authenticating function calls.\n * Uses the Better-Auth API key plugin (arch_* prefix).\n * This is the recommended authentication method.\n * Can be set via ARCHLAST_API_KEY environment variable.\n */\n apiKey?: string;\n /**\n * Better-Auth session cookies to include with WebSocket connection.\n * This enables Better-Auth authentication for WebSocket connections.\n */\n betterAuthCookies?: Record<string, string>;\n}\n\nexport class ArchlastClient {\n private ws: WebSocket | null = null;\n private url: string;\n private listeners: Map<string, Set<(data: any) => void>> = new Map();\n private subscriptions: Map<string, { name: string; args: any }> = new Map();\n private pendingMutations: Map<\n string,\n { resolve: (data: any) => void; reject: (err: Error) => void; timeout: any }\n > = new Map();\n private messageQueue: string[] = [];\n private isConnected = false;\n private reconnectAttempts = 0;\n private maxReconnectAttempts = 5;\n private reconnectDelay = 1000;\n private reconnectTimeout: any = null;\n private isExplicitlyClosed = false;\n private sessionId: string | null = null;\n\n // Event listeners\n private connectionListeners = new Set<(sessionId: string) => void>();\n private disconnectionListeners = new Set<(reason: string) => void>();\n private errorListeners = new Set<(error: string) => void>();\n\n public readonly auth: ArchlastAuthClient;\n public readonly storage: StorageClient;\n public readonly admin: AdminClient;\n public readonly baseUrl: string;\n private appId?: string;\n private isAdmin: boolean;\n private apiKey?: string;\n private betterAuthCookies?: Record<string, string>;\n\n /**\n * @param url WebSocket URL\n * @param httpUrl Backend HTTP URL (used for WS derivation fallback)\n * @param appId App ID for session isolation\n * @param authUrl Optional same-origin URL for auth requests (to avoid cross-origin cookie issues)\n * @param options Configuration options\n */\n constructor(\n url: string,\n httpUrl?: string,\n appId?: string,\n authUrl?: string,\n options: ArchlastClientOptions = {}\n ) {\n this.url = url;\n this.appId = appId;\n this.isAdmin = options.isAdmin ?? false;\n this.apiKey = options.apiKey;\n this.betterAuthCookies = options.betterAuthCookies;\n\n // authUrl: if provided, use it for auth client (same-origin proxy)\n // Otherwise, derive from httpUrl or WS url\n const derivedHttpUrl = httpUrl !== undefined ? httpUrl : url.replace(/^ws/, \"http\");\n const authBaseUrl = authUrl !== undefined ? authUrl : derivedHttpUrl;\n this.baseUrl = authBaseUrl;\n\n this.auth = new ArchlastAuthClient({ baseUrl: authBaseUrl, appId, apiKey: options.apiKey });\n this.storage = new StorageClient(authBaseUrl, appId, { apiKey: options.apiKey });\n this.admin = new AdminClient(authBaseUrl, { apiKey: options.apiKey });\n\n if (options.autoConnect !== false) {\n this.connect();\n }\n }\n\n /**\n * Update Better-Auth cookies (call this when session changes)\n */\n public setBetterAuthCookies(cookies: Record<string, string>) {\n this.betterAuthCookies = cookies;\n // If already connected, reconnect to send new cookies\n if (this.isConnected) {\n this.connect();\n }\n }\n\n /**\n * Update Better-Auth API key (call this when API key changes)\n */\n public setApiKey(apiKey: string) {\n this.apiKey = apiKey;\n // If already connected, reconnect to send new API key\n if (this.isConnected) {\n this.connect();\n }\n }\n\n public connect() {\n // SSR protection: don't connect on the server\n if (typeof window === \"undefined\") {\n return;\n }\n\n this.isExplicitlyClosed = false;\n\n if (this.ws) {\n if (\n this.ws.readyState === WebSocket.OPEN ||\n this.ws.readyState === WebSocket.CONNECTING\n ) {\n return;\n }\n try {\n this.ws.close();\n } catch (e) {\n // ignore\n }\n this.ws = null;\n }\n\n try {\n this.ws = new WebSocket(this.url);\n } catch (e) {\n this.handleClose();\n return;\n }\n\n this.ws.onopen = async () => {\n console.log(\"Connected to Archlast Server\");\n this.isConnected = true;\n this.reconnectAttempts = 0;\n\n // Build auth headers\n const headers: Record<string, string> = {};\n if (this.appId) {\n headers[\"x-archlast-app-id\"] = this.appId;\n }\n // Better-Auth API key - use x-api-key header\n if (this.apiKey) {\n headers[\"x-api-key\"] = this.apiKey;\n }\n\n // Build cookies object for auth (merge Better-Auth cookies)\n const cookies: Record<string, string> = {};\n if (this.betterAuthCookies) {\n Object.assign(cookies, this.betterAuthCookies);\n }\n\n this.sendMessage({\n type: \"connect\",\n auth: {\n headers: Object.keys(headers).length > 0 ? headers : undefined,\n cookies: Object.keys(cookies).length > 0 ? cookies : undefined,\n },\n });\n\n // Subscribe to logs and admin events\n // For admin dashboard (isAdmin=true), always subscribe since it requires auth\n // For app clients, check authentication state\n if (this.isAdmin) {\n // Admin dashboard - always subscribe to admin events\n this.sendMessage({\n type: \"subscribe_logs\",\n });\n this.sendMessage({\n type: \"subscribe_admin_events\",\n });\n } else {\n // App client - only subscribe if authenticated\n try {\n const state = await this.auth.getState();\n console.log(\"Auth state:\", state);\n if (state.isAuthenticated) {\n this.sendMessage({\n type: \"subscribe_logs\",\n });\n this.sendMessage({\n type: \"subscribe_admin_events\",\n });\n }\n } catch (err) {\n // Ignore auth fetch errors\n }\n }\n\n this.flushQueue();\n this.resubscribeAll();\n this.startHeartbeat();\n };\n\n this.ws.onmessage = (event) => this.handleMessage(event);\n\n this.ws.onclose = () => this.handleClose();\n this.ws.onerror = (err) => {\n // Only log if not explicitly closed (sometimes error fires before close)\n if (!this.isExplicitlyClosed) {\n console.error(\"WebSocket error:\", err);\n this.ws?.close();\n }\n };\n }\n\n private heartbeatInterval: any = null;\n\n private startHeartbeat() {\n this.stopHeartbeat();\n this.heartbeatInterval = setInterval(() => {\n if (this.isConnected) {\n this.sendMessage({ type: \"ping\" });\n }\n }, 30000); // 30 seconds\n }\n\n private stopHeartbeat() {\n if (this.heartbeatInterval) {\n clearInterval(this.heartbeatInterval);\n this.heartbeatInterval = null;\n }\n }\n\n private handleClose() {\n this.isConnected = false;\n this.sessionId = null;\n this.disconnectionListeners.forEach((l) => l(\"Disconnected\"));\n\n if (this.isExplicitlyClosed) return;\n\n if (this.reconnectAttempts < this.maxReconnectAttempts) {\n const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts);\n console.log(`Disconnected. Reconnecting in ${delay}ms...`);\n this.reconnectTimeout = setTimeout(() => {\n this.reconnectAttempts++;\n this.connect();\n }, delay);\n }\n }\n\n private handleMessage(event: MessageEvent) {\n try {\n const msg = JSON.parse(event.data);\n\n if (msg.type === \"data\" || msg.type === \"patch\") {\n const queryId = msg.queryId;\n const data = msg.data || msg.patch; // Handle patch logic if needed\n\n // Notify all listeners (React Query handles caching)\n const listeners = this.listeners.get(queryId);\n if (listeners) {\n listeners.forEach((l) => l(data));\n }\n } else if (msg.type === \"mutationResponse\") {\n const pending = this.pendingMutations.get(msg.mutationId);\n if (pending) {\n clearTimeout(pending.timeout);\n this.pendingMutations.delete(msg.mutationId);\n if (msg.success) {\n pending.resolve(msg.data);\n } else {\n pending.reject(new Error(msg.error));\n }\n }\n } else if (msg.type === \"connected\") {\n console.log(\"Session established:\", msg.sessionId);\n this.sessionId = msg.sessionId;\n this.isConnected = true;\n this.reconnectAttempts = 0;\n this.connectionListeners.forEach((l) => l(msg.sessionId));\n } else if (msg.type === \"error\") {\n console.error(\"Server error:\", msg.message);\n this.errorListeners.forEach((l) => l(msg.message));\n\n if (msg.message === \"Authentication required\") {\n // Fatal auth error - do not reconnect\n this.isExplicitlyClosed = true;\n this.ws?.close();\n }\n }\n } catch (e) {\n console.error(\"Error handling message:\", e);\n }\n }\n\n public getWs() {\n return this.ws;\n }\n\n public onConnected(cb: (sessionId: string) => void) {\n this.connectionListeners.add(cb);\n return () => this.connectionListeners.delete(cb);\n }\n\n public onDisconnected(cb: (reason: string) => void) {\n this.disconnectionListeners.add(cb);\n return () => this.disconnectionListeners.delete(cb);\n }\n\n public onError(cb: (error: string) => void) {\n this.errorListeners.add(cb);\n return () => this.errorListeners.delete(cb);\n }\n\n public getStatus() {\n return this.isConnected ? \"connected\" : \"disconnected\";\n }\n\n public getSessionId() {\n return this.sessionId;\n }\n\n private sendMessage(msg: any) {\n const data = JSON.stringify(msg);\n if (this.ws && this.ws.readyState === WebSocket.OPEN) {\n this.ws.send(data);\n } else {\n this.messageQueue.push(data);\n }\n }\n\n private flushQueue() {\n while (this.messageQueue.length > 0) {\n const msg = this.messageQueue.shift();\n if (msg) this.ws?.send(msg);\n }\n }\n\n private resubscribeAll() {\n for (const [queryId, sub] of Array.from(this.subscriptions.entries())) {\n this.sendMessage({\n type: \"query\",\n queryId,\n name: sub.name,\n args: sub.args,\n });\n }\n }\n\n private getQueryId(name: string, args: any) {\n // Sort keys to ensure stable ID\n const stableArgs = JSON.stringify(args, Object.keys(args || {}).sort());\n return `${name}:${stableArgs}`;\n }\n\n subscribe(queryName: string, args: any, onUpdate: (data: any) => void): () => void {\n const queryId = this.getQueryId(queryName, args);\n\n if (!this.listeners.has(queryId)) {\n this.listeners.set(queryId, new Set());\n this.subscriptions.set(queryId, { name: queryName, args });\n // Send subscribe message\n this.sendMessage({\n type: \"query\",\n queryId,\n name: queryName,\n args,\n });\n }\n\n this.listeners.get(queryId)!.add(onUpdate);\n\n return () => {\n const set = this.listeners.get(queryId);\n if (set) {\n set.delete(onUpdate);\n if (set.size === 0) {\n this.listeners.delete(queryId);\n this.subscriptions.delete(queryId);\n // Send unsubscribe message (not implemented in server yet)\n }\n }\n };\n }\n\n async fetch(name: string, args: any): Promise<any> {\n const queryId = this.getQueryId(name, args);\n\n return new Promise((resolve, reject) => {\n let resolved = false;\n const unsubscribe = this.subscribe(name, args, (data) => {\n if (!resolved) {\n resolved = true;\n unsubscribe();\n resolve(data);\n }\n });\n\n setTimeout(() => {\n if (!resolved) {\n resolved = true;\n unsubscribe();\n reject(new Error(\"Timeout waiting for data\"));\n }\n }, 5000);\n });\n }\n\n async mutate(name: string, args: any): Promise<any> {\n return new Promise((resolve, reject) => {\n const mutationId = Math.random().toString(36).slice(2);\n\n const timeout = setTimeout(() => {\n this.pendingMutations.delete(mutationId);\n reject(new Error(\"Mutation timeout\"));\n }, 10000);\n\n this.pendingMutations.set(mutationId, { resolve, reject, timeout });\n\n this.sendMessage({\n type: \"mutation\",\n mutationId,\n name,\n args,\n });\n });\n }\n\n close() {\n this.isExplicitlyClosed = true;\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout);\n this.reconnectTimeout = null;\n }\n\n if (this.ws) {\n // Prevent handlers from firing during closure\n this.ws.onclose = null;\n this.ws.onopen = null;\n this.ws.onerror = null;\n this.ws.onmessage = null;\n\n this.ws.close();\n this.ws = null;\n }\n this.isConnected = false;\n this.stopHeartbeat();\n }\n}\n","/**\n * Client-side auth API wrapper for Archlast.\n *\n * This now uses Better-Auth endpoints via the proxy:\n * - GET /api/auth/get-session\n * - POST /api/auth/sign-up\n * - POST /api/auth/sign-in\n * - POST /api/auth/sign-out\n *\n * Migration from legacy /_auth/* endpoints:\n * - /_auth/state → /api/auth/get-session\n * - /_auth/sign-up → /api/auth/sign-up (email)\n * - /_auth/sign-in → /api/auth/sign-in (email)\n * - /_auth/sign-out → /api/auth/sign-out\n *\n * Notes:\n * - Uses cookie-based sessions by default (credentials: \"include\").\n * - For programmatic access, use Better-Auth API keys (arch_* prefix) via x-api-key header.\n * - Better-Auth supports username, OAuth, magic link, and more.\n */\n\nimport axios, { type AxiosInstance } from \"axios\";\n\nexport type AuthUser = {\n id: string;\n email: string;\n emailVerified: boolean;\n name?: string;\n image?: string;\n createdAt?: Date;\n updatedAt?: Date;\n role?: string;\n banned?: boolean;\n};\n\nexport type AuthSession = {\n token: string;\n expiresAt: Date;\n userId: string;\n ipAddress?: string;\n userAgent?: string;\n};\n\nexport type AuthState = {\n user: AuthUser | null;\n session: AuthSession | null;\n isAuthenticated: boolean;\n};\n\nexport type SignUpInput = {\n email: string;\n password: string;\n name?: string;\n username?: string;\n};\n\nexport type SignInInput = {\n email?: string;\n username?: string;\n password: string;\n};\n\nexport type ArchlastAuthClientOptions = {\n /**\n * Base URL for the Archlast server.\n * Example: \"http://localhost:4000\"\n *\n * If omitted, it will default to:\n * - window.location.origin in the browser\n * - \"\" in non-browser contexts\n */\n baseUrl?: string;\n\n /**\n * App ID for session isolation (e.g. \"web\", \"admin\").\n * When set, adds x-archlast-app-id header.\n */\n appId?: string;\n\n /**\n * Better-Auth API key for authentication.\n * When provided, uses x-api-key header instead of cookies.\n */\n apiKey?: string;\n};\n\nfunction resolveBaseUrl(explicit?: string): string {\n if (explicit && explicit.trim()) return explicit.replace(/\\/+$/, \"\");\n if (typeof window !== \"undefined\" && window.location?.origin) return window.location.origin;\n return \"\";\n}\n\nexport class ArchlastAuthClient {\n private readonly baseUrl: string;\n private readonly axios: AxiosInstance;\n private readonly appId?: string;\n private readonly apiKey?: string;\n\n constructor(options: ArchlastAuthClientOptions = {}) {\n this.baseUrl = resolveBaseUrl(options.baseUrl);\n this.appId = options.appId;\n this.apiKey = options.apiKey;\n this.axios = axios.create({\n baseURL: this.baseUrl,\n withCredentials: !options.apiKey, // Only use cookies if no API key\n headers: {\n \"content-type\": \"application/json\",\n ...(this.appId ? { \"x-archlast-app-id\": this.appId } : {}),\n ...(options.apiKey ? { \"x-api-key\": options.apiKey } : {}),\n },\n });\n }\n\n /**\n * Get current authentication state\n * Uses Better-Auth's getSession endpoint\n */\n async getState(): Promise<AuthState> {\n try {\n const response = await this.axios.get<{\n user: AuthUser | null;\n session: AuthSession | null;\n }>(\"/api/auth/get-session\");\n\n const { user, session } = response.data;\n\n return {\n user,\n session,\n isAuthenticated: !!user,\n };\n } catch (error) {\n // Return unauthenticated state on error\n return {\n user: null,\n session: null,\n isAuthenticated: false,\n };\n }\n }\n\n /**\n * Sign up new user\n * Uses Better-Auth's email signUp endpoint\n */\n async signUp(input: SignUpInput): Promise<AuthState> {\n const response = await this.axios.post<{ user: AuthUser }>(\"/api/auth/sign-up/email\", {\n email: input.email,\n password: input.password,\n name: input.name,\n username: input.username,\n });\n\n return {\n user: response.data.user,\n session: null, // Session is managed via cookies\n isAuthenticated: !!response.data.user,\n };\n }\n\n /**\n * Sign in with email/username and password\n * Uses Better-Auth's credential sign-in endpoint\n */\n async signIn(input: SignInInput): Promise<AuthState> {\n // Support email or username sign-in\n if (!input.email && !input.username) {\n throw new Error(\"Either email or username is required\");\n }\n\n const response = await this.axios.post<{ user: AuthUser }>(\"/api/auth/sign-in/email\", {\n email: input.email,\n username: input.username,\n password: input.password,\n });\n\n return {\n user: response.data.user,\n session: null, // Session is managed via cookies\n isAuthenticated: !!response.data.user,\n };\n }\n\n /**\n * Sign out and revoke session\n * Uses Better-Auth's sign-out endpoint\n */\n async signOut(): Promise<{ success: boolean }> {\n const response = await this.axios.post<{ success: boolean }>(\n \"/api/auth/sign-out\",\n {},\n { withCredentials: true }\n );\n\n return response.data;\n }\n\n /**\n * Request password reset email\n * Uses Better-Auth's password reset flow\n */\n async requestPasswordReset(email: string, callbackURL?: string): Promise<{ success: boolean }> {\n const response = await this.axios.post<{ success: boolean }>(\"/api/auth/forgot-password\", {\n email,\n redirectTo: callbackURL,\n });\n\n return response.data;\n }\n\n /**\n * Reset password with token\n * Uses Better-Auth's reset password endpoint\n */\n async resetPassword(token: string, password: string): Promise<{ success: boolean }> {\n const response = await this.axios.post<{ success: boolean }>(\"/api/auth/reset-password\", {\n token,\n password,\n });\n\n return response.data;\n }\n\n /**\n * Verify email with token\n * Uses Better-Auth's email verification endpoint\n */\n async verifyEmail(token: string): Promise<{ success: boolean; user?: AuthUser }> {\n const response = await this.axios.post<{ success: boolean; user?: AuthUser }>(\"/api/auth/verify-email\", {\n token,\n });\n\n return response.data;\n }\n}\n\n/**\n * Default export for backward compatibility\n */\nexport default ArchlastAuthClient;\n","import axios, { AxiosInstance } from \"axios\";\n\nexport type StorageFile = {\n id: string; // The storage key/path\n url: string; // Public URL\n downloadUrl: string; // Authenticated download URL\n name: string;\n fileName: string | null;\n hash: string;\n refCount: number;\n contentType: string;\n size: number;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type StorageListResponse = {\n items: StorageFile[];\n};\n\nexport type StorageClientOptions = {\n /**\n * Better-Auth API key for authentication\n * When provided, uses x-api-key header instead of cookies\n */\n apiKey?: string;\n};\n\nexport class StorageClient {\n private readonly axios: AxiosInstance;\n\n constructor(baseUrl: string, appId?: string, options?: StorageClientOptions) {\n this.axios = axios.create({\n baseURL: baseUrl,\n withCredentials: !options?.apiKey, // Only use cookies if no API key\n headers: {\n ...(appId ? { \"x-archlast-app-id\": appId } : {}),\n ...(options?.apiKey ? { \"x-api-key\": options.apiKey } : {}),\n },\n });\n }\n\n /**\n * Upload a file\n */\n async upload(\n file: Blob | Uint8Array | ReadableStream | File,\n contentType?: string\n ): Promise<StorageFile> {\n let body: FormData | Blob | Uint8Array | ReadableStream = file;\n let headers: Record<string, string> = {};\n\n if (file instanceof File) {\n const formData = new FormData();\n formData.append(\"file\", file);\n body = formData;\n } else {\n // Raw binary upload\n if (contentType) {\n headers[\"Content-Type\"] = contentType;\n }\n\n // Convert ReadableStream if needed, or pass through if supported by axios/adapter\n // For browser axios, usually Blob/ArrayBuffer/FormData\n if (file instanceof Uint8Array) {\n // wrap in Blob if possible or send directly\n }\n }\n\n const response = await this.axios.post<Partial<StorageFile>>(\n \"/_archlast/storage/upload\",\n body,\n {\n headers,\n }\n );\n\n // Hydrate URLs\n const data = response.data;\n if (!data.id) throw new Error(\"Upload failed: No ID returned\");\n\n return this.hydrate(data as StorageFile);\n }\n\n /**\n * List files\n */\n async list(limit = 20, offset = 0): Promise<StorageListResponse> {\n const response = await this.axios.get<StorageListResponse>(\"/_archlast/storage/list\", {\n params: { limit, offset },\n });\n return {\n items: response.data.items.map((item) => this.hydrate(item)),\n };\n }\n\n /**\n * Get file metadata\n */\n async getMetadata(id: string): Promise<StorageFile> {\n const response = await this.axios.get<StorageFile>(`/_archlast/storage/files/${id}`);\n return this.hydrate(response.data);\n }\n\n /**\n * Generate a presigned download URL\n */\n async presign(id: string, expiresInSeconds: number = 300): Promise<{ url: string }> {\n const response = await this.axios.post<{ url: string }>(\"/_archlast/storage/presign\", {\n id,\n expiresInSeconds,\n });\n return response.data;\n }\n\n /**\n * Delete file\n */\n async delete(id: string): Promise<{ success: boolean }> {\n const response = await this.axios.delete<{ success: boolean }>(\n `/_archlast/storage/files/${id}`\n );\n return response.data;\n }\n\n /**\n * Get public URL for a file\n */\n getPublicUrl(id: string): string {\n const base = this.axios.defaults.baseURL?.replace(/\\/+$/, \"\") || \"\";\n // If base is relative (starts with /), assumes same origin\n return `${base}/_storage/${id}`;\n }\n\n getDownloadUrl(id: string): string {\n // Direct authenticated download endpoint\n const base = this.axios.defaults.baseURL?.replace(/\\/+$/, \"\") || \"\";\n return `${base}/_archlast/storage/files/${id}/download`;\n }\n\n private hydrate(file: Partial<StorageFile>): StorageFile {\n if (!file.id) throw new Error(\"Invalid file object: missing id\");\n return {\n id: file.id,\n name: file.name ?? file.fileName ?? \"Untitled\", // Handle aliasing\n fileName: file.fileName ?? file.name ?? null,\n url: file.url ?? this.getPublicUrl(file.id),\n downloadUrl: file.downloadUrl ?? this.getDownloadUrl(file.id),\n hash: file.hash ?? \"\",\n contentType: file.contentType ?? \"application/octet-stream\",\n size: file.size ?? 0,\n createdAt: file.createdAt ?? Date.now(),\n updatedAt: file.updatedAt ?? Date.now(),\n refCount: file.refCount ?? 1,\n };\n }\n}\n","import axios, { AxiosInstance } from \"axios\";\n\nexport type AdminSession = {\n id: string;\n userId: string;\n createdAt: number;\n lastAccess: number;\n userAgent: string | null;\n ipAddress: string | null;\n current: boolean;\n};\n\nexport type AdminProfile = {\n id: string;\n email: string;\n is_super_admin: boolean;\n created_at: number;\n};\n\nexport type AdminClientOptions = {\n /**\n * Better-Auth API key for authentication\n * When provided, uses x-api-key header instead of cookies\n */\n apiKey?: string;\n};\n\nexport class AdminAuthClient {\n private readonly axios: AxiosInstance;\n\n constructor(baseUrl: string, options?: AdminClientOptions) {\n this.axios = axios.create({\n baseURL: baseUrl,\n withCredentials: !options?.apiKey,\n headers: {\n ...(options?.apiKey ? { \"x-api-key\": options.apiKey } : {}),\n },\n });\n }\n\n async signIn(\n email: string,\n password: string\n ): Promise<{ success: boolean; user: AdminProfile }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-in\", {\n email,\n password,\n });\n return response.data;\n }\n\n async signOut(): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-out\");\n return response.data;\n }\n\n async getProfile(): Promise<{ user: AdminProfile }> {\n const response = await this.axios.get(\"/_archlast/admin/auth/me\");\n return response.data;\n }\n\n async getSessions(): Promise<{ sessions: AdminSession[] }> {\n const response = await this.axios.get(\"/_archlast/admin/auth/sessions\");\n return response.data;\n }\n\n async revokeSession(sessionId: string): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/revoke-session\", {\n sessionId,\n });\n return response.data;\n }\n\n async signOutAll(): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-out-all\");\n return response.data;\n }\n}\n\nexport class AdminClient {\n public auth: AdminAuthClient;\n // Add other admin clients here (users, tenants, etc.)\n\n constructor(baseUrl: string, options?: AdminClientOptions) {\n this.auth = new AdminAuthClient(baseUrl, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqBA,mBAA0C;AAiE1C,SAAS,eAAe,UAA2B;AAC/C,MAAI,YAAY,SAAS,KAAK,EAAG,QAAO,SAAS,QAAQ,QAAQ,EAAE;AACnE,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU,OAAQ,QAAO,OAAO,SAAS;AACrF,SAAO;AACX;AAEO,IAAM,qBAAN,MAAyB;AAAA,EAM5B,YAAY,UAAqC,CAAC,GAAG;AALrD,wBAAiB;AACjB,wBAAiB;AACjB,wBAAiB;AACjB,wBAAiB;AAGb,SAAK,UAAU,eAAe,QAAQ,OAAO;AAC7C,SAAK,QAAQ,QAAQ;AACrB,SAAK,SAAS,QAAQ;AACtB,SAAK,QAAQ,aAAAA,QAAM,OAAO;AAAA,MACtB,SAAS,KAAK;AAAA,MACd,iBAAi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SAAS,EAAE,EAAE,MAAM,CAAC;AAErD,YAAM,UAAU,WAAW,MAAM;AAC7B,aAAK,iBAAiB,OAAO,UAAU;AACvC,eAAO,IAAI,MAAM,kBAAkB,CAAC;AAAA,MACxC,GAAG,GAAK;AAER,WAAK,iBAAiB,IAAI,YAAY,EAAE,SAAS,QAAQ,QAAQ,CAAC;AAElE,WAAK,YAAY;AAAA,QACb,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,MACJ,CAAC;AAAA,IACL,CAAC;AAAA,EACL;AAAA,EAEA,QAAQ;AACJ,SAAK,qBAAqB;AAC1B,QAAI,KAAK,kBAAkB;AACvB,mBAAa,KAAK,gBAAgB;AAClC,WAAK,mBAAmB;AAAA,IAC5B;AAEA,QAAI,KAAK,IAAI;AAET,WAAK,GAAG,UAAU;AAClB,WAAK,GAAG,SAAS;AACjB,WAAK,GAAG,UAAU;AAClB,WAAK,GAAG,YAAY;AAEpB,WAAK,GAAG,MAAM;AACd,WAAK,KAAK;AAAA,IACd;AACA,SAAK,cAAc;AACnB,SAAK,cAAc;AAAA,EACvB;AACJ;","names":["axios","import_axios","axios","import_axios","axios"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import ArchlastAuthClient from './auth/index.cjs';
|
|
2
|
+
import { StorageClient } from './storage/index.cjs';
|
|
3
|
+
import { AdminClient } from './admin/index.cjs';
|
|
4
|
+
|
|
5
|
+
interface ArchlastClientOptions {
|
|
6
|
+
autoConnect?: boolean;
|
|
7
|
+
isAdmin?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Better-Auth API key for authenticating function calls.
|
|
10
|
+
* Uses the Better-Auth API key plugin (arch_* prefix).
|
|
11
|
+
* This is the recommended authentication method.
|
|
12
|
+
* Can be set via ARCHLAST_API_KEY environment variable.
|
|
13
|
+
*/
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Better-Auth session cookies to include with WebSocket connection.
|
|
17
|
+
* This enables Better-Auth authentication for WebSocket connections.
|
|
18
|
+
*/
|
|
19
|
+
betterAuthCookies?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
declare class ArchlastClient {
|
|
22
|
+
private ws;
|
|
23
|
+
private url;
|
|
24
|
+
private listeners;
|
|
25
|
+
private subscriptions;
|
|
26
|
+
private pendingMutations;
|
|
27
|
+
private messageQueue;
|
|
28
|
+
private isConnected;
|
|
29
|
+
private reconnectAttempts;
|
|
30
|
+
private maxReconnectAttempts;
|
|
31
|
+
private reconnectDelay;
|
|
32
|
+
private reconnectTimeout;
|
|
33
|
+
private isExplicitlyClosed;
|
|
34
|
+
private sessionId;
|
|
35
|
+
private connectionListeners;
|
|
36
|
+
private disconnectionListeners;
|
|
37
|
+
private errorListeners;
|
|
38
|
+
readonly auth: ArchlastAuthClient;
|
|
39
|
+
readonly storage: StorageClient;
|
|
40
|
+
readonly admin: AdminClient;
|
|
41
|
+
readonly baseUrl: string;
|
|
42
|
+
private appId?;
|
|
43
|
+
private isAdmin;
|
|
44
|
+
private apiKey?;
|
|
45
|
+
private betterAuthCookies?;
|
|
46
|
+
/**
|
|
47
|
+
* @param url WebSocket URL
|
|
48
|
+
* @param httpUrl Backend HTTP URL (used for WS derivation fallback)
|
|
49
|
+
* @param appId App ID for session isolation
|
|
50
|
+
* @param authUrl Optional same-origin URL for auth requests (to avoid cross-origin cookie issues)
|
|
51
|
+
* @param options Configuration options
|
|
52
|
+
*/
|
|
53
|
+
constructor(url: string, httpUrl?: string, appId?: string, authUrl?: string, options?: ArchlastClientOptions);
|
|
54
|
+
/**
|
|
55
|
+
* Update Better-Auth cookies (call this when session changes)
|
|
56
|
+
*/
|
|
57
|
+
setBetterAuthCookies(cookies: Record<string, string>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Update Better-Auth API key (call this when API key changes)
|
|
60
|
+
*/
|
|
61
|
+
setApiKey(apiKey: string): void;
|
|
62
|
+
connect(): void;
|
|
63
|
+
private heartbeatInterval;
|
|
64
|
+
private startHeartbeat;
|
|
65
|
+
private stopHeartbeat;
|
|
66
|
+
private handleClose;
|
|
67
|
+
private handleMessage;
|
|
68
|
+
getWs(): WebSocket | null;
|
|
69
|
+
onConnected(cb: (sessionId: string) => void): () => boolean;
|
|
70
|
+
onDisconnected(cb: (reason: string) => void): () => boolean;
|
|
71
|
+
onError(cb: (error: string) => void): () => boolean;
|
|
72
|
+
getStatus(): "connected" | "disconnected";
|
|
73
|
+
getSessionId(): string | null;
|
|
74
|
+
private sendMessage;
|
|
75
|
+
private flushQueue;
|
|
76
|
+
private resubscribeAll;
|
|
77
|
+
private getQueryId;
|
|
78
|
+
subscribe(queryName: string, args: any, onUpdate: (data: any) => void): () => void;
|
|
79
|
+
fetch(name: string, args: any): Promise<any>;
|
|
80
|
+
mutate(name: string, args: any): Promise<any>;
|
|
81
|
+
close(): void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { ArchlastClient, type ArchlastClientOptions };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import ArchlastAuthClient from './auth/index.js';
|
|
2
|
+
import { StorageClient } from './storage/index.js';
|
|
3
|
+
import { AdminClient } from './admin/index.js';
|
|
4
|
+
|
|
5
|
+
interface ArchlastClientOptions {
|
|
6
|
+
autoConnect?: boolean;
|
|
7
|
+
isAdmin?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Better-Auth API key for authenticating function calls.
|
|
10
|
+
* Uses the Better-Auth API key plugin (arch_* prefix).
|
|
11
|
+
* This is the recommended authentication method.
|
|
12
|
+
* Can be set via ARCHLAST_API_KEY environment variable.
|
|
13
|
+
*/
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Better-Auth session cookies to include with WebSocket connection.
|
|
17
|
+
* This enables Better-Auth authentication for WebSocket connections.
|
|
18
|
+
*/
|
|
19
|
+
betterAuthCookies?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
declare class ArchlastClient {
|
|
22
|
+
private ws;
|
|
23
|
+
private url;
|
|
24
|
+
private listeners;
|
|
25
|
+
private subscriptions;
|
|
26
|
+
private pendingMutations;
|
|
27
|
+
private messageQueue;
|
|
28
|
+
private isConnected;
|
|
29
|
+
private reconnectAttempts;
|
|
30
|
+
private maxReconnectAttempts;
|
|
31
|
+
private reconnectDelay;
|
|
32
|
+
private reconnectTimeout;
|
|
33
|
+
private isExplicitlyClosed;
|
|
34
|
+
private sessionId;
|
|
35
|
+
private connectionListeners;
|
|
36
|
+
private disconnectionListeners;
|
|
37
|
+
private errorListeners;
|
|
38
|
+
readonly auth: ArchlastAuthClient;
|
|
39
|
+
readonly storage: StorageClient;
|
|
40
|
+
readonly admin: AdminClient;
|
|
41
|
+
readonly baseUrl: string;
|
|
42
|
+
private appId?;
|
|
43
|
+
private isAdmin;
|
|
44
|
+
private apiKey?;
|
|
45
|
+
private betterAuthCookies?;
|
|
46
|
+
/**
|
|
47
|
+
* @param url WebSocket URL
|
|
48
|
+
* @param httpUrl Backend HTTP URL (used for WS derivation fallback)
|
|
49
|
+
* @param appId App ID for session isolation
|
|
50
|
+
* @param authUrl Optional same-origin URL for auth requests (to avoid cross-origin cookie issues)
|
|
51
|
+
* @param options Configuration options
|
|
52
|
+
*/
|
|
53
|
+
constructor(url: string, httpUrl?: string, appId?: string, authUrl?: string, options?: ArchlastClientOptions);
|
|
54
|
+
/**
|
|
55
|
+
* Update Better-Auth cookies (call this when session changes)
|
|
56
|
+
*/
|
|
57
|
+
setBetterAuthCookies(cookies: Record<string, string>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Update Better-Auth API key (call this when API key changes)
|
|
60
|
+
*/
|
|
61
|
+
setApiKey(apiKey: string): void;
|
|
62
|
+
connect(): void;
|
|
63
|
+
private heartbeatInterval;
|
|
64
|
+
private startHeartbeat;
|
|
65
|
+
private stopHeartbeat;
|
|
66
|
+
private handleClose;
|
|
67
|
+
private handleMessage;
|
|
68
|
+
getWs(): WebSocket | null;
|
|
69
|
+
onConnected(cb: (sessionId: string) => void): () => boolean;
|
|
70
|
+
onDisconnected(cb: (reason: string) => void): () => boolean;
|
|
71
|
+
onError(cb: (error: string) => void): () => boolean;
|
|
72
|
+
getStatus(): "connected" | "disconnected";
|
|
73
|
+
getSessionId(): string | null;
|
|
74
|
+
private sendMessage;
|
|
75
|
+
private flushQueue;
|
|
76
|
+
private resubscribeAll;
|
|
77
|
+
private getQueryId;
|
|
78
|
+
subscribe(queryName: string, args: any, onUpdate: (data: any) => void): () => void;
|
|
79
|
+
fetch(name: string, args: any): Promise<any>;
|
|
80
|
+
mutate(name: string, args: any): Promise<any>;
|
|
81
|
+
close(): void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { ArchlastClient, type ArchlastClientOptions };
|