@bymax-one/nest-realtime 1.2.21 → 1.2.22

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,21 @@ Versioning is **not** strict [SemVer](https://semver.org/spec/v2.0.0.html) while
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.22] - 2026-11-20
11
+
12
+ ### Fixed
13
+
14
+ - **The tenant of an authentication result is read once.** The routing tenant was read from the result more than once, so a getter that answers differently the second time could route on a value that was not the one tested. It is read once, the rest of the result is copied beside it, and a `tenantResolver` is given that copy, so a resolver that reads `auth.tenantId` reads the same value.
15
+ - **A field named `err` can no longer stand for the error of a log line.** `logEvent` wrote a caller's `err` field when no error was passed, and `err` is where a logger's serializer reads an error from. Only the error argument writes `err` now. The `logEvent` documentation also says that a field whose read throws, such as a getter, loses the line instead of throwing.
16
+
17
+ #### Apply to a derived backend
18
+
19
+ A `tenantResolver` now receives a plain copy of the authentication result, with its own enumerable properties only, and not the authenticator's original object. A resolver that relies on a prototype method of that object, on its identity, or on a property that is not enumerable must read what it needs in the authenticator and carry it in the result's `metadata`. The result the library hands to the rest of the code was already such a copy.
20
+
21
+ ### Documentation
22
+
23
+ - **The README says what a getter that throws on the authenticator's result does.** The error is the host's own and is not wrapped: the handshake fails, it is logged under `err` and counted as `reason="error"`.
24
+
10
25
  ## [1.2.21] - 2026-11-20
11
26
 
12
27
  ### Fixed
@@ -1237,7 +1252,8 @@ First published release.
1237
1252
  rather than by the manual sweep that raised the NestJS floors — that sweep
1238
1253
  asked about NestJS and never put the same question to the other ten peers.
1239
1254
 
1240
- [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.21...HEAD
1255
+ [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.22...HEAD
1256
+ [1.2.22]: https://github.com/bymaxone/nest-realtime/compare/v1.2.21...v1.2.22
1241
1257
  [1.2.21]: https://github.com/bymaxone/nest-realtime/compare/v1.2.20...v1.2.21
1242
1258
  [1.2.20]: https://github.com/bymaxone/nest-realtime/compare/v1.2.19...v1.2.20
1243
1259
  [1.2.19]: https://github.com/bymaxone/nest-realtime/compare/v1.2.18...v1.2.19
package/README.md CHANGED
@@ -141,7 +141,7 @@ pnpm add socket.io-client
141
141
 
142
142
  ### 2. Implement the Authenticator Interface
143
143
 
144
- This is the only interface you are required to provide. The library calls it once per connection and never inspects the credential itself.
144
+ This is the only interface you are required to provide. The library calls it once per connection and never inspects the credential itself. What it returns is your code's own object: a getter on it that throws raises that error as it is, the handshake fails, the error is logged under `err` and counted as `reason="error"`, and the client is sent nothing of it.
145
145
 
146
146
  ```typescript
147
147
  import type {
@@ -569,7 +569,10 @@ var REALTIME_LOG_EVENTS = [
569
569
  ];
570
570
  function logEvent(logger, level, event, message, fields = {}, error) {
571
571
  try {
572
- logger[level]({ ...fields, event, message, ...error === void 0 ? {} : { err: error } });
572
+ const line = { ...fields, event, message };
573
+ delete line["err"];
574
+ if (error !== void 0) line["err"] = error;
575
+ logger[level](line);
573
576
  } catch {
574
577
  }
575
578
  }
@@ -857,12 +860,12 @@ function isBlank(value) {
857
860
  return typeof value !== "string" || value.trim().length === 0;
858
861
  }
859
862
  function resolveAuthTenant(options, auth) {
860
- const resolved = options.tenantResolver?.(auth) ?? auth.tenantId;
861
- if (resolved === void 0 || resolved === null) {
862
- const { tenantId: _dropped, ...withoutTenant } = auth;
863
- return withoutTenant;
864
- }
865
- return { ...auth, tenantId: resolved };
863
+ const { tenantId: own, ...rest } = auth;
864
+ const resolved = options.tenantResolver?.(
865
+ own === void 0 || own === null ? rest : { ...rest, tenantId: own }
866
+ ) ?? own;
867
+ if (resolved === void 0 || resolved === null) return rest;
868
+ return { ...rest, tenantId: resolved };
866
869
  }
867
870
  function assertIdentityIsNotBlank(auth) {
868
871
  if (isBlank(auth.userId)) {
@@ -2305,7 +2305,9 @@ type LogFields = Readonly<Record<string, string | number | boolean>>;
2305
2305
  * @param level - `warn` for what degrades service, `error` for what fails an operation.
2306
2306
  * @param event - The stable code of the condition.
2307
2307
  * @param message - Human text; the library's own wording, with no host-supplied value in it.
2308
- * @param fields - Closed or numeric fields.
2308
+ * @param fields - Closed or numeric fields, built by the library. A key named `event`, `message` or `err` is replaced by the
2309
+ * library's own value or dropped, and a field whose read throws, such as a getter, loses the line like any other
2310
+ * throw while writing.
2309
2311
  * @param error - What was thrown, when the event reports a failure. It goes under `err` as the value itself, never
2310
2312
  * as text in `message`, so the logger's serializer and redaction apply to it: an error raised by host code can
2311
2313
  * carry a user or a tenant, and the library's own line must not.
@@ -2305,7 +2305,9 @@ type LogFields = Readonly<Record<string, string | number | boolean>>;
2305
2305
  * @param level - `warn` for what degrades service, `error` for what fails an operation.
2306
2306
  * @param event - The stable code of the condition.
2307
2307
  * @param message - Human text; the library's own wording, with no host-supplied value in it.
2308
- * @param fields - Closed or numeric fields.
2308
+ * @param fields - Closed or numeric fields, built by the library. A key named `event`, `message` or `err` is replaced by the
2309
+ * library's own value or dropped, and a field whose read throws, such as a getter, loses the line like any other
2310
+ * throw while writing.
2309
2311
  * @param error - What was thrown, when the event reports a failure. It goes under `err` as the value itself, never
2310
2312
  * as text in `message`, so the logger's serializer and redaction apply to it: an error raised by host code can
2311
2313
  * carry a user or a tenant, and the library's own line must not.
@@ -567,7 +567,10 @@ var REALTIME_LOG_EVENTS = [
567
567
  ];
568
568
  function logEvent(logger, level, event, message, fields = {}, error) {
569
569
  try {
570
- logger[level]({ ...fields, event, message, ...error === void 0 ? {} : { err: error } });
570
+ const line = { ...fields, event, message };
571
+ delete line["err"];
572
+ if (error !== void 0) line["err"] = error;
573
+ logger[level](line);
571
574
  } catch {
572
575
  }
573
576
  }
@@ -855,12 +858,12 @@ function isBlank(value) {
855
858
  return typeof value !== "string" || value.trim().length === 0;
856
859
  }
857
860
  function resolveAuthTenant(options, auth) {
858
- const resolved = options.tenantResolver?.(auth) ?? auth.tenantId;
859
- if (resolved === void 0 || resolved === null) {
860
- const { tenantId: _dropped, ...withoutTenant } = auth;
861
- return withoutTenant;
862
- }
863
- return { ...auth, tenantId: resolved };
861
+ const { tenantId: own, ...rest } = auth;
862
+ const resolved = options.tenantResolver?.(
863
+ own === void 0 || own === null ? rest : { ...rest, tenantId: own }
864
+ ) ?? own;
865
+ if (resolved === void 0 || resolved === null) return rest;
866
+ return { ...rest, tenantId: resolved };
864
867
  }
865
868
  function assertIdentityIsNotBlank(auth) {
866
869
  if (isBlank(auth.userId)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-realtime",
3
- "version": "1.2.21",
3
+ "version": "1.2.22",
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",