kuzzle 2.49.1 → 2.50.0-beta.4

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.
Files changed (591) hide show
  1. package/dist/bin/copy-protobuf.js +17 -0
  2. package/dist/lib/api/controllers/adminController.d.ts +51 -0
  3. package/dist/lib/api/controllers/adminController.js +191 -0
  4. package/{lib → dist/lib}/api/controllers/authController.d.ts +20 -40
  5. package/{lib → dist/lib}/api/controllers/authController.js +23 -24
  6. package/dist/lib/api/controllers/bulkController.d.ts +46 -0
  7. package/dist/lib/api/controllers/bulkController.js +132 -0
  8. package/dist/lib/api/controllers/clusterController.d.ts +6 -0
  9. package/{lib → dist/lib}/api/controllers/clusterController.js +7 -11
  10. package/dist/lib/api/controllers/collectionController.d.ts +136 -0
  11. package/dist/lib/api/controllers/collectionController.js +356 -0
  12. package/dist/lib/api/controllers/documentController.d.ts +181 -0
  13. package/dist/lib/api/controllers/documentController.js +768 -0
  14. package/dist/lib/api/controllers/index.d.ts +12 -0
  15. package/{lib → dist/lib}/api/controllers/index.js +13 -14
  16. package/dist/lib/api/controllers/indexController.d.ts +65 -0
  17. package/dist/lib/api/controllers/indexController.js +139 -0
  18. package/dist/lib/api/controllers/memoryStorageController.d.ts +8 -0
  19. package/dist/lib/api/controllers/memoryStorageController.js +867 -0
  20. package/dist/lib/api/controllers/realtimeController.d.ts +47 -0
  21. package/dist/lib/api/controllers/realtimeController.js +128 -0
  22. package/dist/lib/api/controllers/securityController.d.ts +423 -0
  23. package/dist/lib/api/controllers/securityController.js +1139 -0
  24. package/dist/lib/api/controllers/serverController.d.ts +82 -0
  25. package/dist/lib/api/controllers/serverController.js +321 -0
  26. package/dist/lib/api/documentExtractor.d.ts +9 -0
  27. package/dist/lib/api/documentExtractor.js +274 -0
  28. package/dist/lib/api/funnel.d.ts +183 -0
  29. package/dist/lib/api/funnel.js +821 -0
  30. package/dist/lib/api/httpRoutes.d.ts +17 -0
  31. package/dist/lib/api/httpRoutes.js +1496 -0
  32. package/dist/lib/api/rateLimiter.d.ts +18 -0
  33. package/dist/lib/api/rateLimiter.js +74 -0
  34. package/{lib → dist/lib}/api/request/kuzzleRequest.d.ts +2 -2
  35. package/{lib → dist/lib}/api/request/requestContext.d.ts +2 -1
  36. package/dist/lib/cluster/command.d.ts +73 -0
  37. package/dist/lib/cluster/command.js +236 -0
  38. package/dist/lib/cluster/index.d.ts +2 -0
  39. package/{lib → dist/lib}/cluster/index.js +1 -2
  40. package/dist/lib/cluster/node.d.ts +278 -0
  41. package/dist/lib/cluster/node.js +876 -0
  42. package/dist/lib/cluster/publisher.d.ts +188 -0
  43. package/dist/lib/cluster/publisher.js +347 -0
  44. package/dist/lib/cluster/subscriber.d.ts +269 -0
  45. package/dist/lib/cluster/subscriber.js +555 -0
  46. package/dist/lib/cluster/workers/IDCardRenewer.d.ts +13 -0
  47. package/dist/lib/cluster/workers/IDCardRenewer.js +120 -0
  48. package/{lib → dist/lib}/config/documentEventAliases.d.ts +1 -2
  49. package/dist/lib/config/index.d.ts +5 -0
  50. package/dist/lib/config/index.js +244 -0
  51. package/dist/lib/config/sdkCompatibility.json +9 -0
  52. package/dist/lib/core/auth/formatProcessing.d.ts +30 -0
  53. package/dist/lib/core/auth/formatProcessing.js +55 -0
  54. package/dist/lib/core/auth/passportResponse.d.ts +15 -0
  55. package/{lib → dist/lib}/core/auth/passportResponse.js +24 -30
  56. package/dist/lib/core/auth/passportWrapper.d.ts +28 -0
  57. package/dist/lib/core/auth/passportWrapper.js +126 -0
  58. package/{lib → dist/lib}/core/backend/backendConfig.js +2 -2
  59. package/{lib → dist/lib}/core/backend/backendErrors.js +9 -12
  60. package/dist/lib/core/cache/cacheEngine.d.ts +15 -0
  61. package/dist/lib/core/cache/cacheEngine.js +205 -0
  62. package/dist/lib/core/network/accessLogger.d.ts +29 -0
  63. package/dist/lib/core/network/accessLogger.js +250 -0
  64. package/dist/lib/core/network/clientConnection.d.ts +15 -0
  65. package/{lib → dist/lib}/core/network/clientConnection.js +17 -24
  66. package/dist/lib/core/network/context.d.ts +42 -0
  67. package/dist/lib/core/network/context.js +57 -0
  68. package/dist/lib/core/network/entryPoint.d.ts +62 -0
  69. package/dist/lib/core/network/entryPoint.js +261 -0
  70. package/dist/lib/core/network/httpRouter/index.d.ts +85 -0
  71. package/dist/lib/core/network/httpRouter/index.js +258 -0
  72. package/dist/lib/core/network/httpRouter/routeHandler.d.ts +46 -0
  73. package/dist/lib/core/network/httpRouter/routeHandler.js +101 -0
  74. package/dist/lib/core/network/httpRouter/routePart.d.ts +35 -0
  75. package/dist/lib/core/network/httpRouter/routePart.js +117 -0
  76. package/dist/lib/core/network/protocolManifest.d.ts +6 -0
  77. package/{lib → dist/lib}/core/network/protocolManifest.js +5 -9
  78. package/dist/lib/core/network/protocols/httpMessage.d.ts +22 -0
  79. package/dist/lib/core/network/protocols/httpMessage.js +62 -0
  80. package/dist/lib/core/network/protocols/httpwsProtocol.d.ts +171 -0
  81. package/dist/lib/core/network/protocols/httpwsProtocol.js +921 -0
  82. package/dist/lib/core/network/protocols/internalProtocol.d.ts +27 -0
  83. package/dist/lib/core/network/protocols/internalProtocol.js +82 -0
  84. package/dist/lib/core/network/protocols/mqttProtocol.d.ts +39 -0
  85. package/dist/lib/core/network/protocols/mqttProtocol.js +219 -0
  86. package/dist/lib/core/network/protocols/protocol.d.ts +26 -0
  87. package/dist/lib/core/network/protocols/protocol.js +74 -0
  88. package/dist/lib/core/network/router.d.ts +49 -0
  89. package/dist/lib/core/network/router.js +193 -0
  90. package/dist/lib/core/plugin/plugin.d.ts +56 -0
  91. package/dist/lib/core/plugin/plugin.js +282 -0
  92. package/{lib → dist/lib}/core/plugin/pluginContext.js +2 -2
  93. package/dist/lib/core/plugin/pluginManifest.d.ts +5 -0
  94. package/{lib → dist/lib}/core/plugin/pluginManifest.js +16 -27
  95. package/dist/lib/core/plugin/pluginRepository.d.ts +53 -0
  96. package/dist/lib/core/plugin/pluginRepository.js +112 -0
  97. package/dist/lib/core/plugin/pluginsManager.d.ts +190 -0
  98. package/dist/lib/core/plugin/pluginsManager.js +817 -0
  99. package/dist/lib/core/plugin/privilegedContext.d.ts +14 -0
  100. package/{lib → dist/lib}/core/plugin/privilegedContext.js +10 -14
  101. package/dist/lib/core/realtime/actionEnum.d.ts +25 -0
  102. package/{lib → dist/lib}/core/realtime/actionEnum.js +7 -10
  103. package/dist/lib/core/realtime/index.d.ts +8 -0
  104. package/{lib → dist/lib}/core/realtime/index.js +9 -13
  105. package/dist/lib/core/realtime/notification/document.d.ts +34 -0
  106. package/dist/lib/core/realtime/notification/document.js +98 -0
  107. package/dist/lib/core/realtime/notification/index.d.ts +3 -0
  108. package/{lib → dist/lib}/core/realtime/notification/index.js +4 -5
  109. package/dist/lib/core/realtime/notification/server.d.ts +17 -0
  110. package/{lib → dist/lib}/core/realtime/notification/server.js +8 -10
  111. package/dist/lib/core/realtime/notification/user.d.ts +29 -0
  112. package/dist/lib/core/realtime/notification/user.js +66 -0
  113. package/dist/lib/core/realtime/notifier.d.ts +171 -0
  114. package/dist/lib/core/realtime/notifier.js +405 -0
  115. package/dist/lib/core/security/index.d.ts +14 -0
  116. package/{lib → dist/lib}/core/security/index.js +15 -19
  117. package/dist/lib/core/security/roleRepository.d.ts +143 -0
  118. package/dist/lib/core/security/roleRepository.js +445 -0
  119. package/dist/lib/core/security/securityLoader.d.ts +24 -0
  120. package/dist/lib/core/security/securityLoader.js +125 -0
  121. package/{lib → dist/lib}/core/security/tokenRepository.js +1 -1
  122. package/dist/lib/core/security/userRepository.d.ts +81 -0
  123. package/dist/lib/core/security/userRepository.js +346 -0
  124. package/dist/lib/core/shared/abstractManifest.d.ts +27 -0
  125. package/dist/lib/core/shared/abstractManifest.js +85 -0
  126. package/dist/lib/core/shared/sdk/impersonatedSdk.d.ts +7 -0
  127. package/dist/lib/core/shared/sdk/impersonatedSdk.js +80 -0
  128. package/{lib → dist/lib}/core/shared/store.d.ts +2 -2
  129. package/dist/lib/core/statistics/statistics.d.ts +94 -0
  130. package/dist/lib/core/statistics/statistics.js +287 -0
  131. package/dist/lib/core/storage/clientAdapter.d.ts +62 -0
  132. package/dist/lib/core/storage/clientAdapter.js +756 -0
  133. package/dist/lib/core/storage/storageEngine.d.ts +13 -0
  134. package/dist/lib/core/storage/storageEngine.js +52 -0
  135. package/dist/lib/core/validation/baseType.d.ts +35 -0
  136. package/dist/lib/core/validation/baseType.js +70 -0
  137. package/dist/lib/core/validation/types/anything.d.ts +10 -0
  138. package/{lib → dist/lib}/core/validation/types/anything.js +7 -10
  139. package/dist/lib/core/validation/types/boolean.d.ts +16 -0
  140. package/{lib → dist/lib}/core/validation/types/boolean.js +18 -23
  141. package/dist/lib/core/validation/types/date.d.ts +17 -0
  142. package/dist/lib/core/validation/types/date.js +215 -0
  143. package/dist/lib/core/validation/types/email.d.ts +17 -0
  144. package/dist/lib/core/validation/types/email.js +80 -0
  145. package/dist/lib/core/validation/types/enum.d.ts +17 -0
  146. package/dist/lib/core/validation/types/enum.js +70 -0
  147. package/dist/lib/core/validation/types/geoPoint.d.ts +17 -0
  148. package/{lib → dist/lib}/core/validation/types/geoPoint.js +19 -24
  149. package/dist/lib/core/validation/types/geoShape.d.ts +31 -0
  150. package/dist/lib/core/validation/types/geoShape.js +280 -0
  151. package/dist/lib/core/validation/types/integer.d.ts +7 -0
  152. package/{lib → dist/lib}/core/validation/types/integer.js +21 -27
  153. package/dist/lib/core/validation/types/ipAddress.d.ts +17 -0
  154. package/dist/lib/core/validation/types/ipAddress.js +73 -0
  155. package/dist/lib/core/validation/types/numeric.d.ts +17 -0
  156. package/dist/lib/core/validation/types/numeric.js +84 -0
  157. package/dist/lib/core/validation/types/object.d.ts +24 -0
  158. package/dist/lib/core/validation/types/object.js +74 -0
  159. package/dist/lib/core/validation/types/string.d.ts +17 -0
  160. package/dist/lib/core/validation/types/string.js +85 -0
  161. package/dist/lib/core/validation/types/url.d.ts +17 -0
  162. package/dist/lib/core/validation/types/url.js +73 -0
  163. package/dist/lib/core/validation/validation.d.ts +113 -0
  164. package/dist/lib/core/validation/validation.js +692 -0
  165. package/dist/lib/kerror/codes/0-core.json +194 -0
  166. package/dist/lib/kerror/codes/1-services.json +351 -0
  167. package/dist/lib/kerror/codes/2-api.json +195 -0
  168. package/dist/lib/kerror/codes/3-network.json +151 -0
  169. package/dist/lib/kerror/codes/4-plugin.json +498 -0
  170. package/dist/lib/kerror/codes/5-validation.json +158 -0
  171. package/dist/lib/kerror/codes/6-protocol.json +28 -0
  172. package/dist/lib/kerror/codes/7-security.json +283 -0
  173. package/dist/lib/kerror/codes/8-cluster.json +16 -0
  174. package/dist/lib/kerror/codes/index.d.ts +24 -0
  175. package/dist/lib/kerror/codes/index.js +140 -0
  176. package/{lib → dist/lib}/kerror/index.d.ts +5 -5
  177. package/{lib → dist/lib}/kuzzle/Logger.d.ts +6 -0
  178. package/{lib → dist/lib}/kuzzle/Logger.js +26 -5
  179. package/dist/lib/kuzzle/dumpGenerator.d.ts +14 -0
  180. package/dist/lib/kuzzle/dumpGenerator.js +180 -0
  181. package/dist/lib/kuzzle/event/pipeRunner.d.ts +30 -0
  182. package/dist/lib/kuzzle/event/pipeRunner.js +119 -0
  183. package/dist/lib/kuzzle/event/waterfall.d.ts +2 -0
  184. package/dist/lib/kuzzle/event/waterfall.js +90 -0
  185. package/dist/lib/kuzzle/internalIndexHandler.d.ts +186 -0
  186. package/dist/lib/kuzzle/internalIndexHandler.js +174 -0
  187. package/{lib → dist/lib}/kuzzle/kuzzle.d.ts +6 -7
  188. package/{lib → dist/lib}/kuzzle/kuzzle.js +5 -2
  189. package/dist/lib/kuzzle/kuzzleStateEnum.d.ts +20 -0
  190. package/{lib → dist/lib}/kuzzle/kuzzleStateEnum.js +5 -8
  191. package/dist/lib/kuzzle/vault.d.ts +2 -0
  192. package/dist/lib/kuzzle/vault.js +63 -0
  193. package/dist/lib/model/security/rights.d.ts +8 -0
  194. package/{lib → dist/lib}/model/security/rights.js +4 -8
  195. package/{lib → dist/lib}/model/security/role.d.ts +1 -1
  196. package/{lib → dist/lib}/model/security/user.d.ts +1 -0
  197. package/dist/lib/model/storage/apiKey.d.ts +49 -0
  198. package/dist/lib/model/storage/apiKey.js +126 -0
  199. package/dist/lib/model/storage/baseModel.d.ts +100 -0
  200. package/dist/lib/model/storage/baseModel.js +211 -0
  201. package/dist/lib/service/cache/redis.d.ts +74 -0
  202. package/dist/lib/service/cache/redis.js +237 -0
  203. package/dist/lib/service/service.d.ts +30 -0
  204. package/dist/lib/service/service.js +74 -0
  205. package/{lib → dist/lib}/service/storage/7/elasticsearch.d.ts +2 -2
  206. package/{lib → dist/lib}/service/storage/7/elasticsearch.js +23 -25
  207. package/dist/lib/service/storage/7/esWrapper.d.ts +19 -0
  208. package/dist/lib/service/storage/7/esWrapper.js +245 -0
  209. package/{lib → dist/lib}/service/storage/8/elasticsearch.js +23 -25
  210. package/dist/lib/service/storage/8/esWrapper.d.ts +19 -0
  211. package/dist/lib/service/storage/8/esWrapper.js +245 -0
  212. package/{lib → dist/lib}/types/Plugin.d.ts +1 -1
  213. package/{lib/types → dist/lib/types/controllers}/Controller.d.ts +2 -2
  214. package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.d.ts +1 -1
  215. package/dist/lib/types/controllers/adminControlller.type.d.ts +5 -0
  216. package/dist/lib/types/controllers/adminControlller.type.js +3 -0
  217. package/dist/lib/types/controllers/authController.type.d.ts +5 -0
  218. package/dist/lib/types/controllers/authController.type.js +3 -0
  219. package/dist/lib/types/core/auth/formatProcessing.type.d.ts +7 -0
  220. package/dist/lib/types/core/auth/formatProcessing.type.js +3 -0
  221. package/{lib → dist/lib}/types/index.d.ts +3 -3
  222. package/{lib → dist/lib}/types/index.js +3 -3
  223. package/dist/lib/util/assertType.d.ts +41 -0
  224. package/{lib → dist/lib}/util/assertType.js +38 -56
  225. package/dist/lib/util/asyncStore.d.ts +38 -0
  226. package/dist/lib/util/asyncStore.js +70 -0
  227. package/dist/lib/util/bytes.d.ts +2 -0
  228. package/dist/lib/util/bytes.js +33 -0
  229. package/dist/lib/util/debug.d.ts +2 -0
  230. package/{lib → dist/lib}/util/debug.js +15 -23
  231. package/dist/lib/util/deprecate.d.ts +1 -0
  232. package/dist/lib/util/deprecate.js +64 -0
  233. package/dist/lib/util/didYouMean.d.ts +2 -0
  234. package/{lib → dist/lib}/util/didYouMean.js +9 -15
  235. package/dist/lib/util/extractFields.d.ts +17 -0
  236. package/{lib → dist/lib}/util/extractFields.js +18 -32
  237. package/dist/lib/util/memoize.d.ts +7 -0
  238. package/{lib → dist/lib}/util/memoize.js +14 -21
  239. package/dist/lib/util/promback.d.ts +13 -0
  240. package/dist/lib/util/promback.js +60 -0
  241. package/dist/lib/util/requestAssertions.d.ts +10 -0
  242. package/dist/lib/util/requestAssertions.js +143 -0
  243. package/dist/lib/util/safeObject.d.ts +3 -0
  244. package/{lib → dist/lib}/util/safeObject.js +7 -13
  245. package/dist/lib/util/stackTrace.d.ts +19 -0
  246. package/{lib → dist/lib}/util/stackTrace.js +35 -41
  247. package/dist/lib/util/wildcard.d.ts +1 -0
  248. package/{lib → dist/lib}/util/wildcard.js +21 -30
  249. package/dist/package.json +119 -0
  250. package/package.json +44 -58
  251. package/bin/start-kuzzle-server +0 -126
  252. package/check-node-version.js +0 -17
  253. package/lib/api/controllers/adminController.js +0 -229
  254. package/lib/api/controllers/bulkController.js +0 -210
  255. package/lib/api/controllers/collectionController.js +0 -502
  256. package/lib/api/controllers/documentController.js +0 -1156
  257. package/lib/api/controllers/indexController.js +0 -179
  258. package/lib/api/controllers/memoryStorageController.js +0 -1023
  259. package/lib/api/controllers/realtimeController.js +0 -155
  260. package/lib/api/controllers/securityController.js +0 -1571
  261. package/lib/api/controllers/serverController.js +0 -381
  262. package/lib/api/documentExtractor.js +0 -309
  263. package/lib/api/funnel.js +0 -1143
  264. package/lib/api/httpRoutes.js +0 -1547
  265. package/lib/api/rateLimiter.js +0 -87
  266. package/lib/cluster/command.js +0 -284
  267. package/lib/cluster/node.js +0 -1203
  268. package/lib/cluster/publisher.js +0 -386
  269. package/lib/cluster/subscriber.js +0 -776
  270. package/lib/cluster/workers/IDCardRenewer.js +0 -144
  271. package/lib/config/index.js +0 -351
  272. package/lib/config/sdkCompatibility.json +0 -9
  273. package/lib/core/auth/formatProcessing.js +0 -66
  274. package/lib/core/auth/passportWrapper.js +0 -126
  275. package/lib/core/cache/cacheEngine.js +0 -278
  276. package/lib/core/network/accessLogger.js +0 -322
  277. package/lib/core/network/context.js +0 -80
  278. package/lib/core/network/entryPoint.js +0 -358
  279. package/lib/core/network/httpRouter/index.js +0 -316
  280. package/lib/core/network/httpRouter/routeHandler.js +0 -111
  281. package/lib/core/network/httpRouter/routePart.js +0 -147
  282. package/lib/core/network/protocols/httpMessage.js +0 -69
  283. package/lib/core/network/protocols/httpwsProtocol.js +0 -1254
  284. package/lib/core/network/protocols/internalProtocol.js +0 -109
  285. package/lib/core/network/protocols/mqttProtocol.js +0 -291
  286. package/lib/core/network/protocols/protocol.js +0 -102
  287. package/lib/core/network/router.js +0 -255
  288. package/lib/core/plugin/plugin.js +0 -436
  289. package/lib/core/plugin/pluginRepository.js +0 -132
  290. package/lib/core/plugin/pluginsManager.js +0 -1244
  291. package/lib/core/realtime/notification/document.js +0 -108
  292. package/lib/core/realtime/notification/user.js +0 -70
  293. package/lib/core/realtime/notifier.js +0 -541
  294. package/lib/core/security/README.md +0 -223
  295. package/lib/core/security/roleRepository.js +0 -569
  296. package/lib/core/security/securityLoader.js +0 -174
  297. package/lib/core/security/userRepository.js +0 -446
  298. package/lib/core/shared/README.md +0 -3
  299. package/lib/core/shared/abstractManifest.js +0 -102
  300. package/lib/core/shared/sdk/impersonatedSdk.js +0 -94
  301. package/lib/core/statistics/index.js +0 -24
  302. package/lib/core/statistics/statistics.js +0 -373
  303. package/lib/core/storage/clientAdapter.js +0 -1045
  304. package/lib/core/storage/storageEngine.js +0 -63
  305. package/lib/core/validation/baseType.js +0 -80
  306. package/lib/core/validation/index.js +0 -24
  307. package/lib/core/validation/types/date.js +0 -284
  308. package/lib/core/validation/types/email.js +0 -92
  309. package/lib/core/validation/types/enum.js +0 -100
  310. package/lib/core/validation/types/geoShape.js +0 -370
  311. package/lib/core/validation/types/ipAddress.js +0 -83
  312. package/lib/core/validation/types/numeric.js +0 -108
  313. package/lib/core/validation/types/object.js +0 -88
  314. package/lib/core/validation/types/string.js +0 -110
  315. package/lib/core/validation/types/url.js +0 -83
  316. package/lib/core/validation/validation.js +0 -1180
  317. package/lib/kerror/codes/0-core.json +0 -194
  318. package/lib/kerror/codes/1-services.json +0 -351
  319. package/lib/kerror/codes/2-api.json +0 -195
  320. package/lib/kerror/codes/3-network.json +0 -151
  321. package/lib/kerror/codes/4-plugin.json +0 -498
  322. package/lib/kerror/codes/5-validation.json +0 -158
  323. package/lib/kerror/codes/6-protocol.json +0 -28
  324. package/lib/kerror/codes/7-security.json +0 -283
  325. package/lib/kerror/codes/8-cluster.json +0 -16
  326. package/lib/kerror/codes/index.js +0 -208
  327. package/lib/kuzzle/dumpGenerator.js +0 -259
  328. package/lib/kuzzle/event/pipeRunner.js +0 -144
  329. package/lib/kuzzle/event/waterfall.js +0 -101
  330. package/lib/kuzzle/internalIndexHandler.js +0 -234
  331. package/lib/kuzzle/vault.js +0 -89
  332. package/lib/model/storage/apiKey.js +0 -158
  333. package/lib/model/storage/baseModel.js +0 -275
  334. package/lib/service/cache/redis.js +0 -282
  335. package/lib/service/service.js +0 -84
  336. package/lib/service/storage/7/esWrapper.js +0 -303
  337. package/lib/service/storage/8/esWrapper.js +0 -303
  338. package/lib/util/asyncStore.js +0 -112
  339. package/lib/util/bytes.js +0 -36
  340. package/lib/util/deprecate.js +0 -82
  341. package/lib/util/promback.js +0 -66
  342. package/lib/util/readYamlFile.d.ts +0 -2
  343. package/lib/util/readYamlFile.js +0 -10
  344. package/lib/util/requestAssertions.js +0 -157
  345. /package/{index.d.ts → dist/index.d.ts} +0 -0
  346. /package/{index.js → dist/index.js} +0 -0
  347. /package/{lib → dist/lib}/api/controllers/baseController.d.ts +0 -0
  348. /package/{lib → dist/lib}/api/controllers/baseController.js +0 -0
  349. /package/{lib → dist/lib}/api/controllers/debugController.d.ts +0 -0
  350. /package/{lib → dist/lib}/api/controllers/debugController.js +0 -0
  351. /package/{lib → dist/lib}/api/openapi/OpenApiManager.d.ts +0 -0
  352. /package/{lib → dist/lib}/api/openapi/OpenApiManager.js +0 -0
  353. /package/{lib → dist/lib}/api/openapi/index.d.ts +0 -0
  354. /package/{lib → dist/lib}/api/openapi/index.js +0 -0
  355. /package/{lib → dist/lib}/api/openapi/openApiGenerator.d.ts +0 -0
  356. /package/{lib → dist/lib}/api/openapi/openApiGenerator.js +0 -0
  357. /package/{lib → dist/lib}/api/request/index.d.ts +0 -0
  358. /package/{lib → dist/lib}/api/request/index.js +0 -0
  359. /package/{lib → dist/lib}/api/request/kuzzleRequest.js +0 -0
  360. /package/{lib → dist/lib}/api/request/requestContext.js +0 -0
  361. /package/{lib → dist/lib}/api/request/requestInput.d.ts +0 -0
  362. /package/{lib → dist/lib}/api/request/requestInput.js +0 -0
  363. /package/{lib → dist/lib}/api/request/requestResponse.d.ts +0 -0
  364. /package/{lib → dist/lib}/api/request/requestResponse.js +0 -0
  365. /package/{lib → dist/lib}/cluster/idCardHandler.d.ts +0 -0
  366. /package/{lib → dist/lib}/cluster/idCardHandler.js +0 -0
  367. /package/{lib → dist/lib}/cluster/protobuf/command.proto +0 -0
  368. /package/{lib → dist/lib}/cluster/protobuf/sync.proto +0 -0
  369. /package/{lib → dist/lib}/cluster/state.d.ts +0 -0
  370. /package/{lib → dist/lib}/cluster/state.js +0 -0
  371. /package/{lib → dist/lib}/config/default.config.d.ts +0 -0
  372. /package/{lib → dist/lib}/config/default.config.js +0 -0
  373. /package/{lib → dist/lib}/config/documentEventAliases.js +0 -0
  374. /package/{lib → dist/lib}/core/auth/tokenManager.d.ts +0 -0
  375. /package/{lib → dist/lib}/core/auth/tokenManager.js +0 -0
  376. /package/{lib → dist/lib}/core/backend/applicationManager.d.ts +0 -0
  377. /package/{lib → dist/lib}/core/backend/applicationManager.js +0 -0
  378. /package/{lib → dist/lib}/core/backend/backend.d.ts +0 -0
  379. /package/{lib → dist/lib}/core/backend/backend.js +0 -0
  380. /package/{lib → dist/lib}/core/backend/backendCluster.d.ts +0 -0
  381. /package/{lib → dist/lib}/core/backend/backendCluster.js +0 -0
  382. /package/{lib → dist/lib}/core/backend/backendConfig.d.ts +0 -0
  383. /package/{lib → dist/lib}/core/backend/backendController.d.ts +0 -0
  384. /package/{lib → dist/lib}/core/backend/backendController.js +0 -0
  385. /package/{lib → dist/lib}/core/backend/backendErrors.d.ts +0 -0
  386. /package/{lib → dist/lib}/core/backend/backendHook.d.ts +0 -0
  387. /package/{lib → dist/lib}/core/backend/backendHook.js +0 -0
  388. /package/{lib → dist/lib}/core/backend/backendImport.d.ts +0 -0
  389. /package/{lib → dist/lib}/core/backend/backendImport.js +0 -0
  390. /package/{lib → dist/lib}/core/backend/backendOpenApi.d.ts +0 -0
  391. /package/{lib → dist/lib}/core/backend/backendOpenApi.js +0 -0
  392. /package/{lib → dist/lib}/core/backend/backendPipe.d.ts +0 -0
  393. /package/{lib → dist/lib}/core/backend/backendPipe.js +0 -0
  394. /package/{lib → dist/lib}/core/backend/backendPlugin.d.ts +0 -0
  395. /package/{lib → dist/lib}/core/backend/backendPlugin.js +0 -0
  396. /package/{lib → dist/lib}/core/backend/backendStorage.d.ts +0 -0
  397. /package/{lib → dist/lib}/core/backend/backendStorage.js +0 -0
  398. /package/{lib → dist/lib}/core/backend/backendSubscription.d.ts +0 -0
  399. /package/{lib → dist/lib}/core/backend/backendSubscription.js +0 -0
  400. /package/{lib → dist/lib}/core/backend/backendVault.d.ts +0 -0
  401. /package/{lib → dist/lib}/core/backend/backendVault.js +0 -0
  402. /package/{lib → dist/lib}/core/backend/index.d.ts +0 -0
  403. /package/{lib → dist/lib}/core/backend/index.js +0 -0
  404. /package/{lib → dist/lib}/core/backend/internalLogger.d.ts +0 -0
  405. /package/{lib → dist/lib}/core/backend/internalLogger.js +0 -0
  406. /package/{lib → dist/lib}/core/cache/cacheDbEnum.d.ts +0 -0
  407. /package/{lib → dist/lib}/core/cache/cacheDbEnum.js +0 -0
  408. /package/{lib → dist/lib}/core/debug/kuzzleDebugger.d.ts +0 -0
  409. /package/{lib → dist/lib}/core/debug/kuzzleDebugger.js +0 -0
  410. /package/{lib → dist/lib}/core/plugin/pluginContext.d.ts +0 -0
  411. /package/{lib → dist/lib}/core/realtime/channel.d.ts +0 -0
  412. /package/{lib → dist/lib}/core/realtime/channel.js +0 -0
  413. /package/{lib → dist/lib}/core/realtime/connectionRooms.d.ts +0 -0
  414. /package/{lib → dist/lib}/core/realtime/connectionRooms.js +0 -0
  415. /package/{lib → dist/lib}/core/realtime/hotelClerk.d.ts +0 -0
  416. /package/{lib → dist/lib}/core/realtime/hotelClerk.js +0 -0
  417. /package/{lib → dist/lib}/core/realtime/room.d.ts +0 -0
  418. /package/{lib → dist/lib}/core/realtime/room.js +0 -0
  419. /package/{lib → dist/lib}/core/realtime/subscription.d.ts +0 -0
  420. /package/{lib → dist/lib}/core/realtime/subscription.js +0 -0
  421. /package/{lib → dist/lib}/core/security/profileRepository.d.ts +0 -0
  422. /package/{lib → dist/lib}/core/security/profileRepository.js +0 -0
  423. /package/{lib → dist/lib}/core/security/tokenRepository.d.ts +0 -0
  424. /package/{lib → dist/lib}/core/shared/KoncordeWrapper.d.ts +0 -0
  425. /package/{lib → dist/lib}/core/shared/KoncordeWrapper.js +0 -0
  426. /package/{lib → dist/lib}/core/shared/ObjectRepository.d.ts +0 -0
  427. /package/{lib → dist/lib}/core/shared/ObjectRepository.js +0 -0
  428. /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.d.ts +0 -0
  429. /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.js +0 -0
  430. /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.d.ts +0 -0
  431. /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.js +0 -0
  432. /package/{lib → dist/lib}/core/shared/store.js +0 -0
  433. /package/{lib → dist/lib}/core/storage/indexCache.d.ts +0 -0
  434. /package/{lib → dist/lib}/core/storage/indexCache.js +0 -0
  435. /package/{lib → dist/lib}/core/storage/storeScopeEnum.d.ts +0 -0
  436. /package/{lib → dist/lib}/core/storage/storeScopeEnum.js +0 -0
  437. /package/{lib → dist/lib}/kerror/errors/badRequestError.d.ts +0 -0
  438. /package/{lib → dist/lib}/kerror/errors/badRequestError.js +0 -0
  439. /package/{lib → dist/lib}/kerror/errors/externalServiceError.d.ts +0 -0
  440. /package/{lib → dist/lib}/kerror/errors/externalServiceError.js +0 -0
  441. /package/{lib → dist/lib}/kerror/errors/forbiddenError.d.ts +0 -0
  442. /package/{lib → dist/lib}/kerror/errors/forbiddenError.js +0 -0
  443. /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.d.ts +0 -0
  444. /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.js +0 -0
  445. /package/{lib → dist/lib}/kerror/errors/index.d.ts +0 -0
  446. /package/{lib → dist/lib}/kerror/errors/index.js +0 -0
  447. /package/{lib → dist/lib}/kerror/errors/internalError.d.ts +0 -0
  448. /package/{lib → dist/lib}/kerror/errors/internalError.js +0 -0
  449. /package/{lib → dist/lib}/kerror/errors/kuzzleError.d.ts +0 -0
  450. /package/{lib → dist/lib}/kerror/errors/kuzzleError.js +0 -0
  451. /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.d.ts +0 -0
  452. /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.js +0 -0
  453. /package/{lib → dist/lib}/kerror/errors/notFoundError.d.ts +0 -0
  454. /package/{lib → dist/lib}/kerror/errors/notFoundError.js +0 -0
  455. /package/{lib → dist/lib}/kerror/errors/partialError.d.ts +0 -0
  456. /package/{lib → dist/lib}/kerror/errors/partialError.js +0 -0
  457. /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.d.ts +0 -0
  458. /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.js +0 -0
  459. /package/{lib → dist/lib}/kerror/errors/preconditionError.d.ts +0 -0
  460. /package/{lib → dist/lib}/kerror/errors/preconditionError.js +0 -0
  461. /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.d.ts +0 -0
  462. /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.js +0 -0
  463. /package/{lib → dist/lib}/kerror/errors/sizeLimitError.d.ts +0 -0
  464. /package/{lib → dist/lib}/kerror/errors/sizeLimitError.js +0 -0
  465. /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.d.ts +0 -0
  466. /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.js +0 -0
  467. /package/{lib → dist/lib}/kerror/errors/unauthorizedError.d.ts +0 -0
  468. /package/{lib → dist/lib}/kerror/errors/unauthorizedError.js +0 -0
  469. /package/{lib → dist/lib}/kerror/index.js +0 -0
  470. /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.d.ts +0 -0
  471. /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.js +0 -0
  472. /package/{lib → dist/lib}/kuzzle/index.d.ts +0 -0
  473. /package/{lib → dist/lib}/kuzzle/index.js +0 -0
  474. /package/{lib → dist/lib}/model/security/profile.d.ts +0 -0
  475. /package/{lib → dist/lib}/model/security/profile.js +0 -0
  476. /package/{lib → dist/lib}/model/security/role.js +0 -0
  477. /package/{lib → dist/lib}/model/security/token.d.ts +0 -0
  478. /package/{lib → dist/lib}/model/security/token.js +0 -0
  479. /package/{lib → dist/lib}/model/security/user.js +0 -0
  480. /package/{lib → dist/lib}/service/storage/8/elasticsearch.d.ts +0 -0
  481. /package/{lib → dist/lib}/service/storage/Elasticsearch.d.ts +0 -0
  482. /package/{lib → dist/lib}/service/storage/Elasticsearch.js +0 -0
  483. /package/{lib → dist/lib}/service/storage/commons/queryTranslator.d.ts +0 -0
  484. /package/{lib → dist/lib}/service/storage/commons/queryTranslator.js +0 -0
  485. /package/{lib → dist/lib}/types/ClientConnection.d.ts +0 -0
  486. /package/{lib → dist/lib}/types/ClientConnection.js +0 -0
  487. /package/{lib → dist/lib}/types/Deprecation.d.ts +0 -0
  488. /package/{lib → dist/lib}/types/Deprecation.js +0 -0
  489. /package/{lib → dist/lib}/types/EventHandler.d.ts +0 -0
  490. /package/{lib → dist/lib}/types/EventHandler.js +0 -0
  491. /package/{lib → dist/lib}/types/Global.d.ts +0 -0
  492. /package/{lib → dist/lib}/types/Global.js +0 -0
  493. /package/{lib → dist/lib}/types/HttpMessage.d.ts +0 -0
  494. /package/{lib → dist/lib}/types/HttpMessage.js +0 -0
  495. /package/{lib → dist/lib}/types/HttpStream.d.ts +0 -0
  496. /package/{lib → dist/lib}/types/HttpStream.js +0 -0
  497. /package/{lib → dist/lib}/types/Kuzzle.d.ts +0 -0
  498. /package/{lib → dist/lib}/types/Kuzzle.js +0 -0
  499. /package/{lib → dist/lib}/types/KuzzleDocument.d.ts +0 -0
  500. /package/{lib → dist/lib}/types/KuzzleDocument.js +0 -0
  501. /package/{lib → dist/lib}/types/OpenApiDefinition.d.ts +0 -0
  502. /package/{lib → dist/lib}/types/OpenApiDefinition.js +0 -0
  503. /package/{lib → dist/lib}/types/PasswordPolicy.d.ts +0 -0
  504. /package/{lib → dist/lib}/types/PasswordPolicy.js +0 -0
  505. /package/{lib → dist/lib}/types/Plugin.js +0 -0
  506. /package/{lib → dist/lib}/types/PluginManifest.d.ts +0 -0
  507. /package/{lib → dist/lib}/types/PluginManifest.js +0 -0
  508. /package/{lib → dist/lib}/types/Policy.d.ts +0 -0
  509. /package/{lib → dist/lib}/types/Policy.js +0 -0
  510. /package/{lib → dist/lib}/types/PolicyRestrictions.d.ts +0 -0
  511. /package/{lib → dist/lib}/types/PolicyRestrictions.js +0 -0
  512. /package/{lib → dist/lib}/types/ProfileDefinition.d.ts +0 -0
  513. /package/{lib → dist/lib}/types/ProfileDefinition.js +0 -0
  514. /package/{lib → dist/lib}/types/RoleDefinition.d.ts +0 -0
  515. /package/{lib → dist/lib}/types/RoleDefinition.js +0 -0
  516. /package/{lib → dist/lib}/types/StrategyDefinition.d.ts +0 -0
  517. /package/{lib → dist/lib}/types/StrategyDefinition.js +0 -0
  518. /package/{lib → dist/lib}/types/Target.d.ts +0 -0
  519. /package/{lib → dist/lib}/types/Target.js +0 -0
  520. /package/{lib → dist/lib}/types/Token.d.ts +0 -0
  521. /package/{lib → dist/lib}/types/Token.js +0 -0
  522. /package/{lib → dist/lib}/types/User.d.ts +0 -0
  523. /package/{lib → dist/lib}/types/User.js +0 -0
  524. /package/{lib → dist/lib}/types/config/DumpConfiguration.d.ts +0 -0
  525. /package/{lib → dist/lib}/types/config/DumpConfiguration.js +0 -0
  526. /package/{lib → dist/lib}/types/config/HttpConfiguration.d.ts +0 -0
  527. /package/{lib → dist/lib}/types/config/HttpConfiguration.js +0 -0
  528. /package/{lib → dist/lib}/types/config/KuzzleConfiguration.d.ts +0 -0
  529. /package/{lib → dist/lib}/types/config/KuzzleConfiguration.js +0 -0
  530. /package/{lib → dist/lib}/types/config/LimitsConfiguration.d.ts +0 -0
  531. /package/{lib → dist/lib}/types/config/LimitsConfiguration.js +0 -0
  532. /package/{lib → dist/lib}/types/config/PluginsConfiguration.d.ts +0 -0
  533. /package/{lib → dist/lib}/types/config/PluginsConfiguration.js +0 -0
  534. /package/{lib → dist/lib}/types/config/SecurityConfiguration.d.ts +0 -0
  535. /package/{lib → dist/lib}/types/config/SecurityConfiguration.js +0 -0
  536. /package/{lib → dist/lib}/types/config/ServerConfiguration.d.ts +0 -0
  537. /package/{lib → dist/lib}/types/config/ServerConfiguration.js +0 -0
  538. /package/{lib → dist/lib}/types/config/ServicesConfiguration.d.ts +0 -0
  539. /package/{lib → dist/lib}/types/config/ServicesConfiguration.js +0 -0
  540. /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +0 -0
  541. /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.js +0 -0
  542. /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +0 -0
  543. /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.js +0 -0
  544. /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +0 -0
  545. /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +0 -0
  546. /package/{lib/types → dist/lib/types/controllers}/Controller.js +0 -0
  547. /package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.js +0 -0
  548. /package/{lib/types → dist/lib/types/controllers}/ControllerRights.d.ts +0 -0
  549. /package/{lib/types → dist/lib/types/controllers}/ControllerRights.js +0 -0
  550. /package/{lib → dist/lib}/types/errors/ErrorDefinition.d.ts +0 -0
  551. /package/{lib → dist/lib}/types/errors/ErrorDefinition.js +0 -0
  552. /package/{lib → dist/lib}/types/errors/ErrorDomains.d.ts +0 -0
  553. /package/{lib → dist/lib}/types/errors/ErrorDomains.js +0 -0
  554. /package/{lib → dist/lib}/types/events/EventGenericDocument.d.ts +0 -0
  555. /package/{lib → dist/lib}/types/events/EventGenericDocument.js +0 -0
  556. /package/{lib → dist/lib}/types/events/EventProtocol.d.ts +0 -0
  557. /package/{lib → dist/lib}/types/events/EventProtocol.js +0 -0
  558. /package/{lib → dist/lib}/types/realtime/RealtimeScope.d.ts +0 -0
  559. /package/{lib → dist/lib}/types/realtime/RealtimeScope.js +0 -0
  560. /package/{lib → dist/lib}/types/realtime/RealtimeUsers.d.ts +0 -0
  561. /package/{lib → dist/lib}/types/realtime/RealtimeUsers.js +0 -0
  562. /package/{lib → dist/lib}/types/realtime/RoomList.d.ts +0 -0
  563. /package/{lib → dist/lib}/types/realtime/RoomList.js +0 -0
  564. /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.d.ts +0 -0
  565. /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.js +0 -0
  566. /package/{lib → dist/lib}/types/storage/7/Elasticsearch.d.ts +0 -0
  567. /package/{lib → dist/lib}/types/storage/7/Elasticsearch.js +0 -0
  568. /package/{lib → dist/lib}/types/storage/8/Elasticsearch.d.ts +0 -0
  569. /package/{lib → dist/lib}/types/storage/8/Elasticsearch.js +0 -0
  570. /package/{lib → dist/lib}/util/Inflector.d.ts +0 -0
  571. /package/{lib → dist/lib}/util/Inflector.js +0 -0
  572. /package/{lib → dist/lib}/util/array.d.ts +0 -0
  573. /package/{lib → dist/lib}/util/array.js +0 -0
  574. /package/{lib → dist/lib}/util/async.d.ts +0 -0
  575. /package/{lib → dist/lib}/util/async.js +0 -0
  576. /package/{lib → dist/lib}/util/bufferedPassThrough.d.ts +0 -0
  577. /package/{lib → dist/lib}/util/bufferedPassThrough.js +0 -0
  578. /package/{lib → dist/lib}/util/crypto.d.ts +0 -0
  579. /package/{lib → dist/lib}/util/crypto.js +0 -0
  580. /package/{lib → dist/lib}/util/dump-collection.d.ts +0 -0
  581. /package/{lib → dist/lib}/util/dump-collection.js +0 -0
  582. /package/{lib → dist/lib}/util/esRequest.d.ts +0 -0
  583. /package/{lib → dist/lib}/util/esRequest.js +0 -0
  584. /package/{lib → dist/lib}/util/koncordeCompat.d.ts +0 -0
  585. /package/{lib → dist/lib}/util/koncordeCompat.js +0 -0
  586. /package/{lib → dist/lib}/util/mutex.d.ts +0 -0
  587. /package/{lib → dist/lib}/util/mutex.js +0 -0
  588. /package/{lib → dist/lib}/util/name-generator.d.ts +0 -0
  589. /package/{lib → dist/lib}/util/name-generator.js +0 -0
  590. /package/{lib → dist/lib}/util/time.d.ts +0 -0
  591. /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;