kuzzle 2.16.3 → 2.16.7

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.
@@ -269,7 +269,7 @@ class CollectionController extends NativeController {
269
269
  }
270
270
 
271
271
  /**
272
- * Reset a collection by removing all documents
272
+ * Reset a collection by removing all documents while keeping the existing mapping
273
273
  *
274
274
  * @param {KuzzleRequest} request
275
275
  * @returns {Promise.<Object>}
@@ -277,13 +277,7 @@ class CollectionController extends NativeController {
277
277
  async truncate (request) {
278
278
  const { index, collection } = request.getIndexAndCollection();
279
279
 
280
- await this.ask('core:storage:public:collection:refresh', index, collection);
281
- await this.ask(
282
- 'core:storage:public:document:deleteByQuery',
283
- index,
284
- collection,
285
- {},
286
- { fetch: false, refresh: 'wait_for' });
280
+ await this.ask('core:storage:public:collection:truncate', index, collection);
287
281
 
288
282
  return {
289
283
  acknowledged: true
@@ -47,7 +47,11 @@ class ServerController extends NativeController {
47
47
  'publicApi',
48
48
  'openapi',
49
49
  ]);
50
- this._docOpenapi = generateOpenApi();
50
+
51
+ this._openApiDefinition = {
52
+ json: null,
53
+ yaml: null,
54
+ };
51
55
  }
52
56
 
53
57
  /**
@@ -55,7 +59,7 @@ class ServerController extends NativeController {
55
59
  *
56
60
  * @param {Request} request
57
61
  * @returns {Promise<Object>}
58
- *
62
+ *
59
63
  * @deprecated
60
64
  */
61
65
  getStats (request) {
@@ -66,7 +70,7 @@ class ServerController extends NativeController {
66
70
  * Returns the last statistics frame
67
71
  *
68
72
  * @returns {Promise<Object>}
69
- *
73
+ *
70
74
  * @deprecated
71
75
  */
72
76
  getLastStats () {
@@ -77,7 +81,7 @@ class ServerController extends NativeController {
77
81
  * Returns all stored statistics frames
78
82
  *
79
83
  * @returns {Promise<Object>}
80
- *
84
+ *
81
85
  * @deprecated
82
86
  */
83
87
  getAllStats () {
@@ -242,25 +246,34 @@ class ServerController extends NativeController {
242
246
  }
243
247
 
244
248
  async openapi (request) {
245
- const format = request.input.args.format
246
- ? request.input.args.format
247
- : 'json';
248
- const contentType = format === 'yaml'
249
- ? 'application/yaml'
250
- : 'application/json';
251
- const specifications = format === 'yaml'
252
- ? jsonToYaml.stringify(this._docOpenapi)
253
- : this._docOpenapi;
249
+ const format = request.getString('format', 'json');
250
+ const specifications = this.getOpenApiDefinition(format);
254
251
 
255
252
  request.response.configure({
256
253
  format: 'raw',
257
- headers: { 'Content-Type': contentType },
254
+ headers: { 'Content-Type': `application/${format}` },
258
255
  status: 200,
259
256
  });
260
257
 
261
258
  return specifications;
262
259
  }
263
260
 
261
+ /**
262
+ * Lazy loading of OpenAPI definition.
263
+ *
264
+ * Mainly because we need to wait all plugin to be loaded
265
+ * to generate the definition.
266
+ */
267
+ getOpenApiDefinition (format) {
268
+ if (! this._openApiDefinition[format]) {
269
+ this._openApiDefinition[format] = format === 'json'
270
+ ? generateOpenApi()
271
+ : jsonToYaml.stringify(generateOpenApi());
272
+ }
273
+
274
+ return this._openApiDefinition[format];
275
+ }
276
+
264
277
  /**
265
278
  * Fetches and returns Kuzzle core metrics
266
279
  * @returns {Promise<Object>}
@@ -1,6 +1,7 @@
1
+ import { JSONObject } from '../../index';
1
2
  /**
2
3
  * Generates JSON OpenApi object
3
4
  *
4
5
  * @returns {object} openApi object
5
6
  */
6
- export declare function generateOpenApi(): any;
7
+ export declare function generateOpenApi(): JSONObject;
@@ -1,9 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateOpenApi = void 0;
7
2
  /*
8
3
  * Kuzzle, a backend software, self-hostable and ready to use
9
4
  * to power modern apps
@@ -24,13 +19,18 @@ exports.generateOpenApi = void 0;
24
19
  * See the License for the specific language governing permissions and
25
20
  * limitations under the License.
26
21
  */
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateOpenApi = void 0;
27
27
  const lodash_1 = __importDefault(require("lodash"));
28
- const package_json_1 = require("./../../package.json");
28
+ const package_json_1 = require("../../package.json");
29
29
  const openapi_1 = require("./openapi");
30
- const inflector_1 = require("./../util/inflector");
30
+ const inflector_1 = require("../util/inflector");
31
31
  const routeUrlMatch = /:([^/]*)/g;
32
32
  /**
33
- * Genrate basic openApi Controller
33
+ * Generate basic openApi Controller
34
34
  */
35
35
  function generateController(route, response) {
36
36
  if (route.controller !== undefined) {
@@ -47,7 +47,7 @@ function generateController(route, response) {
47
47
  }
48
48
  }
49
49
  /**
50
- * Genrate basic openApi Summary
50
+ * Generate basic openApi Summary
51
51
  */
52
52
  function generateSummary(route) {
53
53
  if (route.openapi.description === undefined) {
@@ -58,7 +58,7 @@ function generateSummary(route) {
58
58
  }
59
59
  }
60
60
  /**
61
- * Genrate basic openApi Parameters
61
+ * Generate basic openApi Parameters
62
62
  */
63
63
  function generateParameters(route) {
64
64
  if (route.openapi.parameters === undefined) {
@@ -80,7 +80,7 @@ function generateParameters(route) {
80
80
  }
81
81
  }
82
82
  /**
83
- * Genrate basic openApi Response
83
+ * Generate basic openApi Response
84
84
  */
85
85
  function generateResponse(route) {
86
86
  if (route.openapi.responses === undefined) {
@@ -96,22 +96,20 @@ function generateResponse(route) {
96
96
  *
97
97
  * @returns {object} openApi object
98
98
  */
99
- /* eslint-disable @typescript-eslint/no-unused-vars */
100
99
  function generateOpenApi() {
101
- /* eslint-enable @typescript-eslint/no-unused-vars */
102
100
  const routes = [];
103
- global.kuzzle.config.http.routes.forEach(_route => routes.push({ ..._route }));
104
- global.kuzzle.pluginsManager.routes.forEach(_route => routes.push({ ..._route }));
101
+ global.kuzzle.config.http.routes.forEach(route => routes.push({ ...route }));
102
+ global.kuzzle.pluginsManager.routes.forEach(route => routes.push({ ...route }));
105
103
  /* eslint-disable sort-keys */
106
104
  const response = {
107
105
  swagger: '2.0',
108
106
  info: {
109
107
  title: 'Kuzzle API',
110
- description: 'The Kuzzle HTTP API',
108
+ description: 'Kuzzle HTTP API definition',
111
109
  contact: {
112
110
  name: 'Kuzzle team',
113
- url: 'http://kuzzle.io',
114
- email: 'hello@kuzzle.io',
111
+ url: 'https://kuzzle.io',
112
+ email: 'support@kuzzle.io',
115
113
  discord: 'http://join.discord.kuzzle.io'
116
114
  },
117
115
  license: {
@@ -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
 
@@ -678,7 +678,7 @@ class PluginsManager {
678
678
  'Native controllers cannot be overriden');
679
679
  }
680
680
 
681
- Plugin.checkControllerDefinition(controller, definition);
681
+ await Plugin.checkControllerDefinition(controller, definition);
682
682
 
683
683
  for (const [action, actionDefinition ] of Object.entries(definition.actions)) {
684
684
  let apiController = this.controllers.get(controller);
@@ -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.3",
3
+ "version": "2.16.7",
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.3",
4
+ "version": "2.16.7",
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": {