@verdaccio/web 6.0.0-6-next.35 → 6.0.0-6-next.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/build/api/package.d.ts +2 -2
- package/build/api/package.js +1 -1
- package/build/api/package.js.map +1 -1
- package/build/api/readme.d.ts +2 -2
- package/build/api/readme.js.map +1 -1
- package/build/api/search.d.ts +2 -2
- package/build/api/search.js.map +1 -1
- package/build/api/sidebar.d.ts +2 -2
- package/build/api/sidebar.js.map +1 -1
- package/build/api/user.d.ts +2 -2
- package/build/api/user.js.map +1 -1
- package/build/middleware/render-web.d.ts +1 -1
- package/build/middleware/render-web.js +1 -2
- package/build/middleware/render-web.js.map +1 -1
- package/build/middleware/web-api.d.ts +2 -2
- package/build/middleware/web-api.js.map +1 -1
- package/package.json +16 -16
- package/src/api/package.ts +3 -3
- package/src/api/readme.ts +2 -2
- package/src/api/search.ts +2 -2
- package/src/api/sidebar.ts +2 -2
- package/src/api/user.ts +27 -16
- package/src/middleware/render-web.ts +1 -2
- package/src/middleware/web-api.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @verdaccio/web
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.36
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [ce013d2f]
|
|
8
|
+
- @verdaccio/url@11.0.0-6-next.15
|
|
9
|
+
- @verdaccio/store@6.0.0-6-next.29
|
|
10
|
+
- @verdaccio/tarball@11.0.0-6-next.18
|
|
11
|
+
- @verdaccio/core@6.0.0-6-next.49
|
|
12
|
+
- @verdaccio/config@6.0.0-6-next.49
|
|
13
|
+
- @verdaccio/auth@6.0.0-6-next.28
|
|
14
|
+
- @verdaccio/loaders@6.0.0-6-next.18
|
|
15
|
+
- @verdaccio/logger@6.0.0-6-next.17
|
|
16
|
+
- @verdaccio/middleware@6.0.0-6-next.28
|
|
17
|
+
- @verdaccio/utils@6.0.0-6-next.17
|
|
18
|
+
|
|
3
19
|
## 6.0.0-6-next.35
|
|
4
20
|
|
|
5
21
|
### Major Changes
|
package/build/api/package.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware';
|
|
4
4
|
import { Storage } from '@verdaccio/store';
|
|
5
5
|
import { Config } from '@verdaccio/types';
|
|
6
6
|
export { $RequestExtend, $ResponseExtend, $NextFunctionVer };
|
|
7
|
-
declare function addPackageWebApi(storage: Storage, auth:
|
|
7
|
+
declare function addPackageWebApi(storage: Storage, auth: Auth, config: Config): Router;
|
|
8
8
|
export default addPackageWebApi;
|
package/build/api/package.js
CHANGED
package/build/api/package.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","names":["getOrder","order","debug","buildDebug","addPackageWebApi","storage","auth","config","isLoginEnabled","web","login","pkgRouter","Router","anonymousRemoteUser","name","undefined","real_groups","groups","checkAllow","remoteUser","Promise","resolve","reject","allow_access","packageName","err","allowed","processPackages","packages","req","permissions","packagesToProcess","slice","pkg","pkgCopy","author","formatAuthor","remote_user","avatar","generateGravatarUrl","email","gravatar","_","isNil","dist","isNull","tarball","getLocalRegistryTarballUri","protocol","headers","host","hostname","url_prefix","push","logger","error","get","res","next","localPackages","getLocalDatabaseNext","sort_packages","pkgs","sortByName"],"sources":["../../src/api/package.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\nimport _ from 'lodash';\n\nimport {
|
|
1
|
+
{"version":3,"file":"package.js","names":["getOrder","order","debug","buildDebug","addPackageWebApi","storage","auth","config","isLoginEnabled","web","login","pkgRouter","Router","anonymousRemoteUser","name","undefined","real_groups","groups","checkAllow","remoteUser","Promise","resolve","reject","allow_access","packageName","err","allowed","processPackages","packages","req","permissions","packagesToProcess","slice","pkg","pkgCopy","author","formatAuthor","remote_user","avatar","generateGravatarUrl","email","gravatar","_","isNil","dist","isNull","tarball","getLocalRegistryTarballUri","protocol","headers","host","hostname","url_prefix","push","logger","error","get","res","next","localPackages","getLocalDatabaseNext","sort_packages","pkgs","sortByName"],"sources":["../../src/api/package.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport { logger } from '@verdaccio/logger';\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { getLocalRegistryTarballUri } from '@verdaccio/tarball';\nimport { Config, RemoteUser, Version } from '@verdaccio/types';\nimport { formatAuthor, generateGravatarUrl } from '@verdaccio/utils';\n\nimport { sortByName } from '../utils/web-utils';\n\nexport { $RequestExtend, $ResponseExtend, $NextFunctionVer }; // Was required by other packages\n\nconst getOrder = (order = 'asc') => {\n return order === 'asc';\n};\n\nconst debug = buildDebug('verdaccio:web:api:package');\n\nfunction addPackageWebApi(storage: Storage, auth: Auth, config: Config): Router {\n const isLoginEnabled = config?.web?.login === true ?? true;\n const pkgRouter = Router(); /* eslint new-cap: 0 */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const anonymousRemoteUser: RemoteUser = {\n name: undefined,\n real_groups: [],\n groups: [],\n };\n\n debug('initialized package web api');\n const checkAllow = (name: string, remoteUser: RemoteUser): Promise<boolean> =>\n new Promise((resolve, reject): void => {\n debug('is login disabled %o', isLoginEnabled);\n // FIXME: this logic does not work, review\n // const remoteUserAccess = !isLoginEnabled ? anonymousRemoteUser : remoteUser;\n try {\n auth.allow_access({ packageName: name }, remoteUser, (err, allowed): void => {\n if (err) {\n resolve(false);\n }\n return resolve(allowed as boolean);\n });\n } catch (err: any) {\n reject(err);\n }\n });\n\n async function processPackages(packages: Version[] = [], req): Promise<Version[]> {\n const permissions: Version[] = [];\n const packagesToProcess = packages.slice();\n debug('process packages %o', packagesToProcess);\n for (const pkg of packagesToProcess) {\n const pkgCopy = { ...pkg };\n pkgCopy.author = formatAuthor(pkg.author);\n try {\n if (await checkAllow(pkg.name, req.remote_user)) {\n if (config.web) {\n // @ts-ignore\n pkgCopy.author.avatar = generateGravatarUrl(pkgCopy.author.email, config.web.gravatar);\n }\n // convert any remote dist to a local reference\n // eg: if the dist points to npmjs, switch to localhost:4873/prefix/etc.tar.gz\n if (!_.isNil(pkgCopy.dist) && !_.isNull(pkgCopy.dist.tarball)) {\n pkgCopy.dist.tarball = getLocalRegistryTarballUri(\n pkgCopy.dist.tarball,\n pkg.name,\n { protocol: req.protocol, headers: req.headers as any, host: req.hostname },\n config?.url_prefix\n );\n }\n permissions.push(pkgCopy);\n }\n } catch (err: any) {\n debug('process packages error %o', err);\n logger.error(\n { name: pkg.name, error: err },\n 'permission process for @{name} has failed: @{error}'\n );\n throw err;\n }\n }\n\n return permissions;\n }\n\n // Get list of all visible package\n pkgRouter.get(\n '/packages',\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug('hit package web api %o');\n\n try {\n const localPackages: Version[] = await storage.getLocalDatabaseNext();\n\n const order = getOrder(config?.web?.sort_packages);\n debug('order %o', order);\n const pkgs = await processPackages(localPackages, req);\n next(sortByName(pkgs, order));\n } catch (error: any) {\n next(error);\n }\n }\n );\n\n return pkgRouter;\n}\n\nexport default addPackageWebApi;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAGA;;AACA;;AAEA;;AAEA;;AAEA;;;;AAE8D;AAE9D,MAAMA,QAAQ,GAAG,CAACC,KAAK,GAAG,KAAT,KAAmB;EAClC,OAAOA,KAAK,KAAK,KAAjB;AACD,CAFD;;AAIA,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAW,2BAAX,CAAd;;AAEA,SAASC,gBAAT,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AkE9E;;;EACAnB,SAAS,CAAC6C,GAAV,CACE,WADF,EAEE,gBACE3B,GADF,EAEE4B,GAFF,EAGEC,IAHF,EAIiB;IACfxD,KAAK,CAAC,wBAAD,CAAL;;IAEA,IAAI;MAAA;;MACF,MAAMyD,aAAwB,GAAG,MAAMtD,OAAO,CAACuD,oBAAR,EAAvC;MAEA,MAAM3D,KAAK,GAAGD,QAAQ,CAACO,MAAD,aAACA,MAAD,uCAACA,MAAM,CAAEE,GAAT,iDAAC,aAAaoD,aAAd,CAAtB;MACA3D,KAAK,CAAC,UAAD,EAAaD,KAAb,CAAL;MACA,MAAM6D,IAAI,GAAG,MAAMnC,eAAe,CAACgC,aAAD,EAAgB9B,GAAhB,CAAlC;MACA6B,IAAI,CAAC,IAAAK,oBAAA,EAAWD,IAAX,EAAiB7D,KAAjB,CAAD,CAAJ;IACD,CAPD,CAOE,OAAOsD,KAAP,EAAmB;MACnBG,IAAI,CAACH,KAAD,CAAJ;IACD;EACF,CAnBH;EAsBA,OAAO5C,SAAP;AACD;;eAEcP,gB"}
|
package/build/api/readme.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware';
|
|
4
4
|
import { Storage } from '@verdaccio/store';
|
|
5
5
|
import { Manifest } from '@verdaccio/types';
|
|
@@ -12,5 +12,5 @@ export declare type PackageExt = Manifest & {
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
export declare const NOT_README_FOUND = "ERROR: No README data found!";
|
|
15
|
-
declare function addReadmeWebApi(storage: Storage, auth:
|
|
15
|
+
declare function addReadmeWebApi(storage: Storage, auth: Auth): Router;
|
|
16
16
|
export default addReadmeWebApi;
|
package/build/api/readme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readme.js","names":["debug","buildDebug","NOT_README_FOUND","addReadmeWebApi","storage","auth","can","allow","pkgRouter","Router","get","req","res","next","name","params","scope","addScope","package","requestOptions","protocol","headers","host","remoteAddress","socket","manifest","getPackageByOptions","uplinksLook","abbreviated","set","HEADER_TYPE","CONTENT_TYPE","HEADERS","TEXT_PLAIN_UTF8","parseReadme","readme","sanitizyReadme","err"],"sources":["../../src/api/readme.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\n\nimport {
|
|
1
|
+
{"version":3,"file":"readme.js","names":["debug","buildDebug","NOT_README_FOUND","addReadmeWebApi","storage","auth","can","allow","pkgRouter","Router","get","req","res","next","name","params","scope","addScope","package","requestOptions","protocol","headers","host","remoteAddress","socket","manifest","getPackageByOptions","uplinksLook","abbreviated","set","HEADER_TYPE","CONTENT_TYPE","HEADERS","TEXT_PLAIN_UTF8","parseReadme","readme","sanitizyReadme","err"],"sources":["../../src/api/readme.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport { HEADERS, HEADER_TYPE } from '@verdaccio/core';\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend, allow } from '@verdaccio/middleware';\nimport sanitizyReadme from '@verdaccio/readme';\nimport { Storage } from '@verdaccio/store';\nimport { Manifest } from '@verdaccio/types';\n\nimport { AuthorAvatar, addScope, parseReadme } from '../utils/web-utils';\n\nexport { $RequestExtend, $ResponseExtend, $NextFunctionVer }; // Was required by other packages\n\n// TODO: review this type, should be on @verdacid/types\nexport type PackageExt = Manifest & { author: AuthorAvatar; dist?: { tarball: string } };\n\nconst debug = buildDebug('verdaccio:web:api:readme');\n\nexport const NOT_README_FOUND = 'ERROR: No README data found!';\n\nfunction addReadmeWebApi(storage: Storage, auth: Auth): Router {\n debug('initialized readme web api');\n const can = allow(auth);\n const pkgRouter = Router(); /* eslint new-cap: 0 */\n\n pkgRouter.get(\n '/package/readme/(@:scope/)?:package/:version?',\n can('access'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug('readme hit');\n const name = req.params.scope\n ? addScope(req.params.scope, req.params.package)\n : req.params.package;\n debug('readme name %o', name);\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 abbreviated: false,\n requestOptions,\n })) as Manifest;\n debug('readme pkg %o', manifest?.name);\n res.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_PLAIN_UTF8);\n try {\n next(parseReadme(manifest.name, manifest.readme as string));\n } catch {\n next(sanitizyReadme(NOT_README_FOUND));\n }\n } catch (err) {\n next(err);\n }\n }\n );\n return pkgRouter;\n}\n\nexport default addReadmeWebApi;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAGA;;AACA;;AACA;;AAIA;;;;AAOA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,0BAAX,CAAd;AAEO,MAAMC,gBAAgB,GAAG,8BAAzB;;;AAEP,SAASC,eAAT,CAAyBC,OAAzB,EAA2CC,IAA3C,EAA+D;EAC7DL,KAAK,CAAC,4BAAD,CAAL;EACA,MAAMM,GAAG,GAAG,IAAAC,iBAAA,EAAMF,IAAN,CAAZ;EACA,MAAMG,SAAS,GAAG,IAAAC,eAAA,GAAlB;EAA4B;;EAE5BD,SAAS,CAACE,GAAV,CACE,+CADF,EAEEJ,GAAG,CAAC,QAAD,CAFL,EAGE,gBACEK,GADF,EAEEC,GAFF,EAGEC,IAHF,EAIiB;IACfb,KAAK,CAAC,YAAD,CAAL;IACA,MAAMc,IAAI,GAAGH,GAAG,CAACI,MAAJ,CAAWC,KAAX,GACT,IAAAC,kBAAA,EAASN,GAAG,CAACI,MAAJ,CAAWC,KAApB,EAA2BL,GAAG,CAACI,MAAJ,CAAWG,OAAtC,CADS,GAETP,GAAG,CAACI,MAAJ,CAAWG,OAFf;IAGAlB,KAAK,CAAC,gBAAD,EAAmBc,IAAnB,CAAL;IACA,MAAMK,cAAc,GAAG;MACrBC,QAAQ,EAAET,GAAG,CAACS,QADO;MAErBC,OAAO,EAAEV,GAAG,CAACU,OAFQ;MAGrB;MACAC,IAAI,EAAEX,GAAG,CAACW,IAJW;MAKrBC,aAAa,EAAEZ,GAAG,CAACa,MAAJ,CAAWD;IALL,CAAvB;;IAOA,IAAI;MACF,MAAME,QAAQ,GAAI,MAAMrB,OAAO,CAACsB,mBAAR,CAA4B;QAClDZ,IADkD;QAElDa,WAAW,EAAE,IAFqC;QAGlDC,WAAW,EAAE,KAHqC;QAIlDT;MAJkD,CAA5B,CAAxB;MAMAnB,KAAK,CAAC,eAAD,EAAkByB,QAAlB,aAAkBA,QAAlB,uBAAkBA,QAAQ,CAAEX,IAA5B,CAAL;MACAF,GAAG,CAACiB,GAAJ,CAAQC,iBAAA,CAAYC,YAApB,EAAkCC,aAAA,CAAQC,eAA1C;;MACA,IAAI;QACFpB,IAAI,CAAC,IAAAqB,qBAAA,EAAYT,QAAQ,CAACX,IAArB,EAA2BW,QAAQ,CAACU,MAApC,CAAD,CAAJ;MACD,CAFD,CAEE,MAAM;QACNtB,IAAI,CAAC,IAAAuB,eAAA,EAAelC,gBAAf,CAAD,CAAJ;MACD;IACF,CAdD,CAcE,OAAOmC,GAAP,EAAY;MACZxB,IAAI,CAACwB,GAAD,CAAJ;IACD;EACF,CArCH;EAuCA,OAAO7B,SAAP;AACD;;eAEcL,e"}
|
package/build/api/search.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
|
-
declare function addSearchWebApi(storage: Storage, auth:
|
|
4
|
+
declare function addSearchWebApi(storage: Storage, auth: Auth): Router;
|
|
5
5
|
export default addSearchWebApi;
|
package/build/api/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","names":["debug","buildDebug","checkAccess","pkg","auth","remoteUser","Promise","resolve","reject","allow_access","packageName","package","name","err","allowed","status","String","match","addSearchWebApi","storage","router","Router","get","req","res","next","data","abort","AbortController","on","text","params","anything","size","from","query","maintenance","popularity","quality","urlParams","URLSearchParams","search","url","toString","checkAccessPromises","all","map","pkgItem","remote_user","final","filter","i","_","isNull","slice","errorUtils","getInternalError","message"],"sources":["../../src/api/search.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\nimport _ from 'lodash';\nimport { URLSearchParams } from 'url';\n\nimport {
|
|
1
|
+
{"version":3,"file":"search.js","names":["debug","buildDebug","checkAccess","pkg","auth","remoteUser","Promise","resolve","reject","allow_access","packageName","package","name","err","allowed","status","String","match","addSearchWebApi","storage","router","Router","get","req","res","next","data","abort","AbortController","on","text","params","anything","size","from","query","maintenance","popularity","quality","urlParams","URLSearchParams","search","url","toString","checkAccessPromises","all","map","pkgItem","remote_user","final","filter","i","_","isNull","slice","errorUtils","getInternalError","message"],"sources":["../../src/api/search.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\nimport _ from 'lodash';\nimport { URLSearchParams } from 'url';\n\nimport { Auth } from '@verdaccio/auth';\nimport { errorUtils, searchUtils } from '@verdaccio/core';\nimport { SearchQuery } from '@verdaccio/core/src/search-utils';\nimport { Storage } from '@verdaccio/store';\nimport { Manifest } from '@verdaccio/types';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from './package';\n\nconst debug = buildDebug('verdaccio:web:api:search');\n\nfunction 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\nfunction addSearchWebApi(storage: Storage, auth: Auth): Router {\n const router = Router(); /* eslint new-cap: 0 */\n router.get(\n '/search/:anything',\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n try {\n let data;\n const abort = new AbortController();\n req.on('aborted', () => {\n debug('search web aborted');\n abort.abort();\n });\n const text: string = (req.params.anything as string) ?? '';\n // These values are declared as optimal by npm cli\n // FUTURE: could be overwritten by ui settings.\n const size = 20;\n const from = 0;\n const query: SearchQuery = {\n from: 0,\n maintenance: 0.5,\n popularity: 0.98,\n quality: 0.65,\n size: 20,\n text,\n };\n // @ts-ignore\n const urlParams = new URLSearchParams(query);\n debug('search web init');\n data = await storage?.search({\n query,\n url: `/-/v1/search?${urlParams.toString()}`,\n abort,\n });\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\n next(final);\n } catch (err: any) {\n next(errorUtils.getInternalError(err.message));\n }\n }\n );\n return router;\n}\n\nexport default addSearchWebApi;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGA;;;;AAOA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,0BAAX,CAAd;;AAEA,SAASC,WAAT,CAAqBC,GAArB,EAA+BC,IAA/B,EAA0CC,UAA1C,EAAgF;EAC9E,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;IAAA;;IACtCJ,IAAI,CAACK,YAAL,CAAkB;MAAEC,WAAW,EAAEP,GAAF,aAAEA,GAAF,uCAAEA,GAAG,CAAEQ,OAAP,iDAAE,aAA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,oBAAJ,CAAoBL,KAApB,CAAlB;MACAnC,KAAK,CAAC,iBAAD,CAAL;MACA0B,IAAI,GAAG,OAAMP,OAAN,aAAMA,OAAN,uBAAMA,OAAO,CAAEsB,MAAT,CAAgB;QAC3BN,KAD2B;QAE3BO,GAAG,EAAG,gBAAeH,SAAS,CAACI,QAAV,EAAqB,EAFf;QAG3BhB;MAH2B,CAAhB,CAAN,CAAP;MAKA,MAAMiB,mBAAgD,GAAG,MAAMtC,OAAO,CAACuC,GAAR,CAC7DnB,IAAI,CAACoB,GAAL,CAAUC,OAAD,IAAa;QACpB,OAAO7C,WAAW,CAAC6C,OAAD,EAAU3C,IAAV,EAAgBmB,GAAG,CAACyB,WAApB,CAAlB;MACD,CAFD,CAD6D,CAA/D;MAMA,MAAMC,KAAkC,GAAGL,mBAAmB,CAC3DM,MADwC,CAChCC,CAAD,IAAO,CAACC,eAAA,CAAEC,MAAF,CAASF,CAAT,CADyB,EAExCG,KAFwC,CAElCpB,IAFkC,EAE5BD,IAF4B,CAA3C;MAIAR,IAAI,CAACwB,KAAD,CAAJ;IACD,CAvCD,CAuCE,OAAOpC,GAAP,EAAiB;MACjBY,IAAI,CAAC8B,gBAAA,CAAWC,gBAAX,CAA4B3C,GAAG,CAAC4C,OAAhC,CAAD,CAAJ;IACD;EACF,CAjDH;EAmDA,OAAOrC,MAAP;AACD;;eAEcF,e"}
|
package/build/api/sidebar.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware';
|
|
4
4
|
import { Storage } from '@verdaccio/store';
|
|
5
5
|
import { Config, Manifest, Version } from '@verdaccio/types';
|
|
@@ -14,5 +14,5 @@ export declare type PackageExt = Manifest & {
|
|
|
14
14
|
export declare type $SidebarPackage = Manifest & {
|
|
15
15
|
latest: Version;
|
|
16
16
|
};
|
|
17
|
-
declare function addSidebarWebApi(config: Config, storage: Storage, auth:
|
|
17
|
+
declare function addSidebarWebApi(config: Config, storage: Storage, auth: Auth): Router;
|
|
18
18
|
export default addSidebarWebApi;
|
package/build/api/sidebar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sidebar.js","names":["debug","buildDebug","addSidebarWebApi","config","storage","auth","router","Router","can","allow","get","req","res","next","name","params","scope","addScope","package","requestOptions","protocol","headers","host","remoteAddress","socket","info","getPackageByOptions","uplinksLook","keepUpLinkData","v","query","sideBarInfo","versions","convertDistRemoteToLocalTarballUrls","hostname","url_prefix","isVersionValid","latest","author","formatAuthor","DIST_TAGS","deleteProperties","authorAvatar","web","addGravatarSupport","gravatar","err","status","HTTP_STATUS","NOT_FOUND","end"],"sources":["../../src/api/sidebar.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\n\nimport {
|
|
1
|
+
{"version":3,"file":"sidebar.js","names":["debug","buildDebug","addSidebarWebApi","config","storage","auth","router","Router","can","allow","get","req","res","next","name","params","scope","addScope","package","requestOptions","protocol","headers","host","remoteAddress","socket","info","getPackageByOptions","uplinksLook","keepUpLinkData","v","query","sideBarInfo","versions","convertDistRemoteToLocalTarballUrls","hostname","url_prefix","isVersionValid","latest","author","formatAuthor","DIST_TAGS","deleteProperties","authorAvatar","web","addGravatarSupport","gravatar","err","status","HTTP_STATUS","NOT_FOUND","end"],"sources":["../../src/api/sidebar.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport { DIST_TAGS, HTTP_STATUS } from '@verdaccio/core';\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend, allow } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { convertDistRemoteToLocalTarballUrls } from '@verdaccio/tarball';\nimport { Config, Manifest, Version } from '@verdaccio/types';\nimport { addGravatarSupport, formatAuthor, isVersionValid } from '@verdaccio/utils';\n\nimport { AuthorAvatar, addScope, deleteProperties } from '../utils/web-utils';\n\nexport { $RequestExtend, $ResponseExtend, $NextFunctionVer }; // Was required by other packages\n\nexport type PackageExt = Manifest & { author: AuthorAvatar; dist?: { tarball: string } };\n\nexport type $SidebarPackage = Manifest & { latest: Version };\nconst debug = buildDebug('verdaccio:web:api:sidebar');\n\nfunction addSidebarWebApi(config: Config, storage: Storage, auth: Auth): Router {\n debug('initialized sidebar web api');\n const router = Router(); /* eslint new-cap: 0 */\n const can = allow(auth);\n // Get package readme\n router.get(\n '/sidebar/(@:scope/)?:package',\n can('access'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const name: string = req.params.scope\n ? addScope(req.params.scope, req.params.package)\n : 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 info = (await storage.getPackageByOptions({\n name,\n uplinksLook: true,\n keepUpLinkData: true,\n requestOptions,\n })) as Manifest;\n const { v } = req.query;\n let sideBarInfo = { ...info };\n sideBarInfo.versions = convertDistRemoteToLocalTarballUrls(\n info,\n { protocol: req.protocol, headers: req.headers as any, host: req.hostname },\n config.url_prefix\n ).versions;\n // TODO: review this implementation\n if (typeof v === 'string' && isVersionValid(info, v)) {\n // @ts-ignore\n sideBarInfo.latest = sideBarInfo.versions[v];\n // @ts-ignore\n sideBarInfo.latest.author = formatAuthor(sideBarInfo.latest.author);\n } else {\n // @ts-ignore\n sideBarInfo.latest = sideBarInfo.versions[info[DIST_TAGS].latest];\n // @ts-ignore\n sideBarInfo.latest.author = formatAuthor(sideBarInfo.latest.author);\n }\n sideBarInfo = deleteProperties(['readme', '_attachments', '_rev', 'name'], sideBarInfo);\n const authorAvatar = config.web\n ? addGravatarSupport(sideBarInfo, config.web.gravatar)\n : addGravatarSupport(sideBarInfo);\n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A+BE,OAAOI,GAAP,EAAY;MACZlC,GAAG,CAACmC,MAAJ,CAAWC,iBAAA,CAAYC,SAAvB;MACArC,GAAG,CAACsC,GAAJ;IACD;EACF,CArDH;EAwDA,OAAO5C,MAAP;AACD;;eAEcJ,gB"}
|
package/build/api/user.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
|
-
declare function addUserAuthApi(auth:
|
|
4
|
+
declare function addUserAuthApi(auth: Auth, config: Config): Router;
|
|
5
5
|
export default addUserAuthApi;
|
package/build/api/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","names":["debug","buildDebug","addUserAuthApi","auth","config","route","Router","post","req","res","next","username","password","body","authenticate","err","user","errorCode","message","HTTP_STATUS","UNAUTHORIZED","INTERNAL_ERROR","errorUtils","getCode","remote_user","jWTSignOptions","security","web","sign","token","jwtEncrypt","name","flags","changePassword","put","_","isNil","status","API_ERROR","MUST_BE_LOGGED","validatioUtils","validatePassword","new","serverSettings","passwordValidationRegex","old","isUpdated","ok","getInternalError","INTERNAL_SERVER_ERROR","BAD_REQUEST","APP_ERROR","PASSWORD_VALIDATION"],"sources":["../../src/api/user.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Request, Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport {
|
|
1
|
+
{"version":3,"file":"user.js","names":["debug","buildDebug","addUserAuthApi","auth","config","route","Router","post","req","res","next","username","password","body","authenticate","err","user","errorCode","message","HTTP_STATUS","UNAUTHORIZED","INTERNAL_ERROR","errorUtils","getCode","remote_user","jWTSignOptions","security","web","sign","token","jwtEncrypt","name","flags","changePassword","put","_","isNil","status","API_ERROR","MUST_BE_LOGGED","validatioUtils","validatePassword","new","serverSettings","passwordValidationRegex","old","isUpdated","ok","getInternalError","INTERNAL_SERVER_ERROR","BAD_REQUEST","APP_ERROR","PASSWORD_VALIDATION"],"sources":["../../src/api/user.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Request, Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n API_ERROR,\n APP_ERROR,\n HTTP_STATUS,\n VerdaccioError,\n errorUtils,\n validatioUtils,\n} from '@verdaccio/core';\nimport { Config, JWTSignOptions, RemoteUser } from '@verdaccio/types';\n\nimport { $NextFunctionVer } from './package';\n\nconst debug = buildDebug('verdaccio:web:api:user');\n\nfunction addUserAuthApi(auth: Auth, config: Config): Router {\n const route = Router(); /* eslint new-cap: 0 */\n route.post('/login', function (req: Request, res: Response, next: $NextFunctionVer): void {\n const { username, password } = req.body;\n debug('authenticate %o', username);\n auth.authenticate(\n username,\n password,\n async (err: VerdaccioError | null, user?: RemoteUser): Promise<void> => {\n if (err) {\n const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;\n debug('error authenticate %o', errorCode);\n next(errorUtils.getCode(errorCode, err.message));\n } else {\n req.remote_user = user as RemoteUser;\n const jWTSignOptions: JWTSignOptions = config.security.web.sign;\n\n next({\n token: await auth.jwtEncrypt(user as RemoteUser, jWTSignOptions),\n username: req.remote_user.name,\n });\n }\n }\n );\n });\n\n if (config?.flags?.changePassword === true) {\n route.put(\n '/reset_password',\n function (req: Request, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name)) {\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n // FUTURE: update to a more meaningful message\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n\n const { password } = req.body;\n const { name } = req.remote_user;\n\n if (\n validatioUtils.validatePassword(\n password.new,\n config?.serverSettings?.passwordValidationRegex\n ) === false\n ) {\n auth.changePassword(\n name as string,\n password.old,\n password.new,\n (err, isUpdated): void => {\n if (_.isNil(err) && isUpdated) {\n next({\n ok: true,\n });\n } else {\n return next(errorUtils.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR));\n }\n }\n );\n } else {\n return next(errorUtils.getCode(HTTP_STATUS.BAD_REQUEST, APP_ERROR.PASSWORD_VALIDATION));\n }\n }\n );\n }\n\n return route;\n}\n\nexport default addUserAuthApi;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAGA;;;;AAYA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,wBAAX,CAAd;;AAEA,SAASC,cAAT,CAAwBC,IAAxB,EAAoCC,MAApC,EAA4D;EAAA;;EAC1D,MAAMC,KAAK,GAAG,IAAAC,eAAA,GAAd;EAAwB;;EACxBD,KAAK,CAACE,IAAN,CAAW,QAAX,EAAqB,UAAUC,GAAV,EAAwBC,GAAxB,EAAuCC,IAAvC,EAAqE;IACxF,MAAM;MAAEC,QAAF;MAAYC;IAAZ,IAAyBJ,GAAG,CAACK,IAAnC;IACAb,KAAK,CAAC,iBAAD,EAAoBW,QAApB,CAAL;IACAR,IAAI,CAACW,YAAL,CACEH,QADF,EAEEC,QAFF,EAGE,OAAOG,GAAP,EAAmCC,IAAnC,KAAwE;MACtE,IAAID,GAAJ,EAAS;QACP,MAAME,SAAS,GAAGF,GAAG,CAACG,OAAJ,GAAcC,iBAAA,CAAYC,YAA1B,GAAyCD,iBAAA,CAAYE,cAAvE;QACArB,KAAK,CAAC,uBAAD,EAA0BiB,SAA1B,CAAL;QACAP,IAAI,CAACY,gBAAA,CAAWC,OAAX,CAAmBN,SAAnB,EAA8BF,GAAG,CAACG,OAAlC,CAAD,CAAJ;MACD,CAJD,MAIO;QACLV,GAAG,CAACgB,WAAJ,GAAkBR,IAAlB;QACA,MAAMS,cAA8B,GAAGrB,MAAM,CAACsB,QAAP,CAAgBC,GAAhB,CAAoBC,IAA3D;QAEAlB,IAAI,CAAC;UACHmB,KAAK,EAAE,MAAM1B,IAAI,CAAC2B,UAAL,CAAgBd,IAAhB,EAAoCS,cAApC,CADV;UAEHd,QAAQ,EAAEH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ACL,OAAOvC,IAAI,CAACY,gBAAA,CAAWC,OAAX,CAAmBJ,iBAAA,CAAY+B,WAA/B,EAA4CC,eAAA,CAAUC,mBAAtD,CAAD,CAAX;MACD;IACF,CArCH;EAuCD;;EAED,OAAO/C,KAAP;AACD;;eAEcH,c"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function loadTheme(config: any): Promise<unknown>;
|
|
1
|
+
export declare function loadTheme(config: any): Promise<import("@verdaccio/core/build/plugin-utils").Plugin<unknown> | undefined>;
|
|
2
2
|
export declare function renderWebMiddleware(config: any, auth: any): Promise<any>;
|
|
@@ -34,8 +34,7 @@ async function loadTheme(config) {
|
|
|
34
34
|
if (_lodash.default.isNil(config.theme) === false) {
|
|
35
35
|
var _config$serverSetting;
|
|
36
36
|
|
|
37
|
-
const plugin = await (0, _loaders.asyncLoadPlugin)(config.theme,
|
|
38
|
-
{
|
|
37
|
+
const plugin = await (0, _loaders.asyncLoadPlugin)(config.theme, {
|
|
39
38
|
config,
|
|
40
39
|
logger: _logger.logger
|
|
41
40
|
}, function (plugin) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-web.js","names":["debug","buildDebug","loadTheme","config","_","isNil","theme","plugin","asyncLoadPlugin","logger","serverSettings","pluginPrefix","length","warn","head","sendFileCallback","next","err","status","HTTP_STATUS","NOT_FOUND","renderWebMiddleware","auth","staticPath","manifest","manifestFiles","require","router","express","Router","use","webUIJWTmiddleware","setSecurityWebHeaders","logoURI","web","logo","isURLhasValidProtocol","path","posix","join","basename","get","req","res","sendFile","resolve","filename","params","file","renderHTML"],"sources":["../../src/middleware/render-web.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport express from 'express';\nimport _ from 'lodash';\nimport path from 'path';\n\nimport { HTTP_STATUS } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { logger } from '@verdaccio/logger';\nimport { isURLhasValidProtocol } from '@verdaccio/url';\n\nimport renderHTML from '../renderHTML';\nimport { setSecurityWebHeaders } from './security';\n\nconst debug = buildDebug('verdaccio:web:render');\n\nexport async function loadTheme(config: any) {\n if (_.isNil(config.theme) === false) {\n const plugin = await asyncLoadPlugin(\n config.theme,\n
|
|
1
|
+
{"version":3,"file":"render-web.js","names":["debug","buildDebug","loadTheme","config","_","isNil","theme","plugin","asyncLoadPlugin","logger","serverSettings","pluginPrefix","length","warn","head","sendFileCallback","next","err","status","HTTP_STATUS","NOT_FOUND","renderWebMiddleware","auth","staticPath","manifest","manifestFiles","require","router","express","Router","use","webUIJWTmiddleware","setSecurityWebHeaders","logoURI","web","logo","isURLhasValidProtocol","path","posix","join","basename","get","req","res","sendFile","resolve","filename","params","file","renderHTML"],"sources":["../../src/middleware/render-web.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport express from 'express';\nimport _ from 'lodash';\nimport path from 'path';\n\nimport { HTTP_STATUS } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { logger } from '@verdaccio/logger';\nimport { isURLhasValidProtocol } from '@verdaccio/url';\n\nimport renderHTML from '../renderHTML';\nimport { setSecurityWebHeaders } from './security';\n\nconst debug = buildDebug('verdaccio:web:render');\n\nexport async function loadTheme(config: any) {\n if (_.isNil(config.theme) === false) {\n const plugin = await asyncLoadPlugin(\n config.theme,\n { config, logger },\n function (plugin) {\n return typeof plugin === 'string';\n },\n config?.serverSettings?.pluginPrefix ?? 'verdaccio-theme'\n );\n if (plugin.length > 1) {\n logger.warn(\n 'multiple ui themes has been detected and is not supported, only the first one will be used'\n );\n }\n\n return _.head(plugin);\n }\n}\n\nconst sendFileCallback = (next) => (err) => {\n if (!err) {\n return;\n }\n if (err.status === HTTP_STATUS.NOT_FOUND) {\n next();\n } else {\n next(err);\n }\n};\n\nexport async function renderWebMiddleware(config, auth): Promise<any> {\n const { staticPath, manifest, manifestFiles } =\n (await loadTheme(config)) || require('@verdaccio/ui-theme')();\n debug('static path %o', staticPath);\n\n /* eslint new-cap:off */\n const router = express.Router();\n router.use(auth.webUIJWTmiddleware());\n router.use(setSecurityWebHeaders);\n\n // Logo\n let logoURI = config?.web?.logo ?? '';\n if (logoURI && !isURLhasValidProtocol(logoURI)) {\n // URI related to a local file\n\n // Note: `path.join` will break on Windows, because it transforms `/` to `\\`\n // Use POSIX version `path.posix.join` instead.\n logoURI = path.posix.join('/-/static/', path.basename(logoURI));\n router.get(logoURI, function (req, res, next) {\n res.sendFile(path.resolve(config.web.logo), sendFileCallback(next));\n debug('render static');\n });\n }\n\n // Static\n router.get('/-/static/*', function (req, res, next) {\n const filename = req.params[0];\n const file = `${staticPath}/${filename}`;\n debug('render static file %o', file);\n res.sendFile(file, sendFileCallback(next));\n });\n\n router.get('/-/web/:section/*', function (req, res) {\n renderHTML(config, manifest, manifestFiles, req, res);\n debug('render html section');\n });\n\n router.get('/', function (req, res) {\n renderHTML(config, manifest, manifestFiles, req, res);\n debug('render root');\n });\n\n return router;\n}\n"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;AAEA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,sBAAX,CAAd;;AAEO,eAAeC,SAAf,CAAyBC,MAAzB,EAAsC;EAC3C,IAAIC,eAAA,CAAEC,KAAF,CAAQF,MAAM,CAACG,KAAf,MAA0B,KAA9B,EAAqC;IAAA;;IACnC,MAAMC,MAAM,GAAG,MAAM,IAAAC,wBAAA,EACnBL,MAAM,CAACG,KADY,EAEnB;MAAEH,MAAF;MAAUM,MAAM,EAANA;IAAV,CAFmB,EAGnB,UAAUF,MAAV,EAAkB;MAChB,OAAO,OAAOA,MAAP,KAAkB,QAAzB;IACD,CALkB,EAMnB,CAAAJ,MAAM,SAAN,IAAAA,MAAM,WAAN,qCAAAA,MAAM,CAAEO,cAAR,gFAAwBC,YAAxB,KAAwC,iBANrB,CAArB;;IAQA,IAAIJ,MAAM,CAACK,MAAP,GAAgB,CAApB,EAAuB;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AAJ,CAAaP,aAAA,CAAKQ,OAAL,CAAa1C,MAAM,CAAC+B,GAAP,CAAWC,IAAxB,CAAb,EAA4CpB,gBAAgB,CAACC,IAAD,CAA5D;MACAhB,KAAK,CAAC,eAAD,CAAL;IACD,CAHD;EAID,CAtBmE,CAwBpE;;;EACA2B,MAAM,CAACc,GAAP,CAAW,aAAX,EAA0B,UAAUC,GAAV,EAAeC,GAAf,EAAoB3B,IAApB,EAA0B;IAClD,MAAM8B,QAAQ,GAAGJ,GAAG,CAACK,MAAJ,CAAW,CAAX,CAAjB;IACA,MAAMC,IAAI,GAAI,GAAEzB,UAAW,IAAGuB,QAAS,EAAvC;IACA9C,KAAK,CAAC,uBAAD,EAA0BgD,IAA1B,CAAL;IACAL,GAAG,CAACC,QAAJ,CAAaI,IAAb,EAAmBjC,gBAAgB,CAACC,IAAD,CAAnC;EACD,CALD;EAOAW,MAAM,CAACc,GAAP,CAAW,mBAAX,EAAgC,UAAUC,GAAV,EAAeC,GAAf,EAAoB;IAClD,IAAAM,mBAAA,EAAW9C,MAAX,EAAmBqB,QAAnB,EAA6BC,aAA7B,EAA4CiB,GAA5C,EAAiDC,GAAjD;IACA3C,KAAK,CAAC,qBAAD,CAAL;EACD,CAHD;EAKA2B,MAAM,CAACc,GAAP,CAAW,GAAX,EAAgB,UAAUC,GAAV,EAAeC,GAAf,EAAoB;IAClC,IAAAM,mBAAA,EAAW9C,MAAX,EAAmBqB,QAAnB,EAA6BC,aAA7B,EAA4CiB,GAA5C,EAAiDC,GAAjD;IACA3C,KAAK,CAAC,aAAD,CAAL;EACD,CAHD;EAKA,OAAO2B,MAAP;AACD"}
|
|
@@ -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 declare function webAPI(config: Config, auth:
|
|
5
|
+
export declare function webAPI(config: Config, auth: Auth, storage: Storage): Router;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-api.js","names":["webAPI","config","auth","storage","route","Router","param","validatePackage","validateName","match","use","bodyParser","urlencoded","extended","webUIJWTmiddleware","setSecurityWebHeaders","webEndpointsApi"],"sources":["../../src/middleware/web-api.ts"],"sourcesContent":["import bodyParser from 'body-parser';\nimport { Router } from 'express';\n\nimport {
|
|
1
|
+
{"version":3,"file":"web-api.js","names":["webAPI","config","auth","storage","route","Router","param","validatePackage","validateName","match","use","bodyParser","urlencoded","extended","webUIJWTmiddleware","setSecurityWebHeaders","webEndpointsApi"],"sources":["../../src/middleware/web-api.ts"],"sourcesContent":["import bodyParser from 'body-parser';\nimport { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport { match, validateName, validatePackage } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { Config } from '@verdaccio/types';\n\nimport webEndpointsApi from '../api';\nimport { setSecurityWebHeaders } from './security';\n\nexport function webAPI(config: Config, auth: Auth, storage: Storage): Router {\n // eslint-disable-next-line new-cap\n const route = Router();\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble=\n route.param('package', validatePackage);\n route.param('filename', validateName);\n route.param('version', validateName);\n route.param('anything', match(/.*/));\n route.use(bodyParser.urlencoded({ extended: false }));\n route.use(auth.webUIJWTmiddleware());\n route.use(setSecurityWebHeaders);\n route.use(webEndpointsApi(auth, storage, config));\n return route;\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AAGA;;AAIA;;AACA;;;;AAEO,SAASA,MAAT,CAAgBC,MAAhB,EAAgCC,IAAhC,EAA4CC,OAA5C,EAAsE;EAC3E;EACA,MAAMC,KAAK,GAAG,IAAAC,eAAA,GAAd,CAF2E,CAG3E;EACA;;EACAD,KAAK,CAACE,KAAN,CAAY,SAAZ,EAAuBC,2BAAvB;EACAH,KAAK,CAACE,KAAN,CAAY,UAAZ,EAAwBE,wBAAxB;EACAJ,KAAK,CAACE,KAAN,CAAY,SAAZ,EAAuBE,wBAAvB;EACAJ,KAAK,CAACE,KAAN,CAAY,UAAZ,EAAwB,IAAAG,iBAAA,EAAM,IAAN,CAAxB;EACAL,KAAK,CAACM,GAAN,CAAUC,mBAAA,CAAWC,UAAX,CAAsB;IAAEC,QAAQ,EAAE;EAAZ,CAAtB,CAAV;EACAT,KAAK,CAACM,GAAN,CAAUR,IAAI,CAACY,kBAAL,EAAV;EACAV,KAAK,CAACM,GAAN,CAAUK,+BAAV;EACAX,KAAK,CAACM,GAAN,CAAU,IAAAM,YAAA,EAAgBd,IAAhB,EAAsBC,OAAtB,EAA+BF,MAA/B,CAAV;EACA,OAAOG,KAAP;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/web",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
3
|
+
"version": "6.0.0-6-next.36",
|
|
4
4
|
"description": "web ui middleware",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@verdaccio/auth": "6.0.0-6-next.
|
|
29
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
30
|
-
"@verdaccio/config": "6.0.0-6-next.
|
|
31
|
-
"@verdaccio/loaders": "6.0.0-6-next.
|
|
32
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
33
|
-
"@verdaccio/middleware": "6.0.0-6-next.
|
|
28
|
+
"@verdaccio/auth": "6.0.0-6-next.28",
|
|
29
|
+
"@verdaccio/core": "6.0.0-6-next.49",
|
|
30
|
+
"@verdaccio/config": "6.0.0-6-next.49",
|
|
31
|
+
"@verdaccio/loaders": "6.0.0-6-next.18",
|
|
32
|
+
"@verdaccio/logger": "6.0.0-6-next.17",
|
|
33
|
+
"@verdaccio/middleware": "6.0.0-6-next.28",
|
|
34
34
|
"@verdaccio/readme": "11.0.0-6-next.6",
|
|
35
|
-
"@verdaccio/store": "6.0.0-6-next.
|
|
36
|
-
"@verdaccio/tarball": "11.0.0-6-next.
|
|
37
|
-
"@verdaccio/url": "11.0.0-6-next.
|
|
38
|
-
"@verdaccio/utils": "6.0.0-6-next.
|
|
35
|
+
"@verdaccio/store": "6.0.0-6-next.29",
|
|
36
|
+
"@verdaccio/tarball": "11.0.0-6-next.18",
|
|
37
|
+
"@verdaccio/url": "11.0.0-6-next.15",
|
|
38
|
+
"@verdaccio/utils": "6.0.0-6-next.17",
|
|
39
39
|
"body-parser": "1.20.0",
|
|
40
40
|
"debug": "4.3.4",
|
|
41
41
|
"express": "4.18.1",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"lru-cache": "6.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "16.11.
|
|
46
|
+
"@types/node": "16.11.62",
|
|
47
47
|
"@verdaccio/types": "11.0.0-6-next.17",
|
|
48
|
-
"@verdaccio/test-helper": "2.0.0-6-next.
|
|
49
|
-
"@verdaccio/api": "6.0.0-6-next.
|
|
48
|
+
"@verdaccio/test-helper": "2.0.0-6-next.6",
|
|
49
|
+
"@verdaccio/api": "6.0.0-6-next.32",
|
|
50
50
|
"node-html-parser": "4.1.5",
|
|
51
51
|
"supertest": "6.2.4",
|
|
52
52
|
"nock": "13.2.9",
|
|
53
53
|
"jsdom": "20.0.0",
|
|
54
54
|
"undici": "4.16.0",
|
|
55
|
-
"verdaccio-auth-memory": "11.0.0-6-next.
|
|
56
|
-
"verdaccio-memory": "11.0.0-6-next.
|
|
55
|
+
"verdaccio-auth-memory": "11.0.0-6-next.14",
|
|
56
|
+
"verdaccio-memory": "11.0.0-6-next.16"
|
|
57
57
|
},
|
|
58
58
|
"funding": {
|
|
59
59
|
"type": "opencollective",
|
package/src/api/package.ts
CHANGED
|
@@ -2,7 +2,7 @@ import buildDebug from 'debug';
|
|
|
2
2
|
import { Router } from 'express';
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Auth } from '@verdaccio/auth';
|
|
6
6
|
import { logger } from '@verdaccio/logger';
|
|
7
7
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware';
|
|
8
8
|
import { Storage } from '@verdaccio/store';
|
|
@@ -20,7 +20,7 @@ const getOrder = (order = 'asc') => {
|
|
|
20
20
|
|
|
21
21
|
const debug = buildDebug('verdaccio:web:api:package');
|
|
22
22
|
|
|
23
|
-
function addPackageWebApi(storage: Storage, auth:
|
|
23
|
+
function addPackageWebApi(storage: Storage, auth: Auth, config: Config): Router {
|
|
24
24
|
const isLoginEnabled = config?.web?.login === true ?? true;
|
|
25
25
|
const pkgRouter = Router(); /* eslint new-cap: 0 */
|
|
26
26
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -41,7 +41,7 @@ function addPackageWebApi(storage: Storage, auth: IAuth, config: Config): Router
|
|
|
41
41
|
if (err) {
|
|
42
42
|
resolve(false);
|
|
43
43
|
}
|
|
44
|
-
resolve(allowed);
|
|
44
|
+
return resolve(allowed as boolean);
|
|
45
45
|
});
|
|
46
46
|
} catch (err: any) {
|
|
47
47
|
reject(err);
|
package/src/api/readme.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 } from '@verdaccio/core';
|
|
6
6
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend, allow } from '@verdaccio/middleware';
|
|
7
7
|
import sanitizyReadme from '@verdaccio/readme';
|
|
@@ -19,7 +19,7 @@ const debug = buildDebug('verdaccio:web:api:readme');
|
|
|
19
19
|
|
|
20
20
|
export const NOT_README_FOUND = 'ERROR: No README data found!';
|
|
21
21
|
|
|
22
|
-
function addReadmeWebApi(storage: Storage, auth:
|
|
22
|
+
function addReadmeWebApi(storage: Storage, auth: Auth): Router {
|
|
23
23
|
debug('initialized readme web api');
|
|
24
24
|
const can = allow(auth);
|
|
25
25
|
const pkgRouter = Router(); /* eslint new-cap: 0 */
|
package/src/api/search.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Router } from 'express';
|
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import { URLSearchParams } from 'url';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { Auth } from '@verdaccio/auth';
|
|
7
7
|
import { errorUtils, searchUtils } from '@verdaccio/core';
|
|
8
8
|
import { SearchQuery } from '@verdaccio/core/src/search-utils';
|
|
9
9
|
import { Storage } from '@verdaccio/store';
|
|
@@ -32,7 +32,7 @@ function checkAccess(pkg: any, auth: any, remoteUser): Promise<Manifest | null>
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function addSearchWebApi(storage: Storage, auth:
|
|
35
|
+
function addSearchWebApi(storage: Storage, auth: Auth): Router {
|
|
36
36
|
const router = Router(); /* eslint new-cap: 0 */
|
|
37
37
|
router.get(
|
|
38
38
|
'/search/:anything',
|
package/src/api/sidebar.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 { DIST_TAGS, HTTP_STATUS } from '@verdaccio/core';
|
|
6
6
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend, allow } from '@verdaccio/middleware';
|
|
7
7
|
import { Storage } from '@verdaccio/store';
|
|
@@ -18,7 +18,7 @@ export type PackageExt = Manifest & { author: AuthorAvatar; dist?: { tarball: st
|
|
|
18
18
|
export type $SidebarPackage = Manifest & { latest: Version };
|
|
19
19
|
const debug = buildDebug('verdaccio:web:api:sidebar');
|
|
20
20
|
|
|
21
|
-
function addSidebarWebApi(config: Config, storage: Storage, auth:
|
|
21
|
+
function addSidebarWebApi(config: Config, storage: Storage, auth: Auth): Router {
|
|
22
22
|
debug('initialized sidebar web api');
|
|
23
23
|
const router = Router(); /* eslint new-cap: 0 */
|
|
24
24
|
const can = allow(auth);
|
package/src/api/user.ts
CHANGED
|
@@ -2,34 +2,45 @@ import buildDebug from 'debug';
|
|
|
2
2
|
import { Request, Response, Router } from 'express';
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { Auth } from '@verdaccio/auth';
|
|
6
|
+
import {
|
|
7
|
+
API_ERROR,
|
|
8
|
+
APP_ERROR,
|
|
9
|
+
HTTP_STATUS,
|
|
10
|
+
VerdaccioError,
|
|
11
|
+
errorUtils,
|
|
12
|
+
validatioUtils,
|
|
13
|
+
} from '@verdaccio/core';
|
|
7
14
|
import { Config, JWTSignOptions, RemoteUser } from '@verdaccio/types';
|
|
8
15
|
|
|
9
16
|
import { $NextFunctionVer } from './package';
|
|
10
17
|
|
|
11
18
|
const debug = buildDebug('verdaccio:web:api:user');
|
|
12
19
|
|
|
13
|
-
function addUserAuthApi(auth:
|
|
20
|
+
function addUserAuthApi(auth: Auth, config: Config): Router {
|
|
14
21
|
const route = Router(); /* eslint new-cap: 0 */
|
|
15
22
|
route.post('/login', function (req: Request, res: Response, next: $NextFunctionVer): void {
|
|
16
23
|
const { username, password } = req.body;
|
|
17
24
|
debug('authenticate %o', username);
|
|
18
|
-
auth.authenticate(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
auth.authenticate(
|
|
26
|
+
username,
|
|
27
|
+
password,
|
|
28
|
+
async (err: VerdaccioError | null, user?: RemoteUser): Promise<void> => {
|
|
29
|
+
if (err) {
|
|
30
|
+
const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;
|
|
31
|
+
debug('error authenticate %o', errorCode);
|
|
32
|
+
next(errorUtils.getCode(errorCode, err.message));
|
|
33
|
+
} else {
|
|
34
|
+
req.remote_user = user as RemoteUser;
|
|
35
|
+
const jWTSignOptions: JWTSignOptions = config.security.web.sign;
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
next({
|
|
38
|
+
token: await auth.jwtEncrypt(user as RemoteUser, jWTSignOptions),
|
|
39
|
+
username: req.remote_user.name,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
31
42
|
}
|
|
32
|
-
|
|
43
|
+
);
|
|
33
44
|
});
|
|
34
45
|
|
|
35
46
|
if (config?.flags?.changePassword === true) {
|
|
@@ -17,9 +17,8 @@ export async function loadTheme(config: any) {
|
|
|
17
17
|
if (_.isNil(config.theme) === false) {
|
|
18
18
|
const plugin = await asyncLoadPlugin(
|
|
19
19
|
config.theme,
|
|
20
|
-
// @ts-ignore
|
|
21
20
|
{ config, logger },
|
|
22
|
-
function (plugin
|
|
21
|
+
function (plugin) {
|
|
23
22
|
return typeof plugin === 'string';
|
|
24
23
|
},
|
|
25
24
|
config?.serverSettings?.pluginPrefix ?? 'verdaccio-theme'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import bodyParser from 'body-parser';
|
|
2
2
|
import { Router } from 'express';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { Auth } from '@verdaccio/auth';
|
|
5
5
|
import { match, validateName, validatePackage } from '@verdaccio/middleware';
|
|
6
6
|
import { Storage } from '@verdaccio/store';
|
|
7
7
|
import { Config } from '@verdaccio/types';
|
|
@@ -9,7 +9,7 @@ import { Config } from '@verdaccio/types';
|
|
|
9
9
|
import webEndpointsApi from '../api';
|
|
10
10
|
import { setSecurityWebHeaders } from './security';
|
|
11
11
|
|
|
12
|
-
export function webAPI(config: Config, auth:
|
|
12
|
+
export function webAPI(config: Config, auth: Auth, storage: Storage): Router {
|
|
13
13
|
// eslint-disable-next-line new-cap
|
|
14
14
|
const route = Router();
|
|
15
15
|
// validate all of these params as a package name
|