@verdaccio/api 6.0.0-6-next.31 → 6.0.0-6-next.32
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 +17 -0
- package/build/dist-tags.d.ts +2 -2
- package/build/dist-tags.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js.map +1 -1
- package/build/package.d.ts +2 -2
- package/build/package.js.map +1 -1
- package/build/publish.d.ts +2 -2
- package/build/publish.js +10 -13
- package/build/publish.js.map +1 -1
- package/build/user.d.ts +2 -2
- package/build/user.js +2 -2
- package/build/user.js.map +1 -1
- package/build/v1/profile.d.ts +2 -2
- package/build/v1/profile.js.map +1 -1
- package/build/v1/search.d.ts +2 -2
- package/build/v1/search.js.map +1 -1
- package/build/v1/token.d.ts +2 -2
- package/build/v1/token.js.map +1 -1
- package/package.json +11 -11
- package/src/dist-tags.ts +2 -2
- package/src/index.ts +2 -2
- package/src/package.ts +2 -2
- package/src/publish.ts +9 -11
- package/src/user.ts +7 -5
- package/src/v1/profile.ts +2 -2
- package/src/v1/search.ts +2 -2
- package/src/v1/token.ts +4 -4
- package/test/integration/publish.spec.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @verdaccio/api
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.32
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ce013d2f: refactor: npm star command support reimplemented
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [ce013d2f]
|
|
12
|
+
- @verdaccio/store@6.0.0-6-next.29
|
|
13
|
+
- @verdaccio/core@6.0.0-6-next.49
|
|
14
|
+
- @verdaccio/config@6.0.0-6-next.49
|
|
15
|
+
- @verdaccio/auth@6.0.0-6-next.28
|
|
16
|
+
- @verdaccio/logger@6.0.0-6-next.17
|
|
17
|
+
- @verdaccio/middleware@6.0.0-6-next.28
|
|
18
|
+
- @verdaccio/utils@6.0.0-6-next.17
|
|
19
|
+
|
|
3
20
|
## 6.0.0-6-next.31
|
|
4
21
|
|
|
5
22
|
### Major Changes
|
package/build/dist-tags.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Storage } from '@verdaccio/store';
|
|
4
|
-
export default function (route: Router, auth:
|
|
4
|
+
export default function (route: Router, auth: Auth, storage: Storage): void;
|
package/build/dist-tags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dist-tags.js","names":["route","auth","storage","can","allow","addTagPackageVersionMiddleware","req","res","next","_","isString","body","errorUtils","getBadRequest","tags","params","tag","mergeTagsNext","package","status","constants","HTTP_STATUS","CREATED","ok","API_MESSAGE","TAG_ADDED","err","put","media","mime","getType","delete","TAG_REMOVED","get","name","requestOptions","protocol","headers","host","remoteAddress","socket","manifest","getPackageByOptions","uplinksLook","DIST_TAGS","post","TAG_UPDATED"],"sources":["../src/dist-tags.ts"],"sourcesContent":["import { Router } from 'express';\nimport _ from 'lodash';\nimport mime from 'mime';\n\nimport {
|
|
1
|
+
{"version":3,"file":"dist-tags.js","names":["route","auth","storage","can","allow","addTagPackageVersionMiddleware","req","res","next","_","isString","body","errorUtils","getBadRequest","tags","params","tag","mergeTagsNext","package","status","constants","HTTP_STATUS","CREATED","ok","API_MESSAGE","TAG_ADDED","err","put","media","mime","getType","delete","TAG_REMOVED","get","name","requestOptions","protocol","headers","host","remoteAddress","socket","manifest","getPackageByOptions","uplinksLook","DIST_TAGS","post","TAG_UPDATED"],"sources":["../src/dist-tags.ts"],"sourcesContent":["import { Router } from 'express';\nimport _ from 'lodash';\nimport mime from 'mime';\n\nimport { Auth } from '@verdaccio/auth';\nimport { constants, errorUtils } from '@verdaccio/core';\nimport { allow, media } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\nexport default function (route: Router, auth: Auth, storage: Storage): void {\n const can = allow(auth);\n const addTagPackageVersionMiddleware = async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<$NextFunctionVer> {\n if (_.isString(req.body) === false) {\n return next(errorUtils.getBadRequest('version is missing'));\n }\n\n const tags = {};\n tags[req.params.tag] = req.body;\n try {\n await storage.mergeTagsNext(req.params.package, tags);\n res.status(constants.HTTP_STATUS.CREATED);\n return next({\n ok: constants.API_MESSAGE.TAG_ADDED,\n });\n } catch (err) {\n next(err);\n }\n };\n\n // tagging a package.\n route.put(\n '/:package/:tag',\n can('publish'),\n media(mime.getType('json')),\n addTagPackageVersionMiddleware\n );\n\n route.put(\n '/-/package/:package/dist-tags/:tag',\n can('publish'),\n media(mime.getType('json')),\n addTagPackageVersionMiddleware\n );\n\n route.delete(\n '/-/package/:package/dist-tags/:tag',\n can('publish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const tags = {};\n tags[req.params.tag] = null;\n try {\n await storage.mergeTagsNext(req.params.package, tags);\n res.status(constants.HTTP_STATUS.CREATED);\n return next({\n ok: constants.API_MESSAGE.TAG_REMOVED,\n });\n } catch (err) {\n next(err);\n }\n }\n );\n\n route.get(\n '/-/package/:package/dist-tags',\n can('access'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const name = req.params.package;\n const requestOptions = {\n protocol: req.protocol,\n headers: req.headers as any,\n // FIXME: if we migrate to req.hostname, the port is not longer included.\n host: req.host,\n remoteAddress: req.socket.remoteAddress,\n };\n try {\n const manifest = await storage.getPackageByOptions({\n name,\n uplinksLook: true,\n requestOptions,\n });\n next(manifest[constants.DIST_TAGS]);\n } catch (err) {\n next(err);\n }\n }\n );\n\n route.post(\n '/-/package/:package/dist-tags',\n can('publish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n try {\n await storage.mergeTagsNext(req.params.package, req.body);\n res.status(constants.HTTP_STATUS.CREATED);\n return next({\n ok: constants.API_MESSAGE.TAG_UPDATED,\n });\n } catch (err) {\n next(err);\n }\n }\n );\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AAGA;;AACA;;;;AAKe,kBAAUA,KAAV,EAAyBC,IAAzB,EAAqCC,OAArC,EAA6D;EAC1E,MAAMC,GAAG,GAAG,IAAAC,iBAAA,EAAMH,IAAN,CAAZ;;EACA,MAAMI,8BAA8B,GAAG,gBACrCC,GADqC,EAErCC,GAFqC,EAGrCC,IAHqC,EAIV;IAC3B,IAAIC,eAAA,CAAEC,QAAF,CAAWJ,GAAG,CAACK,IAAf,MAAyB,KAA7B,EAAoC;MAClC,OAAOH,IAAI,CAACI,gBAAA,CAAWC,aAAX,CAAyB,oBAAzB,CAAD,CAAX;IACD;;IAED,MAAMC,IAAI,GAAG,EAAb;IACAA,IAAI,CAACR,GAAG,CAACS,MAAJ,CAAWC,GAAZ,CAAJ,GAAuBV,GAAG,CAACK,IAA3B;;IACA,IAAI;MACF,MAAMT,OAAO,CAACe,aAAR,CAAsBX,GAAG,CAACS,MAAJ,CAAWG,OAAjC,EAA0CJ,IAA1C,CAAN;MACAP,GAAG,CAACY,MAAJ,CAAWC,eAAA,CAAUC,WAAV,CAAsBC,OAAjC;MACA,OAAOd,IAAI,CAAC;QACVe,EAAE,EAAEH,eAAA,CAAUI,WAAV,CAAsBC;MADhB,CAAD,CAAX;IAGD,CAND,CAME,OAAOC,GAAP,EAAY;MACZlB,IAAI,CAACkB,GAAD,CAAJ;IACD;EACF,CApBD,CAF0E,CAwB1E;;;EACA1B,KAAK,CAAC2B,GAAN,CACE,gBADF,EAEExB,GAAG,CAAC,SAAD,CAFL,EAGE,IAAAyB,iBAAA,EAAMC,aAAA,CAAKC,OAAL,CA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C,mBAAR,CAA4B;QACjDR,IADiD;QAEjDS,WAAW,EAAE,IAFoC;QAGjDR;MAHiD,CAA5B,CAAvB;MAKA3B,IAAI,CAACiC,QAAQ,CAACrB,eAAA,CAAUwB,SAAX,CAAT,CAAJ;IACD,CAPD,CAOE,OAAOlB,GAAP,EAAY;MACZlB,IAAI,CAACkB,GAAD,CAAJ;IACD;EACF,CA1BH;EA6BA1B,KAAK,CAAC6C,IAAN,CACE,+BADF,EAEE1C,GAAG,CAAC,SAAD,CAFL,EAGE,gBACEG,GADF,EAEEC,GAFF,EAGEC,IAHF,EAIiB;IACf,IAAI;MACF,MAAMN,OAAO,CAACe,aAAR,CAAsBX,GAAG,CAACS,MAAJ,CAAWG,OAAjC,EAA0CZ,GAAG,CAACK,IAA9C,CAAN;MACAJ,GAAG,CAACY,MAAJ,CAAWC,eAAA,CAAUC,WAAV,CAAsBC,OAAjC;MACA,OAAOd,IAAI,CAAC;QACVe,EAAE,EAAEH,eAAA,CAAUI,WAAV,CAAsBsB;MADhB,CAAD,CAAX;IAGD,CAND,CAME,OAAOpB,GAAP,EAAY;MACZlB,IAAI,CAACkB,GAAD,CAAJ;IACD;EACF,CAjBH;AAmBD"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Storage } from '@verdaccio/store';
|
|
4
4
|
import { Config } from '@verdaccio/types';
|
|
5
|
-
export default function (config: Config, auth:
|
|
5
|
+
export default function (config: Config, auth: Auth, storage: Storage): Router;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["config","auth","storage","app","express","Router","param","validatePackage","validateName","match","use","apiJWTmiddleware","bodyParser","json","strict","limit","max_body_size","antiLoop","encodeScopePackage","whoami","pkg","profile","search","user","distTags","publish","ping","stars","v1Search","token"],"sources":["../src/index.ts"],"sourcesContent":["import bodyParser from 'body-parser';\nimport express, { Router } from 'express';\n\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["config","auth","storage","app","express","Router","param","validatePackage","validateName","match","use","apiJWTmiddleware","bodyParser","json","strict","limit","max_body_size","antiLoop","encodeScopePackage","whoami","pkg","profile","search","user","distTags","publish","ping","stars","v1Search","token"],"sources":["../src/index.ts"],"sourcesContent":["import bodyParser from 'body-parser';\nimport express, { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n antiLoop,\n encodeScopePackage,\n match,\n validateName,\n validatePackage,\n} from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { Config } 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\nexport default function (config: Config, auth: Auth, storage: Storage): 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 // these can't be safely put into express url for some reason\n // TODO: For some reason? what reason?\n app.param('_rev', match(/^-rev$/));\n app.param('org_couchdb_user', match(/^org\\.couchdb\\.user:/));\n app.param('anything', match(/.*/));\n app.use(auth.apiJWTmiddleware());\n app.use(bodyParser.json({ strict: false, limit: config.max_body_size || '10mb' }));\n // @ts-ignore\n app.use(antiLoop(config));\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 pkg(app, auth, storage);\n profile(app, auth, config);\n // @deprecated endpoint, 404 by default\n search(app);\n user(app, auth, config);\n distTags(app, auth, storage);\n publish(app, auth, storage);\n ping(app);\n stars(app, stor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,8BAAR,EAxB6E,CAyB7E;;EACA,IAAAC,eAAA,EAAOhB,GAAP;EACA,IAAAiB,gBAAA,EAAIjB,GAAJ,EAASF,IAAT,EAAeC,OAAf;EACA,IAAAmB,gBAAA,EAAQlB,GAAR,EAAaF,IAAb,EAAmBD,MAAnB,EA5B6E,CA6B7E;;EACA,IAAAsB,eAAA,EAAOnB,GAAP;EACA,IAAAoB,aAAA,EAAKpB,GAAL,EAAUF,IAAV,EAAgBD,MAAhB;EACA,IAAAwB,iBAAA,EAASrB,GAAT,EAAcF,IAAd,EAAoBC,OAApB;EACA,IAAAuB,gBAAA,EAAQtB,GAAR,EAAaF,IAAb,EAAmBC,OAAnB;EACA,IAAAwB,aAAA,EAAKvB,GAAL;EACA,IAAAwB,cAAA,EAAMxB,GAAN,EAAWD,OAAX,EAnC6E,CAoC7E;;EACA,IAAA0B,gBAAA,EAASzB,GAAT,EAAcF,IAAd,EAAoBC,OAApB;EACA,IAAA2B,cAAA,EAAM1B,GAAN,EAAWF,IAAX,EAAiBC,OAAjB,EAA0BF,MAA1B;EACA,OAAOG,GAAP;AACD"}
|
package/build/package.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Storage } from '@verdaccio/store';
|
|
4
|
-
export default function (route: Router, auth:
|
|
4
|
+
export default function (route: Router, auth: Auth, storage: Storage): void;
|
package/build/package.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","names":["debug","buildDebug","route","auth","storage","can","allow","get","req","_res","next","name","params","package","version","write","query","abbreviated","stringUtils","getByQualityPriorityValue","Storage","ABBREVIATED_HEADER","requestOptions","protocol","headers","host","remoteAddress","socket","byPassCache","manifest","getPackageByOptions","uplinksLook","setHeader","HEADER_TYPE","CONTENT_TYPE","HEADERS","JSON_INSTALL_CHARSET","JSON","err","res","pkg","filename","abort","AbortController","stream","getTarballNext","signal","on","size","header","CONTENT_LENGTH","once","locals","report_error","url","OCTET_STREAM","pipe"],"sources":["../src/package.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\n\nimport {
|
|
1
|
+
{"version":3,"file":"package.js","names":["debug","buildDebug","route","auth","storage","can","allow","get","req","_res","next","name","params","package","version","write","query","abbreviated","stringUtils","getByQualityPriorityValue","Storage","ABBREVIATED_HEADER","requestOptions","protocol","headers","host","remoteAddress","socket","byPassCache","manifest","getPackageByOptions","uplinksLook","setHeader","HEADER_TYPE","CONTENT_TYPE","HEADERS","JSON_INSTALL_CHARSET","JSON","err","res","pkg","filename","abort","AbortController","stream","getTarballNext","signal","on","size","header","CONTENT_LENGTH","once","locals","report_error","url","OCTET_STREAM","pipe"],"sources":["../src/package.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport { HEADERS, HEADER_TYPE, stringUtils } from '@verdaccio/core';\nimport { allow } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:package');\n\nexport default function (route: Router, auth: Auth, storage: Storage): void {\n const can = allow(auth);\n\n route.get(\n '/:package/:version?',\n can('access'),\n async function (\n req: $RequestExtend,\n _res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug('init package by version');\n const name = req.params.package;\n let version = req.params.version;\n const write = req.query.write === 'true';\n const abbreviated =\n stringUtils.getByQualityPriorityValue(req.get('Accept')) === Storage.ABBREVIATED_HEADER;\n const requestOptions = {\n protocol: req.protocol,\n headers: req.headers as any,\n // FIXME: if we migrate to req.hostname, the port is not longer included.\n host: req.host,\n remoteAddress: req.socket.remoteAddress,\n byPassCache: write,\n };\n\n try {\n const manifest = await storage.getPackageByOptions({\n name,\n uplinksLook: true,\n abbreviated,\n version,\n requestOptions,\n });\n if (abbreviated) {\n _res.setHeader(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_INSTALL_CHARSET);\n } else {\n _res.setHeader(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON);\n }\n\n next(manifest);\n } catch (err) {\n next(err);\n }\n }\n );\n\n route.get(\n '/:pkg/-/:filename',\n can('access'),\n async function (req: $RequestExtend, res: $ResponseExtend, next): Promise<void> {\n const { pkg, filename } = req.params;\n const abort = new AbortController();\n try {\n const stream = (await storage.getTarballNext(pkg, filename, {\n signal: abort.signal,\n // TODO: review why this param\n // enableRemote: true,\n })) as any;\n\n stream.on('content-length', (size) => {\n res.header(HEADER_TYPE.CONTENT_LENGTH, size);\n });\n\n stream.once('error', (err) => {\n res.locals.report_error(err);\n next(err);\n });\n\n req.on('abort', () => {\n debug('request aborted for %o', req.url);\n abort.abort();\n });\n\n res.header(HEADERS.CONTENT_TYPE, HEADERS.OCTET_STREAM);\n stream.pipe(res);\n } catch (err: any) {\n // console.log('catch API error request', err);\n res.locals.report_error(err);\n next(err);\n }\n }\n );\n}\n"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AACA;;;;AAIA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,uBAAX,CAAd;;AAEe,kBAAUC,KAAV,EAAyBC,IAAzB,EAAqCC,OAArC,EAA6D;EAC1E,MAAMC,GAAG,GAAG,IAAAC,iBAAA,EAAMH,IAAN,CAAZ;EAEAD,KAAK,CAACK,GAAN,CACE,qBADF,EAEEF,GAAG,CAAC,QAAD,CAFL,EAGE,gBACEG,GADF,EAEEC,IAFF,EAGEC,IAHF,EAIiB;IACfV,KAAK,CAAC,yBAAD,CAAL;IACA,MAAMW,IAAI,GAAGH,GAAG,CAACI,MAAJ,CAAWC,OAAxB;IACA,IAAIC,OAAO,GAAGN,GAAG,CAACI,MAAJ,CAAWE,OAAzB;IACA,MAAMC,KAAK,GAAGP,GAAG,CAACQ,KAAJ,CAAUD,KAAV,KAAoB,MAAlC;;IACA,M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AC1DK,MAAM,EAAEJ,KAAK,CAACI,MAD4C,CAE1D;QACA;;MAH0D,CAAtC,CAAtB;MAMAF,MAAM,CAACG,EAAP,CAAU,gBAAV,EAA6BC,IAAD,IAAU;QACpCT,GAAG,CAACU,MAAJ,CAAWhB,iBAAA,CAAYiB,cAAvB,EAAuCF,IAAvC;MACD,CAFD;MAIAJ,MAAM,CAACO,IAAP,CAAY,OAAZ,EAAsBb,GAAD,IAAS;QAC5BC,GAAG,CAACa,MAAJ,CAAWC,YAAX,CAAwBf,GAAxB;QACA5B,IAAI,CAAC4B,GAAD,CAAJ;MACD,CAHD;MAKA9B,GAAG,CAACuC,EAAJ,CAAO,OAAP,EAAgB,MAAM;QACpB/C,KAAK,CAAC,wBAAD,EAA2BQ,GAAG,CAAC8C,GAA/B,CAAL;QACAZ,KAAK,CAACA,KAAN;MACD,CAHD;MAKAH,GAAG,CAACU,MAAJ,CAAWd,aAAA,CAAQD,YAAnB,EAAiCC,aAAA,CAAQoB,YAAzC;MACAX,MAAM,CAACY,IAAP,CAAYjB,GAAZ;IACD,CAvBD,CAuBE,OAAOD,GAAP,EAAiB;MACjB;MACAC,GAAG,CAACa,MAAJ,CAAWC,YAAX,CAAwBf,GAAxB;MACA5B,IAAI,CAAC4B,GAAD,CAAJ;IACD;EACF,CAlCH;AAoCD"}
|
package/build/publish.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Storage } from '@verdaccio/store';
|
|
4
4
|
/**
|
|
5
5
|
* Publish a package / update package / un/start a package
|
|
@@ -79,5 +79,5 @@ import { Storage } from '@verdaccio/store';
|
|
|
79
79
|
}
|
|
80
80
|
*
|
|
81
81
|
*/
|
|
82
|
-
export default function publish(router: Router, auth:
|
|
82
|
+
export default function publish(router: Router, auth: Auth, storage: Storage): void;
|
|
83
83
|
export declare function publishPackage(storage: Storage): any;
|
package/build/publish.js
CHANGED
|
@@ -19,7 +19,6 @@ var _middleware = require("@verdaccio/middleware");
|
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
20
|
|
|
21
21
|
// import star from './star';
|
|
22
|
-
// import { isPublishablePackage, isRelatedToDeprecation } from './utils';
|
|
23
22
|
const debug = (0, _debug.default)('verdaccio:api:publish');
|
|
24
23
|
/**
|
|
25
24
|
* Publish a package / update package / un/start a package
|
|
@@ -170,17 +169,19 @@ function publish(router, auth, storage) {
|
|
|
170
169
|
}
|
|
171
170
|
|
|
172
171
|
function publishPackage(storage) {
|
|
173
|
-
return async function (req,
|
|
172
|
+
return async function (req, res, next) {
|
|
173
|
+
var _req$remote_user;
|
|
174
|
+
|
|
174
175
|
const ac = new AbortController();
|
|
175
176
|
const packageName = req.params.package;
|
|
176
177
|
const {
|
|
177
178
|
revision
|
|
178
179
|
} = req.params;
|
|
179
180
|
const metadata = req.body;
|
|
181
|
+
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;
|
|
180
182
|
|
|
181
183
|
try {
|
|
182
|
-
|
|
183
|
-
await storage.updateManifest(metadata, {
|
|
184
|
+
const message = await storage.updateManifest(metadata, {
|
|
184
185
|
name: packageName,
|
|
185
186
|
revision,
|
|
186
187
|
signal: ac.signal,
|
|
@@ -188,18 +189,14 @@ function publishPackage(storage) {
|
|
|
188
189
|
host: req.hostname,
|
|
189
190
|
protocol: req.protocol,
|
|
190
191
|
// @ts-ignore
|
|
191
|
-
headers: req.headers
|
|
192
|
+
headers: req.headers,
|
|
193
|
+
username
|
|
192
194
|
}
|
|
193
195
|
});
|
|
194
|
-
|
|
195
|
-
_res.status(_core.HTTP_STATUS.CREATED);
|
|
196
|
-
|
|
196
|
+
res.status(_core.HTTP_STATUS.CREATED);
|
|
197
197
|
return next({
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
// the message some return from the method
|
|
201
|
-
ok: _core.API_MESSAGE.PKG_CREATED,
|
|
202
|
-
success: true
|
|
198
|
+
success: true,
|
|
199
|
+
ok: message
|
|
203
200
|
});
|
|
204
201
|
} catch (err) {
|
|
205
202
|
// TODO: review if we need the abort controller here
|
package/build/publish.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","names":["debug","buildDebug","publish","router","auth","storage","can","allow","put","media","mime","getType","expectJson","publishPackage","delete","req","res","next","packageName","params","package","rev","revision","logger","removePackage","status","HTTP_STATUS","CREATED","ok","API_MESSAGE","PKG_REMOVED","err","filename","removeTarball","TARBALL_REMOVED","_res","ac","AbortController","metadata","body","updateManifest","name","signal","requestOptions","host","hostname","protocol","headers","PKG_CREATED","success"],"sources":["../src/publish.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\nimport mime from 'mime';\n\nimport { IAuth } from '@verdaccio/auth';\nimport { API_MESSAGE, HTTP_STATUS } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { allow, expectJson, media } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\n// import star from './star';\n// import { isPublishablePackage, isRelatedToDeprecation } from './utils';\n\nconst debug = buildDebug('verdaccio:api:publish');\n\n/**\n * Publish a package / update package / un/start a package\n *\n * There are multiples scenarios here to be considered:\n *\n * 1. Publish scenario\n *\n * Publish a package consist of at least 1 step (PUT) with a metadata payload.\n * When a package is published, an _attachment property is present that contains the data\n * of the tarball.\n *\n * Example flow of publish.\n *\n * npm http fetch PUT 201 http://localhost:4873/@scope%2ftest1 9627ms\n npm info lifecycle @scope/test1@1.0.1~publish: @scope/test1@1.0.1\n npm info lifecycle @scope/test1@1.0.1~postpublish: @scope/test1@1.0.1\n + @scope/test1@1.0.1\n npm verb exit [ 0, true ]\n *\n *\n * 2. Unpublish scenario\n *\n * Unpublish consist in 3 steps.\n * 1. Try to fetch metadata -> if it fails, return 404\n * 2. Compute metadata locally (client side) and send a mutate payload excluding the version to\n * be unpublished\n * eg: if metadata reflects 1.0.1, 1.0.2 and 1.0.3, the computed metadata won't include 1.0.3.\n * 3. Once the second step has been successfully finished, delete the tarball.\n *\n * All these steps are consecutive and required, there is no transacions here, if step 3 fails,\n * metadata might get corrupted.\n *\n * Note the unpublish call will suffix in the url a /-rev/14-5d500cfce92f90fd revision number,\n * this not\n * used internally.\n *\n *\n * Example flow of unpublish.\n *\n * There are two possible flows:\n *\n * - Remove all packages (entirely)\n * eg: npm unpublish package-name@* --force\n * eg: npm unpublish package-name --force\n *\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * - Remove a specific version\n * eg: npm unpublish package-name@1.0.0 --force\n *\n * Get fresh manifest\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * Update manifest without the version to be unpublished\n * npm http fetch PUT 201 http://localhost:4873/custom-name/-rev/14-5d500cfce92f90fd 956606ms\n * Get fresh manifest (revision should be different)\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1601ms\n * Remove the tarball\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n * \n * 3. Star a package\n *\n * Permissions: start a package depends of the publish and unpublish permissions, there is no\n * specific flag for star or un start.\n * The URL for star is similar to the unpublish (change package format)\n *\n * npm has no endpoint for star a package, rather mutate the metadata and acts as, the difference\n * is the users property which is part of the payload and the body only includes\n *\n * {\n\t\t \"_id\": pkgName,\n\t \t\"_rev\": \"3-b0cdaefc9bdb77c8\",\n\t\t \"users\": {\n\t\t [username]: boolean value (true, false)\n\t\t }\n\t}\n *\n */\nexport default function publish(router: Router, auth: IAuth, storage: Storage): void {\n const can = allow(auth);\n router.put(\n '/:package',\n can('publish'),\n media(mime.getType('json')),\n expectJson,\n publishPackage(storage)\n );\n\n router.put(\n '/:package/-rev/:revision',\n can('unpublish'),\n media(mime.getType('json')),\n expectJson,\n publishPackage(storage)\n );\n\n /**\n * Un-publishing an entire package.\n *\n * This scenario happens when the first call detect there is only one version remaining\n * in the metadata, then the client decides to DELETE the resource\n * npm http fetch GET 304 http://localhost:4873/package-name?write=true 1076ms (from cache)\n * npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n '/:package/-rev/:revision',\n can('unpublish'),\n async function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n const packageName = req.params.package;\n const rev = req.params.revision;\n\n logger.debug({ packageName }, `unpublishing @{packageName}`);\n try {\n await storage.removePackage(packageName, rev);\n debug('package %s unpublished', packageName);\n res.status(HTTP_STATUS.CREATED);\n return next({ ok: API_MESSAGE.PKG_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n\n /*\n Remove a tarball, this happens when npm unpublish a package unique version.\n npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n '/:package/-/:filename/-rev/:revision',\n can('unpublish'),\n can('publish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const packageName = req.params.package;\n const { filename, revision } = req.params;\n\n logger.debug(\n { packageName, filename, revision },\n `removing a tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n try {\n await storage.removeTarball(packageName, filename, revision);\n res.status(HTTP_STATUS.CREATED);\n\n logger.debug(\n { packageName, filename, revision },\n `success remove tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n return next({ ok: API_MESSAGE.TARBALL_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n}\n\nexport function publishPackage(storage: Storage): any {\n return async function (\n req: $RequestExtend,\n _res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const ac = new AbortController();\n const packageName = req.params.package;\n const { revision } = req.params;\n const metadata = req.body;\n\n try {\n debug('publishing %s', packageName);\n await storage.updateManifest(metadata, {\n name: packageName,\n revision,\n signal: ac.signal,\n requestOptions: {\n host: req.hostname,\n protocol: req.protocol,\n // @ts-ignore\n headers: req.headers,\n },\n });\n _res.status(HTTP_STATUS.CREATED);\n\n return next({\n // TODO: this could be also Package Updated based on the\n // action, deprecate, star, publish new version, or create a package\n // the message some return from the method\n ok: API_MESSAGE.PKG_CREATED,\n success: true,\n });\n } catch (err: any) {\n // TODO: review if we need the abort controller here\n next(err);\n }\n };\n}\n"],"mappings":";;;;;;;;AAAA;;AAEA;;AAGA;;AACA;;AACA;;;;AAKA;AACA;AAEA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,uBAAX,CAAd;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,OAAT,CAAiBC,MAAjB,EAAiCC,IAAjC,EAA8CC,OAA9C,EAAsE;EACnF,MAAMC,GAAG,GAAG,IAAAC,iBAAA,EAAMH,IAAN,CAAZ;EACAD,MAAM,CAACK,GAAP,CACE,WADF,EAEEF,GAAG,CAAC,SAAD,CAFL,EAGE,IAAAG,iBAAA,EAAMC,aAAA,CAAKC,OAAL,CAAa,MAAb,CAAN,CAHF,EAIEC,sBAJF,EAKEC,cAAc,CAACR,OAAD,CALhB;EAQAF,MAAM,CAACK,GAAP,CACE,0BADF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BAAA,CAAYmB,WAJN;QAKVC,OAAO,EAAE;MALC,CAAD,CAAX;IAOD,CAtBD,CAsBE,OAAOlB,GAAP,EAAiB;MACjB;MACAd,IAAI,CAACc,GAAD,CAAJ;IACD;EACF,CApCD;AAqCD"}
|
|
1
|
+
{"version":3,"file":"publish.js","names":["debug","buildDebug","publish","router","auth","storage","can","allow","put","media","mime","getType","expectJson","publishPackage","delete","req","res","next","packageName","params","package","rev","revision","logger","removePackage","status","HTTP_STATUS","CREATED","ok","API_MESSAGE","PKG_REMOVED","err","filename","removeTarball","TARBALL_REMOVED","ac","AbortController","metadata","body","username","remote_user","name","message","updateManifest","signal","requestOptions","host","hostname","protocol","headers","success"],"sources":["../src/publish.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\nimport mime from 'mime';\n\nimport { Auth } from '@verdaccio/auth';\nimport { API_MESSAGE, HTTP_STATUS } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { allow, expectJson, media } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\n// import star from './star';\n\nconst debug = buildDebug('verdaccio:api:publish');\n\n/**\n * Publish a package / update package / un/start a package\n *\n * There are multiples scenarios here to be considered:\n *\n * 1. Publish scenario\n *\n * Publish a package consist of at least 1 step (PUT) with a metadata payload.\n * When a package is published, an _attachment property is present that contains the data\n * of the tarball.\n *\n * Example flow of publish.\n *\n * npm http fetch PUT 201 http://localhost:4873/@scope%2ftest1 9627ms\n npm info lifecycle @scope/test1@1.0.1~publish: @scope/test1@1.0.1\n npm info lifecycle @scope/test1@1.0.1~postpublish: @scope/test1@1.0.1\n + @scope/test1@1.0.1\n npm verb exit [ 0, true ]\n *\n *\n * 2. Unpublish scenario\n *\n * Unpublish consist in 3 steps.\n * 1. Try to fetch metadata -> if it fails, return 404\n * 2. Compute metadata locally (client side) and send a mutate payload excluding the version to\n * be unpublished\n * eg: if metadata reflects 1.0.1, 1.0.2 and 1.0.3, the computed metadata won't include 1.0.3.\n * 3. Once the second step has been successfully finished, delete the tarball.\n *\n * All these steps are consecutive and required, there is no transacions here, if step 3 fails,\n * metadata might get corrupted.\n *\n * Note the unpublish call will suffix in the url a /-rev/14-5d500cfce92f90fd revision number,\n * this not\n * used internally.\n *\n *\n * Example flow of unpublish.\n *\n * There are two possible flows:\n *\n * - Remove all packages (entirely)\n * eg: npm unpublish package-name@* --force\n * eg: npm unpublish package-name --force\n *\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * - Remove a specific version\n * eg: npm unpublish package-name@1.0.0 --force\n *\n * Get fresh manifest\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * Update manifest without the version to be unpublished\n * npm http fetch PUT 201 http://localhost:4873/custom-name/-rev/14-5d500cfce92f90fd 956606ms\n * Get fresh manifest (revision should be different)\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1601ms\n * Remove the tarball\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n * \n * 3. Star a package\n *\n * Permissions: start a package depends of the publish and unpublish permissions, there is no\n * specific flag for star or un start.\n * The URL for star is similar to the unpublish (change package format)\n *\n * npm has no endpoint for star a package, rather mutate the metadata and acts as, the difference\n * is the users property which is part of the payload and the body only includes\n *\n * {\n\t\t \"_id\": pkgName,\n\t \t\"_rev\": \"3-b0cdaefc9bdb77c8\",\n\t\t \"users\": {\n\t\t [username]: boolean value (true, false)\n\t\t }\n\t}\n *\n */\nexport default function publish(router: Router, auth: Auth, storage: Storage): void {\n const can = allow(auth);\n router.put(\n '/:package',\n can('publish'),\n media(mime.getType('json')),\n expectJson,\n publishPackage(storage)\n );\n\n router.put(\n '/:package/-rev/:revision',\n can('unpublish'),\n media(mime.getType('json')),\n expectJson,\n publishPackage(storage)\n );\n\n /**\n * Un-publishing an entire package.\n *\n * This scenario happens when the first call detect there is only one version remaining\n * in the metadata, then the client decides to DELETE the resource\n * npm http fetch GET 304 http://localhost:4873/package-name?write=true 1076ms (from cache)\n * npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n '/:package/-rev/:revision',\n can('unpublish'),\n async function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n const packageName = req.params.package;\n const rev = req.params.revision;\n\n logger.debug({ packageName }, `unpublishing @{packageName}`);\n try {\n await storage.removePackage(packageName, rev);\n debug('package %s unpublished', packageName);\n res.status(HTTP_STATUS.CREATED);\n return next({ ok: API_MESSAGE.PKG_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n\n /*\n Remove a tarball, this happens when npm unpublish a package unique version.\n npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n '/:package/-/:filename/-rev/:revision',\n can('unpublish'),\n can('publish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const packageName = req.params.package;\n const { filename, revision } = req.params;\n\n logger.debug(\n { packageName, filename, revision },\n `removing a tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n try {\n await storage.removeTarball(packageName, filename, revision);\n res.status(HTTP_STATUS.CREATED);\n\n logger.debug(\n { packageName, filename, revision },\n `success remove tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n return next({ ok: API_MESSAGE.TARBALL_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n}\n\nexport function publishPackage(storage: Storage): any {\n return async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const ac = new AbortController();\n const packageName = req.params.package;\n const { revision } = req.params;\n const metadata = req.body;\n const username = req?.remote_user?.name;\n\n try {\n const message = await storage.updateManifest(metadata, {\n name: packageName,\n revision,\n signal: ac.signal,\n requestOptions: {\n host: req.hostname,\n protocol: req.protocol,\n // @ts-ignore\n headers: req.headers,\n username,\n },\n });\n\n res.status(HTTP_STATUS.CREATED);\n\n return next({\n success: true,\n ok: message,\n });\n } catch (err: any) {\n // TODO: review if we need the abort controller here\n next(err);\n }\n };\n}\n"],"mappings":";;;;;;;;AAAA;;AAEA;;AAGA;;AACA;;AACA;;;;AAKA;AAEA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,uBAAX,CAAd;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,OAAT,CAAiBC,MAAjB,EAAiCC,IAAjC,EAA6CC,OAA7C,EAAqE;EAClF,MAAMC,GAAG,GAAG,IAAAC,iBAAA,EAAMH,IAAN,CAAZ;EACAD,MAAM,CAACK,GAAP,CACE,WADF,EAEEF,GAAG,CAAC,SAAD,CAFL,EAGE,IAAAG,iBAAA,EAAMC,aAAA,CAAKC,OAAL,CAAa,MAAb,CAAN,CAHF,EAIEC,sBAJF,EAKEC,cAAc,CAACR,OAAD,CALhB;EAQAF,MAAM,CAACK,GAAP,CACE,0BADF,EAEEF,GAAG,CAAC,WAAD,CAFL,EAGE,IAAAG,iBAAA,EAAMC,aAAA,CAAKC,OAAL,CAAa,MAAb,CAAN,CAHF,EAIEC,sBAJF,EAKEC,cAAc,CAACR,OAAD,CALhB;EAQA;AACF;AACA;A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I,CAACc,GAAD,CAAJ;IACD;EACF,CAnCD;AAoCD"}
|
package/build/user.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Config } from '@verdaccio/types';
|
|
4
|
-
export default function (route: Router, auth:
|
|
4
|
+
export default function (route: Router, auth: Auth, config: Config): void;
|
package/build/user.js
CHANGED
|
@@ -45,7 +45,7 @@ function _default(route, auth, config) {
|
|
|
45
45
|
*
|
|
46
46
|
* @export
|
|
47
47
|
* @param {Router} route
|
|
48
|
-
* @param {
|
|
48
|
+
* @param {Auth} auth
|
|
49
49
|
* @param {Config} config
|
|
50
50
|
*/
|
|
51
51
|
|
|
@@ -71,7 +71,7 @@ function _default(route, auth, config) {
|
|
|
71
71
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNAUTHORIZED, _core.API_ERROR.BAD_USERNAME_PASSWORD));
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const restoredRemoteUser = (0, _config.createRemoteUser)(name, user.groups || []);
|
|
74
|
+
const restoredRemoteUser = (0, _config.createRemoteUser)(name, (user === null || user === void 0 ? void 0 : user.groups) || []);
|
|
75
75
|
const token = await (0, _auth.getApiToken)(auth, config, restoredRemoteUser, password);
|
|
76
76
|
debug('login: new token');
|
|
77
77
|
|
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 {
|
|
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 { API_ERROR, API_MESSAGE, HTTP_STATUS, errorUtils, validatioUtils } 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\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 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;;AACA;;AAEA;;;;AAIA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,oBAAX,CAAd;;AAEe,kBAAUC,KAAV,EAAyBC,IAAzB,EAAqCC,MAArC,EAA2D;EACxEF,KAAK,CAACG,GAAN,CACE,2BADF,EAEE,UAAUC,GAAV,EAA+BC,GAA/B,EAA8CC,IAA9C,EAA4E;IAC1ER,KAAK,CAAC,gBAAD,CAAL;IACA,MAAMS,OAAO,GAAG,IAAAC,8BAAA,EAAwBJ,GAAG,CAACK,WAAJ,CAAgBC,IAAxC,CAAhB;IACAZ,KAAK,CAAC,+BAAD,EAAkCS,OAAlC,CAAL;IACAF,GAAG,CAACM,MAAJ,CAAWC,iBAAA,CAAYC,EAAvB;IACAP,IAAI,CAAC;MACHQ,EAAE,EAAEP;IADD,CAAD,CAAJ;EAGD,CAVH;EAaA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EACEP,KAAK,CAACe,GAAN,CACE,6CADF,EAEE,UAAUX,GAAV,EAA+BC,GAA/B,EAA8CC,IAA9C,EAA4E;IAAA;;IAC1E,MAAM;MAAEI,IAAF;MAAQM;IAAR,IAAqBZ,GAAG,CAACa,IAA/B;IACAnB,KAAK,CAAC,kBAAD,CAAL;IACA,MAAMoB,UAAU,GAAGd,GAAH,aAAGA,GAAH,2CAAGA,GAAG,CAAEK,WAAR,qDAAG,iBAAkBC,IAArC;;I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AAG,CAACM,MAAJ,CAAWC,iBAAA,CAAYwB,OAAvB;QACAtC,KAAK,CAAC,gCAAD,CAAL;QACA,OAAOQ,IAAI,CAAC;UACVQ,EAAE,EAAG,SAAQV,GAAG,CAACa,IAAJ,CAASP,IAAK,WADjB;UAEVuB;QAFU,CAAD,CAAX;MAID,CAhCD;IAiCD;EACF,CAvFH;EA0FAjC,KAAK,CAACgD,MAAN,CACE,iBADF,EAEE,UAAU5C,GAAV,EAA+BC,GAA/B,EAA8CC,IAA9C,EAA4E;IAC1ED,GAAG,CAACM,MAAJ,CAAWC,iBAAA,CAAYC,EAAvB;IACAP,IAAI,CAAC;MACHQ,EAAE,EAAEmC,iBAAA,CAAYC;IADb,CAAD,CAAJ;EAGD,CAPH;AASD"}
|
package/build/v1/profile.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Config } from '@verdaccio/types';
|
|
4
4
|
export interface Profile {
|
|
5
5
|
tfa: boolean;
|
|
@@ -11,4 +11,4 @@ export interface Profile {
|
|
|
11
11
|
cidr_whitelist: string[] | null;
|
|
12
12
|
fullname: string;
|
|
13
13
|
}
|
|
14
|
-
export default function (route: Router, auth:
|
|
14
|
+
export default function (route: Router, auth: Auth, config: Config): void;
|
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 {
|
|
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;;;;AAuBe,kBAAUA,KAAV,EAAyBC,IAAzB,EAAqCC,MAArC,EAA2D;EACxE,SAASC,YAAT,CAAsBC,IAAtB,EAA6C;IAC3C,OAAO;MACLC,GAAG,EAAE,KADA;MAELD,IAFK;MAGLE,KAAK,EAAE,EAHF;MAILC,cAAc,EAAE,KAJX;MAKLC,OAAO,EAAE,EALJ;MAMLC,OAAO,EAAE,EANJ;MAOLC,cAAc,EAAE,IAPX;MAQLC,QAAQ,EAAE;IARL,CAAP;EAUD;;EAEDX,KAAK,CAACY,GAAN,CACE,gBADF,EAEE,UAAUC,GAAV,EAA+BC,GAA/B,EAA8CC,IAA9C,EAA4E;IAC1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AIE,CAACQ,GAAD,EAAMC,SAAN,KAAsC;QACpC,IAAIvB,eAAA,CAAEwB,MAAF,CAASF,GAAT,MAAkB,KAAtB,EAA6B;UAC3B,OAAOvB,IAAI,CACTkB,gBAAA,CAAWC,OAAX,CAAmBI,GAAG,CAACnB,MAAvB,EAA+BmB,GAAG,CAAChB,OAAnC,KAA+CW,gBAAA,CAAWQ,WAAX,CAAuBH,GAAG,CAAChB,OAA3B,CADtC,CAAX;QAGD;;QAED,IAAIiB,SAAJ,EAAe;UACb,OAAOxB,IAAI,CAACZ,YAAY,CAACU,GAAG,CAACK,WAAJ,CAAgBd,IAAjB,CAAb,CAAX;QACD;;QACD,OAAOW,IAAI,CAACkB,gBAAA,CAAWS,gBAAX,CAA4BnB,eAAA,CAAUoB,qBAAtC,CAAD,CAAX;MACD,CAfH;IAiBD,CA7BD,MA6BO,IAAI3B,eAAA,CAAEC,KAAF,CAAQZ,GAAR,MAAiB,KAArB,EAA4B;MACjC,OAAOU,IAAI,CACTkB,gBAAA,CAAWC,OAAX,CAAmBd,iBAAA,CAAYwB,mBAA/B,EAAoDC,oBAAA,CAAeC,YAAnE,CADS,CAAX;IAGD,CAJM,MAIA;MACL,OAAO/B,IAAI,CAACkB,gBAAA,CAAWC,OAAX,CAAmBd,iBAAA,CAAY2B,cAA/B,EAA+CC,eAAA,CAAUC,aAAzD,CAAD,CAAX;IACD;EACF,CAjDH;AAmDD"}
|
package/build/v1/search.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Auth } from '@verdaccio/auth';
|
|
2
2
|
import { Storage } from '@verdaccio/store';
|
|
3
3
|
/**
|
|
4
4
|
* Endpoint for npm search v1
|
|
@@ -6,4 +6,4 @@ import { Storage } from '@verdaccio/store';
|
|
|
6
6
|
* - {"objects":[],"total":0,"time":"Sun Jul 25 2021 14:09:11 GMT+0000 (Coordinated Universal Time)"}
|
|
7
7
|
* req: 'GET /-/v1/search?text=react&size=20&frpom=0&quality=0.65&popularity=0.98&maintenance=0.5'
|
|
8
8
|
*/
|
|
9
|
-
export default function (route: any, auth:
|
|
9
|
+
export default function (route: any, auth: Auth, storage: Storage): void;
|
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","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 {
|
|
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","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.on('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;;;;AAIA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,sBAAX,CAAd;AAEA;AACA;AACA;AACA;AACA;AACA;;AACe,kBAAUC,KAAV,EAAiBC,IAAjB,EAA6BC,OAA7B,EAAqD;EAClE,SAASC,WAAT,CAAqBC,GAArB,EAA+BH,IAA/B,EAA0CI,UAA1C,EAAgF;IAC9E,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MAAA;;MACtCP,IAAI,CAACQ,YAAL,CAAkB;QAAEC,WAAW,EAAEN,GAAF,aAAEA,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,eAAD,CAAL;MACA,MAAMoC,mBAAgD,GAAG,MAAM5B,OAAO,CAAC6B,GAAR,CAC7DP,IAAI,CAACF,GAAL,CAAUU,OAAD,IAAa;QACpB,OAAOjC,WAAW,CAACiC,OAAD,EAAUnC,IAAV,EAAgBkB,GAAG,CAACkB,WAApB,CAAlB;MACD,CAFD,CAD6D,CAA/D;MAMA,MAAMC,KAAkC,GAAGJ,mBAAmB,CAC3DK,MADwC,CAChCC,CAAD,IAAO,CAACC,eAAA,CAAEC,MAAF,CAASF,CAAT,CADyB,EAExCG,KAFwC,CAElClB,IAFkC,EAE5BD,IAF4B,CAA3C;;MAGAoB,cAAA,CAAO9C,KAAP,CAAc,kBAAiBwC,KAAlB,aAAkBA,KAAlB,uBAAkBA,KAAK,CAAEO,MAAO,EAA7C;;MAEA,MAAMC,QAAmC,GAAG;QAC1CC,OAAO,EAAET,KADiC;QAE1CU,KAAK,EAAEV,KAAK,CAACO,MAF6B;QAG1CI,IAAI,EAAE,IAAIC,IAAJ,GAAWC,WAAX;MAHoC,CAA5C;MAMA/B,GAAG,CAACL,MAAJ,CAAWqC,iBAAA,CAAYC,EAAvB,EAA2BC,IAA3B,CAAgCR,QAAhC;IACD,CAzBD,CAyBE,OAAOS,KAAP,EAAc;MACdX,cAAA,CAAOW,KAAP,CAAa;QAAEA;MAAF,CAAb,EAAwB,6CAAxB;;MACAlC,IAAI,CAACA,IAAD,CAAJ;MACA;IACD;EACF,CA3CD;AA4CD"}
|
package/build/v1/token.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Storage } from '@verdaccio/store';
|
|
4
4
|
import { Config, Token } from '@verdaccio/types';
|
|
5
5
|
export declare type NormalizeToken = Token & {
|
|
6
6
|
created: string;
|
|
7
7
|
};
|
|
8
|
-
export default function (route: Router, auth:
|
|
8
|
+
export default function (route: Router, auth: Auth, storage: Storage, config: Config): void;
|
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 {
|
|
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":";;;;;;;AACA;;AAEA;;AAEA;;AACA;;AAGA;;;;AAQA,SAASA,cAAT,CAAwBC,KAAxB,EAAsD;EACpD,OAAO,EACL,GAAGA,KADE;IAELC,OAAO,EAAE,IAAIC,IAAJ,CAASF,KAAK,CAACC,OAAf,EAAwBE,WAAxB;EAFJ,CAAP;AAID,C,CAED;;;AACe,kBAAUC,KAAV,EAAyBC,IAAzB,EAAqCC,OAArC,EAAuDC,MAAvD,EAA6E;EAC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,EAA0BoD,QAA1B,CAAN;;QACA3C,cAAA,CAAO6C,IAAP,CAAY;UAAEF,QAAF;UAAYpD;QAAZ,CAAZ,EAAgC,mDAAhC;;QACA,OAAOD,IAAI,CAAC,EAAD,CAAX;MACD,CAJD,CAIE,OAAOkB,KAAP,EAAmB;QACnBR,cAAA,CAAOQ,KAAP,CAAa;UAAEA,KAAK,EAAEA,KAAK,CAACC;QAAf,CAAb,EAAmC,qCAAnC;;QACA,OAAOnB,IAAI,CAACoB,gBAAA,CAAWC,OAAX,CAAmBR,iBAAA,CAAYS,cAA/B,EAA+CJ,KAAK,CAACK,OAArD,CAAD,CAAX;MACD;IACF;;IACD,OAAOvB,IAAI,CAACoB,gBAAA,CAAWI,eAAX,EAAD,CAAX;EACD,CApBH;AAsBD"}
|
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.32",
|
|
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.28",
|
|
34
|
+
"@verdaccio/config": "6.0.0-6-next.49",
|
|
35
|
+
"@verdaccio/core": "6.0.0-6-next.49",
|
|
36
|
+
"@verdaccio/logger": "6.0.0-6-next.17",
|
|
37
|
+
"@verdaccio/middleware": "6.0.0-6-next.28",
|
|
38
|
+
"@verdaccio/store": "6.0.0-6-next.29",
|
|
39
|
+
"@verdaccio/utils": "6.0.0-6-next.17",
|
|
40
40
|
"abortcontroller-polyfill": "1.7.3",
|
|
41
41
|
"cookies": "0.8.0",
|
|
42
42
|
"debug": "4.3.4",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"semver": "7.3.7"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@types/node": "16.11.
|
|
51
|
-
"@verdaccio/server": "6.0.0-6-next.
|
|
50
|
+
"@types/node": "16.11.62",
|
|
51
|
+
"@verdaccio/server": "6.0.0-6-next.38",
|
|
52
52
|
"@verdaccio/types": "11.0.0-6-next.17",
|
|
53
|
-
"@verdaccio/test-helper": "2.0.0-6-next.
|
|
53
|
+
"@verdaccio/test-helper": "2.0.0-6-next.6",
|
|
54
54
|
"supertest": "6.2.4",
|
|
55
55
|
"nock": "13.2.9",
|
|
56
56
|
"mockdate": "3.0.5"
|
package/src/dist-tags.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { Router } from 'express';
|
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
import mime from 'mime';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Auth } from '@verdaccio/auth';
|
|
6
6
|
import { constants, errorUtils } from '@verdaccio/core';
|
|
7
7
|
import { allow, media } from '@verdaccio/middleware';
|
|
8
8
|
import { Storage } from '@verdaccio/store';
|
|
9
9
|
|
|
10
10
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';
|
|
11
11
|
|
|
12
|
-
export default function (route: Router, auth:
|
|
12
|
+
export default function (route: Router, auth: Auth, storage: Storage): void {
|
|
13
13
|
const can = allow(auth);
|
|
14
14
|
const addTagPackageVersionMiddleware = async function (
|
|
15
15
|
req: $RequestExtend,
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import bodyParser from 'body-parser';
|
|
2
2
|
import express, { Router } from 'express';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { Auth } from '@verdaccio/auth';
|
|
5
5
|
import {
|
|
6
6
|
antiLoop,
|
|
7
7
|
encodeScopePackage,
|
|
@@ -24,7 +24,7 @@ import v1Search from './v1/search';
|
|
|
24
24
|
import token from './v1/token';
|
|
25
25
|
import whoami from './whoami';
|
|
26
26
|
|
|
27
|
-
export default function (config: Config, auth:
|
|
27
|
+
export default function (config: Config, auth: Auth, storage: Storage): Router {
|
|
28
28
|
/* eslint new-cap:off */
|
|
29
29
|
const app = express.Router();
|
|
30
30
|
/* eslint new-cap:off */
|
package/src/package.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import buildDebug from 'debug';
|
|
2
2
|
import { Router } from 'express';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { Auth } from '@verdaccio/auth';
|
|
5
5
|
import { HEADERS, HEADER_TYPE, stringUtils } from '@verdaccio/core';
|
|
6
6
|
import { allow } from '@verdaccio/middleware';
|
|
7
7
|
import { Storage } from '@verdaccio/store';
|
|
@@ -10,7 +10,7 @@ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/cust
|
|
|
10
10
|
|
|
11
11
|
const debug = buildDebug('verdaccio:api:package');
|
|
12
12
|
|
|
13
|
-
export default function (route: Router, auth:
|
|
13
|
+
export default function (route: Router, auth: Auth, storage: Storage): void {
|
|
14
14
|
const can = allow(auth);
|
|
15
15
|
|
|
16
16
|
route.get(
|
package/src/publish.ts
CHANGED
|
@@ -2,7 +2,7 @@ import buildDebug from 'debug';
|
|
|
2
2
|
import { Router } from 'express';
|
|
3
3
|
import mime from 'mime';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Auth } from '@verdaccio/auth';
|
|
6
6
|
import { API_MESSAGE, HTTP_STATUS } from '@verdaccio/core';
|
|
7
7
|
import { logger } from '@verdaccio/logger';
|
|
8
8
|
import { allow, expectJson, media } from '@verdaccio/middleware';
|
|
@@ -11,7 +11,6 @@ import { Storage } from '@verdaccio/store';
|
|
|
11
11
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';
|
|
12
12
|
|
|
13
13
|
// import star from './star';
|
|
14
|
-
// import { isPublishablePackage, isRelatedToDeprecation } from './utils';
|
|
15
14
|
|
|
16
15
|
const debug = buildDebug('verdaccio:api:publish');
|
|
17
16
|
|
|
@@ -93,7 +92,7 @@ const debug = buildDebug('verdaccio:api:publish');
|
|
|
93
92
|
}
|
|
94
93
|
*
|
|
95
94
|
*/
|
|
96
|
-
export default function publish(router: Router, auth:
|
|
95
|
+
export default function publish(router: Router, auth: Auth, storage: Storage): void {
|
|
97
96
|
const can = allow(auth);
|
|
98
97
|
router.put(
|
|
99
98
|
'/:package',
|
|
@@ -177,17 +176,17 @@ export default function publish(router: Router, auth: IAuth, storage: Storage):
|
|
|
177
176
|
export function publishPackage(storage: Storage): any {
|
|
178
177
|
return async function (
|
|
179
178
|
req: $RequestExtend,
|
|
180
|
-
|
|
179
|
+
res: $ResponseExtend,
|
|
181
180
|
next: $NextFunctionVer
|
|
182
181
|
): Promise<void> {
|
|
183
182
|
const ac = new AbortController();
|
|
184
183
|
const packageName = req.params.package;
|
|
185
184
|
const { revision } = req.params;
|
|
186
185
|
const metadata = req.body;
|
|
186
|
+
const username = req?.remote_user?.name;
|
|
187
187
|
|
|
188
188
|
try {
|
|
189
|
-
|
|
190
|
-
await storage.updateManifest(metadata, {
|
|
189
|
+
const message = await storage.updateManifest(metadata, {
|
|
191
190
|
name: packageName,
|
|
192
191
|
revision,
|
|
193
192
|
signal: ac.signal,
|
|
@@ -196,16 +195,15 @@ export function publishPackage(storage: Storage): any {
|
|
|
196
195
|
protocol: req.protocol,
|
|
197
196
|
// @ts-ignore
|
|
198
197
|
headers: req.headers,
|
|
198
|
+
username,
|
|
199
199
|
},
|
|
200
200
|
});
|
|
201
|
-
|
|
201
|
+
|
|
202
|
+
res.status(HTTP_STATUS.CREATED);
|
|
202
203
|
|
|
203
204
|
return next({
|
|
204
|
-
// TODO: this could be also Package Updated based on the
|
|
205
|
-
// action, deprecate, star, publish new version, or create a package
|
|
206
|
-
// the message some return from the method
|
|
207
|
-
ok: API_MESSAGE.PKG_CREATED,
|
|
208
205
|
success: true,
|
|
206
|
+
ok: message,
|
|
209
207
|
});
|
|
210
208
|
} catch (err: any) {
|
|
211
209
|
// TODO: review if we need the abort controller here
|
package/src/user.ts
CHANGED
|
@@ -2,7 +2,7 @@ import buildDebug from 'debug';
|
|
|
2
2
|
import { Response, Router } from 'express';
|
|
3
3
|
|
|
4
4
|
import { getApiToken } from '@verdaccio/auth';
|
|
5
|
-
import {
|
|
5
|
+
import { Auth } from '@verdaccio/auth';
|
|
6
6
|
import { createRemoteUser } from '@verdaccio/config';
|
|
7
7
|
import { API_ERROR, API_MESSAGE, HTTP_STATUS, errorUtils, validatioUtils } from '@verdaccio/core';
|
|
8
8
|
import { logger } from '@verdaccio/logger';
|
|
@@ -13,7 +13,7 @@ import { $NextFunctionVer, $RequestExtend } from '../types/custom';
|
|
|
13
13
|
|
|
14
14
|
const debug = buildDebug('verdaccio:api:user');
|
|
15
15
|
|
|
16
|
-
export default function (route: Router, auth:
|
|
16
|
+
export default function (route: Router, auth: Auth, config: Config): void {
|
|
17
17
|
route.get(
|
|
18
18
|
'/-/user/:org_couchdb_user',
|
|
19
19
|
function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {
|
|
@@ -41,7 +41,7 @@ export default function (route: Router, auth: IAuth, config: Config): void {
|
|
|
41
41
|
*
|
|
42
42
|
* @export
|
|
43
43
|
* @param {Router} route
|
|
44
|
-
* @param {
|
|
44
|
+
* @param {Auth} auth
|
|
45
45
|
* @param {Config} config
|
|
46
46
|
*/
|
|
47
47
|
route.put(
|
|
@@ -67,7 +67,7 @@ export default function (route: Router, auth: IAuth, config: Config): void {
|
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const restoredRemoteUser: RemoteUser = createRemoteUser(name, user
|
|
70
|
+
const restoredRemoteUser: RemoteUser = createRemoteUser(name, user?.groups || []);
|
|
71
71
|
const token = await getApiToken(auth, config, restoredRemoteUser, password);
|
|
72
72
|
debug('login: new token');
|
|
73
73
|
if (!token) {
|
|
@@ -112,7 +112,9 @@ export default function (route: Router, auth: IAuth, config: Config): void {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
const token =
|
|
115
|
-
name && password
|
|
115
|
+
name && password
|
|
116
|
+
? await getApiToken(auth, config, user as RemoteUser, password)
|
|
117
|
+
: undefined;
|
|
116
118
|
if (token) {
|
|
117
119
|
debug('adduser: new token %o', mask(token as string, 4));
|
|
118
120
|
}
|
package/src/v1/profile.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Response, Router } from 'express';
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { Auth } from '@verdaccio/auth';
|
|
5
5
|
import {
|
|
6
6
|
API_ERROR,
|
|
7
7
|
APP_ERROR,
|
|
@@ -25,7 +25,7 @@ export interface Profile {
|
|
|
25
25
|
fullname: string;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export default function (route: Router, auth:
|
|
28
|
+
export default function (route: Router, auth: Auth, config: Config): void {
|
|
29
29
|
function buildProfile(name: string): Profile {
|
|
30
30
|
return {
|
|
31
31
|
tfa: false,
|
package/src/v1/search.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import buildDebug from 'debug';
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { Auth } from '@verdaccio/auth';
|
|
5
5
|
import { HTTP_STATUS, searchUtils } from '@verdaccio/core';
|
|
6
6
|
import { logger } from '@verdaccio/logger';
|
|
7
7
|
import { Storage } from '@verdaccio/store';
|
|
@@ -15,7 +15,7 @@ const debug = buildDebug('verdaccio:api:search');
|
|
|
15
15
|
* - {"objects":[],"total":0,"time":"Sun Jul 25 2021 14:09:11 GMT+0000 (Coordinated Universal Time)"}
|
|
16
16
|
* req: 'GET /-/v1/search?text=react&size=20&frpom=0&quality=0.65&popularity=0.98&maintenance=0.5'
|
|
17
17
|
*/
|
|
18
|
-
export default function (route, auth:
|
|
18
|
+
export default function (route, auth: Auth, storage: Storage): void {
|
|
19
19
|
function checkAccess(pkg: any, auth: any, remoteUser): Promise<Manifest | null> {
|
|
20
20
|
return new Promise((resolve, reject) => {
|
|
21
21
|
auth.allow_access({ packageName: pkg?.package?.name }, remoteUser, function (err, allowed) {
|
package/src/v1/token.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Response, Router } from 'express';
|
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
|
|
4
4
|
import { getApiToken } from '@verdaccio/auth';
|
|
5
|
-
import {
|
|
5
|
+
import { Auth } from '@verdaccio/auth';
|
|
6
6
|
import { HTTP_STATUS, SUPPORT_ERRORS, errorUtils } from '@verdaccio/core';
|
|
7
7
|
import { logger } from '@verdaccio/logger';
|
|
8
8
|
import { Storage } from '@verdaccio/store';
|
|
@@ -23,7 +23,7 @@ function normalizeToken(token: Token): NormalizeToken {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// https://github.com/npm/npm-profile/blob/latest/lib/index.js
|
|
26
|
-
export default function (route: Router, auth:
|
|
26
|
+
export default function (route: Router, auth: Auth, storage: Storage, config: Config): void {
|
|
27
27
|
route.get(
|
|
28
28
|
'/-/npm/v1/tokens',
|
|
29
29
|
async function (req: $RequestExtend, res: Response, next: $NextFunctionVer) {
|
|
@@ -61,7 +61,7 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C
|
|
|
61
61
|
return next(errorUtils.getCode(HTTP_STATUS.BAD_DATA, SUPPORT_ERRORS.PARAMETERS_NOT_VALID));
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
auth.authenticate(name, password, async (err, user
|
|
64
|
+
auth.authenticate(name, password, async (err, user?: RemoteUser) => {
|
|
65
65
|
if (err) {
|
|
66
66
|
const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;
|
|
67
67
|
return next(errorUtils.getCode(errorCode, err.message));
|
|
@@ -76,7 +76,7 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
try {
|
|
79
|
-
const token = await getApiToken(auth, config, user, password);
|
|
79
|
+
const token = await getApiToken(auth, config, user as RemoteUser, password);
|
|
80
80
|
if (!token) {
|
|
81
81
|
throw errorUtils.getInternalError();
|
|
82
82
|
}
|
|
@@ -160,13 +160,13 @@ describe('publish', () => {
|
|
|
160
160
|
decodeURIComponent(pkgName),
|
|
161
161
|
'1.0.1-patch'
|
|
162
162
|
).expect(HTTP_STATUS.CREATED);
|
|
163
|
-
expect(response.body.ok).toEqual(API_MESSAGE.
|
|
163
|
+
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
164
164
|
const response2 = await publishVersion(
|
|
165
165
|
app,
|
|
166
166
|
decodeURIComponent(pkgName),
|
|
167
167
|
'1.0.2-patch'
|
|
168
168
|
).expect(HTTP_STATUS.CREATED);
|
|
169
|
-
expect(response2.body.ok).toEqual(API_MESSAGE.
|
|
169
|
+
expect(response2.body.ok).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
170
170
|
}
|
|
171
171
|
);
|
|
172
172
|
});
|