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
@@ -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');
@@ -0,0 +1,176 @@
1
+ /// <reference types="lodash" />
2
+ import { Profile } from '../../model/security/profile';
3
+ import Repository from '../shared/repository';
4
+ import { JSONObject } from 'kuzzle-sdk';
5
+ /** @internal */
6
+ declare type CreateOrReplaceOptions = {
7
+ method?: string;
8
+ refresh?: string;
9
+ strict?: boolean;
10
+ userId?: string;
11
+ };
12
+ /** @internal */
13
+ declare type ValidateAndSaveProfileOptions = {
14
+ method?: string;
15
+ refresh?: string;
16
+ strict?: boolean;
17
+ retryOnConflict?: number;
18
+ };
19
+ /** @internal */
20
+ declare type UpdateOptions = {
21
+ userId?: string;
22
+ refresh?: string;
23
+ strict?: boolean;
24
+ retryOnConflict?: number;
25
+ };
26
+ /**
27
+ * @class ProfileRepository
28
+ * @extends Repository
29
+ */
30
+ export declare class ProfileRepository extends Repository {
31
+ private module;
32
+ private profiles;
33
+ /**
34
+ * @constructor
35
+ */
36
+ constructor(securityModule: any);
37
+ init(): void;
38
+ /**
39
+ * Loads a Profile
40
+ *
41
+ * @param {string} id
42
+ * @returns {Promise.<Promise>}
43
+ * @throws {NotFoundError} If the corresponding profile doesn't exist
44
+ */
45
+ load(id: string): Promise<Profile>;
46
+ /**
47
+ * Loads a Profile object given its id.
48
+ * Stores the promise of the profile being loaded in the memcache
49
+ * and then replaces it by the profile itself once it has been loaded
50
+ *
51
+ * This is to allow parallelisation while preventing sending requests
52
+ * to ES, which is slow
53
+ *
54
+ * @param {Array} profileIds - Array of profiles ids
55
+ * @param {Object} options - resetCache (false)
56
+ *
57
+ * @returns {Promise} Resolves to the matching Profile object if found, null
58
+ * if not.
59
+ */
60
+ loadProfiles(profileIds?: string[]): Promise<Profile[]>;
61
+ /**
62
+ * @override
63
+ */
64
+ loadOneFromDatabase(id: string): Promise<Profile>;
65
+ /**
66
+ * Creates a new profile, or create/replace a profile
67
+ *
68
+ * @param {String} id
69
+ * @param {Object} policies
70
+ * @param {Object} [opts]
71
+ * @returns {Profile}
72
+ */
73
+ _createOrReplace(id: string, content: JSONObject, { method, refresh, strict, userId }?: CreateOrReplaceOptions): Promise<Profile>;
74
+ /**
75
+ * Creates a new profile
76
+ *
77
+ * @param {String} id
78
+ * @param {Object} content
79
+ * @param {Object} [opts]
80
+ * @returns {Profile}
81
+ */
82
+ create(id: string, content: JSONObject, opts?: JSONObject): Promise<Profile>;
83
+ /**
84
+ * Creates or replaces a profile
85
+ *
86
+ * @param {String} id
87
+ * @param {Object} content
88
+ * @param {Object} [opts]
89
+ * @returns {Profile}
90
+ */
91
+ createOrReplace(id: string, content: JSONObject, opts?: JSONObject): Promise<Profile>;
92
+ /**
93
+ * Updates a profile
94
+ * @param {String} id
95
+ * @param {Object} content
96
+ * @param {Object} [opts]
97
+ * @returns {Promise}
98
+ */
99
+ update(id: string, content: JSONObject, { refresh, retryOnConflict, strict, userId }?: UpdateOptions): Promise<Profile>;
100
+ /**
101
+ * Deletes a profile
102
+ *
103
+ * @param {String} id
104
+ * @param {object} [options]
105
+ * @returns {Promise}
106
+ */
107
+ deleteById(id: string, options?: JSONObject): Promise<void>;
108
+ /**
109
+ * @override
110
+ */
111
+ delete(profile: Profile, { refresh, onAssignedUsers, userId, }?: {
112
+ refresh?: string;
113
+ onAssignedUsers?: string;
114
+ userId?: string;
115
+ }): Promise<void>;
116
+ /**
117
+ * From a Profile object, returns a serialized object ready to be persisted
118
+ * to the database.
119
+ *
120
+ * @param {Profile} profile
121
+ * @returns {object}
122
+ */
123
+ serializeToDatabase(profile: Profile): import("lodash").Omit<Profile, "_id">;
124
+ /**
125
+ * Given a Profile object, validates its definition and if OK, persist it to the database.
126
+ *
127
+ * @param {Profile} profile
128
+ * @param {Object} [options]
129
+ * @param {string} [options.method] - Document persistence method
130
+ * @param {string} [options.refresh] - (Don't) wait for index refresh
131
+ * @param {number} [options.retryOnConflict] - Number of retries when an
132
+ * update fails due to a conflict
133
+ * @param {boolean} [options.strict] - if true, restrictions can only be
134
+ * applied on existing indexes/collections
135
+ * @returns {Promise<Profile>}
136
+ **/
137
+ validateAndSaveProfile(profile: Profile, { method, refresh, retryOnConflict, strict }?: ValidateAndSaveProfileOptions): Promise<Profile>;
138
+ /**
139
+ * @param {object} dto
140
+ * @returns {Promise<Profile>}
141
+ */
142
+ fromDTO(dto: JSONObject): Promise<Profile>;
143
+ /**
144
+ * @override
145
+ */
146
+ truncate(opts: JSONObject): Promise<void>;
147
+ /**
148
+ * Invalidate the cache entries for the given profile. If none is provided,
149
+ * the entire cache is emptied.
150
+ * @param {string} [profileId]
151
+ */
152
+ invalidate(profileId?: string): void;
153
+ /**
154
+ * Optimize each policy to get a O(1) index access time
155
+ * and a O(log(n)) collection search time.
156
+ *
157
+ * - Deduplicate indexes using a map
158
+ * - Sort collections per index
159
+ * @param {Object[]} policies
160
+ */
161
+ private optimizePolicies;
162
+ /**
163
+ * Optimize a policy to get a O(1) index access time
164
+ * and a O(log(n)) collection search time.
165
+ *
166
+ * - Deduplicate indexes using a map
167
+ * - Sort collections per index
168
+ * @param policy
169
+ */
170
+ private optimizePolicy;
171
+ toDTO(dto: Profile): Promise<JSONObject>;
172
+ deleteFromDatabase(id: string, options: JSONObject): Promise<any>;
173
+ search(searchBody: JSONObject, options: JSONObject): Promise<any>;
174
+ scroll(id: string, ttl: number): Promise<any>;
175
+ }
176
+ export {};