@verdaccio/middleware 8.0.0-next-8.2 → 8.0.0-next-8.3
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 +10 -0
- package/build/middlewares/encode-pkg.js +11 -0
- package/build/middlewares/encode-pkg.js.map +1 -1
- package/package.json +9 -8
- package/src/middlewares/encode-pkg.ts +11 -0
- package/test/__snapshots__/template.test.ts.snap +6 -6
- package/test/allow.spec.ts +1 -0
- package/test/encode.spec.ts +83 -0
- package/test/final.spec.ts +1 -0
- package/test/json.spec.ts +1 -0
- package/test/log.spec.ts +1 -0
- package/test/loop.spec.ts +1 -0
- package/test/manifest.test.ts +2 -0
- package/test/media.spec.ts +1 -0
- package/test/params.spec.ts +1 -0
- package/test/render.spec.ts +1 -0
- package/test/security.spec.ts +1 -0
- package/test/template.test.ts +2 -0
- package/test/utils.spec.ts +2 -0
- package/test/validation.spec.ts +1 -0
- package/jest.config.js +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @verdaccio/middleware
|
|
2
2
|
|
|
3
|
+
## 8.0.0-next-8.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5bb81eb: fix(middleware): encoding of scope package name
|
|
8
|
+
- @verdaccio/core@8.0.0-next-8.3
|
|
9
|
+
- @verdaccio/config@8.0.0-next-8.3
|
|
10
|
+
- @verdaccio/url@13.0.0-next-8.3
|
|
11
|
+
- @verdaccio/utils@8.1.0-next-8.3
|
|
12
|
+
|
|
3
13
|
## 8.0.0-next-8.2
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -4,6 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.encodeScopePackage = encodeScopePackage;
|
|
7
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const debug = (0, _debug.default)('verdaccio:middleware:encode');
|
|
10
|
+
|
|
7
11
|
/**
|
|
8
12
|
* Encode / in a scoped package name to be matched as a single parameter in routes
|
|
9
13
|
* @param req
|
|
@@ -11,10 +15,17 @@ exports.encodeScopePackage = encodeScopePackage;
|
|
|
11
15
|
* @param next
|
|
12
16
|
*/
|
|
13
17
|
function encodeScopePackage(req, res, next) {
|
|
18
|
+
const original = req.url;
|
|
19
|
+
// If the @ sign is encoded, we need to decode it first
|
|
20
|
+
// e.g.: /%40org/pkg/1.2.3 -> /@org/pkg/1.2.3
|
|
21
|
+
if (req.url.indexOf('%40') !== -1) {
|
|
22
|
+
req.url = req.url.replace(/^\/%40/, '/@');
|
|
23
|
+
}
|
|
14
24
|
if (req.url.indexOf('@') !== -1) {
|
|
15
25
|
// e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3
|
|
16
26
|
req.url = req.url.replace(/^(\/@[^\/%]+)\/(?!$)/, '$1%2F');
|
|
17
27
|
}
|
|
28
|
+
debug('encodeScopePackage: %o -> %o', original, req.url);
|
|
18
29
|
next();
|
|
19
30
|
}
|
|
20
31
|
//# sourceMappingURL=encode-pkg.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-pkg.js","names":["encodeScopePackage","req","res","next","url","indexOf","replace"],"sources":["../../src/middlewares/encode-pkg.ts"],"sourcesContent":["import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\n/**\n * Encode / in a scoped package name to be matched as a single parameter in routes\n * @param req\n * @param res\n * @param next\n */\nexport function encodeScopePackage(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n if (req.url.indexOf('@') !== -1) {\n // e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3\n req.url = req.url.replace(/^(\\/@[^\\/%]+)\\/(?!$)/, '$1%2F');\n }\n next();\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"encode-pkg.js","names":["_debug","_interopRequireDefault","require","e","__esModule","default","debug","buildDebug","encodeScopePackage","req","res","next","original","url","indexOf","replace"],"sources":["../../src/middlewares/encode-pkg.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:encode');\n\n/**\n * Encode / in a scoped package name to be matched as a single parameter in routes\n * @param req\n * @param res\n * @param next\n */\nexport function encodeScopePackage(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n const original = req.url;\n // If the @ sign is encoded, we need to decode it first\n // e.g.: /%40org/pkg/1.2.3 -> /@org/pkg/1.2.3\n if (req.url.indexOf('%40') !== -1) {\n req.url = req.url.replace(/^\\/%40/, '/@');\n }\n if (req.url.indexOf('@') !== -1) {\n // e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3\n req.url = req.url.replace(/^(\\/@[^\\/%]+)\\/(?!$)/, '$1%2F');\n }\n debug('encodeScopePackage: %o -> %o', original, req.url);\n next();\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+B,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAI/B,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,6BAA6B,CAAC;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAChCC,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EAChB;EACN,MAAMC,QAAQ,GAAGH,GAAG,CAACI,GAAG;EACxB;EACA;EACA,IAAIJ,GAAG,CAACI,GAAG,CAACC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;IACjCL,GAAG,CAACI,GAAG,GAAGJ,GAAG,CAACI,GAAG,CAACE,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC;EAC3C;EACA,IAAIN,GAAG,CAACI,GAAG,CAACC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;IAC/B;IACAL,GAAG,CAACI,GAAG,GAAGJ,GAAG,CAACI,GAAG,CAACE,OAAO,CAAC,sBAAsB,EAAE,OAAO,CAAC;EAC5D;EACAT,KAAK,CAAC,8BAA8B,EAAEM,QAAQ,EAAEH,GAAG,CAACI,GAAG,CAAC;EACxDF,IAAI,CAAC,CAAC;AACR","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/middleware",
|
|
3
|
-
"version": "8.0.0-next-8.
|
|
3
|
+
"version": "8.0.0-next-8.3",
|
|
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.
|
|
33
|
-
"@verdaccio/core": "8.0.0-next-8.
|
|
34
|
-
"@verdaccio/url": "13.0.0-next-8.
|
|
35
|
-
"@verdaccio/utils": "
|
|
32
|
+
"@verdaccio/config": "8.0.0-next-8.3",
|
|
33
|
+
"@verdaccio/core": "8.0.0-next-8.3",
|
|
34
|
+
"@verdaccio/url": "13.0.0-next-8.3",
|
|
35
|
+
"@verdaccio/utils": "8.1.0-next-8.3",
|
|
36
36
|
"debug": "4.3.7",
|
|
37
37
|
"express": "4.21.0",
|
|
38
38
|
"express-rate-limit": "5.5.1",
|
|
@@ -45,9 +45,10 @@
|
|
|
45
45
|
"url": "https://opencollective.com/verdaccio"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@verdaccio/logger": "8.0.0-next-8.
|
|
48
|
+
"@verdaccio/logger": "8.0.0-next-8.3",
|
|
49
49
|
"body-parser": "1.20.3",
|
|
50
|
-
"supertest": "7.0.0"
|
|
50
|
+
"supertest": "7.0.0",
|
|
51
|
+
"jsdom": "25.0.1"
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
|
53
54
|
"clean": "rimraf ./build",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
|
|
56
57
|
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
|
57
58
|
"watch": "pnpm build:js -- --watch",
|
|
58
|
-
"test": "
|
|
59
|
+
"test": "vitest run",
|
|
59
60
|
"test:snap": "jest --updateSnapshot",
|
|
60
61
|
"build": "pnpm run build:js && pnpm run build:types"
|
|
61
62
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import buildDebug from 'debug';
|
|
2
|
+
|
|
1
3
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
|
|
2
4
|
|
|
5
|
+
const debug = buildDebug('verdaccio:middleware:encode');
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Encode / in a scoped package name to be matched as a single parameter in routes
|
|
5
9
|
* @param req
|
|
@@ -11,9 +15,16 @@ export function encodeScopePackage(
|
|
|
11
15
|
res: $ResponseExtend,
|
|
12
16
|
next: $NextFunctionVer
|
|
13
17
|
): void {
|
|
18
|
+
const original = req.url;
|
|
19
|
+
// If the @ sign is encoded, we need to decode it first
|
|
20
|
+
// e.g.: /%40org/pkg/1.2.3 -> /@org/pkg/1.2.3
|
|
21
|
+
if (req.url.indexOf('%40') !== -1) {
|
|
22
|
+
req.url = req.url.replace(/^\/%40/, '/@');
|
|
23
|
+
}
|
|
14
24
|
if (req.url.indexOf('@') !== -1) {
|
|
15
25
|
// e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3
|
|
16
26
|
req.url = req.url.replace(/^(\/@[^\/%]+)\/(?!$)/, '$1%2F');
|
|
17
27
|
}
|
|
28
|
+
debug('encodeScopePackage: %o -> %o', original, req.url);
|
|
18
29
|
next();
|
|
19
30
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`template custom body after 1`] = `
|
|
3
|
+
exports[`template > custom body after 1`] = `
|
|
4
4
|
"
|
|
5
5
|
<!DOCTYPE html>
|
|
6
6
|
<html lang="en-us">
|
|
@@ -26,7 +26,7 @@ exports[`template custom body after 1`] = `
|
|
|
26
26
|
"
|
|
27
27
|
`;
|
|
28
28
|
|
|
29
|
-
exports[`template custom body before 1`] = `
|
|
29
|
+
exports[`template > custom body before 1`] = `
|
|
30
30
|
"
|
|
31
31
|
<!DOCTYPE html>
|
|
32
32
|
<html lang="en-us">
|
|
@@ -52,7 +52,7 @@ exports[`template custom body before 1`] = `
|
|
|
52
52
|
"
|
|
53
53
|
`;
|
|
54
54
|
|
|
55
|
-
exports[`template custom render 1`] = `
|
|
55
|
+
exports[`template > custom render 1`] = `
|
|
56
56
|
"
|
|
57
57
|
<!DOCTYPE html>
|
|
58
58
|
<html lang="en-us">
|
|
@@ -78,7 +78,7 @@ exports[`template custom render 1`] = `
|
|
|
78
78
|
"
|
|
79
79
|
`;
|
|
80
80
|
|
|
81
|
-
exports[`template custom title 1`] = `
|
|
81
|
+
exports[`template > custom title 1`] = `
|
|
82
82
|
"
|
|
83
83
|
<!DOCTYPE html>
|
|
84
84
|
<html lang="en-us">
|
|
@@ -104,7 +104,7 @@ exports[`template custom title 1`] = `
|
|
|
104
104
|
"
|
|
105
105
|
`;
|
|
106
106
|
|
|
107
|
-
exports[`template meta scripts 1`] = `
|
|
107
|
+
exports[`template > meta scripts 1`] = `
|
|
108
108
|
"
|
|
109
109
|
<!DOCTYPE html>
|
|
110
110
|
<html lang="en-us">
|
package/test/allow.spec.ts
CHANGED
package/test/encode.spec.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
|
+
import { expect, test } from 'vitest';
|
|
2
3
|
|
|
3
4
|
import { HTTP_STATUS } from '@verdaccio/core';
|
|
4
5
|
|
|
@@ -19,3 +20,85 @@ test('encode is json', async () => {
|
|
|
19
20
|
expect(res.body).toEqual({ id: '@scope/foo' });
|
|
20
21
|
expect(res.status).toEqual(HTTP_STATUS.OK);
|
|
21
22
|
});
|
|
23
|
+
|
|
24
|
+
test('packages with version/scope', async () => {
|
|
25
|
+
const app = getApp([]);
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
app.use(encodeScopePackage);
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
app.get('/:package/:version?', (req, res) => {
|
|
30
|
+
const { package: pkg, version } = req.params;
|
|
31
|
+
res.status(HTTP_STATUS.OK).json({ package: pkg, version });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const res = await request(app).get('/foo');
|
|
35
|
+
expect(res.body).toEqual({ package: 'foo' });
|
|
36
|
+
expect(res.status).toEqual(HTTP_STATUS.OK);
|
|
37
|
+
|
|
38
|
+
const res2 = await request(app).get('/foo/1.0.0');
|
|
39
|
+
expect(res2.body).toEqual({ package: 'foo', version: '1.0.0' });
|
|
40
|
+
expect(res2.status).toEqual(HTTP_STATUS.OK);
|
|
41
|
+
|
|
42
|
+
const res3 = await request(app).get('/@scope/foo');
|
|
43
|
+
expect(res3.body).toEqual({ package: '@scope/foo' });
|
|
44
|
+
expect(res3.status).toEqual(HTTP_STATUS.OK);
|
|
45
|
+
|
|
46
|
+
const res4 = await request(app).get('/@scope/foo/1.0.0');
|
|
47
|
+
expect(res4.body).toEqual({ package: '@scope/foo', version: '1.0.0' });
|
|
48
|
+
expect(res4.status).toEqual(HTTP_STATUS.OK);
|
|
49
|
+
|
|
50
|
+
const res5 = await request(app).get('/@scope%2ffoo');
|
|
51
|
+
expect(res5.body).toEqual({ package: '@scope/foo' });
|
|
52
|
+
expect(res5.status).toEqual(HTTP_STATUS.OK);
|
|
53
|
+
|
|
54
|
+
const res6 = await request(app).get('/@scope%2ffoo/1.0.0');
|
|
55
|
+
expect(res6.body).toEqual({ package: '@scope/foo', version: '1.0.0' });
|
|
56
|
+
expect(res6.status).toEqual(HTTP_STATUS.OK);
|
|
57
|
+
|
|
58
|
+
const res7 = await request(app).get('/%40scope%2ffoo');
|
|
59
|
+
expect(res7.body).toEqual({ package: '@scope/foo' });
|
|
60
|
+
expect(res7.status).toEqual(HTTP_STATUS.OK);
|
|
61
|
+
|
|
62
|
+
const res8 = await request(app).get('/%40scope%2ffoo/1.0.0');
|
|
63
|
+
expect(res8.body).toEqual({ package: '@scope/foo', version: '1.0.0' });
|
|
64
|
+
expect(res8.status).toEqual(HTTP_STATUS.OK);
|
|
65
|
+
|
|
66
|
+
const res9 = await request(app).get('/%40scope/foo');
|
|
67
|
+
expect(res9.body).toEqual({ package: '@scope/foo' });
|
|
68
|
+
expect(res9.status).toEqual(HTTP_STATUS.OK);
|
|
69
|
+
|
|
70
|
+
const res10 = await request(app).get('/%40scope/foo/1.0.0');
|
|
71
|
+
expect(res10.body).toEqual({ package: '@scope/foo', version: '1.0.0' });
|
|
72
|
+
expect(res10.status).toEqual(HTTP_STATUS.OK);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('tarballs with and without scope', async () => {
|
|
76
|
+
const app = getApp([]);
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
app.use(encodeScopePackage);
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
app.get('/:package/-/:filename', (req, res) => {
|
|
81
|
+
const { package: pkg, filename } = req.params;
|
|
82
|
+
res.status(HTTP_STATUS.OK).json({ package: pkg, filename });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const res = await request(app).get('/foo/-/foo-1.2.3.tgz');
|
|
86
|
+
expect(res.body).toEqual({ package: 'foo', filename: 'foo-1.2.3.tgz' });
|
|
87
|
+
expect(res.status).toEqual(HTTP_STATUS.OK);
|
|
88
|
+
|
|
89
|
+
const res2 = await request(app).get('/@scope/foo/-/foo-1.2.3.tgz');
|
|
90
|
+
expect(res2.body).toEqual({ package: '@scope/foo', filename: 'foo-1.2.3.tgz' });
|
|
91
|
+
expect(res2.status).toEqual(HTTP_STATUS.OK);
|
|
92
|
+
|
|
93
|
+
const res3 = await request(app).get('/@scope%2ffoo/-/foo-1.2.3.tgz');
|
|
94
|
+
expect(res3.body).toEqual({ package: '@scope/foo', filename: 'foo-1.2.3.tgz' });
|
|
95
|
+
expect(res3.status).toEqual(HTTP_STATUS.OK);
|
|
96
|
+
|
|
97
|
+
const res4 = await request(app).get('/%40scope%2ffoo/-/foo-1.2.3.tgz');
|
|
98
|
+
expect(res4.body).toEqual({ package: '@scope/foo', filename: 'foo-1.2.3.tgz' });
|
|
99
|
+
expect(res4.status).toEqual(HTTP_STATUS.OK);
|
|
100
|
+
|
|
101
|
+
const res5 = await request(app).get('/%40scope/foo/-/foo-1.2.3.tgz');
|
|
102
|
+
expect(res5.body).toEqual({ package: '@scope/foo', filename: 'foo-1.2.3.tgz' });
|
|
103
|
+
expect(res5.status).toEqual(HTTP_STATUS.OK);
|
|
104
|
+
});
|
package/test/final.spec.ts
CHANGED
package/test/json.spec.ts
CHANGED
package/test/log.spec.ts
CHANGED
package/test/loop.spec.ts
CHANGED
package/test/manifest.test.ts
CHANGED
package/test/media.spec.ts
CHANGED
package/test/params.spec.ts
CHANGED
package/test/render.spec.ts
CHANGED
|
@@ -2,6 +2,7 @@ import express from 'express';
|
|
|
2
2
|
import { JSDOM } from 'jsdom';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import supertest from 'supertest';
|
|
5
|
+
import { describe, expect, test } from 'vitest';
|
|
5
6
|
|
|
6
7
|
import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
|
|
7
8
|
import { setup } from '@verdaccio/logger';
|
package/test/security.spec.ts
CHANGED
package/test/template.test.ts
CHANGED
package/test/utils.spec.ts
CHANGED
package/test/validation.spec.ts
CHANGED