box-node-sdk 1.28.0 → 1.29.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.29.0 [2019-04-25]
4
+
5
+ - Added convenience methods for setting metadata on [files](./docs/metadata.md#set-metadata-on-a-file)
6
+ and [folders](./docs/metadata.md#set-metadata-on-a-folder) ([#376](https://github.com/box/box-node-sdk/pull/376))
7
+
3
8
  ## 1.28.0 [2019-03-28]
4
9
 
5
10
  - Added methods for [moving](./docs/web-links.md#move-a-web-link) and [copying](./docs/web-links.md#move-a-web-link)
@@ -743,6 +743,37 @@ Files.prototype.updateMetadata = function(fileID, scope, template, patch, callba
743
743
  return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
744
744
  };
745
745
 
746
+ /**
747
+ * Sets metadata on a file, overwriting any metadata that exists for the provided keys.
748
+ *
749
+ * @param {string} fileID - The file to set metadata on
750
+ * @param {string} scope - The scope of the metadata template
751
+ * @param {string} template - The key of the metadata template
752
+ * @param {Object} metadata - The metadata to set
753
+ * @param {Function} [callback] - Called with updated metadata if successful
754
+ * @returns {Promise<Object>} A promise resolving to the updated metadata
755
+ */
756
+ Files.prototype.setMetadata = function(fileID, scope, template, metadata, callback) {
757
+
758
+ return this.addMetadata(fileID, scope, template, metadata)
759
+ .catch(err => {
760
+
761
+ if (err.statusCode !== 409) {
762
+ throw err;
763
+ }
764
+
765
+ // Metadata already exists on the file; update instead
766
+ var updates = Object.keys(metadata).map(key => ({
767
+ op: 'add',
768
+ path: `/${key}`,
769
+ value: metadata[key],
770
+ }));
771
+
772
+ return this.updateMetadata(fileID, scope, template, updates);
773
+ })
774
+ .asCallback(callback);
775
+ };
776
+
746
777
  /**
747
778
  * Deletes a metadata template from a file.
748
779
  *
@@ -368,6 +368,37 @@ Folders.prototype.updateMetadata = function(folderID, scope, template, patch, ca
368
368
  return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
369
369
  };
370
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
+
371
402
  /**
372
403
  * Deletes a metadata template from a folder.
373
404
  *
@@ -78,6 +78,8 @@ Search.prototype = {
78
78
  * @param {SearchMetadataFilter[]} [options.mdfilters] - Searches for objects with a specific metadata object association. Searches with the this parameter do not require a query string
79
79
  * @param {int} [options.limit=30] - The number of search results to return, max 200
80
80
  * @param {int} [options.offset=0] - The search result at which to start the response, must be a multiple of limit
81
+ * @param {string} [options.sort] - The field on which the results should be sorted, e.g. "modified_at"
82
+ * @param {string} [options.direction] - The sort direction: "ASC" for ascending and "DESC" for descending
81
83
  * @param {APIRequest~Callback} [callback] - passed the new comment data if it was posted successfully
82
84
  * @returns {Promise<Object>} A promise resolving to the collection of search results
83
85
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "box-node-sdk",
3
3
  "author": "Box <oss@box.com>",
4
- "version": "1.28.0",
4
+ "version": "1.29.0",
5
5
  "description": "Official SDK for Box Plaform APIs",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {