Socket
Socket
Sign inDemoInstall

node-box-sdk

Package Overview
Dependencies
23
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.1.5

1

examples/express/middleware/box/index.js

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

return function nodeBoxSDK(req, res, next) {
// ADD YOUR CONFIGURATIONS HERE
box.configure({

@@ -7,0 +8,0 @@ client_id: '',

3

examples/hapi/plugins/index.js
var box = require('../../../box');
exports.register = function (server, config, next) {
// ADD YOUR CONFIGURATIONS HERE
box.configure({

@@ -6,0 +7,0 @@ client_id: '',

@@ -8,3 +8,3 @@ var _ = require('lodash');

var path = '/files';
var operations = ['creat','get', 'delete'];
var operations = ['get', 'delete', 'copy', 'destroy', 'restore', 'share', 'trash'];

@@ -17,5 +17,2 @@ var setup = {

},
share: function share(id, data, options, callback) {
api.execute[this.api]('PUT', this.url + '/' + id, data, options, callback);
},
upload: function upload(data, options, callback) {

@@ -26,3 +23,3 @@ options.multipart = true;

}
// TODO maybe implement this
// TODO implement wrapper around creating view from content - ROUGH DRAFT
// view: function view(id, options, callback) {

@@ -29,0 +26,0 @@ // var self = this;

@@ -6,3 +6,3 @@ var api = require('../../api');

var path = '/folders';
var operations = ['create', 'get', 'update', 'delete'];
var operations = ['create', 'get', 'update', 'delete', 'copy', 'destroy', 'restore', 'share', 'trash'];

@@ -15,20 +15,4 @@ var setup = {

},
copy: function items(id, data, options, callback) {
api.execute[this.api]('POST', this.url + '/' + id + '/copy', data, options, callback);
},
items: function items(id, options, callback) {
api.execute[this.api]('GET', this.url + '/' + id + '/items', {}, options, callback);
},
restore: function restore(id, options, callback) {
api.execute[this.api]('POST', this.url + '/' + id, {}, options, callback);
},
share: function share(id, data, options, callback) {
api.execute[this.api]('PUT', this.url + '/' + id, data, options, callback);
},
trash: function trash(id, options, callback) {
var location = id ? this.url + '/' + id + '/trash' : this.url + '/trash/items'
api.execute[this.api]('GET', location, {}, options, callback);
},
destroy: function destroy(id, options, callback) {
api.execute[this.api]('DELETE', this.url + '/' + id + '/trash', {}, options, callback);
}

@@ -35,0 +19,0 @@ };

@@ -24,2 +24,3 @@ var api = require('../api');

var restFunctions = {
// CRUD
create: function create(data, options, cb) {

@@ -37,2 +38,19 @@ api.execute[this.api]('POST', this.url, data, options, cb);

api.execute[this.api]('DELETE', this.url + '/' + id, {}, options, cb);
},
// SHARED
copy: function copy(id, data, options, callback) {
api.execute[this.api]('POST', this.url + '/' + id + '/copy', data, options, callback);
},
destroy: function destroy(id, options, callback) {
api.execute[this.api]('DELETE', this.url + '/' + id + '/trash', {}, options, callback);
},
restore: function restore(id, data, options, callback) {
api.execute[this.api]('POST', this.url + '/' + id, data, options, callback);
},
share: function share(id, data, options, callback) {
api.execute[this.api]('PUT', this.url + '/' + id, data, options, callback);
},
trash: function trash(id, options, callback) {
var location = id ? this.url + '/' + id + '/trash' : this.url + '/trash/items'
api.execute[this.api]('GET', location, {}, options, callback);
}

@@ -39,0 +57,0 @@ };

{
"name": "node-box-sdk",
"version": "0.1.4",
"version": "0.1.5",
"description": "Node.js Box SDK",

@@ -5,0 +5,0 @@ "main": "box.js",

@@ -9,3 +9,3 @@ # Node.js Box SDK

Examples of how to integrate this module into Express as middleware and into Hapi as a plugin are located in the examples folder. The examples provided show how to attach the node-box-sdk to the server object and then set the returned encrypted token as a cookie.
Examples of how to integrate this module into Express as middleware and into Hapi as a plugin are located in the examples folder. The examples provided show how to attach the node-box-sdk to the server object, set the returned encrypted token string as a cookie and how to use this encrypted token string with the node-box-sdk methods.

@@ -17,3 +17,3 @@ ### Status

- Folders - Completed
- Files - Partially Complete - In Progress
- Files - Completed
- Shared Items - Completed

@@ -28,5 +28,13 @@ - All Additional Methods - In Progress

----------
### Install
npm install node-box-sdk
----------
### Configure

@@ -40,2 +48,71 @@ box.configure({

----------
## Content API
### Authorization
#### Authorize
Returns the URL of Box’s authorization page in the response.redirect. This is the URL that your application should forward the user to in first leg of OAuth. After successful login it returns YOUR_REDIRECT_URI?code=THE_AUTHORIZATION_CODE.
var state = 'abc-xyz'; // An arbitrary string of your choosing that will be included in the response to your application.
box.authorize(state, function(err, res) { });
#### Generate Tokens
Returns the access tokens as an encrypted string. This encrypted token string can be set as cookie in a web application on a user by user basis. This encrypted token string will need to be stored and used in all subsequent calls in the node-box-sdk.
box.generateToken({ authorization_code: code }, function(err, tokens) { });
----------
###Folder Operations
All methods have a 3rd argument in the callback function 'tokens'. Each time the node-box-sdk callsback with the access tokens as an encrypted string.
The reason for this is because - iIf the access token was expired, node-box-sdk will attempt to refresh this token and then returns the updated version of the access tokens as an encrypted string. If no refresh was needed then it returns the same access tokens as an encrypted string.
#### Create
Returns a full folder object in the response.body if the parent folder ID is valid.
var data = { name: 'BoxTest', parent: { id: 0 }};
box.content.folder.create(data, { tokens: tokens }, function(err, res, tokens) { });
#### Get
Returns a full folder object in the response.body.
box.content.folder.get(folderID, { tokens: tokens }, function(err, res, tokens) { });
#### Update
Returns a full folder object in the response.body.
var data = { name: 'BoxTestUpdate', description: 'A folder in Box.'};
box.content.folder.update(folderID, data, { tokens: tokens }, function(err, res, tokens) { });
#### Delete
Moves the folder to trash.
Returns an empty response.body and a 204 if successful.
*A recursive parameter must be included in order to delete folders that have items inside of them
var options = { tokens: tokens params: { recursive: true } };
box.content.folder.delete(folderID, options, function(err, res, tokens) { });
#### Permanently Delete
Permanently deletes an item that is in the trash. The item will no longer exist in Box. This action cannot be undone.
Returns an empty response.body and a 204 if successful.
box.content.folder.destroy(folderID, { tokens: tokens }, function(err, res, tokens) { });
#### Copy
Returns a full folder object in the response.body if the parent folder ID is valid.
var data = { parent: { id : 0 }, name: "AnotherBoxTest" };
box.content.folder.copy(folderID, data, { tokens: tokens }, function(err, res, tokens) { });
----------
### Express Use Example

@@ -48,2 +125,5 @@ [Using node-box-sdk inside Express](https://github.com/cydneymikel/node-box-sdk/tree/master/examples/express)

----------
### Inspiration + References

@@ -50,0 +130,0 @@ API link mixins and dynamic REST API generator - [Paypal SDK](https://github.com/paypal/PayPal-node-SDK)

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

var chai = require('chai');
var expect = chai.expect;
var async = require('async');
var chai = require('chai');
var expect = chai.expect;

@@ -92,4 +93,3 @@ describe('Box Folder Operations', function() {

expect(res.body).to.have.property('id');
copiedFolder = data;
copiedFolder.id = res.body.id;
copiedFolder = res.body;

@@ -141,3 +141,3 @@ expect(res.body).to.have.property('name', data.name);

it('should restore a folder from trash', function(done) {
box.content.folder.restore(global.folderId, global.options, function(err, res, tokens) {
box.content.folder.restore(global.folderId, {}, global.options, function(err, res, tokens) {
expect(res.body).to.have.property('id', global.folderId);

@@ -153,7 +153,20 @@ expect(res.body).to.have.property('type', 'folder');

// DELETE Permanently Delete Folder
it('should permanently delete a folder.', function(done) {
box.content.folder.destroy(copiedFolder.id, global.options, function(err, res, tokens) {
console.log(copiedFolder.id)
it('should permanently delete a folder', function(done) {
async.series({
remove: function(next) {
box.content.folder.delete(copiedFolder.id, global.options, function(err, res, tokens) {
global.options = { tokens: tokens };
next(err, res);
});
},
destroy: function(next) {
box.content.folder.destroy(copiedFolder.id, global.options, function(err, res, tokens) {
global.options = { tokens: tokens };
next(err, res);
});
}
}, function(err, result) {
expect(result.remove.statusCode).to.equal(204);
expect(result.destroy.statusCode).to.equal(204);
global.options = { tokens: tokens };
done();

@@ -160,0 +173,0 @@ });

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

var async = require('async');
var chai = require('chai');

@@ -19,3 +20,2 @@ var expect = chai.expect;

box.content.file.upload(data, global.options, function(err, res, tokens) {
console.log(res)
expect(res.body).to.have.property('entries');

@@ -71,2 +71,62 @@ expect(res.body.entries[0]).to.have.property('id');

// POST Copy File
var copiedFile;
it('should create a copy of a file in another folder.', function(done) {
var data = { parent: { id: 0 } };
box.content.file.copy(global.fileId, data, global.options, function(err, res, tokens) {
expect(res.body).to.have.property('id');
expect(res.body).to.have.property('type', 'file');
expect(res.body).to.have.property('name');
copiedFile = res.body;
global.options = { tokens: tokens };
done();
});
});
// DELETE File
it('should delete folder from box', function(done) {
box.content.file.delete(copiedFile.id, global.options, function(err, res, tokens) {
expect(res.statusCode).to.equal(204);
global.options = { tokens: tokens };
done();
});
});
// POST Restore File
it('should restore a file from trash', function(done) {
box.content.file.restore(copiedFile.id, {}, global.options, function(err, res, tokens) {
expect(res.body).to.have.property('id');
expect(res.body).to.have.property('type', 'file');
expect(res.body).to.have.property('name');
global.options = { tokens: tokens };
done();
});
});
// DELETE Trash and then Permanently Delete File
it('should permanently delete a file', function(done) {
async.series({
remove: function(next) {
box.content.file.delete(copiedFile.id, global.options, function(err, res, tokens) {
global.options = { tokens: tokens };
next(err, res);
});
},
destroy: function(next) {
box.content.file.destroy(copiedFile.id, global.options, function(err, res, tokens) {
global.options = { tokens: tokens };
next(err, res);
});
}
}, function(err, result) {
expect(result.remove.statusCode).to.equal(204);
expect(result.destroy.statusCode).to.equal(204);
done();
});
});
});
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