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,181 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { Store } from "../core/shared/store";
|
|
2
2
|
declare class InternalIndexHandler extends Store {
|
|
3
|
+
private readonly timeout;
|
|
4
|
+
/** Indexed access rather than a new name, so it cannot drift from the config. */
|
|
5
|
+
private readonly config;
|
|
6
|
+
/** IDs for config documents */
|
|
7
|
+
private readonly _BOOTSTRAP_DONE_ID;
|
|
8
|
+
private readonly _DATAMODEL_VERSION_ID;
|
|
9
|
+
private readonly _JWT_SECRET_ID;
|
|
3
10
|
constructor();
|
|
4
|
-
|
|
5
|
-
config: {
|
|
6
|
-
name: string;
|
|
7
|
-
collections: {
|
|
8
|
-
users: {
|
|
9
|
-
settings: {
|
|
10
|
-
number_of_shards: number;
|
|
11
|
-
number_of_replicas: number;
|
|
12
|
-
};
|
|
13
|
-
mappings: {
|
|
14
|
-
dynamic: "false" | "true" | "strict";
|
|
15
|
-
properties: {
|
|
16
|
-
profileIds: {
|
|
17
|
-
type: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
profiles: {
|
|
23
|
-
settings: {
|
|
24
|
-
number_of_shards: number;
|
|
25
|
-
number_of_replicas: number;
|
|
26
|
-
};
|
|
27
|
-
mappings: {
|
|
28
|
-
dynamic: "false";
|
|
29
|
-
properties: {
|
|
30
|
-
tags: {
|
|
31
|
-
type: "keyword";
|
|
32
|
-
};
|
|
33
|
-
policies: {
|
|
34
|
-
properties: {
|
|
35
|
-
roleId: {
|
|
36
|
-
type: "keyword";
|
|
37
|
-
};
|
|
38
|
-
restrictedTo: {
|
|
39
|
-
type: "nested";
|
|
40
|
-
properties: {
|
|
41
|
-
index: {
|
|
42
|
-
type: "keyword";
|
|
43
|
-
};
|
|
44
|
-
collections: {
|
|
45
|
-
type: "keyword";
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
roles: {
|
|
55
|
-
settings: {
|
|
56
|
-
number_of_shards: number;
|
|
57
|
-
number_of_replicas: number;
|
|
58
|
-
};
|
|
59
|
-
mappings: {
|
|
60
|
-
dynamic: "false";
|
|
61
|
-
properties: {
|
|
62
|
-
tags: {
|
|
63
|
-
type: "keyword";
|
|
64
|
-
};
|
|
65
|
-
controllers: {
|
|
66
|
-
dynamic: "false";
|
|
67
|
-
properties: Record<string, unknown>;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
validations: {
|
|
73
|
-
settings: {
|
|
74
|
-
number_of_shards: number;
|
|
75
|
-
number_of_replicas: number;
|
|
76
|
-
};
|
|
77
|
-
mappings: {
|
|
78
|
-
properties: {
|
|
79
|
-
index: {
|
|
80
|
-
type: "keyword";
|
|
81
|
-
};
|
|
82
|
-
collection: {
|
|
83
|
-
type: "keyword";
|
|
84
|
-
};
|
|
85
|
-
validations: {
|
|
86
|
-
dynamic: "false";
|
|
87
|
-
properties: Record<string, unknown>;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
config: {
|
|
93
|
-
settings: {
|
|
94
|
-
number_of_shards: number;
|
|
95
|
-
number_of_replicas: number;
|
|
96
|
-
};
|
|
97
|
-
mappings: {
|
|
98
|
-
dynamic: "false";
|
|
99
|
-
properties: Record<string, unknown>;
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
"api-keys": {
|
|
103
|
-
settings: {
|
|
104
|
-
number_of_shards: number;
|
|
105
|
-
number_of_replicas: number;
|
|
106
|
-
};
|
|
107
|
-
mappings: {
|
|
108
|
-
dynamic: "false";
|
|
109
|
-
properties: {
|
|
110
|
-
userId: {
|
|
111
|
-
type: "keyword";
|
|
112
|
-
};
|
|
113
|
-
hash: {
|
|
114
|
-
type: "keyword";
|
|
115
|
-
};
|
|
116
|
-
description: {
|
|
117
|
-
type: "text";
|
|
118
|
-
};
|
|
119
|
-
expiresAt: {
|
|
120
|
-
type: "long";
|
|
121
|
-
};
|
|
122
|
-
ttl: {
|
|
123
|
-
type: "keyword";
|
|
124
|
-
};
|
|
125
|
-
token: {
|
|
126
|
-
type: "keyword";
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
installations: {
|
|
132
|
-
settings: {
|
|
133
|
-
number_of_shards: number;
|
|
134
|
-
number_of_replicas: number;
|
|
135
|
-
};
|
|
136
|
-
mappings: {
|
|
137
|
-
dynamic: "strict";
|
|
138
|
-
properties: {
|
|
139
|
-
description: {
|
|
140
|
-
type: "text";
|
|
141
|
-
};
|
|
142
|
-
handler: {
|
|
143
|
-
type: "text";
|
|
144
|
-
};
|
|
145
|
-
installedAt: {
|
|
146
|
-
type: "date";
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
};
|
|
151
|
-
imports: {
|
|
152
|
-
settings: {
|
|
153
|
-
number_of_shards: number;
|
|
154
|
-
number_of_replicas: number;
|
|
155
|
-
};
|
|
156
|
-
mappings: {
|
|
157
|
-
dynamic: "strict";
|
|
158
|
-
properties: {
|
|
159
|
-
hash: {
|
|
160
|
-
type: "keyword";
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
_BOOTSTRAP_DONE_ID: string;
|
|
168
|
-
_DATAMODEL_VERSION_ID: string;
|
|
169
|
-
_JWT_SECRET_ID: string;
|
|
170
|
-
logger: import("./Logger").Logger;
|
|
171
|
-
/**
|
|
172
|
-
* @returns {Promise}
|
|
173
|
-
*/
|
|
174
|
-
init(): Promise<any>;
|
|
11
|
+
init(): Promise<void>;
|
|
175
12
|
/**
|
|
176
13
|
* @override
|
|
177
14
|
*/
|
|
178
|
-
|
|
15
|
+
_bootstrapSequence(): Promise<void>;
|
|
179
16
|
/**
|
|
180
17
|
* Creates initial roles and profiles as specified in Kuzzle configuration
|
|
181
18
|
*/
|
|
@@ -183,4 +20,4 @@ declare class InternalIndexHandler extends Store {
|
|
|
183
20
|
createInitialValidations(): Promise<void>;
|
|
184
21
|
_initSecret(): Promise<void>;
|
|
185
22
|
}
|
|
186
|
-
|
|
23
|
+
export = InternalIndexHandler;
|
|
@@ -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,41 @@
|
|
|
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
|
-
|
|
28
|
-
|
|
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 node_crypto_1 = __importDefault(require("node:crypto"));
|
|
49
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
|
50
|
+
const store_1 = require("../core/shared/store");
|
|
51
|
+
const storeScopeEnum_1 = require("../core/storage/storeScopeEnum");
|
|
52
|
+
const specification_1 = require("../core/validation/specification");
|
|
53
|
+
const kerror = __importStar(require("../kerror"));
|
|
54
|
+
const debug_1 = __importDefault(require("../util/debug"));
|
|
55
|
+
const mutex_1 = require("../util/mutex"); // NOSONAR: see init()
|
|
56
|
+
const debug = (0, debug_1.default)("kuzzle:bootstrap:internalIndex");
|
|
29
57
|
const securitiesBootstrap = {
|
|
30
58
|
profiles: {
|
|
31
59
|
admin: {
|
|
@@ -70,9 +98,9 @@ const securitiesBootstrap = {
|
|
|
70
98
|
},
|
|
71
99
|
};
|
|
72
100
|
const dataModelVersion = "2.0.0";
|
|
73
|
-
class InternalIndexHandler extends Store {
|
|
101
|
+
class InternalIndexHandler extends store_1.Store {
|
|
74
102
|
constructor() {
|
|
75
|
-
super(global.kuzzle.config.services.storageEngine.internalIndex.name, storeScopeEnum.PRIVATE);
|
|
103
|
+
super(global.kuzzle.config.services.storageEngine.internalIndex.name, storeScopeEnum_1.storeScopeEnum.PRIVATE);
|
|
76
104
|
this.timeout =
|
|
77
105
|
global.kuzzle.config.services.internalIndex.bootstrapLockTimeout;
|
|
78
106
|
this.config = global.kuzzle.config.services.storageEngine.internalIndex;
|
|
@@ -82,15 +110,13 @@ class InternalIndexHandler extends Store {
|
|
|
82
110
|
this._JWT_SECRET_ID = "security.jwt.secret";
|
|
83
111
|
this.logger = global.kuzzle.log.child("internalIndexHandler");
|
|
84
112
|
}
|
|
85
|
-
/**
|
|
86
|
-
* @returns {Promise}
|
|
87
|
-
*/
|
|
88
113
|
async init() {
|
|
89
114
|
await super.init(this.config.collections);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
115
|
+
// NOSONAR: `Mutex` is deprecated in favour of `withLock`, but the two use
|
|
116
|
+
// incompatible acquisition/TTL formats and must not contend on the same
|
|
117
|
+
// key — swapping it is a behaviour change, deferred to #2894.
|
|
118
|
+
const lockOptions = { timeout: -1, ttl: 30000 };
|
|
119
|
+
const mutex = new mutex_1.Mutex("InternalIndexBootstrap", lockOptions); // NOSONAR
|
|
94
120
|
await mutex.lock();
|
|
95
121
|
try {
|
|
96
122
|
const bootstrapped = await this.exists("config", this._BOOTSTRAP_DONE_ID);
|
|
@@ -98,13 +124,13 @@ class InternalIndexHandler extends Store {
|
|
|
98
124
|
await this._initSecret();
|
|
99
125
|
return;
|
|
100
126
|
}
|
|
101
|
-
await
|
|
127
|
+
await bluebird_1.default.resolve(this._bootstrapSequence()).timeout(this.timeout);
|
|
102
128
|
await this.create("config", { timestamp: Date.now() }, {
|
|
103
129
|
id: this._BOOTSTRAP_DONE_ID,
|
|
104
130
|
});
|
|
105
131
|
}
|
|
106
132
|
catch (error) {
|
|
107
|
-
if (error instanceof
|
|
133
|
+
if (error instanceof bluebird_1.default.TimeoutError) {
|
|
108
134
|
throw kerror.get("services", "storage", "bootstrap_timeout", "internalIndex");
|
|
109
135
|
}
|
|
110
136
|
throw error;
|
|
@@ -132,19 +158,19 @@ class InternalIndexHandler extends Store {
|
|
|
132
158
|
* Creates initial roles and profiles as specified in Kuzzle configuration
|
|
133
159
|
*/
|
|
134
160
|
async createInitialSecurities() {
|
|
135
|
-
await
|
|
161
|
+
await bluebird_1.default.map(Object.entries(securitiesBootstrap.roles), ([roleId, content]) => {
|
|
136
162
|
return this.createOrReplace("roles", roleId, content, {
|
|
137
163
|
refresh: "wait_for",
|
|
138
164
|
});
|
|
139
165
|
});
|
|
140
|
-
await
|
|
166
|
+
await bluebird_1.default.map(Object.entries(securitiesBootstrap.profiles), ([profileId, content]) => {
|
|
141
167
|
return this.createOrReplace("profiles", profileId, content, {
|
|
142
168
|
refresh: "wait_for",
|
|
143
169
|
});
|
|
144
170
|
});
|
|
145
171
|
}
|
|
146
172
|
async createInitialValidations() {
|
|
147
|
-
const initialValidations =
|
|
173
|
+
const initialValidations = (0, specification_1.configuredSpecifications)();
|
|
148
174
|
const promises = [];
|
|
149
175
|
for (const [index, collection] of Object.entries(initialValidations)) {
|
|
150
176
|
for (const [collectionName, validation] of Object.entries(collection)) {
|
|
@@ -152,22 +178,25 @@ class InternalIndexHandler extends Store {
|
|
|
152
178
|
promises.push(this.createOrReplace("validations", validationId, validation));
|
|
153
179
|
}
|
|
154
180
|
}
|
|
155
|
-
await
|
|
181
|
+
await bluebird_1.default.all(promises);
|
|
156
182
|
}
|
|
157
183
|
async _initSecret() {
|
|
158
|
-
|
|
159
|
-
|
|
184
|
+
// NOSONAR: `jwt` is the deprecated spelling of `authToken`, read second so
|
|
185
|
+
// an existing configuration keeps working. Dropping it is a breaking change
|
|
186
|
+
// for anyone who has not migrated, not a conversion's to make.
|
|
187
|
+
const { authToken, jwt } = global.kuzzle.config.security; // NOSONAR
|
|
188
|
+
const configSeed = authToken?.secret ?? jwt?.secret; // NOSONAR
|
|
160
189
|
let storedSeed = await this.exists("config", this._JWT_SECRET_ID);
|
|
161
190
|
if (!configSeed) {
|
|
162
191
|
if (!storedSeed) {
|
|
163
|
-
storedSeed =
|
|
192
|
+
storedSeed = node_crypto_1.default.randomBytes(512).toString("hex");
|
|
164
193
|
await this.create("config", { seed: storedSeed }, { id: this._JWT_SECRET_ID });
|
|
165
194
|
}
|
|
166
195
|
this.logger.warn("[!] Kuzzle is using a generated seed for authentication. This is suitable for development but should NEVER be used in production. See https://docs.kuzzle.io/core/2/guides/getting-started/deploy-your-application/");
|
|
167
196
|
}
|
|
168
|
-
global.kuzzle.secret =
|
|
169
|
-
|
|
170
|
-
|
|
197
|
+
global.kuzzle.secret =
|
|
198
|
+
configSeed ||
|
|
199
|
+
(await this.get("config", this._JWT_SECRET_ID))._source.seed;
|
|
171
200
|
}
|
|
172
201
|
}
|
|
173
202
|
module.exports = InternalIndexHandler;
|
|
@@ -5,19 +5,21 @@ import { TokenManager } from "../core/auth/tokenManager";
|
|
|
5
5
|
import EntryPoint from "../core/network/entryPoint";
|
|
6
6
|
import Router from "../core/network/router";
|
|
7
7
|
import PluginsManager from "../core/plugin/pluginsManager";
|
|
8
|
+
import Statistics from "../core/statistics/statistics";
|
|
8
9
|
import Validation from "../core/validation/validation";
|
|
9
|
-
import {
|
|
10
|
+
import type { IKuzzleConfiguration } from "../types/config/KuzzleConfiguration";
|
|
10
11
|
import AsyncStore from "../util/asyncStore";
|
|
11
|
-
import { ImportConfig, InstallationConfig, StartOptions, SupportConfig } from "./../types/Kuzzle";
|
|
12
|
+
import type { ImportConfig, InstallationConfig, StartOptions, SupportConfig } from "./../types/Kuzzle";
|
|
12
13
|
import KuzzleEventEmitter from "./event/KuzzleEventEmitter";
|
|
13
14
|
import InternalIndexHandler from "./internalIndexHandler";
|
|
14
15
|
import kuzzleStateEnum from "./kuzzleStateEnum";
|
|
15
16
|
import { Logger } from "./Logger";
|
|
16
17
|
declare class Kuzzle extends KuzzleEventEmitter {
|
|
17
|
-
config:
|
|
18
|
+
config: IKuzzleConfiguration;
|
|
18
19
|
private _state;
|
|
19
20
|
log: Logger;
|
|
20
|
-
|
|
21
|
+
/** Read by `PluginsManager` to locate the plugins directories. */
|
|
22
|
+
rootPath: string;
|
|
21
23
|
/**
|
|
22
24
|
* Internal index bootstrapper and accessor
|
|
23
25
|
*/
|
|
@@ -36,7 +38,7 @@ declare class Kuzzle extends KuzzleEventEmitter {
|
|
|
36
38
|
/**
|
|
37
39
|
* Statistics core component
|
|
38
40
|
*/
|
|
39
|
-
|
|
41
|
+
statistics: Statistics;
|
|
40
42
|
/**
|
|
41
43
|
* Network entry point
|
|
42
44
|
*/
|
|
@@ -65,18 +67,27 @@ declare class Kuzzle extends KuzzleEventEmitter {
|
|
|
65
67
|
* Kuzzle version
|
|
66
68
|
*/
|
|
67
69
|
private version;
|
|
70
|
+
/**
|
|
71
|
+
* Built by `start()`, from the application's own OpenAPI declaration.
|
|
72
|
+
* Nothing reads it before then — `server:openapi` answers off it, and the
|
|
73
|
+
* API is not serving yet.
|
|
74
|
+
*/
|
|
68
75
|
private openApiManager;
|
|
69
76
|
/**
|
|
70
77
|
* List of differents imports types and their associated method
|
|
71
78
|
*/
|
|
72
79
|
private importTypes;
|
|
80
|
+
/**
|
|
81
|
+
* The realtime engine, and the secret read out of the internal index.
|
|
82
|
+
* Both are set by `start()`, before anything that uses them is wired up.
|
|
83
|
+
*/
|
|
73
84
|
koncorde: Koncorde;
|
|
74
85
|
secret: string;
|
|
75
86
|
/**
|
|
76
87
|
* Node unique ID amongst other cluster nodes
|
|
77
88
|
*/
|
|
78
89
|
id: string;
|
|
79
|
-
constructor(config:
|
|
90
|
+
constructor(config: IKuzzleConfiguration);
|
|
80
91
|
/**
|
|
81
92
|
* Initializes all the needed components of Kuzzle.
|
|
82
93
|
*
|
|
@@ -95,9 +106,13 @@ declare class Kuzzle extends KuzzleEventEmitter {
|
|
|
95
106
|
/**
|
|
96
107
|
* Gracefully exits after processing remaining requests
|
|
97
108
|
*
|
|
109
|
+
* @param exitCode - the process exit code: 0 for a requested shutdown, and
|
|
110
|
+
* non-zero when the node leaves because of a failure (e.g. a cluster
|
|
111
|
+
* eviction), so that an `on-failure` restart policy brings it back
|
|
112
|
+
*
|
|
98
113
|
* @returns {Promise}
|
|
99
114
|
*/
|
|
100
|
-
shutdown(): Promise<void>;
|
|
115
|
+
shutdown(exitCode?: number): Promise<void>;
|
|
101
116
|
/**
|
|
102
117
|
* Execute multiple handlers only once on any given environment
|
|
103
118
|
*
|
|
@@ -105,7 +120,7 @@ declare class Kuzzle extends KuzzleEventEmitter {
|
|
|
105
120
|
*
|
|
106
121
|
* @returns {Promise<void>}
|
|
107
122
|
*/
|
|
108
|
-
install(installations
|
|
123
|
+
install(installations?: InstallationConfig[]): Promise<void>;
|
|
109
124
|
ask(event: string, ...args: [payload?: any, ...rest: any]): Promise<any>;
|
|
110
125
|
emit(event: string, ...args: any[]): boolean;
|
|
111
126
|
pipe(event: string, ...args: any[]): Promise<any>;
|
|
@@ -128,7 +143,7 @@ declare class Kuzzle extends KuzzleEventEmitter {
|
|
|
128
143
|
* @returns {Promise<void>}
|
|
129
144
|
*/
|
|
130
145
|
loadInitialState(toImport?: ImportConfig, toSupport?: SupportConfig): Promise<void>;
|
|
131
|
-
dump(suffix:
|
|
146
|
+
dump(suffix: string): Promise<string>;
|
|
132
147
|
hash(input: any): number;
|
|
133
148
|
get state(): kuzzleStateEnum;
|
|
134
149
|
set state(value: kuzzleStateEnum);
|
|
@@ -139,7 +154,7 @@ declare class Kuzzle extends KuzzleEventEmitter {
|
|
|
139
154
|
* - uncaught-exception
|
|
140
155
|
*/
|
|
141
156
|
registerSignalHandlers(): void;
|
|
142
|
-
dumpAndExit(suffix:
|
|
157
|
+
dumpAndExit(suffix: string): Promise<void>;
|
|
143
158
|
}
|
|
144
159
|
export { Kuzzle };
|
|
145
160
|
export default Kuzzle;
|
|
@@ -48,6 +48,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
49
|
exports.Kuzzle = void 0;
|
|
50
50
|
const path_1 = __importDefault(require("path"));
|
|
51
|
+
const node_util_1 = require("node:util");
|
|
51
52
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
52
53
|
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
53
54
|
const koncorde_1 = require("koncorde");
|
|
@@ -79,6 +80,7 @@ const internalIndexHandler_1 = __importDefault(require("./internalIndexHandler")
|
|
|
79
80
|
const kuzzleStateEnum_1 = __importDefault(require("./kuzzleStateEnum"));
|
|
80
81
|
const Logger_1 = require("./Logger");
|
|
81
82
|
const vault_1 = __importDefault(require("./vault"));
|
|
83
|
+
const name_generator_1 = require("../util/name-generator");
|
|
82
84
|
let _kuzzle = null;
|
|
83
85
|
Reflect.defineProperty(global, "kuzzle", {
|
|
84
86
|
configurable: true,
|
|
@@ -119,6 +121,16 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
119
121
|
this.asyncStore = new asyncStore_1.default();
|
|
120
122
|
this.debugger = new kuzzleDebugger_1.KuzzleDebugger();
|
|
121
123
|
this.version = package_json_1.version;
|
|
124
|
+
// `global.nodeId` when a `Backend` named this process, and a name of the
|
|
125
|
+
// same shape otherwise — the draw `ClusterIdCardHandler` makes for the
|
|
126
|
+
// same reason. This field was declared `string` and assigned nowhere, so
|
|
127
|
+
// every reader of `kuzzle.id` — the redis `SETNAME`, the ID card, the
|
|
128
|
+
// `node` field of every realtime notification — has been reading
|
|
129
|
+
// `undefined`. `accessLogger` sends `global.nodeId` to its worker and
|
|
130
|
+
// reads it back as `kuzzle.id`, which is what says the two are the same
|
|
131
|
+
// value.
|
|
132
|
+
this.id =
|
|
133
|
+
global.nodeId ?? name_generator_1.NameGenerator.generateRandomName({ prefix: "knode" });
|
|
122
134
|
this.importTypes = {
|
|
123
135
|
fixtures: this.importFixtures.bind(this),
|
|
124
136
|
mappings: this.importMappings.bind(this),
|
|
@@ -152,7 +164,7 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
152
164
|
await new security_1.default().init();
|
|
153
165
|
// This will init the cluster module if enabled
|
|
154
166
|
await this.initKuzzleNode();
|
|
155
|
-
this.vault = vault_1.default.load(options.vaultKey, options.secretsFile);
|
|
167
|
+
this.vault = vault_1.default.load(options.vaultKey, options.secretsFile, this.config.vault?.newAlgorithm);
|
|
156
168
|
this.validation.init();
|
|
157
169
|
await this.tokenManager.init();
|
|
158
170
|
await this.funnel.init();
|
|
@@ -172,7 +184,10 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
172
184
|
this.router.init();
|
|
173
185
|
this.log.info("[✔] Core components loaded");
|
|
174
186
|
await this.install(options.installations);
|
|
175
|
-
|
|
187
|
+
// `application` is the very wrapper handed to the plugins manager six
|
|
188
|
+
// lines up, so reading the name back off the manager was a round trip
|
|
189
|
+
// through a getter that can answer `undefined`.
|
|
190
|
+
this.log.info(`[✔] Start "${application.name}" application`);
|
|
176
191
|
this.openApiManager = new openapi_1.OpenApiManager(application.openApi, this.config.http.routes, this.pluginsManager.routes);
|
|
177
192
|
// @deprecated
|
|
178
193
|
await this.pipe("kuzzle:start");
|
|
@@ -185,7 +200,7 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
185
200
|
this._state = kuzzleStateEnum_1.default.RUNNING;
|
|
186
201
|
}
|
|
187
202
|
catch (error) {
|
|
188
|
-
this.log.error(`[X] Cannot start Kuzzle ${this.version}: ${error.message}`);
|
|
203
|
+
this.log.error(`[X] Cannot start Kuzzle ${this.version}: ${error instanceof Error ? error.message : (0, node_util_1.inspect)(error)}`);
|
|
189
204
|
throw error;
|
|
190
205
|
}
|
|
191
206
|
}
|
|
@@ -206,13 +221,17 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
206
221
|
/**
|
|
207
222
|
* Gracefully exits after processing remaining requests
|
|
208
223
|
*
|
|
224
|
+
* @param exitCode - the process exit code: 0 for a requested shutdown, and
|
|
225
|
+
* non-zero when the node leaves because of a failure (e.g. a cluster
|
|
226
|
+
* eviction), so that an `on-failure` restart policy brings it back
|
|
227
|
+
*
|
|
209
228
|
* @returns {Promise}
|
|
210
229
|
*/
|
|
211
|
-
async shutdown() {
|
|
230
|
+
async shutdown(exitCode = 0) {
|
|
212
231
|
this._state = kuzzleStateEnum_1.default.SHUTTING_DOWN;
|
|
213
232
|
this.log.info("Initiating shutdown...");
|
|
214
233
|
// Ask the network layer to stop accepting new request
|
|
215
|
-
this.entryPoint.dispatch("shutdown");
|
|
234
|
+
this.entryPoint.dispatch("shutdown", {});
|
|
216
235
|
await this.pipe("kuzzle:shutdown");
|
|
217
236
|
// @deprecated
|
|
218
237
|
this.emit("core:shutdown");
|
|
@@ -220,11 +239,19 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
220
239
|
this.log.info(`[shutdown] Waiting: ${this.funnel.remainingRequests} remaining requests`);
|
|
221
240
|
await bluebird_1.default.delay(1000);
|
|
222
241
|
}
|
|
242
|
+
// The other nodes may be waiting on a lock this one holds: a node leaving
|
|
243
|
+
// mid-startup is often in the middle of one (F-13).
|
|
244
|
+
await mutex_1.Mutex.releaseAllBeforeExit(); // NOSONAR: frees locks taken through the deprecated API
|
|
223
245
|
this.log.info("Halted.");
|
|
224
246
|
// flush both application and Kuzzle core loggers before leaving (Could happen even if some core/application components are not initialized)
|
|
225
247
|
await this?.log?.flush?.();
|
|
226
|
-
|
|
227
|
-
|
|
248
|
+
// `log` lives on the application *instance* (`Backend`), while
|
|
249
|
+
// `pluginsManager.application` is the `Plugin` wrapper around it, which
|
|
250
|
+
// nothing ever assigns a `log` to — so the previous
|
|
251
|
+
// `pluginsManager?.application?.log?.flush?.()` was a silent no-op and the
|
|
252
|
+
// application's buffered logs were dropped on shutdown (TD-51).
|
|
253
|
+
await this?.pluginsManager?.application?.instance?.log?.flush?.();
|
|
254
|
+
process.exit(exitCode);
|
|
228
255
|
}
|
|
229
256
|
/**
|
|
230
257
|
* Execute multiple handlers only once on any given environment
|
|
@@ -234,6 +261,8 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
234
261
|
* @returns {Promise<void>}
|
|
235
262
|
*/
|
|
236
263
|
async install(installations) {
|
|
264
|
+
// Optional, which is what `options.installations` is and what the
|
|
265
|
+
// `?.length` below already read it as.
|
|
237
266
|
if (!installations?.length) {
|
|
238
267
|
return;
|
|
239
268
|
}
|
|
@@ -393,9 +422,13 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
393
422
|
if (!existingRedisHash && !existingESHash) {
|
|
394
423
|
// If the import is not initialized in the redis cache and in the ES, we initialize it
|
|
395
424
|
this.log.info(`${type} import is not initialized, initializing...`);
|
|
396
|
-
|
|
425
|
+
// `createOrReplace`, not `create`: this document has a fixed id, so a
|
|
426
|
+
// conflict on it means another node initialized the same import — an
|
|
427
|
+
// outcome to converge on, not an error to die on. `create` made that
|
|
428
|
+
// conflict fatal to startup (TD-69, #2782).
|
|
429
|
+
await this.ask("core:storage:private:document:createOrReplace", "kuzzle", "imports", `backend:init:import:${type}`, {
|
|
397
430
|
hash: importPayloadHash,
|
|
398
|
-
}
|
|
431
|
+
});
|
|
399
432
|
await this.ask("core:cache:internal:store", `backend:init:import:${type}`, importPayloadHash);
|
|
400
433
|
}
|
|
401
434
|
else if (existingRedisHash && !existingESHash) {
|
|
@@ -403,9 +436,10 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
403
436
|
// We initialize it in the ES
|
|
404
437
|
this.log.info(`${type} import is not initialized in %kuzzle.imports, initializing...`);
|
|
405
438
|
const redisCache = await this.ask("core:cache:internal:get", `backend:init:import:${type}`);
|
|
406
|
-
|
|
439
|
+
// Same reasoning as above: a fixed id, so a conflict is convergence.
|
|
440
|
+
await this.ask("core:storage:private:document:createOrReplace", "kuzzle", "imports", `backend:init:import:${type}`, {
|
|
407
441
|
hash: redisCache,
|
|
408
|
-
}
|
|
442
|
+
});
|
|
409
443
|
}
|
|
410
444
|
else if (!existingRedisHash && existingESHash) {
|
|
411
445
|
// If the import is initialized in the ES but not in the redis cache
|
|
@@ -446,8 +480,28 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
446
480
|
lodash_1.default.set(importPayload, "toImport.users", toImport.users);
|
|
447
481
|
break;
|
|
448
482
|
}
|
|
449
|
-
|
|
450
|
-
|
|
483
|
+
// `?? ""`: `json-stable-stringify` answers undefined for a value it
|
|
484
|
+
// cannot serialise, and the payload is built right above.
|
|
485
|
+
const importPayloadHash = (0, crypto_1.sha256)((0, json_stable_stringify_1.default)(importPayload) ?? "");
|
|
486
|
+
// `timeout: 0` means a single acquisition attempt: exactly one node
|
|
487
|
+
// runs the import and the others carry on with `locked: false`.
|
|
488
|
+
// The TTL has to outlive the import itself, because this lock is held
|
|
489
|
+
// until the `finally` below — across every import type and the wait
|
|
490
|
+
// that follows. It is still an upper bound rather than a guarantee,
|
|
491
|
+
// which is why the bookkeeping write below is idempotent (TD-69).
|
|
492
|
+
// NOSONAR: `Mutex` is deprecated in favour of `withLock`, but the two
|
|
493
|
+
// use incompatible acquisition/TTL formats and must not contend on the
|
|
494
|
+
// same key — every other node still takes this lock with `Mutex`, so
|
|
495
|
+
// swapping one site would remove the exclusion it exists for. Deferred
|
|
496
|
+
// to #2894, like the remaining call sites.
|
|
497
|
+
const lockOptions = { timeout: 0, ttl: 60000 };
|
|
498
|
+
const mutex = new mutex_1.Mutex(`backend:import:${type}`, lockOptions); // NOSONAR
|
|
499
|
+
const locked = await mutex.lock();
|
|
500
|
+
// Read the bookkeeping *after* the lock, never before: a read taken
|
|
501
|
+
// before acquiring it is not protected by it, and the holder that
|
|
502
|
+
// acted on a stale "not initialized" used to create a document the
|
|
503
|
+
// previous holder had just written — killing its own startup with
|
|
504
|
+
// `Document already exists`. See TD-69 (#2782).
|
|
451
505
|
const existingRedisHash = await this.ask("core:cache:internal:get", `backend:init:import:${type}`);
|
|
452
506
|
const existingESHash = await this.ask("core:storage:private:document:exist", "kuzzle", "imports", `backend:init:import:${type}`);
|
|
453
507
|
let initialized = false;
|
|
@@ -460,7 +514,6 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
460
514
|
const esDocument = await this.ask("core:storage:private:document:get", "kuzzle", "imports", `backend:init:import:${type}`);
|
|
461
515
|
initialized = esDocument._source.hash === importPayloadHash;
|
|
462
516
|
}
|
|
463
|
-
const locked = await mutex.lock();
|
|
464
517
|
await importMethod({ toImport, toSupport }, {
|
|
465
518
|
firstCall: !initialized && locked,
|
|
466
519
|
initialized: initialized,
|
|
@@ -497,7 +550,7 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
497
550
|
default:
|
|
498
551
|
inString = (0, json_stable_stringify_1.default)(input);
|
|
499
552
|
}
|
|
500
|
-
return murmurhash_1.default.v3(Buffer.from(inString), this.config.internal.hash.seed);
|
|
553
|
+
return murmurhash_1.default.v3(Buffer.from(String(inString)), this.config.internal.hash.seed);
|
|
501
554
|
}
|
|
502
555
|
get state() {
|
|
503
556
|
return this._state;
|
|
@@ -555,7 +608,11 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
555
608
|
process.removeAllListeners("SIGTRAP");
|
|
556
609
|
process.on("SIGTRAP", () => {
|
|
557
610
|
this.log.error("Caught signal SIGTRAP => generating a core dump");
|
|
558
|
-
this
|
|
611
|
+
// Nothing awaits this dump: a failure (another dump running, an
|
|
612
|
+
// unwritable dump path) is logged rather than left unhandled.
|
|
613
|
+
this.dump("signal-sigtrap").catch((error) => {
|
|
614
|
+
this.log.error(`Unable to dump on SIGTRAP: ${error instanceof Error ? error.message : String(error)}`);
|
|
615
|
+
});
|
|
559
616
|
});
|
|
560
617
|
// gracefully exits on normal termination
|
|
561
618
|
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
@@ -571,7 +628,7 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
|
|
|
571
628
|
try {
|
|
572
629
|
await this.dump(suffix);
|
|
573
630
|
}
|
|
574
|
-
catch
|
|
631
|
+
catch {
|
|
575
632
|
// this catch is just there to prevent unhandled rejections, there is
|
|
576
633
|
// nothing to do with that error
|
|
577
634
|
}
|