@verdaccio/api 6.0.0-6-next.33 → 6.0.0-6-next.35
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 +38 -0
- package/build/dist-tags.js +2 -24
- package/build/dist-tags.js.map +1 -1
- package/build/index.js +14 -30
- package/build/index.js.map +1 -1
- package/build/package.js +3 -15
- package/build/package.js.map +1 -1
- package/build/ping.js +0 -1
- package/build/ping.js.map +1 -1
- package/build/publish.js +4 -19
- package/build/publish.js.map +1 -1
- package/build/search.js +0 -4
- package/build/search.js.map +1 -1
- package/build/stars.js +6 -8
- package/build/stars.js.map +1 -1
- package/build/user.js +7 -27
- package/build/user.js.map +1 -1
- package/build/v1/profile.js +0 -11
- package/build/v1/profile.js.map +1 -1
- package/build/v1/search.js +1 -13
- package/build/v1/search.js.map +1 -1
- package/build/v1/token.d.ts +1 -1
- package/build/v1/token.js +8 -35
- package/build/v1/token.js.map +1 -1
- package/build/whoami.js +0 -8
- package/build/whoami.js.map +1 -1
- package/package.json +11 -11
- package/src/dist-tags.ts +0 -20
- package/src/stars.ts +7 -5
- package/src/user.ts +10 -1
- package/src/v1/token.ts +2 -1
- package/test/integration/_helper.ts +42 -3
- package/test/integration/config/star.yaml +26 -0
- package/test/integration/publish.spec.ts +17 -48
- package/test/integration/star.spec.ts +73 -0
- package/types/custom.d.ts +1 -1
- package/build/star.d.ts +0 -4
- package/build/star.js +0 -90
- package/build/star.js.map +0 -1
- package/src/star.ts +0 -88
package/build/stars.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stars.js","names":["route","storage","get","req","res","next","
|
|
1
|
+
{"version":3,"file":"stars.js","names":["route","storage","get","req","res","next","query","key","errorUtils","getBadRequest","localPackages","getLocalDatabase","filteredPackages","filter","localPackage","_","keys","USERS","includes","toString","replace","status","HTTP_STATUS","OK","rows","map","filteredPackage","value","name","err"],"sources":["../src/stars.ts"],"sourcesContent":["import { Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport { HTTP_STATUS, USERS, errorUtils } from '@verdaccio/core';\nimport { Storage } from '@verdaccio/store';\nimport { Version } from '@verdaccio/types';\n\nimport { $NextFunctionVer, $RequestExtend } from '../types/custom';\n\nexport default function (route: Router, storage: Storage): void {\n route.get(\n '/-/_view/starredByUser',\n async (req: $RequestExtend, res: Response, next: $NextFunctionVer): Promise<void> => {\n const query: { key: string } = req.query;\n if (typeof query?.key !== 'string') {\n return next(errorUtils.getBadRequest('missing query key username'));\n }\n\n try {\n const localPackages: Version[] = await storage.getLocalDatabase();\n const filteredPackages: Version[] = localPackages.filter((localPackage: Version) =>\n _.keys(localPackage[USERS]).includes(query?.key.toString().replace(/['\"]+/g, ''))\n );\n\n res.status(HTTP_STATUS.OK);\n next({\n rows: filteredPackages.map((filteredPackage: Version) => ({\n value: filteredPackage.name,\n })),\n });\n } catch (err: any) {\n return next(err);\n }\n }\n );\n}\n"],"mappings":";;;;;;AACA;AAEA;AAAiE;AAMlD,kBAAUA,KAAa,EAAEC,OAAgB,EAAQ;EAC9DD,KAAK,CAACE,GAAG,CACP,wBAAwB,EACxB,OAAOC,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,KAAoB;IACnF,MAAMC,KAAsB,GAAGH,GAAG,CAACG,KAAK;IACxC,IAAI,QAAOA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,GAAG,MAAK,QAAQ,EAAE;MAClC,OAAOF,IAAI,CAACG,gBAAU,CAACC,aAAa,CAAC,4BAA4B,CAAC,CAAC;IACrE;IAEA,IAAI;MACF,MAAMC,aAAwB,GAAG,MAAMT,OAAO,CAACU,gBAAgB,EAAE;MACjE,MAAMC,gBAA2B,GAAGF,aAAa,CAACG,MAAM,CAAEC,YAAqB,IAC7EC,eAAC,CAACC,IAAI,CAACF,YAAY,CAACG,WAAK,CAAC,CAAC,CAACC,QAAQ,CAACZ,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,GAAG,CAACY,QAAQ,EAAE,CAACC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAClF;MAEDhB,GAAG,CAACiB,MAAM,CAACC,iBAAW,CAACC,EAAE,CAAC;MAC1BlB,IAAI,CAAC;QACHmB,IAAI,EAAEZ,gBAAgB,CAACa,GAAG,CAAEC,eAAwB,KAAM;UACxDC,KAAK,EAAED,eAAe,CAACE;QACzB,CAAC,CAAC;MACJ,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOC,GAAQ,EAAE;MACjB,OAAOxB,IAAI,CAACwB,GAAG,CAAC;IAClB;EACF,CAAC,CACF;AACH"}
|
package/build/user.js
CHANGED
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
8
|
var _auth = require("@verdaccio/auth");
|
|
11
|
-
|
|
12
9
|
var _config = require("@verdaccio/config");
|
|
13
|
-
|
|
14
10
|
var _core = require("@verdaccio/core");
|
|
15
|
-
|
|
16
11
|
var _logger = require("@verdaccio/logger");
|
|
17
|
-
|
|
18
12
|
var _utils = require("@verdaccio/utils");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
const debug = (0, _debug.default)('verdaccio:api:user');
|
|
23
|
-
|
|
24
15
|
function _default(route, auth, config) {
|
|
25
16
|
route.get('/-/user/:org_couchdb_user', function (req, res, next) {
|
|
26
17
|
debug('verifying user');
|
|
@@ -31,6 +22,7 @@ function _default(route, auth, config) {
|
|
|
31
22
|
ok: message
|
|
32
23
|
});
|
|
33
24
|
});
|
|
25
|
+
|
|
34
26
|
/**
|
|
35
27
|
*
|
|
36
28
|
* body example
|
|
@@ -48,17 +40,14 @@ function _default(route, auth, config) {
|
|
|
48
40
|
* @param {Auth} auth
|
|
49
41
|
* @param {Config} config
|
|
50
42
|
*/
|
|
51
|
-
|
|
52
43
|
route.put('/-/user/:org_couchdb_user/:_rev?/:revision?', function (req, res, next) {
|
|
53
44
|
var _req$remote_user;
|
|
54
|
-
|
|
55
45
|
const {
|
|
56
46
|
name,
|
|
57
47
|
password
|
|
58
48
|
} = req.body;
|
|
59
49
|
debug('login or adduser');
|
|
60
50
|
const remoteName = req === null || req === void 0 ? void 0 : (_req$remote_user = req.remote_user) === null || _req$remote_user === void 0 ? void 0 : _req$remote_user.name;
|
|
61
|
-
|
|
62
51
|
if (typeof remoteName !== 'undefined' && typeof name === 'string' && remoteName === name) {
|
|
63
52
|
debug('login: no remote user detected');
|
|
64
53
|
auth.authenticate(name, password, async function callbackAuthenticate(err, user) {
|
|
@@ -67,19 +56,16 @@ function _default(route, auth, config) {
|
|
|
67
56
|
name,
|
|
68
57
|
err
|
|
69
58
|
}, 'authenticating for user @{username} failed. Error: @{err.message}');
|
|
70
|
-
|
|
71
59
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNAUTHORIZED, _core.API_ERROR.BAD_USERNAME_PASSWORD));
|
|
72
60
|
}
|
|
73
|
-
|
|
74
61
|
const restoredRemoteUser = (0, _config.createRemoteUser)(name, (user === null || user === void 0 ? void 0 : user.groups) || []);
|
|
75
62
|
const token = await (0, _auth.getApiToken)(auth, config, restoredRemoteUser, password);
|
|
76
63
|
debug('login: new token');
|
|
77
|
-
|
|
78
64
|
if (!token) {
|
|
79
65
|
return next(_core.errorUtils.getUnauthorized());
|
|
80
66
|
}
|
|
81
|
-
|
|
82
67
|
res.status(_core.HTTP_STATUS.CREATED);
|
|
68
|
+
res.set(_core.HEADERS.CACHE_CONTROL, 'no-cache, no-store');
|
|
83
69
|
const message = (0, _utils.getAuthenticatedMessage)(req.remote_user.name);
|
|
84
70
|
debug('login: created user message %o', message);
|
|
85
71
|
return next({
|
|
@@ -89,38 +75,32 @@ function _default(route, auth, config) {
|
|
|
89
75
|
});
|
|
90
76
|
} else {
|
|
91
77
|
var _config$serverSetting;
|
|
92
|
-
|
|
93
78
|
if (_core.validatioUtils.validatePassword(password, config === null || config === void 0 ? void 0 : (_config$serverSetting = config.serverSettings) === null || _config$serverSetting === void 0 ? void 0 : _config$serverSetting.passwordValidationRegex) === false) {
|
|
94
|
-
debug('adduser: invalid password');
|
|
95
|
-
|
|
79
|
+
debug('adduser: invalid password');
|
|
80
|
+
// eslint-disable-next-line new-cap
|
|
96
81
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.BAD_REQUEST, _core.API_ERROR.PASSWORD_SHORT));
|
|
97
82
|
}
|
|
98
|
-
|
|
99
83
|
auth.add_user(name, password, async function (err, user) {
|
|
100
84
|
if (err) {
|
|
101
85
|
if (err.status >= _core.HTTP_STATUS.BAD_REQUEST && err.status < _core.HTTP_STATUS.INTERNAL_ERROR) {
|
|
102
|
-
debug('adduser: error on create user');
|
|
86
|
+
debug('adduser: error on create user');
|
|
87
|
+
// With npm registering is the same as logging in,
|
|
103
88
|
// and npm accepts only an 409 error.
|
|
104
89
|
// So, changing status code here.
|
|
105
|
-
|
|
106
90
|
return next(_core.errorUtils.getCode(err.status, err.message) || _core.errorUtils.getConflict(err.message));
|
|
107
91
|
}
|
|
108
|
-
|
|
109
92
|
return next(err);
|
|
110
93
|
}
|
|
111
|
-
|
|
112
94
|
const token = name && password ? await (0, _auth.getApiToken)(auth, config, user, password) : undefined;
|
|
113
|
-
|
|
114
95
|
if (token) {
|
|
115
96
|
debug('adduser: new token %o', (0, _utils.mask)(token, 4));
|
|
116
97
|
}
|
|
117
|
-
|
|
118
98
|
if (!token) {
|
|
119
99
|
return next(_core.errorUtils.getUnauthorized());
|
|
120
100
|
}
|
|
121
|
-
|
|
122
101
|
req.remote_user = user;
|
|
123
102
|
res.status(_core.HTTP_STATUS.CREATED);
|
|
103
|
+
res.set(_core.HEADERS.CACHE_CONTROL, 'no-cache, no-store');
|
|
124
104
|
debug('adduser: user has been created');
|
|
125
105
|
return next({
|
|
126
106
|
ok: `user '${req.body.name}' created`,
|
package/build/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","names":["debug","buildDebug","route","auth","config","get","req","res","next","message","getAuthenticatedMessage","remote_user","name","status","HTTP_STATUS","OK","ok","put","password","body","remoteName","authenticate","callbackAuthenticate","err","user","logger","trace","errorUtils","getCode","UNAUTHORIZED","API_ERROR","BAD_USERNAME_PASSWORD","restoredRemoteUser","createRemoteUser","groups","token","getApiToken","getUnauthorized","CREATED","validatioUtils","validatePassword","serverSettings","passwordValidationRegex","BAD_REQUEST","PASSWORD_SHORT","add_user","INTERNAL_ERROR","getConflict","undefined","mask","delete","API_MESSAGE","LOGGED_OUT"],"sources":["../src/user.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Response, Router } from 'express';\n\nimport { getApiToken } from '@verdaccio/auth';\nimport { Auth } from '@verdaccio/auth';\nimport { createRemoteUser } from '@verdaccio/config';\nimport {
|
|
1
|
+
{"version":3,"file":"user.js","names":["debug","buildDebug","route","auth","config","get","req","res","next","message","getAuthenticatedMessage","remote_user","name","status","HTTP_STATUS","OK","ok","put","password","body","remoteName","authenticate","callbackAuthenticate","err","user","logger","trace","errorUtils","getCode","UNAUTHORIZED","API_ERROR","BAD_USERNAME_PASSWORD","restoredRemoteUser","createRemoteUser","groups","token","getApiToken","getUnauthorized","CREATED","set","HEADERS","CACHE_CONTROL","validatioUtils","validatePassword","serverSettings","passwordValidationRegex","BAD_REQUEST","PASSWORD_SHORT","add_user","INTERNAL_ERROR","getConflict","undefined","mask","delete","API_MESSAGE","LOGGED_OUT"],"sources":["../src/user.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Response, Router } from 'express';\n\nimport { getApiToken } from '@verdaccio/auth';\nimport { Auth } from '@verdaccio/auth';\nimport { createRemoteUser } from '@verdaccio/config';\nimport {\n API_ERROR,\n API_MESSAGE,\n HEADERS,\n HTTP_STATUS,\n errorUtils,\n validatioUtils,\n} from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { Config, RemoteUser } from '@verdaccio/types';\nimport { getAuthenticatedMessage, mask } from '@verdaccio/utils';\n\nimport { $NextFunctionVer, $RequestExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:user');\n\nexport default function (route: Router, auth: Auth, config: Config): void {\n route.get(\n '/-/user/:org_couchdb_user',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n debug('verifying user');\n const message = getAuthenticatedMessage(req.remote_user.name);\n debug('user authenticated message %o', message);\n res.status(HTTP_STATUS.OK);\n next({\n ok: message,\n });\n }\n );\n\n /**\n * \n * body example\n * req.body = {\n _id: \"org.couchdb.user:jjjj\",\n name: \"jjjj\",\n password: \"jjjj\",\n type: \"user\",\n roles: [],\n date: \"2022-07-08T15:51:04.002Z\",\n }\n * \n * @export\n * @param {Router} route\n * @param {Auth} auth\n * @param {Config} config\n */\n route.put(\n '/-/user/:org_couchdb_user/:_rev?/:revision?',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n const { name, password } = req.body;\n debug('login or adduser');\n const remoteName = req?.remote_user?.name;\n\n if (typeof remoteName !== 'undefined' && typeof name === 'string' && remoteName === name) {\n debug('login: no remote user detected');\n auth.authenticate(\n name,\n password,\n async function callbackAuthenticate(err, user): Promise<void> {\n if (err) {\n logger.trace(\n { name, err },\n 'authenticating for user @{username} failed. Error: @{err.message}'\n );\n return next(\n errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.BAD_USERNAME_PASSWORD)\n );\n }\n\n const restoredRemoteUser: RemoteUser = createRemoteUser(name, user?.groups || []);\n const token = await getApiToken(auth, config, restoredRemoteUser, password);\n debug('login: new token');\n if (!token) {\n return next(errorUtils.getUnauthorized());\n }\n\n res.status(HTTP_STATUS.CREATED);\n res.set(HEADERS.CACHE_CONTROL, 'no-cache, no-store');\n\n const message = getAuthenticatedMessage(req.remote_user.name);\n debug('login: created user message %o', message);\n\n return next({\n ok: message,\n token,\n });\n }\n );\n } else {\n if (\n validatioUtils.validatePassword(\n password,\n config?.serverSettings?.passwordValidationRegex\n ) === false\n ) {\n debug('adduser: invalid password');\n // eslint-disable-next-line new-cap\n return next(errorUtils.getCode(HTTP_STATUS.BAD_REQUEST, API_ERROR.PASSWORD_SHORT));\n }\n\n auth.add_user(name, password, async function (err, user): Promise<void> {\n if (err) {\n if (err.status >= HTTP_STATUS.BAD_REQUEST && err.status < HTTP_STATUS.INTERNAL_ERROR) {\n debug('adduser: error on create user');\n // With npm registering is the same as logging in,\n // and npm accepts only an 409 error.\n // So, changing status code here.\n return next(\n errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message)\n );\n }\n return next(err);\n }\n\n const token =\n name && password\n ? await getApiToken(auth, config, user as RemoteUser, password)\n : undefined;\n if (token) {\n debug('adduser: new token %o', mask(token as string, 4));\n }\n if (!token) {\n return next(errorUtils.getUnauthorized());\n }\n\n req.remote_user = user;\n res.status(HTTP_STATUS.CREATED);\n res.set(HEADERS.CACHE_CONTROL, 'no-cache, no-store');\n debug('adduser: user has been created');\n return next({\n ok: `user '${req.body.name}' created`,\n token,\n });\n });\n }\n }\n );\n\n route.delete(\n '/-/user/token/*',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n res.status(HTTP_STATUS.OK);\n next({\n ok: API_MESSAGE.LOGGED_OUT,\n });\n }\n );\n}\n"],"mappings":";;;;;;AAAA;AAGA;AAEA;AACA;AAQA;AAEA;AAAiE;AAIjE,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,oBAAoB,CAAC;AAE/B,kBAAUC,KAAa,EAAEC,IAAU,EAAEC,MAAc,EAAQ;EACxEF,KAAK,CAACG,GAAG,CACP,2BAA2B,EAC3B,UAAUC,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,EAAQ;IAC1ER,KAAK,CAAC,gBAAgB,CAAC;IACvB,MAAMS,OAAO,GAAG,IAAAC,8BAAuB,EAACJ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
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
-
|
|
10
8
|
var _core = require("@verdaccio/core");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
function _default(route, auth, config) {
|
|
15
11
|
function buildProfile(name) {
|
|
16
12
|
return {
|
|
@@ -24,12 +20,10 @@ function _default(route, auth, config) {
|
|
|
24
20
|
fullname: ''
|
|
25
21
|
};
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
route.get('/-/npm/v1/user', function (req, res, next) {
|
|
29
24
|
if (_lodash.default.isNil(req.remote_user.name) === false) {
|
|
30
25
|
return next(buildProfile(req.remote_user.name));
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
res.status(_core.HTTP_STATUS.UNAUTHORIZED);
|
|
34
28
|
return next({
|
|
35
29
|
message: _core.API_ERROR.MUST_BE_LOGGED
|
|
@@ -42,7 +36,6 @@ function _default(route, auth, config) {
|
|
|
42
36
|
message: _core.API_ERROR.MUST_BE_LOGGED
|
|
43
37
|
});
|
|
44
38
|
}
|
|
45
|
-
|
|
46
39
|
const {
|
|
47
40
|
password,
|
|
48
41
|
tfa
|
|
@@ -50,10 +43,8 @@ function _default(route, auth, config) {
|
|
|
50
43
|
const {
|
|
51
44
|
name
|
|
52
45
|
} = req.remote_user;
|
|
53
|
-
|
|
54
46
|
if (_lodash.default.isNil(password) === false) {
|
|
55
47
|
var _config$serverSetting;
|
|
56
|
-
|
|
57
48
|
if (_core.validatioUtils.validatePassword(password.new, config === null || config === void 0 ? void 0 : (_config$serverSetting = config.serverSettings) === null || _config$serverSetting === void 0 ? void 0 : _config$serverSetting.passwordValidationRegex) === false) {
|
|
58
49
|
/* eslint new-cap:off */
|
|
59
50
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNAUTHORIZED, _core.API_ERROR.PASSWORD_SHORT));
|
|
@@ -64,11 +55,9 @@ function _default(route, auth, config) {
|
|
|
64
55
|
if (_lodash.default.isNull(err) === false) {
|
|
65
56
|
return next(_core.errorUtils.getCode(err.status, err.message) || _core.errorUtils.getConflict(err.message));
|
|
66
57
|
}
|
|
67
|
-
|
|
68
58
|
if (isUpdated) {
|
|
69
59
|
return next(buildProfile(req.remote_user.name));
|
|
70
60
|
}
|
|
71
|
-
|
|
72
61
|
return next(_core.errorUtils.getInternalError(_core.API_ERROR.INTERNAL_SERVER_ERROR));
|
|
73
62
|
});
|
|
74
63
|
} else if (_lodash.default.isNil(tfa) === false) {
|
package/build/v1/profile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","names":["route","auth","config","buildProfile","name","tfa","email","email_verified","created","updated","cidr_whitelist","fullname","get","req","res","next","_","isNil","remote_user","status","HTTP_STATUS","UNAUTHORIZED","message","API_ERROR","MUST_BE_LOGGED","post","password","body","validatioUtils","validatePassword","new","serverSettings","passwordValidationRegex","errorUtils","getCode","PASSWORD_SHORT","changePassword","old","err","isUpdated","isNull","getConflict","getInternalError","INTERNAL_SERVER_ERROR","SERVICE_UNAVAILABLE","SUPPORT_ERRORS","TFA_DISABLED","INTERNAL_ERROR","APP_ERROR","PROFILE_ERROR"],"sources":["../../src/v1/profile.ts"],"sourcesContent":["import { Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n API_ERROR,\n APP_ERROR,\n HTTP_STATUS,\n SUPPORT_ERRORS,\n errorUtils,\n validatioUtils,\n} from '@verdaccio/core';\nimport { Config } from '@verdaccio/types';\n\nimport { $NextFunctionVer, $RequestExtend } from '../../types/custom';\n\nexport interface Profile {\n tfa: boolean;\n name: string;\n email: string;\n email_verified: boolean;\n created: string;\n updated: string;\n cidr_whitelist: string[] | null;\n fullname: string;\n}\n\nexport default function (route: Router, auth: Auth, config: Config): void {\n function buildProfile(name: string): Profile {\n return {\n tfa: false,\n name,\n email: '',\n email_verified: false,\n created: '',\n updated: '',\n cidr_whitelist: null,\n fullname: '',\n };\n }\n\n route.get(\n '/-/npm/v1/user',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name) === false) {\n return next(buildProfile(req.remote_user.name));\n }\n\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n );\n\n route.post(\n '/-/npm/v1/user',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name)) {\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n\n const { password, tfa } = req.body;\n const { name } = req.remote_user;\n\n if (_.isNil(password) === false) {\n if (\n validatioUtils.validatePassword(\n password.new,\n config?.serverSettings?.passwordValidationRegex\n ) === false\n ) {\n /* eslint new-cap:off */\n return next(errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.PASSWORD_SHORT));\n /* eslint new-cap:off */\n }\n\n auth.changePassword(\n name,\n password.old,\n password.new,\n (err, isUpdated): $NextFunctionVer => {\n if (_.isNull(err) === false) {\n return next(\n errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message)\n );\n }\n\n if (isUpdated) {\n return next(buildProfile(req.remote_user.name));\n }\n return next(errorUtils.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR));\n }\n );\n } else if (_.isNil(tfa) === false) {\n return next(\n errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.TFA_DISABLED)\n );\n } else {\n return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, APP_ERROR.PROFILE_ERROR));\n }\n }\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"profile.js","names":["route","auth","config","buildProfile","name","tfa","email","email_verified","created","updated","cidr_whitelist","fullname","get","req","res","next","_","isNil","remote_user","status","HTTP_STATUS","UNAUTHORIZED","message","API_ERROR","MUST_BE_LOGGED","post","password","body","validatioUtils","validatePassword","new","serverSettings","passwordValidationRegex","errorUtils","getCode","PASSWORD_SHORT","changePassword","old","err","isUpdated","isNull","getConflict","getInternalError","INTERNAL_SERVER_ERROR","SERVICE_UNAVAILABLE","SUPPORT_ERRORS","TFA_DISABLED","INTERNAL_ERROR","APP_ERROR","PROFILE_ERROR"],"sources":["../../src/v1/profile.ts"],"sourcesContent":["import { Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n API_ERROR,\n APP_ERROR,\n HTTP_STATUS,\n SUPPORT_ERRORS,\n errorUtils,\n validatioUtils,\n} from '@verdaccio/core';\nimport { Config } from '@verdaccio/types';\n\nimport { $NextFunctionVer, $RequestExtend } from '../../types/custom';\n\nexport interface Profile {\n tfa: boolean;\n name: string;\n email: string;\n email_verified: boolean;\n created: string;\n updated: string;\n cidr_whitelist: string[] | null;\n fullname: string;\n}\n\nexport default function (route: Router, auth: Auth, config: Config): void {\n function buildProfile(name: string): Profile {\n return {\n tfa: false,\n name,\n email: '',\n email_verified: false,\n created: '',\n updated: '',\n cidr_whitelist: null,\n fullname: '',\n };\n }\n\n route.get(\n '/-/npm/v1/user',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name) === false) {\n return next(buildProfile(req.remote_user.name));\n }\n\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n );\n\n route.post(\n '/-/npm/v1/user',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name)) {\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n\n const { password, tfa } = req.body;\n const { name } = req.remote_user;\n\n if (_.isNil(password) === false) {\n if (\n validatioUtils.validatePassword(\n password.new,\n config?.serverSettings?.passwordValidationRegex\n ) === false\n ) {\n /* eslint new-cap:off */\n return next(errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.PASSWORD_SHORT));\n /* eslint new-cap:off */\n }\n\n auth.changePassword(\n name,\n password.old,\n password.new,\n (err, isUpdated): $NextFunctionVer => {\n if (_.isNull(err) === false) {\n return next(\n errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message)\n );\n }\n\n if (isUpdated) {\n return next(buildProfile(req.remote_user.name));\n }\n return next(errorUtils.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR));\n }\n );\n } else if (_.isNil(tfa) === false) {\n return next(\n errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.TFA_DISABLED)\n );\n } else {\n return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, APP_ERROR.PROFILE_ERROR));\n }\n }\n );\n}\n"],"mappings":";;;;;;AACA;AAGA;AAOyB;AAgBV,kBAAUA,KAAa,EAAEC,IAAU,EAAEC,MAAc,EAAQ;EACxE,SAASC,YAAY,CAACC,IAAY,EAAW;IAC3C,OAAO;MACLC,GAAG,EAAE,KAAK;MACVD,IAAI;MACJE,KAAK,EAAE,EAAE;MACTC,cAAc,EAAE,KAAK;MACrBC,OAAO,EAAE,EAAE;MACXC,OAAO,EAAE,EAAE;MACXC,cAAc,EAAE,IAAI;MACpBC,QAAQ,EAAE;IACZ,CAAC;EACH;EAEAX,KAAK,CAACY,GAAG,CACP,gBAAgB,EAChB,UAAUC,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,EAAQ;IAC1E,IAAIC,eAAC,CAACC,KAAK,CAACJ,GAAG,CAACK,WAAW,CAACd,IAAI,CAAC,KAAK,KAAK,EAAE;MAC3C,OAAOW,IAAI,CAACZ,YAAY,CAACU,GAAG,CAACK,WAAW,CAACd,IAAI,CAAC,CAAC;IACjD;IAEAU,GAAG,CAACK,MAAM,CAACC,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CAAC,IAAIW,gBAAU,CAACQ,WAAW,CAACH,GAAG,CAAChB,OAAO,CAAC,CACnF;QACH;QAEA,IAAIiB,SAAS,EAAE;UACb,OAAOxB,IAAI,CAACZ,YAAY,CAACU,GAAG,CAACK,WAAW,CAACd,IAAI,CAAC,CAAC;QACjD;QACA,OAAOW,IAAI,CAACkB,gBAAU,CAACS,gBAAgB,CAACnB,eAAS,CAACoB,qBAAqB,CAAC,CAAC;MAC3E,CAAC,CACF;IACH,CAAC,MAAM,IAAI3B,eAAC,CAACC,KAAK,CAACZ,GAAG,CAAC,KAAK,KAAK,EAAE;MACjC,OAAOU,IAAI,CACTkB,gBAAU,CAACC,OAAO,CAACd,iBAAW,CAACwB,mBAAmB,EAAEC,oBAAc,CAACC,YAAY,CAAC,CACjF;IACH,CAAC,MAAM;MACL,OAAO/B,IAAI,CAACkB,gBAAU,CAACC,OAAO,CAACd,iBAAW,CAAC2B,cAAc,EAAEC,eAAS,CAACC,aAAa,CAAC,CAAC;IACtF;EACF,CAAC,CACF;AACH"}
|
package/build/v1/search.js
CHANGED
|
@@ -4,30 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
8
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
11
|
-
|
|
12
9
|
var _core = require("@verdaccio/core");
|
|
13
|
-
|
|
14
10
|
var _logger = require("@verdaccio/logger");
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
const debug = (0, _debug.default)('verdaccio:api:search');
|
|
13
|
+
|
|
19
14
|
/**
|
|
20
15
|
* Endpoint for npm search v1
|
|
21
16
|
* Empty value
|
|
22
17
|
* - {"objects":[],"total":0,"time":"Sun Jul 25 2021 14:09:11 GMT+0000 (Coordinated Universal Time)"}
|
|
23
18
|
* req: 'GET /-/v1/search?text=react&size=20&frpom=0&quality=0.65&popularity=0.98&maintenance=0.5'
|
|
24
19
|
*/
|
|
25
|
-
|
|
26
20
|
function _default(route, auth, storage) {
|
|
27
21
|
function checkAccess(pkg, auth, remoteUser) {
|
|
28
22
|
return new Promise((resolve, reject) => {
|
|
29
23
|
var _pkg$package;
|
|
30
|
-
|
|
31
24
|
auth.allow_access({
|
|
32
25
|
packageName: pkg === null || pkg === void 0 ? void 0 : (_pkg$package = pkg.package) === null || _pkg$package === void 0 ? void 0 : _pkg$package.name
|
|
33
26
|
}, remoteUser, function (err, allowed) {
|
|
@@ -46,7 +39,6 @@ function _default(route, auth, storage) {
|
|
|
46
39
|
});
|
|
47
40
|
});
|
|
48
41
|
}
|
|
49
|
-
|
|
50
42
|
route.get('/-/v1/search', async (req, res, next) => {
|
|
51
43
|
const {
|
|
52
44
|
query,
|
|
@@ -61,7 +53,6 @@ function _default(route, auth, storage) {
|
|
|
61
53
|
});
|
|
62
54
|
size = parseInt(size, 10) || 20;
|
|
63
55
|
from = parseInt(from, 10) || 0;
|
|
64
|
-
|
|
65
56
|
try {
|
|
66
57
|
data = await storage.search({
|
|
67
58
|
query,
|
|
@@ -73,9 +64,7 @@ function _default(route, auth, storage) {
|
|
|
73
64
|
return checkAccess(pkgItem, auth, req.remote_user);
|
|
74
65
|
}));
|
|
75
66
|
const final = checkAccessPromises.filter(i => !_lodash.default.isNull(i)).slice(from, size);
|
|
76
|
-
|
|
77
67
|
_logger.logger.debug(`search results ${final === null || final === void 0 ? void 0 : final.length}`);
|
|
78
|
-
|
|
79
68
|
const response = {
|
|
80
69
|
objects: final,
|
|
81
70
|
total: final.length,
|
|
@@ -86,7 +75,6 @@ function _default(route, auth, storage) {
|
|
|
86
75
|
_logger.logger.error({
|
|
87
76
|
error
|
|
88
77
|
}, 'search endpoint has failed @{error.message}');
|
|
89
|
-
|
|
90
78
|
next(next);
|
|
91
79
|
return;
|
|
92
80
|
}
|
package/build/v1/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","names":["debug","buildDebug","route","auth","storage","checkAccess","pkg","remoteUser","Promise","resolve","reject","allow_access","packageName","package","name","err","allowed","status","String","match","get","req","res","next","query","url","size","from","map","k","data","abort","AbortController","socket","on","parseInt","search","checkAccessPromises","all","pkgItem","remote_user","final","filter","i","_","isNull","slice","logger","length","response","objects","total","time","Date","toUTCString","HTTP_STATUS","OK","json","error"],"sources":["../../src/v1/search.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport { HTTP_STATUS, searchUtils } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { Storage } from '@verdaccio/store';\nimport { Manifest } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:api:search');\n\n/**\n * Endpoint for npm search v1\n * Empty value\n * - {\"objects\":[],\"total\":0,\"time\":\"Sun Jul 25 2021 14:09:11 GMT+0000 (Coordinated Universal Time)\"}\n * req: 'GET /-/v1/search?text=react&size=20&frpom=0&quality=0.65&popularity=0.98&maintenance=0.5'\n */\nexport default function (route, auth: Auth, storage: Storage): void {\n function checkAccess(pkg: any, auth: any, remoteUser): Promise<Manifest | null> {\n return new Promise((resolve, reject) => {\n auth.allow_access({ packageName: pkg?.package?.name }, remoteUser, function (err, allowed) {\n if (err) {\n if (err.status && String(err.status).match(/^4\\d\\d$/)) {\n // auth plugin returns 4xx user error,\n // that's equivalent of !allowed basically\n allowed = false;\n return resolve(null);\n } else {\n reject(err);\n }\n } else {\n return resolve(allowed ? pkg : null);\n }\n });\n });\n }\n\n route.get('/-/v1/search', async (req, res, next) => {\n const { query, url } = req;\n let [size, from] = ['size', 'from'].map((k) => query[k]);\n let data;\n const abort = new AbortController();\n\n req.socket.on('close', function () {\n debug('search web aborted');\n abort.abort();\n });\n\n size = parseInt(size, 10) || 20;\n from = parseInt(from, 10) || 0;\n\n try {\n data = await storage.search({\n query,\n url,\n abort,\n });\n debug('stream finish');\n const checkAccessPromises: searchUtils.SearchItemPkg[] = await Promise.all(\n data.map((pkgItem) => {\n return checkAccess(pkgItem, auth, req.remote_user);\n })\n );\n\n const final: searchUtils.SearchItemPkg[] = checkAccessPromises\n .filter((i) => !_.isNull(i))\n .slice(from, size);\n logger.debug(`search results ${final?.length}`);\n\n const response: searchUtils.SearchResults = {\n objects: final,\n total: final.length,\n time: new Date().toUTCString(),\n };\n\n res.status(HTTP_STATUS.OK).json(response);\n } catch (error) {\n logger.error({ error }, 'search endpoint has failed @{error.message}');\n next(next);\n return;\n }\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"search.js","names":["debug","buildDebug","route","auth","storage","checkAccess","pkg","remoteUser","Promise","resolve","reject","allow_access","packageName","package","name","err","allowed","status","String","match","get","req","res","next","query","url","size","from","map","k","data","abort","AbortController","socket","on","parseInt","search","checkAccessPromises","all","pkgItem","remote_user","final","filter","i","_","isNull","slice","logger","length","response","objects","total","time","Date","toUTCString","HTTP_STATUS","OK","json","error"],"sources":["../../src/v1/search.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport { HTTP_STATUS, searchUtils } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { Storage } from '@verdaccio/store';\nimport { Manifest } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:api:search');\n\n/**\n * Endpoint for npm search v1\n * Empty value\n * - {\"objects\":[],\"total\":0,\"time\":\"Sun Jul 25 2021 14:09:11 GMT+0000 (Coordinated Universal Time)\"}\n * req: 'GET /-/v1/search?text=react&size=20&frpom=0&quality=0.65&popularity=0.98&maintenance=0.5'\n */\nexport default function (route, auth: Auth, storage: Storage): void {\n function checkAccess(pkg: any, auth: any, remoteUser): Promise<Manifest | null> {\n return new Promise((resolve, reject) => {\n auth.allow_access({ packageName: pkg?.package?.name }, remoteUser, function (err, allowed) {\n if (err) {\n if (err.status && String(err.status).match(/^4\\d\\d$/)) {\n // auth plugin returns 4xx user error,\n // that's equivalent of !allowed basically\n allowed = false;\n return resolve(null);\n } else {\n reject(err);\n }\n } else {\n return resolve(allowed ? pkg : null);\n }\n });\n });\n }\n\n route.get('/-/v1/search', async (req, res, next) => {\n const { query, url } = req;\n let [size, from] = ['size', 'from'].map((k) => query[k]);\n let data;\n const abort = new AbortController();\n\n req.socket.on('close', function () {\n debug('search web aborted');\n abort.abort();\n });\n\n size = parseInt(size, 10) || 20;\n from = parseInt(from, 10) || 0;\n\n try {\n data = await storage.search({\n query,\n url,\n abort,\n });\n debug('stream finish');\n const checkAccessPromises: searchUtils.SearchItemPkg[] = await Promise.all(\n data.map((pkgItem) => {\n return checkAccess(pkgItem, auth, req.remote_user);\n })\n );\n\n const final: searchUtils.SearchItemPkg[] = checkAccessPromises\n .filter((i) => !_.isNull(i))\n .slice(from, size);\n logger.debug(`search results ${final?.length}`);\n\n const response: searchUtils.SearchResults = {\n objects: final,\n total: final.length,\n time: new Date().toUTCString(),\n };\n\n res.status(HTTP_STATUS.OK).json(response);\n } catch (error) {\n logger.error({ error }, 'search endpoint has failed @{error.message}');\n next(next);\n return;\n }\n });\n}\n"],"mappings":";;;;;;AAAA;AACA;AAGA;AACA;AAA2C;AAI3C,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,sBAAsB,CAAC;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACe,kBAAUC,KAAK,EAAEC,IAAU,EAAEC,OAAgB,EAAQ;EAClE,SAASC,WAAW,CAACC,GAAQ,EAAEH,IAAS,EAAEI,UAAU,EAA4B;IAC9E,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MAAA;MACtCP,IAAI,CAACQ,YAAY,CAAC;QAAEC,WAAW,EAAEN,GAAG,aAAHA,GAAG,uCAAHA,GAAG,CAAEO,OAAO,iDAAZ,aAAcC;MAAK,CAAC,EAAEP,UA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BAAgD,GAAG,MAAM7B,OAAO,CAAC8B,GAAG,CACxER,IAAI,CAACF,GAAG,CAAEW,OAAO,IAAK;QACpB,OAAOlC,WAAW,CAACkC,OAAO,EAAEpC,IAAI,EAAEkB,GAAG,CAACmB,WAAW,CAAC;MACpD,CAAC,CAAC,CACH;MAED,MAAMC,KAAkC,GAAGJ,mBAAmB,CAC3DK,MAAM,CAAEC,CAAC,IAAK,CAACC,eAAC,CAACC,MAAM,CAACF,CAAC,CAAC,CAAC,CAC3BG,KAAK,CAACnB,IAAI,EAAED,IAAI,CAAC;MACpBqB,cAAM,CAAC/C,KAAK,CAAE,kBAAiByC,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEO,MAAO,EAAC,CAAC;MAE/C,MAAMC,QAAmC,GAAG;QAC1CC,OAAO,EAAET,KAAK;QACdU,KAAK,EAAEV,KAAK,CAACO,MAAM;QACnBI,IAAI,EAAE,IAAIC,IAAI,EAAE,CAACC,WAAW;MAC9B,CAAC;MAEDhC,GAAG,CAACL,MAAM,CAACsC,iBAAW,CAACC,EAAE,CAAC,CAACC,IAAI,CAACR,QAAQ,CAAC;IAC3C,CAAC,CAAC,OAAOS,KAAK,EAAE;MACdX,cAAM,CAACW,KAAK,CAAC;QAAEA;MAAM,CAAC,EAAE,6CAA6C,CAAC;MACtEnC,IAAI,CAACA,IAAI,CAAC;MACV;IACF;EACF,CAAC,CAAC;AACJ"}
|
package/build/v1/token.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Router } from 'express';
|
|
|
2
2
|
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Storage } from '@verdaccio/store';
|
|
4
4
|
import { Config, Token } from '@verdaccio/types';
|
|
5
|
-
export
|
|
5
|
+
export type NormalizeToken = Token & {
|
|
6
6
|
created: string;
|
|
7
7
|
};
|
|
8
8
|
export default function (route: Router, auth: Auth, storage: Storage, config: Config): void;
|
package/build/v1/token.js
CHANGED
|
@@ -4,60 +4,48 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
-
|
|
10
8
|
var _auth = require("@verdaccio/auth");
|
|
11
|
-
|
|
12
9
|
var _core = require("@verdaccio/core");
|
|
13
|
-
|
|
14
10
|
var _logger = require("@verdaccio/logger");
|
|
15
|
-
|
|
16
11
|
var _utils = require("@verdaccio/utils");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
function normalizeToken(token) {
|
|
21
|
-
return {
|
|
14
|
+
return {
|
|
15
|
+
...token,
|
|
22
16
|
created: new Date(token.created).toISOString()
|
|
23
17
|
};
|
|
24
|
-
}
|
|
25
|
-
|
|
18
|
+
}
|
|
26
19
|
|
|
20
|
+
// https://github.com/npm/npm-profile/blob/latest/lib/index.js
|
|
27
21
|
function _default(route, auth, storage, config) {
|
|
28
22
|
route.get('/-/npm/v1/tokens', async function (req, res, next) {
|
|
29
23
|
const {
|
|
30
24
|
name
|
|
31
25
|
} = req.remote_user;
|
|
32
|
-
|
|
33
26
|
if (_lodash.default.isNil(name) === false) {
|
|
34
27
|
try {
|
|
35
28
|
const tokens = await storage.readTokens({
|
|
36
29
|
user: name
|
|
37
30
|
});
|
|
38
31
|
const totalTokens = tokens.length;
|
|
39
|
-
|
|
40
32
|
_logger.logger.debug({
|
|
41
33
|
totalTokens
|
|
42
34
|
}, 'token list retrieved: @{totalTokens}');
|
|
43
|
-
|
|
44
35
|
res.status(_core.HTTP_STATUS.OK);
|
|
45
36
|
return next({
|
|
46
37
|
objects: tokens.map(normalizeToken),
|
|
47
38
|
urls: {
|
|
48
39
|
next: '' // TODO: pagination?
|
|
49
|
-
|
|
50
40
|
}
|
|
51
41
|
});
|
|
52
42
|
} catch (error) {
|
|
53
43
|
_logger.logger.error({
|
|
54
44
|
error: error.msg
|
|
55
45
|
}, 'token list has failed: @{error}');
|
|
56
|
-
|
|
57
46
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.INTERNAL_ERROR, error.message));
|
|
58
47
|
}
|
|
59
48
|
}
|
|
60
|
-
|
|
61
49
|
return next(_core.errorUtils.getUnauthorized());
|
|
62
50
|
});
|
|
63
51
|
route.post('/-/npm/v1/tokens', function (req, res, next) {
|
|
@@ -69,40 +57,33 @@ function _default(route, auth, storage, config) {
|
|
|
69
57
|
const {
|
|
70
58
|
name
|
|
71
59
|
} = req.remote_user;
|
|
72
|
-
|
|
73
60
|
if (!_lodash.default.isBoolean(readonly) || !_lodash.default.isArray(cidr_whitelist)) {
|
|
74
61
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.BAD_DATA, _core.SUPPORT_ERRORS.PARAMETERS_NOT_VALID));
|
|
75
62
|
}
|
|
76
|
-
|
|
77
63
|
auth.authenticate(name, password, async (err, user) => {
|
|
78
64
|
if (err) {
|
|
79
65
|
const errorCode = err.message ? _core.HTTP_STATUS.UNAUTHORIZED : _core.HTTP_STATUS.INTERNAL_ERROR;
|
|
80
66
|
return next(_core.errorUtils.getCode(errorCode, err.message));
|
|
81
67
|
}
|
|
82
|
-
|
|
83
68
|
req.remote_user = user;
|
|
84
|
-
|
|
85
69
|
if (!_lodash.default.isFunction(storage.saveToken)) {
|
|
86
70
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.NOT_IMPLEMENTED, _core.SUPPORT_ERRORS.STORAGE_NOT_IMPLEMENT));
|
|
87
71
|
}
|
|
88
|
-
|
|
89
72
|
try {
|
|
90
73
|
const token = await (0, _auth.getApiToken)(auth, config, user, password);
|
|
91
|
-
|
|
92
74
|
if (!token) {
|
|
93
75
|
throw _core.errorUtils.getInternalError();
|
|
94
76
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
const key = (0, _utils.stringToMD5)(token);
|
|
78
|
+
// TODO: use a utility here
|
|
98
79
|
const maskedToken = (0, _utils.mask)(token, 5);
|
|
99
80
|
const created = new Date().getTime();
|
|
81
|
+
|
|
100
82
|
/**
|
|
101
83
|
* cidr_whitelist: is not being used, we pass it through
|
|
102
84
|
* token: we do not store the real token (it is generated once and retrieved
|
|
103
85
|
* to the user), just a mask of it.
|
|
104
86
|
*/
|
|
105
|
-
|
|
106
87
|
const saveToken = {
|
|
107
88
|
user: name,
|
|
108
89
|
token: maskedToken,
|
|
@@ -112,12 +93,11 @@ function _default(route, auth, storage, config) {
|
|
|
112
93
|
created
|
|
113
94
|
};
|
|
114
95
|
await storage.saveToken(saveToken);
|
|
115
|
-
|
|
116
96
|
_logger.logger.debug({
|
|
117
97
|
key,
|
|
118
98
|
name
|
|
119
99
|
}, 'token @{key} was created for user @{name}');
|
|
120
|
-
|
|
100
|
+
res.set(_core.HEADERS.CACHE_CONTROL, 'no-cache, no-store');
|
|
121
101
|
return next(normalizeToken({
|
|
122
102
|
token,
|
|
123
103
|
user: name,
|
|
@@ -130,7 +110,6 @@ function _default(route, auth, storage, config) {
|
|
|
130
110
|
_logger.logger.error({
|
|
131
111
|
error: error.msg
|
|
132
112
|
}, 'token creation has failed: @{error}');
|
|
133
|
-
|
|
134
113
|
return next(_core.errorUtils.getInternalError(error.message));
|
|
135
114
|
}
|
|
136
115
|
});
|
|
@@ -144,30 +123,24 @@ function _default(route, auth, storage, config) {
|
|
|
144
123
|
const {
|
|
145
124
|
name
|
|
146
125
|
} = req.remote_user;
|
|
147
|
-
|
|
148
126
|
if (_lodash.default.isNil(name) === false) {
|
|
149
127
|
_logger.logger.debug({
|
|
150
128
|
name
|
|
151
129
|
}, '@{name} has requested remove a token');
|
|
152
|
-
|
|
153
130
|
try {
|
|
154
131
|
await storage.deleteToken(name, tokenKey);
|
|
155
|
-
|
|
156
132
|
_logger.logger.info({
|
|
157
133
|
tokenKey,
|
|
158
134
|
name
|
|
159
135
|
}, 'token id @{tokenKey} was revoked for user @{name}');
|
|
160
|
-
|
|
161
136
|
return next({});
|
|
162
137
|
} catch (error) {
|
|
163
138
|
_logger.logger.error({
|
|
164
139
|
error: error.msg
|
|
165
140
|
}, 'token creation has failed: @{error}');
|
|
166
|
-
|
|
167
141
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.INTERNAL_ERROR, error.message));
|
|
168
142
|
}
|
|
169
143
|
}
|
|
170
|
-
|
|
171
144
|
return next(_core.errorUtils.getUnauthorized());
|
|
172
145
|
});
|
|
173
146
|
}
|