kuzzle 2.16.2 → 2.16.6

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.
@@ -1,19 +1,17 @@
1
1
  import { JSONObject } from 'kuzzle-sdk';
2
- import '../../../lib/types/Global';
3
2
  import { Deprecation } from '../../types';
4
3
  import { KuzzleError } from '../../kerror/errors/kuzzleError';
5
- import { KuzzleRequest } from './kuzzleRequest';
6
4
  export declare class Headers {
7
5
  headers: JSONObject;
8
6
  private namesMap;
9
- proxy: any;
7
+ private proxy;
10
8
  constructor();
11
9
  /**
12
10
  * Gets a header value
13
11
  *
14
12
  * @param name Header name. Could be a string (case-insensitive) or a symbol
15
13
  */
16
- getHeader(name: any): string;
14
+ getHeader(name: any): string | void;
17
15
  removeHeader(name: string): boolean;
18
16
  setHeader(name: string, value: string): boolean;
19
17
  }
@@ -21,22 +19,20 @@ export declare class Headers {
21
19
  * Kuzzle normalized API response
22
20
  */
23
21
  export declare class RequestResponse {
24
- private request;
25
- private _headers;
26
22
  /**
27
23
  * If sets to true, "result" content will not be wrapped in a Kuzzle response
28
24
  */
29
25
  raw: boolean;
30
- constructor(request: KuzzleRequest);
26
+ constructor(request: any);
31
27
  /**
32
28
  * Get the parent request deprecations
33
29
  */
34
- get deprecations(): Array<Deprecation>;
30
+ get deprecations(): Array<Deprecation> | void;
35
31
  /**
36
32
  * Set the parent request deprecations
37
33
  * @param {Object[]} deprecations
38
34
  */
39
- set deprecations(deprecations: Array<Deprecation>);
35
+ set deprecations(deprecations: Array<Deprecation> | void);
40
36
  /**
41
37
  * Get the parent request status
42
38
  * @returns {number}
@@ -103,16 +99,16 @@ export declare class RequestResponse {
103
99
  /**
104
100
  * Gets a header value (case-insensitive)
105
101
  */
106
- getHeader(name: string): string;
102
+ getHeader(name: string): string | null;
107
103
  /**
108
104
  * Deletes a header (case-insensitive)
109
105
  */
110
- removeHeader(name: string): boolean;
106
+ removeHeader(name: string): any;
111
107
  /**
112
108
  * Sets a new array. Behaves the same as Node.js' HTTP response.setHeader
113
109
  * method (@see https://nodejs.org/api/http.html#http_response_setheader_name_value)
114
110
  */
115
- setHeader(name: string, value: string): boolean;
111
+ setHeader(name: string, value: string): any;
116
112
  /**
117
113
  * Adds new multiple headers.
118
114
  */
@@ -40,8 +40,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.RequestResponse = exports.Headers = void 0;
43
- require("../../../lib/types/Global");
44
43
  const assert = __importStar(require("../../util/assertType"));
44
+ // private properties
45
+ // \u200b is a zero width space, used to masquerade console.log output
46
+ const _request = 'request\u200b';
47
+ const _headers = 'headers\u200b';
45
48
  class Headers {
46
49
  constructor() {
47
50
  this.namesMap = new Map();
@@ -51,10 +54,7 @@ class Headers {
51
54
  get: (target, name) => this.getHeader(name),
52
55
  set: (target, name, value) => this.setHeader(name, value),
53
56
  });
54
- // eslint-disable-next-line dot-notation
55
- if (global['_kuzzle'] && global.kuzzle) {
56
- this.setHeader('X-Kuzzle-Node', global.kuzzle.id);
57
- }
57
+ this.setHeader('X-Kuzzle-Node', global.kuzzle.id);
58
58
  }
59
59
  /**
60
60
  * Gets a header value
@@ -144,104 +144,98 @@ exports.Headers = Headers;
144
144
  class RequestResponse {
145
145
  constructor(request) {
146
146
  this.raw = false;
147
- // Make a private property otherwise the tests are ending in recursive loop
148
- Reflect.defineProperty(this, 'request', {
149
- value: request,
150
- });
151
- this._headers = new Headers();
147
+ this[_request] = request;
148
+ this[_headers] = new Headers();
149
+ Object.seal(this);
152
150
  }
153
151
  /**
154
152
  * Get the parent request deprecations
155
153
  */
156
154
  get deprecations() {
157
- return this.request.deprecations;
155
+ return this[_request].deprecations;
158
156
  }
159
157
  /**
160
158
  * Set the parent request deprecations
161
159
  * @param {Object[]} deprecations
162
160
  */
163
161
  set deprecations(deprecations) {
164
- this.request.deprecations = deprecations;
162
+ this[_request].deprecations = deprecations;
165
163
  }
166
164
  /**
167
165
  * Get the parent request status
168
166
  * @returns {number}
169
167
  */
170
168
  get status() {
171
- return this.request.status;
169
+ return this[_request].status;
172
170
  }
173
171
  set status(s) {
174
- this.request.status = s;
172
+ this[_request].status = s;
175
173
  }
176
174
  /**
177
175
  * Request error
178
176
  */
179
177
  get error() {
180
- return this.request.error;
178
+ return this[_request].error;
181
179
  }
182
180
  set error(e) {
183
- this.request.setError(e);
181
+ this[_request].setError(e);
184
182
  }
185
183
  /**
186
184
  * Request external ID
187
185
  */
188
186
  get requestId() {
189
- return this.request.id;
187
+ return this[_request].id;
190
188
  }
191
189
  /**
192
190
  * API controller name
193
191
  */
194
192
  get controller() {
195
- return this.request.input.controller;
193
+ return this[_request].input.controller;
196
194
  }
197
195
  /**
198
196
  * API action name
199
197
  */
200
198
  get action() {
201
- return this.request.input.action;
199
+ return this[_request].input.action;
202
200
  }
203
201
  /**
204
202
  * Collection name
205
203
  */
206
204
  get collection() {
207
- return this.request.input.resource.collection;
205
+ return this[_request].input.resource.collection;
208
206
  }
209
207
  /**
210
208
  * Index name
211
209
  */
212
210
  get index() {
213
- return this.request.input.resource.index;
211
+ return this[_request].input.resource.index;
214
212
  }
215
213
  /**
216
214
  * Volatile object
217
215
  */
218
216
  get volatile() {
219
- return this.request.input.volatile;
217
+ return this[_request].input.volatile;
220
218
  }
221
219
  /**
222
220
  * Response headers
223
221
  */
224
222
  get headers() {
225
- return this._headers.proxy;
223
+ return this[_headers].proxy;
226
224
  }
227
225
  /**
228
226
  * Request result
229
227
  */
230
228
  get result() {
231
- return this.request.result;
229
+ return this[_request].result;
232
230
  }
233
231
  set result(r) {
234
- this.request.setResult(r);
232
+ this[_request].setResult(r);
235
233
  }
236
234
  /**
237
235
  * Node identifier
238
236
  */
239
237
  get node() {
240
- // eslint-disable-next-line dot-notation
241
- if (global['_kuzzle'] && global.kuzzle) {
242
- return global.kuzzle.id;
243
- }
244
- return null;
238
+ return global.kuzzle.id;
245
239
  }
246
240
  /**
247
241
  * Configure the response
@@ -271,20 +265,20 @@ class RequestResponse {
271
265
  * Gets a header value (case-insensitive)
272
266
  */
273
267
  getHeader(name) {
274
- return this._headers.getHeader(name);
268
+ return this[_headers].getHeader(name);
275
269
  }
276
270
  /**
277
271
  * Deletes a header (case-insensitive)
278
272
  */
279
273
  removeHeader(name) {
280
- return this._headers.removeHeader(name);
274
+ return this[_headers].removeHeader(name);
281
275
  }
282
276
  /**
283
277
  * Sets a new array. Behaves the same as Node.js' HTTP response.setHeader
284
278
  * method (@see https://nodejs.org/api/http.html#http_response_setheader_name_value)
285
279
  */
286
280
  setHeader(name, value) {
287
- return this._headers.setHeader(name, value);
281
+ return this[_headers].setHeader(name, value);
288
282
  }
289
283
  /**
290
284
  * Adds new multiple headers.
@@ -307,7 +301,7 @@ class RequestResponse {
307
301
  if (this.raw === true) {
308
302
  return {
309
303
  content: this.result,
310
- headers: this._headers.headers,
304
+ headers: this.headers,
311
305
  raw: true,
312
306
  requestId: this.requestId,
313
307
  status: this.status,
@@ -327,7 +321,7 @@ class RequestResponse {
327
321
  status: this.status,
328
322
  volatile: this.volatile,
329
323
  },
330
- headers: this._headers.headers,
324
+ headers: this.headers,
331
325
  raw: false,
332
326
  requestId: this.requestId,
333
327
  status: this.status,
@@ -141,9 +141,6 @@ class BackendController extends index_1.ApplicationManager {
141
141
  this._add(controller.name, controller.definition);
142
142
  }
143
143
  _add(name, definition) {
144
- // Check definition here to throw error early
145
- // with the corresponding line number
146
- this._application.PluginObject.checkControllerDefinition(name, definition, { application: true });
147
144
  if (this._application._controllers[name]) {
148
145
  throw assertionError.get('invalid_controller_definition', name, 'A controller with this name already exists');
149
146
  }
@@ -264,7 +264,7 @@ class Plugin {
264
264
  return PLUGIN_NAME_REGEX.test(name);
265
265
  }
266
266
 
267
- static checkControllerDefinition (name, definition, { application=false } = {}) {
267
+ static async checkControllerDefinition (name, definition, { application=false } = {}) {
268
268
  if (typeof name !== 'string') {
269
269
  throw assertionError.get(
270
270
  'invalid_controller_definition',
@@ -344,7 +344,7 @@ class Plugin {
344
344
  }
345
345
 
346
346
  if (route.openapi) {
347
- checkOpenAPISpecification(name, action, route);
347
+ await checkOpenAPISpecification(name, action, route);
348
348
  }
349
349
  }
350
350
  }
@@ -365,20 +365,24 @@ function checkHttpRouteProperties (route, action, name, application) {
365
365
  }
366
366
  }
367
367
 
368
- function checkOpenAPISpecification (controller, action, route) {
368
+ async function checkOpenAPISpecification (controller, action, route) {
369
369
  if (! isPlainObject(route.openapi)) {
370
370
  throw assertionError.get(
371
371
  'invalid_controller_definition',
372
372
  controller,
373
- 'The "openapi" property must be an object');
373
+ 'The "openapi" property of the route definition must be an object');
374
374
  }
375
375
 
376
+ const routePath = route.path.charAt(0) === '/'
377
+ ? route.path
378
+ : `/_/${route.path}`;
379
+
376
380
  // Set :param notation to {param}
377
- const formattedPath = route.path.replace(/\/:([^/]*)/g,'/{$1}');
381
+ const formattedPath = routePath.replace(/\/:([^/]*)/g,'/{$1}');
378
382
 
379
- const { error, warning } = enforcer({
383
+ const { error, warning } = await enforcer({
380
384
  /* eslint-disable sort-keys */
381
- openapi: '3.0.1',
385
+ openapi: '3.0.0',
382
386
  info: {
383
387
  title: 'Kuzzle API',
384
388
  version: require('../../../package').version
@@ -394,8 +398,14 @@ function checkOpenAPISpecification (controller, action, route) {
394
398
  if (warning) {
395
399
  global.kuzzle.log.warn(`Warning for OpenAPI specification in "${controller}:${action}", ${route.openapi} : ${warning}`);
396
400
  }
401
+
397
402
  if (error) {
398
- throw controllerError.get('invalid_openapi_schema', controller, action, route.openapi, error);
403
+ throw controllerError.get(
404
+ 'invalid_openapi_schema',
405
+ controller,
406
+ action,
407
+ route.openapi,
408
+ error);
399
409
  }
400
410
  }
401
411
 
@@ -265,9 +265,7 @@ class PluginsManager {
265
265
 
266
266
  debug('[%s] plugin started', plugin.name);
267
267
 
268
- if (! plugin.application) {
269
- this.loadedPlugins.push(plugin.name);
270
- }
268
+ this.loadedPlugins.push(plugin.name);
271
269
 
272
270
  return null;
273
271
  });
@@ -680,7 +678,7 @@ class PluginsManager {
680
678
  'Native controllers cannot be overriden');
681
679
  }
682
680
 
683
- Plugin.checkControllerDefinition(controller, definition);
681
+ await Plugin.checkControllerDefinition(controller, definition);
684
682
 
685
683
  for (const [action, actionDefinition ] of Object.entries(definition.actions)) {
686
684
  let apiController = this.controllers.get(controller);
@@ -54,25 +54,21 @@ const realtime_1 = __importDefault(require("../core/realtime"));
54
54
  const cluster_1 = __importDefault(require("../cluster"));
55
55
  const package_json_1 = require("../../package.json");
56
56
  const BACKEND_IMPORT_KEY = 'backend:init:import';
57
- Reflect.defineProperty(global, '_kuzzle', {
58
- value: null,
59
- writable: true,
60
- });
61
- /* eslint-disable dot-notation */
57
+ let _kuzzle = null;
62
58
  Reflect.defineProperty(global, 'kuzzle', {
63
59
  configurable: true,
64
60
  enumerable: false,
65
61
  get() {
66
- if (global['_kuzzle'] === null) {
62
+ if (_kuzzle === null) {
67
63
  throw new Error('Kuzzle instance not found. Did you try to use a live-only feature before starting your application?');
68
64
  }
69
- return global['_kuzzle'];
65
+ return _kuzzle;
70
66
  },
71
67
  set(value) {
72
- if (global['_kuzzle'] !== null) {
68
+ if (_kuzzle !== null) {
73
69
  throw new Error('Cannot build a Kuzzle instance: another one already exists');
74
70
  }
75
- global['_kuzzle'] = value;
71
+ _kuzzle = value;
76
72
  },
77
73
  });
78
74
  class Kuzzle extends kuzzleEventEmitter_1.default {
@@ -237,6 +237,12 @@ class ElasticSearch extends Service {
237
237
  let size = 0;
238
238
 
239
239
  for (const [indice, indiceInfo] of Object.entries(body.indices)) {
240
+ // Ignore non-Kuzzle indices
241
+ if ( indice[INDEX_PREFIX_POSITION_IN_INDICE] !== PRIVATE_PREFIX
242
+ && indice[INDEX_PREFIX_POSITION_IN_INDICE] !== PUBLIC_PREFIX ) {
243
+ continue;
244
+ }
245
+
240
246
  const alias = await this._getAliasFromIndice(indice);
241
247
  const indexName = this._extractIndex(alias);
242
248
  const collectionName = this._extractCollection(alias);
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle",
3
- "version": "2.16.2",
3
+ "version": "2.16.6",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -730,9 +730,9 @@
730
730
  "dev": true
731
731
  },
732
732
  "@types/lodash": {
733
- "version": "4.14.177",
734
- "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.177.tgz",
735
- "integrity": "sha512-0fDwydE2clKe9MNfvXHBHF9WEahRuj+msTuQqOmAApNORFvhMYZKNGGJdCzuhheVjMps/ti0Ak/iJPACMaevvw==",
733
+ "version": "4.14.178",
734
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.178.tgz",
735
+ "integrity": "sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==",
736
736
  "dev": true
737
737
  },
738
738
  "@types/long": {
@@ -883,9 +883,9 @@
883
883
  "dev": true
884
884
  },
885
885
  "aedes": {
886
- "version": "0.46.1",
887
- "resolved": "https://registry.npmjs.org/aedes/-/aedes-0.46.1.tgz",
888
- "integrity": "sha512-ZTSpKmtUwzaIX+JzigT8Y1vinh64MAEIUb88bAUW+Xwubtuivmj42H3tOgXNSHdpaPebAq83ZHo0AxihXb2HBw==",
886
+ "version": "0.46.2",
887
+ "resolved": "https://registry.npmjs.org/aedes/-/aedes-0.46.2.tgz",
888
+ "integrity": "sha512-bzDY5ZC1zEduKHBuAZW8Ccr46+42TB9lynP+Fw4Bl41kQYxUZBA8hQwp4Eba3gUM2EZHgj22Q83ib2UuvAWnkw==",
889
889
  "requires": {
890
890
  "aedes-packet": "^2.3.1",
891
891
  "aedes-persistence": "^8.1.3",
@@ -904,9 +904,9 @@
904
904
  },
905
905
  "dependencies": {
906
906
  "mqtt-packet": {
907
- "version": "7.1.0",
908
- "resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-7.1.0.tgz",
909
- "integrity": "sha512-ireFY+9xK0JgiLWIBkskTK5B6uPz6kN2JvyBK+TUhxCWaEhpFeG/7O4734Pac3imeZ6ZtU6QQABAvMz4z7pfUg==",
907
+ "version": "7.1.1",
908
+ "resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-7.1.1.tgz",
909
+ "integrity": "sha512-xNNDZG169D2c96NJmkkoDdj3tj5z0jsZ1yv/vGBY9chg4JellV9wJwawKPXv4fyLetmXp50LtPNwL2u8qvLssw==",
910
910
  "requires": {
911
911
  "bl": "^4.0.2",
912
912
  "debug": "^4.1.1",
@@ -2902,9 +2902,9 @@
2902
2902
  "optional": true
2903
2903
  },
2904
2904
  "fastparallel": {
2905
- "version": "2.4.0",
2906
- "resolved": "https://registry.npmjs.org/fastparallel/-/fastparallel-2.4.0.tgz",
2907
- "integrity": "sha512-sacwQ7wwKlQXsa7TN24UvMBLZNLmVcPhmxccC9riFqb3N+fSczJL8eWdnZodZ/KijGVgNBBfvF/NeXER08uXnQ==",
2905
+ "version": "2.4.1",
2906
+ "resolved": "https://registry.npmjs.org/fastparallel/-/fastparallel-2.4.1.tgz",
2907
+ "integrity": "sha512-qUmhxPgNHmvRjZKBFUNI0oZuuH9OlSIOXmJ98lhKPxMZZ7zS/Fi0wRHOihDSz0R1YiIOjxzOY4bq65YTcdBi2Q==",
2908
2908
  "requires": {
2909
2909
  "reusify": "^1.0.4",
2910
2910
  "xtend": "^4.0.2"
@@ -4802,9 +4802,9 @@
4802
4802
  "optional": true
4803
4803
  },
4804
4804
  "mqemitter": {
4805
- "version": "4.4.1",
4806
- "resolved": "https://registry.npmjs.org/mqemitter/-/mqemitter-4.4.1.tgz",
4807
- "integrity": "sha512-tXSsyzhsD70Jc7WFz1tjbfczGOAyObMhJ8O15ZFkpDI+g9ENmWFUo5BseAuS9HCxNnFtnMWo4lHh7yDi5CjVTQ==",
4805
+ "version": "4.5.0",
4806
+ "resolved": "https://registry.npmjs.org/mqemitter/-/mqemitter-4.5.0.tgz",
4807
+ "integrity": "sha512-Mp/zytFeIv6piJQkEKnncHcP4R/ErJc5C7dfonkhkNUT2LA/nTayrfNxbipp3M5iCJUTQSUtzfQAQA3XVcKz6w==",
4808
4808
  "requires": {
4809
4809
  "fastparallel": "^2.3.0",
4810
4810
  "qlobber": "^5.0.0"
@@ -5424,9 +5424,9 @@
5424
5424
  }
5425
5425
  },
5426
5426
  "openapi-enforcer": {
5427
- "version": "1.16.0",
5428
- "resolved": "https://registry.npmjs.org/openapi-enforcer/-/openapi-enforcer-1.16.0.tgz",
5429
- "integrity": "sha512-7wwvOGehsF65UHj1kPBZ+UovgJUvdK8ztWaeqRnwskXd2qlt+YZcOILwmCyxdqHt59B57u46LT28klLgXJOKjQ==",
5427
+ "version": "1.16.1",
5428
+ "resolved": "https://registry.npmjs.org/openapi-enforcer/-/openapi-enforcer-1.16.1.tgz",
5429
+ "integrity": "sha512-MG3lwulSdL9Qo1p0r8QMLjX+jTcvEN+YgMIGDNjyOxe2sYuk4Iu1wWN/3rVtkudrU/AQXIAZZP31NcqTIWcE7Q==",
5430
5430
  "requires": {
5431
5431
  "js-yaml": "^4.1.0",
5432
5432
  "randexp": "^0.5.3"
@@ -7653,9 +7653,9 @@
7653
7653
  }
7654
7654
  },
7655
7655
  "typescript": {
7656
- "version": "4.5.2",
7657
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz",
7658
- "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==",
7656
+ "version": "4.5.3",
7657
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.3.tgz",
7658
+ "integrity": "sha512-eVYaEHALSt+s9LbvgEv4Ef+Tdq7hBiIZgii12xXJnukryt3pMgJf6aKhoCZ3FWQsu6sydEnkg11fYXLzhLBjeQ==",
7659
7659
  "dev": true
7660
7660
  },
7661
7661
  "uWebSockets.js": {
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.16.2",
4
+ "version": "2.16.6",
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": {
7
7
  "kuzzle": "bin/start-kuzzle-server"
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@elastic/elasticsearch": "https://github.com/elastic/elasticsearch-js/archive/refs/tags/v7.13.0.tar.gz",
43
43
  "@types/js-yaml": "^4.0.5",
44
- "aedes": "^0.46.1",
44
+ "aedes": "^0.46.2",
45
45
  "bluebird": "^3.7.2",
46
46
  "cli-color": "^2.0.1",
47
47
  "cookie": "^0.4.1",
@@ -68,7 +68,7 @@
68
68
  "murmurhash-native": "^3.5.0",
69
69
  "nanoid": "^3.1.30",
70
70
  "node-segfault-handler": "^1.0.4",
71
- "openapi-enforcer": "^1.16.0",
71
+ "openapi-enforcer": "^1.16.1",
72
72
  "passport": "^0.5.0",
73
73
  "protobufjs": "~6.11.2",
74
74
  "rc": "1.2.8",
@@ -89,7 +89,7 @@
89
89
  "url": "git://github.com/kuzzleio/kuzzle.git"
90
90
  },
91
91
  "devDependencies": {
92
- "@types/lodash": "^4.14.177",
92
+ "@types/lodash": "^4.14.178",
93
93
  "@typescript-eslint/eslint-plugin": "^5.6.0",
94
94
  "@typescript-eslint/parser": "^5.6.0",
95
95
  "async": "^3.2.2",
@@ -110,7 +110,7 @@
110
110
  "sinon": "^12.0.1",
111
111
  "strip-json-comments": "https://github.com/sindresorhus/strip-json-comments/archive/refs/tags/v3.1.1.tar.gz",
112
112
  "ts-node": "^10.4.0",
113
- "typescript": "^4.5.2",
113
+ "typescript": "^4.5.3",
114
114
  "yaml": "^1.10.2"
115
115
  },
116
116
  "engines": {