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.
Files changed (126) hide show
  1. package/CHANGELOG.md +37 -2
  2. package/README.md +1 -1
  3. package/lib/api-request-manager.d.ts +38 -0
  4. package/lib/api-request-manager.js +48 -55
  5. package/lib/api-request-manager.js.map +1 -0
  6. package/lib/api-request.d.ts +141 -0
  7. package/lib/api-request.js +202 -281
  8. package/lib/api-request.js.map +1 -0
  9. package/lib/box-client.d.ts +269 -0
  10. package/lib/box-client.js +551 -713
  11. package/lib/box-client.js.map +1 -0
  12. package/lib/box-node-sdk.d.ts +216 -0
  13. package/lib/box-node-sdk.js +317 -352
  14. package/lib/box-node-sdk.js.map +1 -0
  15. package/lib/chunked-uploader.d.ts +129 -0
  16. package/lib/chunked-uploader.js +287 -358
  17. package/lib/chunked-uploader.js.map +1 -0
  18. package/lib/enterprise-event-stream.d.ts +82 -0
  19. package/lib/enterprise-event-stream.js +189 -203
  20. package/lib/enterprise-event-stream.js.map +1 -0
  21. package/lib/event-stream.d.ts +92 -0
  22. package/lib/event-stream.js +274 -302
  23. package/lib/event-stream.js.map +1 -0
  24. package/lib/managers/collaboration-allowlist.d.ts +137 -0
  25. package/lib/managers/collaboration-allowlist.js +200 -0
  26. package/lib/managers/collaboration-allowlist.js.map +1 -0
  27. package/lib/managers/collaboration-whitelist.d.ts +3 -0
  28. package/lib/managers/collaboration-whitelist.js +8 -222
  29. package/lib/managers/collaboration-whitelist.js.map +1 -0
  30. package/lib/managers/collaborations.d.ts +166 -0
  31. package/lib/managers/collaborations.js +225 -258
  32. package/lib/managers/collaborations.js.map +1 -0
  33. package/lib/managers/collections.d.ts +42 -0
  34. package/lib/managers/collections.js +45 -50
  35. package/lib/managers/collections.js.map +1 -0
  36. package/lib/managers/comments.d.ts +103 -0
  37. package/lib/managers/comments.js +158 -173
  38. package/lib/managers/comments.js.map +1 -0
  39. package/lib/managers/device-pins.d.ts +52 -0
  40. package/lib/managers/device-pins.js +75 -88
  41. package/lib/managers/device-pins.js.map +1 -0
  42. package/lib/managers/enterprise.d.ts +162 -0
  43. package/lib/managers/enterprise.js +168 -199
  44. package/lib/managers/enterprise.js.map +1 -0
  45. package/lib/managers/events.d.ts +177 -0
  46. package/lib/managers/events.js +230 -254
  47. package/lib/managers/events.js.map +1 -0
  48. package/lib/managers/files.d.ts +772 -0
  49. package/lib/managers/files.js +1400 -1602
  50. package/lib/managers/files.js.map +1 -0
  51. package/lib/managers/folders.d.ts +347 -0
  52. package/lib/managers/folders.js +551 -567
  53. package/lib/managers/folders.js.map +1 -0
  54. package/lib/managers/groups.d.ts +202 -0
  55. package/lib/managers/groups.js +238 -287
  56. package/lib/managers/groups.js.map +1 -0
  57. package/lib/managers/legal-hold-policies.d.ts +190 -0
  58. package/lib/managers/legal-hold-policies.js +228 -272
  59. package/lib/managers/legal-hold-policies.js.map +1 -0
  60. package/lib/managers/metadata.d.ts +228 -0
  61. package/lib/managers/metadata.js +265 -328
  62. package/lib/managers/metadata.js.map +1 -0
  63. package/lib/managers/recent-items.d.ts +38 -0
  64. package/lib/managers/recent-items.js +32 -39
  65. package/lib/managers/recent-items.js.map +1 -0
  66. package/lib/managers/retention-policies.d.ts +213 -0
  67. package/lib/managers/retention-policies.js +235 -281
  68. package/lib/managers/retention-policies.js.map +1 -0
  69. package/lib/managers/search.d.ts +82 -0
  70. package/lib/managers/search.js +68 -88
  71. package/lib/managers/search.js.map +1 -0
  72. package/lib/managers/shared-items.d.ts +33 -0
  73. package/lib/managers/shared-items.js +54 -62
  74. package/lib/managers/shared-items.js.map +1 -0
  75. package/lib/managers/storage-policies.d.ts +86 -0
  76. package/lib/managers/storage-policies.js +108 -142
  77. package/lib/managers/storage-policies.js.map +1 -0
  78. package/lib/managers/tasks.d.ts +161 -0
  79. package/lib/managers/tasks.js +219 -260
  80. package/lib/managers/tasks.js.map +1 -0
  81. package/lib/managers/terms-of-service.d.ts +161 -0
  82. package/lib/managers/terms-of-service.js +250 -273
  83. package/lib/managers/terms-of-service.js.map +1 -0
  84. package/lib/managers/trash.d.ts +30 -0
  85. package/lib/managers/trash.js +30 -41
  86. package/lib/managers/trash.js.map +1 -0
  87. package/lib/managers/users.d.ts +131 -0
  88. package/lib/managers/users.js +160 -203
  89. package/lib/managers/users.js.map +1 -0
  90. package/lib/managers/web-links.d.ts +127 -0
  91. package/lib/managers/web-links.js +183 -209
  92. package/lib/managers/web-links.js.map +1 -0
  93. package/lib/managers/webhooks.d.ts +166 -0
  94. package/lib/managers/webhooks.js +312 -305
  95. package/lib/managers/webhooks.js.map +1 -0
  96. package/lib/sessions/anonymous-session.d.ts +69 -0
  97. package/lib/sessions/anonymous-session.js +88 -102
  98. package/lib/sessions/anonymous-session.js.map +1 -0
  99. package/lib/sessions/app-auth-session.d.ts +92 -0
  100. package/lib/sessions/app-auth-session.js +140 -160
  101. package/lib/sessions/app-auth-session.js.map +1 -0
  102. package/lib/sessions/basic-session.d.ts +56 -0
  103. package/lib/sessions/basic-session.js +40 -50
  104. package/lib/sessions/basic-session.js.map +1 -0
  105. package/lib/sessions/persistent-session.d.ts +96 -0
  106. package/lib/sessions/persistent-session.js +191 -211
  107. package/lib/sessions/persistent-session.js.map +1 -0
  108. package/lib/token-manager.d.ts +191 -0
  109. package/lib/token-manager.js +390 -465
  110. package/lib/token-manager.js.map +1 -0
  111. package/lib/util/config.d.ts +86 -0
  112. package/lib/util/config.js +124 -152
  113. package/lib/util/config.js.map +1 -0
  114. package/lib/util/errors.d.ts +50 -0
  115. package/lib/util/errors.js +134 -145
  116. package/lib/util/errors.js.map +1 -0
  117. package/lib/util/exponential-backoff.d.ts +11 -0
  118. package/lib/util/exponential-backoff.js +10 -22
  119. package/lib/util/exponential-backoff.js.map +1 -0
  120. package/lib/util/paging-iterator.d.ts +53 -0
  121. package/lib/util/paging-iterator.js +202 -218
  122. package/lib/util/paging-iterator.js.map +1 -0
  123. package/lib/util/url-path.d.ts +16 -0
  124. package/lib/util/url-path.js +20 -35
  125. package/lib/util/url-path.js.map +1 -0
  126. 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;