Socket
Socket
Sign inDemoInstall

@platform/fs.s3

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@platform/fs.s3 - npm Package Compare versions

Comparing version 0.7.32 to 0.7.34

lib/s3/s3.url.d.ts

1

lib/common/util.url.js

@@ -54,3 +54,2 @@ "use strict";

'content-disposition': args.contentDisposition,
uid: libs_1.id.cuid(),
acl: acl,

@@ -57,0 +56,0 @@ key: key,

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

export {};
import * as FormData from 'form-data';
export { FormData };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormData = void 0;
var tslib_1 = require("tslib");
var test_1 = require("../test");
var FormData = require("form-data");
exports.FormData = FormData;
var tmp = test_1.fs.resolve('./tmp');

@@ -38,3 +41,48 @@ test_1.fs.ensureDirSync(tmp);

this.timeout(99999);
it('bucket.put (upload)', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
it('upload (signed POST url)', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var data, key, exists, _a, post, contentType, form, headers, res, _b;
var _this = this;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0: return [4, testFile()];
case 1:
data = (_c.sent()).data;
key = PATH + "/post.json";
exists = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, bucket.get({ key: key })];
case 1: return [2, (_a.sent()).status !== 404];
}
}); }); };
return [4, bucket.deleteOne({ key: key })];
case 2:
_c.sent();
_a = test_1.expect;
return [4, exists()];
case 3:
_a.apply(void 0, [_c.sent()]).to.eql(false);
post = s3.url(BUCKET, key).signedPost({ expires: '5m' });
contentType = post.props['content-type'];
form = new FormData();
Object.keys(post.props)
.map(function (key) { return ({ key: key, value: post.props[key] }); })
.forEach(function (_a) {
var key = _a.key, value = _a.value;
return form.append(key, value);
});
form.append('file', data, { contentType: contentType });
headers = form.getHeaders();
return [4, test_1.http.post(post.url, form, { headers: headers })];
case 4:
res = _c.sent();
test_1.expect(res.ok).to.eql(true);
_b = test_1.expect;
return [4, exists()];
case 5:
_b.apply(void 0, [_c.sent()]).to.eql(true);
return [2];
}
});
}); });
it('bucket.put', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, data, json, filename, res1, res2;

@@ -41,0 +89,0 @@ return tslib_1.__generator(this, function (_b) {

@@ -6,2 +6,3 @@ "use strict";

var common_1 = require("../common");
var s3_copy_1 = require("./s3.copy");
var s3_delete_1 = require("./s3.delete");

@@ -12,3 +13,3 @@ var s3_get_1 = require("./s3.get");

var s3_put_1 = require("./s3.put");
var s3_copy_1 = require("./s3.copy");
var s3_url_1 = require("./s3.url");
tslib_1.__exportStar(require("./s3.get"), exports);

@@ -28,27 +29,3 @@ tslib_1.__exportStar(require("./s3.put"), exports);

url: function (bucket, path) {
var object = common_1.util.toObjectUrl({ s3: s3, bucket: bucket, path: path });
return {
object: object,
signedGet: function (options) {
if (options === void 0) { options = {}; }
return common_1.util.toPresignedUrl({
s3: s3,
bucket: bucket,
path: path,
options: tslib_1.__assign(tslib_1.__assign({}, options), { operation: 'getObject' }),
});
},
signedPut: function (options) {
if (options === void 0) { options = {}; }
return common_1.util.toPresignedUrl({
s3: s3,
bucket: bucket,
path: path,
options: tslib_1.__assign(tslib_1.__assign({}, options), { operation: 'putObject' }),
});
},
signedPost: function (options) {
return common_1.util.toPresignedPost(tslib_1.__assign(tslib_1.__assign({ s3: s3 }, options), { bucket: bucket, key: path || (options || {}).key }));
},
};
return s3_url_1.url(s3, bucket, path);
},

@@ -55,0 +32,0 @@ list: function (args) {

@@ -72,13 +72,2 @@ "use strict";

});
it('url.signedPost props are NOT idempotent (differs for each call, more secure)', function () {
var res1 = s3.url('foo', 'file.png').signedPost();
var res2 = s3.url('foo', 'file.png').signedPost();
var props1 = res1.props;
var props2 = res2.props;
test_1.expect(res1.url).to.eql(res2.url);
test_1.expect(Object.keys(res1.props)).to.eql(Object.keys(res1.props));
test_1.expect(props1.uid).to.not.eql(props2.uid);
test_1.expect(props1.Policy).to.not.eql(props2.Policy);
test_1.expect(props1['X-Amz-Signature']).to.not.eql(props2['X-Amz-Signature']);
});
});

@@ -85,0 +74,0 @@ describe('bucket', function () {

{
"name": "@platform/fs.s3",
"version": "0.7.32",
"version": "0.7.34",
"description": "Filesystem like API into AWS S3 (and Digital Ocean Spaces)",

@@ -19,3 +19,3 @@ "main": "lib/index",

"@platform/fs.s3.types": "0.2.25",
"@platform/http": "0.12.36",
"@platform/http": "0.14.0",
"@platform/libs": "0.2.3",

@@ -30,3 +30,3 @@ "@platform/log": "0.1.35",

"devDependencies": {
"@platform/test": "0.1.16",
"@platform/test": "0.1.17",
"@platform/ts": "4.0.6",

@@ -33,0 +33,0 @@ "@types/dotenv": "8.2.0",

import { parse as parseUrl } from 'url';
import { AWS, toMimetype, value, id } from './libs';
import { AWS, toMimetype, value } from './libs';
import * as t from './types';

@@ -76,3 +76,2 @@ import { formatBucket, formatKeyPath } from './util.format';

'content-disposition': args.contentDisposition,
uid: id.cuid(), // NB: Prevents idempotent result props (Policy/Signature). Makes it harder to spoof with repeat calls.
acl,

@@ -79,0 +78,0 @@ key,

@@ -1,3 +0,6 @@

import { expect, util, fs, log } from '../test';
import { expect, util, fs, log, http } from '../test';
import * as FormData from 'form-data';
export { FormData };
const tmp = fs.resolve('./tmp');

@@ -8,2 +11,3 @@ fs.ensureDirSync(tmp);

// const PROVIDER = 'SPACES';
const { s3, BUCKET, ENDPOINT, PATH } = util.init(PROVIDER);

@@ -32,3 +36,31 @@ const bucket = s3.bucket(BUCKET);

it('bucket.put (upload)', async () => {
it('upload (signed POST url)', async () => {
const { data } = await testFile();
const key = `${PATH}/post.json`;
const exists = async () => (await bucket.get({ key })).status !== 404;
await bucket.deleteOne({ key });
expect(await exists()).to.eql(false);
const post = s3.url(BUCKET, key).signedPost({ expires: '5m' });
const contentType = post.props['content-type'];
const form = new FormData();
Object.keys(post.props)
.map((key) => ({ key, value: post.props[key] }))
.forEach(({ key, value }) => form.append(key, value));
form.append('file', data, { contentType });
const headers = form.getHeaders();
const res = await http.post(post.url, form, { headers });
// console.log('res.status:', res.status);
// console.log('res.statusText:', res.statusText);
expect(res.ok).to.eql(true);
expect(await exists()).to.eql(true);
});
it('bucket.put', async () => {
const { data, json, filename } = await testFile();

@@ -96,28 +128,2 @@

/**
*
* Support ticket on Digital Ocean
* [Ticket #4089384] s3.copyObject: 503 SlowDown
*
*/
// it.skip('bucket.put (throttle)', async () => {
// const { data } = await testFile();
// const length = 5;
// const items = Array.from({ length }).map((v, i) => i + 1);
// const put = () => bucket.put({ data, key: 'tmp/throttle.json' });
// for (const i of items) {
// // const res = await Promise.all([put(), put(), put(), put(), put()]);
// const res = await Promise.all(Array.from({ length: 5 }).map(() => put()));
// const status = res.map((res) => res.status);
// console.log('res.error', status);
// }
// console.log('-------------------------------------------');
// console.log('timestamp', new Date().getTime());
// });
it('bucket.copy', async () => {

@@ -124,0 +130,0 @@ const { data } = await testFile();

@@ -82,17 +82,2 @@ import { expect, fs, t } from '../test';

});
it('url.signedPost props are NOT idempotent (differs for each call, more secure)', () => {
const res1 = s3.url('foo', 'file.png').signedPost();
const res2 = s3.url('foo', 'file.png').signedPost();
const props1 = res1.props;
const props2 = res2.props;
expect(res1.url).to.eql(res2.url);
expect(Object.keys(res1.props)).to.eql(Object.keys(res1.props));
expect(props1.uid).to.not.eql(props2.uid);
expect(props1.Policy).to.not.eql(props2.Policy);
expect(props1['X-Amz-Signature']).to.not.eql(props2['X-Amz-Signature']);
});
});

@@ -99,0 +84,0 @@

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

import { AWS, t, util } from '../common';
import { AWS, t } from '../common';
import { copy } from './s3.copy';
import { deleteMany, deleteOne } from './s3.delete';

@@ -7,3 +8,3 @@ import { get } from './s3.get';

import { put } from './s3.put';
import { copy } from './s3.copy';
import { url } from './s3.url';

@@ -27,30 +28,3 @@ export * from './s3.get';

url(bucket: string, path?: string) {
const object = util.toObjectUrl({ s3, bucket, path });
return {
object,
signedGet(options: t.S3SignedUrlGetObjectOptions = {}) {
return util.toPresignedUrl({
s3,
bucket,
path,
options: { ...options, operation: 'getObject' },
});
},
signedPut(options: t.S3SignedUrlPutObjectOptions = {}) {
return util.toPresignedUrl({
s3,
bucket,
path,
options: { ...options, operation: 'putObject' },
});
},
signedPost(options: t.S3SignedPostArgs) {
return util.toPresignedPost({
s3,
...options,
bucket,
key: path || (options || {}).key,
});
},
};
return url(s3, bucket, path);
},

@@ -57,0 +31,0 @@

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