@insforge/sdk 0.0.24 → 0.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insforge/sdk",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "TypeScript SDK for InsForge Backend-as-a-Service platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/dist/index.d.mts DELETED
@@ -1,463 +0,0 @@
1
- import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, StorageFileSchema, ListObjectsResponseSchema } from '@insforge/shared-schemas';
2
- export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
3
- import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
-
5
- /**
6
- * InsForge SDK Types - only SDK-specific types here
7
- * Use @insforge/shared-schemas directly for API types
8
- */
9
-
10
- interface InsForgeConfig {
11
- /**
12
- * The base URL of the InsForge backend API
13
- * @default "http://localhost:7130"
14
- */
15
- baseUrl?: string;
16
- /**
17
- * API key (optional)
18
- * Can be used for server-side operations or specific use cases
19
- */
20
- apiKey?: string;
21
- /**
22
- * Custom fetch implementation (useful for Node.js environments)
23
- */
24
- fetch?: typeof fetch;
25
- /**
26
- * Storage adapter for persisting tokens
27
- */
28
- storage?: TokenStorage;
29
- /**
30
- * Whether to automatically refresh tokens before they expire
31
- * @default true
32
- */
33
- autoRefreshToken?: boolean;
34
- /**
35
- * Whether to persist session in storage
36
- * @default true
37
- */
38
- persistSession?: boolean;
39
- /**
40
- * Custom headers to include with every request
41
- */
42
- headers?: Record<string, string>;
43
- }
44
- interface TokenStorage {
45
- getItem(key: string): string | null | Promise<string | null>;
46
- setItem(key: string, value: string): void | Promise<void>;
47
- removeItem(key: string): void | Promise<void>;
48
- }
49
- interface AuthSession {
50
- user: UserSchema;
51
- accessToken: string;
52
- expiresAt?: Date;
53
- }
54
- interface ApiError {
55
- error: string;
56
- message: string;
57
- statusCode: number;
58
- nextActions?: string;
59
- }
60
- declare class InsForgeError extends Error {
61
- statusCode: number;
62
- error: string;
63
- nextActions?: string;
64
- constructor(message: string, statusCode: number, error: string, nextActions?: string);
65
- static fromApiError(apiError: ApiError): InsForgeError;
66
- }
67
-
68
- interface RequestOptions extends RequestInit {
69
- params?: Record<string, string>;
70
- }
71
- declare class HttpClient {
72
- readonly baseUrl: string;
73
- readonly fetch: typeof fetch;
74
- private defaultHeaders;
75
- constructor(config: InsForgeConfig);
76
- private buildUrl;
77
- request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
78
- get<T>(path: string, options?: RequestOptions): Promise<T>;
79
- post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
80
- put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
81
- patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
82
- delete<T>(path: string, options?: RequestOptions): Promise<T>;
83
- setAuthToken(token: string | null): void;
84
- getHeaders(): Record<string, string>;
85
- }
86
-
87
- declare class TokenManager {
88
- private storage;
89
- constructor(storage?: TokenStorage);
90
- saveSession(session: AuthSession): void;
91
- getSession(): AuthSession | null;
92
- getAccessToken(): string | null;
93
- clearSession(): void;
94
- }
95
-
96
- /**
97
- * Auth module for InsForge SDK
98
- * Uses shared schemas for type safety
99
- */
100
-
101
- declare class Auth {
102
- private http;
103
- private tokenManager;
104
- private database;
105
- constructor(http: HttpClient, tokenManager: TokenManager);
106
- /**
107
- * Automatically detect and handle OAuth callback parameters in the URL
108
- * This runs on initialization to seamlessly complete the OAuth flow
109
- * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
110
- */
111
- private detectOAuthCallback;
112
- /**
113
- * Sign up a new user
114
- */
115
- signUp(request: CreateUserRequest): Promise<{
116
- data: CreateUserResponse | null;
117
- error: InsForgeError | null;
118
- }>;
119
- /**
120
- * Sign in with email and password
121
- */
122
- signInWithPassword(request: CreateSessionRequest): Promise<{
123
- data: CreateSessionResponse | null;
124
- error: InsForgeError | null;
125
- }>;
126
- /**
127
- * Sign in with OAuth provider
128
- */
129
- signInWithOAuth(options: {
130
- provider: 'google' | 'github';
131
- redirectTo?: string;
132
- skipBrowserRedirect?: boolean;
133
- }): Promise<{
134
- data: {
135
- url?: string;
136
- provider?: string;
137
- };
138
- error: InsForgeError | null;
139
- }>;
140
- /**
141
- * Sign out the current user
142
- */
143
- signOut(): Promise<{
144
- error: InsForgeError | null;
145
- }>;
146
- /**
147
- * Get the current user with full profile information
148
- * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)
149
- */
150
- getCurrentUser(): Promise<{
151
- data: {
152
- user: any;
153
- profile: any;
154
- } | null;
155
- error: any | null;
156
- }>;
157
- /**
158
- * Get any user's profile by ID
159
- * Returns profile information from the users table (nickname, avatar_url, bio, etc.)
160
- */
161
- getProfile(userId: string): Promise<{
162
- data: any | null;
163
- error: any | null;
164
- }>;
165
- /**
166
- * Get the current session (only session data, no API call)
167
- * Returns the stored JWT token and basic user info from local storage
168
- */
169
- getCurrentSession(): Promise<{
170
- data: {
171
- session: AuthSession | null;
172
- };
173
- error: InsForgeError | null;
174
- }>;
175
- /**
176
- * Set/Update the current user's profile
177
- * Updates profile information in the users table (nickname, avatar_url, bio, etc.)
178
- */
179
- setProfile(profile: {
180
- nickname?: string;
181
- avatar_url?: string;
182
- bio?: string;
183
- birthday?: string;
184
- [key: string]: any;
185
- }): Promise<{
186
- data: any | null;
187
- error: any | null;
188
- }>;
189
- }
190
-
191
- /**
192
- * Database client using postgrest-js
193
- * Drop-in replacement with FULL PostgREST capabilities
194
- */
195
- declare class Database {
196
- private postgrest;
197
- constructor(httpClient: HttpClient, tokenManager: TokenManager);
198
- /**
199
- * Create a query builder for a table
200
- *
201
- * @example
202
- * // Basic query
203
- * const { data, error } = await client.database
204
- * .from('posts')
205
- * .select('*')
206
- * .eq('user_id', userId);
207
- *
208
- * // With count (Supabase style!)
209
- * const { data, error, count } = await client.database
210
- * .from('posts')
211
- * .select('*', { count: 'exact' })
212
- * .range(0, 9);
213
- *
214
- * // Just get count, no data
215
- * const { count } = await client.database
216
- * .from('posts')
217
- * .select('*', { count: 'exact', head: true });
218
- *
219
- * // Complex queries with OR
220
- * const { data } = await client.database
221
- * .from('posts')
222
- * .select('*, users!inner(*)')
223
- * .or('status.eq.active,status.eq.pending');
224
- *
225
- * // All features work:
226
- * - Nested selects
227
- * - Foreign key expansion
228
- * - OR/AND/NOT conditions
229
- * - Count with head
230
- * - Range pagination
231
- * - Upserts
232
- */
233
- from(table: string): _supabase_postgrest_js.PostgrestQueryBuilder<any, any, any, string, unknown>;
234
- }
235
-
236
- /**
237
- * Storage module for InsForge SDK
238
- * Handles file uploads, downloads, and bucket management
239
- */
240
-
241
- interface StorageResponse<T> {
242
- data: T | null;
243
- error: InsForgeError | null;
244
- }
245
- /**
246
- * Storage bucket operations
247
- */
248
- declare class StorageBucket {
249
- private bucketName;
250
- private http;
251
- constructor(bucketName: string, http: HttpClient);
252
- /**
253
- * Upload a file with a specific key
254
- * @param path - The object key/path
255
- * @param file - File or Blob to upload
256
- */
257
- upload(path: string, file: File | Blob): Promise<StorageResponse<StorageFileSchema>>;
258
- /**
259
- * Upload a file with auto-generated key
260
- * @param file - File or Blob to upload
261
- */
262
- uploadAuto(file: File | Blob): Promise<StorageResponse<StorageFileSchema>>;
263
- /**
264
- * Download a file
265
- * @param path - The object key/path
266
- * Returns the file as a Blob
267
- */
268
- download(path: string): Promise<{
269
- data: Blob | null;
270
- error: InsForgeError | null;
271
- }>;
272
- /**
273
- * Get public URL for a file
274
- * @param path - The object key/path
275
- */
276
- getPublicUrl(path: string): string;
277
- /**
278
- * List objects in the bucket
279
- * @param prefix - Filter by key prefix
280
- * @param search - Search in file names
281
- * @param limit - Maximum number of results (default: 100, max: 1000)
282
- * @param offset - Number of results to skip
283
- */
284
- list(options?: {
285
- prefix?: string;
286
- search?: string;
287
- limit?: number;
288
- offset?: number;
289
- }): Promise<StorageResponse<ListObjectsResponseSchema>>;
290
- /**
291
- * Delete a file
292
- * @param path - The object key/path
293
- */
294
- remove(path: string): Promise<StorageResponse<{
295
- message: string;
296
- }>>;
297
- }
298
- /**
299
- * Storage module for file operations
300
- */
301
- declare class Storage {
302
- private http;
303
- constructor(http: HttpClient);
304
- /**
305
- * Get a bucket instance for operations
306
- * @param bucketName - Name of the bucket
307
- */
308
- from(bucketName: string): StorageBucket;
309
- }
310
-
311
- /**
312
- * AI Module for Insforge SDK
313
- * Response format roughly matches OpenAI SDK for compatibility
314
- *
315
- * The backend handles all the complexity of different AI providers
316
- * and returns a unified format. This SDK transforms responses to match OpenAI-like format.
317
- */
318
-
319
- declare class AI {
320
- private http;
321
- readonly chat: Chat;
322
- readonly images: Images;
323
- constructor(http: HttpClient);
324
- }
325
- declare class Chat {
326
- readonly completions: ChatCompletions;
327
- constructor(http: HttpClient);
328
- }
329
- declare class ChatCompletions {
330
- private http;
331
- constructor(http: HttpClient);
332
- /**
333
- * Create a chat completion - OpenAI-like response format
334
- *
335
- * @example
336
- * ```typescript
337
- * // Non-streaming
338
- * const completion = await client.ai.chat.completions.create({
339
- * model: 'gpt-4',
340
- * messages: [{ role: 'user', content: 'Hello!' }]
341
- * });
342
- * console.log(completion.choices[0].message.content);
343
- *
344
- * // Streaming - returns async iterable
345
- * const stream = await client.ai.chat.completions.create({
346
- * model: 'gpt-4',
347
- * messages: [{ role: 'user', content: 'Tell me a story' }],
348
- * stream: true
349
- * });
350
- *
351
- * for await (const chunk of stream) {
352
- * if (chunk.choices[0]?.delta?.content) {
353
- * process.stdout.write(chunk.choices[0].delta.content);
354
- * }
355
- * }
356
- * ```
357
- */
358
- create(params: {
359
- model: string;
360
- messages: Array<{
361
- role: 'user' | 'assistant' | 'system';
362
- content: string;
363
- }>;
364
- temperature?: number;
365
- maxTokens?: number;
366
- topP?: number;
367
- stream?: boolean;
368
- }): Promise<any>;
369
- /**
370
- * Parse SSE stream into async iterable of OpenAI-like chunks
371
- */
372
- private parseSSEStream;
373
- }
374
- declare class Images {
375
- private http;
376
- constructor(http: HttpClient);
377
- /**
378
- * Generate images - OpenAI-like response format
379
- *
380
- * @example
381
- * ```typescript
382
- * const response = await client.ai.images.generate({
383
- * model: 'dall-e-3',
384
- * prompt: 'A sunset over mountains',
385
- * n: 1,
386
- * size: '1024x1024'
387
- * });
388
- * console.log(response.data[0].url);
389
- * ```
390
- */
391
- generate(params: {
392
- model: string;
393
- prompt: string;
394
- n?: number;
395
- size?: string;
396
- quality?: 'standard' | 'hd';
397
- style?: 'vivid' | 'natural';
398
- response_format?: 'url' | 'b64_json';
399
- }): Promise<any>;
400
- }
401
-
402
- /**
403
- * Main InsForge SDK Client
404
- *
405
- * @example
406
- * ```typescript
407
- * import { InsForgeClient } from '@insforge/sdk';
408
- *
409
- * const client = new InsForgeClient({
410
- * baseUrl: 'http://localhost:7130'
411
- * });
412
- *
413
- * // Authentication
414
- * const session = await client.auth.register({
415
- * email: 'user@example.com',
416
- * password: 'password123',
417
- * name: 'John Doe'
418
- * });
419
- *
420
- * // Database operations
421
- * const { data, error } = await client.database
422
- * .from('posts')
423
- * .select('*')
424
- * .eq('user_id', session.user.id)
425
- * .order('created_at', { ascending: false })
426
- * .limit(10);
427
- *
428
- * // Insert data
429
- * const { data: newPost } = await client.database
430
- * .from('posts')
431
- * .insert({ title: 'Hello', content: 'World' })
432
- * .single();
433
- * ```
434
- */
435
- declare class InsForgeClient {
436
- private http;
437
- private tokenManager;
438
- readonly auth: Auth;
439
- readonly database: Database;
440
- readonly storage: Storage;
441
- readonly ai: AI;
442
- constructor(config?: InsForgeConfig);
443
- /**
444
- * Get the underlying HTTP client for custom requests
445
- *
446
- * @example
447
- * ```typescript
448
- * const httpClient = client.getHttpClient();
449
- * const customData = await httpClient.get('/api/custom-endpoint');
450
- * ```
451
- */
452
- getHttpClient(): HttpClient;
453
- }
454
-
455
- /**
456
- * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service
457
- *
458
- * @packageDocumentation
459
- */
460
-
461
- declare function createClient(config: InsForgeConfig): InsForgeClient;
462
-
463
- export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };