@pylonsync/sync 0.3.142 → 0.3.144

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +27 -9
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.142",
6
+ "version": "0.3.144",
7
7
  "type": "module",
8
8
  "main": "src/index.ts",
9
9
  "types": "src/index.ts",
package/src/index.ts CHANGED
@@ -1113,6 +1113,19 @@ export class SyncEngine {
1113
1113
  return;
1114
1114
  }
1115
1115
 
1116
+ // Session mutated server-side. Fires for select-org / clear-org
1117
+ // / session revoke — every tab connected as this user gets the
1118
+ // envelope (cross-machine too via the cluster bus). Trigger
1119
+ // a fresh /api/auth/me read which updates the cached session
1120
+ // AND, on tenant flip, resets the replica so stale rows from
1121
+ // the previous tenant disappear. App code calling
1122
+ // /api/auth/select-org via raw fetch no longer needs the
1123
+ // manual `notifySessionChanged()` step.
1124
+ if (msg.type === "session-changed") {
1125
+ void this.refreshResolvedSession();
1126
+ return;
1127
+ }
1128
+
1116
1129
  // Reactive query push: the server-side ReactiveRegistry re-ran
1117
1130
  // a subscribed handler and the result hash changed. Route to
1118
1131
  // the handler registered by `subscribeReactive` so the React
@@ -1679,16 +1692,21 @@ export class SyncEngine {
1679
1692
  }
1680
1693
 
1681
1694
  /**
1682
- * Public alias for `refreshResolvedSession`. Call after anything that
1683
- * mutates the server session (sign-in, sign-out, `/api/auth/select-org`)
1684
- * so the cached session and React subscribers pick up the change without
1685
- * waiting for the next pull.
1695
+ * Public alias for `refreshResolvedSession`. Almost never needed by
1696
+ * app code today — the server pushes a `session-changed` envelope
1697
+ * over WS whenever the session is mutated (select-org, clear-org,
1698
+ * session revoke, even from other tabs / admin tools / server
1699
+ * actions), and the engine's WS handler refreshes automatically.
1700
+ *
1701
+ * Kept as an escape hatch for the rare case where you mutated the
1702
+ * session via a path that doesn't go through the framework's auth
1703
+ * surface (e.g. directly writing to the SessionStore from a Rust
1704
+ * plugin that bypassed `notify_session_changed`).
1686
1705
  *
1687
- * Most apps shouldn't need to call this directly prefer the higher-
1688
- * level helpers below (`selectOrg`, `clearOrg`, `signOut`) which do the
1689
- * fetch + notify in one step, or the React `useSession()` hook which
1690
- * exposes the same helpers bound to the in-scope engine. This is the
1691
- * escape hatch for code that talks to /api/auth/* via its own client.
1706
+ * The `selectOrg` / `clearOrg` / `signOut` helpers below remain as
1707
+ * convenience wrappers that combine the HTTP call with an immediate
1708
+ * local refresh useful when the same tab needs the new state
1709
+ * before the WS round-trip lands.
1692
1710
  */
1693
1711
  notifySessionChanged(): Promise<void> {
1694
1712
  return this.refreshResolvedSession();