kuzzle 2.16.11 → 2.17.2

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 (187) 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 +44 -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 +228 -50
  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/{InternalLogger.js → Policy.js} +2 -2
  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 +535 -75
  184. package/package.json +5 -3
  185. package/lib/api/openApiGenerator.d.ts +0 -7
  186. package/lib/api/openApiGenerator.js +0 -197
  187. package/lib/types/InternalLogger.d.ts +0 -25
@@ -0,0 +1,133 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateOpenApi = void 0;
27
+ const lodash_1 = __importDefault(require("lodash"));
28
+ const inflector_1 = require("../../util/inflector");
29
+ const routeUrlMatch = /:([^/]*)/g;
30
+ /**
31
+ * Generate basic openApi Controller
32
+ */
33
+ function generateController(route, definition) {
34
+ if (route.controller === undefined) {
35
+ return;
36
+ }
37
+ if (!lodash_1.default.some(definition.tags, { name: route.controller })) {
38
+ const capitalizedController = inflector_1.Inflector.pascalCase(route.controller);
39
+ definition.tags.push({
40
+ description: `${capitalizedController} Controller`,
41
+ name: route.controller
42
+ });
43
+ }
44
+ if (route.openapi.tags === undefined) {
45
+ route.openapi.tags = [];
46
+ }
47
+ if (!route.openapi.tags.includes(route.controller)) {
48
+ route.openapi.tags.push(route.controller);
49
+ }
50
+ }
51
+ /**
52
+ * Generate basic openApi Summary
53
+ */
54
+ function generateSummary(route) {
55
+ if (route.openapi.description === undefined) {
56
+ route.openapi.description = `Controller: ${route.controller}.`;
57
+ }
58
+ if (route.openapi.summary === undefined) {
59
+ route.openapi.summary = `Action: ${route.action}.`;
60
+ }
61
+ }
62
+ /**
63
+ * Generate basic openApi Parameters
64
+ */
65
+ function generateParameters(route) {
66
+ if (route.openapi.parameters === undefined) {
67
+ route.openapi.parameters = [];
68
+ let m = routeUrlMatch.exec(route.path);
69
+ while (m !== null) {
70
+ routeUrlMatch.lastIndex++;
71
+ route.openapi.parameters.push({
72
+ in: 'path',
73
+ name: m[1],
74
+ required: true,
75
+ schema: { type: 'string' }
76
+ });
77
+ m = routeUrlMatch.exec(route.path);
78
+ }
79
+ }
80
+ if (route.openapi.parameters.length === 0) {
81
+ route.openapi.parameters = undefined;
82
+ }
83
+ }
84
+ /**
85
+ * Generate basic openApi Response
86
+ */
87
+ function generateResponse(route) {
88
+ if (route.openapi.responses === undefined) {
89
+ route.openapi.responses = {
90
+ '200': {
91
+ description: 'OK'
92
+ }
93
+ };
94
+ }
95
+ }
96
+ /**
97
+ * Generates JSON OpenApi object
98
+ *
99
+ * @returns {object} openApi object
100
+ */
101
+ function generateOpenApi(routes, definition) {
102
+ for (const route of routes) {
103
+ // Make sure route verbs are lowercase
104
+ if (route.verb !== undefined) {
105
+ route.verb = route.verb.toLowerCase();
106
+ }
107
+ // Set :param notation to {param}
108
+ route.formattedPath = route.path.replace(routeUrlMatch, '{$1}');
109
+ if (definition.paths[route.formattedPath] === undefined) {
110
+ definition.paths[route.formattedPath] = {};
111
+ }
112
+ if (definition.paths[route.formattedPath][route.verb] !== undefined) {
113
+ continue;
114
+ }
115
+ // If custom specification, return as it is
116
+ if (route.openapi) {
117
+ generateController(route, definition);
118
+ definition.paths[route.formattedPath][route.verb] = route.openapi;
119
+ continue;
120
+ }
121
+ if (route.openapi === undefined) {
122
+ route.openapi = {};
123
+ }
124
+ generateController(route, definition);
125
+ generateSummary(route);
126
+ generateParameters(route);
127
+ generateResponse(route);
128
+ definition.paths[route.formattedPath][route.verb] = route.openapi;
129
+ }
130
+ return definition;
131
+ }
132
+ exports.generateOpenApi = generateOpenApi;
133
+ //# sourceMappingURL=openApiGenerator.js.map
@@ -38,9 +38,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
38
38
  __setModuleDefault(result, mod);
39
39
  return result;
40
40
  };
41
- var __importDefault = (this && this.__importDefault) || function (mod) {
42
- return (mod && mod.__esModule) ? mod : { "default": mod };
43
- };
44
41
  Object.defineProperty(exports, "__esModule", { value: true });
45
42
  exports.Request = exports.KuzzleRequest = void 0;
46
43
  const uuid = __importStar(require("uuid"));
@@ -49,11 +46,12 @@ const requestInput_1 = require("./requestInput");
49
46
  const requestResponse_1 = require("./requestResponse");
50
47
  const requestContext_1 = require("./requestContext");
51
48
  const errors_1 = require("../../kerror/errors");
52
- const kerror_1 = __importDefault(require("../../kerror"));
49
+ const kerror = __importStar(require("../../kerror"));
50
+ const types_1 = require("../../types");
53
51
  const assert = __importStar(require("../../util/assertType"));
54
52
  const safeObject_1 = require("../../util/safeObject");
55
53
  const lodash_1 = require("lodash");
56
- const assertionError = kerror_1.default.wrap('api', 'assert');
54
+ const assertionError = kerror.wrap('api', 'assert');
57
55
  // private properties
58
56
  // \u200b is a zero width space, used to masquerade console.log output
59
57
  const _internalId = 'internalId\u200b';
@@ -217,6 +215,9 @@ class KuzzleRequest {
217
215
  if (result instanceof Error) {
218
216
  throw new errors_1.InternalError('cannot set an error as a request\'s response');
219
217
  }
218
+ if (this.context.connection.protocol !== 'http' && result instanceof types_1.HttpStream) {
219
+ throw kerror.get('api', 'assert', 'forbidden_stream');
220
+ }
220
221
  this.status = options.status || 200;
221
222
  if (options.headers) {
222
223
  this.response.setHeaders(options.headers);
@@ -320,7 +321,7 @@ class KuzzleRequest {
320
321
  getLangParam() {
321
322
  const lang = this.getString('lang', 'elasticsearch');
322
323
  if (lang !== 'elasticsearch' && lang !== 'koncorde') {
323
- throw kerror_1.default.get('api', 'assert', 'invalid_argument', 'lang', '"elasticsearch" or "koncorde"');
324
+ throw kerror.get('api', 'assert', 'invalid_argument', 'lang', '"elasticsearch" or "koncorde"');
324
325
  }
325
326
  return lang;
326
327
  }
@@ -585,6 +586,7 @@ class KuzzleRequest {
585
586
  */
586
587
  getId(options = { generator: uuid.v4, ifMissing: 'error' }) {
587
588
  const id = this.input.args._id;
589
+ options.generator = options.generator || uuid.v4; // Default to uuid v4
588
590
  if (!id) {
589
591
  if (options.ifMissing === 'generate') {
590
592
  return options.generator();
@@ -110,10 +110,10 @@ function getIP ({ family = 'IPv4', interface: netInterface, ip } = {}) {
110
110
  debug('Found interfaces %o', interfaces);
111
111
 
112
112
  interfaces = interfaces.filter(n => {
113
- return !n.internal
114
- && !isInternalIP(n.address)
113
+ return ! n.internal
114
+ && ! isInternalIP(n.address)
115
115
  && n.family === family
116
- && (!ip || mustBePrivate === isPrivateIP(n.address));
116
+ && (! ip || mustBePrivate === isPrivateIP(n.address));
117
117
  });
118
118
 
119
119
  debug('Filtered interfaces %o', interfaces);
@@ -123,7 +123,7 @@ function getIP ({ family = 'IPv4', interface: netInterface, ip } = {}) {
123
123
  }
124
124
 
125
125
  // take the first IP from the list if no interface has been defined
126
- if (!netInterface) {
126
+ if (! netInterface) {
127
127
  return interfaces[0].address;
128
128
  }
129
129
 
@@ -298,7 +298,7 @@ class ClusterNode {
298
298
  async evictNode (nodeId, { broadcast = false, reason = '' }) {
299
299
  const subscriber = this.remoteNodes.get(nodeId);
300
300
 
301
- if (!subscriber) {
301
+ if (! subscriber) {
302
302
  return;
303
303
  }
304
304
 
@@ -358,7 +358,7 @@ class ClusterNode {
358
358
  return split.every((id, index) => id === topology[index]);
359
359
  });
360
360
 
361
- if (!found) {
361
+ if (! found) {
362
362
  splits.push(topology);
363
363
  }
364
364
  }
@@ -415,13 +415,13 @@ class ClusterNode {
415
415
 
416
416
  for (let i = 0; i < isolatedNodes.length; i++) {
417
417
  const idCard = idCards.find(card => card.id === isolatedNodes[i]);
418
- if (!youngestNode || idCard.birthdate > youngestNode.birthdate) {
418
+ if (! youngestNode || idCard.birthdate > youngestNode.birthdate) {
419
419
  youngestNode = idCard;
420
420
  }
421
421
  }
422
422
 
423
423
  if (isIsolated) {
424
- for (let i = 0; !candidates && i < eligibleSplits.length; i++) {
424
+ for (let i = 0; ! candidates && i < eligibleSplits.length; i++) {
425
425
  if (eligibleSplits[i].includes(youngestNode.id)) {
426
426
  candidates = _.intersection(eligibleSplits[i], isolatedNodes);
427
427
  }
@@ -621,7 +621,7 @@ class ClusterNode {
621
621
  async getStatus () {
622
622
  const status = {
623
623
  activeNodes: 0,
624
- activity: this.activity.map(({address, date, event, id, reason}) => ({
624
+ activity: this.activity.map(({ address, date, event, id, reason }) => ({
625
625
  address,
626
626
  date,
627
627
  event: event === nodeActivityEnum.ADDED ? 'joined' : 'evicted',
@@ -337,7 +337,7 @@ class ClusterPublisher {
337
337
  * @return {void}
338
338
  */
339
339
  async bufferSend (topic, data) {
340
- this.buffer.push({data, topic});
340
+ this.buffer.push({ data, topic });
341
341
 
342
342
  if (this.state === STATE.SENDING) {
343
343
  return;
@@ -19,15 +19,31 @@
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
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;
24
40
  };
25
41
  Object.defineProperty(exports, "__esModule", { value: true });
26
42
  const koncorde_1 = require("koncorde");
27
- const kerror_1 = __importDefault(require("../kerror"));
43
+ const kerror = __importStar(require("../kerror"));
28
44
  require("../types/Global");
29
45
  const koncordeCompat_1 = require("../util/koncordeCompat");
30
- const errorFatal = kerror_1.default.wrap('cluster', 'fatal');
46
+ const errorFatal = kerror.wrap('cluster', 'fatal');
31
47
  /**
32
48
  * Private class aiming at maintaining both the number of a node's subscriptions
33
49
  * to a room, and the node's last message ID to detect desyncs.
@@ -667,7 +667,7 @@ class ClusterSubscriber {
667
667
  * @return {boolean} false: the message must be discarded, true otherwise
668
668
  */
669
669
  async validateMessage (message) {
670
- if (!has(message, 'messageId')) {
670
+ if (! has(message, 'messageId')) {
671
671
  global.kuzzle.log.warn(`Invalid message received from node ${this.remoteNodeId}. Evicting it.`);
672
672
 
673
673
  await this.evictNode({
@@ -44,7 +44,7 @@ class IDCardRenewer {
44
44
  * which could be enough to make the ID Card expire.
45
45
  */
46
46
  await this.renewIDCard();
47
- if (!this.disposed) {
47
+ if (! this.disposed) {
48
48
  this.refreshTimer = setInterval(
49
49
  this.renewIDCard.bind(this),
50
50
  this.refreshDelay);
@@ -110,7 +110,7 @@ class IDCardRenewer {
110
110
  }
111
111
  }
112
112
 
113
- if (!isMainThread) {
113
+ if (! isMainThread) {
114
114
  const idCardRenewer = new IDCardRenewer();
115
115
 
116
116
  parentPort.on('message', async message => {
@@ -380,6 +380,7 @@ const defaultConfig = {
380
380
  statsInterval: 10
381
381
  },
382
382
  cluster: {
383
+ enabled: true,
383
384
  activityDepth: 50,
384
385
  heartbeat: 2000,
385
386
  interface: null,
@@ -80,7 +80,7 @@ function loadConfig () {
80
80
  */
81
81
  function unstringify (cfg) {
82
82
  Object.keys(cfg)
83
- .filter(k => !/version$/i.test(k) && (typeof cfg[k] === 'string' || cfg[k] instanceof Object))
83
+ .filter(k => ! /version$/i.test(k) && (typeof cfg[k] === 'string' || cfg[k] instanceof Object))
84
84
  .forEach(k => {
85
85
  if (typeof cfg[k] === 'string') {
86
86
  if (cfg[k] === 'true') {
@@ -138,7 +138,7 @@ function checkLimitsConfig (cfg) {
138
138
  'subscriptionDocumentTTL'
139
139
  ];
140
140
 
141
- if (!isPlainObject(cfg.limits)) {
141
+ if (! isPlainObject(cfg.limits)) {
142
142
  throw kerror.get('invalid_type', 'limits', 'object');
143
143
  }
144
144
 
@@ -148,7 +148,7 @@ function checkLimitsConfig (cfg) {
148
148
  }
149
149
 
150
150
  if ( cfg.limits[opt] < 0
151
- || cfg.limits[opt] === 0 && !canBeZero.includes(opt)
151
+ || cfg.limits[opt] === 0 && ! canBeZero.includes(opt)
152
152
  ) {
153
153
  const allowed = `>= ${canBeZero.includes(opt) ? '0' : '1'}`;
154
154
  throw kerror.get('out_of_range', `limits.${opt}`, allowed);
@@ -221,9 +221,9 @@ function checkClusterOptions (config) {
221
221
  if (`${cfg.ip}`.length === 0 || cfg.ip === 'null') {
222
222
  cfg.ip = null;
223
223
  }
224
- assert(!cfg.ip || ['private', 'public'].includes(cfg.ip), '[CONFIG] kuzzlerc.cluster.ip: invalid value (accepted values: public, private)');
224
+ assert(! cfg.ip || ['private', 'public'].includes(cfg.ip), '[CONFIG] kuzzlerc.cluster.ip: invalid value (accepted values: public, private)');
225
225
 
226
- assert(!cfg.interface || typeof cfg.interface === 'string', '[CONFIG] kuzzlerc.cluster.interface: value must be either null, or a string');
226
+ assert(! cfg.interface || typeof cfg.interface === 'string', '[CONFIG] kuzzlerc.cluster.interface: value must be either null, or a string');
227
227
  }
228
228
 
229
229
  function preprocessHttpOptions (config) {
@@ -251,7 +251,7 @@ function preprocessHttpOptions (config) {
251
251
  }
252
252
  }
253
253
 
254
- function preprocessProtocolsOptions(config) {
254
+ function preprocessProtocolsOptions (config) {
255
255
  const protocols = config.server.protocols;
256
256
 
257
257
  config.internal.notifiableProtocols = [];
@@ -31,30 +31,30 @@ HTTP Response Mockup to emulate response objects for Passport Authentication
31
31
  * @class PassportResponse
32
32
  */
33
33
  class PassportResponse {
34
- constructor() {
34
+ constructor () {
35
35
  this.headers = {};
36
36
  this.statusCode = 200;
37
37
  this.onEndListener = null;
38
38
  }
39
39
 
40
- setHeader(field, value) {
40
+ setHeader (field, value) {
41
41
  this.headers[field] = value;
42
42
  }
43
43
 
44
- end(statusCode) {
44
+ end (statusCode) {
45
45
  if (statusCode) {
46
46
  this.statusCode = statusCode;
47
47
  }
48
- if(typeof this.onEndListener === 'function') {
48
+ if (typeof this.onEndListener === 'function') {
49
49
  this.onEndListener();
50
50
  }
51
51
  }
52
52
 
53
- getHeader(key) {
53
+ getHeader (key) {
54
54
  return this.headers[key];
55
55
  }
56
56
 
57
- addEndListener(listener) {
57
+ addEndListener (listener) {
58
58
  this.onEndListener = listener;
59
59
  }
60
60
  }
@@ -32,7 +32,7 @@ const PassportResponse = require('./passportResponse');
32
32
  * @class PassportWrapper
33
33
  */
34
34
  class PassportWrapper {
35
- constructor() {
35
+ constructor () {
36
36
  this.options = {};
37
37
  }
38
38
 
@@ -41,7 +41,7 @@ class PassportWrapper {
41
41
  * @param strategyName
42
42
  * @returns {Promise.<*>}
43
43
  */
44
- authenticate(request, strategyName) {
44
+ authenticate (request, strategyName) {
45
45
  const response = new PassportResponse();
46
46
 
47
47
  return new Bluebird((resolve, reject) => {
@@ -67,7 +67,7 @@ class PassportWrapper {
67
67
  err.message));
68
68
  }
69
69
  }
70
- else if (!user) {
70
+ else if (! user) {
71
71
  reject(
72
72
  kerror.get('plugin', 'strategy', 'missing_user', info.message));
73
73
  }
@@ -103,7 +103,7 @@ class PassportWrapper {
103
103
  * @param {object} strategy - instantiated strategy object
104
104
  * @param {object} opts - options to provide to authenticate with the strategy
105
105
  */
106
- use(name, strategy, opts = {}) {
106
+ use (name, strategy, opts = {}) {
107
107
  passport.use(name, strategy);
108
108
  this.options[name] = opts;
109
109
  }
@@ -113,7 +113,7 @@ class PassportWrapper {
113
113
  *
114
114
  * @param {string} name - name of the strategy to unregister
115
115
  */
116
- unuse(name) {
116
+ unuse (name) {
117
117
  passport.unuse(name);
118
118
  delete this.options[name];
119
119
  }
@@ -1,6 +1,6 @@
1
1
  import { EmbeddedSDK } from '../shared/sdk/embeddedSdk';
2
2
  import { JSONObject } from '../../../index';
3
- import { BackendCluster, BackendConfig, BackendController, BackendHook, BackendImport, BackendPipe, BackendPlugin, BackendStorage, BackendVault, InternalLogger } from './index';
3
+ import { BackendCluster, BackendConfig, BackendController, BackendHook, BackendImport, BackendPipe, BackendPlugin, BackendStorage, BackendVault, BackendOpenApi, InternalLogger, BackendErrors } from './index';
4
4
  export declare class Backend {
5
5
  private _kuzzle;
6
6
  private _name;
@@ -113,14 +113,22 @@ export declare class Backend {
113
113
  * @method userMappings - Import user mappings
114
114
  */
115
115
  import: BackendImport;
116
+ /**
117
+ * OpenApi manager
118
+ */
119
+ openApi: BackendOpenApi;
120
+ /**
121
+ * Standard errors
122
+ */
123
+ errors: BackendErrors;
116
124
  /**
117
125
  * @deprecated
118
126
  *
127
+ * Use the app.import.xxx() feature instead.
128
+ *
119
129
  * Support for old features available before Kuzzle as a framework
120
130
  * to avoid breaking existing deployments.
121
131
  *
122
- * Do not use this property unless you know exactly what you are doing,
123
- * this property can be removed in future releases.
124
132
  */
125
133
  _support: JSONObject;
126
134
  /**
@@ -46,10 +46,10 @@ exports.Backend = void 0;
46
46
  const fs_1 = __importDefault(require("fs"));
47
47
  const kuzzle_1 = __importDefault(require("../../kuzzle"));
48
48
  const embeddedSdk_1 = require("../shared/sdk/embeddedSdk");
49
- const kerror_1 = __importDefault(require("../../kerror"));
49
+ const kerror = __importStar(require("../../kerror"));
50
50
  const index_1 = require("./index");
51
- const assertionError = kerror_1.default.wrap('plugin', 'assert');
52
- const runtimeError = kerror_1.default.wrap('plugin', 'runtime');
51
+ const assertionError = kerror.wrap('plugin', 'assert');
52
+ const runtimeError = kerror.wrap('plugin', 'runtime');
53
53
  let _app = null;
54
54
  Reflect.defineProperty(global, 'app', {
55
55
  configurable: true,
@@ -95,11 +95,11 @@ class Backend {
95
95
  /**
96
96
  * @deprecated
97
97
  *
98
+ * Use the app.import.xxx() feature instead.
99
+ *
98
100
  * Support for old features available before Kuzzle as a framework
99
101
  * to avoid breaking existing deployments.
100
102
  *
101
- * Do not use this property unless you know exactly what you are doing,
102
- * this property can be removed in future releases.
103
103
  */
104
104
  this._support = {};
105
105
  /**
@@ -127,6 +127,13 @@ class Backend {
127
127
  this.started = true;
128
128
  },
129
129
  ];
130
+ try {
131
+ const info = JSON.parse(fs_1.default.readFileSync('./package.json', 'utf8'));
132
+ this.version = info.version;
133
+ }
134
+ catch (error) {
135
+ // Silent if no version can be found
136
+ }
130
137
  global.app = this;
131
138
  this.pipe = new index_1.BackendPipe(this);
132
139
  this.hook = new index_1.BackendHook(this);
@@ -138,14 +145,9 @@ class Backend {
138
145
  this.import = new index_1.BackendImport(this);
139
146
  this.log = new index_1.InternalLogger(this);
140
147
  this.cluster = new index_1.BackendCluster();
141
- this.kerror = kerror_1.default;
142
- try {
143
- const info = JSON.parse(fs_1.default.readFileSync('./package.json', 'utf8'));
144
- this.version = info.version;
145
- }
146
- catch (error) {
147
- // Silent if no version can be found
148
- }
148
+ this.openApi = new index_1.BackendOpenApi(this);
149
+ this.errors = new index_1.BackendErrors(this);
150
+ this.kerror = kerror;
149
151
  try {
150
152
  this.commit = this._readCommit();
151
153
  }
@@ -171,6 +173,7 @@ class Backend {
171
173
  const application = new this.PluginObject(this._instanceProxy, { application: true, name: this.name });
172
174
  application.version = this.version;
173
175
  application.commit = this.commit;
176
+ application.openApi = this.openApi.definition;
174
177
  const options = {
175
178
  import: this._import,
176
179
  installations: this._installationsWaitingList,
@@ -211,20 +214,22 @@ class Backend {
211
214
  throw runtimeError.get('already_started', 'install');
212
215
  }
213
216
  if (typeof id !== 'string') {
214
- throw kerror_1.default.get('validation', 'assert', 'invalid_type', 'id', 'string');
217
+ throw kerror.get('validation', 'assert', 'invalid_type', 'id', 'string');
215
218
  }
216
219
  if (typeof handler !== 'function') {
217
- throw kerror_1.default.get('validation', 'assert', 'invalid_type', 'handler', 'function');
220
+ throw kerror.get('validation', 'assert', 'invalid_type', 'handler', 'function');
218
221
  }
219
222
  if (description && typeof description !== 'string') {
220
- throw kerror_1.default.get('validation', 'assert', 'invalid_type', 'id', 'string');
223
+ throw kerror.get('validation', 'assert', 'invalid_type', 'id', 'string');
221
224
  }
222
225
  this._installationsWaitingList.push({ description, handler, id });
223
226
  }
224
227
  /**
225
228
  * Application Name
226
229
  */
227
- get name() { return this._name; }
230
+ get name() {
231
+ return this._name;
232
+ }
228
233
  /**
229
234
  * EmbeddedSDK instance
230
235
  */
@@ -2,13 +2,15 @@ import { ApplicationManager, Backend } from './index';
2
2
  import { KuzzleConfiguration } from '../../types/config/KuzzleConfiguration';
3
3
  export declare class BackendConfig extends ApplicationManager {
4
4
  /**
5
- * Configuration content
5
+ * Configuration content.
6
6
  */
7
7
  content: KuzzleConfiguration;
8
8
  constructor(application: Backend);
9
9
  /**
10
10
  * Sets a configuration value
11
11
  *
12
+ * @deprecated use app.config.content instead
13
+ *
12
14
  * @param path - Path to the configuration key (lodash style)
13
15
  * @param value - Value for the configuration key
14
16
  */
@@ -16,6 +18,8 @@ export declare class BackendConfig extends ApplicationManager {
16
18
  /**
17
19
  * Merges a configuration object into the current configuration
18
20
  *
21
+ * @deprecated use app.config.content instead
22
+ *
19
23
  * @param config - Configuration object to merge
20
24
  */
21
25
  merge(config: KuzzleConfiguration): void;
@@ -19,16 +19,35 @@
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
  };
25
44
  Object.defineProperty(exports, "__esModule", { value: true });
26
45
  exports.BackendConfig = void 0;
27
46
  const lodash_1 = __importDefault(require("lodash"));
28
- const kerror_1 = __importDefault(require("../../kerror"));
47
+ const kerror = __importStar(require("../../kerror"));
29
48
  const index_1 = require("./index");
30
49
  const index_js_1 = require("../../config/index.js");
31
- const runtimeError = kerror_1.default.wrap('plugin', 'runtime');
50
+ const runtimeError = kerror.wrap('plugin', 'runtime');
32
51
  class BackendConfig extends index_1.ApplicationManager {
33
52
  constructor(application) {
34
53
  super(application);
@@ -37,6 +56,8 @@ class BackendConfig extends index_1.ApplicationManager {
37
56
  /**
38
57
  * Sets a configuration value
39
58
  *
59
+ * @deprecated use app.config.content instead
60
+ *
40
61
  * @param path - Path to the configuration key (lodash style)
41
62
  * @param value - Value for the configuration key
42
63
  */
@@ -49,6 +70,8 @@ class BackendConfig extends index_1.ApplicationManager {
49
70
  /**
50
71
  * Merges a configuration object into the current configuration
51
72
  *
73
+ * @deprecated use app.config.content instead
74
+ *
52
75
  * @param config - Configuration object to merge
53
76
  */
54
77
  merge(config) {