@bymax-one/nest-realtime 1.2.18 → 1.2.20
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/CHANGELOG.md +59 -1
- package/README.md +94 -10
- package/dist/internal/index.cjs +535 -104
- package/dist/internal/index.d.cts +129 -7
- package/dist/internal/index.d.ts +129 -7
- package/dist/internal/index.mjs +532 -106
- package/dist/observability/index.cjs +104 -0
- package/dist/observability/index.d.cts +47 -0
- package/dist/observability/index.d.ts +47 -0
- package/dist/observability/index.mjs +104 -0
- package/dist/websocket/index.cjs +128 -20
- package/dist/websocket/index.d.cts +14 -4
- package/dist/websocket/index.d.ts +14 -4
- package/dist/websocket/index.mjs +129 -21
- package/package.json +31 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamicModule, INestApplicationContext } from '@nestjs/common';
|
|
2
|
-
import { WebSocketRealtimeModuleOptions, WebSocketRealtimeModuleAsyncOptions, ITransport, ConnectionRegistry, RoomRegistry, AuthenticationGate, IConnectionLifecycleHooks, BymaxRealtimeModuleOptions, ConnectionAdmission, ConnectionAuthContext, AuthenticationResult, AdmissionTicket, SseTransport } from '@bymax-one/nest-realtime/internal';
|
|
2
|
+
import { WebSocketRealtimeModuleOptions, WebSocketRealtimeModuleAsyncOptions, ITransport, ConnectionRegistry, RoomRegistry, AuthenticationGate, IConnectionLifecycleHooks, BymaxRealtimeModuleOptions, ConnectionAdmission, RealtimeMetricsTally, ConnectionAuthContext, AuthenticationResult, AdmissionTicket, RealtimeTracing, SseTransport } from '@bymax-one/nest-realtime/internal';
|
|
3
3
|
export { WebSocketRealtimeModuleAsyncOptions, WebSocketRealtimeModuleOptions } from '@bymax-one/nest-realtime/internal';
|
|
4
4
|
import { Server, Socket, ServerOptions } from 'socket.io';
|
|
5
5
|
import { OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect } from '@nestjs/websockets';
|
|
@@ -79,12 +79,13 @@ declare class WebSocketTransport implements ITransport {
|
|
|
79
79
|
private readonly hooks;
|
|
80
80
|
private readonly options;
|
|
81
81
|
private readonly admission?;
|
|
82
|
+
private readonly tally?;
|
|
82
83
|
readonly kind: "websocket";
|
|
83
84
|
private readonly logger;
|
|
84
85
|
/** Nullable until the gateway's afterInit wires the instance. */
|
|
85
86
|
private server;
|
|
86
87
|
private warnedUnattached;
|
|
87
|
-
constructor(connections: ConnectionRegistry, rooms: RoomRegistry, gate: AuthenticationGate, hooks: IConnectionLifecycleHooks, options: BymaxRealtimeModuleOptions, admission?: ConnectionAdmission | undefined);
|
|
88
|
+
constructor(connections: ConnectionRegistry, rooms: RoomRegistry, gate: AuthenticationGate, hooks: IConnectionLifecycleHooks, options: BymaxRealtimeModuleOptions, admission?: ConnectionAdmission | undefined, tally?: RealtimeMetricsTally | undefined);
|
|
88
89
|
/**
|
|
89
90
|
* Mark shutdown as begun at the first hook Nest runs on close. A slow `onModuleDestroy` in a module
|
|
90
91
|
* nearer the root than the realtime module still runs first, and until it returns a handshake is
|
|
@@ -263,15 +264,24 @@ declare class WebSocketTransport implements ITransport {
|
|
|
263
264
|
declare class RealtimeGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
|
|
264
265
|
private readonly transport;
|
|
265
266
|
private readonly options;
|
|
267
|
+
private readonly tally?;
|
|
268
|
+
private readonly tracing?;
|
|
266
269
|
private readonly logger;
|
|
267
270
|
server: Server;
|
|
268
|
-
constructor(transport: WebSocketTransport, options: BymaxRealtimeModuleOptions);
|
|
271
|
+
constructor(transport: WebSocketTransport, options: BymaxRealtimeModuleOptions, tally?: RealtimeMetricsTally | undefined, tracing?: RealtimeTracing | undefined);
|
|
269
272
|
/** Identities the handshake middleware resolved, until `handleConnection` takes them. */
|
|
270
273
|
private readonly authenticated;
|
|
271
274
|
/** The place held for a socket from before its handshake is authenticated until it is registered. */
|
|
272
275
|
private readonly tickets;
|
|
273
|
-
/**
|
|
276
|
+
/**
|
|
277
|
+
* Authenticate before accept, inside the `realtime.handshake` span when tracing is wired.
|
|
278
|
+
*
|
|
279
|
+
* The refusal the handshake produces is held until the span has ended, so that the span carries it, and is
|
|
280
|
+
* then handed to `next`.
|
|
281
|
+
*/
|
|
274
282
|
private readonly authenticateHandshake;
|
|
283
|
+
/** Authenticate before accept: a refusal is a `connect_error` with `data.code`; a failure is generic. */
|
|
284
|
+
private handshake;
|
|
275
285
|
/**
|
|
276
286
|
* The error a handshake that failed is answered with, after the log line the failure earns.
|
|
277
287
|
*
|
package/dist/websocket/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { Injectable, Inject, Optional, Logger, Global, Module } from '@nestjs/common';
|
|
3
|
-
import { ConnectionRegistry, RoomRegistry, AuthenticationGate, REALTIME_HOOKS_TOKEN, REALTIME_OPTIONS_TOKEN, ConnectionAdmission, SseTransport,
|
|
3
|
+
import { ConnectionRegistry, RoomRegistry, AuthenticationGate, REALTIME_HOOKS_TOKEN, REALTIME_OPTIONS_TOKEN, ConnectionAdmission, RealtimeMetricsTally, SseTransport, RealtimeTracing, logEvent, ROOM_PREFIXES, runHook, DEFAULT_HOOK_TIMEOUT_MS, requireRoomName, refuseReservedRoom, unavailableError, REALTIME_ERROR_CODES, UNBOUNDED_TICKET, composeForRoot, composeForRootAsync, REALTIME_TRANSPORT_TOKEN, SseSubscriptionHandler, RealtimePubSubSubscriber, createSseController, resolveAuthTenant, assertIdentityIsNotBlank, admitRooms, ConnectionLimitError, AuthenticationUnavailableError, parseCookieHeader, RESERVED_EVENT_NAMES, describeError, quitWithin, realtimeError } from '@bymax-one/nest-realtime/internal';
|
|
4
4
|
import { WebSocketServer, WebSocketGateway } from '@nestjs/websockets';
|
|
5
5
|
import { IoAdapter } from '@nestjs/platform-socket.io';
|
|
6
6
|
|
|
@@ -31,17 +31,28 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
|
|
|
31
31
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
32
32
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
33
33
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
34
|
+
|
|
35
|
+
// src/websocket/transports/websocket/connect-hook-failure.ts
|
|
36
|
+
var ConnectHookFailure = class extends Error {
|
|
37
|
+
constructor(cause) {
|
|
38
|
+
super("onConnect hook failed", { cause });
|
|
39
|
+
this.name = "ConnectHookFailure";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/websocket/transports/websocket/websocket.transport.ts
|
|
34
44
|
var CONNECTION_ROOM_PREFIX = "connection";
|
|
35
45
|
var DEFAULT_MAX_CONNECTIONS_PER_USER = 5;
|
|
36
46
|
var _shuttingDown;
|
|
37
47
|
var WebSocketTransport = class {
|
|
38
|
-
constructor(connections, rooms, gate, hooks, options, admission) {
|
|
48
|
+
constructor(connections, rooms, gate, hooks, options, admission, tally) {
|
|
39
49
|
this.connections = connections;
|
|
40
50
|
this.rooms = rooms;
|
|
41
51
|
this.gate = gate;
|
|
42
52
|
this.hooks = hooks;
|
|
43
53
|
this.options = options;
|
|
44
54
|
this.admission = admission;
|
|
55
|
+
this.tally = tally;
|
|
45
56
|
__publicField(this, "kind", "websocket");
|
|
46
57
|
__publicField(this, "logger", new Logger(WebSocketTransport.name));
|
|
47
58
|
__publicField(this, "server", null);
|
|
@@ -54,6 +65,7 @@ var WebSocketTransport = class {
|
|
|
54
65
|
hooks;
|
|
55
66
|
options;
|
|
56
67
|
admission;
|
|
68
|
+
tally;
|
|
57
69
|
onModuleDestroy() {
|
|
58
70
|
__privateSet(this, _shuttingDown, true);
|
|
59
71
|
}
|
|
@@ -70,8 +82,12 @@ var WebSocketTransport = class {
|
|
|
70
82
|
attached(op) {
|
|
71
83
|
if (!this.server && !this.warnedUnattached) {
|
|
72
84
|
this.warnedUnattached = true;
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
logEvent(
|
|
86
|
+
this.logger,
|
|
87
|
+
"warn",
|
|
88
|
+
"REALTIME_SERVER_NOT_ATTACHED",
|
|
89
|
+
"no WebSocket server is attached yet, so emits are dropped until the gateway initialises",
|
|
90
|
+
{ op }
|
|
75
91
|
);
|
|
76
92
|
}
|
|
77
93
|
return this.server;
|
|
@@ -109,9 +125,17 @@ var WebSocketTransport = class {
|
|
|
109
125
|
await this.evictBeyondLimit(auth.userId);
|
|
110
126
|
const failed = await this.runOnConnect(socket, auth, connectedAt);
|
|
111
127
|
if (!failed) return;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
128
|
+
if (this.options.onConnectFailure === "close") {
|
|
129
|
+
throw new ConnectHookFailure(failed.error);
|
|
130
|
+
}
|
|
131
|
+
logEvent(
|
|
132
|
+
this.logger,
|
|
133
|
+
"error",
|
|
134
|
+
"REALTIME_HOOK_FAILED",
|
|
135
|
+
"onConnect hook failed",
|
|
136
|
+
{ hook: "onConnect" },
|
|
137
|
+
failed.error
|
|
138
|
+
);
|
|
115
139
|
}
|
|
116
140
|
async joinRooms(socket, auth) {
|
|
117
141
|
await socket.join(`${ROOM_PREFIXES.USER}:${auth.userId}`);
|
|
@@ -159,20 +183,35 @@ var WebSocketTransport = class {
|
|
|
159
183
|
() => this.hooks.onDisconnect?.(disconnectMeta),
|
|
160
184
|
this.options.hookTimeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS
|
|
161
185
|
);
|
|
162
|
-
if (failed)
|
|
186
|
+
if (failed) {
|
|
187
|
+
logEvent(
|
|
188
|
+
this.logger,
|
|
189
|
+
"error",
|
|
190
|
+
"REALTIME_HOOK_FAILED",
|
|
191
|
+
`onDisconnect hook failed`,
|
|
192
|
+
{
|
|
193
|
+
hook: "onDisconnect"
|
|
194
|
+
},
|
|
195
|
+
failed.error
|
|
196
|
+
);
|
|
197
|
+
}
|
|
163
198
|
}
|
|
164
199
|
async emitToUser(userId, event, data) {
|
|
165
200
|
this.attached("emitToUser")?.to(`${ROOM_PREFIXES.USER}:${userId}`).emit(event, data);
|
|
201
|
+
if (this.server) this.tally?.emitted("websocket");
|
|
166
202
|
}
|
|
167
203
|
async emitToTenant(tenantId, event, data) {
|
|
168
204
|
this.attached("emitToTenant")?.to(`${ROOM_PREFIXES.TENANT}:${tenantId}`).emit(event, data);
|
|
205
|
+
if (this.server) this.tally?.emitted("websocket");
|
|
169
206
|
}
|
|
170
207
|
async emitToRoom(roomId, event, data) {
|
|
171
208
|
requireRoomName("emitToRoom", roomId);
|
|
172
209
|
this.attached("emitToRoom")?.to(roomId).emit(event, data);
|
|
210
|
+
if (this.server) this.tally?.emitted("websocket");
|
|
173
211
|
}
|
|
174
212
|
async broadcast(event, data) {
|
|
175
213
|
this.attached("broadcast")?.emit(event, data);
|
|
214
|
+
if (this.server) this.tally?.emitted("websocket");
|
|
176
215
|
}
|
|
177
216
|
async joinRoom(connectionId, roomId) {
|
|
178
217
|
refuseReservedRoom("joinRoom", roomId);
|
|
@@ -196,7 +235,7 @@ var WebSocketTransport = class {
|
|
|
196
235
|
throw unavailableError(
|
|
197
236
|
REALTIME_ERROR_CODES.TRANSPORT_UNAVAILABLE,
|
|
198
237
|
WebSocketTransport.name,
|
|
199
|
-
`the WebSocket server is not attached, so ${connectionId} cannot be revoked`,
|
|
238
|
+
`the WebSocket server is not attached, so ${connectionId} cannot be revoked (server not attached)`,
|
|
200
239
|
new Error("server not attached")
|
|
201
240
|
);
|
|
202
241
|
}
|
|
@@ -222,6 +261,7 @@ var WebSocketTransport = class {
|
|
|
222
261
|
let userConnections = this.connections.byUser(userId, "websocket");
|
|
223
262
|
while (userConnections.length > max) {
|
|
224
263
|
const oldest = userConnections.reduce((a, b) => a.connectedAt <= b.connectedAt ? a : b);
|
|
264
|
+
this.tally?.evicted("per_user_cap");
|
|
225
265
|
await this.disconnect(oldest.connectionId, REALTIME_ERROR_CODES.TOO_MANY_CONNECTIONS);
|
|
226
266
|
await this.unregisterSocket(oldest.connectionId, REALTIME_ERROR_CODES.TOO_MANY_CONNECTIONS);
|
|
227
267
|
userConnections = this.connections.byUser(userId, "websocket");
|
|
@@ -237,7 +277,9 @@ WebSocketTransport = __decorateClass([
|
|
|
237
277
|
__decorateParam(3, Inject(REALTIME_HOOKS_TOKEN)),
|
|
238
278
|
__decorateParam(4, Inject(REALTIME_OPTIONS_TOKEN)),
|
|
239
279
|
__decorateParam(5, Optional()),
|
|
240
|
-
__decorateParam(5, Inject(ConnectionAdmission))
|
|
280
|
+
__decorateParam(5, Inject(ConnectionAdmission)),
|
|
281
|
+
__decorateParam(6, Optional()),
|
|
282
|
+
__decorateParam(6, Inject(RealtimeMetricsTally))
|
|
241
283
|
], WebSocketTransport);
|
|
242
284
|
|
|
243
285
|
// src/websocket/transports/composite/composite.transport.ts
|
|
@@ -311,7 +353,14 @@ var CompositeTransport = class {
|
|
|
311
353
|
const reasons = results.flatMap((r) => r.status === "rejected" ? [r.reason] : []);
|
|
312
354
|
if (reasons.length === tasks.length) throw this.allFailed(op, reasons);
|
|
313
355
|
for (const reason of reasons) {
|
|
314
|
-
|
|
356
|
+
logEvent(
|
|
357
|
+
this.logger,
|
|
358
|
+
"warn",
|
|
359
|
+
"REALTIME_COMPOSITE_PARTIAL_FAILURE",
|
|
360
|
+
`Composite ${op} partially failed`,
|
|
361
|
+
{ op },
|
|
362
|
+
reason
|
|
363
|
+
);
|
|
315
364
|
}
|
|
316
365
|
}
|
|
317
366
|
allFailed(what, reasons) {
|
|
@@ -390,7 +439,12 @@ var RealtimeIoAdapter = class _RealtimeIoAdapter extends IoAdapter {
|
|
|
390
439
|
if (reported) return;
|
|
391
440
|
reported = true;
|
|
392
441
|
const kind = Object(err).constructor?.name ?? "Error";
|
|
393
|
-
|
|
442
|
+
logEvent(
|
|
443
|
+
this.adapterLogger,
|
|
444
|
+
"warn",
|
|
445
|
+
"REALTIME_ADAPTER_COMMAND_FAILED",
|
|
446
|
+
`Redis adapter subscriber command failed (${kind})`
|
|
447
|
+
);
|
|
394
448
|
});
|
|
395
449
|
return pending;
|
|
396
450
|
};
|
|
@@ -431,21 +485,41 @@ function firstQueryValue(value) {
|
|
|
431
485
|
return Array.isArray(value) ? value[0] : value;
|
|
432
486
|
}
|
|
433
487
|
var RealtimeGateway = class {
|
|
434
|
-
constructor(transport, options) {
|
|
488
|
+
constructor(transport, options, tally, tracing) {
|
|
435
489
|
this.transport = transport;
|
|
436
490
|
this.options = options;
|
|
491
|
+
this.tally = tally;
|
|
492
|
+
this.tracing = tracing;
|
|
437
493
|
}
|
|
438
494
|
transport;
|
|
439
495
|
options;
|
|
496
|
+
tally;
|
|
497
|
+
tracing;
|
|
440
498
|
logger = new Logger(RealtimeGateway.name);
|
|
441
499
|
server;
|
|
442
500
|
authenticated = /* @__PURE__ */ new WeakMap();
|
|
443
501
|
tickets = /* @__PURE__ */ new WeakMap();
|
|
444
502
|
authenticateHandshake = async (socket, next) => {
|
|
503
|
+
let outcome;
|
|
504
|
+
const run = async () => {
|
|
505
|
+
await this.handshake(socket, (err) => {
|
|
506
|
+
outcome = err;
|
|
507
|
+
});
|
|
508
|
+
if (outcome) throw outcome;
|
|
509
|
+
};
|
|
510
|
+
try {
|
|
511
|
+
await (this.tracing ? this.tracing.span("realtime.handshake", { "bymax.realtime.transport": "websocket" }, run) : run());
|
|
512
|
+
} catch {
|
|
513
|
+
}
|
|
514
|
+
if (outcome) next(outcome);
|
|
515
|
+
else next();
|
|
516
|
+
};
|
|
517
|
+
async handshake(socket, next) {
|
|
445
518
|
let ticket;
|
|
446
519
|
let handedOver = false;
|
|
447
520
|
try {
|
|
448
521
|
if (this.transport.shuttingDown) {
|
|
522
|
+
this.tally?.refused("unavailable");
|
|
449
523
|
next(this.unavailable());
|
|
450
524
|
return;
|
|
451
525
|
}
|
|
@@ -453,10 +527,12 @@ var RealtimeGateway = class {
|
|
|
453
527
|
ticket = held;
|
|
454
528
|
const auth = await this.transport.authenticate(this.buildAuthContext(socket));
|
|
455
529
|
if (this.transport.shuttingDown) {
|
|
530
|
+
this.tally?.refused("unavailable");
|
|
456
531
|
next(this.unavailable());
|
|
457
532
|
return;
|
|
458
533
|
}
|
|
459
534
|
if (!auth) {
|
|
535
|
+
this.tally?.refused("unauthorized");
|
|
460
536
|
const refusal = new Error(REALTIME_ERROR_CODES.AUTH_FAILED);
|
|
461
537
|
refusal.data = { code: REALTIME_ERROR_CODES.AUTH_FAILED };
|
|
462
538
|
next(refusal);
|
|
@@ -473,12 +549,25 @@ var RealtimeGateway = class {
|
|
|
473
549
|
} finally {
|
|
474
550
|
if (!handedOver) ticket?.release();
|
|
475
551
|
}
|
|
476
|
-
}
|
|
552
|
+
}
|
|
477
553
|
refusalFor(socket, err) {
|
|
478
|
-
if (err instanceof
|
|
554
|
+
if (err instanceof ConnectionLimitError) {
|
|
555
|
+
this.tally?.refused("limit");
|
|
556
|
+
return this.unavailable("Internal Server Error");
|
|
557
|
+
}
|
|
558
|
+
if (err instanceof AuthenticationUnavailableError) {
|
|
559
|
+
this.tally?.refused("unavailable");
|
|
479
560
|
return this.unavailable("Internal Server Error");
|
|
480
561
|
}
|
|
481
|
-
this.
|
|
562
|
+
this.tally?.refused("error");
|
|
563
|
+
logEvent(
|
|
564
|
+
this.logger,
|
|
565
|
+
"error",
|
|
566
|
+
"REALTIME_HANDSHAKE_FAILED",
|
|
567
|
+
`handshake refused`,
|
|
568
|
+
{ socketId: socket.id },
|
|
569
|
+
err
|
|
570
|
+
);
|
|
482
571
|
return new Error("Internal Server Error");
|
|
483
572
|
}
|
|
484
573
|
unavailable(message = REALTIME_ERROR_CODES.TRANSPORT_UNAVAILABLE) {
|
|
@@ -494,7 +583,10 @@ var RealtimeGateway = class {
|
|
|
494
583
|
}
|
|
495
584
|
reportMissingAdapter() {
|
|
496
585
|
const configured = Object.keys(this.options.websocket ?? {});
|
|
497
|
-
|
|
586
|
+
logEvent(
|
|
587
|
+
this.logger,
|
|
588
|
+
"error",
|
|
589
|
+
"REALTIME_ADAPTER_MISSING",
|
|
498
590
|
"RealtimeIoAdapter is not the active WebSocket adapter, so the websocket options" + (configured.length > 0 ? ` (${configured.join(", ")})` : "") + " are ignored and the gateway CORS stays closed (origin: false): browsers on another origin cannot connect. Add app.useWebSocketAdapter(new RealtimeIoAdapter(app)) in main.ts, importing it from '@bymax-one/nest-realtime/websocket'."
|
|
499
591
|
);
|
|
500
592
|
}
|
|
@@ -535,9 +627,19 @@ var RealtimeGateway = class {
|
|
|
535
627
|
});
|
|
536
628
|
}
|
|
537
629
|
} catch (err) {
|
|
538
|
-
if (
|
|
539
|
-
this.
|
|
540
|
-
|
|
630
|
+
if (err instanceof ConnectionLimitError) {
|
|
631
|
+
this.tally?.refused("limit");
|
|
632
|
+
} else if (err instanceof AuthenticationUnavailableError) {
|
|
633
|
+
this.tally?.refused("unavailable");
|
|
634
|
+
} else {
|
|
635
|
+
if (!(err instanceof ConnectHookFailure)) this.tally?.refused("error");
|
|
636
|
+
logEvent(
|
|
637
|
+
this.logger,
|
|
638
|
+
"error",
|
|
639
|
+
"REALTIME_HANDSHAKE_FAILED",
|
|
640
|
+
`handleConnection threw \u2014 disconnecting`,
|
|
641
|
+
{ socketId: socket.id },
|
|
642
|
+
err
|
|
541
643
|
);
|
|
542
644
|
}
|
|
543
645
|
socket.disconnect(true);
|
|
@@ -564,6 +666,7 @@ var RealtimeGateway = class {
|
|
|
564
666
|
this.tickets.delete(socket);
|
|
565
667
|
if (auth) return { auth, ticket };
|
|
566
668
|
if (this.transport.shuttingDown) {
|
|
669
|
+
this.tally?.refused("unavailable");
|
|
567
670
|
socket.disconnect(true);
|
|
568
671
|
return void 0;
|
|
569
672
|
}
|
|
@@ -571,6 +674,7 @@ var RealtimeGateway = class {
|
|
|
571
674
|
try {
|
|
572
675
|
const fresh = await this.transport.authenticate(this.buildAuthContext(socket));
|
|
573
676
|
if (!fresh) {
|
|
677
|
+
this.tally?.refused("unauthorized");
|
|
574
678
|
socket.disconnect(true);
|
|
575
679
|
held.release();
|
|
576
680
|
return void 0;
|
|
@@ -602,7 +706,11 @@ RealtimeGateway = __decorateClass([
|
|
|
602
706
|
cors: { origin: false }
|
|
603
707
|
}),
|
|
604
708
|
__decorateParam(0, Inject(WebSocketTransport)),
|
|
605
|
-
__decorateParam(1, Inject(REALTIME_OPTIONS_TOKEN))
|
|
709
|
+
__decorateParam(1, Inject(REALTIME_OPTIONS_TOKEN)),
|
|
710
|
+
__decorateParam(2, Optional()),
|
|
711
|
+
__decorateParam(2, Inject(RealtimeMetricsTally)),
|
|
712
|
+
__decorateParam(3, Optional()),
|
|
713
|
+
__decorateParam(3, Inject(RealtimeTracing))
|
|
606
714
|
], RealtimeGateway);
|
|
607
715
|
|
|
608
716
|
// src/websocket/websocket-wiring.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-realtime",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.20",
|
|
4
4
|
"description": "Realtime backend → frontend communication for NestJS — dual-transport SSE (default) and WebSocket (opt-in) with a unified server-side API.",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,6 +64,16 @@
|
|
|
64
64
|
"default": "./dist/websocket/index.cjs"
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
+
"./observability": {
|
|
68
|
+
"import": {
|
|
69
|
+
"types": "./dist/observability/index.d.ts",
|
|
70
|
+
"default": "./dist/observability/index.mjs"
|
|
71
|
+
},
|
|
72
|
+
"require": {
|
|
73
|
+
"types": "./dist/observability/index.d.cts",
|
|
74
|
+
"default": "./dist/observability/index.cjs"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
67
77
|
"./internal": {
|
|
68
78
|
"import": {
|
|
69
79
|
"types": "./dist/internal/index.d.ts",
|
|
@@ -87,6 +97,9 @@
|
|
|
87
97
|
"websocket": [
|
|
88
98
|
"./dist/websocket/index.d.cts"
|
|
89
99
|
],
|
|
100
|
+
"observability": [
|
|
101
|
+
"./dist/observability/index.d.cts"
|
|
102
|
+
],
|
|
90
103
|
"internal": [
|
|
91
104
|
"./dist/internal/index.d.cts"
|
|
92
105
|
]
|
|
@@ -125,12 +138,15 @@
|
|
|
125
138
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json"
|
|
126
139
|
},
|
|
127
140
|
"peerDependencies": {
|
|
141
|
+
"@bymax-one/nest-core": "^1.1.0",
|
|
128
142
|
"@nestjs/common": "^11.0.16",
|
|
129
143
|
"@nestjs/core": "^11.1.18",
|
|
130
144
|
"@nestjs/platform-socket.io": "^11.0.0",
|
|
131
145
|
"@nestjs/websockets": "^11.0.0",
|
|
146
|
+
"@opentelemetry/api": "^1.9.0",
|
|
132
147
|
"@socket.io/redis-adapter": "^8.0.0",
|
|
133
148
|
"ioredis": "^6.0.0",
|
|
149
|
+
"prom-client": "^15.0.0",
|
|
134
150
|
"react": "^19.0.0",
|
|
135
151
|
"react-dom": "^19.0.0",
|
|
136
152
|
"reflect-metadata": "^0.2.0",
|
|
@@ -139,13 +155,16 @@
|
|
|
139
155
|
"socket.io-client": "^4.0.0"
|
|
140
156
|
},
|
|
141
157
|
"peerDependenciesMeta": {
|
|
142
|
-
"@
|
|
158
|
+
"@bymax-one/nest-core": {
|
|
143
159
|
"optional": true
|
|
144
160
|
},
|
|
145
161
|
"@nestjs/platform-socket.io": {
|
|
146
162
|
"optional": true
|
|
147
163
|
},
|
|
148
|
-
"
|
|
164
|
+
"@nestjs/websockets": {
|
|
165
|
+
"optional": true
|
|
166
|
+
},
|
|
167
|
+
"@opentelemetry/api": {
|
|
149
168
|
"optional": true
|
|
150
169
|
},
|
|
151
170
|
"@socket.io/redis-adapter": {
|
|
@@ -154,24 +173,32 @@
|
|
|
154
173
|
"ioredis": {
|
|
155
174
|
"optional": true
|
|
156
175
|
},
|
|
176
|
+
"prom-client": {
|
|
177
|
+
"optional": true
|
|
178
|
+
},
|
|
157
179
|
"react": {
|
|
158
180
|
"optional": true
|
|
159
181
|
},
|
|
160
182
|
"react-dom": {
|
|
161
183
|
"optional": true
|
|
162
184
|
},
|
|
185
|
+
"socket.io": {
|
|
186
|
+
"optional": true
|
|
187
|
+
},
|
|
163
188
|
"socket.io-client": {
|
|
164
189
|
"optional": true
|
|
165
190
|
}
|
|
166
191
|
},
|
|
167
192
|
"devDependencies": {
|
|
168
193
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
194
|
+
"@bymax-one/nest-core": "1.6.10",
|
|
169
195
|
"@nestjs/common": "^11.1.28",
|
|
170
196
|
"@nestjs/core": "^11.1.28",
|
|
171
197
|
"@nestjs/platform-express": "^11.1.28",
|
|
172
198
|
"@nestjs/platform-socket.io": "^11.1.28",
|
|
173
199
|
"@nestjs/testing": "^11.1.28",
|
|
174
200
|
"@nestjs/websockets": "^11.1.28",
|
|
201
|
+
"@opentelemetry/api": "^1.10.0",
|
|
175
202
|
"@socket.io/redis-adapter": "^8.0.0",
|
|
176
203
|
"@stryker-mutator/core": "^9.6.1",
|
|
177
204
|
"@stryker-mutator/jest-runner": "^9.6.1",
|
|
@@ -201,6 +228,7 @@
|
|
|
201
228
|
"jest-environment-jsdom": "^30.0.0",
|
|
202
229
|
"jsonwebtoken": "^9.0.3",
|
|
203
230
|
"prettier": "^3.9.6",
|
|
231
|
+
"prom-client": "^15.1.3",
|
|
204
232
|
"react": "^19.2.8",
|
|
205
233
|
"react-dom": "^19.2.8",
|
|
206
234
|
"reflect-metadata": "^0.2.2",
|