krisspy-sdk 0.6.0 → 0.7.0

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
@@ -17,14 +17,37 @@ pnpm add @krisspy/sdk
17
17
  ## Quick Start
18
18
 
19
19
  ```typescript
20
- import { createClient } from '@krisspy/sdk'
20
+ import { createClient } from 'krisspy-sdk'
21
21
 
22
22
  const krisspy = createClient({
23
23
  backendId: 'your-backend-id',
24
- apiKey: 'your-api-key', // optional for public access
24
+ apiKey: 'your-api-key',
25
25
  })
26
26
  ```
27
27
 
28
+ ### React Native / Expo
29
+
30
+ When using AsyncStorage, call `initialize()` before accessing auth state:
31
+
32
+ ```typescript
33
+ import { createClient } from 'krisspy-sdk'
34
+ import AsyncStorage from '@react-native-async-storage/async-storage'
35
+
36
+ const krisspy = createClient({
37
+ backendId: 'your-backend-id',
38
+ apiKey: 'your-api-key',
39
+ storage: AsyncStorage,
40
+ })
41
+
42
+ // Required — waits for cached session to load from AsyncStorage
43
+ await krisspy.initialize()
44
+
45
+ // Now safe to use
46
+ const user = krisspy.auth.user()
47
+ ```
48
+
49
+ On web (localStorage is synchronous), `initialize()` resolves instantly — calling it is optional but harmless.
50
+
28
51
  ## Authentication
29
52
 
30
53
  ### Sign Up
@@ -227,15 +250,19 @@ console.log('Products:', data)
227
250
  const krisspy = createClient({
228
251
  // Required
229
252
  backendId: 'your-backend-id',
253
+ apiKey: 'your-api-key',
230
254
 
231
255
  // Optional
232
256
  url: 'https://api.krisspy.ai', // Custom API URL
233
- apiKey: 'your-api-key', // For authenticated requests
257
+ storage: AsyncStorage, // React Native: session persistence
234
258
  headers: { // Custom headers
235
259
  'X-Custom-Header': 'value'
236
260
  },
237
261
  debug: true, // Enable debug logging
238
262
  })
263
+
264
+ // React Native only — wait for cached session
265
+ await krisspy.initialize()
239
266
  ```
240
267
 
241
268
  ## License
package/dist/index.d.mts CHANGED
@@ -238,7 +238,16 @@ declare class KrisspyAuth {
238
238
  private listeners;
239
239
  private refreshInterval?;
240
240
  private storage;
241
+ /** Resolves when session restoration is complete (including async storage) */
242
+ private _initialized;
243
+ private _resolveInit;
241
244
  constructor(http: HttpClient, backendId: string, storage?: StorageAdapter);
245
+ /**
246
+ * Wait until session has been restored from storage.
247
+ * On web (localStorage), this resolves immediately.
248
+ * On React Native (AsyncStorage), this waits for the async read to complete.
249
+ */
250
+ initialize(): Promise<void>;
242
251
  /**
243
252
  * Get current session from storage
244
253
  */
@@ -975,6 +984,17 @@ declare class KrisspyClient {
975
984
  private dataMode;
976
985
  private debug;
977
986
  constructor(options: KrisspyClientOptions);
987
+ /**
988
+ * Wait until the client is fully initialized (session restored from storage).
989
+ * **Required on React Native / Expo** when using AsyncStorage.
990
+ * On web (localStorage), this resolves instantly.
991
+ *
992
+ * @example
993
+ * const krisspy = createClient({ backendId: '...', apiKey: '...' });
994
+ * await krisspy.initialize(); // wait for cached session to load
995
+ * const user = krisspy.auth.user(); // now safe to use
996
+ */
997
+ initialize(): Promise<void>;
978
998
  /**
979
999
  * Auth module for user authentication
980
1000
  *
@@ -1213,11 +1233,19 @@ declare class KrisspyClient {
1213
1233
  * @returns KrisspyClient instance
1214
1234
  *
1215
1235
  * @example
1236
+ * // Web (localStorage is sync — works immediately)
1237
+ * const krisspy = createClient({
1238
+ * backendId: 'abc123',
1239
+ * apiKey: 'your-api-key',
1240
+ * })
1241
+ *
1242
+ * // React Native / Expo (AsyncStorage is async — call initialize())
1216
1243
  * const krisspy = createClient({
1217
1244
  * backendId: 'abc123',
1218
1245
  * apiKey: 'your-api-key',
1219
- * url: 'https://krisspy-cloud-backend.thankfulhill-66fc9e74.westeurope.azurecontainerapps.io', // optional
1246
+ * storage: AsyncStorage,
1220
1247
  * })
1248
+ * await krisspy.initialize() // wait for cached session to load
1221
1249
  */
1222
1250
  declare function createClient(options: KrisspyClientOptions): KrisspyClient;
1223
1251
 
package/dist/index.d.ts CHANGED
@@ -238,7 +238,16 @@ declare class KrisspyAuth {
238
238
  private listeners;
239
239
  private refreshInterval?;
240
240
  private storage;
241
+ /** Resolves when session restoration is complete (including async storage) */
242
+ private _initialized;
243
+ private _resolveInit;
241
244
  constructor(http: HttpClient, backendId: string, storage?: StorageAdapter);
245
+ /**
246
+ * Wait until session has been restored from storage.
247
+ * On web (localStorage), this resolves immediately.
248
+ * On React Native (AsyncStorage), this waits for the async read to complete.
249
+ */
250
+ initialize(): Promise<void>;
242
251
  /**
243
252
  * Get current session from storage
244
253
  */
@@ -975,6 +984,17 @@ declare class KrisspyClient {
975
984
  private dataMode;
976
985
  private debug;
977
986
  constructor(options: KrisspyClientOptions);
987
+ /**
988
+ * Wait until the client is fully initialized (session restored from storage).
989
+ * **Required on React Native / Expo** when using AsyncStorage.
990
+ * On web (localStorage), this resolves instantly.
991
+ *
992
+ * @example
993
+ * const krisspy = createClient({ backendId: '...', apiKey: '...' });
994
+ * await krisspy.initialize(); // wait for cached session to load
995
+ * const user = krisspy.auth.user(); // now safe to use
996
+ */
997
+ initialize(): Promise<void>;
978
998
  /**
979
999
  * Auth module for user authentication
980
1000
  *
@@ -1213,11 +1233,19 @@ declare class KrisspyClient {
1213
1233
  * @returns KrisspyClient instance
1214
1234
  *
1215
1235
  * @example
1236
+ * // Web (localStorage is sync — works immediately)
1237
+ * const krisspy = createClient({
1238
+ * backendId: 'abc123',
1239
+ * apiKey: 'your-api-key',
1240
+ * })
1241
+ *
1242
+ * // React Native / Expo (AsyncStorage is async — call initialize())
1216
1243
  * const krisspy = createClient({
1217
1244
  * backendId: 'abc123',
1218
1245
  * apiKey: 'your-api-key',
1219
- * url: 'https://krisspy-cloud-backend.thankfulhill-66fc9e74.westeurope.azurecontainerapps.io', // optional
1246
+ * storage: AsyncStorage,
1220
1247
  * })
1248
+ * await krisspy.initialize() // wait for cached session to load
1221
1249
  */
1222
1250
  declare function createClient(options: KrisspyClientOptions): KrisspyClient;
1223
1251
 
package/dist/index.js CHANGED
@@ -273,8 +273,19 @@ var KrisspyAuth = class {
273
273
  this.http = http;
274
274
  this.backendId = backendId;
275
275
  this.storage = resolveStorage(storage);
276
+ this._initialized = new Promise((resolve) => {
277
+ this._resolveInit = resolve;
278
+ });
276
279
  this.restoreSession();
277
280
  }
281
+ /**
282
+ * Wait until session has been restored from storage.
283
+ * On web (localStorage), this resolves immediately.
284
+ * On React Native (AsyncStorage), this waits for the async read to complete.
285
+ */
286
+ async initialize() {
287
+ return this._initialized;
288
+ }
278
289
  /**
279
290
  * Get current session from storage
280
291
  */
@@ -285,12 +296,18 @@ var KrisspyAuth = class {
285
296
  result.then((stored) => {
286
297
  if (stored) this.hydrateSession(stored);
287
298
  }).catch(() => {
299
+ }).finally(() => {
300
+ this._resolveInit();
288
301
  });
289
- } else if (result) {
290
- this.hydrateSession(result);
302
+ } else {
303
+ if (result) {
304
+ this.hydrateSession(result);
305
+ }
306
+ this._resolveInit();
291
307
  }
292
308
  } catch (err) {
293
309
  console.warn("[Krisspy Auth] Failed to restore session:", err);
310
+ this._resolveInit();
294
311
  }
295
312
  }
296
313
  hydrateSession(stored) {
@@ -1780,6 +1797,19 @@ var KrisspyClient = class {
1780
1797
  }
1781
1798
  });
1782
1799
  }
1800
+ /**
1801
+ * Wait until the client is fully initialized (session restored from storage).
1802
+ * **Required on React Native / Expo** when using AsyncStorage.
1803
+ * On web (localStorage), this resolves instantly.
1804
+ *
1805
+ * @example
1806
+ * const krisspy = createClient({ backendId: '...', apiKey: '...' });
1807
+ * await krisspy.initialize(); // wait for cached session to load
1808
+ * const user = krisspy.auth.user(); // now safe to use
1809
+ */
1810
+ async initialize() {
1811
+ await this._auth.initialize();
1812
+ }
1783
1813
  /**
1784
1814
  * Auth module for user authentication
1785
1815
  *
package/dist/index.mjs CHANGED
@@ -239,8 +239,19 @@ var KrisspyAuth = class {
239
239
  this.http = http;
240
240
  this.backendId = backendId;
241
241
  this.storage = resolveStorage(storage);
242
+ this._initialized = new Promise((resolve) => {
243
+ this._resolveInit = resolve;
244
+ });
242
245
  this.restoreSession();
243
246
  }
247
+ /**
248
+ * Wait until session has been restored from storage.
249
+ * On web (localStorage), this resolves immediately.
250
+ * On React Native (AsyncStorage), this waits for the async read to complete.
251
+ */
252
+ async initialize() {
253
+ return this._initialized;
254
+ }
244
255
  /**
245
256
  * Get current session from storage
246
257
  */
@@ -251,12 +262,18 @@ var KrisspyAuth = class {
251
262
  result.then((stored) => {
252
263
  if (stored) this.hydrateSession(stored);
253
264
  }).catch(() => {
265
+ }).finally(() => {
266
+ this._resolveInit();
254
267
  });
255
- } else if (result) {
256
- this.hydrateSession(result);
268
+ } else {
269
+ if (result) {
270
+ this.hydrateSession(result);
271
+ }
272
+ this._resolveInit();
257
273
  }
258
274
  } catch (err) {
259
275
  console.warn("[Krisspy Auth] Failed to restore session:", err);
276
+ this._resolveInit();
260
277
  }
261
278
  }
262
279
  hydrateSession(stored) {
@@ -1746,6 +1763,19 @@ var KrisspyClient = class {
1746
1763
  }
1747
1764
  });
1748
1765
  }
1766
+ /**
1767
+ * Wait until the client is fully initialized (session restored from storage).
1768
+ * **Required on React Native / Expo** when using AsyncStorage.
1769
+ * On web (localStorage), this resolves instantly.
1770
+ *
1771
+ * @example
1772
+ * const krisspy = createClient({ backendId: '...', apiKey: '...' });
1773
+ * await krisspy.initialize(); // wait for cached session to load
1774
+ * const user = krisspy.auth.user(); // now safe to use
1775
+ */
1776
+ async initialize() {
1777
+ await this._auth.initialize();
1778
+ }
1749
1779
  /**
1750
1780
  * Auth module for user authentication
1751
1781
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "krisspy-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Krisspy Cloud SDK - Database, Auth, Storage, and Functions for your apps",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",