@insforge/sdk 1.0.3-dev.2 → 1.0.3-refresh.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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
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';
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';
3
3
  import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
4
 
5
5
  /**
@@ -162,13 +162,29 @@ 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>>;
165
180
  declare class Auth {
166
181
  private http;
167
182
  private tokenManager;
183
+ private database;
168
184
  constructor(http: HttpClient, tokenManager: TokenManager);
169
185
  /**
170
186
  * Automatically detect and handle OAuth callback parameters in the URL
171
- * This runs after initialization to seamlessly complete the OAuth flow
187
+ * This runs on initialization to seamlessly complete the OAuth flow
172
188
  * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
173
189
  */
174
190
  private detectAuthCallback;
@@ -232,17 +248,22 @@ declare class Auth {
232
248
  */
233
249
  getCurrentUser(): Promise<{
234
250
  data: {
235
- user: UserSchema;
251
+ user: {
252
+ id: UserIdSchema;
253
+ email: EmailSchema;
254
+ role: RoleSchema;
255
+ };
256
+ profile: ProfileData | null;
236
257
  } | null;
237
258
  error: any | null;
238
259
  }>;
239
260
  /**
240
261
  * Get any user's profile by ID
241
- * Returns profile information from the users table
262
+ * Returns profile information from the users table (dynamic fields)
242
263
  */
243
264
  getProfile(userId: string): Promise<{
244
- data: GetProfileResponse | null;
245
- error: InsForgeError | null;
265
+ data: ProfileData | null;
266
+ error: any | null;
246
267
  }>;
247
268
  /**
248
269
  * Get the current session (only session data, no API call)
@@ -257,11 +278,10 @@ declare class Auth {
257
278
  /**
258
279
  * Set/Update the current user's profile
259
280
  * Updates profile information in the users table (supports any dynamic fields)
260
- * Requires authentication
261
281
  */
262
- setProfile(profile: Record<string, unknown>): Promise<{
263
- data: GetProfileResponse | null;
264
- error: InsForgeError | null;
282
+ setProfile(profile: UpdateProfileData): Promise<{
283
+ data: ProfileData | null;
284
+ error: any | null;
265
285
  }>;
266
286
  /**
267
287
  * Send email verification (code or link based on config)
@@ -741,47 +761,6 @@ declare class Realtime {
741
761
  getSubscribedChannels(): string[];
742
762
  }
743
763
 
744
- /**
745
- * Emails client for sending custom emails
746
- *
747
- * @example
748
- * ```typescript
749
- * // Send a simple email
750
- * const { data, error } = await client.emails.send({
751
- * to: 'user@example.com',
752
- * subject: 'Welcome!',
753
- * html: '<h1>Welcome to our platform</h1>'
754
- * });
755
- *
756
- * if (error) {
757
- * console.error('Failed to send:', error.message);
758
- * return;
759
- * }
760
- * // Email sent successfully - data is {} (empty object)
761
- *
762
- * // Send to multiple recipients with CC
763
- * const { data, error } = await client.emails.send({
764
- * to: ['user1@example.com', 'user2@example.com'],
765
- * cc: 'manager@example.com',
766
- * subject: 'Team Update',
767
- * html: '<p>Here is the latest update...</p>',
768
- * replyTo: 'support@example.com'
769
- * });
770
- * ```
771
- */
772
- declare class Emails {
773
- private http;
774
- constructor(http: HttpClient);
775
- /**
776
- * Send a custom HTML email
777
- * @param options Email options including recipients, subject, and HTML content
778
- */
779
- send(options: SendRawEmailRequest): Promise<{
780
- data: SendEmailResponse | null;
781
- error: Error | null;
782
- }>;
783
- }
784
-
785
764
  /**
786
765
  * Main InsForge SDK Client
787
766
  *
@@ -829,7 +808,6 @@ declare class InsForgeClient {
829
808
  readonly ai: AI;
830
809
  readonly functions: Functions;
831
810
  readonly realtime: Realtime;
832
- readonly emails: Emails;
833
811
  constructor(config?: InsForgeConfig);
834
812
  /**
835
813
  * Get the underlying HTTP client for custom requests
@@ -851,4 +829,4 @@ declare class InsForgeClient {
851
829
 
852
830
  declare function createClient(config: InsForgeConfig): InsForgeClient;
853
831
 
854
- 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
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';
3
3
  import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
4
 
5
5
  /**
@@ -162,13 +162,29 @@ 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>>;
165
180
  declare class Auth {
166
181
  private http;
167
182
  private tokenManager;
183
+ private database;
168
184
  constructor(http: HttpClient, tokenManager: TokenManager);
169
185
  /**
170
186
  * Automatically detect and handle OAuth callback parameters in the URL
171
- * This runs after initialization to seamlessly complete the OAuth flow
187
+ * This runs on initialization to seamlessly complete the OAuth flow
172
188
  * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
173
189
  */
174
190
  private detectAuthCallback;
@@ -232,17 +248,22 @@ declare class Auth {
232
248
  */
233
249
  getCurrentUser(): Promise<{
234
250
  data: {
235
- user: UserSchema;
251
+ user: {
252
+ id: UserIdSchema;
253
+ email: EmailSchema;
254
+ role: RoleSchema;
255
+ };
256
+ profile: ProfileData | null;
236
257
  } | null;
237
258
  error: any | null;
238
259
  }>;
239
260
  /**
240
261
  * Get any user's profile by ID
241
- * Returns profile information from the users table
262
+ * Returns profile information from the users table (dynamic fields)
242
263
  */
243
264
  getProfile(userId: string): Promise<{
244
- data: GetProfileResponse | null;
245
- error: InsForgeError | null;
265
+ data: ProfileData | null;
266
+ error: any | null;
246
267
  }>;
247
268
  /**
248
269
  * Get the current session (only session data, no API call)
@@ -257,11 +278,10 @@ declare class Auth {
257
278
  /**
258
279
  * Set/Update the current user's profile
259
280
  * Updates profile information in the users table (supports any dynamic fields)
260
- * Requires authentication
261
281
  */
262
- setProfile(profile: Record<string, unknown>): Promise<{
263
- data: GetProfileResponse | null;
264
- error: InsForgeError | null;
282
+ setProfile(profile: UpdateProfileData): Promise<{
283
+ data: ProfileData | null;
284
+ error: any | null;
265
285
  }>;
266
286
  /**
267
287
  * Send email verification (code or link based on config)
@@ -741,47 +761,6 @@ declare class Realtime {
741
761
  getSubscribedChannels(): string[];
742
762
  }
743
763
 
744
- /**
745
- * Emails client for sending custom emails
746
- *
747
- * @example
748
- * ```typescript
749
- * // Send a simple email
750
- * const { data, error } = await client.emails.send({
751
- * to: 'user@example.com',
752
- * subject: 'Welcome!',
753
- * html: '<h1>Welcome to our platform</h1>'
754
- * });
755
- *
756
- * if (error) {
757
- * console.error('Failed to send:', error.message);
758
- * return;
759
- * }
760
- * // Email sent successfully - data is {} (empty object)
761
- *
762
- * // Send to multiple recipients with CC
763
- * const { data, error } = await client.emails.send({
764
- * to: ['user1@example.com', 'user2@example.com'],
765
- * cc: 'manager@example.com',
766
- * subject: 'Team Update',
767
- * html: '<p>Here is the latest update...</p>',
768
- * replyTo: 'support@example.com'
769
- * });
770
- * ```
771
- */
772
- declare class Emails {
773
- private http;
774
- constructor(http: HttpClient);
775
- /**
776
- * Send a custom HTML email
777
- * @param options Email options including recipients, subject, and HTML content
778
- */
779
- send(options: SendRawEmailRequest): Promise<{
780
- data: SendEmailResponse | null;
781
- error: Error | null;
782
- }>;
783
- }
784
-
785
764
  /**
786
765
  * Main InsForge SDK Client
787
766
  *
@@ -829,7 +808,6 @@ declare class InsForgeClient {
829
808
  readonly ai: AI;
830
809
  readonly functions: Functions;
831
810
  readonly realtime: Realtime;
832
- readonly emails: Emails;
833
811
  constructor(config?: InsForgeConfig);
834
812
  /**
835
813
  * Get the underlying HTTP client for custom requests
@@ -851,4 +829,4 @@ declare class InsForgeClient {
851
829
 
852
830
  declare function createClient(config: InsForgeConfig): InsForgeClient;
853
831
 
854
- 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 };
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 };
package/dist/index.js CHANGED
@@ -23,7 +23,6 @@ __export(index_exports, {
23
23
  AI: () => AI,
24
24
  Auth: () => Auth,
25
25
  Database: () => Database,
26
- Emails: () => Emails,
27
26
  Functions: () => Functions,
28
27
  HttpClient: () => HttpClient,
29
28
  InsForgeClient: () => InsForgeClient,
@@ -329,7 +328,98 @@ var TokenManager = class {
329
328
  }
330
329
  };
331
330
 
331
+ // src/modules/database-postgrest.ts
332
+ var import_postgrest_js = require("@supabase/postgrest-js");
333
+ function createInsForgePostgrestFetch(httpClient, tokenManager) {
334
+ return async (input, init) => {
335
+ const url = typeof input === "string" ? input : input.toString();
336
+ const urlObj = new URL(url);
337
+ const tableName = urlObj.pathname.slice(1);
338
+ const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;
339
+ const token = tokenManager.getAccessToken();
340
+ const httpHeaders = httpClient.getHeaders();
341
+ const authToken = token || httpHeaders["Authorization"]?.replace("Bearer ", "");
342
+ const headers = new Headers(init?.headers);
343
+ if (authToken && !headers.has("Authorization")) {
344
+ headers.set("Authorization", `Bearer ${authToken}`);
345
+ }
346
+ const response = await fetch(insforgeUrl, {
347
+ ...init,
348
+ headers
349
+ });
350
+ return response;
351
+ };
352
+ }
353
+ var Database = class {
354
+ constructor(httpClient, tokenManager) {
355
+ this.postgrest = new import_postgrest_js.PostgrestClient("http://dummy", {
356
+ fetch: createInsForgePostgrestFetch(httpClient, tokenManager),
357
+ headers: {}
358
+ });
359
+ }
360
+ /**
361
+ * Create a query builder for a table
362
+ *
363
+ * @example
364
+ * // Basic query
365
+ * const { data, error } = await client.database
366
+ * .from('posts')
367
+ * .select('*')
368
+ * .eq('user_id', userId);
369
+ *
370
+ * // With count (Supabase style!)
371
+ * const { data, error, count } = await client.database
372
+ * .from('posts')
373
+ * .select('*', { count: 'exact' })
374
+ * .range(0, 9);
375
+ *
376
+ * // Just get count, no data
377
+ * const { count } = await client.database
378
+ * .from('posts')
379
+ * .select('*', { count: 'exact', head: true });
380
+ *
381
+ * // Complex queries with OR
382
+ * const { data } = await client.database
383
+ * .from('posts')
384
+ * .select('*, users!inner(*)')
385
+ * .or('status.eq.active,status.eq.pending');
386
+ *
387
+ * // All features work:
388
+ * - Nested selects
389
+ * - Foreign key expansion
390
+ * - OR/AND/NOT conditions
391
+ * - Count with head
392
+ * - Range pagination
393
+ * - Upserts
394
+ */
395
+ from(table) {
396
+ return this.postgrest.from(table);
397
+ }
398
+ };
399
+
332
400
  // src/modules/auth.ts
401
+ function convertDbProfileToCamelCase(dbProfile) {
402
+ const result = {
403
+ id: dbProfile.id
404
+ };
405
+ Object.keys(dbProfile).forEach((key) => {
406
+ result[key] = dbProfile[key];
407
+ if (key.includes("_")) {
408
+ const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
409
+ result[camelKey] = dbProfile[key];
410
+ }
411
+ });
412
+ return result;
413
+ }
414
+ function convertCamelCaseToDbProfile(profile) {
415
+ const dbProfile = {};
416
+ Object.keys(profile).forEach((key) => {
417
+ if (profile[key] === void 0) return;
418
+ const snakeKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
419
+ dbProfile[snakeKey] = profile[key];
420
+ });
421
+ return dbProfile;
422
+ }
333
423
  function isHostedAuthEnvironment() {
334
424
  if (typeof window === "undefined") {
335
425
  return false;
@@ -347,11 +437,12 @@ var Auth = class {
347
437
  constructor(http, tokenManager) {
348
438
  this.http = http;
349
439
  this.tokenManager = tokenManager;
440
+ this.database = new Database(http, tokenManager);
350
441
  this.detectAuthCallback();
351
442
  }
352
443
  /**
353
444
  * Automatically detect and handle OAuth callback parameters in the URL
354
- * This runs after initialization to seamlessly complete the OAuth flow
445
+ * This runs on initialization to seamlessly complete the OAuth flow
355
446
  * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
356
447
  */
357
448
  detectAuthCallback() {
@@ -373,8 +464,7 @@ var Auth = class {
373
464
  user: {
374
465
  id: userId,
375
466
  email,
376
- profile: { name: name || "" },
377
- metadata: null,
467
+ name: name || "",
378
468
  // These fields are not provided by backend OAuth callback
379
469
  // They'll be populated when calling getCurrentUser()
380
470
  emailVerified: false,
@@ -575,9 +665,14 @@ var Auth = class {
575
665
  }
576
666
  this.http.setAuthToken(session.accessToken);
577
667
  const authResponse = await this.http.get("/api/auth/sessions/current");
668
+ const { data: profile, error: profileError } = await this.database.from("users").select("*").eq("id", authResponse.user.id).single();
669
+ if (profileError && profileError.code !== "PGRST116") {
670
+ return { data: null, error: profileError };
671
+ }
578
672
  return {
579
673
  data: {
580
- user: authResponse.user
674
+ user: authResponse.user,
675
+ profile: profile ? convertDbProfileToCamelCase(profile) : null
581
676
  },
582
677
  error: null
583
678
  };
@@ -601,28 +696,17 @@ var Auth = class {
601
696
  }
602
697
  /**
603
698
  * Get any user's profile by ID
604
- * Returns profile information from the users table
699
+ * Returns profile information from the users table (dynamic fields)
605
700
  */
606
701
  async getProfile(userId) {
607
- try {
608
- const response = await this.http.get(`/api/auth/profiles/${userId}`);
609
- return {
610
- data: response,
611
- error: null
612
- };
613
- } catch (error) {
614
- if (error instanceof InsForgeError) {
615
- return { data: null, error };
616
- }
617
- return {
618
- data: null,
619
- error: new InsForgeError(
620
- "An unexpected error occurred while fetching user profile",
621
- 500,
622
- "UNEXPECTED_ERROR"
623
- )
624
- };
702
+ const { data, error } = await this.database.from("users").select("*").eq("id", userId).single();
703
+ if (error && error.code === "PGRST116") {
704
+ return { data: null, error: null };
625
705
  }
706
+ if (data) {
707
+ return { data: convertDbProfileToCamelCase(data), error: null };
708
+ }
709
+ return { data: null, error };
626
710
  }
627
711
  /**
628
712
  * Get the current session (only session data, no API call)
@@ -693,31 +777,42 @@ var Auth = class {
693
777
  /**
694
778
  * Set/Update the current user's profile
695
779
  * Updates profile information in the users table (supports any dynamic fields)
696
- * Requires authentication
697
780
  */
698
781
  async setProfile(profile) {
699
- try {
700
- const response = await this.http.patch(
701
- "/api/auth/profiles/current",
702
- { profile }
703
- );
704
- return {
705
- data: response,
706
- error: null
707
- };
708
- } catch (error) {
709
- if (error instanceof InsForgeError) {
710
- return { data: null, error };
711
- }
782
+ const session = this.tokenManager.getSession();
783
+ if (!session?.accessToken) {
712
784
  return {
713
785
  data: null,
714
786
  error: new InsForgeError(
715
- "An unexpected error occurred while updating user profile",
716
- 500,
717
- "UNEXPECTED_ERROR"
787
+ "No authenticated user found",
788
+ 401,
789
+ "UNAUTHENTICATED"
718
790
  )
719
791
  };
720
792
  }
793
+ if (!session.user?.id) {
794
+ const { data: data2, error: error2 } = await this.getCurrentUser();
795
+ if (error2) {
796
+ return { data: null, error: error2 };
797
+ }
798
+ if (data2?.user) {
799
+ session.user = {
800
+ id: data2.user.id,
801
+ email: data2.user.email,
802
+ name: "",
803
+ emailVerified: false,
804
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
805
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
806
+ };
807
+ this.tokenManager.saveSession(session);
808
+ }
809
+ }
810
+ const dbProfile = convertCamelCaseToDbProfile(profile);
811
+ const { data, error } = await this.database.from("users").update(dbProfile).eq("id", session.user.id).select().single();
812
+ if (data) {
813
+ return { data: convertDbProfileToCamelCase(data), error: null };
814
+ }
815
+ return { data: null, error };
721
816
  }
722
817
  /**
723
818
  * Send email verification (code or link based on config)
@@ -902,75 +997,6 @@ var Auth = class {
902
997
  }
903
998
  };
904
999
 
905
- // src/modules/database-postgrest.ts
906
- var import_postgrest_js = require("@supabase/postgrest-js");
907
- function createInsForgePostgrestFetch(httpClient, tokenManager) {
908
- return async (input, init) => {
909
- const url = typeof input === "string" ? input : input.toString();
910
- const urlObj = new URL(url);
911
- const tableName = urlObj.pathname.slice(1);
912
- const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;
913
- const token = tokenManager.getAccessToken();
914
- const httpHeaders = httpClient.getHeaders();
915
- const authToken = token || httpHeaders["Authorization"]?.replace("Bearer ", "");
916
- const headers = new Headers(init?.headers);
917
- if (authToken && !headers.has("Authorization")) {
918
- headers.set("Authorization", `Bearer ${authToken}`);
919
- }
920
- const response = await fetch(insforgeUrl, {
921
- ...init,
922
- headers
923
- });
924
- return response;
925
- };
926
- }
927
- var Database = class {
928
- constructor(httpClient, tokenManager) {
929
- this.postgrest = new import_postgrest_js.PostgrestClient("http://dummy", {
930
- fetch: createInsForgePostgrestFetch(httpClient, tokenManager),
931
- headers: {}
932
- });
933
- }
934
- /**
935
- * Create a query builder for a table
936
- *
937
- * @example
938
- * // Basic query
939
- * const { data, error } = await client.database
940
- * .from('posts')
941
- * .select('*')
942
- * .eq('user_id', userId);
943
- *
944
- * // With count (Supabase style!)
945
- * const { data, error, count } = await client.database
946
- * .from('posts')
947
- * .select('*', { count: 'exact' })
948
- * .range(0, 9);
949
- *
950
- * // Just get count, no data
951
- * const { count } = await client.database
952
- * .from('posts')
953
- * .select('*', { count: 'exact', head: true });
954
- *
955
- * // Complex queries with OR
956
- * const { data } = await client.database
957
- * .from('posts')
958
- * .select('*, users!inner(*)')
959
- * .or('status.eq.active,status.eq.pending');
960
- *
961
- * // All features work:
962
- * - Nested selects
963
- * - Foreign key expansion
964
- * - OR/AND/NOT conditions
965
- * - Count with head
966
- * - Range pagination
967
- * - Upserts
968
- */
969
- from(table) {
970
- return this.postgrest.from(table);
971
- }
972
- };
973
-
974
1000
  // src/modules/storage.ts
975
1001
  var StorageBucket = class {
976
1002
  constructor(bucketName, http) {
@@ -1725,29 +1751,6 @@ var Realtime = class {
1725
1751
  }
1726
1752
  };
1727
1753
 
1728
- // src/modules/email.ts
1729
- var Emails = class {
1730
- constructor(http) {
1731
- this.http = http;
1732
- }
1733
- /**
1734
- * Send a custom HTML email
1735
- * @param options Email options including recipients, subject, and HTML content
1736
- */
1737
- async send(options) {
1738
- try {
1739
- const data = await this.http.post(
1740
- "/api/email/send-raw",
1741
- options
1742
- );
1743
- return { data, error: null };
1744
- } catch (error) {
1745
- const normalizedError = error instanceof Error ? error : new Error(String(error));
1746
- return { data: null, error: normalizedError };
1747
- }
1748
- }
1749
- };
1750
-
1751
1754
  // src/client.ts
1752
1755
  var InsForgeClient = class {
1753
1756
  constructor(config = {}) {
@@ -1771,7 +1774,6 @@ var InsForgeClient = class {
1771
1774
  this.ai = new AI(this.http);
1772
1775
  this.functions = new Functions(this.http);
1773
1776
  this.realtime = new Realtime(this.http.baseUrl, this.tokenManager);
1774
- this.emails = new Emails(this.http);
1775
1777
  }
1776
1778
  /**
1777
1779
  * Get the underlying HTTP client for custom requests
@@ -1805,7 +1807,6 @@ var index_default = InsForgeClient;
1805
1807
  AI,
1806
1808
  Auth,
1807
1809
  Database,
1808
- Emails,
1809
1810
  Functions,
1810
1811
  HttpClient,
1811
1812
  InsForgeClient,