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
|
@@ -1,23 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview A Persistent Box API Session.
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
8
|
// ------------------------------------------------------------------------------
|
|
9
9
|
// Requirements
|
|
10
10
|
// ------------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
var assert_1 = __importDefault(require("assert"));
|
|
12
|
+
var bluebird_1 = require("bluebird");
|
|
13
|
+
var http_status_1 = __importDefault(require("http-status"));
|
|
14
|
+
var errors_1 = __importDefault(require("../util/errors"));
|
|
17
15
|
// ------------------------------------------------------------------------------
|
|
18
16
|
// Private
|
|
19
17
|
// ------------------------------------------------------------------------------
|
|
20
|
-
|
|
21
18
|
/**
|
|
22
19
|
* Validate that an object is a valid TokenInfo object
|
|
23
20
|
*
|
|
@@ -27,13 +24,12 @@ const assert = require('assert'),
|
|
|
27
24
|
* @private
|
|
28
25
|
*/
|
|
29
26
|
function isObjectValidTokenInfo(obj) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
return Boolean(obj &&
|
|
28
|
+
obj.accessToken &&
|
|
29
|
+
obj.refreshToken &&
|
|
30
|
+
obj.accessTokenTTLMS &&
|
|
31
|
+
obj.acquiredAtMS);
|
|
35
32
|
}
|
|
36
|
-
|
|
37
33
|
/**
|
|
38
34
|
* Validate that an object is a valid TokenStore object
|
|
39
35
|
*
|
|
@@ -43,14 +39,11 @@ function isObjectValidTokenInfo(obj) {
|
|
|
43
39
|
* @private
|
|
44
40
|
*/
|
|
45
41
|
function isObjectValidTokenStore(obj) {
|
|
46
|
-
|
|
42
|
+
return Boolean(obj && obj.read && obj.write && obj.clear);
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
44
|
// ------------------------------------------------------------------------------
|
|
51
45
|
// Public
|
|
52
46
|
// ------------------------------------------------------------------------------
|
|
53
|
-
|
|
54
47
|
/**
|
|
55
48
|
* A Persistent API Session has the ability to refresh its access token once it becomes expired.
|
|
56
49
|
* It takes in a full tokenInfo object for authentication. It can detect when its tokens have
|
|
@@ -66,194 +59,181 @@ function isObjectValidTokenStore(obj) {
|
|
|
66
59
|
* @param {TokenManager} tokenManager The token manager
|
|
67
60
|
* @constructor
|
|
68
61
|
*/
|
|
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
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
// If a token store is available, clear the store and throw either error
|
|
247
|
-
// eslint-disable-next-line promise/no-promise-in-callback
|
|
248
|
-
return this._tokenStore.clearAsync()
|
|
249
|
-
.catch(e => errors.unwrapAndThrow(e))
|
|
250
|
-
.then(() => {
|
|
251
|
-
throw err;
|
|
252
|
-
});
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* @module box-node-sdk/lib/sessions/persistent-session
|
|
257
|
-
* @see {@Link PersistentSession}
|
|
258
|
-
*/
|
|
62
|
+
var PersistentSession = /** @class */ (function () {
|
|
63
|
+
function PersistentSession(tokenInfo, tokenStore, config, tokenManager) {
|
|
64
|
+
this._config = config;
|
|
65
|
+
this._tokenManager = tokenManager;
|
|
66
|
+
// Keeps track of if tokens are currently being refreshed
|
|
67
|
+
this._refreshPromise = null;
|
|
68
|
+
// Set valid PersistentSession credentials. Throw if expected credentials are invalid or not given.
|
|
69
|
+
assert_1.default(isObjectValidTokenInfo(tokenInfo), 'tokenInfo is improperly formatted. Properties required: accessToken, refreshToken, accessTokenTTLMS and acquiredAtMS.');
|
|
70
|
+
this._setTokenInfo(tokenInfo);
|
|
71
|
+
// If tokenStore was provided, set the persistent data & current store operations
|
|
72
|
+
if (tokenStore) {
|
|
73
|
+
assert_1.default(isObjectValidTokenStore(tokenStore), 'Token store provided but is improperly formatted. Methods required: read(), write(), clear().');
|
|
74
|
+
this._tokenStore = bluebird_1.Promise.promisifyAll(tokenStore);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Sets all relevant token info for this client.
|
|
79
|
+
*
|
|
80
|
+
* @param {TokenInfo} tokenInfo A valid TokenInfo object.
|
|
81
|
+
* @returns {void}
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
PersistentSession.prototype._setTokenInfo = function (tokenInfo) {
|
|
85
|
+
this._tokenInfo = {
|
|
86
|
+
accessToken: tokenInfo.accessToken,
|
|
87
|
+
refreshToken: tokenInfo.refreshToken,
|
|
88
|
+
accessTokenTTLMS: tokenInfo.accessTokenTTLMS,
|
|
89
|
+
acquiredAtMS: tokenInfo.acquiredAtMS,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Attempts to refresh tokens for the client.
|
|
94
|
+
* Will use the Box refresh token grant to complete the refresh. On refresh failure, we'll
|
|
95
|
+
* check the token store for more recently updated tokens and load them if found. Otherwise
|
|
96
|
+
* an error will be propagated.
|
|
97
|
+
*
|
|
98
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
99
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
PersistentSession.prototype._refreshTokens = function (options) {
|
|
103
|
+
var _this = this;
|
|
104
|
+
// If not already refreshing, kick off a token refresh request and set a lock so that additional
|
|
105
|
+
// client requests don't try as well
|
|
106
|
+
if (!this._refreshPromise) {
|
|
107
|
+
this._refreshPromise = this._tokenManager
|
|
108
|
+
.getTokensRefreshGrant(this._tokenInfo.refreshToken, options)
|
|
109
|
+
.catch(function (err) {
|
|
110
|
+
// If we got an error response from Box API, but it was 400 invalid_grant, it indicates we may have just
|
|
111
|
+
// made the request with an invalidated refresh token. Since only a max of 2 refresh tokens can be valid
|
|
112
|
+
// at any point in time, and a horizontally scaled app could have multiple Node instances running in parallel,
|
|
113
|
+
// it is possible to hit cases where too many servers all refresh a user's tokens at once
|
|
114
|
+
// and cause this server's token to become invalidated. However, the user should still be alive, but
|
|
115
|
+
// we'll need to check the central data store for the latest valid tokens that some other server in the app
|
|
116
|
+
// cluster would have received. So, instead pull tokens from the central store and attempt to use them.
|
|
117
|
+
if (err.statusCode === http_status_1.default.BAD_REQUEST &&
|
|
118
|
+
_this._tokenStore) {
|
|
119
|
+
var invalidGrantError = err;
|
|
120
|
+
// Check the tokenStore to see if tokens have been updated recently. If they have, then another
|
|
121
|
+
// instance of the session may have already refreshed the user tokens, which would explain why
|
|
122
|
+
// we couldn't refresh.
|
|
123
|
+
return _this._tokenStore
|
|
124
|
+
.readAsync()
|
|
125
|
+
.catch(function (e) { return errors_1.default.unwrapAndThrow(e); })
|
|
126
|
+
.then(function (storeTokenInfo) {
|
|
127
|
+
// if the tokens we got from the central store are the same as the tokens we made the failed request with
|
|
128
|
+
// already, then we can be sure that no other servers have valid tokens for this server either.
|
|
129
|
+
// Thus, this user truly has an expired refresh token. So, propagate an "Expired Tokens" error.
|
|
130
|
+
if (!storeTokenInfo ||
|
|
131
|
+
storeTokenInfo.refreshToken === _this._tokenInfo.refreshToken) {
|
|
132
|
+
throw errors_1.default.buildAuthError(invalidGrantError.response);
|
|
133
|
+
}
|
|
134
|
+
// Propagate the fresh tokens that we found in the session
|
|
135
|
+
return storeTokenInfo;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Box API returned a permanent error that is not retryable and we can't recover.
|
|
139
|
+
// We have no usable tokens for the user and no way to refresh them - propagate a permanent error.
|
|
140
|
+
throw err;
|
|
141
|
+
})
|
|
142
|
+
.then(function (tokenInfo) {
|
|
143
|
+
// Success! We got back a TokenInfo object from the API.
|
|
144
|
+
// If we have a token store, we'll write it there now before finishing up the request.
|
|
145
|
+
if (_this._tokenStore) {
|
|
146
|
+
return _this._tokenStore
|
|
147
|
+
.writeAsync(tokenInfo)
|
|
148
|
+
.catch(function (e) { return errors_1.default.unwrapAndThrow(e); })
|
|
149
|
+
.then(function () { return tokenInfo; });
|
|
150
|
+
}
|
|
151
|
+
// If no token store, Set and propagate the access token immediately
|
|
152
|
+
return tokenInfo;
|
|
153
|
+
})
|
|
154
|
+
.then(function (tokenInfo) {
|
|
155
|
+
// Set and propagate the new access token
|
|
156
|
+
_this._setTokenInfo(tokenInfo);
|
|
157
|
+
return tokenInfo.accessToken;
|
|
158
|
+
})
|
|
159
|
+
.catch(function (err) { return _this.handleExpiredTokensError(err); })
|
|
160
|
+
.finally(function () {
|
|
161
|
+
// Refresh complete, clear promise
|
|
162
|
+
_this._refreshPromise = null;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return this._refreshPromise;
|
|
166
|
+
};
|
|
167
|
+
// ------------------------------------------------------------------------------
|
|
168
|
+
// Public Instance
|
|
169
|
+
// ------------------------------------------------------------------------------
|
|
170
|
+
/**
|
|
171
|
+
* Returns the clients access token.
|
|
172
|
+
*
|
|
173
|
+
* If tokens don't yet exist, first attempt to retrieve them.
|
|
174
|
+
* If tokens are expired, first attempt to refresh them.
|
|
175
|
+
*
|
|
176
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
177
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
178
|
+
*/
|
|
179
|
+
PersistentSession.prototype.getAccessToken = function (options) {
|
|
180
|
+
// If our tokens are not fresh, we need to refresh them
|
|
181
|
+
var expirationBuffer = Math.max(this._config.expiredBufferMS, this._config.staleBufferMS);
|
|
182
|
+
if (!this._tokenManager.isAccessTokenValid(this._tokenInfo, expirationBuffer)) {
|
|
183
|
+
return this._refreshTokens(options);
|
|
184
|
+
}
|
|
185
|
+
// Current access token is still valid. Return it.
|
|
186
|
+
return bluebird_1.Promise.resolve(this._tokenInfo.accessToken);
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Revokes the session's tokens. If the session has a refresh token we'll use that,
|
|
190
|
+
* since it is more likely to be up to date. Otherwise, we'll revoke the accessToken.
|
|
191
|
+
* Revoking either one will disable the other as well.
|
|
192
|
+
*
|
|
193
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
194
|
+
* @returns {Promise} Promise that resolves when the revoke succeeds
|
|
195
|
+
*/
|
|
196
|
+
PersistentSession.prototype.revokeTokens = function (options) {
|
|
197
|
+
return this._tokenManager.revokeTokens(this._tokenInfo.refreshToken, options);
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Exchange the client access token for one with lower scope
|
|
201
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
202
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
203
|
+
* @param {Object} [options] - Optional parameters
|
|
204
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
205
|
+
* @returns {void}
|
|
206
|
+
*/
|
|
207
|
+
PersistentSession.prototype.exchangeToken = function (scopes, resource, options) {
|
|
208
|
+
var _this = this;
|
|
209
|
+
return this.getAccessToken(options).then(function (accessToken) {
|
|
210
|
+
return _this._tokenManager.exchangeToken(accessToken, scopes, resource, options);
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Handle an an "Expired Tokens" Error. If our tokens are expired, we need to clear the token
|
|
215
|
+
* store (if present) before continuing.
|
|
216
|
+
*
|
|
217
|
+
* @param {Errors~ExpiredTokensError} err An "expired tokens" error including information
|
|
218
|
+
* about the request/response.
|
|
219
|
+
* @returns {Promise<Error>} Promise resolving to an error. This will
|
|
220
|
+
* usually be the original response error, but could an error from trying to access the
|
|
221
|
+
* token store as well.
|
|
222
|
+
*/
|
|
223
|
+
PersistentSession.prototype.handleExpiredTokensError = function (err /* FIXME */) {
|
|
224
|
+
if (!this._tokenStore) {
|
|
225
|
+
return bluebird_1.Promise.resolve(err);
|
|
226
|
+
}
|
|
227
|
+
// If a token store is available, clear the store and throw either error
|
|
228
|
+
// eslint-disable-next-line promise/no-promise-in-callback
|
|
229
|
+
return this._tokenStore
|
|
230
|
+
.clearAsync()
|
|
231
|
+
.catch(function (e) { return errors_1.default.unwrapAndThrow(e); })
|
|
232
|
+
.then(function () {
|
|
233
|
+
throw err;
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
return PersistentSession;
|
|
237
|
+
}());
|
|
259
238
|
module.exports = PersistentSession;
|
|
239
|
+
//# sourceMappingURL=persistent-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistent-session.js","sourceRoot":"","sources":["../../src/sessions/persistent-session.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,iFAAiF;AACjF,eAAe;AACf,iFAAiF;AAEjF,kDAA4B;AAC5B,qCAAmC;AACnC,4DAA0C;AAC1C,0DAAoC;AAYpC,iFAAiF;AACjF,UAAU;AACV,iF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