box-node-sdk 1.32.0 → 1.33.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,9 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## 1.32.0 [2020-03-30]
3
+ ## 1.33.0 [2020-06-25]
4
4
 
5
- - Temporarily removed Node 4 and Node 5 builds from Travis, due to tests not passing. Will investigate, going forward.
6
- - Fixed an issue where an error is thrown during a retry when a response is not returned by the previous call ([#476](https://github.com/box/box-node-sdk/pull/76)).
5
+ - Add path parameter sanitization ([#505](https://github.com/box/box-node-sdk/pull/505))
6
+ - Add support for all streams for uploading files ([#519](https://github.com/box/box-node-sdk/pull/519))
7
+
8
+ ## 1.32.0 [2020-04-01]
9
+
10
+ - Temporarily removed Node 4 and Node 5 builds from Travis, due to tests not passing. Will investigate, going forward ([#495](https://github.com/box/box-node-sdk/pull/495)).
11
+ - Fixed an issue where an error is thrown during a retry when a response is not returned by the previous call ([#477](https://github.com/box/box-node-sdk/pull/477)).
7
12
  - Added the ability to [query](./docs/metadata.md#query) Box items based on their metadata ([#487](https://github.com/box/box-node-sdk/pull/487)).
8
13
 
9
14
  ## 1.31.0 [2020-02-13]
@@ -78,10 +78,11 @@ function createFileMetadataFormData(parentFolderID, filename, options) {
78
78
  /**
79
79
  * Returns the multipart form value for file upload content.
80
80
  * @param {string|Buffer|Stream} content - the content of the file being uploaded
81
+ * @param {Object} options - options for the content
81
82
  * @returns {Object} - the form value expected by the API for the 'content' key
82
83
  * @private
83
84
  */
84
- function createFileContentFormData(content) {
85
+ function createFileContentFormData(content, options) {
85
86
  // The upload API appears to look for a form field that contains a filename
86
87
  // property and assume that this form field contains the file content. Thus,
87
88
  // the value of name does not actually matter (as long as it does not conflict
@@ -90,7 +91,7 @@ function createFileContentFormData(content) {
90
91
  // filename specified in the metadata form field instead.
91
92
  return {
92
93
  value: content,
93
- options: { filename: 'unused' }
94
+ options: Object.assign({ filename: 'unused' }, options)
94
95
  };
95
96
  }
96
97
 
@@ -601,6 +602,7 @@ Files.prototype.promoteVersion = function(fileID, versionID, callback) {
601
602
  * @param {Object} [options] - Optional parameters
602
603
  * @param {string} [options.content_created_at] - RFC 3339 timestamp when the file was created
603
604
  * @param {string} [options.content_modified_at] - RFC 3339 timestamp when the file was last modified
605
+ * @param {int} [options.content_length] - Optional length of the content. Required if content is a read stream of any type other than fs stream.
604
606
  * @param {Function} [callback] - called with data about the upload if successful, or an error if the
605
607
  * upload failed
606
608
  * @returns {Promise<Object>} A promise resolving to the uploaded file
@@ -613,10 +615,17 @@ Files.prototype.uploadFile = function(parentFolderID, filename, content, options
613
615
  options = {};
614
616
  }
615
617
 
618
+ var formOptions = {};
619
+ if (options && options.hasOwnProperty('content_length')) {
620
+ formOptions.knownLength = options.content_length;
621
+ // Delete content_length from options so it's not added to the attributes of the form
622
+ delete options.content_length;
623
+ }
624
+
616
625
  var apiPath = urlPath(BASE_PATH, '/content'),
617
626
  multipartFormData = {
618
627
  attributes: createFileMetadataFormData(parentFolderID, filename, options),
619
- content: createFileContentFormData(content)
628
+ content: createFileContentFormData(content, formOptions)
620
629
  };
621
630
 
622
631
  return this.client.wrapWithDefaultHandler(this.client.upload)(apiPath, null, multipartFormData, callback);
@@ -635,6 +644,7 @@ Files.prototype.uploadFile = function(parentFolderID, filename, content, options
635
644
  * @param {Object} [options] - Optional parameters
636
645
  * @param {string} [options.content_modified_at] - RFC 3339 timestamp when the file was last modified
637
646
  * @param {string} [options.name] - A new name for the file
647
+ * @param {int} [options.content_length] - Optional length of the content. Required if content is a read stream of any type other than fs stream.
638
648
  * @param {Function} [callback] - called with data about the upload if successful, or an error if the
639
649
  * upload failed
640
650
  * @returns {Promise<Object>} A promise resolving to the uploaded file
@@ -650,11 +660,18 @@ Files.prototype.uploadNewFileVersion = function(fileID, content, options, callba
650
660
  var apiPath = urlPath(BASE_PATH, fileID, '/content'),
651
661
  multipartFormData = {};
652
662
 
663
+
664
+ var formOptions = {};
653
665
  if (options) {
666
+ if (options.hasOwnProperty('content_length')) {
667
+ formOptions.knownLength = options.content_length;
668
+ // Delete content_length from options so it's not added to the attributes of the form
669
+ delete options.content_length;
670
+ }
654
671
  multipartFormData.attributes = JSON.stringify(options);
655
672
  }
656
673
 
657
- multipartFormData.content = createFileContentFormData(content);
674
+ multipartFormData.content = createFileContentFormData(content, formOptions);
658
675
 
659
676
  return this.client.wrapWithDefaultHandler(this.client.upload)(apiPath, null, multipartFormData, callback);
660
677
  };
@@ -8,6 +8,8 @@
8
8
  // Private
9
9
  // ------------------------------------------------------------------------------
10
10
 
11
+ // Pattern to check for relative paths
12
+ var PATTERN = /\/\.+/;
11
13
  /**
12
14
  * remove leading & trailing slashes from some string. This is useful for
13
15
  * removing slashes from the path segments that are actually a part of the
@@ -39,7 +41,14 @@ function trimSlashes(segment) {
39
41
  */
40
42
  module.exports = function urlPath(/* arguments*/) {
41
43
  var args = Array.prototype.slice.call(arguments);
42
- var path = args.map(x => String(x)).map(x => trimSlashes(x))
44
+ var path = args.map(x => String(x))
45
+ .map(x => {
46
+ var trimmedX = trimSlashes(x);
47
+ if (PATTERN.test(trimmedX)) {
48
+ throw new Error(`An invalid path parameter exists in ${trimmedX}. Relative path parameters cannot be passed.`);
49
+ }
50
+ return trimmedX;
51
+ })
43
52
  .map(x => encodeURIComponent(x))
44
53
  .join('/');
45
54
  return `/${path}`;
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.32.0",
4
+ "version": "1.33.0",
5
5
  "description": "Official SDK for Box Plaform APIs",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -36,7 +36,6 @@
36
36
  "http-status": "^1.4.1",
37
37
  "jsonwebtoken": "^8.5.1",
38
38
  "merge-options": "^1.0.1",
39
- "npm-upgrade": "^2.0.2",
40
39
  "promise-queue": "^2.2.3",
41
40
  "request": "^2.88.0",
42
41
  "url-template": "^2.0.8",
@@ -57,6 +56,7 @@
57
56
  "mockery": "^2.1.0",
58
57
  "nock": "^9.6.1",
59
58
  "np": "^5.1.3",
59
+ "npm-upgrade": "^2.0.3",
60
60
  "nyc": "^11.9.0",
61
61
  "shelljs": "^0.8.3",
62
62
  "shelljs-nodecli": "^0.1.1",