@fluxbase/sdk 0.0.1-rc.38 → 0.0.1-rc.40

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.cts CHANGED
@@ -1668,6 +1668,7 @@ declare class FluxbaseAuth {
1668
1668
  private autoRefresh;
1669
1669
  private refreshTimer;
1670
1670
  private stateChangeListeners;
1671
+ private storage;
1671
1672
  constructor(fetch: FluxbaseFetch, autoRefresh?: boolean, persist?: boolean);
1672
1673
  /**
1673
1674
  * Get the current session (Supabase-compatible)
package/dist/index.d.ts CHANGED
@@ -1668,6 +1668,7 @@ declare class FluxbaseAuth {
1668
1668
  private autoRefresh;
1669
1669
  private refreshTimer;
1670
1670
  private stateChangeListeners;
1671
+ private storage;
1671
1672
  constructor(fetch: FluxbaseFetch, autoRefresh?: boolean, persist?: boolean);
1672
1673
  /**
1673
1674
  * Get the current session (Supabase-compatible)
package/dist/index.js CHANGED
@@ -139,16 +139,60 @@ async function wrapAsyncVoid(operation) {
139
139
 
140
140
  // src/auth.ts
141
141
  var AUTH_STORAGE_KEY = "fluxbase.auth.session";
142
+ var MemoryStorage = class {
143
+ constructor() {
144
+ this.store = /* @__PURE__ */ new Map();
145
+ }
146
+ get length() {
147
+ return this.store.size;
148
+ }
149
+ clear() {
150
+ this.store.clear();
151
+ }
152
+ getItem(key) {
153
+ return this.store.get(key) ?? null;
154
+ }
155
+ setItem(key, value) {
156
+ this.store.set(key, value);
157
+ }
158
+ removeItem(key) {
159
+ this.store.delete(key);
160
+ }
161
+ key(index) {
162
+ return [...this.store.keys()][index] ?? null;
163
+ }
164
+ };
165
+ function isLocalStorageAvailable() {
166
+ try {
167
+ if (typeof localStorage === "undefined") {
168
+ return false;
169
+ }
170
+ const testKey = "__fluxbase_storage_test__";
171
+ localStorage.setItem(testKey, "test");
172
+ localStorage.removeItem(testKey);
173
+ return true;
174
+ } catch {
175
+ return false;
176
+ }
177
+ }
142
178
  var FluxbaseAuth = class {
143
179
  constructor(fetch2, autoRefresh = true, persist = true) {
144
180
  this.session = null;
145
181
  this.refreshTimer = null;
146
182
  this.stateChangeListeners = /* @__PURE__ */ new Set();
183
+ this.storage = null;
147
184
  this.fetch = fetch2;
148
185
  this.persist = persist;
149
186
  this.autoRefresh = autoRefresh;
150
- if (this.persist && typeof localStorage !== "undefined") {
151
- const stored = localStorage.getItem(AUTH_STORAGE_KEY);
187
+ if (this.persist) {
188
+ if (isLocalStorageAvailable()) {
189
+ this.storage = localStorage;
190
+ } else {
191
+ this.storage = new MemoryStorage();
192
+ }
193
+ }
194
+ if (this.storage) {
195
+ const stored = this.storage.getItem(AUTH_STORAGE_KEY);
152
196
  if (stored) {
153
197
  try {
154
198
  this.session = JSON.parse(stored);
@@ -157,7 +201,7 @@ var FluxbaseAuth = class {
157
201
  this.scheduleTokenRefresh();
158
202
  }
159
203
  } catch {
160
- localStorage.removeItem(AUTH_STORAGE_KEY);
204
+ this.storage.removeItem(AUTH_STORAGE_KEY);
161
205
  }
162
206
  }
163
207
  }
@@ -794,8 +838,8 @@ var FluxbaseAuth = class {
794
838
  clearSession() {
795
839
  this.session = null;
796
840
  this.fetch.setAuthToken(null);
797
- if (this.persist && typeof localStorage !== "undefined") {
798
- localStorage.removeItem(AUTH_STORAGE_KEY);
841
+ if (this.storage) {
842
+ this.storage.removeItem(AUTH_STORAGE_KEY);
799
843
  }
800
844
  if (this.refreshTimer) {
801
845
  clearTimeout(this.refreshTimer);
@@ -807,8 +851,8 @@ var FluxbaseAuth = class {
807
851
  * Internal: Save session to storage
808
852
  */
809
853
  saveSession() {
810
- if (this.persist && typeof localStorage !== "undefined" && this.session) {
811
- localStorage.setItem(AUTH_STORAGE_KEY, JSON.stringify(this.session));
854
+ if (this.storage && this.session) {
855
+ this.storage.setItem(AUTH_STORAGE_KEY, JSON.stringify(this.session));
812
856
  }
813
857
  }
814
858
  /**