@verdaccio/api 8.1.0-next-8.12 → 8.1.0-next-8.14
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 +17 -10
- package/build/index.js +18 -4
- package/build/index.js.map +1 -1
- package/build/user.js +2 -2
- package/build/user.js.map +1 -1
- package/build/v1/profile.js +1 -1
- package/build/v1/profile.js.map +1 -1
- package/package.json +16 -12
- package/.babelrc +0 -3
- package/.eslintrc +0 -5
- package/CHANGELOG.md +0 -2152
- package/src/dist-tags.ts +0 -106
- package/src/index.ts +0 -65
- package/src/package.ts +0 -117
- package/src/ping.ts +0 -14
- package/src/publish.ts +0 -262
- package/src/search.ts +0 -12
- package/src/stars.ts +0 -37
- package/src/user.ts +0 -179
- package/src/v1/profile.ts +0 -113
- package/src/v1/search.ts +0 -85
- package/src/v1/token.ts +0 -157
- package/src/whoami.ts +0 -26
- package/test/.eslintrc +0 -8
- package/test/integration/_helper.ts +0 -198
- package/test/integration/config/distTag.yaml +0 -25
- package/test/integration/config/owner.yaml +0 -24
- package/test/integration/config/package.yaml +0 -25
- package/test/integration/config/ping.yaml +0 -26
- package/test/integration/config/profile.yaml +0 -27
- package/test/integration/config/publish-proxy.yaml +0 -26
- package/test/integration/config/publish.yaml +0 -24
- package/test/integration/config/search.yaml +0 -29
- package/test/integration/config/star.yaml +0 -26
- package/test/integration/config/token.jwt.yaml +0 -27
- package/test/integration/config/token.yaml +0 -19
- package/test/integration/config/user.jwt.yaml +0 -37
- package/test/integration/config/user.yaml +0 -30
- package/test/integration/config/whoami.yaml +0 -29
- package/test/integration/distTag.spec.ts +0 -80
- package/test/integration/owner.spec.ts +0 -119
- package/test/integration/package.spec.ts +0 -107
- package/test/integration/ping.spec.ts +0 -18
- package/test/integration/profile.spec.ts +0 -112
- package/test/integration/publish.spec.ts +0 -232
- package/test/integration/search.spec.ts +0 -139
- package/test/integration/star.spec.ts +0 -74
- package/test/integration/token.spec.ts +0 -125
- package/test/integration/user.spec.ts +0 -222
- package/test/integration/whoami.spec.ts +0 -36
- package/test/unit/publish.disabled.ts +0 -252
- package/test/unit/validate.api.params.middleware.spec.ts +0 -44
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -41
- package/types/custom.d.ts +0 -16
package/README.md
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
# @verdaccio/api
|
|
1
|
+
# @verdaccio/api - Verdaccio Registry API
|
|
2
2
|
|
|
3
|
-
[](https://www.tickgit.com/browse?repo=github.com/verdaccio/verdaccio)
|
|
3
|
+
[](https://verdaccio.org)
|
|
4
|
+
[](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)
|
|
5
|
+
[](https://github.com/verdaccio/verdaccio)
|
|
6
|
+
[](https://npmjs.com/package/@verdaccio/api)
|
|
8
7
|
|
|
9
|
-
[](https://verdaccio.org/docs)
|
|
9
|
+
[](https://discord.com/channels/388674437219745793)
|
|
10
|
+
[](https://bsky.app/profile/verdaccio.org)
|
|
11
|
+
[](https://opencollective.com/verdaccio/contribute)
|
|
12
|
+
[](https://opencollective.com/verdaccio/contribute)
|
|
13
|
+
|
|
14
|
+
[](https://www.npmjs.com/package/verdaccio)
|
|
15
|
+
[](https://hub.docker.com/r/verdaccio/verdaccio)
|
|
16
|
+
[](https://github.com/verdaccio/verdaccio/stargazers)
|
|
10
17
|
|
|
11
18
|
## Donations
|
|
12
19
|
|
|
@@ -20,7 +27,7 @@ If you want to report a security vulnerability, please follow the steps which we
|
|
|
20
27
|
|
|
21
28
|
## Open Collective Sponsors
|
|
22
29
|
|
|
23
|
-
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/verdaccio
|
|
30
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/verdaccio/contribute)]
|
|
24
31
|
|
|
25
32
|
[](https://opencollective.com/verdaccio/sponsor/0/website)
|
|
26
33
|
[](https://opencollective.com/verdaccio/sponsor/1/website)
|
|
@@ -35,9 +42,9 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
35
42
|
|
|
36
43
|
## Open Collective Backers
|
|
37
44
|
|
|
38
|
-
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/verdaccio
|
|
45
|
+
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/verdaccio/contribute)]
|
|
39
46
|
|
|
40
|
-
[](https://opencollective.com/verdaccio
|
|
47
|
+
[](https://opencollective.com/verdaccio/contributes)
|
|
41
48
|
|
|
42
49
|
## Special Thanks
|
|
43
50
|
|
package/build/index.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
7
8
|
var _express = _interopRequireDefault(require("express"));
|
|
8
9
|
var _middleware = require("@verdaccio/middleware");
|
|
9
10
|
var _distTags = _interopRequireDefault(require("./dist-tags"));
|
|
@@ -18,6 +19,7 @@ var _search2 = _interopRequireDefault(require("./v1/search"));
|
|
|
18
19
|
var _token = _interopRequireDefault(require("./v1/token"));
|
|
19
20
|
var _whoami = _interopRequireDefault(require("./whoami"));
|
|
20
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
+
const debug = (0, _debug.default)('verdaccio:api');
|
|
21
23
|
function _default(config, auth, storage, logger) {
|
|
22
24
|
/* eslint new-cap:off */
|
|
23
25
|
const app = _express.default.Router();
|
|
@@ -37,10 +39,16 @@ function _default(config, auth, storage, logger) {
|
|
|
37
39
|
app.param('_rev', (0, _middleware.match)(/^-rev$/));
|
|
38
40
|
app.param('org_couchdb_user', (0, _middleware.match)(/^org\.couchdb\.user:/));
|
|
39
41
|
app.use(auth.apiJWTmiddleware());
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
|
|
43
|
+
// middleware might have registered a json parser already
|
|
44
|
+
if (hasBodyParser(app)) {
|
|
45
|
+
debug('json parser already registered');
|
|
46
|
+
} else {
|
|
47
|
+
app.use(_express.default.json({
|
|
48
|
+
strict: false,
|
|
49
|
+
limit: config.max_body_size || '10mb'
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
44
52
|
app.use((0, _middleware.antiLoop)(config));
|
|
45
53
|
app.use(_middleware.makeURLrelative);
|
|
46
54
|
// encode / in a scoped package name to be matched as a single parameter in routes
|
|
@@ -59,4 +67,10 @@ function _default(config, auth, storage, logger) {
|
|
|
59
67
|
(0, _package.default)(app, auth, storage, logger);
|
|
60
68
|
return app;
|
|
61
69
|
}
|
|
70
|
+
function hasBodyParser(app) {
|
|
71
|
+
const stack = app.stack || [];
|
|
72
|
+
return stack.some(middleware => {
|
|
73
|
+
return middleware.handle?.name === 'jsonParser' || middleware.name === 'jsonParser';
|
|
74
|
+
});
|
|
75
|
+
}
|
|
62
76
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_express","_middleware","_distTags","_package","_ping","_publish","_search","_stars","_user","_profile","_search2","_token","_whoami","e","__esModule","default","debug","buildDebug","_default","config","auth","storage","logger","app","express","Router","param","validatePackage","validateName","match","use","apiJWTmiddleware","hasBodyParser","json","strict","limit","max_body_size","antiLoop","makeURLrelative","encodeScopePackage","whoami","profile","search","user","distTags","publish","ping","stars","v1Search","token","pkg","stack","some","middleware","handle","name"],"sources":["../src/index.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport express, { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n antiLoop,\n encodeScopePackage,\n makeURLrelative,\n match,\n validateName,\n validatePackage,\n} from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { Config, Logger } from '@verdaccio/types';\n\nimport distTags from './dist-tags';\nimport pkg from './package';\nimport ping from './ping';\nimport publish from './publish';\nimport search from './search';\nimport stars from './stars';\nimport user from './user';\nimport profile from './v1/profile';\nimport v1Search from './v1/search';\nimport token from './v1/token';\nimport whoami from './whoami';\n\nconst debug = buildDebug('verdaccio:api');\n\nexport default function (config: Config, auth: Auth, storage: Storage, logger: Logger): Router {\n /* eslint new-cap:off */\n const app = express.Router();\n /* eslint new-cap:off */\n\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble\n app.param('package', validatePackage);\n app.param('filename', validateName);\n app.param('tag', validateName);\n app.param('version', validateName);\n app.param('revision', validateName);\n app.param('token', validateName);\n\n // Express route parameter names must be valid JavaScript identifiers, which means\n // they cannot start with a hyphen (-) or contain special characters like dots (.)\n app.param('_rev', match(/^-rev$/));\n app.param('org_couchdb_user', match(/^org\\.couchdb\\.user:/));\n\n app.use(auth.apiJWTmiddleware());\n\n // middleware might have registered a json parser already\n if (hasBodyParser(app)) {\n debug('json parser already registered');\n } else {\n app.use(express.json({ strict: false, limit: config.max_body_size || '10mb' }));\n }\n\n app.use(antiLoop(config));\n app.use(makeURLrelative);\n // encode / in a scoped package name to be matched as a single parameter in routes\n app.use(encodeScopePackage);\n // for \"npm whoami\"\n whoami(app);\n profile(app, auth, config);\n search(app, logger);\n user(app, auth, config, logger);\n distTags(app, auth, storage, logger);\n publish(app, auth, storage, logger);\n ping(app);\n stars(app, storage);\n v1Search(app, auth, storage, logger);\n token(app, auth, storage, config, logger);\n pkg(app, auth, storage, logger);\n return app;\n}\n\nfunction hasBodyParser(app: Router): boolean {\n const stack = app.stack || [];\n return stack.some((middleware) => {\n return middleware.handle?.name === 'jsonParser' || middleware.name === 'jsonParser';\n });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AAGA,IAAAE,WAAA,GAAAF,OAAA;AAWA,IAAAG,SAAA,GAAAJ,sBA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AO,EAAEF,MAAM,EAAEG,MAAM,CAAC;EACzC,IAAA4B,gBAAG,EAAC3B,GAAG,EAAEH,IAAI,EAAEC,OAAO,EAAEC,MAAM,CAAC;EAC/B,OAAOC,GAAG;AACZ;AAEA,SAASS,aAAaA,CAACT,GAAW,EAAW;EAC3C,MAAM4B,KAAK,GAAG5B,GAAG,CAAC4B,KAAK,IAAI,EAAE;EAC7B,OAAOA,KAAK,CAACC,IAAI,CAAEC,UAAU,IAAK;IAChC,OAAOA,UAAU,CAACC,MAAM,EAAEC,IAAI,KAAK,YAAY,IAAIF,UAAU,CAACE,IAAI,KAAK,YAAY;EACrF,CAAC,CAAC;AACJ","ignoreList":[]}
|
package/build/user.js
CHANGED
|
@@ -59,7 +59,7 @@ function _default(route, auth, config, logger) {
|
|
|
59
59
|
} = req.body;
|
|
60
60
|
debug('login or adduser');
|
|
61
61
|
const remoteName = req?.remote_user?.name;
|
|
62
|
-
if (!_core.
|
|
62
|
+
if (!_core.validationUtils.validateUserName(req.params.org_couchdb_user, name)) {
|
|
63
63
|
return next(_core.errorUtils.getBadRequest(_core.API_ERROR.USERNAME_MISMATCH));
|
|
64
64
|
}
|
|
65
65
|
if (typeof remoteName !== 'undefined' && typeof name === 'string' && remoteName === name) {
|
|
@@ -89,7 +89,7 @@ function _default(route, auth, config, logger) {
|
|
|
89
89
|
});
|
|
90
90
|
} else {
|
|
91
91
|
debug('adduser: %o', name);
|
|
92
|
-
if (_core.
|
|
92
|
+
if (_core.validationUtils.validatePassword(password, config?.serverSettings?.passwordValidationRegex) === false) {
|
|
93
93
|
debug('adduser: invalid password');
|
|
94
94
|
// eslint-disable-next-line new-cap
|
|
95
95
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.BAD_REQUEST, _core.API_ERROR.PASSWORD_SHORT));
|
package/build/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","names":["_debug","_interopRequireDefault","require","_auth","_config","_core","_middleware","_utils","e","__esModule","default","debug","buildDebug","_default","route","auth","config","logger","get","USER_API_ENDPOINTS","get_user","rateLimit","userRateLimit","req","res","next","remote_user","name","status","HTTP_STATUS","OK","ok","username","params","org_couchdb_user","split","message","getAuthenticatedMessage","email","put","add_user","password","body","remoteName","validatioUtils","validateUserName","errorUtils","getBadRequest","API_ERROR","USERNAME_MISMATCH","authenticate","callbackAuthenticate","err","user","trace","getCode","UNAUTHORIZED","BAD_USERNAME_PASSWORD","restoredRemoteUser","createRemoteUser","groups","token","getApiToken","getUnauthorized","CREATED","set","HEADERS","CACHE_CONTROL","validatePassword","serverSettings","passwordValidationRegex","BAD_REQUEST","PASSWORD_SHORT","INTERNAL_ERROR","getConflict","undefined","mask","delete","user_token","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 { USER_API_ENDPOINTS, rateLimit } from '@verdaccio/middleware';\nimport { Logger } from '@verdaccio/types';\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, logger: Logger): void {\n route.get(\n USER_API_ENDPOINTS.get_user,\n rateLimit(config?.userRateLimit),\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n debug('verifying user');\n\n if (\n !req.remote_user ||\n typeof req.remote_user.name !== 'string' ||\n req.remote_user.name === ''\n ) {\n debug('user not logged in');\n res.status(HTTP_STATUS.OK);\n return next({ ok: false });\n }\n\n const username = req.params.org_couchdb_user.split(':')[1];\n const message = getAuthenticatedMessage(req.remote_user.name);\n debug('user authenticated message %o', message);\n res.status(HTTP_STATUS.OK);\n next({\n // 'npm owner' requires user info\n // TODO: we don't have the email\n name: username,\n email: '',\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_API_ENDPOINTS.add_user,\n rateLimit(config?.userRateLimit),\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 (!validatioUtils.validateUserName(req.params.org_couchdb_user, name)) {\n return next(errorUtils.getBadRequest(API_ERROR.USERNAME_MISMATCH));\n }\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 debug('adduser: %o', name);\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_API_ENDPOINTS.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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAQA,IAAAI,WAAA,GAAAJ,OAAA;AAGA,IAAAK,MAAA,GAAAL,OAAA;AAAiE,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIjE,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,oBAAoB,CAAC;AAE/B,SAAAC,SAAUC,KAAa,EAAEC,IAAU,EAAEC,MAAc,EAAEC,MAAc,EAAQ;EACxFH,KAAK,CAACI,GAA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,IAAI,EAAgBZ,QAAQ,CAAC,GAC7DkC,SAAS;QACf,IAAId,KAAK,EAAE;UACTlD,KAAK,CAAC,uBAAuB,EAAE,IAAAiE,WAAI,EAACf,KAAK,EAAY,CAAC,CAAC,CAAC;QAC1D;QACA,IAAI,CAACA,KAAK,EAAE;UACV,OAAOpC,IAAI,CAACqB,gBAAU,CAACiB,eAAe,CAAC,CAAC,CAAC;QAC3C;QAEAxC,GAAG,CAACG,WAAW,GAAG2B,IAAI;QACtB7B,GAAG,CAACI,MAAM,CAACC,iBAAW,CAACmC,OAAO,CAAC;QAC/BxC,GAAG,CAACyC,GAAG,CAACC,aAAO,CAACC,aAAa,EAAE,oBAAoB,CAAC;QACpDxD,KAAK,CAAC,gCAAgC,CAAC;QACvC,OAAOc,IAAI,CAAC;UACVM,EAAE,EAAE,SAASR,GAAG,CAACmB,IAAI,CAACf,IAAI,WAAW;UACrCkC;QACF,CAAC,CAAC;MACJ,CAAC,CAAC;IACJ;EACF,CACF,CAAC;EAED/C,KAAK,CAAC+D,MAAM,CACV1D,8BAAkB,CAAC2D,UAAU,EAC7B,UAAUvD,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,EAAQ;IAC1ED,GAAG,CAACI,MAAM,CAACC,iBAAW,CAACC,EAAE,CAAC;IAC1BL,IAAI,CAAC;MACHM,EAAE,EAAEgD,iBAAW,CAACC;IAClB,CAAC,CAAC;EACJ,CACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"user.js","names":["_debug","_interopRequireDefault","require","_auth","_config","_core","_middleware","_utils","e","__esModule","default","debug","buildDebug","_default","route","auth","config","logger","get","USER_API_ENDPOINTS","get_user","rateLimit","userRateLimit","req","res","next","remote_user","name","status","HTTP_STATUS","OK","ok","username","params","org_couchdb_user","split","message","getAuthenticatedMessage","email","put","add_user","password","body","remoteName","validationUtils","validateUserName","errorUtils","getBadRequest","API_ERROR","USERNAME_MISMATCH","authenticate","callbackAuthenticate","err","user","trace","getCode","UNAUTHORIZED","BAD_USERNAME_PASSWORD","restoredRemoteUser","createRemoteUser","groups","token","getApiToken","getUnauthorized","CREATED","set","HEADERS","CACHE_CONTROL","validatePassword","serverSettings","passwordValidationRegex","BAD_REQUEST","PASSWORD_SHORT","INTERNAL_ERROR","getConflict","undefined","mask","delete","user_token","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 validationUtils,\n} from '@verdaccio/core';\nimport { USER_API_ENDPOINTS, rateLimit } from '@verdaccio/middleware';\nimport { Logger } from '@verdaccio/types';\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, logger: Logger): void {\n route.get(\n USER_API_ENDPOINTS.get_user,\n rateLimit(config?.userRateLimit),\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n debug('verifying user');\n\n if (\n !req.remote_user ||\n typeof req.remote_user.name !== 'string' ||\n req.remote_user.name === ''\n ) {\n debug('user not logged in');\n res.status(HTTP_STATUS.OK);\n return next({ ok: false });\n }\n\n const username = req.params.org_couchdb_user.split(':')[1];\n const message = getAuthenticatedMessage(req.remote_user.name);\n debug('user authenticated message %o', message);\n res.status(HTTP_STATUS.OK);\n next({\n // 'npm owner' requires user info\n // TODO: we don't have the email\n name: username,\n email: '',\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_API_ENDPOINTS.add_user,\n rateLimit(config?.userRateLimit),\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 (!validationUtils.validateUserName(req.params.org_couchdb_user, name)) {\n return next(errorUtils.getBadRequest(API_ERROR.USERNAME_MISMATCH));\n }\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 debug('adduser: %o', name);\n if (\n validationUtils.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_API_ENDPOINTS.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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAQA,IAAAI,WAAA,GAAAJ,OAAA;AAGA,IAAAK,MAAA,GAAAL,OAAA;AAAiE,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIjE,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,oBAAoB,CAAC;AAE/B,SAAAC,SAAUC,KAAa,EAAEC,IAAU,EAAEC,MAAc,EAAEC,MAAc,EAAQ;EACxFH,KAAK,CAACI,GAAG,CACPC,8BAAkB,CAACC,QAAQ,EAC3B,IAAAC,qBAAS,EAACL,MAAM,EAAEM,aAAa,CAAC,EAChC,UAAUC,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,EAAQ;IAC1Ed,KAAK,CAAC,gBAAgB,CAAC;IAEvB,IACE,CAACY,GAAG,CAACG,WAAW,IAChB,OAAOH,GAAG,CAACG,WAAW,CAACC,IAAI,KAA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3C;QAEAxC,GAAG,CAACG,WAAW,GAAG2B,IAAI;QACtB7B,GAAG,CAACI,MAAM,CAACC,iBAAW,CAACmC,OAAO,CAAC;QAC/BxC,GAAG,CAACyC,GAAG,CAACC,aAAO,CAACC,aAAa,EAAE,oBAAoB,CAAC;QACpDxD,KAAK,CAAC,gCAAgC,CAAC;QACvC,OAAOc,IAAI,CAAC;UACVM,EAAE,EAAE,SAASR,GAAG,CAACmB,IAAI,CAACf,IAAI,WAAW;UACrCkC;QACF,CAAC,CAAC;MACJ,CAAC,CAAC;IACJ;EACF,CACF,CAAC;EAED/C,KAAK,CAAC+D,MAAM,CACV1D,8BAAkB,CAAC2D,UAAU,EAC7B,UAAUvD,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,EAAQ;IAC1ED,GAAG,CAACI,MAAM,CAACC,iBAAW,CAACC,EAAE,CAAC;IAC1BL,IAAI,CAAC;MACHM,EAAE,EAAEgD,iBAAW,CAACC;IAClB,CAAC,CAAC;EACJ,CACF,CAAC;AACH","ignoreList":[]}
|
package/build/v1/profile.js
CHANGED
|
@@ -45,7 +45,7 @@ function _default(route, auth, config) {
|
|
|
45
45
|
name
|
|
46
46
|
} = req.remote_user;
|
|
47
47
|
if (_lodash.default.isNil(password) === false) {
|
|
48
|
-
if (_core.
|
|
48
|
+
if (_core.validationUtils.validatePassword(password.new, config?.serverSettings?.passwordValidationRegex) === false) {
|
|
49
49
|
/* eslint new-cap:off */
|
|
50
50
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNAUTHORIZED, _core.API_ERROR.PASSWORD_SHORT));
|
|
51
51
|
/* eslint new-cap:off */
|
package/build/v1/profile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","names":["_lodash","_interopRequireDefault","require","_core","_middleware","e","__esModule","default","_default","route","auth","config","buildProfile","name","tfa","email","email_verified","created","updated","cidr_whitelist","fullname","get","PROFILE_API_ENDPOINTS","get_profile","rateLimit","userRateLimit","req","res","next","_","isNil","remote_user","status","HTTP_STATUS","UNAUTHORIZED","message","API_ERROR","MUST_BE_LOGGED","post","password","body","
|
|
1
|
+
{"version":3,"file":"profile.js","names":["_lodash","_interopRequireDefault","require","_core","_middleware","e","__esModule","default","_default","route","auth","config","buildProfile","name","tfa","email","email_verified","created","updated","cidr_whitelist","fullname","get","PROFILE_API_ENDPOINTS","get_profile","rateLimit","userRateLimit","req","res","next","_","isNil","remote_user","status","HTTP_STATUS","UNAUTHORIZED","message","API_ERROR","MUST_BE_LOGGED","post","password","body","validationUtils","validatePassword","new","serverSettings","passwordValidationRegex","errorUtils","getCode","PASSWORD_SHORT","isEmpty","old","getBadRequest","changePassword","err","isUpdated","isNull","getForbidden","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 validationUtils,\n} from '@verdaccio/core';\nimport { PROFILE_API_ENDPOINTS } from '@verdaccio/middleware';\nimport { rateLimit } from '@verdaccio/middleware';\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 PROFILE_API_ENDPOINTS.get_profile,\n rateLimit(config?.userRateLimit),\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 PROFILE_API_ENDPOINTS.get_profile,\n rateLimit(config?.userRateLimit),\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 validationUtils.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 if (_.isEmpty(password.old)) {\n return next(errorUtils.getBadRequest('old password is required'));\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(errorUtils.getForbidden(err.message));\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,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAQA,IAAAE,WAAA,GAAAF,OAAA;AAA8D,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA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,CAAC0B,mBAAmB,EAAEC,oBAAc,CAACC,YAAY,CACjF,CAAC;IACH,CAAC,MAAM;MACL,OAAOjC,IAAI,CAACkB,gBAAU,CAACC,OAAO,CAACd,iBAAW,CAAC6B,cAAc,EAAEC,eAAS,CAACC,aAAa,CAAC,CAAC;IACtF;EACF,CACF,CAAC;AACH","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/api",
|
|
3
|
-
"version": "8.1.0-next-8.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "8.1.0-next-8.14",
|
|
4
|
+
"description": "Verdaccio Registry API",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"author": {
|
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "https",
|
|
13
|
-
"url": "https://github.com/verdaccio/verdaccio"
|
|
13
|
+
"url": "https://github.com/verdaccio/verdaccio",
|
|
14
|
+
"directory": "packages/api"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/verdaccio/verdaccio/issues"
|
|
14
18
|
},
|
|
15
19
|
"homepage": "https://verdaccio.org",
|
|
16
20
|
"keywords": [
|
|
@@ -29,13 +33,13 @@
|
|
|
29
33
|
},
|
|
30
34
|
"license": "MIT",
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@verdaccio/auth": "8.0.0-next-8.
|
|
33
|
-
"@verdaccio/config": "8.0.0-next-8.
|
|
34
|
-
"@verdaccio/core": "8.0.0-next-8.
|
|
35
|
-
"@verdaccio/logger": "8.0.0-next-8.
|
|
36
|
-
"@verdaccio/middleware": "8.0.0-next-8.
|
|
37
|
-
"@verdaccio/store": "8.0.0-next-8.
|
|
38
|
-
"@verdaccio/utils": "8.1.0-next-8.
|
|
36
|
+
"@verdaccio/auth": "8.0.0-next-8.14",
|
|
37
|
+
"@verdaccio/config": "8.0.0-next-8.14",
|
|
38
|
+
"@verdaccio/core": "8.0.0-next-8.14",
|
|
39
|
+
"@verdaccio/logger": "8.0.0-next-8.14",
|
|
40
|
+
"@verdaccio/middleware": "8.0.0-next-8.14",
|
|
41
|
+
"@verdaccio/store": "8.0.0-next-8.14",
|
|
42
|
+
"@verdaccio/utils": "8.1.0-next-8.14",
|
|
39
43
|
"abortcontroller-polyfill": "1.7.8",
|
|
40
44
|
"body-parser": "1.20.3",
|
|
41
45
|
"cookies": "0.9.1",
|
|
@@ -46,8 +50,8 @@
|
|
|
46
50
|
"semver": "7.7.1"
|
|
47
51
|
},
|
|
48
52
|
"devDependencies": {
|
|
49
|
-
"@verdaccio/test-helper": "4.0.0-next-8.
|
|
50
|
-
"@verdaccio/types": "13.0.0-next-8.
|
|
53
|
+
"@verdaccio/test-helper": "4.0.0-next-8.4",
|
|
54
|
+
"@verdaccio/types": "13.0.0-next-8.5",
|
|
51
55
|
"mockdate": "3.0.5",
|
|
52
56
|
"supertest": "7.0.0"
|
|
53
57
|
},
|
package/.babelrc
DELETED