@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/v1/token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","names":["normalizeToken","token","created","Date","toISOString","route","auth","storage","config","get","req","res","next","name","remote_user","_","isNil","tokens","readTokens","user","totalTokens","length","logger","debug","status","HTTP_STATUS","OK","objects","map","urls","error","msg","errorUtils","getCode","INTERNAL_ERROR","message","getUnauthorized","post","password","readonly","cidr_whitelist","body","isBoolean","isArray","BAD_DATA","SUPPORT_ERRORS","PARAMETERS_NOT_VALID","authenticate","err","errorCode","UNAUTHORIZED","isFunction","saveToken","NOT_IMPLEMENTED","STORAGE_NOT_IMPLEMENT","getApiToken","getInternalError","key","stringToMD5","maskedToken","mask","getTime","cidr","delete","params","tokenKey","deleteToken","info"],"sources":["../../src/v1/token.ts"],"sourcesContent":["import { Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport { getApiToken } from '@verdaccio/auth';\nimport { Auth } from '@verdaccio/auth';\nimport { HTTP_STATUS, SUPPORT_ERRORS, errorUtils } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { Storage } from '@verdaccio/store';\nimport { Config, RemoteUser, Token } from '@verdaccio/types';\nimport { mask, stringToMD5 } from '@verdaccio/utils';\n\nimport { $NextFunctionVer, $RequestExtend } from '../../types/custom';\n\nexport type NormalizeToken = Token & {\n created: string;\n};\n\nfunction normalizeToken(token: Token): NormalizeToken {\n return {\n ...token,\n created: new Date(token.created).toISOString(),\n };\n}\n\n// https://github.com/npm/npm-profile/blob/latest/lib/index.js\nexport default function (route: Router, auth: Auth, storage: Storage, config: Config): void {\n route.get(\n '/-/npm/v1/tokens',\n async function (req: $RequestExtend, res: Response, next: $NextFunctionVer) {\n const { name } = req.remote_user;\n\n if (_.isNil(name) === false) {\n try {\n const tokens = await storage.readTokens({ user: name });\n const totalTokens = tokens.length;\n logger.debug({ totalTokens }, 'token list retrieved: @{totalTokens}');\n\n res.status(HTTP_STATUS.OK);\n return next({\n objects: tokens.map(normalizeToken),\n urls: {\n next: '', // TODO: pagination?\n },\n });\n } catch (error: any) {\n logger.error({ error: error.msg }, 'token list has failed: @{error}');\n return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));\n }\n }\n return next(errorUtils.getUnauthorized());\n }\n );\n\n route.post(\n '/-/npm/v1/tokens',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer) {\n const { password, readonly, cidr_whitelist } = req.body;\n const { name } = req.remote_user;\n\n if (!_.isBoolean(readonly) || !_.isArray(cidr_whitelist)) {\n return next(errorUtils.getCode(HTTP_STATUS.BAD_DATA, SUPPORT_ERRORS.PARAMETERS_NOT_VALID));\n }\n\n auth.authenticate(name, password, async (err, user?: RemoteUser) => {\n if (err) {\n const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;\n return next(errorUtils.getCode(errorCode, err.message));\n }\n\n req.remote_user = user;\n\n if (!_.isFunction(storage.saveToken)) {\n return next(\n errorUtils.getCode(HTTP_STATUS.NOT_IMPLEMENTED, SUPPORT_ERRORS.STORAGE_NOT_IMPLEMENT)\n );\n }\n\n try {\n const token = await getApiToken(auth, config, user as RemoteUser, password);\n if (!token) {\n throw errorUtils.getInternalError();\n }\n\n const key = stringToMD5(token);\n // TODO: use a utility here\n const maskedToken = mask(token, 5);\n const created = new Date().getTime();\n\n /**\n * cidr_whitelist: is not being used, we pass it through\n * token: we do not store the real token (it is generated once and retrieved\n * to the user), just a mask of it.\n */\n const saveToken: Token = {\n user: name,\n token: maskedToken,\n key,\n cidr: cidr_whitelist,\n readonly,\n created,\n };\n\n await storage.saveToken(saveToken);\n logger.debug({ key, name }, 'token @{key} was created for user @{name}');\n return next(\n normalizeToken({\n token,\n user: name,\n key: saveToken.key,\n cidr: cidr_whitelist,\n readonly,\n created: saveToken.created,\n })\n );\n } catch (error: any) {\n logger.error({ error: error.msg }, 'token creation has failed: @{error}');\n return next(errorUtils.getInternalError(error.message));\n }\n });\n }\n );\n\n route.delete(\n '/-/npm/v1/tokens/token/:tokenKey',\n async (req: $RequestExtend, res: Response, next: $NextFunctionVer) => {\n const {\n params: { tokenKey },\n } = req;\n const { name } = req.remote_user;\n\n if (_.isNil(name) === false) {\n logger.debug({ name }, '@{name} has requested remove a token');\n try {\n await storage.deleteToken(name, tokenKey);\n logger.info({ tokenKey, name }, 'token id @{tokenKey} was revoked for user @{name}');\n return next({});\n } catch (error: any) {\n logger.error({ error: error.msg }, 'token creation has failed: @{error}');\n return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));\n }\n }\n return next(errorUtils.getUnauthorized());\n }\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"token.js","names":["normalizeToken","token","created","Date","toISOString","route","auth","storage","config","get","req","res","next","name","remote_user","_","isNil","tokens","readTokens","user","totalTokens","length","logger","debug","status","HTTP_STATUS","OK","objects","map","urls","error","msg","errorUtils","getCode","INTERNAL_ERROR","message","getUnauthorized","post","password","readonly","cidr_whitelist","body","isBoolean","isArray","BAD_DATA","SUPPORT_ERRORS","PARAMETERS_NOT_VALID","authenticate","err","errorCode","UNAUTHORIZED","isFunction","saveToken","NOT_IMPLEMENTED","STORAGE_NOT_IMPLEMENT","getApiToken","getInternalError","key","stringToMD5","maskedToken","mask","getTime","cidr","set","HEADERS","CACHE_CONTROL","delete","params","tokenKey","deleteToken","info"],"sources":["../../src/v1/token.ts"],"sourcesContent":["import { Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport { getApiToken } from '@verdaccio/auth';\nimport { Auth } from '@verdaccio/auth';\nimport { HEADERS, HTTP_STATUS, SUPPORT_ERRORS, errorUtils } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { Storage } from '@verdaccio/store';\nimport { Config, RemoteUser, Token } from '@verdaccio/types';\nimport { mask, stringToMD5 } from '@verdaccio/utils';\n\nimport { $NextFunctionVer, $RequestExtend } from '../../types/custom';\n\nexport type NormalizeToken = Token & {\n created: string;\n};\n\nfunction normalizeToken(token: Token): NormalizeToken {\n return {\n ...token,\n created: new Date(token.created).toISOString(),\n };\n}\n\n// https://github.com/npm/npm-profile/blob/latest/lib/index.js\nexport default function (route: Router, auth: Auth, storage: Storage, config: Config): void {\n route.get(\n '/-/npm/v1/tokens',\n async function (req: $RequestExtend, res: Response, next: $NextFunctionVer) {\n const { name } = req.remote_user;\n\n if (_.isNil(name) === false) {\n try {\n const tokens = await storage.readTokens({ user: name });\n const totalTokens = tokens.length;\n logger.debug({ totalTokens }, 'token list retrieved: @{totalTokens}');\n\n res.status(HTTP_STATUS.OK);\n return next({\n objects: tokens.map(normalizeToken),\n urls: {\n next: '', // TODO: pagination?\n },\n });\n } catch (error: any) {\n logger.error({ error: error.msg }, 'token list has failed: @{error}');\n return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));\n }\n }\n return next(errorUtils.getUnauthorized());\n }\n );\n\n route.post(\n '/-/npm/v1/tokens',\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer) {\n const { password, readonly, cidr_whitelist } = req.body;\n const { name } = req.remote_user;\n\n if (!_.isBoolean(readonly) || !_.isArray(cidr_whitelist)) {\n return next(errorUtils.getCode(HTTP_STATUS.BAD_DATA, SUPPORT_ERRORS.PARAMETERS_NOT_VALID));\n }\n\n auth.authenticate(name, password, async (err, user?: RemoteUser) => {\n if (err) {\n const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;\n return next(errorUtils.getCode(errorCode, err.message));\n }\n\n req.remote_user = user;\n\n if (!_.isFunction(storage.saveToken)) {\n return next(\n errorUtils.getCode(HTTP_STATUS.NOT_IMPLEMENTED, SUPPORT_ERRORS.STORAGE_NOT_IMPLEMENT)\n );\n }\n\n try {\n const token = await getApiToken(auth, config, user as RemoteUser, password);\n if (!token) {\n throw errorUtils.getInternalError();\n }\n\n const key = stringToMD5(token);\n // TODO: use a utility here\n const maskedToken = mask(token, 5);\n const created = new Date().getTime();\n\n /**\n * cidr_whitelist: is not being used, we pass it through\n * token: we do not store the real token (it is generated once and retrieved\n * to the user), just a mask of it.\n */\n const saveToken: Token = {\n user: name,\n token: maskedToken,\n key,\n cidr: cidr_whitelist,\n readonly,\n created,\n };\n\n await storage.saveToken(saveToken);\n logger.debug({ key, name }, 'token @{key} was created for user @{name}');\n res.set(HEADERS.CACHE_CONTROL, 'no-cache, no-store');\n return next(\n normalizeToken({\n token,\n user: name,\n key: saveToken.key,\n cidr: cidr_whitelist,\n readonly,\n created: saveToken.created,\n })\n );\n } catch (error: any) {\n logger.error({ error: error.msg }, 'token creation has failed: @{error}');\n return next(errorUtils.getInternalError(error.message));\n }\n });\n }\n );\n\n route.delete(\n '/-/npm/v1/tokens/token/:tokenKey',\n async (req: $RequestExtend, res: Response, next: $NextFunctionVer) => {\n const {\n params: { tokenKey },\n } = req;\n const { name } = req.remote_user;\n\n if (_.isNil(name) === false) {\n logger.debug({ name }, '@{name} has requested remove a token');\n try {\n await storage.deleteToken(name, tokenKey);\n logger.info({ tokenKey, name }, 'token id @{tokenKey} was revoked for user @{name}');\n return next({});\n } catch (error: any) {\n logger.error({ error: error.msg }, 'token creation has failed: @{error}');\n return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));\n }\n }\n return next(errorUtils.getUnauthorized());\n }\n );\n}\n"],"mappings":";;;;;;AACA;AAEA;AAEA;AACA;AAGA;AAAqD;AAQrD,SAASA,cAAc,CAACC,KAAY,EAAkB;EACpD,OAAO;IACL,GAAGA,KAAK;IACRC,OAAO,EAAE,IAAIC,IAAI,CAACF,KAAK,CAACC,OAAO,CAAC,CAACE,WAAW;EAC9C,CAAC;AACH;;AAEA;AACe,kBAAUC,KAAa,EAAEC,IAAU,EAAEC,OAAgB,EAAEC,MAAc,EAAQ;EAC1FH,KAAK,CAACI,GAAG,CACP,kBAAkB,EAClB,gBAAgBC,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,EAAE;IAC1E,MAAM;MAAEC;IAAK,CAAC,GAAGH,GAAG,CAACI,WAAW;IAEhC,IAAIC,eAAC,CAACC,KAAK,CAACH,IAAI,CAAC,KAAK,KAAK,EAAE;MAC3B,IAAI;QACF,MAAMI,MAAM,GAAG,MAAMV,OAAO,CAACW,UAAU,CAAC;UAAEC,IAAI,EAAEN;QAAK,CAAC,CAAC;QACvD,MAAMO,WAAW,GAAGH,MAAM,CAACI,MAAM;QACjCC,cAAM,CAACC,KAAK,CAAC;UAAEH;QAAY,CA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,OAAO,CAAC,CAAC;MAC5E;IACF;IACA,OAAOvB,IAAI,CAACoB,gBAAU,CAACI,eAAe,EAAE,CAAC;EAC3C,CAAC,CACF;AACH"}
|
package/build/whoami.js
CHANGED
|
@@ -4,27 +4,19 @@ 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 _core = require("@verdaccio/core");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const debug = (0, _debug.default)('verdaccio:api:user');
|
|
15
|
-
|
|
16
11
|
function _default(route) {
|
|
17
12
|
route.get('/-/whoami', (req, _res, next) => {
|
|
18
13
|
var _req$remote_user;
|
|
19
|
-
|
|
20
14
|
// remote_user is set by the auth middleware
|
|
21
15
|
const username = 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;
|
|
22
|
-
|
|
23
16
|
if (!username) {
|
|
24
17
|
debug('whoami: user not found');
|
|
25
18
|
return next(_core.errorUtils.getUnauthorized('Unauthorized'));
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
debug('whoami: response %o', username);
|
|
29
21
|
return next({
|
|
30
22
|
username: username
|
package/build/whoami.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whoami.js","names":["debug","buildDebug","route","get","req","_res","next","username","remote_user","name","errorUtils","getUnauthorized"],"sources":["../src/whoami.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Response, Router } from 'express';\n\nimport { errorUtils } from '@verdaccio/core';\n\nimport { $NextFunctionVer, $RequestExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:user');\n\nexport default function (route: Router): void {\n route.get('/-/whoami', (req: $RequestExtend, _res: Response, next: $NextFunctionVer): any => {\n // remote_user is set by the auth middleware\n const username = req?.remote_user?.name;\n if (!username) {\n debug('whoami: user not found');\n return next(errorUtils.getUnauthorized('Unauthorized'));\n }\n\n debug('whoami: response %o', username);\n return next({ username: username });\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"whoami.js","names":["debug","buildDebug","route","get","req","_res","next","username","remote_user","name","errorUtils","getUnauthorized"],"sources":["../src/whoami.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Response, Router } from 'express';\n\nimport { errorUtils } from '@verdaccio/core';\n\nimport { $NextFunctionVer, $RequestExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:user');\n\nexport default function (route: Router): void {\n route.get('/-/whoami', (req: $RequestExtend, _res: Response, next: $NextFunctionVer): any => {\n // remote_user is set by the auth middleware\n const username = req?.remote_user?.name;\n if (!username) {\n debug('whoami: user not found');\n return next(errorUtils.getUnauthorized('Unauthorized'));\n }\n\n debug('whoami: response %o', username);\n return next({ username: username });\n });\n}\n"],"mappings":";;;;;;AAAA;AAGA;AAA6C;AAI7C,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,oBAAoB,CAAC;AAE/B,kBAAUC,KAAa,EAAQ;EAC5CA,KAAK,CAACC,GAAG,CAAC,WAAW,EAAE,CAACC,GAAmB,EAAEC,IAAc,EAAEC,IAAsB,KAAU;IAAA;IAC3F;IACA,MAAMC,QAAQ,GAAGH,GAAG,aAAHA,GAAG,2CAAHA,GAAG,CAAEI,WAAW,qDAAhB,iBAAkBC,IAAI;IACvC,IAAI,CAACF,QAAQ,EAAE;MACbP,KAAK,CAAC,wBAAwB,CAAC;MAC/B,OAAOM,IAAI,CAACI,gBAAU,CAACC,eAAe,CAAC,cAAc,CAAC,CAAC;IACzD;IAEAX,KAAK,CAAC,qBAAqB,EAAEO,QAAQ,CAAC;IACtC,OAAOD,IAAI,CAAC;MAAEC,QAAQ,EAAEA;IAAS,CAAC,CAAC;EACrC,CAAC,CAAC;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/api",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
3
|
+
"version": "6.0.0-6-next.35",
|
|
4
4
|
"description": "loaders logic",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@verdaccio/auth": "6.0.0-6-next.
|
|
34
|
-
"@verdaccio/config": "6.0.0-6-next.
|
|
35
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
36
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
37
|
-
"@verdaccio/middleware": "6.0.0-6-next.
|
|
38
|
-
"@verdaccio/store": "6.0.0-6-next.
|
|
39
|
-
"@verdaccio/utils": "6.0.0-6-next.
|
|
33
|
+
"@verdaccio/auth": "6.0.0-6-next.31",
|
|
34
|
+
"@verdaccio/config": "6.0.0-6-next.52",
|
|
35
|
+
"@verdaccio/core": "6.0.0-6-next.52",
|
|
36
|
+
"@verdaccio/logger": "6.0.0-6-next.20",
|
|
37
|
+
"@verdaccio/middleware": "6.0.0-6-next.31",
|
|
38
|
+
"@verdaccio/store": "6.0.0-6-next.32",
|
|
39
|
+
"@verdaccio/utils": "6.0.0-6-next.20",
|
|
40
40
|
"abortcontroller-polyfill": "1.7.5",
|
|
41
41
|
"cookies": "0.8.0",
|
|
42
42
|
"debug": "4.3.4",
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"semver": "7.3.8"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@types/node": "16.
|
|
51
|
-
"@verdaccio/server": "6.0.0-6-next.
|
|
50
|
+
"@types/node": "16.18.3",
|
|
51
|
+
"@verdaccio/server": "6.0.0-6-next.41",
|
|
52
52
|
"@verdaccio/types": "11.0.0-6-next.17",
|
|
53
53
|
"@verdaccio/test-helper": "2.0.0-6-next.6",
|
|
54
|
-
"supertest": "6.3.
|
|
54
|
+
"supertest": "6.3.1",
|
|
55
55
|
"nock": "13.2.9",
|
|
56
56
|
"mockdate": "3.0.5"
|
|
57
57
|
},
|
package/src/dist-tags.ts
CHANGED
|
@@ -98,24 +98,4 @@ export default function (route: Router, auth: Auth, storage: Storage): void {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
);
|
|
101
|
-
|
|
102
|
-
route.post(
|
|
103
|
-
'/-/package/:package/dist-tags',
|
|
104
|
-
can('publish'),
|
|
105
|
-
async function (
|
|
106
|
-
req: $RequestExtend,
|
|
107
|
-
res: $ResponseExtend,
|
|
108
|
-
next: $NextFunctionVer
|
|
109
|
-
): Promise<void> {
|
|
110
|
-
try {
|
|
111
|
-
await storage.mergeTagsNext(req.params.package, req.body);
|
|
112
|
-
res.status(constants.HTTP_STATUS.CREATED);
|
|
113
|
-
return next({
|
|
114
|
-
ok: constants.API_MESSAGE.TAG_UPDATED,
|
|
115
|
-
});
|
|
116
|
-
} catch (err) {
|
|
117
|
-
next(err);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
101
|
}
|
package/src/stars.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Response, Router } from 'express';
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
|
|
4
|
-
import { HTTP_STATUS, USERS } from '@verdaccio/core';
|
|
4
|
+
import { HTTP_STATUS, USERS, errorUtils } from '@verdaccio/core';
|
|
5
5
|
import { Storage } from '@verdaccio/store';
|
|
6
6
|
import { Version } from '@verdaccio/types';
|
|
7
7
|
|
|
@@ -11,13 +11,15 @@ export default function (route: Router, storage: Storage): void {
|
|
|
11
11
|
route.get(
|
|
12
12
|
'/-/_view/starredByUser',
|
|
13
13
|
async (req: $RequestExtend, res: Response, next: $NextFunctionVer): Promise<void> => {
|
|
14
|
-
const
|
|
14
|
+
const query: { key: string } = req.query;
|
|
15
|
+
if (typeof query?.key !== 'string') {
|
|
16
|
+
return next(errorUtils.getBadRequest('missing query key username'));
|
|
17
|
+
}
|
|
15
18
|
|
|
16
19
|
try {
|
|
17
|
-
const localPackages: Version[] = await storage.
|
|
18
|
-
|
|
20
|
+
const localPackages: Version[] = await storage.getLocalDatabase();
|
|
19
21
|
const filteredPackages: Version[] = localPackages.filter((localPackage: Version) =>
|
|
20
|
-
_.keys(localPackage[USERS]).includes(
|
|
22
|
+
_.keys(localPackage[USERS]).includes(query?.key.toString().replace(/['"]+/g, ''))
|
|
21
23
|
);
|
|
22
24
|
|
|
23
25
|
res.status(HTTP_STATUS.OK);
|
package/src/user.ts
CHANGED
|
@@ -4,7 +4,14 @@ import { Response, Router } from 'express';
|
|
|
4
4
|
import { getApiToken } from '@verdaccio/auth';
|
|
5
5
|
import { Auth } from '@verdaccio/auth';
|
|
6
6
|
import { createRemoteUser } from '@verdaccio/config';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
API_ERROR,
|
|
9
|
+
API_MESSAGE,
|
|
10
|
+
HEADERS,
|
|
11
|
+
HTTP_STATUS,
|
|
12
|
+
errorUtils,
|
|
13
|
+
validatioUtils,
|
|
14
|
+
} from '@verdaccio/core';
|
|
8
15
|
import { logger } from '@verdaccio/logger';
|
|
9
16
|
import { Config, RemoteUser } from '@verdaccio/types';
|
|
10
17
|
import { getAuthenticatedMessage, mask } from '@verdaccio/utils';
|
|
@@ -75,6 +82,7 @@ export default function (route: Router, auth: Auth, config: Config): void {
|
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
res.status(HTTP_STATUS.CREATED);
|
|
85
|
+
res.set(HEADERS.CACHE_CONTROL, 'no-cache, no-store');
|
|
78
86
|
|
|
79
87
|
const message = getAuthenticatedMessage(req.remote_user.name);
|
|
80
88
|
debug('login: created user message %o', message);
|
|
@@ -124,6 +132,7 @@ export default function (route: Router, auth: Auth, config: Config): void {
|
|
|
124
132
|
|
|
125
133
|
req.remote_user = user;
|
|
126
134
|
res.status(HTTP_STATUS.CREATED);
|
|
135
|
+
res.set(HEADERS.CACHE_CONTROL, 'no-cache, no-store');
|
|
127
136
|
debug('adduser: user has been created');
|
|
128
137
|
return next({
|
|
129
138
|
ok: `user '${req.body.name}' created`,
|
package/src/v1/token.ts
CHANGED
|
@@ -3,7 +3,7 @@ import _ from 'lodash';
|
|
|
3
3
|
|
|
4
4
|
import { getApiToken } from '@verdaccio/auth';
|
|
5
5
|
import { Auth } from '@verdaccio/auth';
|
|
6
|
-
import { HTTP_STATUS, SUPPORT_ERRORS, errorUtils } from '@verdaccio/core';
|
|
6
|
+
import { HEADERS, HTTP_STATUS, SUPPORT_ERRORS, errorUtils } from '@verdaccio/core';
|
|
7
7
|
import { logger } from '@verdaccio/logger';
|
|
8
8
|
import { Storage } from '@verdaccio/store';
|
|
9
9
|
import { Config, RemoteUser, Token } from '@verdaccio/types';
|
|
@@ -102,6 +102,7 @@ export default function (route: Router, auth: Auth, storage: Storage, config: Co
|
|
|
102
102
|
|
|
103
103
|
await storage.saveToken(saveToken);
|
|
104
104
|
logger.debug({ key, name }, 'token @{key} was created for user @{name}');
|
|
105
|
+
res.set(HEADERS.CACHE_CONTROL, 'no-cache, no-store');
|
|
105
106
|
return next(
|
|
106
107
|
normalizeToken({
|
|
107
108
|
token,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
generatePackageMetadata,
|
|
12
12
|
initializeServer as initializeServerHelper,
|
|
13
13
|
} from '@verdaccio/test-helper';
|
|
14
|
-
import { GenericBody } from '@verdaccio/types';
|
|
14
|
+
import { GenericBody, PackageUsers } from '@verdaccio/types';
|
|
15
15
|
import { buildToken, generateRandomHexString } from '@verdaccio/utils';
|
|
16
16
|
|
|
17
17
|
import apiMiddleware from '../../src';
|
|
@@ -39,6 +39,7 @@ export function createUser(app, name: string, password: string): supertest.Test
|
|
|
39
39
|
password: password,
|
|
40
40
|
})
|
|
41
41
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
42
|
+
.expect(HEADERS.CACHE_CONTROL, 'no-cache, no-store')
|
|
42
43
|
.expect(HTTP_STATUS.CREATED);
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -91,16 +92,54 @@ export function publishVersion(
|
|
|
91
92
|
app,
|
|
92
93
|
pkgName: string,
|
|
93
94
|
version: string,
|
|
94
|
-
distTags?: GenericBody
|
|
95
|
+
distTags?: GenericBody,
|
|
96
|
+
token?: string
|
|
95
97
|
): supertest.Test {
|
|
96
98
|
const pkgMetadata = generatePackageMetadata(pkgName, version, distTags);
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
const test = supertest(app)
|
|
99
101
|
.put(`/${encodeURIComponent(pkgName)}`)
|
|
100
102
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
101
103
|
.send(JSON.stringify(pkgMetadata))
|
|
102
104
|
.set('accept', HEADERS.GZIP)
|
|
103
105
|
.set(HEADER_TYPE.ACCEPT_ENCODING, HEADERS.JSON);
|
|
106
|
+
|
|
107
|
+
if (typeof token === 'string') {
|
|
108
|
+
test.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return test;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function starPackage(
|
|
115
|
+
app,
|
|
116
|
+
options: {
|
|
117
|
+
users: PackageUsers;
|
|
118
|
+
name: string;
|
|
119
|
+
_rev: string;
|
|
120
|
+
_id?: string;
|
|
121
|
+
},
|
|
122
|
+
token?: string
|
|
123
|
+
): supertest.Test {
|
|
124
|
+
const { _rev, _id, users } = options;
|
|
125
|
+
const starManifest = {
|
|
126
|
+
_rev,
|
|
127
|
+
_id,
|
|
128
|
+
users,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const test = supertest(app)
|
|
132
|
+
.put(`/${encodeURIComponent(options.name)}`)
|
|
133
|
+
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
134
|
+
.send(JSON.stringify(starManifest))
|
|
135
|
+
.set('accept', HEADERS.GZIP)
|
|
136
|
+
.set(HEADER_TYPE.ACCEPT_ENCODING, HEADERS.JSON);
|
|
137
|
+
|
|
138
|
+
if (typeof token === 'string') {
|
|
139
|
+
test.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return test;
|
|
104
143
|
}
|
|
105
144
|
|
|
106
145
|
export function getDisTags(app, pkgName) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
auth:
|
|
2
|
+
htpasswd:
|
|
3
|
+
file: ./htpasswd-star
|
|
4
|
+
web:
|
|
5
|
+
enable: true
|
|
6
|
+
title: verdaccio
|
|
7
|
+
|
|
8
|
+
uplinks:
|
|
9
|
+
npmjs:
|
|
10
|
+
url: https://registry.npmjs.org/
|
|
11
|
+
|
|
12
|
+
log: { type: stdout, format: pretty, level: info }
|
|
13
|
+
|
|
14
|
+
packages:
|
|
15
|
+
'@*/*':
|
|
16
|
+
access: $all
|
|
17
|
+
publish: $authenticated
|
|
18
|
+
unpublish: $authenticated
|
|
19
|
+
proxy: npmjs
|
|
20
|
+
'**':
|
|
21
|
+
access: $all
|
|
22
|
+
publish: $authenticated
|
|
23
|
+
unpublish: $authenticated
|
|
24
|
+
proxy: npmjs
|
|
25
|
+
|
|
26
|
+
_debug: true
|
|
@@ -6,38 +6,8 @@ import { HTTP_STATUS } from '@verdaccio/core';
|
|
|
6
6
|
import { API_ERROR, API_MESSAGE, HEADERS, HEADER_TYPE } from '@verdaccio/core';
|
|
7
7
|
import { generatePackageMetadata, generateRemotePackageMetadata } from '@verdaccio/test-helper';
|
|
8
8
|
|
|
9
|
-
import { $RequestExtend, $ResponseExtend } from '../../types/custom';
|
|
10
9
|
import { getPackage, initializeServer, publishVersion } from './_helper';
|
|
11
10
|
|
|
12
|
-
const mockApiJWTmiddleware = jest.fn(
|
|
13
|
-
() =>
|
|
14
|
-
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
|
15
|
-
req.remote_user = { name: 'foo', groups: [], real_groups: [] };
|
|
16
|
-
_next();
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
jest.mock('@verdaccio/auth', () => ({
|
|
21
|
-
Auth: class {
|
|
22
|
-
apiJWTmiddleware() {
|
|
23
|
-
return mockApiJWTmiddleware();
|
|
24
|
-
}
|
|
25
|
-
init() {
|
|
26
|
-
return Promise.resolve();
|
|
27
|
-
}
|
|
28
|
-
allow_access(_d, f_, cb) {
|
|
29
|
-
cb(null, true);
|
|
30
|
-
}
|
|
31
|
-
allow_publish(_d, f_, cb) {
|
|
32
|
-
cb(null, true);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
allow_unpublish(_d, f_, cb) {
|
|
36
|
-
cb(null, true);
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
11
|
describe('publish', () => {
|
|
42
12
|
describe('handle errors', () => {
|
|
43
13
|
const pkgName = 'test';
|
|
@@ -80,6 +50,22 @@ describe('publish', () => {
|
|
|
80
50
|
});
|
|
81
51
|
});
|
|
82
52
|
});
|
|
53
|
+
|
|
54
|
+
test.each([['foo', '@scope/foo']])(
|
|
55
|
+
'should fails on publish a duplicated package',
|
|
56
|
+
async (pkgName) => {
|
|
57
|
+
const app = await initializeServer('publish.yaml');
|
|
58
|
+
await publishVersion(app, pkgName, '1.0.0');
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
publishVersion(app, pkgName, '1.0.0')
|
|
61
|
+
.expect(HTTP_STATUS.CONFLICT)
|
|
62
|
+
.then((response) => {
|
|
63
|
+
expect(response.body.error).toEqual(API_ERROR.PACKAGE_EXIST);
|
|
64
|
+
resolve(response);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
);
|
|
83
69
|
});
|
|
84
70
|
|
|
85
71
|
describe('publish a package', () => {
|
|
@@ -141,6 +127,7 @@ describe('publish', () => {
|
|
|
141
127
|
});
|
|
142
128
|
});
|
|
143
129
|
});
|
|
130
|
+
|
|
144
131
|
describe('proxies setup', () => {
|
|
145
132
|
test.each([['foo', '@scope%2Ffoo']])(
|
|
146
133
|
'should publish a a patch package that already exist on a remote',
|
|
@@ -172,22 +159,6 @@ describe('publish', () => {
|
|
|
172
159
|
});
|
|
173
160
|
});
|
|
174
161
|
|
|
175
|
-
test.each([['foo', '@scope/foo']])(
|
|
176
|
-
'should fails on publish a duplicated package',
|
|
177
|
-
async (pkgName) => {
|
|
178
|
-
const app = await initializeServer('publish.yaml');
|
|
179
|
-
await publishVersion(app, pkgName, '1.0.0');
|
|
180
|
-
return new Promise((resolve) => {
|
|
181
|
-
publishVersion(app, pkgName, '1.0.0')
|
|
182
|
-
.expect(HTTP_STATUS.CONFLICT)
|
|
183
|
-
.then((response) => {
|
|
184
|
-
expect(response.body.error).toEqual(API_ERROR.PACKAGE_EXIST);
|
|
185
|
-
resolve(response);
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
|
|
191
162
|
describe('unpublish a package', () => {
|
|
192
163
|
test.each([['foo', '@scope/foo']])('should unpublish entirely a package', async (pkgName) => {
|
|
193
164
|
const app = await initializeServer('publish.yaml');
|
|
@@ -257,6 +228,4 @@ describe('publish', () => {
|
|
|
257
228
|
}
|
|
258
229
|
);
|
|
259
230
|
});
|
|
260
|
-
|
|
261
|
-
describe('star a package', () => {});
|
|
262
231
|
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import nock from 'nock';
|
|
2
|
+
import supertest from 'supertest';
|
|
3
|
+
|
|
4
|
+
import { HTTP_STATUS } from '@verdaccio/core';
|
|
5
|
+
import { HEADERS, HEADER_TYPE } from '@verdaccio/core';
|
|
6
|
+
|
|
7
|
+
import { getNewToken, getPackage, initializeServer, publishVersion, starPackage } from './_helper';
|
|
8
|
+
|
|
9
|
+
describe('star', () => {
|
|
10
|
+
test.each([['foo', '@scope%2Ffoo']])(
|
|
11
|
+
'should list stared packages for an user',
|
|
12
|
+
async (pkgName) => {
|
|
13
|
+
const userLogged = 'jota_token';
|
|
14
|
+
nock('https://registry.npmjs.org').get(`/${pkgName}`).reply(404);
|
|
15
|
+
const app = await initializeServer('star.yaml');
|
|
16
|
+
const token = await getNewToken(app, { name: userLogged, password: 'secretPass' });
|
|
17
|
+
await publishVersion(app, pkgName, '1.0.0', undefined, token).expect(HTTP_STATUS.CREATED);
|
|
18
|
+
await publishVersion(app, 'pkg-1', '1.0.0', undefined, token).expect(HTTP_STATUS.CREATED);
|
|
19
|
+
await publishVersion(app, 'pkg-2', '1.0.0', undefined, token).expect(HTTP_STATUS.CREATED);
|
|
20
|
+
const manifest = await getPackage(app, '', decodeURIComponent(pkgName));
|
|
21
|
+
await starPackage(
|
|
22
|
+
app,
|
|
23
|
+
{
|
|
24
|
+
_rev: manifest.body._rev,
|
|
25
|
+
_id: manifest.body.id,
|
|
26
|
+
name: pkgName,
|
|
27
|
+
users: { [userLogged]: true },
|
|
28
|
+
},
|
|
29
|
+
token
|
|
30
|
+
).expect(HTTP_STATUS.CREATED);
|
|
31
|
+
await starPackage(
|
|
32
|
+
app,
|
|
33
|
+
{
|
|
34
|
+
_rev: manifest.body._rev,
|
|
35
|
+
_id: manifest.body.id,
|
|
36
|
+
name: 'pkg-1',
|
|
37
|
+
users: { [userLogged]: true },
|
|
38
|
+
},
|
|
39
|
+
token
|
|
40
|
+
).expect(HTTP_STATUS.CREATED);
|
|
41
|
+
await starPackage(
|
|
42
|
+
app,
|
|
43
|
+
{
|
|
44
|
+
_rev: manifest.body._rev,
|
|
45
|
+
_id: manifest.body.id,
|
|
46
|
+
name: 'pkg-2',
|
|
47
|
+
users: { [userLogged]: true },
|
|
48
|
+
},
|
|
49
|
+
token
|
|
50
|
+
).expect(HTTP_STATUS.CREATED);
|
|
51
|
+
const resp = await supertest(app)
|
|
52
|
+
.get(`/-/_view/starredByUser?key=%22jota_token%22`)
|
|
53
|
+
.set('Accept', HEADERS.JSON)
|
|
54
|
+
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
55
|
+
.expect(HTTP_STATUS.OK);
|
|
56
|
+
expect(resp.body.rows).toHaveLength(3);
|
|
57
|
+
expect(resp.body.rows).toEqual([{ value: 'foo' }, { value: 'pkg-1' }, { value: 'pkg-2' }]);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
test.each([['foo']])('should requires parameters', async (pkgName) => {
|
|
62
|
+
const userLogged = 'jota_token';
|
|
63
|
+
nock('https://registry.npmjs.org').get(`/${pkgName}`).reply(404);
|
|
64
|
+
const app = await initializeServer('star.yaml');
|
|
65
|
+
const token = await getNewToken(app, { name: userLogged, password: 'secretPass' });
|
|
66
|
+
await publishVersion(app, pkgName, '1.0.0', undefined, token).expect(HTTP_STATUS.CREATED);
|
|
67
|
+
return supertest(app)
|
|
68
|
+
.get(`/-/_view/starredByUser?key_xxxxx=other`)
|
|
69
|
+
.set('Accept', HEADERS.JSON)
|
|
70
|
+
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
71
|
+
.expect(HTTP_STATUS.BAD_REQUEST);
|
|
72
|
+
});
|
|
73
|
+
});
|
package/types/custom.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express';
|
|
|
2
2
|
|
|
3
3
|
import { Logger, RemoteUser } from '@verdaccio/types';
|
|
4
4
|
|
|
5
|
-
export type $RequestExtend = Request & { remote_user?: any; log: Logger };
|
|
5
|
+
export type $RequestExtend = Request & { remote_user?: any; log: Logger; query?: { key: string } };
|
|
6
6
|
export type $ResponseExtend = Response & { cookies?: any };
|
|
7
7
|
export type $NextFunctionVer = NextFunction & any;
|
|
8
8
|
|
package/build/star.d.ts
DELETED
package/build/star.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = _default;
|
|
7
|
-
|
|
8
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
15
|
-
const debug = (0, _debug.default)('verdaccio:api:publish:star');
|
|
16
|
-
|
|
17
|
-
function _default(storage) {
|
|
18
|
-
const validateInputs = (newUsers, localUsers, username, isStar) => {
|
|
19
|
-
const isExistlocalUsers = _lodash.default.isNil(localUsers[username]) === false;
|
|
20
|
-
|
|
21
|
-
if (isStar && isExistlocalUsers && localUsers[username]) {
|
|
22
|
-
return true;
|
|
23
|
-
} else if (!isStar && isExistlocalUsers) {
|
|
24
|
-
return false;
|
|
25
|
-
} else if (!isStar && !isExistlocalUsers) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return false;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
return (req, res, next) => {
|
|
33
|
-
const name = req.params.package;
|
|
34
|
-
debug('starring a package for %o', name); // const afterChangePackage = function (err?: Error) {
|
|
35
|
-
// if (err) {
|
|
36
|
-
// debug('error on update package for %o', name);
|
|
37
|
-
// return next(err);
|
|
38
|
-
// }
|
|
39
|
-
// debug('succes update package for %o', name);
|
|
40
|
-
// res.status(HTTP_STATUS.OK);
|
|
41
|
-
// next({
|
|
42
|
-
// success: true,
|
|
43
|
-
// });
|
|
44
|
-
// };
|
|
45
|
-
|
|
46
|
-
debug('get package info package for %o', name); // @ts-ignore
|
|
47
|
-
// storage.getPackage({
|
|
48
|
-
// name,
|
|
49
|
-
// req,
|
|
50
|
-
// callback: function (err, info) {
|
|
51
|
-
// if (err) {
|
|
52
|
-
// debug('error on get package info package for %o', name);
|
|
53
|
-
// return next(err);
|
|
54
|
-
// }
|
|
55
|
-
// const newStarUser = req.body[USERS];
|
|
56
|
-
// const remoteUsername = req.remote_user.name;
|
|
57
|
-
// const localStarUsers = info[USERS];
|
|
58
|
-
// // Check is star or unstar
|
|
59
|
-
// const isStar = Object.keys(newStarUser).includes(remoteUsername);
|
|
60
|
-
// debug('is start? %o', isStar);
|
|
61
|
-
// if (
|
|
62
|
-
// _.isNil(localStarUsers) === false &&
|
|
63
|
-
// validateInputs(newStarUser, localStarUsers, remoteUsername, isStar)
|
|
64
|
-
// ) {
|
|
65
|
-
// return afterChangePackage();
|
|
66
|
-
// }
|
|
67
|
-
// const users = isStar
|
|
68
|
-
// ? {
|
|
69
|
-
// ...localStarUsers,
|
|
70
|
-
// [remoteUsername]: true,
|
|
71
|
-
// }
|
|
72
|
-
// : _.reduce(
|
|
73
|
-
// localStarUsers,
|
|
74
|
-
// (users, value, key) => {
|
|
75
|
-
// if (key !== remoteUsername) {
|
|
76
|
-
// users[key] = value;
|
|
77
|
-
// }
|
|
78
|
-
// return users;
|
|
79
|
-
// },
|
|
80
|
-
// {}
|
|
81
|
-
// );
|
|
82
|
-
// debug('update package for %o', name);
|
|
83
|
-
// storage.changePackage(name, { ...info, users }, req.body._rev, function (err) {
|
|
84
|
-
// afterChangePackage(err);
|
|
85
|
-
// });
|
|
86
|
-
// },
|
|
87
|
-
// });
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=star.js.map
|
package/build/star.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"star.js","names":["debug","buildDebug","storage","validateInputs","newUsers","localUsers","username","isStar","isExistlocalUsers","_","isNil","req","res","next","name","params","package"],"sources":["../src/star.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport buildDebug from 'debug';\nimport { Response } from 'express';\nimport _ from 'lodash';\n\nimport { HTTP_STATUS, USERS } from '@verdaccio/core';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:publish:star');\n\nexport default function (\n storage: Storage\n): (req: $RequestExtend, res: Response, next: $NextFunctionVer) => void {\n const validateInputs = (newUsers, localUsers, username, isStar): boolean => {\n const isExistlocalUsers = _.isNil(localUsers[username]) === false;\n if (isStar && isExistlocalUsers && localUsers[username]) {\n return true;\n } else if (!isStar && isExistlocalUsers) {\n return false;\n } else if (!isStar && !isExistlocalUsers) {\n return true;\n }\n return false;\n };\n\n return (req: $RequestExtend, res: Response, next: $NextFunctionVer): void => {\n const name = req.params.package;\n debug('starring a package for %o', name);\n // const afterChangePackage = function (err?: Error) {\n // if (err) {\n // debug('error on update package for %o', name);\n // return next(err);\n // }\n\n // debug('succes update package for %o', name);\n // res.status(HTTP_STATUS.OK);\n // next({\n // success: true,\n // });\n // };\n\n debug('get package info package for %o', name);\n // @ts-ignore\n // storage.getPackage({\n // name,\n // req,\n // callback: function (err, info) {\n // if (err) {\n // debug('error on get package info package for %o', name);\n // return next(err);\n // }\n // const newStarUser = req.body[USERS];\n // const remoteUsername = req.remote_user.name;\n // const localStarUsers = info[USERS];\n // // Check is star or unstar\n // const isStar = Object.keys(newStarUser).includes(remoteUsername);\n // debug('is start? %o', isStar);\n // if (\n // _.isNil(localStarUsers) === false &&\n // validateInputs(newStarUser, localStarUsers, remoteUsername, isStar)\n // ) {\n // return afterChangePackage();\n // }\n // const users = isStar\n // ? {\n // ...localStarUsers,\n // [remoteUsername]: true,\n // }\n // : _.reduce(\n // localStarUsers,\n // (users, value, key) => {\n // if (key !== remoteUsername) {\n // users[key] = value;\n // }\n // return users;\n // },\n // {}\n // );\n // debug('update package for %o', name);\n // storage.changePackage(name, { ...info, users }, req.body._rev, function (err) {\n // afterChangePackage(err);\n // });\n // },\n // });\n };\n}\n"],"mappings":";;;;;;;AACA;;AAEA;;;;AAHA;AAUA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,4BAAX,CAAd;;AAEe,kBACbC,OADa,EAEyD;EACtE,MAAMC,cAAc,GAAG,CAACC,QAAD,EAAWC,UAAX,EAAuBC,QAAvB,EAAiCC,MAAjC,KAAqD;IAC1E,MAAMC,iBAAiB,GAAGC,eAAA,CAAEC,KAAF,CAAQL,UAAU,CAACC,QAAD,CAAlB,MAAkC,KAA5D;;IACA,IAAIC,MAAM,IAAIC,iBAAV,IAA+BH,UAAU,CAACC,QAAD,CAA7C,EAAyD;MACvD,OAAO,IAAP;IACD,CAFD,MAEO,IAAI,CAACC,MAAD,IAAWC,iBAAf,EAAkC;MACvC,OAAO,KAAP;IACD,CAFM,MAEA,IAAI,CAACD,MAAD,IAAW,CAACC,iBAAhB,EAAmC;MACxC,OAAO,IAAP;IACD;;IACD,OAAO,KAAP;EACD,CAVD;;EAYA,OAAO,CAACG,GAAD,EAAsBC,GAAtB,EAAqCC,IAArC,KAAsE;IAC3E,MAAMC,IAAI,GAAGH,GAAG,CAACI,MAAJ,CAAWC,OAAxB;IACAhB,KAAK,CAAC,2BAAD,EAA8Bc,IAA9B,CAAL,CAF2E,CAG3E;IACA;IACA;IACA;IACA;IAEA;IACA;IACA;IACA;IACA;IACA;;IAEAd,KAAK,CAAC,iCAAD,EAAoCc,IAApC,CAAL,CAhB2E,CAiB3E;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;EACD,CA3DD;AA4DD"}
|