box-node-sdk 1.9.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nyc_output/b78aeaed90f4d2aa9c875464f096ca11.json +1 -0
- package/.nyc_output/d59c20738f2e8f2570dce1eebad16acf.json +1 -0
- package/.nycrc +15 -0
- package/.travis.yml +2 -0
- package/CHANGELOG.md +26 -0
- package/Makefile.js +5 -1
- package/lib/box-client.js +18 -3
- package/lib/event-stream.js +51 -51
- package/lib/managers/collaboration-whitelist.js +225 -0
- package/lib/managers/files.js +112 -20
- package/lib/managers/metadata.js +18 -0
- package/lib/managers/search.js +2 -2
- package/lib/managers/terms-of-service.js +307 -0
- package/lib/sessions/app-auth-session.js +3 -1
- package/lib/sessions/basic-session.js +3 -1
- package/lib/sessions/persistent-session.js +2 -1
- package/lib/token-manager.js +47 -10
- package/lib/util/paging-iterator.js +5 -1
- package/package.json +8 -6
- package/.npmignore +0 -4
package/.nycrc
ADDED
package/.travis.yml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.12.0
|
|
4
|
+
|
|
5
|
+
- Added support for [metadata template deletion](./docs/metadata.md#delete-metadata-template)
|
|
6
|
+
|
|
7
|
+
## 1.11.0
|
|
8
|
+
|
|
9
|
+
- Added options to preserve file timestamps on [file upload](./docs/files.md#upload-a-file)
|
|
10
|
+
and to rename a file or preserve modification timestamp on [new version upload](./docs/files.md#upload-a-new-version-of-a-file)
|
|
11
|
+
- Added [Collaboration Whitelist](./docs/collaboration-whitelist.md) functionality to allow enterprise admins
|
|
12
|
+
to control which external users can collaborate on their content
|
|
13
|
+
- Added an option to Token Exchange to generate [annotator tokens](./docs/authentication.md#annotator-tokens) for use with Box View
|
|
14
|
+
|
|
15
|
+
## 1.10.1
|
|
16
|
+
|
|
17
|
+
- Updated to jsonwebtoken@8.1.0 to fix an issue where some users were getting
|
|
18
|
+
an error when using App Auth
|
|
19
|
+
|
|
20
|
+
## 1.10.0
|
|
21
|
+
|
|
22
|
+
- Added support for [Terms of Service](./docs/terms-of-service.md) endpoints
|
|
23
|
+
- Fixed a bug where receiving a collection without paging parameters from the API
|
|
24
|
+
would cause the SDK to throw an exception when using the `iterators` SDK option.
|
|
25
|
+
Now, this will return an iterator over the items returned by the API.
|
|
26
|
+
- Fixed a bug in Token Exchange where passing multiple scopes would result in an error
|
|
27
|
+
- Added support for [getting Representations info on a file](./docs/files.md#get-representation-info)
|
|
28
|
+
|
|
3
29
|
## 1.9.0
|
|
4
30
|
|
|
5
31
|
- Fixed token methods to return bluebird Promises instead of native Promises
|
package/Makefile.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
require('shelljs/make');
|
|
13
13
|
var nodeCLI = require('shelljs-nodecli');
|
|
14
|
+
var semver = require('semver');
|
|
14
15
|
|
|
15
16
|
//------------------------------------------------------------------------------
|
|
16
17
|
// Helpers
|
|
@@ -85,7 +86,10 @@ target.lint = function() {
|
|
|
85
86
|
|
|
86
87
|
target.test = function() {
|
|
87
88
|
var code = target.lint();
|
|
88
|
-
|
|
89
|
+
if (semver.gte(process.version.substr(1), '6.0.0')) {
|
|
90
|
+
code += nodeCLI.exec('nsp', 'check').code;
|
|
91
|
+
}
|
|
92
|
+
code += nodeCLI.exec('nyc', MOCHA_BINARY, '-c', '-R spec', '--exit', TEST_FILES).code;
|
|
89
93
|
|
|
90
94
|
if (code) {
|
|
91
95
|
exit(code);
|
package/lib/box-client.js
CHANGED
|
@@ -57,7 +57,9 @@ var Users = require('./managers/users'),
|
|
|
57
57
|
RetentionPolicies = require('./managers/retention-policies'),
|
|
58
58
|
DevicePins = require('./managers/device-pins'),
|
|
59
59
|
Webhooks = require('./managers/webhooks'),
|
|
60
|
-
RecentItems = require('./managers/recent-items')
|
|
60
|
+
RecentItems = require('./managers/recent-items'),
|
|
61
|
+
CollaborationWhitelist = require('./managers/collaboration-whitelist'),
|
|
62
|
+
TermsOfService = require('./managers/terms-of-service');
|
|
61
63
|
|
|
62
64
|
// ------------------------------------------------------------------------------
|
|
63
65
|
// Private
|
|
@@ -207,6 +209,9 @@ function BoxClient(apiSession, config, requestManager) {
|
|
|
207
209
|
this.devicePins = new DevicePins(this);
|
|
208
210
|
this.webhooks = new Webhooks(this);
|
|
209
211
|
this.recentItems = new RecentItems(this);
|
|
212
|
+
this.collaborationWhitelist = new CollaborationWhitelist(this);
|
|
213
|
+
this.termsOfService = new TermsOfService(this);
|
|
214
|
+
|
|
210
215
|
|
|
211
216
|
// Array of requests when in batch mode, null otherwise
|
|
212
217
|
this._batch = null;
|
|
@@ -458,12 +463,22 @@ BoxClient.prototype.revokeTokens = function(callback) {
|
|
|
458
463
|
* Exchange the client access token for one with lower scope
|
|
459
464
|
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
460
465
|
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
466
|
+
* @param {Object} [options] - Optional parameters
|
|
467
|
+
* @param {ActorParams} [options.actor] - Optional actor parameters for creating annotator tokens with Token Auth client
|
|
461
468
|
* @param {Function} [callback] Called with the new token
|
|
462
469
|
* @returns {Promise<TokenInfo>} A promise resolving to the exchanged token info
|
|
463
470
|
*/
|
|
464
|
-
BoxClient.prototype.exchangeToken = function(scopes, resource, callback) {
|
|
471
|
+
BoxClient.prototype.exchangeToken = function(scopes, resource, options, callback) {
|
|
472
|
+
|
|
473
|
+
// Shuffle optional parameters
|
|
474
|
+
if (typeof options === 'function') {
|
|
475
|
+
callback = options;
|
|
476
|
+
options = {};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
var opts = Object.assign({ tokenRequestOptions: this._tokenOptions || null }, options);
|
|
465
480
|
|
|
466
|
-
return this._session.exchangeToken(scopes, resource,
|
|
481
|
+
return this._session.exchangeToken(scopes, resource, opts)
|
|
467
482
|
.asCallback(callback);
|
|
468
483
|
};
|
|
469
484
|
|
package/lib/event-stream.js
CHANGED
|
@@ -181,57 +181,57 @@ EventStream.prototype.fetchEvents = function() {
|
|
|
181
181
|
|
|
182
182
|
// Get new events after the rate limiter expires
|
|
183
183
|
return this._rateLimiter.then(() => this._client.events.get(eventParams)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
184
|
+
.then(events => {
|
|
185
|
+
|
|
186
|
+
// Reset the rate limiter
|
|
187
|
+
this._rateLimiter = Promise.delay(this._options.fetchInterval);
|
|
188
|
+
|
|
189
|
+
// If the response wasn't what we expected, re-poll
|
|
190
|
+
if (!events.entries || !events.next_stream_position) {
|
|
191
|
+
this.doLongPoll();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this._streamPosition = events.next_stream_position;
|
|
196
|
+
|
|
197
|
+
// De-duplicate the fetched events, since the API often returns
|
|
198
|
+
// the same events at multiple subsequent stream positions
|
|
199
|
+
var newEvents = events.entries.filter(event => !this._dedupHash[event.event_id]);
|
|
200
|
+
|
|
201
|
+
// If there aren't any non-duplicate events, go back to polling
|
|
202
|
+
if (!newEvents.length) {
|
|
203
|
+
this.doLongPoll();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Pause the stream to avoid race conditions while pushing in the new events.
|
|
208
|
+
// Without this, _read() would be called again from inside each push(),
|
|
209
|
+
// resulting in multiple parallel calls to fetchEvents().
|
|
210
|
+
// See https://github.com/nodejs/node/issues/3203
|
|
211
|
+
var wasPaused = this.isPaused();
|
|
212
|
+
this.pause();
|
|
213
|
+
|
|
214
|
+
// Push new events into the stream
|
|
215
|
+
newEvents.forEach(event => {
|
|
216
|
+
this._dedupHash[event.event_id] = true;
|
|
217
|
+
this.push(event);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
if (!wasPaused) {
|
|
221
|
+
// This will deliver the events and trigger the next call to _read() once they have been consumed.
|
|
222
|
+
this.resume();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Once the deduplication filter gets too big, clean it up
|
|
226
|
+
if (Object.keys(this._dedupHash).length >= this._options.deduplicationFilterSize) {
|
|
227
|
+
this.cleanupDedupFilter(events.entries);
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
.catch(err => {
|
|
231
|
+
|
|
232
|
+
this.emit('error', err);
|
|
233
|
+
setTimeout(() => this.getLongPollInfo(), this._options.retryDelay);
|
|
234
|
+
})
|
|
235
235
|
);
|
|
236
236
|
};
|
|
237
237
|
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Manager for the Box Collaboration Whitelist Resource
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
// -----------------------------------------------------------------------------
|
|
7
|
+
// Typedefs
|
|
8
|
+
// -----------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Collaboration Whitelist parameter constant
|
|
12
|
+
* @typedef {string} CollaborationWhitelistDirection Determines the type of restriction for whitelisting for a domain
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// ------------------------------------------------------------------------------
|
|
16
|
+
// Requirements
|
|
17
|
+
// ------------------------------------------------------------------------------
|
|
18
|
+
var urlPath = require('../util/url-path');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
// ------------------------------------------------------------------------------
|
|
22
|
+
// Private
|
|
23
|
+
// ------------------------------------------------------------------------------
|
|
24
|
+
var BASE_PATH = '/collaboration_whitelist_entries',
|
|
25
|
+
TARGET_ENTRY_PATH = '/collaboration_whitelist_exempt_targets';
|
|
26
|
+
|
|
27
|
+
// ------------------------------------------------------------------------------
|
|
28
|
+
// Public
|
|
29
|
+
// ------------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Simple manager for interacting with all 'Collaboration Whitelist' endpoints and actions.
|
|
33
|
+
*
|
|
34
|
+
* @constructor
|
|
35
|
+
* @param {BoxClient} client - The Box API Client that is responsible for making calls to the API
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
38
|
+
function CollaborationWhitelist(client) {
|
|
39
|
+
this.client = client;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Enum of valid collaboration whitelist directions
|
|
44
|
+
*
|
|
45
|
+
* @readonly
|
|
46
|
+
* @enum {CollaborationWhitelistDirection}
|
|
47
|
+
*/
|
|
48
|
+
CollaborationWhitelist.prototype.directions = Object.freeze({
|
|
49
|
+
INBOUND: 'inbound',
|
|
50
|
+
OUTBOUND: 'outbound',
|
|
51
|
+
BOTH: 'both'
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Add a domain to the enterprise's whitelist.
|
|
56
|
+
*
|
|
57
|
+
* API Endpoint: '/collaboration_whitelist_entries'
|
|
58
|
+
* Method: POST
|
|
59
|
+
*
|
|
60
|
+
* @param {string} domain - The domain to be added to the whitelist
|
|
61
|
+
* @param {CollaborationWhitelistDirection} direction - Inbound refers to collaboration actions within an enterprise. Outbound
|
|
62
|
+
* refers to collaboration actions external to an enterprise. Both refers to
|
|
63
|
+
* collaboration actions taken within and external to an enterprise
|
|
64
|
+
* @param {Function} [callback] - Passed the collaboration whitelist information if it was created successfully
|
|
65
|
+
* @returns {Promise<Object>} A promise resolve to the collaboration whitelist object
|
|
66
|
+
*/
|
|
67
|
+
CollaborationWhitelist.prototype.addDomain = function(domain, direction, callback) {
|
|
68
|
+
|
|
69
|
+
var params = {
|
|
70
|
+
body: {
|
|
71
|
+
domain: domain,
|
|
72
|
+
direction: direction
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
var apiPath = urlPath(BASE_PATH);
|
|
77
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Requests a collaboration whitelist entry with a given ID.
|
|
82
|
+
*
|
|
83
|
+
* API Endpoint: '/collaboration_whitelist_entries/:domainID'
|
|
84
|
+
* Method: GET
|
|
85
|
+
*
|
|
86
|
+
* @param {string} domainID - Box ID of the collaboration whitelist being requested
|
|
87
|
+
* @param {Object} [qs] - Additional options can be passed with the request via querystring. Can be left null in most cases.
|
|
88
|
+
* @param {Function} [callback] - Passed the collaboration whitelist information if it was acquired successfully
|
|
89
|
+
* @returns {Promise<Object>} A promise resolving to the collaboration whitelist object
|
|
90
|
+
*/
|
|
91
|
+
CollaborationWhitelist.prototype.getWhitelistedDomain = function(domainID, qs, callback) {
|
|
92
|
+
|
|
93
|
+
var params = { qs };
|
|
94
|
+
|
|
95
|
+
var apiPath = urlPath(BASE_PATH, domainID);
|
|
96
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Requests all collaboration whitelist entries within an enterprise.
|
|
101
|
+
*
|
|
102
|
+
* API Endpoint: '/collaboration_whitelist_entries'
|
|
103
|
+
* Method: GET
|
|
104
|
+
*
|
|
105
|
+
* @param {Object} [options] - Additional options. Can be left null in most cases.
|
|
106
|
+
* @param {int} [options.limit] - The number of collaboration whitelists to retrieve
|
|
107
|
+
* @param {string} [options.marker] - Paging marker, retrieve records starting at this position in the list. Left blank to start at the beginning.
|
|
108
|
+
* @param {Function} [callback] - Passed a list of collaboration whitelists if successful, error otherwise
|
|
109
|
+
* @returns {Promise<Object>} A promise resolving to the collection of collaboration whitelists
|
|
110
|
+
*/
|
|
111
|
+
CollaborationWhitelist.prototype.getAllWhitelistedDomains = function(options, callback) {
|
|
112
|
+
|
|
113
|
+
var params = {
|
|
114
|
+
qs: options
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
var apiPath = urlPath(BASE_PATH);
|
|
118
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Delete a given collaboration whitelist entry.
|
|
123
|
+
*
|
|
124
|
+
* API Endpoint: '/collaboration_whitelist_entries/:domainID'
|
|
125
|
+
* Method: DELETE
|
|
126
|
+
*
|
|
127
|
+
* @param {string} domainID - Box ID of the collaboration whitelist being requested
|
|
128
|
+
* @param {Function} [callback] - Empty response body passed if successful.
|
|
129
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
130
|
+
*/
|
|
131
|
+
CollaborationWhitelist.prototype.removeDomain = function(domainID, callback) {
|
|
132
|
+
|
|
133
|
+
var apiPath = urlPath(BASE_PATH, domainID);
|
|
134
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Adds a Box User to the exempt target list.
|
|
139
|
+
*
|
|
140
|
+
* API Endpoint: '/collaboration_whitelist_exempt_targets'
|
|
141
|
+
* Method: GET
|
|
142
|
+
*
|
|
143
|
+
* @param {string} userID - The ID of the Box User to be added to the whitelist
|
|
144
|
+
* @param {Function} [callback] - Passed a collaboration whitelist for user if successful, error otherwise
|
|
145
|
+
* @returns {Promise<Object>} A promise resolving to a user collaboration whitelist
|
|
146
|
+
*/
|
|
147
|
+
CollaborationWhitelist.prototype.addExemption = function(userID, callback) {
|
|
148
|
+
|
|
149
|
+
var params = {
|
|
150
|
+
body: {
|
|
151
|
+
user: {
|
|
152
|
+
id: userID,
|
|
153
|
+
type: 'user'
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
var apiPath = urlPath(TARGET_ENTRY_PATH);
|
|
159
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Retrieves information about a collaboration whitelist for user by whitelist ID.
|
|
164
|
+
*
|
|
165
|
+
* API Endpoint: '/collaboration_whitelist_exempt_targets/:exemptionID'
|
|
166
|
+
* Method: GET
|
|
167
|
+
*
|
|
168
|
+
* @param {string} exemptionID - The ID of the collaboration whitelist
|
|
169
|
+
* @param {Object} [qs] - Additional options can be passed with the request via querystring. Can be left null in most cases.
|
|
170
|
+
* @param {Function} [callback] - Passed the collaboration whitelist information for a user if it was acquired successfully
|
|
171
|
+
* @returns {Promise<Object>} A promise resolving to the collaboration whitelist object
|
|
172
|
+
*/
|
|
173
|
+
CollaborationWhitelist.prototype.getExemption = function(exemptionID, qs, callback) {
|
|
174
|
+
|
|
175
|
+
var params = {
|
|
176
|
+
qs: qs
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
var apiPath = urlPath(TARGET_ENTRY_PATH, exemptionID);
|
|
180
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Retrieve a list of all exemptions to an enterprise's collaboration whitelist.
|
|
185
|
+
*
|
|
186
|
+
* API Endpoint: '/collaboration_whitelist_exempt_targets'
|
|
187
|
+
* Method: GET
|
|
188
|
+
*
|
|
189
|
+
* @param {Object} [options] - Additional options. Can be left null in most cases.
|
|
190
|
+
* @param {string} [options.limit] - The number of user collaboration whitelists to retrieve
|
|
191
|
+
* @param {string} [options.marker] - Paging marker, retrieve records starting at this position in the list. Left blank to start at the beginning.
|
|
192
|
+
* @param {Function} [callback] - Passed a list of user collaboration whitelists if successful, error otherwise
|
|
193
|
+
* @returns {Promise<Object>} A promise resolving to the collection of user collaboration whitelists
|
|
194
|
+
*/
|
|
195
|
+
CollaborationWhitelist.prototype.getAllExemptions = function(options, callback) {
|
|
196
|
+
|
|
197
|
+
var params = {
|
|
198
|
+
qs: options
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
var apiPath = urlPath(TARGET_ENTRY_PATH);
|
|
202
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Delete a given user collaboration whitelist.
|
|
207
|
+
*
|
|
208
|
+
* API Endpoint: '/collaboration_whitelist_exempt_targets/:exemptionID'
|
|
209
|
+
* Method: DELETE
|
|
210
|
+
*
|
|
211
|
+
* @param {string} exemptionID - Box ID of the user collaboration whitelist being requested
|
|
212
|
+
* @param {Function} [callback] - Empty response body passed if successful.
|
|
213
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
214
|
+
*/
|
|
215
|
+
CollaborationWhitelist.prototype.removeExemption = function(exemptionID, callback) {
|
|
216
|
+
|
|
217
|
+
var apiPath = urlPath(TARGET_ENTRY_PATH, exemptionID);
|
|
218
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @module box-node-sdk/lib/managers/collaboration-whitelists
|
|
223
|
+
* @see {@Link CollaborationWhitelist}
|
|
224
|
+
*/
|
|
225
|
+
module.exports = CollaborationWhitelist;
|