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.
- package/README.md +11 -0
- package/lib/api/controllers/adminController.js +7 -6
- package/lib/api/controllers/authController.js +11 -11
- package/lib/api/controllers/baseController.js +60 -3
- package/lib/api/controllers/clusterController.js +1 -1
- package/lib/api/controllers/collectionController.js +7 -5
- package/lib/api/controllers/documentController.js +130 -17
- package/lib/api/controllers/indexController.js +1 -1
- package/lib/api/controllers/memoryStorageController.js +39 -38
- package/lib/api/controllers/realtimeController.js +1 -1
- package/lib/api/controllers/securityController.js +49 -49
- package/lib/api/controllers/serverController.js +73 -27
- package/lib/api/documentExtractor.js +3 -3
- package/lib/api/funnel.js +40 -21
- package/lib/api/httpRoutes.js +9 -4
- package/lib/api/openapi/OpenApiManager.d.ts +11 -0
- package/lib/api/openapi/OpenApiManager.js +96 -0
- package/lib/api/openapi/{document → components/document}/count.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/create.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/createOrReplace.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/delete.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/deleteByQuery.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/exists.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/get.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/index.d.ts +2 -0
- package/lib/api/openapi/{document → components/document}/index.js +7 -2
- package/lib/api/openapi/{document → components/document}/replace.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/scroll.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/update.yaml +2 -2
- package/lib/api/openapi/components/document/validate.yaml +42 -0
- package/lib/api/openapi/components/index.d.ts +2 -0
- package/lib/api/openapi/components/index.js +18 -0
- package/lib/api/openapi/{payloads.yaml → components/payloads.yaml} +0 -0
- package/lib/api/openapi/index.d.ts +1 -2
- package/lib/api/openapi/index.js +1 -5
- package/lib/api/openapi/openApiGenerator.d.ts +7 -0
- package/lib/api/openapi/openApiGenerator.js +133 -0
- package/lib/api/request/kuzzleRequest.d.ts +11 -11
- package/lib/api/request/kuzzleRequest.js +38 -48
- package/lib/cluster/node.js +9 -9
- package/lib/cluster/publisher.js +1 -1
- package/lib/cluster/subscriber.js +1 -1
- package/lib/cluster/workers/IDCardRenewer.js +13 -4
- package/lib/config/default.config.js +1 -0
- package/lib/config/index.js +6 -6
- package/lib/core/auth/passportResponse.js +6 -6
- package/lib/core/auth/passportWrapper.js +5 -5
- package/lib/core/backend/backend.d.ts +5 -1
- package/lib/core/backend/backend.js +12 -8
- package/lib/core/backend/backendConfig.d.ts +5 -1
- package/lib/core/backend/backendConfig.js +4 -0
- package/lib/core/backend/backendOpenApi.d.ts +9 -0
- package/lib/core/backend/backendOpenApi.js +69 -0
- package/lib/core/backend/index.d.ts +1 -0
- package/lib/core/backend/index.js +1 -0
- package/lib/core/network/accessLogger.js +6 -6
- package/lib/core/network/clientConnection.js +1 -1
- package/lib/core/network/entryPoint.js +5 -5
- package/lib/core/network/httpRouter/index.js +5 -5
- package/lib/core/network/httpRouter/routeHandler.js +3 -3
- package/lib/core/network/httpRouter/routePart.js +5 -5
- package/lib/core/network/protocolManifest.js +1 -1
- package/lib/core/network/protocols/httpMessage.js +2 -2
- package/lib/core/network/protocols/httpwsProtocol.js +207 -46
- package/lib/core/network/protocols/mqttProtocol.js +3 -3
- package/lib/core/network/protocols/protocol.js +3 -3
- package/lib/core/network/router.js +7 -6
- package/lib/core/plugin/plugin.js +38 -64
- package/lib/core/plugin/pluginContext.d.ts +10 -1
- package/lib/core/plugin/pluginContext.js +2 -0
- package/lib/core/plugin/pluginManifest.js +3 -3
- package/lib/core/plugin/pluginRepository.js +5 -5
- package/lib/core/plugin/pluginsManager.js +29 -28
- package/lib/core/realtime/notification/server.js +1 -1
- package/lib/core/realtime/notification/user.js +1 -1
- package/lib/core/realtime/notifier.js +5 -5
- package/lib/core/security/index.js +1 -1
- package/lib/core/security/profileRepository.d.ts +176 -0
- package/lib/core/security/profileRepository.js +426 -443
- package/lib/core/security/roleRepository.js +16 -16
- package/lib/core/security/securityLoader.js +3 -3
- package/lib/core/security/tokenRepository.js +18 -21
- package/lib/core/security/userRepository.js +8 -8
- package/lib/core/shared/abstractManifest.js +4 -4
- package/lib/core/shared/repository.js +6 -6
- package/lib/core/shared/sdk/funnelProtocol.js +1 -1
- package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
- package/lib/core/shared/store.js +30 -23
- package/lib/core/statistics/statistics.js +17 -17
- package/lib/core/storage/clientAdapter.js +45 -10
- package/lib/core/validation/baseType.js +5 -5
- package/lib/core/validation/types/anything.js +1 -1
- package/lib/core/validation/types/boolean.js +2 -2
- package/lib/core/validation/types/date.js +9 -9
- package/lib/core/validation/types/email.js +5 -5
- package/lib/core/validation/types/enum.js +6 -6
- package/lib/core/validation/types/geoPoint.js +2 -2
- package/lib/core/validation/types/geoShape.js +28 -25
- package/lib/core/validation/types/integer.js +4 -4
- package/lib/core/validation/types/ipAddress.js +7 -6
- package/lib/core/validation/types/numeric.js +4 -4
- package/lib/core/validation/types/object.js +5 -5
- package/lib/core/validation/types/string.js +5 -5
- package/lib/core/validation/types/url.js +7 -6
- package/lib/core/validation/validation.js +95 -84
- package/lib/kerror/codes/1-services.json +12 -0
- package/lib/kerror/codes/2-api.json +12 -0
- package/lib/kerror/codes/3-network.json +12 -0
- package/lib/kerror/codes/4-plugin.json +6 -0
- package/lib/kerror/codes/index.js +11 -11
- package/lib/kerror/index.js +1 -1
- package/lib/kuzzle/dumpGenerator.js +3 -3
- package/lib/kuzzle/event/kuzzleEventEmitter.js +4 -4
- package/lib/kuzzle/event/pipeRunner.js +1 -1
- package/lib/kuzzle/event/waterfall.js +6 -6
- package/lib/kuzzle/kuzzle.js +36 -5
- package/lib/kuzzle/log.js +3 -3
- package/lib/kuzzle/vault.js +3 -3
- package/lib/model/security/profile.d.ts +54 -0
- package/lib/model/security/profile.js +174 -233
- package/lib/model/security/rights.js +1 -1
- package/lib/model/security/role.d.ts +40 -0
- package/lib/model/security/role.js +159 -191
- package/lib/model/security/user.d.ts +29 -0
- package/lib/model/security/user.js +84 -52
- package/lib/model/storage/apiKey.js +2 -2
- package/lib/model/storage/baseModel.js +3 -3
- package/lib/service/cache/redis.js +7 -7
- package/lib/service/storage/elasticsearch.js +152 -90
- package/lib/service/storage/esWrapper.js +2 -3
- package/lib/types/ControllerDefinition.d.ts +3 -3
- package/lib/types/ControllerRights.d.ts +22 -0
- package/lib/types/ControllerRights.js +23 -0
- package/lib/types/HttpStream.d.ts +32 -0
- package/lib/types/HttpStream.js +70 -0
- package/lib/types/OpenApiDefinition.d.ts +43 -0
- package/lib/types/{config/StorageService/StorageServiceElasticsearchConfiguration.js → OpenApiDefinition.js} +1 -1
- package/lib/types/Policy.d.ts +25 -0
- package/lib/types/Policy.js +23 -0
- package/lib/types/PolicyRestrictions.d.ts +21 -0
- package/lib/types/PolicyRestrictions.js +23 -0
- package/lib/types/Target.d.ts +15 -0
- package/lib/types/Target.js +23 -0
- package/lib/types/config/KuzzleConfiguration.d.ts +4 -0
- package/lib/types/config/ServicesConfiguration.d.ts +2 -2
- package/lib/types/config/{StorageService/StorageServiceElasticsearchConfiguration.d.ts → storageEngine/StorageEngineElasticsearchConfiguration.d.ts} +10 -3
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +3 -0
- package/lib/types/index.d.ts +7 -1
- package/lib/types/index.js +7 -1
- package/lib/util/array.d.ts +11 -0
- package/lib/util/array.js +57 -0
- package/lib/util/assertType.js +6 -6
- package/lib/util/bufferedPassThrough.d.ts +76 -0
- package/lib/util/bufferedPassThrough.js +161 -0
- package/lib/util/deprecate.js +7 -5
- package/lib/util/didYouMean.js +1 -1
- package/lib/util/dump-collection.d.ts +3 -0
- package/lib/util/dump-collection.js +265 -0
- package/lib/util/extractFields.js +2 -2
- package/lib/util/inflector.d.ts +8 -0
- package/lib/util/inflector.js +16 -0
- package/lib/util/requestAssertions.js +7 -7
- package/lib/util/wildcard.js +55 -0
- package/package-lock.json +881 -431
- package/package.json +23 -20
- package/lib/api/openApiGenerator.d.ts +0 -7
- package/lib/api/openApiGenerator.js +0 -197
|
@@ -93,6 +93,12 @@
|
|
|
93
93
|
"code": 15,
|
|
94
94
|
"message": "Plugin \"%s\" not found.%s",
|
|
95
95
|
"class": "NotFoundError"
|
|
96
|
+
},
|
|
97
|
+
"invalid_openapi_schema": {
|
|
98
|
+
"description": "OpenAPI specification is invalid",
|
|
99
|
+
"code": 16,
|
|
100
|
+
"message": "Invalid OpenAPI specification: \"%s\"",
|
|
101
|
+
"class": "PluginImplementationError"
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
104
|
},
|
|
@@ -43,7 +43,7 @@ const domains = {
|
|
|
43
43
|
* @param {object} - error config file domain
|
|
44
44
|
*/
|
|
45
45
|
|
|
46
|
-
function checkErrors(subdomain, domain, options) {
|
|
46
|
+
function checkErrors (subdomain, domain, options) {
|
|
47
47
|
const codes = new Set();
|
|
48
48
|
|
|
49
49
|
for (const [name, error] of Object.entries(subdomain.errors)) {
|
|
@@ -57,7 +57,7 @@ function checkErrors(subdomain, domain, options) {
|
|
|
57
57
|
error.code > 0x0000 && error.code <= 0xFFFF,
|
|
58
58
|
`Error configuration file : Field 'code' must be between 1 and 65535 (domain: ${domain.code}, subdomain: ${subdomain.code}, error: ${name}).`);
|
|
59
59
|
assert(
|
|
60
|
-
!codes.has(error.code),
|
|
60
|
+
! codes.has(error.code),
|
|
61
61
|
`Error configuration file : code ${error.code} for error '${name}' is not unique (domain: ${domain.code}, subdomain: ${subdomain.code}).`);
|
|
62
62
|
|
|
63
63
|
codes.add(error.code);
|
|
@@ -80,7 +80,7 @@ function checkErrors(subdomain, domain, options) {
|
|
|
80
80
|
`Error configuration file : Field 'class' must target a known KuzzleError object (domain: ${domain.code}, subdomain: ${subdomain.code}, error: ${name}), '${name.class}' does not exist.`);
|
|
81
81
|
|
|
82
82
|
// plugin errors aren't required to have descriptions
|
|
83
|
-
if (!options.plugin) {
|
|
83
|
+
if (! options.plugin) {
|
|
84
84
|
assert(
|
|
85
85
|
typeof error.description === 'string' && error.description.length > 0,
|
|
86
86
|
`Error configuration file : Field 'description' must be a non-empty string (domain: ${domain.code}, subdomain: ${subdomain.code}, error: ${name}).`);
|
|
@@ -94,19 +94,19 @@ function checkErrors(subdomain, domain, options) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function checkSubdomains(domain, options) {
|
|
97
|
+
function checkSubdomains (domain, options) {
|
|
98
98
|
const subdomainCodes = new Set();
|
|
99
99
|
|
|
100
100
|
for (const subdomainName of Object.keys(domain.subdomains)) {
|
|
101
101
|
const subdomain = domain.subdomains[subdomainName];
|
|
102
102
|
|
|
103
103
|
// Subdomain code for plugins is not required and is automatically set to 0
|
|
104
|
-
if (!options.plugin) {
|
|
104
|
+
if (! options.plugin) {
|
|
105
105
|
assert(
|
|
106
106
|
has(subdomain, 'code'),
|
|
107
107
|
`Error configuration file : Missing required 'code' field (domain: ${domain.code}, subdomain: ${subdomainName}).`);
|
|
108
108
|
}
|
|
109
|
-
else if (!has(subdomain, 'code')) {
|
|
109
|
+
else if (! has(subdomain, 'code')) {
|
|
110
110
|
subdomain.code = 0;
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -117,11 +117,11 @@ function checkSubdomains(domain, options) {
|
|
|
117
117
|
subdomain.code >= 0x00 && subdomain.code <= 0xFF,
|
|
118
118
|
`Error configuration file : Field 'code' must be between 0 and 255 (domain: ${domain.code}, subdomain: ${subdomainName}).`);
|
|
119
119
|
assert(
|
|
120
|
-
!subdomainCodes.has(subdomain.code),
|
|
120
|
+
! subdomainCodes.has(subdomain.code),
|
|
121
121
|
`Error configuration file : code ${subdomain.code} for subdomain '${subdomainName}' is not unique (domain: ${domain.code}).`);
|
|
122
122
|
|
|
123
123
|
// We don't allow duplicates, except for defaulted plugin subdomain codes
|
|
124
|
-
if (!options.plugin || subdomain.code > 0) {
|
|
124
|
+
if (! options.plugin || subdomain.code > 0) {
|
|
125
125
|
subdomainCodes.add(subdomain.code);
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -136,7 +136,7 @@ function checkSubdomains(domain, options) {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
function checkDomains(errorCodesFiles, options = {plugin: false}) {
|
|
139
|
+
function checkDomains (errorCodesFiles, options = { plugin: false }) {
|
|
140
140
|
const domainCodes = new Set();
|
|
141
141
|
|
|
142
142
|
for (const domainName of Object.keys(errorCodesFiles)) {
|
|
@@ -152,7 +152,7 @@ function checkDomains(errorCodesFiles, options = {plugin: false}) {
|
|
|
152
152
|
domain.code >= 0x00 && domain.code <= 0xFF,
|
|
153
153
|
`Error configuration file : Field 'code' must be between 0 and 255. (domain: '${domainName}').`);
|
|
154
154
|
assert(
|
|
155
|
-
!domainCodes.has(domain.code),
|
|
155
|
+
! domainCodes.has(domain.code),
|
|
156
156
|
`Error configuration file : code ${domain.code} for domain ${domainName} is not unique.`);
|
|
157
157
|
|
|
158
158
|
domainCodes.add(domain.code);
|
|
@@ -168,7 +168,7 @@ function checkDomains(errorCodesFiles, options = {plugin: false}) {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
function loadPluginsErrors(pluginManifest, pluginCode) {
|
|
171
|
+
function loadPluginsErrors (pluginManifest, pluginCode) {
|
|
172
172
|
// @todo this should be in its own, independant domain
|
|
173
173
|
domains.plugin.subdomains[pluginManifest.name] = {
|
|
174
174
|
code: pluginCode,
|
package/lib/kerror/index.js
CHANGED
|
@@ -175,7 +175,7 @@ class DumpGenerator {
|
|
|
175
175
|
// dumping Kuzzle's stats
|
|
176
176
|
global.kuzzle.log.info('> dumping kuzzle\'s stats');
|
|
177
177
|
const statistics = await global.kuzzle.statistics.getAllStats(
|
|
178
|
-
new Request({action: 'getAllStats', controller: 'statistics'}));
|
|
178
|
+
new Request({ action: 'getAllStats', controller: 'statistics' }));
|
|
179
179
|
|
|
180
180
|
fs.writeFileSync(
|
|
181
181
|
path.join(dumpPath, 'statistics.json'),
|
|
@@ -197,14 +197,14 @@ class DumpGenerator {
|
|
|
197
197
|
try {
|
|
198
198
|
fs.accessSync(dumpPath, fs.constants.R_OK | fs.constants.W_OK | fs.constants.X_OK);
|
|
199
199
|
}
|
|
200
|
-
catch(e) {
|
|
200
|
+
catch (e) {
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
const dumps = fs.readdirSync(dumpPath)
|
|
205
205
|
.map(file => {
|
|
206
206
|
const filepath = `${dumpPath}/${file}`;
|
|
207
|
-
return {path: filepath, stat: fs.statSync(filepath)};
|
|
207
|
+
return { path: filepath, stat: fs.statSync(filepath) };
|
|
208
208
|
})
|
|
209
209
|
.filter(prop => prop.stat.isDirectory())
|
|
210
210
|
.sort((a, b) => {
|
|
@@ -80,7 +80,7 @@ class KuzzleEventEmitter extends EventEmitter {
|
|
|
80
80
|
onPipe (event, fn) {
|
|
81
81
|
assert(typeof fn === 'function', `Cannot listen to pipe event ${event}: "${fn}" is not a function`);
|
|
82
82
|
|
|
83
|
-
if (!this.corePipes.has(event)) {
|
|
83
|
+
if (! this.corePipes.has(event)) {
|
|
84
84
|
this.corePipes.set(event, []);
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -96,7 +96,7 @@ class KuzzleEventEmitter extends EventEmitter {
|
|
|
96
96
|
*/
|
|
97
97
|
onAsk (event, fn) {
|
|
98
98
|
assert(typeof fn === 'function', `Cannot listen to ask event "${event}": "${fn}" is not a function`);
|
|
99
|
-
assert(!this.coreAnswerers.has(event), `Cannot add a listener to the ask event "${event}": event has already an answerer`);
|
|
99
|
+
assert(! this.coreAnswerers.has(event), `Cannot add a listener to the ask event "${event}": event has already an answerer`);
|
|
100
100
|
|
|
101
101
|
this.coreAnswerers.set(event, fn);
|
|
102
102
|
}
|
|
@@ -143,7 +143,7 @@ class KuzzleEventEmitter extends EventEmitter {
|
|
|
143
143
|
let callback = null;
|
|
144
144
|
|
|
145
145
|
// safe: a pipe's payload can never contain functions
|
|
146
|
-
if (payload.length > 0 && typeof payload[payload.length-1] === 'function') {
|
|
146
|
+
if (payload.length > 0 && typeof payload[payload.length - 1] === 'function') {
|
|
147
147
|
callback = payload.pop();
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -185,7 +185,7 @@ class KuzzleEventEmitter extends EventEmitter {
|
|
|
185
185
|
|
|
186
186
|
const fn = this.coreAnswerers.get(event);
|
|
187
187
|
|
|
188
|
-
if (!fn) {
|
|
188
|
+
if (! fn) {
|
|
189
189
|
throw kerror.get('core', 'fatal', 'assertion_failed', `the requested ask event '${event}' doesn't have an answerer`);
|
|
190
190
|
}
|
|
191
191
|
|
|
@@ -40,7 +40,7 @@ const kerror = require('../../kerror').wrap('plugin', 'runtime');
|
|
|
40
40
|
function waterfallCallback (error, result) {
|
|
41
41
|
this.instance.running--;
|
|
42
42
|
|
|
43
|
-
if (!this.instance.buffer.isEmpty()) {
|
|
43
|
+
if (! this.instance.buffer.isEmpty()) {
|
|
44
44
|
setImmediate(this.instance._boundRunNext);
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -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);
|
package/lib/kuzzle/kuzzle.js
CHANGED
|
@@ -53,6 +53,8 @@ const security_1 = __importDefault(require("../core/security"));
|
|
|
53
53
|
const realtime_1 = __importDefault(require("../core/realtime"));
|
|
54
54
|
const cluster_1 = __importDefault(require("../cluster"));
|
|
55
55
|
const package_json_1 = require("../../package.json");
|
|
56
|
+
const name_generator_1 = require("../util/name-generator");
|
|
57
|
+
const openapi_1 = require("../api/openapi");
|
|
56
58
|
const BACKEND_IMPORT_KEY = 'backend:init:import';
|
|
57
59
|
let _kuzzle = null;
|
|
58
60
|
Reflect.defineProperty(global, 'kuzzle', {
|
|
@@ -103,7 +105,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
103
105
|
/**
|
|
104
106
|
* Initializes all the needed components of Kuzzle.
|
|
105
107
|
*
|
|
106
|
-
* @param {Application} - Application instance
|
|
108
|
+
* @param {Application} - Application Plugin instance
|
|
107
109
|
* @param {Object} - Additional options (import, installations, plugins, secretsFile, support, vaultKey)
|
|
108
110
|
*
|
|
109
111
|
* @this {Kuzzle}
|
|
@@ -124,7 +126,8 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
124
126
|
await (new realtime_1.default()).init();
|
|
125
127
|
await this.internalIndex.init();
|
|
126
128
|
await (new security_1.default()).init();
|
|
127
|
-
|
|
129
|
+
// This will init the cluster module if enabled
|
|
130
|
+
this.id = await this.initKuzzleNode();
|
|
128
131
|
// Secret used to generate JWTs
|
|
129
132
|
this.secret = await this.internalIndex.getSecret();
|
|
130
133
|
this.vault = vault_1.default.load(options.vaultKey, options.secretsFile);
|
|
@@ -141,11 +144,13 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
141
144
|
this.log.info(`[✔] Successfully loaded ${this.pluginsManager.loadedPlugins.length} plugins: ${this.pluginsManager.loadedPlugins.join(', ')}`);
|
|
142
145
|
// Authentification plugins must be loaded before users import to avoid
|
|
143
146
|
// credentials related error which would prevent Kuzzle from starting
|
|
144
|
-
await this.
|
|
147
|
+
await this.loadInitialState(options.import, options.support);
|
|
145
148
|
await this.ask('core:security:verify');
|
|
146
149
|
this.router.init();
|
|
147
150
|
this.log.info('[✔] Core components loaded');
|
|
148
151
|
await this.install(options.installations);
|
|
152
|
+
this.log.info(`[✔] Start "${this.pluginsManager.application.name}" application`);
|
|
153
|
+
this.openApiManager = new openapi_1.OpenApiManager(application.openApi, this.config.http.routes, this.pluginsManager.routes);
|
|
149
154
|
// @deprecated
|
|
150
155
|
await this.pipe('kuzzle:start');
|
|
151
156
|
await this.pipe('kuzzle:state:live');
|
|
@@ -161,6 +166,23 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
161
166
|
throw error;
|
|
162
167
|
}
|
|
163
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Generates the node ID.
|
|
171
|
+
*
|
|
172
|
+
* This will init the cluster if it's enabled.
|
|
173
|
+
*/
|
|
174
|
+
async initKuzzleNode() {
|
|
175
|
+
let id;
|
|
176
|
+
if (this.config.cluster.enabled) {
|
|
177
|
+
id = await (new cluster_1.default()).init();
|
|
178
|
+
this.log.info('[✔] Cluster initialized');
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
id = (0, name_generator_1.generateRandomName)('knode');
|
|
182
|
+
this.log.info('[X] Cluster disabled: single node mode.');
|
|
183
|
+
}
|
|
184
|
+
return id;
|
|
185
|
+
}
|
|
164
186
|
/**
|
|
165
187
|
* Gracefully exits after processing remaining requests
|
|
166
188
|
*
|
|
@@ -340,7 +362,17 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
340
362
|
*
|
|
341
363
|
* @returns {Promise<void>}
|
|
342
364
|
*/
|
|
343
|
-
async
|
|
365
|
+
async loadInitialState(toImport = {}, toSupport = {}) {
|
|
366
|
+
if (lodash_1.default.isEmpty(toImport.mappings)
|
|
367
|
+
&& lodash_1.default.isEmpty(toImport.profiles)
|
|
368
|
+
&& lodash_1.default.isEmpty(toImport.roles)
|
|
369
|
+
&& lodash_1.default.isEmpty(toImport.userMappings)
|
|
370
|
+
&& lodash_1.default.isEmpty(toImport.users)
|
|
371
|
+
&& lodash_1.default.isEmpty(toSupport.fixtures)
|
|
372
|
+
&& lodash_1.default.isEmpty(toSupport.mappings)
|
|
373
|
+
&& lodash_1.default.isEmpty(toSupport.securities)) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
344
376
|
const lockedMutex = [];
|
|
345
377
|
try {
|
|
346
378
|
for (const [type, importMethod] of Object.entries(this.importTypes)) {
|
|
@@ -357,7 +389,6 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
357
389
|
await this.ask('core:cache:internal:store', `${BACKEND_IMPORT_KEY}:${type}`, 1, { ttl: 5 * 60 * 1000 });
|
|
358
390
|
}
|
|
359
391
|
}
|
|
360
|
-
this.log.info('[✔] Waiting for imports to be finished');
|
|
361
392
|
await this._waitForImportToFinish();
|
|
362
393
|
this.log.info('[✔] Import successful');
|
|
363
394
|
}
|
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) {
|
package/lib/kuzzle/vault.js
CHANGED
|
@@ -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 {};
|