@insforge/sdk 1.4.2 → 1.4.3

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
@@ -185,6 +185,31 @@ const { data, error } = await insforge.database
185
185
  .eq("id", postId);
186
186
  ```
187
187
 
188
+ #### Selecting a schema
189
+
190
+ Queries hit the `public` schema by default. Target a custom schema by chaining `.schema()` — the table name stays bare (it maps to PostgREST's `Accept-Profile`/`Content-Profile` header):
191
+
192
+ ```javascript
193
+ const { data } = await insforge.database
194
+ .schema("analytics")
195
+ .from("events")
196
+ .select("*");
197
+
198
+ await insforge.database.schema("analytics").rpc("rollup", { day: "2026-01-01" });
199
+ ```
200
+
201
+ Or set a default schema for every query when creating the client:
202
+
203
+ ```javascript
204
+ const insforge = createClient({
205
+ baseUrl: "...",
206
+ anonKey: "...",
207
+ db: { schema: "analytics" },
208
+ });
209
+ ```
210
+
211
+ The schema must be exposed by the backend, and access is still gated by grants + RLS like `public`. Older backends that don't expose the schema return PostgREST `PGRST106` rather than silently falling back.
212
+
188
213
  ### File Storage
189
214
 
190
215
  ```javascript
@@ -1,6 +1,7 @@
1
- import { A as AuthSession, I as InsForgeConfig, e as AuthRefreshResponse, d as InsForgeError } from './types-Dk-44JJf.mjs';
1
+ import { A as AuthSession, I as InsForgeConfig, e as AuthRefreshResponse, d as InsForgeError } from './types-MKmYAYeg.mjs';
2
2
  import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, ExchangeResetPasswordTokenResponse, ResetPasswordResponse, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse, StripeEnvironment, CreateCheckoutSessionBody, CreateCheckoutSessionResponse, CreateCustomerPortalSessionBody, CreateCustomerPortalSessionResponse, RazorpayEnvironment, CreateRazorpayOrderBody, CreateRazorpayOrderResponse, VerifyRazorpayOrderBody, VerifyRazorpayOrderResponse, CreateRazorpaySubscriptionBody, CreateRazorpaySubscriptionResponse, VerifyRazorpaySubscriptionBody, VerifyRazorpaySubscriptionResponse, CancelRazorpaySubscriptionBodyInput, CancelRazorpaySubscriptionResponse, PauseRazorpaySubscriptionResponse, ResumeRazorpaySubscriptionResponse } from '@insforge/shared-schemas';
3
3
  import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
+ import { PostgrestClient } from '@supabase/postgrest-js';
4
5
 
5
6
  type LogFunction = (message: string, ...args: any[]) => void;
6
7
  /**
@@ -362,7 +363,22 @@ declare class Auth {
362
363
  */
363
364
  declare class Database {
364
365
  private postgrest;
365
- constructor(httpClient: HttpClient);
366
+ constructor(httpClient: HttpClient, defaultSchema?: string);
367
+ /**
368
+ * Select a non-default Postgres schema for the chained query. Maps to
369
+ * PostgREST's `Accept-Profile` (reads) / `Content-Profile` (writes) header.
370
+ * The schema must be exposed by the backend.
371
+ *
372
+ * @example
373
+ * const { data } = await client.database
374
+ * .schema('analytics')
375
+ * .from('events')
376
+ * .select('*');
377
+ *
378
+ * @example
379
+ * await client.database.schema('analytics').rpc('rollup', { day: '2026-01-01' });
380
+ */
381
+ schema(schemaName: string): PostgrestClient<any, any, string, any>;
366
382
  /**
367
383
  * Create a query builder for a table
368
384
  *
@@ -1,6 +1,7 @@
1
- import { A as AuthSession, I as InsForgeConfig, e as AuthRefreshResponse, d as InsForgeError } from './types-Dk-44JJf.js';
1
+ import { A as AuthSession, I as InsForgeConfig, e as AuthRefreshResponse, d as InsForgeError } from './types-MKmYAYeg.js';
2
2
  import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, ExchangeResetPasswordTokenResponse, ResetPasswordResponse, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse, StripeEnvironment, CreateCheckoutSessionBody, CreateCheckoutSessionResponse, CreateCustomerPortalSessionBody, CreateCustomerPortalSessionResponse, RazorpayEnvironment, CreateRazorpayOrderBody, CreateRazorpayOrderResponse, VerifyRazorpayOrderBody, VerifyRazorpayOrderResponse, CreateRazorpaySubscriptionBody, CreateRazorpaySubscriptionResponse, VerifyRazorpaySubscriptionBody, VerifyRazorpaySubscriptionResponse, CancelRazorpaySubscriptionBodyInput, CancelRazorpaySubscriptionResponse, PauseRazorpaySubscriptionResponse, ResumeRazorpaySubscriptionResponse } from '@insforge/shared-schemas';
3
3
  import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
+ import { PostgrestClient } from '@supabase/postgrest-js';
4
5
 
5
6
  type LogFunction = (message: string, ...args: any[]) => void;
6
7
  /**
@@ -362,7 +363,22 @@ declare class Auth {
362
363
  */
363
364
  declare class Database {
364
365
  private postgrest;
365
- constructor(httpClient: HttpClient);
366
+ constructor(httpClient: HttpClient, defaultSchema?: string);
367
+ /**
368
+ * Select a non-default Postgres schema for the chained query. Maps to
369
+ * PostgREST's `Accept-Profile` (reads) / `Content-Profile` (writes) header.
370
+ * The schema must be exposed by the backend.
371
+ *
372
+ * @example
373
+ * const { data } = await client.database
374
+ * .schema('analytics')
375
+ * .from('events')
376
+ * .select('*');
377
+ *
378
+ * @example
379
+ * await client.database.schema('analytics').rpc('rollup', { day: '2026-01-01' });
380
+ */
381
+ schema(schemaName: string): PostgrestClient<any, any, string, any>;
366
382
  /**
367
383
  * Create a query builder for a table
368
384
  *
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { I as InsForgeClient } from './client-C-qBRoea.mjs';
2
- export { c as AI, A as Auth, C as ConnectionState, D as Database, E as Emails, f as EventCallback, d as FunctionInvokeOptions, F as Functions, H as HttpClient, L as Logger, P as Payments, e as PaymentsResponse, R as Realtime, S as Storage, a as StorageBucket, b as StorageResponse, T as TokenManager } from './client-C-qBRoea.mjs';
3
- import { I as InsForgeConfig, a as InsForgeAdminConfig } from './types-Dk-44JJf.mjs';
4
- export { b as ApiError, A as AuthSession, d as InsForgeError, c as InsForgeErrorCode } from './types-Dk-44JJf.mjs';
1
+ import { I as InsForgeClient } from './client-B6eZHolm.mjs';
2
+ export { c as AI, A as Auth, C as ConnectionState, D as Database, E as Emails, f as EventCallback, d as FunctionInvokeOptions, F as Functions, H as HttpClient, L as Logger, P as Payments, e as PaymentsResponse, R as Realtime, S as Storage, a as StorageBucket, b as StorageResponse, T as TokenManager } from './client-B6eZHolm.mjs';
3
+ import { I as InsForgeConfig, a as InsForgeAdminConfig } from './types-MKmYAYeg.mjs';
4
+ export { b as ApiError, A as AuthSession, d as InsForgeError, c as InsForgeErrorCode } from './types-MKmYAYeg.mjs';
5
5
  export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
6
6
  import '@supabase/postgrest-js';
7
7
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { I as InsForgeClient } from './client-BR9o-WUm.js';
2
- export { c as AI, A as Auth, C as ConnectionState, D as Database, E as Emails, f as EventCallback, d as FunctionInvokeOptions, F as Functions, H as HttpClient, L as Logger, P as Payments, e as PaymentsResponse, R as Realtime, S as Storage, a as StorageBucket, b as StorageResponse, T as TokenManager } from './client-BR9o-WUm.js';
3
- import { I as InsForgeConfig, a as InsForgeAdminConfig } from './types-Dk-44JJf.js';
4
- export { b as ApiError, A as AuthSession, d as InsForgeError, c as InsForgeErrorCode } from './types-Dk-44JJf.js';
1
+ import { I as InsForgeClient } from './client-DUmOm_3W.js';
2
+ export { c as AI, A as Auth, C as ConnectionState, D as Database, E as Emails, f as EventCallback, d as FunctionInvokeOptions, F as Functions, H as HttpClient, L as Logger, P as Payments, e as PaymentsResponse, R as Realtime, S as Storage, a as StorageBucket, b as StorageResponse, T as TokenManager } from './client-DUmOm_3W.js';
3
+ import { I as InsForgeConfig, a as InsForgeAdminConfig } from './types-MKmYAYeg.js';
4
+ export { b as ApiError, A as AuthSession, d as InsForgeError, c as InsForgeErrorCode } from './types-MKmYAYeg.js';
5
5
  export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
6
6
  import '@supabase/postgrest-js';
7
7
 
package/dist/index.js CHANGED
@@ -1054,10 +1054,16 @@ var Auth = class {
1054
1054
  async signOut() {
1055
1055
  try {
1056
1056
  try {
1057
+ const serverMode = this.isServerMode();
1058
+ const csrfToken = !serverMode ? getCsrfToken() : null;
1057
1059
  await this.http.post(
1058
- this.isServerMode() ? "/api/auth/logout?client_type=mobile" : "/api/auth/logout",
1060
+ serverMode ? "/api/auth/logout?client_type=mobile" : "/api/auth/logout",
1059
1061
  void 0,
1060
- { credentials: "include", skipAuthRefresh: true }
1062
+ {
1063
+ credentials: "include",
1064
+ skipAuthRefresh: true,
1065
+ ...csrfToken ? { headers: { "X-CSRF-Token": csrfToken } } : {}
1066
+ }
1061
1067
  );
1062
1068
  } catch {
1063
1069
  }
@@ -1463,12 +1469,30 @@ function createInsForgePostgrestFetch(httpClient) {
1463
1469
  };
1464
1470
  }
1465
1471
  var Database = class {
1466
- constructor(httpClient) {
1472
+ constructor(httpClient, defaultSchema) {
1467
1473
  this.postgrest = new import_postgrest_js.PostgrestClient("http://dummy", {
1468
1474
  fetch: createInsForgePostgrestFetch(httpClient),
1469
- headers: {}
1475
+ headers: {},
1476
+ ...defaultSchema ? { schema: defaultSchema } : {}
1470
1477
  });
1471
1478
  }
1479
+ /**
1480
+ * Select a non-default Postgres schema for the chained query. Maps to
1481
+ * PostgREST's `Accept-Profile` (reads) / `Content-Profile` (writes) header.
1482
+ * The schema must be exposed by the backend.
1483
+ *
1484
+ * @example
1485
+ * const { data } = await client.database
1486
+ * .schema('analytics')
1487
+ * .from('events')
1488
+ * .select('*');
1489
+ *
1490
+ * @example
1491
+ * await client.database.schema('analytics').rpc('rollup', { day: '2026-01-01' });
1492
+ */
1493
+ schema(schemaName) {
1494
+ return this.postgrest.schema(schemaName);
1495
+ }
1472
1496
  /**
1473
1497
  * Create a query builder for a table
1474
1498
  *
@@ -2828,7 +2852,7 @@ var InsForgeClient = class {
2828
2852
  isServerMode: config.isServerMode ?? !!accessToken,
2829
2853
  detectOAuthCallback: config.auth?.detectOAuthCallback
2830
2854
  });
2831
- this.database = new Database(this.http);
2855
+ this.database = new Database(this.http, config.db?.schema);
2832
2856
  this.storage = new Storage(this.http);
2833
2857
  this.ai = new AI(this.http);
2834
2858
  this.functions = new Functions(this.http, config.functionsUrl);