@insforge/sdk 1.2.7 → 1.2.8-dev.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.js CHANGED
@@ -325,6 +325,7 @@ var TokenManager = class {
325
325
  // src/lib/http-client.ts
326
326
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([500, 502, 503, 504]);
327
327
  var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE", "OPTIONS"]);
328
+ var REFRESHABLE_AUTH_ERROR_CODE = "AUTH_UNAUTHORIZED";
328
329
  function serializeBody(method, body, headers) {
329
330
  if (body === void 0) return void 0;
330
331
  if (method === "GET" || method === "HEAD") return void 0;
@@ -379,12 +380,11 @@ var HttpClient = class {
379
380
  */
380
381
  constructor(config, tokenManager, logger) {
381
382
  this.userToken = null;
382
- this.autoRefreshToken = true;
383
383
  this.isRefreshing = false;
384
384
  this.refreshPromise = null;
385
385
  this.refreshToken = null;
386
+ this.config = config;
386
387
  this.baseUrl = config.baseUrl || "http://localhost:7130";
387
- this.autoRefreshToken = config.autoRefreshToken ?? true;
388
388
  this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : void 0);
389
389
  this.anonKey = config.anonKey;
390
390
  this.defaultHeaders = {
@@ -434,48 +434,19 @@ var HttpClient = class {
434
434
  const jitter = base * (0.85 + Math.random() * 0.3);
435
435
  return Math.round(jitter);
436
436
  }
437
- /**
438
- * Performs an HTTP request with automatic retry and timeout handling.
439
- * Retries on network errors and 5xx server errors with exponential backoff.
440
- * Client errors (4xx) and timeouts are thrown immediately without retry.
441
- * @param method - HTTP method (GET, POST, PUT, PATCH, DELETE).
442
- * @param path - API path relative to the base URL.
443
- * @param options - Optional request configuration including headers, body, and query params.
444
- * @returns Parsed response data.
445
- * @throws {InsForgeError} On timeout, network failure, or HTTP error responses.
446
- */
447
- async handleRequest(method, path, options = {}) {
437
+ shouldRefreshAccessToken(statusCode, errorCode, authToken, options = {}) {
438
+ return statusCode === 401 && errorCode === REFRESHABLE_AUTH_ERROR_CODE && !this.config.isServerMode && !this.config.edgeFunctionToken && !options.skipAuthRefresh && authToken !== null;
439
+ }
440
+ async fetchWithRetry(args) {
448
441
  const {
449
- params,
450
- headers = {},
442
+ method,
443
+ url,
444
+ headers,
451
445
  body,
452
- signal: callerSignal,
453
- ...fetchOptions
454
- } = options;
455
- const url = this.buildUrl(path, params);
456
- const startTime = Date.now();
457
- const canRetry = IDEMPOTENT_METHODS.has(method.toUpperCase()) || options.idempotent === true;
458
- const maxAttempts = canRetry ? this.retryCount : 0;
459
- const requestHeaders = {
460
- ...this.defaultHeaders
461
- };
462
- const authToken = this.userToken || this.anonKey;
463
- if (authToken) {
464
- requestHeaders["Authorization"] = `Bearer ${authToken}`;
465
- }
466
- const processedBody = serializeBody(method, body, requestHeaders);
467
- if (headers instanceof Headers) {
468
- headers.forEach((value, key) => {
469
- requestHeaders[key] = value;
470
- });
471
- } else if (Array.isArray(headers)) {
472
- headers.forEach(([key, value]) => {
473
- requestHeaders[key] = value;
474
- });
475
- } else {
476
- Object.assign(requestHeaders, headers);
477
- }
478
- this.logger.logRequest(method, url, requestHeaders, processedBody);
446
+ fetchOptions,
447
+ callerSignal,
448
+ maxAttempts
449
+ } = args;
479
450
  let lastError;
480
451
  for (let attempt = 0; attempt <= maxAttempts; attempt++) {
481
452
  if (attempt > 0) {
@@ -527,8 +498,8 @@ var HttpClient = class {
527
498
  try {
528
499
  const response = await this.fetch(url, {
529
500
  method,
530
- headers: requestHeaders,
531
- body: processedBody,
501
+ headers,
502
+ body,
532
503
  ...fetchOptions,
533
504
  ...controller ? { signal: controller.signal } : {}
534
505
  });
@@ -542,31 +513,8 @@ var HttpClient = class {
542
513
  );
543
514
  continue;
544
515
  }
545
- let data;
546
- try {
547
- data = await parseResponse(response);
548
- } catch (err) {
549
- if (timer !== void 0) clearTimeout(timer);
550
- if (err instanceof InsForgeError) {
551
- this.logger.logResponse(
552
- method,
553
- url,
554
- err.statusCode || response.status,
555
- Date.now() - startTime,
556
- err
557
- );
558
- }
559
- throw err;
560
- }
561
516
  if (timer !== void 0) clearTimeout(timer);
562
- this.logger.logResponse(
563
- method,
564
- url,
565
- response.status,
566
- Date.now() - startTime,
567
- data
568
- );
569
- return data;
517
+ return response;
570
518
  } catch (err) {
571
519
  if (timer !== void 0) clearTimeout(timer);
572
520
  if (err?.name === "AbortError") {
@@ -579,9 +527,6 @@ var HttpClient = class {
579
527
  }
580
528
  throw err;
581
529
  }
582
- if (err instanceof InsForgeError) {
583
- throw err;
584
- }
585
530
  if (attempt < maxAttempts) {
586
531
  lastError = err;
587
532
  continue;
@@ -599,32 +544,244 @@ var HttpClient = class {
599
544
  "NETWORK_ERROR"
600
545
  );
601
546
  }
547
+ /**
548
+ * Performs an HTTP request with automatic retry and timeout handling.
549
+ * Retries on network errors and 5xx server errors with exponential backoff.
550
+ * Client errors (4xx) and timeouts are thrown immediately without retry.
551
+ * @param method - HTTP method (GET, POST, PUT, PATCH, DELETE).
552
+ * @param path - API path relative to the base URL.
553
+ * @param options - Optional request configuration including headers, body, and query params.
554
+ * @returns Parsed response data.
555
+ * @throws {InsForgeError} On timeout, network failure, or HTTP error responses.
556
+ */
557
+ async handleRequest(method, path, options = {}, tokenOverride) {
558
+ const {
559
+ params,
560
+ headers = {},
561
+ body,
562
+ skipAuthRefresh: _skipAuthRefresh,
563
+ signal: callerSignal,
564
+ ...fetchOptions
565
+ } = options;
566
+ const url = this.buildUrl(path, params);
567
+ const startTime = Date.now();
568
+ const canRetry = IDEMPOTENT_METHODS.has(method.toUpperCase()) || options.idempotent === true;
569
+ const maxAttempts = canRetry ? this.retryCount : 0;
570
+ const requestHeaders = {
571
+ ...this.defaultHeaders
572
+ };
573
+ const authToken = tokenOverride ?? this.userToken ?? this.anonKey;
574
+ if (authToken) {
575
+ requestHeaders["Authorization"] = `Bearer ${authToken}`;
576
+ }
577
+ const processedBody = serializeBody(method, body, requestHeaders);
578
+ const setRequestHeader = (key, value) => {
579
+ if (key.toLowerCase() === "authorization") {
580
+ delete requestHeaders["Authorization"];
581
+ delete requestHeaders["authorization"];
582
+ requestHeaders["Authorization"] = value;
583
+ return;
584
+ }
585
+ requestHeaders[key] = value;
586
+ };
587
+ if (headers instanceof Headers) {
588
+ headers.forEach((value, key) => {
589
+ setRequestHeader(key, value);
590
+ });
591
+ } else if (Array.isArray(headers)) {
592
+ headers.forEach(([key, value]) => {
593
+ setRequestHeader(key, value);
594
+ });
595
+ } else {
596
+ Object.entries(headers).forEach(([key, value]) => {
597
+ setRequestHeader(key, value);
598
+ });
599
+ }
600
+ this.logger.logRequest(method, url, requestHeaders, processedBody);
601
+ const response = await this.fetchWithRetry({
602
+ method,
603
+ url,
604
+ headers: requestHeaders,
605
+ body: processedBody,
606
+ fetchOptions,
607
+ callerSignal,
608
+ maxAttempts
609
+ });
610
+ let data;
611
+ try {
612
+ data = await parseResponse(response);
613
+ } catch (err) {
614
+ if (err instanceof InsForgeError) {
615
+ this.logger.logResponse(
616
+ method,
617
+ url,
618
+ err.statusCode || response.status,
619
+ Date.now() - startTime,
620
+ err
621
+ );
622
+ }
623
+ throw err;
624
+ }
625
+ this.logger.logResponse(
626
+ method,
627
+ url,
628
+ response.status,
629
+ Date.now() - startTime,
630
+ data
631
+ );
632
+ return data;
633
+ }
602
634
  async request(method, path, options = {}) {
635
+ const tokenUsed = this.userToken;
603
636
  try {
604
- return await this.handleRequest(method, path, { ...options });
637
+ return await this.handleRequest(
638
+ method,
639
+ path,
640
+ { ...options },
641
+ tokenUsed
642
+ );
605
643
  } catch (error) {
606
- if (error instanceof InsForgeError && error.statusCode === 401 && error.error === "INVALID_TOKEN" && this.autoRefreshToken) {
607
- try {
608
- const newTokenData = await this.handleTokenRefresh();
609
- this.setAuthToken(newTokenData.accessToken);
610
- this.tokenManager.saveSession(newTokenData);
611
- if (newTokenData.csrfToken) {
612
- setCsrfToken(newTokenData.csrfToken);
613
- }
614
- if (newTokenData.refreshToken) {
615
- this.setRefreshToken(newTokenData.refreshToken);
644
+ if (!(error instanceof InsForgeError) || !this.shouldRefreshAccessToken(
645
+ error.statusCode,
646
+ error.error,
647
+ tokenUsed,
648
+ options
649
+ )) {
650
+ throw error;
651
+ }
652
+ if (tokenUsed !== this.userToken) {
653
+ if (this.userToken === null) {
654
+ throw error;
655
+ }
656
+ return await this.handleRequest(
657
+ method,
658
+ path,
659
+ {
660
+ ...options,
661
+ skipAuthRefresh: true
662
+ },
663
+ this.userToken
664
+ );
665
+ }
666
+ try {
667
+ await this.refreshAndSaveSession();
668
+ } catch (error2) {
669
+ this.clearAuthSession();
670
+ throw error2;
671
+ }
672
+ return await this.handleRequest(method, path, {
673
+ ...options,
674
+ skipAuthRefresh: true
675
+ });
676
+ }
677
+ }
678
+ /**
679
+ * Performs an SDK-configured fetch and returns the raw Response.
680
+ * This is used by clients such as postgrest-js that need to own response
681
+ * parsing while still sharing SDK auth and refresh behavior.
682
+ */
683
+ async rawFetch(input, init, options = {}) {
684
+ const request = typeof Request !== "undefined" && input instanceof Request ? input : void 0;
685
+ const {
686
+ method: initMethod,
687
+ headers: initHeaders,
688
+ body: initBody,
689
+ signal: initSignal,
690
+ ...fetchOptions
691
+ } = init ?? {};
692
+ const method = initMethod ?? request?.method ?? "GET";
693
+ const url = request?.url ?? input.toString();
694
+ const startTime = Date.now();
695
+ const tokenUsed = this.userToken;
696
+ const headers = new Headers({
697
+ ...this.defaultHeaders
698
+ });
699
+ const authToken = tokenUsed ?? this.anonKey;
700
+ if (authToken) {
701
+ headers.set("Authorization", `Bearer ${authToken}`);
702
+ }
703
+ request?.headers.forEach((value, key) => {
704
+ headers.set(key, value);
705
+ });
706
+ new Headers(initHeaders).forEach((value, key) => {
707
+ headers.set(key, value);
708
+ });
709
+ const requestHeaders = {};
710
+ headers.forEach((value, key) => {
711
+ requestHeaders[key] = value;
712
+ });
713
+ const sourceBody = initBody ?? request?.body ?? void 0;
714
+ let body = sourceBody;
715
+ let retryInit = init;
716
+ if (typeof ReadableStream !== "undefined" && sourceBody instanceof ReadableStream) {
717
+ body = await new Response(sourceBody).arrayBuffer();
718
+ retryInit = { ...init ?? {}, body };
719
+ }
720
+ const callerSignal = initSignal ?? request?.signal;
721
+ const maxAttempts = IDEMPOTENT_METHODS.has(method.toUpperCase()) ? this.retryCount : 0;
722
+ this.logger.logRequest(method, url, requestHeaders, body);
723
+ const response = await this.fetchWithRetry({
724
+ method,
725
+ url,
726
+ headers: requestHeaders,
727
+ body,
728
+ fetchOptions,
729
+ callerSignal,
730
+ maxAttempts
731
+ });
732
+ this.logger.logResponse(
733
+ method,
734
+ url,
735
+ response.status,
736
+ Date.now() - startTime
737
+ );
738
+ let errorCode = null;
739
+ if (response.status === 401) {
740
+ try {
741
+ const data = await response.clone().json();
742
+ if (data && typeof data === "object") {
743
+ const candidate = data.error ?? data.code;
744
+ if (typeof candidate === "string") {
745
+ errorCode = candidate;
616
746
  }
617
- return await this.handleRequest(method, path, { ...options });
618
- } catch (error2) {
619
- this.tokenManager.clearSession();
620
- this.userToken = null;
621
- this.refreshToken = null;
622
- clearCsrfToken();
623
- throw error2;
624
747
  }
748
+ } catch {
625
749
  }
750
+ }
751
+ if (!this.shouldRefreshAccessToken(
752
+ response.status,
753
+ errorCode,
754
+ tokenUsed,
755
+ options
756
+ )) {
757
+ return response;
758
+ }
759
+ if (tokenUsed !== this.userToken) {
760
+ if (this.userToken === null) {
761
+ return response;
762
+ }
763
+ const retryHeaders2 = new Headers(initHeaders);
764
+ retryHeaders2.set("Authorization", `Bearer ${this.userToken}`);
765
+ return await this.rawFetch(
766
+ input,
767
+ { ...retryInit, headers: retryHeaders2 },
768
+ { skipAuthRefresh: true }
769
+ );
770
+ }
771
+ let newTokenData;
772
+ try {
773
+ newTokenData = await this.refreshAndSaveSession();
774
+ } catch (error) {
775
+ this.clearAuthSession();
626
776
  throw error;
627
777
  }
778
+ const retryHeaders = new Headers(initHeaders);
779
+ retryHeaders.set("Authorization", `Bearer ${newTokenData.accessToken}`);
780
+ return await this.rawFetch(
781
+ input,
782
+ { ...retryInit, headers: retryHeaders },
783
+ { skipAuthRefresh: true }
784
+ );
628
785
  }
629
786
  /** Performs a GET request. */
630
787
  get(path, options) {
@@ -662,7 +819,7 @@ var HttpClient = class {
662
819
  }
663
820
  return headers;
664
821
  }
665
- async handleTokenRefresh() {
822
+ async refreshAccessToken() {
666
823
  if (this.isRefreshing) {
667
824
  return this.refreshPromise;
668
825
  }
@@ -673,7 +830,7 @@ var HttpClient = class {
673
830
  const body = this.refreshToken ? { refreshToken: this.refreshToken } : void 0;
674
831
  const response = await this.handleRequest(
675
832
  "POST",
676
- "/api/auth/sessions/current",
833
+ this.refreshToken ? "/api/auth/refresh?client_type=mobile" : "/api/auth/refresh",
677
834
  {
678
835
  body,
679
836
  headers: csrfToken ? { "X-CSRF-Token": csrfToken } : {},
@@ -688,6 +845,24 @@ var HttpClient = class {
688
845
  })();
689
846
  return this.refreshPromise;
690
847
  }
848
+ async refreshAndSaveSession() {
849
+ const newTokenData = await this.refreshAccessToken();
850
+ this.setAuthToken(newTokenData.accessToken);
851
+ this.tokenManager.saveSession(newTokenData);
852
+ if (newTokenData.csrfToken) {
853
+ setCsrfToken(newTokenData.csrfToken);
854
+ }
855
+ if (newTokenData.refreshToken) {
856
+ this.setRefreshToken(newTokenData.refreshToken);
857
+ }
858
+ return newTokenData;
859
+ }
860
+ clearAuthSession() {
861
+ this.tokenManager.clearSession();
862
+ this.userToken = null;
863
+ this.refreshToken = null;
864
+ clearCsrfToken();
865
+ }
691
866
  };
692
867
 
693
868
  // src/modules/auth/helpers.ts
@@ -816,7 +991,7 @@ var Auth = class {
816
991
  const response = await this.http.post(
817
992
  this.isServerMode() ? "/api/auth/users?client_type=mobile" : "/api/auth/users",
818
993
  request,
819
- { credentials: "include" }
994
+ { credentials: "include", skipAuthRefresh: true }
820
995
  );
821
996
  if (response.accessToken && response.user) {
822
997
  this.saveSessionFromResponse(response);
@@ -834,7 +1009,7 @@ var Auth = class {
834
1009
  const response = await this.http.post(
835
1010
  this.isServerMode() ? "/api/auth/sessions?client_type=mobile" : "/api/auth/sessions",
836
1011
  request,
837
- { credentials: "include" }
1012
+ { credentials: "include", skipAuthRefresh: true }
838
1013
  );
839
1014
  this.saveSessionFromResponse(response);
840
1015
  if (response.refreshToken) {
@@ -851,7 +1026,7 @@ var Auth = class {
851
1026
  await this.http.post(
852
1027
  this.isServerMode() ? "/api/auth/logout?client_type=mobile" : "/api/auth/logout",
853
1028
  void 0,
854
- { credentials: "include" }
1029
+ { credentials: "include", skipAuthRefresh: true }
855
1030
  );
856
1031
  } catch {
857
1032
  }
@@ -888,7 +1063,8 @@ var Auth = class {
888
1063
  );
889
1064
  const oauthPath = isBuiltInProvider ? `/api/auth/oauth/${providerKey}` : `/api/auth/oauth/custom/${providerKey}`;
890
1065
  const response = await this.http.get(oauthPath, {
891
- params
1066
+ params,
1067
+ skipAuthRefresh: true
892
1068
  });
893
1069
  if (!this.isServerMode() && typeof window !== "undefined" && !skipBrowserRedirect) {
894
1070
  window.location.href = response.authUrl;
@@ -936,7 +1112,7 @@ var Auth = class {
936
1112
  const response = await this.http.post(
937
1113
  this.isServerMode() ? "/api/auth/oauth/exchange?client_type=mobile" : "/api/auth/oauth/exchange",
938
1114
  request,
939
- { credentials: "include" }
1115
+ { credentials: "include", skipAuthRefresh: true }
940
1116
  );
941
1117
  this.saveSessionFromResponse(response);
942
1118
  return {
@@ -963,7 +1139,7 @@ var Auth = class {
963
1139
  const response = await this.http.post(
964
1140
  "/api/auth/id-token?client_type=mobile",
965
1141
  { provider, token },
966
- { credentials: "include" }
1142
+ { credentials: "include", skipAuthRefresh: true }
967
1143
  );
968
1144
  this.saveSessionFromResponse(response);
969
1145
  if (response.refreshToken) {
@@ -1010,7 +1186,8 @@ var Auth = class {
1010
1186
  this.isServerMode() ? { refresh_token: options?.refreshToken } : void 0,
1011
1187
  {
1012
1188
  headers: csrfToken ? { "X-CSRF-Token": csrfToken } : {},
1013
- credentials: "include"
1189
+ credentials: "include",
1190
+ skipAuthRefresh: true
1014
1191
  }
1015
1192
  );
1016
1193
  if (response.accessToken) {
@@ -1113,7 +1290,9 @@ var Auth = class {
1113
1290
  // ============================================================================
1114
1291
  async resendVerificationEmail(request) {
1115
1292
  try {
1116
- const response = await this.http.post("/api/auth/email/send-verification", request);
1293
+ const response = await this.http.post("/api/auth/email/send-verification", request, {
1294
+ skipAuthRefresh: true
1295
+ });
1117
1296
  return { data: response, error: null };
1118
1297
  } catch (error) {
1119
1298
  return wrapError(
@@ -1127,7 +1306,7 @@ var Auth = class {
1127
1306
  const response = await this.http.post(
1128
1307
  this.isServerMode() ? "/api/auth/email/verify?client_type=mobile" : "/api/auth/email/verify",
1129
1308
  request,
1130
- { credentials: "include" }
1309
+ { credentials: "include", skipAuthRefresh: true }
1131
1310
  );
1132
1311
  this.saveSessionFromResponse(response);
1133
1312
  if (response.refreshToken) {
@@ -1146,7 +1325,9 @@ var Auth = class {
1146
1325
  // ============================================================================
1147
1326
  async sendResetPasswordEmail(request) {
1148
1327
  try {
1149
- const response = await this.http.post("/api/auth/email/send-reset-password", request);
1328
+ const response = await this.http.post("/api/auth/email/send-reset-password", request, {
1329
+ skipAuthRefresh: true
1330
+ });
1150
1331
  return { data: response, error: null };
1151
1332
  } catch (error) {
1152
1333
  return wrapError(
@@ -1159,7 +1340,8 @@ var Auth = class {
1159
1340
  try {
1160
1341
  const response = await this.http.post(
1161
1342
  "/api/auth/email/exchange-reset-password-token",
1162
- request
1343
+ request,
1344
+ { skipAuthRefresh: true }
1163
1345
  );
1164
1346
  return { data: response, error: null };
1165
1347
  } catch (error) {
@@ -1173,7 +1355,8 @@ var Auth = class {
1173
1355
  try {
1174
1356
  const response = await this.http.post(
1175
1357
  "/api/auth/email/reset-password",
1176
- request
1358
+ request,
1359
+ { skipAuthRefresh: true }
1177
1360
  );
1178
1361
  return { data: response, error: null };
1179
1362
  } catch (error) {
@@ -1189,7 +1372,8 @@ var Auth = class {
1189
1372
  async getPublicAuthConfig() {
1190
1373
  try {
1191
1374
  const response = await this.http.get(
1192
- "/api/auth/public-config"
1375
+ "/api/auth/public-config",
1376
+ { skipAuthRefresh: true }
1193
1377
  );
1194
1378
  return { data: response, error: null };
1195
1379
  } catch (error) {
@@ -1203,7 +1387,7 @@ var Auth = class {
1203
1387
 
1204
1388
  // src/modules/database-postgrest.ts
1205
1389
  var import_postgrest_js = require("@supabase/postgrest-js");
1206
- function createInsForgePostgrestFetch(httpClient, tokenManager) {
1390
+ function createInsForgePostgrestFetch(httpClient) {
1207
1391
  return async (input, init) => {
1208
1392
  const url = typeof input === "string" ? input : input.toString();
1209
1393
  const urlObj = new URL(url);
@@ -1211,14 +1395,11 @@ function createInsForgePostgrestFetch(httpClient, tokenManager) {
1211
1395
  const rpcMatch = pathname.match(/^rpc\/(.+)$/);
1212
1396
  const endpoint = rpcMatch ? `/api/database/rpc/${rpcMatch[1]}` : `/api/database/records/${pathname}`;
1213
1397
  const insforgeUrl = `${httpClient.baseUrl}${endpoint}${urlObj.search}`;
1214
- const token = tokenManager.getAccessToken();
1215
- const httpHeaders = httpClient.getHeaders();
1216
- const authToken = token || httpHeaders["Authorization"]?.replace("Bearer ", "");
1217
- const headers = new Headers(init?.headers);
1218
- if (authToken && !headers.has("Authorization")) {
1219
- headers.set("Authorization", `Bearer ${authToken}`);
1220
- }
1221
- const response = await fetch(insforgeUrl, {
1398
+ const headers = new Headers(httpClient.getHeaders());
1399
+ new Headers(init?.headers).forEach((value, key) => {
1400
+ headers.set(key, value);
1401
+ });
1402
+ const response = await httpClient.rawFetch(insforgeUrl, {
1222
1403
  ...init,
1223
1404
  headers
1224
1405
  });
@@ -1226,42 +1407,42 @@ function createInsForgePostgrestFetch(httpClient, tokenManager) {
1226
1407
  };
1227
1408
  }
1228
1409
  var Database = class {
1229
- constructor(httpClient, tokenManager) {
1410
+ constructor(httpClient) {
1230
1411
  this.postgrest = new import_postgrest_js.PostgrestClient("http://dummy", {
1231
- fetch: createInsForgePostgrestFetch(httpClient, tokenManager),
1412
+ fetch: createInsForgePostgrestFetch(httpClient),
1232
1413
  headers: {}
1233
1414
  });
1234
1415
  }
1235
1416
  /**
1236
1417
  * Create a query builder for a table
1237
- *
1418
+ *
1238
1419
  * @example
1239
1420
  * // Basic query
1240
1421
  * const { data, error } = await client.database
1241
1422
  * .from('posts')
1242
1423
  * .select('*')
1243
1424
  * .eq('user_id', userId);
1244
- *
1425
+ *
1245
1426
  * // With count (Supabase style!)
1246
1427
  * const { data, error, count } = await client.database
1247
1428
  * .from('posts')
1248
1429
  * .select('*', { count: 'exact' })
1249
1430
  * .range(0, 9);
1250
- *
1431
+ *
1251
1432
  * // Just get count, no data
1252
1433
  * const { count } = await client.database
1253
1434
  * .from('posts')
1254
1435
  * .select('*', { count: 'exact', head: true });
1255
- *
1436
+ *
1256
1437
  * // Complex queries with OR
1257
1438
  * const { data } = await client.database
1258
1439
  * .from('posts')
1259
1440
  * .select('*, users!inner(*)')
1260
1441
  * .or('status.eq.active,status.eq.pending');
1261
- *
1442
+ *
1262
1443
  * // All features work:
1263
1444
  * - Nested selects
1264
- * - Foreign key expansion
1445
+ * - Foreign key expansion
1265
1446
  * - OR/AND/NOT conditions
1266
1447
  * - Count with head
1267
1448
  * - Range pagination
@@ -2361,7 +2542,7 @@ var InsForgeClient = class {
2361
2542
  this.auth = new Auth(this.http, this.tokenManager, {
2362
2543
  isServerMode: config.isServerMode ?? !!config.edgeFunctionToken
2363
2544
  });
2364
- this.database = new Database(this.http, this.tokenManager);
2545
+ this.database = new Database(this.http);
2365
2546
  this.storage = new Storage(this.http);
2366
2547
  this.ai = new AI(this.http);
2367
2548
  this.functions = new Functions(this.http, config.functionsUrl);