Socket
Socket
Sign inDemoInstall

s3u

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.10 to 1.0.0

15

package.json
{
"name": "s3u",
"version": "0.2.10",
"version": "1.0.0",
"description": "S3 URL manipulation helper similar to standard URL class",

@@ -23,8 +23,15 @@ "main": "src/index.js",

"keywords": [
"s3",
"aws",
"url",
"amazon",
"digitalocean",
"digitalocean-spaces",
"link",
"parse",
"presigned",
"s3",
"sign",
"spaces",
"stackpath",
"spaces"
"storage",
"url"
],

@@ -31,0 +38,0 @@ "author": "Alexey Prokhorov",

@@ -37,2 +37,3 @@ export class S3Url {

setProtocol(protocol: string): this;
setProvider(provider: S3Provider | string): this;
setRegion(region: string): this;

@@ -39,0 +40,0 @@

@@ -5,5 +5,5 @@ 'use strict';

/**
* @param {Partial<S3Url>} attrs
* @param {Partial<S3Url> | string} options
*/
constructor(attrs = {}) {
constructor(options = {}) {
this.bucket = '';

@@ -25,9 +25,16 @@ this.bucketPosition = 'hostname';

if (typeof attrs === 'string') {
if (typeof options === 'string') {
// eslint-disable-next-line no-constructor-return
return this.constructor.fromUrl({ url: attrs });
return this.constructor.fromUrl({ url: options });
}
const { dirPath, fileName, provider, ...attrs } = options;
Object.assign(this, attrs);
if (!(options instanceof S3Url)) {
dirPath && this.setFileName(dirPath);
fileName && this.setFileName(fileName);
provider && this.setProvider(provider);
}
this.updateBucketPosition();

@@ -68,21 +75,2 @@ }

async sign({
accessKeyId,
expires,
method,
secretAccessKey,
} = {}) {
if (!this.provider) {
throw new Error('Cannot sign url from invalid S3Url');
}
return this.provider.buildSignedUrl({
accessKeyId,
expires,
method,
s3Url: this,
secretAccessKey,
});
}
clone(newAttrs = {}) {

@@ -133,2 +121,16 @@ return new S3Url({ ...this, ...newAttrs });

setProvider(provider) {
if (provider && provider.buildUrl) {
this.provider = provider;
return this;
}
if (typeof provider === 'string' && this.constructor.parser) {
this.provider = this.constructor.parser.getProviderById(provider);
return this;
}
return this;
}
setRegion(region) {

@@ -139,2 +141,21 @@ this.region = region;

async sign({
accessKeyId,
expires,
method,
secretAccessKey,
} = {}) {
if (!this.provider) {
throw new Error('Cannot sign url from invalid S3Url');
}
return this.provider.buildSignedUrl({
accessKeyId,
expires,
method,
s3Url: this,
secretAccessKey,
});
}
trimSlashes({ begin = false, end = false } = {}) {

@@ -141,0 +162,0 @@ let key = this.key;

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc