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