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,18 +1,59 @@
|
|
|
1
|
-
import { JSONObject } from "
|
|
1
|
+
import type { JSONObject } from "../../types/JSONObject";
|
|
2
2
|
import { cacheDbEnum } from "../cache/cacheDbEnum";
|
|
3
|
+
/**
|
|
4
|
+
* What `formatSearchResults` builds out of a raw store answer, and what
|
|
5
|
+
* `truncate`'s recursion reads back.
|
|
6
|
+
*/
|
|
7
|
+
export interface RepositorySearchResult<TObject> {
|
|
8
|
+
aggregations?: JSONObject;
|
|
9
|
+
hits: TObject[];
|
|
10
|
+
scrollId?: string;
|
|
11
|
+
total: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* What `search` and `scroll` are declared to answer: v2.56.0's shape, kept
|
|
15
|
+
* for compatibility — what they build is a {@link RepositorySearchResult},
|
|
16
|
+
* but typed members break code compiled against this one (reading
|
|
17
|
+
* `aggregations.x` under `strict`, assigning `hits` to its own type). Read
|
|
18
|
+
* the answer into a `RepositorySearchResult<T>` to get the types back.
|
|
19
|
+
*/
|
|
20
|
+
export type ObjectRepositorySearchAnswer = {
|
|
21
|
+
aggregations?: any;
|
|
22
|
+
hits: any[];
|
|
23
|
+
scrollId: any;
|
|
24
|
+
total: any;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* `_id` is nullable because the models are: `User`, `Profile` and `Token` are
|
|
28
|
+
* all constructed empty and get their id on the way out of the store
|
|
29
|
+
* (ADR-0001, TD-62). The repository only ever reads it off an object it
|
|
30
|
+
* loaded, which has one.
|
|
31
|
+
*/
|
|
3
32
|
export declare class ObjectRepository<TObject extends {
|
|
4
|
-
_id: string;
|
|
33
|
+
_id: string | null;
|
|
5
34
|
}> {
|
|
6
35
|
protected ttl: number;
|
|
7
36
|
protected index: string;
|
|
37
|
+
/**
|
|
38
|
+
* Set by every subclass's own constructor — the `= null` this used to carry
|
|
39
|
+
* was never read (ADR-0001, TD-62).
|
|
40
|
+
*/
|
|
8
41
|
protected collection: string;
|
|
9
42
|
protected ObjectConstructor: any;
|
|
10
43
|
protected store: any;
|
|
11
44
|
protected cacheDb: cacheDbEnum;
|
|
12
|
-
|
|
45
|
+
/**
|
|
46
|
+
* `store` is declared `unknown`, as v2.56.0's `any` accepted anything; only
|
|
47
|
+
* its `index` is read here.
|
|
48
|
+
*/
|
|
49
|
+
constructor(options?: {
|
|
13
50
|
cache?: cacheDbEnum;
|
|
14
|
-
store?:
|
|
51
|
+
store?: unknown;
|
|
15
52
|
});
|
|
53
|
+
/**
|
|
54
|
+
* Resolves `null` when the document does not carry an `_id` — declared
|
|
55
|
+
* `Promise<TObject>` all the same: see `load()`.
|
|
56
|
+
*/
|
|
16
57
|
loadOneFromDatabase(id: string): Promise<TObject>;
|
|
17
58
|
loadMultiFromDatabase(ids: string[]): Promise<TObject[]>;
|
|
18
59
|
/**
|
|
@@ -21,22 +62,16 @@ export declare class ObjectRepository<TObject extends {
|
|
|
21
62
|
* @param {object} searchBody
|
|
22
63
|
* @param {object} [options] - optional search arguments (from, size, scroll)
|
|
23
64
|
* @returns {Promise}
|
|
65
|
+
*
|
|
66
|
+
* The public signature is v2.56.0's — see {@link ObjectRepositorySearchAnswer}.
|
|
24
67
|
*/
|
|
25
|
-
search(searchBody:
|
|
26
|
-
aggregations: any;
|
|
27
|
-
hits: any[];
|
|
28
|
-
scrollId: any;
|
|
29
|
-
total: any;
|
|
30
|
-
}>;
|
|
68
|
+
search(searchBody: unknown, options?: unknown): Promise<ObjectRepositorySearchAnswer>;
|
|
31
69
|
/**
|
|
32
70
|
* Scroll over a paginated search request
|
|
71
|
+
*
|
|
72
|
+
* The public signature is v2.56.0's — see {@link ObjectRepositorySearchAnswer}.
|
|
33
73
|
*/
|
|
34
|
-
scroll(scrollId: string, ttl?: string | number): Promise<
|
|
35
|
-
aggregations: any;
|
|
36
|
-
hits: any[];
|
|
37
|
-
scrollId: any;
|
|
38
|
-
total: any;
|
|
39
|
-
}>;
|
|
74
|
+
scroll(scrollId: string, ttl?: string | number): Promise<ObjectRepositorySearchAnswer>;
|
|
40
75
|
/**
|
|
41
76
|
* Loads an object from Cache. Returns a promise that resolves either to the
|
|
42
77
|
* retrieved object of null in case it is not found.
|
|
@@ -56,6 +91,13 @@ export declare class ObjectRepository<TObject extends {
|
|
|
56
91
|
* Returns a promise that resolves either to the
|
|
57
92
|
* retrieved object of null in case it is not found.
|
|
58
93
|
*
|
|
94
|
+
* All three of `load`, `loadFromCache` and `loadOneFromDatabase` have
|
|
95
|
+
* always had a `return null` path, and are declared `Promise<TObject>` all
|
|
96
|
+
* the same (the `null!`s): that is what v2.56.0 declared, and plugins and
|
|
97
|
+
* applications subclass this — `(await this.load(id)).name` compiled
|
|
98
|
+
* against it under `strict`. Stating the `| null` (ADR-0001, TD-40, #2727)
|
|
99
|
+
* broke them; a caller that can meet the `null` checks for it.
|
|
100
|
+
*
|
|
59
101
|
* If the object is not found in Cache and found in the Database,
|
|
60
102
|
* it will be written to cache also.
|
|
61
103
|
*
|
|
@@ -134,12 +176,30 @@ export declare class ObjectRepository<TObject extends {
|
|
|
134
176
|
/**
|
|
135
177
|
* Serializes the object before being persisted to the database.
|
|
136
178
|
*
|
|
179
|
+
* v2.56.0 declared it `Omit<TObject, "_id">`, which subclasses do not
|
|
180
|
+
* honour (RoleRepository also drops `restrictedTo`), and which code
|
|
181
|
+
* compiled against it assigns to or overrides with. Only `any` accepts both
|
|
182
|
+
* that and the `JSONObject` Kuzzle's own subclasses answer.
|
|
183
|
+
*
|
|
137
184
|
* @param object - The object to serialize
|
|
138
185
|
*/
|
|
139
|
-
serializeToDatabase(object: TObject):
|
|
186
|
+
serializeToDatabase(object: TObject): any;
|
|
140
187
|
/**
|
|
141
188
|
* @param {string} id
|
|
142
189
|
*/
|
|
190
|
+
/**
|
|
191
|
+
* The id of an object being written, removed or expired.
|
|
192
|
+
*
|
|
193
|
+
* A model carries `null` until it has been stored (ADR-0001, TD-62), and
|
|
194
|
+
* every path that calls this already holds one that has. Building a cache
|
|
195
|
+
* key out of a `null` would silently address `repos/<index>/<collection>/null`,
|
|
196
|
+
* which is the failure this replaces.
|
|
197
|
+
*
|
|
198
|
+
* @throws {PreconditionError} when the object has no id
|
|
199
|
+
*/
|
|
200
|
+
protected idOf(object: {
|
|
201
|
+
_id: string | null;
|
|
202
|
+
}): string;
|
|
143
203
|
getCacheKey(id: string): string;
|
|
144
204
|
/**
|
|
145
205
|
* @param {object} dto
|
|
@@ -157,8 +217,10 @@ export declare class ObjectRepository<TObject extends {
|
|
|
157
217
|
* @param {object} options - ES options (refresh)
|
|
158
218
|
* @param {object} part
|
|
159
219
|
* @returns {Promise<integer>} total deleted objects
|
|
220
|
+
*
|
|
221
|
+
* The public signature is v2.56.0's: untyped options, an `any` answer.
|
|
160
222
|
*/
|
|
161
|
-
truncate(options:
|
|
223
|
+
truncate(options: unknown): Promise<any>;
|
|
162
224
|
/**
|
|
163
225
|
* Do not override this: this function calls itself.
|
|
164
226
|
*/
|
|
@@ -46,22 +46,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
46
46
|
exports.ObjectRepository = void 0;
|
|
47
47
|
const kerror = __importStar(require("../../kerror"));
|
|
48
48
|
const cacheDbEnum_1 = require("../cache/cacheDbEnum");
|
|
49
|
+
/**
|
|
50
|
+
* `_id` is nullable because the models are: `User`, `Profile` and `Token` are
|
|
51
|
+
* all constructed empty and get their id on the way out of the store
|
|
52
|
+
* (ADR-0001, TD-62). The repository only ever reads it off an object it
|
|
53
|
+
* loaded, which has one.
|
|
54
|
+
*/
|
|
49
55
|
class ObjectRepository {
|
|
50
|
-
constructor({ cache = cacheDbEnum_1.cacheDbEnum.INTERNAL, store = null } = {}) {
|
|
56
|
+
constructor({ cache = cacheDbEnum_1.cacheDbEnum.INTERNAL, store = null, } = {}) {
|
|
51
57
|
this.ttl = global.kuzzle.config.repositories.common.cacheTTL;
|
|
52
|
-
this.collection = null;
|
|
53
58
|
this.ObjectConstructor = null;
|
|
54
59
|
this.store = store;
|
|
55
60
|
this.index = store ? store.index : global.kuzzle.internalIndex.index;
|
|
56
61
|
this.cacheDb = cache;
|
|
57
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolves `null` when the document does not carry an `_id` — declared
|
|
65
|
+
* `Promise<TObject>` all the same: see `load()`.
|
|
66
|
+
*/
|
|
58
67
|
async loadOneFromDatabase(id) {
|
|
59
68
|
let response;
|
|
60
69
|
try {
|
|
61
70
|
response = await this.store.get(this.collection, id);
|
|
62
71
|
}
|
|
63
72
|
catch (error) {
|
|
64
|
-
if (error.status === 404) {
|
|
73
|
+
if (error instanceof Error && "status" in error && error.status === 404) {
|
|
65
74
|
throw kerror.get("services", "storage", "not_found", id);
|
|
66
75
|
}
|
|
67
76
|
throw error;
|
|
@@ -93,20 +102,10 @@ class ObjectRepository {
|
|
|
93
102
|
const objects = await Promise.all(promises);
|
|
94
103
|
return objects;
|
|
95
104
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Search in database corresponding repository according to a query
|
|
98
|
-
*
|
|
99
|
-
* @param {object} searchBody
|
|
100
|
-
* @param {object} [options] - optional search arguments (from, size, scroll)
|
|
101
|
-
* @returns {Promise}
|
|
102
|
-
*/
|
|
103
105
|
async search(searchBody, options = {}) {
|
|
104
106
|
const response = await this.store.search(this.collection, searchBody, options);
|
|
105
107
|
return this.formatSearchResults(response);
|
|
106
108
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Scroll over a paginated search request
|
|
109
|
-
*/
|
|
110
109
|
async scroll(scrollId, ttl) {
|
|
111
110
|
const response = await this.store.scroll(scrollId, ttl);
|
|
112
111
|
return this.formatSearchResults(response);
|
|
@@ -133,7 +132,7 @@ class ObjectRepository {
|
|
|
133
132
|
return await this.fromDTO({ ...JSON.parse(response) });
|
|
134
133
|
}
|
|
135
134
|
catch (err) {
|
|
136
|
-
throw kerror.get("services", "cache", "read_failed", err.message);
|
|
135
|
+
throw kerror.get("services", "cache", "read_failed", err instanceof Error ? err.message : String(err));
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
/**
|
|
@@ -141,6 +140,13 @@ class ObjectRepository {
|
|
|
141
140
|
* Returns a promise that resolves either to the
|
|
142
141
|
* retrieved object of null in case it is not found.
|
|
143
142
|
*
|
|
143
|
+
* All three of `load`, `loadFromCache` and `loadOneFromDatabase` have
|
|
144
|
+
* always had a `return null` path, and are declared `Promise<TObject>` all
|
|
145
|
+
* the same (the `null!`s): that is what v2.56.0 declared, and plugins and
|
|
146
|
+
* applications subclass this — `(await this.load(id)).name` compiled
|
|
147
|
+
* against it under `strict`. Stating the `| null` (ADR-0001, TD-40, #2727)
|
|
148
|
+
* broke them; a caller that can meet the `null` checks for it.
|
|
149
|
+
*
|
|
144
150
|
* If the object is not found in Cache and found in the Database,
|
|
145
151
|
* it will be written to cache also.
|
|
146
152
|
*
|
|
@@ -193,10 +199,10 @@ class ObjectRepository {
|
|
|
193
199
|
async delete(object, options = {}) {
|
|
194
200
|
const promises = [];
|
|
195
201
|
if (this.cacheDb !== cacheDbEnum_1.cacheDbEnum.NONE) {
|
|
196
|
-
promises.push(this.deleteFromCache(object
|
|
202
|
+
promises.push(this.deleteFromCache(this.idOf(object), options));
|
|
197
203
|
}
|
|
198
204
|
if (this.store) {
|
|
199
|
-
promises.push(this.deleteFromDatabase(object
|
|
205
|
+
promises.push(this.deleteFromDatabase(this.idOf(object), options));
|
|
200
206
|
}
|
|
201
207
|
await Promise.all(promises);
|
|
202
208
|
}
|
|
@@ -214,7 +220,7 @@ class ObjectRepository {
|
|
|
214
220
|
* @param options.ttl - if provided, overrides the default ttl set on the repository for the current operation
|
|
215
221
|
*/
|
|
216
222
|
async persistToCache(object, options = {}) {
|
|
217
|
-
const key = options.key || this.getCacheKey(object
|
|
223
|
+
const key = options.key || this.getCacheKey(this.idOf(object));
|
|
218
224
|
const value = JSON.stringify(this.serializeToCache(object));
|
|
219
225
|
const ttl = options.ttl ?? this.ttl;
|
|
220
226
|
await global.kuzzle.ask(`core:cache:${this.cacheDb}:store`, key, value, {
|
|
@@ -261,7 +267,7 @@ class ObjectRepository {
|
|
|
261
267
|
* @param options.key - if provided, stores the object to the given key instead of the default one (<collection>/<id>)
|
|
262
268
|
*/
|
|
263
269
|
async expireFromCache(object, options = {}) {
|
|
264
|
-
const key = options.key || this.getCacheKey(object
|
|
270
|
+
const key = options.key || this.getCacheKey(this.idOf(object));
|
|
265
271
|
await global.kuzzle.ask(`core:cache:${this.cacheDb}:expire`, key, -1);
|
|
266
272
|
}
|
|
267
273
|
/**
|
|
@@ -275,8 +281,14 @@ class ObjectRepository {
|
|
|
275
281
|
/**
|
|
276
282
|
* Serializes the object before being persisted to the database.
|
|
277
283
|
*
|
|
284
|
+
* v2.56.0 declared it `Omit<TObject, "_id">`, which subclasses do not
|
|
285
|
+
* honour (RoleRepository also drops `restrictedTo`), and which code
|
|
286
|
+
* compiled against it assigns to or overrides with. Only `any` accepts both
|
|
287
|
+
* that and the `JSONObject` Kuzzle's own subclasses answer.
|
|
288
|
+
*
|
|
278
289
|
* @param object - The object to serialize
|
|
279
290
|
*/
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- v2.56.0's public type, kept for compatibility
|
|
280
292
|
serializeToDatabase(object) {
|
|
281
293
|
const dto = this.toDTO(object);
|
|
282
294
|
delete dto._id;
|
|
@@ -285,6 +297,22 @@ class ObjectRepository {
|
|
|
285
297
|
/**
|
|
286
298
|
* @param {string} id
|
|
287
299
|
*/
|
|
300
|
+
/**
|
|
301
|
+
* The id of an object being written, removed or expired.
|
|
302
|
+
*
|
|
303
|
+
* A model carries `null` until it has been stored (ADR-0001, TD-62), and
|
|
304
|
+
* every path that calls this already holds one that has. Building a cache
|
|
305
|
+
* key out of a `null` would silently address `repos/<index>/<collection>/null`,
|
|
306
|
+
* which is the failure this replaces.
|
|
307
|
+
*
|
|
308
|
+
* @throws {PreconditionError} when the object has no id
|
|
309
|
+
*/
|
|
310
|
+
idOf(object) {
|
|
311
|
+
if (object._id === null) {
|
|
312
|
+
throw kerror.get("services", "storage", "missing_argument", "_id");
|
|
313
|
+
}
|
|
314
|
+
return object._id;
|
|
315
|
+
}
|
|
288
316
|
getCacheKey(id) {
|
|
289
317
|
return `repos/${this.index}/${this.collection}/${id}`;
|
|
290
318
|
}
|
|
@@ -304,13 +332,6 @@ class ObjectRepository {
|
|
|
304
332
|
toDTO(o) {
|
|
305
333
|
return { ...o };
|
|
306
334
|
}
|
|
307
|
-
/**
|
|
308
|
-
* Recursively delete all objects in repository with a scroll
|
|
309
|
-
*
|
|
310
|
-
* @param {object} options - ES options (refresh)
|
|
311
|
-
* @param {object} part
|
|
312
|
-
* @returns {Promise<integer>} total deleted objects
|
|
313
|
-
*/
|
|
314
335
|
async truncate(options) {
|
|
315
336
|
// Allows safe overrides, as _truncate is called recursively
|
|
316
337
|
return this._truncate(options);
|
|
@@ -322,7 +343,10 @@ class ObjectRepository {
|
|
|
322
343
|
if (part === null) {
|
|
323
344
|
const objects = await this.search({}, { refresh: options.refresh, scroll: "5s", size: 100 });
|
|
324
345
|
const deleted = await this.truncatePart(objects, options);
|
|
325
|
-
|
|
346
|
+
// A page that holds back hits always answers a scroll id; without one
|
|
347
|
+
// there is no next page to walk, and calling `scroll(undefined)` is how
|
|
348
|
+
// that used to be discovered.
|
|
349
|
+
if (objects.hits.length < objects.total && objects.scrollId) {
|
|
326
350
|
const total = await this._truncate(options, {
|
|
327
351
|
fetched: objects.hits.length,
|
|
328
352
|
scrollId: objects.scrollId,
|
|
@@ -335,7 +359,7 @@ class ObjectRepository {
|
|
|
335
359
|
const objects = await this.scroll(part.scrollId, "5s");
|
|
336
360
|
const deleted = await this.truncatePart(objects, options);
|
|
337
361
|
part.fetched += objects.hits.length;
|
|
338
|
-
if (part.fetched < part.total) {
|
|
362
|
+
if (part.fetched < part.total && objects.scrollId) {
|
|
339
363
|
part.scrollId = objects.scrollId;
|
|
340
364
|
const total = await this._truncate(options, part);
|
|
341
365
|
return deleted + total;
|
|
@@ -355,10 +379,14 @@ class ObjectRepository {
|
|
|
355
379
|
const protectedObjects = ["profiles", "roles"].indexOf(this.collection) !== -1
|
|
356
380
|
? ["admin", "default", "anonymous"]
|
|
357
381
|
: [];
|
|
358
|
-
|
|
382
|
+
const id = this.idOf(object);
|
|
383
|
+
if (protectedObjects.includes(id)) {
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
const loaded = await this.load(id);
|
|
387
|
+
if (loaded === null) {
|
|
359
388
|
return 0;
|
|
360
389
|
}
|
|
361
|
-
const loaded = await this.load(object._id);
|
|
362
390
|
await this.delete(loaded, options);
|
|
363
391
|
return 1;
|
|
364
392
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { JSONObject } from "../../types/JSONObject";
|
|
2
|
+
import "../../types/Global";
|
|
2
3
|
/**
|
|
3
4
|
* Abstract class used to load a manifest.json file.
|
|
4
5
|
* Used as a base for plugins and protocols.
|
|
@@ -7,13 +8,24 @@ export = AbstractManifest;
|
|
|
7
8
|
* @param {string} pluginPath - Absolute path to the plugin directory
|
|
8
9
|
*/
|
|
9
10
|
declare class AbstractManifest {
|
|
10
|
-
|
|
11
|
-
path: any;
|
|
11
|
+
path: string;
|
|
12
12
|
manifestPath: string;
|
|
13
|
-
name:
|
|
14
|
-
kuzzleVersion:
|
|
15
|
-
raw:
|
|
16
|
-
|
|
13
|
+
name: string | null;
|
|
14
|
+
kuzzleVersion: string | null;
|
|
15
|
+
raw: JSONObject | null;
|
|
16
|
+
constructor(pluginPath: string);
|
|
17
|
+
/**
|
|
18
|
+
* Reads and validates the manifest, and answers the two fields it
|
|
19
|
+
* establishes.
|
|
20
|
+
*
|
|
21
|
+
* Returning them is what lets a caller use them as strings: the fields stay
|
|
22
|
+
* nullable because they are null until this runs, and `plugin.ts` reads
|
|
23
|
+
* them through `?.` for exactly that reason.
|
|
24
|
+
*/
|
|
25
|
+
load(): {
|
|
26
|
+
kuzzleVersion: string;
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
17
29
|
/**
|
|
18
30
|
* This object can be stringified and exported, most notably by the
|
|
19
31
|
* server:info API action
|
|
@@ -23,5 +35,6 @@ declare class AbstractManifest {
|
|
|
23
35
|
*
|
|
24
36
|
* @returns {Object}
|
|
25
37
|
*/
|
|
26
|
-
toJSON():
|
|
38
|
+
toJSON(): JSONObject;
|
|
27
39
|
}
|
|
40
|
+
export = AbstractManifest;
|
|
@@ -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,11 +19,35 @@
|
|
|
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
|
-
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
25
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
26
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(o, k2, desc);
|
|
29
|
+
}) : (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
o[k2] = m[k];
|
|
32
|
+
}));
|
|
33
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
34
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
35
|
+
}) : function(o, v) {
|
|
36
|
+
o["default"] = v;
|
|
37
|
+
});
|
|
38
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
const lodash_1 = require("lodash");
|
|
46
|
+
const path = __importStar(require("node:path"));
|
|
47
|
+
const semver = __importStar(require("semver"));
|
|
48
|
+
const kerror_1 = require("../../kerror");
|
|
49
|
+
require("../../types/Global");
|
|
50
|
+
const kerror = (0, kerror_1.wrap)("plugin", "manifest");
|
|
26
51
|
/**
|
|
27
52
|
* Abstract class used to load a manifest.json file.
|
|
28
53
|
* Used as a base for plugins and protocols.
|
|
@@ -38,31 +63,46 @@ class AbstractManifest {
|
|
|
38
63
|
this.kuzzleVersion = null;
|
|
39
64
|
this.raw = null;
|
|
40
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Reads and validates the manifest, and answers the two fields it
|
|
68
|
+
* establishes.
|
|
69
|
+
*
|
|
70
|
+
* Returning them is what lets a caller use them as strings: the fields stay
|
|
71
|
+
* nullable because they are null until this runs, and `plugin.ts` reads
|
|
72
|
+
* them through `?.` for exactly that reason.
|
|
73
|
+
*/
|
|
41
74
|
load() {
|
|
75
|
+
// Read into a local: `this.raw` is the nullable field, and the six checks
|
|
76
|
+
// below each re-read it.
|
|
77
|
+
let raw;
|
|
42
78
|
try {
|
|
43
|
-
|
|
79
|
+
// The manifest of a plugin or protocol loaded from disk: the path is
|
|
80
|
+
// only known at runtime.
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
82
|
+
raw = require(this.manifestPath);
|
|
44
83
|
}
|
|
45
84
|
catch (e) {
|
|
46
85
|
throw kerror.get("cannot_load", this.manifestPath, e.message);
|
|
47
86
|
}
|
|
48
|
-
|
|
87
|
+
this.raw = raw;
|
|
88
|
+
if ((0, lodash_1.isNil)(raw.kuzzleVersion)) {
|
|
49
89
|
throw kerror.get("missing_version", this.manifestPath);
|
|
50
90
|
}
|
|
51
|
-
|
|
52
|
-
|
|
91
|
+
const kuzzleVersion = raw.kuzzleVersion;
|
|
92
|
+
this.kuzzleVersion = kuzzleVersion;
|
|
93
|
+
if (!semver.satisfies(global.kuzzle.config.version, kuzzleVersion, {
|
|
53
94
|
includePrerelease: true,
|
|
54
95
|
})) {
|
|
55
|
-
throw kerror.get("version_mismatch", this.path, global.kuzzle.config.version,
|
|
96
|
+
throw kerror.get("version_mismatch", this.path, global.kuzzle.config.version, kuzzleVersion);
|
|
56
97
|
}
|
|
57
|
-
if (
|
|
58
|
-
if (typeof this.raw.name !== "string" || this.raw.name.length === 0) {
|
|
59
|
-
throw kerror.get("invalid_name_type", this.manifestPath);
|
|
60
|
-
}
|
|
61
|
-
this.name = this.raw.name;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
98
|
+
if ((0, lodash_1.isNil)(raw.name)) {
|
|
64
99
|
throw kerror.get("missing_name", this.manifestPath);
|
|
65
100
|
}
|
|
101
|
+
if (typeof raw.name !== "string" || raw.name.length === 0) {
|
|
102
|
+
throw kerror.get("invalid_name_type", this.manifestPath);
|
|
103
|
+
}
|
|
104
|
+
this.name = raw.name;
|
|
105
|
+
return { kuzzleVersion, name: raw.name };
|
|
66
106
|
}
|
|
67
107
|
/**
|
|
68
108
|
* This object can be stringified and exported, most notably by the
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { RealtimeController, Notification,
|
|
1
|
+
import type { RealtimeController, Notification, ScopeOption, UserOption, ResponsePayload, BaseRequest } from "kuzzle-sdk";
|
|
2
|
+
import type { JSONObject } from "../../../types/JSONObject";
|
|
3
|
+
import { Kuzzle } from "kuzzle-sdk";
|
|
2
4
|
interface EmbeddedRealtime extends RealtimeController {
|
|
3
5
|
/**
|
|
4
6
|
* Subscribes by providing a set of filters: messages, document changes
|
|
@@ -112,14 +112,15 @@ class EmbeddedSDK extends kuzzle_sdk_1.Kuzzle {
|
|
|
112
112
|
if ((0, safeObject_1.isPlainObject)(request) &&
|
|
113
113
|
request.controller === "realtime" &&
|
|
114
114
|
request.action === "subscribe") {
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
// `propagate` is not part of BaseRequest: it is a Kuzzle-internal flag
|
|
116
|
+
// read back by the realtime controller. Written with `Reflect.set`, like
|
|
117
|
+
// `__kuid__` and `__checkRights__` below, rather than suppressed.
|
|
118
|
+
Reflect.set(request, "propagate", options.propagate === undefined || options.propagate === null
|
|
119
|
+
? false
|
|
120
|
+
: options.propagate);
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
const forbiddenActions = forbiddenEmbeddedActions[request.controller];
|
|
123
|
+
if (forbiddenActions?.has(request.action)) {
|
|
123
124
|
throw kerror.get("api", "process", "forbidden_embedded_sdk_action", request.controller, request.action, ", use user impersonation or security controller instead");
|
|
124
125
|
}
|
|
125
126
|
const warning = lodash_1.default.get(warnEmbeddedActions, [
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RequestPayload } from "kuzzle-sdk";
|
|
2
|
+
import { KuzzleEventEmitter } from "kuzzle-sdk";
|
|
2
3
|
export declare class FunnelProtocol extends KuzzleEventEmitter {
|
|
3
4
|
private id;
|
|
4
5
|
private connectionId;
|
|
@@ -68,12 +68,21 @@ class FunnelProtocol extends kuzzle_sdk_1.KuzzleEventEmitter {
|
|
|
68
68
|
* Hydrate the user and execute SDK query
|
|
69
69
|
*/
|
|
70
70
|
async query(request) {
|
|
71
|
-
if
|
|
72
|
-
|
|
71
|
+
// Through a local: the field is nullable and the narrowing an `if` on it
|
|
72
|
+
// gives does not survive the `await` below.
|
|
73
|
+
let connectionId = this.connectionId;
|
|
74
|
+
if (connectionId === null) {
|
|
75
|
+
// `ask` answers `any`; `InternalProtocol` registers this one as
|
|
76
|
+
// `() => this.connection.id`, a string.
|
|
77
|
+
const id = await global.kuzzle.ask("core:network:internal:connectionId:get");
|
|
78
|
+
connectionId = id;
|
|
79
|
+
this.connectionId = id;
|
|
73
80
|
}
|
|
81
|
+
// Annotated, because the initialiser alone infers `user: null` and every
|
|
82
|
+
// read below is then a read off `never`.
|
|
74
83
|
const requestOptions = {
|
|
75
84
|
connection: {
|
|
76
|
-
id:
|
|
85
|
+
id: connectionId,
|
|
77
86
|
protocol: this.id,
|
|
78
87
|
},
|
|
79
88
|
user: null,
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import type { BaseRequest } from "kuzzle-sdk";
|
|
2
|
+
import type { JSONObject } from "../../../types/JSONObject";
|
|
3
|
+
import "../../../types/Global";
|
|
4
|
+
interface ImpersonationOptions {
|
|
5
|
+
checkRights?: boolean;
|
|
6
|
+
}
|
|
2
7
|
declare class ImpersonatedSDK {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
query(request:
|
|
8
|
+
kuid: string;
|
|
9
|
+
checkRights: boolean;
|
|
10
|
+
constructor(kuid: string, options?: ImpersonationOptions);
|
|
11
|
+
query(request: BaseRequest, options?: JSONObject): Promise<import("kuzzle-sdk").ResponsePayload<JSONObject>>;
|
|
7
12
|
}
|
|
13
|
+
export = ImpersonatedSDK;
|
|
@@ -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,13 +19,20 @@
|
|
|
18
19
|
* See the License for the specific language governing permissions and
|
|
19
20
|
* limitations under the License.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
// The controllers barrel ships `export = { ... }`. A NAMED import cannot
|
|
26
|
+
// target that (TS2497), but a DEFAULT one can under `esModuleInterop` — and
|
|
27
|
+
// unlike `import x = require(...)` it also loads under vitest, which resolves
|
|
28
|
+
// `lib/` as ESM (step 07, PR G2).
|
|
29
|
+
const controllers_1 = __importDefault(require("../../../api/controllers"));
|
|
30
|
+
require("../../../types/Global");
|
|
23
31
|
class ImpersonatedSDK {
|
|
24
32
|
constructor(kuid, options = {}) {
|
|
25
33
|
this.kuid = kuid;
|
|
26
34
|
this.checkRights = options.checkRights || false;
|
|
27
|
-
for (const controller of Object.keys(
|
|
35
|
+
for (const controller of Object.keys(controllers_1.default)) {
|
|
28
36
|
// @todo in the future, native controller names should be normalized to sdk naming
|
|
29
37
|
const controllerName = controller
|
|
30
38
|
.replace("Controller", "")
|
|
@@ -38,11 +46,14 @@ class ImpersonatedSDK {
|
|
|
38
46
|
Reflect.defineProperty(this, controllerName, {
|
|
39
47
|
get: () => {
|
|
40
48
|
// If the requested controller has not yet been proxied
|
|
41
|
-
if (!this
|
|
49
|
+
if (!Reflect.get(this, controllerProxy)) {
|
|
42
50
|
// Create a proxy object to inject our local 'query' behaviour
|
|
43
51
|
// in the underlying base 'sdk' action methods so we can send
|
|
44
52
|
// impersonation configuration (kuid & checkRights) to the funnel
|
|
45
|
-
this[controllerProxy]
|
|
53
|
+
// `Reflect.set`, not `this[controllerProxy] =`: the key is a
|
|
54
|
+
// runtime-built string, which a plain index access cannot type.
|
|
55
|
+
// Behaviour is identical — same receiver, same string key.
|
|
56
|
+
Reflect.set(this, controllerProxy, new Proxy(global.app.sdk[controllerName], {
|
|
46
57
|
get: (controllerInstance, actionName) => {
|
|
47
58
|
const customContext = {
|
|
48
59
|
kuzzle: global.app.sdk,
|
|
@@ -63,16 +74,18 @@ class ImpersonatedSDK {
|
|
|
63
74
|
// containing our 'query' method and any original local methods
|
|
64
75
|
return controllerInstance[actionName].bind(customContext);
|
|
65
76
|
},
|
|
66
|
-
});
|
|
77
|
+
}));
|
|
67
78
|
}
|
|
68
|
-
return this
|
|
79
|
+
return Reflect.get(this, controllerProxy);
|
|
69
80
|
},
|
|
70
81
|
});
|
|
71
82
|
}
|
|
72
83
|
}
|
|
73
84
|
query(request, options = {}) {
|
|
74
|
-
|
|
75
|
-
request
|
|
85
|
+
// Both are read back by the funnel to apply the impersonation; they are
|
|
86
|
+
// not part of the SDK's declared request shape, hence the index writes.
|
|
87
|
+
Reflect.set(request, "__kuid__", this.kuid);
|
|
88
|
+
Reflect.set(request, "__checkRights__", this.checkRights);
|
|
76
89
|
return global.app.sdk.query(request, options);
|
|
77
90
|
}
|
|
78
91
|
}
|