@bymax-one/nest-realtime 1.2.23 → 1.2.24

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 CHANGED
@@ -7,6 +7,18 @@ Versioning is **not** strict [SemVer](https://semver.org/spec/v2.0.0.html) while
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.24] - 2026-11-20
11
+
12
+ ### Fixed
13
+
14
+ - **A `tenantResolver` that writes to the result it receives no longer changes the connection.** With an absent or `null` tenant, the copy handed to the resolver was the object the library kept, so a resolver that assigned to it (for example to `userId`) changed the connection record. The resolver is given its own copy in every case; the copy is shallow, so nested objects are still shared and a write inside them still changes what is kept.
15
+ - **A log field named like what a structured logger writes itself no longer reaches the line.** `logEvent` already dropped `err`, `msg` and `level`; it now also drops `time`, `pid`, `hostname`, `name`, `v`, `req` and `res`, which a logger writes on every line.
16
+ - **Every read of an object the host hands over fails with the library's error and the host's error as its cause.** The keys of a `forRootAsync` registration were read without a guard, so a getter or a proxy on the registration raised the host's own error; they are read once, under the guard. An object that throws when its type is read, as the options, a group or the registration, was refused without the error it threw; the error is now the `cause`. What a synchronous factory returns is read for `then` once and its answer is boxed, so a trap that throws on a later read cannot escape.
17
+
18
+ ### Documentation
19
+
20
+ - **The `tenantResolver` documentation says exactly what the copy holds.** The result's own enumerable properties, and the `tenantId` as the library read it, which counts when an accessor on the prototype supplies it. This replaces "own enumerable properties only", which was true of the rest of the copy and not of the tenant.
21
+
10
22
  ## [1.2.23] - 2026-11-20
11
23
 
12
24
  ### Fixed
@@ -1262,7 +1274,8 @@ First published release.
1262
1274
  rather than by the manual sweep that raised the NestJS floors — that sweep
1263
1275
  asked about NestJS and never put the same question to the other ten peers.
1264
1276
 
1265
- [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.23...HEAD
1277
+ [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.24...HEAD
1278
+ [1.2.24]: https://github.com/bymaxone/nest-realtime/compare/v1.2.23...v1.2.24
1266
1279
  [1.2.23]: https://github.com/bymaxone/nest-realtime/compare/v1.2.22...v1.2.23
1267
1280
  [1.2.22]: https://github.com/bymaxone/nest-realtime/compare/v1.2.21...v1.2.22
1268
1281
  [1.2.21]: https://github.com/bymaxone/nest-realtime/compare/v1.2.20...v1.2.21
package/README.md CHANGED
@@ -412,7 +412,7 @@ An option that holds `undefined` or `null` is read as unset: it takes its defaul
412
412
 
413
413
  The shape of what you pass is checked at start-up too, and refused with `REALTIME_INVALID_OPTIONS`: `sse`, `websocket`, `reauthenticationPolicy` and `hooks` must be objects; `pubsub`, `offlineQueue` and `presence` must have every function of their interface (`IRealtimePubSub`, `IOfflineQueueStorage`, `IPresenceStorage`), on the object or its prototype; each hook that is set and `tenantResolver` must be a function; `sse.emitConnectionEvent` and `websocket.emitConnectionEvent` must be booleans; `sse.endpoint` must be a non-blank string, with or without a leading slash. An endpoint holds no whitespace, because no request can reach it, and the `sseEndpoint` of `forRootAsync` gets the same check. The options argument must be an object, and so must what a `forRootAsync` factory returns; an array, a `Date` or a `Map` is refused there and where a group is expected, while an instance of your own class is read by its keys. `new RedisOfflineQueue(options)` refuses options that are not an object and a `client` that is not one.
414
414
 
415
- The options are typed per entry point: `SseRealtimeModuleOptions` and `SseRealtimeModuleAsyncOptions` fix `transport: 'sse'`, and `WebSocketRealtimeModuleOptions` and `WebSocketRealtimeModuleAsyncOptions` (from `/websocket`) fix `'websocket' | 'both'`. `forRootAsync` takes `useFactory`, `useClass` (a `BymaxRealtimeModuleOptionsFactory`) or `useExisting`. A `useClass` or `useExisting` provider implements `createRealtimeOptions()`, which returns the options or a promise of them; a provider that does not is refused with `REALTIME_INVALID_OPTIONS`, as is an `extraProviders` that is not an array of providers (a class, or an object with `provide`). An options object, a group, a pluggable piece or a provider whose read throws, such as a getter or a proxy, is refused the same way, with the error it threw as the `cause`. The exception is an object that throws when its type is read, such as a proxy whose every read throws: it is refused as a built-in object and its error is not kept. A factory that returns the object itself is covered, including a proxy that throws on `then` or was revoked; one written as an `async` function rejects its own promise with the object's error, which reaches the application as that factory's failure. A refusal is recognised by its stable code, so an error of your own that carries a `REALTIME_` code is not wrapped.
415
+ The options are typed per entry point: `SseRealtimeModuleOptions` and `SseRealtimeModuleAsyncOptions` fix `transport: 'sse'`, and `WebSocketRealtimeModuleOptions` and `WebSocketRealtimeModuleAsyncOptions` (from `/websocket`) fix `'websocket' | 'both'`. `forRootAsync` takes `useFactory`, `useClass` (a `BymaxRealtimeModuleOptionsFactory`) or `useExisting`. A `useClass` or `useExisting` provider implements `createRealtimeOptions()`, which returns the options or a promise of them; a provider that does not is refused with `REALTIME_INVALID_OPTIONS`, as is an `extraProviders` that is not an array of providers (a class, or an object with `provide`). An options object, a group, a pluggable piece or a provider whose read throws, such as a getter or a proxy, is refused the same way, with the error it threw as the `cause`. The same holds for the keys of a `forRootAsync` registration and for an object that throws when its type is read, such as a proxy whose every read throws: it is refused as a built-in object, with the error it threw as the `cause`. A factory that returns the object itself is covered, including a proxy that throws on `then` or was revoked; one written as an `async` function rejects its own promise with the object's error, which reaches the application as that factory's failure. A refusal is recognised by its stable code, so an error of your own that carries a `REALTIME_` code is not wrapped.
416
416
 
417
417
  > [!IMPORTANT]
418
418
  > **`forRootAsync` takes the SSE route on the registration, not from the factory.** NestJS
@@ -777,7 +777,7 @@ Reference implementations shipped: `InMemoryPubSub` (default), `RedisRealtimePub
777
777
 
778
778
  To place a connection in no tenant, **omit `tenantId`**. The runtime also accepts `undefined` or `null`, but whether those type-check depends on the consumer's `tsconfig` (`exactOptionalPropertyTypes` rejects `undefined`, `strictNullChecks` rejects `null`), so omission is the only form that compiles everywhere.
779
779
 
780
- `tenantResolver` cannot clear a tenant. It receives a plain copy of the authentication result, with its own enumerable properties only and no `tenantId` when the tenant is absent or `null`, not the authenticator's original object. Resolution is `tenantResolver?.(auth) ?? auth.tenantId`, so a resolver returning `undefined` or `null` means "no opinion" and the authenticator's tenant stays. Decide the absent case in the authenticator.
780
+ `tenantResolver` cannot clear a tenant. It receives a plain copy of the authentication result, not the authenticator's original object: the result's own enumerable properties, and the `tenantId` as the library read it, which counts when an accessor on the prototype supplies it and is missing when the tenant is absent or `null`. The copy is its own object and is shallow: a resolver that assigns to one of its top-level properties changes nothing the library keeps, while nested objects are shared with the original, so a write inside them changes what the library keeps. Resolution is `tenantResolver?.(auth) ?? auth.tenantId`, so a resolver returning `undefined` or `null` means "no opinion" and the authenticator's tenant stays. Decide the absent case in the authenticator.
781
781
 
782
782
  #### Carrying handshake context into the hooks
783
783
 
@@ -45,11 +45,14 @@ var REALTIME_ERROR_CODES = {
45
45
 
46
46
  // src/server/utils/is-plain-object.ts
47
47
  function isPlainObject(value) {
48
- if (typeof value !== "object") return false;
48
+ return readPlainObject(value).plain;
49
+ }
50
+ function readPlainObject(value) {
51
+ if (typeof value !== "object") return { plain: false, threw: false };
49
52
  try {
50
- return Object.prototype.toString.call(value) === "[object Object]";
51
- } catch {
52
- return false;
53
+ return { plain: Object.prototype.toString.call(value) === "[object Object]", threw: false };
54
+ } catch (error) {
55
+ return { plain: false, threw: true, error };
53
56
  }
54
57
  }
55
58
 
@@ -166,9 +169,12 @@ function guardHostReads(what, read) {
166
169
  );
167
170
  }
168
171
  }
169
- async function awaitHostResult(returned, what = "the options") {
170
- guardHostReads(what, () => returned?.then);
171
- return returned;
172
+ function awaitHostResult(returned, what = "the options") {
173
+ const then = guardHostReads(what, () => returned?.then);
174
+ if (typeof then !== "function") return Promise.resolve({ value: returned });
175
+ return new Promise((resolve, reject) => {
176
+ then.call(returned, (value) => resolve({ value }), reject);
177
+ });
172
178
  }
173
179
 
174
180
  // src/server/constants/injection-tokens.constants.ts
@@ -212,11 +218,11 @@ function describeReceived(value) {
212
218
  }
213
219
 
214
220
  // src/server/utils/refuse-object.ts
215
- function refuseObject(who, path, value) {
221
+ function refuseObject(who, path, value, cause) {
216
222
  throw realtimeError(
217
223
  REALTIME_ERROR_CODES.INVALID_OPTIONS,
218
224
  `${path} must be an object, received ${describeReceived(value)}`,
219
- { who }
225
+ cause === void 0 ? { who } : { who, cause: cause.error }
220
226
  );
221
227
  }
222
228
 
@@ -234,15 +240,17 @@ var HOOK_NAMES = [
234
240
  "onDeliveryFailure"
235
241
  ];
236
242
  var GROUP_NAMES = ["sse", "websocket", "reauthenticationPolicy"];
237
- function refuse(path, expected, received) {
243
+ function refuse(path, expected, received, cause) {
238
244
  throw realtimeError(
239
245
  REALTIME_ERROR_CODES.INVALID_OPTIONS,
240
246
  `options.${path} must be ${expected}, received ${describeReceived(received)}`,
241
- { who: "BymaxRealtimeModule" }
247
+ cause === void 0 ? { who: "BymaxRealtimeModule" } : { who: "BymaxRealtimeModule", cause: cause.error }
242
248
  );
243
249
  }
244
250
  function assertObject(path, value) {
245
- if (value !== void 0 && !isPlainObject(value)) refuse(path, "an object", value);
251
+ if (value === void 0) return;
252
+ const read = readPlainObject(value);
253
+ if (!read.plain) refuse(path, "an object", value, read.threw ? { error: read.error } : void 0);
246
254
  }
247
255
  function assertFunction(path, value) {
248
256
  if (typeof value !== "function") refuse(path, "a function", value);
@@ -261,7 +269,9 @@ function assertSseEndpoint(path, value) {
261
269
  if (/\s/.test(value)) refuse(path, "a string without whitespace", value);
262
270
  }
263
271
  function assertOptionsObject(value, who = "BymaxRealtimeModule") {
264
- if (!isPlainObject(value)) refuseObject(who, "options", value);
272
+ const read = readPlainObject(value);
273
+ if (!read.plain)
274
+ refuseObject(who, "options", value, read.threw ? { error: read.error } : void 0);
265
275
  }
266
276
  function validatePieces(options) {
267
277
  for (const [name, functions] of Object.entries(REQUIRED_FUNCTIONS)) {
@@ -567,7 +577,18 @@ var REALTIME_LOG_EVENTS = [
567
577
  "REALTIME_COMPOSITE_PARTIAL_FAILURE",
568
578
  "REALTIME_SERVER_NOT_ATTACHED"
569
579
  ];
570
- var RESERVED_KEYS = ["err", "msg", "level"];
580
+ var RESERVED_KEYS = [
581
+ "err",
582
+ "msg",
583
+ "level",
584
+ "time",
585
+ "pid",
586
+ "hostname",
587
+ "name",
588
+ "v",
589
+ "req",
590
+ "res"
591
+ ];
571
592
  function logEvent(logger, level, event, message, fields = {}, error) {
572
593
  try {
573
594
  const line = { ...fields, event, message };
@@ -863,7 +884,7 @@ function isBlank(value) {
863
884
  function resolveAuthTenant(options, auth) {
864
885
  const { tenantId: own, ...rest } = auth;
865
886
  const resolved = options.tenantResolver?.(
866
- own === void 0 || own === null ? rest : { ...rest, tenantId: own }
887
+ own === void 0 || own === null ? { ...rest } : { ...rest, tenantId: own }
867
888
  ) ?? own;
868
889
  if (resolved === void 0 || resolved === null) return rest;
869
890
  return { ...rest, tenantId: resolved };
@@ -2684,7 +2705,7 @@ function buildOptionsProvider(asyncOptions, resolve, factoryToken) {
2684
2705
  if (isSet(asyncOptions.useFactory)) {
2685
2706
  return {
2686
2707
  provide: REALTIME_OPTIONS_TOKEN,
2687
- useFactory: async (...args) => resolve(await awaitHostResult(asyncOptions.useFactory(...args)), "useFactory"),
2708
+ useFactory: async (...args) => resolve((await awaitHostResult(asyncOptions.useFactory(...args))).value, "useFactory"),
2688
2709
  inject: [...asyncOptions.inject ?? []]
2689
2710
  };
2690
2711
  }
@@ -2702,7 +2723,7 @@ function buildOptionsProvider(asyncOptions, resolve, factoryToken) {
2702
2723
  );
2703
2724
  }
2704
2725
  return resolve(
2705
- await awaitHostResult(create.call(factory)),
2726
+ (await awaitHostResult(create.call(factory))).value,
2706
2727
  "createRealtimeOptions"
2707
2728
  );
2708
2729
  },
@@ -2739,34 +2760,48 @@ function buildResolver(asyncOptions, instanceId, boundSseEndpoint, logger, modul
2739
2760
  return bindSseEndpoint(resolved, declaredEndpoint, boundSseEndpoint, moduleName);
2740
2761
  };
2741
2762
  }
2763
+ var copied = (value) => Array.isArray(value) ? [...value] : value;
2764
+ function readRegistration(registration) {
2765
+ return guardHostReads("the registration", () => ({
2766
+ transport: registration.transport,
2767
+ sseEndpoint: registration.sseEndpoint,
2768
+ useFactory: registration.useFactory,
2769
+ useClass: registration.useClass,
2770
+ useExisting: registration.useExisting,
2771
+ inject: copied(registration.inject),
2772
+ imports: copied(registration.imports),
2773
+ extraProviders: copied(registration.extraProviders)
2774
+ }));
2775
+ }
2742
2776
  function composeForRootAsync(moduleClass, wiring, logger, asyncOptions) {
2743
2777
  const moduleName = moduleClass.name;
2744
2778
  assertOptionsObject(asyncOptions, moduleName);
2745
- assertOneFactoryPattern(asyncOptions, moduleName);
2746
- assertModeSupported(wiring, asyncOptions.transport, moduleName);
2747
- assertSseEndpoint("sseEndpoint", asyncOptions.sseEndpoint);
2748
- assertSseEndpointApplies(asyncOptions, moduleName);
2749
- assertExtraProviders(asyncOptions.extraProviders);
2779
+ const registration = readRegistration(asyncOptions);
2780
+ assertOneFactoryPattern(registration, moduleName);
2781
+ assertModeSupported(wiring, registration.transport, moduleName);
2782
+ assertSseEndpoint("sseEndpoint", registration.sseEndpoint);
2783
+ assertSseEndpointApplies(registration, moduleName);
2784
+ assertExtraProviders(registration.extraProviders);
2750
2785
  const FACTORY_TOKEN = /* @__PURE__ */ Symbol("REALTIME_OPTIONS_FACTORY");
2751
2786
  const instanceId = crypto.randomUUID();
2752
- const boundSseEndpoint = asyncOptions.sseEndpoint ?? DEFAULT_ASYNC_SSE_ENDPOINT;
2753
- const resolve = buildResolver(asyncOptions, instanceId, boundSseEndpoint, logger, moduleName);
2754
- const factoryClassProvider = isSet(asyncOptions.useClass) ? [{ provide: FACTORY_TOKEN, useClass: asyncOptions.useClass }] : [];
2787
+ const boundSseEndpoint = registration.sseEndpoint ?? DEFAULT_ASYNC_SSE_ENDPOINT;
2788
+ const resolve = buildResolver(registration, instanceId, boundSseEndpoint, logger, moduleName);
2789
+ const factoryClassProvider = isSet(registration.useClass) ? [{ provide: FACTORY_TOKEN, useClass: registration.useClass }] : [];
2755
2790
  const { providers: transportProviders, controllers } = wiring.buildAsync({
2756
- mode: asyncOptions.transport,
2791
+ mode: registration.transport,
2757
2792
  sseEndpoint: boundSseEndpoint
2758
2793
  });
2759
2794
  return {
2760
2795
  module: moduleClass,
2761
- imports: asyncOptions.imports ?? [],
2796
+ imports: registration.imports ?? [],
2762
2797
  controllers,
2763
2798
  providers: [
2764
2799
  ...factoryClassProvider,
2765
- buildOptionsProvider(asyncOptions, resolve, FACTORY_TOKEN),
2800
+ buildOptionsProvider(registration, resolve, FACTORY_TOKEN),
2766
2801
  ...buildOptionDerivedProviders(logger, instanceId),
2767
2802
  ...SHARED_SERVICES,
2768
2803
  ...transportProviders,
2769
- ...asyncOptions.extraProviders ?? []
2804
+ ...registration.extraProviders ?? []
2770
2805
  ],
2771
2806
  exports: EXPORTED_TOKENS
2772
2807
  };
@@ -480,8 +480,13 @@ interface BymaxRealtimeModuleOptions {
480
480
  * Derive the tenant a connection routes on from the authenticated result.
481
481
  *
482
482
  * Applied on **both** transports. It receives a plain copy of the authentication
483
- * result, with its own enumerable properties only and no `tenantId` when the tenant
484
- * is absent or `null`, not the authenticator's original object. `undefined` and
483
+ * result, not the authenticator's original object: the result's own enumerable
484
+ * properties and the `tenantId` as the library read it, which counts when an accessor
485
+ * on the prototype supplies it and is missing when the tenant is absent or `null`.
486
+ * The copy is its own object and is shallow: a resolver that assigns to one of its
487
+ * top-level properties changes nothing the library keeps, while `roles`, `rooms` and
488
+ * `metadata` are shared with the original, so a write inside them changes what the
489
+ * library keeps. `undefined` and
485
490
  * `null` both mean "no opinion"
486
491
  * and fall back to `auth.tenantId` rather than clearing it; to place a connection
487
492
  * in no tenant, return a result without one from the authenticator. `null` is in
@@ -2309,7 +2314,7 @@ type LogFields = Readonly<Record<string, string | number | boolean>>;
2309
2314
  * @param event - The stable code of the condition.
2310
2315
  * @param message - Human text; the library's own wording, with no host-supplied value in it.
2311
2316
  * @param fields - Closed or numeric fields, built by the library. A key named `event` or `message` is replaced by the
2312
- * library's own value, and one named `err`, `msg` or `level` is dropped, and a field whose read throws, such as a getter, loses the line like any other
2317
+ * library's own value, and one named `err`, `msg`, `level`, `time`, `pid`, `hostname`, `name`, `v`, `req` or `res` is dropped, and a field whose read throws, such as a getter, loses the line like any other
2313
2318
  * throw while writing.
2314
2319
  * @param error - What was thrown, when the event reports a failure. It goes under `err` as the value itself, never
2315
2320
  * as text in `message`, so the logger's serializer and redaction apply to it: an error raised by host code can
@@ -480,8 +480,13 @@ interface BymaxRealtimeModuleOptions {
480
480
  * Derive the tenant a connection routes on from the authenticated result.
481
481
  *
482
482
  * Applied on **both** transports. It receives a plain copy of the authentication
483
- * result, with its own enumerable properties only and no `tenantId` when the tenant
484
- * is absent or `null`, not the authenticator's original object. `undefined` and
483
+ * result, not the authenticator's original object: the result's own enumerable
484
+ * properties and the `tenantId` as the library read it, which counts when an accessor
485
+ * on the prototype supplies it and is missing when the tenant is absent or `null`.
486
+ * The copy is its own object and is shallow: a resolver that assigns to one of its
487
+ * top-level properties changes nothing the library keeps, while `roles`, `rooms` and
488
+ * `metadata` are shared with the original, so a write inside them changes what the
489
+ * library keeps. `undefined` and
485
490
  * `null` both mean "no opinion"
486
491
  * and fall back to `auth.tenantId` rather than clearing it; to place a connection
487
492
  * in no tenant, return a result without one from the authenticator. `null` is in
@@ -2309,7 +2314,7 @@ type LogFields = Readonly<Record<string, string | number | boolean>>;
2309
2314
  * @param event - The stable code of the condition.
2310
2315
  * @param message - Human text; the library's own wording, with no host-supplied value in it.
2311
2316
  * @param fields - Closed or numeric fields, built by the library. A key named `event` or `message` is replaced by the
2312
- * library's own value, and one named `err`, `msg` or `level` is dropped, and a field whose read throws, such as a getter, loses the line like any other
2317
+ * library's own value, and one named `err`, `msg`, `level`, `time`, `pid`, `hostname`, `name`, `v`, `req` or `res` is dropped, and a field whose read throws, such as a getter, loses the line like any other
2313
2318
  * throw while writing.
2314
2319
  * @param error - What was thrown, when the event reports a failure. It goes under `err` as the value itself, never
2315
2320
  * as text in `message`, so the logger's serializer and redaction apply to it: an error raised by host code can
@@ -43,11 +43,14 @@ var REALTIME_ERROR_CODES = {
43
43
 
44
44
  // src/server/utils/is-plain-object.ts
45
45
  function isPlainObject(value) {
46
- if (typeof value !== "object") return false;
46
+ return readPlainObject(value).plain;
47
+ }
48
+ function readPlainObject(value) {
49
+ if (typeof value !== "object") return { plain: false, threw: false };
47
50
  try {
48
- return Object.prototype.toString.call(value) === "[object Object]";
49
- } catch {
50
- return false;
51
+ return { plain: Object.prototype.toString.call(value) === "[object Object]", threw: false };
52
+ } catch (error) {
53
+ return { plain: false, threw: true, error };
51
54
  }
52
55
  }
53
56
 
@@ -164,9 +167,12 @@ function guardHostReads(what, read) {
164
167
  );
165
168
  }
166
169
  }
167
- async function awaitHostResult(returned, what = "the options") {
168
- guardHostReads(what, () => returned?.then);
169
- return returned;
170
+ function awaitHostResult(returned, what = "the options") {
171
+ const then = guardHostReads(what, () => returned?.then);
172
+ if (typeof then !== "function") return Promise.resolve({ value: returned });
173
+ return new Promise((resolve, reject) => {
174
+ then.call(returned, (value) => resolve({ value }), reject);
175
+ });
170
176
  }
171
177
 
172
178
  // src/server/constants/injection-tokens.constants.ts
@@ -210,11 +216,11 @@ function describeReceived(value) {
210
216
  }
211
217
 
212
218
  // src/server/utils/refuse-object.ts
213
- function refuseObject(who, path, value) {
219
+ function refuseObject(who, path, value, cause) {
214
220
  throw realtimeError(
215
221
  REALTIME_ERROR_CODES.INVALID_OPTIONS,
216
222
  `${path} must be an object, received ${describeReceived(value)}`,
217
- { who }
223
+ cause === void 0 ? { who } : { who, cause: cause.error }
218
224
  );
219
225
  }
220
226
 
@@ -232,15 +238,17 @@ var HOOK_NAMES = [
232
238
  "onDeliveryFailure"
233
239
  ];
234
240
  var GROUP_NAMES = ["sse", "websocket", "reauthenticationPolicy"];
235
- function refuse(path, expected, received) {
241
+ function refuse(path, expected, received, cause) {
236
242
  throw realtimeError(
237
243
  REALTIME_ERROR_CODES.INVALID_OPTIONS,
238
244
  `options.${path} must be ${expected}, received ${describeReceived(received)}`,
239
- { who: "BymaxRealtimeModule" }
245
+ cause === void 0 ? { who: "BymaxRealtimeModule" } : { who: "BymaxRealtimeModule", cause: cause.error }
240
246
  );
241
247
  }
242
248
  function assertObject(path, value) {
243
- if (value !== void 0 && !isPlainObject(value)) refuse(path, "an object", value);
249
+ if (value === void 0) return;
250
+ const read = readPlainObject(value);
251
+ if (!read.plain) refuse(path, "an object", value, read.threw ? { error: read.error } : void 0);
244
252
  }
245
253
  function assertFunction(path, value) {
246
254
  if (typeof value !== "function") refuse(path, "a function", value);
@@ -259,7 +267,9 @@ function assertSseEndpoint(path, value) {
259
267
  if (/\s/.test(value)) refuse(path, "a string without whitespace", value);
260
268
  }
261
269
  function assertOptionsObject(value, who = "BymaxRealtimeModule") {
262
- if (!isPlainObject(value)) refuseObject(who, "options", value);
270
+ const read = readPlainObject(value);
271
+ if (!read.plain)
272
+ refuseObject(who, "options", value, read.threw ? { error: read.error } : void 0);
263
273
  }
264
274
  function validatePieces(options) {
265
275
  for (const [name, functions] of Object.entries(REQUIRED_FUNCTIONS)) {
@@ -565,7 +575,18 @@ var REALTIME_LOG_EVENTS = [
565
575
  "REALTIME_COMPOSITE_PARTIAL_FAILURE",
566
576
  "REALTIME_SERVER_NOT_ATTACHED"
567
577
  ];
568
- var RESERVED_KEYS = ["err", "msg", "level"];
578
+ var RESERVED_KEYS = [
579
+ "err",
580
+ "msg",
581
+ "level",
582
+ "time",
583
+ "pid",
584
+ "hostname",
585
+ "name",
586
+ "v",
587
+ "req",
588
+ "res"
589
+ ];
569
590
  function logEvent(logger, level, event, message, fields = {}, error) {
570
591
  try {
571
592
  const line = { ...fields, event, message };
@@ -861,7 +882,7 @@ function isBlank(value) {
861
882
  function resolveAuthTenant(options, auth) {
862
883
  const { tenantId: own, ...rest } = auth;
863
884
  const resolved = options.tenantResolver?.(
864
- own === void 0 || own === null ? rest : { ...rest, tenantId: own }
885
+ own === void 0 || own === null ? { ...rest } : { ...rest, tenantId: own }
865
886
  ) ?? own;
866
887
  if (resolved === void 0 || resolved === null) return rest;
867
888
  return { ...rest, tenantId: resolved };
@@ -2682,7 +2703,7 @@ function buildOptionsProvider(asyncOptions, resolve, factoryToken) {
2682
2703
  if (isSet(asyncOptions.useFactory)) {
2683
2704
  return {
2684
2705
  provide: REALTIME_OPTIONS_TOKEN,
2685
- useFactory: async (...args) => resolve(await awaitHostResult(asyncOptions.useFactory(...args)), "useFactory"),
2706
+ useFactory: async (...args) => resolve((await awaitHostResult(asyncOptions.useFactory(...args))).value, "useFactory"),
2686
2707
  inject: [...asyncOptions.inject ?? []]
2687
2708
  };
2688
2709
  }
@@ -2700,7 +2721,7 @@ function buildOptionsProvider(asyncOptions, resolve, factoryToken) {
2700
2721
  );
2701
2722
  }
2702
2723
  return resolve(
2703
- await awaitHostResult(create.call(factory)),
2724
+ (await awaitHostResult(create.call(factory))).value,
2704
2725
  "createRealtimeOptions"
2705
2726
  );
2706
2727
  },
@@ -2737,34 +2758,48 @@ function buildResolver(asyncOptions, instanceId, boundSseEndpoint, logger, modul
2737
2758
  return bindSseEndpoint(resolved, declaredEndpoint, boundSseEndpoint, moduleName);
2738
2759
  };
2739
2760
  }
2761
+ var copied = (value) => Array.isArray(value) ? [...value] : value;
2762
+ function readRegistration(registration) {
2763
+ return guardHostReads("the registration", () => ({
2764
+ transport: registration.transport,
2765
+ sseEndpoint: registration.sseEndpoint,
2766
+ useFactory: registration.useFactory,
2767
+ useClass: registration.useClass,
2768
+ useExisting: registration.useExisting,
2769
+ inject: copied(registration.inject),
2770
+ imports: copied(registration.imports),
2771
+ extraProviders: copied(registration.extraProviders)
2772
+ }));
2773
+ }
2740
2774
  function composeForRootAsync(moduleClass, wiring, logger, asyncOptions) {
2741
2775
  const moduleName = moduleClass.name;
2742
2776
  assertOptionsObject(asyncOptions, moduleName);
2743
- assertOneFactoryPattern(asyncOptions, moduleName);
2744
- assertModeSupported(wiring, asyncOptions.transport, moduleName);
2745
- assertSseEndpoint("sseEndpoint", asyncOptions.sseEndpoint);
2746
- assertSseEndpointApplies(asyncOptions, moduleName);
2747
- assertExtraProviders(asyncOptions.extraProviders);
2777
+ const registration = readRegistration(asyncOptions);
2778
+ assertOneFactoryPattern(registration, moduleName);
2779
+ assertModeSupported(wiring, registration.transport, moduleName);
2780
+ assertSseEndpoint("sseEndpoint", registration.sseEndpoint);
2781
+ assertSseEndpointApplies(registration, moduleName);
2782
+ assertExtraProviders(registration.extraProviders);
2748
2783
  const FACTORY_TOKEN = /* @__PURE__ */ Symbol("REALTIME_OPTIONS_FACTORY");
2749
2784
  const instanceId = randomUUID();
2750
- const boundSseEndpoint = asyncOptions.sseEndpoint ?? DEFAULT_ASYNC_SSE_ENDPOINT;
2751
- const resolve = buildResolver(asyncOptions, instanceId, boundSseEndpoint, logger, moduleName);
2752
- const factoryClassProvider = isSet(asyncOptions.useClass) ? [{ provide: FACTORY_TOKEN, useClass: asyncOptions.useClass }] : [];
2785
+ const boundSseEndpoint = registration.sseEndpoint ?? DEFAULT_ASYNC_SSE_ENDPOINT;
2786
+ const resolve = buildResolver(registration, instanceId, boundSseEndpoint, logger, moduleName);
2787
+ const factoryClassProvider = isSet(registration.useClass) ? [{ provide: FACTORY_TOKEN, useClass: registration.useClass }] : [];
2753
2788
  const { providers: transportProviders, controllers } = wiring.buildAsync({
2754
- mode: asyncOptions.transport,
2789
+ mode: registration.transport,
2755
2790
  sseEndpoint: boundSseEndpoint
2756
2791
  });
2757
2792
  return {
2758
2793
  module: moduleClass,
2759
- imports: asyncOptions.imports ?? [],
2794
+ imports: registration.imports ?? [],
2760
2795
  controllers,
2761
2796
  providers: [
2762
2797
  ...factoryClassProvider,
2763
- buildOptionsProvider(asyncOptions, resolve, FACTORY_TOKEN),
2798
+ buildOptionsProvider(registration, resolve, FACTORY_TOKEN),
2764
2799
  ...buildOptionDerivedProviders(logger, instanceId),
2765
2800
  ...SHARED_SERVICES,
2766
2801
  ...transportProviders,
2767
- ...asyncOptions.extraProviders ?? []
2802
+ ...registration.extraProviders ?? []
2768
2803
  ],
2769
2804
  exports: EXPORTED_TOKENS
2770
2805
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-realtime",
3
- "version": "1.2.23",
3
+ "version": "1.2.24",
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",