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
|
@@ -59,18 +59,18 @@ const errors_1 = require("../../kerror/errors");
|
|
|
59
59
|
const kerror = __importStar(require("../../kerror"));
|
|
60
60
|
const types_1 = require("../../types");
|
|
61
61
|
const assert = __importStar(require("../../util/assertType"));
|
|
62
|
-
const assertionError = kerror.wrap(
|
|
62
|
+
const assertionError = kerror.wrap("api", "assert");
|
|
63
63
|
// private properties
|
|
64
64
|
// \u200b is a zero width space, used to masquerade console.log output
|
|
65
|
-
const _internalId =
|
|
66
|
-
const _status =
|
|
67
|
-
const _input =
|
|
68
|
-
const _error =
|
|
69
|
-
const _result =
|
|
70
|
-
const _context =
|
|
71
|
-
const _timestamp =
|
|
72
|
-
const _response =
|
|
73
|
-
const _deprecations =
|
|
65
|
+
const _internalId = "internalId\u200b";
|
|
66
|
+
const _status = "status\u200b";
|
|
67
|
+
const _input = "input\u200b";
|
|
68
|
+
const _error = "error\u200b";
|
|
69
|
+
const _result = "result\u200b";
|
|
70
|
+
const _context = "context\u200b";
|
|
71
|
+
const _timestamp = "timestamp\u200b";
|
|
72
|
+
const _response = "response\u200b";
|
|
73
|
+
const _deprecations = "deprecations\u200b";
|
|
74
74
|
/**
|
|
75
75
|
* The `KuzzleRequest` class represents a request being processed by Kuzzle.
|
|
76
76
|
*
|
|
@@ -92,13 +92,13 @@ class KuzzleRequest {
|
|
|
92
92
|
// property
|
|
93
93
|
this[_input].headers = this[_context].connection.misc.headers;
|
|
94
94
|
this.id = data.requestId
|
|
95
|
-
? assert.assertString(
|
|
95
|
+
? assert.assertString("requestId", data.requestId)
|
|
96
96
|
: (0, nanoid_1.nanoid)();
|
|
97
97
|
this[_timestamp] = data.timestamp || Date.now();
|
|
98
98
|
// handling provided options
|
|
99
99
|
if (options !== undefined && options !== null) {
|
|
100
|
-
if (typeof options !==
|
|
101
|
-
throw new errors_1.InternalError(
|
|
100
|
+
if (typeof options !== "object" || Array.isArray(options)) {
|
|
101
|
+
throw new errors_1.InternalError("Request options must be an object");
|
|
102
102
|
}
|
|
103
103
|
/*
|
|
104
104
|
* Beware of the order of setXxx methods: if there is an
|
|
@@ -119,7 +119,7 @@ class KuzzleRequest {
|
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
121
|
const error = new errors_1.KuzzleError(options.error.message, options.error.status || 500);
|
|
122
|
-
for (const prop of Object.keys(options.error).filter(key => key !==
|
|
122
|
+
for (const prop of Object.keys(options.error).filter((key) => key !== "message" && key !== "status")) {
|
|
123
123
|
error[prop] = options.error[prop];
|
|
124
124
|
}
|
|
125
125
|
this.setError(error);
|
|
@@ -156,7 +156,7 @@ class KuzzleRequest {
|
|
|
156
156
|
return this[_status];
|
|
157
157
|
}
|
|
158
158
|
set status(i) {
|
|
159
|
-
this[_status] = assert.assertInteger(
|
|
159
|
+
this[_status] = assert.assertInteger("status", i);
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
162
|
* Request input
|
|
@@ -196,9 +196,10 @@ class KuzzleRequest {
|
|
|
196
196
|
*/
|
|
197
197
|
setError(error) {
|
|
198
198
|
if (!error || !(error instanceof Error)) {
|
|
199
|
-
throw new errors_1.InternalError(
|
|
199
|
+
throw new errors_1.InternalError("Cannot set non-error object as a request's error");
|
|
200
200
|
}
|
|
201
|
-
this[_error] =
|
|
201
|
+
this[_error] =
|
|
202
|
+
error instanceof errors_1.KuzzleError ? error : new errors_1.InternalError(error);
|
|
202
203
|
this.status = this[_error].status;
|
|
203
204
|
}
|
|
204
205
|
/**
|
|
@@ -221,15 +222,16 @@ class KuzzleRequest {
|
|
|
221
222
|
*/
|
|
222
223
|
setResult(result, options = {}) {
|
|
223
224
|
if (result instanceof Error) {
|
|
224
|
-
throw new errors_1.InternalError(
|
|
225
|
+
throw new errors_1.InternalError("cannot set an error as a request's response");
|
|
225
226
|
}
|
|
226
|
-
if (this.context.connection.protocol !==
|
|
227
|
-
|
|
227
|
+
if (this.context.connection.protocol !== "http" &&
|
|
228
|
+
result instanceof types_1.HttpStream) {
|
|
229
|
+
throw kerror.get("api", "assert", "forbidden_stream");
|
|
228
230
|
}
|
|
229
231
|
this.status = options.status || 200;
|
|
230
232
|
if (options.headers) {
|
|
231
233
|
this.response.configure({
|
|
232
|
-
headers: options.headers
|
|
234
|
+
headers: options.headers,
|
|
233
235
|
});
|
|
234
236
|
}
|
|
235
237
|
if (options.raw !== undefined) {
|
|
@@ -244,7 +246,7 @@ class KuzzleRequest {
|
|
|
244
246
|
* @param message message displayed in the warning
|
|
245
247
|
*/
|
|
246
248
|
addDeprecation(version, message) {
|
|
247
|
-
if (global.NODE_ENV !==
|
|
249
|
+
if (global.NODE_ENV !== "development") {
|
|
248
250
|
return;
|
|
249
251
|
}
|
|
250
252
|
const deprecation = {
|
|
@@ -329,9 +331,9 @@ class KuzzleRequest {
|
|
|
329
331
|
* It can only be 'elasticsearch' or 'koncorde'
|
|
330
332
|
*/
|
|
331
333
|
getLangParam() {
|
|
332
|
-
const lang = this.getString(
|
|
333
|
-
if (lang !==
|
|
334
|
-
throw kerror.get(
|
|
334
|
+
const lang = this.getString("lang", "elasticsearch");
|
|
335
|
+
if (lang !== "elasticsearch" && lang !== "koncorde") {
|
|
336
|
+
throw kerror.get("api", "assert", "invalid_argument", "lang", '"elasticsearch" or "koncorde"');
|
|
335
337
|
}
|
|
336
338
|
return lang;
|
|
337
339
|
}
|
|
@@ -367,7 +369,7 @@ class KuzzleRequest {
|
|
|
367
369
|
if (def !== undefined) {
|
|
368
370
|
return def;
|
|
369
371
|
}
|
|
370
|
-
throw assertionError.get(
|
|
372
|
+
throw assertionError.get("body_required");
|
|
371
373
|
}
|
|
372
374
|
return this._getNumber(body, name, `body.${name}`, def);
|
|
373
375
|
}
|
|
@@ -389,7 +391,7 @@ class KuzzleRequest {
|
|
|
389
391
|
if (def !== undefined) {
|
|
390
392
|
return def;
|
|
391
393
|
}
|
|
392
|
-
throw assertionError.get(
|
|
394
|
+
throw assertionError.get("body_required");
|
|
393
395
|
}
|
|
394
396
|
return this._getInteger(body, name, `body.${name}`, def);
|
|
395
397
|
}
|
|
@@ -411,7 +413,7 @@ class KuzzleRequest {
|
|
|
411
413
|
if (def !== undefined) {
|
|
412
414
|
return def;
|
|
413
415
|
}
|
|
414
|
-
throw assertionError.get(
|
|
416
|
+
throw assertionError.get("body_required");
|
|
415
417
|
}
|
|
416
418
|
return this._getString(body, name, `body.${name}`, def);
|
|
417
419
|
}
|
|
@@ -433,7 +435,7 @@ class KuzzleRequest {
|
|
|
433
435
|
if (def !== undefined) {
|
|
434
436
|
return def;
|
|
435
437
|
}
|
|
436
|
-
throw assertionError.get(
|
|
438
|
+
throw assertionError.get("body_required");
|
|
437
439
|
}
|
|
438
440
|
return this._getArray(body, name, `body.${name}`, def);
|
|
439
441
|
}
|
|
@@ -455,7 +457,7 @@ class KuzzleRequest {
|
|
|
455
457
|
if (def !== undefined) {
|
|
456
458
|
return def;
|
|
457
459
|
}
|
|
458
|
-
throw assertionError.get(
|
|
460
|
+
throw assertionError.get("body_required");
|
|
459
461
|
}
|
|
460
462
|
return this._getObject(body, name, `body.${name}`, def);
|
|
461
463
|
}
|
|
@@ -543,17 +545,17 @@ class KuzzleRequest {
|
|
|
543
545
|
getArrayLegacy(name, def = undefined) {
|
|
544
546
|
const value = (0, lodash_1.get)(this.input.args, name, def);
|
|
545
547
|
if (value === undefined) {
|
|
546
|
-
throw assertionError.get(
|
|
548
|
+
throw assertionError.get("missing_argument", name);
|
|
547
549
|
}
|
|
548
550
|
if (Array.isArray(value)) {
|
|
549
551
|
return value;
|
|
550
552
|
}
|
|
551
|
-
if (typeof value !==
|
|
552
|
-
throw assertionError.get(
|
|
553
|
+
if (typeof value !== "string") {
|
|
554
|
+
throw assertionError.get("invalid_type", name, "array");
|
|
553
555
|
}
|
|
554
556
|
// If we are using the HTTP protocol and we have a string instead of an Array
|
|
555
557
|
// we try to parse it as JSON
|
|
556
|
-
if (this.context.connection.protocol ===
|
|
558
|
+
if (this.context.connection.protocol === "http") {
|
|
557
559
|
try {
|
|
558
560
|
const parsedValue = JSON.parse(value);
|
|
559
561
|
if (Array.isArray(parsedValue)) {
|
|
@@ -564,7 +566,7 @@ class KuzzleRequest {
|
|
|
564
566
|
// Do nothing, let the code continue
|
|
565
567
|
}
|
|
566
568
|
}
|
|
567
|
-
return value.split(
|
|
569
|
+
return value.split(",");
|
|
568
570
|
}
|
|
569
571
|
/**
|
|
570
572
|
* Gets a parameter from a request arguments and checks that it is an object
|
|
@@ -596,13 +598,13 @@ class KuzzleRequest {
|
|
|
596
598
|
getDate(name, format) {
|
|
597
599
|
const args = this.input.args;
|
|
598
600
|
if (args[name] === undefined) {
|
|
599
|
-
throw assertionError.get(
|
|
601
|
+
throw assertionError.get("missing_argument", name);
|
|
600
602
|
}
|
|
601
603
|
if (format && !(0, moment_1.default)(args[name], format, true).isValid()) {
|
|
602
|
-
throw assertionError.get(
|
|
604
|
+
throw assertionError.get("invalid_type", name, "date");
|
|
603
605
|
}
|
|
604
606
|
if (!(0, moment_1.default)(args[name], moment_1.default.ISO_8601).isValid()) {
|
|
605
|
-
throw assertionError.get(
|
|
607
|
+
throw assertionError.get("invalid_type", name, "date");
|
|
606
608
|
}
|
|
607
609
|
return this.getString(name);
|
|
608
610
|
}
|
|
@@ -617,10 +619,10 @@ class KuzzleRequest {
|
|
|
617
619
|
getTimestamp(name) {
|
|
618
620
|
const args = this.input.args;
|
|
619
621
|
if (args[name] === undefined) {
|
|
620
|
-
throw assertionError.get(
|
|
622
|
+
throw assertionError.get("missing_argument", name);
|
|
621
623
|
}
|
|
622
624
|
if ((0, moment_1.default)(args[name], true).isValid() === false) {
|
|
623
|
-
throw assertionError.get(
|
|
625
|
+
throw assertionError.get("invalid_type", name, "date");
|
|
624
626
|
}
|
|
625
627
|
return this.getInteger(name);
|
|
626
628
|
}
|
|
@@ -629,7 +631,7 @@ class KuzzleRequest {
|
|
|
629
631
|
*/
|
|
630
632
|
getIndex({ required = true } = {}) {
|
|
631
633
|
const index = this.input.args.index;
|
|
632
|
-
this.checkRequired(index,
|
|
634
|
+
this.checkRequired(index, "index", required);
|
|
633
635
|
return index ? String(index) : null;
|
|
634
636
|
}
|
|
635
637
|
/**
|
|
@@ -637,7 +639,7 @@ class KuzzleRequest {
|
|
|
637
639
|
*/
|
|
638
640
|
getCollection({ required = true } = {}) {
|
|
639
641
|
const collection = this.input.args.collection;
|
|
640
|
-
this.checkRequired(collection,
|
|
642
|
+
this.checkRequired(collection, "collection", required);
|
|
641
643
|
return collection ? String(collection) : null;
|
|
642
644
|
}
|
|
643
645
|
/**
|
|
@@ -645,10 +647,10 @@ class KuzzleRequest {
|
|
|
645
647
|
*/
|
|
646
648
|
getIndexAndCollection() {
|
|
647
649
|
if (!this.input.args.index) {
|
|
648
|
-
throw assertionError.get(
|
|
650
|
+
throw assertionError.get("missing_argument", "index");
|
|
649
651
|
}
|
|
650
652
|
if (!this.input.args.collection) {
|
|
651
|
-
throw assertionError.get(
|
|
653
|
+
throw assertionError.get("missing_argument", "collection");
|
|
652
654
|
}
|
|
653
655
|
return {
|
|
654
656
|
collection: this.input.args.collection,
|
|
@@ -668,7 +670,7 @@ class KuzzleRequest {
|
|
|
668
670
|
if (def !== undefined) {
|
|
669
671
|
return def;
|
|
670
672
|
}
|
|
671
|
-
throw assertionError.get(
|
|
673
|
+
throw assertionError.get("body_required");
|
|
672
674
|
}
|
|
673
675
|
return this.input.body;
|
|
674
676
|
}
|
|
@@ -680,20 +682,20 @@ class KuzzleRequest {
|
|
|
680
682
|
* - `generator`: function used to generate an ID (default: 'uuid.v4')
|
|
681
683
|
*
|
|
682
684
|
*/
|
|
683
|
-
getId(options = { generator: uuid.v4, ifMissing:
|
|
685
|
+
getId(options = { generator: uuid.v4, ifMissing: "error" }) {
|
|
684
686
|
const id = this.input.args._id;
|
|
685
687
|
options.generator = options.generator || uuid.v4; // Default to uuid v4
|
|
686
688
|
if (!id) {
|
|
687
|
-
if (options.ifMissing ===
|
|
689
|
+
if (options.ifMissing === "generate") {
|
|
688
690
|
return options.generator();
|
|
689
691
|
}
|
|
690
|
-
if (options.ifMissing ===
|
|
692
|
+
if (options.ifMissing === "ignore") {
|
|
691
693
|
return null;
|
|
692
694
|
}
|
|
693
|
-
throw assertionError.get(
|
|
695
|
+
throw assertionError.get("missing_argument", "_id");
|
|
694
696
|
}
|
|
695
|
-
if (typeof id !==
|
|
696
|
-
throw assertionError.get(
|
|
697
|
+
if (typeof id !== "string") {
|
|
698
|
+
throw assertionError.get("invalid_type", "_id", "string");
|
|
697
699
|
}
|
|
698
700
|
return String(id);
|
|
699
701
|
}
|
|
@@ -719,20 +721,20 @@ class KuzzleRequest {
|
|
|
719
721
|
* Returns the search body query according to the http method
|
|
720
722
|
*/
|
|
721
723
|
getSearchBody() {
|
|
722
|
-
if (this.context.connection.protocol !==
|
|
723
|
-
|
|
724
|
+
if (this.context.connection.protocol !== "http" ||
|
|
725
|
+
this.context.connection.misc.verb !== "GET") {
|
|
724
726
|
return this.getBody({});
|
|
725
727
|
}
|
|
726
|
-
return this.getObject(
|
|
728
|
+
return this.getObject("searchBody", {});
|
|
727
729
|
}
|
|
728
730
|
/**
|
|
729
731
|
* Returns the search params.
|
|
730
732
|
*/
|
|
731
733
|
getSearchParams() {
|
|
732
|
-
const from = this.getInteger(
|
|
733
|
-
const size = this.getInteger(
|
|
734
|
+
const from = this.getInteger("from", 0);
|
|
735
|
+
const size = this.getInteger("size", 10);
|
|
734
736
|
const scrollTTL = this.getScrollTTLParam();
|
|
735
|
-
const query = this.getBodyObject(
|
|
737
|
+
const query = this.getBodyObject("query", {});
|
|
736
738
|
const searchBody = this.getSearchBody();
|
|
737
739
|
return { from, query, scrollTTL, searchBody, size };
|
|
738
740
|
}
|
|
@@ -741,24 +743,24 @@ class KuzzleRequest {
|
|
|
741
743
|
*/
|
|
742
744
|
getScrollTTLParam() {
|
|
743
745
|
const scrollTTLParam = this.input.args.scroll;
|
|
744
|
-
if (scrollTTLParam && typeof scrollTTLParam !==
|
|
745
|
-
throw assertionError.get(
|
|
746
|
+
if (scrollTTLParam && typeof scrollTTLParam !== "string") {
|
|
747
|
+
throw assertionError.get("invalid_type", "scroll", "string");
|
|
746
748
|
}
|
|
747
749
|
return scrollTTLParam;
|
|
748
750
|
}
|
|
749
751
|
/**
|
|
750
752
|
* Gets the refresh value.
|
|
751
753
|
*/
|
|
752
|
-
getRefresh(defaultValue =
|
|
754
|
+
getRefresh(defaultValue = "false") {
|
|
753
755
|
if (this.input.args.refresh === undefined) {
|
|
754
756
|
return defaultValue;
|
|
755
757
|
}
|
|
756
|
-
if (this.input.args.refresh === false
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
return
|
|
758
|
+
if (this.input.args.refresh === false ||
|
|
759
|
+
this.input.args.refresh === "false" ||
|
|
760
|
+
this.input.args.refresh === null) {
|
|
761
|
+
return "false";
|
|
760
762
|
}
|
|
761
|
-
return
|
|
763
|
+
return "wait_for";
|
|
762
764
|
}
|
|
763
765
|
/**
|
|
764
766
|
* Returns true if the current user have `admin` profile
|
|
@@ -768,7 +770,7 @@ class KuzzleRequest {
|
|
|
768
770
|
if (!user) {
|
|
769
771
|
return false;
|
|
770
772
|
}
|
|
771
|
-
return user.profileIds.includes(
|
|
773
|
+
return user.profileIds.includes("admin");
|
|
772
774
|
}
|
|
773
775
|
/**
|
|
774
776
|
* Generic object getter: boolean value
|
|
@@ -784,15 +786,15 @@ class KuzzleRequest {
|
|
|
784
786
|
// whatever its value.
|
|
785
787
|
// If a user needs to unset the option, they need to remove it from the
|
|
786
788
|
// querystring.
|
|
787
|
-
if (this.context.connection.protocol ===
|
|
789
|
+
if (this.context.connection.protocol === "http" && querystring) {
|
|
788
790
|
value = value !== undefined;
|
|
789
791
|
(0, lodash_1.set)(obj, name, value);
|
|
790
792
|
}
|
|
791
793
|
else if (value === undefined || value === null) {
|
|
792
794
|
value = false;
|
|
793
795
|
}
|
|
794
|
-
else if (typeof value !==
|
|
795
|
-
throw assertionError.get(
|
|
796
|
+
else if (typeof value !== "boolean") {
|
|
797
|
+
throw assertionError.get("invalid_type", errorName, "boolean");
|
|
796
798
|
}
|
|
797
799
|
else {
|
|
798
800
|
value = Boolean(value);
|
|
@@ -810,11 +812,11 @@ class KuzzleRequest {
|
|
|
810
812
|
_getNumber(obj, name, errorName, def = undefined) {
|
|
811
813
|
let value = (0, lodash_1.get)(obj, name, def);
|
|
812
814
|
if (value === undefined) {
|
|
813
|
-
throw assertionError.get(
|
|
815
|
+
throw assertionError.get("missing_argument", errorName);
|
|
814
816
|
}
|
|
815
817
|
value = Number.parseFloat(value);
|
|
816
818
|
if (Number.isNaN(value)) {
|
|
817
|
-
throw assertionError.get(
|
|
819
|
+
throw assertionError.get("invalid_type", errorName, "number");
|
|
818
820
|
}
|
|
819
821
|
return value;
|
|
820
822
|
}
|
|
@@ -829,11 +831,11 @@ class KuzzleRequest {
|
|
|
829
831
|
_getInteger(obj, name, errorName, def = undefined) {
|
|
830
832
|
let value = (0, lodash_1.get)(obj, name, def);
|
|
831
833
|
if (value === undefined) {
|
|
832
|
-
throw assertionError.get(
|
|
834
|
+
throw assertionError.get("missing_argument", errorName);
|
|
833
835
|
}
|
|
834
836
|
value = Number.parseFloat(value);
|
|
835
837
|
if (Number.isNaN(value) || !Number.isSafeInteger(value)) {
|
|
836
|
-
throw assertionError.get(
|
|
838
|
+
throw assertionError.get("invalid_type", errorName, "integer");
|
|
837
839
|
}
|
|
838
840
|
return value;
|
|
839
841
|
}
|
|
@@ -848,10 +850,10 @@ class KuzzleRequest {
|
|
|
848
850
|
_getString(obj, name, errorName, def = undefined) {
|
|
849
851
|
const value = (0, lodash_1.get)(obj, name, def);
|
|
850
852
|
if (value === undefined) {
|
|
851
|
-
throw assertionError.get(
|
|
853
|
+
throw assertionError.get("missing_argument", errorName);
|
|
852
854
|
}
|
|
853
|
-
if (typeof value !==
|
|
854
|
-
throw assertionError.get(
|
|
855
|
+
if (typeof value !== "string") {
|
|
856
|
+
throw assertionError.get("invalid_type", errorName, "string");
|
|
855
857
|
}
|
|
856
858
|
return value;
|
|
857
859
|
}
|
|
@@ -866,14 +868,14 @@ class KuzzleRequest {
|
|
|
866
868
|
_getArray(obj, name, errorName, def = undefined, querystring = false) {
|
|
867
869
|
const value = (0, lodash_1.get)(obj, name, def);
|
|
868
870
|
if (value === undefined) {
|
|
869
|
-
throw assertionError.get(
|
|
871
|
+
throw assertionError.get("missing_argument", errorName);
|
|
870
872
|
}
|
|
871
873
|
if (!Array.isArray(value)) {
|
|
872
874
|
// If we are using the HTTP protocol and we have a string instead of an Array
|
|
873
875
|
// we try to parse it as JSON
|
|
874
|
-
if (this.context.connection.protocol ===
|
|
875
|
-
&&
|
|
876
|
-
|
|
876
|
+
if (this.context.connection.protocol === "http" &&
|
|
877
|
+
querystring &&
|
|
878
|
+
typeof value === "string") {
|
|
877
879
|
try {
|
|
878
880
|
const parsedValue = JSON.parse(value);
|
|
879
881
|
if (Array.isArray(parsedValue)) {
|
|
@@ -887,7 +889,7 @@ class KuzzleRequest {
|
|
|
887
889
|
// Do nothing, let the error be thrown below
|
|
888
890
|
}
|
|
889
891
|
}
|
|
890
|
-
throw assertionError.get(
|
|
892
|
+
throw assertionError.get("invalid_type", errorName, "array");
|
|
891
893
|
}
|
|
892
894
|
return value;
|
|
893
895
|
}
|
|
@@ -903,14 +905,14 @@ class KuzzleRequest {
|
|
|
903
905
|
_getObject(obj, name, errorName, def = undefined, querystring = false) {
|
|
904
906
|
const value = (0, lodash_1.get)(obj, name, def);
|
|
905
907
|
if (value === undefined) {
|
|
906
|
-
throw assertionError.get(
|
|
908
|
+
throw assertionError.get("missing_argument", errorName);
|
|
907
909
|
}
|
|
908
910
|
if (!(0, safeObject_1.isPlainObject)(value)) {
|
|
909
911
|
// If we are using the HTTP protocol and we have a string instead of an Array
|
|
910
912
|
// we try to parse it as JSON
|
|
911
|
-
if (this.context.connection.protocol ===
|
|
912
|
-
&&
|
|
913
|
-
|
|
913
|
+
if (this.context.connection.protocol === "http" &&
|
|
914
|
+
querystring &&
|
|
915
|
+
typeof value === "string") {
|
|
914
916
|
try {
|
|
915
917
|
const parsedValue = JSON.parse(value);
|
|
916
918
|
if ((0, safeObject_1.isPlainObject)(parsedValue)) {
|
|
@@ -924,7 +926,7 @@ class KuzzleRequest {
|
|
|
924
926
|
// Do nothing, let the error be thrown below
|
|
925
927
|
}
|
|
926
928
|
}
|
|
927
|
-
throw assertionError.get(
|
|
929
|
+
throw assertionError.get("invalid_type", errorName, "object");
|
|
928
930
|
}
|
|
929
931
|
return value;
|
|
930
932
|
}
|
|
@@ -933,7 +935,7 @@ class KuzzleRequest {
|
|
|
933
935
|
*/
|
|
934
936
|
checkRequired(arg, argName, required) {
|
|
935
937
|
if (required && !arg) {
|
|
936
|
-
throw assertionError.get(
|
|
938
|
+
throw assertionError.get("missing_argument", argName);
|
|
937
939
|
}
|
|
938
940
|
}
|
|
939
941
|
}
|
|
@@ -47,14 +47,14 @@ exports.RequestContext = exports.Connection = void 0;
|
|
|
47
47
|
const assert = __importStar(require("../../util/assertType"));
|
|
48
48
|
// private properties
|
|
49
49
|
// \u200b is a zero width space, used to masquerade console.log output
|
|
50
|
-
const _token =
|
|
51
|
-
const _user =
|
|
52
|
-
const _connection =
|
|
50
|
+
const _token = "token\u200b";
|
|
51
|
+
const _user = "user\u200b";
|
|
52
|
+
const _connection = "connection\u200b";
|
|
53
53
|
// Connection class properties
|
|
54
|
-
const _c_id =
|
|
55
|
-
const _c_protocol =
|
|
56
|
-
const _c_ips =
|
|
57
|
-
const _c_misc =
|
|
54
|
+
const _c_id = "id\u200b";
|
|
55
|
+
const _c_protocol = "protocol\u200b";
|
|
56
|
+
const _c_ips = "ips\u200b";
|
|
57
|
+
const _c_misc = "misc\u200b";
|
|
58
58
|
/**
|
|
59
59
|
* Information about the connection at the origin of the request.
|
|
60
60
|
*/
|
|
@@ -65,11 +65,11 @@ class Connection {
|
|
|
65
65
|
this[_c_ips] = [];
|
|
66
66
|
this[_c_misc] = {};
|
|
67
67
|
Object.seal(this);
|
|
68
|
-
if (typeof connection !==
|
|
68
|
+
if (typeof connection !== "object" || connection === null) {
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
for (const prop of Object.keys(connection)) {
|
|
72
|
-
if ([
|
|
72
|
+
if (["id", "protocol", "ips"].includes(prop)) {
|
|
73
73
|
this[prop] = connection[prop];
|
|
74
74
|
}
|
|
75
75
|
else {
|
|
@@ -81,7 +81,7 @@ class Connection {
|
|
|
81
81
|
* Unique identifier of the user connection
|
|
82
82
|
*/
|
|
83
83
|
set id(str) {
|
|
84
|
-
this[_c_id] = assert.assertString(
|
|
84
|
+
this[_c_id] = assert.assertString("connection.id", str);
|
|
85
85
|
}
|
|
86
86
|
get id() {
|
|
87
87
|
return this[_c_id];
|
|
@@ -90,7 +90,7 @@ class Connection {
|
|
|
90
90
|
* Network protocol name
|
|
91
91
|
*/
|
|
92
92
|
set protocol(str) {
|
|
93
|
-
this[_c_protocol] = assert.assertString(
|
|
93
|
+
this[_c_protocol] = assert.assertString("connection.protocol", str);
|
|
94
94
|
}
|
|
95
95
|
get protocol() {
|
|
96
96
|
return this[_c_protocol];
|
|
@@ -99,7 +99,7 @@ class Connection {
|
|
|
99
99
|
* Chain of IP addresses, starting from the client
|
|
100
100
|
*/
|
|
101
101
|
set ips(arr) {
|
|
102
|
-
this[_c_ips] = assert.assertArray(
|
|
102
|
+
this[_c_ips] = assert.assertArray("connection.ips", arr, "string");
|
|
103
103
|
}
|
|
104
104
|
get ips() {
|
|
105
105
|
return this[_c_ips];
|
|
@@ -118,7 +118,7 @@ class Connection {
|
|
|
118
118
|
id: this[_c_id],
|
|
119
119
|
ips: this[_c_ips],
|
|
120
120
|
protocol: this[_c_protocol],
|
|
121
|
-
...this[_c_misc]
|
|
121
|
+
...this[_c_misc],
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -163,7 +163,7 @@ class RequestContext {
|
|
|
163
163
|
return this[_connection].id;
|
|
164
164
|
}
|
|
165
165
|
set connectionId(str) {
|
|
166
|
-
this[_connection].id = assert.assertString(
|
|
166
|
+
this[_connection].id = assert.assertString("connectionId", str);
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
169
|
* @deprecated use connection.protocol instead
|
|
@@ -172,7 +172,7 @@ class RequestContext {
|
|
|
172
172
|
return this[_connection].protocol;
|
|
173
173
|
}
|
|
174
174
|
set protocol(str) {
|
|
175
|
-
this[_connection].protocol = assert.assertString(
|
|
175
|
+
this[_connection].protocol = assert.assertString("protocol", str);
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
178
|
* Connection that initiated the request
|
|
@@ -187,7 +187,7 @@ class RequestContext {
|
|
|
187
187
|
return this[_token];
|
|
188
188
|
}
|
|
189
189
|
set token(obj) {
|
|
190
|
-
this[_token] = assert.assertObject(
|
|
190
|
+
this[_token] = assert.assertObject("token", obj);
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* Associated user
|
|
@@ -196,7 +196,7 @@ class RequestContext {
|
|
|
196
196
|
return this[_user];
|
|
197
197
|
}
|
|
198
198
|
set user(obj) {
|
|
199
|
-
this[_user] = assert.assertObject(
|
|
199
|
+
this[_user] = assert.assertObject("user", obj);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
exports.RequestContext = RequestContext;
|