kuzzle 2.16.11 → 2.17.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.
Files changed (164) hide show
  1. package/lib/api/controllers/adminController.js +3 -3
  2. package/lib/api/controllers/authController.js +11 -11
  3. package/lib/api/controllers/baseController.js +60 -3
  4. package/lib/api/controllers/clusterController.js +1 -1
  5. package/lib/api/controllers/collectionController.js +7 -5
  6. package/lib/api/controllers/documentController.js +130 -17
  7. package/lib/api/controllers/indexController.js +1 -1
  8. package/lib/api/controllers/memoryStorageController.js +39 -38
  9. package/lib/api/controllers/realtimeController.js +1 -1
  10. package/lib/api/controllers/securityController.js +49 -49
  11. package/lib/api/controllers/serverController.js +73 -27
  12. package/lib/api/documentExtractor.js +3 -3
  13. package/lib/api/funnel.js +40 -21
  14. package/lib/api/httpRoutes.js +9 -4
  15. package/lib/api/openapi/OpenApiManager.d.ts +11 -0
  16. package/lib/api/openapi/OpenApiManager.js +96 -0
  17. package/lib/api/openapi/{document → components/document}/count.yaml +2 -2
  18. package/lib/api/openapi/{document → components/document}/create.yaml +2 -2
  19. package/lib/api/openapi/{document → components/document}/createOrReplace.yaml +2 -2
  20. package/lib/api/openapi/{document → components/document}/delete.yaml +1 -1
  21. package/lib/api/openapi/{document → components/document}/deleteByQuery.yaml +2 -2
  22. package/lib/api/openapi/{document → components/document}/exists.yaml +1 -1
  23. package/lib/api/openapi/{document → components/document}/get.yaml +1 -1
  24. package/lib/api/openapi/{document → components/document}/index.d.ts +2 -0
  25. package/lib/api/openapi/{document → components/document}/index.js +7 -2
  26. package/lib/api/openapi/{document → components/document}/replace.yaml +2 -2
  27. package/lib/api/openapi/{document → components/document}/scroll.yaml +1 -1
  28. package/lib/api/openapi/{document → components/document}/update.yaml +2 -2
  29. package/lib/api/openapi/components/document/validate.yaml +42 -0
  30. package/lib/api/openapi/components/index.d.ts +2 -0
  31. package/lib/api/openapi/components/index.js +18 -0
  32. package/lib/api/openapi/{payloads.yaml → components/payloads.yaml} +0 -0
  33. package/lib/api/openapi/index.d.ts +1 -2
  34. package/lib/api/openapi/index.js +1 -5
  35. package/lib/api/openapi/openApiGenerator.d.ts +7 -0
  36. package/lib/api/openapi/openApiGenerator.js +133 -0
  37. package/lib/api/request/kuzzleRequest.js +4 -0
  38. package/lib/cluster/node.js +9 -9
  39. package/lib/cluster/publisher.js +1 -1
  40. package/lib/cluster/subscriber.js +1 -1
  41. package/lib/cluster/workers/IDCardRenewer.js +2 -2
  42. package/lib/config/default.config.js +1 -0
  43. package/lib/config/index.js +6 -6
  44. package/lib/core/auth/passportResponse.js +6 -6
  45. package/lib/core/auth/passportWrapper.js +5 -5
  46. package/lib/core/backend/backend.d.ts +5 -1
  47. package/lib/core/backend/backend.js +12 -8
  48. package/lib/core/backend/backendConfig.d.ts +5 -1
  49. package/lib/core/backend/backendConfig.js +4 -0
  50. package/lib/core/backend/backendOpenApi.d.ts +9 -0
  51. package/lib/core/backend/backendOpenApi.js +69 -0
  52. package/lib/core/backend/index.d.ts +1 -0
  53. package/lib/core/backend/index.js +1 -0
  54. package/lib/core/network/accessLogger.js +6 -6
  55. package/lib/core/network/clientConnection.js +1 -1
  56. package/lib/core/network/entryPoint.js +5 -5
  57. package/lib/core/network/httpRouter/index.js +5 -5
  58. package/lib/core/network/httpRouter/routeHandler.js +3 -3
  59. package/lib/core/network/httpRouter/routePart.js +5 -5
  60. package/lib/core/network/protocolManifest.js +1 -1
  61. package/lib/core/network/protocols/httpMessage.js +2 -2
  62. package/lib/core/network/protocols/httpwsProtocol.js +205 -48
  63. package/lib/core/network/protocols/mqttProtocol.js +3 -3
  64. package/lib/core/network/protocols/protocol.js +3 -3
  65. package/lib/core/network/router.js +7 -6
  66. package/lib/core/plugin/plugin.js +38 -64
  67. package/lib/core/plugin/pluginManifest.js +3 -3
  68. package/lib/core/plugin/pluginRepository.js +5 -5
  69. package/lib/core/plugin/pluginsManager.js +29 -28
  70. package/lib/core/realtime/notification/server.js +1 -1
  71. package/lib/core/realtime/notification/user.js +1 -1
  72. package/lib/core/realtime/notifier.js +5 -5
  73. package/lib/core/security/index.js +1 -1
  74. package/lib/core/security/profileRepository.d.ts +176 -0
  75. package/lib/core/security/profileRepository.js +426 -443
  76. package/lib/core/security/roleRepository.js +16 -16
  77. package/lib/core/security/securityLoader.js +2 -2
  78. package/lib/core/security/tokenRepository.js +11 -11
  79. package/lib/core/security/userRepository.js +8 -8
  80. package/lib/core/shared/abstractManifest.js +4 -4
  81. package/lib/core/shared/repository.js +5 -5
  82. package/lib/core/shared/sdk/funnelProtocol.js +1 -1
  83. package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
  84. package/lib/core/shared/store.js +30 -23
  85. package/lib/core/statistics/statistics.js +17 -17
  86. package/lib/core/storage/clientAdapter.js +45 -10
  87. package/lib/core/validation/baseType.js +5 -5
  88. package/lib/core/validation/types/anything.js +1 -1
  89. package/lib/core/validation/types/boolean.js +2 -2
  90. package/lib/core/validation/types/date.js +9 -9
  91. package/lib/core/validation/types/email.js +5 -5
  92. package/lib/core/validation/types/enum.js +6 -6
  93. package/lib/core/validation/types/geoPoint.js +2 -2
  94. package/lib/core/validation/types/geoShape.js +28 -25
  95. package/lib/core/validation/types/integer.js +4 -4
  96. package/lib/core/validation/types/ipAddress.js +7 -6
  97. package/lib/core/validation/types/numeric.js +4 -4
  98. package/lib/core/validation/types/object.js +5 -5
  99. package/lib/core/validation/types/string.js +5 -5
  100. package/lib/core/validation/types/url.js +7 -6
  101. package/lib/core/validation/validation.js +95 -84
  102. package/lib/kerror/codes/1-services.json +12 -0
  103. package/lib/kerror/codes/2-api.json +12 -0
  104. package/lib/kerror/codes/3-network.json +12 -0
  105. package/lib/kerror/codes/4-plugin.json +6 -0
  106. package/lib/kerror/codes/index.js +11 -11
  107. package/lib/kerror/index.js +1 -1
  108. package/lib/kuzzle/dumpGenerator.js +3 -3
  109. package/lib/kuzzle/event/kuzzleEventEmitter.js +4 -4
  110. package/lib/kuzzle/event/pipeRunner.js +1 -1
  111. package/lib/kuzzle/event/waterfall.js +6 -6
  112. package/lib/kuzzle/kuzzle.js +36 -5
  113. package/lib/kuzzle/log.js +3 -3
  114. package/lib/kuzzle/vault.js +3 -3
  115. package/lib/model/security/profile.d.ts +54 -0
  116. package/lib/model/security/profile.js +174 -233
  117. package/lib/model/security/rights.js +1 -1
  118. package/lib/model/security/role.d.ts +40 -0
  119. package/lib/model/security/role.js +159 -191
  120. package/lib/model/security/user.d.ts +29 -0
  121. package/lib/model/security/user.js +84 -52
  122. package/lib/model/storage/apiKey.js +2 -2
  123. package/lib/model/storage/baseModel.js +3 -3
  124. package/lib/service/cache/redis.js +7 -7
  125. package/lib/service/storage/elasticsearch.js +152 -90
  126. package/lib/service/storage/esWrapper.js +2 -3
  127. package/lib/types/ControllerDefinition.d.ts +3 -3
  128. package/lib/types/ControllerRights.d.ts +22 -0
  129. package/lib/types/ControllerRights.js +23 -0
  130. package/lib/types/HttpStream.d.ts +32 -0
  131. package/lib/types/HttpStream.js +70 -0
  132. package/lib/types/OpenApiDefinition.d.ts +43 -0
  133. package/lib/types/{config/StorageService/StorageServiceElasticsearchConfiguration.js → OpenApiDefinition.js} +1 -1
  134. package/lib/types/Policy.d.ts +25 -0
  135. package/lib/types/{InternalLogger.js → Policy.js} +2 -2
  136. package/lib/types/PolicyRestrictions.d.ts +21 -0
  137. package/lib/types/PolicyRestrictions.js +23 -0
  138. package/lib/types/Target.d.ts +15 -0
  139. package/lib/types/Target.js +23 -0
  140. package/lib/types/config/KuzzleConfiguration.d.ts +4 -0
  141. package/lib/types/config/ServicesConfiguration.d.ts +2 -2
  142. package/lib/types/config/{StorageService/StorageServiceElasticsearchConfiguration.d.ts → storageEngine/StorageEngineElasticsearchConfiguration.d.ts} +10 -3
  143. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +3 -0
  144. package/lib/types/index.d.ts +7 -1
  145. package/lib/types/index.js +7 -1
  146. package/lib/util/array.d.ts +11 -0
  147. package/lib/util/array.js +57 -0
  148. package/lib/util/assertType.js +6 -6
  149. package/lib/util/bufferedPassThrough.d.ts +76 -0
  150. package/lib/util/bufferedPassThrough.js +161 -0
  151. package/lib/util/deprecate.js +7 -5
  152. package/lib/util/didYouMean.js +1 -1
  153. package/lib/util/dump-collection.d.ts +3 -0
  154. package/lib/util/dump-collection.js +265 -0
  155. package/lib/util/extractFields.js +2 -2
  156. package/lib/util/inflector.d.ts +8 -0
  157. package/lib/util/inflector.js +16 -0
  158. package/lib/util/requestAssertions.js +7 -7
  159. package/lib/util/wildcard.js +55 -0
  160. package/package-lock.json +538 -78
  161. package/package.json +5 -3
  162. package/lib/api/openApiGenerator.d.ts +0 -7
  163. package/lib/api/openApiGenerator.js +0 -197
  164. package/lib/types/InternalLogger.d.ts +0 -25
@@ -0,0 +1,9 @@
1
+ import { ApplicationManager, Backend } from './index';
2
+ import { OpenApiDefinition } from '../../types';
3
+ export declare class BackendOpenApi extends ApplicationManager {
4
+ /**
5
+ * Application Open API definition
6
+ */
7
+ definition: Partial<OpenApiDefinition>;
8
+ constructor(application: Backend);
9
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /*
3
+ * Kuzzle, a backend software, self-hostable and ready to use
4
+ * to power modern apps
5
+ *
6
+ * Copyright 2015-2020 Kuzzle
7
+ * mailto: support AT kuzzle.io
8
+ * website: http://kuzzle.io
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * https://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.BackendOpenApi = void 0;
24
+ const index_1 = require("./index");
25
+ class BackendOpenApi extends index_1.ApplicationManager {
26
+ constructor(application) {
27
+ super(application);
28
+ /* eslint-disable sort-keys */
29
+ this.definition = {
30
+ swagger: '2.0',
31
+ info: {
32
+ title: `${application.name} API`,
33
+ description: `${application.name} HTTP API definition`,
34
+ contact: {
35
+ name: 'Kuzzle team',
36
+ url: 'https://kuzzle.io',
37
+ email: 'support@kuzzle.io',
38
+ discord: 'http://join.discord.kuzzle.io'
39
+ },
40
+ license: {
41
+ name: 'Apache 2',
42
+ url: 'http://opensource.org/licenses/apache2.0'
43
+ },
44
+ version: application.version
45
+ },
46
+ externalDocs: {
47
+ description: 'Kuzzle API Documentation',
48
+ url: 'https://docs.kuzzle.io/core/2/api/'
49
+ },
50
+ servers: [
51
+ {
52
+ url: 'https://{baseUrl}:{port}',
53
+ description: `${application.name} Base Url`,
54
+ variables: {
55
+ baseUrl: { default: 'localhost' },
56
+ port: { default: 7512 },
57
+ }
58
+ }
59
+ ],
60
+ tags: [],
61
+ schemes: ['https', 'http'],
62
+ paths: {},
63
+ components: {}
64
+ };
65
+ /* eslint-enable sort-keys */
66
+ }
67
+ }
68
+ exports.BackendOpenApi = BackendOpenApi;
69
+ //# sourceMappingURL=backendOpenApi.js.map
@@ -9,4 +9,5 @@ export * from './backendPipe';
9
9
  export * from './backendPlugin';
10
10
  export * from './backendStorage';
11
11
  export * from './backendVault';
12
+ export * from './backendOpenApi';
12
13
  export * from './internalLogger';
@@ -21,5 +21,6 @@ __exportStar(require("./backendPipe"), exports);
21
21
  __exportStar(require("./backendPlugin"), exports);
22
22
  __exportStar(require("./backendStorage"), exports);
23
23
  __exportStar(require("./backendVault"), exports);
24
+ __exportStar(require("./backendOpenApi"), exports);
24
25
  __exportStar(require("./internalLogger"), exports);
25
26
  //# sourceMappingURL=index.js.map
@@ -54,15 +54,15 @@ class AccessLogger {
54
54
  const config = global.kuzzle.config.server;
55
55
 
56
56
  for (const out of config.logs.transports) {
57
- if (out.transport && !ALLOWED_TRANSPORTS.includes(out.transport)) {
57
+ if (out.transport && ! ALLOWED_TRANSPORTS.includes(out.transport)) {
58
58
  global.kuzzle.log.error(`Failed to initialize logger transport "${out.transport}": unsupported transport. Skipped.`);
59
59
  }
60
60
  else {
61
- this.isActive = this.isActive || !out.silent;
61
+ this.isActive = this.isActive || ! out.silent;
62
62
  }
63
63
  }
64
64
 
65
- if (!this.isActive) {
65
+ if (! this.isActive) {
66
66
  return;
67
67
  }
68
68
 
@@ -78,7 +78,7 @@ class AccessLogger {
78
78
  }
79
79
 
80
80
  log (connection, request, extra) {
81
- if (!this.isActive) {
81
+ if (! this.isActive) {
82
82
  return;
83
83
  }
84
84
 
@@ -212,7 +212,7 @@ class AccessLoggerWorker {
212
212
  }
213
213
  }
214
214
 
215
- this.logger = winston.createLogger({transports});
215
+ this.logger = winston.createLogger({ transports });
216
216
  }
217
217
 
218
218
  /**
@@ -325,7 +325,7 @@ class AccessLoggerWorker {
325
325
  }
326
326
  }
327
327
 
328
- if (!isMainThread) {
328
+ if (! isMainThread) {
329
329
  // Needed for instantiating a serialized KuzzleRequest object
330
330
  global.kuzzle = { id: workerData.kuzzleId };
331
331
 
@@ -36,7 +36,7 @@ class ClientConnection {
36
36
  this.protocol = protocol;
37
37
  this.headers = {};
38
38
 
39
- if (!Array.isArray(ips)) {
39
+ if (! Array.isArray(ips)) {
40
40
  throw new TypeError(`Expected ips to be an Array, got ${typeof ips}`);
41
41
  }
42
42
  this.ips = ips;
@@ -99,7 +99,7 @@ class EntryPoint {
99
99
  async startListening () {
100
100
  // We need to verify the port ourselves, to make sure Node.js won't open
101
101
  // a named pipe if the provided port number is a string
102
- if (!Number.isInteger(this.config.port)) {
102
+ if (! Number.isInteger(this.config.port)) {
103
103
  throw networkError.get('invalid_port', this.config.port);
104
104
  }
105
105
 
@@ -140,7 +140,7 @@ class EntryPoint {
140
140
 
141
141
  const client = this._clients.get(connectionId);
142
142
 
143
- if (!client || !client.protocol) {
143
+ if (! client || ! client.protocol) {
144
144
  return;
145
145
  }
146
146
 
@@ -160,7 +160,7 @@ class EntryPoint {
160
160
 
161
161
  const client = this._clients.get(connectionId);
162
162
 
163
- if (!client || !client.protocol) {
163
+ if (! client || ! client.protocol) {
164
164
  return;
165
165
  }
166
166
 
@@ -248,7 +248,7 @@ class EntryPoint {
248
248
  global.kuzzle.funnel.execute(request, (error, result) => {
249
249
  const _res = result || request;
250
250
 
251
- if (error && !_res.error) {
251
+ if (error && ! _res.error) {
252
252
  _res.setError(error);
253
253
  }
254
254
 
@@ -327,7 +327,7 @@ class EntryPoint {
327
327
 
328
328
  const client = this._clients.get(data.connectionId);
329
329
 
330
- if (!client || !client.protocol) {
330
+ if (! client || ! client.protocol) {
331
331
  return;
332
332
  }
333
333
 
@@ -142,7 +142,7 @@ class Router {
142
142
  route (message, cb) {
143
143
  debug('Routing HTTP message: %a', message);
144
144
 
145
- if (!has(this.routes, message.method)) {
145
+ if (! has(this.routes, message.method)) {
146
146
  this.routeUnhandledHttpMethod(message, cb);
147
147
  return;
148
148
  }
@@ -165,8 +165,8 @@ class Router {
165
165
  }
166
166
  catch (err) {
167
167
  let request;
168
- if (!routeHandler || !routeHandler._request) {
169
- request = new Request({requestId: message.requestId}, {});
168
+ if (! routeHandler || ! routeHandler._request) {
169
+ request = new Request({ requestId: message.requestId }, {});
170
170
  // Set Headers if not present
171
171
  request.response.setHeaders(this.defaultHeaders, true);
172
172
 
@@ -190,7 +190,7 @@ class Router {
190
190
  * @param {HttpMessage} message
191
191
  * @param {function} cb
192
192
  */
193
- routeUnhandledHttpMethod(message, cb) {
193
+ routeUnhandledHttpMethod (message, cb) {
194
194
  const
195
195
  requestContext = global.kuzzle.router.connections.get(message.connection.id),
196
196
  request = new Request(
@@ -253,7 +253,7 @@ function applyACAOHeader (message, request) {
253
253
  function attach (path, handler, target) {
254
254
  const sanitized = path[path.length - 1] === '/' ? path.slice(0, -1) : path;
255
255
 
256
- if (!attachParts(sanitized.split('/'), handler, target)) {
256
+ if (! attachParts(sanitized.split('/'), handler, target)) {
257
257
  throw kerror.get('duplicate_url', sanitized);
258
258
  }
259
259
  }
@@ -38,7 +38,7 @@ const kerror = require('../../../kerror').wrap('network', 'http');
38
38
  * in JSON format
39
39
  */
40
40
  class RouteHandler {
41
- constructor(url, query, message) {
41
+ constructor (url, query, message) {
42
42
  this.handler = null;
43
43
  this._request = null;
44
44
  this.url = url;
@@ -92,7 +92,7 @@ class RouteHandler {
92
92
  * @param {string} name
93
93
  * @param {string} value
94
94
  */
95
- addArgument(name, value) {
95
+ addArgument (name, value) {
96
96
  this.data[name] = value;
97
97
  }
98
98
 
@@ -101,7 +101,7 @@ class RouteHandler {
101
101
  *
102
102
  * @param {Function} callback
103
103
  */
104
- invokeHandler(callback) {
104
+ invokeHandler (callback) {
105
105
  this.handler(this.request, callback);
106
106
  }
107
107
  }
@@ -32,7 +32,7 @@ const { has } = require('../../../util/safeObject');
32
32
  * @class RoutePart
33
33
  */
34
34
  class RoutePart {
35
- constructor() {
35
+ constructor () {
36
36
  this.subparts = {};
37
37
  this.placeholders = null;
38
38
 
@@ -45,7 +45,7 @@ class RoutePart {
45
45
  * @param {string} part
46
46
  * @returns {boolean}
47
47
  */
48
- exists(part) {
48
+ exists (part) {
49
49
  return this.subparts[part] !== undefined && this.subparts[part].handler !== null;
50
50
  }
51
51
 
@@ -56,8 +56,8 @@ class RoutePart {
56
56
  * @param {string} part
57
57
  * @returns {RoutePart}
58
58
  */
59
- getNext(part) {
60
- if (!has(this.subparts, part)) {
59
+ getNext (part) {
60
+ if (! has(this.subparts, part)) {
61
61
  this.subparts[part] = new RoutePart();
62
62
  }
63
63
 
@@ -71,7 +71,7 @@ class RoutePart {
71
71
  * @param {HttpMessage} message
72
72
  * @returns {RouteHandler} registered function handler
73
73
  */
74
- getHandler(message) {
74
+ getHandler (message) {
75
75
  // Do not use WHATWG API yet, stick with the legacy (and deprecated) URL
76
76
  // There are two issues:
77
77
  // - Heavy performance impact: https://github.com/nodejs/node/issues/30334
@@ -24,7 +24,7 @@
24
24
  const AbstractManifest = require('../shared/abstractManifest');
25
25
 
26
26
  class ProtocolManifest extends AbstractManifest {
27
- constructor(protocolPath, protocol) {
27
+ constructor (protocolPath, protocol) {
28
28
  super(protocolPath);
29
29
 
30
30
  this.protocol = protocol;
@@ -29,7 +29,7 @@ class HttpMessage {
29
29
  * @param {ClientConnection} connection
30
30
  * @param {uWS.HttpRequest} request
31
31
  */
32
- constructor(connection, request) {
32
+ constructor (connection, request) {
33
33
  this.connection = connection;
34
34
  this._content = null;
35
35
  this.ips = connection.ips;
@@ -54,7 +54,7 @@ class HttpMessage {
54
54
  }
55
55
 
56
56
  set content (value) {
57
- if (!value || value.length === 0) {
57
+ if (! value || value.length === 0) {
58
58
  this._content = null;
59
59
  }
60
60
  else {