@insforge/sdk 1.0.3-dev.3 → 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,
@@ -569,19 +659,20 @@ var Auth = class {
569
659
  */
570
660
  async getCurrentUser() {
571
661
  try {
572
- const user = this.tokenManager.getUser();
573
- if (user) {
574
- return { data: { user }, error: null };
575
- }
576
- const accessToken = this.tokenManager.getAccessToken();
577
- if (!accessToken) {
662
+ const session = this.tokenManager.getSession();
663
+ if (!session?.accessToken) {
578
664
  return { data: null, error: null };
579
665
  }
580
- this.http.setAuthToken(accessToken);
666
+ this.http.setAuthToken(session.accessToken);
581
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
+ }
582
672
  return {
583
673
  data: {
584
- user: authResponse.user
674
+ user: authResponse.user,
675
+ profile: profile ? convertDbProfileToCamelCase(profile) : null
585
676
  },
586
677
  error: null
587
678
  };
@@ -605,28 +696,17 @@ var Auth = class {
605
696
  }
606
697
  /**
607
698
  * Get any user's profile by ID
608
- * Returns profile information from the users table
699
+ * Returns profile information from the users table (dynamic fields)
609
700
  */
610
701
  async getProfile(userId) {
611
- try {
612
- const response = await this.http.get(`/api/auth/profiles/${userId}`);
613
- return {
614
- data: response,
615
- error: null
616
- };
617
- } catch (error) {
618
- if (error instanceof InsForgeError) {
619
- return { data: null, error };
620
- }
621
- return {
622
- data: null,
623
- error: new InsForgeError(
624
- "An unexpected error occurred while fetching user profile",
625
- 500,
626
- "UNEXPECTED_ERROR"
627
- )
628
- };
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 };
705
+ }
706
+ if (data) {
707
+ return { data: convertDbProfileToCamelCase(data), error: null };
629
708
  }
709
+ return { data: null, error };
630
710
  }
631
711
  /**
632
712
  * Get the current session (only session data, no API call)
@@ -697,31 +777,42 @@ var Auth = class {
697
777
  /**
698
778
  * Set/Update the current user's profile
699
779
  * Updates profile information in the users table (supports any dynamic fields)
700
- * Requires authentication
701
780
  */
702
781
  async setProfile(profile) {
703
- try {
704
- const response = await this.http.patch(
705
- "/api/auth/profiles/current",
706
- { profile }
707
- );
708
- return {
709
- data: response,
710
- error: null
711
- };
712
- } catch (error) {
713
- if (error instanceof InsForgeError) {
714
- return { data: null, error };
715
- }
782
+ const session = this.tokenManager.getSession();
783
+ if (!session?.accessToken) {
716
784
  return {
717
785
  data: null,
718
786
  error: new InsForgeError(
719
- "An unexpected error occurred while updating user profile",
720
- 500,
721
- "UNEXPECTED_ERROR"
787
+ "No authenticated user found",
788
+ 401,
789
+ "UNAUTHENTICATED"
722
790
  )
723
791
  };
724
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 };
725
816
  }
726
817
  /**
727
818
  * Send email verification (code or link based on config)
@@ -906,75 +997,6 @@ var Auth = class {
906
997
  }
907
998
  };
908
999
 
909
- // src/modules/database-postgrest.ts
910
- var import_postgrest_js = require("@supabase/postgrest-js");
911
- function createInsForgePostgrestFetch(httpClient, tokenManager) {
912
- return async (input, init) => {
913
- const url = typeof input === "string" ? input : input.toString();
914
- const urlObj = new URL(url);
915
- const tableName = urlObj.pathname.slice(1);
916
- const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;
917
- const token = tokenManager.getAccessToken();
918
- const httpHeaders = httpClient.getHeaders();
919
- const authToken = token || httpHeaders["Authorization"]?.replace("Bearer ", "");
920
- const headers = new Headers(init?.headers);
921
- if (authToken && !headers.has("Authorization")) {
922
- headers.set("Authorization", `Bearer ${authToken}`);
923
- }
924
- const response = await fetch(insforgeUrl, {
925
- ...init,
926
- headers
927
- });
928
- return response;
929
- };
930
- }
931
- var Database = class {
932
- constructor(httpClient, tokenManager) {
933
- this.postgrest = new import_postgrest_js.PostgrestClient("http://dummy", {
934
- fetch: createInsForgePostgrestFetch(httpClient, tokenManager),
935
- headers: {}
936
- });
937
- }
938
- /**
939
- * Create a query builder for a table
940
- *
941
- * @example
942
- * // Basic query
943
- * const { data, error } = await client.database
944
- * .from('posts')
945
- * .select('*')
946
- * .eq('user_id', userId);
947
- *
948
- * // With count (Supabase style!)
949
- * const { data, error, count } = await client.database
950
- * .from('posts')
951
- * .select('*', { count: 'exact' })
952
- * .range(0, 9);
953
- *
954
- * // Just get count, no data
955
- * const { count } = await client.database
956
- * .from('posts')
957
- * .select('*', { count: 'exact', head: true });
958
- *
959
- * // Complex queries with OR
960
- * const { data } = await client.database
961
- * .from('posts')
962
- * .select('*, users!inner(*)')
963
- * .or('status.eq.active,status.eq.pending');
964
- *
965
- * // All features work:
966
- * - Nested selects
967
- * - Foreign key expansion
968
- * - OR/AND/NOT conditions
969
- * - Count with head
970
- * - Range pagination
971
- * - Upserts
972
- */
973
- from(table) {
974
- return this.postgrest.from(table);
975
- }
976
- };
977
-
978
1000
  // src/modules/storage.ts
979
1001
  var StorageBucket = class {
980
1002
  constructor(bucketName, http) {
@@ -1729,29 +1751,6 @@ var Realtime = class {
1729
1751
  }
1730
1752
  };
1731
1753
 
1732
- // src/modules/email.ts
1733
- var Emails = class {
1734
- constructor(http) {
1735
- this.http = http;
1736
- }
1737
- /**
1738
- * Send a custom HTML email
1739
- * @param options Email options including recipients, subject, and HTML content
1740
- */
1741
- async send(options) {
1742
- try {
1743
- const data = await this.http.post(
1744
- "/api/email/send-raw",
1745
- options
1746
- );
1747
- return { data, error: null };
1748
- } catch (error) {
1749
- const normalizedError = error instanceof Error ? error : new Error(String(error));
1750
- return { data: null, error: normalizedError };
1751
- }
1752
- }
1753
- };
1754
-
1755
1754
  // src/client.ts
1756
1755
  var InsForgeClient = class {
1757
1756
  constructor(config = {}) {
@@ -1775,7 +1774,6 @@ var InsForgeClient = class {
1775
1774
  this.ai = new AI(this.http);
1776
1775
  this.functions = new Functions(this.http);
1777
1776
  this.realtime = new Realtime(this.http.baseUrl, this.tokenManager);
1778
- this.emails = new Emails(this.http);
1779
1777
  }
1780
1778
  /**
1781
1779
  * Get the underlying HTTP client for custom requests
@@ -1809,7 +1807,6 @@ var index_default = InsForgeClient;
1809
1807
  AI,
1810
1808
  Auth,
1811
1809
  Database,
1812
- Emails,
1813
1810
  Functions,
1814
1811
  HttpClient,
1815
1812
  InsForgeClient,