files.com 1.0.305 → 1.0.306

Sign up to get free protection for your applications and to get access to all the features.
package/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.305
1
+ 1.0.306
package/lib/Api.js CHANGED
@@ -192,14 +192,11 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
192
192
  };
193
193
  }());
194
194
  (0, _defineProperty2.default)(Api, "sendFilePart", function (externalUrl, verb, data) {
195
- var headers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
196
- var params = {
195
+ var optionsRaw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
196
+ var options = _objectSpread(_objectSpread({}, optionsRaw), {}, {
197
197
  body: data
198
- };
199
- if (headers) {
200
- params.headers = headers;
201
- }
202
- return Api._sendVerbatim(externalUrl, verb, params);
198
+ });
199
+ return Api._sendVerbatim(externalUrl, verb, options);
203
200
  });
204
201
  (0, _defineProperty2.default)(Api, "_autoPaginate", /*#__PURE__*/function () {
205
202
  var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(path, verb, params, options, response, metadata) {
@@ -939,7 +939,7 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
939
939
  });
940
940
  readableStream.on('data', /*#__PURE__*/function () {
941
941
  var _ref19 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(chunk) {
942
- var nextLength, excessLength, chunkBuffer, tailLength, lastChunkForPart, firstChunkForNextPart, buffer, nextFileUploadPart, upload_uri, uploadPromise;
942
+ var nextLength, excessLength, chunkBuffer, _options$getAgentForU, tailLength, lastChunkForPart, firstChunkForNextPart, buffer, nextFileUploadPart, upload_uri, agent, uploadPromise;
943
943
  return _regenerator.default.wrap(function _callee15$(_context15) {
944
944
  while (1) switch (_context15.prev = _context15.next) {
945
945
  case 0:
@@ -948,7 +948,7 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
948
948
  excessLength = nextLength - firstFileUploadPart.partsize;
949
949
  chunkBuffer = _safeBuffer.Buffer.from(chunk);
950
950
  if (!(excessLength > 0)) {
951
- _context15.next = 27;
951
+ _context15.next = 28;
952
952
  break;
953
953
  }
954
954
  readableStream.pause();
@@ -963,52 +963,55 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
963
963
  return File._continueUpload(destinationPath, ++part, firstFileUploadPart, options);
964
964
  case 13:
965
965
  nextFileUploadPart = _context15.sent;
966
- upload_uri = determinePartUploadUri(nextFileUploadPart);
967
- uploadPromise = _Api.default.sendFilePart(upload_uri, 'PUT', buffer);
966
+ upload_uri = determinePartUploadUri(nextFileUploadPart); // instantiate an httpsAgent dynamically if needed
967
+ agent = ((_options$getAgentForU = options.getAgentForUrl) === null || _options$getAgentForU === void 0 ? void 0 : _options$getAgentForU.call(options, upload_uri)) || (options === null || options === void 0 ? void 0 : options.agent);
968
+ uploadPromise = _Api.default.sendFilePart(upload_uri, 'PUT', buffer, {
969
+ agent: agent
970
+ });
968
971
  if (!firstFileUploadPart.parallel_parts) {
969
- _context15.next = 20;
972
+ _context15.next = 21;
970
973
  break;
971
974
  }
972
975
  concurrentUploads.push(uploadPromise);
973
- _context15.next = 22;
976
+ _context15.next = 23;
974
977
  break;
975
- case 20:
976
- _context15.next = 22;
978
+ case 21:
979
+ _context15.next = 23;
977
980
  return uploadPromise;
978
- case 22:
981
+ case 23:
979
982
  chunks = [firstChunkForNextPart];
980
983
  length = firstChunkForNextPart.length;
981
984
  readableStream.resume();
982
- _context15.next = 29;
985
+ _context15.next = 30;
983
986
  break;
984
- case 27:
987
+ case 28:
985
988
  chunks.push(chunkBuffer);
986
989
  length += chunk.length;
987
- case 29:
988
- _context15.next = 34;
990
+ case 30:
991
+ _context15.next = 35;
989
992
  break;
990
- case 31:
991
- _context15.prev = 31;
993
+ case 32:
994
+ _context15.prev = 32;
992
995
  _context15.t0 = _context15["catch"](0);
993
996
  reject(_context15.t0);
994
- case 34:
997
+ case 35:
995
998
  case "end":
996
999
  return _context15.stop();
997
1000
  }
998
- }, _callee15, null, [[0, 31]]);
1001
+ }, _callee15, null, [[0, 32]]);
999
1002
  }));
1000
1003
  return function (_x20) {
1001
1004
  return _ref19.apply(this, arguments);
1002
1005
  };
1003
1006
  }());
1004
1007
  readableStream.on('end', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16() {
1005
- var buffer, nextFileUploadPart, upload_uri, response, createdFile;
1008
+ var _options$getAgentForU2, buffer, nextFileUploadPart, upload_uri, agent, response, createdFile;
1006
1009
  return _regenerator.default.wrap(function _callee16$(_context16) {
1007
1010
  while (1) switch (_context16.prev = _context16.next) {
1008
1011
  case 0:
1009
1012
  _context16.prev = 0;
1010
1013
  if (!(chunks.length > 0)) {
1011
- _context16.next = 8;
1014
+ _context16.next = 9;
1012
1015
  break;
1013
1016
  }
1014
1017
  buffer = _safeBuffer.Buffer.concat(chunks);
@@ -1016,29 +1019,32 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
1016
1019
  return File._continueUpload(destinationPath, ++part, firstFileUploadPart, options);
1017
1020
  case 5:
1018
1021
  nextFileUploadPart = _context16.sent;
1019
- upload_uri = determinePartUploadUri(nextFileUploadPart);
1020
- concurrentUploads.push(_Api.default.sendFilePart(upload_uri, 'PUT', buffer));
1021
- case 8:
1022
- _context16.next = 10;
1022
+ upload_uri = determinePartUploadUri(nextFileUploadPart); // instantiate an httpsAgent dynamically if needed
1023
+ agent = ((_options$getAgentForU2 = options.getAgentForUrl) === null || _options$getAgentForU2 === void 0 ? void 0 : _options$getAgentForU2.call(options, upload_uri)) || (options === null || options === void 0 ? void 0 : options.agent);
1024
+ concurrentUploads.push(_Api.default.sendFilePart(upload_uri, 'PUT', buffer, {
1025
+ agent: agent
1026
+ }));
1027
+ case 9:
1028
+ _context16.next = 11;
1023
1029
  return Promise.all(concurrentUploads);
1024
- case 10:
1025
- _context16.next = 12;
1030
+ case 11:
1031
+ _context16.next = 13;
1026
1032
  return File._completeUpload(firstFileUploadPart, options);
1027
- case 12:
1033
+ case 13:
1028
1034
  response = _context16.sent;
1029
1035
  createdFile = new File(response.data, options);
1030
1036
  resolve(createdFile);
1031
- _context16.next = 20;
1037
+ _context16.next = 21;
1032
1038
  break;
1033
- case 17:
1034
- _context16.prev = 17;
1039
+ case 18:
1040
+ _context16.prev = 18;
1035
1041
  _context16.t0 = _context16["catch"](0);
1036
1042
  reject(_context16.t0);
1037
- case 20:
1043
+ case 21:
1038
1044
  case "end":
1039
1045
  return _context16.stop();
1040
1046
  }
1041
- }, _callee16, null, [[0, 17]]);
1047
+ }, _callee16, null, [[0, 18]]);
1042
1048
  })));
1043
1049
  });
1044
1050
  case 10:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "files.com",
3
- "version": "1.0.305",
3
+ "version": "1.0.306",
4
4
  "description": "Files.com SDK for JavaScript",
5
5
  "keywords": [
6
6
  "files.com",
package/src/Api.js CHANGED
@@ -114,14 +114,13 @@ class Api {
114
114
  }
115
115
  }
116
116
 
117
- static sendFilePart = (externalUrl, verb, data, headers = {}) => {
118
- const params = { body: data }
119
-
120
- if (headers) {
121
- params.headers = headers
117
+ static sendFilePart = (externalUrl, verb, data, optionsRaw = {}) => {
118
+ const options = {
119
+ ...optionsRaw,
120
+ body: data,
122
121
  }
123
122
 
124
- return Api._sendVerbatim(externalUrl, verb, params)
123
+ return Api._sendVerbatim(externalUrl, verb, options)
125
124
  }
126
125
 
127
126
  static _autoPaginate = async (path, verb, params, options, response, metadata) => {
@@ -121,7 +121,11 @@ class File {
121
121
  const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, firstFileUploadPart, options)
122
122
 
123
123
  const upload_uri = determinePartUploadUri(nextFileUploadPart)
124
- const uploadPromise = Api.sendFilePart(upload_uri, 'PUT', buffer)
124
+
125
+ // instantiate an httpsAgent dynamically if needed
126
+ const agent = options.getAgentForUrl?.(upload_uri) || options?.agent
127
+
128
+ const uploadPromise = Api.sendFilePart(upload_uri, 'PUT', buffer, { agent })
125
129
 
126
130
  if (firstFileUploadPart.parallel_parts) {
127
131
  concurrentUploads.push(uploadPromise)
@@ -149,7 +153,11 @@ class File {
149
153
  const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, firstFileUploadPart, options)
150
154
 
151
155
  const upload_uri = determinePartUploadUri(nextFileUploadPart)
152
- concurrentUploads.push(Api.sendFilePart(upload_uri, 'PUT', buffer))
156
+
157
+ // instantiate an httpsAgent dynamically if needed
158
+ const agent = options.getAgentForUrl?.(upload_uri) || options?.agent
159
+
160
+ concurrentUploads.push(Api.sendFilePart(upload_uri, 'PUT', buffer, { agent }))
153
161
  }
154
162
 
155
163
  await Promise.all(concurrentUploads)