@rebasepro/server-postgres 0.9.1-canary.09aaf62 → 0.9.1-canary.0de22e0

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/src/websocket.ts CHANGED
@@ -27,7 +27,7 @@ interface WsAuthConfig {
27
27
  * Normalized user identity for WebSocket sessions.
28
28
  */
29
29
  interface WsUserIdentity {
30
- userId: string;
30
+ uid: string;
31
31
  roles: string[];
32
32
  isAdmin: boolean;
33
33
  }
@@ -183,7 +183,7 @@ code } }
183
183
 
184
184
  if (adapterUser) {
185
185
  verifiedUser = {
186
- userId: adapterUser.uid,
186
+ uid: adapterUser.uid,
187
187
  roles: adapterUser.roles,
188
188
  isAdmin: adapterUser.isAdmin
189
189
  };
@@ -195,13 +195,13 @@ code } }
195
195
  // Service key: a static secret, not a JWT. Checked
196
196
  // before verification, mirroring the HTTP middleware —
197
197
  // verifying it as a JWT can only ever fail.
198
- verifiedUser = { userId: "service", roles: ["admin"], isAdmin: true };
198
+ verifiedUser = { uid: "service", roles: ["admin"], isAdmin: true };
199
199
  } else {
200
200
  // Standard JWT path
201
201
  const jwtPayload = extractUserFromToken(token);
202
202
  if (jwtPayload) {
203
203
  verifiedUser = {
204
- userId: jwtPayload.userId,
204
+ uid: jwtPayload.uid,
205
205
  roles: jwtPayload.roles ?? [],
206
206
  isAdmin: (jwtPayload.roles ?? []).some((r: string) => r === "admin")
207
207
  };
@@ -218,10 +218,10 @@ code } }
218
218
  ws.send(JSON.stringify({
219
219
  type: "AUTH_SUCCESS",
220
220
  requestId,
221
- payload: { userId: verifiedUser.userId,
221
+ payload: { uid: verifiedUser.uid,
222
222
  roles: verifiedUser.roles }
223
223
  }));
224
- wsDebug(`🔐 [WebSocket Server] Client ${clientId} authenticated as ${verifiedUser.userId}`);
224
+ wsDebug(`🔐 [WebSocket Server] Client ${clientId} authenticated as ${verifiedUser.uid}`);
225
225
  } else {
226
226
  wsDebug(`[WS] replying AUTH_ERROR for requestId ${requestId} (invalid token)`);
227
227
  sendError("AUTH_ERROR", "INVALID_TOKEN", "Invalid or expired token");
@@ -272,7 +272,7 @@ roles: verifiedUser.roles }
272
272
  try {
273
273
  const userForAuth: User = session?.user
274
274
  ? {
275
- uid: session.user.userId,
275
+ uid: session.user.uid,
276
276
  displayName: null,
277
277
  email: null,
278
278
  photoURL: null,
@@ -421,7 +421,7 @@ colors: true }));
421
421
  sql: typeof sql === "string" ? sql.substring(0, 500) : sql,
422
422
  options,
423
423
  resultRows: Array.isArray(result) ? result.length : "unknown",
424
- userId: auditSession?.user?.userId ?? "unknown",
424
+ uid: auditSession?.user?.uid ?? "unknown",
425
425
  roles: auditSession?.user?.roles ?? [],
426
426
  isAdmin: auditSession?.user?.isAdmin ?? false,
427
427
  }));
@@ -476,6 +476,24 @@ colors: true }));
476
476
  }
477
477
  break;
478
478
 
479
+ case "FETCH_APPLICATION_ROLES": {
480
+ wsDebug("👤 [WebSocket Server] Processing FETCH_APPLICATION_ROLES request");
481
+ const delegate = await getScopedDelegate();
482
+ const admin = delegate.admin;
483
+ let roles: string[] = [];
484
+ if (isSQLAdmin(admin) && admin.fetchApplicationRoles) {
485
+ roles = await admin.fetchApplicationRoles();
486
+ }
487
+ wsDebug(`👤 [WebSocket Server] Fetched ${roles.length} application roles.`);
488
+ const response = {
489
+ type: "FETCH_APPLICATION_ROLES_SUCCESS",
490
+ payload: { roles },
491
+ requestId
492
+ };
493
+ ws.send(JSON.stringify(response));
494
+ }
495
+ break;
496
+
479
497
  case "FETCH_CURRENT_DATABASE": {
480
498
  wsDebug("📚 [WebSocket Server] Processing FETCH_CURRENT_DATABASE request");
481
499
  const delegate = await getScopedDelegate();
@@ -594,14 +612,15 @@ colors: true }));
594
612
  case "broadcast":
595
613
  case "presence_track":
596
614
  case "presence_untrack":
597
- case "presence_state": {
615
+ case "presence_state":
616
+ case "channel_history": {
598
617
  wsDebug("🔄 [WebSocket Server] Routing realtime message to RealtimeService:", type);
599
618
  // Attach auth context from the WS session so RLS-aware refetches work
600
619
  const session = clientSessions.get(clientId);
601
620
  const authContext = session?.user
602
- ? { userId: session.user.userId,
621
+ ? { uid: session.user.uid,
603
622
  roles: session.user.roles ?? [] }
604
- : { userId: "anon",
623
+ : { uid: "anon",
605
624
  roles: ["anon"] };
606
625
  // Let RealtimeService handle these messages
607
626
  await realtimeService.handleClientMessage(clientId, {