kuzzle 2.16.10 → 2.17.1

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 (186) hide show
  1. package/lib/api/controllers/adminController.js +3 -3
  2. package/lib/api/controllers/authController.js +12 -12
  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 +50 -50
  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 +8 -6
  38. package/lib/cluster/node.js +9 -9
  39. package/lib/cluster/publisher.js +1 -1
  40. package/lib/cluster/state.js +20 -4
  41. package/lib/cluster/subscriber.js +1 -1
  42. package/lib/cluster/workers/IDCardRenewer.js +2 -2
  43. package/lib/config/default.config.js +1 -0
  44. package/lib/config/index.js +6 -6
  45. package/lib/core/auth/passportResponse.js +6 -6
  46. package/lib/core/auth/passportWrapper.js +5 -5
  47. package/lib/core/backend/backend.d.ts +11 -3
  48. package/lib/core/backend/backend.js +22 -17
  49. package/lib/core/backend/backendConfig.d.ts +5 -1
  50. package/lib/core/backend/backendConfig.js +25 -2
  51. package/lib/core/backend/backendController.js +21 -5
  52. package/lib/core/backend/backendErrors.d.ts +58 -0
  53. package/lib/core/backend/backendErrors.js +121 -0
  54. package/lib/core/backend/backendHook.js +21 -5
  55. package/lib/core/backend/backendImport.js +21 -5
  56. package/lib/core/backend/backendOpenApi.d.ts +9 -0
  57. package/lib/core/backend/backendOpenApi.js +69 -0
  58. package/lib/core/backend/backendPipe.js +21 -5
  59. package/lib/core/backend/backendPlugin.js +22 -3
  60. package/lib/core/backend/backendVault.js +21 -2
  61. package/lib/core/backend/index.d.ts +2 -0
  62. package/lib/core/backend/index.js +2 -0
  63. package/lib/core/network/accessLogger.js +6 -6
  64. package/lib/core/network/clientConnection.js +1 -1
  65. package/lib/core/network/entryPoint.js +5 -5
  66. package/lib/core/network/httpRouter/index.js +5 -5
  67. package/lib/core/network/httpRouter/routeHandler.js +3 -3
  68. package/lib/core/network/httpRouter/routePart.js +5 -5
  69. package/lib/core/network/protocolManifest.js +1 -1
  70. package/lib/core/network/protocols/httpMessage.js +2 -2
  71. package/lib/core/network/protocols/httpwsProtocol.js +222 -48
  72. package/lib/core/network/protocols/mqttProtocol.js +3 -3
  73. package/lib/core/network/protocols/protocol.js +3 -3
  74. package/lib/core/network/router.js +7 -6
  75. package/lib/core/plugin/plugin.js +38 -64
  76. package/lib/core/plugin/pluginContext.js +22 -3
  77. package/lib/core/plugin/pluginManifest.js +3 -3
  78. package/lib/core/plugin/pluginRepository.js +5 -5
  79. package/lib/core/plugin/pluginsManager.js +29 -28
  80. package/lib/core/realtime/channel.js +20 -4
  81. package/lib/core/realtime/hotelClerk.js +24 -5
  82. package/lib/core/realtime/notification/server.js +1 -1
  83. package/lib/core/realtime/notification/user.js +1 -1
  84. package/lib/core/realtime/notifier.js +5 -5
  85. package/lib/core/security/index.js +1 -1
  86. package/lib/core/security/profileRepository.d.ts +176 -0
  87. package/lib/core/security/profileRepository.js +445 -443
  88. package/lib/core/security/roleRepository.js +16 -16
  89. package/lib/core/security/securityLoader.js +2 -2
  90. package/lib/core/security/tokenRepository.js +11 -11
  91. package/lib/core/security/userRepository.js +8 -8
  92. package/lib/core/shared/abstractManifest.js +4 -4
  93. package/lib/core/shared/repository.js +5 -5
  94. package/lib/core/shared/sdk/embeddedSdk.js +21 -2
  95. package/lib/core/shared/sdk/funnelProtocol.js +1 -1
  96. package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
  97. package/lib/core/shared/store.js +30 -23
  98. package/lib/core/statistics/statistics.js +17 -17
  99. package/lib/core/storage/clientAdapter.js +45 -10
  100. package/lib/core/storage/indexCache.js +20 -4
  101. package/lib/core/validation/baseType.js +5 -5
  102. package/lib/core/validation/types/anything.js +1 -1
  103. package/lib/core/validation/types/boolean.js +2 -2
  104. package/lib/core/validation/types/date.js +9 -9
  105. package/lib/core/validation/types/email.js +5 -5
  106. package/lib/core/validation/types/enum.js +6 -6
  107. package/lib/core/validation/types/geoPoint.js +2 -2
  108. package/lib/core/validation/types/geoShape.js +28 -25
  109. package/lib/core/validation/types/integer.js +4 -4
  110. package/lib/core/validation/types/ipAddress.js +7 -6
  111. package/lib/core/validation/types/numeric.js +4 -4
  112. package/lib/core/validation/types/object.js +5 -5
  113. package/lib/core/validation/types/string.js +5 -5
  114. package/lib/core/validation/types/url.js +7 -6
  115. package/lib/core/validation/validation.js +95 -84
  116. package/lib/kerror/codes/1-services.json +12 -0
  117. package/lib/kerror/codes/2-api.json +12 -0
  118. package/lib/kerror/codes/3-network.json +12 -0
  119. package/lib/kerror/codes/4-plugin.json +6 -0
  120. package/lib/kerror/codes/index.js +11 -11
  121. package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
  122. package/lib/kerror/errors/multipleErrorsError.js +3 -3
  123. package/lib/kerror/index.d.ts +82 -0
  124. package/lib/kerror/index.js +176 -143
  125. package/lib/kuzzle/dumpGenerator.js +3 -3
  126. package/lib/kuzzle/event/kuzzleEventEmitter.js +4 -4
  127. package/lib/kuzzle/event/pipeRunner.js +1 -1
  128. package/lib/kuzzle/event/waterfall.js +6 -6
  129. package/lib/kuzzle/kuzzle.js +59 -9
  130. package/lib/kuzzle/log.js +3 -3
  131. package/lib/kuzzle/vault.js +3 -3
  132. package/lib/model/security/profile.d.ts +54 -0
  133. package/lib/model/security/profile.js +192 -232
  134. package/lib/model/security/rights.js +1 -1
  135. package/lib/model/security/role.d.ts +40 -0
  136. package/lib/model/security/role.js +174 -190
  137. package/lib/model/security/user.d.ts +29 -0
  138. package/lib/model/security/user.js +103 -52
  139. package/lib/model/storage/apiKey.js +2 -2
  140. package/lib/model/storage/baseModel.js +3 -3
  141. package/lib/service/cache/redis.js +7 -7
  142. package/lib/service/storage/elasticsearch.js +152 -90
  143. package/lib/service/storage/esWrapper.js +2 -3
  144. package/lib/types/ControllerDefinition.d.ts +3 -3
  145. package/lib/types/ControllerRights.d.ts +22 -0
  146. package/lib/types/ControllerRights.js +23 -0
  147. package/lib/types/HttpStream.d.ts +32 -0
  148. package/lib/types/HttpStream.js +70 -0
  149. package/lib/types/OpenApiDefinition.d.ts +43 -0
  150. package/lib/types/{config/StorageService/StorageServiceElasticsearchConfiguration.js → OpenApiDefinition.js} +1 -1
  151. package/lib/types/Plugin.js +20 -4
  152. package/lib/types/Policy.d.ts +25 -0
  153. package/lib/types/Policy.js +23 -0
  154. package/lib/types/PolicyRestrictions.d.ts +21 -0
  155. package/lib/types/PolicyRestrictions.js +23 -0
  156. package/lib/types/Target.d.ts +15 -0
  157. package/lib/types/Target.js +23 -0
  158. package/lib/types/config/KuzzleConfiguration.d.ts +4 -0
  159. package/lib/types/config/ServicesConfiguration.d.ts +2 -2
  160. package/lib/types/config/{StorageService/StorageServiceElasticsearchConfiguration.d.ts → storageEngine/StorageEngineElasticsearchConfiguration.d.ts} +10 -3
  161. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +3 -0
  162. package/lib/types/errors/ErrorDefinition.d.ts +27 -0
  163. package/lib/types/errors/ErrorDefinition.js +3 -0
  164. package/lib/types/errors/ErrorDomains.d.ts +17 -0
  165. package/lib/types/errors/ErrorDomains.js +3 -0
  166. package/lib/types/index.d.ts +9 -1
  167. package/lib/types/index.js +9 -1
  168. package/lib/util/array.d.ts +11 -0
  169. package/lib/util/array.js +57 -0
  170. package/lib/util/assertType.js +6 -6
  171. package/lib/util/bufferedPassThrough.d.ts +76 -0
  172. package/lib/util/bufferedPassThrough.js +161 -0
  173. package/lib/util/deprecate.js +7 -5
  174. package/lib/util/didYouMean.js +1 -1
  175. package/lib/util/dump-collection.d.ts +3 -0
  176. package/lib/util/dump-collection.js +284 -0
  177. package/lib/util/extractFields.js +2 -2
  178. package/lib/util/inflector.d.ts +8 -0
  179. package/lib/util/inflector.js +16 -0
  180. package/lib/util/mutex.js +21 -2
  181. package/lib/util/requestAssertions.js +7 -7
  182. package/lib/util/wildcard.js +55 -0
  183. package/package-lock.json +517 -75
  184. package/package.json +5 -3
  185. package/lib/api/openApiGenerator.d.ts +0 -7
  186. package/lib/api/openApiGenerator.js +0 -197
@@ -28,7 +28,7 @@ class WaterfallContext {
28
28
  * @param {Function} cb - end of waterfall callback
29
29
  * @param {Object} cbCtx - functions context
30
30
  */
31
- constructor(chain, args, cb, cbCtx) {
31
+ constructor (chain, args, cb, cbCtx) {
32
32
  this.chain = chain;
33
33
  this.cb = cb;
34
34
  this.cbCtx = cbCtx;
@@ -55,7 +55,7 @@ class WaterfallContext {
55
55
 
56
56
  next (cb) {
57
57
  this.index++;
58
- this.chain[this.index-1](...this.args, cb);
58
+ this.chain[this.index - 1](...this.args, cb);
59
59
  }
60
60
 
61
61
  reject (error) {
@@ -69,7 +69,7 @@ class WaterfallContext {
69
69
  }
70
70
 
71
71
  /* eslint-disable no-invalid-this */
72
- function waterfallCB(err, res) {
72
+ function waterfallCB (err, res) {
73
73
  if (err) {
74
74
  this.reject(err);
75
75
  }
@@ -80,8 +80,8 @@ function waterfallCB(err, res) {
80
80
  }
81
81
  /* eslint-enable no-invalid-this */
82
82
 
83
- function waterfallNext(ctx) {
84
- if (!ctx.hasNext()) {
83
+ function waterfallNext (ctx) {
84
+ if (! ctx.hasNext()) {
85
85
  ctx.resolve();
86
86
  return;
87
87
  }
@@ -94,7 +94,7 @@ function waterfallNext(ctx) {
94
94
  }
95
95
  }
96
96
 
97
- function waterfall(chain, args, cb, context) {
97
+ function waterfall (chain, args, cb, context) {
98
98
  const ctx = new WaterfallContext(chain, args, cb, context);
99
99
 
100
100
  waterfallNext(ctx);
@@ -19,6 +19,25 @@
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
25
+ }) : (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ o[k2] = m[k];
28
+ }));
29
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
30
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
31
+ }) : function(o, v) {
32
+ o["default"] = v;
33
+ });
34
+ var __importStar = (this && this.__importStar) || function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
22
41
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
42
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
43
  };
@@ -45,7 +64,7 @@ const vault_1 = __importDefault(require("./vault"));
45
64
  const dumpGenerator_1 = __importDefault(require("./dumpGenerator"));
46
65
  const asyncStore_1 = __importDefault(require("../util/asyncStore"));
47
66
  const mutex_1 = require("../util/mutex");
48
- const kerror_1 = __importDefault(require("../kerror"));
67
+ const kerror = __importStar(require("../kerror"));
49
68
  const internalIndexHandler_1 = __importDefault(require("./internalIndexHandler"));
50
69
  const cacheEngine_1 = __importDefault(require("../core/cache/cacheEngine"));
51
70
  const storageEngine_1 = __importDefault(require("../core/storage/storageEngine"));
@@ -53,6 +72,8 @@ const security_1 = __importDefault(require("../core/security"));
53
72
  const realtime_1 = __importDefault(require("../core/realtime"));
54
73
  const cluster_1 = __importDefault(require("../cluster"));
55
74
  const package_json_1 = require("../../package.json");
75
+ const name_generator_1 = require("../util/name-generator");
76
+ const openapi_1 = require("../api/openapi");
56
77
  const BACKEND_IMPORT_KEY = 'backend:init:import';
57
78
  let _kuzzle = null;
58
79
  Reflect.defineProperty(global, 'kuzzle', {
@@ -103,7 +124,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
103
124
  /**
104
125
  * Initializes all the needed components of Kuzzle.
105
126
  *
106
- * @param {Application} - Application instance
127
+ * @param {Application} - Application Plugin instance
107
128
  * @param {Object} - Additional options (import, installations, plugins, secretsFile, support, vaultKey)
108
129
  *
109
130
  * @this {Kuzzle}
@@ -124,7 +145,8 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
124
145
  await (new realtime_1.default()).init();
125
146
  await this.internalIndex.init();
126
147
  await (new security_1.default()).init();
127
- this.id = await (new cluster_1.default()).init();
148
+ // This will init the cluster module if enabled
149
+ this.id = await this.initKuzzleNode();
128
150
  // Secret used to generate JWTs
129
151
  this.secret = await this.internalIndex.getSecret();
130
152
  this.vault = vault_1.default.load(options.vaultKey, options.secretsFile);
@@ -141,11 +163,13 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
141
163
  this.log.info(`[✔] Successfully loaded ${this.pluginsManager.loadedPlugins.length} plugins: ${this.pluginsManager.loadedPlugins.join(', ')}`);
142
164
  // Authentification plugins must be loaded before users import to avoid
143
165
  // credentials related error which would prevent Kuzzle from starting
144
- await this.import(options.import, options.support);
166
+ await this.loadInitialState(options.import, options.support);
145
167
  await this.ask('core:security:verify');
146
168
  this.router.init();
147
169
  this.log.info('[✔] Core components loaded');
148
170
  await this.install(options.installations);
171
+ this.log.info(`[✔] Start "${this.pluginsManager.application.name}" application`);
172
+ this.openApiManager = new openapi_1.OpenApiManager(application.openApi, this.config.http.routes, this.pluginsManager.routes);
149
173
  // @deprecated
150
174
  await this.pipe('kuzzle:start');
151
175
  await this.pipe('kuzzle:state:live');
@@ -161,6 +185,23 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
161
185
  throw error;
162
186
  }
163
187
  }
188
+ /**
189
+ * Generates the node ID.
190
+ *
191
+ * This will init the cluster if it's enabled.
192
+ */
193
+ async initKuzzleNode() {
194
+ let id;
195
+ if (this.config.cluster.enabled) {
196
+ id = await (new cluster_1.default()).init();
197
+ this.log.info('[✔] Cluster initialized');
198
+ }
199
+ else {
200
+ id = (0, name_generator_1.generateRandomName)('knode');
201
+ this.log.info('[X] Cluster disabled: single node mode.');
202
+ }
203
+ return id;
204
+ }
164
205
  /**
165
206
  * Gracefully exits after processing remaining requests
166
207
  *
@@ -202,7 +243,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
202
243
  await installation.handler();
203
244
  }
204
245
  catch (error) {
205
- throw kerror_1.default.get('plugin', 'runtime', 'unexpected_installation_error', installation.id, error);
246
+ throw kerror.get('plugin', 'runtime', 'unexpected_installation_error', installation.id, error);
206
247
  }
207
248
  await this.ask('core:storage:private:document:create', 'kuzzle', 'installations', {
208
249
  description: installation.description,
@@ -244,7 +285,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
244
285
  const toImport = config.toImport;
245
286
  const toSupport = config.toSupport;
246
287
  if (!lodash_1.default.isEmpty(toSupport.mappings) && !lodash_1.default.isEmpty(toImport.mappings)) {
247
- throw kerror_1.default.get('plugin', 'runtime', 'incompatible', '_support.mappings', 'import.mappings');
288
+ throw kerror.get('plugin', 'runtime', 'incompatible', '_support.mappings', 'import.mappings');
248
289
  }
249
290
  else if (!lodash_1.default.isEmpty(toSupport.mappings)) {
250
291
  await this.ask('core:storage:public:mappings:import', toSupport.mappings, {
@@ -296,7 +337,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
296
337
  && lodash_1.default.isEmpty(toSupport.securities.roles)
297
338
  && lodash_1.default.isEmpty(toSupport.securities.users));
298
339
  if (isPermissionsToSupport && isPermissionsToImport) {
299
- throw kerror_1.default.get('plugin', 'runtime', 'incompatible', '_support.securities', 'import profiles roles or users');
340
+ throw kerror.get('plugin', 'runtime', 'incompatible', '_support.securities', 'import profiles roles or users');
300
341
  }
301
342
  else if (isPermissionsToSupport) {
302
343
  await this.ask('core:security:load', toSupport.securities, {
@@ -340,7 +381,17 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
340
381
  *
341
382
  * @returns {Promise<void>}
342
383
  */
343
- async import(toImport = {}, toSupport = {}) {
384
+ async loadInitialState(toImport = {}, toSupport = {}) {
385
+ if (lodash_1.default.isEmpty(toImport.mappings)
386
+ && lodash_1.default.isEmpty(toImport.profiles)
387
+ && lodash_1.default.isEmpty(toImport.roles)
388
+ && lodash_1.default.isEmpty(toImport.userMappings)
389
+ && lodash_1.default.isEmpty(toImport.users)
390
+ && lodash_1.default.isEmpty(toSupport.fixtures)
391
+ && lodash_1.default.isEmpty(toSupport.mappings)
392
+ && lodash_1.default.isEmpty(toSupport.securities)) {
393
+ return;
394
+ }
344
395
  const lockedMutex = [];
345
396
  try {
346
397
  for (const [type, importMethod] of Object.entries(this.importTypes)) {
@@ -357,7 +408,6 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
357
408
  await this.ask('core:cache:internal:store', `${BACKEND_IMPORT_KEY}:${type}`, 1, { ttl: 5 * 60 * 1000 });
358
409
  }
359
410
  }
360
- this.log.info('[✔] Waiting for imports to be finished');
361
411
  await this._waitForImportToFinish();
362
412
  this.log.info('[✔] Import successful');
363
413
  }
package/lib/kuzzle/log.js CHANGED
@@ -22,7 +22,7 @@
22
22
  'use strict';
23
23
 
24
24
  class Logger {
25
- constructor() {
25
+ constructor () {
26
26
  this.logMethods = ['info', 'warn', 'error', 'silly', 'debug', 'verbose'];
27
27
 
28
28
  this.failsafeModeString = global.kuzzle.config.plugins.common.failsafeMode
@@ -34,7 +34,7 @@ class Logger {
34
34
  global.kuzzle.once('core:kuzzleStart', this._useLogger.bind(this));
35
35
  }
36
36
 
37
- _useConsole() {
37
+ _useConsole () {
38
38
  // until kuzzle has started, use the console to print logs
39
39
  for (const method of this.logMethods) {
40
40
  this[method] = message => {
@@ -46,7 +46,7 @@ class Logger {
46
46
  }
47
47
  }
48
48
 
49
- _useLogger() {
49
+ _useLogger () {
50
50
 
51
51
  // when kuzzle has started, use the event to dispatch logs
52
52
  for (const method of this.logMethods) {
@@ -38,7 +38,7 @@ function load (vaultKey, secretsFile) {
38
38
  secretsFile || process.env.KUZZLE_SECRETS_FILE || defaultEncryptedSecretsFile;
39
39
 
40
40
  let key = vaultKey;
41
- if (_.isEmpty(vaultKey) && !_.isEmpty(process.env.KUZZLE_VAULT_KEY)) {
41
+ if (_.isEmpty(vaultKey) && ! _.isEmpty(process.env.KUZZLE_VAULT_KEY)) {
42
42
  key = process.env.KUZZLE_VAULT_KEY;
43
43
  }
44
44
 
@@ -53,13 +53,13 @@ function load (vaultKey, secretsFile) {
53
53
  // Abort if a secret file is found (default or custom)
54
54
  // but no vault key has been provided
55
55
  assert(
56
- !(fileExists && _.isEmpty(key)),
56
+ ! (fileExists && _.isEmpty(key)),
57
57
  'A secret file has been provided but Kuzzle cannot find the Vault key. Aborting.');
58
58
 
59
59
  // Abort if a vault key has been provided
60
60
  // but no secrets file can be loaded (default or custom)
61
61
  assert(
62
- !(! _.isEmpty(key) && ! fileExists),
62
+ ! (! _.isEmpty(key) && ! fileExists),
63
63
  `A Vault key is present but Kuzzle cannot find the secret file at "${encryptedSecretsFile}". Aborting.`);
64
64
 
65
65
  const vault = new Vault(key);
@@ -0,0 +1,54 @@
1
+ import { Policy, OptimizedPolicy, OptimizedPolicyRestrictions } from '../../types/index';
2
+ import { Role } from './role';
3
+ import { KuzzleRequest } from '../../../index';
4
+ /** @internal */
5
+ declare type InternalProfilePolicy = {
6
+ role: Role;
7
+ restrictedTo: OptimizedPolicyRestrictions;
8
+ };
9
+ /**
10
+ * @class Profile
11
+ */
12
+ export declare class Profile {
13
+ _id: string;
14
+ policies: Policy[];
15
+ optimizedPolicies: OptimizedPolicy[];
16
+ rateLimit: number;
17
+ constructor();
18
+ /**
19
+ * @param {Kuzzle} kuzzle
20
+ *
21
+ * @returns {Promise}
22
+ */
23
+ getPolicies(): Promise<InternalProfilePolicy[]>;
24
+ /**
25
+ * @param {Request} request
26
+ * @returns {Promise}
27
+ */
28
+ getAllowedPolicies(request: KuzzleRequest): Promise<InternalProfilePolicy[]>;
29
+ /**
30
+ * @param {Request} request
31
+ * @returns {Promise<boolean>}
32
+ */
33
+ isActionAllowed(request: KuzzleRequest): Promise<boolean>;
34
+ /**
35
+ * Validates the Profile format
36
+ *
37
+ * @param {Object} [options]
38
+ * @param {boolean} [options.strict] - If true, only allows resctrictions on
39
+ * existing indexes/collections
40
+ * @returns {Promise}
41
+ */
42
+ validateDefinition({ strict }?: {
43
+ strict?: boolean;
44
+ }): Promise<boolean>;
45
+ /**
46
+ * Resolves an array of rights related to the profile's roles.
47
+ *
48
+ * @returns {Promise}
49
+ */
50
+ getRights(): Promise<{}>;
51
+ static _hash(): boolean;
52
+ validateRateLimit(): void;
53
+ }
54
+ export {};