box-node-sdk 1.37.0 → 1.39.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 +38 -2
- package/README.md +2 -0
- 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 +271 -0
- package/lib/box-client.js +580 -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 -329
- 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/sign-requests.generated.d.ts +92 -0
- package/lib/managers/sign-requests.generated.js +97 -0
- package/lib/managers/sign-requests.generated.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 +303 -308
- package/lib/managers/webhooks.js.map +1 -0
- package/lib/schemas/file-base.generated.d.ts +32 -0
- package/lib/schemas/file-base.generated.js +3 -0
- package/lib/schemas/file-base.generated.js.map +1 -0
- package/lib/schemas/file-mini.generated.d.ts +41 -0
- package/lib/schemas/file-mini.generated.js +3 -0
- package/lib/schemas/file-mini.generated.js.map +1 -0
- package/lib/schemas/file-version-base.generated.d.ts +19 -0
- package/lib/schemas/file-version-base.generated.js +3 -0
- package/lib/schemas/file-version-base.generated.js.map +1 -0
- package/lib/schemas/file-version-mini.generated.d.ts +14 -0
- package/lib/schemas/file-version-mini.generated.js +3 -0
- package/lib/schemas/file-version-mini.generated.js.map +1 -0
- package/lib/schemas/folder-base.generated.d.ts +32 -0
- package/lib/schemas/folder-base.generated.js +3 -0
- package/lib/schemas/folder-base.generated.js.map +1 -0
- package/lib/schemas/folder-mini.generated.d.ts +31 -0
- package/lib/schemas/folder-mini.generated.js +3 -0
- package/lib/schemas/folder-mini.generated.js.map +1 -0
- package/lib/schemas/index.d.ts +13 -0
- package/lib/schemas/index.js +26 -0
- package/lib/schemas/index.js.map +1 -0
- package/lib/schemas/sign-request-create-request.generated.d.ts +62 -0
- package/lib/schemas/sign-request-create-request.generated.js +3 -0
- package/lib/schemas/sign-request-create-request.generated.js.map +1 -0
- package/lib/schemas/sign-request-create-signer.generated.d.ts +38 -0
- package/lib/schemas/sign-request-create-signer.generated.js +3 -0
- package/lib/schemas/sign-request-create-signer.generated.js.map +1 -0
- package/lib/schemas/sign-request-prefill-tag.generated.d.ts +28 -0
- package/lib/schemas/sign-request-prefill-tag.generated.js +3 -0
- package/lib/schemas/sign-request-prefill-tag.generated.js.map +1 -0
- package/lib/schemas/sign-request-signer-input.generated.d.ts +18 -0
- package/lib/schemas/sign-request-signer-input.generated.js +3 -0
- package/lib/schemas/sign-request-signer-input.generated.js.map +1 -0
- package/lib/schemas/sign-request-signer.generated.d.ts +23 -0
- package/lib/schemas/sign-request-signer.generated.js +3 -0
- package/lib/schemas/sign-request-signer.generated.js.map +1 -0
- package/lib/schemas/sign-request.generated.d.ts +50 -0
- package/lib/schemas/sign-request.generated.js +3 -0
- package/lib/schemas/sign-request.generated.js.map +1 -0
- package/lib/schemas/sign-requests.generated.d.ts +27 -0
- package/lib/schemas/sign-requests.generated.js +3 -0
- package/lib/schemas/sign-requests.generated.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/serializable.d.ts +10 -0
- package/lib/util/serializable.js +18 -0
- package/lib/util/serializable.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 +21 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 1.39.0 (2021-08-30)
|
|
4
|
+
|
|
5
|
+
**New Features and Enhancements:**
|
|
6
|
+
|
|
7
|
+
- Add support for Box Sign API ([#658](https://github.com/box/box-node-sdk/pull/658))
|
|
8
|
+
- Enhance TS Imports ([#656](https://github.com/box/box-node-sdk/pull/656))
|
|
9
|
+
|
|
10
|
+
## 1.38.0 (2021-08-05)
|
|
11
|
+
|
|
12
|
+
**New Features and Enhancements:**
|
|
13
|
+
|
|
14
|
+
- Add sensitive-language event types for admin invites ([#648](https://github.com/box/box-node-sdk/pull/648))
|
|
15
|
+
- Use BetterDocs to adapt JSDocs to TypeScript ([#646](https://github.com/box/box-node-sdk/pull/646))
|
|
16
|
+
- Change ProxyAgent import to be dynamic ([#641](https://github.com/box/box-node-sdk/pull/641))
|
|
17
|
+
- New API for get files and file versions under retention ([#585](https://github.com/box/box-node-sdk/pull/585))
|
|
18
|
+
|
|
19
|
+
**Bug Fixes:**
|
|
20
|
+
|
|
21
|
+
- Deeply freeze Config except Buffers and Readable streams ([#651](https://github.com/box/box-node-sdk/pull/651))
|
|
22
|
+
- Fix a typo in docs of src/managers/search.ts ([#649](https://github.com/box/box-node-sdk/pull/649))
|
|
23
|
+
- Update broken documentation link ([#647](https://github.com/box/box-node-sdk/pull/647))
|
|
24
|
+
- fix type annotations for exchangeToken functions ([#645](https://github.com/box/box-node-sdk/pull/645))
|
|
25
|
+
- Deprecate files getThumbnail API in favor of getRepresentationContent ([#627](https://github.com/box/box-node-sdk/pull/627))
|
|
26
|
+
|
|
27
|
+
## 1.37.2 (2021-05-20)
|
|
28
|
+
|
|
29
|
+
**Bug Fixes:**
|
|
30
|
+
|
|
31
|
+
- Fix backwards compatibility issue by moving some TypeScript @types as direct dependencies ([#630](https://github.com/box/box-node-sdk/pull/630))
|
|
32
|
+
|
|
33
|
+
## 1.37.1 (2021-05-19)
|
|
34
|
+
|
|
35
|
+
**Bug Fixes:**
|
|
36
|
+
|
|
37
|
+
- Insensitive language: replace whitelist with allowlist ([#625](https://github.com/box/box-node-sdk/pull/625))
|
|
38
|
+
|
|
39
|
+
## 1.37.0 (2021-04-16)
|
|
4
40
|
|
|
5
41
|
**New Features and Enhancements:**
|
|
6
42
|
|
|
@@ -11,7 +47,7 @@
|
|
|
11
47
|
- Fix webhook signature validation ([#568](https://github.com/box/box-node-sdk/pull/568))
|
|
12
48
|
- Update dependencies to patch security vulnerabilities ([#578](https://github.com/box/box-node-sdk/pull/578))
|
|
13
49
|
|
|
14
|
-
## 1.36.0 (
|
|
50
|
+
## 1.36.0 (2021-01-27)
|
|
15
51
|
|
|
16
52
|
**New Features and Enhancements:**
|
|
17
53
|
|
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ Box Node.js SDK
|
|
|
7
7
|
|
|
8
8
|
A Node.js interface to the [Box Content API](https://developers.box.com/docs/).
|
|
9
9
|
|
|
10
|
+
Getting Started Docs: https://developer.box.com/guides/tooling/sdks/node/
|
|
11
|
+
|
|
10
12
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
11
13
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
12
14
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A library for making requests to the Box API.
|
|
3
|
+
*/
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
/// <reference types="bluebird" />
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
declare type Config = any;
|
|
8
|
+
/**
|
|
9
|
+
* A library for communicating with the Box API.
|
|
10
|
+
*
|
|
11
|
+
* @param {Config} config SDK configuration object instance.
|
|
12
|
+
* @param {EventEmitter} eventBus The event bus for SDK events
|
|
13
|
+
* @constructor
|
|
14
|
+
*/
|
|
15
|
+
declare class APIRequestManager {
|
|
16
|
+
config: Config;
|
|
17
|
+
eventBus: EventEmitter;
|
|
18
|
+
constructor(config: Config, eventBus: EventEmitter);
|
|
19
|
+
/**
|
|
20
|
+
* Make a request to the API, and get the response via callback.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} options The request options
|
|
23
|
+
* @returns {Promise<Response>} A promise resolving to the response object
|
|
24
|
+
*/
|
|
25
|
+
makeRequest(options: any): import("bluebird")<unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Make a request to the API, and return a read stream for the response.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} options The request options
|
|
30
|
+
* @returns {Stream.Readable} The response stream
|
|
31
|
+
*/
|
|
32
|
+
makeStreamingRequest(options: any): any;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @module box-node-sdk/lib/api-request-manager
|
|
36
|
+
* @see {@Link APIRequestManager}
|
|
37
|
+
*/
|
|
38
|
+
export = APIRequestManager;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview A library for making requests to the Box API.
|
|
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
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
var bluebird_1 = require("bluebird");
|
|
12
|
+
var errors_1 = __importDefault(require("./util/errors"));
|
|
13
|
+
var APIRequest = require('./api-request');
|
|
14
14
|
// ------------------------------------------------------------------------------
|
|
15
15
|
// Private
|
|
16
16
|
// ------------------------------------------------------------------------------
|
|
17
|
-
|
|
18
17
|
// ------------------------------------------------------------------------------
|
|
19
18
|
// Public
|
|
20
19
|
// ------------------------------------------------------------------------------
|
|
21
|
-
|
|
22
20
|
/**
|
|
23
21
|
* A library for communicating with the Box API.
|
|
24
22
|
*
|
|
@@ -26,50 +24,45 @@ var APIRequest = require('./api-request'),
|
|
|
26
24
|
* @param {EventEmitter} eventBus The event bus for SDK events
|
|
27
25
|
* @constructor
|
|
28
26
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*/
|
|
41
|
-
APIRequestManager
|
|
42
|
-
|
|
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
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @module box-node-sdk/lib/api-request-manager
|
|
73
|
-
* @see {@Link APIRequestManager}
|
|
74
|
-
*/
|
|
27
|
+
var APIRequestManager = /** @class */ (function () {
|
|
28
|
+
function APIRequestManager(config, eventBus) {
|
|
29
|
+
this.config = config;
|
|
30
|
+
this.eventBus = eventBus;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Make a request to the API, and get the response via callback.
|
|
34
|
+
*
|
|
35
|
+
* @param {Object} options The request options
|
|
36
|
+
* @returns {Promise<Response>} A promise resolving to the response object
|
|
37
|
+
*/
|
|
38
|
+
APIRequestManager.prototype.makeRequest = function (options /* FIXME */) {
|
|
39
|
+
// Add default APIRequestManager options to each request
|
|
40
|
+
var requestConfig = this.config.extend({
|
|
41
|
+
request: options,
|
|
42
|
+
});
|
|
43
|
+
// Make the request
|
|
44
|
+
var apiRequest = new APIRequest(requestConfig, this.eventBus);
|
|
45
|
+
return bluebird_1.Promise.fromCallback(function (callback) {
|
|
46
|
+
return apiRequest.execute(callback);
|
|
47
|
+
}).catch(function (err) { return errors_1.default.unwrapAndThrow(err); });
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Make a request to the API, and return a read stream for the response.
|
|
51
|
+
*
|
|
52
|
+
* @param {Object} options The request options
|
|
53
|
+
* @returns {Stream.Readable} The response stream
|
|
54
|
+
*/
|
|
55
|
+
APIRequestManager.prototype.makeStreamingRequest = function (options /* FIXME */) {
|
|
56
|
+
// Add default APIRequestManager options to each request
|
|
57
|
+
var requestConfig = this.config.extend({
|
|
58
|
+
request: options,
|
|
59
|
+
});
|
|
60
|
+
// Make the request
|
|
61
|
+
var apiRequest = new APIRequest(requestConfig, this.eventBus);
|
|
62
|
+
apiRequest.execute();
|
|
63
|
+
return apiRequest.getResponseStream();
|
|
64
|
+
};
|
|
65
|
+
return APIRequestManager;
|
|
66
|
+
}());
|
|
75
67
|
module.exports = APIRequestManager;
|
|
68
|
+
//# sourceMappingURL=api-request-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-request-manager.js","sourceRoot":"","sources":["../src/api-request-manager.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,iFAAiF;AACjF,eAAe;AACf,iFAAiF;AAEjF,qCAAmC;AAEnC,yDAAmC;AAEnC,IAAM,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAQ5C,iFAAiF;AACjF,UAAU;AACV,iFAAiF;AAEjF,iFAAiF;AACjF,SAAS;AACT,iFAAiF;AAEjF;;;;;;GAMG;AACH;IAIC,2BAAY,MAAc,EAAE,QAAsB;QACjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,uCAAW,GAAX,UAAY,OAAY,CAAC,WAAW;QACnC,wDAAwD;QACxD,IAAI,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACtC,OAAO,EAAE,OAAO;SAChB,CAAC,CAAC;QAEH,mBAAmB;QACnB,IAAI,UAAU,GAAG,IAAI,UAAU,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9D,OAAO,kBAAO,CAAC,YAAY,CAAC,UAAC,QAAQ;YACpC,OAAA,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC;QAA5B,CAA4B,CAC5B,CAAC,KAAK,CAAC,UAAC,GAAG,IAAK,OAAA,gBAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAA1B,CAA0B,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,gDAAoB,GAApB,UAAqB,OAAY,CAAC,WAAW;QAC5C,wDAAwD;QACxD,IAAI,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACtC,OAAO,EAAE,OAAO;SAChB,CAAC,CAAC;QAEH,mBAAmB;QACnB,IAAI,UAAU,GAAG,IAAI,UAAU,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9D,UAAU,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO,UAAU,CAAC,iBAAiB,EAAE,CAAC;IACvC,CAAC;IACF,wBAAC;AAAD,CAAC,AA7CD,IA6CC;AAMD,iBAAS,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A Box API Request
|
|
3
|
+
*/
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import request from 'request';
|
|
7
|
+
import Config from './util/config';
|
|
8
|
+
/**
|
|
9
|
+
* The API response object includes information about the request made and its response. The information attached is a subset
|
|
10
|
+
* of the information returned by the request module, which is too large and complex to be safely handled (contains circular
|
|
11
|
+
* references, errors on serialization, etc.)
|
|
12
|
+
*
|
|
13
|
+
* @typedef {Object} APIRequest~ResponseObject
|
|
14
|
+
* @property {APIRequest~RequestObject} request Information about the request that generated this response
|
|
15
|
+
* @property {int} statusCode The response HTTP status code
|
|
16
|
+
* @property {Object} headers A collection of response headers
|
|
17
|
+
* @property {Object|Buffer|string} [body] The response body. Encoded to JSON by default, but can be a buffer
|
|
18
|
+
* (if encoding fails or if json encoding is disabled) or a string (if string encoding is enabled). Will be undefined
|
|
19
|
+
* if no response body is sent.
|
|
20
|
+
*/
|
|
21
|
+
declare type APIRequestResponseObject = {
|
|
22
|
+
request: APIRequestRequestObject;
|
|
23
|
+
statusCode: number;
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
body?: object | Buffer | string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The API request object includes information about the request made. The information attached is a subset of the information
|
|
29
|
+
* of a request module instance, which is too large and complex to be safely handled (contains circular references, errors on
|
|
30
|
+
* serialization, etc.).
|
|
31
|
+
*
|
|
32
|
+
* @typedef {Object} APIRequest~RequestObject
|
|
33
|
+
* @property {Object} uri Information about the request, including host, path, and the full 'href' url
|
|
34
|
+
* @property {string} method The request method (GET, POST, etc.)
|
|
35
|
+
* @property {Object} headers A collection of headers sent with the request
|
|
36
|
+
*/
|
|
37
|
+
declare type APIRequestRequestObject = {
|
|
38
|
+
uri: Record<string, any>;
|
|
39
|
+
method: string;
|
|
40
|
+
headers: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The error returned by APIRequest callbacks, which includes any relevent, available information about the request
|
|
44
|
+
* and response. Note that these properties do not exist on stream errors, only errors retuned to the callback.
|
|
45
|
+
*
|
|
46
|
+
* @typedef {Error} APIRequest~Error
|
|
47
|
+
* @property {APIRequest~RequestObject} request Information about the request that generated this error
|
|
48
|
+
* @property {APIRequest~ResponseObject} [response] Information about the response related to this error, if available
|
|
49
|
+
* @property {int} [statusCode] The response HTTP status code
|
|
50
|
+
* @property {boolean} [maxRetriesExceeded] True iff the max number of retries were exceeded. Otherwise, undefined.
|
|
51
|
+
*/
|
|
52
|
+
declare type APIRequestError = {
|
|
53
|
+
request: APIRequestRequestObject;
|
|
54
|
+
response?: APIRequestResponseObject;
|
|
55
|
+
statusCode?: number;
|
|
56
|
+
maxRetriesExceeded?: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Callback invoked when an APIRequest request is complete and finalized. On success,
|
|
60
|
+
* propagates the relevent response information. An err will indicate an unresolvable issue
|
|
61
|
+
* with the request (permanent failure or temp error response from the server, retried too many times).
|
|
62
|
+
*
|
|
63
|
+
* @callback APIRequest~Callback
|
|
64
|
+
* @param {?APIRequest~Error} err If Error object, API request did not get back the data it was supposed to. This
|
|
65
|
+
* could be either because of a temporary error, or a more serious error connecting to the API.
|
|
66
|
+
* @param {APIRequest~ResponseObject} response The response returned by an APIRequestManager request
|
|
67
|
+
*/
|
|
68
|
+
declare type APIRequestCallback = (err?: APIRequestError | null, response?: APIRequestResponseObject) => void;
|
|
69
|
+
/**
|
|
70
|
+
* APIRequest helps to prepare and execute requests to the Box API. It supports
|
|
71
|
+
* retries, multipart uploads, and more.
|
|
72
|
+
*
|
|
73
|
+
|
|
74
|
+
* @param {Config} config Request-specific Config object
|
|
75
|
+
* @param {EventEmitter} eventBus Event bus for the SDK instance
|
|
76
|
+
* @constructor
|
|
77
|
+
*/
|
|
78
|
+
declare class APIRequest {
|
|
79
|
+
config: Config;
|
|
80
|
+
eventBus: EventEmitter;
|
|
81
|
+
isRetryable: boolean;
|
|
82
|
+
_callback?: APIRequestCallback;
|
|
83
|
+
request?: request.Request;
|
|
84
|
+
stream?: request.Request;
|
|
85
|
+
numRetries?: number;
|
|
86
|
+
constructor(config: Config, eventBus: EventEmitter);
|
|
87
|
+
/**
|
|
88
|
+
* Executes the request with the given options. If a callback is provided, we'll
|
|
89
|
+
* handle the response via callbacks. Otherwise, the response will be streamed to
|
|
90
|
+
* via the stream property. You can access this stream with the getResponseStream()
|
|
91
|
+
* method.
|
|
92
|
+
*
|
|
93
|
+
* @param {APIRequest~Callback} [callback] Callback for handling the response
|
|
94
|
+
* @returns {void}
|
|
95
|
+
*/
|
|
96
|
+
execute(callback?: APIRequestCallback): void;
|
|
97
|
+
/**
|
|
98
|
+
* Return the response read stream for a request. This will be undefined until
|
|
99
|
+
* a stream-based request has been started.
|
|
100
|
+
*
|
|
101
|
+
* @returns {?ReadableStream} The response stream
|
|
102
|
+
*/
|
|
103
|
+
getResponseStream(): request.Request | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Handle the request response in the callback case.
|
|
106
|
+
*
|
|
107
|
+
* @param {?Error} err An error, if one occurred
|
|
108
|
+
* @param {Object} [response] The full response object, returned by the request module.
|
|
109
|
+
* Contains information about the request & response, including the response body itself.
|
|
110
|
+
* @returns {void}
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
_handleResponse(err?: any, response?: any): void;
|
|
114
|
+
/**
|
|
115
|
+
* Attempt a retry. If the request hasn't exceeded it's maximum number of retries,
|
|
116
|
+
* re-execute the request (after the retry interval). Otherwise, propagate a new error.
|
|
117
|
+
*
|
|
118
|
+
* @param {?Error} err An error, if one occurred
|
|
119
|
+
* @returns {void}
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
_retry(err?: any): void;
|
|
123
|
+
/**
|
|
124
|
+
* Propagate the response to the provided callback.
|
|
125
|
+
*
|
|
126
|
+
* @param {?Error} err An error, if one occurred
|
|
127
|
+
* @param {APIRequest~ResponseObject} response Information about the request & response
|
|
128
|
+
* @returns {void}
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
_finish(err?: any, response?: APIRequestResponseObject): void;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @module box-node-sdk/lib/api-request
|
|
135
|
+
* @see {@Link APIRequest}
|
|
136
|
+
*/
|
|
137
|
+
export = APIRequest;
|