Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@verdaccio/local-storage

Package Overview
Dependencies
Maintainers
4
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@verdaccio/local-storage - npm Package Compare versions

Comparing version 10.3.3 to 10.3.4

lib/dir-utils.d.ts

32

lib/local-database.d.ts

@@ -1,4 +0,7 @@

import { Callback, Config, IPackageStorage, IPluginStorage, LocalStorage, Logger } from '@verdaccio/legacy-types';
import { Callback, Config, Logger } from '@verdaccio/types';
import { searchUtils } from '@verdaccio/core';
import { LocalStorage } from './utils';
import LocalDriver from './local-fs';
import TokenActions from './token';
declare class LocalDatabase extends TokenActions implements IPluginStorage<{}> {
declare class LocalDatabase extends TokenActions {
path: string;

@@ -13,3 +16,9 @@ logger: Logger;

add(name: string, cb: Callback): void;
search(onPackage: Callback, onEnd: Callback, validateName: (name: string) => boolean): void;
/**
* Filter and only match those values that the query define.
**/
filterByQuery(results: searchUtils.SearchItemPkg[], query: searchUtils.SearchQuery): Promise<searchUtils.SearchItemPkg[]>;
getScore(_pkg: searchUtils.SearchItemPkg): Promise<searchUtils.Score>;
private _getCustomPackageLocalStorages;
search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>;
remove(name: string, cb: Callback): void;

@@ -21,6 +30,5 @@ /**

get(cb: Callback): void;
getPackageStorage(packageName: string): IPackageStorage;
getPackageStorage(packageName: string): LocalDriver | undefined;
clean(): void;
private getTime;
private _getCustomPackageLocalStorages;
/**

@@ -31,3 +39,10 @@ * Syncronize {create} database whether does not exist.

private _sync;
private getBaseConfigPath;
/**
* The field storage could be absolute or relative.
* If relative, it will be resolved against the config path.
* If absolute, it will be returned as is.
**/
private getStoragePath;
/**
* Verify the right local storage location.

@@ -40,9 +55,2 @@ * @param {String} path

/**
* Build the local database path.
* @param {Object} config
* @return {string|String|*}
* @private
*/
private _buildStoragePath;
/**
* Fetch local packages.

@@ -49,0 +57,0 @@ * @private

@@ -11,5 +11,5 @@ "use strict";

var _lodash = _interopRequireDefault(require("lodash"));
var _async = _interopRequireDefault(require("async"));
var _mkdirp = _interopRequireDefault(require("mkdirp"));
var _commonsApi = require("@verdaccio/commons-api");
var _dirUtils = require("./dir-utils");
var _core = require("@verdaccio/core");
var _localFs = _interopRequireWildcard(require("./local-fs"));

@@ -21,5 +21,3 @@ var _pkgUtils = require("./pkg-utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const DEPRECATED_DB_NAME = '.sinopia-db.json';
const DB_NAME = '.verdaccio-db.json';
const debug = (0, _debug.default)('verdaccio:plugin:local-storage');
const debug = (0, _debug.default)('verdaccio:plugin:local-storage:database');
class LocalDatabase extends _token.default {

@@ -29,3 +27,3 @@ constructor(config, logger) {

this.config = config;
this.path = this._buildStoragePath(config);
this.path = this._dbGenPath(_core.fileUtils.Files.DatabaseName, config);
this.logger = logger;

@@ -55,80 +53,72 @@ this.locked = false;

}
search(onPackage, onEnd, validateName) {
const storages = this._getCustomPackageLocalStorages();
debug(`search custom local packages: %o`, JSON.stringify(storages));
const base = _path.default.dirname(this.config.self_path);
const self = this;
const storageKeys = Object.keys(storages);
debug(`search base: %o keys: %o`, base, storageKeys);
_async.default.eachSeries(storageKeys, function (storage, cb) {
const position = storageKeys.indexOf(storage);
const base2 = _path.default.join(position !== 0 ? storageKeys[0] : '');
const storagePath = _path.default.resolve(base, base2, storage);
debug('search path: %o : %o', storagePath, storage);
_fs.default.readdir(storagePath, (err, files) => {
if (err) {
return cb(err);
/**
* Filter and only match those values that the query define.
**/
async filterByQuery(results, query) {
// FUTURE: apply new filters, keyword, version, ...
return results.filter(item => {
var _item$name;
return (item === null || item === void 0 ? void 0 : (_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.match(query.text)) !== null;
});
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getScore(_pkg) {
// TODO: there is no particular reason to predefined scores
// could be improved by using
return Promise.resolve({
final: 1,
detail: {
maintenance: 0,
popularity: 1,
quality: 1
}
});
}
_getCustomPackageLocalStorages() {
const storages = new Map();
const {
packages
} = this.config;
if (packages) {
Object.keys(packages || {}).map(pkg => {
const {
storage
} = packages[pkg];
if (typeof storage === 'string') {
const storagePath = _path.default.join(this.getStoragePath(), storage);
debug('add custom storage for %s on %s', storage, storagePath);
storages.set(storage, storagePath);
}
_async.default.eachSeries(files, function (file, cb) {
debug('local-storage: [search] search file path: %o', file);
if (storageKeys.includes(file)) {
return cb();
}
if (file.match(/^@/)) {
// scoped
const fileLocation = _path.default.resolve(base, storage, file);
debug('search scoped file location: %o', fileLocation);
_fs.default.readdir(fileLocation, function (err, files) {
if (err) {
return cb(err);
}
_async.default.eachSeries(files, (file2, cb) => {
if (validateName(file2)) {
const packagePath = _path.default.resolve(base, storage, file, file2);
_fs.default.stat(packagePath, (err, stats) => {
if (_lodash.default.isNil(err) === false) {
return cb(err);
}
const item = {
name: `${file}/${file2}`,
path: packagePath,
time: stats.mtime.getTime()
};
onPackage(item, cb);
});
} else {
cb();
}
}, cb);
});
} else if (validateName(file)) {
const base2 = _path.default.join(position !== 0 ? storageKeys[0] : '');
const packagePath = _path.default.resolve(base, base2, storage, file);
debug('search file location: %o', packagePath);
_fs.default.stat(packagePath, (err, stats) => {
if (_lodash.default.isNil(err) === false) {
return cb(err);
}
onPackage({
name: file,
path: packagePath,
time: self.getTime(stats.mtime.getTime(), stats.mtime)
}, cb);
});
} else {
cb();
}
}, cb);
});
},
// @ts-ignore
onEnd);
}
return storages;
}
async search(query) {
const results = [];
const storagePath = this.getStoragePath();
const storages = this._getCustomPackageLocalStorages();
const packagesOnStorage = await this.filterByQuery(await (0, _dirUtils.searchOnStorage)(storagePath, storages), query);
debug('packages found %o', packagesOnStorage.length);
for (let storage of packagesOnStorage) {
// check if package is listed on the cache private database
const isPrivate = this.data.list.includes(storage.name);
const score = await this.getScore(storage);
results.push({
package: storage,
verdaccioPrivate: isPrivate,
verdaccioPkgCached: !isPrivate,
score
});
}
return results;
}
remove(name, cb) {
this.get((err, data) => {
if (err) {
cb((0, _commonsApi.getInternalError)('error remove private package'));
cb(_core.errorUtils.getInternalError('error remove private package'));
this.logger.error({
err
}, '[local-storage/remove]: remove the private package has failed @{err}');
}, 'remove the private package has failed @{err}');
debug('error on remove package %o', name);

@@ -173,24 +163,3 @@ }

}
_getCustomPackageLocalStorages() {
const storages = {};
// add custom storage if exist
if (this.config.storage) {
storages[this.config.storage] = true;
}
const {
packages
} = this.config;
if (packages) {
const listPackagesConf = Object.keys(packages || {});
listPackagesConf.map(pkg => {
const storage = packages[pkg].storage;
if (storage) {
storages[storage] = false;
}
});
}
return storages;
}
/**

@@ -225,4 +194,24 @@ * Syncronize {create} database whether does not exist.

}
getBaseConfigPath() {
return _path.default.dirname(this.config.configPath);
}
/**
* The field storage could be absolute or relative.
* If relative, it will be resolved against the config path.
* If absolute, it will be returned as is.
**/
getStoragePath() {
const {
storage
} = this.config;
if (typeof storage !== 'string') {
throw new TypeError('storage field is mandatory');
}
const storagePath = _path.default.isAbsolute(storage) ? storage : _path.default.normalize(_path.default.join(this.getBaseConfigPath(), storage));
debug('storage path %o', storagePath);
return storagePath;
}
/**
* Verify the right local storage location.

@@ -246,26 +235,2 @@ * @param {String} path

/**
* Build the local database path.
* @param {Object} config
* @return {string|String|*}
* @private
*/
_buildStoragePath(config) {
const sinopiadbPath = this._dbGenPath(DEPRECATED_DB_NAME, config);
try {
_fs.default.accessSync(sinopiadbPath, _fs.default.constants.F_OK);
// @ts-ignore
process.emitWarning('Database name deprecated!', {
code: 'VERCODE01',
detail: `Please rename database name from ${DEPRECATED_DB_NAME} to ${DB_NAME}`
});
return sinopiadbPath;
} catch (err) {
if (err.code === _localFs.noSuchFile) {
return this._dbGenPath(DB_NAME, config);
}
throw err;
}
}
/**
* Fetch local packages.

@@ -272,0 +237,0 @@ * @private

/// <reference types="node" />
import { ReadTarball } from '@verdaccio/streams';
import { Callback, Logger, Package, ILocalPackageManager, IUploadTarball } from '@verdaccio/legacy-types';
import { VerdaccioError } from '@verdaccio/commons-api';
import { UploadTarball, ReadTarball } from '@verdaccio/streams';
import { Callback, Logger, Package } from '@verdaccio/types';
import { VerdaccioError } from '@verdaccio/core';
export declare const fileExist = "EEXISTS";

@@ -10,7 +10,4 @@ export declare const noSuchFile = "ENOENT";

export declare const fSError: (message: string, code?: number) => VerdaccioError;
export declare type ILocalFSPackageManager = ILocalPackageManager & {
export default class LocalFS {
path: string;
};
export default class LocalFS implements ILocalFSPackageManager {
path: string;
logger: Logger;

@@ -39,3 +36,3 @@ constructor(path: string, logger: Logger);

readPackage(name: string, cb: Callback): void;
writeTarball(name: string): IUploadTarball;
writeTarball(name: string): UploadTarball;
readTarball(name: string): ReadTarball;

@@ -42,0 +39,0 @@ private _createFile;

@@ -14,3 +14,3 @@ "use strict";

var _fileLocking = require("@verdaccio/file-locking");
var _commonsApi = require("@verdaccio/commons-api");
var _core = require("@verdaccio/core");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -29,3 +29,3 @@ /* eslint-disable no-undef */

const fSError = function (message, code = 409) {
const err = (0, _commonsApi.getCode)(code, message);
const err = _core.errorUtils.getCode(code, message);
// FIXME: we should return http-status codes here instead, future improvement

@@ -109,5 +109,5 @@ // @ts-ignore

if (err.code === resourceNotAvailable) {
return unLockCallback((0, _commonsApi.getInternalError)('resource temporarily unavailable'));
return unLockCallback(_core.errorUtils.getInternalError('resource temporarily unavailable'));
} else if (err.code === noSuchFile) {
return unLockCallback((0, _commonsApi.getNotFound)());
return unLockCallback(_core.errorUtils.getNotFound());
} else {

@@ -114,0 +114,0 @@ return unLockCallback(err);

@@ -1,2 +0,3 @@

import { LocalStorage, Logger } from '@verdaccio/legacy-types';
import { Logger } from '@verdaccio/types';
import { LocalStorage } from './utils';
export declare function loadPrivatePackages(path: string, logger: Logger): LocalStorage;
import low from 'lowdb';
import { ITokenActions, Config, Token, TokenFilter } from '@verdaccio/legacy-types';
import { ITokenActions, Config, Token, TokenFilter } from '@verdaccio/types';
export default class TokenActions implements ITokenActions {

@@ -4,0 +4,0 @@ config: Config;

@@ -22,3 +22,7 @@ "use strict";

_dbGenPath(dbName, config) {
return _path.default.join(_path.default.resolve(_path.default.dirname(config.self_path || ''), config.storage, dbName));
var _config$configPath;
// TODO: self_path is a legacy property and is deprecated
// TODO: display deprecation warning for self_path
const selfPath = (_config$configPath = config.configPath) !== null && _config$configPath !== void 0 ? _config$configPath : config.self_path;
return _path.default.join(_path.default.resolve(_path.default.dirname(selfPath || ''), config.storage, dbName));
}

@@ -25,0 +29,0 @@ async getTokenDb() {

/// <reference types="node" />
import fs from 'fs';
export declare type LocalStorage = {
list: any;
secret: string;
};
export declare function getFileStats(packagePath: string): Promise<fs.Stats>;

@@ -4,0 +8,0 @@ export declare function readDirectory(packagePath: string): Promise<string[]>;

{
"name": "@verdaccio/local-storage",
"version": "10.3.3",
"version": "10.3.4",
"description": "Local storage implementation",

@@ -34,7 +34,7 @@ "keywords": [

"dependencies": {
"@verdaccio/commons-api": "10.2.0",
"@verdaccio/core": "7.0.0-next.1",
"@verdaccio/file-locking": "10.3.1",
"@verdaccio/streams": "10.2.1",
"async": "3.2.4",
"debug": "4.3.4",
"globby": "11.1.0",
"lodash": "4.17.21",

@@ -45,5 +45,7 @@ "lowdb": "1.0.0",

"devDependencies": {
"@types/express": "^4.17.17",
"@types/minimatch": "^3.0.3",
"@types/node": "^14.0.0",
"@verdaccio/legacy-types": "1.0.1",
"@types/node": "^20.5.8",
"@verdaccio/config": "7.0.0-next.1",
"@verdaccio/types": "12.0.0-next.0",
"minimatch": "^4.0.0",

@@ -50,0 +52,0 @@ "rmdir-sync": "^1.0.1"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc