@verdaccio/middleware 8.0.0-next-8.4 → 8.0.0-next-8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @verdaccio/middleware
2
2
 
3
+ ## 8.0.0-next-8.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 8995041: fix(middleware): allow content-type with charset
8
+ - @verdaccio/core@8.0.0-next-8.6
9
+ - @verdaccio/config@8.0.0-next-8.6
10
+ - @verdaccio/url@13.0.0-next-8.6
11
+ - @verdaccio/utils@8.1.0-next-8.6
12
+
13
+ ## 8.0.0-next-8.5
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [ba71932]
18
+ - Updated dependencies [64a7fc0]
19
+ - Updated dependencies [4adaa83]
20
+ - Updated dependencies [5cbee6f]
21
+ - Updated dependencies [a049bba]
22
+ - @verdaccio/config@8.0.0-next-8.5
23
+ - @verdaccio/core@8.0.0-next-8.5
24
+ - @verdaccio/url@13.0.0-next-8.5
25
+ - @verdaccio/utils@8.1.0-next-8.5
26
+
3
27
  ## 8.0.0-next-8.4
4
28
 
5
29
  ### Patch Changes
@@ -7,7 +7,12 @@ exports.media = media;
7
7
  var _core = require("@verdaccio/core");
8
8
  function media(expect) {
9
9
  return function (req, res, next) {
10
- if (req.headers[_core.HEADER_TYPE.CONTENT_TYPE] !== expect) {
10
+ const header = req.headers[_core.HEADER_TYPE.CONTENT_TYPE];
11
+ if (!header) {
12
+ next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNSUPPORTED_MEDIA, 'content-type is missing, expect: ' + expect));
13
+ return;
14
+ }
15
+ if (typeof header !== 'string' || header.split(';')[0].trim() !== expect) {
11
16
  next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNSUPPORTED_MEDIA, 'wrong content-type, expect: ' + expect + ', got: ' + req.get[_core.HEADER_TYPE.CONTENT_TYPE]));
12
17
  } else {
13
18
  next();
@@ -1 +1 @@
1
- {"version":3,"file":"media.js","names":["_core","require","media","expect","req","res","next","headers","HEADER_TYPE","CONTENT_TYPE","errorUtils","getCode","HTTP_STATUS","UNSUPPORTED_MEDIA","get"],"sources":["../../src/middlewares/media.ts"],"sourcesContent":["import { HEADER_TYPE, HTTP_STATUS, errorUtils } from '@verdaccio/core';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function media(expect: string | null): any {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n if (req.headers[HEADER_TYPE.CONTENT_TYPE] !== expect) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'wrong content-type, expect: ' + expect + ', got: ' + req.get[HEADER_TYPE.CONTENT_TYPE]\n )\n );\n } else {\n next();\n }\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAIO,SAASC,KAAKA,CAACC,MAAqB,EAAO;EAChD,OAAO,UAAUC,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IACxF,IAAIF,GAAG,CAACG,OAAO,CAACC,iBAAW,CAACC,YAAY,CAAC,KAAKN,MAAM,EAAE;MACpDG,IAAI,CACFI,gBAAU,CAACC,OAAO,CAChBC,iBAAW,CAACC,iBAAiB,EAC7B,8BAA8B,GAAGV,MAAM,GAAG,SAAS,GAAGC,GAAG,CAACU,GAAG,CAACN,iBAAW,CAACC,YAAY,CACxF,CACF,CAAC;IACH,CAAC,MAAM;MACLH,IAAI,CAAC,CAAC;IACR;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"media.js","names":["_core","require","media","expect","req","res","next","header","headers","HEADER_TYPE","CONTENT_TYPE","errorUtils","getCode","HTTP_STATUS","UNSUPPORTED_MEDIA","split","trim","get"],"sources":["../../src/middlewares/media.ts"],"sourcesContent":["import { HEADER_TYPE, HTTP_STATUS, errorUtils } from '@verdaccio/core';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function media(expect: string | null): any {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n const header = req.headers[HEADER_TYPE.CONTENT_TYPE];\n if (!header) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'content-type is missing, expect: ' + expect\n )\n );\n return;\n }\n\n if (typeof header !== 'string' || header.split(';')[0].trim() !== expect) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'wrong content-type, expect: ' + expect + ', got: ' + req.get[HEADER_TYPE.CONTENT_TYPE]\n )\n );\n } else {\n next();\n }\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAIO,SAASC,KAAKA,CAACC,MAAqB,EAAO;EAChD,OAAO,UAAUC,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IACxF,MAAMC,MAAM,GAAGH,GAAG,CAACI,OAAO,CAACC,iBAAW,CAACC,YAAY,CAAC;IACpD,IAAI,CAACH,MAAM,EAAE;MACXD,IAAI,CACFK,gBAAU,CAACC,OAAO,CAChBC,iBAAW,CAACC,iBAAiB,EAC7B,mCAAmC,GAAGX,MACxC,CACF,CAAC;MACD;IACF;IAEA,IAAI,OAAOI,MAAM,KAAK,QAAQ,IAAIA,MAAM,CAACQ,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,KAAKb,MAAM,EAAE;MACxEG,IAAI,CACFK,gBAAU,CAACC,OAAO,CAChBC,iBAAW,CAACC,iBAAiB,EAC7B,8BAA8B,GAAGX,MAAM,GAAG,SAAS,GAAGC,GAAG,CAACa,GAAG,CAACR,iBAAW,CAACC,YAAY,CACxF,CACF,CAAC;IACH,CAAC,MAAM;MACLJ,IAAI,CAAC,CAAC;IACR;EACF,CAAC;AACH","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/middleware",
3
- "version": "8.0.0-next-8.4",
3
+ "version": "8.0.0-next-8.6",
4
4
  "description": "express middleware utils",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -29,10 +29,10 @@
29
29
  "node": ">=18"
30
30
  },
31
31
  "dependencies": {
32
- "@verdaccio/config": "8.0.0-next-8.4",
33
- "@verdaccio/core": "8.0.0-next-8.4",
34
- "@verdaccio/url": "13.0.0-next-8.4",
35
- "@verdaccio/utils": "8.1.0-next-8.4",
32
+ "@verdaccio/config": "8.0.0-next-8.6",
33
+ "@verdaccio/core": "8.0.0-next-8.6",
34
+ "@verdaccio/url": "13.0.0-next-8.6",
35
+ "@verdaccio/utils": "8.1.0-next-8.6",
36
36
  "debug": "4.3.7",
37
37
  "express": "4.21.1",
38
38
  "express-rate-limit": "5.5.1",
@@ -45,7 +45,7 @@
45
45
  "url": "https://opencollective.com/verdaccio"
46
46
  },
47
47
  "devDependencies": {
48
- "@verdaccio/logger": "8.0.0-next-8.4",
48
+ "@verdaccio/logger": "8.0.0-next-8.6",
49
49
  "body-parser": "1.20.3",
50
50
  "supertest": "7.0.0",
51
51
  "jsdom": "25.0.1"
@@ -4,7 +4,18 @@ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
4
4
 
5
5
  export function media(expect: string | null): any {
6
6
  return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
7
- if (req.headers[HEADER_TYPE.CONTENT_TYPE] !== expect) {
7
+ const header = req.headers[HEADER_TYPE.CONTENT_TYPE];
8
+ if (!header) {
9
+ next(
10
+ errorUtils.getCode(
11
+ HTTP_STATUS.UNSUPPORTED_MEDIA,
12
+ 'content-type is missing, expect: ' + expect
13
+ )
14
+ );
15
+ return;
16
+ }
17
+
18
+ if (typeof header !== 'string' || header.split(';')[0].trim() !== expect) {
8
19
  next(
9
20
  errorUtils.getCode(
10
21
  HTTP_STATUS.UNSUPPORTED_MEDIA,
@@ -20,6 +20,19 @@ test('media is json', async () => {
20
20
  .expect(200);
21
21
  });
22
22
 
23
+ test('media is json with charset', async () => {
24
+ const app = getApp([]);
25
+ app.get('/json', media(mime.getType('json')), (req, res) => {
26
+ res.status(200).json();
27
+ });
28
+
29
+ return request(app)
30
+ .get('/json')
31
+ .set(HEADERS.CONTENT_TYPE, 'application/json; charset=utf-8')
32
+ .expect('Content-Type', /json/)
33
+ .expect(200);
34
+ });
35
+
23
36
  test('media is not json', async () => {
24
37
  const app = getApp([]);
25
38
  app.get('/json', media(mime.getType('json')), (req, res) => {
@@ -32,3 +45,12 @@ test('media is not json', async () => {
32
45
  .expect('Content-Type', /html/)
33
46
  .expect(HTTP_STATUS.UNSUPPORTED_MEDIA);
34
47
  });
48
+
49
+ test('missing content-type', async () => {
50
+ const app = getApp([]);
51
+ app.get('/json', media(mime.getType('json')), (req, res) => {
52
+ res.status(HTTP_STATUS.OK).json({});
53
+ });
54
+
55
+ return request(app).get('/json').expect(HTTP_STATUS.UNSUPPORTED_MEDIA);
56
+ });