@nestjs/platform-express 8.0.6 → 8.0.7

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.
package/Readme.md CHANGED
@@ -67,8 +67,11 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
67
67
 
68
68
  <table style="text-align:center;"><tr><td>
69
69
  <a href="https://careers.labster.com/departments/platform" target="_blank"><img src="https://nestjs.com/img/labster-logo.png" width="170" valign="middle" /></a></td><td>
70
- <a href="https://weld.so/" target="_blank"><img src="https://nestjs.com/img/weld-logo.svg" width="150" valign="middle" /></a></td><td>
71
- <a href="https://valor-software.com/" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/valor-software.png" width="170" valign="middle" /></a></td></tr></table>
70
+ <a href="https://weld.app/" target="_blank"><img src="https://nestjs.com/img/weld-logo.svg" width="150" valign="middle" /></a></td>
71
+ <td>
72
+ <a href="https://valor-software.com/" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/valor-software.png" width="170" valign="middle" /></a></td>
73
+ <td>
74
+ <a href="https://intrinsic.ventures/" target="_blank"><img src="https://nestjs.com/img/intrinisic-logo.png" width="210" valign="middle" /></a></td></</tr></table>
72
75
 
73
76
  #### Silver Sponsors
74
77
 
@@ -76,7 +79,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
76
79
  <a href="https://neoteric.eu/" target="_blank"><img src="https://nestjs.com/img/neoteric-cut.png" width="120" valign="middle" /></a> </td><td>
77
80
  <a href="http://gojob.com" target="_blank"><img src="http://nestjs.com/img/gojob-logo.png" valign="middle" width="100" /></a> </td><td>
78
81
  <a href="http://www.leogistics.com" target="_blank"><img src="https://nestjs.com/img/leogistics-logo.jpeg" width="150" valign="middle" /></td><td>
79
- <a href="http://www.meetdandy.com" target="_blank"><img src="https://nestjs.com/img/dandy-wide-logo.png" width="150" valign="middle" /></td><td>
82
+ <a href="http://www.meetdandy.com" target="_blank"><img src="https://nestjs.com/img/dandy-roles-logo.svg" width="150" valign="middle" /></td><td>
80
83
  <a href="https://www.castlecraft.in" target="_blank"><img src="https://nestjs.com/img/castlecraft-logo.png" width="150" valign="middle" /></td></tr></table>
81
84
 
82
85
  #### Sponsors
@@ -1,4 +1,5 @@
1
1
  import { RequestMethod } from '@nestjs/common';
2
+ import { VersioningOptions, VersionValue } from '@nestjs/common/interfaces';
2
3
  import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
3
4
  import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
4
5
  import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
@@ -31,5 +32,6 @@ export declare class ExpressAdapter extends AbstractHttpAdapter {
31
32
  registerParserMiddleware(): void;
32
33
  setLocal(key: string, value: any): this;
33
34
  getType(): string;
35
+ applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): <TRequest extends Record<string, any> = any, TResponse = any>(req: TRequest, res: TResponse, next: () => void) => any;
34
36
  private isMiddlewareApplied;
35
37
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExpressAdapter = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
+ const interfaces_1 = require("@nestjs/common/interfaces");
5
6
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
7
  const http_adapter_1 = require("@nestjs/core/adapters/http-adapter");
7
8
  const bodyParser = require("body-parser");
@@ -118,6 +119,61 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
118
119
  getType() {
119
120
  return 'express';
120
121
  }
122
+ applyVersionFilter(handler, version, versioningOptions) {
123
+ return (req, res, next) => {
124
+ var _a, _b, _c, _d;
125
+ if (version === interfaces_1.VERSION_NEUTRAL) {
126
+ return handler(req, res, next);
127
+ }
128
+ // URL Versioning is done via the path, so the filter continues forward
129
+ if (versioningOptions.type === common_1.VersioningType.URI) {
130
+ return handler(req, res, next);
131
+ }
132
+ // Media Type (Accept Header) Versioning Handler
133
+ if (versioningOptions.type === common_1.VersioningType.MEDIA_TYPE) {
134
+ const MEDIA_TYPE_HEADER = 'Accept';
135
+ const acceptHeaderValue = ((_a = req.headers) === null || _a === void 0 ? void 0 : _a[MEDIA_TYPE_HEADER]) ||
136
+ ((_b = req.headers) === null || _b === void 0 ? void 0 : _b[MEDIA_TYPE_HEADER.toLowerCase()]);
137
+ const acceptHeaderVersionParameter = acceptHeaderValue
138
+ ? acceptHeaderValue.split(';')[1]
139
+ : '';
140
+ if (acceptHeaderVersionParameter) {
141
+ const headerVersion = acceptHeaderVersionParameter.split(versioningOptions.key)[1];
142
+ if (Array.isArray(version)) {
143
+ if (version.includes(headerVersion)) {
144
+ return handler(req, res, next);
145
+ }
146
+ }
147
+ else if (shared_utils_1.isString(version)) {
148
+ if (version === headerVersion) {
149
+ return handler(req, res, next);
150
+ }
151
+ }
152
+ }
153
+ }
154
+ // Header Versioning Handler
155
+ else if (versioningOptions.type === common_1.VersioningType.HEADER) {
156
+ const customHeaderVersionParameter = ((_c = req.headers) === null || _c === void 0 ? void 0 : _c[versioningOptions.header]) ||
157
+ ((_d = req.headers) === null || _d === void 0 ? void 0 : _d[versioningOptions.header.toLowerCase()]);
158
+ if (customHeaderVersionParameter) {
159
+ if (Array.isArray(version)) {
160
+ if (version.includes(customHeaderVersionParameter)) {
161
+ return handler(req, res, next);
162
+ }
163
+ }
164
+ else if (shared_utils_1.isString(version)) {
165
+ if (version === customHeaderVersionParameter) {
166
+ return handler(req, res, next);
167
+ }
168
+ }
169
+ }
170
+ }
171
+ if (!next) {
172
+ throw new common_1.InternalServerErrorException('HTTP adapter does not support filtering on version');
173
+ }
174
+ return next();
175
+ };
176
+ }
121
177
  isMiddlewareApplied(name) {
122
178
  const app = this.getInstance();
123
179
  return (!!app._router &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-express",
3
- "version": "8.0.6",
3
+ "version": "8.0.7",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -20,12 +20,12 @@
20
20
  "body-parser": "1.19.0",
21
21
  "cors": "2.8.5",
22
22
  "express": "4.17.1",
23
- "multer": "1.4.2",
24
- "tslib": "2.3.0"
23
+ "multer": "1.4.3",
24
+ "tslib": "2.3.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@nestjs/common": "8.0.6",
28
- "@nestjs/core": "8.0.6"
27
+ "@nestjs/common": "8.0.7",
28
+ "@nestjs/core": "8.0.7"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@nestjs/common": "^8.0.0",