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
@@ -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;
@@ -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);
@@ -55,8 +55,9 @@ class IDCardRenewer {
55
55
  }
56
56
 
57
57
  async initRedis (config, name) {
58
- this.redis = new Redis(config, name);
59
- await this.redis.init();
58
+ const redis = new Redis(config, name);
59
+ await redis.init();
60
+ this.redis = redis;
60
61
  }
61
62
 
62
63
  async renewIDCard () {
@@ -89,8 +90,16 @@ class IDCardRenewer {
89
90
  }
90
91
 
91
92
  this.disposed = true;
93
+
92
94
  clearInterval(this.refreshTimer);
93
95
  this.refreshTimer = null;
96
+
97
+ // If the worker is disposed before it had time to starts, redis service
98
+ // may not have been initialized
99
+ if (! this.redis) {
100
+ return;
101
+ }
102
+
94
103
  try {
95
104
  await this.redis.commands.del(this.nodeIdKey);
96
105
  }
@@ -101,7 +110,7 @@ class IDCardRenewer {
101
110
  }
102
111
  }
103
112
 
104
- if (!isMainThread) {
113
+ if (! isMainThread) {
105
114
  const idCardRenewer = new IDCardRenewer();
106
115
 
107
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 } from './index';
4
4
  export declare class Backend {
5
5
  private _kuzzle;
6
6
  private _name;
@@ -113,6 +113,10 @@ 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;
116
120
  /**
117
121
  * @deprecated
118
122
  *
@@ -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,8 @@ 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();
148
+ this.openApi = new index_1.BackendOpenApi(this);
141
149
  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
- }
149
150
  try {
150
151
  this.commit = this._readCommit();
151
152
  }
@@ -171,6 +172,7 @@ class Backend {
171
172
  const application = new this.PluginObject(this._instanceProxy, { application: true, name: this.name });
172
173
  application.version = this.version;
173
174
  application.commit = this.commit;
175
+ application.openApi = this.openApi.definition;
174
176
  const options = {
175
177
  import: this._import,
176
178
  installations: this._installationsWaitingList,
@@ -224,7 +226,9 @@ class Backend {
224
226
  /**
225
227
  * Application Name
226
228
  */
227
- get name() { return this._name; }
229
+ get name() {
230
+ return this._name;
231
+ }
228
232
  /**
229
233
  * EmbeddedSDK instance
230
234
  */
@@ -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;
@@ -37,6 +37,8 @@ class BackendConfig extends index_1.ApplicationManager {
37
37
  /**
38
38
  * Sets a configuration value
39
39
  *
40
+ * @deprecated use app.config.content instead
41
+ *
40
42
  * @param path - Path to the configuration key (lodash style)
41
43
  * @param value - Value for the configuration key
42
44
  */
@@ -49,6 +51,8 @@ class BackendConfig extends index_1.ApplicationManager {
49
51
  /**
50
52
  * Merges a configuration object into the current configuration
51
53
  *
54
+ * @deprecated use app.config.content instead
55
+ *
52
56
  * @param config - Configuration object to merge
53
57
  */
54
58
  merge(config) {
@@ -0,0 +1,9 @@
1
+ import { ApplicationManager, Backend } from './index';
2
+ import { OpenApiDefinition } from '../../types';
3
+ export declare class BackendOpenApi extends ApplicationManager {
4
+ /**
5
+ * Application Open API definition
6
+ */
7
+ definition: Partial<OpenApiDefinition>;
8
+ constructor(application: Backend);
9
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /*
3
+ * Kuzzle, a backend software, self-hostable and ready to use
4
+ * to power modern apps
5
+ *
6
+ * Copyright 2015-2020 Kuzzle
7
+ * mailto: support AT kuzzle.io
8
+ * website: http://kuzzle.io
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * https://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.BackendOpenApi = void 0;
24
+ const index_1 = require("./index");
25
+ class BackendOpenApi extends index_1.ApplicationManager {
26
+ constructor(application) {
27
+ super(application);
28
+ /* eslint-disable sort-keys */
29
+ this.definition = {
30
+ swagger: '2.0',
31
+ info: {
32
+ title: `${application.name} API`,
33
+ description: `${application.name} HTTP API definition`,
34
+ contact: {
35
+ name: 'Kuzzle team',
36
+ url: 'https://kuzzle.io',
37
+ email: 'support@kuzzle.io',
38
+ discord: 'http://join.discord.kuzzle.io'
39
+ },
40
+ license: {
41
+ name: 'Apache 2',
42
+ url: 'http://opensource.org/licenses/apache2.0'
43
+ },
44
+ version: application.version
45
+ },
46
+ externalDocs: {
47
+ description: 'Kuzzle API Documentation',
48
+ url: 'https://docs.kuzzle.io/core/2/api/'
49
+ },
50
+ servers: [
51
+ {
52
+ url: 'https://{baseUrl}:{port}',
53
+ description: `${application.name} Base Url`,
54
+ variables: {
55
+ baseUrl: { default: 'localhost' },
56
+ port: { default: 7512 },
57
+ }
58
+ }
59
+ ],
60
+ tags: [],
61
+ schemes: ['https', 'http'],
62
+ paths: {},
63
+ components: {}
64
+ };
65
+ /* eslint-enable sort-keys */
66
+ }
67
+ }
68
+ exports.BackendOpenApi = BackendOpenApi;
69
+ //# sourceMappingURL=backendOpenApi.js.map
@@ -9,4 +9,5 @@ export * from './backendPipe';
9
9
  export * from './backendPlugin';
10
10
  export * from './backendStorage';
11
11
  export * from './backendVault';
12
+ export * from './backendOpenApi';
12
13
  export * from './internalLogger';
@@ -21,5 +21,6 @@ __exportStar(require("./backendPipe"), exports);
21
21
  __exportStar(require("./backendPlugin"), exports);
22
22
  __exportStar(require("./backendStorage"), exports);
23
23
  __exportStar(require("./backendVault"), exports);
24
+ __exportStar(require("./backendOpenApi"), exports);
24
25
  __exportStar(require("./internalLogger"), exports);
25
26
  //# sourceMappingURL=index.js.map
@@ -54,15 +54,15 @@ class AccessLogger {
54
54
  const config = global.kuzzle.config.server;
55
55
 
56
56
  for (const out of config.logs.transports) {
57
- if (out.transport && !ALLOWED_TRANSPORTS.includes(out.transport)) {
57
+ if (out.transport && ! ALLOWED_TRANSPORTS.includes(out.transport)) {
58
58
  global.kuzzle.log.error(`Failed to initialize logger transport "${out.transport}": unsupported transport. Skipped.`);
59
59
  }
60
60
  else {
61
- this.isActive = this.isActive || !out.silent;
61
+ this.isActive = this.isActive || ! out.silent;
62
62
  }
63
63
  }
64
64
 
65
- if (!this.isActive) {
65
+ if (! this.isActive) {
66
66
  return;
67
67
  }
68
68
 
@@ -78,7 +78,7 @@ class AccessLogger {
78
78
  }
79
79
 
80
80
  log (connection, request, extra) {
81
- if (!this.isActive) {
81
+ if (! this.isActive) {
82
82
  return;
83
83
  }
84
84
 
@@ -212,7 +212,7 @@ class AccessLoggerWorker {
212
212
  }
213
213
  }
214
214
 
215
- this.logger = winston.createLogger({transports});
215
+ this.logger = winston.createLogger({ transports });
216
216
  }
217
217
 
218
218
  /**
@@ -325,7 +325,7 @@ class AccessLoggerWorker {
325
325
  }
326
326
  }
327
327
 
328
- if (!isMainThread) {
328
+ if (! isMainThread) {
329
329
  // Needed for instantiating a serialized KuzzleRequest object
330
330
  global.kuzzle = { id: workerData.kuzzleId };
331
331
 
@@ -36,7 +36,7 @@ class ClientConnection {
36
36
  this.protocol = protocol;
37
37
  this.headers = {};
38
38
 
39
- if (!Array.isArray(ips)) {
39
+ if (! Array.isArray(ips)) {
40
40
  throw new TypeError(`Expected ips to be an Array, got ${typeof ips}`);
41
41
  }
42
42
  this.ips = ips;
@@ -99,7 +99,7 @@ class EntryPoint {
99
99
  async startListening () {
100
100
  // We need to verify the port ourselves, to make sure Node.js won't open
101
101
  // a named pipe if the provided port number is a string
102
- if (!Number.isInteger(this.config.port)) {
102
+ if (! Number.isInteger(this.config.port)) {
103
103
  throw networkError.get('invalid_port', this.config.port);
104
104
  }
105
105
 
@@ -140,7 +140,7 @@ class EntryPoint {
140
140
 
141
141
  const client = this._clients.get(connectionId);
142
142
 
143
- if (!client || !client.protocol) {
143
+ if (! client || ! client.protocol) {
144
144
  return;
145
145
  }
146
146
 
@@ -160,7 +160,7 @@ class EntryPoint {
160
160
 
161
161
  const client = this._clients.get(connectionId);
162
162
 
163
- if (!client || !client.protocol) {
163
+ if (! client || ! client.protocol) {
164
164
  return;
165
165
  }
166
166
 
@@ -248,7 +248,7 @@ class EntryPoint {
248
248
  global.kuzzle.funnel.execute(request, (error, result) => {
249
249
  const _res = result || request;
250
250
 
251
- if (error && !_res.error) {
251
+ if (error && ! _res.error) {
252
252
  _res.setError(error);
253
253
  }
254
254
 
@@ -327,7 +327,7 @@ class EntryPoint {
327
327
 
328
328
  const client = this._clients.get(data.connectionId);
329
329
 
330
- if (!client || !client.protocol) {
330
+ if (! client || ! client.protocol) {
331
331
  return;
332
332
  }
333
333
 
@@ -142,7 +142,7 @@ class Router {
142
142
  route (message, cb) {
143
143
  debug('Routing HTTP message: %a', message);
144
144
 
145
- if (!has(this.routes, message.method)) {
145
+ if (! has(this.routes, message.method)) {
146
146
  this.routeUnhandledHttpMethod(message, cb);
147
147
  return;
148
148
  }
@@ -165,8 +165,8 @@ class Router {
165
165
  }
166
166
  catch (err) {
167
167
  let request;
168
- if (!routeHandler || !routeHandler._request) {
169
- request = new Request({requestId: message.requestId}, {});
168
+ if (! routeHandler || ! routeHandler._request) {
169
+ request = new Request({ requestId: message.requestId }, {});
170
170
  // Set Headers if not present
171
171
  request.response.setHeaders(this.defaultHeaders, true);
172
172
 
@@ -190,7 +190,7 @@ class Router {
190
190
  * @param {HttpMessage} message
191
191
  * @param {function} cb
192
192
  */
193
- routeUnhandledHttpMethod(message, cb) {
193
+ routeUnhandledHttpMethod (message, cb) {
194
194
  const
195
195
  requestContext = global.kuzzle.router.connections.get(message.connection.id),
196
196
  request = new Request(
@@ -253,7 +253,7 @@ function applyACAOHeader (message, request) {
253
253
  function attach (path, handler, target) {
254
254
  const sanitized = path[path.length - 1] === '/' ? path.slice(0, -1) : path;
255
255
 
256
- if (!attachParts(sanitized.split('/'), handler, target)) {
256
+ if (! attachParts(sanitized.split('/'), handler, target)) {
257
257
  throw kerror.get('duplicate_url', sanitized);
258
258
  }
259
259
  }
@@ -38,7 +38,7 @@ const kerror = require('../../../kerror').wrap('network', 'http');
38
38
  * in JSON format
39
39
  */
40
40
  class RouteHandler {
41
- constructor(url, query, message) {
41
+ constructor (url, query, message) {
42
42
  this.handler = null;
43
43
  this._request = null;
44
44
  this.url = url;
@@ -92,7 +92,7 @@ class RouteHandler {
92
92
  * @param {string} name
93
93
  * @param {string} value
94
94
  */
95
- addArgument(name, value) {
95
+ addArgument (name, value) {
96
96
  this.data[name] = value;
97
97
  }
98
98
 
@@ -101,7 +101,7 @@ class RouteHandler {
101
101
  *
102
102
  * @param {Function} callback
103
103
  */
104
- invokeHandler(callback) {
104
+ invokeHandler (callback) {
105
105
  this.handler(this.request, callback);
106
106
  }
107
107
  }