@bymax-one/nest-realtime 1.0.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/CHANGELOG.md +64 -0
- package/LICENSE +21 -0
- package/README.md +671 -0
- package/dist/react/index.cjs +274 -0
- package/dist/react/index.d.cts +245 -0
- package/dist/react/index.d.ts +245 -0
- package/dist/react/index.mjs +268 -0
- package/dist/server/index.cjs +2276 -0
- package/dist/server/index.d.cts +1437 -0
- package/dist/server/index.d.ts +1437 -0
- package/dist/server/index.mjs +2260 -0
- package/dist/shared/index.cjs +40 -0
- package/dist/shared/index.d.cts +162 -0
- package/dist/shared/index.d.ts +162 -0
- package/dist/shared/index.mjs +35 -0
- package/package.json +187 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/shared/constants/room-prefixes.constants.ts
|
|
4
|
+
var ROOM_PREFIXES = {
|
|
5
|
+
USER: "user",
|
|
6
|
+
TENANT: "tenant",
|
|
7
|
+
RESOURCE: "resource"
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/shared/constants/reserved-events.constants.ts
|
|
11
|
+
var RESERVED_EVENT_NAMES = {
|
|
12
|
+
CONNECTION_ESTABLISHED: "connection:established",
|
|
13
|
+
CONNECTION_REAUTH_FAILED: "connection:reauthentication-failed",
|
|
14
|
+
CONNECTION_CREDENTIAL_EXPIRING: "connection:credential-expiring",
|
|
15
|
+
ROOM_JOINED: "room:joined",
|
|
16
|
+
ROOM_LEFT: "room:left",
|
|
17
|
+
ERROR: "error"
|
|
18
|
+
};
|
|
19
|
+
var PRESENCE_EVENT_NAMES = {
|
|
20
|
+
ONLINE: "presence:online",
|
|
21
|
+
OFFLINE: "presence:offline"
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/shared/constants/error-codes.constants.ts
|
|
25
|
+
var REALTIME_ERROR_CODES = {
|
|
26
|
+
INVALID_OPTIONS: "REALTIME_INVALID_OPTIONS",
|
|
27
|
+
NO_AUTHENTICATOR: "REALTIME_NO_AUTHENTICATOR",
|
|
28
|
+
AUTH_FAILED: "REALTIME_AUTH_FAILED",
|
|
29
|
+
REAUTHENTICATION_FAILED: "REALTIME_REAUTHENTICATION_FAILED",
|
|
30
|
+
TOO_MANY_CONNECTIONS: "REALTIME_TOO_MANY_CONNECTIONS",
|
|
31
|
+
INVALID_TICKET: "REALTIME_INVALID_TICKET",
|
|
32
|
+
PUBSUB_UNAVAILABLE: "REALTIME_PUBSUB_UNAVAILABLE",
|
|
33
|
+
PAYLOAD_TOO_LARGE: "REALTIME_PAYLOAD_TOO_LARGE",
|
|
34
|
+
REPLAY_BUFFER_MISS: "REALTIME_REPLAY_BUFFER_MISS"
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.PRESENCE_EVENT_NAMES = PRESENCE_EVENT_NAMES;
|
|
38
|
+
exports.REALTIME_ERROR_CODES = REALTIME_ERROR_CODES;
|
|
39
|
+
exports.RESERVED_EVENT_NAMES = RESERVED_EVENT_NAMES;
|
|
40
|
+
exports.ROOM_PREFIXES = ROOM_PREFIXES;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Config-level transport mode selection.
|
|
3
|
+
* @layer shared
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Transport mode chosen by the consumer at module configuration time.
|
|
7
|
+
*
|
|
8
|
+
* - `sse` — Server-Sent Events only. HTTP-based, server → client push.
|
|
9
|
+
* - `websocket` — Socket.IO only. Full duplex.
|
|
10
|
+
* - `both` — Compose SSE and WebSocket. Useful during migrations or when
|
|
11
|
+
* different product surfaces need different transports.
|
|
12
|
+
*
|
|
13
|
+
* Distinct from `ITransport.kind` (`'sse' | 'websocket'`), which identifies a
|
|
14
|
+
* single concrete transport implementation. See
|
|
15
|
+
* `docs/technical_specification.md` §1.3 for selection criteria.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const mode: TransportMode = 'sse'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
type TransportMode = 'sse' | 'websocket' | 'both';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @fileoverview Generic realtime event shape shared across transports and the client.
|
|
26
|
+
* @layer shared
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Generic shape of an event traveling over a realtime transport.
|
|
30
|
+
*
|
|
31
|
+
* Consumers typically declare a mapped type describing their own events and layer
|
|
32
|
+
* it on top of this generic for end-to-end type safety:
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* interface MyAppEvents {
|
|
37
|
+
* 'invoice.paid': { id: string; amount: number }
|
|
38
|
+
* 'webhook.dlq': { webhookId: string; reason: string }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* type InvoicePaid = RealtimeEvent<MyAppEvents['invoice.paid']>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
interface RealtimeEvent<TData = unknown> {
|
|
45
|
+
/** Monotonically increasing event id — used for `Last-Event-ID` replay. */
|
|
46
|
+
readonly id: string;
|
|
47
|
+
/** Event name (matches the consumer's mapped-type key). */
|
|
48
|
+
readonly type: string;
|
|
49
|
+
/** Free-form payload. */
|
|
50
|
+
readonly data: TData;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @fileoverview Public-facing metadata about a single realtime connection.
|
|
55
|
+
* @layer shared
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Public-facing metadata about a single realtime connection.
|
|
59
|
+
*
|
|
60
|
+
* The full internal record (which, for SSE, also holds the per-connection RxJS
|
|
61
|
+
* `Subject` and `close$` teardown signal) is kept private to the server runtime —
|
|
62
|
+
* see `src/server/services/connection-registry.service.ts`. This type exposes only
|
|
63
|
+
* the fields that are safe to share with diagnostics and the client.
|
|
64
|
+
*/
|
|
65
|
+
interface PublicConnectionMeta {
|
|
66
|
+
readonly connectionId: string;
|
|
67
|
+
readonly userId: string;
|
|
68
|
+
readonly tenantId?: string;
|
|
69
|
+
readonly transport: 'sse' | 'websocket';
|
|
70
|
+
readonly connectedAt: Date;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @fileoverview Canonical room id prefixes for scoping emits and auto-join.
|
|
75
|
+
* @layer shared
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* Canonical room id prefixes — used to scope emits and auto-join connections.
|
|
79
|
+
*
|
|
80
|
+
* Convention:
|
|
81
|
+
* - `user:{userId}` — a single user's connections
|
|
82
|
+
* - `tenant:{tenantId}` — every connection within a tenant
|
|
83
|
+
* - `resource:{resourceType}:{id}` — a per-resource room (e.g. invoice, session)
|
|
84
|
+
*
|
|
85
|
+
* Anything else is application-defined and free-form. Changing a prefix value is
|
|
86
|
+
* a breaking change for every connected client and stored room id.
|
|
87
|
+
*/
|
|
88
|
+
declare const ROOM_PREFIXES: {
|
|
89
|
+
readonly USER: "user";
|
|
90
|
+
readonly TENANT: "tenant";
|
|
91
|
+
readonly RESOURCE: "resource";
|
|
92
|
+
};
|
|
93
|
+
/** Union of canonical room prefix values (`'user' | 'tenant' | 'resource'`). */
|
|
94
|
+
type RoomPrefix = (typeof ROOM_PREFIXES)[keyof typeof ROOM_PREFIXES];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @fileoverview Event names reserved by the library (the §13 catalog).
|
|
98
|
+
* @layer shared
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* Event names reserved by the library.
|
|
102
|
+
*
|
|
103
|
+
* Consumer apps should not reuse these names for application-level events; doing
|
|
104
|
+
* so will not throw, but causes confusion in logs and client-side listeners.
|
|
105
|
+
*
|
|
106
|
+
* Note: the SSE heartbeat is intentionally absent. It is a raw `: keepalive`
|
|
107
|
+
* comment written directly to the response stream (not a named event and outside
|
|
108
|
+
* the `Last-Event-ID` id-space), so it is not part of this catalog.
|
|
109
|
+
*/
|
|
110
|
+
declare const RESERVED_EVENT_NAMES: {
|
|
111
|
+
readonly CONNECTION_ESTABLISHED: "connection:established";
|
|
112
|
+
readonly CONNECTION_REAUTH_FAILED: "connection:reauthentication-failed";
|
|
113
|
+
readonly CONNECTION_CREDENTIAL_EXPIRING: "connection:credential-expiring";
|
|
114
|
+
readonly ROOM_JOINED: "room:joined";
|
|
115
|
+
readonly ROOM_LEFT: "room:left";
|
|
116
|
+
readonly ERROR: "error";
|
|
117
|
+
};
|
|
118
|
+
/** Union of reserved event name values. */
|
|
119
|
+
type ReservedEventName = (typeof RESERVED_EVENT_NAMES)[keyof typeof RESERVED_EVENT_NAMES];
|
|
120
|
+
/**
|
|
121
|
+
* Application-level presence event names emitted by an `IPresenceStorage`
|
|
122
|
+
* implementation and consumed by the `usePresence` client hook.
|
|
123
|
+
*
|
|
124
|
+
* These are named transport events — carried over the `event:` SSE field and as
|
|
125
|
+
* Socket.IO event names — so a client must subscribe to them explicitly to
|
|
126
|
+
* preserve the event `type`. The native `EventSource.onmessage` callback only
|
|
127
|
+
* receives the default `message` event, never these named ones.
|
|
128
|
+
*/
|
|
129
|
+
declare const PRESENCE_EVENT_NAMES: {
|
|
130
|
+
readonly ONLINE: "presence:online";
|
|
131
|
+
readonly OFFLINE: "presence:offline";
|
|
132
|
+
};
|
|
133
|
+
/** Union of presence event name values. */
|
|
134
|
+
type PresenceEventName = (typeof PRESENCE_EVENT_NAMES)[keyof typeof PRESENCE_EVENT_NAMES];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @fileoverview Canonical error codes emitted by the library (the §14 catalog).
|
|
138
|
+
* @layer shared
|
|
139
|
+
*/
|
|
140
|
+
/**
|
|
141
|
+
* Canonical error codes emitted by the library. Map 1-to-1 with
|
|
142
|
+
* `docs/technical_specification.md` §14.
|
|
143
|
+
*
|
|
144
|
+
* `TOO_MANY_CONNECTIONS` signals FIFO eviction: when a user exceeds
|
|
145
|
+
* `maxConnectionsPerUser`, the OLDEST connection is evicted (closed with this
|
|
146
|
+
* code) and the new one is admitted — it is never an HTTP 429 rejection.
|
|
147
|
+
*/
|
|
148
|
+
declare const REALTIME_ERROR_CODES: {
|
|
149
|
+
readonly INVALID_OPTIONS: "REALTIME_INVALID_OPTIONS";
|
|
150
|
+
readonly NO_AUTHENTICATOR: "REALTIME_NO_AUTHENTICATOR";
|
|
151
|
+
readonly AUTH_FAILED: "REALTIME_AUTH_FAILED";
|
|
152
|
+
readonly REAUTHENTICATION_FAILED: "REALTIME_REAUTHENTICATION_FAILED";
|
|
153
|
+
readonly TOO_MANY_CONNECTIONS: "REALTIME_TOO_MANY_CONNECTIONS";
|
|
154
|
+
readonly INVALID_TICKET: "REALTIME_INVALID_TICKET";
|
|
155
|
+
readonly PUBSUB_UNAVAILABLE: "REALTIME_PUBSUB_UNAVAILABLE";
|
|
156
|
+
readonly PAYLOAD_TOO_LARGE: "REALTIME_PAYLOAD_TOO_LARGE";
|
|
157
|
+
readonly REPLAY_BUFFER_MISS: "REALTIME_REPLAY_BUFFER_MISS";
|
|
158
|
+
};
|
|
159
|
+
/** Union of canonical error code values. */
|
|
160
|
+
type RealtimeErrorCode = (typeof REALTIME_ERROR_CODES)[keyof typeof REALTIME_ERROR_CODES];
|
|
161
|
+
|
|
162
|
+
export { PRESENCE_EVENT_NAMES, type PresenceEventName, type PublicConnectionMeta, REALTIME_ERROR_CODES, RESERVED_EVENT_NAMES, ROOM_PREFIXES, type RealtimeErrorCode, type RealtimeEvent, type ReservedEventName, type RoomPrefix, type TransportMode };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Config-level transport mode selection.
|
|
3
|
+
* @layer shared
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Transport mode chosen by the consumer at module configuration time.
|
|
7
|
+
*
|
|
8
|
+
* - `sse` — Server-Sent Events only. HTTP-based, server → client push.
|
|
9
|
+
* - `websocket` — Socket.IO only. Full duplex.
|
|
10
|
+
* - `both` — Compose SSE and WebSocket. Useful during migrations or when
|
|
11
|
+
* different product surfaces need different transports.
|
|
12
|
+
*
|
|
13
|
+
* Distinct from `ITransport.kind` (`'sse' | 'websocket'`), which identifies a
|
|
14
|
+
* single concrete transport implementation. See
|
|
15
|
+
* `docs/technical_specification.md` §1.3 for selection criteria.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const mode: TransportMode = 'sse'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
type TransportMode = 'sse' | 'websocket' | 'both';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @fileoverview Generic realtime event shape shared across transports and the client.
|
|
26
|
+
* @layer shared
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Generic shape of an event traveling over a realtime transport.
|
|
30
|
+
*
|
|
31
|
+
* Consumers typically declare a mapped type describing their own events and layer
|
|
32
|
+
* it on top of this generic for end-to-end type safety:
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* interface MyAppEvents {
|
|
37
|
+
* 'invoice.paid': { id: string; amount: number }
|
|
38
|
+
* 'webhook.dlq': { webhookId: string; reason: string }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* type InvoicePaid = RealtimeEvent<MyAppEvents['invoice.paid']>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
interface RealtimeEvent<TData = unknown> {
|
|
45
|
+
/** Monotonically increasing event id — used for `Last-Event-ID` replay. */
|
|
46
|
+
readonly id: string;
|
|
47
|
+
/** Event name (matches the consumer's mapped-type key). */
|
|
48
|
+
readonly type: string;
|
|
49
|
+
/** Free-form payload. */
|
|
50
|
+
readonly data: TData;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @fileoverview Public-facing metadata about a single realtime connection.
|
|
55
|
+
* @layer shared
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Public-facing metadata about a single realtime connection.
|
|
59
|
+
*
|
|
60
|
+
* The full internal record (which, for SSE, also holds the per-connection RxJS
|
|
61
|
+
* `Subject` and `close$` teardown signal) is kept private to the server runtime —
|
|
62
|
+
* see `src/server/services/connection-registry.service.ts`. This type exposes only
|
|
63
|
+
* the fields that are safe to share with diagnostics and the client.
|
|
64
|
+
*/
|
|
65
|
+
interface PublicConnectionMeta {
|
|
66
|
+
readonly connectionId: string;
|
|
67
|
+
readonly userId: string;
|
|
68
|
+
readonly tenantId?: string;
|
|
69
|
+
readonly transport: 'sse' | 'websocket';
|
|
70
|
+
readonly connectedAt: Date;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @fileoverview Canonical room id prefixes for scoping emits and auto-join.
|
|
75
|
+
* @layer shared
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* Canonical room id prefixes — used to scope emits and auto-join connections.
|
|
79
|
+
*
|
|
80
|
+
* Convention:
|
|
81
|
+
* - `user:{userId}` — a single user's connections
|
|
82
|
+
* - `tenant:{tenantId}` — every connection within a tenant
|
|
83
|
+
* - `resource:{resourceType}:{id}` — a per-resource room (e.g. invoice, session)
|
|
84
|
+
*
|
|
85
|
+
* Anything else is application-defined and free-form. Changing a prefix value is
|
|
86
|
+
* a breaking change for every connected client and stored room id.
|
|
87
|
+
*/
|
|
88
|
+
declare const ROOM_PREFIXES: {
|
|
89
|
+
readonly USER: "user";
|
|
90
|
+
readonly TENANT: "tenant";
|
|
91
|
+
readonly RESOURCE: "resource";
|
|
92
|
+
};
|
|
93
|
+
/** Union of canonical room prefix values (`'user' | 'tenant' | 'resource'`). */
|
|
94
|
+
type RoomPrefix = (typeof ROOM_PREFIXES)[keyof typeof ROOM_PREFIXES];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @fileoverview Event names reserved by the library (the §13 catalog).
|
|
98
|
+
* @layer shared
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* Event names reserved by the library.
|
|
102
|
+
*
|
|
103
|
+
* Consumer apps should not reuse these names for application-level events; doing
|
|
104
|
+
* so will not throw, but causes confusion in logs and client-side listeners.
|
|
105
|
+
*
|
|
106
|
+
* Note: the SSE heartbeat is intentionally absent. It is a raw `: keepalive`
|
|
107
|
+
* comment written directly to the response stream (not a named event and outside
|
|
108
|
+
* the `Last-Event-ID` id-space), so it is not part of this catalog.
|
|
109
|
+
*/
|
|
110
|
+
declare const RESERVED_EVENT_NAMES: {
|
|
111
|
+
readonly CONNECTION_ESTABLISHED: "connection:established";
|
|
112
|
+
readonly CONNECTION_REAUTH_FAILED: "connection:reauthentication-failed";
|
|
113
|
+
readonly CONNECTION_CREDENTIAL_EXPIRING: "connection:credential-expiring";
|
|
114
|
+
readonly ROOM_JOINED: "room:joined";
|
|
115
|
+
readonly ROOM_LEFT: "room:left";
|
|
116
|
+
readonly ERROR: "error";
|
|
117
|
+
};
|
|
118
|
+
/** Union of reserved event name values. */
|
|
119
|
+
type ReservedEventName = (typeof RESERVED_EVENT_NAMES)[keyof typeof RESERVED_EVENT_NAMES];
|
|
120
|
+
/**
|
|
121
|
+
* Application-level presence event names emitted by an `IPresenceStorage`
|
|
122
|
+
* implementation and consumed by the `usePresence` client hook.
|
|
123
|
+
*
|
|
124
|
+
* These are named transport events — carried over the `event:` SSE field and as
|
|
125
|
+
* Socket.IO event names — so a client must subscribe to them explicitly to
|
|
126
|
+
* preserve the event `type`. The native `EventSource.onmessage` callback only
|
|
127
|
+
* receives the default `message` event, never these named ones.
|
|
128
|
+
*/
|
|
129
|
+
declare const PRESENCE_EVENT_NAMES: {
|
|
130
|
+
readonly ONLINE: "presence:online";
|
|
131
|
+
readonly OFFLINE: "presence:offline";
|
|
132
|
+
};
|
|
133
|
+
/** Union of presence event name values. */
|
|
134
|
+
type PresenceEventName = (typeof PRESENCE_EVENT_NAMES)[keyof typeof PRESENCE_EVENT_NAMES];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @fileoverview Canonical error codes emitted by the library (the §14 catalog).
|
|
138
|
+
* @layer shared
|
|
139
|
+
*/
|
|
140
|
+
/**
|
|
141
|
+
* Canonical error codes emitted by the library. Map 1-to-1 with
|
|
142
|
+
* `docs/technical_specification.md` §14.
|
|
143
|
+
*
|
|
144
|
+
* `TOO_MANY_CONNECTIONS` signals FIFO eviction: when a user exceeds
|
|
145
|
+
* `maxConnectionsPerUser`, the OLDEST connection is evicted (closed with this
|
|
146
|
+
* code) and the new one is admitted — it is never an HTTP 429 rejection.
|
|
147
|
+
*/
|
|
148
|
+
declare const REALTIME_ERROR_CODES: {
|
|
149
|
+
readonly INVALID_OPTIONS: "REALTIME_INVALID_OPTIONS";
|
|
150
|
+
readonly NO_AUTHENTICATOR: "REALTIME_NO_AUTHENTICATOR";
|
|
151
|
+
readonly AUTH_FAILED: "REALTIME_AUTH_FAILED";
|
|
152
|
+
readonly REAUTHENTICATION_FAILED: "REALTIME_REAUTHENTICATION_FAILED";
|
|
153
|
+
readonly TOO_MANY_CONNECTIONS: "REALTIME_TOO_MANY_CONNECTIONS";
|
|
154
|
+
readonly INVALID_TICKET: "REALTIME_INVALID_TICKET";
|
|
155
|
+
readonly PUBSUB_UNAVAILABLE: "REALTIME_PUBSUB_UNAVAILABLE";
|
|
156
|
+
readonly PAYLOAD_TOO_LARGE: "REALTIME_PAYLOAD_TOO_LARGE";
|
|
157
|
+
readonly REPLAY_BUFFER_MISS: "REALTIME_REPLAY_BUFFER_MISS";
|
|
158
|
+
};
|
|
159
|
+
/** Union of canonical error code values. */
|
|
160
|
+
type RealtimeErrorCode = (typeof REALTIME_ERROR_CODES)[keyof typeof REALTIME_ERROR_CODES];
|
|
161
|
+
|
|
162
|
+
export { PRESENCE_EVENT_NAMES, type PresenceEventName, type PublicConnectionMeta, REALTIME_ERROR_CODES, RESERVED_EVENT_NAMES, ROOM_PREFIXES, type RealtimeErrorCode, type RealtimeEvent, type ReservedEventName, type RoomPrefix, type TransportMode };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/shared/constants/room-prefixes.constants.ts
|
|
2
|
+
var ROOM_PREFIXES = {
|
|
3
|
+
USER: "user",
|
|
4
|
+
TENANT: "tenant",
|
|
5
|
+
RESOURCE: "resource"
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/shared/constants/reserved-events.constants.ts
|
|
9
|
+
var RESERVED_EVENT_NAMES = {
|
|
10
|
+
CONNECTION_ESTABLISHED: "connection:established",
|
|
11
|
+
CONNECTION_REAUTH_FAILED: "connection:reauthentication-failed",
|
|
12
|
+
CONNECTION_CREDENTIAL_EXPIRING: "connection:credential-expiring",
|
|
13
|
+
ROOM_JOINED: "room:joined",
|
|
14
|
+
ROOM_LEFT: "room:left",
|
|
15
|
+
ERROR: "error"
|
|
16
|
+
};
|
|
17
|
+
var PRESENCE_EVENT_NAMES = {
|
|
18
|
+
ONLINE: "presence:online",
|
|
19
|
+
OFFLINE: "presence:offline"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/shared/constants/error-codes.constants.ts
|
|
23
|
+
var REALTIME_ERROR_CODES = {
|
|
24
|
+
INVALID_OPTIONS: "REALTIME_INVALID_OPTIONS",
|
|
25
|
+
NO_AUTHENTICATOR: "REALTIME_NO_AUTHENTICATOR",
|
|
26
|
+
AUTH_FAILED: "REALTIME_AUTH_FAILED",
|
|
27
|
+
REAUTHENTICATION_FAILED: "REALTIME_REAUTHENTICATION_FAILED",
|
|
28
|
+
TOO_MANY_CONNECTIONS: "REALTIME_TOO_MANY_CONNECTIONS",
|
|
29
|
+
INVALID_TICKET: "REALTIME_INVALID_TICKET",
|
|
30
|
+
PUBSUB_UNAVAILABLE: "REALTIME_PUBSUB_UNAVAILABLE",
|
|
31
|
+
PAYLOAD_TOO_LARGE: "REALTIME_PAYLOAD_TOO_LARGE",
|
|
32
|
+
REPLAY_BUFFER_MISS: "REALTIME_REPLAY_BUFFER_MISS"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { PRESENCE_EVENT_NAMES, REALTIME_ERROR_CODES, RESERVED_EVENT_NAMES, ROOM_PREFIXES };
|
package/package.json
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bymax-one/nest-realtime",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Realtime backend → frontend communication for NestJS — dual-transport SSE (default) and WebSocket (opt-in) with a unified server-side API.",
|
|
5
|
+
"author": "Bymax One <support@bymax.one>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/bymaxone/nest-realtime#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/bymaxone/nest-realtime.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/bymaxone/nest-realtime/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"README.md",
|
|
21
|
+
"CHANGELOG.md"
|
|
22
|
+
],
|
|
23
|
+
"main": "./dist/server/index.cjs",
|
|
24
|
+
"module": "./dist/server/index.mjs",
|
|
25
|
+
"types": "./dist/server/index.d.cts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/server/index.d.ts",
|
|
30
|
+
"default": "./dist/server/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/server/index.d.cts",
|
|
34
|
+
"default": "./dist/server/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./shared": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/shared/index.d.ts",
|
|
40
|
+
"default": "./dist/shared/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/shared/index.d.cts",
|
|
44
|
+
"default": "./dist/shared/index.cjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"./react": {
|
|
48
|
+
"import": {
|
|
49
|
+
"types": "./dist/react/index.d.ts",
|
|
50
|
+
"default": "./dist/react/index.mjs"
|
|
51
|
+
},
|
|
52
|
+
"require": {
|
|
53
|
+
"types": "./dist/react/index.d.cts",
|
|
54
|
+
"default": "./dist/react/index.cjs"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"./package.json": "./package.json"
|
|
58
|
+
},
|
|
59
|
+
"typesVersions": {
|
|
60
|
+
"*": {
|
|
61
|
+
"shared": [
|
|
62
|
+
"./dist/shared/index.d.cts"
|
|
63
|
+
],
|
|
64
|
+
"react": [
|
|
65
|
+
"./dist/react/index.d.cts"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@nestjs/common": "^11.0.16",
|
|
71
|
+
"@nestjs/core": "^11.1.18",
|
|
72
|
+
"@nestjs/platform-socket.io": "^11.0.0",
|
|
73
|
+
"@nestjs/websockets": "^11.0.0",
|
|
74
|
+
"@socket.io/redis-adapter": "^8.0.0",
|
|
75
|
+
"ioredis": "^5.0.0",
|
|
76
|
+
"react": "^19.0.0",
|
|
77
|
+
"react-dom": "^19.0.0",
|
|
78
|
+
"reflect-metadata": "^0.2.0",
|
|
79
|
+
"rxjs": "^7.8.0",
|
|
80
|
+
"socket.io": "^4.6.2",
|
|
81
|
+
"socket.io-client": "^4.0.0"
|
|
82
|
+
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"@nestjs/websockets": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"@nestjs/platform-socket.io": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"socket.io": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"@socket.io/redis-adapter": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"ioredis": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"react": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
102
|
+
"react-dom": {
|
|
103
|
+
"optional": true
|
|
104
|
+
},
|
|
105
|
+
"socket.io-client": {
|
|
106
|
+
"optional": true
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"devDependencies": {
|
|
110
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
111
|
+
"@nestjs/common": "^11.1.28",
|
|
112
|
+
"@nestjs/core": "^11.1.28",
|
|
113
|
+
"@nestjs/platform-express": "^11.1.28",
|
|
114
|
+
"@nestjs/platform-socket.io": "^11.1.28",
|
|
115
|
+
"@nestjs/testing": "^11.1.28",
|
|
116
|
+
"@nestjs/websockets": "^11.1.28",
|
|
117
|
+
"@socket.io/redis-adapter": "^8.0.0",
|
|
118
|
+
"@stryker-mutator/core": "^9.6.1",
|
|
119
|
+
"@stryker-mutator/jest-runner": "^9.6.1",
|
|
120
|
+
"@stryker-mutator/typescript-checker": "^9.6.1",
|
|
121
|
+
"@testing-library/react": "^16.0.0",
|
|
122
|
+
"@types/express": "^5.0.0",
|
|
123
|
+
"@types/ioredis-mock": "^8.2.7",
|
|
124
|
+
"@types/jest": "^30.0.0",
|
|
125
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
126
|
+
"@types/node": "^26.1.1",
|
|
127
|
+
"@types/react": "^19.0.0",
|
|
128
|
+
"@types/react-dom": "^19.0.0",
|
|
129
|
+
"@types/supertest": "^7.2.1",
|
|
130
|
+
"@typescript-eslint/eslint-plugin": "^8.65.0",
|
|
131
|
+
"@typescript-eslint/parser": "^8.65.0",
|
|
132
|
+
"eslint": "^10.8.0",
|
|
133
|
+
"eslint-config-prettier": "^10.1.8",
|
|
134
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
135
|
+
"eslint-plugin-import": "^2.29.0",
|
|
136
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
137
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
138
|
+
"eslint-plugin-security": "^4.0.1",
|
|
139
|
+
"eventsource": "^4.1.0",
|
|
140
|
+
"ioredis": "^5.0.0",
|
|
141
|
+
"ioredis-mock": "^8.0.0",
|
|
142
|
+
"jest": "^30.0.0",
|
|
143
|
+
"jest-environment-jsdom": "^30.0.0",
|
|
144
|
+
"jsonwebtoken": "^9.0.3",
|
|
145
|
+
"prettier": "^3.9.6",
|
|
146
|
+
"react": "^19.2.8",
|
|
147
|
+
"react-dom": "^19.2.8",
|
|
148
|
+
"reflect-metadata": "^0.2.2",
|
|
149
|
+
"rxjs": "^7.8.0",
|
|
150
|
+
"socket.io": "^4.6.2",
|
|
151
|
+
"socket.io-client": "^4.0.0",
|
|
152
|
+
"supertest": "^7.0.0",
|
|
153
|
+
"ts-jest": "^29.4.12",
|
|
154
|
+
"ts-node": "^10.9.0",
|
|
155
|
+
"tslib": "^2.6.0",
|
|
156
|
+
"tsup": "^8.0.0",
|
|
157
|
+
"typescript": "^5.6.0"
|
|
158
|
+
},
|
|
159
|
+
"engines": {
|
|
160
|
+
"node": ">=24.0.0"
|
|
161
|
+
},
|
|
162
|
+
"publishConfig": {
|
|
163
|
+
"access": "public",
|
|
164
|
+
"registry": "https://registry.npmjs.org/"
|
|
165
|
+
},
|
|
166
|
+
"scripts": {
|
|
167
|
+
"build": "pnpm clean && tsup",
|
|
168
|
+
"check:exports": "attw --pack . --profile strict",
|
|
169
|
+
"check:published": "node scripts/check-published-surface.mjs",
|
|
170
|
+
"clean": "rm -rf dist coverage",
|
|
171
|
+
"lint": "eslint src",
|
|
172
|
+
"lint:fix": "eslint src --fix",
|
|
173
|
+
"mutation": "stryker run",
|
|
174
|
+
"mutation:dry-run": "stryker run --dryRunOnly",
|
|
175
|
+
"mutation:incremental": "stryker run --incremental",
|
|
176
|
+
"release": "pnpm publish --provenance",
|
|
177
|
+
"size": "node scripts/check-size.mjs",
|
|
178
|
+
"test": "jest",
|
|
179
|
+
"test:all": "pnpm test && pnpm test:e2e",
|
|
180
|
+
"test:cov": "jest --config jest.coverage.config.ts --coverage",
|
|
181
|
+
"test:cov:all": "jest --config jest.coverage.config.ts --coverage",
|
|
182
|
+
"test:e2e": "jest --config jest.e2e.config.ts",
|
|
183
|
+
"test:e2e:cross-instance": "jest --config jest.e2e.cross-instance.config.ts --runInBand",
|
|
184
|
+
"test:watch": "jest --watch",
|
|
185
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json"
|
|
186
|
+
}
|
|
187
|
+
}
|