kuzzle 2.16.8 → 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 (167) hide show
  1. package/README.md +11 -0
  2. package/lib/api/controllers/adminController.js +7 -6
  3. package/lib/api/controllers/authController.js +11 -11
  4. package/lib/api/controllers/baseController.js +60 -3
  5. package/lib/api/controllers/clusterController.js +1 -1
  6. package/lib/api/controllers/collectionController.js +7 -5
  7. package/lib/api/controllers/documentController.js +130 -17
  8. package/lib/api/controllers/indexController.js +1 -1
  9. package/lib/api/controllers/memoryStorageController.js +39 -38
  10. package/lib/api/controllers/realtimeController.js +1 -1
  11. package/lib/api/controllers/securityController.js +49 -49
  12. package/lib/api/controllers/serverController.js +73 -27
  13. package/lib/api/documentExtractor.js +3 -3
  14. package/lib/api/funnel.js +40 -21
  15. package/lib/api/httpRoutes.js +9 -4
  16. package/lib/api/openapi/OpenApiManager.d.ts +11 -0
  17. package/lib/api/openapi/OpenApiManager.js +96 -0
  18. package/lib/api/openapi/{document → components/document}/count.yaml +2 -2
  19. package/lib/api/openapi/{document → components/document}/create.yaml +2 -2
  20. package/lib/api/openapi/{document → components/document}/createOrReplace.yaml +2 -2
  21. package/lib/api/openapi/{document → components/document}/delete.yaml +1 -1
  22. package/lib/api/openapi/{document → components/document}/deleteByQuery.yaml +2 -2
  23. package/lib/api/openapi/{document → components/document}/exists.yaml +1 -1
  24. package/lib/api/openapi/{document → components/document}/get.yaml +1 -1
  25. package/lib/api/openapi/{document → components/document}/index.d.ts +2 -0
  26. package/lib/api/openapi/{document → components/document}/index.js +7 -2
  27. package/lib/api/openapi/{document → components/document}/replace.yaml +2 -2
  28. package/lib/api/openapi/{document → components/document}/scroll.yaml +1 -1
  29. package/lib/api/openapi/{document → components/document}/update.yaml +2 -2
  30. package/lib/api/openapi/components/document/validate.yaml +42 -0
  31. package/lib/api/openapi/components/index.d.ts +2 -0
  32. package/lib/api/openapi/components/index.js +18 -0
  33. package/lib/api/openapi/{payloads.yaml → components/payloads.yaml} +0 -0
  34. package/lib/api/openapi/index.d.ts +1 -2
  35. package/lib/api/openapi/index.js +1 -5
  36. package/lib/api/openapi/openApiGenerator.d.ts +7 -0
  37. package/lib/api/openapi/openApiGenerator.js +133 -0
  38. package/lib/api/request/kuzzleRequest.d.ts +11 -11
  39. package/lib/api/request/kuzzleRequest.js +38 -48
  40. package/lib/cluster/node.js +9 -9
  41. package/lib/cluster/publisher.js +1 -1
  42. package/lib/cluster/subscriber.js +1 -1
  43. package/lib/cluster/workers/IDCardRenewer.js +13 -4
  44. package/lib/config/default.config.js +1 -0
  45. package/lib/config/index.js +6 -6
  46. package/lib/core/auth/passportResponse.js +6 -6
  47. package/lib/core/auth/passportWrapper.js +5 -5
  48. package/lib/core/backend/backend.d.ts +5 -1
  49. package/lib/core/backend/backend.js +12 -8
  50. package/lib/core/backend/backendConfig.d.ts +5 -1
  51. package/lib/core/backend/backendConfig.js +4 -0
  52. package/lib/core/backend/backendOpenApi.d.ts +9 -0
  53. package/lib/core/backend/backendOpenApi.js +69 -0
  54. package/lib/core/backend/index.d.ts +1 -0
  55. package/lib/core/backend/index.js +1 -0
  56. package/lib/core/network/accessLogger.js +6 -6
  57. package/lib/core/network/clientConnection.js +1 -1
  58. package/lib/core/network/entryPoint.js +5 -5
  59. package/lib/core/network/httpRouter/index.js +5 -5
  60. package/lib/core/network/httpRouter/routeHandler.js +3 -3
  61. package/lib/core/network/httpRouter/routePart.js +5 -5
  62. package/lib/core/network/protocolManifest.js +1 -1
  63. package/lib/core/network/protocols/httpMessage.js +2 -2
  64. package/lib/core/network/protocols/httpwsProtocol.js +207 -46
  65. package/lib/core/network/protocols/mqttProtocol.js +3 -3
  66. package/lib/core/network/protocols/protocol.js +3 -3
  67. package/lib/core/network/router.js +7 -6
  68. package/lib/core/plugin/plugin.js +38 -64
  69. package/lib/core/plugin/pluginContext.d.ts +10 -1
  70. package/lib/core/plugin/pluginContext.js +2 -0
  71. package/lib/core/plugin/pluginManifest.js +3 -3
  72. package/lib/core/plugin/pluginRepository.js +5 -5
  73. package/lib/core/plugin/pluginsManager.js +29 -28
  74. package/lib/core/realtime/notification/server.js +1 -1
  75. package/lib/core/realtime/notification/user.js +1 -1
  76. package/lib/core/realtime/notifier.js +5 -5
  77. package/lib/core/security/index.js +1 -1
  78. package/lib/core/security/profileRepository.d.ts +176 -0
  79. package/lib/core/security/profileRepository.js +426 -443
  80. package/lib/core/security/roleRepository.js +16 -16
  81. package/lib/core/security/securityLoader.js +3 -3
  82. package/lib/core/security/tokenRepository.js +18 -21
  83. package/lib/core/security/userRepository.js +8 -8
  84. package/lib/core/shared/abstractManifest.js +4 -4
  85. package/lib/core/shared/repository.js +6 -6
  86. package/lib/core/shared/sdk/funnelProtocol.js +1 -1
  87. package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
  88. package/lib/core/shared/store.js +30 -23
  89. package/lib/core/statistics/statistics.js +17 -17
  90. package/lib/core/storage/clientAdapter.js +45 -10
  91. package/lib/core/validation/baseType.js +5 -5
  92. package/lib/core/validation/types/anything.js +1 -1
  93. package/lib/core/validation/types/boolean.js +2 -2
  94. package/lib/core/validation/types/date.js +9 -9
  95. package/lib/core/validation/types/email.js +5 -5
  96. package/lib/core/validation/types/enum.js +6 -6
  97. package/lib/core/validation/types/geoPoint.js +2 -2
  98. package/lib/core/validation/types/geoShape.js +28 -25
  99. package/lib/core/validation/types/integer.js +4 -4
  100. package/lib/core/validation/types/ipAddress.js +7 -6
  101. package/lib/core/validation/types/numeric.js +4 -4
  102. package/lib/core/validation/types/object.js +5 -5
  103. package/lib/core/validation/types/string.js +5 -5
  104. package/lib/core/validation/types/url.js +7 -6
  105. package/lib/core/validation/validation.js +95 -84
  106. package/lib/kerror/codes/1-services.json +12 -0
  107. package/lib/kerror/codes/2-api.json +12 -0
  108. package/lib/kerror/codes/3-network.json +12 -0
  109. package/lib/kerror/codes/4-plugin.json +6 -0
  110. package/lib/kerror/codes/index.js +11 -11
  111. package/lib/kerror/index.js +1 -1
  112. package/lib/kuzzle/dumpGenerator.js +3 -3
  113. package/lib/kuzzle/event/kuzzleEventEmitter.js +4 -4
  114. package/lib/kuzzle/event/pipeRunner.js +1 -1
  115. package/lib/kuzzle/event/waterfall.js +6 -6
  116. package/lib/kuzzle/kuzzle.js +36 -5
  117. package/lib/kuzzle/log.js +3 -3
  118. package/lib/kuzzle/vault.js +3 -3
  119. package/lib/model/security/profile.d.ts +54 -0
  120. package/lib/model/security/profile.js +174 -233
  121. package/lib/model/security/rights.js +1 -1
  122. package/lib/model/security/role.d.ts +40 -0
  123. package/lib/model/security/role.js +159 -191
  124. package/lib/model/security/user.d.ts +29 -0
  125. package/lib/model/security/user.js +84 -52
  126. package/lib/model/storage/apiKey.js +2 -2
  127. package/lib/model/storage/baseModel.js +3 -3
  128. package/lib/service/cache/redis.js +7 -7
  129. package/lib/service/storage/elasticsearch.js +152 -90
  130. package/lib/service/storage/esWrapper.js +2 -3
  131. package/lib/types/ControllerDefinition.d.ts +3 -3
  132. package/lib/types/ControllerRights.d.ts +22 -0
  133. package/lib/types/ControllerRights.js +23 -0
  134. package/lib/types/HttpStream.d.ts +32 -0
  135. package/lib/types/HttpStream.js +70 -0
  136. package/lib/types/OpenApiDefinition.d.ts +43 -0
  137. package/lib/types/{config/StorageService/StorageServiceElasticsearchConfiguration.js → OpenApiDefinition.js} +1 -1
  138. package/lib/types/Policy.d.ts +25 -0
  139. package/lib/types/Policy.js +23 -0
  140. package/lib/types/PolicyRestrictions.d.ts +21 -0
  141. package/lib/types/PolicyRestrictions.js +23 -0
  142. package/lib/types/Target.d.ts +15 -0
  143. package/lib/types/Target.js +23 -0
  144. package/lib/types/config/KuzzleConfiguration.d.ts +4 -0
  145. package/lib/types/config/ServicesConfiguration.d.ts +2 -2
  146. package/lib/types/config/{StorageService/StorageServiceElasticsearchConfiguration.d.ts → storageEngine/StorageEngineElasticsearchConfiguration.d.ts} +10 -3
  147. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +3 -0
  148. package/lib/types/index.d.ts +7 -1
  149. package/lib/types/index.js +7 -1
  150. package/lib/util/array.d.ts +11 -0
  151. package/lib/util/array.js +57 -0
  152. package/lib/util/assertType.js +6 -6
  153. package/lib/util/bufferedPassThrough.d.ts +76 -0
  154. package/lib/util/bufferedPassThrough.js +161 -0
  155. package/lib/util/deprecate.js +7 -5
  156. package/lib/util/didYouMean.js +1 -1
  157. package/lib/util/dump-collection.d.ts +3 -0
  158. package/lib/util/dump-collection.js +265 -0
  159. package/lib/util/extractFields.js +2 -2
  160. package/lib/util/inflector.d.ts +8 -0
  161. package/lib/util/inflector.js +16 -0
  162. package/lib/util/requestAssertions.js +7 -7
  163. package/lib/util/wildcard.js +55 -0
  164. package/package-lock.json +881 -431
  165. package/package.json +23 -20
  166. package/lib/api/openApiGenerator.d.ts +0 -7
  167. package/lib/api/openApiGenerator.js +0 -197
@@ -24,7 +24,6 @@
24
24
  const path = require('path');
25
25
  const fs = require('fs');
26
26
  const semver = require('semver');
27
- const enforcer = require('openapi-enforcer');
28
27
 
29
28
  const { PluginContext } = require('./pluginContext');
30
29
  const PrivilegedPluginContext = require('./privilegedContext');
@@ -34,7 +33,6 @@ const Manifest = require('./pluginManifest');
34
33
  const { has, isPlainObject } = require('../../util/safeObject');
35
34
 
36
35
  const assertionError = kerror.wrap('plugin', 'assert');
37
- const controllerError = kerror.wrap('plugin', 'controller');
38
36
  const runtimeError = kerror.wrap('plugin', 'runtime');
39
37
 
40
38
  const PLUGIN_NAME_REGEX = /^[a-z-\d]+$/;
@@ -43,7 +41,7 @@ const HTTP_VERBS = ['get', 'head', 'post', 'put', 'delete', 'patch', 'options'];
43
41
  class Plugin {
44
42
  constructor (
45
43
  instance,
46
- { name, application=false, deprecationWarning=true } = {}
44
+ { name, application = false, deprecationWarning = true } = {}
47
45
  ) {
48
46
  this._instance = instance;
49
47
 
@@ -154,24 +152,46 @@ class Plugin {
154
152
 
155
153
  // getters/setters ===========================================================
156
154
 
157
- get instance () { return this._instance; }
155
+ get instance () {
156
+ return this._instance;
157
+ }
158
158
 
159
- get context () { return this._context; }
159
+ get context () {
160
+ return this._context;
161
+ }
160
162
 
161
- get application () { return this._application; }
163
+ get application () {
164
+ return this._application;
165
+ }
162
166
 
163
- get logPrefix () { return `[${this.name}]`; }
167
+ get logPrefix () {
168
+ return `[${this.name}]`;
169
+ }
164
170
 
165
- get config () { return this._config; }
166
- set config (config) { this._config = config; }
171
+ get config () {
172
+ return this._config;
173
+ }
174
+ set config (config) {
175
+ this._config = config;
176
+ }
167
177
 
168
- get version () { return this._version; }
169
- set version (version) { this._version = version; }
178
+ get version () {
179
+ return this._version;
180
+ }
181
+ set version (version) {
182
+ this._version = version;
183
+ }
170
184
 
171
- get deprecationWarning () { return this._deprecationWarning; }
172
- set deprecationWarning (value) { this._deprecationWarning = value; }
185
+ get deprecationWarning () {
186
+ return this._deprecationWarning;
187
+ }
188
+ set deprecationWarning (value) {
189
+ this._deprecationWarning = value;
190
+ }
173
191
 
174
- get name () { return this._name; }
192
+ get name () {
193
+ return this._name;
194
+ }
175
195
  set name (name) {
176
196
  if (! this.constructor.checkName(name)) {
177
197
  this.printDeprecation('Plugin names should be in kebab-case. This behavior will be enforced in futur versions of Kuzzle.');
@@ -180,7 +200,9 @@ class Plugin {
180
200
  this._name = name;
181
201
  }
182
202
 
183
- get manifest () { return this._manifest; }
203
+ get manifest () {
204
+ return this._manifest;
205
+ }
184
206
  set manifest (manifest) {
185
207
  this._manifest = manifest;
186
208
  }
@@ -264,7 +286,7 @@ class Plugin {
264
286
  return PLUGIN_NAME_REGEX.test(name);
265
287
  }
266
288
 
267
- static async checkControllerDefinition (name, definition, { application=false } = {}) {
289
+ static checkControllerDefinition (name, definition, { application = false } = {}) {
268
290
  if (typeof name !== 'string') {
269
291
  throw assertionError.get(
270
292
  'invalid_controller_definition',
@@ -342,10 +364,6 @@ class Plugin {
342
364
  name,
343
365
  `action "${action}" has invalid http properties: ${routeProperties.join(', ')}`);
344
366
  }
345
-
346
- if (route.openapi) {
347
- await checkOpenAPISpecification(name, action, route);
348
- }
349
367
  }
350
368
  }
351
369
  }
@@ -365,48 +383,4 @@ function checkHttpRouteProperties (route, action, name, application) {
365
383
  }
366
384
  }
367
385
 
368
- async function checkOpenAPISpecification (controller, action, route) {
369
- if (! isPlainObject(route.openapi)) {
370
- throw assertionError.get(
371
- 'invalid_controller_definition',
372
- controller,
373
- 'The "openapi" property of the route definition must be an object');
374
- }
375
-
376
- const routePath = route.path.charAt(0) === '/'
377
- ? route.path
378
- : `/_/${route.path}`;
379
-
380
- // Set :param notation to {param}
381
- const formattedPath = routePath.replace(/\/:([^/]*)/g,'/{$1}');
382
-
383
- const { error, warning } = await enforcer({
384
- /* eslint-disable sort-keys */
385
- openapi: '3.0.0',
386
- info: {
387
- title: 'Kuzzle API',
388
- version: require('../../../package').version
389
- },
390
- paths: {
391
- [formattedPath]: {
392
- [route.verb]: route.openapi
393
- }
394
- },
395
- /* eslint-enable sort-keys */
396
- });
397
-
398
- if (warning) {
399
- global.kuzzle.log.warn(`Warning for OpenAPI specification in "${controller}:${action}", ${route.openapi} : ${warning}`);
400
- }
401
-
402
- if (error) {
403
- throw controllerError.get(
404
- 'invalid_openapi_schema',
405
- controller,
406
- action,
407
- route.openapi,
408
- error);
409
- }
410
- }
411
-
412
386
  module.exports = Plugin;
@@ -2,6 +2,7 @@ import { Koncorde } from '../shared/KoncordeWrapper';
2
2
  import { Client } from '@elastic/elasticsearch';
3
3
  import { JSONObject } from 'kuzzle-sdk';
4
4
  import { EmbeddedSDK } from '../shared/sdk/embeddedSdk';
5
+ import { Mutex } from '../../util/mutex';
5
6
  import { RequestContext, RequestInput, KuzzleRequest } from '../../../index';
6
7
  import { BackendCluster } from '../backend';
7
8
  export interface Repository {
@@ -83,6 +84,10 @@ export declare class PluginContext {
83
84
  * @type {BackendCluster}
84
85
  */
85
86
  cluster: BackendCluster;
87
+ /**
88
+ * Current Kuzzle node unique identifier
89
+ */
90
+ nodeId: string;
86
91
  };
87
92
  config: JSONObject;
88
93
  constructors: {
@@ -94,6 +99,10 @@ export declare class PluginContext {
94
99
  * @deprecated import directly: `import { Koncorde } from 'kuzzle'`
95
100
  */
96
101
  Koncorde: Koncorde;
102
+ /**
103
+ * Mutex class
104
+ */
105
+ Mutex: typeof Mutex;
97
106
  /**
98
107
  * Plugin private storage space
99
108
  */
@@ -113,7 +122,7 @@ export declare class PluginContext {
113
122
  /**
114
123
  * Constructor for Elasticsearch SDK Client
115
124
  */
116
- ESClient: new () => Client;
125
+ ESClient: typeof Client;
117
126
  };
118
127
  /**
119
128
  * @deprecated import directly: `import { BadRequestError, ... } from 'kuzzle'`
@@ -97,6 +97,7 @@ class PluginContext {
97
97
  BaseValidationType: require('../validation/baseType'),
98
98
  ESClient: PluginContextESClient,
99
99
  Koncorde: KoncordeWrapper_1.Koncorde,
100
+ Mutex: mutex_1.Mutex,
100
101
  Repository: PluginContextRepository,
101
102
  Request: instantiateRequest,
102
103
  RequestContext: index_1.RequestContext,
@@ -117,6 +118,7 @@ class PluginContext {
117
118
  this.accessors = {
118
119
  cluster: new backend_1.BackendCluster(),
119
120
  execute: (request, callback) => execute(request, callback),
121
+ nodeId: global.kuzzle.id,
120
122
  sdk: new embeddedSdk_1.EmbeddedSDK(),
121
123
  storage: {
122
124
  bootstrap: collections => pluginStore.init(collections),
@@ -27,7 +27,7 @@ const kerror = require('../../kerror').wrap('plugin', 'manifest');
27
27
  const AbstractManifest = require('../shared/abstractManifest');
28
28
 
29
29
  class PluginManifest extends AbstractManifest {
30
- constructor(pluginPath) {
30
+ constructor (pluginPath) {
31
31
  super(pluginPath);
32
32
  this.privileged = false;
33
33
  }
@@ -36,11 +36,11 @@ class PluginManifest extends AbstractManifest {
36
36
  super.load();
37
37
 
38
38
  // Ensure ES will accept the plugin name as index
39
- if (!/^[\w-]+$/.test(this.name)) {
39
+ if (! /^[\w-]+$/.test(this.name)) {
40
40
  throw kerror.get('invalid_name', this.path);
41
41
  }
42
42
 
43
- if (!_.isNil(this.raw) && !_.isNil(this.raw.privileged)) {
43
+ if (! _.isNil(this.raw) && ! _.isNil(this.raw.privileged)) {
44
44
  if (typeof this.raw.privileged !== 'boolean') {
45
45
  throw kerror.get(
46
46
  'invalid_privileged',
@@ -36,7 +36,7 @@ class PluginRepository extends Repository {
36
36
  }
37
37
 
38
38
  init (options) {
39
- if (options && typeof options === 'object' && !Array.isArray(options)) {
39
+ if (options && typeof options === 'object' && ! Array.isArray(options)) {
40
40
  if (options.ObjectConstructor) {
41
41
  this.ObjectConstructor = options.ObjectConstructor;
42
42
  }
@@ -64,7 +64,7 @@ class PluginRepository extends Repository {
64
64
  * @returns {Promise}
65
65
  */
66
66
  create (object, options = {}) {
67
- const opts = Object.assign({method: 'create'}, options);
67
+ const opts = Object.assign({ method: 'create' }, options);
68
68
 
69
69
  return this.persistToDatabase(object, opts);
70
70
  }
@@ -75,7 +75,7 @@ class PluginRepository extends Repository {
75
75
  * @returns {Promise}
76
76
  */
77
77
  createOrReplace (object, options = {}) {
78
- const opts = Object.assign({method: 'createOrReplace'}, options);
78
+ const opts = Object.assign({ method: 'createOrReplace' }, options);
79
79
 
80
80
  return this.persistToDatabase(object, opts);
81
81
  }
@@ -86,7 +86,7 @@ class PluginRepository extends Repository {
86
86
  * @returns {Promise}
87
87
  */
88
88
  replace (object, options = {}) {
89
- const opts = Object.assign({method: 'replace'}, options);
89
+ const opts = Object.assign({ method: 'replace' }, options);
90
90
 
91
91
  return this.persistToDatabase(object, opts);
92
92
  }
@@ -97,7 +97,7 @@ class PluginRepository extends Repository {
97
97
  * @returns {Promise}
98
98
  */
99
99
  update (object, options = {}) {
100
- const opts = Object.assign({method: 'update'}, options);
100
+ const opts = Object.assign({ method: 'update' }, options);
101
101
 
102
102
  return this.persistToDatabase(object, opts);
103
103
  }
@@ -50,7 +50,7 @@ const CORE_PLUGINS = ['kuzzle-plugin-logger', 'kuzzle-plugin-auth-passport-local
50
50
  * @param {Kuzzle} kuzzle
51
51
  */
52
52
  class PluginsManager {
53
- constructor() {
53
+ constructor () {
54
54
  Reflect.defineProperty(this, 'kuzzle', {
55
55
  value: global.kuzzle,
56
56
  });
@@ -234,8 +234,7 @@ class PluginsManager {
234
234
  plugin.initCalled = true;
235
235
 
236
236
  if ( ! _.isEmpty(plugin.instance.controllers)
237
- && ! _.isEmpty(plugin.instance.api))
238
- {
237
+ && ! _.isEmpty(plugin.instance.api)) {
239
238
  throw assertionError.get('duplicated_api_definition');
240
239
  }
241
240
 
@@ -265,7 +264,9 @@ class PluginsManager {
265
264
 
266
265
  debug('[%s] plugin started', plugin.name);
267
266
 
268
- this.loadedPlugins.push(plugin.name);
267
+ if (! plugin.application) {
268
+ this.loadedPlugins.push(plugin.name);
269
+ }
269
270
 
270
271
  return null;
271
272
  });
@@ -322,11 +323,11 @@ class PluginsManager {
322
323
  validateStrategy (pluginName, strategyName, strategy) {
323
324
  const errorPrefix = `[${pluginName}] Strategy ${strategyName}:`;
324
325
 
325
- if (!isPlainObject(strategy)) {
326
+ if (! isPlainObject(strategy)) {
326
327
  throw strategyError.get('invalid_description', errorPrefix, strategy);
327
328
  }
328
329
 
329
- if (!isPlainObject(strategy.methods)) {
330
+ if (! isPlainObject(strategy.methods)) {
330
331
  throw strategyError.get('invalid_methods', errorPrefix, strategy.methods);
331
332
  }
332
333
 
@@ -334,7 +335,7 @@ class PluginsManager {
334
335
 
335
336
  // required methods check
336
337
  ['exists', 'create', 'update', 'delete', 'validate', 'verify'].forEach(methodName => {
337
- if (!_.isString(strategy.methods[methodName])) {
338
+ if (! _.isString(strategy.methods[methodName])) {
338
339
  throw strategyError.get(
339
340
  'invalid_method_type',
340
341
  errorPrefix,
@@ -342,7 +343,7 @@ class PluginsManager {
342
343
  strategy.methods[methodName]);
343
344
  }
344
345
 
345
- if (!_.isFunction(plugin.instance[strategy.methods[methodName]])) {
346
+ if (! _.isFunction(plugin.instance[strategy.methods[methodName]])) {
346
347
  throw strategyError.get(
347
348
  'missing_method_function',
348
349
  errorPrefix,
@@ -354,8 +355,8 @@ class PluginsManager {
354
355
  ['getInfo', 'getById', 'afterRegister'].forEach(name => {
355
356
  const optionalMethodName = strategy.methods[name];
356
357
 
357
- if (!_.isNil(optionalMethodName)) {
358
- if (!_.isString(optionalMethodName)) {
358
+ if (! _.isNil(optionalMethodName)) {
359
+ if (! _.isString(optionalMethodName)) {
359
360
  throw strategyError.get(
360
361
  'invalid_method_type',
361
362
  errorPrefix,
@@ -363,7 +364,7 @@ class PluginsManager {
363
364
  optionalMethodName);
364
365
  }
365
366
 
366
- if (!_.isFunction(plugin.instance[optionalMethodName])) {
367
+ if (! _.isFunction(plugin.instance[optionalMethodName])) {
367
368
  throw strategyError.get(
368
369
  'missing_method_function',
369
370
  errorPrefix,
@@ -372,7 +373,7 @@ class PluginsManager {
372
373
  }
373
374
  });
374
375
 
375
- if (!isPlainObject(strategy.config)) {
376
+ if (! isPlainObject(strategy.config)) {
376
377
  throw strategyError.get('invalid_config', errorPrefix, strategy.config);
377
378
  }
378
379
 
@@ -382,8 +383,8 @@ class PluginsManager {
382
383
  errorPrefix,
383
384
  strategy.config.authenticator);
384
385
  }
385
- else if (!this.authenticators[pluginName]
386
- || !this.authenticators[pluginName][strategy.config.authenticator]
386
+ else if (! this.authenticators[pluginName]
387
+ || ! this.authenticators[pluginName][strategy.config.authenticator]
387
388
  ) {
388
389
  throw strategyError.get(
389
390
  'unknown_authenticator',
@@ -394,12 +395,12 @@ class PluginsManager {
394
395
  for (const optionName of ['strategyOptions', 'authenticateOptions']) {
395
396
  const options = strategy.config[optionName];
396
397
 
397
- if (!_.isNil(options) && !isPlainObject(options)) {
398
+ if (! _.isNil(options) && ! isPlainObject(options)) {
398
399
  throw strategyError.get('invalid_option', errorPrefix, optionName, options);
399
400
  }
400
401
  }
401
402
 
402
- if (!_.isNil(strategy.config.fields) && !Array.isArray(strategy.config.fields)) {
403
+ if (! _.isNil(strategy.config.fields) && ! Array.isArray(strategy.config.fields)) {
403
404
  throw strategyError.get('invalid_fields', errorPrefix, strategy.config.fields);
404
405
  }
405
406
  }
@@ -678,7 +679,7 @@ class PluginsManager {
678
679
  'Native controllers cannot be overriden');
679
680
  }
680
681
 
681
- await Plugin.checkControllerDefinition(controller, definition);
682
+ Plugin.checkControllerDefinition(controller, definition);
682
683
 
683
684
  for (const [action, actionDefinition ] of Object.entries(definition.actions)) {
684
685
  let apiController = this.controllers.get(controller);
@@ -741,7 +742,7 @@ class PluginsManager {
741
742
  */
742
743
  _initControllers (plugin) {
743
744
  // @deprecated - warn about using the obsolete "controllers" object
744
- if (!_.isEmpty(plugin.instance.controllers)) {
745
+ if (! _.isEmpty(plugin.instance.controllers)) {
745
746
  plugin.printDeprecation('Defining controllers using the "controllers" object is deprecated. You should use the "api" object instead.');
746
747
  }
747
748
 
@@ -756,7 +757,7 @@ class PluginsManager {
756
757
  const definition = plugin.instance.controllers[controller];
757
758
  const errorControllerPrefix = `Unable to inject controller "${controller}" from plugin "${plugin.name}":`;
758
759
 
759
- if (!isPlainObject(definition)) {
760
+ if (! isPlainObject(definition)) {
760
761
  // @todo deprecate all those errors and use plugin.assert.invalid_controller_definition
761
762
  throw controllerError.get(
762
763
  'invalid_description',
@@ -809,7 +810,7 @@ class PluginsManager {
809
810
  const controllerNames = Object.keys(plugin.instance.controllers);
810
811
 
811
812
  // @deprecated - warn about using the obsolete "routes" object
812
- if (!_.isEmpty(plugin.instance.routes)) {
813
+ if (! _.isEmpty(plugin.instance.routes)) {
813
814
  plugin.printDeprecation('Defining routes using the "routes" object is deprecated. You should use the "api" object instead.');
814
815
  }
815
816
 
@@ -835,7 +836,7 @@ class PluginsManager {
835
836
 
836
837
  const apiController = this.controllers.get(controller);
837
838
 
838
- if (!apiController) {
839
+ if (! apiController) {
839
840
  throw controllerError.get(
840
841
  'undefined_controller',
841
842
  errorRoutePrefix,
@@ -843,7 +844,7 @@ class PluginsManager {
843
844
  didYouMean(route.controller, controllerNames));
844
845
  }
845
846
 
846
- if (!apiController._isAction(route.action)) {
847
+ if (! apiController._isAction(route.action)) {
847
848
  const actionNames = Array.from(apiController._actions);
848
849
  throw controllerError.get(
849
850
  'undefined_action',
@@ -898,7 +899,7 @@ class PluginsManager {
898
899
  * @throws {PluginImplementationError} If strategies registration fails
899
900
  */
900
901
  _initStrategies (plugin) {
901
- if ( !isPlainObject(plugin.instance.strategies)
902
+ if ( ! isPlainObject(plugin.instance.strategies)
902
903
  || _.isEmpty(plugin.instance.strategies)
903
904
  ) {
904
905
  throw strategyError.get('invalid_definition', plugin.logPrefix);
@@ -917,12 +918,12 @@ class PluginsManager {
917
918
  * @throws {PluginImplementationError} If strategies registration fails
918
919
  */
919
920
  _initAuthenticators (plugin) {
920
- if (!isPlainObject(plugin.instance.authenticators)) {
921
+ if (! isPlainObject(plugin.instance.authenticators)) {
921
922
  throw kerror.get('plugin', 'authenticators', 'not_an_object', plugin.logPrefix);
922
923
  }
923
924
 
924
925
  for (const authenticator of Object.keys(plugin.instance.authenticators)) {
925
- if (!isConstructor(plugin.instance.authenticators[authenticator])) {
926
+ if (! isConstructor(plugin.instance.authenticators[authenticator])) {
926
927
  throw kerror.get(
927
928
  'plugin',
928
929
  'authenticators',
@@ -1015,7 +1016,7 @@ class PluginsManager {
1015
1016
 
1016
1017
  // catching plugins returning non-thenable content
1017
1018
  // @todo - with async/await we might consider allowing non-promise results
1018
- if (!ret || !_.isFunction(ret.then)) {
1019
+ if (! ret || ! _.isFunction(ret.then)) {
1019
1020
  callback(strategyError.get('invalid_verify_return', prefix, ret));
1020
1021
  return;
1021
1022
  }
@@ -1031,11 +1032,11 @@ class PluginsManager {
1031
1032
  }
1032
1033
 
1033
1034
  if (result === false) {
1034
- callback(null, result, {message: null});
1035
+ callback(null, result, { message: null });
1035
1036
  return;
1036
1037
  }
1037
1038
 
1038
- if (!isPlainObject(result)) {
1039
+ if (! isPlainObject(result)) {
1039
1040
  callback(strategyError.get('invalid_verify_resolve', prefix));
1040
1041
  return;
1041
1042
  }
@@ -30,7 +30,7 @@
30
30
  * @param {string} message - Notification message
31
31
  */
32
32
  class ServerNotification {
33
- constructor(type, message) {
33
+ constructor (type, message) {
34
34
  this.status = 200;
35
35
  this.info = 'This is an automated server notification';
36
36
  this.message = message;
@@ -27,7 +27,7 @@
27
27
  * @class UserNotification
28
28
  */
29
29
  class UserNotification {
30
- constructor(opts) {
30
+ constructor (opts) {
31
31
  this.type = 'user';
32
32
 
33
33
  this.status = opts.status;
@@ -53,7 +53,7 @@ const KUZZLE_NOTIFICATION_CHANNEL = 'kuzzle:notification:server';
53
53
  * @class NotifierController
54
54
  */
55
55
  class NotifierController {
56
- constructor(realtimeModule) {
56
+ constructor (realtimeModule) {
57
57
  this.module = realtimeModule;
58
58
  this.ttl = global.kuzzle.config.limits.subscriptionDocumentTTL;
59
59
  }
@@ -267,7 +267,7 @@ class NotifierController {
267
267
  let cached = action === actionEnum.REPLACE || action === actionEnum.UPDATE;
268
268
 
269
269
  const cacheIds = documents.map(doc => {
270
- if ((action === actionEnum.WRITE || action === actionEnum.UPSERT) && !cached) {
270
+ if ((action === actionEnum.WRITE || action === actionEnum.UPSERT) && ! cached) {
271
271
  cached = doc.created !== true; // force a bool value if undefined
272
272
  }
273
273
 
@@ -414,7 +414,7 @@ class NotifierController {
414
414
  *
415
415
  * @returns {Promise}
416
416
  */
417
- _notifyDocument (rooms, notification, { fromCluster=true } = {}) {
417
+ _notifyDocument (rooms, notification, { fromCluster = true } = {}) {
418
418
  const channels = [];
419
419
 
420
420
  for (const room of rooms) {
@@ -452,7 +452,7 @@ class NotifierController {
452
452
  *
453
453
  * @returns {Promise}
454
454
  */
455
- _notifyUser (room, notification, { fromCluster=true } = {}) {
455
+ _notifyUser (room, notification, { fromCluster = true } = {}) {
456
456
  const channels = [];
457
457
  const hotelClerkRoom = this.module.hotelClerk.rooms.get(room);
458
458
 
@@ -493,7 +493,7 @@ class NotifierController {
493
493
  }
494
494
  }
495
495
 
496
- function getCachePrefix(request) {
496
+ function getCachePrefix (request) {
497
497
  // use redis key hash tag
498
498
  // (see https://redis.io/topics/cluster-spec#keys-distribution-model)
499
499
  return `{notif/${request.input.args.index}/${request.input.args.collection}}/`;
@@ -22,7 +22,7 @@
22
22
  'use strict';
23
23
 
24
24
  const RoleRepository = require('./roleRepository');
25
- const ProfileRepository = require('./profileRepository');
25
+ const { ProfileRepository } = require('./profileRepository');
26
26
  const TokenRepository = require('./tokenRepository');
27
27
  const UserRepository = require('./userRepository');
28
28
  const SecurityLoader = require('./securityLoader');