Socket
Socket
Sign inDemoInstall

backblaze-b2

Package Overview
Dependencies
5
Maintainers
4
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0

6

CHANGELOG.md

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

### v1.2.0 (January 30, 2017) - The getBucket release
Features
- Adds `B2.getBucket(...)` to help get bucket IDs with restricted bucket keys. In B2 v2, `B2.listBuckets()` will respond with an error, if you authorize without the `master key`.
### v1.1.0 (January 27, 2017) - The B2 v2 release

@@ -2,0 +8,0 @@

@@ -50,2 +50,24 @@ var utils = require('./../utils');

// https://www.backblaze.com/b2/docs/b2_list_buckets.html
exports.get = function(b2, args) {
const data = {
accountId: b2.accountId,
};
// only one of these can/should be used at a time
if (args.bucketName) {
data.bucketName = args.bucketName;
} else if (args.bucketId) {
data.bucketId = args.bucketId;
}
const options = {
url: getListUrl(b2),
method: 'POST',
data,
headers: utils.getAuthHeaderObjectWithToken(b2)
};
return request.sendRequest(options);
};
exports.update = function(b2, bucketId, bucketType) {

@@ -52,0 +74,0 @@ var options = {

@@ -29,2 +29,9 @@ const actions = require('./actions');

// args:
// - bucketName
// - bucketId
B2.prototype.getBucket = function(args) {
return actions.bucket.get(this, args);
};
B2.prototype.updateBucket = function(bucketId, bucketType) {

@@ -31,0 +38,0 @@ return actions.bucket.update(this, bucketId, bucketType);

1

lib/utils.js

@@ -54,2 +54,3 @@ /* global Buffer */

context.downloadUrl = authResponse.downloadUrl;
context.accountId = authResponse.accountId;
};

@@ -56,0 +57,0 @@

4

package.json
{
"name": "backblaze-b2",
"version": "1.1.0",
"version": "1.2.0",
"description": "Node.js Library for the Backblaze B2 Storage Service",

@@ -32,3 +32,3 @@ "main": "index.js",

"devDependencies": {
"eslint": "^5.12.0",
"eslint": "^5.12.1",
"expect.js": "^0.3.1",

@@ -35,0 +35,0 @@ "mocha": "^5.2.0"

@@ -43,13 +43,13 @@ ### Backblaze B2 Node.js Library

const b2 = new B2({
accountId: '<accountId>',
applicationKey: 'applicationKey'
accountId: 'applicationKeyId', // or accountId
applicationKey: 'applicationKey' // or masterApplicationKey
});
async function GetBuckets() {
async function GetBucket() {
try {
await b2.authorize();
let response = await b2.listBuckets();
await b2.authorize(); // must authorize first
let response = await b2.getBucket({bucketName: 'my-bucket'});
console.log(response.data);
} catch (err) {
console.log('Error getting buckets:', err);
console.log('Error getting bucket:', err);
}

@@ -65,9 +65,9 @@ }

```javascript
let response = await this.b2.startLargeFile({bucketId, fileName});
let fileID = response.data.fileId;
let response = await b2.startLargeFile({bucketId, fileName});
let fileId = response.data.fileId;
```
Then for each part you request an uploadUrl, and use the response to upload the part:
Then for each part you request an `uploadUrl`, and use the response to upload the part:
```javascript
let response = await this.b2.getUploadPartUrl({fileId: this.fileID});
let response = await b2.getUploadPartUrl({fileId});

@@ -77,3 +77,3 @@ let uploadURL = response.data.uploadUrl;

response = await this.b2.uploadPart({
response = await b2.uploadPart({
partNumber: parNum,

@@ -89,4 +89,4 @@ uploadUrl: uploadURL,

```javascript
let response = await this.b2.finishLargeFile({
fileId: this.fileID,
let response = await b2.finishLargeFile({
fileId,
partSha1Array: parts.map(buf => sha1(buf))

@@ -102,8 +102,8 @@ })

// All functions on the b2 instance return the response from the B2 API in the success callback
// i.e. b2.foo(...).then(function(b2JsonResponse) {})
// i.e. b2.foo(...).then((b2JsonResponse) => {})
// create b2 object instance
// create B2 object instance
const b2 = new B2({
accountId: 'accountId',
applicationKey: 'applicationKey'
accountId: 'applicationKeyId', // or accountId
applicationKey: 'applicationKey' // or masterApplicationKey
});

@@ -126,3 +126,9 @@

// update bucket2
// get the bucket
b2.getBucket({
bucketName,
bucketId // optional
}); // returns promise
// update bucket
b2.updateBucket(bucketId, bucketType); // returns promise

@@ -129,0 +135,0 @@

/* global describe, beforeEach, it */
var expect = require('expect.js');
const expect = require('expect.js');
var request = require('../../../../lib/request');
const request = require('../../../../lib/request');
const utils = require('../../../../lib/utils');
var bucket = require('../../../../lib/actions/bucket');
const bucket = require('../../../../lib/actions/bucket');
describe('actions/bucket', function() {
var requestOptions;
var bogusRequestModule;
var response;
var actualResponse;
var errorMessage;
var b2;
let requestOptions;
let bogusRequestModule;
let response;
let actualResponse;
let errorMessage;
let b2;

@@ -28,3 +28,3 @@ beforeEach(function() {

bogusRequestModule = function(options, cb) {
var deferred = new utils.Deferred();
let deferred = new utils.Deferred();
requestOptions = options;

@@ -189,2 +189,77 @@ cb(errorMessage, false, JSON.stringify(response), deferred);

describe('get', function() {
describe('with good response', function() {
beforeEach(function(done) {
response = {
buckets:[
{
accountId: '98765',
bucketId: '1234abcd',
bucketName: 'bucket-foo',
bucketType: 'allPrivate',
bucketInfo: {},
corsRules: [],
lifecycleRules: [],
revision: 1
}
]
};
bucket.get(b2, {bucketName: 'bucket-foo'}).then((response) => {
actualResponse = response;
done();
});
});
it('should set correct options and resolve with good response', function() {
expect(actualResponse).to.eql(response);
expect(requestOptions).to.eql({
method: 'POST',
url: 'https://foo/b2api/v2/b2_list_buckets',
data: {
accountId: '98765',
bucketName: 'bucket-foo'
},
headers: { Authorization: 'unicorns and rainbows' }
});
});
});
describe('with response containing no buckets', function() {
beforeEach(function(done) {
errorMessage = 'unauthorized';
bucket.get(b2, {bucketName: 'not-a-real-bucket'}).then(null, function(error) {
actualResponse = error;
done();
});
});
it('Should respond with an error and reject promise', function() {
// status code is 401
expect(actualResponse).to.be(errorMessage);
});
});
describe('with error response', function() {
beforeEach(function(done) {
errorMessage = 'Something went wrong';
bucket.get(b2, {}).then(null, function(error) {
actualResponse = error;
done();
});
});
it('Should respond with an error and reject promise', function() {
expect(actualResponse).to.be(errorMessage);
});
});
});
describe('update', function() {

@@ -191,0 +266,0 @@

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