kuzzle 2.49.1 → 2.50.0-beta.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/dist/bin/check-node-version.js +11 -0
- package/dist/bin/copy-protobuf.js +17 -0
- package/dist/lib/api/controllers/adminController.d.ts +51 -0
- package/dist/lib/api/controllers/adminController.js +191 -0
- package/{lib → dist/lib}/api/controllers/authController.d.ts +20 -40
- package/{lib → dist/lib}/api/controllers/authController.js +23 -24
- package/dist/lib/api/controllers/bulkController.d.ts +46 -0
- package/dist/lib/api/controllers/bulkController.js +132 -0
- package/dist/lib/api/controllers/clusterController.d.ts +6 -0
- package/{lib → dist/lib}/api/controllers/clusterController.js +7 -11
- package/dist/lib/api/controllers/collectionController.d.ts +136 -0
- package/dist/lib/api/controllers/collectionController.js +356 -0
- package/dist/lib/api/controllers/documentController.d.ts +181 -0
- package/dist/lib/api/controllers/documentController.js +768 -0
- package/dist/lib/api/controllers/index.d.ts +12 -0
- package/{lib → dist/lib}/api/controllers/index.js +13 -14
- package/dist/lib/api/controllers/indexController.d.ts +65 -0
- package/dist/lib/api/controllers/indexController.js +139 -0
- package/dist/lib/api/controllers/memoryStorageController.d.ts +8 -0
- package/dist/lib/api/controllers/memoryStorageController.js +867 -0
- package/dist/lib/api/controllers/realtimeController.d.ts +47 -0
- package/dist/lib/api/controllers/realtimeController.js +128 -0
- package/dist/lib/api/controllers/securityController.d.ts +423 -0
- package/dist/lib/api/controllers/securityController.js +1139 -0
- package/dist/lib/api/controllers/serverController.d.ts +82 -0
- package/dist/lib/api/controllers/serverController.js +321 -0
- package/dist/lib/api/documentExtractor.d.ts +9 -0
- package/dist/lib/api/documentExtractor.js +274 -0
- package/dist/lib/api/funnel.d.ts +183 -0
- package/dist/lib/api/funnel.js +821 -0
- package/dist/lib/api/httpRoutes.d.ts +17 -0
- package/dist/lib/api/httpRoutes.js +1496 -0
- package/dist/lib/api/rateLimiter.d.ts +18 -0
- package/dist/lib/api/rateLimiter.js +74 -0
- package/{lib → dist/lib}/api/request/kuzzleRequest.d.ts +2 -2
- package/{lib → dist/lib}/api/request/requestContext.d.ts +2 -1
- package/dist/lib/cluster/command.d.ts +73 -0
- package/dist/lib/cluster/command.js +236 -0
- package/dist/lib/cluster/index.d.ts +2 -0
- package/{lib → dist/lib}/cluster/index.js +1 -2
- package/dist/lib/cluster/node.d.ts +278 -0
- package/dist/lib/cluster/node.js +876 -0
- package/dist/lib/cluster/publisher.d.ts +188 -0
- package/dist/lib/cluster/publisher.js +347 -0
- package/dist/lib/cluster/subscriber.d.ts +269 -0
- package/dist/lib/cluster/subscriber.js +555 -0
- package/dist/lib/cluster/workers/IDCardRenewer.d.ts +13 -0
- package/dist/lib/cluster/workers/IDCardRenewer.js +120 -0
- package/{lib → dist/lib}/config/documentEventAliases.d.ts +1 -2
- package/dist/lib/config/index.d.ts +5 -0
- package/dist/lib/config/index.js +244 -0
- package/dist/lib/config/sdkCompatibility.json +9 -0
- package/dist/lib/core/auth/formatProcessing.d.ts +30 -0
- package/dist/lib/core/auth/formatProcessing.js +55 -0
- package/dist/lib/core/auth/passportResponse.d.ts +15 -0
- package/{lib → dist/lib}/core/auth/passportResponse.js +24 -30
- package/dist/lib/core/auth/passportWrapper.d.ts +28 -0
- package/dist/lib/core/auth/passportWrapper.js +126 -0
- package/{lib → dist/lib}/core/backend/backendConfig.js +2 -2
- package/{lib → dist/lib}/core/backend/backendErrors.js +9 -12
- package/dist/lib/core/cache/cacheEngine.d.ts +15 -0
- package/dist/lib/core/cache/cacheEngine.js +205 -0
- package/dist/lib/core/network/accessLogger.d.ts +29 -0
- package/dist/lib/core/network/accessLogger.js +250 -0
- package/dist/lib/core/network/clientConnection.d.ts +15 -0
- package/{lib → dist/lib}/core/network/clientConnection.js +17 -24
- package/dist/lib/core/network/context.d.ts +42 -0
- package/dist/lib/core/network/context.js +57 -0
- package/dist/lib/core/network/entryPoint.d.ts +62 -0
- package/dist/lib/core/network/entryPoint.js +261 -0
- package/dist/lib/core/network/httpRouter/index.d.ts +85 -0
- package/dist/lib/core/network/httpRouter/index.js +258 -0
- package/dist/lib/core/network/httpRouter/routeHandler.d.ts +46 -0
- package/dist/lib/core/network/httpRouter/routeHandler.js +101 -0
- package/dist/lib/core/network/httpRouter/routePart.d.ts +35 -0
- package/dist/lib/core/network/httpRouter/routePart.js +117 -0
- package/dist/lib/core/network/protocolManifest.d.ts +6 -0
- package/{lib → dist/lib}/core/network/protocolManifest.js +5 -9
- package/dist/lib/core/network/protocols/httpMessage.d.ts +22 -0
- package/dist/lib/core/network/protocols/httpMessage.js +62 -0
- package/dist/lib/core/network/protocols/httpwsProtocol.d.ts +171 -0
- package/dist/lib/core/network/protocols/httpwsProtocol.js +921 -0
- package/dist/lib/core/network/protocols/internalProtocol.d.ts +27 -0
- package/dist/lib/core/network/protocols/internalProtocol.js +82 -0
- package/dist/lib/core/network/protocols/mqttProtocol.d.ts +39 -0
- package/dist/lib/core/network/protocols/mqttProtocol.js +219 -0
- package/dist/lib/core/network/protocols/protocol.d.ts +26 -0
- package/dist/lib/core/network/protocols/protocol.js +74 -0
- package/dist/lib/core/network/router.d.ts +49 -0
- package/dist/lib/core/network/router.js +193 -0
- package/dist/lib/core/plugin/plugin.d.ts +56 -0
- package/dist/lib/core/plugin/plugin.js +282 -0
- package/{lib → dist/lib}/core/plugin/pluginContext.js +2 -2
- package/dist/lib/core/plugin/pluginManifest.d.ts +5 -0
- package/{lib → dist/lib}/core/plugin/pluginManifest.js +16 -27
- package/dist/lib/core/plugin/pluginRepository.d.ts +53 -0
- package/dist/lib/core/plugin/pluginRepository.js +112 -0
- package/dist/lib/core/plugin/pluginsManager.d.ts +190 -0
- package/dist/lib/core/plugin/pluginsManager.js +817 -0
- package/dist/lib/core/plugin/privilegedContext.d.ts +14 -0
- package/{lib → dist/lib}/core/plugin/privilegedContext.js +10 -14
- package/dist/lib/core/realtime/actionEnum.d.ts +25 -0
- package/{lib → dist/lib}/core/realtime/actionEnum.js +7 -10
- package/dist/lib/core/realtime/index.d.ts +8 -0
- package/{lib → dist/lib}/core/realtime/index.js +9 -13
- package/dist/lib/core/realtime/notification/document.d.ts +34 -0
- package/dist/lib/core/realtime/notification/document.js +98 -0
- package/dist/lib/core/realtime/notification/index.d.ts +3 -0
- package/{lib → dist/lib}/core/realtime/notification/index.js +4 -5
- package/dist/lib/core/realtime/notification/server.d.ts +17 -0
- package/{lib → dist/lib}/core/realtime/notification/server.js +8 -10
- package/dist/lib/core/realtime/notification/user.d.ts +29 -0
- package/dist/lib/core/realtime/notification/user.js +66 -0
- package/dist/lib/core/realtime/notifier.d.ts +171 -0
- package/dist/lib/core/realtime/notifier.js +405 -0
- package/dist/lib/core/security/index.d.ts +14 -0
- package/{lib → dist/lib}/core/security/index.js +15 -19
- package/dist/lib/core/security/roleRepository.d.ts +143 -0
- package/dist/lib/core/security/roleRepository.js +445 -0
- package/dist/lib/core/security/securityLoader.d.ts +24 -0
- package/dist/lib/core/security/securityLoader.js +125 -0
- package/{lib → dist/lib}/core/security/tokenRepository.js +1 -1
- package/dist/lib/core/security/userRepository.d.ts +81 -0
- package/dist/lib/core/security/userRepository.js +346 -0
- package/dist/lib/core/shared/abstractManifest.d.ts +27 -0
- package/dist/lib/core/shared/abstractManifest.js +85 -0
- package/dist/lib/core/shared/sdk/impersonatedSdk.d.ts +7 -0
- package/dist/lib/core/shared/sdk/impersonatedSdk.js +80 -0
- package/{lib → dist/lib}/core/shared/store.d.ts +2 -2
- package/dist/lib/core/statistics/statistics.d.ts +94 -0
- package/dist/lib/core/statistics/statistics.js +287 -0
- package/dist/lib/core/storage/clientAdapter.d.ts +62 -0
- package/dist/lib/core/storage/clientAdapter.js +756 -0
- package/dist/lib/core/storage/storageEngine.d.ts +13 -0
- package/dist/lib/core/storage/storageEngine.js +52 -0
- package/dist/lib/core/validation/baseType.d.ts +35 -0
- package/dist/lib/core/validation/baseType.js +70 -0
- package/dist/lib/core/validation/types/anything.d.ts +10 -0
- package/{lib → dist/lib}/core/validation/types/anything.js +7 -10
- package/dist/lib/core/validation/types/boolean.d.ts +16 -0
- package/{lib → dist/lib}/core/validation/types/boolean.js +18 -23
- package/dist/lib/core/validation/types/date.d.ts +17 -0
- package/dist/lib/core/validation/types/date.js +215 -0
- package/dist/lib/core/validation/types/email.d.ts +17 -0
- package/dist/lib/core/validation/types/email.js +80 -0
- package/dist/lib/core/validation/types/enum.d.ts +17 -0
- package/dist/lib/core/validation/types/enum.js +70 -0
- package/dist/lib/core/validation/types/geoPoint.d.ts +17 -0
- package/{lib → dist/lib}/core/validation/types/geoPoint.js +19 -24
- package/dist/lib/core/validation/types/geoShape.d.ts +31 -0
- package/dist/lib/core/validation/types/geoShape.js +280 -0
- package/dist/lib/core/validation/types/integer.d.ts +7 -0
- package/{lib → dist/lib}/core/validation/types/integer.js +21 -27
- package/dist/lib/core/validation/types/ipAddress.d.ts +17 -0
- package/dist/lib/core/validation/types/ipAddress.js +73 -0
- package/dist/lib/core/validation/types/numeric.d.ts +17 -0
- package/dist/lib/core/validation/types/numeric.js +84 -0
- package/dist/lib/core/validation/types/object.d.ts +24 -0
- package/dist/lib/core/validation/types/object.js +74 -0
- package/dist/lib/core/validation/types/string.d.ts +17 -0
- package/dist/lib/core/validation/types/string.js +85 -0
- package/dist/lib/core/validation/types/url.d.ts +17 -0
- package/dist/lib/core/validation/types/url.js +73 -0
- package/dist/lib/core/validation/validation.d.ts +113 -0
- package/dist/lib/core/validation/validation.js +692 -0
- package/dist/lib/kerror/codes/0-core.json +194 -0
- package/dist/lib/kerror/codes/1-services.json +351 -0
- package/dist/lib/kerror/codes/2-api.json +195 -0
- package/dist/lib/kerror/codes/3-network.json +151 -0
- package/dist/lib/kerror/codes/4-plugin.json +498 -0
- package/dist/lib/kerror/codes/5-validation.json +158 -0
- package/dist/lib/kerror/codes/6-protocol.json +28 -0
- package/dist/lib/kerror/codes/7-security.json +283 -0
- package/dist/lib/kerror/codes/8-cluster.json +16 -0
- package/dist/lib/kerror/codes/index.d.ts +24 -0
- package/dist/lib/kerror/codes/index.js +140 -0
- package/{lib → dist/lib}/kerror/index.d.ts +5 -5
- package/{lib → dist/lib}/kuzzle/Logger.d.ts +6 -0
- package/{lib → dist/lib}/kuzzle/Logger.js +26 -5
- package/dist/lib/kuzzle/dumpGenerator.d.ts +14 -0
- package/dist/lib/kuzzle/dumpGenerator.js +180 -0
- package/dist/lib/kuzzle/event/pipeRunner.d.ts +30 -0
- package/dist/lib/kuzzle/event/pipeRunner.js +119 -0
- package/dist/lib/kuzzle/event/waterfall.d.ts +2 -0
- package/dist/lib/kuzzle/event/waterfall.js +90 -0
- package/dist/lib/kuzzle/internalIndexHandler.d.ts +186 -0
- package/dist/lib/kuzzle/internalIndexHandler.js +174 -0
- package/{lib → dist/lib}/kuzzle/kuzzle.d.ts +6 -7
- package/{lib → dist/lib}/kuzzle/kuzzle.js +5 -2
- package/dist/lib/kuzzle/kuzzleStateEnum.d.ts +20 -0
- package/{lib → dist/lib}/kuzzle/kuzzleStateEnum.js +5 -8
- package/dist/lib/kuzzle/vault.d.ts +2 -0
- package/dist/lib/kuzzle/vault.js +63 -0
- package/dist/lib/model/security/rights.d.ts +8 -0
- package/{lib → dist/lib}/model/security/rights.js +4 -8
- package/{lib → dist/lib}/model/security/role.d.ts +1 -1
- package/{lib → dist/lib}/model/security/user.d.ts +1 -0
- package/dist/lib/model/storage/apiKey.d.ts +49 -0
- package/dist/lib/model/storage/apiKey.js +126 -0
- package/dist/lib/model/storage/baseModel.d.ts +100 -0
- package/dist/lib/model/storage/baseModel.js +211 -0
- package/dist/lib/service/cache/redis.d.ts +74 -0
- package/dist/lib/service/cache/redis.js +237 -0
- package/dist/lib/service/service.d.ts +30 -0
- package/dist/lib/service/service.js +74 -0
- package/{lib → dist/lib}/service/storage/7/elasticsearch.d.ts +2 -2
- package/{lib → dist/lib}/service/storage/7/elasticsearch.js +23 -25
- package/dist/lib/service/storage/7/esWrapper.d.ts +19 -0
- package/dist/lib/service/storage/7/esWrapper.js +245 -0
- package/{lib → dist/lib}/service/storage/8/elasticsearch.js +23 -25
- package/dist/lib/service/storage/8/esWrapper.d.ts +19 -0
- package/dist/lib/service/storage/8/esWrapper.js +245 -0
- package/{lib → dist/lib}/types/Plugin.d.ts +1 -1
- package/{lib/types → dist/lib/types/controllers}/Controller.d.ts +2 -2
- package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.d.ts +1 -1
- package/dist/lib/types/controllers/adminControlller.type.d.ts +5 -0
- package/dist/lib/types/controllers/adminControlller.type.js +3 -0
- package/dist/lib/types/controllers/authController.type.d.ts +5 -0
- package/dist/lib/types/controllers/authController.type.js +3 -0
- package/dist/lib/types/core/auth/formatProcessing.type.d.ts +7 -0
- package/dist/lib/types/core/auth/formatProcessing.type.js +3 -0
- package/{lib → dist/lib}/types/index.d.ts +3 -3
- package/{lib → dist/lib}/types/index.js +3 -3
- package/dist/lib/util/assertType.d.ts +41 -0
- package/{lib → dist/lib}/util/assertType.js +38 -56
- package/dist/lib/util/asyncStore.d.ts +38 -0
- package/dist/lib/util/asyncStore.js +70 -0
- package/dist/lib/util/bytes.d.ts +2 -0
- package/dist/lib/util/bytes.js +33 -0
- package/dist/lib/util/debug.d.ts +2 -0
- package/{lib → dist/lib}/util/debug.js +15 -23
- package/dist/lib/util/deprecate.d.ts +1 -0
- package/dist/lib/util/deprecate.js +64 -0
- package/dist/lib/util/didYouMean.d.ts +2 -0
- package/{lib → dist/lib}/util/didYouMean.js +9 -15
- package/dist/lib/util/extractFields.d.ts +17 -0
- package/{lib → dist/lib}/util/extractFields.js +18 -32
- package/dist/lib/util/memoize.d.ts +7 -0
- package/{lib → dist/lib}/util/memoize.js +14 -21
- package/dist/lib/util/promback.d.ts +13 -0
- package/dist/lib/util/promback.js +60 -0
- package/dist/lib/util/requestAssertions.d.ts +10 -0
- package/dist/lib/util/requestAssertions.js +143 -0
- package/dist/lib/util/safeObject.d.ts +3 -0
- package/{lib → dist/lib}/util/safeObject.js +7 -13
- package/dist/lib/util/stackTrace.d.ts +19 -0
- package/{lib → dist/lib}/util/stackTrace.js +35 -41
- package/dist/lib/util/wildcard.d.ts +1 -0
- package/{lib → dist/lib}/util/wildcard.js +21 -30
- package/dist/package.json +120 -0
- package/package.json +45 -58
- package/bin/start-kuzzle-server +0 -126
- package/check-node-version.js +0 -17
- package/lib/api/controllers/adminController.js +0 -229
- package/lib/api/controllers/bulkController.js +0 -210
- package/lib/api/controllers/collectionController.js +0 -502
- package/lib/api/controllers/documentController.js +0 -1156
- package/lib/api/controllers/indexController.js +0 -179
- package/lib/api/controllers/memoryStorageController.js +0 -1023
- package/lib/api/controllers/realtimeController.js +0 -155
- package/lib/api/controllers/securityController.js +0 -1571
- package/lib/api/controllers/serverController.js +0 -381
- package/lib/api/documentExtractor.js +0 -309
- package/lib/api/funnel.js +0 -1143
- package/lib/api/httpRoutes.js +0 -1547
- package/lib/api/rateLimiter.js +0 -87
- package/lib/cluster/command.js +0 -284
- package/lib/cluster/node.js +0 -1203
- package/lib/cluster/publisher.js +0 -386
- package/lib/cluster/subscriber.js +0 -776
- package/lib/cluster/workers/IDCardRenewer.js +0 -144
- package/lib/config/index.js +0 -351
- package/lib/config/sdkCompatibility.json +0 -9
- package/lib/core/auth/formatProcessing.js +0 -66
- package/lib/core/auth/passportWrapper.js +0 -126
- package/lib/core/cache/cacheEngine.js +0 -278
- package/lib/core/network/accessLogger.js +0 -322
- package/lib/core/network/context.js +0 -80
- package/lib/core/network/entryPoint.js +0 -358
- package/lib/core/network/httpRouter/index.js +0 -316
- package/lib/core/network/httpRouter/routeHandler.js +0 -111
- package/lib/core/network/httpRouter/routePart.js +0 -147
- package/lib/core/network/protocols/httpMessage.js +0 -69
- package/lib/core/network/protocols/httpwsProtocol.js +0 -1254
- package/lib/core/network/protocols/internalProtocol.js +0 -109
- package/lib/core/network/protocols/mqttProtocol.js +0 -291
- package/lib/core/network/protocols/protocol.js +0 -102
- package/lib/core/network/router.js +0 -255
- package/lib/core/plugin/plugin.js +0 -436
- package/lib/core/plugin/pluginRepository.js +0 -132
- package/lib/core/plugin/pluginsManager.js +0 -1244
- package/lib/core/realtime/notification/document.js +0 -108
- package/lib/core/realtime/notification/user.js +0 -70
- package/lib/core/realtime/notifier.js +0 -541
- package/lib/core/security/README.md +0 -223
- package/lib/core/security/roleRepository.js +0 -569
- package/lib/core/security/securityLoader.js +0 -174
- package/lib/core/security/userRepository.js +0 -446
- package/lib/core/shared/README.md +0 -3
- package/lib/core/shared/abstractManifest.js +0 -102
- package/lib/core/shared/sdk/impersonatedSdk.js +0 -94
- package/lib/core/statistics/index.js +0 -24
- package/lib/core/statistics/statistics.js +0 -373
- package/lib/core/storage/clientAdapter.js +0 -1045
- package/lib/core/storage/storageEngine.js +0 -63
- package/lib/core/validation/baseType.js +0 -80
- package/lib/core/validation/index.js +0 -24
- package/lib/core/validation/types/date.js +0 -284
- package/lib/core/validation/types/email.js +0 -92
- package/lib/core/validation/types/enum.js +0 -100
- package/lib/core/validation/types/geoShape.js +0 -370
- package/lib/core/validation/types/ipAddress.js +0 -83
- package/lib/core/validation/types/numeric.js +0 -108
- package/lib/core/validation/types/object.js +0 -88
- package/lib/core/validation/types/string.js +0 -110
- package/lib/core/validation/types/url.js +0 -83
- package/lib/core/validation/validation.js +0 -1180
- package/lib/kerror/codes/0-core.json +0 -194
- package/lib/kerror/codes/1-services.json +0 -351
- package/lib/kerror/codes/2-api.json +0 -195
- package/lib/kerror/codes/3-network.json +0 -151
- package/lib/kerror/codes/4-plugin.json +0 -498
- package/lib/kerror/codes/5-validation.json +0 -158
- package/lib/kerror/codes/6-protocol.json +0 -28
- package/lib/kerror/codes/7-security.json +0 -283
- package/lib/kerror/codes/8-cluster.json +0 -16
- package/lib/kerror/codes/index.js +0 -208
- package/lib/kuzzle/dumpGenerator.js +0 -259
- package/lib/kuzzle/event/pipeRunner.js +0 -144
- package/lib/kuzzle/event/waterfall.js +0 -101
- package/lib/kuzzle/internalIndexHandler.js +0 -234
- package/lib/kuzzle/vault.js +0 -89
- package/lib/model/storage/apiKey.js +0 -158
- package/lib/model/storage/baseModel.js +0 -275
- package/lib/service/cache/redis.js +0 -282
- package/lib/service/service.js +0 -84
- package/lib/service/storage/7/esWrapper.js +0 -303
- package/lib/service/storage/8/esWrapper.js +0 -303
- package/lib/util/asyncStore.js +0 -112
- package/lib/util/bytes.js +0 -36
- package/lib/util/deprecate.js +0 -82
- package/lib/util/promback.js +0 -66
- package/lib/util/readYamlFile.d.ts +0 -2
- package/lib/util/readYamlFile.js +0 -10
- package/lib/util/requestAssertions.js +0 -157
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{lib → dist/lib}/api/controllers/baseController.d.ts +0 -0
- /package/{lib → dist/lib}/api/controllers/baseController.js +0 -0
- /package/{lib → dist/lib}/api/controllers/debugController.d.ts +0 -0
- /package/{lib → dist/lib}/api/controllers/debugController.js +0 -0
- /package/{lib → dist/lib}/api/openapi/OpenApiManager.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/OpenApiManager.js +0 -0
- /package/{lib → dist/lib}/api/openapi/index.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/index.js +0 -0
- /package/{lib → dist/lib}/api/openapi/openApiGenerator.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/openApiGenerator.js +0 -0
- /package/{lib → dist/lib}/api/request/index.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/index.js +0 -0
- /package/{lib → dist/lib}/api/request/kuzzleRequest.js +0 -0
- /package/{lib → dist/lib}/api/request/requestContext.js +0 -0
- /package/{lib → dist/lib}/api/request/requestInput.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/requestInput.js +0 -0
- /package/{lib → dist/lib}/api/request/requestResponse.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/requestResponse.js +0 -0
- /package/{lib → dist/lib}/cluster/idCardHandler.d.ts +0 -0
- /package/{lib → dist/lib}/cluster/idCardHandler.js +0 -0
- /package/{lib → dist/lib}/cluster/protobuf/command.proto +0 -0
- /package/{lib → dist/lib}/cluster/protobuf/sync.proto +0 -0
- /package/{lib → dist/lib}/cluster/state.d.ts +0 -0
- /package/{lib → dist/lib}/cluster/state.js +0 -0
- /package/{lib → dist/lib}/config/default.config.d.ts +0 -0
- /package/{lib → dist/lib}/config/default.config.js +0 -0
- /package/{lib → dist/lib}/config/documentEventAliases.js +0 -0
- /package/{lib → dist/lib}/core/auth/tokenManager.d.ts +0 -0
- /package/{lib → dist/lib}/core/auth/tokenManager.js +0 -0
- /package/{lib → dist/lib}/core/backend/applicationManager.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/applicationManager.js +0 -0
- /package/{lib → dist/lib}/core/backend/backend.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backend.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendCluster.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendCluster.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendConfig.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendController.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendController.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendErrors.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendHook.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendHook.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendImport.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendImport.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendOpenApi.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendOpenApi.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendPipe.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendPipe.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendPlugin.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendPlugin.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendStorage.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendStorage.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendSubscription.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendSubscription.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendVault.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendVault.js +0 -0
- /package/{lib → dist/lib}/core/backend/index.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/index.js +0 -0
- /package/{lib → dist/lib}/core/backend/internalLogger.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/internalLogger.js +0 -0
- /package/{lib → dist/lib}/core/cache/cacheDbEnum.d.ts +0 -0
- /package/{lib → dist/lib}/core/cache/cacheDbEnum.js +0 -0
- /package/{lib → dist/lib}/core/debug/kuzzleDebugger.d.ts +0 -0
- /package/{lib → dist/lib}/core/debug/kuzzleDebugger.js +0 -0
- /package/{lib → dist/lib}/core/plugin/pluginContext.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/channel.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/channel.js +0 -0
- /package/{lib → dist/lib}/core/realtime/connectionRooms.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/connectionRooms.js +0 -0
- /package/{lib → dist/lib}/core/realtime/hotelClerk.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/hotelClerk.js +0 -0
- /package/{lib → dist/lib}/core/realtime/room.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/room.js +0 -0
- /package/{lib → dist/lib}/core/realtime/subscription.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/subscription.js +0 -0
- /package/{lib → dist/lib}/core/security/profileRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/security/profileRepository.js +0 -0
- /package/{lib → dist/lib}/core/security/tokenRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/KoncordeWrapper.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/KoncordeWrapper.js +0 -0
- /package/{lib → dist/lib}/core/shared/ObjectRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/ObjectRepository.js +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.js +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.js +0 -0
- /package/{lib → dist/lib}/core/shared/store.js +0 -0
- /package/{lib → dist/lib}/core/storage/indexCache.d.ts +0 -0
- /package/{lib → dist/lib}/core/storage/indexCache.js +0 -0
- /package/{lib → dist/lib}/core/storage/storeScopeEnum.d.ts +0 -0
- /package/{lib → dist/lib}/core/storage/storeScopeEnum.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/badRequestError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/badRequestError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/externalServiceError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/externalServiceError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/forbiddenError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/forbiddenError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/index.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/index.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/internalError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/internalError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/kuzzleError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/kuzzleError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/notFoundError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/notFoundError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/partialError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/partialError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/preconditionError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/preconditionError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/sizeLimitError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/sizeLimitError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/unauthorizedError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/unauthorizedError.js +0 -0
- /package/{lib → dist/lib}/kerror/index.js +0 -0
- /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.d.ts +0 -0
- /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.js +0 -0
- /package/{lib → dist/lib}/kuzzle/index.d.ts +0 -0
- /package/{lib → dist/lib}/kuzzle/index.js +0 -0
- /package/{lib → dist/lib}/model/security/profile.d.ts +0 -0
- /package/{lib → dist/lib}/model/security/profile.js +0 -0
- /package/{lib → dist/lib}/model/security/role.js +0 -0
- /package/{lib → dist/lib}/model/security/token.d.ts +0 -0
- /package/{lib → dist/lib}/model/security/token.js +0 -0
- /package/{lib → dist/lib}/model/security/user.js +0 -0
- /package/{lib → dist/lib}/service/storage/8/elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/service/storage/commons/queryTranslator.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/commons/queryTranslator.js +0 -0
- /package/{lib → dist/lib}/types/ClientConnection.d.ts +0 -0
- /package/{lib → dist/lib}/types/ClientConnection.js +0 -0
- /package/{lib → dist/lib}/types/Deprecation.d.ts +0 -0
- /package/{lib → dist/lib}/types/Deprecation.js +0 -0
- /package/{lib → dist/lib}/types/EventHandler.d.ts +0 -0
- /package/{lib → dist/lib}/types/EventHandler.js +0 -0
- /package/{lib → dist/lib}/types/Global.d.ts +0 -0
- /package/{lib → dist/lib}/types/Global.js +0 -0
- /package/{lib → dist/lib}/types/HttpMessage.d.ts +0 -0
- /package/{lib → dist/lib}/types/HttpMessage.js +0 -0
- /package/{lib → dist/lib}/types/HttpStream.d.ts +0 -0
- /package/{lib → dist/lib}/types/HttpStream.js +0 -0
- /package/{lib → dist/lib}/types/Kuzzle.d.ts +0 -0
- /package/{lib → dist/lib}/types/Kuzzle.js +0 -0
- /package/{lib → dist/lib}/types/KuzzleDocument.d.ts +0 -0
- /package/{lib → dist/lib}/types/KuzzleDocument.js +0 -0
- /package/{lib → dist/lib}/types/OpenApiDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/OpenApiDefinition.js +0 -0
- /package/{lib → dist/lib}/types/PasswordPolicy.d.ts +0 -0
- /package/{lib → dist/lib}/types/PasswordPolicy.js +0 -0
- /package/{lib → dist/lib}/types/Plugin.js +0 -0
- /package/{lib → dist/lib}/types/PluginManifest.d.ts +0 -0
- /package/{lib → dist/lib}/types/PluginManifest.js +0 -0
- /package/{lib → dist/lib}/types/Policy.d.ts +0 -0
- /package/{lib → dist/lib}/types/Policy.js +0 -0
- /package/{lib → dist/lib}/types/PolicyRestrictions.d.ts +0 -0
- /package/{lib → dist/lib}/types/PolicyRestrictions.js +0 -0
- /package/{lib → dist/lib}/types/ProfileDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/ProfileDefinition.js +0 -0
- /package/{lib → dist/lib}/types/RoleDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/RoleDefinition.js +0 -0
- /package/{lib → dist/lib}/types/StrategyDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/StrategyDefinition.js +0 -0
- /package/{lib → dist/lib}/types/Target.d.ts +0 -0
- /package/{lib → dist/lib}/types/Target.js +0 -0
- /package/{lib → dist/lib}/types/Token.d.ts +0 -0
- /package/{lib → dist/lib}/types/Token.js +0 -0
- /package/{lib → dist/lib}/types/User.d.ts +0 -0
- /package/{lib → dist/lib}/types/User.js +0 -0
- /package/{lib → dist/lib}/types/config/DumpConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/DumpConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/HttpConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/HttpConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/KuzzleConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/KuzzleConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/LimitsConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/LimitsConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/PluginsConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/PluginsConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/SecurityConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/SecurityConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/ServerConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/ServerConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/ServicesConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/ServicesConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/Controller.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerRights.d.ts +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerRights.js +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDefinition.js +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDomains.d.ts +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDomains.js +0 -0
- /package/{lib → dist/lib}/types/events/EventGenericDocument.d.ts +0 -0
- /package/{lib → dist/lib}/types/events/EventGenericDocument.js +0 -0
- /package/{lib → dist/lib}/types/events/EventProtocol.d.ts +0 -0
- /package/{lib → dist/lib}/types/events/EventProtocol.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeScope.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeScope.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeUsers.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeUsers.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RoomList.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RoomList.js +0 -0
- /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.js +0 -0
- /package/{lib → dist/lib}/types/storage/7/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/types/storage/7/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/types/storage/8/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/types/storage/8/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/util/Inflector.d.ts +0 -0
- /package/{lib → dist/lib}/util/Inflector.js +0 -0
- /package/{lib → dist/lib}/util/array.d.ts +0 -0
- /package/{lib → dist/lib}/util/array.js +0 -0
- /package/{lib → dist/lib}/util/async.d.ts +0 -0
- /package/{lib → dist/lib}/util/async.js +0 -0
- /package/{lib → dist/lib}/util/bufferedPassThrough.d.ts +0 -0
- /package/{lib → dist/lib}/util/bufferedPassThrough.js +0 -0
- /package/{lib → dist/lib}/util/crypto.d.ts +0 -0
- /package/{lib → dist/lib}/util/crypto.js +0 -0
- /package/{lib → dist/lib}/util/dump-collection.d.ts +0 -0
- /package/{lib → dist/lib}/util/dump-collection.js +0 -0
- /package/{lib → dist/lib}/util/esRequest.d.ts +0 -0
- /package/{lib → dist/lib}/util/esRequest.js +0 -0
- /package/{lib → dist/lib}/util/koncordeCompat.d.ts +0 -0
- /package/{lib → dist/lib}/util/koncordeCompat.js +0 -0
- /package/{lib → dist/lib}/util/mutex.d.ts +0 -0
- /package/{lib → dist/lib}/util/mutex.js +0 -0
- /package/{lib → dist/lib}/util/name-generator.d.ts +0 -0
- /package/{lib → dist/lib}/util/name-generator.js +0 -0
- /package/{lib → dist/lib}/util/time.d.ts +0 -0
- /package/{lib → dist/lib}/util/time.js +0 -0
package/lib/api/funnel.js
DELETED
|
@@ -1,1143 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2022 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
"use strict";
|
|
23
|
-
|
|
24
|
-
const Bluebird = require("bluebird");
|
|
25
|
-
const Deque = require("denque");
|
|
26
|
-
const Cookie = require("cookie");
|
|
27
|
-
|
|
28
|
-
const kuzzleStateEnum = require("../kuzzle/kuzzleStateEnum");
|
|
29
|
-
const { KuzzleError } = require("../kerror/errors");
|
|
30
|
-
const {
|
|
31
|
-
AdminController,
|
|
32
|
-
AuthController,
|
|
33
|
-
BulkController,
|
|
34
|
-
ClusterController,
|
|
35
|
-
CollectionController,
|
|
36
|
-
DebugController,
|
|
37
|
-
DocumentController,
|
|
38
|
-
IndexController,
|
|
39
|
-
MemoryStorageController,
|
|
40
|
-
RealtimeController,
|
|
41
|
-
SecurityController,
|
|
42
|
-
ServerController,
|
|
43
|
-
} = require("./controllers");
|
|
44
|
-
const { documentEventAliases } = require("../config/documentEventAliases");
|
|
45
|
-
const DocumentExtractor = require("./documentExtractor");
|
|
46
|
-
const sdkCompatibility = require("../config/sdkCompatibility");
|
|
47
|
-
const RateLimiter = require("./rateLimiter");
|
|
48
|
-
const kerror = require("../kerror");
|
|
49
|
-
|
|
50
|
-
const debug = require("../util/debug")("kuzzle:funnel");
|
|
51
|
-
const processError = kerror.wrap("api", "process");
|
|
52
|
-
const { has } = require("../util/safeObject");
|
|
53
|
-
const { HttpStream } = require("../types");
|
|
54
|
-
const get = require("lodash/get");
|
|
55
|
-
|
|
56
|
-
// Actions of the auth controller that does not necessite to verify the token
|
|
57
|
-
// when cookie auth is active
|
|
58
|
-
const SKIP_TOKEN_VERIF_ACTIONS = ["login", "checkToken", "logout"];
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @class PendingRequest
|
|
62
|
-
* @param {Request} request
|
|
63
|
-
* @param {Function} fn
|
|
64
|
-
* @param {Object} context
|
|
65
|
-
*/
|
|
66
|
-
class PendingRequest {
|
|
67
|
-
constructor(request, fn, context) {
|
|
68
|
-
this.request = request;
|
|
69
|
-
this.fn = fn;
|
|
70
|
-
this.context = context;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @class Funnel
|
|
76
|
-
*/
|
|
77
|
-
class Funnel {
|
|
78
|
-
constructor() {
|
|
79
|
-
this.overloaded = false;
|
|
80
|
-
this.concurrentRequests = 0;
|
|
81
|
-
this.controllers = new Map();
|
|
82
|
-
this.pendingRequestsQueue = new Deque();
|
|
83
|
-
this.pendingRequestsById = new Map();
|
|
84
|
-
this.lastOverloadTime = 0;
|
|
85
|
-
this.overloadWarned = false;
|
|
86
|
-
this.lastWarningTime = 0;
|
|
87
|
-
this.rateLimiter = new RateLimiter();
|
|
88
|
-
|
|
89
|
-
this.lastDumpedErrors = {};
|
|
90
|
-
this.loadDocumentEventAliases();
|
|
91
|
-
|
|
92
|
-
this.sdkCompatibility = sdkCompatibility;
|
|
93
|
-
|
|
94
|
-
this.logger = global.kuzzle.log.child("api:funnel");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
init() {
|
|
98
|
-
/**
|
|
99
|
-
* Returns true if the controller is one of Kuzzle native's one
|
|
100
|
-
*
|
|
101
|
-
* @param {String} name
|
|
102
|
-
*
|
|
103
|
-
* @returns {Boolean}
|
|
104
|
-
*/
|
|
105
|
-
global.kuzzle.onAsk("kuzzle:api:funnel:controller:isNative", (name) =>
|
|
106
|
-
this.isNativeController(name),
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Returns inner metrics from the Funnel
|
|
111
|
-
* @returns {Object}
|
|
112
|
-
*/
|
|
113
|
-
global.kuzzle.onAsk("kuzzle:api:funnel:metrics", () => this.metrics());
|
|
114
|
-
|
|
115
|
-
this.rateLimiter.init();
|
|
116
|
-
|
|
117
|
-
this.controllers.set("auth", new AuthController());
|
|
118
|
-
this.controllers.set("bulk", new BulkController());
|
|
119
|
-
this.controllers.set("cluster", new ClusterController());
|
|
120
|
-
this.controllers.set("collection", new CollectionController());
|
|
121
|
-
this.controllers.set("debug", new DebugController());
|
|
122
|
-
this.controllers.set("document", new DocumentController());
|
|
123
|
-
this.controllers.set("index", new IndexController());
|
|
124
|
-
this.controllers.set("realtime", new RealtimeController());
|
|
125
|
-
this.controllers.set("security", new SecurityController());
|
|
126
|
-
this.controllers.set("server", new ServerController());
|
|
127
|
-
this.controllers.set("admin", new AdminController());
|
|
128
|
-
|
|
129
|
-
const msController = new MemoryStorageController();
|
|
130
|
-
this.controllers.set("memoryStorage", msController);
|
|
131
|
-
this.controllers.set("ms", msController);
|
|
132
|
-
|
|
133
|
-
const initPromises = Array.from(this.controllers.keys()).map((ctrl) =>
|
|
134
|
-
this.controllers.get(ctrl).init(),
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
return Bluebird.all(initPromises);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
loadDocumentEventAliases() {
|
|
141
|
-
this.documentEventAliases = documentEventAliases;
|
|
142
|
-
this.documentEventAliases.mirrorList = {};
|
|
143
|
-
|
|
144
|
-
Object.keys(documentEventAliases.list).forEach((alias) => {
|
|
145
|
-
documentEventAliases.list[alias].forEach((aliasOf) => {
|
|
146
|
-
this.documentEventAliases.mirrorList[aliasOf] = alias;
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Asks the overload-protection system for an execution slot.
|
|
153
|
-
*
|
|
154
|
-
* Returns immediately true if the request can be
|
|
155
|
-
* executed.
|
|
156
|
-
*
|
|
157
|
-
* Otherwise, false is returned, and the caller MUST
|
|
158
|
-
* stop the request execution.
|
|
159
|
-
* In this case:
|
|
160
|
-
* - if it can be bufferized, then the request is left untouched
|
|
161
|
-
* and the executor function will be called later when a slot
|
|
162
|
-
* becomes available
|
|
163
|
-
* - if the buffer limit has been reached, a ServiceUnavailable error
|
|
164
|
-
* is set to the request. In that case, the executor is free to
|
|
165
|
-
* retry submitting the request later, or to abort it and return
|
|
166
|
-
* the request as it is
|
|
167
|
-
*
|
|
168
|
-
* @param {Function} fn - The function to be executed as soon as the slot is
|
|
169
|
-
* available.
|
|
170
|
-
* @param {Object} context - The execution context of the `fn` param.
|
|
171
|
-
* @param {String} request - The request object that will be passed as
|
|
172
|
-
* argument to `fn`.
|
|
173
|
-
* @returns {Boolean} - A boolean telling whether the request has been
|
|
174
|
-
* immediately executed or not.
|
|
175
|
-
*/
|
|
176
|
-
throttle(fn, context, request) {
|
|
177
|
-
if (global.kuzzle.state === kuzzleStateEnum.SHUTTING_DOWN) {
|
|
178
|
-
throw processError.get("shutting_down");
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (global.kuzzle.state === kuzzleStateEnum.NOT_ENOUGH_NODES) {
|
|
182
|
-
throw processError.get("not_enough_nodes");
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const isRequestFromDebugSession = get(
|
|
186
|
-
request,
|
|
187
|
-
"context.connection.misc.internal.debugSession",
|
|
188
|
-
false,
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
if (this.overloaded) {
|
|
192
|
-
const now = Date.now();
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
this.pendingRequestsQueue.length >
|
|
196
|
-
global.kuzzle.config.limits.requestsBufferWarningThreshold &&
|
|
197
|
-
(this.lastWarningTime === 0 || this.lastWarningTime < now - 500)
|
|
198
|
-
) {
|
|
199
|
-
const overloadPercentage =
|
|
200
|
-
Math.round(
|
|
201
|
-
(10000 * this.pendingRequestsQueue.length) /
|
|
202
|
-
global.kuzzle.config.limits.requestsBufferSize,
|
|
203
|
-
) / 100;
|
|
204
|
-
global.kuzzle.emit("core:overload", overloadPercentage);
|
|
205
|
-
this.logger.warn(
|
|
206
|
-
`[!WARNING!] Kuzzle overloaded: ${overloadPercentage}%. Delaying requests...`,
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
this.overloadWarned = true;
|
|
210
|
-
this.lastWarningTime = now;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
this.concurrentRequests < global.kuzzle.config.limits.concurrentRequests
|
|
216
|
-
) {
|
|
217
|
-
if (this.pendingRequestsById.has(request.internalId)) {
|
|
218
|
-
this.pendingRequestsById.delete(request.internalId);
|
|
219
|
-
}
|
|
220
|
-
// Execute fn immediately, since the slot is available
|
|
221
|
-
fn.call(context, request);
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/*
|
|
226
|
-
If kuzzle is overloaded, check the requests cache.
|
|
227
|
-
There are two possibilities:
|
|
228
|
-
|
|
229
|
-
1- the cache limit has not been reached: the request is cached
|
|
230
|
-
and will be played as soon as the config.limits.concurrentRequests
|
|
231
|
-
property allows it
|
|
232
|
-
|
|
233
|
-
2- the number of cached requests is equal to the requestsBufferSize property.
|
|
234
|
-
The request is then discarded and an error is returned to the sender
|
|
235
|
-
*/
|
|
236
|
-
if (
|
|
237
|
-
this.pendingRequestsQueue.length >=
|
|
238
|
-
global.kuzzle.config.limits.requestsBufferSize &&
|
|
239
|
-
!isRequestFromDebugSession
|
|
240
|
-
) {
|
|
241
|
-
const error = processError.get("overloaded");
|
|
242
|
-
global.kuzzle.emit("log:error", error);
|
|
243
|
-
this.logger.error(error);
|
|
244
|
-
throw error;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (!this.pendingRequestsById.has(request.internalId)) {
|
|
248
|
-
this.pendingRequestsById.set(
|
|
249
|
-
request.internalId,
|
|
250
|
-
new PendingRequest(request, fn, context),
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
if (isRequestFromDebugSession) {
|
|
254
|
-
// Push at the front to prioritize debug requests
|
|
255
|
-
this.pendingRequestsQueue.unshift(request.internalId);
|
|
256
|
-
} else {
|
|
257
|
-
this.pendingRequestsQueue.push(request.internalId);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (!this.overloaded) {
|
|
261
|
-
this.overloaded = true;
|
|
262
|
-
|
|
263
|
-
/*
|
|
264
|
-
/!\ Invoking this function here with setTimeout() leads to V8 deoptimizing
|
|
265
|
-
the entire getRequestSlot method (as of node.js 6.9.1),
|
|
266
|
-
because of an "out of bounds" heuristic error (caused by node's
|
|
267
|
-
setTimeout code written in JS? this needs further investigations)
|
|
268
|
-
|
|
269
|
-
We get better performances by keeping this method optimized by crankshaft
|
|
270
|
-
even if this means executing this function once for nothing each
|
|
271
|
-
time we start overload mode.
|
|
272
|
-
*/
|
|
273
|
-
this._playPendingRequests();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Execute the API request by
|
|
282
|
-
* 1/ check domain from origin header
|
|
283
|
-
* 2/ asking for a request slot,
|
|
284
|
-
* 3/ verify that the user is still connected
|
|
285
|
-
* 4/ checking if the requesting user has the right credentials
|
|
286
|
-
* 5/ send the request itself to the corresponding controller+action
|
|
287
|
-
*
|
|
288
|
-
* @param {Request} request
|
|
289
|
-
* @param {Function} callback
|
|
290
|
-
* @returns {Number} -1: request delayed, 0: request processing, 1: error
|
|
291
|
-
*/
|
|
292
|
-
execute(request, callback) {
|
|
293
|
-
if (!request.input.controller || !request.input.controller.length) {
|
|
294
|
-
callback(
|
|
295
|
-
kerror.get("api", "assert", "missing_argument", "controller"),
|
|
296
|
-
request,
|
|
297
|
-
);
|
|
298
|
-
return 1;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (!request.input.action || !request.input.action.length) {
|
|
302
|
-
callback(
|
|
303
|
-
kerror.get("api", "assert", "missing_argument", "action"),
|
|
304
|
-
request,
|
|
305
|
-
);
|
|
306
|
-
return 1;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// If there is a body, retrieve the targets if any
|
|
310
|
-
const targets = request.getArray("targets", []);
|
|
311
|
-
/**
|
|
312
|
-
* Only index and collection as a pair or the targets parameter is allowed at the same time
|
|
313
|
-
* otherwise we throw an error because we don't know which one to use to verify the rights
|
|
314
|
-
*/
|
|
315
|
-
if (
|
|
316
|
-
targets.length > 0 &&
|
|
317
|
-
(request.input.args.index || request.input.args.collection)
|
|
318
|
-
) {
|
|
319
|
-
callback(
|
|
320
|
-
kerror.get(
|
|
321
|
-
"api",
|
|
322
|
-
"assert",
|
|
323
|
-
"mutually_exclusive",
|
|
324
|
-
"index, collection",
|
|
325
|
-
"targets",
|
|
326
|
-
),
|
|
327
|
-
request,
|
|
328
|
-
);
|
|
329
|
-
return 1;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (
|
|
333
|
-
request.input.headers &&
|
|
334
|
-
has(request.input.headers, "origin") &&
|
|
335
|
-
!this._isOriginAuthorized(request.input.headers.origin)
|
|
336
|
-
) {
|
|
337
|
-
debug(
|
|
338
|
-
"Reject request, unauthorized origin %s",
|
|
339
|
-
request.input.headers.origin,
|
|
340
|
-
);
|
|
341
|
-
return this._executeError(
|
|
342
|
-
kerror.get(
|
|
343
|
-
"api",
|
|
344
|
-
"process",
|
|
345
|
-
"unauthorized_origin",
|
|
346
|
-
request.input.headers.origin,
|
|
347
|
-
),
|
|
348
|
-
request,
|
|
349
|
-
true,
|
|
350
|
-
callback,
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
try {
|
|
355
|
-
const executing = this.throttle(
|
|
356
|
-
(req) => {
|
|
357
|
-
// if the connection is closed there is no need to execute the request
|
|
358
|
-
// => discarding it
|
|
359
|
-
if (!global.kuzzle.router.isConnectionAlive(req.context)) {
|
|
360
|
-
debug("Client connection dead: dropping request: %a", req.input);
|
|
361
|
-
callback(processError.get("connection_dropped"), req);
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
debug(
|
|
366
|
-
"Starting request %s:%s [%s]: %j",
|
|
367
|
-
req.input.controller,
|
|
368
|
-
req.input.action,
|
|
369
|
-
req.id,
|
|
370
|
-
req.input,
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
global.kuzzle.asyncStore.run(() => {
|
|
374
|
-
global.kuzzle.asyncStore.set("REQUEST", req);
|
|
375
|
-
global.kuzzle
|
|
376
|
-
.pipe("request:beforeExecution", req)
|
|
377
|
-
.then((modifiedRequest) => {
|
|
378
|
-
let _request;
|
|
379
|
-
|
|
380
|
-
return this.checkRights(modifiedRequest)
|
|
381
|
-
.then((newModifiedRequest) => {
|
|
382
|
-
_request = newModifiedRequest;
|
|
383
|
-
return this.rateLimiter.isAllowed(_request);
|
|
384
|
-
})
|
|
385
|
-
.then((allowed) => {
|
|
386
|
-
if (!allowed) {
|
|
387
|
-
if (
|
|
388
|
-
request.input.controller === "auth" &&
|
|
389
|
-
request.input.action === "login"
|
|
390
|
-
) {
|
|
391
|
-
throw processError.get("too_many_logins_requests");
|
|
392
|
-
}
|
|
393
|
-
throw processError.get("too_many_requests");
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
return this.processRequest(_request);
|
|
397
|
-
})
|
|
398
|
-
.then((processResult) => {
|
|
399
|
-
debug(
|
|
400
|
-
"Request %s successfully executed. Result: %a",
|
|
401
|
-
modifiedRequest.id,
|
|
402
|
-
processResult,
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
return global.kuzzle
|
|
406
|
-
.pipe("request:afterExecution", {
|
|
407
|
-
request: _request,
|
|
408
|
-
result: processResult,
|
|
409
|
-
success: true,
|
|
410
|
-
})
|
|
411
|
-
.then((pipeEvent) => {
|
|
412
|
-
callback(null, pipeEvent.result);
|
|
413
|
-
|
|
414
|
-
// disables a bluebird warning in dev. mode triggered when
|
|
415
|
-
// a promise is created and not returned
|
|
416
|
-
return null;
|
|
417
|
-
});
|
|
418
|
-
})
|
|
419
|
-
.catch((err) => {
|
|
420
|
-
debug(
|
|
421
|
-
"Error processing request %s: %a",
|
|
422
|
-
modifiedRequest.id,
|
|
423
|
-
err,
|
|
424
|
-
);
|
|
425
|
-
return global.kuzzle
|
|
426
|
-
.pipe("request:afterExecution", {
|
|
427
|
-
error: err,
|
|
428
|
-
request: modifiedRequest,
|
|
429
|
-
success: false,
|
|
430
|
-
})
|
|
431
|
-
.then((pipeEvent) =>
|
|
432
|
-
this._executeError(
|
|
433
|
-
pipeEvent.error,
|
|
434
|
-
pipeEvent.request,
|
|
435
|
-
true,
|
|
436
|
-
callback,
|
|
437
|
-
),
|
|
438
|
-
);
|
|
439
|
-
});
|
|
440
|
-
})
|
|
441
|
-
.catch((err) => {
|
|
442
|
-
debug("Error processing request %s: %a", req.id, err);
|
|
443
|
-
return global.kuzzle
|
|
444
|
-
.pipe("request:afterExecution", {
|
|
445
|
-
error: err,
|
|
446
|
-
request: req,
|
|
447
|
-
success: false,
|
|
448
|
-
})
|
|
449
|
-
.then((pipeEvent) =>
|
|
450
|
-
this._executeError(
|
|
451
|
-
pipeEvent.error,
|
|
452
|
-
pipeEvent.request,
|
|
453
|
-
true,
|
|
454
|
-
callback,
|
|
455
|
-
),
|
|
456
|
-
);
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
},
|
|
460
|
-
this,
|
|
461
|
-
request,
|
|
462
|
-
);
|
|
463
|
-
|
|
464
|
-
return executing ? 0 : -1;
|
|
465
|
-
} catch (error) {
|
|
466
|
-
request.setError(error);
|
|
467
|
-
callback(error, request);
|
|
468
|
-
return 1;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* Checks if an error is worth dumping Kuzzle. If so,
|
|
474
|
-
* creates a dump.
|
|
475
|
-
*
|
|
476
|
-
* @param {KuzzleError|*} err
|
|
477
|
-
*/
|
|
478
|
-
handleErrorDump(err) {
|
|
479
|
-
const handledErrors = global.kuzzle.config.dump.handledErrors;
|
|
480
|
-
|
|
481
|
-
if (global.kuzzle.config.dump.enabled && handledErrors.enabled) {
|
|
482
|
-
setImmediate(() => {
|
|
483
|
-
const errorType =
|
|
484
|
-
typeof err === "object" && err.name ? err.name : typeof err;
|
|
485
|
-
|
|
486
|
-
if (handledErrors.whitelist.indexOf(errorType) > -1) {
|
|
487
|
-
const now = Date.now();
|
|
488
|
-
|
|
489
|
-
// JSON.stringify(new NativeError()) === '{}'
|
|
490
|
-
// i.e. Error, SyntaxError, TypeError, ReferenceError, etc.
|
|
491
|
-
this.logger.error(
|
|
492
|
-
err instanceof Error && !(err instanceof KuzzleError)
|
|
493
|
-
? `${err.message}\n${err.stack}`
|
|
494
|
-
: err,
|
|
495
|
-
);
|
|
496
|
-
|
|
497
|
-
if (
|
|
498
|
-
!this.lastDumpedErrors[errorType] ||
|
|
499
|
-
this.lastDumpedErrors[errorType] < now - handledErrors.minInterval
|
|
500
|
-
) {
|
|
501
|
-
// simplify error message to use it in folder dump name
|
|
502
|
-
let errorMessage = err.message;
|
|
503
|
-
|
|
504
|
-
if (errorMessage.indexOf("\n") > -1) {
|
|
505
|
-
errorMessage = errorMessage.split("\n")[0];
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
errorMessage = errorMessage
|
|
509
|
-
.toLowerCase()
|
|
510
|
-
.replace(/[^a-zA-Z0-9-_]/g, "-")
|
|
511
|
-
.split("-")
|
|
512
|
-
.filter((value) => value !== "")
|
|
513
|
-
.join("-");
|
|
514
|
-
|
|
515
|
-
global.kuzzle.dump(
|
|
516
|
-
`handled-${errorType.toLocaleLowerCase()}-${errorMessage}`,
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
this.lastDumpedErrors[errorType] = now;
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Checks if a user has the necessary rights to execute the action
|
|
528
|
-
*
|
|
529
|
-
* @param {Request} request
|
|
530
|
-
* @returns {Promise<Request>}
|
|
531
|
-
*/
|
|
532
|
-
async checkRights(request) {
|
|
533
|
-
if (
|
|
534
|
-
!global.kuzzle.config.http.cookieAuthentication &&
|
|
535
|
-
request.getBoolean("cookieAuth")
|
|
536
|
-
) {
|
|
537
|
-
throw kerror.get("security", "cookie", "unsupported");
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
let skipTokenVerification = false;
|
|
541
|
-
// When the Support of Cookie as Authentication Token is enabled we check if an auth token cookie is present
|
|
542
|
-
// When a request is made with cookieAuth set to true
|
|
543
|
-
// We try to use the auth token cookie if present as auth token
|
|
544
|
-
// otherwise check for auth token as input
|
|
545
|
-
if (request.input.headers && has(request.input.headers, "cookie")) {
|
|
546
|
-
let cookie;
|
|
547
|
-
try {
|
|
548
|
-
cookie = Cookie.parse(request.input.headers.cookie);
|
|
549
|
-
} catch (error) {
|
|
550
|
-
throw kerror.get("security", "cookie", "invalid");
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
// if cookie is present and not null, and a token is present we should throw because we don't know which one to use
|
|
554
|
-
if (cookie.authToken && cookie.authToken !== "null") {
|
|
555
|
-
if (!global.kuzzle.config.http.cookieAuthentication) {
|
|
556
|
-
throw kerror.get("security", "cookie", "unsupported");
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
if (request.input.jwt) {
|
|
560
|
-
throw kerror.get(
|
|
561
|
-
"security",
|
|
562
|
-
"token",
|
|
563
|
-
"verification_error",
|
|
564
|
-
"Both token and cookie are present, could not decide which one to use",
|
|
565
|
-
);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
request.input.jwt = cookie.authToken;
|
|
569
|
-
|
|
570
|
-
skipTokenVerification =
|
|
571
|
-
request.getBoolean("cookieAuth") &&
|
|
572
|
-
request.input.controller === "auth" &&
|
|
573
|
-
SKIP_TOKEN_VERIF_ACTIONS.includes(request.input.action);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
try {
|
|
578
|
-
// If the verification should be skipped, we pass a null token,
|
|
579
|
-
// this way the verification will be made as anonymous
|
|
580
|
-
const token = skipTokenVerification ? null : request.input.jwt;
|
|
581
|
-
|
|
582
|
-
request.context.token = await global.kuzzle.ask(
|
|
583
|
-
"core:security:token:verify",
|
|
584
|
-
token,
|
|
585
|
-
);
|
|
586
|
-
} catch (error) {
|
|
587
|
-
await global.kuzzle.pipe("request:onUnauthorized", request);
|
|
588
|
-
throw error;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
const userId = request.context.token.userId;
|
|
592
|
-
|
|
593
|
-
request.context.user = await global.kuzzle.ask(
|
|
594
|
-
"core:security:user:get",
|
|
595
|
-
userId,
|
|
596
|
-
);
|
|
597
|
-
|
|
598
|
-
// If we have a token, link the connection with the token,
|
|
599
|
-
// this way the connection can be notified when the token has expired.
|
|
600
|
-
if (
|
|
601
|
-
global.kuzzle.config.internal.notifiableProtocols.includes(
|
|
602
|
-
request.context.connection.protocol,
|
|
603
|
-
)
|
|
604
|
-
) {
|
|
605
|
-
global.kuzzle.tokenManager.link(
|
|
606
|
-
request.context.token,
|
|
607
|
-
request.context.connection.id,
|
|
608
|
-
);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
if (!(await request.context.user.isActionAllowed(request))) {
|
|
612
|
-
// anonymous user => 401 (Unauthorized) error
|
|
613
|
-
// logged-in user with insufficient permissions => 403 (Forbidden) error
|
|
614
|
-
const error = kerror.get(
|
|
615
|
-
"security",
|
|
616
|
-
"rights",
|
|
617
|
-
userId === "-1" ? "unauthorized" : "forbidden",
|
|
618
|
-
request.input.controller,
|
|
619
|
-
request.input.action,
|
|
620
|
-
request.context.user._id,
|
|
621
|
-
);
|
|
622
|
-
|
|
623
|
-
request.setError(error);
|
|
624
|
-
|
|
625
|
-
await global.kuzzle.pipe("request:onUnauthorized", request);
|
|
626
|
-
throw error;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
if (
|
|
630
|
-
global.kuzzle.config.plugins.common.failsafeMode &&
|
|
631
|
-
!this._isLogin(request) &&
|
|
632
|
-
!request.context.user.profileIds.includes("admin")
|
|
633
|
-
) {
|
|
634
|
-
await global.kuzzle.pipe("request:onUnauthorized", request);
|
|
635
|
-
throw kerror.get("security", "rights", "failsafe_mode_admin_only");
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
return global.kuzzle.pipe("request:onAuthorized", request);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
_isLogin(request) {
|
|
642
|
-
return (
|
|
643
|
-
request.input.controller === "auth" && request.input.action === "login"
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Executes the request immediately.
|
|
649
|
-
* /!\ To be used only by methods having already passed the overload check.
|
|
650
|
-
*
|
|
651
|
-
* @param {Request} request
|
|
652
|
-
* @returns {Promise}
|
|
653
|
-
*/
|
|
654
|
-
async processRequest(request) {
|
|
655
|
-
const controller = this.getController(request);
|
|
656
|
-
|
|
657
|
-
global.kuzzle.statistics.startRequest(request);
|
|
658
|
-
this.concurrentRequests++;
|
|
659
|
-
|
|
660
|
-
let _request = request;
|
|
661
|
-
|
|
662
|
-
try {
|
|
663
|
-
await this._checkSdkVersion(_request);
|
|
664
|
-
_request = await global.kuzzle.pipe("request:onExecution", _request);
|
|
665
|
-
_request = await this.performDocumentAlias(_request, "before");
|
|
666
|
-
_request = await global.kuzzle.pipe(
|
|
667
|
-
this.getEventName(_request, "before"),
|
|
668
|
-
_request,
|
|
669
|
-
);
|
|
670
|
-
|
|
671
|
-
const responseData = await doAction(controller, _request);
|
|
672
|
-
|
|
673
|
-
_request.setResult(responseData, {
|
|
674
|
-
status: _request.status === 102 ? 200 : _request.status,
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
if (
|
|
678
|
-
!this.isNativeController(_request.input.controller) &&
|
|
679
|
-
!_request.response.raw
|
|
680
|
-
) {
|
|
681
|
-
// check if the plugin response can be serialized
|
|
682
|
-
try {
|
|
683
|
-
if (!(responseData instanceof HttpStream)) {
|
|
684
|
-
JSON.stringify(responseData);
|
|
685
|
-
}
|
|
686
|
-
} catch (e) {
|
|
687
|
-
_request.setResult(null);
|
|
688
|
-
throw kerror.get("plugin", "controller", "unserializable_response");
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
_request = await global.kuzzle.pipe(
|
|
693
|
-
this.getEventName(_request, "after"),
|
|
694
|
-
_request,
|
|
695
|
-
);
|
|
696
|
-
|
|
697
|
-
_request = await this.performDocumentAlias(_request, "after");
|
|
698
|
-
_request = await global.kuzzle.pipe("request:onSuccess", _request);
|
|
699
|
-
global.kuzzle.statistics.completedRequest(_request);
|
|
700
|
-
} catch (error) {
|
|
701
|
-
return this.handleProcessRequestError(_request, _request, error);
|
|
702
|
-
} finally {
|
|
703
|
-
this.concurrentRequests--;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
return _request;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
/**
|
|
710
|
-
* Triggers generic:document:* events
|
|
711
|
-
*
|
|
712
|
-
* @warning Critical code section
|
|
713
|
-
*
|
|
714
|
-
* @param {KuzzleRequest} request
|
|
715
|
-
* @param {String} prefix
|
|
716
|
-
*
|
|
717
|
-
* @returns {Promise<KuzzleRequest>}
|
|
718
|
-
*/
|
|
719
|
-
async performDocumentAlias(request, prefix) {
|
|
720
|
-
const { controller, action } = request.input;
|
|
721
|
-
const mustTrigger =
|
|
722
|
-
controller === "document" &&
|
|
723
|
-
this.documentEventAliases.mirrorList[action] &&
|
|
724
|
-
(prefix !== "before" ||
|
|
725
|
-
!this.documentEventAliases.notBefore.includes(action));
|
|
726
|
-
|
|
727
|
-
if (!mustTrigger) {
|
|
728
|
-
return request;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
const alias = this.documentEventAliases.mirrorList[action];
|
|
732
|
-
const event = `${this.documentEventAliases.namespace}:${prefix}${capitalize(
|
|
733
|
-
alias,
|
|
734
|
-
)}`;
|
|
735
|
-
const extractor = new DocumentExtractor(request);
|
|
736
|
-
|
|
737
|
-
const documents = await global.kuzzle.pipe(
|
|
738
|
-
event,
|
|
739
|
-
extractor.extract(),
|
|
740
|
-
request,
|
|
741
|
-
);
|
|
742
|
-
|
|
743
|
-
return extractor.insert(documents);
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
/**
|
|
747
|
-
* Exposes API requests execution to plugins
|
|
748
|
-
*
|
|
749
|
-
* Similar to execute, except that:
|
|
750
|
-
* - plugin requests do not trigger API events
|
|
751
|
-
* - plugin requests are not counted towards requests statistics
|
|
752
|
-
* - the overload protection mechanism is disabled
|
|
753
|
-
*
|
|
754
|
-
* @param {Request} request
|
|
755
|
-
* @returns {Promise}
|
|
756
|
-
*/
|
|
757
|
-
async executePluginRequest(request) {
|
|
758
|
-
if (request.input.triggerEvents) {
|
|
759
|
-
let error;
|
|
760
|
-
let res;
|
|
761
|
-
try {
|
|
762
|
-
const { result } = await this.processRequest(request);
|
|
763
|
-
debug(
|
|
764
|
-
"Request %s successfully executed. Result: %a",
|
|
765
|
-
request.id,
|
|
766
|
-
result,
|
|
767
|
-
);
|
|
768
|
-
res = result;
|
|
769
|
-
return { ...result };
|
|
770
|
-
} catch (e) {
|
|
771
|
-
error = e;
|
|
772
|
-
debug("Error processing request %s: %a", request.id, error);
|
|
773
|
-
} finally {
|
|
774
|
-
global.kuzzle.pipe("request:afterExecution", {
|
|
775
|
-
error: error,
|
|
776
|
-
request: request,
|
|
777
|
-
result: res,
|
|
778
|
-
success: error === undefined ? true : false,
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
try {
|
|
783
|
-
return await doAction(this.getController(request), request);
|
|
784
|
-
} catch (e) {
|
|
785
|
-
this.handleErrorDump(e);
|
|
786
|
-
throw e;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
async handleProcessRequestError(modifiedRequest, request, error) {
|
|
791
|
-
let _error = this._wrapError(request, error);
|
|
792
|
-
modifiedRequest.setError(_error);
|
|
793
|
-
|
|
794
|
-
try {
|
|
795
|
-
const updated = await global.kuzzle.pipe(
|
|
796
|
-
this.getEventName(modifiedRequest, "error"),
|
|
797
|
-
modifiedRequest,
|
|
798
|
-
);
|
|
799
|
-
|
|
800
|
-
// If there is no pipe attached on this event, the same request is
|
|
801
|
-
// passed in resolve and we should reject it
|
|
802
|
-
if (updated.error !== null) {
|
|
803
|
-
throw updated.error;
|
|
804
|
-
}
|
|
805
|
-
// Pipe recovered from the error: returned the new result
|
|
806
|
-
return updated;
|
|
807
|
-
} catch (err) {
|
|
808
|
-
_error = this._wrapError(request, err);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
// Handling the error thrown by the error pipe
|
|
812
|
-
modifiedRequest.setError(_error);
|
|
813
|
-
global.kuzzle.statistics.failedRequest(request);
|
|
814
|
-
|
|
815
|
-
try {
|
|
816
|
-
const updated = await global.kuzzle.pipe(
|
|
817
|
-
"request:onError",
|
|
818
|
-
modifiedRequest,
|
|
819
|
-
);
|
|
820
|
-
|
|
821
|
-
if (updated === modifiedRequest) {
|
|
822
|
-
throw modifiedRequest.error;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
return updated;
|
|
826
|
-
} catch (err) {
|
|
827
|
-
throw this._wrapError(request, err);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
/**
|
|
832
|
-
* Helper function meant to normalize event names
|
|
833
|
-
* by retrieving controller aliases' original names.
|
|
834
|
-
*
|
|
835
|
-
* @param {Request} Executed request
|
|
836
|
-
* @param {string} prefix - event prefix
|
|
837
|
-
* @returns {string} event name
|
|
838
|
-
*/
|
|
839
|
-
getEventName(request, prefix) {
|
|
840
|
-
const event =
|
|
841
|
-
request.input.controller === "memoryStorage"
|
|
842
|
-
? "ms"
|
|
843
|
-
: request.input.controller;
|
|
844
|
-
|
|
845
|
-
return `${event}:${prefix}${capitalize(request.input.action)}`;
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* Returns the number of remaining requests
|
|
850
|
-
*
|
|
851
|
-
* @returns {number}
|
|
852
|
-
*/
|
|
853
|
-
get remainingRequests() {
|
|
854
|
-
return this.concurrentRequests + this.pendingRequestsQueue.length;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
/**
|
|
858
|
-
* Return the controller corresponding to the action asked by the request
|
|
859
|
-
*
|
|
860
|
-
* @param {Request} request
|
|
861
|
-
* @returns {Object} controller object
|
|
862
|
-
* @throws {BadRequestError} If the asked controller or action is unknown
|
|
863
|
-
*/
|
|
864
|
-
getController(request) {
|
|
865
|
-
for (const controllers of [
|
|
866
|
-
this.controllers,
|
|
867
|
-
global.kuzzle.pluginsManager.controllers,
|
|
868
|
-
]) {
|
|
869
|
-
const controller = controllers.get(request.input.controller);
|
|
870
|
-
|
|
871
|
-
if (controller) {
|
|
872
|
-
if (controller._isAction(request.input.action)) {
|
|
873
|
-
return controller;
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
throw processError.get(
|
|
877
|
-
"action_not_found",
|
|
878
|
-
request.input.controller,
|
|
879
|
-
request.input.action,
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
throw processError.get("controller_not_found", request.input.controller);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
/**
|
|
888
|
-
* Tell if the controller is a native controller or not
|
|
889
|
-
* @param {String} controller
|
|
890
|
-
* @returns {Boolean}
|
|
891
|
-
*/
|
|
892
|
-
isNativeController(controller) {
|
|
893
|
-
return this.controllers.has(controller);
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
/**
|
|
897
|
-
* Returns inner metrics from the Funnel
|
|
898
|
-
* @returns {Object}
|
|
899
|
-
*/
|
|
900
|
-
metrics() {
|
|
901
|
-
return {
|
|
902
|
-
concurrentRequests: this.concurrentRequests,
|
|
903
|
-
pendingRequests: this.pendingRequestsQueue.length,
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
/**
|
|
908
|
-
* If the request is coming from an official SDK,
|
|
909
|
-
* then checks the compatibility of the SDK against current Kuzzle version.
|
|
910
|
-
*
|
|
911
|
-
* @param {Request} request
|
|
912
|
-
*
|
|
913
|
-
* @throws
|
|
914
|
-
*/
|
|
915
|
-
_checkSdkVersion(request) {
|
|
916
|
-
if (!global.kuzzle.config.server.strictSdkVersion) {
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
const sdkVersion =
|
|
921
|
-
request.input.volatile && request.input.volatile.sdkVersion;
|
|
922
|
-
const sdkName = request.input.volatile && request.input.volatile.sdkName;
|
|
923
|
-
|
|
924
|
-
// sdkVersion property is only used by Kuzzle v1 SDKs
|
|
925
|
-
if (sdkVersion) {
|
|
926
|
-
throw processError.get(
|
|
927
|
-
"incompatible_sdk_version",
|
|
928
|
-
sdkVersion,
|
|
929
|
-
"Kuzzle v2",
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
if (!sdkName || typeof sdkName !== "string") {
|
|
934
|
-
return;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
const separatorIdx = sdkName.indexOf("@"),
|
|
938
|
-
name = sdkName.substr(0, separatorIdx),
|
|
939
|
-
version = sdkName.substr(separatorIdx + 1);
|
|
940
|
-
|
|
941
|
-
if (name.length === 0 || version.length === 0) {
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
const requirements = this.sdkCompatibility[name];
|
|
946
|
-
if (!requirements) {
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
if (!satisfiesMajor(version, requirements)) {
|
|
951
|
-
const hint = `min: ${requirements.min || "none"}, max: ${
|
|
952
|
-
requirements.max || "none"
|
|
953
|
-
}`;
|
|
954
|
-
|
|
955
|
-
throw processError.get("incompatible_sdk_version", version, hint);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
/**
|
|
960
|
-
* Populates the given request with the error and calls the callback
|
|
961
|
-
*
|
|
962
|
-
* @param {Error} error
|
|
963
|
-
* @param {Request} request
|
|
964
|
-
* @param {boolean} asError - if set to true, calls the callback with its first argument as error
|
|
965
|
-
* @param {Function} callback
|
|
966
|
-
* @returns {null}
|
|
967
|
-
* @private
|
|
968
|
-
*/
|
|
969
|
-
_executeError(error, request, asError, callback) {
|
|
970
|
-
request.setError(error);
|
|
971
|
-
|
|
972
|
-
if (asError) {
|
|
973
|
-
callback(error, request);
|
|
974
|
-
this.handleErrorDump(error);
|
|
975
|
-
} else {
|
|
976
|
-
callback(null, request);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
return null;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
/**
|
|
983
|
-
* Background task. Checks if there are any requests in cache, and replay them
|
|
984
|
-
* if Kuzzle is not overloaded anymore,
|
|
985
|
-
*/
|
|
986
|
-
_playPendingRequests() {
|
|
987
|
-
// If there is room to play bufferized requests, do it now. If not, retry later
|
|
988
|
-
const quantityToInject = Math.min(
|
|
989
|
-
this.pendingRequestsQueue.length,
|
|
990
|
-
global.kuzzle.config.limits.concurrentRequests - this.concurrentRequests,
|
|
991
|
-
);
|
|
992
|
-
|
|
993
|
-
if (quantityToInject > 0) {
|
|
994
|
-
for (let i = 0; i < quantityToInject; i++) {
|
|
995
|
-
const pendingItem = this.pendingRequestsById.get(
|
|
996
|
-
this.pendingRequestsQueue.peekFront(),
|
|
997
|
-
);
|
|
998
|
-
|
|
999
|
-
try {
|
|
1000
|
-
if (
|
|
1001
|
-
this.throttle(
|
|
1002
|
-
pendingItem.fn,
|
|
1003
|
-
pendingItem.context,
|
|
1004
|
-
pendingItem.request,
|
|
1005
|
-
)
|
|
1006
|
-
) {
|
|
1007
|
-
this.pendingRequestsQueue.shift();
|
|
1008
|
-
} else {
|
|
1009
|
-
break;
|
|
1010
|
-
}
|
|
1011
|
-
} catch (error) {
|
|
1012
|
-
break;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
if (this.pendingRequestsQueue.length > 0) {
|
|
1018
|
-
setTimeout(() => this._playPendingRequests(), 0);
|
|
1019
|
-
} else {
|
|
1020
|
-
const now = Date.now();
|
|
1021
|
-
// No request remaining in cache => stop the background task and return to normal behavior
|
|
1022
|
-
this.overloaded = false;
|
|
1023
|
-
|
|
1024
|
-
if (
|
|
1025
|
-
this.overloadWarned &&
|
|
1026
|
-
(this.lastOverloadTime === 0 || this.lastOverloadTime < now - 500)
|
|
1027
|
-
) {
|
|
1028
|
-
this.overloadWarned = false;
|
|
1029
|
-
this.logger.info("End of overloaded state. Resuming normal activity.");
|
|
1030
|
-
this.lastOverloadTime = now;
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
/**
|
|
1036
|
-
* Eventually wrap an error into a PluginImplementationError
|
|
1037
|
-
* @param {Request} request
|
|
1038
|
-
* @param {Error} error
|
|
1039
|
-
* @returns {KuzzleError}
|
|
1040
|
-
*/
|
|
1041
|
-
_wrapError(request, error) {
|
|
1042
|
-
if (!this.isNativeController(request) && !(error instanceof KuzzleError)) {
|
|
1043
|
-
return kerror.getFrom(
|
|
1044
|
-
error,
|
|
1045
|
-
"plugin",
|
|
1046
|
-
"runtime",
|
|
1047
|
-
"unexpected_error",
|
|
1048
|
-
error.message,
|
|
1049
|
-
);
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
return error;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
/**
|
|
1056
|
-
* Verifies if requests sent from a specific origin are allowed
|
|
1057
|
-
* @param {string} origin
|
|
1058
|
-
* @returns
|
|
1059
|
-
*/
|
|
1060
|
-
_isOriginAuthorized(origin) {
|
|
1061
|
-
const httpConfig = global.kuzzle.config.http;
|
|
1062
|
-
|
|
1063
|
-
if (!origin) {
|
|
1064
|
-
return true;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
if (global.kuzzle.config.internal.allowAllOrigins) {
|
|
1068
|
-
return true;
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
if (httpConfig.accessControlAllowOriginUseRegExp) {
|
|
1072
|
-
for (const re of httpConfig.accessControlAllowOrigin) {
|
|
1073
|
-
if (re.test(origin)) {
|
|
1074
|
-
return true;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
return false;
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
return httpConfig.accessControlAllowOrigin.includes(origin);
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
/**
|
|
1085
|
-
* @param {string} string
|
|
1086
|
-
* @returns {string}
|
|
1087
|
-
*/
|
|
1088
|
-
function capitalize(string) {
|
|
1089
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* Execute a controller action, checking that its return
|
|
1094
|
-
* value is a Promise. If not, wraps the returned value
|
|
1095
|
-
* in a rejected Promise and returns it.
|
|
1096
|
-
*
|
|
1097
|
-
* Used to make Kuzzle safe from badly implemented plugins
|
|
1098
|
-
*
|
|
1099
|
-
* @param {Object} controller
|
|
1100
|
-
* @param {Request} request
|
|
1101
|
-
* @returns {Promise}
|
|
1102
|
-
*/
|
|
1103
|
-
function doAction(controller, request) {
|
|
1104
|
-
const ret = controller[request.input.action](request);
|
|
1105
|
-
|
|
1106
|
-
if (!ret || typeof ret.then !== "function") {
|
|
1107
|
-
return kerror.reject(
|
|
1108
|
-
"plugin",
|
|
1109
|
-
"controller",
|
|
1110
|
-
"invalid_action_response",
|
|
1111
|
-
request.input.controller,
|
|
1112
|
-
request.input.action,
|
|
1113
|
-
);
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
return ret;
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
/**
|
|
1120
|
-
* Very straightforward function to check only if the version satisfies
|
|
1121
|
-
* the major version requirements
|
|
1122
|
-
*
|
|
1123
|
-
* @param {String} version
|
|
1124
|
-
* @param {Object} requirements
|
|
1125
|
-
*
|
|
1126
|
-
* @returns {Boolean}
|
|
1127
|
-
*/
|
|
1128
|
-
function satisfiesMajor(version, requirements) {
|
|
1129
|
-
let maxRequirement = true,
|
|
1130
|
-
minRequirement = true;
|
|
1131
|
-
|
|
1132
|
-
if (requirements.min) {
|
|
1133
|
-
minRequirement = version[0] >= requirements.min.toString();
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
if (requirements.max) {
|
|
1137
|
-
maxRequirement = version[0] <= requirements.max.toString();
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
return maxRequirement && minRequirement;
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
module.exports = Funnel;
|