kuzzle 2.43.2 → 2.44.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.
@@ -14,6 +14,7 @@ export declare class TokenManager {
14
14
  */
15
15
  private tokensByConnection;
16
16
  private timer;
17
+ private readonly logger;
17
18
  constructor();
18
19
  init(): Promise<void>;
19
20
  runTimer(): void;
@@ -65,6 +65,7 @@ class TokenManager {
65
65
  */
66
66
  this.tokensByConnection = new Map();
67
67
  this.timer = null;
68
+ this.logger = global.kuzzle.log.child("auth:tokenManager");
68
69
  /*
69
70
  * Tokens are sorted by their expiration date
70
71
  *
@@ -95,7 +96,7 @@ class TokenManager {
95
96
  const anonymous = await global.kuzzle.ask("core:security:user:anonymous:get");
96
97
  this.anonymousUserId = anonymous._id;
97
98
  global.kuzzle.on("connection:remove", (connection) => {
98
- this.removeConnection(connection.id).catch((err) => global.kuzzle.log.info(err));
99
+ this.removeConnection(connection.id).catch((err) => this.logger.info(err));
99
100
  });
100
101
  }
101
102
  runTimer() {
@@ -121,6 +122,7 @@ class TokenManager {
121
122
  const currentToken = this.tokensByConnection.get(connectionId);
122
123
  if (currentToken) {
123
124
  if (currentToken._id === token._id) {
125
+ this.logger.trace(`connection "${connectionId}" from user "${token.userId}" already linked to token`);
124
126
  return; // Connection and Token already linked
125
127
  }
126
128
  this.removeConnectionLinkedToToken(connectionId, currentToken);
@@ -128,11 +130,13 @@ class TokenManager {
128
130
  const pos = this.tokens.search({ idx });
129
131
  if (pos === -1) {
130
132
  this.add(token, new Set([connectionId]));
133
+ this.logger.trace(`connection "${connectionId}" from user "${token.userId}" linked to a new token`);
131
134
  }
132
135
  else {
133
136
  const managedToken = this.tokens.array[pos];
134
137
  managedToken.connectionIds.add(connectionId);
135
138
  this.tokensByConnection.set(connectionId, managedToken);
139
+ this.logger.trace(`connection "${connectionId}" from user "${token.userId}" linked to existing token`);
136
140
  }
137
141
  }
138
142
  /**
@@ -142,12 +146,18 @@ class TokenManager {
142
146
  * @param connectionId
143
147
  */
144
148
  unlink(token, connectionId) {
145
- if (!token || token.userId === this.anonymousUserId) {
149
+ if (!token) {
150
+ this.logger.warn(`tried to unlink connection "${connectionId}" with no token`);
151
+ return;
152
+ }
153
+ if (token.userId === this.anonymousUserId) {
154
+ this.logger.warn(`tried to unlink connection "${connectionId}" from anonymous user`);
146
155
  return;
147
156
  }
148
157
  const idx = ManagedToken.indexFor(token);
149
158
  const pos = this.tokens.search({ idx });
150
159
  if (pos === -1) {
160
+ this.logger.warn(`tried to unlink connection "${connectionId}" with no token associated`);
151
161
  return;
152
162
  }
153
163
  this.removeConnectionLinkedToToken(connectionId, this.tokens.array[pos]);
@@ -155,17 +165,19 @@ class TokenManager {
155
165
  if (currentToken && currentToken._id === token._id) {
156
166
  this.tokensByConnection.delete(connectionId);
157
167
  }
168
+ this.logger.trace(`connection "${connectionId}" from user "${token.userId}" unlinked from token`);
158
169
  }
159
170
  /**
160
171
  * Remove token associated with a connection.
161
172
  */
162
173
  async removeConnection(connectionId) {
163
174
  const managedToken = this.tokensByConnection.get(connectionId);
164
- // Anonymous connection does not have associated token
165
175
  if (!managedToken) {
176
+ this.logger.warn(`tried to remove connection "${connectionId}" with no token associated`);
166
177
  return;
167
178
  }
168
- await this.expire(managedToken);
179
+ this.unlink(managedToken, connectionId);
180
+ this.logger.trace(`connection "${connectionId}" from user "${managedToken.userId}" removed and unlinked from token`);
169
181
  }
170
182
  /**
171
183
  * Called when a token expires before its time (e.g. following a
@@ -177,6 +189,7 @@ class TokenManager {
177
189
  */
178
190
  async expire(token) {
179
191
  if (token.userId === this.anonymousUserId) {
192
+ this.logger.warn(`tried to expire an anonymous token`);
180
193
  return;
181
194
  }
182
195
  const idx = ManagedToken.indexFor(token);
@@ -188,6 +201,7 @@ class TokenManager {
188
201
  await global.kuzzle.ask("core:realtime:connection:remove", connectionId);
189
202
  }
190
203
  this.deleteByIndex(searchResult);
204
+ this.logger.trace(`token from user "${token.userId}" expired and removed from list`);
191
205
  }
192
206
  }
193
207
  /**
@@ -211,6 +225,7 @@ class TokenManager {
211
225
  this.add(newToken, connectionIds);
212
226
  // Delete old token
213
227
  this.deleteByIndex(pos);
228
+ this.logger.trace(`token from user ${oldToken.userId} refreshed`);
214
229
  }
215
230
  }
216
231
  async checkTokensValidity() {
@@ -267,6 +282,7 @@ class TokenManager {
267
282
  if (this.tokens.array[0].idx === orderedToken.idx) {
268
283
  this.runTimer();
269
284
  }
285
+ this.logger.trace(`token from user ${token.userId} linked to connections ${Array.from(connectionIds)}`);
270
286
  }
271
287
  removeConnectionLinkedToToken(connectionId, managedToken) {
272
288
  managedToken.connectionIds.delete(connectionId);
@@ -31,6 +31,7 @@ class Logger extends kuzzle_logger_1.KuzzleLogger {
31
31
  const deprecatedConfig = kuzzleConfig.plugins["kuzzle-plugin-logger"];
32
32
  const getMergingObject = () => {
33
33
  const mergingObject = {};
34
+ mergingObject.namespace = "kuzzle";
34
35
  mergingObject.failsafeMode = Boolean(kuzzleConfig.plugins.common.failsafeMode);
35
36
  if (global.kuzzle.id) {
36
37
  mergingObject.nodeId = global.kuzzle.id;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.43.2",
4
+ "version": "2.44.0",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "bin": "bin/start-kuzzle-server",
7
7
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  "build": "tsc",
10
10
  "clean": "touch index.ts && npm run build | grep TSFILE | cut -d' ' -f 2 | xargs rm",
11
11
  "cucumber": "cucumber.js --fail-fast",
12
- "dev": "tsx docker/scripts/start-kuzzle-dev.ts",
12
+ "dev": "tsx watch docker/scripts/start-kuzzle-dev.ts",
13
13
  "doc-error-codes": "node -r ts-node/register doc/build-error-codes",
14
14
  "prepublishOnly": "npm run build",
15
15
  "prettier": "prettier ./lib ./test ./features ./plugins/available/functional-test-plugin --write",
@@ -38,14 +38,14 @@
38
38
  "didyoumean": "1.2.2",
39
39
  "dumpme": "2.0.0",
40
40
  "eventemitter3": "5.0.1",
41
- "inquirer": "12.6.3",
41
+ "inquirer": "12.8.2",
42
42
  "ioredis": "5.6.1",
43
43
  "js-yaml": "4.1.0",
44
44
  "json-stable-stringify": "1.3.0",
45
45
  "json2yaml": "1.1.0",
46
46
  "jsonwebtoken": "9.0.2",
47
47
  "koncorde": "4.6.0",
48
- "kuzzle-logger": "1.2.0",
48
+ "kuzzle-logger": "1.3.0",
49
49
  "kuzzle-plugin-auth-passport-local": "6.4.1",
50
50
  "kuzzle-sdk": ">=7.15.0",
51
51
  "kuzzle-vault": "2.1.0",
@@ -75,7 +75,7 @@
75
75
  "winston-syslog": "2.7.1",
76
76
  "winston-transport": "4.9.0",
77
77
  "yargs": "18.0.0",
78
- "zeromq": "6.4.2"
78
+ "zeromq": "6.5.0"
79
79
  },
80
80
  "repository": {
81
81
  "type": "git",
@@ -84,22 +84,22 @@
84
84
  "devDependencies": {
85
85
  "@commitlint/cli": "19.8.1",
86
86
  "@commitlint/config-conventional": "19.8.1",
87
- "@jest/globals": "29.7.0",
87
+ "@jest/globals": "30.0.5",
88
88
  "@types/bluebird": "3.5.42",
89
89
  "@types/cookie": "1.0.0",
90
- "@types/jest": "29.5.14",
90
+ "@types/jest": "30.0.0",
91
91
  "@types/js-yaml": "4.0.9",
92
- "@types/lodash": "4.17.17",
92
+ "@types/lodash": "4.17.20",
93
93
  "@types/mocha": "10.0.10",
94
94
  "async": "3.2.6",
95
95
  "chokidar": "4.0.3",
96
96
  "cucumber": "6.0.7",
97
97
  "cz-conventional-changelog": "3.3.0",
98
- "eslint-plugin-kuzzle": "0.0.13",
99
- "jest": "29.7.0",
100
- "mocha": "11.5.0",
98
+ "eslint-plugin-kuzzle": "0.0.14",
99
+ "jest": "30.0.5",
100
+ "mocha": "11.7.1",
101
101
  "mock-require": "3.0.3",
102
- "mqtt": "5.13.1",
102
+ "mqtt": "5.13.3",
103
103
  "nyc": "17.1.0",
104
104
  "request": "2.88.2",
105
105
  "request-promise": "4.2.6",
@@ -107,18 +107,18 @@
107
107
  "semantic-release-config-kuzzle": "1.1.2",
108
108
  "should": "13.2.3",
109
109
  "should-sinon": "0.0.6",
110
- "sinon": "20.0.0",
110
+ "sinon": "21.0.0",
111
111
  "strip-json-comments": "https://github.com/sindresorhus/strip-json-comments/archive/refs/tags/v3.1.1.tar.gz",
112
- "ts-jest": "29.3.4",
112
+ "ts-jest": "29.4.0",
113
113
  "ts-node": "10.9.2",
114
- "tsx": "^4.19.4",
114
+ "tsx": "4.20.3",
115
115
  "typescript": "5.3.2",
116
116
  "yaml": "2.8.0"
117
117
  },
118
118
  "engines": {
119
119
  "node": ">=18.0.0 <23.0.0"
120
120
  },
121
- "packageManager": "npm@11.4.1",
121
+ "packageManager": "npm@11.4.2",
122
122
  "engineStrict": true,
123
123
  "license": "Apache-2.0",
124
124
  "files": [