kuzzle 2.56.0 → 2.57.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/copy-binaries.js +71 -4
- package/dist/bin/start-kuzzle-server +191 -97
- package/dist/index.d.ts +31 -1
- package/dist/index.js +45 -2
- package/dist/lib/api/controllers/adminController.d.ts +4 -3
- package/dist/lib/api/controllers/adminController.js +1 -2
- package/dist/lib/api/controllers/authController.d.ts +37 -16
- package/dist/lib/api/controllers/authController.js +88 -39
- package/dist/lib/api/controllers/baseController.d.ts +10 -5
- package/dist/lib/api/controllers/baseController.js +36 -15
- package/dist/lib/api/controllers/bulkController.d.ts +11 -7
- package/dist/lib/api/controllers/bulkController.js +28 -5
- package/dist/lib/api/controllers/clusterController.d.ts +2 -2
- package/dist/lib/api/controllers/clusterController.js +3 -3
- package/dist/lib/api/controllers/collectionController.d.ts +57 -21
- package/dist/lib/api/controllers/collectionController.js +40 -11
- package/dist/lib/api/controllers/debugController.d.ts +1 -1
- package/dist/lib/api/controllers/documentController.d.ts +137 -28
- package/dist/lib/api/controllers/documentController.js +156 -125
- package/dist/lib/api/controllers/index.d.ts +27 -12
- package/dist/lib/api/controllers/index.js +28 -13
- package/dist/lib/api/controllers/indexController.d.ts +17 -10
- package/dist/lib/api/controllers/indexController.js +13 -11
- package/dist/lib/api/controllers/memoryStorageController.d.ts +2 -5
- package/dist/lib/api/controllers/memoryStorageController.js +199 -127
- package/dist/lib/api/controllers/realtimeController.d.ts +19 -9
- package/dist/lib/api/controllers/realtimeController.js +8 -4
- package/dist/lib/api/controllers/securityController.d.ts +42 -29
- package/dist/lib/api/controllers/securityController.js +35 -19
- package/dist/lib/api/controllers/serverController.d.ts +114 -19
- package/dist/lib/api/controllers/serverController.js +69 -29
- package/dist/lib/api/documentExtractor.d.ts +9 -7
- package/dist/lib/api/documentExtractor.js +105 -41
- package/dist/lib/api/funnel.d.ts +131 -29
- package/dist/lib/api/funnel.js +436 -225
- package/dist/lib/api/httpRoutes.d.ts +16 -11
- package/dist/lib/api/httpRoutes.js +272 -2
- package/dist/lib/api/openapi/OpenApiManager.d.ts +1 -1
- package/dist/lib/api/openapi/openApiGenerator.d.ts +1 -1
- package/dist/lib/api/rateLimiter.d.ts +15 -5
- package/dist/lib/api/rateLimiter.js +42 -14
- package/dist/lib/api/request/kuzzleRequest.d.ts +83 -12
- package/dist/lib/api/request/kuzzleRequest.js +88 -23
- package/dist/lib/api/request/requestContext.d.ts +20 -5
- package/dist/lib/api/request/requestContext.js +14 -4
- package/dist/lib/api/request/requestInput.d.ts +37 -6
- package/dist/lib/api/request/requestInput.js +22 -9
- package/dist/lib/api/request/requestResponse.d.ts +45 -9
- package/dist/lib/api/request/requestResponse.js +34 -3
- package/dist/lib/cluster/command.d.ts +131 -37
- package/dist/lib/cluster/command.js +243 -71
- package/dist/lib/cluster/idCardHandler.d.ts +18 -5
- package/dist/lib/cluster/idCardHandler.js +52 -19
- package/dist/lib/cluster/index.d.ts +8 -2
- package/dist/lib/cluster/index.js +6 -2
- package/dist/lib/cluster/node.d.ts +127 -49
- package/dist/lib/cluster/node.js +412 -179
- package/dist/lib/cluster/protobuf/command.proto +18 -0
- package/dist/lib/cluster/protobuf/commandMessages.d.ts +104 -0
- package/dist/lib/cluster/protobuf/commandMessages.js +30 -0
- package/dist/lib/cluster/protobuf/syncMessages.d.ts +184 -0
- package/dist/lib/cluster/protobuf/syncMessages.js +23 -0
- package/dist/lib/cluster/publisher.d.ts +118 -78
- package/dist/lib/cluster/publisher.js +174 -72
- package/dist/lib/cluster/state.d.ts +15 -9
- package/dist/lib/cluster/state.js +12 -8
- package/dist/lib/cluster/subscriber.d.ts +185 -131
- package/dist/lib/cluster/subscriber.js +357 -95
- package/dist/lib/cluster/workers/IDCardRenewer.d.ts +39 -8
- package/dist/lib/cluster/workers/IDCardRenewer.js +88 -23
- package/dist/lib/config/default.config.d.ts +2 -2
- package/dist/lib/config/default.config.js +10 -3
- package/dist/lib/config/documentEventAliases.d.ts +1 -1
- package/dist/lib/config/index.d.ts +2 -5
- package/dist/lib/config/index.js +30 -17
- package/dist/lib/core/auth/formatProcessing.d.ts +3 -3
- package/dist/lib/core/auth/passportResponse.d.ts +1 -1
- package/dist/lib/core/auth/passportWrapper.d.ts +1 -1
- package/dist/lib/core/auth/passportWrapper.js +14 -13
- package/dist/lib/core/auth/tokenManager.d.ts +24 -3
- package/dist/lib/core/auth/tokenManager.js +47 -19
- package/dist/lib/core/backend/applicationManager.d.ts +2 -2
- package/dist/lib/core/backend/backend.d.ts +16 -5
- package/dist/lib/core/backend/backend.js +14 -6
- package/dist/lib/core/backend/backendCluster.d.ts +1 -1
- package/dist/lib/core/backend/backendConfig.d.ts +17 -5
- package/dist/lib/core/backend/backendConfig.js +1 -0
- package/dist/lib/core/backend/backendController.d.ts +1 -1
- package/dist/lib/core/backend/backendController.js +8 -1
- package/dist/lib/core/backend/backendErrors.d.ts +15 -8
- package/dist/lib/core/backend/backendErrors.js +5 -0
- package/dist/lib/core/backend/backendHook.d.ts +1 -1
- package/dist/lib/core/backend/backendImport.d.ts +1 -1
- package/dist/lib/core/backend/backendOpenApi.d.ts +3 -2
- package/dist/lib/core/backend/backendPipe.d.ts +1 -1
- package/dist/lib/core/backend/backendPipe.js +9 -1
- package/dist/lib/core/backend/backendPlugin.d.ts +2 -2
- package/dist/lib/core/backend/backendSubscription.d.ts +2 -2
- package/dist/lib/core/backend/backendVault.d.ts +1 -1
- package/dist/lib/core/backend/backendVault.js +8 -1
- package/dist/lib/core/cache/cacheEngine.d.ts +7 -4
- package/dist/lib/core/cache/cacheEngine.js +25 -8
- package/dist/lib/core/debug/kuzzleDebugger.d.ts +2 -1
- package/dist/lib/core/debug/kuzzleDebugger.js +31 -17
- package/dist/lib/core/network/accessLogger.d.ts +33 -18
- package/dist/lib/core/network/accessLogger.js +135 -73
- package/dist/lib/core/network/clientConnection.d.ts +13 -11
- package/dist/lib/core/network/clientConnection.js +33 -9
- package/dist/lib/core/network/context.d.ts +17 -22
- package/dist/lib/core/network/context.js +43 -26
- package/dist/lib/core/network/entryPoint.d.ts +38 -16
- package/dist/lib/core/network/entryPoint.js +119 -48
- package/dist/lib/core/network/httpRouter/index.d.ts +20 -50
- package/dist/lib/core/network/httpRouter/index.js +61 -75
- package/dist/lib/core/network/httpRouter/routeHandler.d.ts +17 -32
- package/dist/lib/core/network/httpRouter/routeHandler.js +26 -36
- package/dist/lib/core/network/httpRouter/routePart.d.ts +9 -18
- package/dist/lib/core/network/httpRouter/routePart.js +61 -43
- package/dist/lib/core/network/httpRouter/routeTypes.d.ts +3 -0
- package/dist/lib/core/network/httpRouter/routeTypes.js +23 -0
- package/dist/lib/core/network/networkEntryPoint.d.ts +20 -0
- package/dist/lib/core/network/networkEntryPoint.js +23 -0
- package/dist/lib/core/network/protocolManifest.d.ts +5 -4
- package/dist/lib/core/network/protocolManifest.js +6 -3
- package/dist/lib/core/network/protocols/httpMessage.d.ts +25 -18
- package/dist/lib/core/network/protocols/httpMessage.js +14 -11
- package/dist/lib/core/network/protocols/httpwsProtocol.d.ts +84 -93
- package/dist/lib/core/network/protocols/httpwsProtocol.js +284 -129
- package/dist/lib/core/network/protocols/internalProtocol.d.ts +26 -15
- package/dist/lib/core/network/protocols/internalProtocol.js +17 -16
- package/dist/lib/core/network/protocols/mqttProtocol.d.ts +56 -32
- package/dist/lib/core/network/protocols/mqttProtocol.js +91 -44
- package/dist/lib/core/network/protocols/protocol.d.ts +85 -21
- package/dist/lib/core/network/protocols/protocol.js +83 -27
- package/dist/lib/core/network/router.d.ts +13 -22
- package/dist/lib/core/network/router.js +59 -46
- package/dist/lib/core/plugin/plugin.d.ts +57 -51
- package/dist/lib/core/plugin/plugin.js +218 -103
- package/dist/lib/core/plugin/pluginContext.d.ts +54 -11
- package/dist/lib/core/plugin/pluginContext.js +99 -58
- package/dist/lib/core/plugin/pluginManifest.d.ts +6 -2
- package/dist/lib/core/plugin/pluginManifest.js +18 -11
- package/dist/lib/core/plugin/pluginRepository.d.ts +35 -44
- package/dist/lib/core/plugin/pluginRepository.js +35 -50
- package/dist/lib/core/plugin/pluginsManager.d.ts +128 -46
- package/dist/lib/core/plugin/pluginsManager.js +468 -231
- package/dist/lib/core/plugin/privilegedContext.d.ts +4 -9
- package/dist/lib/core/plugin/privilegedContext.js +5 -10
- package/dist/lib/core/realtime/actionEnum.d.ts +12 -21
- package/dist/lib/core/realtime/actionEnum.js +6 -7
- package/dist/lib/core/realtime/channel.d.ts +11 -5
- package/dist/lib/core/realtime/channel.js +17 -2
- package/dist/lib/core/realtime/connectionRooms.d.ts +2 -2
- package/dist/lib/core/realtime/hotelClerk.d.ts +12 -6
- package/dist/lib/core/realtime/hotelClerk.js +29 -11
- package/dist/lib/core/realtime/index.d.ts +8 -3
- package/dist/lib/core/realtime/index.js +12 -5
- package/dist/lib/core/realtime/notification/document.d.ts +54 -25
- package/dist/lib/core/realtime/notification/document.js +10 -13
- package/dist/lib/core/realtime/notification/index.d.ts +9 -3
- package/dist/lib/core/realtime/notification/index.js +10 -4
- package/dist/lib/core/realtime/notification/server.d.ts +7 -10
- package/dist/lib/core/realtime/notification/server.js +4 -7
- package/dist/lib/core/realtime/notification/user.d.ts +45 -21
- package/dist/lib/core/realtime/notification/user.js +8 -9
- package/dist/lib/core/realtime/notifier.d.ts +52 -40
- package/dist/lib/core/realtime/notifier.js +60 -25
- package/dist/lib/core/realtime/room.d.ts +1 -1
- package/dist/lib/core/realtime/subscription.d.ts +11 -6
- package/dist/lib/core/realtime/subscription.js +5 -1
- package/dist/lib/core/security/index.d.ts +14 -6
- package/dist/lib/core/security/index.js +27 -13
- package/dist/lib/core/security/profileRepository.d.ts +24 -19
- package/dist/lib/core/security/profileRepository.js +23 -10
- package/dist/lib/core/security/roleRepository.d.ts +60 -23
- package/dist/lib/core/security/roleRepository.js +122 -53
- package/dist/lib/core/security/securityLoader.d.ts +33 -18
- package/dist/lib/core/security/securityLoader.js +43 -16
- package/dist/lib/core/security/tokenRepository.d.ts +21 -7
- package/dist/lib/core/security/tokenRepository.js +50 -23
- package/dist/lib/core/security/userRepository.d.ts +44 -21
- package/dist/lib/core/security/userRepository.js +59 -19
- package/dist/lib/core/shared/KoncordeWrapper.d.ts +1 -1
- package/dist/lib/core/shared/ObjectRepository.d.ts +80 -18
- package/dist/lib/core/shared/ObjectRepository.js +57 -29
- package/dist/lib/core/shared/abstractManifest.d.ts +21 -8
- package/dist/lib/core/shared/abstractManifest.js +57 -17
- package/dist/lib/core/shared/sdk/embeddedSdk.d.ts +3 -1
- package/dist/lib/core/shared/sdk/embeddedSdk.js +8 -7
- package/dist/lib/core/shared/sdk/funnelProtocol.d.ts +2 -1
- package/dist/lib/core/shared/sdk/funnelProtocol.js +12 -3
- package/dist/lib/core/shared/sdk/impersonatedSdk.d.ts +11 -5
- package/dist/lib/core/shared/sdk/impersonatedSdk.js +22 -9
- package/dist/lib/core/shared/store.d.ts +45 -29
- package/dist/lib/core/shared/store.js +48 -27
- package/dist/lib/core/statistics/statistics.d.ts +1 -1
- package/dist/lib/core/storage/clientAdapter.d.ts +39 -21
- package/dist/lib/core/storage/clientAdapter.js +88 -48
- package/dist/lib/core/storage/indexCache.d.ts +8 -0
- package/dist/lib/core/storage/indexCache.js +16 -7
- package/dist/lib/core/storage/storageEngine.d.ts +7 -6
- package/dist/lib/core/storage/storageEngine.js +11 -8
- package/dist/lib/core/validation/baseType.d.ts +22 -22
- package/dist/lib/core/validation/baseType.js +11 -26
- package/dist/lib/core/validation/specification.d.ts +148 -0
- package/dist/lib/core/validation/specification.js +34 -0
- package/dist/lib/core/validation/typeOptions.d.ts +62 -0
- package/dist/lib/core/validation/typeOptions.js +23 -0
- package/dist/lib/core/validation/types/anything.d.ts +3 -6
- package/dist/lib/core/validation/types/anything.js +7 -7
- package/dist/lib/core/validation/types/boolean.d.ts +5 -12
- package/dist/lib/core/validation/types/boolean.js +7 -12
- package/dist/lib/core/validation/types/date.d.ts +19 -11
- package/dist/lib/core/validation/types/date.js +212 -161
- package/dist/lib/core/validation/types/email.d.ts +7 -11
- package/dist/lib/core/validation/types/email.js +13 -17
- package/dist/lib/core/validation/types/enum.d.ts +7 -11
- package/dist/lib/core/validation/types/enum.js +39 -20
- package/dist/lib/core/validation/types/geoPoint.d.ts +5 -13
- package/dist/lib/core/validation/types/geoPoint.js +10 -15
- package/dist/lib/core/validation/types/geoShape.d.ts +22 -21
- package/dist/lib/core/validation/types/geoShape.js +113 -129
- package/dist/lib/core/validation/types/geoShapeUtils.d.ts +15 -0
- package/dist/lib/core/validation/types/geoShapeUtils.js +75 -0
- package/dist/lib/core/validation/types/integer.d.ts +7 -5
- package/dist/lib/core/validation/types/integer.js +7 -13
- package/dist/lib/core/validation/types/ipAddress.d.ts +7 -11
- package/dist/lib/core/validation/types/ipAddress.js +13 -17
- package/dist/lib/core/validation/types/numeric.d.ts +7 -11
- package/dist/lib/core/validation/types/numeric.js +22 -29
- package/dist/lib/core/validation/types/object.d.ts +8 -15
- package/dist/lib/core/validation/types/object.js +12 -21
- package/dist/lib/core/validation/types/string.d.ts +7 -11
- package/dist/lib/core/validation/types/string.js +22 -29
- package/dist/lib/core/validation/types/url.d.ts +7 -11
- package/dist/lib/core/validation/types/url.js +14 -18
- package/dist/lib/core/validation/validation.d.ts +119 -80
- package/dist/lib/core/validation/validation.js +470 -412
- package/dist/lib/core/validation/validationUtils.d.ts +31 -0
- package/dist/lib/core/validation/validationUtils.js +190 -0
- package/dist/lib/kerror/codes/4-plugin.json +0 -12
- package/dist/lib/kerror/codes/index.d.ts +12 -2
- package/dist/lib/kerror/codes/index.js +5 -4
- package/dist/lib/kerror/errors/badRequestError.d.ts +1 -1
- package/dist/lib/kerror/errors/badRequestError.js +1 -1
- package/dist/lib/kerror/errors/externalServiceError.d.ts +1 -1
- package/dist/lib/kerror/errors/externalServiceError.js +1 -1
- package/dist/lib/kerror/errors/forbiddenError.d.ts +1 -1
- package/dist/lib/kerror/errors/forbiddenError.js +1 -1
- package/dist/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
- package/dist/lib/kerror/errors/gatewayTimeoutError.js +1 -1
- package/dist/lib/kerror/errors/internalError.d.ts +1 -1
- package/dist/lib/kerror/errors/internalError.js +1 -1
- package/dist/lib/kerror/errors/kuzzleError.d.ts +32 -3
- package/dist/lib/kerror/errors/kuzzleError.js +21 -7
- package/dist/lib/kerror/errors/multipleErrorsError.d.ts +2 -2
- package/dist/lib/kerror/errors/multipleErrorsError.js +2 -2
- package/dist/lib/kerror/errors/notFoundError.d.ts +1 -1
- package/dist/lib/kerror/errors/notFoundError.js +1 -1
- package/dist/lib/kerror/errors/partialError.d.ts +8 -2
- package/dist/lib/kerror/errors/partialError.js +22 -9
- package/dist/lib/kerror/errors/pluginImplementationError.d.ts +9 -1
- package/dist/lib/kerror/errors/pluginImplementationError.js +9 -3
- package/dist/lib/kerror/errors/preconditionError.d.ts +1 -1
- package/dist/lib/kerror/errors/preconditionError.js +1 -1
- package/dist/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
- package/dist/lib/kerror/errors/serviceUnavailableError.js +1 -1
- package/dist/lib/kerror/errors/sizeLimitError.d.ts +1 -1
- package/dist/lib/kerror/errors/sizeLimitError.js +1 -1
- package/dist/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
- package/dist/lib/kerror/errors/tooManyRequestsError.js +1 -1
- package/dist/lib/kerror/errors/unauthorizedError.d.ts +1 -1
- package/dist/lib/kerror/errors/unauthorizedError.js +1 -1
- package/dist/lib/kerror/index.d.ts +19 -13
- package/dist/lib/kerror/index.js +60 -19
- package/dist/lib/kuzzle/Logger.d.ts +2 -2
- package/dist/lib/kuzzle/dumpGenerator.d.ts +12 -8
- package/dist/lib/kuzzle/dumpGenerator.js +130 -62
- package/dist/lib/kuzzle/event/KuzzleEventEmitter.d.ts +18 -9
- package/dist/lib/kuzzle/event/KuzzleEventEmitter.js +45 -18
- package/dist/lib/kuzzle/event/pipeRunner.d.ts +37 -16
- package/dist/lib/kuzzle/event/pipeRunner.js +73 -26
- package/dist/lib/kuzzle/event/waterfall.d.ts +11 -1
- package/dist/lib/kuzzle/event/waterfall.js +38 -13
- package/dist/lib/kuzzle/internalIndexHandler.d.ts +11 -174
- package/dist/lib/kuzzle/internalIndexHandler.js +58 -29
- package/dist/lib/kuzzle/kuzzle.d.ts +25 -10
- package/dist/lib/kuzzle/kuzzle.js +74 -17
- package/dist/lib/kuzzle/kuzzleStateEnum.d.ts +16 -12
- package/dist/lib/kuzzle/kuzzleStateEnum.js +5 -7
- package/dist/lib/kuzzle/vault.d.ts +5 -1
- package/dist/lib/kuzzle/vault.js +29 -17
- package/dist/lib/model/security/profile.d.ts +34 -5
- package/dist/lib/model/security/profile.js +6 -5
- package/dist/lib/model/security/rights.d.ts +12 -4
- package/dist/lib/model/security/rights.js +7 -6
- package/dist/lib/model/security/role.d.ts +8 -4
- package/dist/lib/model/security/role.js +12 -6
- package/dist/lib/model/security/token.d.ts +8 -0
- package/dist/lib/model/security/user.d.ts +8 -2
- package/dist/lib/model/security/user.js +7 -4
- package/dist/lib/model/storage/apiKey.d.ts +55 -26
- package/dist/lib/model/storage/apiKey.js +97 -24
- package/dist/lib/model/storage/baseModel.d.ts +77 -66
- package/dist/lib/model/storage/baseModel.js +21 -34
- package/dist/lib/service/cache/redis.d.ts +53 -36
- package/dist/lib/service/cache/redis.js +148 -71
- package/dist/lib/service/service.d.ts +14 -19
- package/dist/lib/service/service.js +41 -22
- package/dist/lib/service/storage/7/elasticsearch.d.ts +136 -93
- package/dist/lib/service/storage/7/elasticsearch.js +218 -165
- package/dist/lib/service/storage/7/esWrapper.d.ts +30 -13
- package/dist/lib/service/storage/7/esWrapper.js +58 -37
- package/dist/lib/service/storage/8/elasticsearch.d.ts +153 -119
- package/dist/lib/service/storage/8/elasticsearch.js +286 -213
- package/dist/lib/service/storage/8/esWrapper.d.ts +30 -13
- package/dist/lib/service/storage/8/esWrapper.js +59 -38
- package/dist/lib/service/storage/commons/queryTranslator.d.ts +3 -3
- package/dist/lib/service/storage/commons/queryTranslator.js +71 -35
- package/dist/lib/types/ApiRoute.d.ts +12 -0
- package/dist/lib/types/ApiRoute.js +23 -0
- package/dist/lib/types/ClientConnection.d.ts +1 -1
- package/dist/lib/types/EventHandler.d.ts +10 -0
- package/dist/lib/types/Global.d.ts +8 -3
- package/dist/lib/types/HttpMessage.d.ts +2 -2
- package/dist/lib/types/HttpStream.d.ts +1 -1
- package/dist/lib/types/HttpStream.js +3 -1
- package/dist/lib/types/JSONObject.d.ts +9 -0
- package/dist/lib/types/JSONObject.js +23 -0
- package/dist/lib/types/Kuzzle.d.ts +5 -3
- package/dist/lib/types/KuzzleDocument.d.ts +1 -1
- package/dist/lib/types/KuzzleWebSocket.d.ts +24 -0
- package/dist/lib/types/KuzzleWebSocket.js +23 -0
- package/dist/lib/types/OpenApiDefinition.d.ts +1 -1
- package/dist/lib/types/Plugin.d.ts +33 -8
- package/dist/lib/types/PluginInstance.d.ts +67 -0
- package/dist/lib/types/PluginInstance.js +23 -0
- package/dist/lib/types/Policy.d.ts +1 -1
- package/dist/lib/types/Target.d.ts +8 -0
- package/dist/lib/types/Token.d.ts +14 -2
- package/dist/lib/types/config/HttpConfiguration.d.ts +5 -0
- package/dist/lib/types/config/KuzzleConfiguration.d.ts +102 -1
- package/dist/lib/types/config/PluginsConfiguration.d.ts +3 -2
- package/dist/lib/types/config/SecurityConfiguration.d.ts +6 -2
- package/dist/lib/types/config/ServerConfiguration.d.ts +2 -2
- package/dist/lib/types/config/ServicesConfiguration.d.ts +1 -1
- package/dist/lib/types/config/cache/BaseCacheRedisConfiguration.d.ts +131 -0
- package/dist/lib/types/config/cache/BaseCacheRedisConfiguration.js +3 -0
- package/dist/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +2 -106
- package/dist/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +2 -26
- package/dist/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +3 -0
- package/dist/lib/types/controllers/Controller.d.ts +12 -3
- package/dist/lib/types/controllers/ControllerDefinition.d.ts +2 -2
- package/dist/lib/types/controllers/{adminControlller.type.js → adminController.type.js} +1 -1
- package/dist/lib/types/controllers/authController.type.d.ts +2 -2
- package/dist/lib/types/core/auth/formatProcessing.type.d.ts +7 -1
- package/dist/lib/types/errors/ErrorDomains.d.ts +1 -1
- package/dist/lib/types/events/EventGenericDocument.d.ts +10 -9
- package/dist/lib/types/events/EventProtocol.d.ts +4 -4
- package/dist/lib/types/index.d.ts +7 -0
- package/dist/lib/types/index.js +7 -0
- package/dist/lib/types/shared/StoreCollectionsDefinition.d.ts +1 -1
- package/dist/lib/types/storage/7/Elasticsearch.d.ts +62 -13
- package/dist/lib/types/storage/8/Elasticsearch.d.ts +62 -13
- package/dist/lib/util/Inflector.d.ts +4 -1
- package/dist/lib/util/Inflector.js +0 -3
- package/dist/lib/util/assertType.d.ts +24 -27
- package/dist/lib/util/assertType.js +28 -39
- package/dist/lib/util/async.js +19 -6
- package/dist/lib/util/asyncStore.js +1 -1
- package/dist/lib/util/bufferedPassThrough.d.ts +9 -0
- package/dist/lib/util/bufferedPassThrough.js +27 -13
- package/dist/lib/util/bytes.d.ts +1 -1
- package/dist/lib/util/bytes.js +6 -2
- package/dist/lib/util/debug.d.ts +3 -1
- package/dist/lib/util/debug.js +42 -10
- package/dist/lib/util/deprecate.d.ts +9 -1
- package/dist/lib/util/deprecate.js +10 -6
- package/dist/lib/util/didYouMean.d.ts +2 -1
- package/dist/lib/util/didYouMean.js +8 -4
- package/dist/lib/util/distributedLock.d.ts +56 -0
- package/dist/lib/util/distributedLock.js +166 -0
- package/dist/lib/util/dump-collection.d.ts +1 -1
- package/dist/lib/util/dump-collection.js +4 -5
- package/dist/lib/util/extractFields.d.ts +15 -11
- package/dist/lib/util/extractFields.js +8 -9
- package/dist/lib/util/koncordeCompat.d.ts +2 -2
- package/dist/lib/util/koncordeCompat.js +33 -0
- package/dist/lib/util/memoize.d.ts +7 -6
- package/dist/lib/util/memoize.js +3 -3
- package/dist/lib/util/mutex.d.ts +22 -2
- package/dist/lib/util/mutex.js +39 -1
- package/dist/lib/util/name-generator.js +14 -2
- package/dist/lib/util/promback.d.ts +20 -11
- package/dist/lib/util/promback.js +14 -7
- package/dist/lib/util/requestAssertions.d.ts +30 -10
- package/dist/lib/util/requestAssertions.js +125 -121
- package/dist/lib/util/safeObject.d.ts +3 -3
- package/dist/lib/util/safeObject.js +7 -3
- package/dist/lib/util/stackTrace.d.ts +13 -5
- package/dist/lib/util/stackTrace.js +17 -12
- package/dist/lib/util/thrown.d.ts +13 -0
- package/dist/lib/util/thrown.js +46 -0
- package/dist/package.json +26 -19
- package/package.json +26 -19
- package/dist/lib/util/wildcard.d.ts +0 -1
- package/dist/lib/util/wildcard.js +0 -46
- /package/dist/lib/types/controllers/{adminControlller.type.d.ts → adminController.type.d.ts} +0 -0
|
@@ -2,8 +2,9 @@ import Bluebird from "bluebird";
|
|
|
2
2
|
import { KuzzleRequest } from "../request";
|
|
3
3
|
import { NativeController } from "./baseController";
|
|
4
4
|
import { User } from "../../model/security/user";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import type { JSONObject } from "../../types/JSONObject";
|
|
6
|
+
import type { Token } from "../../model/security/token";
|
|
7
|
+
declare class AuthController extends NativeController {
|
|
7
8
|
private anonymousId;
|
|
8
9
|
private readonly logger;
|
|
9
10
|
/**
|
|
@@ -18,6 +19,17 @@ export default class AuthController extends NativeController {
|
|
|
18
19
|
* @returns {Promise}
|
|
19
20
|
*/
|
|
20
21
|
init(): Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* The user and the token the funnel attached to the request.
|
|
24
|
+
*
|
|
25
|
+
* `RequestContext` starts every field at `null` and the funnel fills them —
|
|
26
|
+
* with the anonymous user and token when nothing authenticated. Every
|
|
27
|
+
* action below runs after that, and read them straight through: eleven
|
|
28
|
+
* unchecked dereferences, each of which would have raised a TypeError
|
|
29
|
+
* rather than the 401 this controller exists to produce.
|
|
30
|
+
*/
|
|
31
|
+
private userOf;
|
|
32
|
+
private tokenOf;
|
|
21
33
|
createToken(request: KuzzleRequest): Promise<{
|
|
22
34
|
expiresAt: number;
|
|
23
35
|
singleUse: boolean;
|
|
@@ -34,19 +46,25 @@ export default class AuthController extends NativeController {
|
|
|
34
46
|
* Creates a new API key for the user
|
|
35
47
|
* @param {KuzzleRequest} request
|
|
36
48
|
*/
|
|
37
|
-
createApiKey(request: KuzzleRequest): Promise<
|
|
49
|
+
createApiKey(request: KuzzleRequest): Promise<{
|
|
50
|
+
_id: string | null;
|
|
51
|
+
_source: JSONObject;
|
|
52
|
+
}>;
|
|
38
53
|
/**
|
|
39
54
|
* Search in the user API keys
|
|
40
55
|
*/
|
|
41
56
|
searchApiKeys(request: KuzzleRequest): Promise<{
|
|
42
|
-
hits:
|
|
57
|
+
hits: {
|
|
58
|
+
_id: string | null;
|
|
59
|
+
_source: JSONObject;
|
|
60
|
+
}[];
|
|
43
61
|
total: number;
|
|
44
62
|
}>;
|
|
45
63
|
/**
|
|
46
64
|
* Deletes an API key
|
|
47
65
|
*/
|
|
48
66
|
deleteApiKey(request: KuzzleRequest): Promise<{
|
|
49
|
-
_id: string;
|
|
67
|
+
_id: string | null;
|
|
50
68
|
}>;
|
|
51
69
|
/**
|
|
52
70
|
* Logs the current user out
|
|
@@ -84,13 +102,13 @@ export default class AuthController extends NativeController {
|
|
|
84
102
|
* @param {KuzzleRequest} request
|
|
85
103
|
* @returns {Promise<object>}
|
|
86
104
|
*/
|
|
87
|
-
checkToken(request:
|
|
105
|
+
checkToken(request: KuzzleRequest): Promise<{
|
|
88
106
|
expiresAt: any;
|
|
89
107
|
kuid: any;
|
|
90
108
|
valid: boolean;
|
|
91
109
|
state?: undefined;
|
|
92
110
|
} | {
|
|
93
|
-
state:
|
|
111
|
+
state: string;
|
|
94
112
|
valid: boolean;
|
|
95
113
|
expiresAt?: undefined;
|
|
96
114
|
kuid?: undefined;
|
|
@@ -101,7 +119,7 @@ export default class AuthController extends NativeController {
|
|
|
101
119
|
* @param {KuzzleRequest} request
|
|
102
120
|
* @returns {Promise<object>}
|
|
103
121
|
*/
|
|
104
|
-
updateSelf(request:
|
|
122
|
+
updateSelf(request: KuzzleRequest): Promise<import("../../types/core/auth/formatProcessing.type").Serialized<User>>;
|
|
105
123
|
/**
|
|
106
124
|
* List authentication strategies
|
|
107
125
|
*
|
|
@@ -112,35 +130,38 @@ export default class AuthController extends NativeController {
|
|
|
112
130
|
* @param {KuzzleRequest} request
|
|
113
131
|
* @returns {Promise.<Object>}
|
|
114
132
|
*/
|
|
115
|
-
createMyCredentials(request:
|
|
133
|
+
createMyCredentials(request: KuzzleRequest): Promise<JSONObject>;
|
|
116
134
|
/**
|
|
117
135
|
* @param {KuzzleRequest} request
|
|
118
136
|
* @returns {Promise.<Object>}
|
|
119
137
|
*/
|
|
120
|
-
updateMyCredentials(request:
|
|
138
|
+
updateMyCredentials(request: KuzzleRequest): Promise<JSONObject>;
|
|
121
139
|
/**
|
|
122
140
|
* @param {KuzzleRequest} request
|
|
123
141
|
* @returns {Promise.<Object>}
|
|
124
142
|
*/
|
|
125
|
-
credentialsExist(request:
|
|
143
|
+
credentialsExist(request: KuzzleRequest): Promise<JSONObject>;
|
|
126
144
|
/**
|
|
127
145
|
* @param {KuzzleRequest} request
|
|
128
146
|
* @returns {Promise.<Object>}
|
|
129
147
|
*/
|
|
130
|
-
validateMyCredentials(request:
|
|
148
|
+
validateMyCredentials(request: KuzzleRequest): Promise<JSONObject>;
|
|
131
149
|
/**
|
|
132
150
|
* @param {KuzzleRequest} request
|
|
133
151
|
* @returns {Promise.<Object>}
|
|
134
152
|
*/
|
|
135
|
-
deleteMyCredentials(request:
|
|
153
|
+
deleteMyCredentials(request: KuzzleRequest): Promise<{
|
|
154
|
+
acknowledged: boolean;
|
|
155
|
+
}>;
|
|
136
156
|
/**
|
|
137
157
|
* @param {KuzzleRequest} request
|
|
138
158
|
* @returns {Promise.<Object>}
|
|
139
159
|
*/
|
|
140
|
-
getMyCredentials(request:
|
|
160
|
+
getMyCredentials(request: KuzzleRequest): Promise<JSONObject>;
|
|
141
161
|
/**
|
|
142
162
|
* @param {KuzzleRequest} request
|
|
143
163
|
*/
|
|
144
|
-
refreshToken(request:
|
|
145
|
-
assertIsAuthenticated(request:
|
|
164
|
+
refreshToken(request: KuzzleRequest): Promise<Token>;
|
|
165
|
+
assertIsAuthenticated(request: KuzzleRequest): void;
|
|
146
166
|
}
|
|
167
|
+
export = AuthController;
|
|
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
28
|
/*
|
|
30
29
|
* Kuzzle, a backend software, self-hostable and ready to use
|
|
31
30
|
* to power modern apps
|
|
@@ -47,6 +46,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
47
46
|
* limitations under the License.
|
|
48
47
|
*/
|
|
49
48
|
const node_http_1 = require("node:http");
|
|
49
|
+
const node_net_1 = require("node:net");
|
|
50
|
+
const node_util_1 = require("node:util");
|
|
50
51
|
const Cookie = __importStar(require("cookie"));
|
|
51
52
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
52
53
|
const lodash_1 = require("lodash");
|
|
@@ -60,6 +61,9 @@ const user_1 = require("../../model/security/user");
|
|
|
60
61
|
const apiKey_1 = __importDefault(require("../../model/storage/apiKey"));
|
|
61
62
|
const securityController_1 = __importDefault(require("./securityController"));
|
|
62
63
|
const securityError = kerror.wrap("security", "token");
|
|
64
|
+
function isStored(user) {
|
|
65
|
+
return user._id !== null;
|
|
66
|
+
}
|
|
63
67
|
class AuthController extends baseController_1.NativeController {
|
|
64
68
|
/**
|
|
65
69
|
* @param {Kuzzle} kuzzle
|
|
@@ -100,6 +104,29 @@ class AuthController extends baseController_1.NativeController {
|
|
|
100
104
|
const anonymous = await globalThis.kuzzle.ask("core:security:user:anonymous:get");
|
|
101
105
|
this.anonymousId = anonymous._id;
|
|
102
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* The user and the token the funnel attached to the request.
|
|
109
|
+
*
|
|
110
|
+
* `RequestContext` starts every field at `null` and the funnel fills them —
|
|
111
|
+
* with the anonymous user and token when nothing authenticated. Every
|
|
112
|
+
* action below runs after that, and read them straight through: eleven
|
|
113
|
+
* unchecked dereferences, each of which would have raised a TypeError
|
|
114
|
+
* rather than the 401 this controller exists to produce.
|
|
115
|
+
*/
|
|
116
|
+
userOf(request) {
|
|
117
|
+
const user = request.context.user;
|
|
118
|
+
if (user === null || !isStored(user)) {
|
|
119
|
+
throw kerror.get("security", "rights", "unauthorized", request.input.controller, request.input.action);
|
|
120
|
+
}
|
|
121
|
+
return user;
|
|
122
|
+
}
|
|
123
|
+
tokenOf(request) {
|
|
124
|
+
const token = request.context.token;
|
|
125
|
+
if (token === null) {
|
|
126
|
+
throw securityError.get("invalid");
|
|
127
|
+
}
|
|
128
|
+
return token;
|
|
129
|
+
}
|
|
103
130
|
async createToken(request) {
|
|
104
131
|
const singleUse = request.getBoolean("singleUse");
|
|
105
132
|
if (`${request.input.args.expiresIn}` === "-1") {
|
|
@@ -127,7 +154,7 @@ class AuthController extends baseController_1.NativeController {
|
|
|
127
154
|
if (typeof requestPayload.action !== "string") {
|
|
128
155
|
throw kerror.get("api", "assert", "missing_argument", "body.action");
|
|
129
156
|
}
|
|
130
|
-
const user = request
|
|
157
|
+
const user = this.userOf(request);
|
|
131
158
|
const allowed = await user.isActionAllowed(new request_1.KuzzleRequest(requestPayload));
|
|
132
159
|
return {
|
|
133
160
|
allowed,
|
|
@@ -142,7 +169,7 @@ class AuthController extends baseController_1.NativeController {
|
|
|
142
169
|
const refresh = request.getRefresh("wait_for");
|
|
143
170
|
const apiKeyId = request.getId({ ifMissing: "generate" });
|
|
144
171
|
const description = request.getBodyString("description");
|
|
145
|
-
const user = request
|
|
172
|
+
const user = this.userOf(request);
|
|
146
173
|
const apiKey = await apiKey_1.default.create(user, expiresIn, description, {
|
|
147
174
|
apiKeyId,
|
|
148
175
|
creatorId: user._id,
|
|
@@ -157,7 +184,7 @@ class AuthController extends baseController_1.NativeController {
|
|
|
157
184
|
let query = request.getBody({});
|
|
158
185
|
const { from, size } = request.getSearchParams();
|
|
159
186
|
const lang = request.getLangParam();
|
|
160
|
-
const user = request
|
|
187
|
+
const user = this.userOf(request);
|
|
161
188
|
if (lang === "koncorde") {
|
|
162
189
|
query = await this.translateKoncorde(query);
|
|
163
190
|
}
|
|
@@ -179,11 +206,11 @@ class AuthController extends baseController_1.NativeController {
|
|
|
179
206
|
* Deletes an API key
|
|
180
207
|
*/
|
|
181
208
|
async deleteApiKey(request) {
|
|
182
|
-
const
|
|
209
|
+
const userId = this.userOf(request)._id;
|
|
183
210
|
const refresh = request.getRefresh();
|
|
184
|
-
const apiKey = await apiKey_1.default.
|
|
211
|
+
const apiKey = await apiKey_1.default.loadFromRequest(userId, request);
|
|
185
212
|
await apiKey.delete({ refresh });
|
|
186
|
-
return { _id:
|
|
213
|
+
return { _id: apiKey._id };
|
|
187
214
|
}
|
|
188
215
|
/**
|
|
189
216
|
* Logs the current user out
|
|
@@ -196,24 +223,29 @@ class AuthController extends baseController_1.NativeController {
|
|
|
196
223
|
!request.getBoolean("cookieAuth")) {
|
|
197
224
|
this.assertIsAuthenticated(request);
|
|
198
225
|
}
|
|
199
|
-
|
|
226
|
+
const { id: connectionId, protocol } = request.context.connection;
|
|
227
|
+
const token = request.context.token;
|
|
228
|
+
if (connectionId !== null &&
|
|
229
|
+
protocol !== null &&
|
|
230
|
+
globalThis.kuzzle.config.internal.notifiableProtocols.includes(protocol)) {
|
|
200
231
|
// Unlink connection so the connection will not be notified when the token expires.
|
|
201
|
-
globalThis.kuzzle.tokenManager.unlink(
|
|
232
|
+
globalThis.kuzzle.tokenManager.unlink(token, connectionId);
|
|
202
233
|
}
|
|
203
|
-
if (request.
|
|
234
|
+
if (this.userOf(request)._id !== this.anonymousId) {
|
|
204
235
|
if (request.getBoolean("global")) {
|
|
205
236
|
await globalThis.kuzzle.ask("core:security:token:deleteByKuid", request.getKuid(), { keepApiKeys: true });
|
|
206
237
|
}
|
|
207
|
-
else if (
|
|
208
|
-
|
|
209
|
-
await globalThis.kuzzle.ask("core:security:token:delete", request.context.token);
|
|
238
|
+
else if (token && token.type !== "apiKey") {
|
|
239
|
+
await globalThis.kuzzle.ask("core:security:token:delete", token);
|
|
210
240
|
}
|
|
211
241
|
}
|
|
212
242
|
if (globalThis.kuzzle.config.http.cookieAuthentication &&
|
|
213
243
|
request.getBoolean("cookieAuth")) {
|
|
214
244
|
request.response.configure({
|
|
215
245
|
headers: {
|
|
216
|
-
|
|
246
|
+
// The empty string, not `null`: `cookie.serialize` stringifies its
|
|
247
|
+
// value, so this header used to read `authToken=null`.
|
|
248
|
+
"Set-Cookie": Cookie.serialize("authToken", "", {
|
|
217
249
|
httpOnly: true,
|
|
218
250
|
path: "/",
|
|
219
251
|
sameSite: "strict",
|
|
@@ -240,6 +272,13 @@ class AuthController extends baseController_1.NativeController {
|
|
|
240
272
|
// Here we are not sending auth token when cookieAuth is set to true
|
|
241
273
|
// This allow us to detect if kuzzle does support cookie as auth token directly from the SDK
|
|
242
274
|
// or that the version of kuzzle doesn't support the feature Browser Cookie as Authentication Token
|
|
275
|
+
// `jwt` and `expiresAt` are null on a Token that has not been issued
|
|
276
|
+
// (TD-62). One that reaches the cookie has been, and the alternative to
|
|
277
|
+
// saying so here is a cookie reading `authToken=null` with an
|
|
278
|
+
// `Invalid Date` expiry.
|
|
279
|
+
if (token.jwt === null || token.expiresAt === null) {
|
|
280
|
+
throw securityError.get("generation_failed", "the issued token carries no JWT");
|
|
281
|
+
}
|
|
243
282
|
request.response.configure({
|
|
244
283
|
headers: {
|
|
245
284
|
"Set-Cookie": Cookie.serialize("authToken", token.jwt, {
|
|
@@ -263,7 +302,10 @@ class AuthController extends baseController_1.NativeController {
|
|
|
263
302
|
*/
|
|
264
303
|
async login(request) {
|
|
265
304
|
const strategy = request.getString("strategy");
|
|
266
|
-
|
|
305
|
+
// An unconnected socket rather than `null`: `IncomingMessage` only reads
|
|
306
|
+
// `readableHighWaterMark` off it, `net.Socket` opens no descriptor until
|
|
307
|
+
// it is connected, and the parameter is not optional.
|
|
308
|
+
const passportRequest = new node_http_1.IncomingMessage(new node_net_1.Socket());
|
|
267
309
|
// Even in http, the url and the method are not pushed back to the request object
|
|
268
310
|
// set some arbitrary values to get a pseudo-valid object.
|
|
269
311
|
passportRequest.url = `/login?strategy=${strategy}`;
|
|
@@ -301,7 +343,8 @@ class AuthController extends baseController_1.NativeController {
|
|
|
301
343
|
if (request.input.args.expiresIn) {
|
|
302
344
|
options.expiresIn = request.input.args.expiresIn;
|
|
303
345
|
}
|
|
304
|
-
const
|
|
346
|
+
const { id: connectionId, protocol } = request.context.connection;
|
|
347
|
+
const existingToken = globalThis.kuzzle.tokenManager.getConnectedUserToken(authResponse.content._id, connectionId);
|
|
305
348
|
/**
|
|
306
349
|
* If a previous token from the same User is linked to this connection
|
|
307
350
|
* and the token is either an API Key or an infinite duration token
|
|
@@ -309,16 +352,19 @@ class AuthController extends baseController_1.NativeController {
|
|
|
309
352
|
* to avoid breaking changes.
|
|
310
353
|
*/
|
|
311
354
|
if (existingToken &&
|
|
312
|
-
(existingToken.type === "apiKey" ||
|
|
355
|
+
(existingToken.type === "apiKey" ||
|
|
356
|
+
(existingToken.ttl !== null && existingToken.ttl < 0))) {
|
|
313
357
|
return this._sendToken(existingToken, request);
|
|
314
358
|
}
|
|
315
359
|
const token = await this.ask("core:security:token:create", authResponse.content, options);
|
|
316
360
|
if (existingToken) {
|
|
317
361
|
globalThis.kuzzle.tokenManager.refresh(existingToken, token);
|
|
318
362
|
}
|
|
319
|
-
if (
|
|
363
|
+
if (connectionId !== null &&
|
|
364
|
+
protocol !== null &&
|
|
365
|
+
globalThis.kuzzle.config.internal.notifiableProtocols.includes(protocol)) {
|
|
320
366
|
// Link the connection with the token, this way the connection can be notified when the token has expired.
|
|
321
|
-
globalThis.kuzzle.tokenManager.link(token,
|
|
367
|
+
globalThis.kuzzle.tokenManager.link(token, connectionId);
|
|
322
368
|
}
|
|
323
369
|
return this._sendToken(token, request);
|
|
324
370
|
}
|
|
@@ -330,15 +376,16 @@ class AuthController extends baseController_1.NativeController {
|
|
|
330
376
|
*/
|
|
331
377
|
async getCurrentUser(request) {
|
|
332
378
|
const promises = [];
|
|
333
|
-
const userId = request.
|
|
379
|
+
const userId = this.tokenOf(request).userId;
|
|
334
380
|
const formattedUser = {
|
|
335
|
-
...formatProcessing_1.default.serializeUser(request
|
|
381
|
+
...formatProcessing_1.default.serializeUser(this.userOf(request)),
|
|
336
382
|
strategies: [],
|
|
337
383
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
384
|
+
// The anonymous user has no credentials on any strategy. The branch this
|
|
385
|
+
// replaces pushed `Bluebird.resolve([])` into the list, so `strategies`
|
|
386
|
+
// came back as `[[]]` and the response carried a `strategies` array whose
|
|
387
|
+
// one entry was an empty array.
|
|
388
|
+
if (this.anonymousId !== userId) {
|
|
342
389
|
for (const strategy of globalThis.kuzzle.pluginsManager.listStrategies()) {
|
|
343
390
|
const existsMethod = globalThis.kuzzle.pluginsManager.getStrategyMethod(strategy, "exists");
|
|
344
391
|
promises.push(existsMethod(request, userId, strategy)
|
|
@@ -347,9 +394,7 @@ class AuthController extends baseController_1.NativeController {
|
|
|
347
394
|
}
|
|
348
395
|
}
|
|
349
396
|
const strategies = await bluebird_1.default.all(promises);
|
|
350
|
-
|
|
351
|
-
formattedUser.strategies = strategies.filter((item) => item !== null);
|
|
352
|
-
}
|
|
397
|
+
formattedUser.strategies = strategies.filter((item) => item !== null);
|
|
353
398
|
return formattedUser;
|
|
354
399
|
}
|
|
355
400
|
/**
|
|
@@ -359,10 +404,12 @@ class AuthController extends baseController_1.NativeController {
|
|
|
359
404
|
* @returns {Promise<object>}
|
|
360
405
|
*/
|
|
361
406
|
getMyRights(request) {
|
|
362
|
-
return request
|
|
407
|
+
return (this.userOf(request)
|
|
363
408
|
.getRights()
|
|
364
|
-
.
|
|
365
|
-
|
|
409
|
+
// `Object.values`: the reduce it replaces concatenated each key's value
|
|
410
|
+
// into an array, one level deep, which is what that is.
|
|
411
|
+
.then((rights) => Object.values(rights))
|
|
412
|
+
.then((rights) => ({ hits: rights, total: rights.length })));
|
|
366
413
|
}
|
|
367
414
|
/**
|
|
368
415
|
* Checks the validity of a token.
|
|
@@ -371,7 +418,7 @@ class AuthController extends baseController_1.NativeController {
|
|
|
371
418
|
* @returns {Promise<object>}
|
|
372
419
|
*/
|
|
373
420
|
async checkToken(request) {
|
|
374
|
-
let token
|
|
421
|
+
let token;
|
|
375
422
|
if (globalThis.kuzzle.config.http.cookieAuthentication &&
|
|
376
423
|
request.getBoolean("cookieAuth")) {
|
|
377
424
|
token = request.input.jwt;
|
|
@@ -384,7 +431,8 @@ class AuthController extends baseController_1.NativeController {
|
|
|
384
431
|
return { expiresAt, kuid: userId, valid: true };
|
|
385
432
|
}
|
|
386
433
|
catch (error) {
|
|
387
|
-
|
|
434
|
+
// A 401 is the answer, not a failure: the token is simply not valid.
|
|
435
|
+
if (error instanceof errors_1.KuzzleError && error.status === 401) {
|
|
388
436
|
return { state: error.message, valid: false };
|
|
389
437
|
}
|
|
390
438
|
throw error;
|
|
@@ -520,23 +568,24 @@ class AuthController extends baseController_1.NativeController {
|
|
|
520
568
|
this.logger.error(`Error while refreshing the token with the strategy ${strategy} with ERROR: ${err}`);
|
|
521
569
|
// Adding some debug information to better known our target here.
|
|
522
570
|
this.logger.debug(`Error when refreshing token with request: ${JSON.stringify(request)}`);
|
|
523
|
-
throw securityError.get("refresh_forbidden", request.
|
|
571
|
+
throw securityError.get("refresh_forbidden", this.tokenOf(request).jwt);
|
|
524
572
|
}
|
|
525
573
|
}
|
|
526
574
|
const token = await this.ask("core:security:token:refresh", request.context.user, request.context.token, expiresIn);
|
|
527
575
|
return this._sendToken(token, request);
|
|
528
576
|
}
|
|
529
577
|
assertIsAuthenticated(request) {
|
|
530
|
-
if (request.
|
|
578
|
+
if (this.userOf(request)._id === this.anonymousId) {
|
|
531
579
|
throw kerror.get("security", "rights", "unauthorized", request.input.controller, request.input.action);
|
|
532
580
|
}
|
|
533
581
|
}
|
|
534
582
|
}
|
|
535
|
-
exports.default = AuthController;
|
|
536
583
|
function wrapPluginError(error) {
|
|
537
|
-
if (
|
|
538
|
-
throw
|
|
584
|
+
if (error instanceof errors_1.KuzzleError) {
|
|
585
|
+
throw error;
|
|
539
586
|
}
|
|
540
|
-
|
|
587
|
+
const cause = error instanceof Error ? error : new Error((0, node_util_1.inspect)(error));
|
|
588
|
+
throw kerror.getFrom(cause, "plugin", "runtime", "unexpected_error", cause.message);
|
|
541
589
|
}
|
|
590
|
+
module.exports = AuthController;
|
|
542
591
|
//# sourceMappingURL=authController.js.map
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { JSONObject } from "
|
|
2
|
-
import { KuzzleRequest } from "../request";
|
|
1
|
+
import type { JSONObject } from "../../types/JSONObject";
|
|
2
|
+
import type { KuzzleRequest } from "../request";
|
|
3
|
+
/**
|
|
4
|
+
* Handler of a controller action. Returns the action result, or a promise of
|
|
5
|
+
* it — the funnel awaits whatever comes back.
|
|
6
|
+
*/
|
|
7
|
+
export type ControllerAction = (request: KuzzleRequest) => unknown;
|
|
3
8
|
/**
|
|
4
9
|
* Base class for all controllers
|
|
5
10
|
*/
|
|
@@ -7,7 +12,7 @@ export declare class BaseController {
|
|
|
7
12
|
protected __actions: Set<string>;
|
|
8
13
|
constructor();
|
|
9
14
|
get _actions(): Set<string>;
|
|
10
|
-
_addAction(name:
|
|
15
|
+
_addAction(name: string, fn: ControllerAction): void;
|
|
11
16
|
/**
|
|
12
17
|
* Check if the provided action name exists within that controller.
|
|
13
18
|
* This check's purpose is to prevent actions leak by making actions exposure
|
|
@@ -20,7 +25,7 @@ export declare class BaseController {
|
|
|
20
25
|
export declare class NativeController extends BaseController {
|
|
21
26
|
protected ask: (event: string, ...args: any[]) => Promise<any>;
|
|
22
27
|
protected pipe: (event: string, ...args: any[]) => Promise<any>;
|
|
23
|
-
constructor(actions?:
|
|
28
|
+
constructor(actions?: string[]);
|
|
24
29
|
/**
|
|
25
30
|
* Controller optional initialization method.
|
|
26
31
|
* Used to perform asynchronous initialization safely: the funnel will wait
|
|
@@ -54,7 +59,7 @@ export declare class NativeController extends BaseController {
|
|
|
54
59
|
index: string;
|
|
55
60
|
collections?: string[];
|
|
56
61
|
}>, { allowEmptyCollections }?: {
|
|
57
|
-
allowEmptyCollections?: boolean;
|
|
62
|
+
allowEmptyCollections?: boolean | undefined;
|
|
58
63
|
}): void;
|
|
59
64
|
_hasMultiTargets(str: string): boolean;
|
|
60
65
|
/**
|
|
@@ -47,6 +47,13 @@ exports.NativeController = exports.BaseController = void 0;
|
|
|
47
47
|
const kerror = __importStar(require("../../kerror"));
|
|
48
48
|
const safeObject_1 = require("../../util/safeObject");
|
|
49
49
|
const assertionError = kerror.wrap("api", "assert");
|
|
50
|
+
/** What `QueryTranslator` throws for a Koncorde keyword it cannot translate. */
|
|
51
|
+
function isKeywordError(thrown) {
|
|
52
|
+
return (typeof thrown === "object" &&
|
|
53
|
+
thrown !== null &&
|
|
54
|
+
"keyword" in thrown &&
|
|
55
|
+
(0, safeObject_1.isPlainObject)(thrown.keyword));
|
|
56
|
+
}
|
|
50
57
|
/**
|
|
51
58
|
* Base class for all controllers
|
|
52
59
|
*/
|
|
@@ -59,7 +66,11 @@ class BaseController {
|
|
|
59
66
|
}
|
|
60
67
|
_addAction(name, fn) {
|
|
61
68
|
this.__actions.add(name);
|
|
62
|
-
this[name] = fn
|
|
69
|
+
// `name` is a runtime-built key, so a plain `this[name] = fn` cannot be
|
|
70
|
+
// typed without opening the whole class to an index signature — the same
|
|
71
|
+
// trade-off TD-28 (#2704) settled in `memoryStorageController` with
|
|
72
|
+
// `Reflect.set`, kept consistent here.
|
|
73
|
+
Reflect.set(this, name, fn);
|
|
63
74
|
}
|
|
64
75
|
/**
|
|
65
76
|
* Check if the provided action name exists within that controller.
|
|
@@ -99,10 +110,15 @@ class NativeController extends BaseController {
|
|
|
99
110
|
return await this.ask("core:storage:public:translate", koncordeFilters);
|
|
100
111
|
}
|
|
101
112
|
catch (error) {
|
|
102
|
-
|
|
113
|
+
// `QueryTranslator` raises a `KeywordError`, which carries the keyword
|
|
114
|
+
// it could not translate. Anything else is not this method's to
|
|
115
|
+
// reinterpret — duck-typed, as it was, since that class is not
|
|
116
|
+
// exported.
|
|
117
|
+
const keyword = isKeywordError(error) ? error.keyword : undefined;
|
|
118
|
+
if (keyword === undefined) {
|
|
103
119
|
throw error;
|
|
104
120
|
}
|
|
105
|
-
throw assertionError.get("koncorde_restricted_keyword",
|
|
121
|
+
throw assertionError.get("koncorde_restricted_keyword", keyword.type, keyword.name);
|
|
106
122
|
}
|
|
107
123
|
}
|
|
108
124
|
/**
|
|
@@ -140,29 +156,34 @@ class NativeController extends BaseController {
|
|
|
140
156
|
* @param options.allowEmptyCollections
|
|
141
157
|
*/
|
|
142
158
|
assertTargetsAreValid(targets, { allowEmptyCollections = false } = {}) {
|
|
143
|
-
for (
|
|
144
|
-
const target = targets[i];
|
|
159
|
+
for (const [i, target] of targets.entries()) {
|
|
145
160
|
if (!target.index) {
|
|
146
161
|
throw kerror.get("api", "assert", "missing_argument", `targets[${i}].index`);
|
|
147
162
|
}
|
|
148
163
|
if (this._hasMultiTargets(target.index)) {
|
|
149
164
|
throw kerror.get("services", "storage", "invalid_target_format", `targets[${i}].index`, target.index);
|
|
150
165
|
}
|
|
151
|
-
|
|
152
|
-
|
|
166
|
+
// Read once, and the two "nothing to check" cases answered where they
|
|
167
|
+
// are decided: the chain this replaces dereferenced `target.collections`
|
|
168
|
+
// twice past the guards that had established it, which is what the
|
|
169
|
+
// `allowEmptyCollections` branch made unprovable.
|
|
170
|
+
const collections = target.collections;
|
|
171
|
+
if (collections === undefined) {
|
|
172
|
+
if (!allowEmptyCollections) {
|
|
173
|
+
throw kerror.get("api", "assert", "missing_argument", `targets[${i}].collections`);
|
|
174
|
+
}
|
|
175
|
+
continue;
|
|
153
176
|
}
|
|
154
|
-
if (
|
|
177
|
+
if (!Array.isArray(collections)) {
|
|
155
178
|
throw kerror.get("api", "assert", "invalid_type", `targets[${i}].collections`, "array");
|
|
156
179
|
}
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
(!target.collections || target.collections.length === 0)) {
|
|
180
|
+
if (collections.length === 0) {
|
|
181
|
+
if (!allowEmptyCollections) {
|
|
182
|
+
throw kerror.get("api", "assert", "empty_argument", `targets[${i}].collections`);
|
|
183
|
+
}
|
|
162
184
|
continue;
|
|
163
185
|
}
|
|
164
|
-
for (
|
|
165
|
-
const collection = target.collections[j];
|
|
186
|
+
for (const [j, collection] of collections.entries()) {
|
|
166
187
|
if (typeof collection !== "string") {
|
|
167
188
|
throw kerror.get("api", "assert", "invalid_type", `targets[${i}].collections[${j}]`, "string");
|
|
168
189
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { KuzzleRequest } from "../request";
|
|
2
|
+
import { NativeController } from "./baseController";
|
|
2
3
|
/**
|
|
3
4
|
* @class BulkController
|
|
4
5
|
*/
|
|
@@ -10,11 +11,14 @@ declare class BulkController extends NativeController {
|
|
|
10
11
|
* @param {Request} request
|
|
11
12
|
* @returns {Promise}
|
|
12
13
|
*/
|
|
13
|
-
import(request:
|
|
14
|
+
import(request: KuzzleRequest): Promise<{
|
|
15
|
+
errors: any;
|
|
16
|
+
successes: any;
|
|
17
|
+
}>;
|
|
14
18
|
/**
|
|
15
19
|
* Write a document without adding metadata or performing data validation.
|
|
16
20
|
*/
|
|
17
|
-
write(request:
|
|
21
|
+
write(request: KuzzleRequest): Promise<{
|
|
18
22
|
_id: any;
|
|
19
23
|
_source: any;
|
|
20
24
|
_version: any;
|
|
@@ -22,7 +26,7 @@ declare class BulkController extends NativeController {
|
|
|
22
26
|
/**
|
|
23
27
|
* Write several documents without adding metadata or performing data validation.
|
|
24
28
|
*/
|
|
25
|
-
mWrite(request:
|
|
29
|
+
mWrite(request: KuzzleRequest): Promise<{
|
|
26
30
|
errors: any;
|
|
27
31
|
successes: any;
|
|
28
32
|
}>;
|
|
@@ -32,7 +36,7 @@ declare class BulkController extends NativeController {
|
|
|
32
36
|
* - fetching deleted documents
|
|
33
37
|
* - triggering realtime notifications
|
|
34
38
|
*/
|
|
35
|
-
deleteByQuery(request:
|
|
39
|
+
deleteByQuery(request: KuzzleRequest): Promise<{
|
|
36
40
|
deleted: any;
|
|
37
41
|
}>;
|
|
38
42
|
/**
|
|
@@ -41,6 +45,6 @@ declare class BulkController extends NativeController {
|
|
|
41
45
|
* - Injecting Kuzzle metadata
|
|
42
46
|
* - Triggering realtime notifications
|
|
43
47
|
*/
|
|
44
|
-
updateByQuery(request:
|
|
48
|
+
updateByQuery(request: KuzzleRequest): Promise<any>;
|
|
45
49
|
}
|
|
46
|
-
|
|
50
|
+
export = BulkController;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*
|
|
2
3
|
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
4
|
* to power modern apps
|
|
@@ -18,14 +19,36 @@
|
|
|
18
19
|
* See the License for the specific language governing permissions and
|
|
19
20
|
* limitations under the License.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
25
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
26
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(o, k2, desc);
|
|
29
|
+
}) : (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
o[k2] = m[k];
|
|
32
|
+
}));
|
|
33
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
34
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
35
|
+
}) : function(o, v) {
|
|
36
|
+
o["default"] = v;
|
|
37
|
+
});
|
|
38
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
const actionEnum = __importStar(require("../../core/realtime/actionEnum"));
|
|
46
|
+
const kerror = __importStar(require("../../kerror"));
|
|
47
|
+
const baseController_1 = require("./baseController");
|
|
25
48
|
/**
|
|
26
49
|
* @class BulkController
|
|
27
50
|
*/
|
|
28
|
-
class BulkController extends NativeController {
|
|
51
|
+
class BulkController extends baseController_1.NativeController {
|
|
29
52
|
constructor() {
|
|
30
53
|
super(["import", "write", "mWrite", "deleteByQuery", "updateByQuery"]);
|
|
31
54
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { NativeController } from "./baseController";
|
|
2
2
|
declare class ClusterController extends NativeController {
|
|
3
3
|
constructor();
|
|
4
4
|
status(): Promise<any>;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
export = ClusterController;
|