@nestjs/core 8.4.5 → 8.4.6

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.
@@ -47,7 +47,7 @@ export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any,
47
47
  abstract setErrorHandler(handler: Function, prefix?: string): any;
48
48
  abstract setNotFoundHandler(handler: Function, prefix?: string): any;
49
49
  abstract setHeader(response: any, name: string, value: string): any;
50
- abstract registerParserMiddleware(prefix?: string): any;
50
+ abstract registerParserMiddleware(prefix?: string, rawBody?: boolean): any;
51
51
  abstract enableCors(options: CorsOptions | CorsOptionsDelegate<TRequest>, prefix?: string): any;
52
52
  abstract createMiddlewareFactory(requestMethod: RequestMethod): ((path: string, callback: Function) => any) | Promise<(path: string, callback: Function) => any>;
53
53
  abstract getType(): string;
@@ -9,5 +9,5 @@ export declare class ContextIdFactory {
9
9
  * Generates a random identifier to track asynchronous execution context.
10
10
  * @param request request object
11
11
  */
12
- static getByRequest<T extends Record<any, any> = any>(request: T): ContextId;
12
+ static getByRequest<T extends Record<any, any> = any>(request: T, propsToInspect?: string[]): ContextId;
13
13
  }
@@ -25,17 +25,20 @@ class ContextIdFactory {
25
25
  * Generates a random identifier to track asynchronous execution context.
26
26
  * @param request request object
27
27
  */
28
- static getByRequest(request) {
28
+ static getByRequest(request, propsToInspect = ['raw']) {
29
+ var _a;
29
30
  if (!request) {
30
- return createContextId();
31
+ return ContextIdFactory.create();
31
32
  }
32
33
  if (request[request_constants_1.REQUEST_CONTEXT_ID]) {
33
34
  return request[request_constants_1.REQUEST_CONTEXT_ID];
34
35
  }
35
- if (request.raw && request.raw[request_constants_1.REQUEST_CONTEXT_ID]) {
36
- return request.raw[request_constants_1.REQUEST_CONTEXT_ID];
36
+ for (const key of propsToInspect) {
37
+ if ((_a = request[key]) === null || _a === void 0 ? void 0 : _a[request_constants_1.REQUEST_CONTEXT_ID]) {
38
+ return request[key][request_constants_1.REQUEST_CONTEXT_ID];
39
+ }
37
40
  }
38
- return createContextId();
41
+ return ContextIdFactory.create();
39
42
  }
40
43
  }
41
44
  exports.ContextIdFactory = ContextIdFactory;
@@ -32,7 +32,7 @@ export declare class NestApplicationContext implements INestApplicationContext {
32
32
  }): Promise<TResult>;
33
33
  registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
34
34
  /**
35
- * Initalizes the Nest application.
35
+ * Initializes the Nest application.
36
36
  * Calls the Nest lifecycle events.
37
37
  *
38
38
  * @returns {Promise<this>} The NestApplicationContext instance as Promise
@@ -63,7 +63,7 @@ class NestApplicationContext {
63
63
  this.container.registerRequestProvider(request, contextId);
64
64
  }
65
65
  /**
66
- * Initalizes the Nest application.
66
+ * Initializes the Nest application.
67
67
  * Calls the Nest lifecycle events.
68
68
  *
69
69
  * @returns {Promise<this>} The NestApplicationContext instance as Promise
@@ -101,7 +101,10 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
101
101
  return this;
102
102
  }
103
103
  registerParserMiddleware() {
104
- this.httpAdapter.registerParserMiddleware();
104
+ var _a;
105
+ const prefix = this.config.getGlobalPrefix();
106
+ const rawBody = !!((_a = this.appOptions) === null || _a === void 0 ? void 0 : _a.rawBody);
107
+ this.httpAdapter.registerParserMiddleware(prefix, rawBody);
105
108
  }
106
109
  async registerRouter() {
107
110
  await this.registerMiddleware(this.httpAdapter);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "8.4.5",
3
+ "version": "8.4.6",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "uuid": "8.3.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "8.4.5"
39
+ "@nestjs/common": "8.4.6"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@nestjs/common": "^8.0.0",
@@ -166,8 +166,7 @@ class RouterExplorer {
166
166
  return router.applyVersionFilter(handler, version, versioningOptions);
167
167
  }
168
168
  /**
169
- * This can be removed in the next major release.
170
- * Left for backward-compatibility.
169
+ * TODO(v9): This was left for backward-compatibility and can be removed.
171
170
  */
172
171
  return (req, res, next) => {
173
172
  var _a, _b, _c, _d;
@@ -209,8 +208,16 @@ class RouterExplorer {
209
208
  ((_b = req.headers) === null || _b === void 0 ? void 0 : _b[MEDIA_TYPE_HEADER.toLowerCase()]);
210
209
  const acceptHeaderVersionParameter = acceptHeaderValue
211
210
  ? acceptHeaderValue.split(';')[1]
212
- : '';
213
- if (acceptHeaderVersionParameter) {
211
+ : undefined;
212
+ // No version was supplied
213
+ if ((0, shared_utils_1.isUndefined)(acceptHeaderVersionParameter)) {
214
+ if (Array.isArray(version)) {
215
+ if (version.includes(version_options_interface_1.VERSION_NEUTRAL)) {
216
+ return handler(req, res, next);
217
+ }
218
+ }
219
+ }
220
+ else {
214
221
  const headerVersion = acceptHeaderVersionParameter.split(versioningOptions.key)[1];
215
222
  if (Array.isArray(version)) {
216
223
  if (version.includes(headerVersion)) {
@@ -228,7 +235,15 @@ class RouterExplorer {
228
235
  else if (versioningOptions.type === version_type_enum_1.VersioningType.HEADER) {
229
236
  const customHeaderVersionParameter = ((_c = req.headers) === null || _c === void 0 ? void 0 : _c[versioningOptions.header]) ||
230
237
  ((_d = req.headers) === null || _d === void 0 ? void 0 : _d[versioningOptions.header.toLowerCase()]);
231
- if (customHeaderVersionParameter) {
238
+ // No version was supplied
239
+ if ((0, shared_utils_1.isUndefined)(customHeaderVersionParameter)) {
240
+ if (Array.isArray(version)) {
241
+ if (version.includes(version_options_interface_1.VERSION_NEUTRAL)) {
242
+ return handler(req, res, next);
243
+ }
244
+ }
245
+ }
246
+ else {
232
247
  if (Array.isArray(version)) {
233
248
  if (version.includes(customHeaderVersionParameter)) {
234
249
  return handler(req, res, next);
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import { MessageEvent } from '@nestjs/common/interfaces';
3
5
  import { IncomingMessage, OutgoingHttpHeaders } from 'http';
4
6
  import { Transform } from 'stream';