@verdaccio/web 6.0.0-6-next.29 → 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 +96 -0
- package/build/api/index.js.map +1 -1
- package/build/api/package.d.ts +1 -8
- package/build/api/package.js +51 -54
- package/build/api/package.js.map +1 -1
- package/build/api/readme.d.ts +2 -2
- package/build/api/readme.js +26 -20
- package/build/api/readme.js.map +1 -1
- package/build/api/search.js +1 -3
- package/build/api/search.js.map +1 -1
- package/build/api/sidebar.d.ts +3 -3
- package/build/api/sidebar.js +46 -39
- package/build/api/sidebar.js.map +1 -1
- package/build/api/user.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/middleware/render-web.js.map +1 -1
- package/build/middleware/security.js.map +1 -1
- package/build/middleware/web-api.js.map +1 -1
- package/build/renderHTML.js.map +1 -1
- package/build/template.js.map +1 -1
- package/build/utils/manifest.js.map +1 -1
- package/build/utils/web-utils.js.map +1 -1
- package/build/web-middleware.js.map +1 -1
- package/jest.config.js +8 -1
- package/package.json +24 -24
- package/src/api/package.ts +53 -54
- package/src/api/readme.ts +34 -24
- package/src/api/search.ts +1 -1
- package/src/api/sidebar.ts +51 -39
- package/test/api.readme.test.ts +1 -1
- package/test/render.test.ts +2 -2
- package/tsconfig.json +0 -3
package/src/api/sidebar.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import buildDebug from 'debug';
|
|
2
2
|
import { Router } from 'express';
|
|
3
|
-
import _ from 'lodash';
|
|
4
3
|
|
|
5
4
|
import { IAuth } from '@verdaccio/auth';
|
|
6
5
|
import { DIST_TAGS, HTTP_STATUS } from '@verdaccio/core';
|
|
7
6
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend, allow } from '@verdaccio/middleware';
|
|
8
7
|
import { Storage } from '@verdaccio/store';
|
|
9
8
|
import { convertDistRemoteToLocalTarballUrls } from '@verdaccio/tarball';
|
|
10
|
-
import { Config,
|
|
9
|
+
import { Config, Manifest, Version } from '@verdaccio/types';
|
|
11
10
|
import { addGravatarSupport, formatAuthor, isVersionValid } from '@verdaccio/utils';
|
|
12
11
|
|
|
13
12
|
import { AuthorAvatar, addScope, deleteProperties } from '../utils/web-utils';
|
|
14
13
|
|
|
15
14
|
export { $RequestExtend, $ResponseExtend, $NextFunctionVer }; // Was required by other packages
|
|
16
15
|
|
|
17
|
-
export type PackageExt =
|
|
16
|
+
export type PackageExt = Manifest & { author: AuthorAvatar; dist?: { tarball: string } };
|
|
18
17
|
|
|
19
|
-
export type $SidebarPackage =
|
|
18
|
+
export type $SidebarPackage = Manifest & { latest: Version };
|
|
20
19
|
const debug = buildDebug('verdaccio:web:api:sidebar');
|
|
21
20
|
|
|
22
21
|
function addSidebarWebApi(config: Config, storage: Storage, auth: IAuth): Router {
|
|
@@ -27,43 +26,56 @@ function addSidebarWebApi(config: Config, storage: Storage, auth: IAuth): Router
|
|
|
27
26
|
router.get(
|
|
28
27
|
'/sidebar/(@:scope/)?:package',
|
|
29
28
|
can('access'),
|
|
30
|
-
function (
|
|
31
|
-
|
|
29
|
+
async function (
|
|
30
|
+
req: $RequestExtend,
|
|
31
|
+
res: $ResponseExtend,
|
|
32
|
+
next: $NextFunctionVer
|
|
33
|
+
): Promise<void> {
|
|
34
|
+
const name: string = req.params.scope
|
|
32
35
|
? addScope(req.params.scope, req.params.package)
|
|
33
36
|
: req.params.package;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
req,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
37
|
+
const requestOptions = {
|
|
38
|
+
protocol: req.protocol,
|
|
39
|
+
headers: req.headers as any,
|
|
40
|
+
// FIXME: if we migrate to req.hostname, the port is not longer included.
|
|
41
|
+
host: req.host,
|
|
42
|
+
remoteAddress: req.socket.remoteAddress,
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
const info = (await storage.getPackageByOptions({
|
|
46
|
+
name,
|
|
47
|
+
uplinksLook: true,
|
|
48
|
+
keepUpLinkData: true,
|
|
49
|
+
requestOptions,
|
|
50
|
+
})) as Manifest;
|
|
51
|
+
const { v } = req.query;
|
|
52
|
+
let sideBarInfo = { ...info };
|
|
53
|
+
sideBarInfo.versions = convertDistRemoteToLocalTarballUrls(
|
|
54
|
+
info,
|
|
55
|
+
{ protocol: req.protocol, headers: req.headers as any, host: req.hostname },
|
|
56
|
+
config.url_prefix
|
|
57
|
+
).versions;
|
|
58
|
+
// TODO: review this implementation
|
|
59
|
+
if (typeof v === 'string' && isVersionValid(info, v)) {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
sideBarInfo.latest = sideBarInfo.versions[v];
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
sideBarInfo.latest.author = formatAuthor(sideBarInfo.latest.author);
|
|
64
|
+
} else {
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
sideBarInfo.latest = sideBarInfo.versions[info[DIST_TAGS].latest];
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
sideBarInfo.latest.author = formatAuthor(sideBarInfo.latest.author);
|
|
69
|
+
}
|
|
70
|
+
sideBarInfo = deleteProperties(['readme', '_attachments', '_rev', 'name'], sideBarInfo);
|
|
71
|
+
const authorAvatar = config.web
|
|
72
|
+
? addGravatarSupport(sideBarInfo, config.web.gravatar)
|
|
73
|
+
: addGravatarSupport(sideBarInfo);
|
|
74
|
+
next(authorAvatar);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
res.status(HTTP_STATUS.NOT_FOUND);
|
|
77
|
+
res.end();
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
);
|
|
69
81
|
|
package/test/api.readme.test.ts
CHANGED
|
@@ -38,7 +38,7 @@ describe('readme api', () => {
|
|
|
38
38
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_PLAIN_UTF8)
|
|
39
39
|
.expect(HTTP_STATUS.OK);
|
|
40
40
|
expect(response.text).toMatch('my readme scoped');
|
|
41
|
-
});
|
|
41
|
+
}, 70000);
|
|
42
42
|
|
|
43
43
|
test('should fetch readme scoped package with not found message', async () => {
|
|
44
44
|
const app = await initializeServer('default-test.yaml');
|
package/test/render.test.ts
CHANGED