files.com 1.0.305 → 1.0.307

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.307
package/lib/Api.js CHANGED
@@ -128,40 +128,49 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
128
128
  }
129
129
  contentType = headers['content-type'] || '';
130
130
  if (!contentType.includes('application/json')) {
131
- _context2.next = 23;
131
+ _context2.next = 27;
132
132
  break;
133
133
  }
134
- _context2.next = 20;
134
+ if (!(headers['content-length'] === '0')) {
135
+ _context2.next = 22;
136
+ break;
137
+ }
138
+ data = response.body;
139
+ _context2.next = 25;
140
+ break;
141
+ case 22:
142
+ _context2.next = 24;
135
143
  return response.json();
136
- case 20:
144
+ case 24:
137
145
  data = _context2.sent;
138
- _context2.next = 36;
146
+ case 25:
147
+ _context2.next = 40;
139
148
  break;
140
- case 23:
149
+ case 27:
141
150
  if (!contentType.includes('text/')) {
142
- _context2.next = 29;
151
+ _context2.next = 33;
143
152
  break;
144
153
  }
145
- _context2.next = 26;
154
+ _context2.next = 30;
146
155
  return response.text();
147
- case 26:
156
+ case 30:
148
157
  data = _context2.sent;
149
- _context2.next = 36;
158
+ _context2.next = 40;
150
159
  break;
151
- case 29:
160
+ case 33:
152
161
  if (!contentType.includes('multipart/form-data')) {
153
- _context2.next = 35;
162
+ _context2.next = 39;
154
163
  break;
155
164
  }
156
- _context2.next = 32;
165
+ _context2.next = 36;
157
166
  return response.formData();
158
- case 32:
167
+ case 36:
159
168
  data = _context2.sent;
160
- _context2.next = 36;
169
+ _context2.next = 40;
161
170
  break;
162
- case 35:
171
+ case 39:
163
172
  data = response.body;
164
- case 36:
173
+ case 40:
165
174
  normalizedResponse = {
166
175
  status: response.status,
167
176
  reason: response.statusText,
@@ -169,37 +178,34 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
169
178
  data: data
170
179
  };
171
180
  if (response.ok) {
172
- _context2.next = 39;
181
+ _context2.next = 43;
173
182
  break;
174
183
  }
175
184
  throw {
176
185
  response: normalizedResponse
177
186
  };
178
- case 39:
187
+ case 43:
179
188
  return _context2.abrupt("return", normalizedResponse);
180
- case 42:
181
- _context2.prev = 42;
189
+ case 46:
190
+ _context2.prev = 46;
182
191
  _context2.t0 = _context2["catch"](8);
183
192
  errors.handleErrorResponse(_context2.t0);
184
- case 45:
193
+ case 49:
185
194
  case "end":
186
195
  return _context2.stop();
187
196
  }
188
- }, _callee2, null, [[8, 42]]);
197
+ }, _callee2, null, [[8, 46]]);
189
198
  }));
190
199
  return function (_x3, _x4, _x5) {
191
200
  return _ref3.apply(this, arguments);
192
201
  };
193
202
  }());
194
203
  (0, _defineProperty2.default)(Api, "sendFilePart", function (externalUrl, verb, data) {
195
- var headers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
196
- var params = {
204
+ var optionsRaw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
205
+ var options = _objectSpread(_objectSpread({}, optionsRaw), {}, {
197
206
  body: data
198
- };
199
- if (headers) {
200
- params.headers = headers;
201
- }
202
- return Api._sendVerbatim(externalUrl, verb, params);
207
+ });
208
+ return Api._sendVerbatim(externalUrl, verb, options);
203
209
  });
204
210
  (0, _defineProperty2.default)(Api, "_autoPaginate", /*#__PURE__*/function () {
205
211
  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.307",
4
4
  "description": "Files.com SDK for JavaScript",
5
5
  "keywords": [
6
6
  "files.com",
package/src/Api.js CHANGED
@@ -88,7 +88,11 @@ class Api {
88
88
  let data
89
89
 
90
90
  if (contentType.includes('application/json')) {
91
- data = await response.json()
91
+ if (headers['content-length'] === '0') {
92
+ data = response.body
93
+ } else {
94
+ data = await response.json()
95
+ }
92
96
  } else if (contentType.includes('text/')) {
93
97
  data = await response.text()
94
98
  } else if (contentType.includes('multipart/form-data')) {
@@ -114,14 +118,13 @@ class Api {
114
118
  }
115
119
  }
116
120
 
117
- static sendFilePart = (externalUrl, verb, data, headers = {}) => {
118
- const params = { body: data }
119
-
120
- if (headers) {
121
- params.headers = headers
121
+ static sendFilePart = (externalUrl, verb, data, optionsRaw = {}) => {
122
+ const options = {
123
+ ...optionsRaw,
124
+ body: data,
122
125
  }
123
126
 
124
- return Api._sendVerbatim(externalUrl, verb, params)
127
+ return Api._sendVerbatim(externalUrl, verb, options)
125
128
  }
126
129
 
127
130
  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)