@palbase/web 1.8.0 → 1.9.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.
@@ -1,7 +1,7 @@
1
- import { v as PalbeConfig, T as PalbeRuntime } from './analytics-facade-DfJ420F5.cjs';
2
- export { V as buildRuntime } from './analytics-facade-DfJ420F5.cjs';
1
+ import { v as PalbeConfig, T as PalbeRuntime } from './analytics-facade-DFd5LB3_.cjs';
2
+ export { V as buildRuntime } from './analytics-facade-DFd5LB3_.cjs';
3
3
  import { B as BackendError } from './errors-fDoNdTrJ.cjs';
4
- export { P as PB, c as createBoundClient } from './pb-BwQwp411.cjs';
4
+ export { P as PB, c as createBoundClient } from './pb-D_fuhafL.cjs';
5
5
  import 'livekit-client';
6
6
  import './storage-BPaeSG8K.cjs';
7
7
  import './pooled-flags-Bwq4usn0.js';
@@ -1,7 +1,7 @@
1
- import { v as PalbeConfig, T as PalbeRuntime } from './analytics-facade-CgURkjpP.js';
2
- export { V as buildRuntime } from './analytics-facade-CgURkjpP.js';
1
+ import { v as PalbeConfig, T as PalbeRuntime } from './analytics-facade-DsvKx5A5.js';
2
+ export { V as buildRuntime } from './analytics-facade-DsvKx5A5.js';
3
3
  import { B as BackendError } from './errors-fDoNdTrJ.js';
4
- export { P as PB, c as createBoundClient } from './pb-C1v9ErPy.js';
4
+ export { P as PB, c as createBoundClient } from './pb-CDVMy1l1.js';
5
5
  import 'livekit-client';
6
6
  import './storage-BPaeSG8K.js';
7
7
  import './pooled-flags-Bwq4usn0.js';
package/dist/internal.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  createBoundClient,
7
7
  getRuntime,
8
8
  onConfigured
9
- } from "./chunk-AWVNDAMG.js";
9
+ } from "./chunk-I3ZMB7XM.js";
10
10
  export {
11
11
  __configure,
12
12
  __registerNamespaces,
@@ -1312,6 +1312,8 @@ var PalbeAuth = class {
1312
1312
  // suppresses AuthClient's TOKEN_REFRESHED during re-signIn
1313
1313
  signedInState = false;
1314
1314
  // dedupes AuthClient's repeated SIGNED_OUT events
1315
+ hydratingUser = false;
1316
+ // guards hydrateUser() to a single boot fetch
1315
1317
  stateListeners = /* @__PURE__ */ new Set();
1316
1318
  eventListeners = /* @__PURE__ */ new Set();
1317
1319
  userListeners = /* @__PURE__ */ new Set();
@@ -1364,13 +1366,37 @@ var PalbeAuth = class {
1364
1366
  if (changed) for (const cb of this.userListeners) this.safeInvoke(() => cb(user));
1365
1367
  return user;
1366
1368
  }
1369
+ /**
1370
+ * Restore the user after a session was rehydrated from storage (page reload).
1371
+ * Hydration in buildRuntime restores the TOKENS synchronously, but the access
1372
+ * token JWT does not carry emailVerified/createdAt, so the full AuthUser can't
1373
+ * be reconstructed offline — this fetches GET /auth/user once and announces
1374
+ * `signedIn`, so the app no longer has to `await pb.auth.refreshUser()` itself
1375
+ * on boot. Idempotent (runs once), browser-safe (no-op when not signed in or
1376
+ * a user is already cached), and never throws (a boot-time network failure
1377
+ * must not break app startup — isSignedIn stays true, the app can retry).
1378
+ */
1379
+ hydrateUser() {
1380
+ if (this.hydratingUser || this.cachedUser || !this.isSignedIn) return;
1381
+ this.hydratingUser = true;
1382
+ void this.refreshUser().then((user) => {
1383
+ if (this.isSignedIn) {
1384
+ this.signedInState = true;
1385
+ this.emitState({ status: "signedIn", user });
1386
+ }
1387
+ }).catch(() => {
1388
+ }).finally(() => {
1389
+ this.hydratingUser = false;
1390
+ });
1391
+ }
1367
1392
  // ── listeners ──────────────────────────────────────────
1368
1393
  /**
1369
1394
  * Subscribe to signed-in/signed-out state. Fires immediately with the
1370
- * current snapshot (iOS parity). NOTE: a restored session (page reload) has
1371
- * no cached user yet, so the immediate snapshot reports signedOut even when
1372
- * `isSignedIn` is true call `refreshUser()` on boot to populate the user
1373
- * and rely on `isSignedIn` for the session truth.
1395
+ * current snapshot (iOS parity). A restored session (page reload) hydrates
1396
+ * the user asynchronously via `hydrateUser()` (fired once at boot), so the
1397
+ * FIRST snapshot may report signedOut for a tick even when `isSignedIn` is
1398
+ * true; the listener then fires again with `signedIn` once the user lands.
1399
+ * Rely on `isSignedIn` for the session truth if you need it synchronously.
1374
1400
  */
1375
1401
  onAuthStateChange(callback) {
1376
1402
  this.stateListeners.add(callback);
@@ -8724,7 +8750,7 @@ function defaultSessionStorage(key) {
8724
8750
  }
8725
8751
 
8726
8752
  // src/version.ts
8727
- var VERSION = "1.8.0";
8753
+ var VERSION = "1.9.0";
8728
8754
 
8729
8755
  // src/runtime.ts
8730
8756
  function buildRuntime(config) {
@@ -8842,6 +8868,7 @@ function buildRuntime(config) {
8842
8868
  void rt.perf;
8843
8869
  if (typeof document !== "undefined") {
8844
8870
  void new PerfConfigClient().fetchConfig(rt, rt.perf);
8871
+ rt.auth.hydrateUser();
8845
8872
  }
8846
8873
  recordColdStart(rt);
8847
8874
  observeWebVitals((item) => rt.perf.record(item));