diff --git a/package.json b/package.json index 410c6585d..0659a64b7 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@verdaccio/file-locking": "0.0.7", - "@verdaccio/local-storage": "1.1.2", + "@verdaccio/local-storage": "1.1.3", "@verdaccio/streams": "1.0.0", "JSONStream": "1.3.2", "asciidoctor.js": "1.5.6", @@ -52,7 +52,7 @@ "devDependencies": { "@commitlint/cli": "6.1.3", "@commitlint/config-conventional": "6.1.3", - "@verdaccio/types": "3.1.0", + "@verdaccio/types": "3.2.0", "babel-cli": "6.26.0", "babel-core": "6.26.0", "babel-eslint": "8.2.2", diff --git a/test/flow/plugins/auth/complete.js b/test/flow/plugins/auth/example.auth.plugin.js similarity index 70% rename from test/flow/plugins/auth/complete.js rename to test/flow/plugins/auth/example.auth.plugin.js index 4da7c7c6c..e7a53fab1 100644 --- a/test/flow/plugins/auth/complete.js +++ b/test/flow/plugins/auth/example.auth.plugin.js @@ -1,19 +1,18 @@ // @flow +// this file is not aim to be tested, just to check flow definitions + import Config from '../../../../src/lib/config'; import LoggerApi from '../../../../src/lib/logger'; import type { - AuthPlugin, Config as AppConfig, - IAuthPlugin, + IPluginAuth, Logger, PluginOptions } from '@verdaccio/types'; - -// this class is not aim to be tested, just to check flow definitions -class ExampleAuthPlugin implements IAuthPlugin { +class ExampleAuthPlugin implements IPluginAuth { config: AppConfig; logger: Logger; @@ -45,6 +44,8 @@ const options: PluginOptions = { logger: LoggerApi.logger.child() } -// $FlowFixMe -const instance1: AuthPlugin = new ExampleAuthPlugin(config1, options); -console.log(instance1); \ No newline at end of file +const auth = new ExampleAuthPlugin(config1, options); + +auth.authenticate('user', 'pass', () => {}); +auth.allow_access('packageName', 'user', () => {}); +auth.allow_publish('packageName', 'user', () => {}); diff --git a/test/flow/plugins/middleware/example.middleware.plugin.js b/test/flow/plugins/middleware/example.middleware.plugin.js new file mode 100644 index 000000000..5514ca5e7 --- /dev/null +++ b/test/flow/plugins/middleware/example.middleware.plugin.js @@ -0,0 +1,47 @@ +// @flow + +// this file is not aim to be tested, just to check flow definitions +import Config from '../../../../src/lib/config'; +import {generatePackageTemplate} from '../../../../src/lib/storage-utils'; +import {readFile} from '../../../functional/lib/test.utils'; + +const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`); + +import type { + Config as AppConfig, + IPluginMiddleware, + IBasicStorage, + 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 { + auth.authenticate('user', 'password', () => {}); + auth.allow_access('packageName', 'user', () => {}); + auth.add_user('user', 'password', () => {}); + auth.aesEncrypt(new Buffer('pass')); + // storage + storage.addPackage('name', generatePackageTemplate('test'), () => {}); + storage.addVersion('name', 'version', readMetadata(), 'tag', () => {}); + 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', + self_path: '/home/sotrage' + }); + 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); + /* eslint no-unused-vars: 0 */ + } +} + diff --git a/test/flow/plugins/storage/example.storage.plugin.js b/test/flow/plugins/storage/example.storage.plugin.js new file mode 100644 index 000000000..42f06b8ad --- /dev/null +++ b/test/flow/plugins/storage/example.storage.plugin.js @@ -0,0 +1,139 @@ +// @flow + +// this file is not aim to be tested, just to check flow definitions + +import Config from '../../../../src/lib/config'; +import LoggerApi from '../../../../src/lib/logger'; +import {generatePackageTemplate} from '../../../../src/lib/storage-utils'; +import { UploadTarball, ReadTarball } from '@verdaccio/streams'; + +import type { + Callback, + Config as AppConfig, + Logger, + Package, + // PluginOptions +} from '@verdaccio/types'; + +import type { + IPluginStorage, + IPackageStorageManager, + IPackageStorage +} from '@verdaccio/local-storage'; +import type { IUploadTarball, IReadTarball } from '@verdaccio/streams'; + +class PackageStorage implements IPackageStorageManager { + path: string; + logger: Logger; + + constructor(path: string, logger: Logger) { + this.path = path; + this.logger = logger; + } + + updatePackage(name: string, updateHandler: Callback, + onWrite: Callback, + transformPackage: Function, + onEnd: Callback) { + onEnd(); + } + + deletePackage(fileName: string, callback: Callback) { + callback(); + } + + removePackage(callback: Callback): void { + callback(); + } + + createPackage(name: string, value: Package, cb: Callback) { + cb(); + } + + savePackage(name: string, value: Package, cb: Callback) { + cb(); + } + + readPackage(name: string, cb: Callback) { + cb(); + } + + writeTarball(name: string): IUploadTarball { + const uploadStream = new UploadTarball(); + + return uploadStream; + } + + readTarball(name: string): IReadTarball { + const readTarballStream: IReadTarball = new ReadTarball(); + + return readTarballStream; + } +} + +class ExampleStoragePlugin implements IPluginStorage { + logger: Logger; + config: AppConfig; + + constructor(config: AppConfig, logger: Logger) { + this.config = config; + this.logger = logger; + } + + getSecret(): Promise { + return Promise.resolve(); + } + + setSecret(secret: string): Promise { + return Promise.resolve(); + } + + add(name: string, cb: Callback) { + cb(); + } + + remove(name: string, cb: Callback) { + cb(); + } + + get(cb: Callback) { + cb(); + } + + getPackageStorage(packageInfo: string): IPackageStorage { + return new PackageStorage(packageInfo, this.logger); + } + + search(onPackage: Callback, onEnd: Callback, validateName: any): void { + onPackage(onEnd()); + } +} + +export default ExampleStoragePlugin; + +const config1: AppConfig = new Config({ + storage: './storage', + self_path: '/home/sotrage' +}); + + +const storage = new ExampleStoragePlugin(config1, LoggerApi.logger.child()); + +storage.add('test', () => {}); +storage.remove('test', () => {}); +storage.getSecret().then(() => {}); +storage.setSecret('newSecret').then(() => {}); +storage.search(() => {}, () => {}, 'validateName'); +storage.get(() => {}); + +const storageManager: IPackageStorage = storage.getPackageStorage('test'); + +if (storageManager) { + storageManager.createPackage('test', generatePackageTemplate('test'), () => {}); + storageManager.savePackage('fileName', generatePackageTemplate('test'), () => {}); + storageManager.updatePackage('pkgFileName', () =>{}, () => {}, () => {}, () => {}); + storageManager.deletePackage('test', () => {}); + storageManager.removePackage(() => {}); + storageManager.readPackage('test', () => {}); + storageManager.writeTarball('test'); +} \ No newline at end of file diff --git a/types/index.js b/types/index.js index 451a624c3..11b8ae08a 100644 --- a/types/index.js +++ b/types/index.js @@ -1,6 +1,8 @@ // @flow import type { + IBasicAuth, + IBasicStorage, UpLinkConf, Callback, Versions, @@ -9,6 +11,7 @@ import type { Config, Logger, PackageAccess, + StringValue as verdaccio$StringValue, Package} from '@verdaccio/types'; import type { IUploadTarball, @@ -17,20 +20,22 @@ import type { import type {ILocalData} from '@verdaccio/local-storage'; import type {NextFunction, $Request, $Response} from 'request'; -export type StringValue = string | void | null; +export type StringValue = verdaccio$StringValue; -export interface IAuth { - config: Config; - logger: Logger; - secret: string; - plugins: Array; - aesEncrypt(buf: Buffer): Buffer; +interface IAuthWebUI { + issueUIjwt(user: string, time: string): string; +} + +interface IAuthMiddleware { apiJWTmiddleware(): $NextFunctionVer; webUIJWTmiddleware(): $NextFunctionVer; - authenticate(user: string, password: string, cb: Callback): void; - allow_access(packageName: string, user: string, callback: Callback): void; - issueUIjwt(user: string, time: string): string; - add_user(user: string, password: string, cb: Callback): any; +} + +export interface IAuth extends IBasicAuth, IAuthMiddleware, IAuthWebUI { + config: verdaccio$Config; + logger: verdaccio$Logger; + secret: string; + plugins: Array; } export interface IWebSearch { @@ -103,22 +108,10 @@ export type StartUpConfig = { export type MatchedPackage = PackageAccess | void; -export interface IStorage { +export interface IStorage extends IBasicStorage { config: Config; localData: ILocalData; logger: Logger; - addPackage(name: string, info: Package, callback: Callback): void; - removePackage(name: string, callback: Callback): void; - updateVersions(name: string, packageInfo: Package, callback: Callback): void; - addVersion(name: string, version: string, metadata: Version, tag: StringValue, callback: Callback): void; - mergeTags(name: string, tags: MergeTags, callback: Callback): void; - changePackage(name: string, metadata: Package, revision: 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; - getPackageMetadata(name: string, callback: Callback): void; - search(startKey: string, options: any): IUploadTarball; - getSecret(config: Config): Promise; } export type JWTPayload = { diff --git a/yarn.lock b/yarn.lock index af308aa3d..bc2c4105d 100644 Binary files a/yarn.lock and b/yarn.lock differ