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.
Files changed (592) hide show
  1. package/dist/bin/check-node-version.js +11 -0
  2. package/dist/bin/copy-protobuf.js +17 -0
  3. package/dist/lib/api/controllers/adminController.d.ts +51 -0
  4. package/dist/lib/api/controllers/adminController.js +191 -0
  5. package/{lib → dist/lib}/api/controllers/authController.d.ts +20 -40
  6. package/{lib → dist/lib}/api/controllers/authController.js +23 -24
  7. package/dist/lib/api/controllers/bulkController.d.ts +46 -0
  8. package/dist/lib/api/controllers/bulkController.js +132 -0
  9. package/dist/lib/api/controllers/clusterController.d.ts +6 -0
  10. package/{lib → dist/lib}/api/controllers/clusterController.js +7 -11
  11. package/dist/lib/api/controllers/collectionController.d.ts +136 -0
  12. package/dist/lib/api/controllers/collectionController.js +356 -0
  13. package/dist/lib/api/controllers/documentController.d.ts +181 -0
  14. package/dist/lib/api/controllers/documentController.js +768 -0
  15. package/dist/lib/api/controllers/index.d.ts +12 -0
  16. package/{lib → dist/lib}/api/controllers/index.js +13 -14
  17. package/dist/lib/api/controllers/indexController.d.ts +65 -0
  18. package/dist/lib/api/controllers/indexController.js +139 -0
  19. package/dist/lib/api/controllers/memoryStorageController.d.ts +8 -0
  20. package/dist/lib/api/controllers/memoryStorageController.js +867 -0
  21. package/dist/lib/api/controllers/realtimeController.d.ts +47 -0
  22. package/dist/lib/api/controllers/realtimeController.js +128 -0
  23. package/dist/lib/api/controllers/securityController.d.ts +423 -0
  24. package/dist/lib/api/controllers/securityController.js +1139 -0
  25. package/dist/lib/api/controllers/serverController.d.ts +82 -0
  26. package/dist/lib/api/controllers/serverController.js +321 -0
  27. package/dist/lib/api/documentExtractor.d.ts +9 -0
  28. package/dist/lib/api/documentExtractor.js +274 -0
  29. package/dist/lib/api/funnel.d.ts +183 -0
  30. package/dist/lib/api/funnel.js +821 -0
  31. package/dist/lib/api/httpRoutes.d.ts +17 -0
  32. package/dist/lib/api/httpRoutes.js +1496 -0
  33. package/dist/lib/api/rateLimiter.d.ts +18 -0
  34. package/dist/lib/api/rateLimiter.js +74 -0
  35. package/{lib → dist/lib}/api/request/kuzzleRequest.d.ts +2 -2
  36. package/{lib → dist/lib}/api/request/requestContext.d.ts +2 -1
  37. package/dist/lib/cluster/command.d.ts +73 -0
  38. package/dist/lib/cluster/command.js +236 -0
  39. package/dist/lib/cluster/index.d.ts +2 -0
  40. package/{lib → dist/lib}/cluster/index.js +1 -2
  41. package/dist/lib/cluster/node.d.ts +278 -0
  42. package/dist/lib/cluster/node.js +876 -0
  43. package/dist/lib/cluster/publisher.d.ts +188 -0
  44. package/dist/lib/cluster/publisher.js +347 -0
  45. package/dist/lib/cluster/subscriber.d.ts +269 -0
  46. package/dist/lib/cluster/subscriber.js +555 -0
  47. package/dist/lib/cluster/workers/IDCardRenewer.d.ts +13 -0
  48. package/dist/lib/cluster/workers/IDCardRenewer.js +120 -0
  49. package/{lib → dist/lib}/config/documentEventAliases.d.ts +1 -2
  50. package/dist/lib/config/index.d.ts +5 -0
  51. package/dist/lib/config/index.js +244 -0
  52. package/dist/lib/config/sdkCompatibility.json +9 -0
  53. package/dist/lib/core/auth/formatProcessing.d.ts +30 -0
  54. package/dist/lib/core/auth/formatProcessing.js +55 -0
  55. package/dist/lib/core/auth/passportResponse.d.ts +15 -0
  56. package/{lib → dist/lib}/core/auth/passportResponse.js +24 -30
  57. package/dist/lib/core/auth/passportWrapper.d.ts +28 -0
  58. package/dist/lib/core/auth/passportWrapper.js +126 -0
  59. package/{lib → dist/lib}/core/backend/backendConfig.js +2 -2
  60. package/{lib → dist/lib}/core/backend/backendErrors.js +9 -12
  61. package/dist/lib/core/cache/cacheEngine.d.ts +15 -0
  62. package/dist/lib/core/cache/cacheEngine.js +205 -0
  63. package/dist/lib/core/network/accessLogger.d.ts +29 -0
  64. package/dist/lib/core/network/accessLogger.js +250 -0
  65. package/dist/lib/core/network/clientConnection.d.ts +15 -0
  66. package/{lib → dist/lib}/core/network/clientConnection.js +17 -24
  67. package/dist/lib/core/network/context.d.ts +42 -0
  68. package/dist/lib/core/network/context.js +57 -0
  69. package/dist/lib/core/network/entryPoint.d.ts +62 -0
  70. package/dist/lib/core/network/entryPoint.js +261 -0
  71. package/dist/lib/core/network/httpRouter/index.d.ts +85 -0
  72. package/dist/lib/core/network/httpRouter/index.js +258 -0
  73. package/dist/lib/core/network/httpRouter/routeHandler.d.ts +46 -0
  74. package/dist/lib/core/network/httpRouter/routeHandler.js +101 -0
  75. package/dist/lib/core/network/httpRouter/routePart.d.ts +35 -0
  76. package/dist/lib/core/network/httpRouter/routePart.js +117 -0
  77. package/dist/lib/core/network/protocolManifest.d.ts +6 -0
  78. package/{lib → dist/lib}/core/network/protocolManifest.js +5 -9
  79. package/dist/lib/core/network/protocols/httpMessage.d.ts +22 -0
  80. package/dist/lib/core/network/protocols/httpMessage.js +62 -0
  81. package/dist/lib/core/network/protocols/httpwsProtocol.d.ts +171 -0
  82. package/dist/lib/core/network/protocols/httpwsProtocol.js +921 -0
  83. package/dist/lib/core/network/protocols/internalProtocol.d.ts +27 -0
  84. package/dist/lib/core/network/protocols/internalProtocol.js +82 -0
  85. package/dist/lib/core/network/protocols/mqttProtocol.d.ts +39 -0
  86. package/dist/lib/core/network/protocols/mqttProtocol.js +219 -0
  87. package/dist/lib/core/network/protocols/protocol.d.ts +26 -0
  88. package/dist/lib/core/network/protocols/protocol.js +74 -0
  89. package/dist/lib/core/network/router.d.ts +49 -0
  90. package/dist/lib/core/network/router.js +193 -0
  91. package/dist/lib/core/plugin/plugin.d.ts +56 -0
  92. package/dist/lib/core/plugin/plugin.js +282 -0
  93. package/{lib → dist/lib}/core/plugin/pluginContext.js +2 -2
  94. package/dist/lib/core/plugin/pluginManifest.d.ts +5 -0
  95. package/{lib → dist/lib}/core/plugin/pluginManifest.js +16 -27
  96. package/dist/lib/core/plugin/pluginRepository.d.ts +53 -0
  97. package/dist/lib/core/plugin/pluginRepository.js +112 -0
  98. package/dist/lib/core/plugin/pluginsManager.d.ts +190 -0
  99. package/dist/lib/core/plugin/pluginsManager.js +817 -0
  100. package/dist/lib/core/plugin/privilegedContext.d.ts +14 -0
  101. package/{lib → dist/lib}/core/plugin/privilegedContext.js +10 -14
  102. package/dist/lib/core/realtime/actionEnum.d.ts +25 -0
  103. package/{lib → dist/lib}/core/realtime/actionEnum.js +7 -10
  104. package/dist/lib/core/realtime/index.d.ts +8 -0
  105. package/{lib → dist/lib}/core/realtime/index.js +9 -13
  106. package/dist/lib/core/realtime/notification/document.d.ts +34 -0
  107. package/dist/lib/core/realtime/notification/document.js +98 -0
  108. package/dist/lib/core/realtime/notification/index.d.ts +3 -0
  109. package/{lib → dist/lib}/core/realtime/notification/index.js +4 -5
  110. package/dist/lib/core/realtime/notification/server.d.ts +17 -0
  111. package/{lib → dist/lib}/core/realtime/notification/server.js +8 -10
  112. package/dist/lib/core/realtime/notification/user.d.ts +29 -0
  113. package/dist/lib/core/realtime/notification/user.js +66 -0
  114. package/dist/lib/core/realtime/notifier.d.ts +171 -0
  115. package/dist/lib/core/realtime/notifier.js +405 -0
  116. package/dist/lib/core/security/index.d.ts +14 -0
  117. package/{lib → dist/lib}/core/security/index.js +15 -19
  118. package/dist/lib/core/security/roleRepository.d.ts +143 -0
  119. package/dist/lib/core/security/roleRepository.js +445 -0
  120. package/dist/lib/core/security/securityLoader.d.ts +24 -0
  121. package/dist/lib/core/security/securityLoader.js +125 -0
  122. package/{lib → dist/lib}/core/security/tokenRepository.js +1 -1
  123. package/dist/lib/core/security/userRepository.d.ts +81 -0
  124. package/dist/lib/core/security/userRepository.js +346 -0
  125. package/dist/lib/core/shared/abstractManifest.d.ts +27 -0
  126. package/dist/lib/core/shared/abstractManifest.js +85 -0
  127. package/dist/lib/core/shared/sdk/impersonatedSdk.d.ts +7 -0
  128. package/dist/lib/core/shared/sdk/impersonatedSdk.js +80 -0
  129. package/{lib → dist/lib}/core/shared/store.d.ts +2 -2
  130. package/dist/lib/core/statistics/statistics.d.ts +94 -0
  131. package/dist/lib/core/statistics/statistics.js +287 -0
  132. package/dist/lib/core/storage/clientAdapter.d.ts +62 -0
  133. package/dist/lib/core/storage/clientAdapter.js +756 -0
  134. package/dist/lib/core/storage/storageEngine.d.ts +13 -0
  135. package/dist/lib/core/storage/storageEngine.js +52 -0
  136. package/dist/lib/core/validation/baseType.d.ts +35 -0
  137. package/dist/lib/core/validation/baseType.js +70 -0
  138. package/dist/lib/core/validation/types/anything.d.ts +10 -0
  139. package/{lib → dist/lib}/core/validation/types/anything.js +7 -10
  140. package/dist/lib/core/validation/types/boolean.d.ts +16 -0
  141. package/{lib → dist/lib}/core/validation/types/boolean.js +18 -23
  142. package/dist/lib/core/validation/types/date.d.ts +17 -0
  143. package/dist/lib/core/validation/types/date.js +215 -0
  144. package/dist/lib/core/validation/types/email.d.ts +17 -0
  145. package/dist/lib/core/validation/types/email.js +80 -0
  146. package/dist/lib/core/validation/types/enum.d.ts +17 -0
  147. package/dist/lib/core/validation/types/enum.js +70 -0
  148. package/dist/lib/core/validation/types/geoPoint.d.ts +17 -0
  149. package/{lib → dist/lib}/core/validation/types/geoPoint.js +19 -24
  150. package/dist/lib/core/validation/types/geoShape.d.ts +31 -0
  151. package/dist/lib/core/validation/types/geoShape.js +280 -0
  152. package/dist/lib/core/validation/types/integer.d.ts +7 -0
  153. package/{lib → dist/lib}/core/validation/types/integer.js +21 -27
  154. package/dist/lib/core/validation/types/ipAddress.d.ts +17 -0
  155. package/dist/lib/core/validation/types/ipAddress.js +73 -0
  156. package/dist/lib/core/validation/types/numeric.d.ts +17 -0
  157. package/dist/lib/core/validation/types/numeric.js +84 -0
  158. package/dist/lib/core/validation/types/object.d.ts +24 -0
  159. package/dist/lib/core/validation/types/object.js +74 -0
  160. package/dist/lib/core/validation/types/string.d.ts +17 -0
  161. package/dist/lib/core/validation/types/string.js +85 -0
  162. package/dist/lib/core/validation/types/url.d.ts +17 -0
  163. package/dist/lib/core/validation/types/url.js +73 -0
  164. package/dist/lib/core/validation/validation.d.ts +113 -0
  165. package/dist/lib/core/validation/validation.js +692 -0
  166. package/dist/lib/kerror/codes/0-core.json +194 -0
  167. package/dist/lib/kerror/codes/1-services.json +351 -0
  168. package/dist/lib/kerror/codes/2-api.json +195 -0
  169. package/dist/lib/kerror/codes/3-network.json +151 -0
  170. package/dist/lib/kerror/codes/4-plugin.json +498 -0
  171. package/dist/lib/kerror/codes/5-validation.json +158 -0
  172. package/dist/lib/kerror/codes/6-protocol.json +28 -0
  173. package/dist/lib/kerror/codes/7-security.json +283 -0
  174. package/dist/lib/kerror/codes/8-cluster.json +16 -0
  175. package/dist/lib/kerror/codes/index.d.ts +24 -0
  176. package/dist/lib/kerror/codes/index.js +140 -0
  177. package/{lib → dist/lib}/kerror/index.d.ts +5 -5
  178. package/{lib → dist/lib}/kuzzle/Logger.d.ts +6 -0
  179. package/{lib → dist/lib}/kuzzle/Logger.js +26 -5
  180. package/dist/lib/kuzzle/dumpGenerator.d.ts +14 -0
  181. package/dist/lib/kuzzle/dumpGenerator.js +180 -0
  182. package/dist/lib/kuzzle/event/pipeRunner.d.ts +30 -0
  183. package/dist/lib/kuzzle/event/pipeRunner.js +119 -0
  184. package/dist/lib/kuzzle/event/waterfall.d.ts +2 -0
  185. package/dist/lib/kuzzle/event/waterfall.js +90 -0
  186. package/dist/lib/kuzzle/internalIndexHandler.d.ts +186 -0
  187. package/dist/lib/kuzzle/internalIndexHandler.js +174 -0
  188. package/{lib → dist/lib}/kuzzle/kuzzle.d.ts +6 -7
  189. package/{lib → dist/lib}/kuzzle/kuzzle.js +5 -2
  190. package/dist/lib/kuzzle/kuzzleStateEnum.d.ts +20 -0
  191. package/{lib → dist/lib}/kuzzle/kuzzleStateEnum.js +5 -8
  192. package/dist/lib/kuzzle/vault.d.ts +2 -0
  193. package/dist/lib/kuzzle/vault.js +63 -0
  194. package/dist/lib/model/security/rights.d.ts +8 -0
  195. package/{lib → dist/lib}/model/security/rights.js +4 -8
  196. package/{lib → dist/lib}/model/security/role.d.ts +1 -1
  197. package/{lib → dist/lib}/model/security/user.d.ts +1 -0
  198. package/dist/lib/model/storage/apiKey.d.ts +49 -0
  199. package/dist/lib/model/storage/apiKey.js +126 -0
  200. package/dist/lib/model/storage/baseModel.d.ts +100 -0
  201. package/dist/lib/model/storage/baseModel.js +211 -0
  202. package/dist/lib/service/cache/redis.d.ts +74 -0
  203. package/dist/lib/service/cache/redis.js +237 -0
  204. package/dist/lib/service/service.d.ts +30 -0
  205. package/dist/lib/service/service.js +74 -0
  206. package/{lib → dist/lib}/service/storage/7/elasticsearch.d.ts +2 -2
  207. package/{lib → dist/lib}/service/storage/7/elasticsearch.js +23 -25
  208. package/dist/lib/service/storage/7/esWrapper.d.ts +19 -0
  209. package/dist/lib/service/storage/7/esWrapper.js +245 -0
  210. package/{lib → dist/lib}/service/storage/8/elasticsearch.js +23 -25
  211. package/dist/lib/service/storage/8/esWrapper.d.ts +19 -0
  212. package/dist/lib/service/storage/8/esWrapper.js +245 -0
  213. package/{lib → dist/lib}/types/Plugin.d.ts +1 -1
  214. package/{lib/types → dist/lib/types/controllers}/Controller.d.ts +2 -2
  215. package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.d.ts +1 -1
  216. package/dist/lib/types/controllers/adminControlller.type.d.ts +5 -0
  217. package/dist/lib/types/controllers/adminControlller.type.js +3 -0
  218. package/dist/lib/types/controllers/authController.type.d.ts +5 -0
  219. package/dist/lib/types/controllers/authController.type.js +3 -0
  220. package/dist/lib/types/core/auth/formatProcessing.type.d.ts +7 -0
  221. package/dist/lib/types/core/auth/formatProcessing.type.js +3 -0
  222. package/{lib → dist/lib}/types/index.d.ts +3 -3
  223. package/{lib → dist/lib}/types/index.js +3 -3
  224. package/dist/lib/util/assertType.d.ts +41 -0
  225. package/{lib → dist/lib}/util/assertType.js +38 -56
  226. package/dist/lib/util/asyncStore.d.ts +38 -0
  227. package/dist/lib/util/asyncStore.js +70 -0
  228. package/dist/lib/util/bytes.d.ts +2 -0
  229. package/dist/lib/util/bytes.js +33 -0
  230. package/dist/lib/util/debug.d.ts +2 -0
  231. package/{lib → dist/lib}/util/debug.js +15 -23
  232. package/dist/lib/util/deprecate.d.ts +1 -0
  233. package/dist/lib/util/deprecate.js +64 -0
  234. package/dist/lib/util/didYouMean.d.ts +2 -0
  235. package/{lib → dist/lib}/util/didYouMean.js +9 -15
  236. package/dist/lib/util/extractFields.d.ts +17 -0
  237. package/{lib → dist/lib}/util/extractFields.js +18 -32
  238. package/dist/lib/util/memoize.d.ts +7 -0
  239. package/{lib → dist/lib}/util/memoize.js +14 -21
  240. package/dist/lib/util/promback.d.ts +13 -0
  241. package/dist/lib/util/promback.js +60 -0
  242. package/dist/lib/util/requestAssertions.d.ts +10 -0
  243. package/dist/lib/util/requestAssertions.js +143 -0
  244. package/dist/lib/util/safeObject.d.ts +3 -0
  245. package/{lib → dist/lib}/util/safeObject.js +7 -13
  246. package/dist/lib/util/stackTrace.d.ts +19 -0
  247. package/{lib → dist/lib}/util/stackTrace.js +35 -41
  248. package/dist/lib/util/wildcard.d.ts +1 -0
  249. package/{lib → dist/lib}/util/wildcard.js +21 -30
  250. package/dist/package.json +120 -0
  251. package/package.json +45 -58
  252. package/bin/start-kuzzle-server +0 -126
  253. package/check-node-version.js +0 -17
  254. package/lib/api/controllers/adminController.js +0 -229
  255. package/lib/api/controllers/bulkController.js +0 -210
  256. package/lib/api/controllers/collectionController.js +0 -502
  257. package/lib/api/controllers/documentController.js +0 -1156
  258. package/lib/api/controllers/indexController.js +0 -179
  259. package/lib/api/controllers/memoryStorageController.js +0 -1023
  260. package/lib/api/controllers/realtimeController.js +0 -155
  261. package/lib/api/controllers/securityController.js +0 -1571
  262. package/lib/api/controllers/serverController.js +0 -381
  263. package/lib/api/documentExtractor.js +0 -309
  264. package/lib/api/funnel.js +0 -1143
  265. package/lib/api/httpRoutes.js +0 -1547
  266. package/lib/api/rateLimiter.js +0 -87
  267. package/lib/cluster/command.js +0 -284
  268. package/lib/cluster/node.js +0 -1203
  269. package/lib/cluster/publisher.js +0 -386
  270. package/lib/cluster/subscriber.js +0 -776
  271. package/lib/cluster/workers/IDCardRenewer.js +0 -144
  272. package/lib/config/index.js +0 -351
  273. package/lib/config/sdkCompatibility.json +0 -9
  274. package/lib/core/auth/formatProcessing.js +0 -66
  275. package/lib/core/auth/passportWrapper.js +0 -126
  276. package/lib/core/cache/cacheEngine.js +0 -278
  277. package/lib/core/network/accessLogger.js +0 -322
  278. package/lib/core/network/context.js +0 -80
  279. package/lib/core/network/entryPoint.js +0 -358
  280. package/lib/core/network/httpRouter/index.js +0 -316
  281. package/lib/core/network/httpRouter/routeHandler.js +0 -111
  282. package/lib/core/network/httpRouter/routePart.js +0 -147
  283. package/lib/core/network/protocols/httpMessage.js +0 -69
  284. package/lib/core/network/protocols/httpwsProtocol.js +0 -1254
  285. package/lib/core/network/protocols/internalProtocol.js +0 -109
  286. package/lib/core/network/protocols/mqttProtocol.js +0 -291
  287. package/lib/core/network/protocols/protocol.js +0 -102
  288. package/lib/core/network/router.js +0 -255
  289. package/lib/core/plugin/plugin.js +0 -436
  290. package/lib/core/plugin/pluginRepository.js +0 -132
  291. package/lib/core/plugin/pluginsManager.js +0 -1244
  292. package/lib/core/realtime/notification/document.js +0 -108
  293. package/lib/core/realtime/notification/user.js +0 -70
  294. package/lib/core/realtime/notifier.js +0 -541
  295. package/lib/core/security/README.md +0 -223
  296. package/lib/core/security/roleRepository.js +0 -569
  297. package/lib/core/security/securityLoader.js +0 -174
  298. package/lib/core/security/userRepository.js +0 -446
  299. package/lib/core/shared/README.md +0 -3
  300. package/lib/core/shared/abstractManifest.js +0 -102
  301. package/lib/core/shared/sdk/impersonatedSdk.js +0 -94
  302. package/lib/core/statistics/index.js +0 -24
  303. package/lib/core/statistics/statistics.js +0 -373
  304. package/lib/core/storage/clientAdapter.js +0 -1045
  305. package/lib/core/storage/storageEngine.js +0 -63
  306. package/lib/core/validation/baseType.js +0 -80
  307. package/lib/core/validation/index.js +0 -24
  308. package/lib/core/validation/types/date.js +0 -284
  309. package/lib/core/validation/types/email.js +0 -92
  310. package/lib/core/validation/types/enum.js +0 -100
  311. package/lib/core/validation/types/geoShape.js +0 -370
  312. package/lib/core/validation/types/ipAddress.js +0 -83
  313. package/lib/core/validation/types/numeric.js +0 -108
  314. package/lib/core/validation/types/object.js +0 -88
  315. package/lib/core/validation/types/string.js +0 -110
  316. package/lib/core/validation/types/url.js +0 -83
  317. package/lib/core/validation/validation.js +0 -1180
  318. package/lib/kerror/codes/0-core.json +0 -194
  319. package/lib/kerror/codes/1-services.json +0 -351
  320. package/lib/kerror/codes/2-api.json +0 -195
  321. package/lib/kerror/codes/3-network.json +0 -151
  322. package/lib/kerror/codes/4-plugin.json +0 -498
  323. package/lib/kerror/codes/5-validation.json +0 -158
  324. package/lib/kerror/codes/6-protocol.json +0 -28
  325. package/lib/kerror/codes/7-security.json +0 -283
  326. package/lib/kerror/codes/8-cluster.json +0 -16
  327. package/lib/kerror/codes/index.js +0 -208
  328. package/lib/kuzzle/dumpGenerator.js +0 -259
  329. package/lib/kuzzle/event/pipeRunner.js +0 -144
  330. package/lib/kuzzle/event/waterfall.js +0 -101
  331. package/lib/kuzzle/internalIndexHandler.js +0 -234
  332. package/lib/kuzzle/vault.js +0 -89
  333. package/lib/model/storage/apiKey.js +0 -158
  334. package/lib/model/storage/baseModel.js +0 -275
  335. package/lib/service/cache/redis.js +0 -282
  336. package/lib/service/service.js +0 -84
  337. package/lib/service/storage/7/esWrapper.js +0 -303
  338. package/lib/service/storage/8/esWrapper.js +0 -303
  339. package/lib/util/asyncStore.js +0 -112
  340. package/lib/util/bytes.js +0 -36
  341. package/lib/util/deprecate.js +0 -82
  342. package/lib/util/promback.js +0 -66
  343. package/lib/util/readYamlFile.d.ts +0 -2
  344. package/lib/util/readYamlFile.js +0 -10
  345. package/lib/util/requestAssertions.js +0 -157
  346. /package/{index.d.ts → dist/index.d.ts} +0 -0
  347. /package/{index.js → dist/index.js} +0 -0
  348. /package/{lib → dist/lib}/api/controllers/baseController.d.ts +0 -0
  349. /package/{lib → dist/lib}/api/controllers/baseController.js +0 -0
  350. /package/{lib → dist/lib}/api/controllers/debugController.d.ts +0 -0
  351. /package/{lib → dist/lib}/api/controllers/debugController.js +0 -0
  352. /package/{lib → dist/lib}/api/openapi/OpenApiManager.d.ts +0 -0
  353. /package/{lib → dist/lib}/api/openapi/OpenApiManager.js +0 -0
  354. /package/{lib → dist/lib}/api/openapi/index.d.ts +0 -0
  355. /package/{lib → dist/lib}/api/openapi/index.js +0 -0
  356. /package/{lib → dist/lib}/api/openapi/openApiGenerator.d.ts +0 -0
  357. /package/{lib → dist/lib}/api/openapi/openApiGenerator.js +0 -0
  358. /package/{lib → dist/lib}/api/request/index.d.ts +0 -0
  359. /package/{lib → dist/lib}/api/request/index.js +0 -0
  360. /package/{lib → dist/lib}/api/request/kuzzleRequest.js +0 -0
  361. /package/{lib → dist/lib}/api/request/requestContext.js +0 -0
  362. /package/{lib → dist/lib}/api/request/requestInput.d.ts +0 -0
  363. /package/{lib → dist/lib}/api/request/requestInput.js +0 -0
  364. /package/{lib → dist/lib}/api/request/requestResponse.d.ts +0 -0
  365. /package/{lib → dist/lib}/api/request/requestResponse.js +0 -0
  366. /package/{lib → dist/lib}/cluster/idCardHandler.d.ts +0 -0
  367. /package/{lib → dist/lib}/cluster/idCardHandler.js +0 -0
  368. /package/{lib → dist/lib}/cluster/protobuf/command.proto +0 -0
  369. /package/{lib → dist/lib}/cluster/protobuf/sync.proto +0 -0
  370. /package/{lib → dist/lib}/cluster/state.d.ts +0 -0
  371. /package/{lib → dist/lib}/cluster/state.js +0 -0
  372. /package/{lib → dist/lib}/config/default.config.d.ts +0 -0
  373. /package/{lib → dist/lib}/config/default.config.js +0 -0
  374. /package/{lib → dist/lib}/config/documentEventAliases.js +0 -0
  375. /package/{lib → dist/lib}/core/auth/tokenManager.d.ts +0 -0
  376. /package/{lib → dist/lib}/core/auth/tokenManager.js +0 -0
  377. /package/{lib → dist/lib}/core/backend/applicationManager.d.ts +0 -0
  378. /package/{lib → dist/lib}/core/backend/applicationManager.js +0 -0
  379. /package/{lib → dist/lib}/core/backend/backend.d.ts +0 -0
  380. /package/{lib → dist/lib}/core/backend/backend.js +0 -0
  381. /package/{lib → dist/lib}/core/backend/backendCluster.d.ts +0 -0
  382. /package/{lib → dist/lib}/core/backend/backendCluster.js +0 -0
  383. /package/{lib → dist/lib}/core/backend/backendConfig.d.ts +0 -0
  384. /package/{lib → dist/lib}/core/backend/backendController.d.ts +0 -0
  385. /package/{lib → dist/lib}/core/backend/backendController.js +0 -0
  386. /package/{lib → dist/lib}/core/backend/backendErrors.d.ts +0 -0
  387. /package/{lib → dist/lib}/core/backend/backendHook.d.ts +0 -0
  388. /package/{lib → dist/lib}/core/backend/backendHook.js +0 -0
  389. /package/{lib → dist/lib}/core/backend/backendImport.d.ts +0 -0
  390. /package/{lib → dist/lib}/core/backend/backendImport.js +0 -0
  391. /package/{lib → dist/lib}/core/backend/backendOpenApi.d.ts +0 -0
  392. /package/{lib → dist/lib}/core/backend/backendOpenApi.js +0 -0
  393. /package/{lib → dist/lib}/core/backend/backendPipe.d.ts +0 -0
  394. /package/{lib → dist/lib}/core/backend/backendPipe.js +0 -0
  395. /package/{lib → dist/lib}/core/backend/backendPlugin.d.ts +0 -0
  396. /package/{lib → dist/lib}/core/backend/backendPlugin.js +0 -0
  397. /package/{lib → dist/lib}/core/backend/backendStorage.d.ts +0 -0
  398. /package/{lib → dist/lib}/core/backend/backendStorage.js +0 -0
  399. /package/{lib → dist/lib}/core/backend/backendSubscription.d.ts +0 -0
  400. /package/{lib → dist/lib}/core/backend/backendSubscription.js +0 -0
  401. /package/{lib → dist/lib}/core/backend/backendVault.d.ts +0 -0
  402. /package/{lib → dist/lib}/core/backend/backendVault.js +0 -0
  403. /package/{lib → dist/lib}/core/backend/index.d.ts +0 -0
  404. /package/{lib → dist/lib}/core/backend/index.js +0 -0
  405. /package/{lib → dist/lib}/core/backend/internalLogger.d.ts +0 -0
  406. /package/{lib → dist/lib}/core/backend/internalLogger.js +0 -0
  407. /package/{lib → dist/lib}/core/cache/cacheDbEnum.d.ts +0 -0
  408. /package/{lib → dist/lib}/core/cache/cacheDbEnum.js +0 -0
  409. /package/{lib → dist/lib}/core/debug/kuzzleDebugger.d.ts +0 -0
  410. /package/{lib → dist/lib}/core/debug/kuzzleDebugger.js +0 -0
  411. /package/{lib → dist/lib}/core/plugin/pluginContext.d.ts +0 -0
  412. /package/{lib → dist/lib}/core/realtime/channel.d.ts +0 -0
  413. /package/{lib → dist/lib}/core/realtime/channel.js +0 -0
  414. /package/{lib → dist/lib}/core/realtime/connectionRooms.d.ts +0 -0
  415. /package/{lib → dist/lib}/core/realtime/connectionRooms.js +0 -0
  416. /package/{lib → dist/lib}/core/realtime/hotelClerk.d.ts +0 -0
  417. /package/{lib → dist/lib}/core/realtime/hotelClerk.js +0 -0
  418. /package/{lib → dist/lib}/core/realtime/room.d.ts +0 -0
  419. /package/{lib → dist/lib}/core/realtime/room.js +0 -0
  420. /package/{lib → dist/lib}/core/realtime/subscription.d.ts +0 -0
  421. /package/{lib → dist/lib}/core/realtime/subscription.js +0 -0
  422. /package/{lib → dist/lib}/core/security/profileRepository.d.ts +0 -0
  423. /package/{lib → dist/lib}/core/security/profileRepository.js +0 -0
  424. /package/{lib → dist/lib}/core/security/tokenRepository.d.ts +0 -0
  425. /package/{lib → dist/lib}/core/shared/KoncordeWrapper.d.ts +0 -0
  426. /package/{lib → dist/lib}/core/shared/KoncordeWrapper.js +0 -0
  427. /package/{lib → dist/lib}/core/shared/ObjectRepository.d.ts +0 -0
  428. /package/{lib → dist/lib}/core/shared/ObjectRepository.js +0 -0
  429. /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.d.ts +0 -0
  430. /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.js +0 -0
  431. /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.d.ts +0 -0
  432. /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.js +0 -0
  433. /package/{lib → dist/lib}/core/shared/store.js +0 -0
  434. /package/{lib → dist/lib}/core/storage/indexCache.d.ts +0 -0
  435. /package/{lib → dist/lib}/core/storage/indexCache.js +0 -0
  436. /package/{lib → dist/lib}/core/storage/storeScopeEnum.d.ts +0 -0
  437. /package/{lib → dist/lib}/core/storage/storeScopeEnum.js +0 -0
  438. /package/{lib → dist/lib}/kerror/errors/badRequestError.d.ts +0 -0
  439. /package/{lib → dist/lib}/kerror/errors/badRequestError.js +0 -0
  440. /package/{lib → dist/lib}/kerror/errors/externalServiceError.d.ts +0 -0
  441. /package/{lib → dist/lib}/kerror/errors/externalServiceError.js +0 -0
  442. /package/{lib → dist/lib}/kerror/errors/forbiddenError.d.ts +0 -0
  443. /package/{lib → dist/lib}/kerror/errors/forbiddenError.js +0 -0
  444. /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.d.ts +0 -0
  445. /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.js +0 -0
  446. /package/{lib → dist/lib}/kerror/errors/index.d.ts +0 -0
  447. /package/{lib → dist/lib}/kerror/errors/index.js +0 -0
  448. /package/{lib → dist/lib}/kerror/errors/internalError.d.ts +0 -0
  449. /package/{lib → dist/lib}/kerror/errors/internalError.js +0 -0
  450. /package/{lib → dist/lib}/kerror/errors/kuzzleError.d.ts +0 -0
  451. /package/{lib → dist/lib}/kerror/errors/kuzzleError.js +0 -0
  452. /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.d.ts +0 -0
  453. /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.js +0 -0
  454. /package/{lib → dist/lib}/kerror/errors/notFoundError.d.ts +0 -0
  455. /package/{lib → dist/lib}/kerror/errors/notFoundError.js +0 -0
  456. /package/{lib → dist/lib}/kerror/errors/partialError.d.ts +0 -0
  457. /package/{lib → dist/lib}/kerror/errors/partialError.js +0 -0
  458. /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.d.ts +0 -0
  459. /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.js +0 -0
  460. /package/{lib → dist/lib}/kerror/errors/preconditionError.d.ts +0 -0
  461. /package/{lib → dist/lib}/kerror/errors/preconditionError.js +0 -0
  462. /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.d.ts +0 -0
  463. /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.js +0 -0
  464. /package/{lib → dist/lib}/kerror/errors/sizeLimitError.d.ts +0 -0
  465. /package/{lib → dist/lib}/kerror/errors/sizeLimitError.js +0 -0
  466. /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.d.ts +0 -0
  467. /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.js +0 -0
  468. /package/{lib → dist/lib}/kerror/errors/unauthorizedError.d.ts +0 -0
  469. /package/{lib → dist/lib}/kerror/errors/unauthorizedError.js +0 -0
  470. /package/{lib → dist/lib}/kerror/index.js +0 -0
  471. /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.d.ts +0 -0
  472. /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.js +0 -0
  473. /package/{lib → dist/lib}/kuzzle/index.d.ts +0 -0
  474. /package/{lib → dist/lib}/kuzzle/index.js +0 -0
  475. /package/{lib → dist/lib}/model/security/profile.d.ts +0 -0
  476. /package/{lib → dist/lib}/model/security/profile.js +0 -0
  477. /package/{lib → dist/lib}/model/security/role.js +0 -0
  478. /package/{lib → dist/lib}/model/security/token.d.ts +0 -0
  479. /package/{lib → dist/lib}/model/security/token.js +0 -0
  480. /package/{lib → dist/lib}/model/security/user.js +0 -0
  481. /package/{lib → dist/lib}/service/storage/8/elasticsearch.d.ts +0 -0
  482. /package/{lib → dist/lib}/service/storage/Elasticsearch.d.ts +0 -0
  483. /package/{lib → dist/lib}/service/storage/Elasticsearch.js +0 -0
  484. /package/{lib → dist/lib}/service/storage/commons/queryTranslator.d.ts +0 -0
  485. /package/{lib → dist/lib}/service/storage/commons/queryTranslator.js +0 -0
  486. /package/{lib → dist/lib}/types/ClientConnection.d.ts +0 -0
  487. /package/{lib → dist/lib}/types/ClientConnection.js +0 -0
  488. /package/{lib → dist/lib}/types/Deprecation.d.ts +0 -0
  489. /package/{lib → dist/lib}/types/Deprecation.js +0 -0
  490. /package/{lib → dist/lib}/types/EventHandler.d.ts +0 -0
  491. /package/{lib → dist/lib}/types/EventHandler.js +0 -0
  492. /package/{lib → dist/lib}/types/Global.d.ts +0 -0
  493. /package/{lib → dist/lib}/types/Global.js +0 -0
  494. /package/{lib → dist/lib}/types/HttpMessage.d.ts +0 -0
  495. /package/{lib → dist/lib}/types/HttpMessage.js +0 -0
  496. /package/{lib → dist/lib}/types/HttpStream.d.ts +0 -0
  497. /package/{lib → dist/lib}/types/HttpStream.js +0 -0
  498. /package/{lib → dist/lib}/types/Kuzzle.d.ts +0 -0
  499. /package/{lib → dist/lib}/types/Kuzzle.js +0 -0
  500. /package/{lib → dist/lib}/types/KuzzleDocument.d.ts +0 -0
  501. /package/{lib → dist/lib}/types/KuzzleDocument.js +0 -0
  502. /package/{lib → dist/lib}/types/OpenApiDefinition.d.ts +0 -0
  503. /package/{lib → dist/lib}/types/OpenApiDefinition.js +0 -0
  504. /package/{lib → dist/lib}/types/PasswordPolicy.d.ts +0 -0
  505. /package/{lib → dist/lib}/types/PasswordPolicy.js +0 -0
  506. /package/{lib → dist/lib}/types/Plugin.js +0 -0
  507. /package/{lib → dist/lib}/types/PluginManifest.d.ts +0 -0
  508. /package/{lib → dist/lib}/types/PluginManifest.js +0 -0
  509. /package/{lib → dist/lib}/types/Policy.d.ts +0 -0
  510. /package/{lib → dist/lib}/types/Policy.js +0 -0
  511. /package/{lib → dist/lib}/types/PolicyRestrictions.d.ts +0 -0
  512. /package/{lib → dist/lib}/types/PolicyRestrictions.js +0 -0
  513. /package/{lib → dist/lib}/types/ProfileDefinition.d.ts +0 -0
  514. /package/{lib → dist/lib}/types/ProfileDefinition.js +0 -0
  515. /package/{lib → dist/lib}/types/RoleDefinition.d.ts +0 -0
  516. /package/{lib → dist/lib}/types/RoleDefinition.js +0 -0
  517. /package/{lib → dist/lib}/types/StrategyDefinition.d.ts +0 -0
  518. /package/{lib → dist/lib}/types/StrategyDefinition.js +0 -0
  519. /package/{lib → dist/lib}/types/Target.d.ts +0 -0
  520. /package/{lib → dist/lib}/types/Target.js +0 -0
  521. /package/{lib → dist/lib}/types/Token.d.ts +0 -0
  522. /package/{lib → dist/lib}/types/Token.js +0 -0
  523. /package/{lib → dist/lib}/types/User.d.ts +0 -0
  524. /package/{lib → dist/lib}/types/User.js +0 -0
  525. /package/{lib → dist/lib}/types/config/DumpConfiguration.d.ts +0 -0
  526. /package/{lib → dist/lib}/types/config/DumpConfiguration.js +0 -0
  527. /package/{lib → dist/lib}/types/config/HttpConfiguration.d.ts +0 -0
  528. /package/{lib → dist/lib}/types/config/HttpConfiguration.js +0 -0
  529. /package/{lib → dist/lib}/types/config/KuzzleConfiguration.d.ts +0 -0
  530. /package/{lib → dist/lib}/types/config/KuzzleConfiguration.js +0 -0
  531. /package/{lib → dist/lib}/types/config/LimitsConfiguration.d.ts +0 -0
  532. /package/{lib → dist/lib}/types/config/LimitsConfiguration.js +0 -0
  533. /package/{lib → dist/lib}/types/config/PluginsConfiguration.d.ts +0 -0
  534. /package/{lib → dist/lib}/types/config/PluginsConfiguration.js +0 -0
  535. /package/{lib → dist/lib}/types/config/SecurityConfiguration.d.ts +0 -0
  536. /package/{lib → dist/lib}/types/config/SecurityConfiguration.js +0 -0
  537. /package/{lib → dist/lib}/types/config/ServerConfiguration.d.ts +0 -0
  538. /package/{lib → dist/lib}/types/config/ServerConfiguration.js +0 -0
  539. /package/{lib → dist/lib}/types/config/ServicesConfiguration.d.ts +0 -0
  540. /package/{lib → dist/lib}/types/config/ServicesConfiguration.js +0 -0
  541. /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +0 -0
  542. /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.js +0 -0
  543. /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +0 -0
  544. /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.js +0 -0
  545. /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +0 -0
  546. /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +0 -0
  547. /package/{lib/types → dist/lib/types/controllers}/Controller.js +0 -0
  548. /package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.js +0 -0
  549. /package/{lib/types → dist/lib/types/controllers}/ControllerRights.d.ts +0 -0
  550. /package/{lib/types → dist/lib/types/controllers}/ControllerRights.js +0 -0
  551. /package/{lib → dist/lib}/types/errors/ErrorDefinition.d.ts +0 -0
  552. /package/{lib → dist/lib}/types/errors/ErrorDefinition.js +0 -0
  553. /package/{lib → dist/lib}/types/errors/ErrorDomains.d.ts +0 -0
  554. /package/{lib → dist/lib}/types/errors/ErrorDomains.js +0 -0
  555. /package/{lib → dist/lib}/types/events/EventGenericDocument.d.ts +0 -0
  556. /package/{lib → dist/lib}/types/events/EventGenericDocument.js +0 -0
  557. /package/{lib → dist/lib}/types/events/EventProtocol.d.ts +0 -0
  558. /package/{lib → dist/lib}/types/events/EventProtocol.js +0 -0
  559. /package/{lib → dist/lib}/types/realtime/RealtimeScope.d.ts +0 -0
  560. /package/{lib → dist/lib}/types/realtime/RealtimeScope.js +0 -0
  561. /package/{lib → dist/lib}/types/realtime/RealtimeUsers.d.ts +0 -0
  562. /package/{lib → dist/lib}/types/realtime/RealtimeUsers.js +0 -0
  563. /package/{lib → dist/lib}/types/realtime/RoomList.d.ts +0 -0
  564. /package/{lib → dist/lib}/types/realtime/RoomList.js +0 -0
  565. /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.d.ts +0 -0
  566. /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.js +0 -0
  567. /package/{lib → dist/lib}/types/storage/7/Elasticsearch.d.ts +0 -0
  568. /package/{lib → dist/lib}/types/storage/7/Elasticsearch.js +0 -0
  569. /package/{lib → dist/lib}/types/storage/8/Elasticsearch.d.ts +0 -0
  570. /package/{lib → dist/lib}/types/storage/8/Elasticsearch.js +0 -0
  571. /package/{lib → dist/lib}/util/Inflector.d.ts +0 -0
  572. /package/{lib → dist/lib}/util/Inflector.js +0 -0
  573. /package/{lib → dist/lib}/util/array.d.ts +0 -0
  574. /package/{lib → dist/lib}/util/array.js +0 -0
  575. /package/{lib → dist/lib}/util/async.d.ts +0 -0
  576. /package/{lib → dist/lib}/util/async.js +0 -0
  577. /package/{lib → dist/lib}/util/bufferedPassThrough.d.ts +0 -0
  578. /package/{lib → dist/lib}/util/bufferedPassThrough.js +0 -0
  579. /package/{lib → dist/lib}/util/crypto.d.ts +0 -0
  580. /package/{lib → dist/lib}/util/crypto.js +0 -0
  581. /package/{lib → dist/lib}/util/dump-collection.d.ts +0 -0
  582. /package/{lib → dist/lib}/util/dump-collection.js +0 -0
  583. /package/{lib → dist/lib}/util/esRequest.d.ts +0 -0
  584. /package/{lib → dist/lib}/util/esRequest.js +0 -0
  585. /package/{lib → dist/lib}/util/koncordeCompat.d.ts +0 -0
  586. /package/{lib → dist/lib}/util/koncordeCompat.js +0 -0
  587. /package/{lib → dist/lib}/util/mutex.d.ts +0 -0
  588. /package/{lib → dist/lib}/util/mutex.js +0 -0
  589. /package/{lib → dist/lib}/util/name-generator.d.ts +0 -0
  590. /package/{lib → dist/lib}/util/name-generator.js +0 -0
  591. /package/{lib → dist/lib}/util/time.d.ts +0 -0
  592. /package/{lib → dist/lib}/util/time.js +0 -0
@@ -1,776 +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 { Subscriber } = require("zeromq");
25
- const protobuf = require("protobufjs");
26
- const Long = require("long");
27
-
28
- const debug = require("../util/debug")("kuzzle:cluster:sync");
29
- const DocumentNotification = require("../core/realtime/notification/document");
30
- const UserNotification = require("../core/realtime/notification/user");
31
- const { has } = require("../util/safeObject");
32
- const { fromKoncordeIndex } = require("../util/koncordeCompat");
33
-
34
- /* eslint-disable sort-keys */
35
- const stateEnum = Object.freeze({
36
- BUFFERING: 1,
37
- SANE: 2,
38
- MISSING_HEARTBEAT: 3,
39
- EVICTED: 4,
40
- });
41
- /* eslint-enable sort-keys */
42
-
43
- // Handles messages received from other nodes
44
- class ClusterSubscriber {
45
- /**
46
- * @constructor
47
- * @param {ClusterNode} localNode
48
- * @param {string} remoteNodeId - Remote node unique ID
49
- * @param {string} remoteNodeIP - address of the distant node
50
- */
51
- constructor(localNode, remoteNodeId, remoteNodeIP) {
52
- // not to be confused with remote nodes
53
- this.localNode = localNode;
54
-
55
- this.remoteNodeIP = remoteNodeIP;
56
- this.remoteNodeAddress = `tcp://${remoteNodeIP}:${this.localNode.config.ports.sync}`;
57
- this.remoteNodeId = remoteNodeId;
58
- // Used in debug mode when the node might be slower
59
- this.remoteNodeEvictionPrevented = false;
60
- this.socket = null;
61
- this.protoroot = null;
62
-
63
- // keeps track of received message ids from the remote node
64
- this.lastMessageId = new Long(0, 0, true);
65
-
66
- // A subscriber starts in the BUFFERING state, meaning it stores incoming
67
- // sync messages without processing them, until it enters the SANE state
68
- // This delays applying sync messages while the local node initializes
69
- this.state = stateEnum.BUFFERING;
70
- this.buffer = [];
71
-
72
- // keeps track of the remote node heartbeats, and evicts it if no
73
- // heartbeats have been received after some time
74
- this.heartbeatTimer = null;
75
- this.lastHeartbeat = Date.now();
76
- this.heartbeatDelay = this.localNode.heartbeatDelay * 1.5;
77
-
78
- // Messages handlers (quick translation between a topic name and its
79
- // associated handler)
80
- this.handlers = Object.freeze({
81
- AddCollection: this.handleCollectionAddition,
82
- AddIndex: this.handleIndexAddition,
83
- ClusterWideEvent: this.handleClusterWideEvent,
84
- DocumentNotification: this.handleDocumentNotification,
85
- DumpRequest: this.handleDumpRequest,
86
- Heartbeat: this.handleHeartbeat,
87
- InvalidateProfile: this.handleProfileInvalidation,
88
- InvalidateRole: this.handleRoleInvalidation,
89
- NewAuthStrategy: this.handleNewAuthStrategy,
90
- NewRealtimeRoom: this.handleNewRealtimeRoom,
91
- NodeEvicted: this.handleNodeEviction,
92
- NodePreventEviction: this.handleNodePreventEviction,
93
- NodeShutdown: this.handleNodeShutdown,
94
- RefreshIndexCache: this.handleRefreshIndexCache,
95
- RefreshValidators: this.handleRefreshValidators,
96
- RemoveAuthStrategy: this.handleAuthStrategyRemoval,
97
- RemoveCollection: this.handleCollectionRemoval,
98
- RemoveIndexes: this.handleIndexesRemoval,
99
- RemoveRealtimeRoom: this.handleRealtimeRoomRemoval,
100
- ResetSecurity: this.handleResetSecurity,
101
- Shutdown: this.handleShutdown,
102
- Subscription: this.handleSubscription,
103
- Unsubscription: this.handleUnsubscription,
104
- UserNotification: this.handleUserNotification,
105
- });
106
-
107
- this.logger = global.kuzzle.log.child("cluster:subscriber");
108
- }
109
-
110
- /**
111
- * Initializes this class, establishes a connection to the remote node and
112
- * starts listening to it.
113
- */
114
- async init() {
115
- this.protoroot = await protobuf.load(`${__dirname}/protobuf/sync.proto`);
116
- this.socket = new Subscriber();
117
- this.socket.connect(this.remoteNodeAddress);
118
- this.socket.subscribe();
119
- this.heartbeatTimer = setInterval(
120
- () => this.checkHeartbeat(),
121
- this.heartbeatDelay,
122
- );
123
-
124
- this.listen();
125
- }
126
-
127
- /**
128
- * Starts subscribing to other nodes
129
- * Do NOT wait this method: it's an infinite loop, it's not meant to ever
130
- * return (unless the remote node has been evicted)
131
- */
132
- async listen() {
133
- while (this.state !== stateEnum.EVICTED) {
134
- let topic;
135
- let data;
136
-
137
- try {
138
- [topic, data] = await this.socket.receive();
139
- } catch (e) {
140
- if (this.state !== stateEnum.EVICTED) {
141
- await this.evictNode({
142
- broadcast: true,
143
- reason: e.message,
144
- });
145
- }
146
-
147
- return;
148
- }
149
-
150
- // do nothing is the node was evicted even if we already check
151
- // for this in processData()
152
- if (this.state === stateEnum.EVICTED) {
153
- return;
154
- }
155
-
156
- if (this.state !== stateEnum.BUFFERING) {
157
- await this.processData(topic.toString(), data);
158
- } else {
159
- this.buffer.push([topic.toString(), data]);
160
- }
161
- }
162
- }
163
-
164
- /**
165
- * Plays all buffered sync messages, and switches this subscriber state from
166
- * BUFFERING to SANE.
167
- *
168
- * @param {Long} lastMessageId
169
- * @return {void}
170
- */
171
- async sync(lastMessageId) {
172
- this.lastMessageId = lastMessageId;
173
-
174
- // copy the buffer for processing: new sync messages might be buffered
175
- // while we apply older messages with async functions
176
- while (this.buffer.length > 0) {
177
- const _buffer = this.buffer;
178
- this.buffer = [];
179
-
180
- for (let i = 0; i < _buffer.length; i++) {
181
- await this.processData(_buffer[i][0], _buffer[i][1]);
182
- }
183
- }
184
-
185
- this.state = stateEnum.SANE;
186
- }
187
-
188
- /**
189
- * Decodes an incoming message, and dispatches it.
190
- * The topic name must match a protobuf message.
191
- *
192
- * /!\ This method MUST NEVER THROW
193
- * It's awaited by this.listen(), which cannot be awaited (infinite loop),
194
- * and it also cannot afford to attach a rejection handler everytime a message
195
- * is received to prevent clogging the event loop with unnecessary promises
196
- *
197
- * @param {string} topic
198
- * @param {Buffer} data
199
- * @return {void}
200
- */
201
- async processData(topic, data) {
202
- if (this.state === stateEnum.EVICTED) {
203
- return;
204
- }
205
-
206
- const decoder = this.protoroot.lookup(topic);
207
-
208
- if (decoder === null) {
209
- await this.evictNode({
210
- broadcast: true,
211
- reason: `received an invalid message from ${this.remoteNodeId} (unknown topic "${topic}")`,
212
- });
213
- return;
214
- }
215
-
216
- const message = decoder.toObject(decoder.decode(data));
217
-
218
- if (!(await this.validateMessage(message))) {
219
- return;
220
- }
221
-
222
- try {
223
- // If we are receiving messages from a node,
224
- // it means the node is alive so it should counts as an heartbeat
225
- this.handleHeartbeat();
226
- await this.handlers[topic].call(this, message);
227
- } catch (e) {
228
- this.localNode.evictSelf(
229
- `Unable to process sync message (topic: ${topic}, message: ${JSON.stringify(
230
- message,
231
- )}`,
232
- e,
233
- );
234
- }
235
- }
236
-
237
- async handleNodePreventEviction(message) {
238
- this.remoteNodeEvictionPrevented = message.evictionPrevented;
239
- }
240
-
241
- /**
242
- * Handles a heartbeat from the remote node
243
- *
244
- * @return {void}
245
- */
246
- handleHeartbeat() {
247
- this.lastHeartbeat = Date.now();
248
- }
249
-
250
- /**
251
- * Handles a node eviction message.
252
- *
253
- * @param {Object} message - decoded NodeEvicted protobuf message
254
- * @return {void}
255
- */
256
- async handleNodeEviction(message) {
257
- if (message.nodeId === this.localNode.nodeId) {
258
- this.logger.error(
259
- `[CLUSTER] Node evicted by ${message.evictor}. Reason: ${message.reason}`,
260
- );
261
- global.kuzzle.shutdown();
262
- return;
263
- }
264
-
265
- await this.localNode.evictNode(message.nodeId, {
266
- broadcast: false,
267
- reason: message.reason,
268
- });
269
- }
270
-
271
- /**
272
- * Handles a node shutdown.
273
- *
274
- * @param {Object} message - decoded NodeShutdown protobuf message
275
- * @return {void}
276
- */
277
- async handleNodeShutdown(message) {
278
- await this.localNode.evictNode(message.nodeId, {
279
- broadcast: false,
280
- reason: "Node is shutting down",
281
- });
282
- }
283
-
284
- /**
285
- * Handles messages about realtime room creations
286
- *
287
- * @param {Object} message - decoded NewRealtimeRoom protobuf message
288
- * @return {void}
289
- */
290
- handleNewRealtimeRoom(message) {
291
- const { id, index, filter, messageId } = message;
292
- const icpair = fromKoncordeIndex(index);
293
-
294
- debug(
295
- "New realtime room created by node %s (message: %d, room: %s, index: %s, collection: %s)",
296
- this.remoteNodeId,
297
- messageId,
298
- id,
299
- icpair.index,
300
- icpair.collection,
301
- );
302
-
303
- this.localNode.fullState.addRealtimeRoom(
304
- id,
305
- icpair.index,
306
- icpair.collection,
307
- JSON.parse(filter),
308
- {
309
- messageId,
310
- nodeId: this.remoteNodeId,
311
- subscribers: 0,
312
- },
313
- );
314
- }
315
-
316
- /**
317
- * Handles messages about realtime subscriptions
318
- *
319
- * @param {Object} message - decoded Subscription protobuf message
320
- * @return {void}
321
- */
322
- handleSubscription(message) {
323
- debug(
324
- "New realtime subscription received from node %s (message: %d, room: %s)",
325
- this.remoteNodeId,
326
- message.messageId,
327
- message.roomId,
328
- );
329
-
330
- this.localNode.fullState.addRealtimeSubscription(
331
- message.roomId,
332
- this.remoteNodeId,
333
- message.messageId,
334
- );
335
- }
336
-
337
- /**
338
- * Handles messages about realtime room removal
339
- *
340
- * @param {Object} message - decoded RemoveRealtimeRoom protobuf message
341
- * @return {void}
342
- */
343
- handleRealtimeRoomRemoval(message) {
344
- debug(
345
- "Realtime room removal received from node %s (message: %d, room: %s)",
346
- this.remoteNodeId,
347
- message.messageId,
348
- message.roomId,
349
- );
350
-
351
- this.localNode.fullState.removeRealtimeRoom(
352
- message.roomId,
353
- this.remoteNodeId,
354
- );
355
- }
356
-
357
- /**
358
- * Handles messages about user unsubscriptions
359
- *
360
- * @param {Object} message - decoded Unscription protobuf message
361
- * @return {void}
362
- */
363
- handleUnsubscription(message) {
364
- debug(
365
- "Realtime unsubscription received from node %s (message: %d, room: %s)",
366
- this.remoteNodeId,
367
- message.messageId,
368
- message.roomId,
369
- );
370
-
371
- this.localNode.fullState.removeRealtimeSubscription(
372
- message.roomId,
373
- this.remoteNodeId,
374
- message.messageId,
375
- );
376
- }
377
-
378
- /**
379
- * Handles messages about cluster-wide events
380
- *
381
- * @param {Object} message - decoded ClusterWideEvent protobuf message
382
- * @return {void}
383
- */
384
- handleClusterWideEvent(message) {
385
- const payload = JSON.parse(message.payload);
386
-
387
- this.localNode.eventEmitter.emit(message.event, payload);
388
- }
389
-
390
- /**
391
- * Handles messages about document notifications
392
- *
393
- * @param {Object} message - decoded DocumentNotification protobuf message
394
- * @return {void}
395
- */
396
- async handleDocumentNotification(message) {
397
- const notification = new DocumentNotification({
398
- action: message.action,
399
- collection: message.collection,
400
- controller: message.controller,
401
- index: message.index,
402
- node: this.remoteNodeId,
403
- protocol: message.protocol,
404
- requestId: message.requestId,
405
- result: JSON.parse(message.result),
406
- scope: message.scope,
407
- status: message.status,
408
- timestamp: message.timestamp.toNumber(),
409
- volatile: JSON.parse(message.volatile),
410
- });
411
-
412
- return global.kuzzle.ask(
413
- "core:realtime:document:dispatch",
414
- message.rooms,
415
- notification,
416
- );
417
- }
418
-
419
- /**
420
- * Handles messages about user notifications
421
- *
422
- * @param {Object} message - decoded UserNotification protobuf message
423
- * @return {void}
424
- */
425
- async handleUserNotification(message) {
426
- const notification = new UserNotification({
427
- action: message.action,
428
- collection: message.collection,
429
- controller: message.controller,
430
- index: message.index,
431
- node: this.remoteNodeId,
432
- protocol: message.protocol,
433
- result: JSON.parse(message.result),
434
- status: message.status,
435
- timestamp: message.timestamp.toNumber(),
436
- user: message.user,
437
- volatile: JSON.parse(message.volatile),
438
- });
439
-
440
- return global.kuzzle.ask(
441
- "core:realtime:user:sendMessage",
442
- message.room,
443
- notification,
444
- );
445
- }
446
-
447
- /**
448
- * Handles messages about new authentication strategies
449
- *
450
- * @param {Object} message - decoded NewAuthStrategy protobuf message
451
- * @return {void}
452
- */
453
- handleNewAuthStrategy(message) {
454
- const { pluginName, strategy, strategyName } = message;
455
-
456
- debug(
457
- "New authentication strategy added by node %s (plugin: %s, strategy: %s)",
458
- this.remoteNodeId,
459
- pluginName,
460
- strategyName,
461
- );
462
-
463
- this.localNode.fullState.addAuthStrategy(message);
464
-
465
- global.kuzzle.pluginsManager.registerStrategy(
466
- pluginName,
467
- strategyName,
468
- strategy,
469
- );
470
- }
471
-
472
- /**
473
- * Handles messages about authentication strategy removals
474
- *
475
- * @param {Object} message - decoded RemoveAuthStrategy protobuf message
476
- * @return {void}
477
- */
478
- handleAuthStrategyRemoval(message) {
479
- const { pluginName, strategyName } = message;
480
-
481
- debug(
482
- "Authentication strategy removed by node %s (plugin: %s, strategy: %s)",
483
- this.remoteNodeId,
484
- pluginName,
485
- strategyName,
486
- );
487
-
488
- global.kuzzle.pluginsManager.unregisterStrategy(pluginName, strategyName);
489
- this.localNode.fullState.removeAuthStrategy(strategyName);
490
- }
491
-
492
- /**
493
- * Handles messages about security resets
494
- *
495
- * @return {void}
496
- */
497
- async handleResetSecurity() {
498
- debug("Security reset received from node %s", this.remoteNodeId);
499
- await global.kuzzle.ask("core:security:profile:invalidate");
500
- await global.kuzzle.ask("core:security:role:invalidate");
501
- }
502
-
503
- /**
504
- * Handles a cross-nodes dump request
505
- *
506
- * @param {Object} message - decoded DumpRequest protobuf message
507
- * @return {void}
508
- */
509
- handleDumpRequest(message) {
510
- debug("Dump generation request received from node %s", this.remoteNodeId);
511
- global.kuzzle.dump(message.suffix);
512
- }
513
-
514
- /**
515
- * Handles cluster-wide shutdown
516
- * @return {void}
517
- */
518
- handleShutdown() {
519
- debug(
520
- "Cluster-wide shutdown request received from node %s",
521
- this.remoteNodeId,
522
- );
523
- this.logger.error(
524
- `[CLUSTER] Cluster wide shutdown from ${this.remoteNodeId}`,
525
- );
526
- global.kuzzle.shutdown();
527
- }
528
-
529
- /**
530
- * Handles changes on document validators
531
- *
532
- * @return {void}
533
- */
534
- async handleRefreshValidators() {
535
- debug(
536
- "Validators changed notification received from node %s",
537
- this.remoteNodeId,
538
- );
539
- await global.kuzzle.validation.curateSpecification();
540
- }
541
-
542
- /**
543
- * Handles manual refresh of the index cache
544
- */
545
- async handleRefreshIndexCache() {
546
- debug(
547
- "Index cache manually refresh received from node %s",
548
- this.remoteNodeId,
549
- );
550
- await global.kuzzle.ask("core:storage:public:cache:refresh", {
551
- from: "cluster",
552
- });
553
- }
554
-
555
- /**
556
- * Invalidates a profile to force reloading it from the storage space
557
- *
558
- * @param {Object} message - decoded DumpRequest protobuf message
559
- * @return {void}
560
- */
561
- async handleProfileInvalidation(message) {
562
- debug(
563
- "Profile invalidation request received from node %s (profile: %s)",
564
- this.remoteNodeId,
565
- message.profileId,
566
- );
567
-
568
- await global.kuzzle.ask(
569
- "core:security:profile:invalidate",
570
- message.profileId,
571
- );
572
- }
573
-
574
- /**
575
- * Invalidates a role to force reloading it from the storage space
576
- *
577
- * @param {Object} message - decoded DumpRequest protobuf message
578
- * @return {void}
579
- */
580
- async handleRoleInvalidation(message) {
581
- debug(
582
- "Role invalidation request received from node %s (role: %s)",
583
- this.remoteNodeId,
584
- message.roleId,
585
- );
586
-
587
- await global.kuzzle.ask("core:security:role:invalidate", message.roleId);
588
- }
589
-
590
- /**
591
- * Adds a new index to the index cache
592
- *
593
- * @param {Object} message - decoded IndexCacheAdd protobuf message
594
- * @return {void}
595
- */
596
- async handleIndexAddition(message) {
597
- const { index, scope } = message;
598
-
599
- debug(
600
- "New index added by node %s (scope: %s, index: %s)",
601
- this.remoteNodeId,
602
- scope,
603
- index,
604
- );
605
-
606
- await global.kuzzle.ask(`core:storage:${scope}:cache:addIndex`, index);
607
- }
608
-
609
- /**
610
- * Removes indexes from the index cache
611
- *
612
- * @param {Object} message - decoded IndexCacheAdd protobuf message
613
- * @return {void}
614
- */
615
- async handleIndexesRemoval(message) {
616
- const { indexes, scope } = message;
617
-
618
- debug(
619
- "Indexes removed by node %s (scope: %s, indexes: %s)",
620
- this.remoteNodeId,
621
- scope,
622
- indexes,
623
- );
624
-
625
- await global.kuzzle.ask(
626
- `core:storage:${scope}:cache:removeIndexes`,
627
- indexes,
628
- );
629
- }
630
-
631
- /**
632
- * Adds a new collection to the index cache
633
- *
634
- * @param {Object} message - decoded IndexCacheAdd protobuf message
635
- * @return {void}
636
- */
637
- async handleCollectionAddition(message) {
638
- const { collection, index, scope } = message;
639
-
640
- debug(
641
- "New collection added by node %s (scope: %s, index: %s, collection: %s)",
642
- this.remoteNodeId,
643
- scope,
644
- index,
645
- collection,
646
- );
647
-
648
- await global.kuzzle.ask(
649
- `core:storage:${scope}:cache:addCollection`,
650
- index,
651
- collection,
652
- );
653
- }
654
-
655
- /**
656
- * Removes a collection from the index cache
657
- *
658
- * @param {Object} message - decoded IndexCacheAdd protobuf message
659
- * @return {void}
660
- */
661
- async handleCollectionRemoval(message) {
662
- const { collection, index, scope } = message;
663
-
664
- debug(
665
- "Indexes removed by node %s (scope: %s, index: %s, collection: %s)",
666
- this.remoteNodeId,
667
- scope,
668
- index,
669
- collection,
670
- );
671
-
672
- await global.kuzzle.ask(
673
- `core:storage:${scope}:cache:removeCollection`,
674
- index,
675
- collection,
676
- );
677
- }
678
-
679
- /**
680
- * Checks that we did receive a heartbeat from the remote node
681
- * If a heartbeat is missing, we allow 1 heartbeat round for the remote node
682
- * to recover, otherwise we evict it from the cluster.
683
- */
684
- async checkHeartbeat() {
685
- if (this.remoteNodeEvictionPrevented) {
686
- // Fake the heartbeat while the node eviction prevention is enabled
687
- // otherwise when the node eviction prevention is disabled
688
- // the node will be evicted if it did not send a heartbeat before disabling the protection.
689
- this.lastHeartbeat = Date.now();
690
- return;
691
- }
692
-
693
- if (this.state === stateEnum.EVICTED) {
694
- return;
695
- }
696
-
697
- const now = Date.now();
698
-
699
- if (now - this.lastHeartbeat > this.heartbeatDelay) {
700
- if (this.state === stateEnum.MISSING_HEARTBEAT) {
701
- await this.evictNode({
702
- broadcast: true,
703
- reason: "heartbeat timeout",
704
- });
705
- } else {
706
- this.state = stateEnum.MISSING_HEARTBEAT;
707
- }
708
- } else {
709
- this.state = stateEnum.SANE;
710
- }
711
- }
712
-
713
- /**
714
- * Disconnects from the remote node, and frees all allocated resources.
715
- */
716
- dispose() {
717
- if (this.state === stateEnum.EVICTED) {
718
- return;
719
- }
720
-
721
- this.state = stateEnum.EVICTED;
722
- this.socket.close();
723
- this.socket = null;
724
- clearInterval(this.heartbeatTimer);
725
- }
726
-
727
- /**
728
- * Checks that the received message is the one we expect.
729
- * @param {Object} message - decoded protobuf message
730
- * @return {boolean} false: the message must be discarded, true otherwise
731
- */
732
- async validateMessage(message) {
733
- if (!has(message, "messageId")) {
734
- this.logger.warn(
735
- `Invalid message received from node ${this.remoteNodeId}. Evicting it.`,
736
- );
737
-
738
- await this.evictNode({
739
- broadcast: true,
740
- reason: 'invalid message received (missing "messageId" field)',
741
- });
742
-
743
- return false;
744
- }
745
-
746
- if (
747
- this.state === stateEnum.BUFFERING &&
748
- this.lastMessageId.greaterThanOrEqual(message.messageId)
749
- ) {
750
- return false;
751
- }
752
-
753
- this.lastMessageId = this.lastMessageId.add(1);
754
-
755
- if (this.lastMessageId.notEquals(message.messageId)) {
756
- await this.localNode.evictSelf(
757
- `Node out-of-sync: ${
758
- message.messageId - this.lastMessageId - 1
759
- } messages lost from node ${this.remoteNodeId}`,
760
- );
761
- return false;
762
- }
763
-
764
- return true;
765
- }
766
-
767
- async evictNode({ broadcast, reason }) {
768
- this.state = stateEnum.EVICTED;
769
-
770
- await this.localNode.evictNode(this.remoteNodeId, { broadcast, reason });
771
- }
772
- }
773
-
774
- ClusterSubscriber.stateEnum = stateEnum;
775
-
776
- module.exports = ClusterSubscriber;