@insforge/sdk 1.0.5-dev.1 → 1.0.5-dev.2

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
@@ -105,7 +105,6 @@ declare class TokenManager {
105
105
  private user;
106
106
  private storage;
107
107
  private _mode;
108
- onTokenChange: (() => void) | null;
109
108
  constructor(storage?: TokenStorage);
110
109
  /**
111
110
  * Get current mode
@@ -659,8 +658,7 @@ declare class Realtime {
659
658
  private connectPromise;
660
659
  private subscribedChannels;
661
660
  private eventListeners;
662
- private anonKey?;
663
- constructor(baseUrl: string, tokenManager: TokenManager, anonKey?: string);
661
+ constructor(baseUrl: string, tokenManager: TokenManager);
664
662
  private notifyListeners;
665
663
  /**
666
664
  * Connect to the realtime server
@@ -671,12 +669,6 @@ declare class Realtime {
671
669
  * Disconnect from the realtime server
672
670
  */
673
671
  disconnect(): void;
674
- /**
675
- * Handle token changes (e.g., after auth refresh)
676
- * Updates socket auth so reconnects use the new token
677
- * If connected, triggers reconnect to apply new token immediately
678
- */
679
- private onTokenChange;
680
672
  /**
681
673
  * Check if connected to the realtime server
682
674
  */
package/dist/index.d.ts CHANGED
@@ -105,7 +105,6 @@ declare class TokenManager {
105
105
  private user;
106
106
  private storage;
107
107
  private _mode;
108
- onTokenChange: (() => void) | null;
109
108
  constructor(storage?: TokenStorage);
110
109
  /**
111
110
  * Get current mode
@@ -659,8 +658,7 @@ declare class Realtime {
659
658
  private connectPromise;
660
659
  private subscribedChannels;
661
660
  private eventListeners;
662
- private anonKey?;
663
- constructor(baseUrl: string, tokenManager: TokenManager, anonKey?: string);
661
+ constructor(baseUrl: string, tokenManager: TokenManager);
664
662
  private notifyListeners;
665
663
  /**
666
664
  * Connect to the realtime server
@@ -671,12 +669,6 @@ declare class Realtime {
671
669
  * Disconnect from the realtime server
672
670
  */
673
671
  disconnect(): void;
674
- /**
675
- * Handle token changes (e.g., after auth refresh)
676
- * Updates socket auth so reconnects use the new token
677
- * If connected, triggers reconnect to apply new token immediately
678
- */
679
- private onTokenChange;
680
672
  /**
681
673
  * Check if connected to the realtime server
682
674
  */
package/dist/index.js CHANGED
@@ -202,8 +202,6 @@ var TokenManager = class {
202
202
  this.user = null;
203
203
  // Mode: 'memory' (new backend) or 'storage' (legacy backend, default)
204
204
  this._mode = "storage";
205
- // Callback for token changes (used by realtime to reconnect with new token)
206
- this.onTokenChange = null;
207
205
  if (storage) {
208
206
  this.storage = storage;
209
207
  } else if (typeof window !== "undefined" && window.localStorage) {
@@ -264,16 +262,12 @@ var TokenManager = class {
264
262
  * Save session (memory always, localStorage only in storage mode)
265
263
  */
266
264
  saveSession(session) {
267
- const tokenChanged = session.accessToken !== this.accessToken;
268
265
  this.accessToken = session.accessToken;
269
266
  this.user = session.user;
270
267
  if (this._mode === "storage") {
271
268
  this.storage.setItem(TOKEN_KEY, session.accessToken);
272
269
  this.storage.setItem(USER_KEY, JSON.stringify(session.user));
273
270
  }
274
- if (tokenChanged && this.onTokenChange) {
275
- this.onTokenChange();
276
- }
277
271
  }
278
272
  /**
279
273
  * Get current session
@@ -297,14 +291,10 @@ var TokenManager = class {
297
291
  * Set access token
298
292
  */
299
293
  setAccessToken(token) {
300
- const tokenChanged = token !== this.accessToken;
301
294
  this.accessToken = token;
302
295
  if (this._mode === "storage") {
303
296
  this.storage.setItem(TOKEN_KEY, token);
304
297
  }
305
- if (tokenChanged && this.onTokenChange) {
306
- this.onTokenChange();
307
- }
308
298
  }
309
299
  /**
310
300
  * Get user
@@ -325,14 +315,10 @@ var TokenManager = class {
325
315
  * Clear session (both memory and localStorage)
326
316
  */
327
317
  clearSession() {
328
- const hadToken = this.accessToken !== null;
329
318
  this.accessToken = null;
330
319
  this.user = null;
331
320
  this.storage.removeItem(TOKEN_KEY);
332
321
  this.storage.removeItem(USER_KEY);
333
- if (hadToken && this.onTokenChange) {
334
- this.onTokenChange();
335
- }
336
322
  }
337
323
  /**
338
324
  * Check if there's a session in localStorage (for legacy detection)
@@ -719,6 +705,13 @@ var Auth = class {
719
705
  "/api/auth/profiles/current",
720
706
  { profile }
721
707
  );
708
+ const currentUser = this.tokenManager.getUser();
709
+ if (currentUser && response.profile !== void 0) {
710
+ this.tokenManager.setUser({
711
+ ...currentUser,
712
+ profile: response.profile
713
+ });
714
+ }
722
715
  return {
723
716
  data: response,
724
717
  error: null
@@ -1514,15 +1507,13 @@ var Functions = class {
1514
1507
  var import_socket = require("socket.io-client");
1515
1508
  var CONNECT_TIMEOUT = 1e4;
1516
1509
  var Realtime = class {
1517
- constructor(baseUrl, tokenManager, anonKey) {
1510
+ constructor(baseUrl, tokenManager) {
1518
1511
  this.socket = null;
1519
1512
  this.connectPromise = null;
1520
1513
  this.subscribedChannels = /* @__PURE__ */ new Set();
1521
1514
  this.eventListeners = /* @__PURE__ */ new Map();
1522
1515
  this.baseUrl = baseUrl;
1523
1516
  this.tokenManager = tokenManager;
1524
- this.anonKey = anonKey;
1525
- this.tokenManager.onTokenChange = () => this.onTokenChange();
1526
1517
  }
1527
1518
  notifyListeners(event, payload) {
1528
1519
  const listeners = this.eventListeners.get(event);
@@ -1548,7 +1539,7 @@ var Realtime = class {
1548
1539
  }
1549
1540
  this.connectPromise = new Promise((resolve, reject) => {
1550
1541
  const session = this.tokenManager.getSession();
1551
- const token = session?.accessToken ?? this.anonKey;
1542
+ const token = session?.accessToken;
1552
1543
  this.socket = (0, import_socket.io)(this.baseUrl, {
1553
1544
  transports: ["websocket"],
1554
1545
  auth: token ? { token } : void 0
@@ -1614,22 +1605,6 @@ var Realtime = class {
1614
1605
  }
1615
1606
  this.subscribedChannels.clear();
1616
1607
  }
1617
- /**
1618
- * Handle token changes (e.g., after auth refresh)
1619
- * Updates socket auth so reconnects use the new token
1620
- * If connected, triggers reconnect to apply new token immediately
1621
- */
1622
- onTokenChange() {
1623
- const session = this.tokenManager.getSession();
1624
- const token = session?.accessToken ?? this.anonKey;
1625
- if (this.socket) {
1626
- this.socket.auth = token ? { token } : {};
1627
- }
1628
- if (this.socket?.connected) {
1629
- this.socket.disconnect();
1630
- this.socket.connect();
1631
- }
1632
- }
1633
1608
  /**
1634
1609
  * Check if connected to the realtime server
1635
1610
  */
@@ -1806,7 +1781,7 @@ var InsForgeClient = class {
1806
1781
  this.storage = new Storage(this.http);
1807
1782
  this.ai = new AI(this.http);
1808
1783
  this.functions = new Functions(this.http);
1809
- this.realtime = new Realtime(this.http.baseUrl, this.tokenManager, config.anonKey);
1784
+ this.realtime = new Realtime(this.http.baseUrl, this.tokenManager);
1810
1785
  this.emails = new Emails(this.http);
1811
1786
  }
1812
1787
  /**