kuzzle 2.19.2 → 2.19.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 (289) hide show
  1. package/lib/api/controllers/adminController.js +94 -80
  2. package/lib/api/controllers/authController.js +239 -212
  3. package/lib/api/controllers/baseController.js +89 -51
  4. package/lib/api/controllers/bulkController.js +62 -49
  5. package/lib/api/controllers/clusterController.js +6 -8
  6. package/lib/api/controllers/collectionController.js +140 -129
  7. package/lib/api/controllers/debugController.d.ts +2 -2
  8. package/lib/api/controllers/debugController.js +33 -31
  9. package/lib/api/controllers/documentController.js +365 -274
  10. package/lib/api/controllers/index.js +13 -13
  11. package/lib/api/controllers/indexController.js +46 -50
  12. package/lib/api/controllers/memoryStorageController.js +410 -360
  13. package/lib/api/controllers/realtimeController.js +37 -36
  14. package/lib/api/controllers/securityController.js +553 -412
  15. package/lib/api/controllers/serverController.js +111 -104
  16. package/lib/api/documentExtractor.js +75 -68
  17. package/lib/api/funnel.js +411 -312
  18. package/lib/api/httpRoutes.js +1493 -324
  19. package/lib/api/openapi/OpenApiManager.d.ts +1 -1
  20. package/lib/api/openapi/OpenApiManager.js +22 -22
  21. package/lib/api/openapi/components/document/count.yaml +1 -1
  22. package/lib/api/openapi/components/document/create.yaml +2 -2
  23. package/lib/api/openapi/components/document/delete.yaml +1 -1
  24. package/lib/api/openapi/components/document/deleteByQuery.yaml +1 -1
  25. package/lib/api/openapi/components/document/exists.yaml +1 -1
  26. package/lib/api/openapi/components/document/get.yaml +2 -2
  27. package/lib/api/openapi/components/document/index.js +12 -12
  28. package/lib/api/openapi/components/document/replace.yaml +1 -1
  29. package/lib/api/openapi/components/document/scroll.yaml +1 -1
  30. package/lib/api/openapi/components/document/validate.yaml +1 -1
  31. package/lib/api/openapi/components/index.d.ts +2 -2
  32. package/lib/api/openapi/components/index.js +1 -1
  33. package/lib/api/openapi/components/security/index.js +1 -1
  34. package/lib/api/openapi/components/security/upsertUser.yaml +2 -3
  35. package/lib/api/openapi/index.d.ts +1 -1
  36. package/lib/api/openapi/openApiGenerator.d.ts +1 -1
  37. package/lib/api/openapi/openApiGenerator.js +7 -7
  38. package/lib/api/rateLimiter.js +12 -13
  39. package/lib/api/request/index.d.ts +4 -4
  40. package/lib/api/request/kuzzleRequest.d.ts +9 -9
  41. package/lib/api/request/kuzzleRequest.js +89 -87
  42. package/lib/api/request/requestContext.d.ts +2 -2
  43. package/lib/api/request/requestContext.js +17 -17
  44. package/lib/api/request/requestInput.d.ts +1 -1
  45. package/lib/api/request/requestInput.js +19 -19
  46. package/lib/api/request/requestResponse.d.ts +4 -4
  47. package/lib/api/request/requestResponse.js +31 -33
  48. package/lib/cluster/command.js +48 -44
  49. package/lib/cluster/idCardHandler.d.ts +1 -1
  50. package/lib/cluster/idCardHandler.js +15 -15
  51. package/lib/cluster/index.js +2 -2
  52. package/lib/cluster/node.js +301 -269
  53. package/lib/cluster/publisher.js +45 -46
  54. package/lib/cluster/state.d.ts +5 -5
  55. package/lib/cluster/state.js +8 -8
  56. package/lib/cluster/subscriber.js +163 -113
  57. package/lib/cluster/workers/IDCardRenewer.js +33 -32
  58. package/lib/config/default.config.d.ts +1 -1
  59. package/lib/config/default.config.js +212 -171
  60. package/lib/config/documentEventAliases.js +6 -6
  61. package/lib/config/index.js +161 -98
  62. package/lib/config/sdkCompatibility.json +8 -8
  63. package/lib/core/auth/formatProcessing.js +7 -7
  64. package/lib/core/auth/passportResponse.js +7 -7
  65. package/lib/core/auth/passportWrapper.js +34 -30
  66. package/lib/core/auth/tokenManager.d.ts +2 -2
  67. package/lib/core/auth/tokenManager.js +11 -10
  68. package/lib/core/backend/applicationManager.d.ts +1 -1
  69. package/lib/core/backend/applicationManager.js +2 -2
  70. package/lib/core/backend/backend.d.ts +3 -3
  71. package/lib/core/backend/backend.js +34 -31
  72. package/lib/core/backend/backendCluster.d.ts +2 -2
  73. package/lib/core/backend/backendCluster.js +5 -5
  74. package/lib/core/backend/backendConfig.d.ts +2 -2
  75. package/lib/core/backend/backendConfig.js +3 -3
  76. package/lib/core/backend/backendController.d.ts +2 -2
  77. package/lib/core/backend/backendController.js +9 -10
  78. package/lib/core/backend/backendErrors.d.ts +3 -3
  79. package/lib/core/backend/backendErrors.js +2 -1
  80. package/lib/core/backend/backendHook.d.ts +2 -2
  81. package/lib/core/backend/backendHook.js +5 -5
  82. package/lib/core/backend/backendImport.d.ts +3 -3
  83. package/lib/core/backend/backendImport.js +23 -23
  84. package/lib/core/backend/backendOpenApi.d.ts +2 -2
  85. package/lib/core/backend/backendOpenApi.js +16 -16
  86. package/lib/core/backend/backendPipe.d.ts +2 -2
  87. package/lib/core/backend/backendPipe.js +6 -6
  88. package/lib/core/backend/backendPlugin.d.ts +4 -4
  89. package/lib/core/backend/backendPlugin.js +14 -14
  90. package/lib/core/backend/backendStorage.d.ts +2 -2
  91. package/lib/core/backend/backendStorage.js +1 -2
  92. package/lib/core/backend/backendVault.d.ts +2 -2
  93. package/lib/core/backend/backendVault.js +3 -3
  94. package/lib/core/backend/index.d.ts +14 -14
  95. package/lib/core/backend/internalLogger.d.ts +1 -1
  96. package/lib/core/backend/internalLogger.js +5 -5
  97. package/lib/core/cache/cacheDbEnum.js +4 -4
  98. package/lib/core/cache/cacheEngine.js +79 -85
  99. package/lib/core/network/accessLogger.js +126 -120
  100. package/lib/core/network/clientConnection.js +5 -5
  101. package/lib/core/network/context.js +8 -8
  102. package/lib/core/network/entryPoint.js +100 -85
  103. package/lib/core/network/httpRouter/index.js +63 -60
  104. package/lib/core/network/httpRouter/routeHandler.js +18 -19
  105. package/lib/core/network/httpRouter/routePart.js +23 -19
  106. package/lib/core/network/protocolManifest.js +3 -3
  107. package/lib/core/network/protocols/httpMessage.js +8 -10
  108. package/lib/core/network/protocols/httpwsProtocol.js +305 -250
  109. package/lib/core/network/protocols/internalProtocol.js +27 -24
  110. package/lib/core/network/protocols/mqttProtocol.js +106 -96
  111. package/lib/core/network/protocols/protocol.js +20 -17
  112. package/lib/core/network/router.js +56 -46
  113. package/lib/core/plugin/plugin.js +151 -120
  114. package/lib/core/plugin/pluginContext.d.ts +7 -7
  115. package/lib/core/plugin/pluginContext.js +48 -44
  116. package/lib/core/plugin/pluginManifest.js +13 -12
  117. package/lib/core/plugin/pluginRepository.js +26 -27
  118. package/lib/core/plugin/pluginsManager.js +425 -304
  119. package/lib/core/plugin/privilegedContext.js +3 -3
  120. package/lib/core/realtime/actionEnum.js +1 -1
  121. package/lib/core/realtime/channel.d.ts +1 -1
  122. package/lib/core/realtime/channel.js +22 -22
  123. package/lib/core/realtime/connectionRooms.d.ts +1 -1
  124. package/lib/core/realtime/hotelClerk.d.ts +2 -2
  125. package/lib/core/realtime/hotelClerk.js +53 -50
  126. package/lib/core/realtime/index.js +5 -5
  127. package/lib/core/realtime/notification/document.js +25 -25
  128. package/lib/core/realtime/notification/index.js +4 -4
  129. package/lib/core/realtime/notification/server.js +3 -3
  130. package/lib/core/realtime/notification/user.js +4 -4
  131. package/lib/core/realtime/notifier.js +113 -75
  132. package/lib/core/realtime/room.d.ts +1 -1
  133. package/lib/core/realtime/subscription.d.ts +1 -1
  134. package/lib/core/realtime/subscription.js +1 -1
  135. package/lib/core/security/index.js +8 -8
  136. package/lib/core/security/profileRepository.d.ts +6 -6
  137. package/lib/core/security/profileRepository.js +48 -45
  138. package/lib/core/security/roleRepository.js +127 -115
  139. package/lib/core/security/securityLoader.js +70 -63
  140. package/lib/core/security/tokenRepository.js +132 -118
  141. package/lib/core/security/userRepository.js +104 -88
  142. package/lib/core/shared/KoncordeWrapper.d.ts +1 -1
  143. package/lib/core/shared/KoncordeWrapper.js +3 -1
  144. package/lib/core/shared/abstractManifest.js +22 -23
  145. package/lib/core/shared/repository.js +69 -67
  146. package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
  147. package/lib/core/shared/sdk/embeddedSdk.js +36 -32
  148. package/lib/core/shared/sdk/funnelProtocol.d.ts +1 -1
  149. package/lib/core/shared/sdk/funnelProtocol.js +11 -11
  150. package/lib/core/shared/sdk/impersonatedSdk.js +19 -18
  151. package/lib/core/shared/store.js +127 -32
  152. package/lib/core/statistics/index.js +2 -2
  153. package/lib/core/statistics/statistics.js +99 -85
  154. package/lib/core/storage/clientAdapter.js +219 -136
  155. package/lib/core/storage/indexCache.js +3 -3
  156. package/lib/core/storage/storageEngine.js +10 -13
  157. package/lib/core/storage/storeScopeEnum.js +3 -3
  158. package/lib/core/validation/baseType.js +12 -10
  159. package/lib/core/validation/index.js +2 -2
  160. package/lib/core/validation/types/anything.js +4 -4
  161. package/lib/core/validation/types/boolean.js +7 -7
  162. package/lib/core/validation/types/date.js +165 -131
  163. package/lib/core/validation/types/email.js +18 -21
  164. package/lib/core/validation/types/enum.js +34 -21
  165. package/lib/core/validation/types/geoPoint.js +7 -7
  166. package/lib/core/validation/types/geoShape.js +148 -125
  167. package/lib/core/validation/types/integer.js +9 -9
  168. package/lib/core/validation/types/ipAddress.js +17 -19
  169. package/lib/core/validation/types/numeric.js +36 -29
  170. package/lib/core/validation/types/object.js +19 -19
  171. package/lib/core/validation/types/string.js +36 -29
  172. package/lib/core/validation/types/url.js +17 -19
  173. package/lib/core/validation/validation.js +422 -378
  174. package/lib/kerror/codes/1-services.json +7 -1
  175. package/lib/kerror/codes/4-plugin.json +2 -2
  176. package/lib/kerror/codes/index.js +85 -63
  177. package/lib/kerror/errors/badRequestError.d.ts +1 -1
  178. package/lib/kerror/errors/externalServiceError.d.ts +1 -1
  179. package/lib/kerror/errors/forbiddenError.d.ts +1 -1
  180. package/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
  181. package/lib/kerror/errors/index.d.ts +15 -15
  182. package/lib/kerror/errors/internalError.d.ts +1 -1
  183. package/lib/kerror/errors/kuzzleError.d.ts +1 -1
  184. package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
  185. package/lib/kerror/errors/multipleErrorsError.js +1 -1
  186. package/lib/kerror/errors/notFoundError.d.ts +1 -1
  187. package/lib/kerror/errors/partialError.d.ts +1 -1
  188. package/lib/kerror/errors/partialError.js +1 -1
  189. package/lib/kerror/errors/pluginImplementationError.d.ts +1 -1
  190. package/lib/kerror/errors/pluginImplementationError.js +2 -1
  191. package/lib/kerror/errors/preconditionError.d.ts +1 -1
  192. package/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
  193. package/lib/kerror/errors/sizeLimitError.d.ts +1 -1
  194. package/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
  195. package/lib/kerror/errors/unauthorizedError.d.ts +1 -1
  196. package/lib/kerror/index.d.ts +3 -3
  197. package/lib/kerror/index.js +17 -16
  198. package/lib/kuzzle/dumpGenerator.js +130 -114
  199. package/lib/kuzzle/event/kuzzleEventEmitter.js +96 -70
  200. package/lib/kuzzle/event/pipeRunner.js +25 -24
  201. package/lib/kuzzle/event/waterfall.js +13 -15
  202. package/lib/kuzzle/index.js +2 -2
  203. package/lib/kuzzle/internalIndexHandler.js +80 -59
  204. package/lib/kuzzle/kuzzle.js +99 -99
  205. package/lib/kuzzle/kuzzleStateEnum.js +1 -1
  206. package/lib/kuzzle/log.js +23 -18
  207. package/lib/kuzzle/vault.js +34 -19
  208. package/lib/model/security/profile.d.ts +3 -3
  209. package/lib/model/security/profile.js +38 -37
  210. package/lib/model/security/rights.js +5 -5
  211. package/lib/model/security/role.d.ts +3 -3
  212. package/lib/model/security/role.js +25 -26
  213. package/lib/model/security/token.d.ts +1 -1
  214. package/lib/model/security/token.js +4 -4
  215. package/lib/model/security/user.d.ts +2 -2
  216. package/lib/model/security/user.js +9 -9
  217. package/lib/model/storage/apiKey.js +43 -33
  218. package/lib/model/storage/baseModel.js +49 -45
  219. package/lib/service/cache/redis.js +60 -55
  220. package/lib/service/service.js +17 -17
  221. package/lib/service/storage/elasticsearch.js +839 -755
  222. package/lib/service/storage/esWrapper.js +103 -86
  223. package/lib/service/storage/queryTranslator.js +52 -59
  224. package/lib/types/Controller.d.ts +3 -3
  225. package/lib/types/ControllerDefinition.d.ts +3 -3
  226. package/lib/types/DebugModule.d.ts +2 -2
  227. package/lib/types/DebugModule.js +1 -1
  228. package/lib/types/Global.d.ts +1 -1
  229. package/lib/types/HttpStream.d.ts +2 -1
  230. package/lib/types/HttpStream.js +7 -5
  231. package/lib/types/Kuzzle.d.ts +1 -1
  232. package/lib/types/KuzzleDocument.d.ts +1 -1
  233. package/lib/types/OpenApiDefinition.d.ts +1 -1
  234. package/lib/types/PasswordPolicy.d.ts +1 -1
  235. package/lib/types/Plugin.d.ts +6 -6
  236. package/lib/types/Plugin.js +2 -2
  237. package/lib/types/Policy.d.ts +1 -1
  238. package/lib/types/RequestPayload.d.ts +1 -1
  239. package/lib/types/ResponsePayload.d.ts +1 -1
  240. package/lib/types/Token.d.ts +1 -1
  241. package/lib/types/User.d.ts +1 -1
  242. package/lib/types/config/DumpConfiguration.d.ts +8 -8
  243. package/lib/types/config/HttpConfiguration.d.ts +1 -1
  244. package/lib/types/config/KuzzleConfiguration.d.ts +1 -1
  245. package/lib/types/config/LimitsConfiguration.d.ts +8 -8
  246. package/lib/types/config/PluginsConfiguration.d.ts +4 -4
  247. package/lib/types/config/SecurityConfiguration.d.ts +62 -62
  248. package/lib/types/config/ServerConfiguration.d.ts +55 -55
  249. package/lib/types/config/ServicesConfiguration.d.ts +2 -2
  250. package/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +10 -10
  251. package/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +3 -3
  252. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +194 -110
  253. package/lib/types/errors/ErrorDefinition.d.ts +1 -1
  254. package/lib/types/errors/ErrorDomains.d.ts +1 -1
  255. package/lib/types/index.d.ts +38 -38
  256. package/lib/types/realtime/RealtimeScope.d.ts +1 -1
  257. package/lib/types/realtime/RealtimeUsers.d.ts +1 -1
  258. package/lib/util/assertType.js +13 -11
  259. package/lib/util/async.d.ts +1 -0
  260. package/lib/util/async.js +61 -0
  261. package/lib/util/asyncStore.js +19 -21
  262. package/lib/util/bufferedPassThrough.d.ts +2 -2
  263. package/lib/util/bufferedPassThrough.js +4 -4
  264. package/lib/util/bytes.js +9 -13
  265. package/lib/util/crypto.js +1 -1
  266. package/lib/util/debug.js +5 -5
  267. package/lib/util/deprecate.js +24 -21
  268. package/lib/util/didYouMean.js +7 -7
  269. package/lib/util/dump-collection.d.ts +2 -2
  270. package/lib/util/dump-collection.js +26 -26
  271. package/lib/util/esRequest.d.ts +1 -0
  272. package/lib/util/esRequest.js +62 -0
  273. package/lib/util/extractFields.js +24 -25
  274. package/lib/util/inflector.js +5 -5
  275. package/lib/util/koncordeCompat.d.ts +2 -2
  276. package/lib/util/koncordeCompat.js +5 -5
  277. package/lib/util/memoize.js +3 -5
  278. package/lib/util/mutex.d.ts +19 -1
  279. package/lib/util/mutex.js +39 -12
  280. package/lib/util/name-generator.js +1331 -1331
  281. package/lib/util/promback.js +8 -10
  282. package/lib/util/readYamlFile.d.ts +1 -1
  283. package/lib/util/readYamlFile.js +1 -1
  284. package/lib/util/requestAssertions.js +34 -34
  285. package/lib/util/safeObject.js +5 -5
  286. package/lib/util/stackTrace.js +20 -22
  287. package/lib/util/wildcard.js +15 -15
  288. package/package.json +6 -6
  289. package/npm-shrinkwrap.json +0 -19422
@@ -19,12 +19,12 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- const Bluebird = require('bluebird');
24
+ const Bluebird = require("bluebird");
25
25
 
26
- const cacheDbEnum = require('../cache/cacheDbEnum');
27
- const kerror = require('../../kerror');
26
+ const cacheDbEnum = require("../cache/cacheDbEnum");
27
+ const kerror = require("../../kerror");
28
28
 
29
29
  /**
30
30
  * @class Repository
@@ -41,7 +41,7 @@ class Repository {
41
41
  * @param {{cache: cacheDbEnum, store: Store}} [options]
42
42
  * @constructor
43
43
  */
44
- constructor ({ cache = cacheDbEnum.INTERNAL, store = null } = {}) {
44
+ constructor({ cache = cacheDbEnum.INTERNAL, store = null } = {}) {
45
45
  this.ttl = global.kuzzle.config.repositories.common.cacheTTL;
46
46
  this.collection = null;
47
47
  this.ObjectConstructor = null;
@@ -54,15 +54,14 @@ class Repository {
54
54
  * @param {string} id
55
55
  * @returns {Promise} resolves on a new ObjectConstructor()
56
56
  */
57
- async loadOneFromDatabase (id) {
57
+ async loadOneFromDatabase(id) {
58
58
  let response;
59
59
 
60
60
  try {
61
61
  response = await this.store.get(this.collection, id);
62
- }
63
- catch (error) {
62
+ } catch (error) {
64
63
  if (error.status === 404) {
65
- throw kerror.get('services', 'storage', 'not_found', id);
64
+ throw kerror.get("services", "storage", "not_found", id);
66
65
  }
67
66
 
68
67
  throw error;
@@ -73,8 +72,7 @@ class Repository {
73
72
 
74
73
  if (response._source) {
75
74
  Object.assign(dto, response._source, { _id: response._id });
76
- }
77
- else {
75
+ } else {
78
76
  Object.assign(dto, response);
79
77
  }
80
78
 
@@ -89,16 +87,16 @@ class Repository {
89
87
  * @param {string[]|object[]} _ids
90
88
  * @returns {Promise<object>}
91
89
  */
92
- async loadMultiFromDatabase (ids) {
90
+ async loadMultiFromDatabase(ids) {
93
91
  const { items } = await this.store.mGet(this.collection, ids);
94
92
 
95
93
  if (items.length === 0) {
96
94
  return [];
97
95
  }
98
96
 
99
- return Bluebird.map(
100
- items,
101
- doc => this.fromDTO(Object.assign({}, doc._source, { _id: doc._id })));
97
+ return Bluebird.map(items, (doc) =>
98
+ this.fromDTO(Object.assign({}, doc._source, { _id: doc._id }))
99
+ );
102
100
  }
103
101
 
104
102
  /**
@@ -108,8 +106,12 @@ class Repository {
108
106
  * @param {object} [options] - optional search arguments (from, size, scroll)
109
107
  * @returns {Promise}
110
108
  */
111
- async search (searchBody, options = {}) {
112
- const response = await this.store.search(this.collection, searchBody, options);
109
+ async search(searchBody, options = {}) {
110
+ const response = await this.store.search(
111
+ this.collection,
112
+ searchBody,
113
+ options
114
+ );
113
115
 
114
116
  return this._formatSearchResults(response);
115
117
  }
@@ -119,7 +121,7 @@ class Repository {
119
121
  * @param {string} scrollId
120
122
  * @param {string} [ttl]
121
123
  */
122
- async scroll (scrollId, ttl) {
124
+ async scroll(scrollId, ttl) {
123
125
  const response = await this.store.scroll(scrollId, ttl);
124
126
 
125
127
  return this._formatSearchResults(response);
@@ -137,7 +139,7 @@ class Repository {
137
139
  * @param {object} [options] - Optional options.
138
140
  * @returns {Promise}
139
141
  */
140
- async loadFromCache (id, options = {}) {
142
+ async loadFromCache(id, options = {}) {
141
143
  const key = options.key || this.getCacheKey(id);
142
144
  let response;
143
145
 
@@ -149,9 +151,8 @@ class Repository {
149
151
  }
150
152
 
151
153
  return await this.fromDTO(Object.assign({}, JSON.parse(response)));
152
- }
153
- catch (err) {
154
- throw kerror.get('services', 'cache', 'read_failed', err.message);
154
+ } catch (err) {
155
+ throw kerror.get("services", "cache", "read_failed", err.message);
155
156
  }
156
157
  }
157
158
 
@@ -172,7 +173,7 @@ class Repository {
172
173
  * @param {object} [options] - Optional options.
173
174
  * @returns {Promise}
174
175
  */
175
- async load (id, options = {}) {
176
+ async load(id, options = {}) {
176
177
  if (this.cacheDb === cacheDbEnum.NONE) {
177
178
  return this.loadOneFromDatabase(id);
178
179
  }
@@ -205,21 +206,23 @@ class Repository {
205
206
  * @param {object} [options] - The persistence options
206
207
  * @returns {Promise}
207
208
  */
208
- persistToDatabase (object, options = {}) {
209
- const method = options.method || 'createOrReplace';
209
+ persistToDatabase(object, options = {}) {
210
+ const method = options.method || "createOrReplace";
210
211
 
211
- if (method === 'create') {
212
+ if (method === "create") {
212
213
  return this.store.create(
213
214
  this.collection,
214
215
  this.serializeToDatabase(object),
215
- { ...options, id: object._id });
216
+ { ...options, id: object._id }
217
+ );
216
218
  }
217
219
 
218
220
  return this.store[method](
219
221
  this.collection,
220
222
  object._id,
221
223
  this.serializeToDatabase(object),
222
- options);
224
+ options
225
+ );
223
226
  }
224
227
 
225
228
  /**
@@ -231,7 +234,7 @@ class Repository {
231
234
  * @param {object} [options] - optional options for the current operation
232
235
  * @returns {Promise}
233
236
  */
234
- delete (object, options = {}) {
237
+ delete(object, options = {}) {
235
238
  const promises = [];
236
239
 
237
240
  if (this.cacheDb !== cacheDbEnum.NONE) {
@@ -251,7 +254,7 @@ class Repository {
251
254
  * @param {string} id
252
255
  * @param {object} [options]
253
256
  */
254
- deleteFromDatabase (id, options = {}) {
257
+ deleteFromDatabase(id, options = {}) {
255
258
  return this.store.delete(this.collection, id, options);
256
259
  }
257
260
 
@@ -267,13 +270,13 @@ class Repository {
267
270
  * @param {object} [options] - Optional options for the current operation
268
271
  * @returns {Promise}
269
272
  */
270
- async persistToCache (object, options = {}) {
273
+ async persistToCache(object, options = {}) {
271
274
  const key = options.key || this.getCacheKey(object._id);
272
275
  const value = JSON.stringify(this.serializeToCache(object));
273
276
  const ttl = options.ttl !== undefined ? options.ttl : this.ttl;
274
277
 
275
278
  await global.kuzzle.ask(`core:cache:${this.cacheDb}:store`, key, value, {
276
- ttl
279
+ ttl,
277
280
  });
278
281
 
279
282
  return object;
@@ -288,7 +291,7 @@ class Repository {
288
291
  * @param {object} [options] - optional options for the current operation
289
292
  * @returns {Promise}
290
293
  */
291
- deleteFromCache (id, options = {}) {
294
+ deleteFromCache(id, options = {}) {
292
295
  const key = options.key || this.getCacheKey(id);
293
296
 
294
297
  return global.kuzzle.ask(`core:cache:${this.cacheDb}:del`, key);
@@ -299,19 +302,17 @@ class Repository {
299
302
  * @param {object} [options] - optional options for the current operation
300
303
  * @returns {Promise}
301
304
  */
302
- refreshCacheTTL (object, options = {}) {
305
+ refreshCacheTTL(object, options = {}) {
303
306
  const key = options.key || this.getCacheKey(object._id);
304
307
  let ttl;
305
308
 
306
309
  if (options.ttl !== undefined) {
307
310
  ttl = options.ttl;
308
- }
309
- else if (object.ttl !== undefined) {
311
+ } else if (object.ttl !== undefined) {
310
312
  // if a TTL has been defined at the entry creation, we should
311
313
  // use it
312
314
  ttl = object.ttl;
313
- }
314
- else {
315
+ } else {
315
316
  ttl = this.ttl;
316
317
  }
317
318
 
@@ -327,7 +328,7 @@ class Repository {
327
328
  * @param {object} [options] - optional options for the current operation
328
329
  * @returns {*}
329
330
  */
330
- expireFromCache (object, options = {}) {
331
+ expireFromCache(object, options = {}) {
331
332
  const key = options.key || this.getCacheKey(object._id);
332
333
  return global.kuzzle.ask(`core:cache:${this.cacheDb}:expire`, key, -1);
333
334
  }
@@ -338,7 +339,7 @@ class Repository {
338
339
  * @param {object} object - The object to serialize
339
340
  * @returns {object}
340
341
  */
341
- serializeToCache (object) {
342
+ serializeToCache(object) {
342
343
  return this.toDTO(object);
343
344
  }
344
345
 
@@ -348,7 +349,7 @@ class Repository {
348
349
  * @param {object} object - The object to serialize
349
350
  * @returns {object}
350
351
  */
351
- serializeToDatabase (object) {
352
+ serializeToDatabase(object) {
352
353
  const dto = this.toDTO(object);
353
354
  delete dto._id;
354
355
  return dto;
@@ -357,7 +358,7 @@ class Repository {
357
358
  /**
358
359
  * @param {string} id
359
360
  */
360
- getCacheKey (id) {
361
+ getCacheKey(id) {
361
362
  return `repos/${this.index}/${this.collection}/${id}`;
362
363
  }
363
364
 
@@ -365,7 +366,7 @@ class Repository {
365
366
  * @param {object} dto
366
367
  * @returns {Promise<ObjectConstructor>}
367
368
  */
368
- async fromDTO (dto) {
369
+ async fromDTO(dto) {
369
370
  const o = new this.ObjectConstructor();
370
371
  Object.assign(o, dto);
371
372
 
@@ -376,7 +377,7 @@ class Repository {
376
377
  * @param {ObjectConstructor} o
377
378
  * @returns {object}
378
379
  */
379
- toDTO (o) {
380
+ toDTO(o) {
380
381
  return Object.assign({}, o);
381
382
  }
382
383
 
@@ -387,7 +388,7 @@ class Repository {
387
388
  * @param {object} part
388
389
  * @returns {Promise<integer>} total deleted objects
389
390
  */
390
- async truncate (options) {
391
+ async truncate(options) {
391
392
  // Allows safe overrides, as _truncate is called recursively
392
393
  return this._truncate(options);
393
394
  }
@@ -396,16 +397,19 @@ class Repository {
396
397
  * Do not override this: this function calls itself.
397
398
  * @private
398
399
  */
399
- async _truncate (options, part = null) {
400
+ async _truncate(options, part = null) {
400
401
  if (part === null) {
401
- const objects = await this.search({}, { refresh: options.refresh, scroll: '5s', size: 100 });
402
+ const objects = await this.search(
403
+ {},
404
+ { refresh: options.refresh, scroll: "5s", size: 100 }
405
+ );
402
406
  const deleted = await this._truncatePart(objects, options);
403
407
 
404
408
  if (objects.hits.length < objects.total) {
405
409
  const total = await this._truncate(options, {
406
410
  fetched: objects.hits.length,
407
411
  scrollId: objects.scrollId,
408
- total: objects.total
412
+ total: objects.total,
409
413
  });
410
414
 
411
415
  return deleted + total;
@@ -414,7 +418,7 @@ class Repository {
414
418
  return deleted;
415
419
  }
416
420
 
417
- const objects = await this.scroll(part.scrollId, '5s');
421
+ const objects = await this.scroll(part.scrollId, "5s");
418
422
  const deleted = await this._truncatePart(objects, options);
419
423
 
420
424
  part.fetched += objects.hits.length;
@@ -435,26 +439,24 @@ class Repository {
435
439
  * @returns {Promise<integer>} count of deleted objects
436
440
  * @private
437
441
  */
438
- async _truncatePart (objects, options) {
439
- return Bluebird
440
- .map(objects.hits, async object => {
441
- // profile and role repositories have protected objects, we can't delete
442
- // them
443
- const protectedObjects = ['profiles', 'roles']
444
- .indexOf(this.collection) !== -1
445
- ? ['admin', 'default', 'anonymous']
442
+ async _truncatePart(objects, options) {
443
+ return Bluebird.map(objects.hits, async (object) => {
444
+ // profile and role repositories have protected objects, we can't delete
445
+ // them
446
+ const protectedObjects =
447
+ ["profiles", "roles"].indexOf(this.collection) !== -1
448
+ ? ["admin", "default", "anonymous"]
446
449
  : [];
447
450
 
448
- if (protectedObjects.indexOf(object._id) !== -1) {
449
- return 0;
450
- }
451
+ if (protectedObjects.indexOf(object._id) !== -1) {
452
+ return 0;
453
+ }
451
454
 
452
- const loaded = await this.load(object._id);
453
- await this.delete(loaded, options);
455
+ const loaded = await this.load(object._id);
456
+ await this.delete(loaded, options);
454
457
 
455
- return 1;
456
- })
457
- .reduce((total, deleted) => total + deleted, 0);
458
+ return 1;
459
+ }).reduce((total, deleted) => total + deleted, 0);
458
460
  }
459
461
 
460
462
  /**
@@ -463,7 +465,7 @@ class Repository {
463
465
  * @returns {Promise<object>}
464
466
  * @private
465
467
  */
466
- async _formatSearchResults (raw) {
468
+ async _formatSearchResults(raw) {
467
469
  const result = {
468
470
  aggregations: raw.aggregations,
469
471
  hits: [],
@@ -472,7 +474,7 @@ class Repository {
472
474
  };
473
475
 
474
476
  if (raw.hits && raw.hits.length > 0) {
475
- result.hits = await Bluebird.map(raw.hits, doc => {
477
+ result.hits = await Bluebird.map(raw.hits, (doc) => {
476
478
  return this.fromDTO(Object.assign({}, doc._source, { _id: doc._id }));
477
479
  });
478
480
  }
@@ -1,5 +1,5 @@
1
- import { RealtimeController, Notification, JSONObject, ScopeOption, UserOption, Kuzzle, RequestPayload } from 'kuzzle-sdk';
2
- import { ResponsePayload } from '../../../types';
1
+ import { RealtimeController, Notification, JSONObject, ScopeOption, UserOption, Kuzzle, RequestPayload } from "kuzzle-sdk";
2
+ import { ResponsePayload } from "../../../types";
3
3
  interface EmbeddedRealtime extends RealtimeController {
4
4
  /**
5
5
  * Subscribes by providing a set of filters: messages, document changes
@@ -53,30 +53,30 @@ const funnelProtocol_1 = require("./funnelProtocol");
53
53
  const safeObject_1 = require("../../../util/safeObject");
54
54
  const kerror = __importStar(require("../../../kerror"));
55
55
  const impersonatedSdk_1 = __importDefault(require("./impersonatedSdk"));
56
- const contextError = kerror.wrap('plugin', 'context');
56
+ const contextError = kerror.wrap("plugin", "context");
57
57
  const forbiddenEmbeddedActions = {
58
- 'auth': new Set([
59
- 'checkRights',
60
- 'createApiKey',
61
- 'createMyCredentials',
62
- 'credentialsExist',
63
- 'deleteApiKey',
64
- 'getCurrentUser',
65
- 'getMyCredentials',
66
- 'getMyRights',
67
- 'getStrategies',
68
- 'logout',
69
- 'refreshToken',
70
- 'searchApiKeys',
71
- 'updateMyCredentials',
72
- 'updateSelf',
73
- 'validateMyCredentials',
58
+ auth: new Set([
59
+ "checkRights",
60
+ "createApiKey",
61
+ "createMyCredentials",
62
+ "credentialsExist",
63
+ "deleteApiKey",
64
+ "getCurrentUser",
65
+ "getMyCredentials",
66
+ "getMyRights",
67
+ "getStrategies",
68
+ "logout",
69
+ "refreshToken",
70
+ "searchApiKeys",
71
+ "updateMyCredentials",
72
+ "updateSelf",
73
+ "validateMyCredentials",
74
74
  ]),
75
75
  };
76
76
  const warnEmbeddedActions = {
77
- 'auth': {
78
- 'login': 'EmbeddedSDK.login is deprecated, use user impersonation instead',
79
- }
77
+ auth: {
78
+ login: "EmbeddedSDK.login is deprecated, use user impersonation instead",
79
+ },
80
80
  };
81
81
  /**
82
82
  * Kuzzle embedded SDK to make API calls inside applications or plugins.
@@ -93,8 +93,8 @@ class EmbeddedSDK extends kuzzle_sdk_1.Kuzzle {
93
93
  * @param options - Optional sdk arguments
94
94
  */
95
95
  as(user, options = { checkRights: false }) {
96
- if (!(0, safeObject_1.isPlainObject)(user) || typeof user._id !== 'string') {
97
- throw contextError.get('invalid_user');
96
+ if (!(0, safeObject_1.isPlainObject)(user) || typeof user._id !== "string") {
97
+ throw contextError.get("invalid_user");
98
98
  }
99
99
  return new impersonatedSdk_1.default(user._id, options);
100
100
  }
@@ -109,18 +109,22 @@ class EmbeddedSDK extends kuzzle_sdk_1.Kuzzle {
109
109
  */
110
110
  query(request, options = {}) {
111
111
  // By default, do not propagate realtime notification accross cluster nodes
112
- if ((0, safeObject_1.isPlainObject)(request)
113
- && request.controller === 'realtime'
114
- && request.action === 'subscribe') {
115
- request.propagate = options.propagate === undefined || options.propagate === null
116
- ? false
117
- : options.propagate;
112
+ if ((0, safeObject_1.isPlainObject)(request) &&
113
+ request.controller === "realtime" &&
114
+ request.action === "subscribe") {
115
+ request.propagate =
116
+ options.propagate === undefined || options.propagate === null
117
+ ? false
118
+ : options.propagate;
118
119
  }
119
- if (forbiddenEmbeddedActions[request.controller] !== undefined
120
- && forbiddenEmbeddedActions[request.controller].has(request.action)) {
121
- throw kerror.get('api', 'process', 'forbidden_embedded_sdk_action', request.controller, request.action, ', use user impersonation or security controller instead');
120
+ if (forbiddenEmbeddedActions[request.controller] !== undefined &&
121
+ forbiddenEmbeddedActions[request.controller].has(request.action)) {
122
+ throw kerror.get("api", "process", "forbidden_embedded_sdk_action", request.controller, request.action, ", use user impersonation or security controller instead");
122
123
  }
123
- const warning = lodash_1.default.get(warnEmbeddedActions, [request.controller, request.action]);
124
+ const warning = lodash_1.default.get(warnEmbeddedActions, [
125
+ request.controller,
126
+ request.action,
127
+ ]);
124
128
  if (warning) {
125
129
  global.kuzzle.log.warn(warning);
126
130
  }
@@ -1,4 +1,4 @@
1
- import { KuzzleEventEmitter, RequestPayload } from 'kuzzle-sdk';
1
+ import { KuzzleEventEmitter, RequestPayload } from "kuzzle-sdk";
2
2
  export declare class FunnelProtocol extends KuzzleEventEmitter {
3
3
  private id;
4
4
  private connectionId;
@@ -50,13 +50,13 @@ const kerror = __importStar(require("../../../kerror"));
50
50
  class FunnelProtocol extends kuzzle_sdk_1.KuzzleEventEmitter {
51
51
  constructor() {
52
52
  super();
53
- this.id = 'funnel';
53
+ this.id = "funnel";
54
54
  this.connectionId = null;
55
55
  /**
56
56
  * Realtime notifications are sent by the InternalProtocol
57
57
  * through the internal event system.
58
58
  */
59
- global.kuzzle.on('core:network:internal:message', message => {
59
+ global.kuzzle.on("core:network:internal:message", (message) => {
60
60
  // Send the notifications to the SDK for the internal Room mechanism
61
61
  this.emit(message.room, message);
62
62
  });
@@ -69,28 +69,28 @@ class FunnelProtocol extends kuzzle_sdk_1.KuzzleEventEmitter {
69
69
  */
70
70
  async query(request) {
71
71
  if (!this.connectionId) {
72
- this.connectionId = await global.kuzzle.ask('core:network:internal:connectionId:get');
72
+ this.connectionId = await global.kuzzle.ask("core:network:internal:connectionId:get");
73
73
  }
74
74
  const requestOptions = {
75
75
  connection: {
76
76
  id: this.connectionId,
77
- protocol: this.id
77
+ protocol: this.id,
78
78
  },
79
79
  user: null,
80
80
  };
81
81
  // Validate and use the provided request.kuid
82
82
  if (request.__kuid__) {
83
- if (typeof request.__kuid__ !== 'string') {
84
- throw kerror.get('plugin', 'context', 'invalid_user');
83
+ if (typeof request.__kuid__ !== "string") {
84
+ throw kerror.get("plugin", "context", "invalid_user");
85
85
  }
86
86
  // Get the user and store it in this context to prevent any possible race conditions
87
- requestOptions.user = await global.kuzzle.ask('core:security:user:get', request.__kuid__);
87
+ requestOptions.user = await global.kuzzle.ask("core:security:user:get", request.__kuid__);
88
88
  }
89
89
  const kuzzleRequest = new request_1.Request(request, requestOptions);
90
- if (requestOptions.user
91
- && request.__checkRights__
92
- && !await requestOptions.user.isActionAllowed(kuzzleRequest)) {
93
- throw kerror.get('security', 'rights', 'forbidden', kuzzleRequest.input.controller, kuzzleRequest.input.action, requestOptions.user._id);
90
+ if (requestOptions.user &&
91
+ request.__checkRights__ &&
92
+ !(await requestOptions.user.isActionAllowed(kuzzleRequest))) {
93
+ throw kerror.get("security", "rights", "forbidden", kuzzleRequest.input.controller, kuzzleRequest.input.action, requestOptions.user._id);
94
94
  }
95
95
  const result = await global.kuzzle.funnel.executePluginRequest(kuzzleRequest);
96
96
  return { result };
@@ -19,24 +19,24 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- const nativeControllers = require('../../../api/controllers');
24
+ const nativeControllers = require("../../../api/controllers");
25
25
 
26
26
  class ImpersonatedSDK {
27
- constructor (kuid, options = {}) {
27
+ constructor(kuid, options = {}) {
28
28
  this.kuid = kuid;
29
29
  this.checkRights = options.checkRights || false;
30
30
 
31
31
  for (const controller of Object.keys(nativeControllers)) {
32
32
  // @todo in the future, native controller names should be normalized to sdk naming
33
33
  const controllerName = controller
34
- .replace('Controller', '')
35
- .replace('MemoryStorage', 'ms')
34
+ .replace("Controller", "")
35
+ .replace("MemoryStorage", "ms")
36
36
  .toLowerCase();
37
37
  const controllerProxy = `${controllerName}Proxy`;
38
38
 
39
- if (! global.app.sdk[controllerName]) {
39
+ if (!global.app.sdk[controllerName]) {
40
40
  continue;
41
41
  }
42
42
 
@@ -44,8 +44,7 @@ class ImpersonatedSDK {
44
44
  Reflect.defineProperty(this, controllerName, {
45
45
  get: () => {
46
46
  // If the requested controller has not yet been proxied
47
- if (! this[controllerProxy]) {
48
-
47
+ if (!this[controllerProxy]) {
49
48
  // Create a proxy object to inject our local 'query' behaviour
50
49
  // in the underlying base 'sdk' action methods so we can send
51
50
  // impersonation configuration (kuid & checkRights) to the funnel
@@ -58,31 +57,33 @@ class ImpersonatedSDK {
58
57
 
59
58
  // Call the 'ImpersonatedSdk.query' method instead
60
59
  return this.query(request, opts);
61
- }
60
+ },
62
61
  };
63
62
 
64
63
  // Make sure we bring any local methods into our new custom context
65
- Object.getOwnPropertyNames(Object.getPrototypeOf(global.app.sdk[controllerName]))
66
- .forEach((localMethod) => {
67
- if (! ['constructor', 'query'].includes(localMethod)) {
68
- customContext[localMethod] = controllerInstance[localMethod];
69
- }
70
- });
64
+ Object.getOwnPropertyNames(
65
+ Object.getPrototypeOf(global.app.sdk[controllerName])
66
+ ).forEach((localMethod) => {
67
+ if (!["constructor", "query"].includes(localMethod)) {
68
+ customContext[localMethod] =
69
+ controllerInstance[localMethod];
70
+ }
71
+ });
71
72
 
72
73
  // Return the original SDK action method AND also bind our merged custom context
73
74
  // containing our 'query' method and any original local methods
74
75
  return controllerInstance[actionName].bind(customContext);
75
- }
76
+ },
76
77
  });
77
78
  }
78
79
 
79
80
  return this[controllerProxy];
80
- }
81
+ },
81
82
  });
82
83
  }
83
84
  }
84
85
 
85
- query (request, options = {}) {
86
+ query(request, options = {}) {
86
87
  request.__kuid__ = this.kuid;
87
88
  request.__checkRights__ = this.checkRights;
88
89