@insforge/sdk 0.0.20 → 0.0.22

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.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, StorageFileSchema, ListObjectsResponseSchema } from '@insforge/shared-schemas';
2
2
  export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
3
+ import * as _supabase_postgrest_js from '@supabase/postgrest-js';
3
4
 
4
5
  /**
5
6
  * InsForge SDK Types - only SDK-specific types here
@@ -151,7 +152,7 @@ declare class Auth {
151
152
  user: any;
152
153
  profile: any;
153
154
  } | null;
154
- error: InsForgeError | null;
155
+ error: any | null;
155
156
  }>;
156
157
  /**
157
158
  * Get any user's profile by ID
@@ -159,7 +160,7 @@ declare class Auth {
159
160
  */
160
161
  getProfile(userId: string): Promise<{
161
162
  data: any | null;
162
- error: InsForgeError | null;
163
+ error: any | null;
163
164
  }>;
164
165
  /**
165
166
  * Get the current session (only session data, no API call)
@@ -183,187 +184,53 @@ declare class Auth {
183
184
  [key: string]: any;
184
185
  }): Promise<{
185
186
  data: any | null;
186
- error: InsForgeError | null;
187
+ error: any | null;
187
188
  }>;
188
189
  }
189
190
 
190
191
  /**
191
- * Database module for InsForge SDK
192
- * Supabase-style query builder for PostgREST operations
193
- */
194
-
195
- interface DatabaseResponse<T> {
196
- data: T | null;
197
- error: InsForgeError | null;
198
- count?: number;
199
- }
200
- /**
201
- * Query builder for database operations
202
- * Uses method chaining like Supabase
203
- */
204
- declare class QueryBuilder<T = any> {
205
- private table;
206
- private http;
207
- private method;
208
- private headers;
209
- private queryParams;
210
- private body?;
211
- constructor(table: string, http: HttpClient);
212
- /**
213
- * Perform a SELECT query
214
- * For mutations (insert/update/delete), this enables returning data
215
- * @param columns - Columns to select (default: '*')
216
- * @example
217
- * .select('*')
218
- * .select('id, title, content')
219
- * .select('*, users!inner(*)') // Join with users table
220
- * .select('*, profile:profiles(*)') // Join with alias
221
- * .insert({ title: 'New' }).select() // Returns inserted data
222
- */
223
- select(columns?: string): this;
224
- /**
225
- * Perform an INSERT
226
- * @param values - Single object or array of objects
227
- * @param options - { upsert: true } for upsert behavior
228
- * @example
229
- * .insert({ title: 'Hello', content: 'World' }).select()
230
- * .insert([{ title: 'Post 1' }, { title: 'Post 2' }]).select()
231
- */
232
- insert(values: Partial<T> | Partial<T>[], options?: {
233
- upsert?: boolean;
234
- }): this;
235
- /**
236
- * Perform an UPDATE
237
- * @param values - Object with fields to update
238
- * @example
239
- * .update({ title: 'Updated Title' }).select()
240
- */
241
- update(values: Partial<T>): this;
242
- /**
243
- * Perform a DELETE
244
- * @example
245
- * .delete().select()
246
- */
247
- delete(): this;
248
- /**
249
- * Perform an UPSERT
250
- * @param values - Single object or array of objects
251
- * @example
252
- * .upsert({ id: 1, title: 'Hello' })
253
- */
254
- upsert(values: Partial<T> | Partial<T>[]): this;
255
- /**
256
- * Filter by column equal to value
257
- * @example .eq('id', 123)
258
- */
259
- eq(column: string, value: any): this;
260
- /**
261
- * Filter by column not equal to value
262
- * @example .neq('status', 'draft')
263
- */
264
- neq(column: string, value: any): this;
265
- /**
266
- * Filter by column greater than value
267
- * @example .gt('age', 18)
268
- */
269
- gt(column: string, value: any): this;
270
- /**
271
- * Filter by column greater than or equal to value
272
- * @example .gte('price', 100)
273
- */
274
- gte(column: string, value: any): this;
275
- /**
276
- * Filter by column less than value
277
- * @example .lt('stock', 10)
278
- */
279
- lt(column: string, value: any): this;
280
- /**
281
- * Filter by column less than or equal to value
282
- * @example .lte('discount', 50)
283
- */
284
- lte(column: string, value: any): this;
285
- /**
286
- * Filter by pattern matching (case-sensitive)
287
- * @example .like('email', '%@gmail.com')
288
- */
289
- like(column: string, pattern: string): this;
290
- /**
291
- * Filter by pattern matching (case-insensitive)
292
- * @example .ilike('name', '%john%')
293
- */
294
- ilike(column: string, pattern: string): this;
295
- /**
296
- * Filter by checking if column is a value
297
- * @example .is('deleted_at', null)
298
- */
299
- is(column: string, value: null | boolean): this;
300
- /**
301
- * Filter by checking if value is in array
302
- * @example .in('status', ['active', 'pending'])
303
- */
304
- in(column: string, values: any[]): this;
305
- /**
306
- * Order by column
307
- * @example
308
- * .order('created_at') // ascending
309
- * .order('created_at', { ascending: false }) // descending
310
- */
311
- order(column: string, options?: {
312
- ascending?: boolean;
313
- }): this;
314
- /**
315
- * Limit the number of rows returned
316
- * @example .limit(10)
317
- */
318
- limit(count: number): this;
319
- /**
320
- * Return results from an offset
321
- * @example .offset(20)
322
- */
323
- offset(count: number): this;
324
- /**
325
- * Set a range of rows to return
326
- * @example .range(0, 9) // First 10 rows
327
- */
328
- range(from: number, to: number): this;
329
- /**
330
- * Return a single object instead of array
331
- * @example .single()
332
- */
333
- single(): this;
334
- /**
335
- * Get the total count (use with select)
336
- * @example .select('*', { count: 'exact' })
337
- */
338
- count(algorithm?: 'exact' | 'planned' | 'estimated'): this;
339
- /**
340
- * Execute the query and return results
341
- */
342
- execute(): Promise<DatabaseResponse<T>>;
343
- /**
344
- * Make QueryBuilder thenable for async/await
345
- */
346
- then<TResult1 = DatabaseResponse<T>, TResult2 = never>(onfulfilled?: ((value: DatabaseResponse<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
347
- }
348
- /**
349
- * Database client for InsForge SDK
350
- * Provides Supabase-style interface
192
+ * Database client using postgrest-js
193
+ * Drop-in replacement with FULL PostgREST capabilities
351
194
  */
352
195
  declare class Database {
353
- private http;
354
- constructor(http: HttpClient);
196
+ private postgrest;
197
+ constructor(httpClient: HttpClient, tokenManager: TokenManager);
355
198
  /**
356
199
  * Create a query builder for a table
357
- * @param table - The table name
200
+ *
358
201
  * @example
202
+ * // Basic query
359
203
  * const { data, error } = await client.database
360
204
  * .from('posts')
361
205
  * .select('*')
362
- * .eq('user_id', userId)
363
- * .order('created_at', { ascending: false })
364
- * .limit(10);
365
- */
366
- from<T = any>(table: string): QueryBuilder<T>;
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>;
367
234
  }
368
235
 
369
236
  /**
@@ -441,6 +308,106 @@ declare class Storage {
441
308
  from(bucketName: string): StorageBucket;
442
309
  }
443
310
 
311
+ /**
312
+ * AI Module for Insforge SDK
313
+ * Wrapper for AI endpoints that follows OpenAI-like patterns
314
+ *
315
+ * The backend handles all the complexity of different AI providers
316
+ * and returns a unified format. This SDK just calls the endpoints.
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
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * // Non-streaming
338
+ * const response = await client.ai.chat.completions.create({
339
+ * model: 'gpt-4',
340
+ * messages: [{ role: 'user', content: 'Hello!' }]
341
+ * });
342
+ * console.log(response.response);
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 event of stream) {
352
+ * if (event.chunk) {
353
+ * process.stdout.write(event.chunk);
354
+ * }
355
+ * if (event.done) {
356
+ * console.log('Stream complete!');
357
+ * }
358
+ * }
359
+ * ```
360
+ */
361
+ create(params: {
362
+ model: string;
363
+ messages?: Array<{
364
+ role: 'user' | 'assistant' | 'system';
365
+ content: string;
366
+ }>;
367
+ message?: string;
368
+ temperature?: number;
369
+ maxTokens?: number;
370
+ topP?: number;
371
+ systemPrompt?: string;
372
+ stream?: boolean;
373
+ }): Promise<any>;
374
+ /**
375
+ * Parse SSE stream into async iterable of parsed events
376
+ * Users don't need to handle SSE parsing themselves
377
+ */
378
+ private parseSSEStream;
379
+ }
380
+ declare class Images {
381
+ private http;
382
+ constructor(http: HttpClient);
383
+ /**
384
+ * Generate images
385
+ *
386
+ * @example
387
+ * ```typescript
388
+ * const response = await client.ai.images.generate({
389
+ * model: 'dall-e-3',
390
+ * prompt: 'A sunset over mountains',
391
+ * numImages: 1,
392
+ * size: '1024x1024'
393
+ * });
394
+ * console.log(response.images[0].url);
395
+ * ```
396
+ */
397
+ generate(params: {
398
+ model: string;
399
+ prompt: string;
400
+ negativePrompt?: string;
401
+ width?: number;
402
+ height?: number;
403
+ numImages?: number;
404
+ quality?: 'standard' | 'hd';
405
+ style?: 'vivid' | 'natural';
406
+ responseFormat?: 'url' | 'b64_json';
407
+ size?: string;
408
+ }): Promise<unknown>;
409
+ }
410
+
444
411
  /**
445
412
  * Main InsForge SDK Client
446
413
  *
@@ -480,19 +447,8 @@ declare class InsForgeClient {
480
447
  readonly auth: Auth;
481
448
  readonly database: Database;
482
449
  readonly storage: Storage;
450
+ readonly ai: AI;
483
451
  constructor(config?: InsForgeConfig);
484
- /**
485
- * Set a custom API key for authentication
486
- * This is useful for server-to-server communication
487
- *
488
- * @param apiKey - The API key (should start with 'ik_')
489
- *
490
- * @example
491
- * ```typescript
492
- * client.setApiKey('ik_your_api_key_here');
493
- * ```
494
- */
495
- setApiKey(apiKey: string): void;
496
452
  /**
497
453
  * Get the underlying HTTP client for custom requests
498
454
  *
@@ -513,4 +469,4 @@ declare class InsForgeClient {
513
469
 
514
470
  declare function createClient(config: InsForgeConfig): InsForgeClient;
515
471
 
516
- export { type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type DatabaseResponse, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, QueryBuilder, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };
472
+ 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 };