@insforge/sdk 0.0.23 → 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 +1 -1
- package/dist/index.d.mts +0 -472
- package/dist/index.d.ts +0 -472
- package/dist/index.js +0 -893
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -857
- package/dist/index.mjs.map +0 -1
package/package.json
CHANGED
package/dist/index.d.mts
DELETED
|
@@ -1,472 +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
|
-
* 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
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Main InsForge SDK Client
|
|
413
|
-
*
|
|
414
|
-
* @example
|
|
415
|
-
* ```typescript
|
|
416
|
-
* import { InsForgeClient } from '@insforge/sdk';
|
|
417
|
-
*
|
|
418
|
-
* const client = new InsForgeClient({
|
|
419
|
-
* baseUrl: 'http://localhost:7130'
|
|
420
|
-
* });
|
|
421
|
-
*
|
|
422
|
-
* // Authentication
|
|
423
|
-
* const session = await client.auth.register({
|
|
424
|
-
* email: 'user@example.com',
|
|
425
|
-
* password: 'password123',
|
|
426
|
-
* name: 'John Doe'
|
|
427
|
-
* });
|
|
428
|
-
*
|
|
429
|
-
* // Database operations
|
|
430
|
-
* const { data, error } = await client.database
|
|
431
|
-
* .from('posts')
|
|
432
|
-
* .select('*')
|
|
433
|
-
* .eq('user_id', session.user.id)
|
|
434
|
-
* .order('created_at', { ascending: false })
|
|
435
|
-
* .limit(10);
|
|
436
|
-
*
|
|
437
|
-
* // Insert data
|
|
438
|
-
* const { data: newPost } = await client.database
|
|
439
|
-
* .from('posts')
|
|
440
|
-
* .insert({ title: 'Hello', content: 'World' })
|
|
441
|
-
* .single();
|
|
442
|
-
* ```
|
|
443
|
-
*/
|
|
444
|
-
declare class InsForgeClient {
|
|
445
|
-
private http;
|
|
446
|
-
private tokenManager;
|
|
447
|
-
readonly auth: Auth;
|
|
448
|
-
readonly database: Database;
|
|
449
|
-
readonly storage: Storage;
|
|
450
|
-
readonly ai: AI;
|
|
451
|
-
constructor(config?: InsForgeConfig);
|
|
452
|
-
/**
|
|
453
|
-
* Get the underlying HTTP client for custom requests
|
|
454
|
-
*
|
|
455
|
-
* @example
|
|
456
|
-
* ```typescript
|
|
457
|
-
* const httpClient = client.getHttpClient();
|
|
458
|
-
* const customData = await httpClient.get('/api/custom-endpoint');
|
|
459
|
-
* ```
|
|
460
|
-
*/
|
|
461
|
-
getHttpClient(): HttpClient;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service
|
|
466
|
-
*
|
|
467
|
-
* @packageDocumentation
|
|
468
|
-
*/
|
|
469
|
-
|
|
470
|
-
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
471
|
-
|
|
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 };
|