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.6 to 0.1.7

5

lib/resources/content/file.js
var _ = require('lodash');
var api = require('../../api');
var async = require('async');
var async = require('async');
var generate = require('../generate');

@@ -16,2 +16,5 @@

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

@@ -18,0 +21,0 @@ options.multipart = true;

4

package.json
{
"name": "node-box-sdk",
"version": "0.1.6",
"version": "0.1.7",
"description": "Node.js Box SDK",
"main": "box.js",
"scripts": {
"test": "echo \"Error: Configure Tests Before Running\" && exit 1"
"test": "mocha --recursive test"
},

@@ -9,0 +9,0 @@ "author": "Cydney Auman",

@@ -5,8 +5,8 @@ # Node.js Box SDK

This module interacts with the Box Content and View APIs. The Node.js Box SDK module returns the data requested as well as an encrypted string containing the Box Access Token and Box Refresh Token.
The purpose of this module is to provide an efficient and intentional method of interacting with the Box APIs. This SDK wraps both the Box Content and View API Thus, it is important to understand the Box APIs at the REST endpoint level. You are strongly encouraged to read the Box documentation.
It abstracts away some of the complexity in regards to updating the Box Token upon expiration. However, provides flexibility for the developer to handle the Box callback and storage of the encrypted Box Token on a user by user basis.
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.
Contributors Welcome!
### Status

@@ -19,2 +19,3 @@ #####Content API

- Shared Items - Completed
- Search - Completed
- All Additional Methods - In Progress

@@ -63,4 +64,6 @@

#### 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.
Returns the access tokens. If the box client was configured using encrypt with a password then the tokens will be returned as an encrypted string. Otherwise the tokens will be returned as an object. Either the encrypted token string or the token object will need to be persisted, because the box client will handle refreshing the authorization tokens as needed.
One option is to set the encrypted token string as cookie in a web application. Examples of this strategy are provided.
box.generateToken({ authorization_code: code }, function(err, tokens) { });

@@ -88,2 +91,7 @@

#### Items
Returns the files and/or folders contained within this folder in the response.body.
box.content.folder.items(folderID, { tokens: tokens }, function(err, res, tokens) { });
#### Update

@@ -115,5 +123,108 @@ Returns a full folder object in the response.body.

#### Restore
Restores a full folder object that is in the trash.
box.content.folder.restore(folderID, {}, { tokens: tokens }, function(err, res, tokens) { });
#### Trash
View the files and/or folders that have been moved to the trash.
box.content.folder.trash(null, { tokens: tokens }, function(err, res, tokens) { });
View a specific folders that has been moved to the trash.
box.content.folder.trash(folderID, { tokens: tokens }, function(err, res, tokens) { });
#### Share
Creates a shared link for this folder, returns a full folder object in the response.body.
var data = { shared_link: { } }; // default access
box.content.folder.share(folderID, data, { tokens: tokens }, function(err, res, tokens) { });
#### Collaborations
Returns a list of all the collaborations on a folder.
box.content.folder.collaborations(folderID, { tokens: tokens }, function(err, res, tokens) { });
----------
###File 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.
#### Upload
Returns a full file object inside response.body if the folderID is valid.
var data = { name: 'Penguin Facts', folder: folderId, file: file, filename: 'penguin_fact_sheet.pdf' };
var options = {};
box.content.file.upload(data, options, function(err, res, tokens) { });
#### Get
Returns a full file object inside response.body.
var options = {};
box.content.file.get(fileId, options, function(err, res, tokens) { });
#### Update
Returns the updated full file object inside response.body.
var data = { name: 'Penguin Facts v2', description: 'updated version of penguin fact sheet' };
box.content.file.update(fileId, data, options, function(err, res, tokens) { });
----------
###Shared Items 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.
// TODO update docs
----------
###Search
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 - if 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.
var options = {
query: '',
scope: '',
file_extensions: '',
created_at_range: '',
updated_at_range: '',
size_range: '',
owner_user_ids '',
ancestor_folder_ids: '',
content_types: '',
type: '',
trash_content: '',
limit: '',
offset: ''
}
box.content.search(query, { tokens: tokens }, function(err, res, tokens) { });
----------
## View API
// TODO update docs
----------
### Running Integration Tests
1. npm install -g phantomjs (phantom.js is used with casper.js to login into box.com via a headless client)
2. Setup the config.json with the credentials your application will use.
3. npm test
----------
### Express Use Example

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

Testing with Casper & PhantomJS - [Node Box](https://github.com/adityamukho/node-box-sdk)

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

before(function(done) {
var args = [redirect, config.username, config.password];
var args = [redirect, config.headlessClient.username, config.headlessClient.password];

@@ -43,0 +43,0 @@ util.runHeadlessClient(args, function(resource) {

@@ -42,2 +42,17 @@ var async = require('async');

// UPDATE File Info
it('should update info for a file from box folder', function(done) {
var data = { name: 'Penguin Facts v2', description: 'updated version of penguin fact sheet' };
box.content.file.update(global.fileId, data, global.options, function(err, res, tokens) {
expect(res.body).to.have.property('id', global.fileId);
expect(res.body).to.have.property('type', 'file');
expect(res.body).to.have.property('name', data.name);
expect(res.body).to.have.property('description', data.description);
global.options = { tokens: tokens };
done();
});
});
// PUT Create Shared Link

@@ -44,0 +59,0 @@ it('should create a shared link for a file', function(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