@linabase/js 0.4.0 → 0.4.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.cjs CHANGED
@@ -694,6 +694,8 @@ var BucketClient = class {
694
694
  var AuthClient = class {
695
695
  request;
696
696
  listeners = [];
697
+ /** Promise that resolves when session restore from storage is complete. */
698
+ _restorePromise = Promise.resolve();
697
699
  currentSession = null;
698
700
  /**
699
701
  * Callback that the parent LinabaseClient can set to update the Authorization
@@ -1064,6 +1066,11 @@ var AuthClient = class {
1064
1066
  // ─── Auth State Listener ───────────────────────────────────
1065
1067
  onAuthStateChange(callback) {
1066
1068
  this.listeners.push(callback);
1069
+ this._restorePromise.then(() => {
1070
+ if (this.listeners.includes(callback)) {
1071
+ callback("INITIAL_SESSION", this.currentSession);
1072
+ }
1073
+ });
1067
1074
  return {
1068
1075
  unsubscribe: () => {
1069
1076
  this.listeners = this.listeners.filter((l) => l !== callback);
@@ -1161,7 +1168,7 @@ function createClient(config) {
1161
1168
  sessionStorage.removeItem(sessionKey);
1162
1169
  }
1163
1170
  });
1164
- Promise.resolve(sessionStorage.getItem(sessionKey)).then((raw) => {
1171
+ authClient._restorePromise = Promise.resolve(sessionStorage.getItem(sessionKey)).then((raw) => {
1165
1172
  if (raw) {
1166
1173
  try {
1167
1174
  authClient.setSession(JSON.parse(raw));
@@ -1173,10 +1180,12 @@ function createClient(config) {
1173
1180
  }
1174
1181
  function buildClient(reqFn, branchSlug) {
1175
1182
  const rc = new RpcClient(reqFn);
1176
- const ac = new AuthClient(reqFn);
1177
- ac.onSessionChange = (session) => {
1178
- accessToken = session?.access_token || null;
1179
- };
1183
+ const ac = branchSlug ? new AuthClient(reqFn) : authClient;
1184
+ if (branchSlug) {
1185
+ ac.onSessionChange = (session) => {
1186
+ accessToken = session?.access_token || null;
1187
+ };
1188
+ }
1180
1189
  return {
1181
1190
  from: (table) => new DatabaseClient(reqFn, table),
1182
1191
  schema: (schemaName) => ({
@@ -1188,7 +1197,7 @@ function createClient(config) {
1188
1197
  }),
1189
1198
  rpc: (fn, args) => rc.call(fn, args),
1190
1199
  storage: new StorageClient(reqFn, baseUrl),
1191
- auth: branchSlug ? authClient : ac,
1200
+ auth: ac,
1192
1201
  functions: new FunctionsClient(reqFn),
1193
1202
  /** Realtime channel (stub; not yet supported). Returns a chainable no-op. */
1194
1203
  channel: (_name) => {
package/dist/index.d.cts CHANGED
@@ -266,6 +266,8 @@ interface AuthUser {
266
266
  declare class AuthClient {
267
267
  private request;
268
268
  private listeners;
269
+ /** Promise that resolves when session restore from storage is complete. */
270
+ _restorePromise: Promise<void>;
269
271
  private currentSession;
270
272
  /**
271
273
  * Callback that the parent LinabaseClient can set to update the Authorization
package/dist/index.d.ts CHANGED
@@ -266,6 +266,8 @@ interface AuthUser {
266
266
  declare class AuthClient {
267
267
  private request;
268
268
  private listeners;
269
+ /** Promise that resolves when session restore from storage is complete. */
270
+ _restorePromise: Promise<void>;
269
271
  private currentSession;
270
272
  /**
271
273
  * Callback that the parent LinabaseClient can set to update the Authorization
package/dist/index.js CHANGED
@@ -662,6 +662,8 @@ var BucketClient = class {
662
662
  var AuthClient = class {
663
663
  request;
664
664
  listeners = [];
665
+ /** Promise that resolves when session restore from storage is complete. */
666
+ _restorePromise = Promise.resolve();
665
667
  currentSession = null;
666
668
  /**
667
669
  * Callback that the parent LinabaseClient can set to update the Authorization
@@ -1032,6 +1034,11 @@ var AuthClient = class {
1032
1034
  // ─── Auth State Listener ───────────────────────────────────
1033
1035
  onAuthStateChange(callback) {
1034
1036
  this.listeners.push(callback);
1037
+ this._restorePromise.then(() => {
1038
+ if (this.listeners.includes(callback)) {
1039
+ callback("INITIAL_SESSION", this.currentSession);
1040
+ }
1041
+ });
1035
1042
  return {
1036
1043
  unsubscribe: () => {
1037
1044
  this.listeners = this.listeners.filter((l) => l !== callback);
@@ -1129,7 +1136,7 @@ function createClient(config) {
1129
1136
  sessionStorage.removeItem(sessionKey);
1130
1137
  }
1131
1138
  });
1132
- Promise.resolve(sessionStorage.getItem(sessionKey)).then((raw) => {
1139
+ authClient._restorePromise = Promise.resolve(sessionStorage.getItem(sessionKey)).then((raw) => {
1133
1140
  if (raw) {
1134
1141
  try {
1135
1142
  authClient.setSession(JSON.parse(raw));
@@ -1141,10 +1148,12 @@ function createClient(config) {
1141
1148
  }
1142
1149
  function buildClient(reqFn, branchSlug) {
1143
1150
  const rc = new RpcClient(reqFn);
1144
- const ac = new AuthClient(reqFn);
1145
- ac.onSessionChange = (session) => {
1146
- accessToken = session?.access_token || null;
1147
- };
1151
+ const ac = branchSlug ? new AuthClient(reqFn) : authClient;
1152
+ if (branchSlug) {
1153
+ ac.onSessionChange = (session) => {
1154
+ accessToken = session?.access_token || null;
1155
+ };
1156
+ }
1148
1157
  return {
1149
1158
  from: (table) => new DatabaseClient(reqFn, table),
1150
1159
  schema: (schemaName) => ({
@@ -1156,7 +1165,7 @@ function createClient(config) {
1156
1165
  }),
1157
1166
  rpc: (fn, args) => rc.call(fn, args),
1158
1167
  storage: new StorageClient(reqFn, baseUrl),
1159
- auth: branchSlug ? authClient : ac,
1168
+ auth: ac,
1160
1169
  functions: new FunctionsClient(reqFn),
1161
1170
  /** Realtime channel (stub; not yet supported). Returns a chainable no-op. */
1162
1171
  channel: (_name) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linabase/js",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "JavaScript/TypeScript client SDK for Linabase (database, storage, auth)",
5
5
  "license": "MIT",
6
6
  "type": "module",