box-node-sdk 1.35.0 → 1.37.2
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/CHANGELOG.md +37 -2
- package/README.md +1 -1
- package/lib/api-request-manager.d.ts +38 -0
- package/lib/api-request-manager.js +48 -55
- package/lib/api-request-manager.js.map +1 -0
- package/lib/api-request.d.ts +141 -0
- package/lib/api-request.js +202 -281
- package/lib/api-request.js.map +1 -0
- package/lib/box-client.d.ts +269 -0
- package/lib/box-client.js +551 -713
- package/lib/box-client.js.map +1 -0
- package/lib/box-node-sdk.d.ts +216 -0
- package/lib/box-node-sdk.js +317 -352
- package/lib/box-node-sdk.js.map +1 -0
- package/lib/chunked-uploader.d.ts +129 -0
- package/lib/chunked-uploader.js +287 -358
- package/lib/chunked-uploader.js.map +1 -0
- package/lib/enterprise-event-stream.d.ts +82 -0
- package/lib/enterprise-event-stream.js +189 -203
- package/lib/enterprise-event-stream.js.map +1 -0
- package/lib/event-stream.d.ts +92 -0
- package/lib/event-stream.js +274 -302
- package/lib/event-stream.js.map +1 -0
- package/lib/managers/collaboration-allowlist.d.ts +137 -0
- package/lib/managers/collaboration-allowlist.js +200 -0
- package/lib/managers/collaboration-allowlist.js.map +1 -0
- package/lib/managers/collaboration-whitelist.d.ts +3 -0
- package/lib/managers/collaboration-whitelist.js +8 -222
- package/lib/managers/collaboration-whitelist.js.map +1 -0
- package/lib/managers/collaborations.d.ts +166 -0
- package/lib/managers/collaborations.js +225 -258
- package/lib/managers/collaborations.js.map +1 -0
- package/lib/managers/collections.d.ts +42 -0
- package/lib/managers/collections.js +45 -50
- package/lib/managers/collections.js.map +1 -0
- package/lib/managers/comments.d.ts +103 -0
- package/lib/managers/comments.js +158 -173
- package/lib/managers/comments.js.map +1 -0
- package/lib/managers/device-pins.d.ts +52 -0
- package/lib/managers/device-pins.js +75 -88
- package/lib/managers/device-pins.js.map +1 -0
- package/lib/managers/enterprise.d.ts +162 -0
- package/lib/managers/enterprise.js +168 -199
- package/lib/managers/enterprise.js.map +1 -0
- package/lib/managers/events.d.ts +177 -0
- package/lib/managers/events.js +230 -254
- package/lib/managers/events.js.map +1 -0
- package/lib/managers/files.d.ts +772 -0
- package/lib/managers/files.js +1400 -1602
- package/lib/managers/files.js.map +1 -0
- package/lib/managers/folders.d.ts +347 -0
- package/lib/managers/folders.js +551 -567
- package/lib/managers/folders.js.map +1 -0
- package/lib/managers/groups.d.ts +202 -0
- package/lib/managers/groups.js +238 -287
- package/lib/managers/groups.js.map +1 -0
- package/lib/managers/legal-hold-policies.d.ts +190 -0
- package/lib/managers/legal-hold-policies.js +228 -272
- package/lib/managers/legal-hold-policies.js.map +1 -0
- package/lib/managers/metadata.d.ts +228 -0
- package/lib/managers/metadata.js +265 -328
- package/lib/managers/metadata.js.map +1 -0
- package/lib/managers/recent-items.d.ts +38 -0
- package/lib/managers/recent-items.js +32 -39
- package/lib/managers/recent-items.js.map +1 -0
- package/lib/managers/retention-policies.d.ts +213 -0
- package/lib/managers/retention-policies.js +235 -281
- package/lib/managers/retention-policies.js.map +1 -0
- package/lib/managers/search.d.ts +82 -0
- package/lib/managers/search.js +68 -88
- package/lib/managers/search.js.map +1 -0
- package/lib/managers/shared-items.d.ts +33 -0
- package/lib/managers/shared-items.js +54 -62
- package/lib/managers/shared-items.js.map +1 -0
- package/lib/managers/storage-policies.d.ts +86 -0
- package/lib/managers/storage-policies.js +108 -142
- package/lib/managers/storage-policies.js.map +1 -0
- package/lib/managers/tasks.d.ts +161 -0
- package/lib/managers/tasks.js +219 -260
- package/lib/managers/tasks.js.map +1 -0
- package/lib/managers/terms-of-service.d.ts +161 -0
- package/lib/managers/terms-of-service.js +250 -273
- package/lib/managers/terms-of-service.js.map +1 -0
- package/lib/managers/trash.d.ts +30 -0
- package/lib/managers/trash.js +30 -41
- package/lib/managers/trash.js.map +1 -0
- package/lib/managers/users.d.ts +131 -0
- package/lib/managers/users.js +160 -203
- package/lib/managers/users.js.map +1 -0
- package/lib/managers/web-links.d.ts +127 -0
- package/lib/managers/web-links.js +183 -209
- package/lib/managers/web-links.js.map +1 -0
- package/lib/managers/webhooks.d.ts +166 -0
- package/lib/managers/webhooks.js +312 -305
- package/lib/managers/webhooks.js.map +1 -0
- package/lib/sessions/anonymous-session.d.ts +69 -0
- package/lib/sessions/anonymous-session.js +88 -102
- package/lib/sessions/anonymous-session.js.map +1 -0
- package/lib/sessions/app-auth-session.d.ts +92 -0
- package/lib/sessions/app-auth-session.js +140 -160
- package/lib/sessions/app-auth-session.js.map +1 -0
- package/lib/sessions/basic-session.d.ts +56 -0
- package/lib/sessions/basic-session.js +40 -50
- package/lib/sessions/basic-session.js.map +1 -0
- package/lib/sessions/persistent-session.d.ts +96 -0
- package/lib/sessions/persistent-session.js +191 -211
- package/lib/sessions/persistent-session.js.map +1 -0
- package/lib/token-manager.d.ts +191 -0
- package/lib/token-manager.js +390 -465
- package/lib/token-manager.js.map +1 -0
- package/lib/util/config.d.ts +86 -0
- package/lib/util/config.js +124 -152
- package/lib/util/config.js.map +1 -0
- package/lib/util/errors.d.ts +50 -0
- package/lib/util/errors.js +134 -145
- package/lib/util/errors.js.map +1 -0
- package/lib/util/exponential-backoff.d.ts +11 -0
- package/lib/util/exponential-backoff.js +10 -22
- package/lib/util/exponential-backoff.js.map +1 -0
- package/lib/util/paging-iterator.d.ts +53 -0
- package/lib/util/paging-iterator.js +202 -218
- package/lib/util/paging-iterator.js.map +1 -0
- package/lib/util/url-path.d.ts +16 -0
- package/lib/util/url-path.js +20 -35
- package/lib/util/url-path.js.map +1 -0
- package/package.json +24 -9
package/lib/box-node-sdk.js
CHANGED
|
@@ -1,67 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview Box SDK for Node.js
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*/
|
|
39
|
-
|
|
5
|
+
var __extends = (this && this.__extends) || (function () {
|
|
6
|
+
var extendStatics = function (d, b) {
|
|
7
|
+
extendStatics = Object.setPrototypeOf ||
|
|
8
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
9
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
10
|
+
return extendStatics(d, b);
|
|
11
|
+
};
|
|
12
|
+
return function (d, b) {
|
|
13
|
+
if (typeof b !== "function" && b !== null)
|
|
14
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
15
|
+
extendStatics(d, b);
|
|
16
|
+
function __() { this.constructor = d; }
|
|
17
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
40
39
|
// ------------------------------------------------------------------------------
|
|
41
40
|
// Requirements
|
|
42
41
|
// ------------------------------------------------------------------------------
|
|
43
|
-
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
BasicAPISession = require('./sessions/basic-session'),
|
|
51
|
-
PersistentAPISession = require('./sessions/persistent-session'),
|
|
52
|
-
AnonymousAPISession = require('./sessions/anonymous-session'),
|
|
53
|
-
AppAuthSession = require('./sessions/app-auth-session'),
|
|
54
|
-
BoxClient = require('./box-client'),
|
|
55
|
-
Webhooks = require('./managers/webhooks');
|
|
56
|
-
|
|
42
|
+
var events_1 = require("events");
|
|
43
|
+
var qs = __importStar(require("querystring"));
|
|
44
|
+
var AnonymousAPISession = require("./sessions/anonymous-session");
|
|
45
|
+
var APIRequestManager = require("./api-request-manager");
|
|
46
|
+
var BoxClient = require("./box-client");
|
|
47
|
+
var TokenManager = require("./token-manager");
|
|
48
|
+
var Config = require('./util/config'), BasicAPISession = require('./sessions/basic-session'), PersistentAPISession = require('./sessions/persistent-session'), AppAuthSession = require('./sessions/app-auth-session'), Webhooks = require('./managers/webhooks');
|
|
57
49
|
// ------------------------------------------------------------------------------
|
|
58
50
|
// Private
|
|
59
51
|
// ------------------------------------------------------------------------------
|
|
60
|
-
|
|
61
52
|
// ------------------------------------------------------------------------------
|
|
62
53
|
// Public
|
|
63
54
|
// ------------------------------------------------------------------------------
|
|
64
|
-
|
|
65
55
|
/**
|
|
66
56
|
* A backend NodeJS SDK to interact with the Box V2 API.
|
|
67
57
|
* This is the single entry point for all SDK consumer interactions. This is the only file that a 3rd party app
|
|
@@ -75,311 +65,286 @@ var EventEmitter = require('events').EventEmitter,
|
|
|
75
65
|
* @param {UserConfigurationOptions} params User settings used to initialize and customize the SDK
|
|
76
66
|
* @constructor
|
|
77
67
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
68
|
+
var BoxSDKNode = /** @class */ (function (_super) {
|
|
69
|
+
__extends(BoxSDKNode, _super);
|
|
70
|
+
function BoxSDKNode(params) {
|
|
71
|
+
var _this = _super.call(this) || this;
|
|
72
|
+
var eventBus = new events_1.EventEmitter();
|
|
73
|
+
var self = _this;
|
|
74
|
+
eventBus.on('response', function () {
|
|
75
|
+
var args = [].slice.call(arguments);
|
|
76
|
+
args.unshift('response');
|
|
77
|
+
self.emit.apply(self, args);
|
|
78
|
+
});
|
|
79
|
+
// Setup the configuration with the given params
|
|
80
|
+
_this.config = new Config(params);
|
|
81
|
+
_this._eventBus = eventBus;
|
|
82
|
+
_this._setup();
|
|
83
|
+
return _this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Setup the SDK instance by instantiating necessary objects with current
|
|
87
|
+
* configuration values.
|
|
88
|
+
*
|
|
89
|
+
* @returns {void}
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
BoxSDKNode.prototype._setup = function () {
|
|
93
|
+
// Instantiate the request manager
|
|
94
|
+
this.requestManager = new APIRequestManager(this.config, this._eventBus);
|
|
95
|
+
// Initialize the rest of the SDK with the given configuration
|
|
96
|
+
this.tokenManager = new TokenManager(this.config, this.requestManager);
|
|
97
|
+
this.anonymousSession = new AnonymousAPISession(this.config, this.tokenManager);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Gets the BoxSDKNode instance by passing boxAppSettings json downloaded from the developer console.
|
|
101
|
+
*
|
|
102
|
+
* @param {Object} appConfig boxAppSettings object retrieved from Dev Console.
|
|
103
|
+
* @returns {BoxSDKNode} an instance that has been preconfigured with the values from the Dev Console
|
|
104
|
+
*/
|
|
105
|
+
BoxSDKNode.getPreconfiguredInstance = function (appConfig /* FIXME */) {
|
|
106
|
+
if (typeof appConfig.boxAppSettings !== 'object') {
|
|
107
|
+
throw new TypeError('Configuration does not include boxAppSettings object.');
|
|
108
|
+
}
|
|
109
|
+
var boxAppSettings = appConfig.boxAppSettings;
|
|
110
|
+
var webhooks = appConfig.webhooks;
|
|
111
|
+
if (typeof webhooks === 'object') {
|
|
112
|
+
Webhooks.setSignatureKeys(webhooks.primaryKey, webhooks.secondaryKey);
|
|
113
|
+
}
|
|
114
|
+
var params = {};
|
|
115
|
+
if (typeof boxAppSettings.clientID === 'string') {
|
|
116
|
+
params.clientID = boxAppSettings.clientID;
|
|
117
|
+
}
|
|
118
|
+
if (typeof boxAppSettings.clientSecret === 'string') {
|
|
119
|
+
params.clientSecret = boxAppSettings.clientSecret;
|
|
120
|
+
}
|
|
121
|
+
// Only try to assign app auth settings if they are present
|
|
122
|
+
// Some configurations do not include them (but might include other info, e.g. webhooks)
|
|
123
|
+
if (typeof boxAppSettings.appAuth === 'object' &&
|
|
124
|
+
boxAppSettings.appAuth.publicKeyID) {
|
|
125
|
+
params.appAuth = {
|
|
126
|
+
keyID: boxAppSettings.appAuth.publicKeyID,
|
|
127
|
+
privateKey: boxAppSettings.appAuth.privateKey,
|
|
128
|
+
};
|
|
129
|
+
var passphrase = boxAppSettings.appAuth.passphrase;
|
|
130
|
+
if (typeof passphrase === 'string') {
|
|
131
|
+
params.appAuth.passphrase = passphrase;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (typeof appConfig.enterpriseID === 'string') {
|
|
135
|
+
params.enterpriseID = appConfig.enterpriseID;
|
|
136
|
+
}
|
|
137
|
+
return new BoxSDKNode(params);
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Updates the SDK configuration with new parameters.
|
|
141
|
+
*
|
|
142
|
+
* @param {UserConfigurationOptions} params User settings
|
|
143
|
+
* @returns {void}
|
|
144
|
+
*/
|
|
145
|
+
BoxSDKNode.prototype.configure = function (params) {
|
|
146
|
+
this.config = this.config.extend(params);
|
|
147
|
+
this._setup();
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Returns a Box Client with a Basic API Session. The client is able to make requests on behalf of a user.
|
|
151
|
+
* A basic session has no access to a user's refresh token. Because of this, once the session's tokens
|
|
152
|
+
* expire the client cannot recover and a new session will need to be generated.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} accessToken A user's Box API access token
|
|
155
|
+
* @returns {BoxClient} Returns a new Box Client paired to a new BasicAPISession
|
|
156
|
+
*/
|
|
157
|
+
BoxSDKNode.prototype.getBasicClient = function (accessToken) {
|
|
158
|
+
var apiSession = new BasicAPISession(accessToken, this.tokenManager);
|
|
159
|
+
return new BoxClient(apiSession, this.config, this.requestManager);
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Returns a Box Client with a Basic API Session. The client is able to make requests on behalf of a user.
|
|
163
|
+
* A basic session has no access to a user's refresh token. Because of this, once the session's tokens
|
|
164
|
+
* expire the client cannot recover and a new session will need to be generated.
|
|
165
|
+
*
|
|
166
|
+
* @param {string} accessToken A user's Box API access token
|
|
167
|
+
* @returns {BoxClient} Returns a new Box Client paired to a new BasicAPISession
|
|
168
|
+
*/
|
|
169
|
+
BoxSDKNode.getBasicClient = function (accessToken) {
|
|
170
|
+
return new BoxSDKNode({
|
|
171
|
+
clientID: '',
|
|
172
|
+
clientSecret: '',
|
|
173
|
+
}).getBasicClient(accessToken);
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Returns a Box Client with a persistent API session. A persistent API session helps manage the user's tokens,
|
|
177
|
+
* and can refresh them automatically if the access token expires. If a central data-store is given, the session
|
|
178
|
+
* can read & write tokens to it.
|
|
179
|
+
*
|
|
180
|
+
* @NOTE: If tokenInfo or tokenStore are formatted incorrectly, this method will throw an error. If you
|
|
181
|
+
* haven't explicitly created either of these objects or are otherwise not completly confident in their validity,
|
|
182
|
+
* you should wrap your call to getPersistentClient in a try-catch to handle any potential errors.
|
|
183
|
+
*
|
|
184
|
+
* @param {TokenInfo} tokenInfo A tokenInfo object to use for authentication
|
|
185
|
+
* @param {TokenStore} [tokenStore] An optional token store for reading/writing tokens to session
|
|
186
|
+
* @returns {BoxClient} Returns a new Box Client paired to a new PersistentAPISession
|
|
187
|
+
*/
|
|
188
|
+
BoxSDKNode.prototype.getPersistentClient = function (tokenInfo /* FIXME */, tokenStore) {
|
|
189
|
+
var apiSession = new PersistentAPISession(tokenInfo, tokenStore, this.config, this.tokenManager);
|
|
190
|
+
return new BoxClient(apiSession, this.config, this.requestManager);
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Returns A Box Client with an Anonymous API Session. An Anonymous API Session has access to an anonymous
|
|
194
|
+
* client-credentials token, which isn't tied to any specific user. Because of this, the client will only
|
|
195
|
+
* have access to endpoints that allow client-credential tokens. All Anonymous API Sessions share the
|
|
196
|
+
* same tokens, which allows them to refresh them efficiently and reduce load on both the application and
|
|
197
|
+
* the API.
|
|
198
|
+
*
|
|
199
|
+
* @returns {BoxClient} Returns a new Box Client paired to a AnonymousAPISession
|
|
200
|
+
*/
|
|
201
|
+
BoxSDKNode.prototype.getAnonymousClient = function () {
|
|
202
|
+
return new BoxClient(this.anonymousSession, this.config, this.requestManager);
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Create a new client using App Auth for the given entity. This allows either
|
|
206
|
+
* managing App Users (as the enterprise) or performing operations as the App
|
|
207
|
+
* Users themselves (as a user).
|
|
208
|
+
*
|
|
209
|
+
* @param {string} type The type of entity to operate as, "enterprise" or "user"
|
|
210
|
+
* @param {string} [id] (Optional) The Box ID of the entity to operate as
|
|
211
|
+
* @param {TokenStore} [tokenStore] (Optional) the token store to use for caching tokens
|
|
212
|
+
* @returns {BoxClient} A new client authorized as the app user or enterprise
|
|
213
|
+
*/
|
|
214
|
+
BoxSDKNode.prototype.getAppAuthClient = function (type, id, tokenStore) {
|
|
215
|
+
if (type === 'enterprise' && !id) {
|
|
216
|
+
if (this.config.enterpriseID) {
|
|
217
|
+
id = this.config.enterpriseID;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
throw new Error('Enterprise ID must be passed');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
var appAuthSession = new AppAuthSession(type, id, this.config, this.tokenManager, tokenStore);
|
|
224
|
+
return new BoxClient(appAuthSession, this.config, this.requestManager);
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Generate the URL for the authorize page to send users to for the first leg of
|
|
228
|
+
* the OAuth2 flow.
|
|
229
|
+
*
|
|
230
|
+
* @param {Object} params The OAuth2 parameters
|
|
231
|
+
* @returns {string} The authorize page URL
|
|
232
|
+
*/
|
|
233
|
+
BoxSDKNode.prototype.getAuthorizeURL = function (params) {
|
|
234
|
+
params.client_id = this.config.clientID;
|
|
235
|
+
return this.config.authorizeRootURL + "/oauth2/authorize?" + qs.stringify(params);
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Acquires token info using an authorization code
|
|
239
|
+
*
|
|
240
|
+
* @param {string} authorizationCode - authorization code issued by Box
|
|
241
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
242
|
+
* @param {Function} [callback] - passed a TokenInfo object if tokens were granted successfully
|
|
243
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
244
|
+
*/
|
|
245
|
+
BoxSDKNode.prototype.getTokensAuthorizationCodeGrant = function (authorizationCode, options, callback) {
|
|
246
|
+
return this.tokenManager
|
|
247
|
+
.getTokensAuthorizationCodeGrant(authorizationCode, options /* FIXME */)
|
|
248
|
+
.asCallback(callback);
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Refreshes the access and refresh tokens for a given refresh token.
|
|
252
|
+
*
|
|
253
|
+
* @param {string} refreshToken - A valid OAuth refresh token
|
|
254
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
255
|
+
* @param {Function} [callback] - passed a TokenInfo object if tokens were granted successfully
|
|
256
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
257
|
+
*/
|
|
258
|
+
BoxSDKNode.prototype.getTokensRefreshGrant = function (refreshToken, options, callback) {
|
|
259
|
+
if (typeof options === 'function') {
|
|
260
|
+
callback = options;
|
|
261
|
+
options = null;
|
|
262
|
+
}
|
|
263
|
+
return this.tokenManager
|
|
264
|
+
.getTokensRefreshGrant(refreshToken, options /* FIXME */)
|
|
265
|
+
.asCallback(callback);
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Gets tokens for enterprise administration of app users
|
|
269
|
+
* @param {string} enterpriseID The ID of the enterprise to generate a token for
|
|
270
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
271
|
+
* @param {Function} [callback] Passed the tokens if successful
|
|
272
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
273
|
+
*/
|
|
274
|
+
BoxSDKNode.prototype.getEnterpriseAppAuthTokens = function (enterpriseID, options, callback) {
|
|
275
|
+
if (typeof options === 'function') {
|
|
276
|
+
callback = options;
|
|
277
|
+
options = null;
|
|
278
|
+
}
|
|
279
|
+
if (!enterpriseID) {
|
|
280
|
+
if (this.config.enterpriseID) {
|
|
281
|
+
enterpriseID = this.config.enterpriseID;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
throw new Error('Enterprise id must be passed');
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return this.tokenManager
|
|
288
|
+
.getTokensJWTGrant('enterprise', enterpriseID, options /* FIXME */)
|
|
289
|
+
.asCallback(callback);
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Gets tokens for App Users via a JWT grant
|
|
293
|
+
* @param {string} userID The ID of the App User to generate a token for
|
|
294
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
295
|
+
* @param {Function} [callback] Passed the tokens if successful
|
|
296
|
+
* @returns {Promise<TokentInfo>} Promise reolving to the token infp
|
|
297
|
+
*/
|
|
298
|
+
BoxSDKNode.prototype.getAppUserTokens = function (userID, options, callback) {
|
|
299
|
+
if (typeof options === 'function') {
|
|
300
|
+
callback = options;
|
|
301
|
+
options = null;
|
|
302
|
+
}
|
|
303
|
+
return this.tokenManager
|
|
304
|
+
.getTokensJWTGrant('user', userID, options /* FIXME */)
|
|
305
|
+
.asCallback(callback);
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Revokes a token pair associated with a given access or refresh token.
|
|
309
|
+
*
|
|
310
|
+
* @param {string} token - A valid access or refresh token to revoke
|
|
311
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
312
|
+
* @param {Function} [callback] - If err, revoke failed. Otherwise, revoke succeeded.
|
|
313
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
314
|
+
*/
|
|
315
|
+
BoxSDKNode.prototype.revokeTokens = function (token, options, callback) {
|
|
316
|
+
if (typeof options === 'function') {
|
|
317
|
+
callback = options;
|
|
318
|
+
options = null;
|
|
319
|
+
}
|
|
320
|
+
return this.tokenManager
|
|
321
|
+
.revokeTokens(token, options /* FIXME */)
|
|
322
|
+
.asCallback(callback);
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* Expose the BoxClient property enumerations to the SDK as a whole. This allows
|
|
326
|
+
* the consumer to access and use these values from anywhere in their application
|
|
327
|
+
* (like a helper) by requiring the SDK, instead of needing to pass the client.
|
|
328
|
+
*/
|
|
329
|
+
BoxSDKNode.accessLevels = BoxSDKNode.prototype.accessLevels;
|
|
330
|
+
BoxSDKNode.collaborationRoles = BoxSDKNode.prototype.collaborationRoles;
|
|
331
|
+
BoxSDKNode.CURRENT_USER_ID = BoxSDKNode.prototype.CURRENT_USER_ID;
|
|
332
|
+
/**
|
|
333
|
+
* Expose Webhooks.validateMessage() to the SDK as a whole. This allows
|
|
334
|
+
* the consumer to call BoxSDK.validateWebhookMessage() by just requiring the SDK,
|
|
335
|
+
* instead of needing to create a client (which is not needed to validate messages).
|
|
336
|
+
*/
|
|
337
|
+
BoxSDKNode.validateWebhookMessage = Webhooks.validateMessage;
|
|
338
|
+
return BoxSDKNode;
|
|
339
|
+
}(events_1.EventEmitter));
|
|
117
340
|
/**
|
|
118
341
|
* Expose the BoxClient property enumerations to the SDK as a whole. This allows
|
|
119
342
|
* the consumer to access and use these values from anywhere in their application
|
|
120
343
|
* (like a helper) by requiring the SDK, instead of needing to pass the client.
|
|
121
344
|
*/
|
|
122
345
|
BoxSDKNode.prototype.accessLevels = BoxClient.prototype.accessLevels;
|
|
123
|
-
BoxSDKNode.
|
|
124
|
-
|
|
125
|
-
BoxSDKNode.collaborationRoles = BoxSDKNode.prototype.collaborationRoles;
|
|
346
|
+
BoxSDKNode.prototype.collaborationRoles =
|
|
347
|
+
BoxClient.prototype.collaborationRoles;
|
|
126
348
|
BoxSDKNode.prototype.CURRENT_USER_ID = BoxClient.prototype.CURRENT_USER_ID;
|
|
127
|
-
BoxSDKNode.CURRENT_USER_ID = BoxSDKNode.prototype.CURRENT_USER_ID;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Gets the BoxSDKNode instance by passing boxAppSettings json downloaded from the developer console.
|
|
131
|
-
*
|
|
132
|
-
* @param {Object} appConfig boxAppSettings object retrieved from Dev Console.
|
|
133
|
-
* @returns {BoxSDKNode} an instance that has been preconfigured with the values from the Dev Console
|
|
134
|
-
*/
|
|
135
|
-
BoxSDKNode.getPreconfiguredInstance = function(appConfig) {
|
|
136
|
-
if (typeof appConfig.boxAppSettings !== 'object') {
|
|
137
|
-
throw new TypeError('Configuration does not include boxAppSettings object.');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
var boxAppSettings = appConfig.boxAppSettings;
|
|
141
|
-
var webhooks = appConfig.webhooks;
|
|
142
|
-
if (typeof webhooks === 'object') {
|
|
143
|
-
Webhooks.setSignatureKeys(webhooks.primaryKey, webhooks.secondaryKey);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
var params = {};
|
|
147
|
-
if (typeof boxAppSettings.clientID === 'string') {
|
|
148
|
-
params.clientID = boxAppSettings.clientID;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (typeof boxAppSettings.clientSecret === 'string') {
|
|
152
|
-
params.clientSecret = boxAppSettings.clientSecret;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Only try to assign app auth settings if they are present
|
|
156
|
-
// Some configurations do not include them (but might include other info, e.g. webhooks)
|
|
157
|
-
if (typeof boxAppSettings.appAuth === 'object' && boxAppSettings.appAuth.publicKeyID) {
|
|
158
|
-
|
|
159
|
-
var appAuth = {};
|
|
160
|
-
// Assign publicKeyID to keyID
|
|
161
|
-
appAuth.keyID = boxAppSettings.appAuth.publicKeyID;
|
|
162
|
-
|
|
163
|
-
appAuth.privateKey = boxAppSettings.appAuth.privateKey;
|
|
164
|
-
|
|
165
|
-
var passphrase = boxAppSettings.appAuth.passphrase;
|
|
166
|
-
if (typeof passphrase === 'string') {
|
|
167
|
-
appAuth.passphrase = passphrase;
|
|
168
|
-
}
|
|
169
|
-
params.appAuth = appAuth;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (typeof appConfig.enterpriseID === 'string') {
|
|
173
|
-
params.enterpriseID = appConfig.enterpriseID;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return new BoxSDKNode(params);
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Updates the SDK configuration with new parameters.
|
|
181
|
-
*
|
|
182
|
-
* @param {UserConfigurationOptions} params User settings
|
|
183
|
-
* @returns {void}
|
|
184
|
-
*/
|
|
185
|
-
BoxSDKNode.prototype.configure = function(params) {
|
|
186
|
-
this.config = this.config.extend(params);
|
|
187
|
-
this._setup();
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Returns a Box Client with a Basic API Session. The client is able to make requests on behalf of a user.
|
|
192
|
-
* A basic session has no access to a user's refresh token. Because of this, once the session's tokens
|
|
193
|
-
* expire the client cannot recover and a new session will need to be generated.
|
|
194
|
-
*
|
|
195
|
-
* @param {string} accessToken A user's Box API access token
|
|
196
|
-
* @returns {BoxClient} Returns a new Box Client paired to a new BasicAPISession
|
|
197
|
-
*/
|
|
198
|
-
BoxSDKNode.prototype.getBasicClient = function(accessToken) {
|
|
199
|
-
var apiSession = new BasicAPISession(accessToken, this.tokenManager);
|
|
200
|
-
return new BoxClient(apiSession, this.config, this.requestManager);
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Returns a Box Client with a Basic API Session. The client is able to make requests on behalf of a user.
|
|
205
|
-
* A basic session has no access to a user's refresh token. Because of this, once the session's tokens
|
|
206
|
-
* expire the client cannot recover and a new session will need to be generated.
|
|
207
|
-
*
|
|
208
|
-
* @param {string} accessToken A user's Box API access token
|
|
209
|
-
* @returns {BoxClient} Returns a new Box Client paired to a new BasicAPISession
|
|
210
|
-
*/
|
|
211
|
-
BoxSDKNode.getBasicClient = function(accessToken) {
|
|
212
|
-
return new BoxSDKNode({
|
|
213
|
-
clientID: '',
|
|
214
|
-
clientSecret: ''
|
|
215
|
-
}).getBasicClient(accessToken);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Returns a Box Client with a persistent API session. A persistent API session helps manage the user's tokens,
|
|
220
|
-
* and can refresh them automatically if the access token expires. If a central data-store is given, the session
|
|
221
|
-
* can read & write tokens to it.
|
|
222
|
-
*
|
|
223
|
-
* @NOTE: If tokenInfo or tokenStore are formatted incorrectly, this method will throw an error. If you
|
|
224
|
-
* haven't explicitly created either of these objects or are otherwise not completly confident in their validity,
|
|
225
|
-
* you should wrap your call to getPersistentClient in a try-catch to handle any potential errors.
|
|
226
|
-
*
|
|
227
|
-
* @param {TokenInfo} tokenInfo A tokenInfo object to use for authentication
|
|
228
|
-
* @param {TokenStore} [tokenStore] An optional token store for reading/writing tokens to session
|
|
229
|
-
* @returns {BoxClient} Returns a new Box Client paired to a new PersistentAPISession
|
|
230
|
-
*/
|
|
231
|
-
BoxSDKNode.prototype.getPersistentClient = function(tokenInfo, tokenStore) {
|
|
232
|
-
var apiSession = new PersistentAPISession(tokenInfo, tokenStore, this.config, this.tokenManager);
|
|
233
|
-
return new BoxClient(apiSession, this.config, this.requestManager);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Returns A Box Client with an Anonymous API Session. An Anonymous API Session has access to an anonymous
|
|
238
|
-
* client-credentials token, which isn't tied to any specific user. Because of this, the client will only
|
|
239
|
-
* have access to endpoints that allow client-credential tokens. All Anonymous API Sessions share the
|
|
240
|
-
* same tokens, which allows them to refresh them efficiently and reduce load on both the application and
|
|
241
|
-
* the API.
|
|
242
|
-
*
|
|
243
|
-
* @returns {BoxClient} Returns a new Box Client paired to a AnonymousAPISession
|
|
244
|
-
*/
|
|
245
|
-
BoxSDKNode.prototype.getAnonymousClient = function() {
|
|
246
|
-
return new BoxClient(this.anonymousSession, this.config, this.requestManager);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Create a new client using App Auth for the given entity. This allows either
|
|
251
|
-
* managing App Users (as the enterprise) or performing operations as the App
|
|
252
|
-
* Users themselves (as a user).
|
|
253
|
-
*
|
|
254
|
-
* @param {string} type The type of entity to operate as, "enterprise" or "user"
|
|
255
|
-
* @param {string} id The Box ID of the entity to operate as
|
|
256
|
-
* @param {TokenStore} [tokenStore] (Optional) the token store to use for caching tokens
|
|
257
|
-
* @returns {BoxClient} A new client authorized as the app user or enterprise
|
|
258
|
-
*/
|
|
259
|
-
BoxSDKNode.prototype.getAppAuthClient = function(type, id, tokenStore) {
|
|
260
|
-
if (type === 'enterprise' && !id) {
|
|
261
|
-
if (this.config.enterpriseID) {
|
|
262
|
-
id = this.config.enterpriseID;
|
|
263
|
-
} else {
|
|
264
|
-
throw new Error('Enterprise ID must be passed');
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
var appAuthSession = new AppAuthSession(type, id, this.config, this.tokenManager, tokenStore);
|
|
269
|
-
return new BoxClient(appAuthSession, this.config, this.requestManager);
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Generate the URL for the authorize page to send users to for the first leg of
|
|
274
|
-
* the OAuth2 flow.
|
|
275
|
-
*
|
|
276
|
-
* @param {Object} params The OAuth2 parameters
|
|
277
|
-
* @returns {string} The authorize page URL
|
|
278
|
-
*/
|
|
279
|
-
BoxSDKNode.prototype.getAuthorizeURL = function(params) {
|
|
280
|
-
|
|
281
|
-
params.client_id = this.config.clientID;
|
|
282
|
-
|
|
283
|
-
return `${this.config.authorizeRootURL}/oauth2/authorize?${qs.stringify(params)}`;
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Acquires token info using an authorization code
|
|
288
|
-
*
|
|
289
|
-
* @param {string} authorizationCode - authorization code issued by Box
|
|
290
|
-
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
291
|
-
* @param {Function} [callback] - passed a TokenInfo object if tokens were granted successfully
|
|
292
|
-
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
293
|
-
*/
|
|
294
|
-
BoxSDKNode.prototype.getTokensAuthorizationCodeGrant = function(authorizationCode, options, callback) {
|
|
295
|
-
return this.tokenManager.getTokensAuthorizationCodeGrant(authorizationCode, options)
|
|
296
|
-
.asCallback(callback);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Refreshes the access and refresh tokens for a given refresh token.
|
|
301
|
-
*
|
|
302
|
-
* @param {string} refreshToken - A valid OAuth refresh token
|
|
303
|
-
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
304
|
-
* @param {Function} [callback] - passed a TokenInfo object if tokens were granted successfully
|
|
305
|
-
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
306
|
-
*/
|
|
307
|
-
BoxSDKNode.prototype.getTokensRefreshGrant = function(refreshToken, options, callback) {
|
|
308
|
-
if (typeof options === 'function') {
|
|
309
|
-
callback = options;
|
|
310
|
-
options = null;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return this.tokenManager.getTokensRefreshGrant(refreshToken, options)
|
|
314
|
-
.asCallback(callback);
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Gets tokens for enterprise administration of app users
|
|
319
|
-
* @param {string} enterpriseID The ID of the enterprise to generate a token for
|
|
320
|
-
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
321
|
-
* @param {Function} [callback] Passed the tokens if successful
|
|
322
|
-
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
323
|
-
*/
|
|
324
|
-
BoxSDKNode.prototype.getEnterpriseAppAuthTokens = function(enterpriseID, options, callback) {
|
|
325
|
-
if (typeof options === 'function') {
|
|
326
|
-
callback = options;
|
|
327
|
-
options = null;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (!enterpriseID) {
|
|
331
|
-
if (this.config.enterpriseID) {
|
|
332
|
-
enterpriseID = this.config.enterpriseID;
|
|
333
|
-
} else {
|
|
334
|
-
throw new Error('Enterprise id must be passed');
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
return this.tokenManager.getTokensJWTGrant('enterprise', enterpriseID, options)
|
|
339
|
-
.asCallback(callback);
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Gets tokens for App Users via a JWT grant
|
|
344
|
-
* @param {string} userID The ID of the App User to generate a token for
|
|
345
|
-
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
346
|
-
* @param {Function} [callback] Passed the tokens if successful
|
|
347
|
-
* @returns {Promise<TokentInfo>} Promise reolving to the token infp
|
|
348
|
-
*/
|
|
349
|
-
BoxSDKNode.prototype.getAppUserTokens = function(userID, options, callback) {
|
|
350
|
-
if (typeof options === 'function') {
|
|
351
|
-
callback = options;
|
|
352
|
-
options = null;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return this.tokenManager.getTokensJWTGrant('user', userID, options)
|
|
356
|
-
.asCallback(callback);
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Revokes a token pair associated with a given access or refresh token.
|
|
361
|
-
*
|
|
362
|
-
* @param {string} token - A valid access or refresh token to revoke
|
|
363
|
-
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
364
|
-
* @param {Function} [callback] - If err, revoke failed. Otherwise, revoke succeeded.
|
|
365
|
-
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
366
|
-
*/
|
|
367
|
-
BoxSDKNode.prototype.revokeTokens = function(token, options, callback) {
|
|
368
|
-
if (typeof options === 'function') {
|
|
369
|
-
callback = options;
|
|
370
|
-
options = null;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return this.tokenManager.revokeTokens(token, options)
|
|
374
|
-
.asCallback(callback);
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Expose Webhooks.validateMessage() to the SDK as a whole. This allows
|
|
379
|
-
* the consumer to call BoxSDK.validateWebhookMessage() by just requiring the SDK,
|
|
380
|
-
* instead of needing to create a client (which is not needed to validate messages).
|
|
381
|
-
*/
|
|
382
|
-
BoxSDKNode.validateWebhookMessage = Webhooks.validateMessage;
|
|
383
|
-
|
|
384
|
-
/** @module box-node-sdk/lib/box-node-sdk */
|
|
385
349
|
module.exports = BoxSDKNode;
|
|
350
|
+
//# sourceMappingURL=box-node-sdk.js.map
|