kuzzle 2.17.7 → 2.18.1

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 (212) 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 +9 -3
  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 +13 -4
  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 +80 -42
  14. package/lib/api/controllers/serverController.js +3 -2
  15. package/lib/api/documentExtractor.js +3 -2
  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 +46 -0
  32. package/lib/api/request/kuzzleRequest.js +147 -19
  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 +26 -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.d.ts +7 -1
  54. package/lib/core/backend/backendController.js +16 -4
  55. package/lib/core/backend/backendErrors.js +1 -1
  56. package/lib/core/backend/backendHook.js +1 -1
  57. package/lib/core/backend/backendImport.js +1 -1
  58. package/lib/core/backend/backendOpenApi.js +1 -1
  59. package/lib/core/backend/backendPipe.js +1 -1
  60. package/lib/core/backend/backendPlugin.js +1 -1
  61. package/lib/core/backend/backendStorage.js +1 -1
  62. package/lib/core/backend/backendVault.js +1 -1
  63. package/lib/core/backend/internalLogger.js +1 -1
  64. package/lib/core/cache/cacheDbEnum.js +1 -1
  65. package/lib/core/cache/cacheEngine.js +1 -1
  66. package/lib/core/network/accessLogger.js +1 -1
  67. package/lib/core/network/clientConnection.js +1 -1
  68. package/lib/core/network/context.js +1 -1
  69. package/lib/core/network/entryPoint.js +6 -6
  70. package/lib/core/network/httpRouter/index.js +1 -1
  71. package/lib/core/network/httpRouter/routeHandler.js +1 -1
  72. package/lib/core/network/httpRouter/routePart.js +1 -1
  73. package/lib/core/network/protocolManifest.js +1 -1
  74. package/lib/core/network/protocols/httpMessage.js +1 -1
  75. package/lib/core/network/protocols/httpwsProtocol.js +13 -16
  76. package/lib/core/network/protocols/internalProtocol.js +1 -1
  77. package/lib/core/network/protocols/mqttProtocol.js +4 -3
  78. package/lib/core/network/protocols/protocol.js +1 -1
  79. package/lib/core/network/router.js +11 -2
  80. package/lib/core/plugin/plugin.js +8 -1
  81. package/lib/core/plugin/pluginContext.js +1 -1
  82. package/lib/core/plugin/pluginManifest.js +1 -1
  83. package/lib/core/plugin/pluginRepository.js +1 -1
  84. package/lib/core/plugin/pluginsManager.js +1 -1
  85. package/lib/core/plugin/privilegedContext.js +1 -1
  86. package/lib/core/realtime/actionEnum.js +1 -1
  87. package/lib/core/realtime/channel.js +1 -1
  88. package/lib/core/realtime/connectionRooms.js +1 -1
  89. package/lib/core/realtime/hotelClerk.js +66 -24
  90. package/lib/core/realtime/index.js +1 -1
  91. package/lib/core/realtime/notification/document.js +1 -1
  92. package/lib/core/realtime/notification/index.js +1 -1
  93. package/lib/core/realtime/notification/server.js +1 -1
  94. package/lib/core/realtime/notification/user.js +1 -1
  95. package/lib/core/realtime/notifier.js +1 -1
  96. package/lib/core/realtime/room.js +1 -1
  97. package/lib/core/realtime/subscription.js +1 -1
  98. package/lib/core/security/index.js +1 -1
  99. package/lib/core/security/profileRepository.js +1 -1
  100. package/lib/core/security/roleRepository.js +1 -1
  101. package/lib/core/security/securityLoader.js +1 -1
  102. package/lib/core/security/tokenRepository.js +1 -1
  103. package/lib/core/security/userRepository.js +1 -1
  104. package/lib/core/shared/KoncordeWrapper.js +1 -1
  105. package/lib/core/shared/abstractManifest.js +1 -1
  106. package/lib/core/shared/repository.js +1 -1
  107. package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
  108. package/lib/core/shared/sdk/embeddedSdk.js +4 -3
  109. package/lib/core/shared/sdk/funnelProtocol.d.ts +13 -0
  110. package/lib/core/shared/sdk/funnelProtocol.js +76 -81
  111. package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
  112. package/lib/core/shared/store.js +1 -1
  113. package/lib/core/statistics/index.js +1 -1
  114. package/lib/core/statistics/statistics.js +1 -1
  115. package/lib/core/storage/clientAdapter.js +1 -1
  116. package/lib/core/storage/indexCache.js +1 -1
  117. package/lib/core/storage/storageEngine.js +1 -1
  118. package/lib/core/storage/storeScopeEnum.js +1 -1
  119. package/lib/core/validation/baseType.js +1 -1
  120. package/lib/core/validation/index.js +1 -1
  121. package/lib/core/validation/types/anything.js +1 -1
  122. package/lib/core/validation/types/boolean.js +1 -1
  123. package/lib/core/validation/types/date.js +1 -1
  124. package/lib/core/validation/types/email.js +1 -1
  125. package/lib/core/validation/types/enum.js +1 -1
  126. package/lib/core/validation/types/geoPoint.js +1 -1
  127. package/lib/core/validation/types/geoShape.js +1 -1
  128. package/lib/core/validation/types/integer.js +1 -1
  129. package/lib/core/validation/types/ipAddress.js +1 -1
  130. package/lib/core/validation/types/numeric.js +1 -1
  131. package/lib/core/validation/types/object.js +1 -1
  132. package/lib/core/validation/types/string.js +1 -1
  133. package/lib/core/validation/types/url.js +1 -1
  134. package/lib/core/validation/validation.js +1 -1
  135. package/lib/kerror/codes/1-services.json +1 -1
  136. package/lib/kerror/codes/index.js +1 -1
  137. package/lib/kerror/errors/badRequestError.js +1 -1
  138. package/lib/kerror/errors/externalServiceError.js +1 -1
  139. package/lib/kerror/errors/forbiddenError.js +1 -1
  140. package/lib/kerror/errors/gatewayTimeoutError.js +1 -1
  141. package/lib/kerror/errors/index.js +1 -1
  142. package/lib/kerror/errors/internalError.js +1 -1
  143. package/lib/kerror/errors/kuzzleError.d.ts +1 -1
  144. package/lib/kerror/errors/kuzzleError.js +1 -1
  145. package/lib/kerror/errors/multipleErrorsError.js +1 -1
  146. package/lib/kerror/errors/notFoundError.js +1 -1
  147. package/lib/kerror/errors/partialError.js +1 -1
  148. package/lib/kerror/errors/pluginImplementationError.js +1 -1
  149. package/lib/kerror/errors/preconditionError.js +1 -1
  150. package/lib/kerror/errors/serviceUnavailableError.js +1 -1
  151. package/lib/kerror/errors/sizeLimitError.js +1 -1
  152. package/lib/kerror/errors/tooManyRequestsError.js +1 -1
  153. package/lib/kerror/errors/unauthorizedError.js +1 -1
  154. package/lib/kerror/index.js +2 -4
  155. package/lib/kuzzle/dumpGenerator.js +1 -1
  156. package/lib/kuzzle/event/kuzzleEventEmitter.js +39 -1
  157. package/lib/kuzzle/event/pipeRunner.js +1 -1
  158. package/lib/kuzzle/event/waterfall.js +1 -1
  159. package/lib/kuzzle/index.js +1 -1
  160. package/lib/kuzzle/internalIndexHandler.js +1 -1
  161. package/lib/kuzzle/kuzzle.js +1 -1
  162. package/lib/kuzzle/kuzzleStateEnum.js +1 -1
  163. package/lib/kuzzle/log.js +1 -1
  164. package/lib/kuzzle/vault.js +1 -1
  165. package/lib/model/security/profile.js +1 -1
  166. package/lib/model/security/rights.js +1 -1
  167. package/lib/model/security/role.js +1 -1
  168. package/lib/model/security/token.js +1 -1
  169. package/lib/model/security/user.js +6 -7
  170. package/lib/model/storage/apiKey.js +1 -1
  171. package/lib/model/storage/baseModel.js +1 -1
  172. package/lib/service/cache/redis.js +1 -1
  173. package/lib/service/service.js +1 -1
  174. package/lib/service/storage/elasticsearch.js +108 -39
  175. package/lib/service/storage/esWrapper.js +1 -1
  176. package/lib/service/storage/queryTranslator.js +1 -1
  177. package/lib/types/Controller.js +1 -1
  178. package/lib/types/ControllerDefinition.js +1 -1
  179. package/lib/types/Deprecation.js +1 -1
  180. package/lib/types/EventHandler.js +1 -1
  181. package/lib/types/KuzzleDocument.d.ts +3 -0
  182. package/lib/types/Plugin.js +1 -1
  183. package/lib/types/PluginManifest.js +1 -1
  184. package/lib/types/RequestPayload.js +1 -1
  185. package/lib/types/ResponsePayload.js +1 -1
  186. package/lib/types/StrategyDefinition.js +1 -1
  187. package/lib/types/Token.js +1 -1
  188. package/lib/types/User.js +1 -1
  189. package/lib/types/index.d.ts +0 -1
  190. package/lib/types/index.js +1 -2
  191. package/lib/util/array.js +1 -1
  192. package/lib/util/assertType.js +1 -1
  193. package/lib/util/asyncStore.js +1 -1
  194. package/lib/util/debug.js +1 -1
  195. package/lib/util/deprecate.js +1 -1
  196. package/lib/util/didYouMean.js +1 -1
  197. package/lib/util/dump-collection.d.ts +35 -0
  198. package/lib/util/dump-collection.js +11 -8
  199. package/lib/util/extractFields.js +1 -1
  200. package/lib/util/inflector.js +1 -1
  201. package/lib/util/koncordeCompat.js +1 -1
  202. package/lib/util/memoize.js +1 -1
  203. package/lib/util/mutex.js +1 -1
  204. package/lib/util/name-generator.js +1 -1
  205. package/lib/util/promback.js +1 -1
  206. package/lib/util/requestAssertions.js +1 -1
  207. package/lib/util/safeObject.js +1 -1
  208. package/lib/util/stackTrace.js +56 -17
  209. package/lib/util/wildcard.js +1 -1
  210. package/package-lock.json +102 -83
  211. package/package.json +18 -17
  212. package/lib/core/network/removeErrorStack.js +0 -56
@@ -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
+
@@ -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
  *
@@ -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
  *
@@ -258,6 +258,9 @@ export declare class KuzzleRequest {
258
258
  /**
259
259
  * Gets a parameter from a request arguments and checks that it is an array
260
260
  *
261
+ * If the request argument is a JSON String instead of an array, it will be parsed
262
+ * and returned if it is a valid JSON array, otherwise it will @throws {api.assert.invalid_type}.
263
+ *
261
264
  * @param name parameter name
262
265
  * @param def default value to return if the parameter is not set
263
266
  *
@@ -266,9 +269,29 @@ export declare class KuzzleRequest {
266
269
  * @throws {api.assert.invalid_type} If the fetched parameter is not an array
267
270
  */
268
271
  getArray(name: string, def?: [] | undefined): any[];
272
+ /**
273
+ * @deprecated do not use, Use getArray instead
274
+ *
275
+ * Gets a parameter from a request arguments and checks that it is an array
276
+ *
277
+ * If the request argument is a String instead of an array, it will be JSON parsed
278
+ * and returned if it is a valid JSON array, otherwise it will return the string splitted on `,`.
279
+ *
280
+ *
281
+ * @param name parameter name
282
+ * @param def default value to return if the parameter is not set
283
+ *
284
+ * @throws {api.assert.missing_argument} If parameter not found and no default
285
+ * value provided
286
+ * @throws {api.assert.invalid_type} If the fetched parameter is not an array or a string
287
+ */
288
+ getArrayLegacy(name: string, def?: [] | undefined): any[];
269
289
  /**
270
290
  * Gets a parameter from a request arguments and checks that it is an object
271
291
  *
292
+ * If the request argument is a JSON String instead of an object, it will be parsed
293
+ * and returned if it is a valid JSON object, otherwise it will @throws {api.assert.invalid_type}.
294
+ *
272
295
  * @param name parameter name
273
296
  * @param def default value to return if the parameter is not set
274
297
  *
@@ -277,6 +300,27 @@ export declare class KuzzleRequest {
277
300
  * @throws {api.assert.invalid_type} If the fetched parameter is not an object
278
301
  */
279
302
  getObject(name: string, def?: JSONObject | undefined): JSONObject;
303
+ /**
304
+ * Gets a parameter from a request arguments and check with moment.js if the date is an ISO8601 format date
305
+ * or is valid regarding a given custom format (example : YYYY-MM-DD).
306
+ *
307
+ * @param name parameter name.
308
+ * @param format optional parameter to check if the date is valid regarding a format. If not set, the format checked
309
+ * is ISO8601.
310
+ * @throws {api.assert.missing_argument} If parameter not found and no default
311
+ * value provided
312
+ * @throws {api.assert.invalid_type} If parameter value is not a valid date.
313
+ */
314
+ getDate(name: string, format?: string): string;
315
+ /**
316
+ * Gets a parameter from a request arguments and returns it to timestamp format.
317
+ *
318
+ * @param name parameter name.
319
+ * @throws {api.assert.missing_argument} If parameter not found and no default
320
+ * value provided
321
+ * @throws {api.assert.invalid_type} If parameter value is not a valid date.
322
+ */
323
+ getTimestamp(name: string): number;
280
324
  /**
281
325
  * Returns the index specified in the request
282
326
  */
@@ -353,6 +397,7 @@ export declare class KuzzleRequest {
353
397
  * @param obj container object
354
398
  * @param name parameter name
355
399
  * @param errorName name to use in error messages
400
+ * @param querystring if true, the object is expected to be found in a querystring
356
401
  */
357
402
  private _getBoolean;
358
403
  /**
@@ -398,6 +443,7 @@ export declare class KuzzleRequest {
398
443
  * @param name parameter name
399
444
  * @param errorName name to use in error messages
400
445
  * @param def default value
446
+ * @param querystring if true, the object is expected to be found in a querystring
401
447
  */
402
448
  private _getObject;
403
449
  }
@@ -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
  *
@@ -42,8 +42,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
42
42
  __setModuleDefault(result, mod);
43
43
  return result;
44
44
  };
45
+ var __importDefault = (this && this.__importDefault) || function (mod) {
46
+ return (mod && mod.__esModule) ? mod : { "default": mod };
47
+ };
45
48
  Object.defineProperty(exports, "__esModule", { value: true });
46
49
  exports.Request = exports.KuzzleRequest = void 0;
50
+ const safeObject_1 = require("../../util/safeObject");
51
+ const lodash_1 = require("lodash");
52
+ const moment_1 = __importDefault(require("moment"));
47
53
  const uuid = __importStar(require("uuid"));
48
54
  const nanoid_1 = require("nanoid");
49
55
  const requestInput_1 = require("./requestInput");
@@ -53,8 +59,6 @@ const errors_1 = require("../../kerror/errors");
53
59
  const kerror = __importStar(require("../../kerror"));
54
60
  const types_1 = require("../../types");
55
61
  const assert = __importStar(require("../../util/assertType"));
56
- const safeObject_1 = require("../../util/safeObject");
57
- const lodash_1 = require("lodash");
58
62
  const assertionError = kerror.wrap('api', 'assert');
59
63
  // private properties
60
64
  // \u200b is a zero width space, used to masquerade console.log output
@@ -224,7 +228,9 @@ class KuzzleRequest {
224
228
  }
225
229
  this.status = options.status || 200;
226
230
  if (options.headers) {
227
- this.response.setHeaders(options.headers);
231
+ this.response.configure({
232
+ headers: options.headers
233
+ });
228
234
  }
229
235
  if (options.raw !== undefined) {
230
236
  this.response.raw = options.raw;
@@ -461,7 +467,7 @@ class KuzzleRequest {
461
467
  * @param name parameter name
462
468
  */
463
469
  getBoolean(name) {
464
- return this._getBoolean(this.input.args, name, name);
470
+ return this._getBoolean(this.input.args, name, name, true);
465
471
  }
466
472
  /**
467
473
  * Gets a parameter from a request arguments and checks that it is a number
@@ -505,6 +511,9 @@ class KuzzleRequest {
505
511
  /**
506
512
  * Gets a parameter from a request arguments and checks that it is an array
507
513
  *
514
+ * If the request argument is a JSON String instead of an array, it will be parsed
515
+ * and returned if it is a valid JSON array, otherwise it will @throws {api.assert.invalid_type}.
516
+ *
508
517
  * @param name parameter name
509
518
  * @param def default value to return if the parameter is not set
510
519
  *
@@ -513,11 +522,56 @@ class KuzzleRequest {
513
522
  * @throws {api.assert.invalid_type} If the fetched parameter is not an array
514
523
  */
515
524
  getArray(name, def = undefined) {
516
- return this._getArray(this.input.args, name, name, def);
525
+ return this._getArray(this.input.args, name, name, def, true);
526
+ }
527
+ /**
528
+ * @deprecated do not use, Use getArray instead
529
+ *
530
+ * Gets a parameter from a request arguments and checks that it is an array
531
+ *
532
+ * If the request argument is a String instead of an array, it will be JSON parsed
533
+ * and returned if it is a valid JSON array, otherwise it will return the string splitted on `,`.
534
+ *
535
+ *
536
+ * @param name parameter name
537
+ * @param def default value to return if the parameter is not set
538
+ *
539
+ * @throws {api.assert.missing_argument} If parameter not found and no default
540
+ * value provided
541
+ * @throws {api.assert.invalid_type} If the fetched parameter is not an array or a string
542
+ */
543
+ getArrayLegacy(name, def = undefined) {
544
+ const value = (0, lodash_1.get)(this.input.args, name, def);
545
+ if (value === undefined) {
546
+ throw assertionError.get('missing_argument', name);
547
+ }
548
+ if (Array.isArray(value)) {
549
+ return value;
550
+ }
551
+ if (typeof value !== 'string') {
552
+ throw assertionError.get('invalid_type', name, 'array');
553
+ }
554
+ // If we are using the HTTP protocol and we have a string instead of an Array
555
+ // we try to parse it as JSON
556
+ if (this.context.connection.protocol === 'http') {
557
+ try {
558
+ const parsedValue = JSON.parse(value);
559
+ if (Array.isArray(parsedValue)) {
560
+ return parsedValue;
561
+ }
562
+ }
563
+ catch (e) {
564
+ // Do nothing, let the code continue
565
+ }
566
+ }
567
+ return value.split(',');
517
568
  }
518
569
  /**
519
570
  * Gets a parameter from a request arguments and checks that it is an object
520
571
  *
572
+ * If the request argument is a JSON String instead of an object, it will be parsed
573
+ * and returned if it is a valid JSON object, otherwise it will @throws {api.assert.invalid_type}.
574
+ *
521
575
  * @param name parameter name
522
576
  * @param def default value to return if the parameter is not set
523
577
  *
@@ -526,7 +580,49 @@ class KuzzleRequest {
526
580
  * @throws {api.assert.invalid_type} If the fetched parameter is not an object
527
581
  */
528
582
  getObject(name, def = undefined) {
529
- return this._getObject(this.input.args, name, name, def);
583
+ return this._getObject(this.input.args, name, name, def, true);
584
+ }
585
+ /**
586
+ * Gets a parameter from a request arguments and check with moment.js if the date is an ISO8601 format date
587
+ * or is valid regarding a given custom format (example : YYYY-MM-DD).
588
+ *
589
+ * @param name parameter name.
590
+ * @param format optional parameter to check if the date is valid regarding a format. If not set, the format checked
591
+ * is ISO8601.
592
+ * @throws {api.assert.missing_argument} If parameter not found and no default
593
+ * value provided
594
+ * @throws {api.assert.invalid_type} If parameter value is not a valid date.
595
+ */
596
+ getDate(name, format) {
597
+ const args = this.input.args;
598
+ if (args[name] === undefined) {
599
+ throw assertionError.get('missing_argument', name);
600
+ }
601
+ if (format && !(0, moment_1.default)(args[name], format, true).isValid()) {
602
+ throw assertionError.get('invalid_type', name, 'date');
603
+ }
604
+ if (!(0, moment_1.default)(args[name], moment_1.default.ISO_8601).isValid()) {
605
+ throw assertionError.get('invalid_type', name, 'date');
606
+ }
607
+ return this.getString(name);
608
+ }
609
+ /**
610
+ * Gets a parameter from a request arguments and returns it to timestamp format.
611
+ *
612
+ * @param name parameter name.
613
+ * @throws {api.assert.missing_argument} If parameter not found and no default
614
+ * value provided
615
+ * @throws {api.assert.invalid_type} If parameter value is not a valid date.
616
+ */
617
+ getTimestamp(name) {
618
+ const args = this.input.args;
619
+ if (args[name] === undefined) {
620
+ throw assertionError.get('missing_argument', name);
621
+ }
622
+ if ((0, moment_1.default)(args[name], true).isValid() === false) {
623
+ throw assertionError.get('invalid_type', name, 'date');
624
+ }
625
+ return this.getInteger(name);
530
626
  }
531
627
  /**
532
628
  * Returns the index specified in the request
@@ -631,13 +727,7 @@ class KuzzleRequest {
631
727
  || this.context.connection.misc.verb !== 'GET') {
632
728
  return this.getBody({});
633
729
  }
634
- const searchBody = this.getString('searchBody', '{}');
635
- try {
636
- return JSON.parse(searchBody);
637
- }
638
- catch (err) {
639
- throw assertionError.get('invalid_argument', err.message);
640
- }
730
+ return this.getObject('searchBody', {});
641
731
  }
642
732
  /**
643
733
  * Returns the search params.
@@ -690,16 +780,17 @@ class KuzzleRequest {
690
780
  * @param obj container object
691
781
  * @param name parameter name
692
782
  * @param errorName name to use in error messages
783
+ * @param querystring if true, the object is expected to be found in a querystring
693
784
  */
694
- _getBoolean(obj, name, errorName) {
785
+ _getBoolean(obj, name, errorName, querystring = false) {
695
786
  let value = (0, lodash_1.get)(obj, name);
696
787
  // In HTTP, booleans are flags: if it's in the querystring, it's set,
697
788
  // whatever its value.
698
789
  // If a user needs to unset the option, they need to remove it from the
699
790
  // querystring.
700
- if (this.context.connection.protocol === 'http') {
791
+ if (this.context.connection.protocol === 'http' && querystring) {
701
792
  value = value !== undefined;
702
- obj[name] = value;
793
+ (0, lodash_1.set)(obj, name, value);
703
794
  }
704
795
  else if (value === undefined || value === null) {
705
796
  value = false;
@@ -776,12 +867,30 @@ class KuzzleRequest {
776
867
  * @param errorName name to use in error messages
777
868
  * @param def default value
778
869
  */
779
- _getArray(obj, name, errorName, def = undefined) {
870
+ _getArray(obj, name, errorName, def = undefined, querystring = false) {
780
871
  const value = (0, lodash_1.get)(obj, name, def);
781
872
  if (value === undefined) {
782
873
  throw assertionError.get('missing_argument', errorName);
783
874
  }
784
875
  if (!Array.isArray(value)) {
876
+ // If we are using the HTTP protocol and we have a string instead of an Array
877
+ // we try to parse it as JSON
878
+ if (this.context.connection.protocol === 'http'
879
+ && querystring
880
+ && typeof value === 'string') {
881
+ try {
882
+ const parsedValue = JSON.parse(value);
883
+ if (Array.isArray(parsedValue)) {
884
+ // Replace the value with the parsed value
885
+ // This way subsequent calls to this function will return the parsed value directly
886
+ (0, lodash_1.set)(obj, name, parsedValue);
887
+ return parsedValue;
888
+ }
889
+ }
890
+ catch (e) {
891
+ // Do nothing, let the error be thrown below
892
+ }
893
+ }
785
894
  throw assertionError.get('invalid_type', errorName, 'array');
786
895
  }
787
896
  return value;
@@ -793,13 +902,32 @@ class KuzzleRequest {
793
902
  * @param name parameter name
794
903
  * @param errorName name to use in error messages
795
904
  * @param def default value
905
+ * @param querystring if true, the object is expected to be found in a querystring
796
906
  */
797
- _getObject(obj, name, errorName, def = undefined) {
907
+ _getObject(obj, name, errorName, def = undefined, querystring = false) {
798
908
  const value = (0, lodash_1.get)(obj, name, def);
799
909
  if (value === undefined) {
800
910
  throw assertionError.get('missing_argument', errorName);
801
911
  }
802
912
  if (!(0, safeObject_1.isPlainObject)(value)) {
913
+ // If we are using the HTTP protocol and we have a string instead of an Array
914
+ // we try to parse it as JSON
915
+ if (this.context.connection.protocol === 'http'
916
+ && querystring
917
+ && typeof value === 'string') {
918
+ try {
919
+ const parsedValue = JSON.parse(value);
920
+ if ((0, safeObject_1.isPlainObject)(parsedValue)) {
921
+ // Replace the value with the parsed value
922
+ // This way subsequent calls to this function will return the parsed value directly
923
+ (0, lodash_1.set)(obj, name, parsedValue);
924
+ return parsedValue;
925
+ }
926
+ }
927
+ catch (e) {
928
+ // Do nothing, let the error be thrown below
929
+ }
930
+ }
803
931
  throw assertionError.get('invalid_type', errorName, 'object');
804
932
  }
805
933
  return value;
@@ -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
  *
@@ -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
  *
@@ -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
  *
@@ -49,6 +49,11 @@ const assert = __importStar(require("../../util/assertType"));
49
49
  // \u200b is a zero width space, used to masquerade console.log output
50
50
  const _request = 'request\u200b';
51
51
  const _headers = 'headers\u200b';
52
+ const _userHeaders = 'userHeaders\u200b'; // List of headers to be sent in the response
53
+ // List of headers that should not be present in the body of the response
54
+ const restrictedHeaders = [
55
+ 'set-cookie',
56
+ ];
52
57
  class Headers {
53
58
  constructor() {
54
59
  this.namesMap = new Map();
@@ -150,6 +155,7 @@ class RequestResponse {
150
155
  this.raw = false;
151
156
  this[_request] = request;
152
157
  this[_headers] = new Headers();
158
+ this[_userHeaders] = new Set();
153
159
  Object.seal(this);
154
160
  }
155
161
  /**
@@ -254,6 +260,9 @@ class RequestResponse {
254
260
  configure(options = {}) {
255
261
  if (options.headers) {
256
262
  this.setHeaders(options.headers);
263
+ for (const key of Object.keys(options.headers)) {
264
+ this[_userHeaders].add(key.toLowerCase());
265
+ }
257
266
  }
258
267
  if (options.status) {
259
268
  this.status = options.status;
@@ -316,6 +325,21 @@ class RequestResponse {
316
325
  status: this.status,
317
326
  };
318
327
  }
328
+ const filteredHeaders = {};
329
+ for (const name of this[_userHeaders]) {
330
+ filteredHeaders[name] = this.getHeader(name);
331
+ }
332
+ /**
333
+ * Remove headers that are not allowed to be sent to the client in the response's body
334
+ * For example "set-cookie" headers should only be visible by the browser,
335
+ * otherwise they may leak information about the server's cookies, since the browser will
336
+ * not be able to restrict them to the domain of the request.
337
+ */
338
+ for (const header of restrictedHeaders) {
339
+ if (filteredHeaders[header] !== undefined) {
340
+ filteredHeaders[header] = undefined;
341
+ }
342
+ }
319
343
  return {
320
344
  content: {
321
345
  action: this.action,
@@ -323,6 +347,7 @@ class RequestResponse {
323
347
  controller: this.controller,
324
348
  deprecations: this.deprecations,
325
349
  error: this.error,
350
+ headers: filteredHeaders,
326
351
  index: this.index,
327
352
  node: this.node,
328
353
  requestId: this.requestId,