Socket
Socket
Sign inDemoInstall

backblaze-b2

Package Overview
Dependencies
Maintainers
4
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backblaze-b2 - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

.jshintrc

11

CHANGELOG.md

@@ -0,1 +1,12 @@

### v1.1.0 (January 27, 2017) - The B2 v2 release
Features
- Uses [B2 v2 API](https://www.backblaze.com/b2/docs/versions.html). This allows you to use application keys with [bucket restrictions](https://www.backblaze.com/b2/docs/application_keys.html#usingRestrictedKeys).
- Updated minimum `nodejs` target to `10`
- Updated documentation
- [and more...](https://github.com/yakovkhalinsky/backblaze-b2/milestone/15?closed=1)
Thanks to the [contributors](https://github.com/yakovkhalinsky/backblaze-b2/graphs/contributors) for this release.
### v1.0.4 (November 30, 2017) - The buffed release

@@ -2,0 +13,0 @@

4

conf.js
module.exports = {
API_AUTHORIZE__URL: 'https://api.backblaze.com/b2api/v1/b2_authorize_account',
API_VERSION_URL: '/b2api/v1',
API_AUTHORIZE__URL: 'https://api.backblazeb2.com/b2api/v2/b2_authorize_account',
API_VERSION_URL: '/b2api/v2',
MAX_INFO_HEADERS: 10 // maximum number of custom x-bz-info-* headers
};

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

var sha1 = require('sha1');
var utils = require('./../utils');

@@ -7,2 +5,3 @@ var headersUtil = require('../headers');

var conf = require('../../conf');
const sha1 = (value) => require('crypto').createHash('sha1').update(value).digest('hex');

@@ -12,3 +11,4 @@ exports.uploadFile = function(b2, args) {

var uploadAuthToken = args.uploadAuthToken;
var filename = utils.getUrlEncodedFileName(args.filename);
// Previous versions used filename (lowercase), so support that here
var fileName = utils.getUrlEncodedFileName(args.fileName || args.filename);
var data = args.data;

@@ -25,6 +25,8 @@ var hash = args.hash;

'Content-Type': mime || 'b2/x-auto',
'X-Bz-File-Name': filename,
'Content-Length': data.byteLength || data.length,
'X-Bz-File-Name': fileName,
'X-Bz-Content-Sha1': hash || (data ? sha1(data) : null)
},
data: data,
maxRedirects: 0,
onUploadProgress: args.onUploadProgress || null

@@ -68,7 +70,9 @@ };

Authorization: args.uploadAuthToken,
'Content-Length': args.data.byteLength || args.data.length,
'X-Bz-Part-Number': args.partNumber,
'X-Bz-Content-Sha1': args.data ? sha1(args.data) : null
'X-Bz-Content-Sha1': args.hash || (args.data ? sha1(args.data) : null)
},
data: args.data,
onUploadProgress: args.onUploadProgress || null
onUploadProgress: args.onUploadProgress || null,
maxRedirects: 0
};

@@ -110,3 +114,2 @@ return request.sendRequest(options);

var options = {

@@ -117,8 +120,7 @@ url: getListFilesUrl(b2),

data: {
bucketId: bucketId,
startFileName: startFileName ? startFileName : '',
maxFileCount: maxFileCount ? maxFileCount : 100,
prefix: prefix ? prefix : '',
delimiter: delimiter ? delimiter : null
bucketId,
startFileName: startFileName || '',
maxFileCount: maxFileCount || 100,
prefix: prefix || '',
delimiter: delimiter || null
}

@@ -140,4 +142,4 @@ };

bucketId: bucketId,
startFileName: startFileName ? startFileName : '',
maxFileCount: maxFileCount ? maxFileCount : 100
startFileName: startFileName || '',
maxFileCount: maxFileCount || 100
}

@@ -144,0 +146,0 @@ };

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

var actions = require('./actions');
const actions = require('./actions');

@@ -40,3 +40,3 @@ function B2(options) {

// - uploadAuthToken
// - filename
// - fileName
// - data

@@ -132,11 +132,6 @@ // - hash (optional)

var q = require('q');
function notYetImplemented() {
var deferred = q.defer();
deferred.reject('Feature not yet implemented');
return deferred.promise;
return Promise.reject('Feature not yet implemented');
}
module.exports = B2;

@@ -1,11 +0,11 @@

var conf = require('../conf');
const conf = require('../conf');
exports.addInfoHeaders = function(options, info) {
var MAX_INFO_HEADERS = conf.MAX_INFO_HEADERS;
var invalidKeys = [];
const MAX_INFO_HEADERS = conf.MAX_INFO_HEADERS;
let invalidKeys = [];
if (info) {
var keys = Object.keys(info);
let keys = Object.keys(info);
if (keys.length > MAX_INFO_HEADERS) {
throw new Error('Too many info headers: maximum of ' + MAX_INFO_HEADERS + ' allowed');
throw new Error(`Too many info headers: maximum of ${MAX_INFO_HEADERS} allowed`);
}

@@ -21,3 +21,3 @@

function isValidHeader(header) {
return /^[a-z0-9\-]+$/i.test(header);
return /^[a-z0-9-]+$/i.test(header);
}

@@ -24,0 +24,0 @@

@@ -0,1 +1,17 @@

/* global Buffer */
// use: let deferred = new Deferred();
/** Backwards compatible Promise.defer() function */
exports.Deferred = function() {
// credit: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Deferred#Backwards_and_forwards_compatible_helper
this.resolve = null;
this.reject = null;
this.promise = new Promise(function(resolve, reject) {
this.resolve = resolve;
this.reject = reject;
}.bind(this));
Object.freeze(this);
};
exports.getAuthHeaderObject = function(accountId, applicationKey) {

@@ -8,3 +24,3 @@ if (!accountId) {

}
var base64 = new Buffer(accountId + ':' + applicationKey).toString('base64');
let base64 = Buffer.from(accountId + ':' + applicationKey).toString('base64');
return {

@@ -60,3 +76,3 @@ Authorization: 'Basic ' + base64

} else {
var genericResponse = exports.parseJson(body);
let genericResponse = exports.parseJson(body);
deferred.resolve(genericResponse);

@@ -63,0 +79,0 @@ }

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

@@ -9,4 +9,4 @@ "main": "index.js",

"test-unit": "mocha \"test/**/*Test.js\"",
"lint-lib": "eslint \"lib/**/*.js\"",
"lint-test": "eslint \"test/**/*.js\" --global describe,it,beforeEach",
"lint-lib": "eslint \"lib/**/*.js\" --parser-options=ecmaVersion:6 --global Promise",
"lint-test": "eslint \"test/**/*.js\" --parser-options=ecmaVersion:6 --global describe,it,beforeEach,Promise",
"lint-all": "npm run lint-lib && npm run lint-test"

@@ -33,11 +33,12 @@ },

"devDependencies": {
"eslint": "^3.17.1",
"eslint": "^5.12.0",
"expect.js": "^0.3.1",
"mocha": "^4.0.1"
"mocha": "^5.2.0"
},
"dependencies": {
"axios": "^0.17.1",
"q": "^1.5.1",
"sha1": "^1.1.1"
"axios": "^0.18.0"
},
"engines": {
"node": ">=10.0"
}
}
### Backblaze B2 Node.js Library
[![npm version](https://badge.fury.io/js/backblaze-b2.svg)](https://badge.fury.io/js/backblaze-b2) [![Build Status](https://travis-ci.org/yakovkhalinsky/backblaze-b2.svg?branch=master)](https://travis-ci.org/yakovkhalinsky/backblaze-b2)
This library uses promises, so all actions on a `B2` instance return a promise in the following pattern
This library uses promises, so all actions on a `B2` instance return a promise in the following pattern:
``` javascript
b2.instanceFunction(arg1, arg2).then(
successFn(response) { ... },
errorFn(err) { ... }
);
b2.instanceFunction(arg1, arg2).then(
successFn(response) { ... },
errorFn(err) { ... }
);
```

@@ -16,50 +16,29 @@

### Contributing
### Contributing and Suggestions for Changes and Fixes
Contributions, suggestions, and questions are welcome. Please review the [contributing guidelines](CONTRIBUTING.md) for details.
Contributions and questions are welcome. If you are looking for something to help with, please have a look at the
[ISSUES](https://github.com/yakovkhalinsky/backblaze-b2/issues) or add an issue if there is something you would like to see or fix.
Make sure you use the `.editorconfig` in your IDE/editor when writing code.
Pull Requests should include:
* Updated example in README.md
* Update existing tests, or add new tests to cover code changes
If you are adding tests, add these to `/test/unit`. Make sure the test is named `fooTest.js` and
is located in a similar folder to the node module that is being tested.
Always run `npm test` before you commit.
### Upgrading from 0.9.x to 1.0.x
For this update, we've switched the back end HTTP request library from `request` to `axios` as it has better Promise and progress support built in. However, there are a couple changes that will break your code and ruin your day. Here are the changes:
* The Promise resolution has a different data structure. Where previously, the request response data was the root object in the promise resolution (`res`), this data now resides in `res.data`.
* In v0.9.12, we added request progress reporting via the third parameter to `then()`. Because we are no longer using the same promise library, this functionality has been removed. However, progress reporting is still available by passing a callback function into the `b2.method()` that you're calling. See the documentation below for details.
* The Promise resolution has a different data structure. Where previously, the request response data was the root object in the promise resolution (`res`), this data now resides in `res.data`.
* In v0.9.12, we added request progress reporting via the third parameter to `then()`. Because we are no longer using the same promise library, this functionality has been removed. However, progress reporting is still available by passing a callback function into the `b2.method()` that you're calling. See the documentation below for details.
* In v0.9.x, `b2.downloadFileById()` accepted a `fileId` parameter as a String or Number. As of 1.0.0, the first parameter is now expected to be a plain Object of arguments.
### Response Object
Each request returns an object with
Each request returns an object with:
- `status` - int, html error Status
- `statusText`
- `headers`
- `config`
- `request`
- `data` - actual returned data from backblaze, https://www.backblaze.com/b2/docs/calling.html
status - int, html error Status
statusText
headers
config
request
data - actual returned data from backblaze, https://www.backblaze.com/b2/docs/calling.html
### Basic Example
```javascript
var B2 = require('backblaze-b2');
const B2 = require('backblaze-b2');
var b2 = new B2({
const b2 = new B2({
accountId: '<accountId>',

@@ -72,6 +51,6 @@ applicationKey: 'applicationKey'

await b2.authorize();
var response = await b2.listBuckets()
console.log(response.data)
} catch (e){
console.log('Error getting buckets:', e)
let response = await b2.listBuckets();
console.log(response.data);
} catch (err) {
console.log('Error getting buckets:', err);
}

@@ -83,174 +62,177 @@ }

To upload large files, you need to split the file into parts (between 5MB and 5GB) and upload each
part seperately
To upload large files, you need to split the file into parts (between 5MB and 5GB) and upload each part seperately.
First, you initiate the large file upload to get the fileId
First, you initiate the large file upload to get the fileId:
```javascript
var response = await this.b2.startLargeFile({bucketId: bucketID,fileName: fileName })
var fileID = response.data.fileId
let response = await this.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
var response = await this.b2.getUploadPartUrl({fileId: this.fileID})
let response = await this.b2.getUploadPartUrl({fileId: this.fileID});
var uploadURL = resp.data.uploadUrl
var authToken = resp.data.authorizationToken
let uploadURL = response.data.uploadUrl;
let authToken = response.data.authorizationToken;
response = await this.b2.uploadPart({
partNumber: parNum,
uploadUrl: uploadURL,
uploadAuthToken: authToken,
data: buf
})
partNumber: parNum,
uploadUrl: uploadURL,
uploadAuthToken: authToken,
data: buf
});
// status checks etc.
```
Then finish the uploadUrl
Then finish the uploadUrl:
```javascript
var response = await this.b2.finishLargeFile({
fileId: this.fileID,
partSha1Array: parts.map(function(buf) {return sha1(buf)})
})
let response = await this.b2.finishLargeFile({
fileId: this.fileID,
partSha1Array: parts.map(buf => sha1(buf))
})
```
### Usage
### Usage
```javascript
var B2 = require('backblaze-b2');
const B2 = require('backblaze-b2');
// All functions on the b2 instance return the response from the B2 API in the success callback
// i.e. b2.foo(...).then(function(b2JsonResponse) {})
// All functions on the b2 instance return the response from the B2 API in the success callback
// i.e. b2.foo(...).then(function(b2JsonResponse) {})
// create b2 object instance
var b2 = new B2({
accountId: 'accountId',
applicationKey: 'applicationKey'
});
// create b2 object instance
const b2 = new B2({
accountId: 'accountId',
applicationKey: 'applicationKey'
});
// authorize with provided credentials
b2.authorize(); // returns promise
// authorize with provided credentials
b2.authorize(); // returns promise
// create bucket
b2.createBucket(
bucketName,
bucketType // one of `allPublic`, `allPrivate`
); // returns promise
// create bucket
b2.createBucket(
bucketName,
bucketType // one of `allPublic`, `allPrivate`
); // returns promise
// delete bucket
b2.deleteBucket(bucketId); // returns promise
// delete bucket
b2.deleteBucket(bucketId); // returns promise
// list buckets
b2.listBuckets(); // returns promise
// list buckets
b2.listBuckets(); // returns promise
// update bucket2
b2.updateBucket(bucketId, bucketType); // returns promise
// update bucket2
b2.updateBucket(bucketId, bucketType); // returns promise
// get upload url
b2.getUploadUrl(bucketId); // returns promise
// get upload url
b2.getUploadUrl(bucketId); // returns promise
// upload file
b2.uploadFile({
uploadUrl: 'uploadUrl',
uploadAuthToken: 'uploadAuthToken',
filename: 'filename',
mime: '', // optional mime type, will default to 'b2/x-auto' if not provided
data: 'data', // this is expecting a Buffer, not an encoded string
hash: 'sha1-hash', // optional data hash, will use sha1(data) if not provided
info: {
// optional info headers, prepended with X-Bz-Info- when sent, throws error if more than 10 keys set
// valid characters should be a-z, A-Z and '-', all other characters will cause an error to be thrown
key1: value
key2: value
},
onUploadProgress: function(event) || null // progress monitoring
}); // returns promise
// upload file
b2.uploadFile({
uploadUrl: 'uploadUrl',
uploadAuthToken: 'uploadAuthToken',
fileName: 'fileName',
mime: '', // optional mime type, will default to 'b2/x-auto' if not provided
data: 'data', // this is expecting a Buffer, not an encoded string
hash: 'sha1-hash', // optional data hash, will use sha1(data) if not provided
info: {
// optional info headers, prepended with X-Bz-Info- when sent, throws error if more than 10 keys set
// valid characters should be a-z, A-Z and '-', all other characters will cause an error to be thrown
key1: 'value'
key2: 'value'
},
onUploadProgress: (event) => {} || null // progress monitoring
}); // returns promise
// list file names
b2.listFileNames({
bucketId: 'bucketId',
startFileName: 'startFileName',
maxFileCount: 100,
delimiter: '',
prefix: ''
}); // returns promise
// list file names
b2.listFileNames({
bucketId: 'bucketId',
startFileName: 'startFileName',
maxFileCount: 100,
delimiter: '',
prefix: ''
}); // returns promise
// list file versions
b2.listFileVersions({
bucketId: 'bucketId',
startFileName: 'startFileName',
maxFileCount: 100
}); // returns promise
// list file versions
b2.listFileVersions({
bucketId: 'bucketId',
startFileName: 'startFileName',
maxFileCount: 100
}); // returns promise
// hide file
b2.hideFile({
bucketId: 'bucketId',
fileName: 'fileName'
}); // returns promise
// hide file
b2.hideFile({
bucketId: 'bucketId',
fileName: 'fileName'
}); // returns promise
// get file info
b2.getFileInfo(fileId); // returns promise
// get file info
b2.getFileInfo(fileId); // returns promise
// get download authorization
b2.getDownloadAuthorization({
bucketId: 'bucketId',
fileNamePrefix: 'fileNamePrefix',
validDurationInSeconds: 'validDurationInSeconds', // a number from 0 to 604800
b2ContentDisposition: 'b2ContentDisposition'
}); // returns promise
// get download authorization
b2.getDownloadAuthorization({
bucketId: 'bucketId',
fileNamePrefix: 'fileNamePrefix',
validDurationInSeconds: 'validDurationInSeconds', // a number from 0 to 604800
b2ContentDisposition: 'b2ContentDisposition'
}); // returns promise
// download file by name
b2.downloadFileByName({
bucketName: 'bucketName',
fileName: 'fileName',
onDownloadProgress: function(event) || null // progress monitoring
}); // returns promise
// download file by name
b2.downloadFileByName({
bucketName: 'bucketName',
fileName: 'fileName',
responseType: 'arraybuffer', // options are as in axios: 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
onDownloadProgress: (event) => {} || null // progress monitoring
}); // returns promise
// download file by fileId
b2.downloadFileById({
fileId: 'fileId',
onDownloadProgress: function(event) || null // progress monitoring
}); // returns promise
// download file by fileId
b2.downloadFileById({
fileId: 'fileId',
responseType: 'arraybuffer', // options are as in axios: 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
onDownloadProgress: (event) => {} || null // progress monitoring
}); // returns promise
// delete file version
b2.deleteFileVersion({
fileId: 'fileId',
fileName: 'fileName'
}); // returns promise
// delete file version
b2.deleteFileVersion({
fileId: 'fileId',
fileName: 'fileName'
}); // returns promise
// start large file
b2.startLargeFile({
bucketId: 'bucketId',
fileName: 'fileName'
}) // returns promise
// start large file
b2.startLargeFile({
bucketId: 'bucketId',
fileName: 'fileName'
}); // returns promise
// get upload part url
b2.getUploadPartUrl({
fileId: 'fileId'
}) // returns promise
// get upload part url
b2.getUploadPartUrl({
fileId: 'fileId'
}); // returns promise
// get upload part
b2.uploadPart({
partNumber: 'partNumber', // A number from 1 to 10000
uploadUrl: 'uploadUrl',
uploadAuthToken: 'uploadAuthToken', // comes from getUploadPartUrl();
data: Buffer // this is expecting a Buffer not an encoded string,
onUploadProgress: function(event) || null // progress monitoring
}) // returns promise
// get upload part
b2.uploadPart({
partNumber: 'partNumber', // A number from 1 to 10000
uploadUrl: 'uploadUrl',
uploadAuthToken: 'uploadAuthToken', // comes from getUploadPartUrl();
data: Buffer // this is expecting a Buffer not an encoded string,
hash: 'sha1-hash', // optional data hash, will use sha1(data) if not provided
onUploadProgress: (event) => {} || null // progress monitoring
}); // returns promise
// finish large file
b2.finishLargeFile({
fileId: 'fileId',
partSha1Array: [partSha1Array] // array of sha1 for each part
}) // returns promise
// finish large file
b2.finishLargeFile({
fileId: 'fileId',
partSha1Array: [partSha1Array] // array of sha1 for each part
}); // returns promise
// cancel large file
b2.cancelLargeFile({
fileId: 'fileId'
}) // returns promise
// cancel large file
b2.cancelLargeFile({
fileId: 'fileId'
}); // returns promise
```
### Authors
* Yakov Khalinsky (@yakovkhalinsky)
* Ivan Kalinin (@IvanKalinin) at Isolary
* Brandon Patton (@crazyscience) at Isolary

@@ -0,4 +1,6 @@

/* global describe, beforeEach, it */
var expect = require('expect.js');
var q = require('q');
const utils = require('../../../../lib/utils');
var request = require('../../../../lib/request');

@@ -20,3 +22,3 @@ var auth = require('../../../../lib/actions/auth');

errorMessage = null;
deferred = q.defer();
deferred = new utils.Deferred();

@@ -23,0 +25,0 @@ bogusAxiosModule = function(options) {

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

/* global describe, beforeEach, it */
var expect = require('expect.js');
var q = require('q');
var request = require('../../../../lib/request');
const utils = require('../../../../lib/utils');
var bucket = require('../../../../lib/actions/bucket');

@@ -26,3 +28,3 @@

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

@@ -53,3 +55,3 @@ cb(errorMessage, false, JSON.stringify(response), deferred);

expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_create_bucket',
url: 'https://foo/b2api/v2/b2_create_bucket',
method: 'POST',

@@ -101,3 +103,3 @@ data: {

method: 'POST',
url: 'https://foo/b2api/v1/b2_delete_bucket',
url: 'https://foo/b2api/v2/b2_delete_bucket',
data: {

@@ -162,3 +164,3 @@ accountId: '98765',

method: 'POST',
url: 'https://foo/b2api/v1/b2_list_buckets',
url: 'https://foo/b2api/v2/b2_list_buckets',
data: {

@@ -212,3 +214,3 @@ accountId: '98765'

method: 'POST',
url: 'https://foo/b2api/v1/b2_update_bucket',
url: 'https://foo/b2api/v2/b2_update_bucket',
data: {

@@ -250,3 +252,3 @@ accountId: '98765',

bucketId: '1234abcd',
uploadUrl: 'https://foo-001.backblaze.com/b2api/v1/b2_upload_file/abcd1234/unicorns_and_rainbows'
uploadUrl: 'https://foo-001.backblaze.com/b2api/v2/b2_upload_file/abcd1234/unicorns_and_rainbows'
};

@@ -264,3 +266,3 @@

method: 'POST',
url: 'https://foo/b2api/v1/b2_get_upload_url',
url: 'https://foo/b2api/v2/b2_get_upload_url',
data: {

@@ -267,0 +269,0 @@ bucketId: '1234abcd'

@@ -0,4 +1,6 @@

/* global describe, beforeEach, it */
var expect = require('expect.js');
var q = require('q');
const utils = require('../../../../lib/utils');
var request = require('../../../../lib/request');

@@ -28,3 +30,3 @@ var file = require('../../../../lib/actions/file');

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

@@ -44,3 +46,3 @@ cb(errorMessage, false, JSON.stringify(response), deferred);

uploadAuthToken: 'uploadauthtoken',
filename: 'foo.txt',
fileName: 'foo.txt',
data: 'some text file content'

@@ -68,5 +70,7 @@ };

'Content-Type': 'b2/x-auto',
'Content-Length': 22,
'X-Bz-File-Name': 'foo.txt',
'X-Bz-Content-Sha1': '332e7f863695677895a406aff6d60acf7e84ea22' },
data: 'some text file content',
maxRedirects: 0,
onUploadProgress: null

@@ -100,3 +104,3 @@ });

uploadAuthToken: 'uploadauthtoken',
filename: 'foo.txt',
fileName: 'foo.txt',
data: 'some text file content',

@@ -106,3 +110,4 @@ info: {

unicorns: 'rainbows'
}
},
maxRedirects: 0,
};

@@ -123,2 +128,3 @@

'Content-Type': 'b2/x-auto',
'Content-Length': 22,
'X-Bz-File-Name': 'foo.txt',

@@ -129,2 +135,3 @@ 'X-Bz-Content-Sha1': '332e7f863695677895a406aff6d60acf7e84ea22',

},
maxRedirects: 0,
data: 'some text file content',

@@ -143,3 +150,3 @@ onUploadProgress: null

uploadAuthToken: 'uploadauthtoken',
filename: 'foo.txt',
fileName: 'foo.txt',
data: 'some text file content',

@@ -169,3 +176,3 @@ info: {

uploadAuthToken: 'uploadauthtoken',
filename: 'foo.txt',
fileName: 'foo.txt',
mime: 'foo/type',

@@ -196,3 +203,3 @@ data: 'some text file content',

uploadAuthToken: 'uploadauthtoken',
filename: 'foo.txt',
fileName: 'foo.txt',
data: 'some text file content'

@@ -218,3 +225,3 @@ };

uploadAuthToken: 'uploadauthtoken',
filename: 'foo.txt',
fileName: 'foo.txt',
data: 'some text file content',

@@ -237,3 +244,52 @@ hash: 'my hash value'

describe('uploadPart', function() {
describe('with good response and with specified hash', function() {
beforeEach(function(done) {
options = {
uploadUrl: 'https://uploadUrl',
uploadAuthToken: 'uploadauthtoken',
data: 'some text file content',
partNumber: 3,
hash: 'my hash value'
};
file.uploadPart(b2, options).then(function() {
done();
});
});
it('should properly set x-bz-content-sha1 in headers', function() {
expect(requestOptions.headers['X-Bz-Content-Sha1']).to.equal('my hash value');
});
it('should properly set content-length in headers', function() {
expect(requestOptions.headers['Content-Length']).to.equal(22);
});
it('should properly set x-bz-part-number in headers', function() {
expect(requestOptions.headers['X-Bz-Part-Number']).to.equal(3);
});
});
describe('with good response and with no hash specified', function() {
beforeEach(function(done) {
options = {
uploadUrl: 'https://uploadUrl',
uploadAuthToken: 'uploadauthtoken',
partNumber: 7,
data: 'some text file content'
};
file.uploadPart(b2, options).then(function() {
done();
});
});
it('should properly set x-bz-content-sha1 in headers', function() {
expect(requestOptions.headers['X-Bz-Content-Sha1']).to.equal('332e7f863695677895a406aff6d60acf7e84ea22');
});
});
});
describe('listFileNames', function() {

@@ -262,3 +318,3 @@

expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_list_file_names',
url: 'https://foo/b2api/v2/b2_list_file_names',
method: 'POST',

@@ -322,3 +378,3 @@ headers:

expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_list_file_versions',
url: 'https://foo/b2api/v2/b2_list_file_versions',
method: 'POST',

@@ -379,3 +435,3 @@ headers:

expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_hide_file',
url: 'https://foo/b2api/v2/b2_hide_file',
method: 'POST',

@@ -428,3 +484,3 @@ headers:

expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_get_file_info',
url: 'https://foo/b2api/v2/b2_get_file_info',
method: 'POST',

@@ -483,3 +539,3 @@ headers:

expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_get_download_authorization',
url: 'https://foo/b2api/v2/b2_get_download_authorization',
method: 'POST',

@@ -543,3 +599,3 @@ headers:

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

@@ -607,3 +663,3 @@ cb(errorMessage, response, 'file contents', deferred);

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

@@ -625,3 +681,3 @@ cb(errorMessage, response, 'file contents', deferred);

expect(requestOptions).to.eql({
url: 'https://download/b2api/v1/b2_download_file_by_id?fileId=abcd1234',
url: 'https://download/b2api/v2/b2_download_file_by_id?fileId=abcd1234',
headers: {

@@ -686,3 +742,3 @@ Authorization: 'unicorns and rainbows'

expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_delete_file_version',
url: 'https://foo/b2api/v2/b2_delete_file_version',
method: 'POST',

@@ -689,0 +745,0 @@ headers: {

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

/* global describe, beforeEach, it */
var expect = require('expect.js');

@@ -2,0 +4,0 @@

@@ -0,4 +1,6 @@

/* global describe, beforeEach, it */
var expect = require('expect.js');
var q = require('q');
const utils = require('../../../lib/utils');
var request = require('../../../lib/request');

@@ -14,3 +16,3 @@

bogusRequestModule = function(options, cb) {
var deferred = q.defer();
var deferred = new utils.Deferred();
cb(false, false, JSON.stringify(options), deferred);

@@ -17,0 +19,0 @@

@@ -0,4 +1,6 @@

/* global describe, beforeEach, it */
var expect = require('expect.js');
var utils = require('../../../lib/utils');
const utils = require('../../../lib/utils');

@@ -24,6 +26,5 @@ describe('utils', function() {

it('Should throw error given invalid accountId', function() {
var accountId = undefined;
var applicationKey = 'rainbows';
try {
utils.getAuthHeaderObject(accountId, applicationKey);
utils.getAuthHeaderObject(undefined, applicationKey);
} catch (e) {

@@ -37,5 +38,4 @@ err = e;

var accountId = 'unicorns';
var applicationKey = undefined;
try {
utils.getAuthHeaderObject(accountId, applicationKey);
utils.getAuthHeaderObject(accountId, undefined);
} catch (e) {

@@ -58,5 +58,4 @@ err = e;

it('Should throw error given b2 object is not defined or falsey', function() {
var b2 = undefined;
try {
utils.getAuthHeaderObjectWithToken(b2);
utils.getAuthHeaderObjectWithToken(undefined);
} catch (e) {

@@ -63,0 +62,0 @@ err = e;

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