diff --git a/.babelrc b/.babelrc index 617b5c1a3..9a7ab1b1f 100644 --- a/.babelrc +++ b/.babelrc @@ -38,7 +38,6 @@ ] }, "testOldEnv": { - /** FIXME: for an issue on jest env we need to use es2015-node4 **/ "presets": [ "es2015-node4", "flow"], "plugins": [ "transform-class-properties", diff --git a/package.json b/package.json index 0659a64b7..ea3899ad7 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "devDependencies": { "@commitlint/cli": "6.1.3", "@commitlint/config-conventional": "6.1.3", - "@verdaccio/types": "3.2.0", + "@verdaccio/types": "3.3.0", "babel-cli": "6.26.0", "babel-core": "6.26.0", "babel-eslint": "8.2.2", diff --git a/src/api/index.js b/src/api/index.js index d69802a2f..f1d95b2d4 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -5,18 +5,26 @@ import express from 'express'; import compression from 'compression'; import cors from 'cors'; import Storage from '../lib/storage'; -import {loadPlugin} from '../lib/plugin-loader'; +import loadPlugin from '../lib/plugin-loader'; import hookDebug from './debug'; import Auth from '../lib/auth'; import apiEndpoint from './endpoint'; - -import type {$Application} from 'express'; -import type {$ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler, IAuth} from '../../types'; -import type {Config as IConfig} from '@verdaccio/types'; import {ErrorCode} from '../lib/utils'; import {API_ERROR, HTTP_STATUS} from '../lib/constants'; import AppConfig from '../lib/config'; +import type {$Application} from 'express'; +import type { + $ResponseExtend, + $RequestExtend, + $NextFunctionVer, + IStorageHandler, + IAuth} from '../../types'; +import type { + Config as IConfig, + IPluginMiddleware, +} from '@verdaccio/types'; + const LoggerApp = require('../lib/logger'); const Middleware = require('./middleware'); const Cats = require('../lib/status-cats'); @@ -54,10 +62,10 @@ const defineAPI = function(config: IConfig, storage: IStorageHandler) { config: config, logger: LoggerApp.logger, }; - const plugins = loadPlugin(config, config.middlewares, plugin_params, function(plugin) { + const plugins = loadPlugin(config, config.middlewares, plugin_params, function(plugin: IPluginMiddleware) { return plugin.register_middlewares; }); - plugins.forEach(function(plugin) { + plugins.forEach((plugin) => { plugin.register_middlewares(app, auth, storage); }); diff --git a/src/lib/auth.js b/src/lib/auth.js index f5b61d599..8a1cce9d3 100644 --- a/src/lib/auth.js +++ b/src/lib/auth.js @@ -3,7 +3,7 @@ import _ from 'lodash'; import {API_ERROR, HTTP_STATUS, ROLES, TOKEN_BASIC, TOKEN_BEARER} from './constants'; -import {loadPlugin} from '../lib/plugin-loader'; +import loadPlugin from '../lib/plugin-loader'; import {buildBase64Buffer, ErrorCode} from './utils'; import {aesDecrypt, aesEncrypt, signPayload, verifyPayload} from './crypto-utils'; import {getDefaultPlugins} from './auth-utils'; @@ -39,7 +39,7 @@ class Auth implements IAuth { logger: this.logger, }; - return loadPlugin(config, config.auth, pluginOptions, (plugin: IPluginAuth) => { + return loadPlugin(config, config.auth, pluginOptions, (plugin: IPluginAuth) => { const {authenticate, allow_access, allow_publish} = plugin; return authenticate || allow_access || allow_publish; diff --git a/src/lib/local-storage.js b/src/lib/local-storage.js index 327d75fd9..4b45c62e0 100644 --- a/src/lib/local-storage.js +++ b/src/lib/local-storage.js @@ -13,7 +13,7 @@ fileExist, noSuchFile, DEFAULT_REVISION, pkgFileName, } from './storage-utils'; import {createTarballHash} from './crypto-utils'; import {prepareSearchPackage} from './storage-utils'; -import {loadPlugin} from '../lib/plugin-loader'; +import loadPlugin from '../lib/plugin-loader'; import LocalDatabase from '@verdaccio/local-storage'; import {UploadTarball, ReadTarball} from '@verdaccio/streams'; import type { @@ -570,7 +570,7 @@ class LocalStorage implements IStorage { * @return {Function} */ search(startKey: string, options: any) { - const stream = new UploadTarball({objectMode: true}); + const stream = new ReadTarball({objectMode: true}); this._searchEachPackage((item, cb) => { if (item.time > parseInt(startKey, 10)) { diff --git a/src/lib/plugin-loader.js b/src/lib/plugin-loader.js index 099c44e01..1bfdeaf27 100644 --- a/src/lib/plugin-loader.js +++ b/src/lib/plugin-loader.js @@ -45,7 +45,7 @@ function isES6(plugin) { * @param {*} sanityCheck callback that check the shape that should fulfill the plugin * @return {Array} list of plugins */ -function loadPlugin( +export default function loadPlugin( config: Config, pluginConfigs: any = {}, params: any, @@ -97,5 +97,3 @@ function loadPlugin( return plugin; }); } - -export {loadPlugin}; diff --git a/test/flow/plugins/middleware/example.middleware.plugin.js b/test/flow/plugins/middleware/example.middleware.plugin.js index 5514ca5e7..2e5767f7e 100644 --- a/test/flow/plugins/middleware/example.middleware.plugin.js +++ b/test/flow/plugins/middleware/example.middleware.plugin.js @@ -10,13 +10,13 @@ const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/par import type { Config as AppConfig, IPluginMiddleware, - IBasicStorage, + IStorageManager, IBasicAuth, } from '@verdaccio/types'; import type { IUploadTarball, IReadTarball } from '@verdaccio/streams'; export default class ExampleMiddlewarePlugin implements IPluginMiddleware { - register_middlewares(app: any, auth: IBasicAuth, storage: IBasicStorage): void { + register_middlewares(app: any, auth: IBasicAuth, storage: IStorageManager): void { auth.authenticate('user', 'password', () => {}); auth.allow_access('packageName', 'user', () => {}); auth.add_user('user', 'password', () => {}); @@ -27,10 +27,8 @@ export default class ExampleMiddlewarePlugin implements IPluginMiddleware { storage.mergeTags('name', {'latest': '1.0.0'}, () => {}); storage.changePackage('name', readMetadata(), 'revision', () => {}); storage.removePackage('name', () => {}); - storage.updateVersions('name', generatePackageTemplate('test'), () => {}); storage.mergeTags('name', {'latest': '1.0.0'}, () => {}); storage.removeTarball('name', 'filename', 'revision', () => {}); - storage.getPackageMetadata('test', () => {}); /* eslint no-unused-vars: 0 */ const config1: AppConfig = new Config({ storage: './storage', @@ -39,8 +37,7 @@ export default class ExampleMiddlewarePlugin implements IPluginMiddleware { const add: IUploadTarball = storage.addTarball('name', 'filename'); storage.getTarball('name', 'filename'); const read: IReadTarball = storage.getTarball('name', 'filename'); - const search: IUploadTarball = storage.search('test'); - const secret: Promise = storage.getSecret(config1); + const search: IReadTarball = storage.search('test'); /* eslint no-unused-vars: 0 */ } } diff --git a/test/unit/api/plugin_loader.spec.js b/test/unit/api/plugin_loader.spec.js index 906146239..04ca89757 100644 --- a/test/unit/api/plugin_loader.spec.js +++ b/test/unit/api/plugin_loader.spec.js @@ -1,5 +1,5 @@ import path from 'path'; -import {loadPlugin} from '../../../src/lib/plugin-loader'; +import loadPlugin from '../../../src/lib/plugin-loader'; import logger from '../../../src/lib/logger'; logger.setup([]); diff --git a/types/index.js b/types/index.js index 11b8ae08a..9956d46b7 100644 --- a/types/index.js +++ b/types/index.js @@ -3,18 +3,17 @@ import type { IBasicAuth, IBasicStorage, + IStorageManager, UpLinkConf, Callback, Versions, Version, - MergeTags, Config, Logger, PackageAccess, StringValue as verdaccio$StringValue, Package} from '@verdaccio/types'; import type { - IUploadTarball, IReadTarball, } from '@verdaccio/streams'; import type {ILocalData} from '@verdaccio/local-storage'; @@ -22,6 +21,42 @@ import type {NextFunction, $Request, $Response} from 'request'; export type StringValue = verdaccio$StringValue; +export type StartUpConfig = { + storage: string; + self_path: string; +} + +export type MatchedPackage = PackageAccess | void; + +export type JWTPayload = { + user: string; + group: string | void; +} + +export type JWTSignOptions = { + expiresIn: string; +} + +export type ProxyList = { + [key: string]: IProxy; +} + +export type Utils = { + ErrorCode: any; + getLatestVersion: Callback; + isObject: (value: any) => boolean; + validate_name: (value: any) => boolean; + tag_version: (value: any, version: string, tag: string) => void; + normalizeDistTags: (pkg: Package) => void; + semverSort: (keys: Array) => Array; +} + +export type $RequestExtend = $Request & {remote_user?: any} +export type $ResponseExtend = $Response & {cookies?: any} +export type $NextFunctionVer = NextFunction & mixed; +export type $SidebarPackage = Package & {latest: mixed} + + interface IAuthWebUI { issueUIjwt(user: string, time: string): string; } @@ -66,64 +101,15 @@ export interface IProxy { getRemoteMetadata(name: string, options: any, callback: Callback): void; } -export type ProxyList = { - [key: string]: IProxy; -} - -export type Utils = { - ErrorCode: any; - getLatestVersion: Callback; - isObject: (value: any) => boolean; - validate_name: (value: any) => boolean; - tag_version: (value: any, version: string, tag: string) => void; - normalizeDistTags: (pkg: Package) => void; - semverSort: (keys: Array) => Array; -} - -export interface IStorageHandler { - config: Config; - localStorage: IStorage; - logger: Logger; - uplinks: ProxyList; - addPackage(name: string, metadata: any, callback: Function): Promise; - init(config: Config): Promise; - addVersion(name: string, version: string, metadata: Version, tag: StringValue, callback: Callback): void; - mergeTags(name: string, tagHash: MergeTags, callback: Callback): void; - changePackage(name: string, metadata: Package, revision: string, callback: Callback): void; - removePackage(name: string, callback: Callback): void; - removeTarball(name: string, filename: string, revision: string, callback: Callback): void; - addTarball(name: string, filename: string): IUploadTarball; - getTarball(name: string, filename: string): IReadTarball; - getPackage(options: any): void; - search(startkey: string, options: any): void; - getLocalDatabase(callback: Callback): void; - _syncUplinksMetadata(name: string, packageInfo: Package, options: any, callback: Callback): void; - _updateVersionsHiddenUpLink(versions: Versions, upLink: IProxy): void; -} - -export type StartUpConfig = { - storage: string; - self_path: string; -} - -export type MatchedPackage = PackageAccess | void; - export interface IStorage extends IBasicStorage { config: Config; localData: ILocalData; logger: Logger; } -export type JWTPayload = { - user: string; - group: string | void; +export interface IStorageHandler extends IStorageManager { + localStorage: IStorage; + uplinks: ProxyList; + _syncUplinksMetadata(name: string, packageInfo: Package, options: any, callback: Callback): void; + _updateVersionsHiddenUpLink(versions: Versions, upLink: IProxy): void; } - -export type JWTSignOptions = { - expiresIn: string; -} - -export type $RequestExtend = $Request & {remote_user?: any} -export type $ResponseExtend = $Response & {cookies?: any} -export type $NextFunctionVer = NextFunction & mixed; -export type $SidebarPackage = Package & {latest: mixed} diff --git a/yarn.lock b/yarn.lock index bc2c4105d..cbb5555d9 100644 Binary files a/yarn.lock and b/yarn.lock differ