@verdaccio/server 8.0.0-next-8.11 → 8.0.0-next-8.13

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.
@@ -1,4 +0,0 @@
1
- JotaJWT:$6V.OzhCA9jFk:autocreated 2020-01-05T19:30:24.861Z
2
- userTest2000:$6JZevb9Sewsg:autocreated 2020-01-05T19:30:24.901Z
3
- userTest2001:$6V.OzhCA9jFk:autocreated 2020-01-05T19:30:24.924Z
4
- userTest2002:$6V.OzhCA9jFk:autocreated 2020-01-05T19:30:24.942Z
@@ -1,24 +0,0 @@
1
- import { Application } from 'express';
2
-
3
- import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../../types/custom';
4
-
5
- export default (app: Application, configPath?: string): void => {
6
- // Hook for tests only
7
- app.get(
8
- '/-/_debug',
9
- function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
10
- if (global.gc) {
11
- global.gc();
12
- }
13
-
14
- next({
15
- pid: process.pid,
16
- // @ts-ignore
17
- main: process.main,
18
- conf: configPath,
19
- mem: process.memoryUsage(),
20
- gc: global.gc,
21
- });
22
- }
23
- );
24
- };
package/src/env.ts DELETED
@@ -1,8 +0,0 @@
1
- // const path = require('path');
2
- //
3
- // const APP_ROOT = path.resolve(__dirname, '../../');
4
- //
5
- // module.exports = {
6
- // APP_ROOT,
7
- // SRC_ROOT: path.resolve(APP_ROOT, 'src/')
8
- // };
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export { default, startServer } from './server';
package/src/server.ts DELETED
@@ -1,169 +0,0 @@
1
- import compression from 'compression';
2
- import cors from 'cors';
3
- import buildDebug from 'debug';
4
- import express, { Express } from 'express';
5
- import _ from 'lodash';
6
- import AuditMiddleware from 'verdaccio-audit';
7
-
8
- import apiEndpoint from '@verdaccio/api';
9
- import { Auth } from '@verdaccio/auth';
10
- import { Config as AppConfig } from '@verdaccio/config';
11
- import { API_ERROR, PLUGIN_CATEGORY, errorUtils, pluginUtils } from '@verdaccio/core';
12
- import { asyncLoadPlugin } from '@verdaccio/loaders';
13
- import { logger } from '@verdaccio/logger';
14
- import {
15
- errorReportingMiddleware,
16
- final,
17
- handleError,
18
- log,
19
- rateLimit,
20
- userAgent,
21
- } from '@verdaccio/middleware';
22
- import { Storage } from '@verdaccio/store';
23
- import { ConfigYaml } from '@verdaccio/types';
24
- import { Config as IConfig } from '@verdaccio/types';
25
- import webMiddleware from '@verdaccio/web';
26
-
27
- import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';
28
- import hookDebug from './debug';
29
-
30
- const debug = buildDebug('verdaccio:server');
31
- const { version } = require('../package.json');
32
-
33
- const defineAPI = async function (config: IConfig, storage: Storage): Promise<Express> {
34
- const auth: Auth = new Auth(config, logger);
35
- await auth.init();
36
- const app = express();
37
- // run in production mode by default, just in case
38
- // it shouldn't make any difference anyway
39
- app.set('env', process.env.NODE_ENV || 'production');
40
- if (config.server?.trustProxy) {
41
- app.set('trust proxy', config.server.trustProxy);
42
- }
43
- app.use(cors());
44
- app.use(rateLimit(config.serverSettings.rateLimit));
45
-
46
- const errorReportingMiddlewareWrap = errorReportingMiddleware(logger);
47
-
48
- // Router setup
49
- app.use(log(logger));
50
- app.use(errorReportingMiddlewareWrap);
51
- app.use(userAgent(config));
52
- app.use(compression());
53
-
54
- app.get(
55
- '/favicon.ico',
56
- function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
57
- req.url = '/-/static/favicon.ico';
58
- next();
59
- }
60
- );
61
-
62
- // Hook for tests only
63
- if (config._debug) {
64
- hookDebug(app, config.configPath);
65
- }
66
-
67
- const plugins: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>[] = await asyncLoadPlugin(
68
- config.middlewares,
69
- {
70
- config,
71
- logger,
72
- },
73
- function (plugin) {
74
- return typeof plugin.register_middlewares !== 'undefined';
75
- },
76
- config?.serverSettings?.pluginPrefix ?? 'verdaccio',
77
- PLUGIN_CATEGORY.MIDDLEWARE
78
- );
79
-
80
- if (plugins.length === 0) {
81
- const auditPlugin = new AuditMiddleware(
82
- { enabled: true, strict_ssl: true },
83
- { config, logger }
84
- );
85
- logger.info(
86
- { name: 'verdaccio-audit', pluginCategory: PLUGIN_CATEGORY.MIDDLEWARE },
87
- 'plugin @{name} successfully loaded (@{pluginCategory})'
88
- );
89
- plugins.push(auditPlugin);
90
- }
91
-
92
- plugins.forEach((plugin: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>) => {
93
- plugin.register_middlewares(app, auth, storage);
94
- });
95
-
96
- // For npm request
97
- // @ts-ignore
98
- app.use(apiEndpoint(config, auth, storage, logger));
99
-
100
- // For WebUI & WebUI API
101
- if (_.get(config, 'web.enable', true)) {
102
- app.use((_req, res, next) => {
103
- res.locals.app_version = version ?? '';
104
- next();
105
- });
106
- const middleware = await webMiddleware(config, auth, storage, logger);
107
- app.use(middleware);
108
- } else {
109
- app.get('/', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
110
- next(errorUtils.getNotFound(API_ERROR.WEB_DISABLED));
111
- });
112
- }
113
-
114
- // Catch 404
115
- app.get('/*', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
116
- next(errorUtils.getNotFound('resource not found'));
117
- });
118
-
119
- // @ts-ignore
120
- app.use(handleError(logger));
121
-
122
- // app.use(function (
123
- // err: HttpError,
124
- // req: $RequestExtend,
125
- // res: $ResponseExtend,
126
- // next: $NextFunctionVer
127
- // ) {
128
- // if (_.isError(err)) {
129
- // if (err.code === 'ECONNABORT' && res.statusCode === HTTP_STATUS.NOT_MODIFIED) {
130
- // return next();
131
- // }
132
- // if (_.isFunction(res.locals.report_error) === false) {
133
- // // in case of very early error this middleware may not be loaded before error is generated
134
- // // fixing that
135
- // errorReportingMiddlewareWrap(req, res, _.noop);
136
- // }
137
- // res.locals.report_error(err);
138
- // } else {
139
- // // Fall to Middleware.final
140
- // return next(err);
141
- // }
142
- // });
143
-
144
- app.use(final);
145
-
146
- return app;
147
- };
148
-
149
- const startServer = async function startServer(configHash: ConfigYaml): Promise<Express> {
150
- debug('start server');
151
- const config: IConfig = new AppConfig({ ...configHash } as any);
152
- // register middleware plugins
153
- debug('loaded filter plugin');
154
- // @ts-ignore
155
- const storage: Storage = new Storage(config, logger);
156
- try {
157
- // waits until init calls have been initialized
158
- debug('storage init start');
159
- await storage.init(config);
160
- debug('storage init end');
161
- } catch (err: any) {
162
- logger.error({ error: err.msg }, 'storage has failed: @{error}');
163
- throw new Error(err);
164
- }
165
- return await defineAPI(config, storage);
166
- };
167
-
168
- export { startServer };
169
- export default startServer;
package/test/_helper.ts DELETED
@@ -1,29 +0,0 @@
1
- import { Application } from 'express';
2
- import path from 'path';
3
-
4
- import { parseConfigFile } from '@verdaccio/config';
5
- import { fileUtils } from '@verdaccio/core';
6
- import { setup } from '@verdaccio/logger';
7
- import { generateRandomHexString } from '@verdaccio/utils';
8
-
9
- import apiMiddleware from '../src';
10
-
11
- export const getConf = async (conf) => {
12
- const configPath = path.join(__dirname, 'config', conf);
13
- const config = parseConfigFile(configPath);
14
- // generate and create storage folder
15
- const storage = await fileUtils.createTempFolder('config');
16
- config.storage = storage;
17
- // custom config to avoid conflict with other tests
18
- config.auth.htpasswd.file = path.join(
19
- storage,
20
- `${config.auth.htpasswd.file}-${generateRandomHexString()}`
21
- );
22
- return config;
23
- };
24
-
25
- export async function initializeServer(configName): Promise<Application> {
26
- const config = await getConf(configName);
27
- setup(config.log ?? {});
28
- return apiMiddleware(config);
29
- }
@@ -1,28 +0,0 @@
1
- # storage: this is generated on _helper file
2
-
3
- auth:
4
- htpasswd:
5
- file: ./htpasswd-package
6
-
7
- web:
8
- enable: true
9
- title: verdaccio
10
-
11
- publish:
12
- allow_offline: false
13
-
14
- uplinks:
15
-
16
- log: { type: stdout, format: pretty, level: trace }
17
-
18
- packages:
19
- '@*/*':
20
- access: $all
21
- publish: $all
22
- unpublish: none
23
- '**':
24
- access: $all
25
- publish: $all
26
- unpublish: none
27
-
28
- _debug: true
@@ -1,26 +0,0 @@
1
- # storage: this is generated on _helper file
2
-
3
- auth:
4
- htpasswd:
5
- file: ./htpasswd-package
6
-
7
- web:
8
- enable: true
9
- title: verdaccio
10
-
11
- publish:
12
- allow_offline: false
13
-
14
- uplinks:
15
-
16
- log: { type: stdout, format: pretty, level: trace }
17
-
18
- packages:
19
- '@*/*':
20
- access: $all
21
- publish: $all
22
- unpublish: none
23
- '**':
24
- access: $all
25
- publish: $all
26
- unpublish: none
@@ -1,29 +0,0 @@
1
- # storage: this is generated on _helper file
2
-
3
- auth:
4
- htpasswd:
5
- file: ./htpasswd-package
6
-
7
- web:
8
- enable: true
9
-
10
- user_agent: 'custom user agent'
11
-
12
- publish:
13
- allow_offline: false
14
-
15
- uplinks:
16
-
17
- log: { type: stdout, format: pretty, level: trace }
18
-
19
- packages:
20
- '@*/*':
21
- access: $all
22
- publish: $all
23
- unpublish: none
24
- '**':
25
- access: $all
26
- publish: $all
27
- unpublish: none
28
-
29
- _debug: true
@@ -1,29 +0,0 @@
1
- # storage: this is generated on _helper file
2
-
3
- auth:
4
- htpasswd:
5
- file: ./htpasswd-package
6
-
7
- web:
8
- enable: true
9
-
10
- user_agent: false
11
-
12
- publish:
13
- allow_offline: false
14
-
15
- uplinks:
16
-
17
- log: { type: stdout, format: pretty, level: trace }
18
-
19
- packages:
20
- '@*/*':
21
- access: $all
22
- publish: $all
23
- unpublish: none
24
- '**':
25
- access: $all
26
- publish: $all
27
- unpublish: none
28
-
29
- _debug: true
@@ -1,27 +0,0 @@
1
- # storage: this is generated on _helper file
2
-
3
- auth:
4
- htpasswd:
5
- file: ./htpasswd-package
6
-
7
- web:
8
- enable: false
9
-
10
- publish:
11
- allow_offline: false
12
-
13
- uplinks:
14
-
15
- log: { type: stdout, format: pretty, level: trace }
16
-
17
- packages:
18
- '@*/*':
19
- access: $all
20
- publish: $all
21
- unpublish: none
22
- '**':
23
- access: $all
24
- publish: $all
25
- unpublish: none
26
-
27
- _debug: true
@@ -1,119 +0,0 @@
1
- import supertest from 'supertest';
2
- import { describe, expect, test } from 'vitest';
3
-
4
- import { API_ERROR, HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
5
- import { setup } from '@verdaccio/logger';
6
-
7
- import { initializeServer } from './_helper';
8
-
9
- setup({});
10
-
11
- describe('server api', () => {
12
- test('should request any package', async () => {
13
- const app = await initializeServer('conf.yaml');
14
- await supertest(app)
15
- .get('/jquery')
16
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
17
- .expect(HTTP_STATUS.NOT_FOUND);
18
- });
19
-
20
- test('should able to catch non defined routes with 404', async () => {
21
- const app = await initializeServer('conf.yaml');
22
- await supertest(app)
23
- .get('/-/this-does-not-exist-anywhere')
24
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
25
- .expect(HTTP_STATUS.NOT_FOUND);
26
- });
27
-
28
- test('should return index page if web is enabled', async () => {
29
- const app = await initializeServer('conf.yaml');
30
- const response = await supertest(app)
31
- .get('/')
32
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
33
- .expect(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP)
34
- .expect(HTTP_STATUS.OK);
35
- expect(response.text).toMatch('<title>verdaccio</title>');
36
- });
37
-
38
- test('should define rate limit headers', async () => {
39
- const app = await initializeServer('conf.yaml');
40
- await supertest(app)
41
- .get('/')
42
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
43
- .expect(HEADERS.RATELIMIT_LIMIT, '10000')
44
- .expect(HEADERS.RATELIMIT_REMAINING, '9999')
45
- .expect(HTTP_STATUS.OK);
46
- });
47
-
48
- test('should contains cors headers', async () => {
49
- const app = await initializeServer('conf.yaml');
50
- await supertest(app).get('/').expect('access-control-allow-origin', '*').expect(HTTP_STATUS.OK);
51
- });
52
-
53
- test('should contains etag', async () => {
54
- const app = await initializeServer('conf.yaml');
55
- const response = await supertest(app)
56
- .get('/')
57
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
58
- .expect(HTTP_STATUS.OK);
59
- const etag = response.get(HEADERS.ETAG);
60
- expect(typeof etag === 'string').toBeTruthy();
61
- });
62
-
63
- test('should be hidden by default', async () => {
64
- const app = await initializeServer('conf.yaml');
65
- const response = await supertest(app)
66
- .get('/')
67
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
68
- .expect(HTTP_STATUS.OK);
69
- const powered = response.get(HEADERS.POWERED_BY);
70
- expect(powered).toMatch('hidden');
71
- }, 40000);
72
-
73
- test('should not contains powered header', async () => {
74
- const app = await initializeServer('powered-disabled.yaml');
75
- const response = await supertest(app)
76
- .get('/')
77
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
78
- .expect(HTTP_STATUS.OK);
79
- const powered = response.get(HEADERS.POWERED_BY);
80
- expect(powered).toEqual('hidden');
81
- });
82
-
83
- test('should contains custom powered header', async () => {
84
- const app = await initializeServer('powered-custom.yaml');
85
- const response = await supertest(app)
86
- .get('/')
87
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
88
- .expect(HTTP_STATUS.OK);
89
- const powered = response.get(HEADERS.POWERED_BY);
90
- expect(powered).toEqual('custom user agent');
91
- });
92
-
93
- test('should return 404 if web is disabled', async () => {
94
- const app = await initializeServer('web-disabled.yaml');
95
- const response = await supertest(app)
96
- .get('/')
97
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
98
- .expect(HTTP_STATUS.NOT_FOUND);
99
- expect(response.body.error).toEqual(API_ERROR.WEB_DISABLED);
100
- });
101
-
102
- test('should not display debug hook disabled by default', async () => {
103
- const app = await initializeServer('no_debug.yaml');
104
- await supertest(app)
105
- .get('/-/_debug')
106
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
107
- .expect(HTTP_STATUS.NOT_FOUND);
108
- });
109
-
110
- test('should display debug hook if directly enabled', async () => {
111
- const app = await initializeServer('conf.yaml');
112
- const res = await supertest(app)
113
- .get('/-/_debug')
114
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
115
- .expect(HTTP_STATUS.OK);
116
- expect(res.body.pid).toEqual(process.pid);
117
- expect(res.body.mem).toBeDefined();
118
- });
119
- });
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./build"
6
- },
7
- "include": ["src/**/*.ts", "types/*.d.ts"],
8
- "exclude": ["src/**/*.test.ts"]
9
- }
package/tsconfig.json DELETED
@@ -1,44 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.reference.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./build"
6
- },
7
- "include": ["src/**/*", "types/*.d.ts"],
8
- "exclude": ["src/**/*.test.ts"],
9
- "references": [
10
- {
11
- "path": "../../api"
12
- },
13
- {
14
- "path": "../../auth"
15
- },
16
- {
17
- "path": "../../config"
18
- },
19
- {
20
- "path": "../../loaders"
21
- },
22
- {
23
- "path": "../../logger/logger"
24
- },
25
- {
26
- "path": "../../middleware"
27
- },
28
- {
29
- "path": "../../plugins/audit"
30
- },
31
- {
32
- "path": "../../proxy"
33
- },
34
- {
35
- "path": "../../store"
36
- },
37
- {
38
- "path": "../../utils"
39
- },
40
- {
41
- "path": "../../web"
42
- }
43
- ]
44
- }
package/types/custom.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { NextFunction, Request, Response } from 'express';
2
-
3
- import { Logger, RemoteUser } from '@verdaccio/types';
4
-
5
- export type $RequestExtend = Request & { remote_user?: any; log: Logger };
6
- export type $ResponseExtend = Response & { cookies?: any };
7
- export type $NextFunctionVer = NextFunction & any;
8
-
9
- declare global {
10
- namespace Express {
11
- export interface Request {
12
- remote_user: RemoteUser;
13
- log: Logger;
14
- }
15
- }
16
- }