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

verdaccio-aws-s3-storage

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

verdaccio-aws-s3-storage - npm Package Compare versions

Comparing version 11.0.0-6-next.5 to 11.0.0-6-next.6

8

build/index.d.ts

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

import { Logger, Config, Callback, IPluginStorage, PluginOptions, Token, TokenFilter } from '@verdaccio/types';
import { Logger, Config, IPluginStorage, PluginOptions, Token, TokenFilter } from '@verdaccio/types';
import { S3Config } from './config';

@@ -13,7 +13,7 @@ import S3PackageManager from './s3PackageManager';

setSecret(secret: string): Promise<void>;
add(name: string, callback: Callback): void;
add(name: string): Promise<void>;
search(onPackage: Function, onEnd: Function): Promise<void>;
private _fetchPackageInfo;
remove(name: string, callback: Callback): void;
get(callback: Callback): void;
remove(name: string): Promise<void>;
get(): Promise<any>;
private _sync;

@@ -20,0 +20,0 @@ getPackageStorage(packageName: string): S3PackageManager;

@@ -82,23 +82,25 @@ "use strict";

add(name, callback) {
this.logger.debug({
name
}, 's3: [add] private package @{name}');
async add(name) {
return new Promise((resolve, reject) => {
this.logger.debug({
name
}, 's3: [add] private package @{name}');
this._getData().then(async data => {
if (data.list.indexOf(name) === -1) {
data.list.push(name);
this.logger.trace({
name
}, 's3: [add] @{name} has been added');
this._getData().then(async data => {
if (data.list.indexOf(name) === -1) {
data.list.push(name);
this.logger.trace({
name
}, 's3: [add] @{name} has been added');
try {
await this._sync();
callback(null);
} catch (err) {
callback(err);
try {
await this._sync();
resolve();
} catch (err) {
reject(err);
}
} else {
resolve();
}
} else {
callback(null);
}
});
});

@@ -161,42 +163,42 @@ }

remove(name, callback) {
async remove(name) {
this.logger.debug({
name
}, 's3: [remove] @{name}');
this.get(async (err, data) => {
if (err) {
this.logger.error({
err
}, 's3: [remove] error: @{err}');
callback((0, _commonsApi.getInternalError)('something went wrong on remove a package'));
}
let data;
const pkgName = data.indexOf(name);
try {
data = await this.get();
} catch (err) {
this.logger.error({
err
}, 's3: [remove] error: @{err}');
throw (0, _commonsApi.getInternalError)('something went wrong on remove a package');
}
if (pkgName !== -1) {
const data = await this._getData();
data.list.splice(pkgName, 1);
this.logger.debug({
pkgName
}, 's3: [remove] sucessfully removed @{pkgName}');
}
const pkgName = data.indexOf(name);
try {
this.logger.trace('s3: [remove] starting sync');
await this._sync();
this.logger.trace('s3: [remove] finish sync');
callback(null);
} catch (err) {
this.logger.error({
err
}, 's3: [remove] sync error: @{err}');
callback(err);
}
});
if (pkgName !== -1) {
const data = await this._getData();
data.list.splice(pkgName, 1);
this.logger.debug({
pkgName
}, 's3: [remove] sucessfully removed @{pkgName}');
}
try {
this.logger.trace('s3: [remove] starting sync');
await this._sync();
this.logger.trace('s3: [remove] finish sync');
} catch (err) {
this.logger.error({
err
}, 's3: [remove] sync error: @{err}');
throw err;
}
}
get(callback) {
async get() {
this.logger.debug('s3: [get]');
this._getData().then(data => callback(null, data.list));
return this._getData().then(data => Promise.resolve(data.list));
} // Create/write database file to s3

@@ -203,0 +205,0 @@

import { UploadTarball, ReadTarball } from '@verdaccio/streams';
import { Callback, Logger, Package, ILocalPackageManager, CallbackAction, ReadPackageCallback } from '@verdaccio/types';
import { Callback, Logger, Package, ILocalPackageManager, CallbackAction } from '@verdaccio/types';
import { S3Config } from './config';

@@ -13,9 +13,9 @@ export default class S3PackageManager implements ILocalPackageManager {

private _getData;
deletePackage(fileName: string, callback: Callback): void;
removePackage(callback: CallbackAction): void;
deletePackage(fileName: string): Promise<void>;
removePackage(): Promise<void>;
createPackage(name: string, value: Package, callback: CallbackAction): void;
savePackage(name: string, value: Package, callback: CallbackAction): void;
readPackage(name: string, callback: ReadPackageCallback): void;
readPackage(name: string, callback: any): void;
writeTarball(name: string): UploadTarball;
readTarball(name: string): ReadTarball;
}

@@ -160,25 +160,29 @@ "use strict";

deletePackage(fileName, callback) {
this.s3.deleteObject({
Bucket: this.config.bucket,
Key: `${this.packagePath}/${fileName}`
}, err => {
if (err) {
callback(err);
} else {
callback(null);
}
deletePackage(fileName) {
return new Promise((resolve, reject) => {
this.s3.deleteObject({
Bucket: this.config.bucket,
Key: `${this.packagePath}/${fileName}`
}, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
removePackage(callback) {
(0, _deleteKeyPrefix.deleteKeyPrefix)(this.s3, {
Bucket: this.config.bucket,
Prefix: (0, _addTrailingSlash.default)(this.packagePath)
}, function (err) {
if (err && (0, _s3Errors.is404Error)(err)) {
callback(null);
} else {
callback(err);
}
removePackage() {
return new Promise((resolve, reject) => {
(0, _deleteKeyPrefix.deleteKeyPrefix)(this.s3, {
Bucket: this.config.bucket,
Prefix: (0, _addTrailingSlash.default)(this.packagePath)
}, function (err) {
if (err && (0, _s3Errors.is404Error)(err)) {
resolve();
} else {
reject(err);
}
});
});

@@ -185,0 +189,0 @@ }

# Change Log
## 11.0.0-6-next.6
### Major Changes
- 459b6fa7: refactor: search v1 endpoint and local-database
- refactor search `api v1` endpoint, improve performance
- remove usage of `async` dependency https://github.com/verdaccio/verdaccio/issues/1225
- refactor method storage class
- create new module `core` to reduce the ammount of modules with utilities
- use `undici` instead `node-fetch`
- use `fastify` instead `express` for functional test
### Breaking changes
- plugin storage API changes
- remove old search endpoint (return 404)
- filter local private packages at plugin level
The storage api changes for methods `get`, `add`, `remove` as promise base. The `search` methods also changes and recieves a `query` object that contains all query params from the client.
```ts
export interface IPluginStorage<T> extends IPlugin {
add(name: string): Promise<void>;
remove(name: string): Promise<void>;
get(): Promise<any>;
init(): Promise<void>;
getSecret(): Promise<string>;
setSecret(secret: string): Promise<any>;
getPackageStorage(packageInfo: string): IPackageStorage;
search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>;
saveToken(token: Token): Promise<any>;
deleteToken(user: string, tokenKey: string): Promise<any>;
readTokens(filter: TokenFilter): Promise<Token[]>;
}
```
### Patch Changes
- Updated dependencies [459b6fa7]
- @verdaccio/commons-api@11.0.0-6-next.4
- @verdaccio/streams@11.0.0-6-next.4
## 11.0.0-6-next.5

@@ -4,0 +47,0 @@

{
"name": "verdaccio-aws-s3-storage",
"version": "11.0.0-6-next.5",
"version": "11.0.0-6-next.6",
"description": "AWS S3 storage implementation for Verdaccio",

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

"dependencies": {
"@verdaccio/commons-api": "11.0.0-alpha.3",
"@verdaccio/streams": "11.0.0-alpha.3",
"@verdaccio/commons-api": "11.0.0-6-next.4",
"@verdaccio/streams": "11.0.0-6-next.4",
"aws-sdk": "2.981.0"
},
"devDependencies": {
"@verdaccio/types": "11.0.0-6-next.7",
"@verdaccio/types": "11.0.0-6-next.8",
"recursive-readdir": "2.2.2"

@@ -42,0 +42,0 @@ },

@@ -5,3 +5,2 @@ import {

Config,
Callback,
IPluginStorage,

@@ -79,17 +78,19 @@ PluginOptions,

public add(name: string, callback: Callback): void {
this.logger.debug({ name }, 's3: [add] private package @{name}');
this._getData().then(async (data) => {
if (data.list.indexOf(name) === -1) {
data.list.push(name);
this.logger.trace({ name }, 's3: [add] @{name} has been added');
try {
await this._sync();
callback(null);
} catch (err: any) {
callback(err);
async add(name: string): Promise<void> {
return new Promise((resolve, reject) => {
this.logger.debug({ name }, 's3: [add] private package @{name}');
this._getData().then(async (data) => {
if (data.list.indexOf(name) === -1) {
data.list.push(name);
this.logger.trace({ name }, 's3: [add] @{name} has been added');
try {
await this._sync();
resolve();
} catch (err: any) {
reject(err);
}
} else {
resolve();
}
} else {
callback(null);
}
});
});

@@ -146,32 +147,32 @@ }

public remove(name: string, callback: Callback): void {
async remove(name: string): Promise<void> {
this.logger.debug({ name }, 's3: [remove] @{name}');
this.get(async (err, data) => {
if (err) {
this.logger.error({ err }, 's3: [remove] error: @{err}');
callback(getInternalError('something went wrong on remove a package'));
}
let data;
try {
data = await this.get();
} catch (err) {
this.logger.error({ err }, 's3: [remove] error: @{err}');
throw getInternalError('something went wrong on remove a package');
}
const pkgName = data.indexOf(name);
if (pkgName !== -1) {
const data = await this._getData();
data.list.splice(pkgName, 1);
this.logger.debug({ pkgName }, 's3: [remove] sucessfully removed @{pkgName}');
}
const pkgName = data.indexOf(name);
if (pkgName !== -1) {
const data = await this._getData();
data.list.splice(pkgName, 1);
this.logger.debug({ pkgName }, 's3: [remove] sucessfully removed @{pkgName}');
}
try {
this.logger.trace('s3: [remove] starting sync');
await this._sync();
this.logger.trace('s3: [remove] finish sync');
callback(null);
} catch (err: any) {
this.logger.error({ err }, 's3: [remove] sync error: @{err}');
callback(err);
}
});
try {
this.logger.trace('s3: [remove] starting sync');
await this._sync();
this.logger.trace('s3: [remove] finish sync');
} catch (err: any) {
this.logger.error({ err }, 's3: [remove] sync error: @{err}');
throw err;
}
}
public get(callback: Callback): void {
async get(): Promise<any> {
this.logger.debug('s3: [get]');
this._getData().then((data) => callback(null, data.list));
return this._getData().then((data) => Promise.resolve(data.list));
}

@@ -178,0 +179,0 @@

import { S3, AWSError } from 'aws-sdk';
import { UploadTarball, ReadTarball } from '@verdaccio/streams';
import { HEADERS, HTTP_STATUS, VerdaccioError } from '@verdaccio/commons-api';
import {
Callback,
Logger,
Package,
ILocalPackageManager,
CallbackAction,
ReadPackageCallback,
} from '@verdaccio/types';
import { Callback, Logger, Package, ILocalPackageManager, CallbackAction } from '@verdaccio/types';
import { HttpError } from 'http-errors';

@@ -148,33 +141,37 @@

public deletePackage(fileName: string, callback: Callback): void {
this.s3.deleteObject(
{
Bucket: this.config.bucket,
Key: `${this.packagePath}/${fileName}`,
},
(err) => {
if (err) {
callback(err);
} else {
callback(null);
public deletePackage(fileName: string): Promise<void> {
return new Promise((resolve, reject) => {
this.s3.deleteObject(
{
Bucket: this.config.bucket,
Key: `${this.packagePath}/${fileName}`,
},
(err) => {
if (err) {
reject(err);
} else {
resolve();
}
}
}
);
);
});
}
public removePackage(callback: CallbackAction): void {
deleteKeyPrefix(
this.s3,
{
Bucket: this.config.bucket,
Prefix: addTrailingSlash(this.packagePath),
},
function (err) {
if (err && is404Error(err as VerdaccioError)) {
callback(null);
} else {
callback(err);
public removePackage(): Promise<void> {
return new Promise((resolve, reject) => {
deleteKeyPrefix(
this.s3,
{
Bucket: this.config.bucket,
Prefix: addTrailingSlash(this.packagePath),
},
function (err) {
if (err && is404Error(err as VerdaccioError)) {
resolve();
} else {
reject(err);
}
}
}
);
);
});
}

@@ -239,3 +236,3 @@

public readPackage(name: string, callback: ReadPackageCallback): void {
public readPackage(name: string, callback): void {
this.logger.debug(

@@ -242,0 +239,0 @@ { name, packageName: this.packageName },

@@ -27,3 +27,4 @@ import { PackageAccess } from '@verdaccio/types';

describe('S3PackageManager with mocked s3', function () {
// TODO: fix by https://github.com/verdaccio/verdaccio/pull/2218
describe.skip('S3PackageManager with mocked s3', function () {
beforeEach(() => {

@@ -30,0 +31,0 @@ mockHeadObject.mockClear();

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