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
|
@@ -1,24 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
import type { JSONObject } from "../../types/JSONObject";
|
|
2
|
+
import type { Logger } from "../../kuzzle/Logger";
|
|
3
|
+
import "../../types/Global";
|
|
4
|
+
/**
|
|
5
|
+
* A `{ _id: body }` map, as the security fixtures / import payloads express
|
|
6
|
+
* roles, profiles and users.
|
|
7
|
+
*/
|
|
8
|
+
type SecurityObjects = Record<string, JSONObject>;
|
|
9
|
+
interface SecurityPermissions {
|
|
10
|
+
roles?: SecurityObjects;
|
|
11
|
+
profiles?: SecurityObjects;
|
|
12
|
+
users?: SecurityObjects;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* How to react to users that already exist when importing.
|
|
16
|
+
*/
|
|
17
|
+
type OnExistingUsers = "fail" | "skip" | "overwrite";
|
|
18
|
+
interface LoadOptions {
|
|
19
|
+
force?: boolean;
|
|
20
|
+
onExistingUsers?: OnExistingUsers;
|
|
21
|
+
onExistingUsersWarning?: boolean;
|
|
22
|
+
refresh?: string;
|
|
23
|
+
user?: JSONObject | null;
|
|
24
|
+
}
|
|
2
25
|
/**
|
|
3
26
|
* @class SecurityLoader
|
|
4
27
|
*/
|
|
5
28
|
declare class SecurityLoader {
|
|
6
|
-
logger:
|
|
29
|
+
logger: Logger;
|
|
30
|
+
constructor();
|
|
7
31
|
init(): Promise<void>;
|
|
8
|
-
load(permissions?:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}): Promise<void>;
|
|
15
|
-
_create(action: any, objects: any, collection: any, { force, refresh, user }?: {
|
|
16
|
-
force: any;
|
|
17
|
-
refresh: any;
|
|
18
|
-
user: any;
|
|
19
|
-
}): Promise<void>;
|
|
20
|
-
_getUsersToLoad(users: any, { onExistingUsers, warning }?: {
|
|
21
|
-
onExistingUsers: any;
|
|
22
|
-
warning: any;
|
|
23
|
-
}): Promise<any>;
|
|
32
|
+
load(permissions?: SecurityPermissions, { force, onExistingUsers, onExistingUsersWarning, refresh, user, }?: LoadOptions): Promise<void>;
|
|
33
|
+
_create(action: string, objects: SecurityObjects | undefined, collection: string, { force, refresh, user, }?: Pick<LoadOptions, "force" | "refresh" | "user">): Promise<void>;
|
|
34
|
+
_getUsersToLoad(users: SecurityObjects | undefined, { onExistingUsers, warning, }?: {
|
|
35
|
+
onExistingUsers?: OnExistingUsers;
|
|
36
|
+
warning?: boolean;
|
|
37
|
+
}): Promise<SecurityObjects | undefined>;
|
|
24
38
|
}
|
|
39
|
+
export = SecurityLoader;
|
|
@@ -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,12 +19,38 @@
|
|
|
18
19
|
* See the License for the specific language governing permissions and
|
|
19
20
|
* limitations under the License.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
48
|
+
const lodash_1 = require("lodash");
|
|
49
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
|
50
|
+
const request_1 = require("../../api/request");
|
|
51
|
+
const requestAssertions_1 = require("../../util/requestAssertions");
|
|
52
|
+
const kerror = __importStar(require("../../kerror"));
|
|
53
|
+
require("../../types/Global");
|
|
27
54
|
/**
|
|
28
55
|
* @class SecurityLoader
|
|
29
56
|
*/
|
|
@@ -40,7 +67,7 @@ class SecurityLoader {
|
|
|
40
67
|
global.kuzzle.onAsk("core:security:load", (json, opts) => this.load(json, opts));
|
|
41
68
|
}
|
|
42
69
|
async load(permissions = {}, { force, onExistingUsers = "fail", onExistingUsersWarning = false, refresh = "false", user = null, } = {}) {
|
|
43
|
-
assertIsObject(permissions);
|
|
70
|
+
(0, requestAssertions_1.assertIsObject)(permissions);
|
|
44
71
|
await this._create("createOrReplaceRole", permissions.roles, "roles", {
|
|
45
72
|
force,
|
|
46
73
|
refresh,
|
|
@@ -53,15 +80,15 @@ class SecurityLoader {
|
|
|
53
80
|
});
|
|
54
81
|
await this._create("createUser", usersToLoad, "users", { refresh, user });
|
|
55
82
|
}
|
|
56
|
-
async _create(action, objects, collection, { force, refresh, user } = {}) {
|
|
83
|
+
async _create(action, objects, collection, { force, refresh, user, } = {}) {
|
|
57
84
|
if (!objects) {
|
|
58
85
|
return;
|
|
59
86
|
}
|
|
60
|
-
assertIsObject(objects);
|
|
87
|
+
(0, requestAssertions_1.assertIsObject)(objects);
|
|
61
88
|
const promises = [];
|
|
62
89
|
for (const [_id, body] of Object.entries(objects)) {
|
|
63
|
-
assertIsObject(body);
|
|
64
|
-
const request = new Request({
|
|
90
|
+
(0, requestAssertions_1.assertIsObject)(body);
|
|
91
|
+
const request = new request_1.Request({
|
|
65
92
|
_id,
|
|
66
93
|
action,
|
|
67
94
|
body,
|
|
@@ -71,15 +98,15 @@ class SecurityLoader {
|
|
|
71
98
|
}, { user });
|
|
72
99
|
promises.push(global.kuzzle.funnel.processRequest(request));
|
|
73
100
|
}
|
|
74
|
-
await
|
|
101
|
+
await bluebird_1.default.all(promises);
|
|
75
102
|
await global.kuzzle.internalIndex.refreshCollection(collection);
|
|
76
103
|
}
|
|
77
|
-
async _getUsersToLoad(users, { onExistingUsers, warning } = {}) {
|
|
78
|
-
if (isEmpty(users)) {
|
|
104
|
+
async _getUsersToLoad(users, { onExistingUsers, warning, } = {}) {
|
|
105
|
+
if ((0, lodash_1.isEmpty)(users)) {
|
|
79
106
|
return users;
|
|
80
107
|
}
|
|
81
108
|
const ids = Object.keys(users);
|
|
82
|
-
const mGetUsers = new Request({
|
|
109
|
+
const mGetUsers = new request_1.Request({
|
|
83
110
|
action: "mGetUsers",
|
|
84
111
|
body: { ids },
|
|
85
112
|
controller: "security",
|
|
@@ -107,7 +134,7 @@ class SecurityLoader {
|
|
|
107
134
|
if (warning) {
|
|
108
135
|
this.logger.info(`Users overwritten during import: ${existingUserIds}`);
|
|
109
136
|
}
|
|
110
|
-
const mDeleteUsers = new Request({
|
|
137
|
+
const mDeleteUsers = new request_1.Request({
|
|
111
138
|
action: "mDeleteUsers",
|
|
112
139
|
body: { ids: existingUserIds },
|
|
113
140
|
controller: "security",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JSONObject } from "
|
|
1
|
+
import type { JSONObject } from "../../types/JSONObject";
|
|
2
2
|
import { Token } from "../../model/security/token";
|
|
3
|
-
import { User } from "../../model/security/user";
|
|
3
|
+
import type { User } from "../../model/security/user";
|
|
4
4
|
import { ObjectRepository } from "../shared/ObjectRepository";
|
|
5
5
|
export declare class TokenRepository extends ObjectRepository<Token> {
|
|
6
6
|
private tokenGracePeriod;
|
|
@@ -45,17 +45,31 @@ export declare class TokenRepository extends ObjectRepository<Token> {
|
|
|
45
45
|
ttl: number;
|
|
46
46
|
singleUse: boolean;
|
|
47
47
|
}): Promise<Token>;
|
|
48
|
+
/**
|
|
49
|
+
* Verifies a JWT's signature and answers its payload.
|
|
50
|
+
*
|
|
51
|
+
* Extracted from `verifyToken` unchanged: its three `catch` branches were
|
|
52
|
+
* most of that method's cognitive complexity, and none of them is about
|
|
53
|
+
* what the token then means.
|
|
54
|
+
*/
|
|
55
|
+
private decodeToken;
|
|
56
|
+
/**
|
|
57
|
+
* `loadForUser`, with the wrapping every caller of `verifyToken` expects:
|
|
58
|
+
* an `UnauthorizedError` is the answer, anything else is a verification
|
|
59
|
+
* failure.
|
|
60
|
+
*/
|
|
61
|
+
private loadVerifiedToken;
|
|
48
62
|
verifyToken(token: string): Promise<Token>;
|
|
49
|
-
_verifyApiKey(decoded:
|
|
63
|
+
_verifyApiKey(decoded: JSONObject, token: string): Promise<Token>;
|
|
50
64
|
removeTokenPrefix(token: string): string;
|
|
51
|
-
loadForUser(userId: string, encodedToken: string): Promise<Token>;
|
|
52
|
-
hydrate(userToken:
|
|
53
|
-
serializeToDatabase(token:
|
|
65
|
+
loadForUser(userId: string, encodedToken: string): Promise<Token | null>;
|
|
66
|
+
hydrate(userToken: Token, data: JSONObject): Promise<Token>;
|
|
67
|
+
serializeToDatabase(token: Token): any;
|
|
54
68
|
/**
|
|
55
69
|
* Deletes tokens affiliated to the provided user identifier
|
|
56
70
|
*/
|
|
57
71
|
deleteByKuid(kuid: string, { keepApiKeys }?: {
|
|
58
|
-
keepApiKeys?: boolean;
|
|
72
|
+
keepApiKeys?: boolean | undefined;
|
|
59
73
|
}): Promise<void>;
|
|
60
74
|
/**
|
|
61
75
|
* The repository main class refreshes automatically the TTL
|
|
@@ -57,6 +57,14 @@ const apiKey_1 = __importDefault(require("../../model/storage/apiKey"));
|
|
|
57
57
|
const ObjectRepository_1 = require("../shared/ObjectRepository");
|
|
58
58
|
const crypto_1 = require("../../util/crypto");
|
|
59
59
|
const securityError = kerror.wrap("security", "token");
|
|
60
|
+
/**
|
|
61
|
+
* The deprecated `security.jwt` section, which the `authToken` settings fall
|
|
62
|
+
* back to. The packaged defaults always ship it; the type says optional only
|
|
63
|
+
* because v2.56.0's did (see SecurityConfiguration.jwt).
|
|
64
|
+
*/
|
|
65
|
+
function legacyJwtConfig() {
|
|
66
|
+
return global.kuzzle.config.security.jwt; // NOSONAR: the deprecated section is read on purpose, as the documented fallback
|
|
67
|
+
}
|
|
60
68
|
class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
61
69
|
constructor(opts = {}) {
|
|
62
70
|
super();
|
|
@@ -65,7 +73,7 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
65
73
|
if (opts.ttl !== undefined) {
|
|
66
74
|
this.ttl = opts.ttl;
|
|
67
75
|
}
|
|
68
|
-
this.tokenGracePeriod = Math.floor(
|
|
76
|
+
this.tokenGracePeriod = Math.floor(legacyJwtConfig().gracePeriod);
|
|
69
77
|
this.anonymousToken = new token_1.Token({ userId: "-1" });
|
|
70
78
|
}
|
|
71
79
|
async init() {
|
|
@@ -130,7 +138,9 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
130
138
|
}
|
|
131
139
|
catch (e) {
|
|
132
140
|
// ? seed has changed
|
|
133
|
-
if (e
|
|
141
|
+
if (e instanceof Error &&
|
|
142
|
+
"id" in e &&
|
|
143
|
+
e.id === "security.token.invalid") {
|
|
134
144
|
await global.kuzzle.ask("core:cache:internal:del", existingTokens);
|
|
135
145
|
}
|
|
136
146
|
}
|
|
@@ -158,7 +168,7 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
158
168
|
throw securityError.get("invalid");
|
|
159
169
|
}
|
|
160
170
|
// do not refresh API Keys or token that have an infinite TTL
|
|
161
|
-
if (token.type === "apiKey" || token.ttl < 0) {
|
|
171
|
+
if (token.type === "apiKey" || (token.ttl ?? 0) < 0) {
|
|
162
172
|
throw securityError.get("refresh_forbidden", token.type === "apiKey" ? "API Key" : "Token with infinite TTL");
|
|
163
173
|
}
|
|
164
174
|
const refreshed = await this.generateToken(user, { expiresIn });
|
|
@@ -175,8 +185,8 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
175
185
|
* @returns {Promise.<Object>} { _id, jwt, userId, ttl, expiresAt }
|
|
176
186
|
*/
|
|
177
187
|
async generateToken(user, { algorithm = global.kuzzle.config.security.authToken.algorithm ??
|
|
178
|
-
|
|
179
|
-
|
|
188
|
+
legacyJwtConfig().algorithm, expiresIn = global.kuzzle.config.security.authToken.expiresIn ??
|
|
189
|
+
legacyJwtConfig().expiresIn, bypassMaxTTL = false, type = "authToken", singleUse = false, } = {}) {
|
|
180
190
|
if (!user || user._id === null) {
|
|
181
191
|
throw securityError.get("unknown_user");
|
|
182
192
|
}
|
|
@@ -184,7 +194,7 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
184
194
|
const maxTTL = type === "apiKey"
|
|
185
195
|
? global.kuzzle.config.security.apiKey.maxTTL
|
|
186
196
|
: (global.kuzzle.config.security.authToken.maxTTL ??
|
|
187
|
-
|
|
197
|
+
legacyJwtConfig().maxTTL);
|
|
188
198
|
if (!bypassMaxTTL &&
|
|
189
199
|
maxTTL > -1 &&
|
|
190
200
|
(parsedExpiresIn > maxTTL || parsedExpiresIn === -1)) {
|
|
@@ -204,7 +214,7 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
204
214
|
encodedToken = jsonwebtoken_1.default.sign({ _id: user._id }, global.kuzzle.secret, signOptions);
|
|
205
215
|
}
|
|
206
216
|
catch (err) {
|
|
207
|
-
throw securityError.getFrom(err, "generation_failed", err.message);
|
|
217
|
+
throw securityError.getFrom(err instanceof Error ? err : new Error(String(err)), "generation_failed", err instanceof Error ? err.message : String(err));
|
|
208
218
|
}
|
|
209
219
|
if (type === "apiKey") {
|
|
210
220
|
encodedToken = token_1.Token.APIKEY_PREFIX + encodedToken;
|
|
@@ -247,22 +257,24 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
247
257
|
return await this.persistToCache(token, { ttl: redisTTL });
|
|
248
258
|
}
|
|
249
259
|
catch (err) {
|
|
250
|
-
throw kerror.getFrom(err, "services", "cache", "write_failed", err.message);
|
|
260
|
+
throw kerror.getFrom(err instanceof Error ? err : new Error(String(err)), "services", "cache", "write_failed", err instanceof Error ? err.message : String(err));
|
|
251
261
|
}
|
|
252
262
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Verifies a JWT's signature and answers its payload.
|
|
265
|
+
*
|
|
266
|
+
* Extracted from `verifyToken` unchanged: its three `catch` branches were
|
|
267
|
+
* most of that method's cognitive complexity, and none of them is about
|
|
268
|
+
* what the token then means.
|
|
269
|
+
*/
|
|
270
|
+
decodeToken(tokenWithoutPrefix) {
|
|
260
271
|
try {
|
|
261
|
-
decoded = jsonwebtoken_1.default.verify(tokenWithoutPrefix, global.kuzzle.secret);
|
|
272
|
+
const decoded = jsonwebtoken_1.default.verify(tokenWithoutPrefix, global.kuzzle.secret);
|
|
262
273
|
// probably forged token => throw without providing any information
|
|
263
274
|
if (!decoded._id) {
|
|
264
275
|
throw new jsonwebtoken_1.default.JsonWebTokenError("Invalid token");
|
|
265
276
|
}
|
|
277
|
+
return decoded;
|
|
266
278
|
}
|
|
267
279
|
catch (err) {
|
|
268
280
|
if (err instanceof jsonwebtoken_1.default.JsonWebTokenError) {
|
|
@@ -271,21 +283,36 @@ class TokenRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
271
283
|
if (err instanceof jsonwebtoken_1.default.TokenExpiredError) {
|
|
272
284
|
throw securityError.get("expired");
|
|
273
285
|
}
|
|
274
|
-
throw securityError.getFrom(err, "verification_error", err.message);
|
|
275
|
-
}
|
|
276
|
-
if (isApiKey) {
|
|
277
|
-
return this._verifyApiKey(decoded, token);
|
|
286
|
+
throw securityError.getFrom(err instanceof Error ? err : new Error(String(err)), "verification_error", err instanceof Error ? err.message : String(err));
|
|
278
287
|
}
|
|
279
|
-
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* `loadForUser`, with the wrapping every caller of `verifyToken` expects:
|
|
291
|
+
* an `UnauthorizedError` is the answer, anything else is a verification
|
|
292
|
+
* failure.
|
|
293
|
+
*/
|
|
294
|
+
async loadVerifiedToken(userId, token) {
|
|
280
295
|
try {
|
|
281
|
-
|
|
296
|
+
return await this.loadForUser(userId, token);
|
|
282
297
|
}
|
|
283
298
|
catch (err) {
|
|
284
299
|
if (err instanceof errors_1.UnauthorizedError) {
|
|
285
300
|
throw err;
|
|
286
301
|
}
|
|
287
|
-
throw securityError.getFrom(err, "verification_error", err.message);
|
|
302
|
+
throw securityError.getFrom(err instanceof Error ? err : new Error(String(err)), "verification_error", err instanceof Error ? err.message : String(err));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async verifyToken(token) {
|
|
306
|
+
if (token === null) {
|
|
307
|
+
return this.anonymousToken;
|
|
308
|
+
}
|
|
309
|
+
const isApiKey = token.startsWith(token_1.Token.APIKEY_PREFIX);
|
|
310
|
+
const tokenWithoutPrefix = this.removeTokenPrefix(token);
|
|
311
|
+
const decoded = this.decodeToken(tokenWithoutPrefix);
|
|
312
|
+
if (isApiKey) {
|
|
313
|
+
return this._verifyApiKey(decoded, token);
|
|
288
314
|
}
|
|
315
|
+
const userToken = await this.loadVerifiedToken(decoded._id, token);
|
|
289
316
|
if (userToken === null) {
|
|
290
317
|
throw securityError.get("invalid");
|
|
291
318
|
}
|
|
@@ -1,17 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import type { JSONObject } from "../../types/JSONObject";
|
|
2
|
+
import { ObjectRepository } from "../shared/ObjectRepository";
|
|
3
|
+
import { User } from "../../model/security/user";
|
|
4
|
+
import "../../types/Global";
|
|
5
|
+
import type { ProfileRepository } from "./profileRepository";
|
|
6
|
+
import type { TokenRepository } from "./tokenRepository";
|
|
7
|
+
interface SecurityModule {
|
|
8
|
+
profile: ProfileRepository;
|
|
9
|
+
token: TokenRepository;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Who is performing the write, and how eagerly the change must be visible.
|
|
13
|
+
* `userId` ends up in `_kuzzle_info.author`.
|
|
14
|
+
*/
|
|
15
|
+
interface WriteOptions {
|
|
16
|
+
userId?: string | null;
|
|
17
|
+
refresh?: string;
|
|
18
|
+
retryOnConflict?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Per-backend options forwarded to `ObjectRepository.persistToDatabase` and
|
|
22
|
+
* `persistToCache`.
|
|
23
|
+
*/
|
|
24
|
+
interface PersistOptions {
|
|
25
|
+
database?: JSONObject;
|
|
26
|
+
cache?: JSONObject;
|
|
27
|
+
}
|
|
2
28
|
/**
|
|
3
29
|
* @class UserRepository
|
|
4
30
|
* @extends ObjectRepository
|
|
5
31
|
*/
|
|
6
|
-
declare class UserRepository extends ObjectRepository<
|
|
32
|
+
declare class UserRepository extends ObjectRepository<User> {
|
|
33
|
+
protected module: SecurityModule;
|
|
34
|
+
/**
|
|
35
|
+
* Built by `init()` and read nowhere before it — the `null` the constructor
|
|
36
|
+
* used to write was never observed. See ADR-0001, TD-62.
|
|
37
|
+
*/
|
|
38
|
+
anonymousUser: User;
|
|
7
39
|
/**
|
|
8
40
|
* @param {SecurityModule} securityModule
|
|
9
41
|
* @constructor
|
|
10
42
|
*/
|
|
11
43
|
constructor(securityModule: SecurityModule);
|
|
12
|
-
module: SecurityModule;
|
|
13
|
-
ObjectConstructor: typeof User;
|
|
14
|
-
anonymousUser: User;
|
|
15
44
|
init(): Promise<void>;
|
|
16
45
|
/**
|
|
17
46
|
* Creates a user
|
|
@@ -20,7 +49,7 @@ declare class UserRepository extends ObjectRepository<any> {
|
|
|
20
49
|
* @param {Object} content
|
|
21
50
|
* @param {Object} [opts]
|
|
22
51
|
*/
|
|
23
|
-
create(id: string, profileIds:
|
|
52
|
+
create(id: string, profileIds: string[], content: JSONObject, { userId, refresh }?: WriteOptions): Promise<User>;
|
|
24
53
|
/**
|
|
25
54
|
* Updates a user's content
|
|
26
55
|
* @param {String} id
|
|
@@ -29,7 +58,7 @@ declare class UserRepository extends ObjectRepository<any> {
|
|
|
29
58
|
* @param {Object} [opts]
|
|
30
59
|
* @returns {Promise}
|
|
31
60
|
*/
|
|
32
|
-
update(id: string, profileIds:
|
|
61
|
+
update(id: string, profileIds: string[], content: JSONObject, { refresh, retryOnConflict, userId }?: WriteOptions): Promise<User>;
|
|
33
62
|
/**
|
|
34
63
|
* Replaces a user's content
|
|
35
64
|
* @param {String} id
|
|
@@ -37,10 +66,7 @@ declare class UserRepository extends ObjectRepository<any> {
|
|
|
37
66
|
* @param {Object} [opts]
|
|
38
67
|
* @returns {Promise}
|
|
39
68
|
*/
|
|
40
|
-
replace(id: string, profileIds:
|
|
41
|
-
refresh?: string;
|
|
42
|
-
userId: any;
|
|
43
|
-
}): Promise<any>;
|
|
69
|
+
replace(id: string, profileIds: string[], content: JSONObject, { refresh, userId }?: WriteOptions): Promise<User>;
|
|
44
70
|
/**
|
|
45
71
|
* Loads a user
|
|
46
72
|
*
|
|
@@ -49,12 +75,12 @@ declare class UserRepository extends ObjectRepository<any> {
|
|
|
49
75
|
* @throws {NotFoundError} If the user is not found
|
|
50
76
|
*/
|
|
51
77
|
load(id: string): Promise<User>;
|
|
52
|
-
persist(user:
|
|
78
|
+
persist(user: User, options?: PersistOptions): Promise<User>;
|
|
53
79
|
/**
|
|
54
80
|
* @param dto
|
|
55
81
|
* @returns {Promise<User>}
|
|
56
82
|
*/
|
|
57
|
-
fromDTO(dto:
|
|
83
|
+
fromDTO(dto: JSONObject): Promise<User>;
|
|
58
84
|
/**
|
|
59
85
|
* Deletes a user from memory and database, along with its related tokens and
|
|
60
86
|
* strategies.
|
|
@@ -63,19 +89,16 @@ declare class UserRepository extends ObjectRepository<any> {
|
|
|
63
89
|
* @param {Object} [options]
|
|
64
90
|
* @returns {Promise}
|
|
65
91
|
*/
|
|
66
|
-
deleteById(id: string, opts
|
|
92
|
+
deleteById(id: string, opts?: JSONObject): Promise<void>;
|
|
67
93
|
/**
|
|
68
94
|
* @override
|
|
69
95
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}): Promise<void>;
|
|
73
|
-
_removeUserStrategies(user: any): Promise<void>;
|
|
96
|
+
delete(user: User, { refresh }?: WriteOptions): Promise<void>;
|
|
97
|
+
_removeUserStrategies(user: User): Promise<void>;
|
|
74
98
|
/**
|
|
75
99
|
* @override
|
|
76
100
|
*/
|
|
77
|
-
|
|
101
|
+
loadOneFromDatabase(id: string): Promise<User>;
|
|
78
102
|
adminExists(): Promise<boolean>;
|
|
79
103
|
}
|
|
80
|
-
|
|
81
|
-
import { User } from "../../model/security/user";
|
|
104
|
+
export = UserRepository;
|
|
@@ -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,18 +19,45 @@
|
|
|
18
19
|
* See the License for the specific language governing permissions and
|
|
19
20
|
* limitations under the License.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
48
|
+
const request_1 = require("../../api/request");
|
|
49
|
+
const debug_1 = __importDefault(require("../../util/debug"));
|
|
50
|
+
const debug = (0, debug_1.default)("kuzzle:core:security:users");
|
|
51
|
+
const ObjectRepository_1 = require("../shared/ObjectRepository");
|
|
52
|
+
const kerror = __importStar(require("../../kerror"));
|
|
53
|
+
const user_1 = require("../../model/security/user");
|
|
54
|
+
const apiKey_1 = __importDefault(require("../../model/storage/apiKey"));
|
|
55
|
+
require("../../types/Global");
|
|
28
56
|
/**
|
|
29
57
|
* @class UserRepository
|
|
30
58
|
* @extends ObjectRepository
|
|
31
59
|
*/
|
|
32
|
-
class UserRepository extends ObjectRepository {
|
|
60
|
+
class UserRepository extends ObjectRepository_1.ObjectRepository {
|
|
33
61
|
/**
|
|
34
62
|
* @param {SecurityModule} securityModule
|
|
35
63
|
* @constructor
|
|
@@ -38,8 +66,7 @@ class UserRepository extends ObjectRepository {
|
|
|
38
66
|
super({ store: global.kuzzle.internalIndex });
|
|
39
67
|
this.module = securityModule;
|
|
40
68
|
this.collection = "users";
|
|
41
|
-
this.ObjectConstructor = User;
|
|
42
|
-
this.anonymousUser = null;
|
|
69
|
+
this.ObjectConstructor = user_1.User;
|
|
43
70
|
}
|
|
44
71
|
async init() {
|
|
45
72
|
this.anonymousUser = await this.fromDTO({
|
|
@@ -153,7 +180,9 @@ class UserRepository extends ObjectRepository {
|
|
|
153
180
|
});
|
|
154
181
|
}
|
|
155
182
|
catch (error) {
|
|
156
|
-
if (error
|
|
183
|
+
if (error instanceof Error &&
|
|
184
|
+
"id" in error &&
|
|
185
|
+
error.id === "services.storage.document_already_exists") {
|
|
157
186
|
throw kerror.get("security", "user", "already_exists", id);
|
|
158
187
|
}
|
|
159
188
|
throw error;
|
|
@@ -231,13 +260,20 @@ class UserRepository extends ObjectRepository {
|
|
|
231
260
|
if (id === "anonymous" || id === "-1") {
|
|
232
261
|
return this.anonymousUser;
|
|
233
262
|
}
|
|
234
|
-
|
|
263
|
+
const user = await super.load(id);
|
|
264
|
+
// The base resolves `null` for a user it could not build; `fromDTO` and
|
|
265
|
+
// `loadOneFromDatabase` both already turn that into a not_found, so this
|
|
266
|
+
// is the same answer stated where the return type can see it.
|
|
267
|
+
if (user === null) {
|
|
268
|
+
throw kerror.get("security", "user", "not_found", id);
|
|
269
|
+
}
|
|
270
|
+
return user;
|
|
235
271
|
}
|
|
236
272
|
async persist(user, options = {}) {
|
|
237
273
|
const databaseOptions = options.database || {};
|
|
238
274
|
const cacheOptions = options.cache || {};
|
|
239
275
|
if (user._id === this.anonymousUser._id &&
|
|
240
|
-
user.profileIds.
|
|
276
|
+
!user.profileIds.includes("anonymous")) {
|
|
241
277
|
throw kerror.get("security", "user", "anonymous_profile_required");
|
|
242
278
|
}
|
|
243
279
|
await this.persistToDatabase(user, databaseOptions);
|
|
@@ -263,7 +299,7 @@ class UserRepository extends ObjectRepository {
|
|
|
263
299
|
}
|
|
264
300
|
const profiles = await this.module.profile.loadProfiles(user.profileIds);
|
|
265
301
|
// Fail if not all profiles are found
|
|
266
|
-
if (profiles.some((
|
|
302
|
+
if (profiles.some((profile) => !profile)) {
|
|
267
303
|
throw kerror.get("security", "user", "cannot_hydrate", dto._id);
|
|
268
304
|
}
|
|
269
305
|
return user;
|
|
@@ -286,14 +322,14 @@ class UserRepository extends ObjectRepository {
|
|
|
286
322
|
async delete(user, { refresh = "false" } = {}) {
|
|
287
323
|
debug("Delete user: %s", user);
|
|
288
324
|
await this._removeUserStrategies(user);
|
|
289
|
-
await
|
|
290
|
-
await this.module.token.deleteByKuid(user
|
|
325
|
+
await apiKey_1.default.deleteByUser(user, { refresh });
|
|
326
|
+
await this.module.token.deleteByKuid(this.idOf(user));
|
|
291
327
|
await super.delete(user, { refresh });
|
|
292
328
|
}
|
|
293
329
|
async _removeUserStrategies(user) {
|
|
294
330
|
const availableStrategies = global.kuzzle.pluginsManager.listStrategies();
|
|
295
331
|
const userStrategies = [];
|
|
296
|
-
const request = new Request({ _id: user._id });
|
|
332
|
+
const request = new request_1.Request({ _id: user._id });
|
|
297
333
|
for (const strategy of availableStrategies) {
|
|
298
334
|
const existStrategy = global.kuzzle.pluginsManager.getStrategyMethod(strategy, "exists");
|
|
299
335
|
if (await existStrategy(request, user._id, strategy)) {
|
|
@@ -324,10 +360,14 @@ class UserRepository extends ObjectRepository {
|
|
|
324
360
|
*/
|
|
325
361
|
async loadOneFromDatabase(id) {
|
|
326
362
|
try {
|
|
327
|
-
|
|
363
|
+
const user = await super.loadOneFromDatabase(id);
|
|
364
|
+
if (user === null) {
|
|
365
|
+
throw kerror.get("security", "user", "not_found", id);
|
|
366
|
+
}
|
|
367
|
+
return user;
|
|
328
368
|
}
|
|
329
369
|
catch (err) {
|
|
330
|
-
if (err.status === 404) {
|
|
370
|
+
if (err instanceof Error && "status" in err && err.status === 404) {
|
|
331
371
|
throw kerror.get("security", "user", "not_found", id);
|
|
332
372
|
}
|
|
333
373
|
throw err;
|