kuzzle 2.17.6 → 2.18.0

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 (211) hide show
  1. package/bin/start-kuzzle-server +1 -1
  2. package/lib/api/controllers/adminController.js +1 -1
  3. package/lib/api/controllers/authController.js +7 -2
  4. package/lib/api/controllers/baseController.js +1 -1
  5. package/lib/api/controllers/bulkController.js +1 -1
  6. package/lib/api/controllers/clusterController.js +1 -1
  7. package/lib/api/controllers/collectionController.js +1 -1
  8. package/lib/api/controllers/documentController.js +7 -2
  9. package/lib/api/controllers/index.js +1 -1
  10. package/lib/api/controllers/indexController.js +11 -7
  11. package/lib/api/controllers/memoryStorageController.js +1 -1
  12. package/lib/api/controllers/realtimeController.js +1 -1
  13. package/lib/api/controllers/securityController.js +55 -23
  14. package/lib/api/controllers/serverController.js +1 -1
  15. package/lib/api/documentExtractor.js +1 -1
  16. package/lib/api/funnel.js +1 -1
  17. package/lib/api/httpRoutes.js +7 -5
  18. package/lib/api/openapi/OpenApiManager.js +5 -1
  19. package/lib/api/openapi/components/document/get.yaml +1 -1
  20. package/lib/api/openapi/components/document/index.d.ts +2 -0
  21. package/lib/api/openapi/components/document/index.js +6 -1
  22. package/lib/api/openapi/components/document/mCreateOrReplace.yaml +93 -0
  23. package/lib/api/openapi/components/document/update.yaml +1 -1
  24. package/lib/api/openapi/components/index.d.ts +1 -0
  25. package/lib/api/openapi/components/index.js +1 -0
  26. package/lib/api/openapi/components/security/index.d.ts +2 -0
  27. package/lib/api/openapi/components/security/index.js +10 -0
  28. package/lib/api/openapi/components/security/upsertUser.yaml +59 -0
  29. package/lib/api/openapi/openApiGenerator.js +1 -1
  30. package/lib/api/rateLimiter.js +1 -1
  31. package/lib/api/request/kuzzleRequest.d.ts +21 -0
  32. package/lib/api/request/kuzzleRequest.js +49 -3
  33. package/lib/api/request/requestContext.js +1 -1
  34. package/lib/api/request/requestInput.js +1 -1
  35. package/lib/api/request/requestResponse.js +1 -1
  36. package/lib/cluster/command.js +1 -1
  37. package/lib/cluster/idCardHandler.js +1 -1
  38. package/lib/cluster/index.js +1 -1
  39. package/lib/cluster/node.js +8 -8
  40. package/lib/cluster/publisher.js +1 -1
  41. package/lib/cluster/state.js +1 -1
  42. package/lib/cluster/subscriber.js +4 -1
  43. package/lib/config/documentEventAliases.js +1 -1
  44. package/lib/config/index.js +1 -1
  45. package/lib/core/auth/formatProcessing.js +1 -1
  46. package/lib/core/auth/passportResponse.js +1 -1
  47. package/lib/core/auth/passportWrapper.js +1 -1
  48. package/lib/core/auth/tokenManager.js +1 -1
  49. package/lib/core/backend/applicationManager.js +1 -1
  50. package/lib/core/backend/backend.js +1 -1
  51. package/lib/core/backend/backendCluster.js +1 -1
  52. package/lib/core/backend/backendConfig.js +1 -1
  53. package/lib/core/backend/backendController.js +1 -1
  54. package/lib/core/backend/backendErrors.js +1 -1
  55. package/lib/core/backend/backendHook.js +1 -1
  56. package/lib/core/backend/backendImport.js +1 -1
  57. package/lib/core/backend/backendOpenApi.js +1 -1
  58. package/lib/core/backend/backendPipe.js +1 -1
  59. package/lib/core/backend/backendPlugin.js +1 -1
  60. package/lib/core/backend/backendStorage.js +1 -1
  61. package/lib/core/backend/backendVault.js +1 -1
  62. package/lib/core/backend/internalLogger.js +1 -1
  63. package/lib/core/cache/cacheDbEnum.js +1 -1
  64. package/lib/core/cache/cacheEngine.js +1 -1
  65. package/lib/core/network/accessLogger.js +12 -7
  66. package/lib/core/network/clientConnection.js +1 -1
  67. package/lib/core/network/context.js +1 -1
  68. package/lib/core/network/entryPoint.js +6 -6
  69. package/lib/core/network/httpRouter/index.js +1 -1
  70. package/lib/core/network/httpRouter/routeHandler.js +1 -1
  71. package/lib/core/network/httpRouter/routePart.js +1 -1
  72. package/lib/core/network/protocolManifest.js +1 -1
  73. package/lib/core/network/protocols/httpMessage.js +1 -1
  74. package/lib/core/network/protocols/httpwsProtocol.js +5 -10
  75. package/lib/core/network/protocols/internalProtocol.js +1 -1
  76. package/lib/core/network/protocols/mqttProtocol.js +4 -3
  77. package/lib/core/network/protocols/protocol.js +1 -1
  78. package/lib/core/network/router.js +11 -2
  79. package/lib/core/plugin/plugin.js +1 -1
  80. package/lib/core/plugin/pluginContext.js +1 -1
  81. package/lib/core/plugin/pluginManifest.js +1 -1
  82. package/lib/core/plugin/pluginRepository.js +1 -1
  83. package/lib/core/plugin/pluginsManager.js +1 -1
  84. package/lib/core/plugin/privilegedContext.js +1 -1
  85. package/lib/core/realtime/actionEnum.js +1 -1
  86. package/lib/core/realtime/channel.js +1 -1
  87. package/lib/core/realtime/connectionRooms.js +1 -1
  88. package/lib/core/realtime/hotelClerk.js +66 -24
  89. package/lib/core/realtime/index.js +1 -1
  90. package/lib/core/realtime/notification/document.js +1 -1
  91. package/lib/core/realtime/notification/index.js +1 -1
  92. package/lib/core/realtime/notification/server.js +1 -1
  93. package/lib/core/realtime/notification/user.js +1 -1
  94. package/lib/core/realtime/notifier.js +1 -1
  95. package/lib/core/realtime/room.js +1 -1
  96. package/lib/core/realtime/subscription.js +1 -1
  97. package/lib/core/security/index.js +1 -1
  98. package/lib/core/security/profileRepository.js +1 -1
  99. package/lib/core/security/roleRepository.js +1 -1
  100. package/lib/core/security/securityLoader.js +1 -1
  101. package/lib/core/security/tokenRepository.js +1 -1
  102. package/lib/core/security/userRepository.js +1 -1
  103. package/lib/core/shared/KoncordeWrapper.js +1 -1
  104. package/lib/core/shared/abstractManifest.js +1 -1
  105. package/lib/core/shared/repository.js +1 -1
  106. package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
  107. package/lib/core/shared/sdk/embeddedSdk.js +4 -3
  108. package/lib/core/shared/sdk/funnelProtocol.d.ts +13 -0
  109. package/lib/core/shared/sdk/funnelProtocol.js +76 -81
  110. package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
  111. package/lib/core/shared/store.js +1 -1
  112. package/lib/core/statistics/index.js +1 -1
  113. package/lib/core/statistics/statistics.js +1 -1
  114. package/lib/core/storage/clientAdapter.js +1 -1
  115. package/lib/core/storage/indexCache.js +1 -1
  116. package/lib/core/storage/storageEngine.js +1 -1
  117. package/lib/core/storage/storeScopeEnum.js +1 -1
  118. package/lib/core/validation/baseType.js +1 -1
  119. package/lib/core/validation/index.js +1 -1
  120. package/lib/core/validation/types/anything.js +1 -1
  121. package/lib/core/validation/types/boolean.js +1 -1
  122. package/lib/core/validation/types/date.js +1 -1
  123. package/lib/core/validation/types/email.js +1 -1
  124. package/lib/core/validation/types/enum.js +1 -1
  125. package/lib/core/validation/types/geoPoint.js +1 -1
  126. package/lib/core/validation/types/geoShape.js +1 -1
  127. package/lib/core/validation/types/integer.js +1 -1
  128. package/lib/core/validation/types/ipAddress.js +1 -1
  129. package/lib/core/validation/types/numeric.js +1 -1
  130. package/lib/core/validation/types/object.js +1 -1
  131. package/lib/core/validation/types/string.js +1 -1
  132. package/lib/core/validation/types/url.js +1 -1
  133. package/lib/core/validation/validation.js +1 -1
  134. package/lib/kerror/codes/1-services.json +1 -1
  135. package/lib/kerror/codes/index.js +1 -1
  136. package/lib/kerror/errors/badRequestError.js +1 -1
  137. package/lib/kerror/errors/externalServiceError.js +1 -1
  138. package/lib/kerror/errors/forbiddenError.js +1 -1
  139. package/lib/kerror/errors/gatewayTimeoutError.js +1 -1
  140. package/lib/kerror/errors/index.js +1 -1
  141. package/lib/kerror/errors/internalError.js +1 -1
  142. package/lib/kerror/errors/kuzzleError.d.ts +1 -1
  143. package/lib/kerror/errors/kuzzleError.js +1 -1
  144. package/lib/kerror/errors/multipleErrorsError.js +1 -1
  145. package/lib/kerror/errors/notFoundError.js +1 -1
  146. package/lib/kerror/errors/partialError.js +1 -1
  147. package/lib/kerror/errors/pluginImplementationError.js +1 -1
  148. package/lib/kerror/errors/preconditionError.js +1 -1
  149. package/lib/kerror/errors/serviceUnavailableError.js +1 -1
  150. package/lib/kerror/errors/sizeLimitError.js +1 -1
  151. package/lib/kerror/errors/tooManyRequestsError.js +1 -1
  152. package/lib/kerror/errors/unauthorizedError.js +1 -1
  153. package/lib/kerror/index.js +2 -4
  154. package/lib/kuzzle/dumpGenerator.js +1 -1
  155. package/lib/kuzzle/event/kuzzleEventEmitter.js +39 -1
  156. package/lib/kuzzle/event/pipeRunner.js +1 -1
  157. package/lib/kuzzle/event/waterfall.js +1 -1
  158. package/lib/kuzzle/index.js +1 -1
  159. package/lib/kuzzle/internalIndexHandler.js +1 -1
  160. package/lib/kuzzle/kuzzle.js +1 -1
  161. package/lib/kuzzle/kuzzleStateEnum.js +1 -1
  162. package/lib/kuzzle/log.js +1 -1
  163. package/lib/kuzzle/vault.js +1 -1
  164. package/lib/model/security/profile.js +1 -1
  165. package/lib/model/security/rights.js +1 -1
  166. package/lib/model/security/role.js +1 -1
  167. package/lib/model/security/token.js +1 -1
  168. package/lib/model/security/user.js +6 -7
  169. package/lib/model/storage/apiKey.js +1 -1
  170. package/lib/model/storage/baseModel.js +1 -1
  171. package/lib/service/cache/redis.js +1 -1
  172. package/lib/service/service.js +1 -1
  173. package/lib/service/storage/elasticsearch.js +108 -39
  174. package/lib/service/storage/esWrapper.js +1 -1
  175. package/lib/service/storage/queryTranslator.js +1 -1
  176. package/lib/types/Controller.js +1 -1
  177. package/lib/types/ControllerDefinition.js +1 -1
  178. package/lib/types/Deprecation.js +1 -1
  179. package/lib/types/EventHandler.js +1 -1
  180. package/lib/types/KuzzleDocument.d.ts +3 -0
  181. package/lib/types/Plugin.js +1 -1
  182. package/lib/types/PluginManifest.js +1 -1
  183. package/lib/types/RequestPayload.js +1 -1
  184. package/lib/types/ResponsePayload.js +1 -1
  185. package/lib/types/StrategyDefinition.js +1 -1
  186. package/lib/types/Token.js +1 -1
  187. package/lib/types/User.js +1 -1
  188. package/lib/types/index.d.ts +0 -1
  189. package/lib/types/index.js +1 -2
  190. package/lib/util/array.js +1 -1
  191. package/lib/util/assertType.js +1 -1
  192. package/lib/util/asyncStore.js +1 -1
  193. package/lib/util/debug.js +1 -1
  194. package/lib/util/deprecate.js +1 -1
  195. package/lib/util/didYouMean.js +1 -1
  196. package/lib/util/dump-collection.d.ts +35 -0
  197. package/lib/util/dump-collection.js +11 -8
  198. package/lib/util/extractFields.js +1 -1
  199. package/lib/util/inflector.js +1 -1
  200. package/lib/util/koncordeCompat.js +1 -1
  201. package/lib/util/memoize.js +1 -1
  202. package/lib/util/mutex.js +1 -1
  203. package/lib/util/name-generator.js +1 -1
  204. package/lib/util/promback.js +1 -1
  205. package/lib/util/requestAssertions.js +1 -1
  206. package/lib/util/safeObject.js +1 -1
  207. package/lib/util/stackTrace.js +56 -17
  208. package/lib/util/wildcard.js +1 -1
  209. package/package-lock.json +102 -83
  210. package/package.json +18 -17
  211. package/lib/core/network/removeErrorStack.js +0 -56
@@ -4,7 +4,7 @@
4
4
  * Kuzzle, a backend software, self-hostable and ready to use
5
5
  * to power modern apps
6
6
  *
7
- * Copyright 2015-2020 Kuzzle
7
+ * Copyright 2015-2022 Kuzzle
8
8
  * mailto: support AT kuzzle.io
9
9
  * website: http://kuzzle.io
10
10
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -646,7 +646,12 @@ class AuthController extends NativeController {
646
646
 
647
647
  assertIsAuthenticated (request) {
648
648
  if (request.context.user._id === this.anonymousId) {
649
- throw kerror.get('security', 'rights', 'unauthorized');
649
+ throw kerror.get(
650
+ 'security',
651
+ 'rights',
652
+ 'unauthorized',
653
+ request.input.controller,
654
+ request.input.action);
650
655
  }
651
656
  }
652
657
  }
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -829,6 +829,7 @@ class DocumentController extends NativeController {
829
829
  * @returns {Promise.<Object>} { successes, errors }
830
830
  */
831
831
  async _mChanges (request, methodName, action) {
832
+ let source = true;
832
833
  const userId = request.getKuid();
833
834
  const strict = request.getBoolean('strict');
834
835
  const silent = request.getBoolean('silent');
@@ -842,6 +843,10 @@ class DocumentController extends NativeController {
842
843
 
843
844
  this.assertNotExceedMaxWrite(documents.length);
844
845
 
846
+ if (request.input.args.source !== undefined) {
847
+ source = request.input.args.source === 'false' ? false : request.getBoolean('source');
848
+ }
849
+
845
850
  if (documents.length === 0) {
846
851
  return {
847
852
  errors: [],
@@ -865,7 +870,7 @@ class DocumentController extends NativeController {
865
870
  index,
866
871
  collection,
867
872
  documents,
868
- { refresh, retryOnConflict, userId });
873
+ { refresh, retryOnConflict, source, userId });
869
874
 
870
875
  if (strict && response.errors.length) {
871
876
  throw kerror.get('api', 'process', 'incomplete_multiple_request', methodName, response.errors);
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -21,8 +21,6 @@
21
21
 
22
22
  'use strict';
23
23
 
24
- const Bluebird = require('bluebird');
25
-
26
24
  const { Request } = require('../request');
27
25
  const { NativeController } = require('./baseController');
28
26
 
@@ -119,7 +117,7 @@ class IndexController extends NativeController {
119
117
  );
120
118
  }
121
119
 
122
- await Bluebird.all(promises);
120
+ await Promise.all(promises);
123
121
  }
124
122
 
125
123
  return response;
@@ -148,12 +146,18 @@ class IndexController extends NativeController {
148
146
  }
149
147
 
150
148
  /**
151
- * Returns a list of indexes allowed to be deleted by the user
149
+ * Returns a list of indexes allowed to be deleted by the user.
150
+ *
151
+ * Returns entire list of public indexes when called from EmbeddedSDK
152
152
  *
153
153
  * @param {Request} request
154
- * @param {String[]} publicIndexes - Complete indexes list
154
+ * @param {String[]} publicIndexes - Public indexes list
155
155
  */
156
156
  _allowedIndexes (request, publicIndexes) {
157
+ if (request.getUser() === null) {
158
+ return publicIndexes;
159
+ }
160
+
157
161
  const allowedIndexes = [];
158
162
 
159
163
  const promises = publicIndexes
@@ -171,7 +175,7 @@ class IndexController extends NativeController {
171
175
  });
172
176
  });
173
177
 
174
- return Bluebird.all(promises)
178
+ return Promise.all(promises)
175
179
  .then(() => allowedIndexes);
176
180
  }
177
181
  }
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -31,7 +31,7 @@ const { NativeController } = require('./baseController');
31
31
  const formatProcessing = require('../../core/auth/formatProcessing');
32
32
  const ApiKey = require('../../model/storage/apiKey');
33
33
  const kerror = require('../../kerror');
34
- const { has, get } = require('../../util/safeObject');
34
+ const { has } = require('../../util/safeObject');
35
35
  const { generateRandomName } = require('../../util/name-generator');
36
36
 
37
37
  /**
@@ -92,6 +92,7 @@ class SecurityController extends NativeController {
92
92
  'updateRoleMapping',
93
93
  'updateUser',
94
94
  'updateUserMapping',
95
+ 'upsertUser',
95
96
  'validateCredentials'
96
97
  ]);
97
98
 
@@ -770,17 +771,9 @@ class SecurityController extends NativeController {
770
771
  */
771
772
  async createUser (request) {
772
773
  const content = request.getBodyObject('content');
773
- const profileIds = get(content, 'profileIds');
774
+ const profileIds = request.getBodyArray('content.profileIds');
774
775
  const humanReadableId = request.getString('kuid', 'human') !== 'uuid';
775
776
 
776
- if (profileIds === undefined) {
777
- throw kerror.get('api', 'assert', 'missing_argument', 'body.content.profileIds');
778
- }
779
-
780
- if (! Array.isArray(profileIds)) {
781
- throw kerror.get('api', 'assert', 'invalid_type', 'body.content.profileIds', 'array');
782
- }
783
-
784
777
  return this._persistUser(request, profileIds, content, { humanReadableId });
785
778
  }
786
779
 
@@ -819,20 +812,38 @@ class SecurityController extends NativeController {
819
812
  ? null
820
813
  : request.getBodyArray('profileIds');
821
814
 
822
- const updated = await this.ask(
823
- 'core:security:user:update',
824
- id,
825
- profileIds,
826
- content,
827
- {
828
- refresh: request.getRefresh('wait_for'),
829
- retryOnConflict: request.getInteger('retryOnConflict', 10),
830
- userId,
831
- });
815
+ return this._changeUser(request, id, content, userId, profileIds);
816
+ }
832
817
 
833
- global.kuzzle.log.info(`[SECURITY] User "${userId}" applied action "${request.input.action}" on user "${id}."`);
818
+ /**
819
+ * Applies a partial update to an existing user.
820
+ * If the user doesn't already exist, a new user is created.
821
+ *
822
+ * @param {Request} request
823
+ * @returns {Promise}
824
+ */
825
+ async upsertUser (request) {
826
+ const id = request.getId();
827
+ const content = request.getBodyObject('content');
828
+ const userId = request.getKuid();
829
+ const profileIds = request.getBodyArray('content.profileIds');
830
+ const defaultValues = request.getBodyObject('default', {});
834
831
 
835
- return formatProcessing.serializeUser(updated);
832
+ try {
833
+ return await this._changeUser(request, id, content, userId, profileIds);
834
+ }
835
+ catch (error) {
836
+ if (error.id && error.id === 'security.user.not_found') {
837
+ const creatingContent = {
838
+ ...defaultValues,
839
+ ...content, // Order important, content erase default duplicates
840
+ };
841
+
842
+ return this._persistUser(request, profileIds, creatingContent);
843
+ }
844
+
845
+ throw error;
846
+ }
836
847
  }
837
848
 
838
849
  /**
@@ -1226,6 +1237,27 @@ class SecurityController extends NativeController {
1226
1237
  return successes;
1227
1238
  }
1228
1239
 
1240
+ /**
1241
+ * @returns {Promise}
1242
+ * @private
1243
+ */
1244
+ async _changeUser (request, id, content, userId, profileIds) {
1245
+ const updated = await this.ask(
1246
+ 'core:security:user:update',
1247
+ id,
1248
+ profileIds,
1249
+ content,
1250
+ {
1251
+ refresh: request.getRefresh('wait_for'),
1252
+ retryOnConflict: request.getInteger('retryOnConflict', 10),
1253
+ userId,
1254
+ });
1255
+
1256
+ global.kuzzle.log.info(`[SECURITY] User "${userId}" applied action "${request.input.action}" on user "${id}."`);
1257
+
1258
+ return formatProcessing.serializeUser(updated);
1259
+ }
1260
+
1229
1261
  /**
1230
1262
  * @param {Request} request
1231
1263
  * @returns {Promise}
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
package/lib/api/funnel.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * Kuzzle, a backend software, self-hostable and ready to use
3
3
  * to power modern apps
4
4
  *
5
- * Copyright 2015-2020 Kuzzle
5
+ * Copyright 2015-2022 Kuzzle
6
6
  * mailto: support AT kuzzle.io
7
7
  * website: http://kuzzle.io
8
8
  *
@@ -35,8 +35,9 @@ const {
35
35
  OpenApiDocumentCreate,
36
36
  OpenApiDocumentCreateOrReplace,
37
37
  OpenApiDocumentValidate,
38
- } = require('./openapi/components/document');
39
-
38
+ OpenApiSecurityUpsertUser,
39
+ OpenApiDocumentmCreateOrReplace,
40
+ } = require('./openapi/components');
40
41
 
41
42
  const routes = [
42
43
  // GET (idempotent)
@@ -76,7 +77,7 @@ const routes = [
76
77
  { verb: 'get', path: '/:index/:collection/:_id', controller: 'document', action: 'get', openapi: OpenApiDocumentGet },
77
78
  { verb: 'get', path: '/:index/:collection/_mGet', controller: 'document', action: 'mGet' },
78
79
  { verb: 'get', path: '/:index/:collection/:_id/_exists', controller: 'document', action: 'exists', openapi: OpenApiDocumentExists },
79
- { verb: 'get', path: '/:index/:collection/_mExists', controller: 'document', action: 'mExists' },
80
+ { verb: 'post', path: '/:index/:collection/_mExists', controller: 'document', action: 'mExists' },
80
81
  { verb: 'get', path: '/_scroll/:scrollId', controller: 'document', action: 'scroll', openapi: OpenApiDocumentScroll },
81
82
 
82
83
  { verb: 'get', path: '/:index/_exists', controller: 'index', action: 'exists' },
@@ -234,6 +235,7 @@ const routes = [
234
235
  { verb: 'post', path: '/roles/_search', controller: 'security', action: 'searchRoles' },
235
236
  { verb: 'post', path: '/users/_search', controller: 'security', action: 'searchUsers' },
236
237
  { verb: 'post', path: '/credentials/:strategy/users/_search', controller: 'security', action: 'searchUsersByCredentials' },
238
+ { verb: 'post', path: '/users/:_id/_upsert', controller: 'security', action: 'upsertUser', openapi: OpenApiSecurityUpsertUser },
237
239
  { verb: 'post', path: '/credentials/:strategy/:_id/_validate', controller: 'security', action: 'validateCredentials' },
238
240
  { verb: 'post', path: '/_checkRights', controller: 'auth', action: 'checkRights' },
239
241
  { verb: 'post', path: '/_checkRights/:userId', controller: 'security', action: 'checkRights' },
@@ -355,7 +357,7 @@ const routes = [
355
357
  { verb: 'put', path: '/:index/:collection/_specifications', controller: 'collection', action: 'updateSpecifications' },
356
358
 
357
359
  { verb: 'put', path: '/:index/:collection/:_id', controller: 'document', action: 'createOrReplace', openapi: OpenApiDocumentCreateOrReplace },
358
- { verb: 'put', path: '/:index/:collection/_mCreateOrReplace', controller: 'document', action: 'mCreateOrReplace' },
360
+ { verb: 'put', path: '/:index/:collection/_mCreateOrReplace', controller: 'document', action: 'mCreateOrReplace', openapi: OpenApiDocumentmCreateOrReplace },
359
361
  { verb: 'put', path: '/:index/:collection/:_id/_replace', controller: 'document', action: 'replace', openapi: OpenApiDocumentReplace },
360
362
  { verb: 'put', path: '/:index/:collection/_mReplace', controller: 'document', action: 'mReplace' },
361
363
  { verb: 'put', path: '/:index/:collection/_mUpdate', controller: 'document', action: 'mUpdate', deprecated: { since: '2.11.0', message: 'Use "document:mUpdate" route with PATCH instead of PUT' } }, // @deprecated
@@ -3,7 +3,7 @@
3
3
  * Kuzzle, a backend software, self-hostable and ready to use
4
4
  * to power modern apps
5
5
  *
6
- * Copyright 2015-2020 Kuzzle
6
+ * Copyright 2015-2022 Kuzzle
7
7
  * mailto: support AT kuzzle.io
8
8
  * website: http://kuzzle.io
9
9
  *
@@ -79,6 +79,10 @@ class OpenApiManager {
79
79
  ...components_1.OpenApiDocumentCreateOrReplaceComponent,
80
80
  ...components_1.OpenApiDocumentCreateComponent,
81
81
  ...components_1.OpenApiDocumentValidateComponent,
82
+ },
83
+ security: {
84
+ ...components_1.OpenApiSecurityUpsertUserComponent,
85
+ ...components_1.OpenApiDocumentmCreateOrReplaceComponent,
82
86
  }
83
87
  }
84
88
  };
@@ -14,7 +14,7 @@ DocumentGet:
14
14
  type: string
15
15
  required: true
16
16
  - in: path
17
- name: documentId
17
+ name: _id
18
18
  schema:
19
19
  type: string
20
20
  required: true
@@ -20,3 +20,5 @@ export declare const OpenApiDocumentDeleteByQuery: any;
20
20
  export declare const OpenApiDocumentDeleteByQueryComponent: any;
21
21
  export declare const OpenApiDocumentValidate: any;
22
22
  export declare const OpenApiDocumentValidateComponent: any;
23
+ export declare const OpenApiDocumentmCreateOrReplace: any;
24
+ export declare const OpenApiDocumentmCreateOrReplaceComponent: any;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenApiDocumentValidateComponent = exports.OpenApiDocumentValidate = exports.OpenApiDocumentDeleteByQueryComponent = exports.OpenApiDocumentDeleteByQuery = exports.OpenApiDocumentDeleteComponent = exports.OpenApiDocumentDelete = exports.OpenApiDocumentScrollComponent = exports.OpenApiDocumentScroll = exports.OpenApiDocumentUpdateComponent = exports.OpenApiDocumentUpdate = exports.OpenApiDocumentExistsComponent = exports.OpenApiDocumentExists = exports.OpenApiDocumentReplaceComponent = exports.OpenApiDocumentReplace = exports.OpenApiDocumentGetComponent = exports.OpenApiDocumentGet = exports.OpenApiDocumentCreateOrReplaceComponent = exports.OpenApiDocumentCreateOrReplace = exports.OpenApiDocumentCreateComponent = exports.OpenApiDocumentCreate = exports.OpenApiDocumentCountComponent = exports.OpenApiDocumentCount = void 0;
3
+ exports.OpenApiDocumentmCreateOrReplaceComponent = exports.OpenApiDocumentmCreateOrReplace = exports.OpenApiDocumentValidateComponent = exports.OpenApiDocumentValidate = exports.OpenApiDocumentDeleteByQueryComponent = exports.OpenApiDocumentDeleteByQuery = exports.OpenApiDocumentDeleteComponent = exports.OpenApiDocumentDelete = exports.OpenApiDocumentScrollComponent = exports.OpenApiDocumentScroll = exports.OpenApiDocumentUpdateComponent = exports.OpenApiDocumentUpdate = exports.OpenApiDocumentExistsComponent = exports.OpenApiDocumentExists = exports.OpenApiDocumentReplaceComponent = exports.OpenApiDocumentReplace = exports.OpenApiDocumentGetComponent = exports.OpenApiDocumentGet = exports.OpenApiDocumentCreateOrReplaceComponent = exports.OpenApiDocumentCreateOrReplace = exports.OpenApiDocumentCreateComponent = exports.OpenApiDocumentCreate = exports.OpenApiDocumentCountComponent = exports.OpenApiDocumentCount = void 0;
4
4
  const readYamlFile_1 = require("../../../../util/readYamlFile");
5
5
  // reading the description of the Count action in the controller document.
6
6
  // The yaml objects are then stored in the variables below
@@ -57,4 +57,9 @@ exports.OpenApiDocumentDeleteByQueryComponent = deleteByQueryObject.components.s
57
57
  const validateObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/validate.yaml');
58
58
  exports.OpenApiDocumentValidate = validateObject.DocumentValidate;
59
59
  exports.OpenApiDocumentValidateComponent = validateObject.components.schemas;
60
+ // reading the description of the mCreateOrReplace action in the controller document.
61
+ // The yaml objects are then stored in the variables below
62
+ const mCreateOrReplaceObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/mCreateOrReplace.yaml');
63
+ exports.OpenApiDocumentmCreateOrReplace = mCreateOrReplaceObject.DocumentmCreateOrReplace;
64
+ exports.OpenApiDocumentmCreateOrReplaceComponent = mCreateOrReplaceObject.components.schemas;
60
65
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,93 @@
1
+ DocumentmCreateOrReplace:
2
+ summary: "Creates or replaces multiple documents."
3
+ tags:
4
+ - document
5
+ parameters:
6
+ - in: path
7
+ name: index
8
+ schema:
9
+ type: string
10
+ required: true
11
+ - in: path
12
+ name: collection
13
+ schema:
14
+ type: string
15
+ required: true
16
+ - in: path
17
+ name: refresh
18
+ schema:
19
+ type: string
20
+ required: false
21
+ - in: path
22
+ name: silent
23
+ schema:
24
+ type: boolean
25
+ required: false
26
+ - in: path
27
+ name: _source
28
+ description: "if set to true, the response will include the document's source (default value true)"
29
+ schema:
30
+ type: boolean
31
+ required: false
32
+ - name: body
33
+ in: "body"
34
+ description: "Creates or replaces multiple documents."
35
+ required: true
36
+ schema:
37
+ $ref: "#/components/document/DocumentmCreateOrReplaceRequest"
38
+ responses:
39
+ 200:
40
+ description: "Creates or replaces multiple documents."
41
+ schema:
42
+ $ref: "#/components/document/DocumentmCreateOrReplaceResponse"
43
+
44
+ components:
45
+ schemas:
46
+ DocumentmCreateOrReplaceRequest:
47
+ allOf:
48
+ - type: "object"
49
+ properties:
50
+ documents:
51
+ type: "array"
52
+ items:
53
+ type: "object"
54
+ properties:
55
+ _id:
56
+ type: "string"
57
+ body:
58
+ type: "object"
59
+ description: "document content"
60
+ DocumentmCreateOrReplaceResponse:
61
+ allOf:
62
+ - $ref: "#/components/ResponsePayload"
63
+ - type: "object"
64
+ properties:
65
+ result:
66
+ type: "object"
67
+ properties:
68
+ successes:
69
+ type: "array"
70
+ items:
71
+ type: "object"
72
+ properties:
73
+ _id:
74
+ type: "string"
75
+ _source:
76
+ type: "object"
77
+ description: "document content"
78
+ _version:
79
+ type: "integer"
80
+ created:
81
+ type: "boolean"
82
+ errors:
83
+ type: "array"
84
+ items:
85
+ type: "object"
86
+ properties:
87
+ document:
88
+ type: "object"
89
+ description: "document content"
90
+ status:
91
+ type: "integer"
92
+ reason:
93
+ type: "string"
@@ -75,4 +75,4 @@ components:
75
75
  type: "integer"
76
76
  _source:
77
77
  type: string
78
- description: "partial or entire document"
78
+ description: "partial or entire document"
@@ -1,2 +1,3 @@
1
1
  export * from './document';
2
+ export * from './security';
2
3
  export declare const OpenApiPayloadsDefinitions: any;
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.OpenApiPayloadsDefinitions = void 0;
18
18
  const readYamlFile_1 = require("../../../util/readYamlFile");
19
19
  __exportStar(require("./document"), exports);
20
+ __exportStar(require("./security"), exports);
20
21
  // Document definitions (reusable object for KuzzleRequest and KuzzleResponse)
21
22
  exports.OpenApiPayloadsDefinitions = (0, readYamlFile_1.readYamlFile)(__dirname + '/payloads.yaml').definitions;
22
23
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export declare const OpenApiSecurityUpsertUser: any;
2
+ export declare const OpenApiSecurityUpsertUserComponent: any;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenApiSecurityUpsertUserComponent = exports.OpenApiSecurityUpsertUser = void 0;
4
+ const readYamlFile_1 = require("../../../../util/readYamlFile");
5
+ // reading the description of the UpsertUser action in the controller security.
6
+ // The yaml objects are then stored in the variables below
7
+ const upsertUserObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/upsertUser.yaml');
8
+ exports.OpenApiSecurityUpsertUser = upsertUserObject.SecurityUpsertUser;
9
+ exports.OpenApiSecurityUpsertUserComponent = upsertUserObject.components.schemas;
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,59 @@
1
+ SecurityUpsertUser:
2
+ summary: "Update or create a user."
3
+ tags:
4
+ - user
5
+ parameters:
6
+ - in: path
7
+ name: _id
8
+ schema:
9
+ type: string
10
+ required: true
11
+ - in: path
12
+ name: refresh
13
+ schema:
14
+ type: string
15
+ description: " if set to wait_for, Kuzzle will not respond until the deletion has been indexed"
16
+ required: false
17
+ - in: path
18
+ name: retryOnConflict
19
+ schema:
20
+ type: integer
21
+ description: "conflicts may occur if the same user gets updated multiple times within a short timespan, in a database cluster. You can set the retryOnConflict optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error."
22
+ required: false
23
+ - name: content
24
+ in: "body"
25
+ description: "Updates a user content."
26
+ required: true
27
+ schema:
28
+ $ref: "#/components/security/SecurityUpsertUserRequest"
29
+ responses:
30
+ 200:
31
+ description: "Updates or creates a user."
32
+ schema:
33
+ $ref: "#/components/security/SecurityUpsertUserResponse"
34
+
35
+ components:
36
+ schemas:
37
+ SecurityUpsertUserRequest:
38
+ allOf:
39
+ - type: "object"
40
+ description: "user changes"
41
+ SecurityUpsertUserResponse:
42
+ allOf:
43
+ - $ref: "#/components/ResponsePayload"
44
+ - type: "object"
45
+ properties:
46
+ result:
47
+ type: "object"
48
+ properties:
49
+ _id:
50
+ type: "string"
51
+ description: "userId"
52
+ _version:
53
+ type: "integer"
54
+ _source:
55
+ type: "object"
56
+ description: " (optional) actualized user content. This property appears only if the \"source\" option is set to true"
57
+ created:
58
+ type: "boolean"
59
+