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
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Token Manager
|
|
3
|
+
*/
|
|
4
|
+
import Promise from 'bluebird';
|
|
5
|
+
import APIRequestManager from './api-request-manager';
|
|
6
|
+
declare type Config = Record<string, any>;
|
|
7
|
+
/**
|
|
8
|
+
* Token request options. Set by the consumer to add/modify the params sent to the
|
|
9
|
+
* request.
|
|
10
|
+
*
|
|
11
|
+
* @typedef {Object} TokenRequestOptions
|
|
12
|
+
* @property {string} [ip] The IP Address of the requesting user. This IP will be reflected in authentication
|
|
13
|
+
* notification emails sent to your users on login. Defaults to the IP address of the
|
|
14
|
+
* server requesting the tokens.
|
|
15
|
+
*/
|
|
16
|
+
declare type TokenRequestOptions = {
|
|
17
|
+
ip?: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Parameters for creating a token using a Box shared link via token exchange
|
|
21
|
+
* @typedef {Object} SharedLinkParams
|
|
22
|
+
* @property {string} url Shared link URL
|
|
23
|
+
*/
|
|
24
|
+
declare type SharedLinkParams = {
|
|
25
|
+
url: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Parameters for creating an actor token via token exchange
|
|
29
|
+
* @typedef {Object} ActorParams
|
|
30
|
+
* @property {string} id The external identifier for the actor
|
|
31
|
+
* @property {string} name The display name of the actor
|
|
32
|
+
*/
|
|
33
|
+
declare type ActorParams = {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* An object representing all token information for a single Box user.
|
|
39
|
+
*
|
|
40
|
+
* @typedef {Object} TokenInfo
|
|
41
|
+
* @property {string} accessToken The API access token. Used to authenticate API requests to a certain
|
|
42
|
+
* user and/or application.
|
|
43
|
+
* @property {int} acquiredAtMS The time that the tokens were acquired.
|
|
44
|
+
* @property {int} accessTokenTTLMS The TTL of the access token. Can be used with acquiredAtMS to
|
|
45
|
+
* calculate if the current access token has expired.
|
|
46
|
+
* @property {string} [refreshToken] The API refresh token is a Longer-lasting than an access token, and can
|
|
47
|
+
* be used to gain a new access token if the current access token becomes
|
|
48
|
+
* expired. Grants like the 'client credentials' grant don't return a
|
|
49
|
+
* refresh token, and have no refresh capabilities.
|
|
50
|
+
*/
|
|
51
|
+
declare type TokenInfo = {
|
|
52
|
+
accessToken: string;
|
|
53
|
+
acquiredAtMS: number;
|
|
54
|
+
accessTokenTTLMS: number;
|
|
55
|
+
refreshToken?: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Manager for API access abd refresh tokens
|
|
59
|
+
*
|
|
60
|
+
* @param {Config} config The config object
|
|
61
|
+
* @param {APIRequestManager} requestManager The API Request Manager
|
|
62
|
+
* @constructor
|
|
63
|
+
*/
|
|
64
|
+
declare class TokenManager {
|
|
65
|
+
config: Config;
|
|
66
|
+
requestManager: APIRequestManager;
|
|
67
|
+
oauthBaseURL: string;
|
|
68
|
+
constructor(config: Config, requestManager: APIRequestManager);
|
|
69
|
+
/**
|
|
70
|
+
* Given a TokenInfo object, returns whether its access token is expired. An access token is considered
|
|
71
|
+
* expired once its TTL surpasses the current time outside of the given buffer. This is a public method so
|
|
72
|
+
* that other modules may check the validity of their tokens.
|
|
73
|
+
*
|
|
74
|
+
* @param {TokenInfo} tokenInfo the token info to be written
|
|
75
|
+
* @param {int} [bufferMS] An optional buffer we'd like to test against. The greater this buffer, the more aggressively
|
|
76
|
+
* we'll call a token invalid.
|
|
77
|
+
* @returns {boolean} True if token is valid outside of buffer, otherwise false
|
|
78
|
+
*/
|
|
79
|
+
isAccessTokenValid(tokenInfo: TokenInfo, bufferMS?: number): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Acquires OAuth2 tokens using a grant type (authorization_code, password, refresh_token)
|
|
82
|
+
*
|
|
83
|
+
* @param {Object} formParams - should contain all params expected by Box OAuth2 token endpoint
|
|
84
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant, null for default behavior
|
|
85
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
getTokens(formParams: Record<string, any>, options?: TokenRequestOptions | null): Promise<{
|
|
89
|
+
accessToken: any;
|
|
90
|
+
refreshToken: any;
|
|
91
|
+
accessTokenTTLMS: number;
|
|
92
|
+
acquiredAtMS: number;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Acquires token info using an authorization code
|
|
96
|
+
*
|
|
97
|
+
* @param {string} authorizationCode - authorization code issued by Box
|
|
98
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
99
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
100
|
+
*/
|
|
101
|
+
getTokensAuthorizationCodeGrant(authorizationCode: string, options?: TokenRequestOptions): Promise<{
|
|
102
|
+
accessToken: any;
|
|
103
|
+
refreshToken: any;
|
|
104
|
+
accessTokenTTLMS: number;
|
|
105
|
+
acquiredAtMS: number;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Acquires token info using the client credentials grant.
|
|
109
|
+
*
|
|
110
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
111
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
112
|
+
*/
|
|
113
|
+
getTokensClientCredentialsGrant(options?: TokenRequestOptions): Promise<{
|
|
114
|
+
accessToken: any;
|
|
115
|
+
refreshToken: any;
|
|
116
|
+
accessTokenTTLMS: number;
|
|
117
|
+
acquiredAtMS: number;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Refreshes the access and refresh tokens for a given refresh token.
|
|
121
|
+
*
|
|
122
|
+
* @param {string} refreshToken - A valid OAuth refresh token
|
|
123
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
124
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
125
|
+
*/
|
|
126
|
+
getTokensRefreshGrant(refreshToken: string, options?: TokenRequestOptions): Promise<{
|
|
127
|
+
accessToken: any;
|
|
128
|
+
refreshToken: any;
|
|
129
|
+
accessTokenTTLMS: number;
|
|
130
|
+
acquiredAtMS: number;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Gets tokens for enterprise administration of app users
|
|
134
|
+
* @param {string} type The type of token to create, "user" or "enterprise"
|
|
135
|
+
* @param {string} id The ID of the enterprise to generate a token for
|
|
136
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
137
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
138
|
+
*/
|
|
139
|
+
getTokensJWTGrant(type: string, id: string, options?: TokenRequestOptions): Promise<any>;
|
|
140
|
+
/**
|
|
141
|
+
* Attempt a retry if possible and create a new JTI claim. If the request hasn't exceeded it's maximum number of retries,
|
|
142
|
+
* re-execute the request (after the retry interval). Otherwise, propagate a new error.
|
|
143
|
+
*
|
|
144
|
+
* @param {Object} claims - JTI claims object
|
|
145
|
+
* @param {Object} [jwtOptions] - JWT options for the signature
|
|
146
|
+
* @param {Object} keyParams - Key JWT parameters object that contains the private key and the passphrase
|
|
147
|
+
* @param {Object} params - Should contain all params expected by Box OAuth2 token endpoint
|
|
148
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
149
|
+
* @param {Error} error - Error from the previous JWT request
|
|
150
|
+
* @param {int} numRetries - Number of retries attempted
|
|
151
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the token info
|
|
152
|
+
*/
|
|
153
|
+
retryJWTGrant(claims: any, jwtOptions: any, keyParams: any, params: any, options: TokenRequestOptions | undefined, error: any, numRetries: number): any;
|
|
154
|
+
/**
|
|
155
|
+
* Exchange a valid access token for one with a lower scope, or delegated to
|
|
156
|
+
* an external user identifier.
|
|
157
|
+
*
|
|
158
|
+
* @param {string} accessToken - The valid access token to exchange
|
|
159
|
+
* @param {string|string[]} scopes - The scope(s) of the new access token
|
|
160
|
+
* @param {string} [resource] - The absolute URL of an API resource to restrict the new token to
|
|
161
|
+
* @param {Object} [options] - Optional parameters
|
|
162
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
163
|
+
* @param {ActorParams} [options.actor] - Optional actor parameters for creating annotator tokens
|
|
164
|
+
* @param {SharedLinkParams} [options.sharedLink] - Optional shared link parameters for creating tokens using shared links
|
|
165
|
+
* @returns {Promise<TokenInfo>} Promise resolving to the new token info
|
|
166
|
+
*/
|
|
167
|
+
exchangeToken(accessToken: string, scopes: string | string[], resource?: string, options?: {
|
|
168
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
169
|
+
actor?: ActorParams;
|
|
170
|
+
sharedLink?: SharedLinkParams;
|
|
171
|
+
}): Promise<{
|
|
172
|
+
accessToken: any;
|
|
173
|
+
refreshToken: any;
|
|
174
|
+
accessTokenTTLMS: number;
|
|
175
|
+
acquiredAtMS: number;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Revokes a token pair associated with a given access or refresh token.
|
|
179
|
+
*
|
|
180
|
+
* @param {string} token - A valid access or refresh token to revoke
|
|
181
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
182
|
+
* @returns {Promise} Promise resolving if the revoke succeeds
|
|
183
|
+
*/
|
|
184
|
+
revokeTokens(token: string, options?: TokenRequestOptions): Promise<unknown>;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Provides interactions with Box OAuth2 tokening system.
|
|
188
|
+
*
|
|
189
|
+
* @module box-node-sdk/lib/token-manager
|
|
190
|
+
*/
|
|
191
|
+
export = TokenManager;
|