@rebasepro/server-mongo 0.9.1-canary.fd3754b → 0.10.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/auth/services.d.ts +43 -43
- package/dist/auth/services.d.ts.map +1 -1
- package/dist/index.es.js +97 -97
- package/dist/index.es.js.map +1 -1
- package/dist/services/MongoRealtimeService.d.ts +5 -5
- package/dist/services/MongoRealtimeService.d.ts.map +1 -1
- package/dist/{websocket-DQlwCHFq.js → websocket-CoKu1mvm.js} +4 -4
- package/dist/websocket-CoKu1mvm.js.map +1 -0
- package/package.json +9 -10
- package/src/auth/services.ts +92 -92
- package/src/services/MongoDriver.ts +2 -2
- package/src/services/MongoRealtimeService.ts +10 -10
- package/src/websocket.ts +3 -3
- package/dist/index.umd.js +0 -2925
- package/dist/index.umd.js.map +0 -1
- package/dist/websocket-DQlwCHFq.js.map +0 -1
|
@@ -781,7 +781,7 @@ export class AuthenticatedMongoDriver implements DataDriver {
|
|
|
781
781
|
|
|
782
782
|
listenCollection<M extends Record<string, any>>(props: ListenCollectionProps<M>): () => void {
|
|
783
783
|
const unsubscribe = this.delegate.listenCollection(props);
|
|
784
|
-
const authContext = {
|
|
784
|
+
const authContext = { uid: this.user.uid,
|
|
785
785
|
roles: this.user.roles ?? [] };
|
|
786
786
|
const subscriptions = this.delegate.getRealtimeService().getSubscriptions();
|
|
787
787
|
const lastEntry = Array.from(subscriptions.entries()).pop();
|
|
@@ -806,7 +806,7 @@ roles: this.user.roles ?? [] };
|
|
|
806
806
|
|
|
807
807
|
listenOne<M extends Record<string, any>>(props: ListenOneProps<M>): () => void {
|
|
808
808
|
const unsubscribe = this.delegate.listenOne(props);
|
|
809
|
-
const authContext = {
|
|
809
|
+
const authContext = { uid: this.user.uid,
|
|
810
810
|
roles: this.user.roles ?? [] };
|
|
811
811
|
const subscriptions = this.delegate.getRealtimeService().getSubscriptions();
|
|
812
812
|
const lastEntry = Array.from(subscriptions.entries()).pop();
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { WebSocket } from "ws";
|
|
18
18
|
import { MongoDataService } from "../db/MongoDataService";
|
|
19
19
|
|
|
20
|
-
import { MongoDriver } from "./MongoDriver";
|
|
20
|
+
import type { MongoDriver } from "./MongoDriver";
|
|
21
21
|
import { logger } from "@rebasepro/server";
|
|
22
22
|
|
|
23
23
|
interface Subscription {
|
|
@@ -25,7 +25,7 @@ interface Subscription {
|
|
|
25
25
|
config: CollectionSubscriptionConfig | SingleSubscriptionConfig;
|
|
26
26
|
changeStream?: ChangeStream;
|
|
27
27
|
callback?: (data: any) => void;
|
|
28
|
-
authContext?: {
|
|
28
|
+
authContext?: { uid: string; roles: string[] };
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -60,7 +60,7 @@ export class MongoRealtimeService implements RealtimeProvider {
|
|
|
60
60
|
*/
|
|
61
61
|
subscribeToCollection(
|
|
62
62
|
subscriptionId: string,
|
|
63
|
-
config: CollectionSubscriptionConfig & { authContext?: {
|
|
63
|
+
config: CollectionSubscriptionConfig & { authContext?: { uid: string; roles: string[] } },
|
|
64
64
|
callback?: (rows: Record<string, unknown>[]) => void
|
|
65
65
|
): void {
|
|
66
66
|
// Clean up existing subscription if any
|
|
@@ -133,7 +133,7 @@ export class MongoRealtimeService implements RealtimeProvider {
|
|
|
133
133
|
*/
|
|
134
134
|
private async fetchAndNotifyCollection(
|
|
135
135
|
subscriptionId: string,
|
|
136
|
-
config: CollectionSubscriptionConfig & { authContext?: {
|
|
136
|
+
config: CollectionSubscriptionConfig & { authContext?: { uid: string; roles: string[] } },
|
|
137
137
|
callback?: (rows: Record<string, unknown>[]) => void
|
|
138
138
|
): Promise<void> {
|
|
139
139
|
try {
|
|
@@ -141,7 +141,7 @@ export class MongoRealtimeService implements RealtimeProvider {
|
|
|
141
141
|
const registryCollection = this.driver?.registry?.getCollectionByPath(config.path);
|
|
142
142
|
|
|
143
143
|
if (config.authContext && this.driver) {
|
|
144
|
-
const mockUser = { uid: config.authContext.
|
|
144
|
+
const mockUser = { uid: config.authContext.uid,
|
|
145
145
|
roles: config.authContext.roles } as User;
|
|
146
146
|
const authenticatedDriver = await this.driver.withAuth(mockUser);
|
|
147
147
|
rows = await authenticatedDriver.fetchCollection({
|
|
@@ -179,7 +179,7 @@ roles: config.authContext.roles } as User;
|
|
|
179
179
|
*/
|
|
180
180
|
subscribeToOne(
|
|
181
181
|
subscriptionId: string,
|
|
182
|
-
config: SingleSubscriptionConfig & { authContext?: {
|
|
182
|
+
config: SingleSubscriptionConfig & { authContext?: { uid: string; roles: string[] } },
|
|
183
183
|
callback?: (row: Record<string, unknown> | null) => void
|
|
184
184
|
): void {
|
|
185
185
|
// Clean up existing subscription if any
|
|
@@ -257,7 +257,7 @@ roles: config.authContext.roles } as User;
|
|
|
257
257
|
*/
|
|
258
258
|
private async fetchAndNotifyOne(
|
|
259
259
|
subscriptionId: string,
|
|
260
|
-
config: SingleSubscriptionConfig & { authContext?: {
|
|
260
|
+
config: SingleSubscriptionConfig & { authContext?: { uid: string; roles: string[] } },
|
|
261
261
|
callback?: (row: Record<string, unknown> | null) => void
|
|
262
262
|
): Promise<void> {
|
|
263
263
|
try {
|
|
@@ -265,7 +265,7 @@ roles: config.authContext.roles } as User;
|
|
|
265
265
|
const registryCollection = this.driver?.registry?.getCollectionByPath(config.path);
|
|
266
266
|
|
|
267
267
|
if (config.authContext && this.driver) {
|
|
268
|
-
const mockUser = { uid: config.authContext.
|
|
268
|
+
const mockUser = { uid: config.authContext.uid,
|
|
269
269
|
roles: config.authContext.roles } as User;
|
|
270
270
|
const authenticatedDriver = await this.driver.withAuth(mockUser);
|
|
271
271
|
row = await authenticatedDriver.fetchOne({
|
|
@@ -376,12 +376,12 @@ roles: config.authContext.roles } as User;
|
|
|
376
376
|
async handleClientMessage(
|
|
377
377
|
clientId: string,
|
|
378
378
|
message: { type: string; payload?: any; subscriptionId?: string },
|
|
379
|
-
_authContext?: {
|
|
379
|
+
_authContext?: { uid: string; roles: unknown[] }
|
|
380
380
|
): Promise<void> {
|
|
381
381
|
const ws = this.clients.get(clientId);
|
|
382
382
|
if (!ws) return;
|
|
383
383
|
|
|
384
|
-
const authContext = _authContext ? {
|
|
384
|
+
const authContext = _authContext ? { uid: _authContext.uid,
|
|
385
385
|
roles: (_authContext.roles ?? []).map(String) } : undefined;
|
|
386
386
|
|
|
387
387
|
switch (message.type) {
|
package/src/websocket.ts
CHANGED
|
@@ -110,7 +110,7 @@ code } } }));
|
|
|
110
110
|
}
|
|
111
111
|
ws.send(JSON.stringify({ type: "AUTH_SUCCESS",
|
|
112
112
|
requestId,
|
|
113
|
-
payload: {
|
|
113
|
+
payload: { uid: user.uid,
|
|
114
114
|
roles: user.roles } }));
|
|
115
115
|
} else {
|
|
116
116
|
sendError("AUTH_ERROR", "INVALID_TOKEN", "Invalid or expired token");
|
|
@@ -155,7 +155,7 @@ roles: user.roles } }));
|
|
|
155
155
|
if (session?.user && isDriverWithAuth(driver)) {
|
|
156
156
|
try {
|
|
157
157
|
const userForAuth: User = {
|
|
158
|
-
uid: session.user.
|
|
158
|
+
uid: session.user.uid,
|
|
159
159
|
email: session.user.email ?? "",
|
|
160
160
|
displayName: session.user.displayName ?? "",
|
|
161
161
|
photoURL: session.user.photoURL ?? "",
|
|
@@ -273,7 +273,7 @@ requestId }));
|
|
|
273
273
|
case "subscribe_one":
|
|
274
274
|
case "unsubscribe": {
|
|
275
275
|
const session = clientSessions.get(clientId);
|
|
276
|
-
const authContext = session?.user ? {
|
|
276
|
+
const authContext = session?.user ? { uid: session.user.uid,
|
|
277
277
|
roles: session.user.roles ?? [] } : undefined;
|
|
278
278
|
await realtimeService.handleClientMessage(clientId, {
|
|
279
279
|
type,
|