kuzzle 2.49.1 → 2.50.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/check-node-version.js +11 -0
- package/dist/bin/copy-protobuf.js +17 -0
- package/dist/lib/api/controllers/adminController.d.ts +51 -0
- package/dist/lib/api/controllers/adminController.js +191 -0
- package/{lib → dist/lib}/api/controllers/authController.d.ts +20 -40
- package/{lib → dist/lib}/api/controllers/authController.js +23 -24
- package/dist/lib/api/controllers/bulkController.d.ts +46 -0
- package/dist/lib/api/controllers/bulkController.js +132 -0
- package/dist/lib/api/controllers/clusterController.d.ts +6 -0
- package/{lib → dist/lib}/api/controllers/clusterController.js +7 -11
- package/dist/lib/api/controllers/collectionController.d.ts +136 -0
- package/dist/lib/api/controllers/collectionController.js +356 -0
- package/dist/lib/api/controllers/documentController.d.ts +181 -0
- package/dist/lib/api/controllers/documentController.js +768 -0
- package/dist/lib/api/controllers/index.d.ts +12 -0
- package/{lib → dist/lib}/api/controllers/index.js +13 -14
- package/dist/lib/api/controllers/indexController.d.ts +65 -0
- package/dist/lib/api/controllers/indexController.js +139 -0
- package/dist/lib/api/controllers/memoryStorageController.d.ts +8 -0
- package/dist/lib/api/controllers/memoryStorageController.js +867 -0
- package/dist/lib/api/controllers/realtimeController.d.ts +47 -0
- package/dist/lib/api/controllers/realtimeController.js +128 -0
- package/dist/lib/api/controllers/securityController.d.ts +423 -0
- package/dist/lib/api/controllers/securityController.js +1139 -0
- package/dist/lib/api/controllers/serverController.d.ts +82 -0
- package/dist/lib/api/controllers/serverController.js +321 -0
- package/dist/lib/api/documentExtractor.d.ts +9 -0
- package/dist/lib/api/documentExtractor.js +274 -0
- package/dist/lib/api/funnel.d.ts +183 -0
- package/dist/lib/api/funnel.js +821 -0
- package/dist/lib/api/httpRoutes.d.ts +17 -0
- package/dist/lib/api/httpRoutes.js +1496 -0
- package/dist/lib/api/rateLimiter.d.ts +18 -0
- package/dist/lib/api/rateLimiter.js +74 -0
- package/{lib → dist/lib}/api/request/kuzzleRequest.d.ts +2 -2
- package/{lib → dist/lib}/api/request/requestContext.d.ts +2 -1
- package/dist/lib/cluster/command.d.ts +73 -0
- package/dist/lib/cluster/command.js +236 -0
- package/dist/lib/cluster/index.d.ts +2 -0
- package/{lib → dist/lib}/cluster/index.js +1 -2
- package/dist/lib/cluster/node.d.ts +278 -0
- package/dist/lib/cluster/node.js +876 -0
- package/dist/lib/cluster/publisher.d.ts +188 -0
- package/dist/lib/cluster/publisher.js +347 -0
- package/dist/lib/cluster/subscriber.d.ts +269 -0
- package/dist/lib/cluster/subscriber.js +555 -0
- package/dist/lib/cluster/workers/IDCardRenewer.d.ts +13 -0
- package/dist/lib/cluster/workers/IDCardRenewer.js +120 -0
- package/{lib → dist/lib}/config/documentEventAliases.d.ts +1 -2
- package/dist/lib/config/index.d.ts +5 -0
- package/dist/lib/config/index.js +244 -0
- package/dist/lib/config/sdkCompatibility.json +9 -0
- package/dist/lib/core/auth/formatProcessing.d.ts +30 -0
- package/dist/lib/core/auth/formatProcessing.js +55 -0
- package/dist/lib/core/auth/passportResponse.d.ts +15 -0
- package/{lib → dist/lib}/core/auth/passportResponse.js +24 -30
- package/dist/lib/core/auth/passportWrapper.d.ts +28 -0
- package/dist/lib/core/auth/passportWrapper.js +126 -0
- package/{lib → dist/lib}/core/backend/backendConfig.js +2 -2
- package/{lib → dist/lib}/core/backend/backendErrors.js +9 -12
- package/dist/lib/core/cache/cacheEngine.d.ts +15 -0
- package/dist/lib/core/cache/cacheEngine.js +205 -0
- package/dist/lib/core/network/accessLogger.d.ts +29 -0
- package/dist/lib/core/network/accessLogger.js +250 -0
- package/dist/lib/core/network/clientConnection.d.ts +15 -0
- package/{lib → dist/lib}/core/network/clientConnection.js +17 -24
- package/dist/lib/core/network/context.d.ts +42 -0
- package/dist/lib/core/network/context.js +57 -0
- package/dist/lib/core/network/entryPoint.d.ts +62 -0
- package/dist/lib/core/network/entryPoint.js +261 -0
- package/dist/lib/core/network/httpRouter/index.d.ts +85 -0
- package/dist/lib/core/network/httpRouter/index.js +258 -0
- package/dist/lib/core/network/httpRouter/routeHandler.d.ts +46 -0
- package/dist/lib/core/network/httpRouter/routeHandler.js +101 -0
- package/dist/lib/core/network/httpRouter/routePart.d.ts +35 -0
- package/dist/lib/core/network/httpRouter/routePart.js +117 -0
- package/dist/lib/core/network/protocolManifest.d.ts +6 -0
- package/{lib → dist/lib}/core/network/protocolManifest.js +5 -9
- package/dist/lib/core/network/protocols/httpMessage.d.ts +22 -0
- package/dist/lib/core/network/protocols/httpMessage.js +62 -0
- package/dist/lib/core/network/protocols/httpwsProtocol.d.ts +171 -0
- package/dist/lib/core/network/protocols/httpwsProtocol.js +921 -0
- package/dist/lib/core/network/protocols/internalProtocol.d.ts +27 -0
- package/dist/lib/core/network/protocols/internalProtocol.js +82 -0
- package/dist/lib/core/network/protocols/mqttProtocol.d.ts +39 -0
- package/dist/lib/core/network/protocols/mqttProtocol.js +219 -0
- package/dist/lib/core/network/protocols/protocol.d.ts +26 -0
- package/dist/lib/core/network/protocols/protocol.js +74 -0
- package/dist/lib/core/network/router.d.ts +49 -0
- package/dist/lib/core/network/router.js +193 -0
- package/dist/lib/core/plugin/plugin.d.ts +56 -0
- package/dist/lib/core/plugin/plugin.js +282 -0
- package/{lib → dist/lib}/core/plugin/pluginContext.js +2 -2
- package/dist/lib/core/plugin/pluginManifest.d.ts +5 -0
- package/{lib → dist/lib}/core/plugin/pluginManifest.js +16 -27
- package/dist/lib/core/plugin/pluginRepository.d.ts +53 -0
- package/dist/lib/core/plugin/pluginRepository.js +112 -0
- package/dist/lib/core/plugin/pluginsManager.d.ts +190 -0
- package/dist/lib/core/plugin/pluginsManager.js +817 -0
- package/dist/lib/core/plugin/privilegedContext.d.ts +14 -0
- package/{lib → dist/lib}/core/plugin/privilegedContext.js +10 -14
- package/dist/lib/core/realtime/actionEnum.d.ts +25 -0
- package/{lib → dist/lib}/core/realtime/actionEnum.js +7 -10
- package/dist/lib/core/realtime/index.d.ts +8 -0
- package/{lib → dist/lib}/core/realtime/index.js +9 -13
- package/dist/lib/core/realtime/notification/document.d.ts +34 -0
- package/dist/lib/core/realtime/notification/document.js +98 -0
- package/dist/lib/core/realtime/notification/index.d.ts +3 -0
- package/{lib → dist/lib}/core/realtime/notification/index.js +4 -5
- package/dist/lib/core/realtime/notification/server.d.ts +17 -0
- package/{lib → dist/lib}/core/realtime/notification/server.js +8 -10
- package/dist/lib/core/realtime/notification/user.d.ts +29 -0
- package/dist/lib/core/realtime/notification/user.js +66 -0
- package/dist/lib/core/realtime/notifier.d.ts +171 -0
- package/dist/lib/core/realtime/notifier.js +405 -0
- package/dist/lib/core/security/index.d.ts +14 -0
- package/{lib → dist/lib}/core/security/index.js +15 -19
- package/dist/lib/core/security/roleRepository.d.ts +143 -0
- package/dist/lib/core/security/roleRepository.js +445 -0
- package/dist/lib/core/security/securityLoader.d.ts +24 -0
- package/dist/lib/core/security/securityLoader.js +125 -0
- package/{lib → dist/lib}/core/security/tokenRepository.js +1 -1
- package/dist/lib/core/security/userRepository.d.ts +81 -0
- package/dist/lib/core/security/userRepository.js +346 -0
- package/dist/lib/core/shared/abstractManifest.d.ts +27 -0
- package/dist/lib/core/shared/abstractManifest.js +85 -0
- package/dist/lib/core/shared/sdk/impersonatedSdk.d.ts +7 -0
- package/dist/lib/core/shared/sdk/impersonatedSdk.js +80 -0
- package/{lib → dist/lib}/core/shared/store.d.ts +2 -2
- package/dist/lib/core/statistics/statistics.d.ts +94 -0
- package/dist/lib/core/statistics/statistics.js +287 -0
- package/dist/lib/core/storage/clientAdapter.d.ts +62 -0
- package/dist/lib/core/storage/clientAdapter.js +756 -0
- package/dist/lib/core/storage/storageEngine.d.ts +13 -0
- package/dist/lib/core/storage/storageEngine.js +52 -0
- package/dist/lib/core/validation/baseType.d.ts +35 -0
- package/dist/lib/core/validation/baseType.js +70 -0
- package/dist/lib/core/validation/types/anything.d.ts +10 -0
- package/{lib → dist/lib}/core/validation/types/anything.js +7 -10
- package/dist/lib/core/validation/types/boolean.d.ts +16 -0
- package/{lib → dist/lib}/core/validation/types/boolean.js +18 -23
- package/dist/lib/core/validation/types/date.d.ts +17 -0
- package/dist/lib/core/validation/types/date.js +215 -0
- package/dist/lib/core/validation/types/email.d.ts +17 -0
- package/dist/lib/core/validation/types/email.js +80 -0
- package/dist/lib/core/validation/types/enum.d.ts +17 -0
- package/dist/lib/core/validation/types/enum.js +70 -0
- package/dist/lib/core/validation/types/geoPoint.d.ts +17 -0
- package/{lib → dist/lib}/core/validation/types/geoPoint.js +19 -24
- package/dist/lib/core/validation/types/geoShape.d.ts +31 -0
- package/dist/lib/core/validation/types/geoShape.js +280 -0
- package/dist/lib/core/validation/types/integer.d.ts +7 -0
- package/{lib → dist/lib}/core/validation/types/integer.js +21 -27
- package/dist/lib/core/validation/types/ipAddress.d.ts +17 -0
- package/dist/lib/core/validation/types/ipAddress.js +73 -0
- package/dist/lib/core/validation/types/numeric.d.ts +17 -0
- package/dist/lib/core/validation/types/numeric.js +84 -0
- package/dist/lib/core/validation/types/object.d.ts +24 -0
- package/dist/lib/core/validation/types/object.js +74 -0
- package/dist/lib/core/validation/types/string.d.ts +17 -0
- package/dist/lib/core/validation/types/string.js +85 -0
- package/dist/lib/core/validation/types/url.d.ts +17 -0
- package/dist/lib/core/validation/types/url.js +73 -0
- package/dist/lib/core/validation/validation.d.ts +113 -0
- package/dist/lib/core/validation/validation.js +692 -0
- package/dist/lib/kerror/codes/0-core.json +194 -0
- package/dist/lib/kerror/codes/1-services.json +351 -0
- package/dist/lib/kerror/codes/2-api.json +195 -0
- package/dist/lib/kerror/codes/3-network.json +151 -0
- package/dist/lib/kerror/codes/4-plugin.json +498 -0
- package/dist/lib/kerror/codes/5-validation.json +158 -0
- package/dist/lib/kerror/codes/6-protocol.json +28 -0
- package/dist/lib/kerror/codes/7-security.json +283 -0
- package/dist/lib/kerror/codes/8-cluster.json +16 -0
- package/dist/lib/kerror/codes/index.d.ts +24 -0
- package/dist/lib/kerror/codes/index.js +140 -0
- package/{lib → dist/lib}/kerror/index.d.ts +5 -5
- package/{lib → dist/lib}/kuzzle/Logger.d.ts +6 -0
- package/{lib → dist/lib}/kuzzle/Logger.js +26 -5
- package/dist/lib/kuzzle/dumpGenerator.d.ts +14 -0
- package/dist/lib/kuzzle/dumpGenerator.js +180 -0
- package/dist/lib/kuzzle/event/pipeRunner.d.ts +30 -0
- package/dist/lib/kuzzle/event/pipeRunner.js +119 -0
- package/dist/lib/kuzzle/event/waterfall.d.ts +2 -0
- package/dist/lib/kuzzle/event/waterfall.js +90 -0
- package/dist/lib/kuzzle/internalIndexHandler.d.ts +186 -0
- package/dist/lib/kuzzle/internalIndexHandler.js +174 -0
- package/{lib → dist/lib}/kuzzle/kuzzle.d.ts +6 -7
- package/{lib → dist/lib}/kuzzle/kuzzle.js +5 -2
- package/dist/lib/kuzzle/kuzzleStateEnum.d.ts +20 -0
- package/{lib → dist/lib}/kuzzle/kuzzleStateEnum.js +5 -8
- package/dist/lib/kuzzle/vault.d.ts +2 -0
- package/dist/lib/kuzzle/vault.js +63 -0
- package/dist/lib/model/security/rights.d.ts +8 -0
- package/{lib → dist/lib}/model/security/rights.js +4 -8
- package/{lib → dist/lib}/model/security/role.d.ts +1 -1
- package/{lib → dist/lib}/model/security/user.d.ts +1 -0
- package/dist/lib/model/storage/apiKey.d.ts +49 -0
- package/dist/lib/model/storage/apiKey.js +126 -0
- package/dist/lib/model/storage/baseModel.d.ts +100 -0
- package/dist/lib/model/storage/baseModel.js +211 -0
- package/dist/lib/service/cache/redis.d.ts +74 -0
- package/dist/lib/service/cache/redis.js +237 -0
- package/dist/lib/service/service.d.ts +30 -0
- package/dist/lib/service/service.js +74 -0
- package/{lib → dist/lib}/service/storage/7/elasticsearch.d.ts +2 -2
- package/{lib → dist/lib}/service/storage/7/elasticsearch.js +23 -25
- package/dist/lib/service/storage/7/esWrapper.d.ts +19 -0
- package/dist/lib/service/storage/7/esWrapper.js +245 -0
- package/{lib → dist/lib}/service/storage/8/elasticsearch.js +23 -25
- package/dist/lib/service/storage/8/esWrapper.d.ts +19 -0
- package/dist/lib/service/storage/8/esWrapper.js +245 -0
- package/{lib → dist/lib}/types/Plugin.d.ts +1 -1
- package/{lib/types → dist/lib/types/controllers}/Controller.d.ts +2 -2
- package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.d.ts +1 -1
- package/dist/lib/types/controllers/adminControlller.type.d.ts +5 -0
- package/dist/lib/types/controllers/adminControlller.type.js +3 -0
- package/dist/lib/types/controllers/authController.type.d.ts +5 -0
- package/dist/lib/types/controllers/authController.type.js +3 -0
- package/dist/lib/types/core/auth/formatProcessing.type.d.ts +7 -0
- package/dist/lib/types/core/auth/formatProcessing.type.js +3 -0
- package/{lib → dist/lib}/types/index.d.ts +3 -3
- package/{lib → dist/lib}/types/index.js +3 -3
- package/dist/lib/util/assertType.d.ts +41 -0
- package/{lib → dist/lib}/util/assertType.js +38 -56
- package/dist/lib/util/asyncStore.d.ts +38 -0
- package/dist/lib/util/asyncStore.js +70 -0
- package/dist/lib/util/bytes.d.ts +2 -0
- package/dist/lib/util/bytes.js +33 -0
- package/dist/lib/util/debug.d.ts +2 -0
- package/{lib → dist/lib}/util/debug.js +15 -23
- package/dist/lib/util/deprecate.d.ts +1 -0
- package/dist/lib/util/deprecate.js +64 -0
- package/dist/lib/util/didYouMean.d.ts +2 -0
- package/{lib → dist/lib}/util/didYouMean.js +9 -15
- package/dist/lib/util/extractFields.d.ts +17 -0
- package/{lib → dist/lib}/util/extractFields.js +18 -32
- package/dist/lib/util/memoize.d.ts +7 -0
- package/{lib → dist/lib}/util/memoize.js +14 -21
- package/dist/lib/util/promback.d.ts +13 -0
- package/dist/lib/util/promback.js +60 -0
- package/dist/lib/util/requestAssertions.d.ts +10 -0
- package/dist/lib/util/requestAssertions.js +143 -0
- package/dist/lib/util/safeObject.d.ts +3 -0
- package/{lib → dist/lib}/util/safeObject.js +7 -13
- package/dist/lib/util/stackTrace.d.ts +19 -0
- package/{lib → dist/lib}/util/stackTrace.js +35 -41
- package/dist/lib/util/wildcard.d.ts +1 -0
- package/{lib → dist/lib}/util/wildcard.js +21 -30
- package/dist/package.json +120 -0
- package/package.json +45 -58
- package/bin/start-kuzzle-server +0 -126
- package/check-node-version.js +0 -17
- package/lib/api/controllers/adminController.js +0 -229
- package/lib/api/controllers/bulkController.js +0 -210
- package/lib/api/controllers/collectionController.js +0 -502
- package/lib/api/controllers/documentController.js +0 -1156
- package/lib/api/controllers/indexController.js +0 -179
- package/lib/api/controllers/memoryStorageController.js +0 -1023
- package/lib/api/controllers/realtimeController.js +0 -155
- package/lib/api/controllers/securityController.js +0 -1571
- package/lib/api/controllers/serverController.js +0 -381
- package/lib/api/documentExtractor.js +0 -309
- package/lib/api/funnel.js +0 -1143
- package/lib/api/httpRoutes.js +0 -1547
- package/lib/api/rateLimiter.js +0 -87
- package/lib/cluster/command.js +0 -284
- package/lib/cluster/node.js +0 -1203
- package/lib/cluster/publisher.js +0 -386
- package/lib/cluster/subscriber.js +0 -776
- package/lib/cluster/workers/IDCardRenewer.js +0 -144
- package/lib/config/index.js +0 -351
- package/lib/config/sdkCompatibility.json +0 -9
- package/lib/core/auth/formatProcessing.js +0 -66
- package/lib/core/auth/passportWrapper.js +0 -126
- package/lib/core/cache/cacheEngine.js +0 -278
- package/lib/core/network/accessLogger.js +0 -322
- package/lib/core/network/context.js +0 -80
- package/lib/core/network/entryPoint.js +0 -358
- package/lib/core/network/httpRouter/index.js +0 -316
- package/lib/core/network/httpRouter/routeHandler.js +0 -111
- package/lib/core/network/httpRouter/routePart.js +0 -147
- package/lib/core/network/protocols/httpMessage.js +0 -69
- package/lib/core/network/protocols/httpwsProtocol.js +0 -1254
- package/lib/core/network/protocols/internalProtocol.js +0 -109
- package/lib/core/network/protocols/mqttProtocol.js +0 -291
- package/lib/core/network/protocols/protocol.js +0 -102
- package/lib/core/network/router.js +0 -255
- package/lib/core/plugin/plugin.js +0 -436
- package/lib/core/plugin/pluginRepository.js +0 -132
- package/lib/core/plugin/pluginsManager.js +0 -1244
- package/lib/core/realtime/notification/document.js +0 -108
- package/lib/core/realtime/notification/user.js +0 -70
- package/lib/core/realtime/notifier.js +0 -541
- package/lib/core/security/README.md +0 -223
- package/lib/core/security/roleRepository.js +0 -569
- package/lib/core/security/securityLoader.js +0 -174
- package/lib/core/security/userRepository.js +0 -446
- package/lib/core/shared/README.md +0 -3
- package/lib/core/shared/abstractManifest.js +0 -102
- package/lib/core/shared/sdk/impersonatedSdk.js +0 -94
- package/lib/core/statistics/index.js +0 -24
- package/lib/core/statistics/statistics.js +0 -373
- package/lib/core/storage/clientAdapter.js +0 -1045
- package/lib/core/storage/storageEngine.js +0 -63
- package/lib/core/validation/baseType.js +0 -80
- package/lib/core/validation/index.js +0 -24
- package/lib/core/validation/types/date.js +0 -284
- package/lib/core/validation/types/email.js +0 -92
- package/lib/core/validation/types/enum.js +0 -100
- package/lib/core/validation/types/geoShape.js +0 -370
- package/lib/core/validation/types/ipAddress.js +0 -83
- package/lib/core/validation/types/numeric.js +0 -108
- package/lib/core/validation/types/object.js +0 -88
- package/lib/core/validation/types/string.js +0 -110
- package/lib/core/validation/types/url.js +0 -83
- package/lib/core/validation/validation.js +0 -1180
- package/lib/kerror/codes/0-core.json +0 -194
- package/lib/kerror/codes/1-services.json +0 -351
- package/lib/kerror/codes/2-api.json +0 -195
- package/lib/kerror/codes/3-network.json +0 -151
- package/lib/kerror/codes/4-plugin.json +0 -498
- package/lib/kerror/codes/5-validation.json +0 -158
- package/lib/kerror/codes/6-protocol.json +0 -28
- package/lib/kerror/codes/7-security.json +0 -283
- package/lib/kerror/codes/8-cluster.json +0 -16
- package/lib/kerror/codes/index.js +0 -208
- package/lib/kuzzle/dumpGenerator.js +0 -259
- package/lib/kuzzle/event/pipeRunner.js +0 -144
- package/lib/kuzzle/event/waterfall.js +0 -101
- package/lib/kuzzle/internalIndexHandler.js +0 -234
- package/lib/kuzzle/vault.js +0 -89
- package/lib/model/storage/apiKey.js +0 -158
- package/lib/model/storage/baseModel.js +0 -275
- package/lib/service/cache/redis.js +0 -282
- package/lib/service/service.js +0 -84
- package/lib/service/storage/7/esWrapper.js +0 -303
- package/lib/service/storage/8/esWrapper.js +0 -303
- package/lib/util/asyncStore.js +0 -112
- package/lib/util/bytes.js +0 -36
- package/lib/util/deprecate.js +0 -82
- package/lib/util/promback.js +0 -66
- package/lib/util/readYamlFile.d.ts +0 -2
- package/lib/util/readYamlFile.js +0 -10
- package/lib/util/requestAssertions.js +0 -157
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{lib → dist/lib}/api/controllers/baseController.d.ts +0 -0
- /package/{lib → dist/lib}/api/controllers/baseController.js +0 -0
- /package/{lib → dist/lib}/api/controllers/debugController.d.ts +0 -0
- /package/{lib → dist/lib}/api/controllers/debugController.js +0 -0
- /package/{lib → dist/lib}/api/openapi/OpenApiManager.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/OpenApiManager.js +0 -0
- /package/{lib → dist/lib}/api/openapi/index.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/index.js +0 -0
- /package/{lib → dist/lib}/api/openapi/openApiGenerator.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/openApiGenerator.js +0 -0
- /package/{lib → dist/lib}/api/request/index.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/index.js +0 -0
- /package/{lib → dist/lib}/api/request/kuzzleRequest.js +0 -0
- /package/{lib → dist/lib}/api/request/requestContext.js +0 -0
- /package/{lib → dist/lib}/api/request/requestInput.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/requestInput.js +0 -0
- /package/{lib → dist/lib}/api/request/requestResponse.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/requestResponse.js +0 -0
- /package/{lib → dist/lib}/cluster/idCardHandler.d.ts +0 -0
- /package/{lib → dist/lib}/cluster/idCardHandler.js +0 -0
- /package/{lib → dist/lib}/cluster/protobuf/command.proto +0 -0
- /package/{lib → dist/lib}/cluster/protobuf/sync.proto +0 -0
- /package/{lib → dist/lib}/cluster/state.d.ts +0 -0
- /package/{lib → dist/lib}/cluster/state.js +0 -0
- /package/{lib → dist/lib}/config/default.config.d.ts +0 -0
- /package/{lib → dist/lib}/config/default.config.js +0 -0
- /package/{lib → dist/lib}/config/documentEventAliases.js +0 -0
- /package/{lib → dist/lib}/core/auth/tokenManager.d.ts +0 -0
- /package/{lib → dist/lib}/core/auth/tokenManager.js +0 -0
- /package/{lib → dist/lib}/core/backend/applicationManager.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/applicationManager.js +0 -0
- /package/{lib → dist/lib}/core/backend/backend.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backend.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendCluster.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendCluster.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendConfig.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendController.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendController.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendErrors.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendHook.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendHook.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendImport.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendImport.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendOpenApi.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendOpenApi.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendPipe.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendPipe.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendPlugin.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendPlugin.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendStorage.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendStorage.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendSubscription.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendSubscription.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendVault.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendVault.js +0 -0
- /package/{lib → dist/lib}/core/backend/index.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/index.js +0 -0
- /package/{lib → dist/lib}/core/backend/internalLogger.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/internalLogger.js +0 -0
- /package/{lib → dist/lib}/core/cache/cacheDbEnum.d.ts +0 -0
- /package/{lib → dist/lib}/core/cache/cacheDbEnum.js +0 -0
- /package/{lib → dist/lib}/core/debug/kuzzleDebugger.d.ts +0 -0
- /package/{lib → dist/lib}/core/debug/kuzzleDebugger.js +0 -0
- /package/{lib → dist/lib}/core/plugin/pluginContext.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/channel.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/channel.js +0 -0
- /package/{lib → dist/lib}/core/realtime/connectionRooms.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/connectionRooms.js +0 -0
- /package/{lib → dist/lib}/core/realtime/hotelClerk.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/hotelClerk.js +0 -0
- /package/{lib → dist/lib}/core/realtime/room.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/room.js +0 -0
- /package/{lib → dist/lib}/core/realtime/subscription.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/subscription.js +0 -0
- /package/{lib → dist/lib}/core/security/profileRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/security/profileRepository.js +0 -0
- /package/{lib → dist/lib}/core/security/tokenRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/KoncordeWrapper.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/KoncordeWrapper.js +0 -0
- /package/{lib → dist/lib}/core/shared/ObjectRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/ObjectRepository.js +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.js +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.js +0 -0
- /package/{lib → dist/lib}/core/shared/store.js +0 -0
- /package/{lib → dist/lib}/core/storage/indexCache.d.ts +0 -0
- /package/{lib → dist/lib}/core/storage/indexCache.js +0 -0
- /package/{lib → dist/lib}/core/storage/storeScopeEnum.d.ts +0 -0
- /package/{lib → dist/lib}/core/storage/storeScopeEnum.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/badRequestError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/badRequestError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/externalServiceError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/externalServiceError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/forbiddenError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/forbiddenError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/index.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/index.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/internalError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/internalError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/kuzzleError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/kuzzleError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/notFoundError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/notFoundError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/partialError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/partialError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/preconditionError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/preconditionError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/sizeLimitError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/sizeLimitError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/unauthorizedError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/unauthorizedError.js +0 -0
- /package/{lib → dist/lib}/kerror/index.js +0 -0
- /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.d.ts +0 -0
- /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.js +0 -0
- /package/{lib → dist/lib}/kuzzle/index.d.ts +0 -0
- /package/{lib → dist/lib}/kuzzle/index.js +0 -0
- /package/{lib → dist/lib}/model/security/profile.d.ts +0 -0
- /package/{lib → dist/lib}/model/security/profile.js +0 -0
- /package/{lib → dist/lib}/model/security/role.js +0 -0
- /package/{lib → dist/lib}/model/security/token.d.ts +0 -0
- /package/{lib → dist/lib}/model/security/token.js +0 -0
- /package/{lib → dist/lib}/model/security/user.js +0 -0
- /package/{lib → dist/lib}/service/storage/8/elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/service/storage/commons/queryTranslator.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/commons/queryTranslator.js +0 -0
- /package/{lib → dist/lib}/types/ClientConnection.d.ts +0 -0
- /package/{lib → dist/lib}/types/ClientConnection.js +0 -0
- /package/{lib → dist/lib}/types/Deprecation.d.ts +0 -0
- /package/{lib → dist/lib}/types/Deprecation.js +0 -0
- /package/{lib → dist/lib}/types/EventHandler.d.ts +0 -0
- /package/{lib → dist/lib}/types/EventHandler.js +0 -0
- /package/{lib → dist/lib}/types/Global.d.ts +0 -0
- /package/{lib → dist/lib}/types/Global.js +0 -0
- /package/{lib → dist/lib}/types/HttpMessage.d.ts +0 -0
- /package/{lib → dist/lib}/types/HttpMessage.js +0 -0
- /package/{lib → dist/lib}/types/HttpStream.d.ts +0 -0
- /package/{lib → dist/lib}/types/HttpStream.js +0 -0
- /package/{lib → dist/lib}/types/Kuzzle.d.ts +0 -0
- /package/{lib → dist/lib}/types/Kuzzle.js +0 -0
- /package/{lib → dist/lib}/types/KuzzleDocument.d.ts +0 -0
- /package/{lib → dist/lib}/types/KuzzleDocument.js +0 -0
- /package/{lib → dist/lib}/types/OpenApiDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/OpenApiDefinition.js +0 -0
- /package/{lib → dist/lib}/types/PasswordPolicy.d.ts +0 -0
- /package/{lib → dist/lib}/types/PasswordPolicy.js +0 -0
- /package/{lib → dist/lib}/types/Plugin.js +0 -0
- /package/{lib → dist/lib}/types/PluginManifest.d.ts +0 -0
- /package/{lib → dist/lib}/types/PluginManifest.js +0 -0
- /package/{lib → dist/lib}/types/Policy.d.ts +0 -0
- /package/{lib → dist/lib}/types/Policy.js +0 -0
- /package/{lib → dist/lib}/types/PolicyRestrictions.d.ts +0 -0
- /package/{lib → dist/lib}/types/PolicyRestrictions.js +0 -0
- /package/{lib → dist/lib}/types/ProfileDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/ProfileDefinition.js +0 -0
- /package/{lib → dist/lib}/types/RoleDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/RoleDefinition.js +0 -0
- /package/{lib → dist/lib}/types/StrategyDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/StrategyDefinition.js +0 -0
- /package/{lib → dist/lib}/types/Target.d.ts +0 -0
- /package/{lib → dist/lib}/types/Target.js +0 -0
- /package/{lib → dist/lib}/types/Token.d.ts +0 -0
- /package/{lib → dist/lib}/types/Token.js +0 -0
- /package/{lib → dist/lib}/types/User.d.ts +0 -0
- /package/{lib → dist/lib}/types/User.js +0 -0
- /package/{lib → dist/lib}/types/config/DumpConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/DumpConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/HttpConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/HttpConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/KuzzleConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/KuzzleConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/LimitsConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/LimitsConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/PluginsConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/PluginsConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/SecurityConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/SecurityConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/ServerConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/ServerConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/ServicesConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/ServicesConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/Controller.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerRights.d.ts +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerRights.js +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDefinition.js +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDomains.d.ts +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDomains.js +0 -0
- /package/{lib → dist/lib}/types/events/EventGenericDocument.d.ts +0 -0
- /package/{lib → dist/lib}/types/events/EventGenericDocument.js +0 -0
- /package/{lib → dist/lib}/types/events/EventProtocol.d.ts +0 -0
- /package/{lib → dist/lib}/types/events/EventProtocol.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeScope.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeScope.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeUsers.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeUsers.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RoomList.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RoomList.js +0 -0
- /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.js +0 -0
- /package/{lib → dist/lib}/types/storage/7/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/types/storage/7/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/types/storage/8/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/types/storage/8/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/util/Inflector.d.ts +0 -0
- /package/{lib → dist/lib}/util/Inflector.js +0 -0
- /package/{lib → dist/lib}/util/array.d.ts +0 -0
- /package/{lib → dist/lib}/util/array.js +0 -0
- /package/{lib → dist/lib}/util/async.d.ts +0 -0
- /package/{lib → dist/lib}/util/async.js +0 -0
- /package/{lib → dist/lib}/util/bufferedPassThrough.d.ts +0 -0
- /package/{lib → dist/lib}/util/bufferedPassThrough.js +0 -0
- /package/{lib → dist/lib}/util/crypto.d.ts +0 -0
- /package/{lib → dist/lib}/util/crypto.js +0 -0
- /package/{lib → dist/lib}/util/dump-collection.d.ts +0 -0
- /package/{lib → dist/lib}/util/dump-collection.js +0 -0
- /package/{lib → dist/lib}/util/esRequest.d.ts +0 -0
- /package/{lib → dist/lib}/util/esRequest.js +0 -0
- /package/{lib → dist/lib}/util/koncordeCompat.d.ts +0 -0
- /package/{lib → dist/lib}/util/koncordeCompat.js +0 -0
- /package/{lib → dist/lib}/util/mutex.d.ts +0 -0
- /package/{lib → dist/lib}/util/mutex.js +0 -0
- /package/{lib → dist/lib}/util/name-generator.d.ts +0 -0
- /package/{lib → dist/lib}/util/name-generator.js +0 -0
- /package/{lib → dist/lib}/util/time.d.ts +0 -0
- /package/{lib → dist/lib}/util/time.js +0 -0
|
@@ -1,1244 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2022 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
"use strict";
|
|
23
|
-
|
|
24
|
-
const assert = require("assert");
|
|
25
|
-
const path = require("path");
|
|
26
|
-
const fs = require("fs");
|
|
27
|
-
|
|
28
|
-
const Bluebird = require("bluebird");
|
|
29
|
-
const _ = require("lodash");
|
|
30
|
-
|
|
31
|
-
const kerror = require("../../kerror");
|
|
32
|
-
const didYouMean = require("../../util/didYouMean");
|
|
33
|
-
const { Inflector } = require("../../util/Inflector");
|
|
34
|
-
const debug = require("../../util/debug")("kuzzle:plugins");
|
|
35
|
-
const { KuzzleError } = require("../../kerror/errors");
|
|
36
|
-
const { has, get, isPlainObject } = require("../../util/safeObject");
|
|
37
|
-
const { BaseController } = require("../../api/controllers/baseController");
|
|
38
|
-
const Plugin = require("./plugin");
|
|
39
|
-
|
|
40
|
-
const assertionError = kerror.wrap("plugin", "assert");
|
|
41
|
-
const runtimeError = kerror.wrap("plugin", "runtime");
|
|
42
|
-
const strategyError = kerror.wrap("plugin", "strategy");
|
|
43
|
-
const controllerError = kerror.wrap("plugin", "controller");
|
|
44
|
-
|
|
45
|
-
// Without those plugins, Kuzzle won't start at all.
|
|
46
|
-
const CORE_PLUGINS = ["kuzzle-plugin-auth-passport-local"];
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @class PluginsManager
|
|
50
|
-
* @param {Kuzzle} kuzzle
|
|
51
|
-
*/
|
|
52
|
-
class PluginsManager {
|
|
53
|
-
constructor() {
|
|
54
|
-
Reflect.defineProperty(this, "kuzzle", {
|
|
55
|
-
value: global.kuzzle,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
this._plugins = new Map();
|
|
59
|
-
|
|
60
|
-
// Map.<controller, BaseController instance >
|
|
61
|
-
this.controllers = new Map();
|
|
62
|
-
|
|
63
|
-
this.strategies = {};
|
|
64
|
-
this.routes = [];
|
|
65
|
-
|
|
66
|
-
this.pluginsEnabledDir = path.resolve(
|
|
67
|
-
path.join(global.kuzzle.rootPath, "plugins", "enabled"),
|
|
68
|
-
);
|
|
69
|
-
this.pluginsAvailableDir = path.resolve(
|
|
70
|
-
path.join(global.kuzzle.rootPath, "plugins", "available"),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @example
|
|
75
|
-
* {
|
|
76
|
-
* pluginName: {
|
|
77
|
-
* authName: <constructor>,
|
|
78
|
-
* authname2: <constructor>,
|
|
79
|
-
* ...
|
|
80
|
-
* },
|
|
81
|
-
* pluginName2: {
|
|
82
|
-
* ...
|
|
83
|
-
* }
|
|
84
|
-
* }
|
|
85
|
-
*
|
|
86
|
-
* This structure prevents authenticator names collisions between
|
|
87
|
-
* multiple auth. plugins
|
|
88
|
-
*/
|
|
89
|
-
this.authenticators = {};
|
|
90
|
-
|
|
91
|
-
this.config = global.kuzzle.config.plugins;
|
|
92
|
-
|
|
93
|
-
this.logger = global.kuzzle.log.child("core:plugin:pluginsManager");
|
|
94
|
-
|
|
95
|
-
// @deprecated - Warn about the pipeTimeout configuration being obsolete
|
|
96
|
-
if (this.config.common.pipeTimeout) {
|
|
97
|
-
this.logger.warn(
|
|
98
|
-
'The configuration "plugins.common.pipeTimeout" has been deprecated and is now unused. It can be safely removed from configuration files',
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this.loadedPlugins = [];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
set application(plugin) {
|
|
106
|
-
assert(
|
|
107
|
-
this._plugins.size === 0,
|
|
108
|
-
"The application plugin can only be set before every other plugins are loaded",
|
|
109
|
-
);
|
|
110
|
-
assert(
|
|
111
|
-
plugin.application,
|
|
112
|
-
'The application plugin must have the "application" property equals to true',
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
this._plugins.set(plugin.name, plugin);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get plugins() {
|
|
119
|
-
return Array.from(this._plugins.values()).filter(
|
|
120
|
-
(plugin) => !plugin.application,
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
get application() {
|
|
125
|
-
return Array.from(this._plugins.values()).find(
|
|
126
|
-
(plugin) => plugin.application,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Giving a controller name, tells if exists
|
|
132
|
-
*
|
|
133
|
-
* @param {string} controller
|
|
134
|
-
* @returns {Boolean}
|
|
135
|
-
*/
|
|
136
|
-
isController(controller) {
|
|
137
|
-
return this.controllers.has(controller);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Giving a controller name and an action, tells if action exists
|
|
142
|
-
*
|
|
143
|
-
* @param {string} controller
|
|
144
|
-
* @param {string} action
|
|
145
|
-
* @returns {Boolean}
|
|
146
|
-
*/
|
|
147
|
-
isAction(controller, action) {
|
|
148
|
-
return this.getActions(controller).includes(action);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Giving a controller name, returns its actions
|
|
153
|
-
*
|
|
154
|
-
* @param {string} controller
|
|
155
|
-
* @returns {Array}
|
|
156
|
-
*/
|
|
157
|
-
getActions(controller) {
|
|
158
|
-
return Array.from(this.controllers.get(controller)._actions);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Returns an array filled with controller names
|
|
163
|
-
*
|
|
164
|
-
* @returns {Array}
|
|
165
|
-
*/
|
|
166
|
-
getControllerNames() {
|
|
167
|
-
return Array.from(this.controllers.keys());
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Giving a plugin name, tell if it exists
|
|
172
|
-
*
|
|
173
|
-
* @param {string} pluginName
|
|
174
|
-
* @returns {boolean}
|
|
175
|
-
*/
|
|
176
|
-
|
|
177
|
-
exists(pluginName) {
|
|
178
|
-
return this._plugins.has(pluginName);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Used to dump loaded plugin feature into serverInfo route / cli
|
|
183
|
-
*
|
|
184
|
-
* @returns {object}
|
|
185
|
-
*/
|
|
186
|
-
getPluginsDescription() {
|
|
187
|
-
const pluginsDescription = {};
|
|
188
|
-
|
|
189
|
-
for (const plugin of this.plugins) {
|
|
190
|
-
pluginsDescription[plugin.name] = plugin.info();
|
|
191
|
-
|
|
192
|
-
debug(
|
|
193
|
-
"[%s] reading plugin configuration: %a",
|
|
194
|
-
plugin,
|
|
195
|
-
pluginsDescription[plugin.name],
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return pluginsDescription;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Register plugins feature to Kuzzle
|
|
204
|
-
*
|
|
205
|
-
* @returns {Promise}
|
|
206
|
-
*
|
|
207
|
-
* @throws PluginImplementationError - Throws when an error occurs when registering a plugin
|
|
208
|
-
*/
|
|
209
|
-
async init(plugins = {}) {
|
|
210
|
-
this._plugins = new Map([...this.loadPlugins(plugins), ...this._plugins]);
|
|
211
|
-
|
|
212
|
-
global.kuzzle.on("plugin:hook:loop-error", ({ error, pluginName }) => {
|
|
213
|
-
this.logger.error(
|
|
214
|
-
`[${pluginName}] Infinite loop detected on event "hook:onError": ${error}`,
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
global.kuzzle.on("hook:onError", ({ error, event, pluginName }) => {
|
|
219
|
-
this.logger.error(
|
|
220
|
-
`[${pluginName}] Error executing hook on "${event}": ${error}${error.stack}`,
|
|
221
|
-
);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
// register regular plugins features
|
|
225
|
-
const loadPlugins = [];
|
|
226
|
-
const defaultImports = {};
|
|
227
|
-
|
|
228
|
-
for (const plugin of this._plugins.values()) {
|
|
229
|
-
if (
|
|
230
|
-
this.config.common.failsafeMode &&
|
|
231
|
-
!CORE_PLUGINS.includes(plugin.name)
|
|
232
|
-
) {
|
|
233
|
-
this.logger.info(
|
|
234
|
-
`Failsafe mode activated, skipping plugin "${plugin.name}"`,
|
|
235
|
-
);
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (plugin.application) {
|
|
240
|
-
plugin.init(plugin.name);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const { initTimeout } = this.config.common;
|
|
244
|
-
|
|
245
|
-
debug(
|
|
246
|
-
'[%s] starting plugin in "%s" mode',
|
|
247
|
-
plugin.name,
|
|
248
|
-
plugin.config.privileged ? "privileged" : "standard",
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
const promise = Bluebird.resolve(
|
|
252
|
-
(async () => {
|
|
253
|
-
try {
|
|
254
|
-
await plugin.instance.init(plugin.config, plugin.context);
|
|
255
|
-
} catch (error) {
|
|
256
|
-
throw runtimeError.get("failed_init", plugin.name, error);
|
|
257
|
-
}
|
|
258
|
-
})(),
|
|
259
|
-
)
|
|
260
|
-
.timeout(
|
|
261
|
-
initTimeout,
|
|
262
|
-
`${plugin.logPrefix} Initialization timed out after ${initTimeout}ms. Try to increase the configuration "plugins.common.initTimeout".`,
|
|
263
|
-
)
|
|
264
|
-
.then(async () => {
|
|
265
|
-
plugin.initCalled = true;
|
|
266
|
-
|
|
267
|
-
if (
|
|
268
|
-
!_.isEmpty(plugin.instance.controllers) &&
|
|
269
|
-
!_.isEmpty(plugin.instance.api)
|
|
270
|
-
) {
|
|
271
|
-
throw assertionError.get("duplicated_api_definition");
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (!_.isEmpty(plugin.instance.controllers)) {
|
|
275
|
-
this._initControllers(plugin);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (!_.isEmpty(plugin.instance.api)) {
|
|
279
|
-
await this._initApi(plugin);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (!_.isEmpty(plugin.instance.authenticators)) {
|
|
283
|
-
this._initAuthenticators(plugin);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (!_.isEmpty(plugin.instance.strategies)) {
|
|
287
|
-
this._initStrategies(plugin);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (!_.isEmpty(plugin.instance.hooks)) {
|
|
291
|
-
this._initHooks(plugin);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (!_.isEmpty(plugin.instance.pipes)) {
|
|
295
|
-
this._initPipes(plugin);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
debug("[%s] plugin started", plugin.name);
|
|
299
|
-
|
|
300
|
-
if (!plugin.application) {
|
|
301
|
-
this.loadedPlugins.push(plugin.name);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (!_.isEmpty(plugin.instance.imports)) {
|
|
305
|
-
_.merge(defaultImports, plugin.instance.imports);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return null;
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
loadPlugins.push(promise);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
await Promise.all(loadPlugins);
|
|
315
|
-
|
|
316
|
-
this.logger.info(
|
|
317
|
-
`[✔] Successfully loaded ${
|
|
318
|
-
this.loadedPlugins.length
|
|
319
|
-
} plugins: ${this.loadedPlugins.join(", ")}`,
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
return defaultImports;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* @param {string} strategyName
|
|
327
|
-
* @returns {string[]}
|
|
328
|
-
*/
|
|
329
|
-
getStrategyFields(strategyName) {
|
|
330
|
-
return this.strategies[strategyName].strategy.config.fields || [];
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* @param {string} strategyName
|
|
335
|
-
* @param {string} methodName
|
|
336
|
-
* @returns {boolean}
|
|
337
|
-
*/
|
|
338
|
-
hasStrategyMethod(strategyName, methodName) {
|
|
339
|
-
const strategy = get(this.strategies, strategyName);
|
|
340
|
-
return strategy && has(strategy.methods, methodName);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* @param {string} strategyName
|
|
345
|
-
* @param {string} methodName
|
|
346
|
-
* @returns {function}
|
|
347
|
-
*/
|
|
348
|
-
getStrategyMethod(strategyName, methodName) {
|
|
349
|
-
return this.strategies[strategyName].methods[methodName];
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Returns the list of registered passport strategies
|
|
354
|
-
* @returns {string[]}
|
|
355
|
-
*/
|
|
356
|
-
listStrategies() {
|
|
357
|
-
return Object.keys(this.strategies);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Checks if a strategy is well-formed
|
|
362
|
-
*
|
|
363
|
-
* @param {string} pluginName
|
|
364
|
-
* @param {string} strategyName
|
|
365
|
-
* @param {object} strategy
|
|
366
|
-
* @throws {PluginImplementationError} If the strategy is invalid
|
|
367
|
-
*/
|
|
368
|
-
validateStrategy(pluginName, strategyName, strategy) {
|
|
369
|
-
const errorPrefix = `[${pluginName}] Strategy ${strategyName}:`;
|
|
370
|
-
|
|
371
|
-
if (!isPlainObject(strategy)) {
|
|
372
|
-
throw strategyError.get("invalid_description", errorPrefix, strategy);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (!isPlainObject(strategy.methods)) {
|
|
376
|
-
throw strategyError.get("invalid_methods", errorPrefix, strategy.methods);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const plugin = this._plugins.get(pluginName.toLowerCase());
|
|
380
|
-
|
|
381
|
-
// required methods check
|
|
382
|
-
["exists", "create", "update", "delete", "validate", "verify"].forEach(
|
|
383
|
-
(methodName) => {
|
|
384
|
-
if (!_.isString(strategy.methods[methodName])) {
|
|
385
|
-
throw strategyError.get(
|
|
386
|
-
"invalid_method_type",
|
|
387
|
-
errorPrefix,
|
|
388
|
-
methodName,
|
|
389
|
-
strategy.methods[methodName],
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
if (!_.isFunction(plugin.instance[strategy.methods[methodName]])) {
|
|
394
|
-
throw strategyError.get(
|
|
395
|
-
"missing_method_function",
|
|
396
|
-
errorPrefix,
|
|
397
|
-
strategy.methods[methodName],
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
},
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
// optional methods check
|
|
404
|
-
["getInfo", "getById", "afterRegister"].forEach((name) => {
|
|
405
|
-
const optionalMethodName = strategy.methods[name];
|
|
406
|
-
|
|
407
|
-
if (!_.isNil(optionalMethodName)) {
|
|
408
|
-
if (!_.isString(optionalMethodName)) {
|
|
409
|
-
throw strategyError.get(
|
|
410
|
-
"invalid_method_type",
|
|
411
|
-
errorPrefix,
|
|
412
|
-
name,
|
|
413
|
-
optionalMethodName,
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (!_.isFunction(plugin.instance[optionalMethodName])) {
|
|
418
|
-
throw strategyError.get(
|
|
419
|
-
"missing_method_function",
|
|
420
|
-
errorPrefix,
|
|
421
|
-
optionalMethodName,
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
if (!isPlainObject(strategy.config)) {
|
|
428
|
-
throw strategyError.get("invalid_config", errorPrefix, strategy.config);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
if (typeof strategy.config.authenticator !== "string") {
|
|
432
|
-
throw strategyError.get(
|
|
433
|
-
"invalid_authenticator",
|
|
434
|
-
errorPrefix,
|
|
435
|
-
strategy.config.authenticator,
|
|
436
|
-
);
|
|
437
|
-
} else if (
|
|
438
|
-
!this.authenticators[pluginName] ||
|
|
439
|
-
!this.authenticators[pluginName][strategy.config.authenticator]
|
|
440
|
-
) {
|
|
441
|
-
throw strategyError.get(
|
|
442
|
-
"unknown_authenticator",
|
|
443
|
-
errorPrefix,
|
|
444
|
-
strategy.config.authenticator,
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
for (const optionName of ["strategyOptions", "authenticateOptions"]) {
|
|
449
|
-
const options = strategy.config[optionName];
|
|
450
|
-
|
|
451
|
-
if (!_.isNil(options) && !isPlainObject(options)) {
|
|
452
|
-
throw strategyError.get(
|
|
453
|
-
"invalid_option",
|
|
454
|
-
errorPrefix,
|
|
455
|
-
optionName,
|
|
456
|
-
options,
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (
|
|
462
|
-
!_.isNil(strategy.config.fields) &&
|
|
463
|
-
!Array.isArray(strategy.config.fields)
|
|
464
|
-
) {
|
|
465
|
-
throw strategyError.get(
|
|
466
|
-
"invalid_fields",
|
|
467
|
-
errorPrefix,
|
|
468
|
-
strategy.config.fields,
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Register a pipe function on an event
|
|
475
|
-
*
|
|
476
|
-
* @param {object} plugin
|
|
477
|
-
* @param {number} warnDelay - delay before a warning is issued
|
|
478
|
-
* @param {string} event name
|
|
479
|
-
* @param {Function} handler - function to attach
|
|
480
|
-
*
|
|
481
|
-
* @returns {string} pipeId
|
|
482
|
-
*/
|
|
483
|
-
registerPipe(plugin, event, handler) {
|
|
484
|
-
debug('[%s] registering pipe on event "%s"', plugin.name, event);
|
|
485
|
-
|
|
486
|
-
const warnDelay =
|
|
487
|
-
plugin.config.pipeWarnTime !== undefined
|
|
488
|
-
? plugin.config.pipeWarnTime
|
|
489
|
-
: this.config.common.pipeWarnTime;
|
|
490
|
-
|
|
491
|
-
const wrapper = (...data) => {
|
|
492
|
-
const now = warnDelay ? Date.now() : null;
|
|
493
|
-
const callback = data.pop();
|
|
494
|
-
|
|
495
|
-
const cb = (error, result) => {
|
|
496
|
-
if (warnDelay) {
|
|
497
|
-
const elapsed = Date.now() - now;
|
|
498
|
-
|
|
499
|
-
if (elapsed > warnDelay) {
|
|
500
|
-
this.logger.warn(
|
|
501
|
-
`${plugin.logPrefix} pipe for event '${event}' is slow (${elapsed}ms)`,
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
callback(error, result);
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
try {
|
|
510
|
-
const pipeResponse =
|
|
511
|
-
data.length === 0 ? handler(null, cb) : handler(...data, cb);
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
typeof pipeResponse === "object" &&
|
|
515
|
-
pipeResponse !== null &&
|
|
516
|
-
typeof pipeResponse.then === "function" &&
|
|
517
|
-
typeof pipeResponse.catch === "function"
|
|
518
|
-
) {
|
|
519
|
-
pipeResponse
|
|
520
|
-
.then((result) => {
|
|
521
|
-
cb(null, result);
|
|
522
|
-
return null; // prevents a false-positive bluebird warning
|
|
523
|
-
})
|
|
524
|
-
.catch((error) => cb(error));
|
|
525
|
-
}
|
|
526
|
-
} catch (error) {
|
|
527
|
-
cb(
|
|
528
|
-
error instanceof KuzzleError
|
|
529
|
-
? error
|
|
530
|
-
: runtimeError.getFrom(error, "unexpected_error", error.message),
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
return global.kuzzle.registerPluginPipe(event, wrapper);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
unregisterPipe(pipeId) {
|
|
539
|
-
global.kuzzle.unregisterPluginPipe(pipeId);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Registers an authentication strategy.
|
|
544
|
-
* If the plugin init method has not been called yet, add the strategy to
|
|
545
|
-
* the plugin.instance.strategies object.
|
|
546
|
-
*
|
|
547
|
-
* @param {string} pluginName - plugin name
|
|
548
|
-
* @param {string} strategyName - strategy name
|
|
549
|
-
* @param {object} strategy - strategy properties
|
|
550
|
-
* @throws {PluginImplementationError} If the strategy is invalid or if
|
|
551
|
-
* registration fails
|
|
552
|
-
*/
|
|
553
|
-
registerStrategy(pluginName, strategyName, strategy) {
|
|
554
|
-
// prior to Kaaf, plugin names can contains upper case
|
|
555
|
-
const plugin = this._plugins.get(pluginName.toLowerCase());
|
|
556
|
-
|
|
557
|
-
// only add the strategy to the strategies object if the init method
|
|
558
|
-
// has not been called
|
|
559
|
-
if (!plugin.initCalled) {
|
|
560
|
-
plugin.instance.strategies = plugin.instance.strategies || {};
|
|
561
|
-
plugin.instance.strategies[strategyName] = strategy;
|
|
562
|
-
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
this.validateStrategy(plugin.name, strategyName, strategy);
|
|
567
|
-
|
|
568
|
-
if (has(this.strategies, strategyName)) {
|
|
569
|
-
this.unregisterStrategy(plugin.name, strategyName);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
const methods = {};
|
|
573
|
-
|
|
574
|
-
// wrap plugin methods to force their context and to
|
|
575
|
-
// convert uncaught exception into PluginImplementationError
|
|
576
|
-
// promise rejections
|
|
577
|
-
for (const methodName of Object.keys(strategy.methods).filter(
|
|
578
|
-
(name) => name !== "verify",
|
|
579
|
-
)) {
|
|
580
|
-
methods[methodName] = async (...args) => {
|
|
581
|
-
try {
|
|
582
|
-
const boundFunction = plugin.instance[
|
|
583
|
-
strategy.methods[methodName]
|
|
584
|
-
].bind(plugin.instance);
|
|
585
|
-
|
|
586
|
-
return await boundFunction(...args);
|
|
587
|
-
} catch (error) {
|
|
588
|
-
if (error instanceof KuzzleError) {
|
|
589
|
-
throw error;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
throw runtimeError.getFrom(error, "unexpected_error", error.message);
|
|
593
|
-
}
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
const opts = {
|
|
598
|
-
...strategy.config.strategyOptions,
|
|
599
|
-
passReqToCallback: true,
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
const verifyAdapter = this.wrapStrategyVerify(
|
|
603
|
-
plugin.logPrefix,
|
|
604
|
-
strategyName,
|
|
605
|
-
plugin.instance[strategy.methods.verify].bind(plugin.instance),
|
|
606
|
-
);
|
|
607
|
-
|
|
608
|
-
try {
|
|
609
|
-
const Ctor =
|
|
610
|
-
this.authenticators[plugin.name][strategy.config.authenticator],
|
|
611
|
-
instance = new Ctor(opts, verifyAdapter);
|
|
612
|
-
|
|
613
|
-
this.strategies[strategyName] = { methods, owner: plugin.name, strategy };
|
|
614
|
-
global.kuzzle.passport.use(
|
|
615
|
-
strategyName,
|
|
616
|
-
instance,
|
|
617
|
-
strategy.config.authenticateOptions,
|
|
618
|
-
);
|
|
619
|
-
|
|
620
|
-
if (methods.afterRegister) {
|
|
621
|
-
methods.afterRegister(instance);
|
|
622
|
-
}
|
|
623
|
-
} catch (e) {
|
|
624
|
-
throw strategyError.getFrom(
|
|
625
|
-
e,
|
|
626
|
-
"failed_registration",
|
|
627
|
-
strategyName,
|
|
628
|
-
e.message,
|
|
629
|
-
);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* Unregister
|
|
635
|
-
* @param {string} pluginName
|
|
636
|
-
* @param {string} strategyName
|
|
637
|
-
* @throws {PluginImplementationError} If not the owner of the strategy or if strategy
|
|
638
|
-
* does not exist
|
|
639
|
-
*/
|
|
640
|
-
unregisterStrategy(pluginName, strategyName) {
|
|
641
|
-
const strategy = this.strategies[strategyName];
|
|
642
|
-
|
|
643
|
-
if (strategy) {
|
|
644
|
-
if (strategy.owner !== pluginName) {
|
|
645
|
-
throw strategyError.get("unauthorized_removal", strategyName);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
delete this.strategies[strategyName];
|
|
649
|
-
global.kuzzle.passport.unuse(strategyName);
|
|
650
|
-
} else {
|
|
651
|
-
throw strategyError.get("strategy_not_found", strategyName);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* @param {object} plugin
|
|
657
|
-
* @param {number} pipeWarnTime
|
|
658
|
-
*/
|
|
659
|
-
_initPipes(plugin) {
|
|
660
|
-
const methodsList = getMethods(plugin.instance);
|
|
661
|
-
|
|
662
|
-
for (const [event, fn] of Object.entries(plugin.instance.pipes)) {
|
|
663
|
-
const list = Array.isArray(fn) ? fn : [fn];
|
|
664
|
-
|
|
665
|
-
for (const target of list) {
|
|
666
|
-
if (
|
|
667
|
-
typeof target !== "function" &&
|
|
668
|
-
typeof plugin.instance[target] !== "function"
|
|
669
|
-
) {
|
|
670
|
-
const message =
|
|
671
|
-
typeof target === "string" ? didYouMean(target, methodsList) : "";
|
|
672
|
-
|
|
673
|
-
throw assertionError.get("invalid_pipe", event, target, message);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
let handler = target;
|
|
677
|
-
|
|
678
|
-
if (typeof target === "string") {
|
|
679
|
-
// @deprecated - warn about using a string representing an instance method
|
|
680
|
-
plugin.printDeprecation(
|
|
681
|
-
"Defining pipe handler using a string is deprecated. Pass a function instead.",
|
|
682
|
-
);
|
|
683
|
-
|
|
684
|
-
handler = plugin.instance[target].bind(plugin.instance);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
// if the function handler is a plugin instance method,
|
|
688
|
-
// bound the context to the plugin instance
|
|
689
|
-
if (target.name && typeof plugin.instance[target.name] === "function") {
|
|
690
|
-
handler = target.bind(plugin.instance);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
this.registerPipe(plugin, event, handler);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
/**
|
|
699
|
-
* @param {object} plugin
|
|
700
|
-
*/
|
|
701
|
-
_initHooks(plugin) {
|
|
702
|
-
const methodsList = getMethods(plugin.instance);
|
|
703
|
-
|
|
704
|
-
for (const [event, fn] of Object.entries(plugin.instance.hooks)) {
|
|
705
|
-
const list = Array.isArray(fn) ? fn : [fn];
|
|
706
|
-
|
|
707
|
-
for (const target of list) {
|
|
708
|
-
if (
|
|
709
|
-
typeof target !== "function" &&
|
|
710
|
-
typeof plugin.instance[target] !== "function"
|
|
711
|
-
) {
|
|
712
|
-
const message =
|
|
713
|
-
typeof target === "string" ? didYouMean(target, methodsList) : "";
|
|
714
|
-
|
|
715
|
-
throw assertionError.get("invalid_hook", event, target, message);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
debug('[%s] register hook on event "%s"', plugin.name, event);
|
|
719
|
-
|
|
720
|
-
let handler = target;
|
|
721
|
-
|
|
722
|
-
// @deprecated - warn about using a string representing an instance method
|
|
723
|
-
if (typeof target === "string") {
|
|
724
|
-
plugin.printDeprecation(
|
|
725
|
-
"Defining hook handler using a string is deprecated. Pass a function instead.",
|
|
726
|
-
);
|
|
727
|
-
|
|
728
|
-
handler = plugin.instance[target].bind(plugin.instance);
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
// if the function handler is a plugin instance method,
|
|
732
|
-
// bound the context to the plugin instance
|
|
733
|
-
if (target.name && typeof plugin.instance[target.name] === "function") {
|
|
734
|
-
handler = target.bind(plugin.instance);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
global.kuzzle.registerPluginHook(plugin.name, event, handler);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
async _initApi(plugin) {
|
|
743
|
-
for (const [controller, definition] of Object.entries(
|
|
744
|
-
plugin.instance.api,
|
|
745
|
-
)) {
|
|
746
|
-
debug(
|
|
747
|
-
"[%s][%s] starting api controller registration",
|
|
748
|
-
plugin.name,
|
|
749
|
-
controller,
|
|
750
|
-
);
|
|
751
|
-
|
|
752
|
-
if (
|
|
753
|
-
await global.kuzzle.ask(
|
|
754
|
-
"kuzzle:api:funnel:controller:isNative",
|
|
755
|
-
controller,
|
|
756
|
-
)
|
|
757
|
-
) {
|
|
758
|
-
throw assertionError.get(
|
|
759
|
-
"invalid_controller_definition",
|
|
760
|
-
controller,
|
|
761
|
-
"Native controllers cannot be overriden",
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
Plugin.checkControllerDefinition(controller, definition);
|
|
766
|
-
|
|
767
|
-
for (const [action, actionDefinition] of Object.entries(
|
|
768
|
-
definition.actions,
|
|
769
|
-
)) {
|
|
770
|
-
let apiController = this.controllers.get(controller);
|
|
771
|
-
|
|
772
|
-
if (!apiController) {
|
|
773
|
-
apiController = new BaseController();
|
|
774
|
-
this.controllers.set(controller, apiController);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
let handler = actionDefinition.handler;
|
|
778
|
-
|
|
779
|
-
// if the function handler is a plugin instance method,
|
|
780
|
-
// bind the context to the plugin instance
|
|
781
|
-
if (
|
|
782
|
-
handler.name &&
|
|
783
|
-
typeof plugin.instance[handler.name] === "function"
|
|
784
|
-
) {
|
|
785
|
-
handler = handler.bind(plugin.instance);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
apiController._addAction(action, handler);
|
|
789
|
-
|
|
790
|
-
const httpRoutes = actionDefinition.http || [];
|
|
791
|
-
|
|
792
|
-
// Define default HTTP route if none have been provided
|
|
793
|
-
if (httpRoutes.length === 0) {
|
|
794
|
-
httpRoutes.push({
|
|
795
|
-
path: `${Inflector.kebabCase(controller)}/${Inflector.kebabCase(
|
|
796
|
-
action,
|
|
797
|
-
)}`,
|
|
798
|
-
verb: "get",
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
for (const httpRoute of httpRoutes) {
|
|
803
|
-
debug(
|
|
804
|
-
'[%s] binding HTTP route "%s" to controller "%s"',
|
|
805
|
-
plugin.name,
|
|
806
|
-
httpRoute.path,
|
|
807
|
-
controller,
|
|
808
|
-
);
|
|
809
|
-
|
|
810
|
-
const routePath =
|
|
811
|
-
httpRoute.path.charAt(0) === "/"
|
|
812
|
-
? httpRoute.path
|
|
813
|
-
: `/_/${httpRoute.path}`;
|
|
814
|
-
|
|
815
|
-
this.routes.push({
|
|
816
|
-
action,
|
|
817
|
-
controller,
|
|
818
|
-
openapi: httpRoute.openapi,
|
|
819
|
-
path: routePath,
|
|
820
|
-
verb: httpRoute.verb,
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
/**
|
|
828
|
-
* Init plugin controllers
|
|
829
|
-
*
|
|
830
|
-
* @param {object} plugin
|
|
831
|
-
* @returns {boolean}
|
|
832
|
-
*/
|
|
833
|
-
_initControllers(plugin) {
|
|
834
|
-
// @deprecated - warn about using the obsolete "controllers" object
|
|
835
|
-
if (!_.isEmpty(plugin.instance.controllers)) {
|
|
836
|
-
plugin.printDeprecation(
|
|
837
|
-
'Defining controllers using the "controllers" object is deprecated. You should use the "api" object instead.',
|
|
838
|
-
);
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
for (const controller of Object.keys(plugin.instance.controllers)) {
|
|
842
|
-
debug(
|
|
843
|
-
"[%s][%s] starting controller registration",
|
|
844
|
-
plugin.name,
|
|
845
|
-
controller,
|
|
846
|
-
);
|
|
847
|
-
|
|
848
|
-
const methodsList = getMethods(plugin.instance);
|
|
849
|
-
const controllerName = `${plugin.name}/${controller}`;
|
|
850
|
-
const definition = plugin.instance.controllers[controller];
|
|
851
|
-
const errorControllerPrefix = `Unable to inject controller "${controller}" from plugin "${plugin.name}":`;
|
|
852
|
-
|
|
853
|
-
if (!isPlainObject(definition)) {
|
|
854
|
-
// @todo deprecate all those errors and use plugin.assert.invalid_controller_definition
|
|
855
|
-
throw controllerError.get(
|
|
856
|
-
"invalid_description",
|
|
857
|
-
errorControllerPrefix,
|
|
858
|
-
typeof definition,
|
|
859
|
-
);
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
for (const action of Object.keys(definition)) {
|
|
863
|
-
debug(
|
|
864
|
-
"[%s][%s][%s] starting action controller registration",
|
|
865
|
-
plugin.name,
|
|
866
|
-
controller,
|
|
867
|
-
action,
|
|
868
|
-
);
|
|
869
|
-
|
|
870
|
-
if (
|
|
871
|
-
typeof definition[action] !== "function" &&
|
|
872
|
-
typeof plugin.instance[definition[action]] !== "function"
|
|
873
|
-
) {
|
|
874
|
-
const suggestion =
|
|
875
|
-
typeof definition[action] === "string"
|
|
876
|
-
? didYouMean(definition[action], methodsList)
|
|
877
|
-
: "";
|
|
878
|
-
|
|
879
|
-
throw controllerError.get(
|
|
880
|
-
"invalid_action",
|
|
881
|
-
errorControllerPrefix,
|
|
882
|
-
controller,
|
|
883
|
-
action,
|
|
884
|
-
suggestion,
|
|
885
|
-
);
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
let apiController = this.controllers.get(controllerName);
|
|
889
|
-
|
|
890
|
-
if (!apiController) {
|
|
891
|
-
apiController = new BaseController();
|
|
892
|
-
this.controllers.set(controllerName, apiController);
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
if (typeof definition[action] === "function") {
|
|
896
|
-
apiController._addAction(action, definition[action]);
|
|
897
|
-
} else {
|
|
898
|
-
apiController._addAction(
|
|
899
|
-
action,
|
|
900
|
-
plugin.instance[definition[action]].bind(plugin.instance),
|
|
901
|
-
);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
const httpVerbs = [
|
|
907
|
-
"get",
|
|
908
|
-
"head",
|
|
909
|
-
"post",
|
|
910
|
-
"put",
|
|
911
|
-
"delete",
|
|
912
|
-
"patch",
|
|
913
|
-
"options",
|
|
914
|
-
];
|
|
915
|
-
const routeProperties = ["verb", "url", "controller", "action", "path"];
|
|
916
|
-
const controllerNames = Object.keys(plugin.instance.controllers);
|
|
917
|
-
|
|
918
|
-
// @deprecated - warn about using the obsolete "routes" object
|
|
919
|
-
if (!_.isEmpty(plugin.instance.routes)) {
|
|
920
|
-
plugin.printDeprecation(
|
|
921
|
-
'Defining routes using the "routes" object is deprecated. You should use the "api" object instead.',
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
for (const route of plugin.instance.routes || []) {
|
|
926
|
-
const controller = `${plugin.name}/${route.controller}`;
|
|
927
|
-
const errorRoutePrefix = `Unable to inject API route "${JSON.stringify(
|
|
928
|
-
route,
|
|
929
|
-
)}" from plugin "${plugin.name}":`;
|
|
930
|
-
|
|
931
|
-
for (const key of Object.keys(route)) {
|
|
932
|
-
if (routeProperties.indexOf(key) === -1) {
|
|
933
|
-
throw controllerError.get(
|
|
934
|
-
"unexpected_route_property",
|
|
935
|
-
errorRoutePrefix,
|
|
936
|
-
key,
|
|
937
|
-
didYouMean(key, routeProperties),
|
|
938
|
-
);
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
if (
|
|
942
|
-
typeof route[key] !== "string" ||
|
|
943
|
-
(route[key].length === 0 && key !== "url")
|
|
944
|
-
) {
|
|
945
|
-
throw controllerError.get(
|
|
946
|
-
"invalid_route_property",
|
|
947
|
-
errorRoutePrefix,
|
|
948
|
-
key,
|
|
949
|
-
);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
const apiController = this.controllers.get(controller);
|
|
954
|
-
|
|
955
|
-
if (!apiController) {
|
|
956
|
-
throw controllerError.get(
|
|
957
|
-
"undefined_controller",
|
|
958
|
-
errorRoutePrefix,
|
|
959
|
-
route.controller,
|
|
960
|
-
didYouMean(route.controller, controllerNames),
|
|
961
|
-
);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
if (!apiController._isAction(route.action)) {
|
|
965
|
-
const actionNames = Array.from(apiController._actions);
|
|
966
|
-
throw controllerError.get(
|
|
967
|
-
"undefined_action",
|
|
968
|
-
errorRoutePrefix,
|
|
969
|
-
route.action,
|
|
970
|
-
didYouMean(route.action, actionNames),
|
|
971
|
-
);
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
if (httpVerbs.indexOf(route.verb.toLowerCase()) === -1) {
|
|
975
|
-
throw controllerError.get(
|
|
976
|
-
"unsupported_verb",
|
|
977
|
-
errorRoutePrefix,
|
|
978
|
-
httpVerbs.join(", "),
|
|
979
|
-
didYouMean(route.verb, httpVerbs),
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
// @deprecated route.url is deprecated
|
|
984
|
-
if (route.url) {
|
|
985
|
-
plugin.printDeprecation(
|
|
986
|
-
'Usage of "url" property for routes is deprecated. Use "path" instead.',
|
|
987
|
-
);
|
|
988
|
-
}
|
|
989
|
-
route.path = route.path || route.url;
|
|
990
|
-
|
|
991
|
-
debug(
|
|
992
|
-
'[%s] binding HTTP route "%s" to controller "%s"',
|
|
993
|
-
plugin.name,
|
|
994
|
-
route.path,
|
|
995
|
-
route.controller,
|
|
996
|
-
);
|
|
997
|
-
|
|
998
|
-
// @deprecated "/_plugin" prefix is deprecated for plugin routes
|
|
999
|
-
this.routes.push({
|
|
1000
|
-
action: route.action,
|
|
1001
|
-
controller,
|
|
1002
|
-
path: `/_plugin/${plugin.name}${route.path}`,
|
|
1003
|
-
verb: route.verb,
|
|
1004
|
-
});
|
|
1005
|
-
|
|
1006
|
-
const routePath =
|
|
1007
|
-
route.path.charAt(0) === "/"
|
|
1008
|
-
? `/_${route.path}`
|
|
1009
|
-
: `/_/${plugin.name}/${route.path}`;
|
|
1010
|
-
|
|
1011
|
-
this.routes.push({
|
|
1012
|
-
action: route.action,
|
|
1013
|
-
controller,
|
|
1014
|
-
path: routePath,
|
|
1015
|
-
verb: route.verb,
|
|
1016
|
-
});
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
/**
|
|
1021
|
-
* @param {object} plugin
|
|
1022
|
-
* @throws {PluginImplementationError} If strategies registration fails
|
|
1023
|
-
*/
|
|
1024
|
-
_initStrategies(plugin) {
|
|
1025
|
-
if (
|
|
1026
|
-
!isPlainObject(plugin.instance.strategies) ||
|
|
1027
|
-
_.isEmpty(plugin.instance.strategies)
|
|
1028
|
-
) {
|
|
1029
|
-
throw strategyError.get("invalid_definition", plugin.logPrefix);
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
for (const name of Object.keys(plugin.instance.strategies)) {
|
|
1033
|
-
this.registerStrategy(
|
|
1034
|
-
plugin.name,
|
|
1035
|
-
name,
|
|
1036
|
-
plugin.instance.strategies[name],
|
|
1037
|
-
);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
/**
|
|
1042
|
-
* @param {object} plugin
|
|
1043
|
-
* @throws {PluginImplementationError} If strategies registration fails
|
|
1044
|
-
*/
|
|
1045
|
-
_initAuthenticators(plugin) {
|
|
1046
|
-
if (!isPlainObject(plugin.instance.authenticators)) {
|
|
1047
|
-
throw kerror.get(
|
|
1048
|
-
"plugin",
|
|
1049
|
-
"authenticators",
|
|
1050
|
-
"not_an_object",
|
|
1051
|
-
plugin.logPrefix,
|
|
1052
|
-
);
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
for (const authenticator of Object.keys(plugin.instance.authenticators)) {
|
|
1056
|
-
if (!isConstructor(plugin.instance.authenticators[authenticator])) {
|
|
1057
|
-
throw kerror.get(
|
|
1058
|
-
"plugin",
|
|
1059
|
-
"authenticators",
|
|
1060
|
-
"invalid_authenticator",
|
|
1061
|
-
plugin.logPrefix,
|
|
1062
|
-
authenticator,
|
|
1063
|
-
);
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
this.authenticators[plugin.name] = Object.assign(
|
|
1068
|
-
{},
|
|
1069
|
-
plugin.instance.authenticators,
|
|
1070
|
-
);
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
/**
|
|
1074
|
-
* Load detected plugins in memory
|
|
1075
|
-
*
|
|
1076
|
-
* @returns {object} list of loaded plugin
|
|
1077
|
-
*/
|
|
1078
|
-
loadPlugins(plugins = {}) {
|
|
1079
|
-
const loadedPlugins = new Map();
|
|
1080
|
-
|
|
1081
|
-
// first load plugins from Backend.plugin.use
|
|
1082
|
-
for (const [name, { plugin: instance, options }] of Object.entries(
|
|
1083
|
-
plugins,
|
|
1084
|
-
)) {
|
|
1085
|
-
const plugin = new Plugin(instance, { name, ...options });
|
|
1086
|
-
|
|
1087
|
-
// the plugin cluster can be loaded in the startup script
|
|
1088
|
-
// and we need the manifest
|
|
1089
|
-
plugin.manifest = plugin.manifest || options.manifest;
|
|
1090
|
-
|
|
1091
|
-
plugin.init(name);
|
|
1092
|
-
|
|
1093
|
-
if (loadedPlugins.has(plugin.name)) {
|
|
1094
|
-
throw assertionError.get("name_already_exists", plugin.name);
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
loadedPlugins.set(plugin.name, plugin);
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
// then try to load plugins from the filesystem
|
|
1101
|
-
if (!fs.existsSync(this.pluginsEnabledDir)) {
|
|
1102
|
-
return loadedPlugins;
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
let pluginsPath = [];
|
|
1106
|
-
|
|
1107
|
-
try {
|
|
1108
|
-
pluginsPath = fs
|
|
1109
|
-
.readdirSync(this.pluginsEnabledDir)
|
|
1110
|
-
.map((name) => path.join(this.pluginsEnabledDir, name))
|
|
1111
|
-
.filter((filePath) => fs.statSync(filePath).isDirectory());
|
|
1112
|
-
} catch (e) {
|
|
1113
|
-
throw assertionError.get(
|
|
1114
|
-
"invalid_plugins_dir",
|
|
1115
|
-
this.pluginsEnabledDir,
|
|
1116
|
-
e.message,
|
|
1117
|
-
);
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
debug("loading plugins: %a", pluginsPath);
|
|
1121
|
-
|
|
1122
|
-
for (const relativePluginPath of pluginsPath) {
|
|
1123
|
-
const plugin = Plugin.loadFromDirectory(relativePluginPath);
|
|
1124
|
-
|
|
1125
|
-
plugin.init(plugin.manifest.raw.name);
|
|
1126
|
-
|
|
1127
|
-
if (loadedPlugins.has(plugin.name)) {
|
|
1128
|
-
throw assertionError.get("name_already_exists", plugin.name);
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
loadedPlugins.set(plugin.name, plugin);
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
return loadedPlugins;
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
/**
|
|
1138
|
-
* Wraps a strategy plugin's verify function.
|
|
1139
|
-
*
|
|
1140
|
-
* @param {String} pluginName
|
|
1141
|
-
* @param {String} strategyName
|
|
1142
|
-
* @param {Function} verifyMethod - Strategy plugin's verify method
|
|
1143
|
-
* @returns {Function}
|
|
1144
|
-
*/
|
|
1145
|
-
wrapStrategyVerify(pluginName, strategyName, verifyMethod) {
|
|
1146
|
-
const prefix = `${pluginName} Strategy ${strategyName}:`;
|
|
1147
|
-
|
|
1148
|
-
return async (...args) => {
|
|
1149
|
-
const callback = args[args.length - 1];
|
|
1150
|
-
const ret = verifyMethod(...args.slice(0, -1));
|
|
1151
|
-
|
|
1152
|
-
// catching plugins returning non-thenable content
|
|
1153
|
-
// @todo - with async/await we might consider allowing non-promise results
|
|
1154
|
-
if (!ret || !_.isFunction(ret.then)) {
|
|
1155
|
-
callback(strategyError.get("invalid_verify_return", prefix, ret));
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
let result;
|
|
1160
|
-
|
|
1161
|
-
try {
|
|
1162
|
-
result = await ret;
|
|
1163
|
-
} catch (e) {
|
|
1164
|
-
callback(e);
|
|
1165
|
-
return;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
if (result === false) {
|
|
1169
|
-
callback(null, result, { message: null });
|
|
1170
|
-
return;
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
if (!isPlainObject(result)) {
|
|
1174
|
-
callback(strategyError.get("invalid_verify_resolve", prefix));
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
if (result.kuid !== null && result.kuid !== undefined) {
|
|
1179
|
-
if (typeof result.kuid === "string") {
|
|
1180
|
-
try {
|
|
1181
|
-
const user = await global.kuzzle.ask(
|
|
1182
|
-
"core:security:user:get",
|
|
1183
|
-
result.kuid,
|
|
1184
|
-
);
|
|
1185
|
-
|
|
1186
|
-
callback(null, user);
|
|
1187
|
-
} catch (e) {
|
|
1188
|
-
if (e.id === "security.user.not_found") {
|
|
1189
|
-
callback(strategyError.get("unknown_kuid", prefix));
|
|
1190
|
-
} else {
|
|
1191
|
-
callback(e);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
return;
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
callback(strategyError.get("invalid_kuid", prefix, typeof result.kuid));
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
let message;
|
|
1203
|
-
if (result.message && typeof result.message === "string") {
|
|
1204
|
-
message = result.message;
|
|
1205
|
-
} else {
|
|
1206
|
-
message = `Unable to log in using the strategy "${strategyName}"`;
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
callback(null, false, { message });
|
|
1210
|
-
};
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* Test if the provided argument is a constructor or not
|
|
1216
|
-
*
|
|
1217
|
-
* @param {*} arg
|
|
1218
|
-
* @returns {Boolean}
|
|
1219
|
-
*/
|
|
1220
|
-
function isConstructor(arg) {
|
|
1221
|
-
try {
|
|
1222
|
-
Reflect.construct(Object, [], arg);
|
|
1223
|
-
} catch (e) {
|
|
1224
|
-
return false;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
return true;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
function getMethods(object) {
|
|
1231
|
-
const prototype = Object.getPrototypeOf(object);
|
|
1232
|
-
|
|
1233
|
-
const instanceMethods = Object.getOwnPropertyNames(prototype).filter(
|
|
1234
|
-
(method) => ["init", "constructor"].indexOf(method) === -1,
|
|
1235
|
-
);
|
|
1236
|
-
|
|
1237
|
-
const objectMethods = Object.getOwnPropertyNames(object).filter(
|
|
1238
|
-
(key) => typeof object[key] === "function",
|
|
1239
|
-
);
|
|
1240
|
-
|
|
1241
|
-
return [...instanceMethods, ...objectMethods];
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
module.exports = PluginsManager;
|