Source: managers/folders.ts

  1. /**
  2. * @fileoverview Manager for the Box Folders Resource
  3. */
  4. // ------------------------------------------------------------------------------
  5. // Requirements
  6. // ------------------------------------------------------------------------------
  7. import BoxClient from '../box-client';
  8. import urlPath from '../util/url-path';
  9. import errors from '../util/errors';
  10. import {Collaborations} from "../schemas";
  11. // -----------------------------------------------------------------------------
  12. // Typedefs
  13. // -----------------------------------------------------------------------------
  14. type FolderSharedLinkAccess = 'open' | 'company' | 'collaborators' | null;
  15. type FolderSharedLinkPermissions = {
  16. /**
  17. * If the shared link allows only to view folders. This can only be set when access is set to open or company.
  18. */
  19. can_view?: true,
  20. /**
  21. * If the shared link allows only to download folders. This can only be set when access is set to open or company.
  22. */
  23. can_download?: boolean
  24. }
  25. type FolderSharedLink = {
  26. /**
  27. * The level of access for the shared link. This can be restricted to anyone with the link (open),
  28. * only people within the company (company) and only those who have been invited to the file (collaborators).
  29. *
  30. * If not set, this field defaults to the access level specified by the enterprise admin.
  31. * To create a shared link with this default setting pass the shared_link object with no access field.
  32. * To remove access and change its value to default one pass the shared_link object with null value access field.
  33. */
  34. access?: FolderSharedLinkAccess,
  35. /**
  36. * The password required to access the shared link. Set the password to null to remove it.
  37. * A password can only be set when access is set to open.
  38. */
  39. password?: string | null,
  40. /**
  41. * The timestamp at which this shared link will expire. This field can only be set by users with paid accounts.
  42. * The value must be greater than the current date and time.
  43. * Example value: '2012-12-12T10:53:43-08:00'
  44. */
  45. unshared_at?: string | null,
  46. /**
  47. * Defines a custom vanity name to use in the shared link URL, for example vanity_name: "my-shared-link" will
  48. * produce a shared link of "https://app.box.com/v/my-shared-link".
  49. *
  50. * Custom URLs should not be used when sharing sensitive content as vanity URLs are a lot easier to guess
  51. * than regular shared links.
  52. */
  53. vanity_name?: string | null,
  54. /**
  55. * Defines what actions are allowed on a shared link.
  56. */
  57. permissions?: FolderSharedLinkPermissions
  58. }
  59. // ------------------------------------------------------------------------------
  60. // Private
  61. // ------------------------------------------------------------------------------
  62. const BASE_PATH = '/folders',
  63. FOLDER_LOCK = '/folder_locks',
  64. WATERMARK_SUBRESOURCE = '/watermark';
  65. // ------------------------------------------------------------------------------
  66. // Public
  67. // ------------------------------------------------------------------------------
  68. /**
  69. * Simple manager for interacting with all 'Folder' endpoints and actions.
  70. *
  71. * @constructor
  72. * @param {BoxClient} client - The Box API Client that is responsible for making calls to the API
  73. * @returns {void}
  74. */
  75. class Folders {
  76. client: BoxClient;
  77. constructor(client: BoxClient) {
  78. this.client = client;
  79. }
  80. /**
  81. * Requests a folder object with the given ID.
  82. *
  83. * API Endpoint: '/folders/:folderID'
  84. * Method: GET
  85. *
  86. * @param {string} folderID - Box ID of the folder being requested
  87. * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
  88. * @param {Function} [callback] - Passed the folder information if it was acquired successfully
  89. * @returns {Promise<Object>} A promise resolving to the folder object
  90. */
  91. get(folderID: string, options?: Record<string, any>, callback?: Function) {
  92. var params = {
  93. qs: options,
  94. };
  95. var apiPath = urlPath(BASE_PATH, folderID);
  96. return this.client.wrapWithDefaultHandler(this.client.get)(
  97. apiPath,
  98. params,
  99. callback
  100. );
  101. }
  102. /**
  103. * Requests items contained within a given folder.
  104. *
  105. * API Endpoint: '/folders/:folderID/items'
  106. * Method: GET
  107. *
  108. * @param {string} folderID - Box ID of the folder being requested
  109. * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
  110. * @param {Function} [callback] - Passed the folder information if it was acquired successfully
  111. * @returns {Promise<Object>} A promise resolving to the collection of the items in the folder
  112. */
  113. getItems(
  114. folderID: string,
  115. options?: Record<string, any>,
  116. callback?: Function
  117. ) {
  118. var params = {
  119. qs: options,
  120. };
  121. var apiPath = urlPath(BASE_PATH, folderID, '/items');
  122. return this.client.wrapWithDefaultHandler(this.client.get)(
  123. apiPath,
  124. params,
  125. callback
  126. );
  127. }
  128. /**
  129. * Requests collaborations on a given folder.
  130. *
  131. * API Endpoint: '/folders/:folderID/collaborations'
  132. * Method: GET
  133. *
  134. * @param {string} folderID - Box ID of the folder being requested
  135. * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
  136. * @param {Function} [callback] - Passed the folder information if it was acquired successfully
  137. * @returns {Promise<schemas.Collaborations>} A promise resolving to the collection of collaborations
  138. */
  139. getCollaborations(
  140. folderID: string,
  141. options?: Record<string, any>,
  142. callback?: Function
  143. ): Promise<Collaborations> {
  144. var params = {
  145. qs: options,
  146. };
  147. var apiPath = urlPath(BASE_PATH, folderID, '/collaborations');
  148. return this.client.wrapWithDefaultHandler(this.client.get)(
  149. apiPath,
  150. params,
  151. callback
  152. );
  153. }
  154. /**
  155. * Creates a new Folder within a parent folder
  156. *
  157. * API Endpoint: '/folders
  158. * Method: POST
  159. *
  160. * @param {string} parentFolderID - Box folder id of the folder to add into
  161. * @param {string} name - The name for the new folder
  162. * @param {Function} [callback] - passed the new folder info if call was successful
  163. * @returns {Promise<Object>} A promise resolving to the created folder object
  164. */
  165. create(parentFolderID: string, name: string, callback?: Function) {
  166. var params = {
  167. body: {
  168. name,
  169. parent: {
  170. id: parentFolderID,
  171. },
  172. },
  173. };
  174. return this.client.wrapWithDefaultHandler(this.client.post)(
  175. BASE_PATH,
  176. params,
  177. callback
  178. );
  179. }
  180. /**
  181. * Copy a folder into a new, different folder
  182. *
  183. * API Endpoint: '/folders/:folderID/copy
  184. * Method: POST
  185. *
  186. * @param {string} folderID - The Box ID of the folder being requested
  187. * @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files.
  188. * @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases
  189. * @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder
  190. * @param {Function} [callback] - passed the new folder info if call was successful
  191. * @returns {Promise<Object>} A promise resolving to the new folder object
  192. */
  193. copy(
  194. folderID: string,
  195. newParentID: string,
  196. options?:
  197. | {
  198. [key: string]: any;
  199. name?: string;
  200. }
  201. | Function,
  202. callback?: Function
  203. ) {
  204. // @NOTE(mwiller) 2016-10-25: Shuffle arguments to maintain backward compatibility
  205. // This can be removed at the v2.0 update
  206. if (typeof options === 'function') {
  207. callback = options;
  208. options = {};
  209. }
  210. options = options || {};
  211. options.parent = {
  212. id: newParentID,
  213. };
  214. var params = {
  215. body: options,
  216. };
  217. var apiPath = urlPath(BASE_PATH, folderID, '/copy');
  218. return this.client.wrapWithDefaultHandler(this.client.post)(
  219. apiPath,
  220. params,
  221. callback
  222. );
  223. }
  224. /**
  225. * Update some information about a given folder.
  226. *
  227. * API Endpoint: '/folders/:folderID'
  228. * Method: PUT
  229. *
  230. * @param {string} folderID - The Box ID of the folder being requested
  231. * @param {Object} updates - Folder fields to update
  232. * @param {string} [updates.etag] Only update the folder if the ETag matches
  233. * @param {string} [updates.fields] Comma-separated list of fields to return
  234. * @param {Function} [callback] - Passed the updated folder information if it was acquired successfully
  235. * @returns {Promise<Object>} A promise resolving to the updated folder object
  236. */
  237. update(
  238. folderID: string,
  239. updates: {
  240. [key: string]: any;
  241. etag?: string;
  242. shared_link?: FolderSharedLink;
  243. fields?: string;
  244. },
  245. callback?: Function
  246. ) {
  247. var params: Record<string, any> = {
  248. body: updates,
  249. };
  250. if (updates && updates.etag) {
  251. params.headers = {
  252. 'If-Match': updates.etag,
  253. };
  254. delete updates.etag;
  255. }
  256. if (updates && updates.fields) {
  257. params.qs = {
  258. fields: updates.fields,
  259. };
  260. delete updates.fields;
  261. }
  262. var apiPath = urlPath(BASE_PATH, folderID);
  263. return this.client.wrapWithDefaultHandler(this.client.put)(
  264. apiPath,
  265. params,
  266. callback
  267. );
  268. }
  269. /**
  270. * Add a folder to a given collection
  271. *
  272. * API Endpoint: '/folders/:folderID'
  273. * Method: PUT
  274. *
  275. * @param {string} folderID - The folder to add to the collection
  276. * @param {string} collectionID - The collection to add the folder to
  277. * @param {Function} [callback] - Passed the updated folder if successful, error otherwise
  278. * @returns {Promise<Object>} A promise resolving to the updated folder object
  279. */
  280. addToCollection(folderID: string, collectionID: string, callback?: Function) {
  281. return this.get(folderID, { fields: 'collections' })
  282. .then((data: any /* FIXME */) => {
  283. var collections = data.collections || [];
  284. // Convert to correct format
  285. collections = collections.map((c: any /* FIXME */) => ({ id: c.id }));
  286. if (!collections.find((c: any /* FIXME */) => c.id === collectionID)) {
  287. collections.push({ id: collectionID });
  288. }
  289. return this.update(folderID, { collections });
  290. })
  291. .asCallback(callback);
  292. }
  293. /**
  294. * Remove a folder from a given collection
  295. *
  296. * API Endpoint: '/folders/:folderID'
  297. * Method: PUT
  298. *
  299. * @param {string} folderID - The folder to remove from the collection
  300. * @param {string} collectionID - The collection to remove the folder from
  301. * @param {Function} [callback] - Passed the updated folder if successful, error otherwise
  302. * @returns {Promise<Object>} A promise resolving to the updated folder object
  303. */
  304. removeFromCollection(
  305. folderID: string,
  306. collectionID: string,
  307. callback?: Function
  308. ) {
  309. return this.get(folderID, { fields: 'collections' })
  310. .then((data: any /* FIXME */) => {
  311. var collections = data.collections || [];
  312. // Convert to correct object format and remove the specified collection
  313. collections = collections
  314. .map((c: any /* FIXME */) => ({ id: c.id }))
  315. .filter((c: any /* FIXME */) => c.id !== collectionID);
  316. return this.update(folderID, { collections });
  317. })
  318. .asCallback(callback);
  319. }
  320. /**
  321. * Move a folder into a new parent folder.
  322. *
  323. * API Endpoint: '/folders/:folderID'
  324. * Method: PUT
  325. *
  326. * @param {string} folderID - The Box ID of the folder being requested
  327. * @param {string} newParentID - The Box ID for the new parent folder. '0' to move to All Files.
  328. * @param {Function} [callback] - Passed the updated folder information if it was acquired successfully
  329. * @returns {Promise<Object>} A promise resolving to the updated folder object
  330. */
  331. move(folderID: string, newParentID: string, callback?: Function) {
  332. var params = {
  333. body: {
  334. parent: {
  335. id: newParentID,
  336. },
  337. },
  338. };
  339. var apiPath = urlPath(BASE_PATH, folderID);
  340. return this.client.wrapWithDefaultHandler(this.client.put)(
  341. apiPath,
  342. params,
  343. callback
  344. );
  345. }
  346. /**
  347. * Delete a given folder.
  348. *
  349. * API Endpoint: '/folders/:folderID'
  350. * Method: DELETE
  351. *
  352. * @param {string} folderID - Box ID of the folder being requested
  353. * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
  354. * @param {string} [options.etag] Only delete the folder if the ETag matches
  355. * @param {Function} [callback] - Empty response body passed if successful.
  356. * @returns {Promise<void>} A promise resolving to nothing
  357. */
  358. delete(
  359. folderID: string,
  360. options?: {
  361. [key: string]: any;
  362. etag?: string;
  363. },
  364. callback?: Function
  365. ) {
  366. var params: Record<string, any> = {
  367. qs: options,
  368. };
  369. if (options && options.etag) {
  370. params.headers = {
  371. 'If-Match': options.etag,
  372. };
  373. delete options.etag;
  374. }
  375. var apiPath = urlPath(BASE_PATH, folderID);
  376. return this.client.wrapWithDefaultHandler(this.client.del)(
  377. apiPath,
  378. params,
  379. callback
  380. );
  381. }
  382. /**
  383. * Retrieves all metadata associated with a folder.
  384. *
  385. * API Endpoint: '/folders/:folderID/metadata'
  386. * Method: GET
  387. *
  388. * @param {string} folderID - the ID of the folder to get metadata for
  389. * @param {Function} [callback] - called with an array of metadata when successful
  390. * @returns {Promise<Object>} A promise resolving to the collection of metadata on the folder
  391. */
  392. getAllMetadata(folderID: string, callback?: Function) {
  393. var apiPath = urlPath(BASE_PATH, folderID, 'metadata');
  394. return this.client.wrapWithDefaultHandler(this.client.get)(
  395. apiPath,
  396. null,
  397. callback
  398. );
  399. }
  400. /**
  401. * Retrieve a single metadata template instance for a folder.
  402. *
  403. * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
  404. * Method: GET
  405. *
  406. * @param {string} folderID - The ID of the folder to retrive the metadata of
  407. * @param {string} scope - The scope of the metadata template, e.g. "global"
  408. * @param {string} template - The metadata template to retrieve
  409. * @param {Function} [callback] - Passed the metadata template if successful
  410. * @returns {Promise<Object>} A promise resolving to the metadata template
  411. */
  412. getMetadata(
  413. folderID: string,
  414. scope: string,
  415. template: string,
  416. callback?: Function
  417. ) {
  418. var apiPath = urlPath(BASE_PATH, folderID, 'metadata', scope, template);
  419. return this.client.wrapWithDefaultHandler(this.client.get)(
  420. apiPath,
  421. null,
  422. callback
  423. );
  424. }
  425. /**
  426. * Adds metadata to a folder. Metadata must either match a template schema or
  427. * be placed into the unstructured "properties" template in global scope.
  428. *
  429. * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
  430. * Method: POST
  431. *
  432. * @param {string} folderID - The ID of the folder to add metadata to
  433. * @param {string} scope - The scope of the metadata template, e.g. "enterprise"
  434. * @param {string} template - The metadata template schema to add
  435. * @param {Object} data - Key/value pairs to add as metadata
  436. * @param {Function} [callback] - Called with error if unsuccessful
  437. * @returns {Promise<Object>} A promise resolving to the created metadata
  438. */
  439. addMetadata(
  440. folderID: string,
  441. scope: string,
  442. template: string,
  443. data: Record<string, any>,
  444. callback?: Function
  445. ) {
  446. var apiPath = urlPath(BASE_PATH, folderID, 'metadata', scope, template),
  447. params = {
  448. body: data,
  449. };
  450. return this.client.wrapWithDefaultHandler(this.client.post)(
  451. apiPath,
  452. params,
  453. callback
  454. );
  455. }
  456. /**
  457. * Updates a metadata template instance with JSON Patch-formatted data.
  458. *
  459. * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
  460. * Method: PUT
  461. *
  462. * @param {string} folderID - The folder to update metadata for
  463. * @param {string} scope - The scope of the template to update
  464. * @param {string} template - The template to update
  465. * @param {Object} patch - The patch data
  466. * @param {Function} [callback] - Called with updated metadata if successful
  467. * @returns {Promise<Object>} A promise resolving to the updated metadata
  468. */
  469. updateMetadata(
  470. folderID: string,
  471. scope: string,
  472. template: string,
  473. patch: Record<string, any>,
  474. callback?: Function
  475. ) {
  476. var apiPath = urlPath(BASE_PATH, folderID, 'metadata', scope, template),
  477. params = {
  478. body: patch,
  479. headers: {
  480. 'Content-Type': 'application/json-patch+json',
  481. },
  482. };
  483. return this.client.wrapWithDefaultHandler(this.client.put)(
  484. apiPath,
  485. params,
  486. callback
  487. );
  488. }
  489. /**
  490. * Sets metadata on a folder, overwriting any metadata that exists for the provided keys.
  491. *
  492. * @param {string} folderID - The folder to set metadata on
  493. * @param {string} scope - The scope of the metadata template
  494. * @param {string} template - The key of the metadata template
  495. * @param {Object} metadata - The metadata to set
  496. * @param {Function} [callback] - Called with updated metadata if successful
  497. * @returns {Promise<Object>} A promise resolving to the updated metadata
  498. */
  499. setMetadata(
  500. folderID: string,
  501. scope: string,
  502. template: string,
  503. metadata: Record<string, any>,
  504. callback?: Function
  505. ) {
  506. return this.addMetadata(folderID, scope, template, metadata)
  507. .catch((err: any /* FIXME */) => {
  508. if (err.statusCode !== 409) {
  509. throw err;
  510. }
  511. // Metadata already exists on the file; update instead
  512. var updates = Object.keys(metadata).map((key) => ({
  513. op: 'add',
  514. path: `/${key}`,
  515. value: metadata[key],
  516. }));
  517. return this.updateMetadata(folderID, scope, template, updates);
  518. })
  519. .asCallback(callback);
  520. }
  521. /**
  522. * Deletes a metadata template from a folder.
  523. *
  524. * API Endpoint: '/folders/:folderID/metadata/:scope/:template'
  525. * Method: DELETE
  526. *
  527. * @param {string} folderID - The ID of the folder to remove metadata from
  528. * @param {string} scope - The scope of the metadata template
  529. * @param {string} template - The template to remove from the folder
  530. * @param {Function} [callback] - Called with nothing if successful, error otherwise
  531. * @returns {Promise<void>} A promise resolving to nothing
  532. */
  533. deleteMetadata(
  534. folderID: string,
  535. scope: string,
  536. template: string,
  537. callback?: Function
  538. ) {
  539. var apiPath = urlPath(BASE_PATH, folderID, 'metadata', scope, template);
  540. return this.client.wrapWithDefaultHandler(this.client.del)(
  541. apiPath,
  542. null,
  543. callback
  544. );
  545. }
  546. /**
  547. * Retrieves a folder that has been moved to the trash
  548. *
  549. * API Endpoint: '/folders/:folderID/trash'
  550. * Method: GET
  551. *
  552. * @param {string} folderID - The ID of the folder being requested
  553. * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
  554. * @param {Function} [callback] - Passed the folder information if it was acquired successfully
  555. * @returns {Promise<Object>} A promise resolving to the trashed folder object
  556. */
  557. getTrashedFolder(
  558. folderID: string,
  559. options?: Record<string, any>,
  560. callback?: Function
  561. ) {
  562. var params = {
  563. qs: options,
  564. };
  565. var apiPath = urlPath(BASE_PATH, folderID, 'trash');
  566. return this.client.wrapWithDefaultHandler(this.client.get)(
  567. apiPath,
  568. params,
  569. callback
  570. );
  571. }
  572. /**
  573. * Restores an item that has been moved to the trash. Default behavior is to restore the item
  574. * to the folder it was in before it was moved to the trash. If that parent folder no longer
  575. * exists or if there is now an item with the same name in that parent folder, the new parent
  576. * older and/or new name will need to be included in the request.
  577. *
  578. * API Endpoint: '/folders/:folderID'
  579. * Method: POST
  580. *
  581. * @param {string} folderID - The ID of the folder to restore
  582. * @param {Object} [options] - Optional parameters, can be left null
  583. * @param {?string} [options.name] - The new name for this item
  584. * @param {string} [options.parent_id] - The new parent folder for this item
  585. * @param {Function} [callback] - Called with folder information if successful, error otherwise
  586. * @returns {Promise<Object>} A promise resolving to the restored folder object
  587. */
  588. restoreFromTrash(
  589. folderID: string,
  590. options?: {
  591. [key: string]: any;
  592. name?: string;
  593. parent_id?: string;
  594. },
  595. callback?: Function
  596. ) {
  597. // Set up the parent_id parameter
  598. if (options && options.parent_id) {
  599. options.parent = {
  600. id: options.parent_id,
  601. };
  602. delete options.parent_id;
  603. }
  604. var apiPath = urlPath(BASE_PATH, folderID),
  605. params = {
  606. body: options || {},
  607. };
  608. return this.client.wrapWithDefaultHandler(this.client.post)(
  609. apiPath,
  610. params,
  611. callback
  612. );
  613. }
  614. /**
  615. * Permanently deletes an folder that is in the trash. The item will no longer exist in Box. This action cannot be undone
  616. *
  617. * API Endpoint: '/folders/:folderID/trash'
  618. * Method: DELETE
  619. *
  620. * @param {string} folderID Box ID of the folder being requested
  621. * @param {Object} [options] Optional parameters
  622. * @param {string} [options.etag] Only delete the folder if the ETag matches
  623. * @param {Function} [callback] Called with nothing if successful, error otherwise
  624. * @returns {Promise<void>} A promise resolving to nothing
  625. */
  626. deletePermanently(
  627. folderID: string,
  628. options?: {
  629. [key: string]: any;
  630. etag?: string;
  631. },
  632. callback?: Function
  633. ) {
  634. // Switch around arguments if necessary for backwards compatibility
  635. if (typeof options === 'function') {
  636. callback = options;
  637. options = {};
  638. }
  639. var params: Record<string, any> = {};
  640. if (options && options.etag) {
  641. params.headers = {
  642. 'If-Match': options.etag,
  643. };
  644. }
  645. var apiPath = urlPath(BASE_PATH, folderID, '/trash');
  646. return this.client.wrapWithDefaultHandler(this.client.del)(
  647. apiPath,
  648. params,
  649. callback
  650. );
  651. }
  652. /**
  653. * Used to retrieve the watermark for a corresponding Box folder.
  654. *
  655. * API Endpoint: '/folders/:folderID/watermark'
  656. * Method: GET
  657. *
  658. * @param {string} folderID - The Box ID of the folder to get watermark for
  659. * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
  660. * @param {Function} [callback] - Passed the watermark information if successful, error otherwise
  661. * @returns {Promise<Object>} A promise resolving to the watermark info
  662. */
  663. getWatermark(
  664. folderID: string,
  665. options?: Record<string, any>,
  666. callback?: Function
  667. ) {
  668. var apiPath = urlPath(BASE_PATH, folderID, WATERMARK_SUBRESOURCE),
  669. params = {
  670. qs: options,
  671. };
  672. return this.client
  673. .get(apiPath, params)
  674. .then((response: any /* FIXME */) => {
  675. if (response.statusCode !== 200) {
  676. throw errors.buildUnexpectedResponseError(response);
  677. }
  678. return response.body.watermark;
  679. })
  680. .asCallback(callback);
  681. }
  682. /**
  683. * Used to apply or update the watermark for a corresponding Box folder.
  684. *
  685. * API Endpoint: '/folders/:folderID/watermark'
  686. * Method: PUT
  687. *
  688. * @param {string} folderID - The Box ID of the folder to update watermark for
  689. * @param {Object} [options] - Optional parameters, can be left null
  690. * @param {Function} [callback] - Passed the watermark information if successful, error otherwise
  691. * @returns {Promise<Object>} A promise resolving to the watermark info
  692. */
  693. applyWatermark(
  694. folderID: string,
  695. options?: Record<string, any>,
  696. callback?: Function
  697. ) {
  698. var apiPath = urlPath(BASE_PATH, folderID, WATERMARK_SUBRESOURCE),
  699. params = {
  700. body: {
  701. watermark: {
  702. imprint: 'default', // Currently the API only supports default imprint
  703. },
  704. },
  705. };
  706. Object.assign(params.body.watermark, options);
  707. return this.client.wrapWithDefaultHandler(this.client.put)(
  708. apiPath,
  709. params,
  710. callback
  711. );
  712. }
  713. /**
  714. * Used to remove the watermark for a corresponding Box folder.
  715. *
  716. * API Endpoint: '/folders/:folderID/watermark'
  717. * Method: DELETE
  718. *
  719. * @param {string} folderID - The Box ID of the folder to remove watermark from
  720. * @param {Function} [callback] - Empty response body passed if successful, error otherwise
  721. * @returns {Promise<void>} A promise resolving to nothing
  722. */
  723. removeWatermark(folderID: string, callback?: Function) {
  724. var apiPath = urlPath(BASE_PATH, folderID, WATERMARK_SUBRESOURCE);
  725. return this.client.wrapWithDefaultHandler(this.client.del)(
  726. apiPath,
  727. null,
  728. callback
  729. );
  730. }
  731. /**
  732. * Used to lock a Box folder.
  733. *
  734. * API Endpoint: '/folder_locks'
  735. * Method: POST
  736. *
  737. * @param {string} folderID - The Box ID of the folder to lock
  738. * @param {Function} [callback] - Passed the folder lock object if successful, error otherwise
  739. * @returns {Promise<void>} A promise resolving to a folder lock object
  740. */
  741. lock(folderID: string, callback?: Function) {
  742. var params = {
  743. body: {
  744. folder: {
  745. type: 'folder',
  746. id: folderID,
  747. },
  748. locked_operations: {
  749. move: true,
  750. delete: true,
  751. },
  752. },
  753. };
  754. return this.client.wrapWithDefaultHandler(this.client.post)(
  755. FOLDER_LOCK,
  756. params,
  757. callback
  758. );
  759. }
  760. /**
  761. * Used to get all locks on a folder.
  762. *
  763. * API Endpoint: '/folder_locks'
  764. * Method: GET
  765. *
  766. * @param {string} folderID - The Box ID of the folder to lock
  767. * @param {Function} [callback] - Passed a collection of folder lock objects if successful, error otherwise
  768. * @returns {Promise<void>} A promise resolving to a collection of folder lock objects
  769. */
  770. getLocks(folderID: string, callback?: Function) {
  771. var params = {
  772. qs: {
  773. folder_id: folderID,
  774. },
  775. };
  776. return this.client.wrapWithDefaultHandler(this.client.get)(
  777. FOLDER_LOCK,
  778. params,
  779. callback
  780. );
  781. }
  782. /**
  783. * Used to delete a lock on a folder.
  784. *
  785. * API Endpoint: '/folder_locks/:folderLockID'
  786. * Method: DELETE
  787. *
  788. * @param {string} folderLockID - The Box ID of the folder lock
  789. * @param {Function} [callback] - Empty response body passed if successful, error otherwise
  790. * @returns {Promise<void>} A promise resolving to nothing
  791. */
  792. deleteLock(folderLockID: string, callback?: Function) {
  793. var apiPath = urlPath(FOLDER_LOCK, folderLockID);
  794. return this.client.wrapWithDefaultHandler(this.client.del)(
  795. apiPath,
  796. null,
  797. callback
  798. );
  799. }
  800. }
  801. /**
  802. * @module box-node-sdk/lib/managers/folders
  803. * @see {@Link Folders}
  804. */
  805. export = Folders;