files.com 1.0.304 → 1.0.305
Sign up to get free protection for your applications and to get access to all the features.
- package/_VERSION +1 -1
- package/lib/Api.js +44 -42
- package/package.json +1 -1
- package/src/Api.js +4 -2
package/_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.305
|
package/lib/Api.js
CHANGED
@@ -17,7 +17,8 @@ var _Files = _interopRequireDefault(require("./Files"));
|
|
17
17
|
var errors = _interopRequireWildcard(require("./Errors"));
|
18
18
|
var _Logger = _interopRequireDefault(require("./Logger"));
|
19
19
|
var _utils = require("./utils");
|
20
|
-
var _excluded = ["timeoutSecs"]
|
20
|
+
var _excluded = ["timeoutSecs"],
|
21
|
+
_excluded2 = ["getAgentForUrl"];
|
21
22
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
22
23
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
23
24
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
@@ -86,19 +87,20 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
86
87
|
(0, _classCallCheck2.default)(this, Api);
|
87
88
|
});
|
88
89
|
(0, _defineProperty2.default)(Api, "_sendVerbatim", /*#__PURE__*/function () {
|
89
|
-
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(path, verb,
|
90
|
-
var isExternal, baseUrl, url, agent, response, headers, contentType, data, normalizedResponse;
|
90
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(path, verb, optionsRaw) {
|
91
|
+
var _ref4, getAgentForUrl, options, isExternal, baseUrl, url, agent, response, headers, contentType, data, normalizedResponse;
|
91
92
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
92
93
|
while (1) switch (_context2.prev = _context2.next) {
|
93
94
|
case 0:
|
95
|
+
_ref4 = optionsRaw || {}, getAgentForUrl = _ref4.getAgentForUrl, options = (0, _objectWithoutProperties2.default)(_ref4, _excluded2);
|
94
96
|
isExternal = /^[a-zA-Z]+:\/\//.test(path);
|
95
97
|
baseUrl = _Files.default.getBaseUrl();
|
96
98
|
if (!(!isExternal && !baseUrl)) {
|
97
|
-
_context2.next =
|
99
|
+
_context2.next = 5;
|
98
100
|
break;
|
99
101
|
}
|
100
102
|
throw new errors.ConfigurationError('Base URL has not been set - use Files.setBaseUrl() to set it');
|
101
|
-
case
|
103
|
+
case 5:
|
102
104
|
url = isExternal ? path : "".concat(baseUrl).concat(_Files.default.getEndpointPrefix()).concat(path);
|
103
105
|
_Logger.default.debug("Sending request: ".concat(verb, " ").concat(url));
|
104
106
|
_Logger.default.debug('Sending options:', _objectSpread(_objectSpread({
|
@@ -108,15 +110,15 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
108
110
|
'X-FilesAPI-Key': '<redacted>'
|
109
111
|
})
|
110
112
|
}));
|
111
|
-
_context2.prev =
|
112
|
-
agent = (options === null || options === void 0 ? void 0 : options.agent) || (options === null || options === void 0 ? void 0 : options.httpsAgent) || (options === null || options === void 0 ? void 0 : options.httpAgent);
|
113
|
-
_context2.next =
|
113
|
+
_context2.prev = 8;
|
114
|
+
agent = (getAgentForUrl === null || getAgentForUrl === void 0 ? void 0 : getAgentForUrl(url)) || (options === null || options === void 0 ? void 0 : options.agent) || (options === null || options === void 0 ? void 0 : options.httpsAgent) || (options === null || options === void 0 ? void 0 : options.httpAgent);
|
115
|
+
_context2.next = 12;
|
114
116
|
return fetchWithRetry(url, _objectSpread({
|
115
117
|
agent: agent,
|
116
118
|
method: verb,
|
117
119
|
timeoutSecs: _Files.default.getNetworkTimeout()
|
118
120
|
}, options));
|
119
|
-
case
|
121
|
+
case 12:
|
120
122
|
response = _context2.sent;
|
121
123
|
headers = Object.fromEntries(response.headers.entries());
|
122
124
|
_Logger.default.debug("Status: ".concat(response.status, " ").concat(response.statusText));
|
@@ -126,40 +128,40 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
126
128
|
}
|
127
129
|
contentType = headers['content-type'] || '';
|
128
130
|
if (!contentType.includes('application/json')) {
|
129
|
-
_context2.next =
|
131
|
+
_context2.next = 23;
|
130
132
|
break;
|
131
133
|
}
|
132
|
-
_context2.next =
|
134
|
+
_context2.next = 20;
|
133
135
|
return response.json();
|
134
|
-
case
|
136
|
+
case 20:
|
135
137
|
data = _context2.sent;
|
136
|
-
_context2.next =
|
138
|
+
_context2.next = 36;
|
137
139
|
break;
|
138
|
-
case
|
140
|
+
case 23:
|
139
141
|
if (!contentType.includes('text/')) {
|
140
|
-
_context2.next =
|
142
|
+
_context2.next = 29;
|
141
143
|
break;
|
142
144
|
}
|
143
|
-
_context2.next =
|
145
|
+
_context2.next = 26;
|
144
146
|
return response.text();
|
145
|
-
case
|
147
|
+
case 26:
|
146
148
|
data = _context2.sent;
|
147
|
-
_context2.next =
|
149
|
+
_context2.next = 36;
|
148
150
|
break;
|
149
|
-
case
|
151
|
+
case 29:
|
150
152
|
if (!contentType.includes('multipart/form-data')) {
|
151
|
-
_context2.next =
|
153
|
+
_context2.next = 35;
|
152
154
|
break;
|
153
155
|
}
|
154
|
-
_context2.next =
|
156
|
+
_context2.next = 32;
|
155
157
|
return response.formData();
|
156
|
-
case
|
158
|
+
case 32:
|
157
159
|
data = _context2.sent;
|
158
|
-
_context2.next =
|
160
|
+
_context2.next = 36;
|
159
161
|
break;
|
160
|
-
case 34:
|
161
|
-
data = response.body;
|
162
162
|
case 35:
|
163
|
+
data = response.body;
|
164
|
+
case 36:
|
163
165
|
normalizedResponse = {
|
164
166
|
status: response.status,
|
165
167
|
reason: response.statusText,
|
@@ -167,23 +169,23 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
167
169
|
data: data
|
168
170
|
};
|
169
171
|
if (response.ok) {
|
170
|
-
_context2.next =
|
172
|
+
_context2.next = 39;
|
171
173
|
break;
|
172
174
|
}
|
173
175
|
throw {
|
174
176
|
response: normalizedResponse
|
175
177
|
};
|
176
|
-
case
|
178
|
+
case 39:
|
177
179
|
return _context2.abrupt("return", normalizedResponse);
|
178
|
-
case
|
179
|
-
_context2.prev =
|
180
|
-
_context2.t0 = _context2["catch"](
|
180
|
+
case 42:
|
181
|
+
_context2.prev = 42;
|
182
|
+
_context2.t0 = _context2["catch"](8);
|
181
183
|
errors.handleErrorResponse(_context2.t0);
|
182
|
-
case
|
184
|
+
case 45:
|
183
185
|
case "end":
|
184
186
|
return _context2.stop();
|
185
187
|
}
|
186
|
-
}, _callee2, null, [[
|
188
|
+
}, _callee2, null, [[8, 42]]);
|
187
189
|
}));
|
188
190
|
return function (_x3, _x4, _x5) {
|
189
191
|
return _ref3.apply(this, arguments);
|
@@ -200,9 +202,9 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
200
202
|
return Api._sendVerbatim(externalUrl, verb, params);
|
201
203
|
});
|
202
204
|
(0, _defineProperty2.default)(Api, "_autoPaginate", /*#__PURE__*/function () {
|
203
|
-
var
|
205
|
+
var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(path, verb, params, options, response, metadata) {
|
204
206
|
var _options$autoPaginate;
|
205
|
-
var _response$headers, nextCursor,
|
207
|
+
var _response$headers, nextCursor, _ref6, autoPaginateCount, previousAutoPaginateData, nextPage, nextParams, nextMetadata;
|
206
208
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
207
209
|
while (1) switch (_context3.prev = _context3.next) {
|
208
210
|
case 0:
|
@@ -211,7 +213,7 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
211
213
|
break;
|
212
214
|
}
|
213
215
|
nextCursor = response === null || response === void 0 || (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers['x-files-cursor'];
|
214
|
-
|
216
|
+
_ref6 = metadata || {}, autoPaginateCount = _ref6.autoPaginateCount, previousAutoPaginateData = _ref6.previousAutoPaginateData;
|
215
217
|
if (!nextCursor) {
|
216
218
|
_context3.next = 10;
|
217
219
|
break;
|
@@ -244,11 +246,11 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
244
246
|
}, _callee3);
|
245
247
|
}));
|
246
248
|
return function (_x6, _x7, _x8, _x9, _x10, _x11) {
|
247
|
-
return
|
249
|
+
return _ref5.apply(this, arguments);
|
248
250
|
};
|
249
251
|
}());
|
250
252
|
(0, _defineProperty2.default)(Api, "sendRequest", /*#__PURE__*/function () {
|
251
|
-
var
|
253
|
+
var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(path, verb) {
|
252
254
|
var params,
|
253
255
|
options,
|
254
256
|
metadata,
|
@@ -309,10 +311,10 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
309
311
|
hasParams = (0, _utils.isObject)(params) && !(0, _utils.isEmpty)(params);
|
310
312
|
if (hasParams) {
|
311
313
|
if (verb.toUpperCase() === 'GET') {
|
312
|
-
pairs = Object.entries(params).map(function (
|
313
|
-
var
|
314
|
-
key =
|
315
|
-
value =
|
314
|
+
pairs = Object.entries(params).map(function (_ref8) {
|
315
|
+
var _ref9 = (0, _slicedToArray2.default)(_ref8, 2),
|
316
|
+
key = _ref9[0],
|
317
|
+
value = _ref9[1];
|
316
318
|
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
|
317
319
|
});
|
318
320
|
requestPath += path.includes('?') ? '&' : '?';
|
@@ -343,7 +345,7 @@ var Api = /*#__PURE__*/(0, _createClass2.default)(function Api() {
|
|
343
345
|
}, _callee4);
|
344
346
|
}));
|
345
347
|
return function (_x12, _x13) {
|
346
|
-
return
|
348
|
+
return _ref7.apply(this, arguments);
|
347
349
|
};
|
348
350
|
}());
|
349
351
|
var _default = Api;
|
package/package.json
CHANGED
package/src/Api.js
CHANGED
@@ -40,7 +40,9 @@ const fetchWithRetry = async (url, options, retries = 0) => {
|
|
40
40
|
}
|
41
41
|
|
42
42
|
class Api {
|
43
|
-
static _sendVerbatim = async (path, verb,
|
43
|
+
static _sendVerbatim = async (path, verb, optionsRaw) => {
|
44
|
+
const { getAgentForUrl, ...options } = optionsRaw || {}
|
45
|
+
|
44
46
|
const isExternal = /^[a-zA-Z]+:\/\//.test(path)
|
45
47
|
const baseUrl = Files.getBaseUrl()
|
46
48
|
|
@@ -64,7 +66,7 @@ class Api {
|
|
64
66
|
})
|
65
67
|
|
66
68
|
try {
|
67
|
-
const agent = options?.agent || options?.httpsAgent || options?.httpAgent
|
69
|
+
const agent = getAgentForUrl?.(url) || options?.agent || options?.httpsAgent || options?.httpAgent
|
68
70
|
|
69
71
|
const response = await fetchWithRetry(url, {
|
70
72
|
agent,
|