box-node-sdk 1.36.0 → 1.38.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/CHANGELOG.md +45 -3
- package/README.md +3 -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 +137 -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 +179 -0
- package/lib/managers/events.js +232 -254
- package/lib/managers/events.js.map +1 -0
- package/lib/managers/files.d.ts +773 -0
- package/lib/managers/files.js +1401 -1602
- package/lib/managers/files.js.map +1 -0
- package/lib/managers/folders.d.ts +347 -0
- package/lib/managers/folders.js +551 -630
- package/lib/managers/folders.js.map +1 -0
- package/lib/managers/groups.d.ts +202 -0
- package/lib/managers/groups.js +238 -288
- 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 +251 -0
- package/lib/managers/retention-policies.js +278 -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 +130 -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 +146 -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 +14 -3
|
@@ -1,21 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview App Auth Box API Session.
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
7
8
|
// ------------------------------------------------------------------------------
|
|
8
9
|
// Requirements
|
|
9
10
|
// ------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const errors = require('../util/errors');
|
|
14
|
-
|
|
11
|
+
var assert_1 = __importDefault(require("assert"));
|
|
12
|
+
var bluebird_1 = require("bluebird");
|
|
13
|
+
var errors_1 = __importDefault(require("../util/errors"));
|
|
15
14
|
// ------------------------------------------------------------------------------
|
|
16
15
|
// Private
|
|
17
16
|
// ------------------------------------------------------------------------------
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
18
|
* Validate that an object is a valid TokenStore object
|
|
21
19
|
*
|
|
@@ -25,13 +23,11 @@ const errors = require('../util/errors');
|
|
|
25
23
|
* @private
|
|
26
24
|
*/
|
|
27
25
|
function isObjectValidTokenStore(obj) {
|
|
28
|
-
|
|
26
|
+
return Boolean(obj && obj.read && obj.write && obj.clear);
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
// ------------------------------------------------------------------------------
|
|
32
29
|
// Public
|
|
33
30
|
// ------------------------------------------------------------------------------
|
|
34
|
-
|
|
35
31
|
/**
|
|
36
32
|
* App Auth Box API Session.
|
|
37
33
|
*
|
|
@@ -51,152 +47,136 @@ function isObjectValidTokenStore(obj) {
|
|
|
51
47
|
* @param {TokenStore} [tokenStore] The token store instance to use for caching token info
|
|
52
48
|
* @constructor
|
|
53
49
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
AppAuthSession
|
|
184
|
-
|
|
185
|
-
if (!this._tokenStore) {
|
|
186
|
-
return Promise.resolve(err);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// If a token store is available, clear the store and throw either error
|
|
190
|
-
// eslint-disable-next-line promise/no-promise-in-callback
|
|
191
|
-
return this._tokenStore.clearAsync()
|
|
192
|
-
.catch(e => errors.unwrapAndThrow(e))
|
|
193
|
-
.then(() => {
|
|
194
|
-
throw err;
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* @module box-node-sdk/lib/sessions/app-auth-session
|
|
200
|
-
* @see {@Link AppAuthSession}
|
|
201
|
-
*/
|
|
50
|
+
var AppAuthSession = /** @class */ (function () {
|
|
51
|
+
function AppAuthSession(type, id, config, tokenManager, tokenStore) {
|
|
52
|
+
this._type = type;
|
|
53
|
+
this._id = id;
|
|
54
|
+
this._config = config;
|
|
55
|
+
this._tokenManager = tokenManager;
|
|
56
|
+
// If tokenStore was provided, set the persistent data & current store operations
|
|
57
|
+
if (tokenStore) {
|
|
58
|
+
assert_1.default(isObjectValidTokenStore(tokenStore), 'Token store provided is improperly formatted. Methods required: read(), write(), clear().');
|
|
59
|
+
this._tokenStore = bluebird_1.Promise.promisifyAll(tokenStore);
|
|
60
|
+
}
|
|
61
|
+
// The TokenInfo object for this app auth session
|
|
62
|
+
this._tokenInfo = null;
|
|
63
|
+
// Indicates if tokens are currently being refreshed
|
|
64
|
+
this._refreshPromise = null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Initiate a refresh of the app auth access tokens. New tokens should be passed
|
|
68
|
+
* to the caller, and then cached for later use.
|
|
69
|
+
*
|
|
70
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
71
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
AppAuthSession.prototype._refreshAppAuthAccessToken = function (options) {
|
|
75
|
+
var _this = this;
|
|
76
|
+
// If tokens aren't already being refreshed, start the refresh
|
|
77
|
+
if (!this._refreshPromise) {
|
|
78
|
+
this._refreshPromise = this._tokenManager
|
|
79
|
+
.getTokensJWTGrant(this._type, this._id, options)
|
|
80
|
+
.then(function (tokenInfo) {
|
|
81
|
+
// Set new token info and propagate the new access token
|
|
82
|
+
_this._tokenInfo = tokenInfo;
|
|
83
|
+
if (_this._tokenStore) {
|
|
84
|
+
return _this._tokenStore
|
|
85
|
+
.writeAsync(tokenInfo)
|
|
86
|
+
.then(function () { return tokenInfo.accessToken; });
|
|
87
|
+
}
|
|
88
|
+
return tokenInfo.accessToken;
|
|
89
|
+
})
|
|
90
|
+
.finally(function () {
|
|
91
|
+
// Refresh complete, clear promise
|
|
92
|
+
_this._refreshPromise = null;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return this._refreshPromise;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Produces a valid, app auth access token.
|
|
99
|
+
* Performs a refresh before returning if the current token is expired. If the current
|
|
100
|
+
* token is considered stale but still valid, return the current token but initiate a
|
|
101
|
+
* new refresh in the background.
|
|
102
|
+
*
|
|
103
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
104
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
105
|
+
*/
|
|
106
|
+
AppAuthSession.prototype.getAccessToken = function (options) {
|
|
107
|
+
var _this = this;
|
|
108
|
+
var expirationBuffer = Math.max(this._config.expiredBufferMS, this._config.staleBufferMS);
|
|
109
|
+
// If we're initializing the client and have a token store, try reading from it
|
|
110
|
+
if (!this._tokenInfo && this._tokenStore) {
|
|
111
|
+
return this._tokenStore.readAsync().then(function (tokenInfo) {
|
|
112
|
+
if (!_this._tokenManager.isAccessTokenValid(tokenInfo, expirationBuffer)) {
|
|
113
|
+
// Token store contains expired tokens, refresh
|
|
114
|
+
return _this._refreshAppAuthAccessToken(options);
|
|
115
|
+
}
|
|
116
|
+
_this._tokenInfo = tokenInfo;
|
|
117
|
+
return tokenInfo.accessToken;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// If the current token is not fresh, get a new token. All incoming
|
|
121
|
+
// requests will be held until a fresh token is retrieved.
|
|
122
|
+
if (!this._tokenInfo ||
|
|
123
|
+
!this._tokenManager.isAccessTokenValid(this._tokenInfo, expirationBuffer)) {
|
|
124
|
+
return this._refreshAppAuthAccessToken(options);
|
|
125
|
+
}
|
|
126
|
+
// Your token is not currently stale! Return the current access token.
|
|
127
|
+
return bluebird_1.Promise.resolve(this._tokenInfo.accessToken);
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Revokes the app auth token used by this session, and clears the saved tokenInfo.
|
|
131
|
+
*
|
|
132
|
+
* @param {TokenRequestOptions} [options]- Sets optional behavior for the token grant
|
|
133
|
+
* @returns {Promise} Promise resolving if the revoke succeeds
|
|
134
|
+
*/
|
|
135
|
+
AppAuthSession.prototype.revokeTokens = function (options) {
|
|
136
|
+
// The current app auth token is revoked (but a new one will be created automatically as needed).
|
|
137
|
+
var tokenInfo = this._tokenInfo || {}, accessToken = tokenInfo.accessToken;
|
|
138
|
+
this._tokenInfo = null;
|
|
139
|
+
return this._tokenManager.revokeTokens(accessToken, options);
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Exchange the client access token for one with lower scope
|
|
143
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
144
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
145
|
+
* @param {Object} [options] - Optional parameters
|
|
146
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
147
|
+
* @param {ActorParams} [options.actor] - Optional actor parameters for creating annotator tokens
|
|
148
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the new token info
|
|
149
|
+
*/
|
|
150
|
+
AppAuthSession.prototype.exchangeToken = function (scopes, resource, options) {
|
|
151
|
+
var _this = this;
|
|
152
|
+
return this.getAccessToken(options).then(function (accessToken) {
|
|
153
|
+
return _this._tokenManager.exchangeToken(accessToken, scopes, resource, options);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Handle an an "Expired Tokens" Error. If our tokens are expired, we need to clear the token
|
|
158
|
+
* store (if present) before continuing.
|
|
159
|
+
*
|
|
160
|
+
* @param {Errors~ExpiredTokensError} err An "expired tokens" error including information
|
|
161
|
+
* about the request/response.
|
|
162
|
+
* @returns {Promise<Error>} Promise resolving to an error. This will
|
|
163
|
+
* usually be the original response error, but could an error from trying to access the
|
|
164
|
+
* token store as well.
|
|
165
|
+
*/
|
|
166
|
+
AppAuthSession.prototype.handleExpiredTokensError = function (err /* FIXME */) {
|
|
167
|
+
if (!this._tokenStore) {
|
|
168
|
+
return bluebird_1.Promise.resolve(err);
|
|
169
|
+
}
|
|
170
|
+
// If a token store is available, clear the store and throw either error
|
|
171
|
+
// eslint-disable-next-line promise/no-promise-in-callback
|
|
172
|
+
return this._tokenStore
|
|
173
|
+
.clearAsync()
|
|
174
|
+
.catch(function (e) { return errors_1.default.unwrapAndThrow(e); })
|
|
175
|
+
.then(function () {
|
|
176
|
+
throw err;
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
return AppAuthSession;
|
|
180
|
+
}());
|
|
202
181
|
module.exports = AppAuthSession;
|
|
182
|
+
//# sourceMappingURL=app-auth-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-auth-session.js","sourceRoot":"","sources":["../../src/sessions/app-auth-session.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,iFAAiF;AACjF,eAAe;AACf,iFAAiF;AAEjF,kDAA4B;AAC5B,qCAAmC;AACnC,0DAAoC;AAYpC,iFAAiF;AACjF,UAAU;AACV,iFAAiF;AAEjF;;;;;;;GAOG;AACH,SAAS,uBAAuB,CAAC,GAAwB;IACxD,OAAO,OAAO,CAAC,GAAG,IAAI,GAAG,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,OAA4B;QACxC,iGAAiG;QACjG,IAAI,SAAS,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,EACpC,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;;;;OAQG;IACH,sCAAa,GAAb,UACC,MAAyB,EACzB,QAAiB,EACjB,OAGC;QANF,iBAWC;QAHA,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAC,WAAmB;YAC5D,OAAA,KAAI,CAAC,aAAa,CAAC,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC;QAAxE,CAAwE,CACxE,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,iDAAwB,GAAxB,UAAyB,GAAQ,CAAC,WAAW;QAC5C,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACtB,OAAO,kBAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SAC5B;QAED,wEAAwE;QACxE,0DAA0D;QAC1D,OAAO,IAAI,CAAC,WAAW;aACrB,UAAU,EAAE;aACZ,KAAK,CAAC,UAAC,CAAM,IAAK,OAAA,gBAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAxB,CAAwB,CAAC;aAC3C,IAAI,CAAC;YACL,MAAM,GAAG,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC;IACF,qBAAC;AAAD,CAAC,AA9KD,IA8KC;AAMD,iBAAS,cAAc,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A Basic Box API Session.
|
|
3
|
+
*/
|
|
4
|
+
/// <reference types="bluebird" />
|
|
5
|
+
declare type TokenManager = any;
|
|
6
|
+
declare type TokenRequestOptions = Record<string, any>;
|
|
7
|
+
/**
|
|
8
|
+
* A BasicSession holds only a single accessToken. It has no idea how to authenticate,
|
|
9
|
+
* refresh, or persist its token information. When that token expires, the session
|
|
10
|
+
* and any clients using it will become useless.
|
|
11
|
+
*
|
|
12
|
+
* Basic API Session is the most simple API Session to use, which makes it a good choice
|
|
13
|
+
* for simple applications, developers who are just getting started, and applications
|
|
14
|
+
* that wish to manage tokens themselves.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} accessToken The existing access token for a user
|
|
17
|
+
* @param {TokenManager} tokenManager The token manager
|
|
18
|
+
* @constructor
|
|
19
|
+
*/
|
|
20
|
+
declare class BasicSession {
|
|
21
|
+
_accessToken: string;
|
|
22
|
+
_tokenManager: TokenManager;
|
|
23
|
+
constructor(accessToken: string, tokenManager: TokenManager);
|
|
24
|
+
/**
|
|
25
|
+
* Returns the clients access token. BasicSession never returns an error, since it doesn't
|
|
26
|
+
* know the status of its own token.
|
|
27
|
+
*
|
|
28
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
29
|
+
*/
|
|
30
|
+
getAccessToken(): import("bluebird")<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Revokes the session's access token.
|
|
33
|
+
*
|
|
34
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
35
|
+
* @returns {Promise} Promise resolving if the revoke succeeds
|
|
36
|
+
*/
|
|
37
|
+
revokeTokens(options?: TokenRequestOptions): any;
|
|
38
|
+
/**
|
|
39
|
+
* Exchange the client access token for one with lower scope
|
|
40
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
41
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
42
|
+
* @param {Object} [options] - Optional parameters
|
|
43
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
44
|
+
* @param {ActorParams} [options.actor] - Optional actor parameters for creating annotator tokens
|
|
45
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the new token info
|
|
46
|
+
*/
|
|
47
|
+
exchangeToken(scopes: string | string[], resource?: string, options?: {
|
|
48
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
49
|
+
actor?: any;
|
|
50
|
+
}): any;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @module box-node-sdk/lib/sessions/basic-session
|
|
54
|
+
* @see {@Link BasicSession}
|
|
55
|
+
*/
|
|
56
|
+
export = BasicSession;
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview A Basic Box API Session.
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
|
|
8
5
|
// ------------------------------------------------------------------------------
|
|
9
6
|
// Requirements
|
|
10
7
|
// ------------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
const Promise = require('bluebird');
|
|
13
|
-
|
|
8
|
+
var bluebird_1 = require("bluebird");
|
|
14
9
|
// ------------------------------------------------------------------------------
|
|
15
10
|
// Public
|
|
16
11
|
// ------------------------------------------------------------------------------
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* A BasicSession holds only a single accessToken. It has no idea how to authenticate,
|
|
20
14
|
* refresh, or persist its token information. When that token expires, the session
|
|
@@ -28,46 +22,42 @@ const Promise = require('bluebird');
|
|
|
28
22
|
* @param {TokenManager} tokenManager The token manager
|
|
29
23
|
* @constructor
|
|
30
24
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
BasicSession.prototype.getAccessToken = function() {
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @module box-node-sdk/lib/sessions/basic-session
|
|
71
|
-
* @see {@Link BasicSession}
|
|
72
|
-
*/
|
|
25
|
+
var BasicSession = /** @class */ (function () {
|
|
26
|
+
function BasicSession(accessToken, tokenManager) {
|
|
27
|
+
this._accessToken = accessToken;
|
|
28
|
+
this._tokenManager = tokenManager;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns the clients access token. BasicSession never returns an error, since it doesn't
|
|
32
|
+
* know the status of its own token.
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
35
|
+
*/
|
|
36
|
+
BasicSession.prototype.getAccessToken = function () {
|
|
37
|
+
return bluebird_1.Promise.resolve(this._accessToken);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Revokes the session's access token.
|
|
41
|
+
*
|
|
42
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
43
|
+
* @returns {Promise} Promise resolving if the revoke succeeds
|
|
44
|
+
*/
|
|
45
|
+
BasicSession.prototype.revokeTokens = function (options) {
|
|
46
|
+
return this._tokenManager.revokeTokens(this._accessToken, options);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Exchange the client access token for one with lower scope
|
|
50
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
51
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
52
|
+
* @param {Object} [options] - Optional parameters
|
|
53
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
54
|
+
* @param {ActorParams} [options.actor] - Optional actor parameters for creating annotator tokens
|
|
55
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the new token info
|
|
56
|
+
*/
|
|
57
|
+
BasicSession.prototype.exchangeToken = function (scopes, resource, options) {
|
|
58
|
+
return this._tokenManager.exchangeToken(this._accessToken, scopes, resource, options);
|
|
59
|
+
};
|
|
60
|
+
return BasicSession;
|
|
61
|
+
}());
|
|
73
62
|
module.exports = BasicSession;
|
|
63
|
+
//# sourceMappingURL=basic-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-session.js","sourceRoot":"","sources":["../../src/sessions/basic-session.ts"],"names":[],"mappings":";AAAA;;GAEG;AAEH,iFAAiF;AACjF,eAAe;AACf,iFAAiF;AAEjF,qCAAmC;AASnC,iFAAiF;AACjF,SAAS;AACT,iFAAiF;AAEjF;;;;;;;;;;;;GAYG;AAEH;IAIC,sBAAY,WAAmB,EAAE,YAA0B;QAC1D,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,qCAAc,GAAd;QACC,OAAO,kBAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACH,mCAAY,GAAZ,UAAa,OAA6B;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;;OAQG;IACH,oCAAa,GAAb,UACC,MAAyB,EACzB,QAAiB,EACjB,OAGC;QAED,OAAO,IAAI,CAAC,aAAa,CAAC,aAAa,CACtC,IAAI,CAAC,YAAY,EACjB,MAAM,EACN,QAAQ,EACR,OAAO,CACP,CAAC;IACH,CAAC;IACF,mBAAC;AAAD,CAAC,AArDD,IAqDC;AAMD,iBAAS,YAAY,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A Persistent Box API Session.
|
|
3
|
+
*/
|
|
4
|
+
declare type TokenInfo = any;
|
|
5
|
+
declare type TokenStore = any;
|
|
6
|
+
declare type Config = any;
|
|
7
|
+
declare type TokenManager = any;
|
|
8
|
+
declare type TokenRequestOptions = Record<string, any>;
|
|
9
|
+
/**
|
|
10
|
+
* A Persistent API Session has the ability to refresh its access token once it becomes expired.
|
|
11
|
+
* It takes in a full tokenInfo object for authentication. It can detect when its tokens have
|
|
12
|
+
* expired and will request new, valid tokens if needed. It can also interface with a token
|
|
13
|
+
* data-store if one is provided.
|
|
14
|
+
*
|
|
15
|
+
* Persistent API Session a good choice for long-running applications or web servers that
|
|
16
|
+
* must remember users across sessions.
|
|
17
|
+
*
|
|
18
|
+
* @param {TokenInfo} tokenInfo A valid TokenInfo object. Will throw if improperly formatted.
|
|
19
|
+
* @param {TokenStore} [tokenStore] A valid TokenStore object. Will throw if improperly formatted.
|
|
20
|
+
* @param {Config} config The SDK configuration options
|
|
21
|
+
* @param {TokenManager} tokenManager The token manager
|
|
22
|
+
* @constructor
|
|
23
|
+
*/
|
|
24
|
+
declare class PersistentSession {
|
|
25
|
+
_config: Config;
|
|
26
|
+
_refreshPromise: Promise<any> | null;
|
|
27
|
+
_tokenManager: TokenManager;
|
|
28
|
+
_tokenStore: TokenStore;
|
|
29
|
+
_tokenInfo: TokenInfo;
|
|
30
|
+
constructor(tokenInfo: TokenInfo, tokenStore: TokenStore, config: Config, tokenManager: TokenManager);
|
|
31
|
+
/**
|
|
32
|
+
* Sets all relevant token info for this client.
|
|
33
|
+
*
|
|
34
|
+
* @param {TokenInfo} tokenInfo A valid TokenInfo object.
|
|
35
|
+
* @returns {void}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
_setTokenInfo(tokenInfo: TokenStore): void;
|
|
39
|
+
/**
|
|
40
|
+
* Attempts to refresh tokens for the client.
|
|
41
|
+
* Will use the Box refresh token grant to complete the refresh. On refresh failure, we'll
|
|
42
|
+
* check the token store for more recently updated tokens and load them if found. Otherwise
|
|
43
|
+
* an error will be propagated.
|
|
44
|
+
*
|
|
45
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
46
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
_refreshTokens(options?: TokenRequestOptions): Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the clients access token.
|
|
52
|
+
*
|
|
53
|
+
* If tokens don't yet exist, first attempt to retrieve them.
|
|
54
|
+
* If tokens are expired, first attempt to refresh them.
|
|
55
|
+
*
|
|
56
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
57
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
58
|
+
*/
|
|
59
|
+
getAccessToken(options?: TokenRequestOptions): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Revokes the session's tokens. If the session has a refresh token we'll use that,
|
|
62
|
+
* since it is more likely to be up to date. Otherwise, we'll revoke the accessToken.
|
|
63
|
+
* Revoking either one will disable the other as well.
|
|
64
|
+
*
|
|
65
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
66
|
+
* @returns {Promise} Promise that resolves when the revoke succeeds
|
|
67
|
+
*/
|
|
68
|
+
revokeTokens(options?: TokenRequestOptions): any;
|
|
69
|
+
/**
|
|
70
|
+
* Exchange the client access token for one with lower scope
|
|
71
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
72
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
73
|
+
* @param {Object} [options] - Optional parameters
|
|
74
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
75
|
+
* @returns {void}
|
|
76
|
+
*/
|
|
77
|
+
exchangeToken(scopes: string | string[], resource?: string, options?: {
|
|
78
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
79
|
+
}): Promise<any>;
|
|
80
|
+
/**
|
|
81
|
+
* Handle an an "Expired Tokens" Error. If our tokens are expired, we need to clear the token
|
|
82
|
+
* store (if present) before continuing.
|
|
83
|
+
*
|
|
84
|
+
* @param {Errors~ExpiredTokensError} err An "expired tokens" error including information
|
|
85
|
+
* about the request/response.
|
|
86
|
+
* @returns {Promise<Error>} Promise resolving to an error. This will
|
|
87
|
+
* usually be the original response error, but could an error from trying to access the
|
|
88
|
+
* token store as well.
|
|
89
|
+
*/
|
|
90
|
+
handleExpiredTokensError(err: any): any;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @module box-node-sdk/lib/sessions/persistent-session
|
|
94
|
+
* @see {@Link PersistentSession}
|
|
95
|
+
*/
|
|
96
|
+
export = PersistentSession;
|