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/util/errors.js
CHANGED
|
@@ -1,174 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview Errors Helper
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
var qs = __importStar(require("querystring"));
|
|
7
25
|
// ------------------------------------------------------------------------------
|
|
8
26
|
// Requirements
|
|
9
27
|
// ------------------------------------------------------------------------------
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const TRACE_ID_HEADER_NAME = 'box-request-id';
|
|
14
|
-
|
|
28
|
+
var httpStatusCodes = require('http-status');
|
|
29
|
+
var TRACE_ID_HEADER_NAME = 'box-request-id';
|
|
15
30
|
// ------------------------------------------------------------------------------
|
|
16
31
|
// Typedefs and Callbacks
|
|
17
32
|
// ------------------------------------------------------------------------------
|
|
18
|
-
|
|
19
33
|
/**
|
|
20
34
|
* An generic error propagated when the response has caused an error.
|
|
21
35
|
* @typedef {Error} Errors~ResponseError
|
|
22
36
|
* @property {APIRequest~ResponseObject} response The response object that generated the error
|
|
23
37
|
* @property {int} statusCode A shortcut to the status code of the response
|
|
24
38
|
*/
|
|
25
|
-
|
|
26
39
|
/**
|
|
27
40
|
* Error propagated whenever the SDK is unable to successfully complete an action
|
|
28
41
|
* due to an expired access token (and refresh token, if one was provided).
|
|
29
42
|
* @typedef {Errors~ResponseError} Errors~AuthError
|
|
30
43
|
* @property {boolean} authExpired - always true
|
|
31
44
|
*/
|
|
32
|
-
|
|
33
45
|
/**
|
|
34
46
|
* Request structure for error objects
|
|
35
47
|
* @param {Object} req The request object
|
|
36
48
|
* @constructor
|
|
37
49
|
* @private
|
|
38
50
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* A Helper for building errors across the SDK. Makes sure that easily-forgotten
|
|
63
|
-
* fields aren't missed, and that everything is formatted properly to return to the
|
|
64
|
-
* consumer.
|
|
65
|
-
*
|
|
66
|
-
* @name Errors
|
|
67
|
-
* @module box-node-sdk/lib/util/errors
|
|
68
|
-
*/
|
|
51
|
+
var Request = /** @class */ (function () {
|
|
52
|
+
function Request(req /* FIXME */) {
|
|
53
|
+
this.method = req.method;
|
|
54
|
+
if (req.uri) {
|
|
55
|
+
this.url = {
|
|
56
|
+
protocol: req.uri.protocol,
|
|
57
|
+
host: req.uri.host,
|
|
58
|
+
path: req.uri.pathname,
|
|
59
|
+
query: qs.parse(req.uri.query),
|
|
60
|
+
fragment: req.uri.hash,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.url = null;
|
|
65
|
+
}
|
|
66
|
+
this.httpVersion = req.response ? req.response.httpVersion : null;
|
|
67
|
+
this.headers = req.headers;
|
|
68
|
+
this.body = req.body;
|
|
69
|
+
}
|
|
70
|
+
return Request;
|
|
71
|
+
}());
|
|
69
72
|
module.exports = {
|
|
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
|
-
* is not a Bluebird error. This is necessary to preserve errors when
|
|
160
|
-
* a function is promisified.
|
|
161
|
-
* @param {Error} error The error to unwrap
|
|
162
|
-
* @returns {void}
|
|
163
|
-
* @throws {Error} The unwrapped error
|
|
164
|
-
*/
|
|
165
|
-
unwrapAndThrow(error) {
|
|
166
|
-
|
|
167
|
-
if (error.cause) {
|
|
168
|
-
throw error.cause;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Build a response error with the given message, and attaching meta data from the
|
|
75
|
+
* response data.
|
|
76
|
+
*
|
|
77
|
+
* @param {?APIRequest~ResponseObject} response - The response returned by an APIRequestManager request
|
|
78
|
+
* @param {string} message - the response error message
|
|
79
|
+
* @returns {Errors~ResponseError} an error describing the response error
|
|
80
|
+
*/
|
|
81
|
+
buildResponseError: function (response /* FIXME */, message) {
|
|
82
|
+
response = response || {};
|
|
83
|
+
message = message || 'API Response Error';
|
|
84
|
+
var statusCode = response.statusCode;
|
|
85
|
+
var statusMessage = httpStatusCodes[statusCode];
|
|
86
|
+
var debugID = ''; // Of the form <requestID>.<traceID>, both parts optional
|
|
87
|
+
var errorCode;
|
|
88
|
+
var errorDescription;
|
|
89
|
+
if (response.headers && response.headers[TRACE_ID_HEADER_NAME]) {
|
|
90
|
+
// Append trace ID with dot separator — if not present, the dot should be omitted
|
|
91
|
+
debugID += "." + response.headers[TRACE_ID_HEADER_NAME];
|
|
92
|
+
}
|
|
93
|
+
if (response.body) {
|
|
94
|
+
if (response.body.request_id) {
|
|
95
|
+
// Prepend request ID
|
|
96
|
+
debugID = response.body.request_id + debugID;
|
|
97
|
+
}
|
|
98
|
+
errorCode = response.body.code || response.body.error;
|
|
99
|
+
errorDescription =
|
|
100
|
+
response.body.message || response.body.error_description;
|
|
101
|
+
}
|
|
102
|
+
var errorMessage;
|
|
103
|
+
if (debugID) {
|
|
104
|
+
errorMessage = message + " [" + statusCode + " " + statusMessage + " | " + debugID + "]";
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
errorMessage = message + " [" + statusCode + " " + statusMessage + "]";
|
|
108
|
+
}
|
|
109
|
+
if (errorCode) {
|
|
110
|
+
errorMessage += " " + errorCode;
|
|
111
|
+
}
|
|
112
|
+
if (errorDescription) {
|
|
113
|
+
errorMessage += " - " + errorDescription;
|
|
114
|
+
}
|
|
115
|
+
var responseError = new Error(errorMessage);
|
|
116
|
+
responseError.statusCode = response.statusCode;
|
|
117
|
+
responseError.response = response;
|
|
118
|
+
responseError.request = response.request
|
|
119
|
+
? new Request(response.request)
|
|
120
|
+
: {};
|
|
121
|
+
return responseError;
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Build an authentication error. {@see Errors~AuthError}
|
|
125
|
+
*
|
|
126
|
+
* @param {?APIRequest~ResponseObject} response - The response returned by an APIRequestManager request
|
|
127
|
+
* @param {string} [message] - Optional message for the error
|
|
128
|
+
* @returns {Errors~AuthError} A properly formatted authentication error
|
|
129
|
+
*/
|
|
130
|
+
buildAuthError: function (response /* FIXME */, message) {
|
|
131
|
+
message = message || 'Expired Auth: Auth code or refresh token has expired';
|
|
132
|
+
var responseError = this.buildResponseError(response, message);
|
|
133
|
+
responseError.authExpired = true;
|
|
134
|
+
return responseError;
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* Build the error for an "Unexpected Response" from the API. This is a shortcut for
|
|
138
|
+
* responseError built specifically for the 401 UNEXPECTED response case. It
|
|
139
|
+
* should be called and the error should be propogated to the consumer
|
|
140
|
+
* whenever an unexpected response was recieved from the API.
|
|
141
|
+
*
|
|
142
|
+
* @param {?APIRequest~ResponseObject} response - The response returned by an APIRequestManager request
|
|
143
|
+
* @returns {Errors~ResponseError} an error describing the response error
|
|
144
|
+
*/
|
|
145
|
+
buildUnexpectedResponseError: function (response /* FIXME */) {
|
|
146
|
+
return this.buildResponseError(response, 'Unexpected API Response');
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* Unwrap a Bluebird error and throw it, or just re-throw if the error
|
|
150
|
+
* is not a Bluebird error. This is necessary to preserve errors when
|
|
151
|
+
* a function is promisified.
|
|
152
|
+
* @param {Error} error The error to unwrap
|
|
153
|
+
* @returns {void}
|
|
154
|
+
* @throws {Error} The unwrapped error
|
|
155
|
+
*/
|
|
156
|
+
unwrapAndThrow: function (error /* FIXME */) {
|
|
157
|
+
if (error.cause) {
|
|
158
|
+
throw error.cause;
|
|
159
|
+
}
|
|
160
|
+
throw error;
|
|
161
|
+
},
|
|
174
162
|
};
|
|
163
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/util/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;AAEH,8CAAkC;AAElC,iFAAiF;AACjF,eAAe;AACf,iFAAiF;AACjF,IAAM,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAE/C,IAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAE9C,iFAAiF;AACjF,yBAAyB;AACzB,iFAAiF;AAEjF;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;GAKG;AACH;IAOC,iBAAY,GAAQ,CAAC,WAAW;QAC/B,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,IAAI,GAAG,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,GAAG,GAAG;gBACV,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ;gBAC1B,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI;gBAClB,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ;gBACtB,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC;gBAC9B,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI;aACtB,CAAC;SACF;aAAM;YACN,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;SAChB;QACD,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW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* @fileoverview Calculate exponential backoff time
|
|
3
|
+
*/
|
|
4
|
+
declare const _default: (numRetries: number, baseInterval: number) => number;
|
|
5
|
+
/**
|
|
6
|
+
* Calculate the exponential backoff time with randomized jitter
|
|
7
|
+
* @param {int} numRetries Which retry number this one will be
|
|
8
|
+
* @param {int} baseInterval The base retry interval set in config
|
|
9
|
+
* @returns {int} The number of milliseconds after which to retry
|
|
10
|
+
*/
|
|
11
|
+
export = _default;
|
|
@@ -1,29 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview Calculate exponential backoff time
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
5
|
// ------------------------------------------------------------------------------
|
|
8
6
|
// Private
|
|
9
7
|
// ------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
8
|
// Retry intervals are between 50% and 150% of the exponentially increasing base amount
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var minRandomization = 1 - RETRY_RANDOMIZATION_FACTOR;
|
|
23
|
-
var maxRandomization = 1 + RETRY_RANDOMIZATION_FACTOR;
|
|
24
|
-
var randomization = (Math.random() * (maxRandomization - minRandomization)) + minRandomization;
|
|
25
|
-
var exponential = Math.pow(2, numRetries - 1);
|
|
26
|
-
return Math.ceil(exponential * baseInterval * randomization);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = getRetryTimeout;
|
|
9
|
+
var RETRY_RANDOMIZATION_FACTOR = 0.5;
|
|
10
|
+
module.exports = function getRetryTimeout(numRetries, baseInterval) {
|
|
11
|
+
var minRandomization = 1 - RETRY_RANDOMIZATION_FACTOR;
|
|
12
|
+
var maxRandomization = 1 + RETRY_RANDOMIZATION_FACTOR;
|
|
13
|
+
var randomization = Math.random() * (maxRandomization - minRandomization) + minRandomization;
|
|
14
|
+
var exponential = Math.pow(2, numRetries - 1);
|
|
15
|
+
return Math.ceil(exponential * baseInterval * randomization);
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=exponential-backoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exponential-backoff.js","sourceRoot":"","sources":["../../src/util/exponential-backoff.ts"],"names":[],"mappings":";AAAA;;GAEG;AAEH,iFAAiF;AACjF,UAAU;AACV,iFAAiF;AAEjF,uFAAuF;AACvF,IAAM,0BAA0B,GAAG,GAAG,CAAC;AAQvC,iBAAS,SAAS,eAAe,CAAC,UAAkB,EAAE,YAAoB;IACzE,IAAI,gBAAgB,GAAG,CAAC,GAAG,0BAA0B,CAAC;IACtD,IAAI,gBAAgB,GAAG,CAAC,GAAG,0BAA0B,CAAC;IACtD,IAAI,aAAa,GAChB,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;IAC1E,IAAI,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,YAAY,GAAG,aAAa,CAAC,CAAC;AAC9D,CAAC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Iterator for paged responses
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Asynchronous iterator for paged collections
|
|
6
|
+
*/
|
|
7
|
+
declare class PagingIterator {
|
|
8
|
+
/**
|
|
9
|
+
* Determine if a response is iterable
|
|
10
|
+
* @param {Object} response - The API response
|
|
11
|
+
* @returns {boolean} Whether the response is iterable
|
|
12
|
+
*/
|
|
13
|
+
static isIterable(response: any): boolean;
|
|
14
|
+
nextField: any;
|
|
15
|
+
nextValue: any;
|
|
16
|
+
limit: any;
|
|
17
|
+
done: boolean;
|
|
18
|
+
options: Record<string, any>;
|
|
19
|
+
fetch: any;
|
|
20
|
+
buffer: any;
|
|
21
|
+
queue: any;
|
|
22
|
+
/**
|
|
23
|
+
* @constructor
|
|
24
|
+
* @param {Object} response - The original API response
|
|
25
|
+
* @param {BoxClient} client - An API client to make further requests
|
|
26
|
+
* @returns {void}
|
|
27
|
+
* @throws {Error} Will throw when collection cannot be paged
|
|
28
|
+
*/
|
|
29
|
+
constructor(response: any, client: any);
|
|
30
|
+
/**
|
|
31
|
+
* Update the paging parameters for the iterator
|
|
32
|
+
* @private
|
|
33
|
+
* @param {Object} response - The latest API response
|
|
34
|
+
* @returns {void}
|
|
35
|
+
*/
|
|
36
|
+
_updatePaging(response: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* Fetch the next page of results
|
|
39
|
+
* @returns {Promise} Promise resolving to iterator state
|
|
40
|
+
*/
|
|
41
|
+
_getData(): any;
|
|
42
|
+
/**
|
|
43
|
+
* Fetch the next page of the collection
|
|
44
|
+
* @returns {Promise} Promise resolving to iterator state
|
|
45
|
+
*/
|
|
46
|
+
next(): any;
|
|
47
|
+
/**
|
|
48
|
+
* Fetch the next marker
|
|
49
|
+
* @returns {string|int} String that is the next marker or int that is the next offset
|
|
50
|
+
*/
|
|
51
|
+
getNextMarker(): any;
|
|
52
|
+
}
|
|
53
|
+
export = PagingIterator;
|