@verdaccio/middleware 6.0.0-6-next.36 → 6.0.0-6-next.38
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 +16 -0
- package/build/middlewares/allow.d.ts +4 -1
- package/build/middlewares/allow.js +15 -3
- package/build/middlewares/allow.js.map +1 -1
- package/jest.config.js +2 -2
- package/package.json +5 -5
- package/src/middlewares/allow.ts +15 -3
- package/test/allow.spec.ts +36 -21
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @verdaccio/middleware
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.38
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 65f88b82: bump logger packages
|
|
8
|
+
- @verdaccio/core@6.0.0-6-next.59
|
|
9
|
+
- @verdaccio/utils@6.0.0-6-next.27
|
|
10
|
+
|
|
11
|
+
## 6.0.0-6-next.37
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- fa274ee4: chore: bumb up package
|
|
16
|
+
- @verdaccio/core@6.0.0-6-next.58
|
|
17
|
+
- @verdaccio/utils@6.0.0-6-next.26
|
|
18
|
+
|
|
3
19
|
## 6.0.0-6-next.36
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -5,16 +5,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.allow = allow;
|
|
7
7
|
var _core = require("@verdaccio/core");
|
|
8
|
-
var _logger = require("@verdaccio/logger");
|
|
9
8
|
var _utils = require("@verdaccio/utils");
|
|
10
|
-
function allow(auth
|
|
9
|
+
function allow(auth, options = {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
beforeAll: (_a, _b) => {},
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
+
afterAll: (_a, _b) => {}
|
|
14
|
+
}) {
|
|
15
|
+
const {
|
|
16
|
+
beforeAll,
|
|
17
|
+
afterAll
|
|
18
|
+
} = options;
|
|
11
19
|
return function (action) {
|
|
12
20
|
return function (req, res, next) {
|
|
13
21
|
req.pause();
|
|
14
22
|
const packageName = req.params.scope ? `@${req.params.scope}/${req.params.package}` : req.params.package;
|
|
15
23
|
const packageVersion = req.params.filename ? (0, _utils.getVersionFromTarball)(req.params.filename) : undefined;
|
|
16
24
|
const remote = req.remote_user;
|
|
17
|
-
|
|
25
|
+
beforeAll === null || beforeAll === void 0 ? void 0 : beforeAll({
|
|
18
26
|
action,
|
|
19
27
|
user: remote === null || remote === void 0 ? void 0 : remote.name
|
|
20
28
|
}, `[middleware/allow][@{action}] allow for @{user}`);
|
|
@@ -26,6 +34,10 @@ function allow(auth) {
|
|
|
26
34
|
if (error) {
|
|
27
35
|
next(error);
|
|
28
36
|
} else if (allowed) {
|
|
37
|
+
afterAll === null || afterAll === void 0 ? void 0 : afterAll({
|
|
38
|
+
action,
|
|
39
|
+
user: remote === null || remote === void 0 ? void 0 : remote.name
|
|
40
|
+
}, `[middleware/allow][@{action}] allowed for @{user}`);
|
|
29
41
|
next();
|
|
30
42
|
} else {
|
|
31
43
|
// last plugin (that's our built-in one) returns either
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allow.js","names":["allow","auth","action","req","res","next","pause","packageName","params","scope","package","packageVersion","filename","getVersionFromTarball","undefined","remote","remote_user","
|
|
1
|
+
{"version":3,"file":"allow.js","names":["allow","auth","options","beforeAll","_a","_b","afterAll","action","req","res","next","pause","packageName","params","scope","package","packageVersion","filename","getVersionFromTarball","undefined","remote","remote_user","user","name","error","allowed","resume","errorUtils","getInternalError","API_ERROR","PLUGIN_ERROR"],"sources":["../../src/middlewares/allow.ts"],"sourcesContent":["import { API_ERROR, errorUtils } from '@verdaccio/core';\nimport { getVersionFromTarball } from '@verdaccio/utils';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function allow<T>(\n auth: T,\n options = {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n beforeAll: (_a: any, _b: any) => {},\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n afterAll: (_a: any, _b: any) => {},\n }\n): Function {\n const { beforeAll, afterAll } = options;\n return function (action: string): Function {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n req.pause();\n const packageName = req.params.scope\n ? `@${req.params.scope}/${req.params.package}`\n : req.params.package;\n const packageVersion = req.params.filename\n ? getVersionFromTarball(req.params.filename)\n : undefined;\n const remote = req.remote_user;\n beforeAll?.(\n { action, user: remote?.name },\n `[middleware/allow][@{action}] allow for @{user}`\n );\n auth['allow_' + action](\n { packageName, packageVersion },\n remote,\n function (error, allowed): void {\n req.resume();\n if (error) {\n next(error);\n } else if (allowed) {\n afterAll?.(\n { action, user: remote?.name },\n `[middleware/allow][@{action}] allowed for @{user}`\n );\n next();\n } else {\n // last plugin (that's our built-in one) returns either\n // cb(err) or cb(null, true), so this should never happen\n throw errorUtils.getInternalError(API_ERROR.PLUGIN_ERROR);\n }\n }\n );\n };\n };\n}\n"],"mappings":";;;;;;AAAA;AACA;AAIO,SAASA,KAAK,CACnBC,IAAO,EACPC,OAAO,GAAG;EACR;EACAC,SAAS,EAAE,CAACC,EAAO,EAAEC,EAAO,KAAK,CAAC,CAAC;EACnC;EACAC,QAAQ,EAAE,CAACF,EAAO,EAAEC,EAAO,KAAK,CAAC;AACnC,CAAC,EACS;EACV,MAAM;IAAEF,SAAS;IAAEG;EAAS,CAAC,GAAGJ,OAAO;EACvC,OAAO,UAAUK,MAAc,EAAY;IACzC,OAAO,UAAUC,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;MACxFF,GAAG,CAACG,KAAK,EAAE;MACX,MAAMC,WAAW,GAAGJ,GAAG,CAACK,MAAM,CAACC,KAAK,GAC/B,IAAGN,GAAG,CAACK,MAAM,CAACC,KAAM,IAAGN,GAAG,CAACK,MAAM,CAACE,OAAQ,EAAC,GAC5CP,GAAG,CAACK,MAAM,CAACE,OAAO;MACtB,MAAMC,cAAc,GAAGR,GAAG,CAACK,MAAM,CAACI,QAAQ,GACtC,IAAAC,4BAAqB,EAACV,GAAG,CAACK,MAAM,CAACI,QAAQ,CAAC,GAC1CE,SAAS;MACb,MAAMC,MAAM,GAAGZ,GAAG,CAACa,WAAW;MAC9BlB,SAAS,aAATA,SAAS,uBAATA,SAAS,CACP;QAAEI,MAAM;QAAEe,IAAI,EAAEF,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEG;MAAK,CAAC,EAC7B,iDAAgD,CAClD;MACDtB,IAAI,CAAC,QAAQ,GAAGM,MAAM,CAAC,CACrB;QAAEK,WAAW;QAAEI;MAAe,CAAC,EAC/BI,MAAM,EACN,UAAUI,KAAK,EAAEC,OAAO,EAAQ;QAC9BjB,GAAG,CAACkB,MAAM,EAAE;QACZ,IAAIF,KAAK,EAAE;UACTd,IAAI,CAACc,KAAK,CAAC;QACb,CAAC,MAAM,IAAIC,OAAO,EAAE;UAClBnB,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CACN;YAAEC,MAAM;YAAEe,IAAI,EAAEF,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEG;UAAK,CAAC,EAC7B,mDAAkD,CACpD;UACDb,IAAI,EAAE;QACR,CAAC,MAAM;UACL;UACA;UACA,MAAMiB,gBAAU,CAACC,gBAAgB,CAACC,eAAS,CAACC,YAAY,CAAC;QAC3D;MACF,CAAC,CACF;IACH,CAAC;EACH,CAAC;AACH"}
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/middleware",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "6.0.0-6-next.38",
|
|
4
|
+
"description": "express middleware utils",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"author": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"node": ">=12"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
33
|
-
"@verdaccio/utils": "6.0.0-6-next.
|
|
32
|
+
"@verdaccio/core": "6.0.0-6-next.59",
|
|
33
|
+
"@verdaccio/utils": "6.0.0-6-next.27",
|
|
34
34
|
"debug": "4.3.4",
|
|
35
35
|
"lodash": "4.17.21",
|
|
36
36
|
"mime": "2.6.0"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"url": "https://opencollective.com/verdaccio"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
43
|
+
"@verdaccio/logger": "6.0.0-6-next.27",
|
|
44
44
|
"body-parser": "1.20.1",
|
|
45
45
|
"supertest": "6.3.3"
|
|
46
46
|
},
|
package/src/middlewares/allow.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { API_ERROR, errorUtils } from '@verdaccio/core';
|
|
2
|
-
import { logger } from '@verdaccio/logger';
|
|
3
2
|
import { getVersionFromTarball } from '@verdaccio/utils';
|
|
4
3
|
|
|
5
4
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
|
|
6
5
|
|
|
7
|
-
export function allow<T>(
|
|
6
|
+
export function allow<T>(
|
|
7
|
+
auth: T,
|
|
8
|
+
options = {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
+
beforeAll: (_a: any, _b: any) => {},
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
afterAll: (_a: any, _b: any) => {},
|
|
13
|
+
}
|
|
14
|
+
): Function {
|
|
15
|
+
const { beforeAll, afterAll } = options;
|
|
8
16
|
return function (action: string): Function {
|
|
9
17
|
return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
|
|
10
18
|
req.pause();
|
|
@@ -15,7 +23,7 @@ export function allow<T>(auth: T): Function {
|
|
|
15
23
|
? getVersionFromTarball(req.params.filename)
|
|
16
24
|
: undefined;
|
|
17
25
|
const remote = req.remote_user;
|
|
18
|
-
|
|
26
|
+
beforeAll?.(
|
|
19
27
|
{ action, user: remote?.name },
|
|
20
28
|
`[middleware/allow][@{action}] allow for @{user}`
|
|
21
29
|
);
|
|
@@ -27,6 +35,10 @@ export function allow<T>(auth: T): Function {
|
|
|
27
35
|
if (error) {
|
|
28
36
|
next(error);
|
|
29
37
|
} else if (allowed) {
|
|
38
|
+
afterAll?.(
|
|
39
|
+
{ action, user: remote?.name },
|
|
40
|
+
`[middleware/allow][@{action}] allowed for @{user}`
|
|
41
|
+
);
|
|
30
42
|
next();
|
|
31
43
|
} else {
|
|
32
44
|
// last plugin (that's our built-in one) returns either
|
package/test/allow.spec.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
2
|
|
|
3
3
|
import { HTTP_STATUS } from '@verdaccio/core';
|
|
4
|
-
import { setup } from '@verdaccio/logger';
|
|
4
|
+
import { logger, setup } from '@verdaccio/logger';
|
|
5
5
|
|
|
6
6
|
import { allow } from '../src';
|
|
7
7
|
import { getApp } from './helper';
|
|
@@ -9,11 +9,14 @@ import { getApp } from './helper';
|
|
|
9
9
|
setup({});
|
|
10
10
|
|
|
11
11
|
test('should allow request', async () => {
|
|
12
|
-
const can = allow(
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const can = allow(
|
|
13
|
+
{
|
|
14
|
+
allow_publish: (params, remove, cb) => {
|
|
15
|
+
return cb(null, true);
|
|
16
|
+
},
|
|
15
17
|
},
|
|
16
|
-
|
|
18
|
+
logger
|
|
19
|
+
);
|
|
17
20
|
const app = getApp([]);
|
|
18
21
|
// @ts-ignore
|
|
19
22
|
app.get('/:package', can('publish'), (req, res) => {
|
|
@@ -24,11 +27,14 @@ test('should allow request', async () => {
|
|
|
24
27
|
});
|
|
25
28
|
|
|
26
29
|
test('should allow scope request', async () => {
|
|
27
|
-
const can = allow(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const can = allow(
|
|
31
|
+
{
|
|
32
|
+
allow_publish: (params, remove, cb) => {
|
|
33
|
+
return cb(null, true);
|
|
34
|
+
},
|
|
30
35
|
},
|
|
31
|
-
|
|
36
|
+
logger
|
|
37
|
+
);
|
|
32
38
|
const app = getApp([]);
|
|
33
39
|
// @ts-ignore
|
|
34
40
|
app.get('/:package/:scope', can('publish'), (req, res) => {
|
|
@@ -39,11 +45,14 @@ test('should allow scope request', async () => {
|
|
|
39
45
|
});
|
|
40
46
|
|
|
41
47
|
test('should allow filename request', async () => {
|
|
42
|
-
const can = allow(
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
const can = allow(
|
|
49
|
+
{
|
|
50
|
+
allow_publish: (params, remove, cb) => {
|
|
51
|
+
return cb(null, true);
|
|
52
|
+
},
|
|
45
53
|
},
|
|
46
|
-
|
|
54
|
+
logger
|
|
55
|
+
);
|
|
47
56
|
const app = getApp([]);
|
|
48
57
|
// @ts-ignore
|
|
49
58
|
app.get('/:filename', can('publish'), (req, res) => {
|
|
@@ -54,11 +63,14 @@ test('should allow filename request', async () => {
|
|
|
54
63
|
});
|
|
55
64
|
|
|
56
65
|
test('should not allow request', async () => {
|
|
57
|
-
const can = allow(
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
const can = allow(
|
|
67
|
+
{
|
|
68
|
+
allow_publish: (params, remove, cb) => {
|
|
69
|
+
return cb(null, false);
|
|
70
|
+
},
|
|
60
71
|
},
|
|
61
|
-
|
|
72
|
+
logger
|
|
73
|
+
);
|
|
62
74
|
const app = getApp([]);
|
|
63
75
|
// @ts-ignore
|
|
64
76
|
app.get('/sec', can('publish'), (req, res) => {
|
|
@@ -69,11 +81,14 @@ test('should not allow request', async () => {
|
|
|
69
81
|
});
|
|
70
82
|
|
|
71
83
|
test('should handle error request', async () => {
|
|
72
|
-
const can = allow(
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
const can = allow(
|
|
85
|
+
{
|
|
86
|
+
allow_publish: (params, remove, cb) => {
|
|
87
|
+
return cb(Error('foo error'));
|
|
88
|
+
},
|
|
75
89
|
},
|
|
76
|
-
|
|
90
|
+
logger
|
|
91
|
+
);
|
|
77
92
|
const app = getApp([]);
|
|
78
93
|
// @ts-ignore
|
|
79
94
|
app.get('/err', can('publish'));
|