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.
- package/lib/api/controllers/adminController.js +3 -3
- package/lib/api/controllers/authController.js +12 -12
- 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 +50 -50
- package/lib/api/controllers/serverController.js +73 -27
- package/lib/api/documentExtractor.js +3 -3
- package/lib/api/funnel.js +44 -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.js +8 -6
- package/lib/cluster/node.js +9 -9
- package/lib/cluster/publisher.js +1 -1
- package/lib/cluster/state.js +20 -4
- package/lib/cluster/subscriber.js +1 -1
- package/lib/cluster/workers/IDCardRenewer.js +2 -2
- 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 +11 -3
- package/lib/core/backend/backend.js +22 -17
- package/lib/core/backend/backendConfig.d.ts +5 -1
- package/lib/core/backend/backendConfig.js +25 -2
- package/lib/core/backend/backendController.js +21 -5
- package/lib/core/backend/backendErrors.d.ts +58 -0
- package/lib/core/backend/backendErrors.js +121 -0
- package/lib/core/backend/backendHook.js +21 -5
- package/lib/core/backend/backendImport.js +21 -5
- package/lib/core/backend/backendOpenApi.d.ts +9 -0
- package/lib/core/backend/backendOpenApi.js +69 -0
- package/lib/core/backend/backendPipe.js +21 -5
- package/lib/core/backend/backendPlugin.js +22 -3
- package/lib/core/backend/backendVault.js +21 -2
- package/lib/core/backend/index.d.ts +2 -0
- package/lib/core/backend/index.js +2 -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 +228 -50
- 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.js +22 -3
- 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/channel.js +20 -4
- package/lib/core/realtime/hotelClerk.js +24 -5
- 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 +445 -443
- package/lib/core/security/roleRepository.js +16 -16
- package/lib/core/security/securityLoader.js +2 -2
- package/lib/core/security/tokenRepository.js +11 -11
- package/lib/core/security/userRepository.js +8 -8
- package/lib/core/shared/abstractManifest.js +4 -4
- package/lib/core/shared/repository.js +5 -5
- package/lib/core/shared/sdk/embeddedSdk.js +21 -2
- 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/storage/indexCache.js +20 -4
- 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/errors/multipleErrorsError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.js +3 -3
- package/lib/kerror/index.d.ts +82 -0
- package/lib/kerror/index.js +176 -143
- 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 +59 -9
- 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 +192 -232
- package/lib/model/security/rights.js +1 -1
- package/lib/model/security/role.d.ts +40 -0
- package/lib/model/security/role.js +174 -190
- package/lib/model/security/user.d.ts +29 -0
- package/lib/model/security/user.js +103 -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/Plugin.js +20 -4
- package/lib/types/Policy.d.ts +25 -0
- package/lib/types/{InternalLogger.js → Policy.js} +2 -2
- 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/errors/ErrorDefinition.d.ts +27 -0
- package/lib/types/errors/ErrorDefinition.js +3 -0
- package/lib/types/errors/ErrorDomains.d.ts +17 -0
- package/lib/types/errors/ErrorDomains.js +3 -0
- package/lib/types/index.d.ts +9 -1
- package/lib/types/index.js +9 -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 +284 -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/mutex.js +21 -2
- package/lib/util/requestAssertions.js +7 -7
- package/lib/util/wildcard.js +55 -0
- package/package-lock.json +535 -75
- package/package.json +5 -3
- package/lib/api/openApiGenerator.d.ts +0 -7
- package/lib/api/openApiGenerator.js +0 -197
- package/lib/types/InternalLogger.d.ts +0 -25
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
const path = require('path');
|
|
25
25
|
const fs = require('fs');
|
|
26
26
|
const semver = require('semver');
|
|
27
|
-
const enforcer = require('openapi-enforcer');
|
|
28
27
|
|
|
29
28
|
const { PluginContext } = require('./pluginContext');
|
|
30
29
|
const PrivilegedPluginContext = require('./privilegedContext');
|
|
@@ -34,7 +33,6 @@ const Manifest = require('./pluginManifest');
|
|
|
34
33
|
const { has, isPlainObject } = require('../../util/safeObject');
|
|
35
34
|
|
|
36
35
|
const assertionError = kerror.wrap('plugin', 'assert');
|
|
37
|
-
const controllerError = kerror.wrap('plugin', 'controller');
|
|
38
36
|
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
39
37
|
|
|
40
38
|
const PLUGIN_NAME_REGEX = /^[a-z-\d]+$/;
|
|
@@ -43,7 +41,7 @@ const HTTP_VERBS = ['get', 'head', 'post', 'put', 'delete', 'patch', 'options'];
|
|
|
43
41
|
class Plugin {
|
|
44
42
|
constructor (
|
|
45
43
|
instance,
|
|
46
|
-
{ name, application=false, deprecationWarning=true } = {}
|
|
44
|
+
{ name, application = false, deprecationWarning = true } = {}
|
|
47
45
|
) {
|
|
48
46
|
this._instance = instance;
|
|
49
47
|
|
|
@@ -154,24 +152,46 @@ class Plugin {
|
|
|
154
152
|
|
|
155
153
|
// getters/setters ===========================================================
|
|
156
154
|
|
|
157
|
-
get instance () {
|
|
155
|
+
get instance () {
|
|
156
|
+
return this._instance;
|
|
157
|
+
}
|
|
158
158
|
|
|
159
|
-
get context () {
|
|
159
|
+
get context () {
|
|
160
|
+
return this._context;
|
|
161
|
+
}
|
|
160
162
|
|
|
161
|
-
get application () {
|
|
163
|
+
get application () {
|
|
164
|
+
return this._application;
|
|
165
|
+
}
|
|
162
166
|
|
|
163
|
-
get logPrefix () {
|
|
167
|
+
get logPrefix () {
|
|
168
|
+
return `[${this.name}]`;
|
|
169
|
+
}
|
|
164
170
|
|
|
165
|
-
get config () {
|
|
166
|
-
|
|
171
|
+
get config () {
|
|
172
|
+
return this._config;
|
|
173
|
+
}
|
|
174
|
+
set config (config) {
|
|
175
|
+
this._config = config;
|
|
176
|
+
}
|
|
167
177
|
|
|
168
|
-
get version () {
|
|
169
|
-
|
|
178
|
+
get version () {
|
|
179
|
+
return this._version;
|
|
180
|
+
}
|
|
181
|
+
set version (version) {
|
|
182
|
+
this._version = version;
|
|
183
|
+
}
|
|
170
184
|
|
|
171
|
-
get deprecationWarning () {
|
|
172
|
-
|
|
185
|
+
get deprecationWarning () {
|
|
186
|
+
return this._deprecationWarning;
|
|
187
|
+
}
|
|
188
|
+
set deprecationWarning (value) {
|
|
189
|
+
this._deprecationWarning = value;
|
|
190
|
+
}
|
|
173
191
|
|
|
174
|
-
get name () {
|
|
192
|
+
get name () {
|
|
193
|
+
return this._name;
|
|
194
|
+
}
|
|
175
195
|
set name (name) {
|
|
176
196
|
if (! this.constructor.checkName(name)) {
|
|
177
197
|
this.printDeprecation('Plugin names should be in kebab-case. This behavior will be enforced in futur versions of Kuzzle.');
|
|
@@ -180,7 +200,9 @@ class Plugin {
|
|
|
180
200
|
this._name = name;
|
|
181
201
|
}
|
|
182
202
|
|
|
183
|
-
get manifest () {
|
|
203
|
+
get manifest () {
|
|
204
|
+
return this._manifest;
|
|
205
|
+
}
|
|
184
206
|
set manifest (manifest) {
|
|
185
207
|
this._manifest = manifest;
|
|
186
208
|
}
|
|
@@ -264,7 +286,7 @@ class Plugin {
|
|
|
264
286
|
return PLUGIN_NAME_REGEX.test(name);
|
|
265
287
|
}
|
|
266
288
|
|
|
267
|
-
static
|
|
289
|
+
static checkControllerDefinition (name, definition, { application = false } = {}) {
|
|
268
290
|
if (typeof name !== 'string') {
|
|
269
291
|
throw assertionError.get(
|
|
270
292
|
'invalid_controller_definition',
|
|
@@ -342,10 +364,6 @@ class Plugin {
|
|
|
342
364
|
name,
|
|
343
365
|
`action "${action}" has invalid http properties: ${routeProperties.join(', ')}`);
|
|
344
366
|
}
|
|
345
|
-
|
|
346
|
-
if (route.openapi) {
|
|
347
|
-
await checkOpenAPISpecification(name, action, route);
|
|
348
|
-
}
|
|
349
367
|
}
|
|
350
368
|
}
|
|
351
369
|
}
|
|
@@ -365,48 +383,4 @@ function checkHttpRouteProperties (route, action, name, application) {
|
|
|
365
383
|
}
|
|
366
384
|
}
|
|
367
385
|
|
|
368
|
-
async function checkOpenAPISpecification (controller, action, route) {
|
|
369
|
-
if (! isPlainObject(route.openapi)) {
|
|
370
|
-
throw assertionError.get(
|
|
371
|
-
'invalid_controller_definition',
|
|
372
|
-
controller,
|
|
373
|
-
'The "openapi" property of the route definition must be an object');
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
const routePath = route.path.charAt(0) === '/'
|
|
377
|
-
? route.path
|
|
378
|
-
: `/_/${route.path}`;
|
|
379
|
-
|
|
380
|
-
// Set :param notation to {param}
|
|
381
|
-
const formattedPath = routePath.replace(/\/:([^/]*)/g,'/{$1}');
|
|
382
|
-
|
|
383
|
-
const { error, warning } = await enforcer({
|
|
384
|
-
/* eslint-disable sort-keys */
|
|
385
|
-
openapi: '3.0.0',
|
|
386
|
-
info: {
|
|
387
|
-
title: 'Kuzzle API',
|
|
388
|
-
version: require('../../../package').version
|
|
389
|
-
},
|
|
390
|
-
paths: {
|
|
391
|
-
[formattedPath]: {
|
|
392
|
-
[route.verb]: route.openapi
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
/* eslint-enable sort-keys */
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
if (warning) {
|
|
399
|
-
global.kuzzle.log.warn(`Warning for OpenAPI specification in "${controller}:${action}", ${route.openapi} : ${warning}`);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (error) {
|
|
403
|
-
throw controllerError.get(
|
|
404
|
-
'invalid_openapi_schema',
|
|
405
|
-
controller,
|
|
406
|
-
action,
|
|
407
|
-
route.openapi,
|
|
408
|
-
error);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
386
|
module.exports = Plugin;
|
|
@@ -19,6 +19,25 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
22
41
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
43
|
};
|
|
@@ -33,12 +52,12 @@ const elasticsearch_1 = __importDefault(require("../../service/storage/elasticse
|
|
|
33
52
|
const safeObject_1 = require("../../util/safeObject");
|
|
34
53
|
const promback_1 = __importDefault(require("../../util/promback"));
|
|
35
54
|
const mutex_1 = require("../../util/mutex");
|
|
36
|
-
const
|
|
55
|
+
const kerror = __importStar(require("../../kerror"));
|
|
37
56
|
const storeScopeEnum_1 = __importDefault(require("../storage/storeScopeEnum"));
|
|
38
57
|
const errors_1 = require("../../kerror/errors");
|
|
39
58
|
const index_1 = require("../../../index");
|
|
40
59
|
const backend_1 = require("../backend");
|
|
41
|
-
const contextError =
|
|
60
|
+
const contextError = kerror.wrap('plugin', 'context');
|
|
42
61
|
class PluginContext {
|
|
43
62
|
constructor(pluginName) {
|
|
44
63
|
this.config = JSON.parse(JSON.stringify(global.kuzzle.config));
|
|
@@ -60,7 +79,7 @@ class PluginContext {
|
|
|
60
79
|
TooManyRequestsError: errors_1.TooManyRequestsError,
|
|
61
80
|
UnauthorizedError: errors_1.UnauthorizedError,
|
|
62
81
|
};
|
|
63
|
-
this.kerror =
|
|
82
|
+
this.kerror = kerror.wrap('plugin', pluginName);
|
|
64
83
|
// @deprecated - backward compatibility only
|
|
65
84
|
this.errorsManager = this.kerror;
|
|
66
85
|
/* context.secrets ====================================================== */
|
|
@@ -27,7 +27,7 @@ const kerror = require('../../kerror').wrap('plugin', 'manifest');
|
|
|
27
27
|
const AbstractManifest = require('../shared/abstractManifest');
|
|
28
28
|
|
|
29
29
|
class PluginManifest extends AbstractManifest {
|
|
30
|
-
constructor(pluginPath) {
|
|
30
|
+
constructor (pluginPath) {
|
|
31
31
|
super(pluginPath);
|
|
32
32
|
this.privileged = false;
|
|
33
33
|
}
|
|
@@ -36,11 +36,11 @@ class PluginManifest extends AbstractManifest {
|
|
|
36
36
|
super.load();
|
|
37
37
|
|
|
38
38
|
// Ensure ES will accept the plugin name as index
|
|
39
|
-
if (
|
|
39
|
+
if (! /^[\w-]+$/.test(this.name)) {
|
|
40
40
|
throw kerror.get('invalid_name', this.path);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
if (!_.isNil(this.raw) && !_.isNil(this.raw.privileged)) {
|
|
43
|
+
if (! _.isNil(this.raw) && ! _.isNil(this.raw.privileged)) {
|
|
44
44
|
if (typeof this.raw.privileged !== 'boolean') {
|
|
45
45
|
throw kerror.get(
|
|
46
46
|
'invalid_privileged',
|
|
@@ -36,7 +36,7 @@ class PluginRepository extends Repository {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
init (options) {
|
|
39
|
-
if (options && typeof options === 'object' && !Array.isArray(options)) {
|
|
39
|
+
if (options && typeof options === 'object' && ! Array.isArray(options)) {
|
|
40
40
|
if (options.ObjectConstructor) {
|
|
41
41
|
this.ObjectConstructor = options.ObjectConstructor;
|
|
42
42
|
}
|
|
@@ -64,7 +64,7 @@ class PluginRepository extends Repository {
|
|
|
64
64
|
* @returns {Promise}
|
|
65
65
|
*/
|
|
66
66
|
create (object, options = {}) {
|
|
67
|
-
const opts = Object.assign({method: 'create'}, options);
|
|
67
|
+
const opts = Object.assign({ method: 'create' }, options);
|
|
68
68
|
|
|
69
69
|
return this.persistToDatabase(object, opts);
|
|
70
70
|
}
|
|
@@ -75,7 +75,7 @@ class PluginRepository extends Repository {
|
|
|
75
75
|
* @returns {Promise}
|
|
76
76
|
*/
|
|
77
77
|
createOrReplace (object, options = {}) {
|
|
78
|
-
const opts = Object.assign({method: 'createOrReplace'}, options);
|
|
78
|
+
const opts = Object.assign({ method: 'createOrReplace' }, options);
|
|
79
79
|
|
|
80
80
|
return this.persistToDatabase(object, opts);
|
|
81
81
|
}
|
|
@@ -86,7 +86,7 @@ class PluginRepository extends Repository {
|
|
|
86
86
|
* @returns {Promise}
|
|
87
87
|
*/
|
|
88
88
|
replace (object, options = {}) {
|
|
89
|
-
const opts = Object.assign({method: 'replace'}, options);
|
|
89
|
+
const opts = Object.assign({ method: 'replace' }, options);
|
|
90
90
|
|
|
91
91
|
return this.persistToDatabase(object, opts);
|
|
92
92
|
}
|
|
@@ -97,7 +97,7 @@ class PluginRepository extends Repository {
|
|
|
97
97
|
* @returns {Promise}
|
|
98
98
|
*/
|
|
99
99
|
update (object, options = {}) {
|
|
100
|
-
const opts = Object.assign({method: 'update'}, options);
|
|
100
|
+
const opts = Object.assign({ method: 'update' }, options);
|
|
101
101
|
|
|
102
102
|
return this.persistToDatabase(object, opts);
|
|
103
103
|
}
|
|
@@ -50,7 +50,7 @@ const CORE_PLUGINS = ['kuzzle-plugin-logger', 'kuzzle-plugin-auth-passport-local
|
|
|
50
50
|
* @param {Kuzzle} kuzzle
|
|
51
51
|
*/
|
|
52
52
|
class PluginsManager {
|
|
53
|
-
constructor() {
|
|
53
|
+
constructor () {
|
|
54
54
|
Reflect.defineProperty(this, 'kuzzle', {
|
|
55
55
|
value: global.kuzzle,
|
|
56
56
|
});
|
|
@@ -234,8 +234,7 @@ class PluginsManager {
|
|
|
234
234
|
plugin.initCalled = true;
|
|
235
235
|
|
|
236
236
|
if ( ! _.isEmpty(plugin.instance.controllers)
|
|
237
|
-
&& ! _.isEmpty(plugin.instance.api))
|
|
238
|
-
{
|
|
237
|
+
&& ! _.isEmpty(plugin.instance.api)) {
|
|
239
238
|
throw assertionError.get('duplicated_api_definition');
|
|
240
239
|
}
|
|
241
240
|
|
|
@@ -265,7 +264,9 @@ class PluginsManager {
|
|
|
265
264
|
|
|
266
265
|
debug('[%s] plugin started', plugin.name);
|
|
267
266
|
|
|
268
|
-
|
|
267
|
+
if (! plugin.application) {
|
|
268
|
+
this.loadedPlugins.push(plugin.name);
|
|
269
|
+
}
|
|
269
270
|
|
|
270
271
|
return null;
|
|
271
272
|
});
|
|
@@ -322,11 +323,11 @@ class PluginsManager {
|
|
|
322
323
|
validateStrategy (pluginName, strategyName, strategy) {
|
|
323
324
|
const errorPrefix = `[${pluginName}] Strategy ${strategyName}:`;
|
|
324
325
|
|
|
325
|
-
if (!isPlainObject(strategy)) {
|
|
326
|
+
if (! isPlainObject(strategy)) {
|
|
326
327
|
throw strategyError.get('invalid_description', errorPrefix, strategy);
|
|
327
328
|
}
|
|
328
329
|
|
|
329
|
-
if (!isPlainObject(strategy.methods)) {
|
|
330
|
+
if (! isPlainObject(strategy.methods)) {
|
|
330
331
|
throw strategyError.get('invalid_methods', errorPrefix, strategy.methods);
|
|
331
332
|
}
|
|
332
333
|
|
|
@@ -334,7 +335,7 @@ class PluginsManager {
|
|
|
334
335
|
|
|
335
336
|
// required methods check
|
|
336
337
|
['exists', 'create', 'update', 'delete', 'validate', 'verify'].forEach(methodName => {
|
|
337
|
-
if (!_.isString(strategy.methods[methodName])) {
|
|
338
|
+
if (! _.isString(strategy.methods[methodName])) {
|
|
338
339
|
throw strategyError.get(
|
|
339
340
|
'invalid_method_type',
|
|
340
341
|
errorPrefix,
|
|
@@ -342,7 +343,7 @@ class PluginsManager {
|
|
|
342
343
|
strategy.methods[methodName]);
|
|
343
344
|
}
|
|
344
345
|
|
|
345
|
-
if (!_.isFunction(plugin.instance[strategy.methods[methodName]])) {
|
|
346
|
+
if (! _.isFunction(plugin.instance[strategy.methods[methodName]])) {
|
|
346
347
|
throw strategyError.get(
|
|
347
348
|
'missing_method_function',
|
|
348
349
|
errorPrefix,
|
|
@@ -354,8 +355,8 @@ class PluginsManager {
|
|
|
354
355
|
['getInfo', 'getById', 'afterRegister'].forEach(name => {
|
|
355
356
|
const optionalMethodName = strategy.methods[name];
|
|
356
357
|
|
|
357
|
-
if (!_.isNil(optionalMethodName)) {
|
|
358
|
-
if (!_.isString(optionalMethodName)) {
|
|
358
|
+
if (! _.isNil(optionalMethodName)) {
|
|
359
|
+
if (! _.isString(optionalMethodName)) {
|
|
359
360
|
throw strategyError.get(
|
|
360
361
|
'invalid_method_type',
|
|
361
362
|
errorPrefix,
|
|
@@ -363,7 +364,7 @@ class PluginsManager {
|
|
|
363
364
|
optionalMethodName);
|
|
364
365
|
}
|
|
365
366
|
|
|
366
|
-
if (!_.isFunction(plugin.instance[optionalMethodName])) {
|
|
367
|
+
if (! _.isFunction(plugin.instance[optionalMethodName])) {
|
|
367
368
|
throw strategyError.get(
|
|
368
369
|
'missing_method_function',
|
|
369
370
|
errorPrefix,
|
|
@@ -372,7 +373,7 @@ class PluginsManager {
|
|
|
372
373
|
}
|
|
373
374
|
});
|
|
374
375
|
|
|
375
|
-
if (!isPlainObject(strategy.config)) {
|
|
376
|
+
if (! isPlainObject(strategy.config)) {
|
|
376
377
|
throw strategyError.get('invalid_config', errorPrefix, strategy.config);
|
|
377
378
|
}
|
|
378
379
|
|
|
@@ -382,8 +383,8 @@ class PluginsManager {
|
|
|
382
383
|
errorPrefix,
|
|
383
384
|
strategy.config.authenticator);
|
|
384
385
|
}
|
|
385
|
-
else if (!this.authenticators[pluginName]
|
|
386
|
-
|| !this.authenticators[pluginName][strategy.config.authenticator]
|
|
386
|
+
else if (! this.authenticators[pluginName]
|
|
387
|
+
|| ! this.authenticators[pluginName][strategy.config.authenticator]
|
|
387
388
|
) {
|
|
388
389
|
throw strategyError.get(
|
|
389
390
|
'unknown_authenticator',
|
|
@@ -394,12 +395,12 @@ class PluginsManager {
|
|
|
394
395
|
for (const optionName of ['strategyOptions', 'authenticateOptions']) {
|
|
395
396
|
const options = strategy.config[optionName];
|
|
396
397
|
|
|
397
|
-
if (!_.isNil(options) && !isPlainObject(options)) {
|
|
398
|
+
if (! _.isNil(options) && ! isPlainObject(options)) {
|
|
398
399
|
throw strategyError.get('invalid_option', errorPrefix, optionName, options);
|
|
399
400
|
}
|
|
400
401
|
}
|
|
401
402
|
|
|
402
|
-
if (!_.isNil(strategy.config.fields) && !Array.isArray(strategy.config.fields)) {
|
|
403
|
+
if (! _.isNil(strategy.config.fields) && ! Array.isArray(strategy.config.fields)) {
|
|
403
404
|
throw strategyError.get('invalid_fields', errorPrefix, strategy.config.fields);
|
|
404
405
|
}
|
|
405
406
|
}
|
|
@@ -678,7 +679,7 @@ class PluginsManager {
|
|
|
678
679
|
'Native controllers cannot be overriden');
|
|
679
680
|
}
|
|
680
681
|
|
|
681
|
-
|
|
682
|
+
Plugin.checkControllerDefinition(controller, definition);
|
|
682
683
|
|
|
683
684
|
for (const [action, actionDefinition ] of Object.entries(definition.actions)) {
|
|
684
685
|
let apiController = this.controllers.get(controller);
|
|
@@ -741,7 +742,7 @@ class PluginsManager {
|
|
|
741
742
|
*/
|
|
742
743
|
_initControllers (plugin) {
|
|
743
744
|
// @deprecated - warn about using the obsolete "controllers" object
|
|
744
|
-
if (!_.isEmpty(plugin.instance.controllers)) {
|
|
745
|
+
if (! _.isEmpty(plugin.instance.controllers)) {
|
|
745
746
|
plugin.printDeprecation('Defining controllers using the "controllers" object is deprecated. You should use the "api" object instead.');
|
|
746
747
|
}
|
|
747
748
|
|
|
@@ -756,7 +757,7 @@ class PluginsManager {
|
|
|
756
757
|
const definition = plugin.instance.controllers[controller];
|
|
757
758
|
const errorControllerPrefix = `Unable to inject controller "${controller}" from plugin "${plugin.name}":`;
|
|
758
759
|
|
|
759
|
-
if (!isPlainObject(definition)) {
|
|
760
|
+
if (! isPlainObject(definition)) {
|
|
760
761
|
// @todo deprecate all those errors and use plugin.assert.invalid_controller_definition
|
|
761
762
|
throw controllerError.get(
|
|
762
763
|
'invalid_description',
|
|
@@ -809,7 +810,7 @@ class PluginsManager {
|
|
|
809
810
|
const controllerNames = Object.keys(plugin.instance.controllers);
|
|
810
811
|
|
|
811
812
|
// @deprecated - warn about using the obsolete "routes" object
|
|
812
|
-
if (!_.isEmpty(plugin.instance.routes)) {
|
|
813
|
+
if (! _.isEmpty(plugin.instance.routes)) {
|
|
813
814
|
plugin.printDeprecation('Defining routes using the "routes" object is deprecated. You should use the "api" object instead.');
|
|
814
815
|
}
|
|
815
816
|
|
|
@@ -835,7 +836,7 @@ class PluginsManager {
|
|
|
835
836
|
|
|
836
837
|
const apiController = this.controllers.get(controller);
|
|
837
838
|
|
|
838
|
-
if (!apiController) {
|
|
839
|
+
if (! apiController) {
|
|
839
840
|
throw controllerError.get(
|
|
840
841
|
'undefined_controller',
|
|
841
842
|
errorRoutePrefix,
|
|
@@ -843,7 +844,7 @@ class PluginsManager {
|
|
|
843
844
|
didYouMean(route.controller, controllerNames));
|
|
844
845
|
}
|
|
845
846
|
|
|
846
|
-
if (!apiController._isAction(route.action)) {
|
|
847
|
+
if (! apiController._isAction(route.action)) {
|
|
847
848
|
const actionNames = Array.from(apiController._actions);
|
|
848
849
|
throw controllerError.get(
|
|
849
850
|
'undefined_action',
|
|
@@ -898,7 +899,7 @@ class PluginsManager {
|
|
|
898
899
|
* @throws {PluginImplementationError} If strategies registration fails
|
|
899
900
|
*/
|
|
900
901
|
_initStrategies (plugin) {
|
|
901
|
-
if ( !isPlainObject(plugin.instance.strategies)
|
|
902
|
+
if ( ! isPlainObject(plugin.instance.strategies)
|
|
902
903
|
|| _.isEmpty(plugin.instance.strategies)
|
|
903
904
|
) {
|
|
904
905
|
throw strategyError.get('invalid_definition', plugin.logPrefix);
|
|
@@ -917,12 +918,12 @@ class PluginsManager {
|
|
|
917
918
|
* @throws {PluginImplementationError} If strategies registration fails
|
|
918
919
|
*/
|
|
919
920
|
_initAuthenticators (plugin) {
|
|
920
|
-
if (!isPlainObject(plugin.instance.authenticators)) {
|
|
921
|
+
if (! isPlainObject(plugin.instance.authenticators)) {
|
|
921
922
|
throw kerror.get('plugin', 'authenticators', 'not_an_object', plugin.logPrefix);
|
|
922
923
|
}
|
|
923
924
|
|
|
924
925
|
for (const authenticator of Object.keys(plugin.instance.authenticators)) {
|
|
925
|
-
if (!isConstructor(plugin.instance.authenticators[authenticator])) {
|
|
926
|
+
if (! isConstructor(plugin.instance.authenticators[authenticator])) {
|
|
926
927
|
throw kerror.get(
|
|
927
928
|
'plugin',
|
|
928
929
|
'authenticators',
|
|
@@ -1015,7 +1016,7 @@ class PluginsManager {
|
|
|
1015
1016
|
|
|
1016
1017
|
// catching plugins returning non-thenable content
|
|
1017
1018
|
// @todo - with async/await we might consider allowing non-promise results
|
|
1018
|
-
if (!ret || !_.isFunction(ret.then)) {
|
|
1019
|
+
if (! ret || ! _.isFunction(ret.then)) {
|
|
1019
1020
|
callback(strategyError.get('invalid_verify_return', prefix, ret));
|
|
1020
1021
|
return;
|
|
1021
1022
|
}
|
|
@@ -1031,11 +1032,11 @@ class PluginsManager {
|
|
|
1031
1032
|
}
|
|
1032
1033
|
|
|
1033
1034
|
if (result === false) {
|
|
1034
|
-
callback(null, result, {message: null});
|
|
1035
|
+
callback(null, result, { message: null });
|
|
1035
1036
|
return;
|
|
1036
1037
|
}
|
|
1037
1038
|
|
|
1038
|
-
if (!isPlainObject(result)) {
|
|
1039
|
+
if (! isPlainObject(result)) {
|
|
1039
1040
|
callback(strategyError.get('invalid_verify_resolve', prefix));
|
|
1040
1041
|
return;
|
|
1041
1042
|
}
|
|
@@ -19,13 +19,29 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
var
|
|
23
|
-
|
|
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
|
exports.Channel = void 0;
|
|
27
|
-
const
|
|
28
|
-
const realtimeError =
|
|
43
|
+
const kerror = __importStar(require("../../kerror"));
|
|
44
|
+
const realtimeError = kerror.wrap('core', 'realtime');
|
|
29
45
|
/**
|
|
30
46
|
* A channel define how notifications should be send for a particular realtime
|
|
31
47
|
* room.
|
|
@@ -19,6 +19,25 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
22
41
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
43
|
};
|
|
@@ -26,14 +45,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
45
|
exports.HotelClerk = void 0;
|
|
27
46
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
28
47
|
const request_1 = require("../../api/request");
|
|
29
|
-
const
|
|
48
|
+
const kerror = __importStar(require("../../kerror"));
|
|
30
49
|
const debug_1 = __importDefault(require("../../util/debug"));
|
|
31
50
|
const koncordeCompat_1 = require("../../util/koncordeCompat");
|
|
32
51
|
const channel_1 = require("./channel");
|
|
33
52
|
const connectionRooms_1 = require("./connectionRooms");
|
|
34
53
|
const room_1 = require("./room");
|
|
35
54
|
const subscription_1 = require("./subscription");
|
|
36
|
-
const realtimeError =
|
|
55
|
+
const realtimeError = kerror.wrap('core', 'realtime');
|
|
37
56
|
const debug = (0, debug_1.default)('kuzzle:realtime:hotelClerk');
|
|
38
57
|
/**
|
|
39
58
|
* The HotelClerk is responsible of keeping the list of rooms and subscriptions
|
|
@@ -168,10 +187,10 @@ class HotelClerk {
|
|
|
168
187
|
async subscribe(request) {
|
|
169
188
|
const { index, collection } = request.input.resource;
|
|
170
189
|
if (!index) {
|
|
171
|
-
return
|
|
190
|
+
return kerror.reject('api', 'assert', 'missing_argument', 'index');
|
|
172
191
|
}
|
|
173
192
|
if (!collection) {
|
|
174
|
-
return
|
|
193
|
+
return kerror.reject('api', 'assert', 'missing_argument', 'collection');
|
|
175
194
|
}
|
|
176
195
|
/*
|
|
177
196
|
* /!\ This check is a duplicate to the one already made by the
|
|
@@ -192,7 +211,7 @@ class HotelClerk {
|
|
|
192
211
|
normalized = this.koncorde.normalize(request.input.body, (0, koncordeCompat_1.toKoncordeIndex)(index, collection));
|
|
193
212
|
}
|
|
194
213
|
catch (e) {
|
|
195
|
-
throw
|
|
214
|
+
throw kerror.get('api', 'assert', 'koncorde_dsl_error', e.message);
|
|
196
215
|
}
|
|
197
216
|
this.createRoom(normalized);
|
|
198
217
|
const { channel, subscribed } = await this.subscribeToRoom(normalized.id, request);
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
* @param {string} message - Notification message
|
|
31
31
|
*/
|
|
32
32
|
class ServerNotification {
|
|
33
|
-
constructor(type, message) {
|
|
33
|
+
constructor (type, message) {
|
|
34
34
|
this.status = 200;
|
|
35
35
|
this.info = 'This is an automated server notification';
|
|
36
36
|
this.message = message;
|
|
@@ -53,7 +53,7 @@ const KUZZLE_NOTIFICATION_CHANNEL = 'kuzzle:notification:server';
|
|
|
53
53
|
* @class NotifierController
|
|
54
54
|
*/
|
|
55
55
|
class NotifierController {
|
|
56
|
-
constructor(realtimeModule) {
|
|
56
|
+
constructor (realtimeModule) {
|
|
57
57
|
this.module = realtimeModule;
|
|
58
58
|
this.ttl = global.kuzzle.config.limits.subscriptionDocumentTTL;
|
|
59
59
|
}
|
|
@@ -267,7 +267,7 @@ class NotifierController {
|
|
|
267
267
|
let cached = action === actionEnum.REPLACE || action === actionEnum.UPDATE;
|
|
268
268
|
|
|
269
269
|
const cacheIds = documents.map(doc => {
|
|
270
|
-
if ((action === actionEnum.WRITE || action === actionEnum.UPSERT) && !cached) {
|
|
270
|
+
if ((action === actionEnum.WRITE || action === actionEnum.UPSERT) && ! cached) {
|
|
271
271
|
cached = doc.created !== true; // force a bool value if undefined
|
|
272
272
|
}
|
|
273
273
|
|
|
@@ -414,7 +414,7 @@ class NotifierController {
|
|
|
414
414
|
*
|
|
415
415
|
* @returns {Promise}
|
|
416
416
|
*/
|
|
417
|
-
_notifyDocument (rooms, notification, { fromCluster=true } = {}) {
|
|
417
|
+
_notifyDocument (rooms, notification, { fromCluster = true } = {}) {
|
|
418
418
|
const channels = [];
|
|
419
419
|
|
|
420
420
|
for (const room of rooms) {
|
|
@@ -452,7 +452,7 @@ class NotifierController {
|
|
|
452
452
|
*
|
|
453
453
|
* @returns {Promise}
|
|
454
454
|
*/
|
|
455
|
-
_notifyUser (room, notification, { fromCluster=true } = {}) {
|
|
455
|
+
_notifyUser (room, notification, { fromCluster = true } = {}) {
|
|
456
456
|
const channels = [];
|
|
457
457
|
const hotelClerkRoom = this.module.hotelClerk.rooms.get(room);
|
|
458
458
|
|
|
@@ -493,7 +493,7 @@ class NotifierController {
|
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
-
function getCachePrefix(request) {
|
|
496
|
+
function getCachePrefix (request) {
|
|
497
497
|
// use redis key hash tag
|
|
498
498
|
// (see https://redis.io/topics/cluster-spec#keys-distribution-model)
|
|
499
499
|
return `{notif/${request.input.args.index}/${request.input.args.collection}}/`;
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
24
|
const RoleRepository = require('./roleRepository');
|
|
25
|
-
const ProfileRepository = require('./profileRepository');
|
|
25
|
+
const { ProfileRepository } = require('./profileRepository');
|
|
26
26
|
const TokenRepository = require('./tokenRepository');
|
|
27
27
|
const UserRepository = require('./userRepository');
|
|
28
28
|
const SecurityLoader = require('./securityLoader');
|