@linabase/js 0.2.3 → 0.3.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/dist/index.cjs CHANGED
@@ -1072,9 +1072,30 @@ function createClient(config) {
1072
1072
  });
1073
1073
  }
1074
1074
  const authClient = new AuthClient(request);
1075
+ const persistSession = config.auth?.persistSession !== false && !!config.auth?.storage;
1076
+ const sessionStorage = config.auth?.storage;
1077
+ const sessionKey = config.auth?.storageKey || "@linabase/session";
1075
1078
  authClient.onSessionChange = (session) => {
1076
1079
  accessToken = session?.access_token || null;
1077
1080
  };
1081
+ if (persistSession && sessionStorage) {
1082
+ authClient.onAuthStateChange((event, session) => {
1083
+ if (session) {
1084
+ sessionStorage.setItem(sessionKey, JSON.stringify(session));
1085
+ } else if (event === "SIGNED_OUT") {
1086
+ sessionStorage.removeItem(sessionKey);
1087
+ }
1088
+ });
1089
+ Promise.resolve(sessionStorage.getItem(sessionKey)).then((raw) => {
1090
+ if (raw) {
1091
+ try {
1092
+ authClient.setSession(JSON.parse(raw));
1093
+ } catch {
1094
+ sessionStorage.removeItem(sessionKey);
1095
+ }
1096
+ }
1097
+ });
1098
+ }
1078
1099
  function buildClient(reqFn, branchSlug) {
1079
1100
  const rc = new RpcClient(reqFn);
1080
1101
  const ac = new AuthClient(reqFn);
package/dist/index.d.cts CHANGED
@@ -416,10 +416,24 @@ declare class FunctionsClient {
416
416
  }>;
417
417
  }
418
418
 
419
+ /**
420
+ * Minimal async key-value storage interface (compatible with AsyncStorage, localStorage, etc.)
421
+ */
422
+ interface SessionStorage {
423
+ getItem(key: string): Promise<string | null> | string | null;
424
+ setItem(key: string, value: string): Promise<void> | void;
425
+ removeItem(key: string): Promise<void> | void;
426
+ }
419
427
  interface LinabaseConfig {
420
428
  url: string;
421
429
  anonKey?: string;
422
430
  serviceRoleKey?: string;
431
+ /** Persistent storage for auth sessions (e.g., AsyncStorage for React Native). */
432
+ auth?: {
433
+ storage?: SessionStorage;
434
+ storageKey?: string;
435
+ persistSession?: boolean;
436
+ };
423
437
  }
424
438
  interface LinabaseClient {
425
439
  from: (table: string) => DatabaseClient;
@@ -440,4 +454,4 @@ interface LinabaseClient {
440
454
  }
441
455
  declare function createClient(config: LinabaseConfig): LinabaseClient;
442
456
 
443
- export { AuthClient, type AuthSession, type AuthUser, BucketClient, type CsvQueryResult, DatabaseClient, type FunctionInvokeOptions, FunctionsClient, type LinabaseClient, type LinabaseConfig, type OAuthProvider, type PostgrestError, type QueryResult, RpcClient, type SingleQueryResult, StorageClient, createClient };
457
+ export { AuthClient, type AuthSession, type AuthUser, BucketClient, type CsvQueryResult, DatabaseClient, type FunctionInvokeOptions, FunctionsClient, type LinabaseClient, type LinabaseConfig, type OAuthProvider, type PostgrestError, type QueryResult, RpcClient, type SessionStorage, type SingleQueryResult, StorageClient, createClient };
package/dist/index.d.ts CHANGED
@@ -416,10 +416,24 @@ declare class FunctionsClient {
416
416
  }>;
417
417
  }
418
418
 
419
+ /**
420
+ * Minimal async key-value storage interface (compatible with AsyncStorage, localStorage, etc.)
421
+ */
422
+ interface SessionStorage {
423
+ getItem(key: string): Promise<string | null> | string | null;
424
+ setItem(key: string, value: string): Promise<void> | void;
425
+ removeItem(key: string): Promise<void> | void;
426
+ }
419
427
  interface LinabaseConfig {
420
428
  url: string;
421
429
  anonKey?: string;
422
430
  serviceRoleKey?: string;
431
+ /** Persistent storage for auth sessions (e.g., AsyncStorage for React Native). */
432
+ auth?: {
433
+ storage?: SessionStorage;
434
+ storageKey?: string;
435
+ persistSession?: boolean;
436
+ };
423
437
  }
424
438
  interface LinabaseClient {
425
439
  from: (table: string) => DatabaseClient;
@@ -440,4 +454,4 @@ interface LinabaseClient {
440
454
  }
441
455
  declare function createClient(config: LinabaseConfig): LinabaseClient;
442
456
 
443
- export { AuthClient, type AuthSession, type AuthUser, BucketClient, type CsvQueryResult, DatabaseClient, type FunctionInvokeOptions, FunctionsClient, type LinabaseClient, type LinabaseConfig, type OAuthProvider, type PostgrestError, type QueryResult, RpcClient, type SingleQueryResult, StorageClient, createClient };
457
+ export { AuthClient, type AuthSession, type AuthUser, BucketClient, type CsvQueryResult, DatabaseClient, type FunctionInvokeOptions, FunctionsClient, type LinabaseClient, type LinabaseConfig, type OAuthProvider, type PostgrestError, type QueryResult, RpcClient, type SessionStorage, type SingleQueryResult, StorageClient, createClient };
package/dist/index.js CHANGED
@@ -1040,9 +1040,30 @@ function createClient(config) {
1040
1040
  });
1041
1041
  }
1042
1042
  const authClient = new AuthClient(request);
1043
+ const persistSession = config.auth?.persistSession !== false && !!config.auth?.storage;
1044
+ const sessionStorage = config.auth?.storage;
1045
+ const sessionKey = config.auth?.storageKey || "@linabase/session";
1043
1046
  authClient.onSessionChange = (session) => {
1044
1047
  accessToken = session?.access_token || null;
1045
1048
  };
1049
+ if (persistSession && sessionStorage) {
1050
+ authClient.onAuthStateChange((event, session) => {
1051
+ if (session) {
1052
+ sessionStorage.setItem(sessionKey, JSON.stringify(session));
1053
+ } else if (event === "SIGNED_OUT") {
1054
+ sessionStorage.removeItem(sessionKey);
1055
+ }
1056
+ });
1057
+ Promise.resolve(sessionStorage.getItem(sessionKey)).then((raw) => {
1058
+ if (raw) {
1059
+ try {
1060
+ authClient.setSession(JSON.parse(raw));
1061
+ } catch {
1062
+ sessionStorage.removeItem(sessionKey);
1063
+ }
1064
+ }
1065
+ });
1066
+ }
1046
1067
  function buildClient(reqFn, branchSlug) {
1047
1068
  const rc = new RpcClient(reqFn);
1048
1069
  const ac = new AuthClient(reqFn);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linabase/js",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "JavaScript/TypeScript client SDK for Linabase (database, storage, auth)",
5
5
  "license": "MIT",
6
6
  "type": "module",