@insforge/sdk 1.0.3-refresh.1 → 1.0.5-dev.0

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/README.md CHANGED
@@ -1,249 +1,259 @@
1
- # insforge-sdk-js
2
-
3
- [![npm version](https://img.shields.io/npm/v/@insforge/sdk.svg)](https://www.npmjs.com/package/@insforge/sdk)
4
- [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
-
6
- Official TypeScript/JavaScript SDK for [InsForge](https://github.com/InsForge/InsForge) - A powerful, open-source Backend-as-a-Service (BaaS) platform.
7
-
8
- ## Features
9
-
10
- - **Authentication** - Email/password, OAuth (Google, GitHub), session management
11
- - **Database** - Full PostgreSQL database access with PostgREST
12
- - **Storage** - File upload and management with S3-compatible storage
13
- - **Edge Functions** - Serverless function invocation
14
- - **AI Integration** - Built-in AI capabilities
15
- - **TypeScript** - Full TypeScript support with type definitions
16
- - **Automatic OAuth Handling** - Seamless OAuth callback detection
17
-
18
- ## Installation
19
-
20
- ```bash
21
- npm install @insforge/sdk
22
- ```
23
-
24
- Or with yarn:
25
-
26
- ```bash
27
- yarn add @insforge/sdk
28
- ```
29
-
30
- ## Quick Start
31
-
32
- ### Initialize the Client
33
-
34
- ```javascript
35
- import { createClient } from '@insforge/sdk';
36
-
37
- const insforge = createClient({
38
- baseUrl: 'http://localhost:7130' // Your InsForge backend URL
39
- });
40
- ```
41
-
42
- ### Authentication
43
-
44
- ```javascript
45
- // Sign up a new user
46
- const { data, error } = await insforge.auth.signUp({
47
- email: 'user@example.com',
48
- password: 'securePassword123',
49
- name: 'John Doe' // optional
50
- });
51
-
52
- // Sign in with email/password
53
- const { data, error } = await insforge.auth.signInWithPassword({
54
- email: 'user@example.com',
55
- password: 'securePassword123'
56
- });
57
-
58
- // OAuth authentication (Google, GitHub)
59
- await insforge.auth.signInWithOAuth({
60
- provider: 'google',
61
- redirectTo: 'http://localhost:3000/dashboard'
62
- });
63
-
64
- // Get current user
65
- const { data: user } = await insforge.auth.getCurrentUser();
66
-
67
- // Sign out
68
- await insforge.auth.signOut();
69
- ```
70
-
71
- ### Database Operations
72
-
73
- ```javascript
74
- // Insert data
75
- const { data, error } = await insforge.database
76
- .from('posts')
77
- .insert([
78
- { title: 'My First Post', content: 'Hello World!' }
79
- ]);
80
-
81
- // Query data
82
- const { data, error } = await insforge.database
83
- .from('posts')
84
- .select('*')
85
- .eq('author_id', userId);
86
-
87
- // Update data
88
- const { data, error } = await insforge.database
89
- .from('posts')
90
- .update({ title: 'Updated Title' })
91
- .eq('id', postId);
92
-
93
- // Delete data
94
- const { data, error } = await insforge.database
95
- .from('posts')
96
- .delete()
97
- .eq('id', postId);
98
- ```
99
-
100
- ### File Storage
101
-
102
- ```javascript
103
- // Upload a file
104
- const file = document.querySelector('input[type="file"]').files[0];
105
- const { data, error } = await insforge.storage
106
- .from('avatars')
107
- .upload(file);
108
-
109
- // Download a file
110
- const { data, error } = await insforge.storage
111
- .from('avatars')
112
- .download('user-avatar.png');
113
-
114
- // Delete a file
115
- const { data, error } = await insforge.storage
116
- .from('avatars')
117
- .remove(['user-avatar.png']);
118
-
119
- // List files
120
- const { data, error } = await insforge.storage
121
- .from('avatars')
122
- .list();
123
- ```
124
-
125
- ### Edge Functions
126
-
127
- ```javascript
128
- // Invoke an edge function
129
- const { data, error } = await insforge.functions.invoke('my-function', {
130
- body: { key: 'value' }
131
- });
132
- ```
133
-
134
- ### AI Integration
135
-
136
- ```javascript
137
- // Generate text completion
138
- const { data, error } = await insforge.ai.completion({
139
- model: 'gpt-3.5-turbo',
140
- prompt: 'Write a hello world program'
141
- });
142
-
143
- // Analyze an image
144
- const { data, error } = await insforge.ai.vision({
145
- imageUrl: 'https://example.com/image.jpg',
146
- prompt: 'Describe this image'
147
- });
148
- ```
149
-
150
- ## Documentation
151
-
152
- For complete API reference and advanced usage, see:
153
-
154
- - **[SDK Reference](./SDK-REFERENCE.md)** - Complete API documentation
155
- - **[InsForge Main Repository](https://github.com/InsForge/InsForge)** - Backend platform and setup guides
156
-
157
- ## Configuration
158
-
159
- The SDK supports the following configuration options:
160
-
161
- ```javascript
162
- const insforge = createClient({
163
- baseUrl: 'http://localhost:7130', // Required: Your InsForge backend URL
164
- storageStrategy: 'localStorage' // Optional: 'localStorage' or 'memory' (default: 'localStorage')
165
- });
166
- ```
167
-
168
- ## TypeScript Support
169
-
170
- The SDK is written in TypeScript and provides full type definitions:
171
-
172
- ```typescript
173
- import { createClient, InsForgeClient, User, Session } from '@insforge/sdk';
174
-
175
- const insforge: InsForgeClient = createClient({
176
- baseUrl: 'http://localhost:7130'
177
- });
178
-
179
- // Type-safe API calls
180
- const response: { data: User | null; error: Error | null } =
181
- await insforge.auth.getCurrentUser();
182
- ```
183
-
184
- ## Error Handling
185
-
186
- All SDK methods return a consistent response format:
187
-
188
- ```javascript
189
- const { data, error } = await insforge.auth.signUp({...});
190
-
191
- if (error) {
192
- console.error('Error:', error.message);
193
- console.error('Status:', error.statusCode);
194
- } else {
195
- console.log('Success:', data);
196
- }
197
- ```
198
-
199
- ## Browser Support
200
-
201
- The SDK works in all modern browsers that support:
202
- - ES6+ features
203
- - Fetch API
204
- - LocalStorage (for session management)
205
-
206
- For Node.js environments, ensure you're using Node.js 18 or higher.
207
-
208
- ## Contributing
209
-
210
- We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
211
-
212
- ### Development Setup
213
-
214
- ```bash
215
- # Clone the repository
216
- git clone https://github.com/InsForge/insforge-sdk-js.git
217
- cd insforge-sdk-js
218
-
219
- # Install dependencies
220
- npm install
221
-
222
- # Build the SDK
223
- npm run build
224
-
225
- # Run tests
226
- npm test
227
-
228
- # Run integration tests
229
- npm run test:integration
230
- ```
231
-
232
- ## License
233
-
234
- This project is licensed under the Apache License 2.0 - see the [LICENSE](./LICENSE) file for details.
235
-
236
- ## Community & Support
237
-
238
- - **GitHub Issues**: [Report bugs or request features](https://github.com/InsForge/insforge-sdk-js/issues)
239
- - **Documentation**: [https://docs.insforge.com](https://docs.insforge.com)
240
- - **Main Repository**: [InsForge Backend Platform](https://github.com/InsForge/InsForge)
241
-
242
- ## Related Projects
243
-
244
- - **[InsForge](https://github.com/InsForge/InsForge)** - The main InsForge backend platform
245
- - **[InsForge MCP](https://github.com/InsForge/insforge-mcp)** - Model Context Protocol server for InsForge
246
-
247
- ---
248
-
249
- Built with ❤️ by the InsForge team
1
+ # insforge-sdk-js
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@insforge/sdk.svg)](https://www.npmjs.com/package/@insforge/sdk)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+
6
+ Official TypeScript/JavaScript SDK for [InsForge](https://github.com/InsForge/InsForge) - A powerful, open-source Backend-as-a-Service (BaaS) platform.
7
+
8
+ ## Features
9
+
10
+ - **Authentication** - Email/password, OAuth (Google, GitHub), session management
11
+ - **Database** - Full PostgreSQL database access with PostgREST
12
+ - **Storage** - File upload and management with S3-compatible storage
13
+ - **Edge Functions** - Serverless function invocation
14
+ - **AI Integration** - Built-in AI capabilities
15
+ - **TypeScript** - Full TypeScript support with type definitions
16
+ - **Automatic OAuth Handling** - Seamless OAuth callback detection
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @insforge/sdk
22
+ ```
23
+
24
+ Or with yarn:
25
+
26
+ ```bash
27
+ yarn add @insforge/sdk
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ### Initialize the Client
33
+
34
+ ```javascript
35
+ import { createClient } from '@insforge/sdk';
36
+
37
+ const insforge = createClient({
38
+ baseUrl: 'http://localhost:7130' // Your InsForge backend URL
39
+ });
40
+ ```
41
+
42
+ ### Authentication
43
+
44
+ ```javascript
45
+ // Sign up a new user
46
+ const { data, error } = await insforge.auth.signUp({
47
+ email: 'user@example.com',
48
+ password: 'securePassword123',
49
+ name: 'John Doe' // optional
50
+ });
51
+
52
+ // Sign in with email/password
53
+ const { data, error } = await insforge.auth.signInWithPassword({
54
+ email: 'user@example.com',
55
+ password: 'securePassword123'
56
+ });
57
+
58
+ // OAuth authentication (Google, GitHub)
59
+ await insforge.auth.signInWithOAuth({
60
+ provider: 'google',
61
+ redirectTo: 'http://localhost:3000/dashboard'
62
+ });
63
+
64
+ // Get current user
65
+ const { data: user } = await insforge.auth.getCurrentUser();
66
+
67
+ // Get any user's profile by ID (public endpoint)
68
+ const { data: profile, error } = await insforge.auth.getProfile('user-id-here');
69
+
70
+ // Update current user's profile (requires authentication)
71
+ const { data: updatedProfile, error } = await insforge.auth.setProfile({
72
+ displayName: 'John Doe',
73
+ bio: 'Software developer',
74
+ avatarUrl: 'https://example.com/avatar.jpg'
75
+ });
76
+
77
+ // Sign out
78
+ await insforge.auth.signOut();
79
+ ```
80
+
81
+ ### Database Operations
82
+
83
+ ```javascript
84
+ // Insert data
85
+ const { data, error } = await insforge.database
86
+ .from('posts')
87
+ .insert([
88
+ { title: 'My First Post', content: 'Hello World!' }
89
+ ]);
90
+
91
+ // Query data
92
+ const { data, error } = await insforge.database
93
+ .from('posts')
94
+ .select('*')
95
+ .eq('author_id', userId);
96
+
97
+ // Update data
98
+ const { data, error } = await insforge.database
99
+ .from('posts')
100
+ .update({ title: 'Updated Title' })
101
+ .eq('id', postId);
102
+
103
+ // Delete data
104
+ const { data, error } = await insforge.database
105
+ .from('posts')
106
+ .delete()
107
+ .eq('id', postId);
108
+ ```
109
+
110
+ ### File Storage
111
+
112
+ ```javascript
113
+ // Upload a file
114
+ const file = document.querySelector('input[type="file"]').files[0];
115
+ const { data, error } = await insforge.storage
116
+ .from('avatars')
117
+ .upload(file);
118
+
119
+ // Download a file
120
+ const { data, error } = await insforge.storage
121
+ .from('avatars')
122
+ .download('user-avatar.png');
123
+
124
+ // Delete a file
125
+ const { data, error } = await insforge.storage
126
+ .from('avatars')
127
+ .remove(['user-avatar.png']);
128
+
129
+ // List files
130
+ const { data, error } = await insforge.storage
131
+ .from('avatars')
132
+ .list();
133
+ ```
134
+
135
+ ### Edge Functions
136
+
137
+ ```javascript
138
+ // Invoke an edge function
139
+ const { data, error } = await insforge.functions.invoke('my-function', {
140
+ body: { key: 'value' }
141
+ });
142
+ ```
143
+
144
+ ### AI Integration
145
+
146
+ ```javascript
147
+ // Generate text completion
148
+ const { data, error } = await insforge.ai.completion({
149
+ model: 'gpt-3.5-turbo',
150
+ prompt: 'Write a hello world program'
151
+ });
152
+
153
+ // Analyze an image
154
+ const { data, error } = await insforge.ai.vision({
155
+ imageUrl: 'https://example.com/image.jpg',
156
+ prompt: 'Describe this image'
157
+ });
158
+ ```
159
+
160
+ ## Documentation
161
+
162
+ For complete API reference and advanced usage, see:
163
+
164
+ - **[SDK Reference](./SDK-REFERENCE.md)** - Complete API documentation
165
+ - **[InsForge Main Repository](https://github.com/InsForge/InsForge)** - Backend platform and setup guides
166
+
167
+ ## Configuration
168
+
169
+ The SDK supports the following configuration options:
170
+
171
+ ```javascript
172
+ const insforge = createClient({
173
+ baseUrl: 'http://localhost:7130', // Required: Your InsForge backend URL
174
+ storageStrategy: 'localStorage' // Optional: 'localStorage' or 'memory' (default: 'localStorage')
175
+ });
176
+ ```
177
+
178
+ ## TypeScript Support
179
+
180
+ The SDK is written in TypeScript and provides full type definitions:
181
+
182
+ ```typescript
183
+ import { createClient, InsForgeClient, User, Session } from '@insforge/sdk';
184
+
185
+ const insforge: InsForgeClient = createClient({
186
+ baseUrl: 'http://localhost:7130'
187
+ });
188
+
189
+ // Type-safe API calls
190
+ const response: { data: User | null; error: Error | null } =
191
+ await insforge.auth.getCurrentUser();
192
+ ```
193
+
194
+ ## Error Handling
195
+
196
+ All SDK methods return a consistent response format:
197
+
198
+ ```javascript
199
+ const { data, error } = await insforge.auth.signUp({...});
200
+
201
+ if (error) {
202
+ console.error('Error:', error.message);
203
+ console.error('Status:', error.statusCode);
204
+ } else {
205
+ console.log('Success:', data);
206
+ }
207
+ ```
208
+
209
+ ## Browser Support
210
+
211
+ The SDK works in all modern browsers that support:
212
+ - ES6+ features
213
+ - Fetch API
214
+ - LocalStorage (for session management)
215
+
216
+ For Node.js environments, ensure you're using Node.js 18 or higher.
217
+
218
+ ## Contributing
219
+
220
+ We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
221
+
222
+ ### Development Setup
223
+
224
+ ```bash
225
+ # Clone the repository
226
+ git clone https://github.com/InsForge/insforge-sdk-js.git
227
+ cd insforge-sdk-js
228
+
229
+ # Install dependencies
230
+ npm install
231
+
232
+ # Build the SDK
233
+ npm run build
234
+
235
+ # Run tests
236
+ npm test
237
+
238
+ # Run integration tests
239
+ npm run test:integration
240
+ ```
241
+
242
+ ## License
243
+
244
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](./LICENSE) file for details.
245
+
246
+ ## Community & Support
247
+
248
+ - **GitHub Issues**: [Report bugs or request features](https://github.com/InsForge/insforge-sdk-js/issues)
249
+ - **Documentation**: [https://docs.insforge.com](https://docs.insforge.com)
250
+ - **Main Repository**: [InsForge Backend Platform](https://github.com/InsForge/InsForge)
251
+
252
+ ## Related Projects
253
+
254
+ - **[InsForge](https://github.com/InsForge/InsForge)** - The main InsForge backend platform
255
+ - **[InsForge MCP](https://github.com/InsForge/insforge-mcp)** - Model Context Protocol server for InsForge
256
+
257
+ ---
258
+
259
+ Built with ❤️ by the InsForge team
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, VerifyEmailResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, SubscribeResponse, SocketMessage } from '@insforge/shared-schemas';
2
- export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
1
+ import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, GetProfileResponse, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, VerifyEmailResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
2
+ export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
3
3
  import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
4
 
5
5
  /**
@@ -162,29 +162,13 @@ declare class TokenManager {
162
162
  * Uses shared schemas for type safety
163
163
  */
164
164
 
165
- /**
166
- * Dynamic profile type - represents flexible profile data from database
167
- * Fields can vary based on database schema configuration.
168
- * All fields are converted from snake_case (database) to camelCase (API)
169
- */
170
- type ProfileData = Record<string, any> & {
171
- id: string;
172
- createdAt?: string;
173
- updatedAt?: string;
174
- };
175
- /**
176
- * Dynamic profile update type - for updating profile fields
177
- * Supports any fields that exist in the profile table
178
- */
179
- type UpdateProfileData = Partial<Record<string, any>>;
180
165
  declare class Auth {
181
166
  private http;
182
167
  private tokenManager;
183
- private database;
184
168
  constructor(http: HttpClient, tokenManager: TokenManager);
185
169
  /**
186
170
  * Automatically detect and handle OAuth callback parameters in the URL
187
- * This runs on initialization to seamlessly complete the OAuth flow
171
+ * This runs after initialization to seamlessly complete the OAuth flow
188
172
  * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
189
173
  */
190
174
  private detectAuthCallback;
@@ -248,22 +232,17 @@ declare class Auth {
248
232
  */
249
233
  getCurrentUser(): Promise<{
250
234
  data: {
251
- user: {
252
- id: UserIdSchema;
253
- email: EmailSchema;
254
- role: RoleSchema;
255
- };
256
- profile: ProfileData | null;
235
+ user: UserSchema;
257
236
  } | null;
258
237
  error: any | null;
259
238
  }>;
260
239
  /**
261
240
  * Get any user's profile by ID
262
- * Returns profile information from the users table (dynamic fields)
241
+ * Returns profile information from the users table
263
242
  */
264
243
  getProfile(userId: string): Promise<{
265
- data: ProfileData | null;
266
- error: any | null;
244
+ data: GetProfileResponse | null;
245
+ error: InsForgeError | null;
267
246
  }>;
268
247
  /**
269
248
  * Get the current session (only session data, no API call)
@@ -278,10 +257,11 @@ declare class Auth {
278
257
  /**
279
258
  * Set/Update the current user's profile
280
259
  * Updates profile information in the users table (supports any dynamic fields)
260
+ * Requires authentication
281
261
  */
282
- setProfile(profile: UpdateProfileData): Promise<{
283
- data: ProfileData | null;
284
- error: any | null;
262
+ setProfile(profile: Record<string, unknown>): Promise<{
263
+ data: GetProfileResponse | null;
264
+ error: InsForgeError | null;
285
265
  }>;
286
266
  /**
287
267
  * Send email verification (code or link based on config)
@@ -678,7 +658,8 @@ declare class Realtime {
678
658
  private connectPromise;
679
659
  private subscribedChannels;
680
660
  private eventListeners;
681
- constructor(baseUrl: string, tokenManager: TokenManager);
661
+ private anonKey?;
662
+ constructor(baseUrl: string, tokenManager: TokenManager, anonKey?: string);
682
663
  private notifyListeners;
683
664
  /**
684
665
  * Connect to the realtime server
@@ -761,6 +742,47 @@ declare class Realtime {
761
742
  getSubscribedChannels(): string[];
762
743
  }
763
744
 
745
+ /**
746
+ * Emails client for sending custom emails
747
+ *
748
+ * @example
749
+ * ```typescript
750
+ * // Send a simple email
751
+ * const { data, error } = await client.emails.send({
752
+ * to: 'user@example.com',
753
+ * subject: 'Welcome!',
754
+ * html: '<h1>Welcome to our platform</h1>'
755
+ * });
756
+ *
757
+ * if (error) {
758
+ * console.error('Failed to send:', error.message);
759
+ * return;
760
+ * }
761
+ * // Email sent successfully - data is {} (empty object)
762
+ *
763
+ * // Send to multiple recipients with CC
764
+ * const { data, error } = await client.emails.send({
765
+ * to: ['user1@example.com', 'user2@example.com'],
766
+ * cc: 'manager@example.com',
767
+ * subject: 'Team Update',
768
+ * html: '<p>Here is the latest update...</p>',
769
+ * replyTo: 'support@example.com'
770
+ * });
771
+ * ```
772
+ */
773
+ declare class Emails {
774
+ private http;
775
+ constructor(http: HttpClient);
776
+ /**
777
+ * Send a custom HTML email
778
+ * @param options Email options including recipients, subject, and HTML content
779
+ */
780
+ send(options: SendRawEmailRequest): Promise<{
781
+ data: SendEmailResponse | null;
782
+ error: Error | null;
783
+ }>;
784
+ }
785
+
764
786
  /**
765
787
  * Main InsForge SDK Client
766
788
  *
@@ -808,6 +830,7 @@ declare class InsForgeClient {
808
830
  readonly ai: AI;
809
831
  readonly functions: Functions;
810
832
  readonly realtime: Realtime;
833
+ readonly emails: Emails;
811
834
  constructor(config?: InsForgeConfig);
812
835
  /**
813
836
  * Get the underlying HTTP client for custom requests
@@ -829,4 +852,4 @@ declare class InsForgeClient {
829
852
 
830
853
  declare function createClient(config: InsForgeConfig): InsForgeClient;
831
854
 
832
- export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, type ProfileData, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, type UpdateProfileData, createClient, InsForgeClient as default };
855
+ export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };