kuzzle 2.19.2 → 2.19.3
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 +94 -80
- package/lib/api/controllers/authController.js +239 -212
- package/lib/api/controllers/baseController.js +89 -51
- package/lib/api/controllers/bulkController.js +62 -49
- package/lib/api/controllers/clusterController.js +6 -8
- package/lib/api/controllers/collectionController.js +140 -129
- package/lib/api/controllers/debugController.d.ts +2 -2
- package/lib/api/controllers/debugController.js +33 -31
- package/lib/api/controllers/documentController.js +365 -274
- package/lib/api/controllers/index.js +13 -13
- package/lib/api/controllers/indexController.js +46 -50
- package/lib/api/controllers/memoryStorageController.js +410 -360
- package/lib/api/controllers/realtimeController.js +37 -36
- package/lib/api/controllers/securityController.js +553 -412
- package/lib/api/controllers/serverController.js +111 -104
- package/lib/api/documentExtractor.js +75 -68
- package/lib/api/funnel.js +411 -312
- package/lib/api/httpRoutes.js +1493 -324
- package/lib/api/openapi/OpenApiManager.d.ts +1 -1
- package/lib/api/openapi/OpenApiManager.js +22 -22
- package/lib/api/openapi/components/document/count.yaml +1 -1
- package/lib/api/openapi/components/document/create.yaml +2 -2
- package/lib/api/openapi/components/document/delete.yaml +1 -1
- package/lib/api/openapi/components/document/deleteByQuery.yaml +1 -1
- package/lib/api/openapi/components/document/exists.yaml +1 -1
- package/lib/api/openapi/components/document/get.yaml +2 -2
- package/lib/api/openapi/components/document/index.js +12 -12
- package/lib/api/openapi/components/document/replace.yaml +1 -1
- package/lib/api/openapi/components/document/scroll.yaml +1 -1
- package/lib/api/openapi/components/document/validate.yaml +1 -1
- package/lib/api/openapi/components/index.d.ts +2 -2
- package/lib/api/openapi/components/index.js +1 -1
- package/lib/api/openapi/components/security/index.js +1 -1
- package/lib/api/openapi/components/security/upsertUser.yaml +2 -3
- package/lib/api/openapi/index.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.js +7 -7
- package/lib/api/rateLimiter.js +12 -13
- package/lib/api/request/index.d.ts +4 -4
- package/lib/api/request/kuzzleRequest.d.ts +9 -9
- package/lib/api/request/kuzzleRequest.js +89 -87
- package/lib/api/request/requestContext.d.ts +2 -2
- package/lib/api/request/requestContext.js +17 -17
- package/lib/api/request/requestInput.d.ts +1 -1
- package/lib/api/request/requestInput.js +19 -19
- package/lib/api/request/requestResponse.d.ts +4 -4
- package/lib/api/request/requestResponse.js +31 -33
- package/lib/cluster/command.js +48 -44
- package/lib/cluster/idCardHandler.d.ts +1 -1
- package/lib/cluster/idCardHandler.js +15 -15
- package/lib/cluster/index.js +2 -2
- package/lib/cluster/node.js +301 -269
- package/lib/cluster/publisher.js +45 -46
- package/lib/cluster/state.d.ts +5 -5
- package/lib/cluster/state.js +8 -8
- package/lib/cluster/subscriber.js +163 -113
- package/lib/cluster/workers/IDCardRenewer.js +33 -32
- package/lib/config/default.config.d.ts +1 -1
- package/lib/config/default.config.js +212 -171
- package/lib/config/documentEventAliases.js +6 -6
- package/lib/config/index.js +161 -98
- package/lib/config/sdkCompatibility.json +8 -8
- package/lib/core/auth/formatProcessing.js +7 -7
- package/lib/core/auth/passportResponse.js +7 -7
- package/lib/core/auth/passportWrapper.js +34 -30
- package/lib/core/auth/tokenManager.d.ts +2 -2
- package/lib/core/auth/tokenManager.js +11 -10
- package/lib/core/backend/applicationManager.d.ts +1 -1
- package/lib/core/backend/applicationManager.js +2 -2
- package/lib/core/backend/backend.d.ts +3 -3
- package/lib/core/backend/backend.js +34 -31
- package/lib/core/backend/backendCluster.d.ts +2 -2
- package/lib/core/backend/backendCluster.js +5 -5
- package/lib/core/backend/backendConfig.d.ts +2 -2
- package/lib/core/backend/backendConfig.js +3 -3
- package/lib/core/backend/backendController.d.ts +2 -2
- package/lib/core/backend/backendController.js +9 -10
- package/lib/core/backend/backendErrors.d.ts +3 -3
- package/lib/core/backend/backendErrors.js +2 -1
- package/lib/core/backend/backendHook.d.ts +2 -2
- package/lib/core/backend/backendHook.js +5 -5
- package/lib/core/backend/backendImport.d.ts +3 -3
- package/lib/core/backend/backendImport.js +23 -23
- package/lib/core/backend/backendOpenApi.d.ts +2 -2
- package/lib/core/backend/backendOpenApi.js +16 -16
- package/lib/core/backend/backendPipe.d.ts +2 -2
- package/lib/core/backend/backendPipe.js +6 -6
- package/lib/core/backend/backendPlugin.d.ts +4 -4
- package/lib/core/backend/backendPlugin.js +14 -14
- package/lib/core/backend/backendStorage.d.ts +2 -2
- package/lib/core/backend/backendStorage.js +1 -2
- package/lib/core/backend/backendVault.d.ts +2 -2
- package/lib/core/backend/backendVault.js +3 -3
- package/lib/core/backend/index.d.ts +14 -14
- package/lib/core/backend/internalLogger.d.ts +1 -1
- package/lib/core/backend/internalLogger.js +5 -5
- package/lib/core/cache/cacheDbEnum.js +4 -4
- package/lib/core/cache/cacheEngine.js +79 -85
- package/lib/core/network/accessLogger.js +126 -120
- package/lib/core/network/clientConnection.js +5 -5
- package/lib/core/network/context.js +8 -8
- package/lib/core/network/entryPoint.js +100 -85
- package/lib/core/network/httpRouter/index.js +63 -60
- package/lib/core/network/httpRouter/routeHandler.js +18 -19
- package/lib/core/network/httpRouter/routePart.js +23 -19
- package/lib/core/network/protocolManifest.js +3 -3
- package/lib/core/network/protocols/httpMessage.js +8 -10
- package/lib/core/network/protocols/httpwsProtocol.js +305 -250
- package/lib/core/network/protocols/internalProtocol.js +27 -24
- package/lib/core/network/protocols/mqttProtocol.js +106 -96
- package/lib/core/network/protocols/protocol.js +20 -17
- package/lib/core/network/router.js +56 -46
- package/lib/core/plugin/plugin.js +151 -120
- package/lib/core/plugin/pluginContext.d.ts +7 -7
- package/lib/core/plugin/pluginContext.js +48 -44
- package/lib/core/plugin/pluginManifest.js +13 -12
- package/lib/core/plugin/pluginRepository.js +26 -27
- package/lib/core/plugin/pluginsManager.js +425 -304
- package/lib/core/plugin/privilegedContext.js +3 -3
- package/lib/core/realtime/actionEnum.js +1 -1
- package/lib/core/realtime/channel.d.ts +1 -1
- package/lib/core/realtime/channel.js +22 -22
- package/lib/core/realtime/connectionRooms.d.ts +1 -1
- package/lib/core/realtime/hotelClerk.d.ts +2 -2
- package/lib/core/realtime/hotelClerk.js +53 -50
- package/lib/core/realtime/index.js +5 -5
- package/lib/core/realtime/notification/document.js +25 -25
- package/lib/core/realtime/notification/index.js +4 -4
- package/lib/core/realtime/notification/server.js +3 -3
- package/lib/core/realtime/notification/user.js +4 -4
- package/lib/core/realtime/notifier.js +113 -75
- package/lib/core/realtime/room.d.ts +1 -1
- package/lib/core/realtime/subscription.d.ts +1 -1
- package/lib/core/realtime/subscription.js +1 -1
- package/lib/core/security/index.js +8 -8
- package/lib/core/security/profileRepository.d.ts +6 -6
- package/lib/core/security/profileRepository.js +48 -45
- package/lib/core/security/roleRepository.js +127 -115
- package/lib/core/security/securityLoader.js +70 -63
- package/lib/core/security/tokenRepository.js +132 -118
- package/lib/core/security/userRepository.js +104 -88
- package/lib/core/shared/KoncordeWrapper.d.ts +1 -1
- package/lib/core/shared/KoncordeWrapper.js +3 -1
- package/lib/core/shared/abstractManifest.js +22 -23
- package/lib/core/shared/repository.js +69 -67
- package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
- package/lib/core/shared/sdk/embeddedSdk.js +36 -32
- package/lib/core/shared/sdk/funnelProtocol.d.ts +1 -1
- package/lib/core/shared/sdk/funnelProtocol.js +11 -11
- package/lib/core/shared/sdk/impersonatedSdk.js +19 -18
- package/lib/core/shared/store.js +127 -32
- package/lib/core/statistics/index.js +2 -2
- package/lib/core/statistics/statistics.js +99 -85
- package/lib/core/storage/clientAdapter.js +219 -136
- package/lib/core/storage/indexCache.js +3 -3
- package/lib/core/storage/storageEngine.js +10 -13
- package/lib/core/storage/storeScopeEnum.js +3 -3
- package/lib/core/validation/baseType.js +12 -10
- package/lib/core/validation/index.js +2 -2
- package/lib/core/validation/types/anything.js +4 -4
- package/lib/core/validation/types/boolean.js +7 -7
- package/lib/core/validation/types/date.js +165 -131
- package/lib/core/validation/types/email.js +18 -21
- package/lib/core/validation/types/enum.js +34 -21
- package/lib/core/validation/types/geoPoint.js +7 -7
- package/lib/core/validation/types/geoShape.js +148 -125
- package/lib/core/validation/types/integer.js +9 -9
- package/lib/core/validation/types/ipAddress.js +17 -19
- package/lib/core/validation/types/numeric.js +36 -29
- package/lib/core/validation/types/object.js +19 -19
- package/lib/core/validation/types/string.js +36 -29
- package/lib/core/validation/types/url.js +17 -19
- package/lib/core/validation/validation.js +422 -378
- package/lib/kerror/codes/1-services.json +7 -1
- package/lib/kerror/codes/4-plugin.json +2 -2
- package/lib/kerror/codes/index.js +85 -63
- package/lib/kerror/errors/badRequestError.d.ts +1 -1
- package/lib/kerror/errors/externalServiceError.d.ts +1 -1
- package/lib/kerror/errors/forbiddenError.d.ts +1 -1
- package/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
- package/lib/kerror/errors/index.d.ts +15 -15
- package/lib/kerror/errors/internalError.d.ts +1 -1
- package/lib/kerror/errors/kuzzleError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.js +1 -1
- package/lib/kerror/errors/notFoundError.d.ts +1 -1
- package/lib/kerror/errors/partialError.d.ts +1 -1
- package/lib/kerror/errors/partialError.js +1 -1
- package/lib/kerror/errors/pluginImplementationError.d.ts +1 -1
- package/lib/kerror/errors/pluginImplementationError.js +2 -1
- package/lib/kerror/errors/preconditionError.d.ts +1 -1
- package/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
- package/lib/kerror/errors/sizeLimitError.d.ts +1 -1
- package/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
- package/lib/kerror/errors/unauthorizedError.d.ts +1 -1
- package/lib/kerror/index.d.ts +3 -3
- package/lib/kerror/index.js +17 -16
- package/lib/kuzzle/dumpGenerator.js +130 -114
- package/lib/kuzzle/event/kuzzleEventEmitter.js +96 -70
- package/lib/kuzzle/event/pipeRunner.js +25 -24
- package/lib/kuzzle/event/waterfall.js +13 -15
- package/lib/kuzzle/index.js +2 -2
- package/lib/kuzzle/internalIndexHandler.js +80 -59
- package/lib/kuzzle/kuzzle.js +99 -99
- package/lib/kuzzle/kuzzleStateEnum.js +1 -1
- package/lib/kuzzle/log.js +23 -18
- package/lib/kuzzle/vault.js +34 -19
- package/lib/model/security/profile.d.ts +3 -3
- package/lib/model/security/profile.js +38 -37
- package/lib/model/security/rights.js +5 -5
- package/lib/model/security/role.d.ts +3 -3
- package/lib/model/security/role.js +25 -26
- package/lib/model/security/token.d.ts +1 -1
- package/lib/model/security/token.js +4 -4
- package/lib/model/security/user.d.ts +2 -2
- package/lib/model/security/user.js +9 -9
- package/lib/model/storage/apiKey.js +43 -33
- package/lib/model/storage/baseModel.js +49 -45
- package/lib/service/cache/redis.js +60 -55
- package/lib/service/service.js +17 -17
- package/lib/service/storage/elasticsearch.js +839 -755
- package/lib/service/storage/esWrapper.js +103 -86
- package/lib/service/storage/queryTranslator.js +52 -59
- package/lib/types/Controller.d.ts +3 -3
- package/lib/types/ControllerDefinition.d.ts +3 -3
- package/lib/types/DebugModule.d.ts +2 -2
- package/lib/types/DebugModule.js +1 -1
- package/lib/types/Global.d.ts +1 -1
- package/lib/types/HttpStream.d.ts +2 -1
- package/lib/types/HttpStream.js +7 -5
- package/lib/types/Kuzzle.d.ts +1 -1
- package/lib/types/KuzzleDocument.d.ts +1 -1
- package/lib/types/OpenApiDefinition.d.ts +1 -1
- package/lib/types/PasswordPolicy.d.ts +1 -1
- package/lib/types/Plugin.d.ts +6 -6
- package/lib/types/Plugin.js +2 -2
- package/lib/types/Policy.d.ts +1 -1
- package/lib/types/RequestPayload.d.ts +1 -1
- package/lib/types/ResponsePayload.d.ts +1 -1
- package/lib/types/Token.d.ts +1 -1
- package/lib/types/User.d.ts +1 -1
- package/lib/types/config/DumpConfiguration.d.ts +8 -8
- package/lib/types/config/HttpConfiguration.d.ts +1 -1
- package/lib/types/config/KuzzleConfiguration.d.ts +1 -1
- package/lib/types/config/LimitsConfiguration.d.ts +8 -8
- package/lib/types/config/PluginsConfiguration.d.ts +4 -4
- package/lib/types/config/SecurityConfiguration.d.ts +62 -62
- package/lib/types/config/ServerConfiguration.d.ts +55 -55
- package/lib/types/config/ServicesConfiguration.d.ts +2 -2
- package/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +10 -10
- package/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +3 -3
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +194 -110
- package/lib/types/errors/ErrorDefinition.d.ts +1 -1
- package/lib/types/errors/ErrorDomains.d.ts +1 -1
- package/lib/types/index.d.ts +38 -38
- package/lib/types/realtime/RealtimeScope.d.ts +1 -1
- package/lib/types/realtime/RealtimeUsers.d.ts +1 -1
- package/lib/util/assertType.js +13 -11
- package/lib/util/async.d.ts +1 -0
- package/lib/util/async.js +61 -0
- package/lib/util/asyncStore.js +19 -21
- package/lib/util/bufferedPassThrough.d.ts +2 -2
- package/lib/util/bufferedPassThrough.js +4 -4
- package/lib/util/bytes.js +9 -13
- package/lib/util/crypto.js +1 -1
- package/lib/util/debug.js +5 -5
- package/lib/util/deprecate.js +24 -21
- package/lib/util/didYouMean.js +7 -7
- package/lib/util/dump-collection.d.ts +2 -2
- package/lib/util/dump-collection.js +26 -26
- package/lib/util/esRequest.d.ts +1 -0
- package/lib/util/esRequest.js +62 -0
- package/lib/util/extractFields.js +24 -25
- package/lib/util/inflector.js +5 -5
- package/lib/util/koncordeCompat.d.ts +2 -2
- package/lib/util/koncordeCompat.js +5 -5
- package/lib/util/memoize.js +3 -5
- package/lib/util/mutex.d.ts +19 -1
- package/lib/util/mutex.js +39 -12
- package/lib/util/name-generator.js +1331 -1331
- package/lib/util/promback.js +8 -10
- package/lib/util/readYamlFile.d.ts +1 -1
- package/lib/util/readYamlFile.js +1 -1
- package/lib/util/requestAssertions.js +34 -34
- package/lib/util/safeObject.js +5 -5
- package/lib/util/stackTrace.js +20 -22
- package/lib/util/wildcard.js +15 -15
- package/package.json +6 -6
- package/npm-shrinkwrap.json +0 -19422
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const Bluebird = require(
|
|
24
|
+
const Bluebird = require("bluebird");
|
|
25
25
|
|
|
26
|
-
const cacheDbEnum = require(
|
|
27
|
-
const kerror = require(
|
|
26
|
+
const cacheDbEnum = require("../cache/cacheDbEnum");
|
|
27
|
+
const kerror = require("../../kerror");
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* @class Repository
|
|
@@ -41,7 +41,7 @@ class Repository {
|
|
|
41
41
|
* @param {{cache: cacheDbEnum, store: Store}} [options]
|
|
42
42
|
* @constructor
|
|
43
43
|
*/
|
|
44
|
-
constructor
|
|
44
|
+
constructor({ cache = cacheDbEnum.INTERNAL, store = null } = {}) {
|
|
45
45
|
this.ttl = global.kuzzle.config.repositories.common.cacheTTL;
|
|
46
46
|
this.collection = null;
|
|
47
47
|
this.ObjectConstructor = null;
|
|
@@ -54,15 +54,14 @@ class Repository {
|
|
|
54
54
|
* @param {string} id
|
|
55
55
|
* @returns {Promise} resolves on a new ObjectConstructor()
|
|
56
56
|
*/
|
|
57
|
-
async loadOneFromDatabase
|
|
57
|
+
async loadOneFromDatabase(id) {
|
|
58
58
|
let response;
|
|
59
59
|
|
|
60
60
|
try {
|
|
61
61
|
response = await this.store.get(this.collection, id);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
62
|
+
} catch (error) {
|
|
64
63
|
if (error.status === 404) {
|
|
65
|
-
throw kerror.get(
|
|
64
|
+
throw kerror.get("services", "storage", "not_found", id);
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
throw error;
|
|
@@ -73,8 +72,7 @@ class Repository {
|
|
|
73
72
|
|
|
74
73
|
if (response._source) {
|
|
75
74
|
Object.assign(dto, response._source, { _id: response._id });
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
75
|
+
} else {
|
|
78
76
|
Object.assign(dto, response);
|
|
79
77
|
}
|
|
80
78
|
|
|
@@ -89,16 +87,16 @@ class Repository {
|
|
|
89
87
|
* @param {string[]|object[]} _ids
|
|
90
88
|
* @returns {Promise<object>}
|
|
91
89
|
*/
|
|
92
|
-
async loadMultiFromDatabase
|
|
90
|
+
async loadMultiFromDatabase(ids) {
|
|
93
91
|
const { items } = await this.store.mGet(this.collection, ids);
|
|
94
92
|
|
|
95
93
|
if (items.length === 0) {
|
|
96
94
|
return [];
|
|
97
95
|
}
|
|
98
96
|
|
|
99
|
-
return Bluebird.map(
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
return Bluebird.map(items, (doc) =>
|
|
98
|
+
this.fromDTO(Object.assign({}, doc._source, { _id: doc._id }))
|
|
99
|
+
);
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
/**
|
|
@@ -108,8 +106,12 @@ class Repository {
|
|
|
108
106
|
* @param {object} [options] - optional search arguments (from, size, scroll)
|
|
109
107
|
* @returns {Promise}
|
|
110
108
|
*/
|
|
111
|
-
async search
|
|
112
|
-
const response = await this.store.search(
|
|
109
|
+
async search(searchBody, options = {}) {
|
|
110
|
+
const response = await this.store.search(
|
|
111
|
+
this.collection,
|
|
112
|
+
searchBody,
|
|
113
|
+
options
|
|
114
|
+
);
|
|
113
115
|
|
|
114
116
|
return this._formatSearchResults(response);
|
|
115
117
|
}
|
|
@@ -119,7 +121,7 @@ class Repository {
|
|
|
119
121
|
* @param {string} scrollId
|
|
120
122
|
* @param {string} [ttl]
|
|
121
123
|
*/
|
|
122
|
-
async scroll
|
|
124
|
+
async scroll(scrollId, ttl) {
|
|
123
125
|
const response = await this.store.scroll(scrollId, ttl);
|
|
124
126
|
|
|
125
127
|
return this._formatSearchResults(response);
|
|
@@ -137,7 +139,7 @@ class Repository {
|
|
|
137
139
|
* @param {object} [options] - Optional options.
|
|
138
140
|
* @returns {Promise}
|
|
139
141
|
*/
|
|
140
|
-
async loadFromCache
|
|
142
|
+
async loadFromCache(id, options = {}) {
|
|
141
143
|
const key = options.key || this.getCacheKey(id);
|
|
142
144
|
let response;
|
|
143
145
|
|
|
@@ -149,9 +151,8 @@ class Repository {
|
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
return await this.fromDTO(Object.assign({}, JSON.parse(response)));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
throw kerror.get('services', 'cache', 'read_failed', err.message);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
throw kerror.get("services", "cache", "read_failed", err.message);
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
|
|
@@ -172,7 +173,7 @@ class Repository {
|
|
|
172
173
|
* @param {object} [options] - Optional options.
|
|
173
174
|
* @returns {Promise}
|
|
174
175
|
*/
|
|
175
|
-
async load
|
|
176
|
+
async load(id, options = {}) {
|
|
176
177
|
if (this.cacheDb === cacheDbEnum.NONE) {
|
|
177
178
|
return this.loadOneFromDatabase(id);
|
|
178
179
|
}
|
|
@@ -205,21 +206,23 @@ class Repository {
|
|
|
205
206
|
* @param {object} [options] - The persistence options
|
|
206
207
|
* @returns {Promise}
|
|
207
208
|
*/
|
|
208
|
-
persistToDatabase
|
|
209
|
-
const method = options.method ||
|
|
209
|
+
persistToDatabase(object, options = {}) {
|
|
210
|
+
const method = options.method || "createOrReplace";
|
|
210
211
|
|
|
211
|
-
if (method ===
|
|
212
|
+
if (method === "create") {
|
|
212
213
|
return this.store.create(
|
|
213
214
|
this.collection,
|
|
214
215
|
this.serializeToDatabase(object),
|
|
215
|
-
{ ...options, id: object._id }
|
|
216
|
+
{ ...options, id: object._id }
|
|
217
|
+
);
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
return this.store[method](
|
|
219
221
|
this.collection,
|
|
220
222
|
object._id,
|
|
221
223
|
this.serializeToDatabase(object),
|
|
222
|
-
options
|
|
224
|
+
options
|
|
225
|
+
);
|
|
223
226
|
}
|
|
224
227
|
|
|
225
228
|
/**
|
|
@@ -231,7 +234,7 @@ class Repository {
|
|
|
231
234
|
* @param {object} [options] - optional options for the current operation
|
|
232
235
|
* @returns {Promise}
|
|
233
236
|
*/
|
|
234
|
-
delete
|
|
237
|
+
delete(object, options = {}) {
|
|
235
238
|
const promises = [];
|
|
236
239
|
|
|
237
240
|
if (this.cacheDb !== cacheDbEnum.NONE) {
|
|
@@ -251,7 +254,7 @@ class Repository {
|
|
|
251
254
|
* @param {string} id
|
|
252
255
|
* @param {object} [options]
|
|
253
256
|
*/
|
|
254
|
-
deleteFromDatabase
|
|
257
|
+
deleteFromDatabase(id, options = {}) {
|
|
255
258
|
return this.store.delete(this.collection, id, options);
|
|
256
259
|
}
|
|
257
260
|
|
|
@@ -267,13 +270,13 @@ class Repository {
|
|
|
267
270
|
* @param {object} [options] - Optional options for the current operation
|
|
268
271
|
* @returns {Promise}
|
|
269
272
|
*/
|
|
270
|
-
async persistToCache
|
|
273
|
+
async persistToCache(object, options = {}) {
|
|
271
274
|
const key = options.key || this.getCacheKey(object._id);
|
|
272
275
|
const value = JSON.stringify(this.serializeToCache(object));
|
|
273
276
|
const ttl = options.ttl !== undefined ? options.ttl : this.ttl;
|
|
274
277
|
|
|
275
278
|
await global.kuzzle.ask(`core:cache:${this.cacheDb}:store`, key, value, {
|
|
276
|
-
ttl
|
|
279
|
+
ttl,
|
|
277
280
|
});
|
|
278
281
|
|
|
279
282
|
return object;
|
|
@@ -288,7 +291,7 @@ class Repository {
|
|
|
288
291
|
* @param {object} [options] - optional options for the current operation
|
|
289
292
|
* @returns {Promise}
|
|
290
293
|
*/
|
|
291
|
-
deleteFromCache
|
|
294
|
+
deleteFromCache(id, options = {}) {
|
|
292
295
|
const key = options.key || this.getCacheKey(id);
|
|
293
296
|
|
|
294
297
|
return global.kuzzle.ask(`core:cache:${this.cacheDb}:del`, key);
|
|
@@ -299,19 +302,17 @@ class Repository {
|
|
|
299
302
|
* @param {object} [options] - optional options for the current operation
|
|
300
303
|
* @returns {Promise}
|
|
301
304
|
*/
|
|
302
|
-
refreshCacheTTL
|
|
305
|
+
refreshCacheTTL(object, options = {}) {
|
|
303
306
|
const key = options.key || this.getCacheKey(object._id);
|
|
304
307
|
let ttl;
|
|
305
308
|
|
|
306
309
|
if (options.ttl !== undefined) {
|
|
307
310
|
ttl = options.ttl;
|
|
308
|
-
}
|
|
309
|
-
else if (object.ttl !== undefined) {
|
|
311
|
+
} else if (object.ttl !== undefined) {
|
|
310
312
|
// if a TTL has been defined at the entry creation, we should
|
|
311
313
|
// use it
|
|
312
314
|
ttl = object.ttl;
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
+
} else {
|
|
315
316
|
ttl = this.ttl;
|
|
316
317
|
}
|
|
317
318
|
|
|
@@ -327,7 +328,7 @@ class Repository {
|
|
|
327
328
|
* @param {object} [options] - optional options for the current operation
|
|
328
329
|
* @returns {*}
|
|
329
330
|
*/
|
|
330
|
-
expireFromCache
|
|
331
|
+
expireFromCache(object, options = {}) {
|
|
331
332
|
const key = options.key || this.getCacheKey(object._id);
|
|
332
333
|
return global.kuzzle.ask(`core:cache:${this.cacheDb}:expire`, key, -1);
|
|
333
334
|
}
|
|
@@ -338,7 +339,7 @@ class Repository {
|
|
|
338
339
|
* @param {object} object - The object to serialize
|
|
339
340
|
* @returns {object}
|
|
340
341
|
*/
|
|
341
|
-
serializeToCache
|
|
342
|
+
serializeToCache(object) {
|
|
342
343
|
return this.toDTO(object);
|
|
343
344
|
}
|
|
344
345
|
|
|
@@ -348,7 +349,7 @@ class Repository {
|
|
|
348
349
|
* @param {object} object - The object to serialize
|
|
349
350
|
* @returns {object}
|
|
350
351
|
*/
|
|
351
|
-
serializeToDatabase
|
|
352
|
+
serializeToDatabase(object) {
|
|
352
353
|
const dto = this.toDTO(object);
|
|
353
354
|
delete dto._id;
|
|
354
355
|
return dto;
|
|
@@ -357,7 +358,7 @@ class Repository {
|
|
|
357
358
|
/**
|
|
358
359
|
* @param {string} id
|
|
359
360
|
*/
|
|
360
|
-
getCacheKey
|
|
361
|
+
getCacheKey(id) {
|
|
361
362
|
return `repos/${this.index}/${this.collection}/${id}`;
|
|
362
363
|
}
|
|
363
364
|
|
|
@@ -365,7 +366,7 @@ class Repository {
|
|
|
365
366
|
* @param {object} dto
|
|
366
367
|
* @returns {Promise<ObjectConstructor>}
|
|
367
368
|
*/
|
|
368
|
-
async fromDTO
|
|
369
|
+
async fromDTO(dto) {
|
|
369
370
|
const o = new this.ObjectConstructor();
|
|
370
371
|
Object.assign(o, dto);
|
|
371
372
|
|
|
@@ -376,7 +377,7 @@ class Repository {
|
|
|
376
377
|
* @param {ObjectConstructor} o
|
|
377
378
|
* @returns {object}
|
|
378
379
|
*/
|
|
379
|
-
toDTO
|
|
380
|
+
toDTO(o) {
|
|
380
381
|
return Object.assign({}, o);
|
|
381
382
|
}
|
|
382
383
|
|
|
@@ -387,7 +388,7 @@ class Repository {
|
|
|
387
388
|
* @param {object} part
|
|
388
389
|
* @returns {Promise<integer>} total deleted objects
|
|
389
390
|
*/
|
|
390
|
-
async truncate
|
|
391
|
+
async truncate(options) {
|
|
391
392
|
// Allows safe overrides, as _truncate is called recursively
|
|
392
393
|
return this._truncate(options);
|
|
393
394
|
}
|
|
@@ -396,16 +397,19 @@ class Repository {
|
|
|
396
397
|
* Do not override this: this function calls itself.
|
|
397
398
|
* @private
|
|
398
399
|
*/
|
|
399
|
-
async _truncate
|
|
400
|
+
async _truncate(options, part = null) {
|
|
400
401
|
if (part === null) {
|
|
401
|
-
const objects = await this.search(
|
|
402
|
+
const objects = await this.search(
|
|
403
|
+
{},
|
|
404
|
+
{ refresh: options.refresh, scroll: "5s", size: 100 }
|
|
405
|
+
);
|
|
402
406
|
const deleted = await this._truncatePart(objects, options);
|
|
403
407
|
|
|
404
408
|
if (objects.hits.length < objects.total) {
|
|
405
409
|
const total = await this._truncate(options, {
|
|
406
410
|
fetched: objects.hits.length,
|
|
407
411
|
scrollId: objects.scrollId,
|
|
408
|
-
total: objects.total
|
|
412
|
+
total: objects.total,
|
|
409
413
|
});
|
|
410
414
|
|
|
411
415
|
return deleted + total;
|
|
@@ -414,7 +418,7 @@ class Repository {
|
|
|
414
418
|
return deleted;
|
|
415
419
|
}
|
|
416
420
|
|
|
417
|
-
const objects = await this.scroll(part.scrollId,
|
|
421
|
+
const objects = await this.scroll(part.scrollId, "5s");
|
|
418
422
|
const deleted = await this._truncatePart(objects, options);
|
|
419
423
|
|
|
420
424
|
part.fetched += objects.hits.length;
|
|
@@ -435,26 +439,24 @@ class Repository {
|
|
|
435
439
|
* @returns {Promise<integer>} count of deleted objects
|
|
436
440
|
* @private
|
|
437
441
|
*/
|
|
438
|
-
async _truncatePart
|
|
439
|
-
return Bluebird
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
? ['admin', 'default', 'anonymous']
|
|
442
|
+
async _truncatePart(objects, options) {
|
|
443
|
+
return Bluebird.map(objects.hits, async (object) => {
|
|
444
|
+
// profile and role repositories have protected objects, we can't delete
|
|
445
|
+
// them
|
|
446
|
+
const protectedObjects =
|
|
447
|
+
["profiles", "roles"].indexOf(this.collection) !== -1
|
|
448
|
+
? ["admin", "default", "anonymous"]
|
|
446
449
|
: [];
|
|
447
450
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
+
if (protectedObjects.indexOf(object._id) !== -1) {
|
|
452
|
+
return 0;
|
|
453
|
+
}
|
|
451
454
|
|
|
452
|
-
|
|
453
|
-
|
|
455
|
+
const loaded = await this.load(object._id);
|
|
456
|
+
await this.delete(loaded, options);
|
|
454
457
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
.reduce((total, deleted) => total + deleted, 0);
|
|
458
|
+
return 1;
|
|
459
|
+
}).reduce((total, deleted) => total + deleted, 0);
|
|
458
460
|
}
|
|
459
461
|
|
|
460
462
|
/**
|
|
@@ -463,7 +465,7 @@ class Repository {
|
|
|
463
465
|
* @returns {Promise<object>}
|
|
464
466
|
* @private
|
|
465
467
|
*/
|
|
466
|
-
async _formatSearchResults
|
|
468
|
+
async _formatSearchResults(raw) {
|
|
467
469
|
const result = {
|
|
468
470
|
aggregations: raw.aggregations,
|
|
469
471
|
hits: [],
|
|
@@ -472,7 +474,7 @@ class Repository {
|
|
|
472
474
|
};
|
|
473
475
|
|
|
474
476
|
if (raw.hits && raw.hits.length > 0) {
|
|
475
|
-
result.hits = await Bluebird.map(raw.hits, doc => {
|
|
477
|
+
result.hits = await Bluebird.map(raw.hits, (doc) => {
|
|
476
478
|
return this.fromDTO(Object.assign({}, doc._source, { _id: doc._id }));
|
|
477
479
|
});
|
|
478
480
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RealtimeController, Notification, JSONObject, ScopeOption, UserOption, Kuzzle, RequestPayload } from
|
|
2
|
-
import { ResponsePayload } from
|
|
1
|
+
import { RealtimeController, Notification, JSONObject, ScopeOption, UserOption, Kuzzle, RequestPayload } from "kuzzle-sdk";
|
|
2
|
+
import { ResponsePayload } from "../../../types";
|
|
3
3
|
interface EmbeddedRealtime extends RealtimeController {
|
|
4
4
|
/**
|
|
5
5
|
* Subscribes by providing a set of filters: messages, document changes
|
|
@@ -53,30 +53,30 @@ const funnelProtocol_1 = require("./funnelProtocol");
|
|
|
53
53
|
const safeObject_1 = require("../../../util/safeObject");
|
|
54
54
|
const kerror = __importStar(require("../../../kerror"));
|
|
55
55
|
const impersonatedSdk_1 = __importDefault(require("./impersonatedSdk"));
|
|
56
|
-
const contextError = kerror.wrap(
|
|
56
|
+
const contextError = kerror.wrap("plugin", "context");
|
|
57
57
|
const forbiddenEmbeddedActions = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
auth: new Set([
|
|
59
|
+
"checkRights",
|
|
60
|
+
"createApiKey",
|
|
61
|
+
"createMyCredentials",
|
|
62
|
+
"credentialsExist",
|
|
63
|
+
"deleteApiKey",
|
|
64
|
+
"getCurrentUser",
|
|
65
|
+
"getMyCredentials",
|
|
66
|
+
"getMyRights",
|
|
67
|
+
"getStrategies",
|
|
68
|
+
"logout",
|
|
69
|
+
"refreshToken",
|
|
70
|
+
"searchApiKeys",
|
|
71
|
+
"updateMyCredentials",
|
|
72
|
+
"updateSelf",
|
|
73
|
+
"validateMyCredentials",
|
|
74
74
|
]),
|
|
75
75
|
};
|
|
76
76
|
const warnEmbeddedActions = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
77
|
+
auth: {
|
|
78
|
+
login: "EmbeddedSDK.login is deprecated, use user impersonation instead",
|
|
79
|
+
},
|
|
80
80
|
};
|
|
81
81
|
/**
|
|
82
82
|
* Kuzzle embedded SDK to make API calls inside applications or plugins.
|
|
@@ -93,8 +93,8 @@ class EmbeddedSDK extends kuzzle_sdk_1.Kuzzle {
|
|
|
93
93
|
* @param options - Optional sdk arguments
|
|
94
94
|
*/
|
|
95
95
|
as(user, options = { checkRights: false }) {
|
|
96
|
-
if (!(0, safeObject_1.isPlainObject)(user) || typeof user._id !==
|
|
97
|
-
throw contextError.get(
|
|
96
|
+
if (!(0, safeObject_1.isPlainObject)(user) || typeof user._id !== "string") {
|
|
97
|
+
throw contextError.get("invalid_user");
|
|
98
98
|
}
|
|
99
99
|
return new impersonatedSdk_1.default(user._id, options);
|
|
100
100
|
}
|
|
@@ -109,18 +109,22 @@ class EmbeddedSDK extends kuzzle_sdk_1.Kuzzle {
|
|
|
109
109
|
*/
|
|
110
110
|
query(request, options = {}) {
|
|
111
111
|
// By default, do not propagate realtime notification accross cluster nodes
|
|
112
|
-
if ((0, safeObject_1.isPlainObject)(request)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
request.propagate =
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
if ((0, safeObject_1.isPlainObject)(request) &&
|
|
113
|
+
request.controller === "realtime" &&
|
|
114
|
+
request.action === "subscribe") {
|
|
115
|
+
request.propagate =
|
|
116
|
+
options.propagate === undefined || options.propagate === null
|
|
117
|
+
? false
|
|
118
|
+
: options.propagate;
|
|
118
119
|
}
|
|
119
|
-
if (forbiddenEmbeddedActions[request.controller] !== undefined
|
|
120
|
-
|
|
121
|
-
throw kerror.get(
|
|
120
|
+
if (forbiddenEmbeddedActions[request.controller] !== undefined &&
|
|
121
|
+
forbiddenEmbeddedActions[request.controller].has(request.action)) {
|
|
122
|
+
throw kerror.get("api", "process", "forbidden_embedded_sdk_action", request.controller, request.action, ", use user impersonation or security controller instead");
|
|
122
123
|
}
|
|
123
|
-
const warning = lodash_1.default.get(warnEmbeddedActions, [
|
|
124
|
+
const warning = lodash_1.default.get(warnEmbeddedActions, [
|
|
125
|
+
request.controller,
|
|
126
|
+
request.action,
|
|
127
|
+
]);
|
|
124
128
|
if (warning) {
|
|
125
129
|
global.kuzzle.log.warn(warning);
|
|
126
130
|
}
|
|
@@ -50,13 +50,13 @@ const kerror = __importStar(require("../../../kerror"));
|
|
|
50
50
|
class FunnelProtocol extends kuzzle_sdk_1.KuzzleEventEmitter {
|
|
51
51
|
constructor() {
|
|
52
52
|
super();
|
|
53
|
-
this.id =
|
|
53
|
+
this.id = "funnel";
|
|
54
54
|
this.connectionId = null;
|
|
55
55
|
/**
|
|
56
56
|
* Realtime notifications are sent by the InternalProtocol
|
|
57
57
|
* through the internal event system.
|
|
58
58
|
*/
|
|
59
|
-
global.kuzzle.on(
|
|
59
|
+
global.kuzzle.on("core:network:internal:message", (message) => {
|
|
60
60
|
// Send the notifications to the SDK for the internal Room mechanism
|
|
61
61
|
this.emit(message.room, message);
|
|
62
62
|
});
|
|
@@ -69,28 +69,28 @@ class FunnelProtocol extends kuzzle_sdk_1.KuzzleEventEmitter {
|
|
|
69
69
|
*/
|
|
70
70
|
async query(request) {
|
|
71
71
|
if (!this.connectionId) {
|
|
72
|
-
this.connectionId = await global.kuzzle.ask(
|
|
72
|
+
this.connectionId = await global.kuzzle.ask("core:network:internal:connectionId:get");
|
|
73
73
|
}
|
|
74
74
|
const requestOptions = {
|
|
75
75
|
connection: {
|
|
76
76
|
id: this.connectionId,
|
|
77
|
-
protocol: this.id
|
|
77
|
+
protocol: this.id,
|
|
78
78
|
},
|
|
79
79
|
user: null,
|
|
80
80
|
};
|
|
81
81
|
// Validate and use the provided request.kuid
|
|
82
82
|
if (request.__kuid__) {
|
|
83
|
-
if (typeof request.__kuid__ !==
|
|
84
|
-
throw kerror.get(
|
|
83
|
+
if (typeof request.__kuid__ !== "string") {
|
|
84
|
+
throw kerror.get("plugin", "context", "invalid_user");
|
|
85
85
|
}
|
|
86
86
|
// Get the user and store it in this context to prevent any possible race conditions
|
|
87
|
-
requestOptions.user = await global.kuzzle.ask(
|
|
87
|
+
requestOptions.user = await global.kuzzle.ask("core:security:user:get", request.__kuid__);
|
|
88
88
|
}
|
|
89
89
|
const kuzzleRequest = new request_1.Request(request, requestOptions);
|
|
90
|
-
if (requestOptions.user
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
throw kerror.get(
|
|
90
|
+
if (requestOptions.user &&
|
|
91
|
+
request.__checkRights__ &&
|
|
92
|
+
!(await requestOptions.user.isActionAllowed(kuzzleRequest))) {
|
|
93
|
+
throw kerror.get("security", "rights", "forbidden", kuzzleRequest.input.controller, kuzzleRequest.input.action, requestOptions.user._id);
|
|
94
94
|
}
|
|
95
95
|
const result = await global.kuzzle.funnel.executePluginRequest(kuzzleRequest);
|
|
96
96
|
return { result };
|
|
@@ -19,24 +19,24 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const nativeControllers = require(
|
|
24
|
+
const nativeControllers = require("../../../api/controllers");
|
|
25
25
|
|
|
26
26
|
class ImpersonatedSDK {
|
|
27
|
-
constructor
|
|
27
|
+
constructor(kuid, options = {}) {
|
|
28
28
|
this.kuid = kuid;
|
|
29
29
|
this.checkRights = options.checkRights || false;
|
|
30
30
|
|
|
31
31
|
for (const controller of Object.keys(nativeControllers)) {
|
|
32
32
|
// @todo in the future, native controller names should be normalized to sdk naming
|
|
33
33
|
const controllerName = controller
|
|
34
|
-
.replace(
|
|
35
|
-
.replace(
|
|
34
|
+
.replace("Controller", "")
|
|
35
|
+
.replace("MemoryStorage", "ms")
|
|
36
36
|
.toLowerCase();
|
|
37
37
|
const controllerProxy = `${controllerName}Proxy`;
|
|
38
38
|
|
|
39
|
-
if (!
|
|
39
|
+
if (!global.app.sdk[controllerName]) {
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -44,8 +44,7 @@ class ImpersonatedSDK {
|
|
|
44
44
|
Reflect.defineProperty(this, controllerName, {
|
|
45
45
|
get: () => {
|
|
46
46
|
// If the requested controller has not yet been proxied
|
|
47
|
-
if (!
|
|
48
|
-
|
|
47
|
+
if (!this[controllerProxy]) {
|
|
49
48
|
// Create a proxy object to inject our local 'query' behaviour
|
|
50
49
|
// in the underlying base 'sdk' action methods so we can send
|
|
51
50
|
// impersonation configuration (kuid & checkRights) to the funnel
|
|
@@ -58,31 +57,33 @@ class ImpersonatedSDK {
|
|
|
58
57
|
|
|
59
58
|
// Call the 'ImpersonatedSdk.query' method instead
|
|
60
59
|
return this.query(request, opts);
|
|
61
|
-
}
|
|
60
|
+
},
|
|
62
61
|
};
|
|
63
62
|
|
|
64
63
|
// Make sure we bring any local methods into our new custom context
|
|
65
|
-
Object.getOwnPropertyNames(
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
Object.getOwnPropertyNames(
|
|
65
|
+
Object.getPrototypeOf(global.app.sdk[controllerName])
|
|
66
|
+
).forEach((localMethod) => {
|
|
67
|
+
if (!["constructor", "query"].includes(localMethod)) {
|
|
68
|
+
customContext[localMethod] =
|
|
69
|
+
controllerInstance[localMethod];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
71
72
|
|
|
72
73
|
// Return the original SDK action method AND also bind our merged custom context
|
|
73
74
|
// containing our 'query' method and any original local methods
|
|
74
75
|
return controllerInstance[actionName].bind(customContext);
|
|
75
|
-
}
|
|
76
|
+
},
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
return this[controllerProxy];
|
|
80
|
-
}
|
|
81
|
+
},
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
query
|
|
86
|
+
query(request, options = {}) {
|
|
86
87
|
request.__kuid__ = this.kuid;
|
|
87
88
|
request.__checkRights__ = this.checkRights;
|
|
88
89
|
|