kuzzle 2.57.0-beta.2 → 2.57.0-beta.4

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.
@@ -8,6 +8,7 @@ import type ClientConnection from "./clientConnection";
8
8
  export interface AccessLogExtra {
9
9
  method: string;
10
10
  url: string;
11
+ connection?: ClientConnection;
11
12
  }
12
13
  declare class AccessLogger {
13
14
  isActive: boolean;
@@ -51,6 +51,7 @@ exports.AccessLoggerWorker = exports.AccessLogger = void 0;
51
51
  // efficient CPU resources management, and more performances in the end
52
52
  const node_worker_threads_1 = require("node:worker_threads");
53
53
  const node_assert_1 = __importDefault(require("node:assert"));
54
+ const lodash_1 = require("lodash");
54
55
  const moment_1 = __importDefault(require("moment"));
55
56
  const pino = __importStar(require("pino"));
56
57
  const request_1 = require("../../api/request");
@@ -207,10 +208,14 @@ class AccessLoggerWorker {
207
208
  logAccess(connection, request, size, extra = null) {
208
209
  if (this.config.logs.accessLogFormat === "logstash") {
209
210
  // custom kuzzle logs to be exported to logstash
211
+ // The request headers are logged once, under `extra.headers`, where
212
+ // v2.56.0 already logged them (its connections had no headers): the
213
+ // same values under `connection` and `extra.connection` only tripled
214
+ // the size of every entry.
210
215
  this.logger.info({
211
- connection,
216
+ connection: (0, lodash_1.omit)(connection, "headers"),
212
217
  error: request.error,
213
- extra,
218
+ extra: withoutConnectionHeaders(extra),
214
219
  namespace: "kuzzle:accessLogs",
215
220
  nodeId: global.kuzzle.id,
216
221
  request: request.input,
@@ -271,6 +276,12 @@ class AccessLoggerWorker {
271
276
  }
272
277
  }
273
278
  exports.AccessLoggerWorker = AccessLoggerWorker;
279
+ function withoutConnectionHeaders(extra) {
280
+ if (!extra?.connection) {
281
+ return extra;
282
+ }
283
+ return { ...extra, connection: (0, lodash_1.omit)(extra.connection, "headers") };
284
+ }
274
285
  /**
275
286
  * For protocols other than http, we rebuild a pseudo url out of the request's
276
287
  * controller, action and arguments.
@@ -57,6 +57,14 @@ declare class ApiKey extends BaseModel {
57
57
  * @param fingerprint - API key fingerprint
58
58
  */
59
59
  static loadByFingerprint(userId: string, fingerprint: string): Promise<ApiKey>;
60
+ /**
61
+ * Finds a user's API key by comparing the fingerprint stored in each of
62
+ * their keys, for collections where `fingerprint` is not indexed.
63
+ *
64
+ * @param userId - User ID
65
+ * @param fingerprint - API key fingerprint
66
+ */
67
+ static scanByFingerprint(userId: string, fingerprint: string): Promise<ApiKey | null>;
60
68
  /**
61
69
  * Loads a user's API key from a request, identified by its `_id`, its
62
70
  * clear-text `key` or its `fingerprint` (in that order of precedence).
@@ -156,6 +156,14 @@ class ApiKey extends baseModel_1.default {
156
156
  },
157
157
  }, { size: 1 });
158
158
  if (!apiKey) {
159
+ // An install upgraded from a version without the `fingerprint` mapping
160
+ // keeps its old one (existing internal collections are never
161
+ // re-mapped), so the term query above finds nothing there — for any key.
162
+ // Every key stores its fingerprint in `_source`, so scan the user's keys.
163
+ const scanned = await this.scanByFingerprint(userId, fingerprint);
164
+ if (scanned) {
165
+ return scanned;
166
+ }
159
167
  throw kerror.get("services", "storage", "not_found", fingerprint, {
160
168
  message: `ApiKey with fingerprint "${fingerprint}" not found for user "${userId}".`,
161
169
  });
@@ -163,6 +171,23 @@ class ApiKey extends baseModel_1.default {
163
171
  // @ts-expect-error We fetch from the api key collection so this is safe
164
172
  return apiKey;
165
173
  }
174
+ /**
175
+ * Finds a user's API key by comparing the fingerprint stored in each of
176
+ * their keys, for collections where `fingerprint` is not indexed.
177
+ *
178
+ * @param userId - User ID
179
+ * @param fingerprint - API key fingerprint
180
+ */
181
+ static async scanByFingerprint(userId, fingerprint) {
182
+ let foundId = null;
183
+ await this.batchExecute({ term: { userId } }, (hits) => {
184
+ const hit = hits.find((document) => document._source.fingerprint === fingerprint);
185
+ if (hit && !foundId) {
186
+ foundId = hit._id;
187
+ }
188
+ });
189
+ return foundId ? this.load(userId, foundId) : null;
190
+ }
166
191
  /**
167
192
  * Loads a user's API key from a request, identified by its `_id`, its
168
193
  * clear-text `key` or its `fingerprint` (in that order of precedence).
@@ -92,7 +92,7 @@ declare class BaseModel {
92
92
  static truncate({ refresh, }?: {
93
93
  refresh?: boolean | string;
94
94
  }): Promise<void>;
95
- static batchExecute(query: JSONObject, callback: (...args: unknown[]) => unknown): Promise<any>;
95
+ static batchExecute(query: JSONObject, callback: (hits: StorageDocument[]) => unknown): Promise<any>;
96
96
  /**
97
97
  * Must be overriden by children
98
98
  */
@@ -166,7 +166,6 @@ class BaseModel {
166
166
  static truncate({ refresh, } = {}) {
167
167
  return this.deleteByQuery({ match_all: {} }, { refresh });
168
168
  }
169
- // ? This looks not in use anymore ?
170
169
  static batchExecute(query, callback) {
171
170
  return global.kuzzle.internalIndex.mExecute(this.collection, query, callback);
172
171
  }
package/dist/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.57.0-beta.2",
4
+ "version": "2.57.0-beta.4",
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
  "scripts": {
7
7
  "build": "rm -Rf ./dist && tsc && node -r ts-node/register/transpile-only ./bin/copy-binaries.ts",
@@ -32,6 +32,8 @@
32
32
  "lib": "lib"
33
33
  },
34
34
  "dependencies": {
35
+ "@types/bluebird": "3.5.42",
36
+ "@types/passport": "1.0.17",
35
37
  "aedes": "0.51.3",
36
38
  "bluebird": "3.7.2",
37
39
  "cli-color": "2.0.4",
@@ -39,14 +41,14 @@
39
41
  "debug": "4.4.3",
40
42
  "denque": "2.1.0",
41
43
  "didyoumean": "1.2.2",
42
- "dumpme": "2.1.0-dev.1",
44
+ "dumpme": "2.1.0",
43
45
  "eventemitter3": "5.0.1",
44
46
  "inquirer": "13.1.0",
45
47
  "ioredis": "5.8.2",
46
48
  "json-stable-stringify": "1.3.0",
47
49
  "json2yaml": "1.1.0",
48
50
  "jsonwebtoken": "9.0.3",
49
- "koncorde": "4.8.0-beta.2",
51
+ "koncorde": "4.8.0",
50
52
  "kuzzle-logger": "1.4.0",
51
53
  "kuzzle-plugin-auth-passport-local": "6.4.1",
52
54
  "kuzzle-sdk": ">=7.17.1 <8.0.0",
@@ -83,10 +85,8 @@
83
85
  "devDependencies": {
84
86
  "@cucumber/cucumber": "12.5.0",
85
87
  "@types/async": "^3.2.24",
86
- "@types/bluebird": "3.5.42",
87
88
  "@types/cookie": "1.0.0",
88
89
  "@types/lodash": "4.17.21",
89
- "@types/passport": "1.0.17",
90
90
  "@types/validator": "^13.15.10",
91
91
  "@types/yargs": "17.0.35",
92
92
  "@vitest/coverage-v8": "4.0.16",
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.57.0-beta.2",
4
+ "version": "2.57.0-beta.4",
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
  "scripts": {
7
7
  "build": "rm -Rf ./dist && tsc && node -r ts-node/register/transpile-only ./bin/copy-binaries.ts",
@@ -32,6 +32,8 @@
32
32
  "lib": "lib"
33
33
  },
34
34
  "dependencies": {
35
+ "@types/bluebird": "3.5.42",
36
+ "@types/passport": "1.0.17",
35
37
  "aedes": "0.51.3",
36
38
  "bluebird": "3.7.2",
37
39
  "cli-color": "2.0.4",
@@ -39,14 +41,14 @@
39
41
  "debug": "4.4.3",
40
42
  "denque": "2.1.0",
41
43
  "didyoumean": "1.2.2",
42
- "dumpme": "2.1.0-dev.1",
44
+ "dumpme": "2.1.0",
43
45
  "eventemitter3": "5.0.1",
44
46
  "inquirer": "13.1.0",
45
47
  "ioredis": "5.8.2",
46
48
  "json-stable-stringify": "1.3.0",
47
49
  "json2yaml": "1.1.0",
48
50
  "jsonwebtoken": "9.0.3",
49
- "koncorde": "4.8.0-beta.2",
51
+ "koncorde": "4.8.0",
50
52
  "kuzzle-logger": "1.4.0",
51
53
  "kuzzle-plugin-auth-passport-local": "6.4.1",
52
54
  "kuzzle-sdk": ">=7.17.1 <8.0.0",
@@ -83,10 +85,8 @@
83
85
  "devDependencies": {
84
86
  "@cucumber/cucumber": "12.5.0",
85
87
  "@types/async": "^3.2.24",
86
- "@types/bluebird": "3.5.42",
87
88
  "@types/cookie": "1.0.0",
88
89
  "@types/lodash": "4.17.21",
89
- "@types/passport": "1.0.17",
90
90
  "@types/validator": "^13.15.10",
91
91
  "@types/yargs": "17.0.35",
92
92
  "@vitest/coverage-v8": "4.0.16",