kuzzle 2.19.2 → 2.19.5

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 (293) 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 +91 -90
  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 +4 -4
  71. package/lib/core/backend/backend.js +34 -31
  72. package/lib/core/backend/backendCluster.d.ts +8 -9
  73. package/lib/core/backend/backendCluster.js +8 -8
  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 +3 -3
  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 +3 -3
  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 +26 -25
  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 +3 -2
  227. package/lib/types/DebugModule.js +1 -1
  228. package/lib/types/EventHandler.d.ts +31 -1
  229. package/lib/types/Global.d.ts +1 -1
  230. package/lib/types/HttpStream.d.ts +2 -1
  231. package/lib/types/HttpStream.js +7 -5
  232. package/lib/types/Kuzzle.d.ts +1 -1
  233. package/lib/types/KuzzleDocument.d.ts +1 -1
  234. package/lib/types/OpenApiDefinition.d.ts +1 -1
  235. package/lib/types/PasswordPolicy.d.ts +1 -1
  236. package/lib/types/Plugin.d.ts +8 -8
  237. package/lib/types/Plugin.js +2 -2
  238. package/lib/types/Policy.d.ts +1 -1
  239. package/lib/types/RequestPayload.d.ts +1 -1
  240. package/lib/types/ResponsePayload.d.ts +1 -1
  241. package/lib/types/Token.d.ts +1 -1
  242. package/lib/types/User.d.ts +1 -1
  243. package/lib/types/config/DumpConfiguration.d.ts +8 -8
  244. package/lib/types/config/HttpConfiguration.d.ts +1 -1
  245. package/lib/types/config/KuzzleConfiguration.d.ts +1 -1
  246. package/lib/types/config/LimitsConfiguration.d.ts +8 -8
  247. package/lib/types/config/PluginsConfiguration.d.ts +4 -4
  248. package/lib/types/config/SecurityConfiguration.d.ts +62 -62
  249. package/lib/types/config/ServerConfiguration.d.ts +55 -55
  250. package/lib/types/config/ServicesConfiguration.d.ts +2 -2
  251. package/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +10 -10
  252. package/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +3 -3
  253. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +194 -110
  254. package/lib/types/errors/ErrorDefinition.d.ts +1 -1
  255. package/lib/types/errors/ErrorDomains.d.ts +1 -1
  256. package/lib/types/events/EventGenericDocument.d.ts +26 -0
  257. package/lib/types/events/EventGenericDocument.js +3 -0
  258. package/lib/types/index.d.ts +39 -38
  259. package/lib/types/index.js +1 -0
  260. package/lib/types/realtime/RealtimeScope.d.ts +1 -1
  261. package/lib/types/realtime/RealtimeUsers.d.ts +1 -1
  262. package/lib/util/assertType.js +13 -11
  263. package/lib/util/async.d.ts +1 -0
  264. package/lib/util/async.js +61 -0
  265. package/lib/util/asyncStore.js +19 -21
  266. package/lib/util/bufferedPassThrough.d.ts +3 -2
  267. package/lib/util/bufferedPassThrough.js +4 -4
  268. package/lib/util/bytes.js +9 -13
  269. package/lib/util/crypto.js +1 -1
  270. package/lib/util/debug.js +5 -5
  271. package/lib/util/deprecate.js +24 -21
  272. package/lib/util/didYouMean.js +7 -7
  273. package/lib/util/dump-collection.d.ts +2 -2
  274. package/lib/util/dump-collection.js +26 -26
  275. package/lib/util/esRequest.d.ts +1 -0
  276. package/lib/util/esRequest.js +62 -0
  277. package/lib/util/extractFields.js +24 -25
  278. package/lib/util/inflector.js +5 -5
  279. package/lib/util/koncordeCompat.d.ts +2 -2
  280. package/lib/util/koncordeCompat.js +5 -5
  281. package/lib/util/memoize.js +3 -5
  282. package/lib/util/mutex.d.ts +19 -1
  283. package/lib/util/mutex.js +39 -12
  284. package/lib/util/name-generator.js +1331 -1331
  285. package/lib/util/promback.js +8 -10
  286. package/lib/util/readYamlFile.d.ts +1 -1
  287. package/lib/util/readYamlFile.js +1 -1
  288. package/lib/util/requestAssertions.js +34 -34
  289. package/lib/util/safeObject.js +5 -5
  290. package/lib/util/stackTrace.js +20 -22
  291. package/lib/util/wildcard.js +15 -15
  292. package/package.json +28 -29
  293. package/npm-shrinkwrap.json +0 -19422
@@ -51,7 +51,6 @@ const safeObject_1 = require("../../util/safeObject");
51
51
  const lodash_1 = require("lodash");
52
52
  const moment_1 = __importDefault(require("moment"));
53
53
  const uuid = __importStar(require("uuid"));
54
- const nanoid_1 = require("nanoid");
55
54
  const requestInput_1 = require("./requestInput");
56
55
  const requestResponse_1 = require("./requestResponse");
57
56
  const requestContext_1 = require("./requestContext");
@@ -59,18 +58,18 @@ const errors_1 = require("../../kerror/errors");
59
58
  const kerror = __importStar(require("../../kerror"));
60
59
  const types_1 = require("../../types");
61
60
  const assert = __importStar(require("../../util/assertType"));
62
- const assertionError = kerror.wrap('api', 'assert');
61
+ const assertionError = kerror.wrap("api", "assert");
63
62
  // private properties
64
63
  // \u200b is a zero width space, used to masquerade console.log output
65
- const _internalId = 'internalId\u200b';
66
- const _status = 'status\u200b';
67
- const _input = 'input\u200b';
68
- const _error = 'error\u200b';
69
- const _result = 'result\u200b';
70
- const _context = 'context\u200b';
71
- const _timestamp = 'timestamp\u200b';
72
- const _response = 'response\u200b';
73
- const _deprecations = 'deprecations\u200b';
64
+ const _internalId = "internalId\u200b";
65
+ const _status = "status\u200b";
66
+ const _input = "input\u200b";
67
+ const _error = "error\u200b";
68
+ const _result = "result\u200b";
69
+ const _context = "context\u200b";
70
+ const _timestamp = "timestamp\u200b";
71
+ const _response = "response\u200b";
72
+ const _deprecations = "deprecations\u200b";
74
73
  /**
75
74
  * The `KuzzleRequest` class represents a request being processed by Kuzzle.
76
75
  *
@@ -80,7 +79,7 @@ const _deprecations = 'deprecations\u200b';
80
79
  */
81
80
  class KuzzleRequest {
82
81
  constructor(data, options) {
83
- this[_internalId] = (0, nanoid_1.nanoid)();
82
+ this[_internalId] = uuid.v4();
84
83
  this[_status] = 102;
85
84
  this[_input] = new requestInput_1.RequestInput(data);
86
85
  this[_context] = new requestContext_1.RequestContext(options);
@@ -92,13 +91,13 @@ class KuzzleRequest {
92
91
  // property
93
92
  this[_input].headers = this[_context].connection.misc.headers;
94
93
  this.id = data.requestId
95
- ? assert.assertString('requestId', data.requestId)
96
- : (0, nanoid_1.nanoid)();
94
+ ? assert.assertString("requestId", data.requestId)
95
+ : uuid.v4();
97
96
  this[_timestamp] = data.timestamp || Date.now();
98
97
  // handling provided options
99
98
  if (options !== undefined && options !== null) {
100
- if (typeof options !== 'object' || Array.isArray(options)) {
101
- throw new errors_1.InternalError('Request options must be an object');
99
+ if (typeof options !== "object" || Array.isArray(options)) {
100
+ throw new errors_1.InternalError("Request options must be an object");
102
101
  }
103
102
  /*
104
103
  * Beware of the order of setXxx methods: if there is an
@@ -119,7 +118,7 @@ class KuzzleRequest {
119
118
  }
120
119
  else {
121
120
  const error = new errors_1.KuzzleError(options.error.message, options.error.status || 500);
122
- for (const prop of Object.keys(options.error).filter(key => key !== 'message' && key !== 'status')) {
121
+ for (const prop of Object.keys(options.error).filter((key) => key !== "message" && key !== "status")) {
123
122
  error[prop] = options.error[prop];
124
123
  }
125
124
  this.setError(error);
@@ -156,7 +155,7 @@ class KuzzleRequest {
156
155
  return this[_status];
157
156
  }
158
157
  set status(i) {
159
- this[_status] = assert.assertInteger('status', i);
158
+ this[_status] = assert.assertInteger("status", i);
160
159
  }
161
160
  /**
162
161
  * Request input
@@ -196,9 +195,10 @@ class KuzzleRequest {
196
195
  */
197
196
  setError(error) {
198
197
  if (!error || !(error instanceof Error)) {
199
- throw new errors_1.InternalError('Cannot set non-error object as a request\'s error');
198
+ throw new errors_1.InternalError("Cannot set non-error object as a request's error");
200
199
  }
201
- this[_error] = error instanceof errors_1.KuzzleError ? error : new errors_1.InternalError(error);
200
+ this[_error] =
201
+ error instanceof errors_1.KuzzleError ? error : new errors_1.InternalError(error);
202
202
  this.status = this[_error].status;
203
203
  }
204
204
  /**
@@ -221,15 +221,16 @@ class KuzzleRequest {
221
221
  */
222
222
  setResult(result, options = {}) {
223
223
  if (result instanceof Error) {
224
- throw new errors_1.InternalError('cannot set an error as a request\'s response');
224
+ throw new errors_1.InternalError("cannot set an error as a request's response");
225
225
  }
226
- if (this.context.connection.protocol !== 'http' && result instanceof types_1.HttpStream) {
227
- throw kerror.get('api', 'assert', 'forbidden_stream');
226
+ if (this.context.connection.protocol !== "http" &&
227
+ result instanceof types_1.HttpStream) {
228
+ throw kerror.get("api", "assert", "forbidden_stream");
228
229
  }
229
230
  this.status = options.status || 200;
230
231
  if (options.headers) {
231
232
  this.response.configure({
232
- headers: options.headers
233
+ headers: options.headers,
233
234
  });
234
235
  }
235
236
  if (options.raw !== undefined) {
@@ -244,7 +245,7 @@ class KuzzleRequest {
244
245
  * @param message message displayed in the warning
245
246
  */
246
247
  addDeprecation(version, message) {
247
- if (global.NODE_ENV !== 'development') {
248
+ if (global.NODE_ENV !== "development") {
248
249
  return;
249
250
  }
250
251
  const deprecation = {
@@ -329,9 +330,9 @@ class KuzzleRequest {
329
330
  * It can only be 'elasticsearch' or 'koncorde'
330
331
  */
331
332
  getLangParam() {
332
- const lang = this.getString('lang', 'elasticsearch');
333
- if (lang !== 'elasticsearch' && lang !== 'koncorde') {
334
- throw kerror.get('api', 'assert', 'invalid_argument', 'lang', '"elasticsearch" or "koncorde"');
333
+ const lang = this.getString("lang", "elasticsearch");
334
+ if (lang !== "elasticsearch" && lang !== "koncorde") {
335
+ throw kerror.get("api", "assert", "invalid_argument", "lang", '"elasticsearch" or "koncorde"');
335
336
  }
336
337
  return lang;
337
338
  }
@@ -367,7 +368,7 @@ class KuzzleRequest {
367
368
  if (def !== undefined) {
368
369
  return def;
369
370
  }
370
- throw assertionError.get('body_required');
371
+ throw assertionError.get("body_required");
371
372
  }
372
373
  return this._getNumber(body, name, `body.${name}`, def);
373
374
  }
@@ -389,7 +390,7 @@ class KuzzleRequest {
389
390
  if (def !== undefined) {
390
391
  return def;
391
392
  }
392
- throw assertionError.get('body_required');
393
+ throw assertionError.get("body_required");
393
394
  }
394
395
  return this._getInteger(body, name, `body.${name}`, def);
395
396
  }
@@ -411,7 +412,7 @@ class KuzzleRequest {
411
412
  if (def !== undefined) {
412
413
  return def;
413
414
  }
414
- throw assertionError.get('body_required');
415
+ throw assertionError.get("body_required");
415
416
  }
416
417
  return this._getString(body, name, `body.${name}`, def);
417
418
  }
@@ -433,7 +434,7 @@ class KuzzleRequest {
433
434
  if (def !== undefined) {
434
435
  return def;
435
436
  }
436
- throw assertionError.get('body_required');
437
+ throw assertionError.get("body_required");
437
438
  }
438
439
  return this._getArray(body, name, `body.${name}`, def);
439
440
  }
@@ -455,7 +456,7 @@ class KuzzleRequest {
455
456
  if (def !== undefined) {
456
457
  return def;
457
458
  }
458
- throw assertionError.get('body_required');
459
+ throw assertionError.get("body_required");
459
460
  }
460
461
  return this._getObject(body, name, `body.${name}`, def);
461
462
  }
@@ -543,17 +544,17 @@ class KuzzleRequest {
543
544
  getArrayLegacy(name, def = undefined) {
544
545
  const value = (0, lodash_1.get)(this.input.args, name, def);
545
546
  if (value === undefined) {
546
- throw assertionError.get('missing_argument', name);
547
+ throw assertionError.get("missing_argument", name);
547
548
  }
548
549
  if (Array.isArray(value)) {
549
550
  return value;
550
551
  }
551
- if (typeof value !== 'string') {
552
- throw assertionError.get('invalid_type', name, 'array');
552
+ if (typeof value !== "string") {
553
+ throw assertionError.get("invalid_type", name, "array");
553
554
  }
554
555
  // If we are using the HTTP protocol and we have a string instead of an Array
555
556
  // we try to parse it as JSON
556
- if (this.context.connection.protocol === 'http') {
557
+ if (this.context.connection.protocol === "http") {
557
558
  try {
558
559
  const parsedValue = JSON.parse(value);
559
560
  if (Array.isArray(parsedValue)) {
@@ -564,7 +565,7 @@ class KuzzleRequest {
564
565
  // Do nothing, let the code continue
565
566
  }
566
567
  }
567
- return value.split(',');
568
+ return value.split(",");
568
569
  }
569
570
  /**
570
571
  * Gets a parameter from a request arguments and checks that it is an object
@@ -596,13 +597,13 @@ class KuzzleRequest {
596
597
  getDate(name, format) {
597
598
  const args = this.input.args;
598
599
  if (args[name] === undefined) {
599
- throw assertionError.get('missing_argument', name);
600
+ throw assertionError.get("missing_argument", name);
600
601
  }
601
602
  if (format && !(0, moment_1.default)(args[name], format, true).isValid()) {
602
- throw assertionError.get('invalid_type', name, 'date');
603
+ throw assertionError.get("invalid_type", name, "date");
603
604
  }
604
605
  if (!(0, moment_1.default)(args[name], moment_1.default.ISO_8601).isValid()) {
605
- throw assertionError.get('invalid_type', name, 'date');
606
+ throw assertionError.get("invalid_type", name, "date");
606
607
  }
607
608
  return this.getString(name);
608
609
  }
@@ -617,10 +618,10 @@ class KuzzleRequest {
617
618
  getTimestamp(name) {
618
619
  const args = this.input.args;
619
620
  if (args[name] === undefined) {
620
- throw assertionError.get('missing_argument', name);
621
+ throw assertionError.get("missing_argument", name);
621
622
  }
622
623
  if ((0, moment_1.default)(args[name], true).isValid() === false) {
623
- throw assertionError.get('invalid_type', name, 'date');
624
+ throw assertionError.get("invalid_type", name, "date");
624
625
  }
625
626
  return this.getInteger(name);
626
627
  }
@@ -629,7 +630,7 @@ class KuzzleRequest {
629
630
  */
630
631
  getIndex({ required = true } = {}) {
631
632
  const index = this.input.args.index;
632
- this.checkRequired(index, 'index', required);
633
+ this.checkRequired(index, "index", required);
633
634
  return index ? String(index) : null;
634
635
  }
635
636
  /**
@@ -637,7 +638,7 @@ class KuzzleRequest {
637
638
  */
638
639
  getCollection({ required = true } = {}) {
639
640
  const collection = this.input.args.collection;
640
- this.checkRequired(collection, 'collection', required);
641
+ this.checkRequired(collection, "collection", required);
641
642
  return collection ? String(collection) : null;
642
643
  }
643
644
  /**
@@ -645,10 +646,10 @@ class KuzzleRequest {
645
646
  */
646
647
  getIndexAndCollection() {
647
648
  if (!this.input.args.index) {
648
- throw assertionError.get('missing_argument', 'index');
649
+ throw assertionError.get("missing_argument", "index");
649
650
  }
650
651
  if (!this.input.args.collection) {
651
- throw assertionError.get('missing_argument', 'collection');
652
+ throw assertionError.get("missing_argument", "collection");
652
653
  }
653
654
  return {
654
655
  collection: this.input.args.collection,
@@ -668,7 +669,7 @@ class KuzzleRequest {
668
669
  if (def !== undefined) {
669
670
  return def;
670
671
  }
671
- throw assertionError.get('body_required');
672
+ throw assertionError.get("body_required");
672
673
  }
673
674
  return this.input.body;
674
675
  }
@@ -680,20 +681,20 @@ class KuzzleRequest {
680
681
  * - `generator`: function used to generate an ID (default: 'uuid.v4')
681
682
  *
682
683
  */
683
- getId(options = { generator: uuid.v4, ifMissing: 'error' }) {
684
+ getId(options = { generator: uuid.v4, ifMissing: "error" }) {
684
685
  const id = this.input.args._id;
685
686
  options.generator = options.generator || uuid.v4; // Default to uuid v4
686
687
  if (!id) {
687
- if (options.ifMissing === 'generate') {
688
+ if (options.ifMissing === "generate") {
688
689
  return options.generator();
689
690
  }
690
- if (options.ifMissing === 'ignore') {
691
+ if (options.ifMissing === "ignore") {
691
692
  return null;
692
693
  }
693
- throw assertionError.get('missing_argument', '_id');
694
+ throw assertionError.get("missing_argument", "_id");
694
695
  }
695
- if (typeof id !== 'string') {
696
- throw assertionError.get('invalid_type', '_id', 'string');
696
+ if (typeof id !== "string") {
697
+ throw assertionError.get("invalid_type", "_id", "string");
697
698
  }
698
699
  return String(id);
699
700
  }
@@ -719,20 +720,20 @@ class KuzzleRequest {
719
720
  * Returns the search body query according to the http method
720
721
  */
721
722
  getSearchBody() {
722
- if (this.context.connection.protocol !== 'http'
723
- || this.context.connection.misc.verb !== 'GET') {
723
+ if (this.context.connection.protocol !== "http" ||
724
+ this.context.connection.misc.verb !== "GET") {
724
725
  return this.getBody({});
725
726
  }
726
- return this.getObject('searchBody', {});
727
+ return this.getObject("searchBody", {});
727
728
  }
728
729
  /**
729
730
  * Returns the search params.
730
731
  */
731
732
  getSearchParams() {
732
- const from = this.getInteger('from', 0);
733
- const size = this.getInteger('size', 10);
733
+ const from = this.getInteger("from", 0);
734
+ const size = this.getInteger("size", 10);
734
735
  const scrollTTL = this.getScrollTTLParam();
735
- const query = this.getBodyObject('query', {});
736
+ const query = this.getBodyObject("query", {});
736
737
  const searchBody = this.getSearchBody();
737
738
  return { from, query, scrollTTL, searchBody, size };
738
739
  }
@@ -741,24 +742,24 @@ class KuzzleRequest {
741
742
  */
742
743
  getScrollTTLParam() {
743
744
  const scrollTTLParam = this.input.args.scroll;
744
- if (scrollTTLParam && typeof scrollTTLParam !== 'string') {
745
- throw assertionError.get('invalid_type', 'scroll', 'string');
745
+ if (scrollTTLParam && typeof scrollTTLParam !== "string") {
746
+ throw assertionError.get("invalid_type", "scroll", "string");
746
747
  }
747
748
  return scrollTTLParam;
748
749
  }
749
750
  /**
750
751
  * Gets the refresh value.
751
752
  */
752
- getRefresh(defaultValue = 'false') {
753
+ getRefresh(defaultValue = "false") {
753
754
  if (this.input.args.refresh === undefined) {
754
755
  return defaultValue;
755
756
  }
756
- if (this.input.args.refresh === false
757
- || this.input.args.refresh === 'false'
758
- || this.input.args.refresh === null) {
759
- return 'false';
757
+ if (this.input.args.refresh === false ||
758
+ this.input.args.refresh === "false" ||
759
+ this.input.args.refresh === null) {
760
+ return "false";
760
761
  }
761
- return 'wait_for';
762
+ return "wait_for";
762
763
  }
763
764
  /**
764
765
  * Returns true if the current user have `admin` profile
@@ -768,7 +769,7 @@ class KuzzleRequest {
768
769
  if (!user) {
769
770
  return false;
770
771
  }
771
- return user.profileIds.includes('admin');
772
+ return user.profileIds.includes("admin");
772
773
  }
773
774
  /**
774
775
  * Generic object getter: boolean value
@@ -784,15 +785,15 @@ class KuzzleRequest {
784
785
  // whatever its value.
785
786
  // If a user needs to unset the option, they need to remove it from the
786
787
  // querystring.
787
- if (this.context.connection.protocol === 'http' && querystring) {
788
+ if (this.context.connection.protocol === "http" && querystring) {
788
789
  value = value !== undefined;
789
790
  (0, lodash_1.set)(obj, name, value);
790
791
  }
791
792
  else if (value === undefined || value === null) {
792
793
  value = false;
793
794
  }
794
- else if (typeof value !== 'boolean') {
795
- throw assertionError.get('invalid_type', errorName, 'boolean');
795
+ else if (typeof value !== "boolean") {
796
+ throw assertionError.get("invalid_type", errorName, "boolean");
796
797
  }
797
798
  else {
798
799
  value = Boolean(value);
@@ -810,11 +811,11 @@ class KuzzleRequest {
810
811
  _getNumber(obj, name, errorName, def = undefined) {
811
812
  let value = (0, lodash_1.get)(obj, name, def);
812
813
  if (value === undefined) {
813
- throw assertionError.get('missing_argument', errorName);
814
+ throw assertionError.get("missing_argument", errorName);
814
815
  }
815
816
  value = Number.parseFloat(value);
816
817
  if (Number.isNaN(value)) {
817
- throw assertionError.get('invalid_type', errorName, 'number');
818
+ throw assertionError.get("invalid_type", errorName, "number");
818
819
  }
819
820
  return value;
820
821
  }
@@ -829,11 +830,11 @@ class KuzzleRequest {
829
830
  _getInteger(obj, name, errorName, def = undefined) {
830
831
  let value = (0, lodash_1.get)(obj, name, def);
831
832
  if (value === undefined) {
832
- throw assertionError.get('missing_argument', errorName);
833
+ throw assertionError.get("missing_argument", errorName);
833
834
  }
834
835
  value = Number.parseFloat(value);
835
836
  if (Number.isNaN(value) || !Number.isSafeInteger(value)) {
836
- throw assertionError.get('invalid_type', errorName, 'integer');
837
+ throw assertionError.get("invalid_type", errorName, "integer");
837
838
  }
838
839
  return value;
839
840
  }
@@ -848,10 +849,10 @@ class KuzzleRequest {
848
849
  _getString(obj, name, errorName, def = undefined) {
849
850
  const value = (0, lodash_1.get)(obj, name, def);
850
851
  if (value === undefined) {
851
- throw assertionError.get('missing_argument', errorName);
852
+ throw assertionError.get("missing_argument", errorName);
852
853
  }
853
- if (typeof value !== 'string') {
854
- throw assertionError.get('invalid_type', errorName, 'string');
854
+ if (typeof value !== "string") {
855
+ throw assertionError.get("invalid_type", errorName, "string");
855
856
  }
856
857
  return value;
857
858
  }
@@ -866,14 +867,14 @@ class KuzzleRequest {
866
867
  _getArray(obj, name, errorName, def = undefined, querystring = false) {
867
868
  const value = (0, lodash_1.get)(obj, name, def);
868
869
  if (value === undefined) {
869
- throw assertionError.get('missing_argument', errorName);
870
+ throw assertionError.get("missing_argument", errorName);
870
871
  }
871
872
  if (!Array.isArray(value)) {
872
873
  // If we are using the HTTP protocol and we have a string instead of an Array
873
874
  // we try to parse it as JSON
874
- if (this.context.connection.protocol === 'http'
875
- && querystring
876
- && typeof value === 'string') {
875
+ if (this.context.connection.protocol === "http" &&
876
+ querystring &&
877
+ typeof value === "string") {
877
878
  try {
878
879
  const parsedValue = JSON.parse(value);
879
880
  if (Array.isArray(parsedValue)) {
@@ -887,7 +888,7 @@ class KuzzleRequest {
887
888
  // Do nothing, let the error be thrown below
888
889
  }
889
890
  }
890
- throw assertionError.get('invalid_type', errorName, 'array');
891
+ throw assertionError.get("invalid_type", errorName, "array");
891
892
  }
892
893
  return value;
893
894
  }
@@ -903,14 +904,14 @@ class KuzzleRequest {
903
904
  _getObject(obj, name, errorName, def = undefined, querystring = false) {
904
905
  const value = (0, lodash_1.get)(obj, name, def);
905
906
  if (value === undefined) {
906
- throw assertionError.get('missing_argument', errorName);
907
+ throw assertionError.get("missing_argument", errorName);
907
908
  }
908
909
  if (!(0, safeObject_1.isPlainObject)(value)) {
909
910
  // If we are using the HTTP protocol and we have a string instead of an Array
910
911
  // we try to parse it as JSON
911
- if (this.context.connection.protocol === 'http'
912
- && querystring
913
- && typeof value === 'string') {
912
+ if (this.context.connection.protocol === "http" &&
913
+ querystring &&
914
+ typeof value === "string") {
914
915
  try {
915
916
  const parsedValue = JSON.parse(value);
916
917
  if ((0, safeObject_1.isPlainObject)(parsedValue)) {
@@ -924,7 +925,7 @@ class KuzzleRequest {
924
925
  // Do nothing, let the error be thrown below
925
926
  }
926
927
  }
927
- throw assertionError.get('invalid_type', errorName, 'object');
928
+ throw assertionError.get("invalid_type", errorName, "object");
928
929
  }
929
930
  return value;
930
931
  }
@@ -933,7 +934,7 @@ class KuzzleRequest {
933
934
  */
934
935
  checkRequired(arg, argName, required) {
935
936
  if (required && !arg) {
936
- throw assertionError.get('missing_argument', argName);
937
+ throw assertionError.get("missing_argument", argName);
937
938
  }
938
939
  }
939
940
  }
@@ -1,5 +1,5 @@
1
- import { JSONObject } from 'kuzzle-sdk';
2
- import { User, Token } from '../../types';
1
+ import { JSONObject } from "kuzzle-sdk";
2
+ import { User, Token } from "../../types";
3
3
  export declare type ContextMisc = {
4
4
  /**
5
5
  * HTTP url
@@ -47,14 +47,14 @@ exports.RequestContext = exports.Connection = void 0;
47
47
  const assert = __importStar(require("../../util/assertType"));
48
48
  // private properties
49
49
  // \u200b is a zero width space, used to masquerade console.log output
50
- const _token = 'token\u200b';
51
- const _user = 'user\u200b';
52
- const _connection = 'connection\u200b';
50
+ const _token = "token\u200b";
51
+ const _user = "user\u200b";
52
+ const _connection = "connection\u200b";
53
53
  // Connection class properties
54
- const _c_id = 'id\u200b';
55
- const _c_protocol = 'protocol\u200b';
56
- const _c_ips = 'ips\u200b';
57
- const _c_misc = 'misc\u200b';
54
+ const _c_id = "id\u200b";
55
+ const _c_protocol = "protocol\u200b";
56
+ const _c_ips = "ips\u200b";
57
+ const _c_misc = "misc\u200b";
58
58
  /**
59
59
  * Information about the connection at the origin of the request.
60
60
  */
@@ -65,11 +65,11 @@ class Connection {
65
65
  this[_c_ips] = [];
66
66
  this[_c_misc] = {};
67
67
  Object.seal(this);
68
- if (typeof connection !== 'object' || connection === null) {
68
+ if (typeof connection !== "object" || connection === null) {
69
69
  return;
70
70
  }
71
71
  for (const prop of Object.keys(connection)) {
72
- if (['id', 'protocol', 'ips'].includes(prop)) {
72
+ if (["id", "protocol", "ips"].includes(prop)) {
73
73
  this[prop] = connection[prop];
74
74
  }
75
75
  else {
@@ -81,7 +81,7 @@ class Connection {
81
81
  * Unique identifier of the user connection
82
82
  */
83
83
  set id(str) {
84
- this[_c_id] = assert.assertString('connection.id', str);
84
+ this[_c_id] = assert.assertString("connection.id", str);
85
85
  }
86
86
  get id() {
87
87
  return this[_c_id];
@@ -90,7 +90,7 @@ class Connection {
90
90
  * Network protocol name
91
91
  */
92
92
  set protocol(str) {
93
- this[_c_protocol] = assert.assertString('connection.protocol', str);
93
+ this[_c_protocol] = assert.assertString("connection.protocol", str);
94
94
  }
95
95
  get protocol() {
96
96
  return this[_c_protocol];
@@ -99,7 +99,7 @@ class Connection {
99
99
  * Chain of IP addresses, starting from the client
100
100
  */
101
101
  set ips(arr) {
102
- this[_c_ips] = assert.assertArray('connection.ips', arr, 'string');
102
+ this[_c_ips] = assert.assertArray("connection.ips", arr, "string");
103
103
  }
104
104
  get ips() {
105
105
  return this[_c_ips];
@@ -118,7 +118,7 @@ class Connection {
118
118
  id: this[_c_id],
119
119
  ips: this[_c_ips],
120
120
  protocol: this[_c_protocol],
121
- ...this[_c_misc]
121
+ ...this[_c_misc],
122
122
  };
123
123
  }
124
124
  }
@@ -163,7 +163,7 @@ class RequestContext {
163
163
  return this[_connection].id;
164
164
  }
165
165
  set connectionId(str) {
166
- this[_connection].id = assert.assertString('connectionId', str);
166
+ this[_connection].id = assert.assertString("connectionId", str);
167
167
  }
168
168
  /**
169
169
  * @deprecated use connection.protocol instead
@@ -172,7 +172,7 @@ class RequestContext {
172
172
  return this[_connection].protocol;
173
173
  }
174
174
  set protocol(str) {
175
- this[_connection].protocol = assert.assertString('protocol', str);
175
+ this[_connection].protocol = assert.assertString("protocol", str);
176
176
  }
177
177
  /**
178
178
  * Connection that initiated the request
@@ -187,7 +187,7 @@ class RequestContext {
187
187
  return this[_token];
188
188
  }
189
189
  set token(obj) {
190
- this[_token] = assert.assertObject('token', obj);
190
+ this[_token] = assert.assertObject("token", obj);
191
191
  }
192
192
  /**
193
193
  * Associated user
@@ -196,7 +196,7 @@ class RequestContext {
196
196
  return this[_user];
197
197
  }
198
198
  set user(obj) {
199
- this[_user] = assert.assertObject('user', obj);
199
+ this[_user] = assert.assertObject("user", obj);
200
200
  }
201
201
  }
202
202
  exports.RequestContext = RequestContext;
@@ -1,4 +1,4 @@
1
- import { JSONObject } from 'kuzzle-sdk';
1
+ import { JSONObject } from "kuzzle-sdk";
2
2
  /**
3
3
  * @deprecated
4
4
  */