box-node-sdk 1.36.0 → 1.38.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.
Files changed (126) hide show
  1. package/CHANGELOG.md +45 -3
  2. package/README.md +3 -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 +137 -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 +179 -0
  46. package/lib/managers/events.js +232 -254
  47. package/lib/managers/events.js.map +1 -0
  48. package/lib/managers/files.d.ts +773 -0
  49. package/lib/managers/files.js +1401 -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 -630
  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 -288
  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 +251 -0
  67. package/lib/managers/retention-policies.js +278 -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 +130 -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 +146 -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 +14 -3
@@ -1,28 +1,22 @@
1
+ "use strict";
1
2
  /**
2
3
  * @fileoverview Manager for the Box Folders Resource
3
4
  */
4
-
5
- 'use strict';
6
-
7
- // ------------------------------------------------------------------------------
8
- // Requirements
9
- // ------------------------------------------------------------------------------
10
- var urlPath = require('../util/url-path'),
11
- errors = require('../util/errors');
12
-
13
-
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ var url_path_1 = __importDefault(require("../util/url-path"));
9
+ var errors_1 = __importDefault(require("../util/errors"));
10
+ // -----------------------------------------------------------------------------
11
+ // Typedefs
12
+ // -----------------------------------------------------------------------------
14
13
  // ------------------------------------------------------------------------------
15
14
  // Private
16
15
  // ------------------------------------------------------------------------------
17
- var BASE_PATH = '/folders',
18
- FOLDER_LOCK = '/folder_locks',
19
- WATERMARK_SUBRESOURCE = '/watermark';
20
-
21
-
16
+ var BASE_PATH = '/folders', FOLDER_LOCK = '/folder_locks', WATERMARK_SUBRESOURCE = '/watermark';
22
17
  // ------------------------------------------------------------------------------
23
18
  // Public
24
19
  // ------------------------------------------------------------------------------
25
-
26
20
  /**
27
21
  * Simple manager for interacting with all 'Folder' endpoints and actions.
28
22
  *
@@ -30,618 +24,545 @@ var BASE_PATH = '/folders',
30
24
  * @param {BoxClient} client - The Box API Client that is responsible for making calls to the API
31
25
  * @returns {void}
32
26
  */
33
- function Folders(client) {
34
- this.client = client;
35
- }
36
-
37
- /**
38
- * Requests a folder object with the given ID.
39
- *
40
- * API Endpoint: '/folders/:folderID'
41
- * Method: GET
42
- *
43
- * @param {string} folderID - Box ID of the folder being requested
44
- * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
45
- * @param {Function} [callback] - Passed the folder information if it was acquired successfully
46
- * @returns {Promise<Object>} A promise resolving to the folder object
47
- */
48
- Folders.prototype.get = function(folderID, options, callback) {
49
- var params = {
50
- qs: options
51
- };
52
- var apiPath = urlPath(BASE_PATH, folderID);
53
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
54
- };
55
-
56
- /**
57
- * Requests items contained within a given folder.
58
- *
59
- * API Endpoint: '/folders/:folderID/items'
60
- * Method: GET
61
- *
62
- * @param {string} folderID - Box ID of the folder being requested
63
- * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
64
- * @param {Function} [callback] - Passed the folder information if it was acquired successfully
65
- * @returns {Promise<Object>} A promise resolving to the collection of the items in the folder
66
- */
67
- Folders.prototype.getItems = function(folderID, options, callback) {
68
- var params = {
69
- qs: options
70
- };
71
- var apiPath = urlPath(BASE_PATH, folderID, '/items');
72
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
73
- };
74
-
75
- /**
76
- * Requests collaborations on a given folder.
77
- *
78
- * API Endpoint: '/folders/:folderID/collaborations'
79
- * Method: GET
80
- *
81
- * @param {string} folderID - Box ID of the folder being requested
82
- * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
83
- * @param {Function} [callback] - Passed the folder information if it was acquired successfully
84
- * @returns {Promise<Object>} A promise resolving to the collection of collaborations
85
- */
86
- Folders.prototype.getCollaborations = function(folderID, options, callback) {
87
- var params = {
88
- qs: options
89
- };
90
- var apiPath = urlPath(BASE_PATH, folderID, '/collaborations');
91
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
92
- };
93
-
94
- /**
95
- * Creates a new Folder within a parent folder
96
- *
97
- * API Endpoint: '/folders
98
- * Method: POST
99
- *
100
- * @param {string} parentFolderID - Box folder id of the folder to add into
101
- * @param {string} name - The name for the new folder
102
- * @param {Function} [callback] - passed the new folder info if call was successful
103
- * @returns {Promise<Object>} A promise resolving to the created folder object
104
- */
105
- Folders.prototype.create = function(parentFolderID, name, callback) {
106
- var params = {
107
- body: {
108
- name,
109
- parent: {
110
- id: parentFolderID
111
- }
112
- }
113
- };
114
- return this.client.wrapWithDefaultHandler(this.client.post)(BASE_PATH, params, callback);
115
- };
116
-
117
- /**
118
- * Copy a folder into a new, different folder
119
- *
120
- * API Endpoint: '/folders/:folderID/copy
121
- * Method: POST
122
- *
123
- * @param {string} folderID - The Box ID of the folder being requested
124
- * @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files.
125
- * @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases
126
- * @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder
127
- * @param {Function} [callback] - passed the new folder info if call was successful
128
- * @returns {Promise<Object>} A promise resolving to the new folder object
129
- */
130
- Folders.prototype.copy = function(folderID, newParentID, options, callback) {
131
-
132
- // @NOTE(mwiller) 2016-10-25: Shuffle arguments to maintain backward compatibility
133
- // This can be removed at the v2.0 update
134
- if (typeof options === 'function') {
135
- callback = options;
136
- options = {};
137
- }
138
-
139
- options = options || {};
140
-
141
- options.parent = {
142
- id: newParentID
143
- };
144
-
145
- var params = {
146
- body: options
147
- };
148
- var apiPath = urlPath(BASE_PATH, folderID, '/copy');
149
- return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
150
- };
151
-
152
- /**
153
- * Update some information about a given folder.
154
- *
155
- * API Endpoint: '/folders/:folderID'
156
- * Method: PUT
157
- *
158
- * @param {string} folderID - The Box ID of the folder being requested
159
- * @param {Object} updates - Folder fields to update
160
- * @param {string} [updates.etag] Only update the folder if the ETag matches
161
- * @param {Function} [callback] - Passed the updated folder information if it was acquired successfully
162
- * @returns {Promise<Object>} A promise resolving to the updated folder object
163
- */
164
- Folders.prototype.update = function(folderID, updates, callback) {
165
- var params = {
166
- body: updates
167
- };
168
-
169
- if (updates && updates.etag) {
170
- params.headers = {
171
- 'If-Match': updates.etag
172
- };
173
- delete updates.etag;
174
- }
175
-
176
- var apiPath = urlPath(BASE_PATH, folderID);
177
- return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
178
- };
179
-
180
- /**
181
- * Add a folder to a given collection
182
- *
183
- * API Endpoint: '/folders/:folderID'
184
- * Method: PUT
185
- *
186
- * @param {string} folderID - The folder to add to the collection
187
- * @param {string} collectionID - The collection to add the folder to
188
- * @param {Function} [callback] - Passed the updated folder if successful, error otherwise
189
- * @returns {Promise<Object>} A promise resolving to the updated folder object
190
- */
191
- Folders.prototype.addToCollection = function(folderID, collectionID, callback) {
192
-
193
- return this.get(folderID, {fields: 'collections'})
194
- .then(data => {
195
-
196
- var collections = data.collections || [];
197
-
198
- // Convert to correct format
199
- collections = collections.map(c => ({id: c.id}));
200
-
201
- if (!collections.find(c => c.id === collectionID)) {
202
-
203
- collections.push({id: collectionID});
204
- }
205
-
206
- return this.update(folderID, {collections});
207
- })
208
- .asCallback(callback);
209
- };
210
-
211
- /**
212
- * Remove a folder from a given collection
213
- *
214
- * API Endpoint: '/folders/:folderID'
215
- * Method: PUT
216
- *
217
- * @param {string} folderID - The folder to remove from the collection
218
- * @param {string} collectionID - The collection to remove the folder from
219
- * @param {Function} [callback] - Passed the updated folder if successful, error otherwise
220
- * @returns {Promise<Object>} A promise resolving to the updated folder object
221
- */
222
- Folders.prototype.removeFromCollection = function(folderID, collectionID, callback) {
223
-
224
- return this.get(folderID, {fields: 'collections'})
225
- .then(data => {
226
-
227
- var collections = data.collections || [];
228
- // Convert to correct object format and remove the specified collection
229
- collections = collections.map(c => ({id: c.id})).filter(c => c.id !== collectionID);
230
-
231
- return this.update(folderID, {collections});
232
- })
233
- .asCallback(callback);
234
- };
235
-
236
- /**
237
- * Move a folder into a new parent folder.
238
- *
239
- * API Endpoint: '/folders/:folderID'
240
- * Method: PUT
241
- *
242
- * @param {string} folderID - The Box ID of the folder being requested
243
- * @param {string} newParentID - The Box ID for the new parent folder. '0' to move to All Files.
244
- * @param {Function} [callback] - Passed the updated folder information if it was acquired successfully
245
- * @returns {Promise<Object>} A promise resolving to the updated folder object
246
- */
247
- Folders.prototype.move = function(folderID, newParentID, callback) {
248
- var params = {
249
- body: {
250
- parent: {
251
- id: newParentID
252
- }
253
- }
254
- };
255
- var apiPath = urlPath(BASE_PATH, folderID);
256
- return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
257
- };
258
-
259
- /**
260
- * Delete a given folder.
261
- *
262
- * API Endpoint: '/folders/:folderID'
263
- * Method: DELETE
264
- *
265
- * @param {string} folderID - Box ID of the folder being requested
266
- * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
267
- * @param {string} [options.etag] Only delete the folder if the ETag matches
268
- * @param {Function} [callback] - Empty response body passed if successful.
269
- * @returns {Promise<void>} A promise resolving to nothing
270
- */
271
- Folders.prototype.delete = function(folderID, options, callback) {
272
-
273
- var params = {
274
- qs: options
275
- };
276
-
277
- if (options && options.etag) {
278
- params.headers = {
279
- 'If-Match': options.etag
280
- };
281
- delete options.etag;
282
- }
283
-
284
- var apiPath = urlPath(BASE_PATH, folderID);
285
- return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, params, callback);
286
- };
287
-
288
- /**
289
- * Retrieves all metadata associated with a folder.
290
- *
291
- * API Endpoint: '/folders/:folderID/metadata'
292
- * Method: GET
293
- *
294
- * @param {string} folderID - the ID of the folder to get metadata for
295
- * @param {Function} [callback] - called with an array of metadata when successful
296
- * @returns {Promise<Object>} A promise resolving to the collection of metadata on the folder
297
- */
298
- Folders.prototype.getAllMetadata = function(folderID, callback) {
299
-
300
- var apiPath = urlPath(BASE_PATH, folderID, 'metadata');
301
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
302
- };
303
-
304
- /**
305
- * Retrieve a single metadata template instance for a folder.
306
- *
307
- * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
308
- * Method: GET
309
- *
310
- * @param {string} folderID - The ID of the folder to retrive the metadata of
311
- * @param {string} scope - The scope of the metadata template, e.g. "global"
312
- * @param {string} template - The metadata template to retrieve
313
- * @param {Function} [callback] - Passed the metadata template if successful
314
- * @returns {Promise<Object>} A promise resolving to the metadata template
315
- */
316
- Folders.prototype.getMetadata = function(folderID, scope, template, callback) {
317
-
318
- var apiPath = urlPath(BASE_PATH, folderID, 'metadata', scope, template);
319
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
320
- };
321
-
322
- /**
323
- * Adds metadata to a folder. Metadata must either match a template schema or
324
- * be placed into the unstructured "properties" template in global scope.
325
- *
326
- * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
327
- * Method: POST
328
- *
329
- * @param {string} folderID - The ID of the folder to add metadata to
330
- * @param {string} scope - The scope of the metadata template, e.g. "enterprise"
331
- * @param {string} template - The metadata template schema to add
332
- * @param {Object} data - Key/value pairs tp add as metadata
333
- * @param {Function} [callback] - Called with error if unsuccessful
334
- * @returns {Promise<Object>} A promise resolving to the created metadata
335
- */
336
- Folders.prototype.addMetadata = function(folderID, scope, template, data, callback) {
337
-
338
- var apiPath = urlPath(BASE_PATH, folderID, 'metadata', scope, template),
339
- params = {
340
- body: data
341
- };
342
-
343
- return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
344
- };
345
-
346
- /**
347
- * Updates a metadata template instance with JSON Patch-formatted data.
348
- *
349
- * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
350
- * Method: PUT
351
- *
352
- * @param {string} folderID - The folder to update metadata for
353
- * @param {string} scope - The scope of the template to update
354
- * @param {string} template - The template to update
355
- * @param {Object} patch - The patch data
356
- * @param {Function} [callback] - Called with updated metadata if successful
357
- * @returns {Promise<Object>} A promise resolving to the updated metadata
358
- */
359
- Folders.prototype.updateMetadata = function(folderID, scope, template, patch, callback) {
360
-
361
- var apiPath = urlPath(BASE_PATH, folderID, 'metadata', scope, template),
362
- params = {
363
- body: patch,
364
- headers: {
365
- 'Content-Type': 'application/json-patch+json'
366
- }
367
- };
368
-
369
- return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
370
- };
371
-
372
- /**
373
- * Sets metadata on a folder, overwriting any metadata that exists for the provided keys.
374
- *
375
- * @param {string} folderID - The folder to set metadata on
376
- * @param {string} scope - The scope of the metadata template
377
- * @param {string} template - The key of the metadata template
378
- * @param {Object} metadata - The metadata to set
379
- * @param {Function} [callback] - Called with updated metadata if successful
380
- * @returns {Promise<Object>} A promise resolving to the updated metadata
381
- */
382
- Folders.prototype.setMetadata = function(folderID, scope, template, metadata, callback) {
383
-
384
- return this.addMetadata(folderID, scope, template, metadata)
385
- .catch(err => {
386
-
387
- if (err.statusCode !== 409) {
388
- throw err;
389
- }
390
-
391
- // Metadata already exists on the file; update instead
392
- var updates = Object.keys(metadata).map(key => ({
393
- op: 'add',
394
- path: `/${key}`,
395
- value: metadata[key],
396
- }));
397
-
398
- return this.updateMetadata(folderID, scope, template, updates);
399
- })
400
- .asCallback(callback);
401
- };
402
-
403
- /**
404
- * Deletes a metadata template from a folder.
405
- *
406
- * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
407
- * Method: DELETE
408
- *
409
- * @param {string} folderID - The ID of the folder to remove metadata from
410
- * @param {string} scope - The scope of the metadata template
411
- * @param {string} template - The template to remove from the folder
412
- * @param {Function} [callback] - Called with nothing if successful, error otherwise
413
- * @returns {Promise<void>} A promise resolving to nothing
414
- */
415
- Folders.prototype.deleteMetadata = function(folderID, scope, template, callback) {
416
-
417
- var apiPath = urlPath(BASE_PATH, folderID, 'metadata', scope, template);
418
- return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
419
- };
420
-
421
- /**
422
- * Retrieves a folder that has been moved to the trash
423
- *
424
- * API Endpoint: '/folders/:folderID/trash'
425
- * Method: GET
426
- *
427
- * @param {string} folderID - The ID of the folder being requested
428
- * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
429
- * @param {Funnction} [callback] - Passed the folder information if it was acquired successfully
430
- * @returns {Promise<Object>} A promise resolving to the trashed folder object
431
- */
432
- Folders.prototype.getTrashedFolder = function(folderID, options, callback) {
433
- var params = {
434
- qs: options
435
- };
436
-
437
- var apiPath = urlPath(BASE_PATH, folderID, 'trash');
438
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
439
- };
440
-
441
- /**
442
- * Restores an item that has been moved to the trash. Default behavior is to restore the item
443
- * to the folder it was in before it was moved to the trash. If that parent folder no longer
444
- * exists or if there is now an item with the same name in that parent folder, the new parent
445
- * older and/or new name will need to be included in the request.
446
- *
447
- * API Endpoint: '/folders/:folderID'
448
- * Method: POST
449
- *
450
- * @param {string} folderID - The ID of the folder to restore
451
- * @param {Object} [options] - Optional parameters, can be left null
452
- * @param {?string} [options.name] - The new name for this item
453
- * @param {string} [options.parent_id] - The new parent folder for this item
454
- * @param {Function} [callback] - Called with folder information if successful, error otherwise
455
- * @returns {Promise<Object>} A promise resolving to the restored folder object
456
- */
457
- Folders.prototype.restoreFromTrash = function(folderID, options, callback) {
458
-
459
- // Set up the parent_id parameter
460
- if (options && options.parent_id) {
461
-
462
- options.parent = {
463
- id: options.parent_id
464
- };
465
-
466
- delete options.parent_id;
467
- }
468
-
469
- var apiPath = urlPath(BASE_PATH, folderID),
470
- params = {
471
- body: options || {}
472
- };
473
-
474
- return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
475
- };
476
-
477
- /**
478
- * Permanently deletes an folder that is in the trash. The item will no longer exist in Box. This action cannot be undone
479
- *
480
- * API Endpoint: '/folders/:folderID/trash'
481
- * Method: DELETE
482
- *
483
- * @param {string} folderID Box ID of the folder being requested
484
- * @param {Object} [options] Optional parameters
485
- * @param {string} [options.etag] Only delete the folder if the ETag matches
486
- * @param {Function} [callback] Called with nothing if successful, error otherwise
487
- * @returns {Promise<void>} A promise resolving to nothing
488
- */
489
- Folders.prototype.deletePermanently = function(folderID, options, callback) {
490
-
491
- // Switch around arguments if necessary for backwards compatibility
492
- if (typeof options === 'function') {
493
- callback = options;
494
- options = {};
495
- }
496
-
497
- var params = {};
498
-
499
- if (options && options.etag) {
500
- params.headers = {
501
- 'If-Match': options.etag
502
- };
503
- }
504
-
505
- var apiPath = urlPath(BASE_PATH, folderID, '/trash');
506
- return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, params, callback);
507
- };
508
-
509
- /**
510
- * Used to retrieve the watermark for a corresponding Box folder.
511
- *
512
- * API Endpoint: '/folders/:folderID/watermark'
513
- * Method: GET
514
- *
515
- * @param {string} folderID - The Box ID of the folder to get watermark for
516
- * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
517
- * @param {Function} [callback] - Passed the watermark information if successful, error otherwise
518
- * @returns {Promise<Object>} A promise resolving to the watermark info
519
- */
520
- Folders.prototype.getWatermark = function(folderID, options, callback) {
521
-
522
- var apiPath = urlPath(BASE_PATH, folderID, WATERMARK_SUBRESOURCE),
523
- params = {
524
- qs: options
525
- };
526
-
527
- return this.client.get(apiPath, params)
528
- .then(response => {
529
-
530
- if (response.statusCode !== 200) {
531
- throw errors.buildUnexpectedResponseError(response);
532
- }
533
-
534
- return response.body.watermark;
535
- })
536
- .asCallback(callback);
537
- };
538
-
539
- /**
540
- * Used to apply or update the watermark for a corresponding Box folder.
541
- *
542
- * API Endpoint: '/folders/:folderID/watermark'
543
- * Method: PUT
544
- *
545
- * @param {string} folderID - The Box ID of the folder to update watermark for
546
- * @param {Object} [options] - Optional parameters, can be left null
547
- * @param {Function} [callback] - Passed the watermark information if successful, error otherwise
548
- * @returns {Promise<Object>} A promise resolving to the watermark info
549
- */
550
- Folders.prototype.applyWatermark = function(folderID, options, callback) {
551
- var apiPath = urlPath(BASE_PATH, folderID, WATERMARK_SUBRESOURCE),
552
- params = {
553
- body: {
554
- watermark: {
555
- imprint: 'default' // Currently the API only supports default imprint
556
- }
557
- }
558
- };
559
-
560
- Object.assign(params.body.watermark, options);
561
-
562
- return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
563
- };
564
-
565
- /**
566
- * Used to remove the watermark for a corresponding Box folder.
567
- *
568
- * API Endpoint: '/folders/:folderID/watermark'
569
- * Method: DELETE
570
- *
571
- * @param {string} folderID - The Box ID of the folder to remove watermark from
572
- * @param {Function} [callback] - Empty response body passed if successful, error otherwise
573
- * @returns {Promise<void>} A promise resolving to nothing
574
- */
575
- Folders.prototype.removeWatermark = function(folderID, callback) {
576
-
577
- var apiPath = urlPath(BASE_PATH, folderID, WATERMARK_SUBRESOURCE);
578
-
579
- return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
580
- };
581
-
582
- /**
583
- * Used to lock a Box folder.
584
- *
585
- * API Endpoint: '/folder_locks'
586
- * Method: POST
587
- *
588
- * @param {string} folderID - The Box ID of the folder to lock
589
- * @param {Function} [callback] - Passed the folder lock object if successful, error otherwise
590
- * @returns {Promise<void>} A promise resolving to a folder lock object
591
- */
592
- Folders.prototype.lock = function(folderID, callback) {
593
- var params = {
594
- body: {
595
- folder: {
596
- type: 'folder',
597
- id: folderID
598
- },
599
- locked_operations: {
600
- move: true,
601
- delete: true
602
- }
603
- }
604
- };
605
- return this.client.wrapWithDefaultHandler(this.client.post)(FOLDER_LOCK, params, callback);
606
- };
607
-
608
- /**
609
- * Used to get all locks on a folder.
610
- *
611
- * API Endpoint: '/folder_locks'
612
- * Method: GET
613
- *
614
- * @param {string} folderID - The Box ID of the folder to lock
615
- * @param {Function} [callback] - Passed a collection of folder lock objects if successful, error otherwise
616
- * @returns {Promise<void>} A promise resolving to a collection of folder lock objects
617
- */
618
- Folders.prototype.getLocks = function(folderID, callback) {
619
- var params = {
620
- qs: {
621
- folder_id: folderID
622
- }
623
- };
624
- return this.client.wrapWithDefaultHandler(this.client.get)(FOLDER_LOCK, params, callback);
625
- };
626
-
627
- /**
628
- * Used to delete a lock on a folder.
629
- *
630
- * API Endpoint: '/folder_locks/:folderLockID'
631
- * Method: DELETE
632
- *
633
- * @param {string} folderLockID - The Box ID of the folder lock
634
- * @param {Function} [callback] - Empty response body passed if successful, error otherwise
635
- * @returns {Promise<void>} A promise resolving to nothing
636
- */
637
- Folders.prototype.deleteLock = function(folderLockID, callback) {
638
-
639
- var apiPath = urlPath(FOLDER_LOCK, folderLockID);
640
-
641
- return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
642
- };
643
- /**
644
- * @module box-node-sdk/lib/managers/folders
645
- * @see {@Link Folders}
646
- */
27
+ var Folders = /** @class */ (function () {
28
+ function Folders(client) {
29
+ this.client = client;
30
+ }
31
+ /**
32
+ * Requests a folder object with the given ID.
33
+ *
34
+ * API Endpoint: '/folders/:folderID'
35
+ * Method: GET
36
+ *
37
+ * @param {string} folderID - Box ID of the folder being requested
38
+ * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
39
+ * @param {Function} [callback] - Passed the folder information if it was acquired successfully
40
+ * @returns {Promise<Object>} A promise resolving to the folder object
41
+ */
42
+ Folders.prototype.get = function (folderID, options, callback) {
43
+ var params = {
44
+ qs: options,
45
+ };
46
+ var apiPath = url_path_1.default(BASE_PATH, folderID);
47
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
48
+ };
49
+ /**
50
+ * Requests items contained within a given folder.
51
+ *
52
+ * API Endpoint: '/folders/:folderID/items'
53
+ * Method: GET
54
+ *
55
+ * @param {string} folderID - Box ID of the folder being requested
56
+ * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
57
+ * @param {Function} [callback] - Passed the folder information if it was acquired successfully
58
+ * @returns {Promise<Object>} A promise resolving to the collection of the items in the folder
59
+ */
60
+ Folders.prototype.getItems = function (folderID, options, callback) {
61
+ var params = {
62
+ qs: options,
63
+ };
64
+ var apiPath = url_path_1.default(BASE_PATH, folderID, '/items');
65
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
66
+ };
67
+ /**
68
+ * Requests collaborations on a given folder.
69
+ *
70
+ * API Endpoint: '/folders/:folderID/collaborations'
71
+ * Method: GET
72
+ *
73
+ * @param {string} folderID - Box ID of the folder being requested
74
+ * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
75
+ * @param {Function} [callback] - Passed the folder information if it was acquired successfully
76
+ * @returns {Promise<Object>} A promise resolving to the collection of collaborations
77
+ */
78
+ Folders.prototype.getCollaborations = function (folderID, options, callback) {
79
+ var params = {
80
+ qs: options,
81
+ };
82
+ var apiPath = url_path_1.default(BASE_PATH, folderID, '/collaborations');
83
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
84
+ };
85
+ /**
86
+ * Creates a new Folder within a parent folder
87
+ *
88
+ * API Endpoint: '/folders
89
+ * Method: POST
90
+ *
91
+ * @param {string} parentFolderID - Box folder id of the folder to add into
92
+ * @param {string} name - The name for the new folder
93
+ * @param {Function} [callback] - passed the new folder info if call was successful
94
+ * @returns {Promise<Object>} A promise resolving to the created folder object
95
+ */
96
+ Folders.prototype.create = function (parentFolderID, name, callback) {
97
+ var params = {
98
+ body: {
99
+ name: name,
100
+ parent: {
101
+ id: parentFolderID,
102
+ },
103
+ },
104
+ };
105
+ return this.client.wrapWithDefaultHandler(this.client.post)(BASE_PATH, params, callback);
106
+ };
107
+ /**
108
+ * Copy a folder into a new, different folder
109
+ *
110
+ * API Endpoint: '/folders/:folderID/copy
111
+ * Method: POST
112
+ *
113
+ * @param {string} folderID - The Box ID of the folder being requested
114
+ * @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files.
115
+ * @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases
116
+ * @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder
117
+ * @param {Function} [callback] - passed the new folder info if call was successful
118
+ * @returns {Promise<Object>} A promise resolving to the new folder object
119
+ */
120
+ Folders.prototype.copy = function (folderID, newParentID, options, callback) {
121
+ // @NOTE(mwiller) 2016-10-25: Shuffle arguments to maintain backward compatibility
122
+ // This can be removed at the v2.0 update
123
+ if (typeof options === 'function') {
124
+ callback = options;
125
+ options = {};
126
+ }
127
+ options = options || {};
128
+ options.parent = {
129
+ id: newParentID,
130
+ };
131
+ var params = {
132
+ body: options,
133
+ };
134
+ var apiPath = url_path_1.default(BASE_PATH, folderID, '/copy');
135
+ return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
136
+ };
137
+ /**
138
+ * Update some information about a given folder.
139
+ *
140
+ * API Endpoint: '/folders/:folderID'
141
+ * Method: PUT
142
+ *
143
+ * @param {string} folderID - The Box ID of the folder being requested
144
+ * @param {Object} updates - Folder fields to update
145
+ * @param {string} [updates.etag] Only update the folder if the ETag matches
146
+ * @param {Function} [callback] - Passed the updated folder information if it was acquired successfully
147
+ * @returns {Promise<Object>} A promise resolving to the updated folder object
148
+ */
149
+ Folders.prototype.update = function (folderID, updates, callback) {
150
+ var params = {
151
+ body: updates,
152
+ };
153
+ if (updates && updates.etag) {
154
+ params.headers = {
155
+ 'If-Match': updates.etag,
156
+ };
157
+ delete updates.etag;
158
+ }
159
+ var apiPath = url_path_1.default(BASE_PATH, folderID);
160
+ return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
161
+ };
162
+ /**
163
+ * Add a folder to a given collection
164
+ *
165
+ * API Endpoint: '/folders/:folderID'
166
+ * Method: PUT
167
+ *
168
+ * @param {string} folderID - The folder to add to the collection
169
+ * @param {string} collectionID - The collection to add the folder to
170
+ * @param {Function} [callback] - Passed the updated folder if successful, error otherwise
171
+ * @returns {Promise<Object>} A promise resolving to the updated folder object
172
+ */
173
+ Folders.prototype.addToCollection = function (folderID, collectionID, callback) {
174
+ var _this = this;
175
+ return this.get(folderID, { fields: 'collections' })
176
+ .then(function (data /* FIXME */) {
177
+ var collections = data.collections || [];
178
+ // Convert to correct format
179
+ collections = collections.map(function (c /* FIXME */) { return ({ id: c.id }); });
180
+ if (!collections.find(function (c /* FIXME */) { return c.id === collectionID; })) {
181
+ collections.push({ id: collectionID });
182
+ }
183
+ return _this.update(folderID, { collections: collections });
184
+ })
185
+ .asCallback(callback);
186
+ };
187
+ /**
188
+ * Remove a folder from a given collection
189
+ *
190
+ * API Endpoint: '/folders/:folderID'
191
+ * Method: PUT
192
+ *
193
+ * @param {string} folderID - The folder to remove from the collection
194
+ * @param {string} collectionID - The collection to remove the folder from
195
+ * @param {Function} [callback] - Passed the updated folder if successful, error otherwise
196
+ * @returns {Promise<Object>} A promise resolving to the updated folder object
197
+ */
198
+ Folders.prototype.removeFromCollection = function (folderID, collectionID, callback) {
199
+ var _this = this;
200
+ return this.get(folderID, { fields: 'collections' })
201
+ .then(function (data /* FIXME */) {
202
+ var collections = data.collections || [];
203
+ // Convert to correct object format and remove the specified collection
204
+ collections = collections
205
+ .map(function (c /* FIXME */) { return ({ id: c.id }); })
206
+ .filter(function (c /* FIXME */) { return c.id !== collectionID; });
207
+ return _this.update(folderID, { collections: collections });
208
+ })
209
+ .asCallback(callback);
210
+ };
211
+ /**
212
+ * Move a folder into a new parent folder.
213
+ *
214
+ * API Endpoint: '/folders/:folderID'
215
+ * Method: PUT
216
+ *
217
+ * @param {string} folderID - The Box ID of the folder being requested
218
+ * @param {string} newParentID - The Box ID for the new parent folder. '0' to move to All Files.
219
+ * @param {Function} [callback] - Passed the updated folder information if it was acquired successfully
220
+ * @returns {Promise<Object>} A promise resolving to the updated folder object
221
+ */
222
+ Folders.prototype.move = function (folderID, newParentID, callback) {
223
+ var params = {
224
+ body: {
225
+ parent: {
226
+ id: newParentID,
227
+ },
228
+ },
229
+ };
230
+ var apiPath = url_path_1.default(BASE_PATH, folderID);
231
+ return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
232
+ };
233
+ /**
234
+ * Delete a given folder.
235
+ *
236
+ * API Endpoint: '/folders/:folderID'
237
+ * Method: DELETE
238
+ *
239
+ * @param {string} folderID - Box ID of the folder being requested
240
+ * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
241
+ * @param {string} [options.etag] Only delete the folder if the ETag matches
242
+ * @param {Function} [callback] - Empty response body passed if successful.
243
+ * @returns {Promise<void>} A promise resolving to nothing
244
+ */
245
+ Folders.prototype.delete = function (folderID, options, callback) {
246
+ var params = {
247
+ qs: options,
248
+ };
249
+ if (options && options.etag) {
250
+ params.headers = {
251
+ 'If-Match': options.etag,
252
+ };
253
+ delete options.etag;
254
+ }
255
+ var apiPath = url_path_1.default(BASE_PATH, folderID);
256
+ return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, params, callback);
257
+ };
258
+ /**
259
+ * Retrieves all metadata associated with a folder.
260
+ *
261
+ * API Endpoint: '/folders/:folderID/metadata'
262
+ * Method: GET
263
+ *
264
+ * @param {string} folderID - the ID of the folder to get metadata for
265
+ * @param {Function} [callback] - called with an array of metadata when successful
266
+ * @returns {Promise<Object>} A promise resolving to the collection of metadata on the folder
267
+ */
268
+ Folders.prototype.getAllMetadata = function (folderID, callback) {
269
+ var apiPath = url_path_1.default(BASE_PATH, folderID, 'metadata');
270
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
271
+ };
272
+ /**
273
+ * Retrieve a single metadata template instance for a folder.
274
+ *
275
+ * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
276
+ * Method: GET
277
+ *
278
+ * @param {string} folderID - The ID of the folder to retrive the metadata of
279
+ * @param {string} scope - The scope of the metadata template, e.g. "global"
280
+ * @param {string} template - The metadata template to retrieve
281
+ * @param {Function} [callback] - Passed the metadata template if successful
282
+ * @returns {Promise<Object>} A promise resolving to the metadata template
283
+ */
284
+ Folders.prototype.getMetadata = function (folderID, scope, template, callback) {
285
+ var apiPath = url_path_1.default(BASE_PATH, folderID, 'metadata', scope, template);
286
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
287
+ };
288
+ /**
289
+ * Adds metadata to a folder. Metadata must either match a template schema or
290
+ * be placed into the unstructured "properties" template in global scope.
291
+ *
292
+ * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
293
+ * Method: POST
294
+ *
295
+ * @param {string} folderID - The ID of the folder to add metadata to
296
+ * @param {string} scope - The scope of the metadata template, e.g. "enterprise"
297
+ * @param {string} template - The metadata template schema to add
298
+ * @param {Object} data - Key/value pairs to add as metadata
299
+ * @param {Function} [callback] - Called with error if unsuccessful
300
+ * @returns {Promise<Object>} A promise resolving to the created metadata
301
+ */
302
+ Folders.prototype.addMetadata = function (folderID, scope, template, data, callback) {
303
+ var apiPath = url_path_1.default(BASE_PATH, folderID, 'metadata', scope, template), params = {
304
+ body: data,
305
+ };
306
+ return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
307
+ };
308
+ /**
309
+ * Updates a metadata template instance with JSON Patch-formatted data.
310
+ *
311
+ * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
312
+ * Method: PUT
313
+ *
314
+ * @param {string} folderID - The folder to update metadata for
315
+ * @param {string} scope - The scope of the template to update
316
+ * @param {string} template - The template to update
317
+ * @param {Object} patch - The patch data
318
+ * @param {Function} [callback] - Called with updated metadata if successful
319
+ * @returns {Promise<Object>} A promise resolving to the updated metadata
320
+ */
321
+ Folders.prototype.updateMetadata = function (folderID, scope, template, patch, callback) {
322
+ var apiPath = url_path_1.default(BASE_PATH, folderID, 'metadata', scope, template), params = {
323
+ body: patch,
324
+ headers: {
325
+ 'Content-Type': 'application/json-patch+json',
326
+ },
327
+ };
328
+ return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
329
+ };
330
+ /**
331
+ * Sets metadata on a folder, overwriting any metadata that exists for the provided keys.
332
+ *
333
+ * @param {string} folderID - The folder to set metadata on
334
+ * @param {string} scope - The scope of the metadata template
335
+ * @param {string} template - The key of the metadata template
336
+ * @param {Object} metadata - The metadata to set
337
+ * @param {Function} [callback] - Called with updated metadata if successful
338
+ * @returns {Promise<Object>} A promise resolving to the updated metadata
339
+ */
340
+ Folders.prototype.setMetadata = function (folderID, scope, template, metadata, callback) {
341
+ var _this = this;
342
+ return this.addMetadata(folderID, scope, template, metadata)
343
+ .catch(function (err /* FIXME */) {
344
+ if (err.statusCode !== 409) {
345
+ throw err;
346
+ }
347
+ // Metadata already exists on the file; update instead
348
+ var updates = Object.keys(metadata).map(function (key) { return ({
349
+ op: 'add',
350
+ path: "/" + key,
351
+ value: metadata[key],
352
+ }); });
353
+ return _this.updateMetadata(folderID, scope, template, updates);
354
+ })
355
+ .asCallback(callback);
356
+ };
357
+ /**
358
+ * Deletes a metadata template from a folder.
359
+ *
360
+ * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
361
+ * Method: DELETE
362
+ *
363
+ * @param {string} folderID - The ID of the folder to remove metadata from
364
+ * @param {string} scope - The scope of the metadata template
365
+ * @param {string} template - The template to remove from the folder
366
+ * @param {Function} [callback] - Called with nothing if successful, error otherwise
367
+ * @returns {Promise<void>} A promise resolving to nothing
368
+ */
369
+ Folders.prototype.deleteMetadata = function (folderID, scope, template, callback) {
370
+ var apiPath = url_path_1.default(BASE_PATH, folderID, 'metadata', scope, template);
371
+ return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
372
+ };
373
+ /**
374
+ * Retrieves a folder that has been moved to the trash
375
+ *
376
+ * API Endpoint: '/folders/:folderID/trash'
377
+ * Method: GET
378
+ *
379
+ * @param {string} folderID - The ID of the folder being requested
380
+ * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
381
+ * @param {Funnction} [callback] - Passed the folder information if it was acquired successfully
382
+ * @returns {Promise<Object>} A promise resolving to the trashed folder object
383
+ */
384
+ Folders.prototype.getTrashedFolder = function (folderID, options, callback) {
385
+ var params = {
386
+ qs: options,
387
+ };
388
+ var apiPath = url_path_1.default(BASE_PATH, folderID, 'trash');
389
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
390
+ };
391
+ /**
392
+ * Restores an item that has been moved to the trash. Default behavior is to restore the item
393
+ * to the folder it was in before it was moved to the trash. If that parent folder no longer
394
+ * exists or if there is now an item with the same name in that parent folder, the new parent
395
+ * older and/or new name will need to be included in the request.
396
+ *
397
+ * API Endpoint: '/folders/:folderID'
398
+ * Method: POST
399
+ *
400
+ * @param {string} folderID - The ID of the folder to restore
401
+ * @param {Object} [options] - Optional parameters, can be left null
402
+ * @param {?string} [options.name] - The new name for this item
403
+ * @param {string} [options.parent_id] - The new parent folder for this item
404
+ * @param {Function} [callback] - Called with folder information if successful, error otherwise
405
+ * @returns {Promise<Object>} A promise resolving to the restored folder object
406
+ */
407
+ Folders.prototype.restoreFromTrash = function (folderID, options, callback) {
408
+ // Set up the parent_id parameter
409
+ if (options && options.parent_id) {
410
+ options.parent = {
411
+ id: options.parent_id,
412
+ };
413
+ delete options.parent_id;
414
+ }
415
+ var apiPath = url_path_1.default(BASE_PATH, folderID), params = {
416
+ body: options || {},
417
+ };
418
+ return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
419
+ };
420
+ /**
421
+ * Permanently deletes an folder that is in the trash. The item will no longer exist in Box. This action cannot be undone
422
+ *
423
+ * API Endpoint: '/folders/:folderID/trash'
424
+ * Method: DELETE
425
+ *
426
+ * @param {string} folderID Box ID of the folder being requested
427
+ * @param {Object} [options] Optional parameters
428
+ * @param {string} [options.etag] Only delete the folder if the ETag matches
429
+ * @param {Function} [callback] Called with nothing if successful, error otherwise
430
+ * @returns {Promise<void>} A promise resolving to nothing
431
+ */
432
+ Folders.prototype.deletePermanently = function (folderID, options, callback) {
433
+ // Switch around arguments if necessary for backwards compatibility
434
+ if (typeof options === 'function') {
435
+ callback = options;
436
+ options = {};
437
+ }
438
+ var params = {};
439
+ if (options && options.etag) {
440
+ params.headers = {
441
+ 'If-Match': options.etag,
442
+ };
443
+ }
444
+ var apiPath = url_path_1.default(BASE_PATH, folderID, '/trash');
445
+ return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, params, callback);
446
+ };
447
+ /**
448
+ * Used to retrieve the watermark for a corresponding Box folder.
449
+ *
450
+ * API Endpoint: '/folders/:folderID/watermark'
451
+ * Method: GET
452
+ *
453
+ * @param {string} folderID - The Box ID of the folder to get watermark for
454
+ * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
455
+ * @param {Function} [callback] - Passed the watermark information if successful, error otherwise
456
+ * @returns {Promise<Object>} A promise resolving to the watermark info
457
+ */
458
+ Folders.prototype.getWatermark = function (folderID, options, callback) {
459
+ var apiPath = url_path_1.default(BASE_PATH, folderID, WATERMARK_SUBRESOURCE), params = {
460
+ qs: options,
461
+ };
462
+ return this.client
463
+ .get(apiPath, params)
464
+ .then(function (response /* FIXME */) {
465
+ if (response.statusCode !== 200) {
466
+ throw errors_1.default.buildUnexpectedResponseError(response);
467
+ }
468
+ return response.body.watermark;
469
+ })
470
+ .asCallback(callback);
471
+ };
472
+ /**
473
+ * Used to apply or update the watermark for a corresponding Box folder.
474
+ *
475
+ * API Endpoint: '/folders/:folderID/watermark'
476
+ * Method: PUT
477
+ *
478
+ * @param {string} folderID - The Box ID of the folder to update watermark for
479
+ * @param {Object} [options] - Optional parameters, can be left null
480
+ * @param {Function} [callback] - Passed the watermark information if successful, error otherwise
481
+ * @returns {Promise<Object>} A promise resolving to the watermark info
482
+ */
483
+ Folders.prototype.applyWatermark = function (folderID, options, callback) {
484
+ var apiPath = url_path_1.default(BASE_PATH, folderID, WATERMARK_SUBRESOURCE), params = {
485
+ body: {
486
+ watermark: {
487
+ imprint: 'default', // Currently the API only supports default imprint
488
+ },
489
+ },
490
+ };
491
+ Object.assign(params.body.watermark, options);
492
+ return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
493
+ };
494
+ /**
495
+ * Used to remove the watermark for a corresponding Box folder.
496
+ *
497
+ * API Endpoint: '/folders/:folderID/watermark'
498
+ * Method: DELETE
499
+ *
500
+ * @param {string} folderID - The Box ID of the folder to remove watermark from
501
+ * @param {Function} [callback] - Empty response body passed if successful, error otherwise
502
+ * @returns {Promise<void>} A promise resolving to nothing
503
+ */
504
+ Folders.prototype.removeWatermark = function (folderID, callback) {
505
+ var apiPath = url_path_1.default(BASE_PATH, folderID, WATERMARK_SUBRESOURCE);
506
+ return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
507
+ };
508
+ /**
509
+ * Used to lock a Box folder.
510
+ *
511
+ * API Endpoint: '/folder_locks'
512
+ * Method: POST
513
+ *
514
+ * @param {string} folderID - The Box ID of the folder to lock
515
+ * @param {Function} [callback] - Passed the folder lock object if successful, error otherwise
516
+ * @returns {Promise<void>} A promise resolving to a folder lock object
517
+ */
518
+ Folders.prototype.lock = function (folderID, callback) {
519
+ var params = {
520
+ body: {
521
+ folder: {
522
+ type: 'folder',
523
+ id: folderID,
524
+ },
525
+ locked_operations: {
526
+ move: true,
527
+ delete: true,
528
+ },
529
+ },
530
+ };
531
+ return this.client.wrapWithDefaultHandler(this.client.post)(FOLDER_LOCK, params, callback);
532
+ };
533
+ /**
534
+ * Used to get all locks on a folder.
535
+ *
536
+ * API Endpoint: '/folder_locks'
537
+ * Method: GET
538
+ *
539
+ * @param {string} folderID - The Box ID of the folder to lock
540
+ * @param {Function} [callback] - Passed a collection of folder lock objects if successful, error otherwise
541
+ * @returns {Promise<void>} A promise resolving to a collection of folder lock objects
542
+ */
543
+ Folders.prototype.getLocks = function (folderID, callback) {
544
+ var params = {
545
+ qs: {
546
+ folder_id: folderID,
547
+ },
548
+ };
549
+ return this.client.wrapWithDefaultHandler(this.client.get)(FOLDER_LOCK, params, callback);
550
+ };
551
+ /**
552
+ * Used to delete a lock on a folder.
553
+ *
554
+ * API Endpoint: '/folder_locks/:folderLockID'
555
+ * Method: DELETE
556
+ *
557
+ * @param {string} folderLockID - The Box ID of the folder lock
558
+ * @param {Function} [callback] - Empty response body passed if successful, error otherwise
559
+ * @returns {Promise<void>} A promise resolving to nothing
560
+ */
561
+ Folders.prototype.deleteLock = function (folderLockID, callback) {
562
+ var apiPath = url_path_1.default(FOLDER_LOCK, folderLockID);
563
+ return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
564
+ };
565
+ return Folders;
566
+ }());
647
567
  module.exports = Folders;
568
+ //# sourceMappingURL=folders.js.map