enterprise-fetch 1.0.0-alpha.5 → 1.0.1
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/README.md +9 -0
- package/dist/client/enterprise-fetch.cjs.js +28 -25
- package/dist/client/enterprise-fetch.cjs.min.js +1 -1
- package/dist/client/enterprise-fetch.esm.js +7 -2
- package/dist/client/enterprise-fetch.esm.min.js +1 -1
- package/dist/enterprise-fetch.cjs.js +7 -2
- package/dist/enterprise-fetch.esm.js +7 -2
- package/package.json +16 -13
- package/dist/util/client/fetch.d.ts +0 -1
- package/package-lock.json +0 -10264
package/README.md
CHANGED
|
@@ -287,3 +287,12 @@ You could use a polyfill service to polyfill missing features by adding a snippe
|
|
|
287
287
|
src="https://polyfill.io/v3/polyfill.min.js?features=AbortController%2Cfetch"
|
|
288
288
|
></script>
|
|
289
289
|
```
|
|
290
|
+
|
|
291
|
+
## Development scripts
|
|
292
|
+
|
|
293
|
+
- `npm start` builds the library and runs through all tests in command line
|
|
294
|
+
- `npm run build` build the library from source and create an instrumented copy of the build for coverage reporting
|
|
295
|
+
- `npm test` starts a http server and runs through all tests in command line
|
|
296
|
+
- `npm run cy:open` starts a http server and opens cypress testing gui for you to execute test specs interactively in a browser window
|
|
297
|
+
- `npm run report:coverage` checks code coverage and starts a http server rendering the test coverage report for review in a browser
|
|
298
|
+
- `npm run serve` starts a http server with a simple browser testing page available at the `/test` route
|
|
@@ -1382,26 +1382,26 @@
|
|
|
1382
1382
|
proxyUri = typeof process !== 'undefined' && process.env.http_proxy || false;
|
|
1383
1383
|
|
|
1384
1384
|
if (!proxyUri) {
|
|
1385
|
-
_context.next =
|
|
1385
|
+
_context.next = 8;
|
|
1386
1386
|
break;
|
|
1387
1387
|
}
|
|
1388
1388
|
|
|
1389
|
-
console.info(
|
|
1389
|
+
// console.info(`Proxying via http_proxy: ${process.env.http_proxy}`);
|
|
1390
1390
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
1391
|
-
_context.next =
|
|
1391
|
+
_context.next = 5;
|
|
1392
1392
|
return ('https-proxy-agent');
|
|
1393
1393
|
|
|
1394
|
-
case
|
|
1394
|
+
case 5:
|
|
1395
1395
|
_yield$import = _context.sent;
|
|
1396
1396
|
HttpsProxyAgent = _yield$import.HttpsProxyAgent;
|
|
1397
1397
|
return _context.abrupt("return", {
|
|
1398
1398
|
agent: new HttpsProxyAgent(proxyUri)
|
|
1399
1399
|
});
|
|
1400
1400
|
|
|
1401
|
-
case
|
|
1401
|
+
case 8:
|
|
1402
1402
|
return _context.abrupt("return", {});
|
|
1403
1403
|
|
|
1404
|
-
case
|
|
1404
|
+
case 9:
|
|
1405
1405
|
case "end":
|
|
1406
1406
|
return _context.stop();
|
|
1407
1407
|
}
|
|
@@ -1446,7 +1446,7 @@
|
|
|
1446
1446
|
_context2.next = 3;
|
|
1447
1447
|
return promiseRetry_1( /*#__PURE__*/function () {
|
|
1448
1448
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(retry, attempt) {
|
|
1449
|
-
var _init$retry, _init$timeout, rtimeout, _init$doRetry, doRetry, options, timeoutMs, controller, _yield$to, _yield$to2, error, response;
|
|
1449
|
+
var _init$retry, _init$timeout, rtimeout, _init$doRetry, doRetry, options, timeoutMs, controller, timeoutId, _yield$to, _yield$to2, error, response;
|
|
1450
1450
|
|
|
1451
1451
|
return regenerator.wrap(function _callee$(_context) {
|
|
1452
1452
|
while (1) {
|
|
@@ -1456,7 +1456,7 @@
|
|
|
1456
1456
|
timeoutMs = rtimeout || fetchDefaults$1.timeout || 60 * 1000; // Abort signal pattern
|
|
1457
1457
|
|
|
1458
1458
|
controller = new browser();
|
|
1459
|
-
setTimeout(function () {
|
|
1459
|
+
timeoutId = setTimeout(function () {
|
|
1460
1460
|
controller.abort();
|
|
1461
1461
|
}, timeoutMs); // Try fetching, wait for error or response
|
|
1462
1462
|
|
|
@@ -1489,74 +1489,77 @@
|
|
|
1489
1489
|
response = _yield$to2[1];
|
|
1490
1490
|
|
|
1491
1491
|
if (!error) {
|
|
1492
|
-
_context.next =
|
|
1492
|
+
_context.next = 34;
|
|
1493
1493
|
break;
|
|
1494
1494
|
}
|
|
1495
1495
|
|
|
1496
|
+
clearTimeout(timeoutId);
|
|
1496
1497
|
_context.t12 = isFunc(doRetry);
|
|
1497
1498
|
|
|
1498
1499
|
if (!_context.t12) {
|
|
1499
|
-
_context.next =
|
|
1500
|
+
_context.next = 31;
|
|
1500
1501
|
break;
|
|
1501
1502
|
}
|
|
1502
1503
|
|
|
1503
|
-
_context.next =
|
|
1504
|
+
_context.next = 30;
|
|
1504
1505
|
return doRetry(attempt, error, {
|
|
1505
1506
|
url: url,
|
|
1506
1507
|
options: init
|
|
1507
1508
|
});
|
|
1508
1509
|
|
|
1509
|
-
case
|
|
1510
|
+
case 30:
|
|
1510
1511
|
_context.t12 = _context.sent;
|
|
1511
1512
|
|
|
1512
|
-
case
|
|
1513
|
+
case 31:
|
|
1513
1514
|
if (!_context.t12) {
|
|
1514
|
-
_context.next =
|
|
1515
|
+
_context.next = 33;
|
|
1515
1516
|
break;
|
|
1516
1517
|
}
|
|
1517
1518
|
|
|
1518
1519
|
retry(error);
|
|
1519
1520
|
|
|
1520
|
-
case
|
|
1521
|
+
case 33:
|
|
1521
1522
|
throw error;
|
|
1522
1523
|
|
|
1523
|
-
case
|
|
1524
|
+
case 34:
|
|
1524
1525
|
if (response.ok) {
|
|
1525
|
-
_context.next =
|
|
1526
|
+
_context.next = 44;
|
|
1526
1527
|
break;
|
|
1527
1528
|
}
|
|
1528
1529
|
|
|
1530
|
+
clearTimeout(timeoutId);
|
|
1529
1531
|
_context.t13 = isFunc(doRetry);
|
|
1530
1532
|
|
|
1531
1533
|
if (!_context.t13) {
|
|
1532
|
-
_context.next =
|
|
1534
|
+
_context.next = 41;
|
|
1533
1535
|
break;
|
|
1534
1536
|
}
|
|
1535
1537
|
|
|
1536
|
-
_context.next =
|
|
1538
|
+
_context.next = 40;
|
|
1537
1539
|
return doRetry(attempt, response, {
|
|
1538
1540
|
url: url,
|
|
1539
1541
|
options: init
|
|
1540
1542
|
});
|
|
1541
1543
|
|
|
1542
|
-
case
|
|
1544
|
+
case 40:
|
|
1543
1545
|
_context.t13 = _context.sent;
|
|
1544
1546
|
|
|
1545
|
-
case
|
|
1547
|
+
case 41:
|
|
1546
1548
|
if (!_context.t13) {
|
|
1547
|
-
_context.next =
|
|
1549
|
+
_context.next = 43;
|
|
1548
1550
|
break;
|
|
1549
1551
|
}
|
|
1550
1552
|
|
|
1551
1553
|
retry(response);
|
|
1552
1554
|
|
|
1553
|
-
case
|
|
1555
|
+
case 43:
|
|
1554
1556
|
return _context.abrupt("return", response);
|
|
1555
1557
|
|
|
1556
|
-
case
|
|
1558
|
+
case 44:
|
|
1559
|
+
clearTimeout(timeoutId);
|
|
1557
1560
|
return _context.abrupt("return", response);
|
|
1558
1561
|
|
|
1559
|
-
case
|
|
1562
|
+
case 46:
|
|
1560
1563
|
case "end":
|
|
1561
1564
|
return _context.stop();
|
|
1562
1565
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("cross-fetch")):"function"==typeof define&&define.amd?define(["exports","cross-fetch"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["enterprise-fetch-legacy"]={},t.fetch)}(this,(function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(e);function o(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return r}}(t,e)||function(t,e){if(t){if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||(o[r]=t[r]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}function c(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function s(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){c(i,n,o,a,u,"next",t)}function u(t){c(i,n,o,a,u,"throw",t)}a(void 0)}))}}function f(t){var e={exports:{}};return t(e,e.exports),e.exports}var p=f((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,i=Object.create(o.prototype),a=new P(n||[]);return i._invoke=function(t,e,r){var n=p;return function(o,i){if(n===l)throw new Error("Generator is already running");if(n===y){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=E(a,r);if(u){if(u===m)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=l;var c=f(t,e,r);if("normal"===c.type){if(n=r.done?y:h,c.arg===m)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=y,r.method="throw",r.arg=c.arg)}}}(t,r,a),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p="suspendedStart",h="suspendedYield",l="executing",y="completed",m={};function v(){}function d(){}function g(){}var b={};b[i]=function(){return this};var w=Object.getPrototypeOf,_=w&&w(w(L([])));_&&_!==r&&n.call(_,i)&&(b=_);var x=g.prototype=v.prototype=Object.create(b);function O(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function T(t,e){function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,p=s.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function E(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,E(t,r),"throw"===r.method))return m;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,m;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,m):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function j(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function L(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:k}}function k(){return{value:e,done:!0}}return d.prototype=x.constructor=g,g.constructor=d,d.displayName=c(g,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,c(t,u,"GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},O(T.prototype),T.prototype[a]=function(){return this},t.AsyncIterator=T,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new T(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(x),c(x,u,"Generator"),x[i]=function(){return this},x.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=L,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(S),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),S(r),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;S(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),m}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function h(t){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(t,e){for(var r in e)Object.defineProperty(t,r,{value:e[r],enumerable:!0,configurable:!0});return t}var y=function(t,e,r){if(!t||"string"==typeof t)throw new TypeError("Please pass an Error to err-code");r||(r={}),"object"===h(e)&&(r=e,e=void 0),null!=e&&(r.code=e);try{return l(t,r)}catch(e){r.message=t.message,r.stack=t.stack;var n=function(){};return n.prototype=Object.create(Object.getPrototypeOf(t)),l(new n,r)}};function m(t,e){"boolean"==typeof e&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(t)),this._timeouts=t,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var v=m;m.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts},m.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null},m.prototype.retry=function(t){if(this._timeout&&clearTimeout(this._timeout),!t)return!1;var e=(new Date).getTime();if(t&&e-this._operationStart>=this._maxRetryTime)return this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(t);var r=this._timeouts.shift();if(void 0===r){if(!this._cachedTimeouts)return!1;this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),r=this._timeouts.shift()}var n=this,o=setTimeout((function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout((function(){n._operationTimeoutCb(n._attempts)}),n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)}),r);return this._options.unref&&o.unref(),!0},m.prototype.attempt=function(t,e){this._fn=t,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){r._operationTimeoutCb()}),r._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},m.prototype.try=function(t){console.log("Using RetryOperation.try() is deprecated"),this.attempt(t)},m.prototype.start=function(t){console.log("Using RetryOperation.start() is deprecated"),this.attempt(t)},m.prototype.start=m.prototype.try,m.prototype.errors=function(){return this._errors},m.prototype.attempts=function(){return this._attempts},m.prototype.mainError=function(){if(0===this._errors.length)return null;for(var t={},e=null,r=0,n=0;n<this._errors.length;n++){var o=this._errors[n],i=o.message,a=(t[i]||0)+1;t[i]=a,a>=r&&(e=o,r=a)}return e};var d=f((function(t,e){e.operation=function(t){var r=e.timeouts(t);return new v(r,{forever:t&&t.forever,unref:t&&t.unref,maxRetryTime:t&&t.maxRetryTime})},e.timeouts=function(t){if(t instanceof Array)return[].concat(t);var e={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var r in t)e[r]=t[r];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],o=0;o<e.retries;o++)n.push(this.createTimeout(o,e));return t&&t.forever&&!n.length&&n.push(this.createTimeout(o,e)),n.sort((function(t,e){return t-e})),n},e.createTimeout=function(t,e){var r=e.randomize?Math.random()+1:1,n=Math.round(r*e.minTimeout*Math.pow(e.factor,t));return n=Math.min(n,e.maxTimeout)},e.wrap=function(t,r,n){if(r instanceof Array&&(n=r,r=null),!n)for(var o in n=[],t)"function"==typeof t[o]&&n.push(o);for(var i=0;i<n.length;i++){var a=n[i],u=t[a];t[a]=function(n){var o=e.operation(r),i=Array.prototype.slice.call(arguments,1),a=i.pop();i.push((function(t){o.retry(t)||(t&&(arguments[0]=o.mainError()),a.apply(this,arguments))})),o.attempt((function(){n.apply(t,i)}))}.bind(t,u),t[a].options=r}}})),g=Object.prototype.hasOwnProperty;function b(t){return t&&"EPROMISERETRY"===t.code&&g.call(t,"retried")}var w=function(t,e){var r,n;return"object"==typeof t&&"function"==typeof e&&(r=e,e=t,t=r),n=d.operation(e),new Promise((function(e,r){n.attempt((function(o){Promise.resolve().then((function(){return t((function(t){throw b(t)&&(t=t.retried),y(new Error("Retrying"),"EPROMISERETRY",{retried:t})}),o)})).then(e,(function(t){b(t)&&(t=t.retried,n.retry(t||new Error))||r(t)}))}))}))},_="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0,x=_.AbortController,O=_.AbortSignal,T=x,E=O,j=x;function S(t,e){return t.then((function(t){return[null,t]})).catch((function(t){return e&&Object.assign(t,e),[t,void 0]}))}T.AbortSignal=E,T.default=j;var P,L={timeout:6e4,retry:{retries:3,minTimeout:400,factor:2},doRetry:(P=s(p.mark((function t(e,r,n){var o,i,a,u,c;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o=n.url,i=n.options,a=i.retry,u=void 0===a?L.retry:a,!(e<=u.retries)){t.next=7;break}if(c="".concat(e,"/").concat(u.retries),r.status&&!(r.status>=400&&404!==r.status)){t.next=7;break}return"message"in r?console.warn("[fetch] Attempt ".concat(c," ").concat(r.name,": ").concat(r.message," ").concat(o)):console.warn("[fetch] Attempt ".concat(c," ").concat(r.status,": ").concat(r.statusText," ").concat(o)),t.abrupt("return",!0);case 7:return t.abrupt("return",!1);case 8:case"end":return t.stop()}}),t)}))),function(t,e,r){return P.apply(this,arguments)})},k=function(){var t=s(p.mark((function t(){var e,r,n;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(e="undefined"!=typeof process&&process.env.http_proxy||!1)){t.next=9;break}return console.info("Proxying via http_proxy: ".concat(process.env.http_proxy)),process.env.NODE_TLS_REJECT_UNAUTHORIZED="0",t.next=6,"https-proxy-agent";case 6:return r=t.sent,n=r.HttpsProxyAgent,t.abrupt("return",{agent:new n(e)});case 9:return t.abrupt("return",{});case 10:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),R=function(t){return"function"==typeof t};function A(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function N(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?A(Object(r),!0).forEach((function(e){o(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):A(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var I="undefined"!=typeof window?window.fetch:n.default,C=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:L,e=function(){var e=s(p.mark((function e(r){var n,o,i=arguments;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},e.next=3,w(function(){var e=s(p.mark((function e(o,i){var c,s,f,h,l,y,m,v,d,g,b;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n.retry&&t.retry,c=n.timeout,s=void 0===c?t.timeout:c,f=n.doRetry,h=void 0===f?t.doRetry||L.doRetry:f,l=u(n,["retry","timeout","doRetry"]),y=s||t.timeout||6e4,m=new T,setTimeout((function(){m.abort()}),y),e.t0=S,e.t1=I,e.t2=r,e.t3=N,e.t4=N,e.t5=N({},l),e.next=12,k();case 12:return e.t6=e.sent,e.t7=(0,e.t4)(e.t5,e.t6),e.t8={},e.t9={signal:m.signal},e.t10=(0,e.t3)(e.t7,e.t8,e.t9),e.t11=(0,e.t1)(e.t2,e.t10),e.next=20,(0,e.t0)(e.t11);case 20:if(v=e.sent,d=a(v,2),g=d[0],b=d[1],!g){e.next=33;break}if(e.t12=R(h),!e.t12){e.next=30;break}return e.next=29,h(i,g,{url:r,options:n});case 29:e.t12=e.sent;case 30:if(!e.t12){e.next=32;break}o(g);case 32:throw g;case 33:if(b.ok){e.next=42;break}if(e.t13=R(h),!e.t13){e.next=39;break}return e.next=38,h(i,b,{url:r,options:n});case 38:e.t13=e.sent;case 39:if(!e.t13){e.next=41;break}o(b);case 41:case 42:return e.abrupt("return",b);case 43:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),n.retry||t.retry);case 3:return o=e.sent,e.abrupt("return",o);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();return e},D=C(L);t.default=D,t.fetchWithDefaults=C,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("cross-fetch")):"function"==typeof define&&define.amd?define(["exports","cross-fetch"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["enterprise-fetch-legacy"]={},t.fetch)}(this,(function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(e);function o(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return r}}(t,e)||function(t,e){if(t){if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||(o[r]=t[r]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}function c(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function s(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){c(i,n,o,a,u,"next",t)}function u(t){c(i,n,o,a,u,"throw",t)}a(void 0)}))}}function f(t){var e={exports:{}};return t(e,e.exports),e.exports}var p=f((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,i=Object.create(o.prototype),a=new L(n||[]);return i._invoke=function(t,e,r){var n=p;return function(o,i){if(n===l)throw new Error("Generator is already running");if(n===y){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=E(a,r);if(u){if(u===m)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=l;var c=f(t,e,r);if("normal"===c.type){if(n=r.done?y:h,c.arg===m)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=y,r.method="throw",r.arg=c.arg)}}}(t,r,a),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p="suspendedStart",h="suspendedYield",l="executing",y="completed",m={};function v(){}function d(){}function g(){}var b={};b[i]=function(){return this};var w=Object.getPrototypeOf,_=w&&w(w(P([])));_&&_!==r&&n.call(_,i)&&(b=_);var x=g.prototype=v.prototype=Object.create(b);function T(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,p=s.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function E(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,E(t,r),"throw"===r.method))return m;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,m;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,m):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function j(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function P(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:k}}function k(){return{value:e,done:!0}}return d.prototype=x.constructor=g,g.constructor=d,d.displayName=c(g,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,c(t,u,"GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},T(O.prototype),O.prototype[a]=function(){return this},t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new O(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},T(x),c(x,u,"Generator"),x[i]=function(){return this},x.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=P,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(S),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),S(r),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;S(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:P(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),m}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function h(t){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(t,e){for(var r in e)Object.defineProperty(t,r,{value:e[r],enumerable:!0,configurable:!0});return t}var y=function(t,e,r){if(!t||"string"==typeof t)throw new TypeError("Please pass an Error to err-code");r||(r={}),"object"===h(e)&&(r=e,e=void 0),null!=e&&(r.code=e);try{return l(t,r)}catch(e){r.message=t.message,r.stack=t.stack;var n=function(){};return n.prototype=Object.create(Object.getPrototypeOf(t)),l(new n,r)}};function m(t,e){"boolean"==typeof e&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(t)),this._timeouts=t,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var v=m;m.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts},m.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null},m.prototype.retry=function(t){if(this._timeout&&clearTimeout(this._timeout),!t)return!1;var e=(new Date).getTime();if(t&&e-this._operationStart>=this._maxRetryTime)return this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(t);var r=this._timeouts.shift();if(void 0===r){if(!this._cachedTimeouts)return!1;this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),r=this._timeouts.shift()}var n=this,o=setTimeout((function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout((function(){n._operationTimeoutCb(n._attempts)}),n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)}),r);return this._options.unref&&o.unref(),!0},m.prototype.attempt=function(t,e){this._fn=t,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){r._operationTimeoutCb()}),r._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},m.prototype.try=function(t){console.log("Using RetryOperation.try() is deprecated"),this.attempt(t)},m.prototype.start=function(t){console.log("Using RetryOperation.start() is deprecated"),this.attempt(t)},m.prototype.start=m.prototype.try,m.prototype.errors=function(){return this._errors},m.prototype.attempts=function(){return this._attempts},m.prototype.mainError=function(){if(0===this._errors.length)return null;for(var t={},e=null,r=0,n=0;n<this._errors.length;n++){var o=this._errors[n],i=o.message,a=(t[i]||0)+1;t[i]=a,a>=r&&(e=o,r=a)}return e};var d=f((function(t,e){e.operation=function(t){var r=e.timeouts(t);return new v(r,{forever:t&&t.forever,unref:t&&t.unref,maxRetryTime:t&&t.maxRetryTime})},e.timeouts=function(t){if(t instanceof Array)return[].concat(t);var e={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var r in t)e[r]=t[r];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],o=0;o<e.retries;o++)n.push(this.createTimeout(o,e));return t&&t.forever&&!n.length&&n.push(this.createTimeout(o,e)),n.sort((function(t,e){return t-e})),n},e.createTimeout=function(t,e){var r=e.randomize?Math.random()+1:1,n=Math.round(r*e.minTimeout*Math.pow(e.factor,t));return n=Math.min(n,e.maxTimeout)},e.wrap=function(t,r,n){if(r instanceof Array&&(n=r,r=null),!n)for(var o in n=[],t)"function"==typeof t[o]&&n.push(o);for(var i=0;i<n.length;i++){var a=n[i],u=t[a];t[a]=function(n){var o=e.operation(r),i=Array.prototype.slice.call(arguments,1),a=i.pop();i.push((function(t){o.retry(t)||(t&&(arguments[0]=o.mainError()),a.apply(this,arguments))})),o.attempt((function(){n.apply(t,i)}))}.bind(t,u),t[a].options=r}}})),g=Object.prototype.hasOwnProperty;function b(t){return t&&"EPROMISERETRY"===t.code&&g.call(t,"retried")}var w=function(t,e){var r,n;return"object"==typeof t&&"function"==typeof e&&(r=e,e=t,t=r),n=d.operation(e),new Promise((function(e,r){n.attempt((function(o){Promise.resolve().then((function(){return t((function(t){throw b(t)&&(t=t.retried),y(new Error("Retrying"),"EPROMISERETRY",{retried:t})}),o)})).then(e,(function(t){b(t)&&(t=t.retried,n.retry(t||new Error))||r(t)}))}))}))},_="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0,x=_.AbortController,T=_.AbortSignal,O=x,E=T,j=x;function S(t,e){return t.then((function(t){return[null,t]})).catch((function(t){return e&&Object.assign(t,e),[t,void 0]}))}O.AbortSignal=E,O.default=j;var L,P={timeout:6e4,retry:{retries:3,minTimeout:400,factor:2},doRetry:(L=s(p.mark((function t(e,r,n){var o,i,a,u,c;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o=n.url,i=n.options,a=i.retry,u=void 0===a?P.retry:a,!(e<=u.retries)){t.next=7;break}if(c="".concat(e,"/").concat(u.retries),r.status&&!(r.status>=400&&404!==r.status)){t.next=7;break}return"message"in r?console.warn("[fetch] Attempt ".concat(c," ").concat(r.name,": ").concat(r.message," ").concat(o)):console.warn("[fetch] Attempt ".concat(c," ").concat(r.status,": ").concat(r.statusText," ").concat(o)),t.abrupt("return",!0);case 7:return t.abrupt("return",!1);case 8:case"end":return t.stop()}}),t)}))),function(t,e,r){return L.apply(this,arguments)})},k=function(){var t=s(p.mark((function t(){var e,r,n;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(e="undefined"!=typeof process&&process.env.http_proxy||!1)){t.next=8;break}return process.env.NODE_TLS_REJECT_UNAUTHORIZED="0",t.next=5,"https-proxy-agent";case 5:return r=t.sent,n=r.HttpsProxyAgent,t.abrupt("return",{agent:new n(e)});case 8:return t.abrupt("return",{});case 9:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),R=function(t){return"function"==typeof t};function A(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function N(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?A(Object(r),!0).forEach((function(e){o(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):A(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var I="undefined"!=typeof window?window.fetch:n.default,C=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:P,e=function(){var e=s(p.mark((function e(r){var n,o,i=arguments;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},e.next=3,w(function(){var e=s(p.mark((function e(o,i){var c,s,f,h,l,y,m,v,d,g,b,w;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n.retry&&t.retry,c=n.timeout,s=void 0===c?t.timeout:c,f=n.doRetry,h=void 0===f?t.doRetry||P.doRetry:f,l=u(n,["retry","timeout","doRetry"]),y=s||t.timeout||6e4,m=new O,v=setTimeout((function(){m.abort()}),y),e.t0=S,e.t1=I,e.t2=r,e.t3=N,e.t4=N,e.t5=N({},l),e.next=12,k();case 12:return e.t6=e.sent,e.t7=(0,e.t4)(e.t5,e.t6),e.t8={},e.t9={signal:m.signal},e.t10=(0,e.t3)(e.t7,e.t8,e.t9),e.t11=(0,e.t1)(e.t2,e.t10),e.next=20,(0,e.t0)(e.t11);case 20:if(d=e.sent,g=a(d,2),b=g[0],w=g[1],!b){e.next=34;break}if(clearTimeout(v),e.t12=R(h),!e.t12){e.next=31;break}return e.next=30,h(i,b,{url:r,options:n});case 30:e.t12=e.sent;case 31:if(!e.t12){e.next=33;break}o(b);case 33:throw b;case 34:if(w.ok){e.next=44;break}if(clearTimeout(v),e.t13=R(h),!e.t13){e.next=41;break}return e.next=40,h(i,w,{url:r,options:n});case 40:e.t13=e.sent;case 41:if(!e.t13){e.next=43;break}o(w);case 43:return e.abrupt("return",w);case 44:return clearTimeout(v),e.abrupt("return",w);case 46:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),n.retry||t.retry);case 3:return o=e.sent,e.abrupt("return",o);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();return e},D=C(P);t.default=D,t.fetchWithDefaults=C,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
@@ -524,7 +524,7 @@
|
|
|
524
524
|
const proxyUri = typeof process !== 'undefined' && process.env.http_proxy || false;
|
|
525
525
|
|
|
526
526
|
if (proxyUri) {
|
|
527
|
-
console.info(`Proxying via http_proxy: ${process.env.http_proxy}`);
|
|
527
|
+
// console.info(`Proxying via http_proxy: ${process.env.http_proxy}`);
|
|
528
528
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
529
529
|
const {
|
|
530
530
|
HttpsProxyAgent
|
|
@@ -559,7 +559,7 @@
|
|
|
559
559
|
const timeoutMs = rtimeout || fetchDefaults$1.timeout || 60 * 1000; // Abort signal pattern
|
|
560
560
|
|
|
561
561
|
const controller = new browser();
|
|
562
|
-
setTimeout(() => {
|
|
562
|
+
const timeoutId = setTimeout(() => {
|
|
563
563
|
controller.abort();
|
|
564
564
|
}, timeoutMs); // Try fetching, wait for error or response
|
|
565
565
|
|
|
@@ -569,6 +569,8 @@
|
|
|
569
569
|
})));
|
|
570
570
|
|
|
571
571
|
if (error) {
|
|
572
|
+
clearTimeout(timeoutId);
|
|
573
|
+
|
|
572
574
|
if (isFunc(doRetry) && (await doRetry(attempt, error, {
|
|
573
575
|
url,
|
|
574
576
|
options: init
|
|
@@ -580,6 +582,8 @@
|
|
|
580
582
|
}
|
|
581
583
|
|
|
582
584
|
if (!response.ok) {
|
|
585
|
+
clearTimeout(timeoutId);
|
|
586
|
+
|
|
583
587
|
if (isFunc(doRetry) && (await doRetry(attempt, response, {
|
|
584
588
|
url,
|
|
585
589
|
options: init
|
|
@@ -590,6 +594,7 @@
|
|
|
590
594
|
return response;
|
|
591
595
|
}
|
|
592
596
|
|
|
597
|
+
clearTimeout(timeoutId);
|
|
593
598
|
return response;
|
|
594
599
|
}, init.retry || fetchDefaults$1.retry);
|
|
595
600
|
return fetchResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("cross-fetch")):"function"==typeof define&&define.amd?define(["exports","cross-fetch"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["enterprise-fetch"]={},t.fetch)}(this,(function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=r(e);function
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("cross-fetch")):"function"==typeof define&&define.amd?define(["exports","cross-fetch"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["enterprise-fetch"]={},t.fetch)}(this,(function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=r(e);function i(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,o)}return r}function s(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function u(t,e){if(null==t)return{};var r,o,i=function(t,e){if(null==t)return{};var r,o,i={},n=Object.keys(t);for(o=0;o<n.length;o++)r=n[o],e.indexOf(r)>=0||(i[r]=t[r]);return i}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(o=0;o<n.length;o++)r=n[o],e.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(t,r)&&(i[r]=t[r])}return i}function a(t,e){for(const r in e)Object.defineProperty(t,r,{value:e[r],enumerable:!0,configurable:!0});return t}var c=function(t,e,r){if(!t||"string"==typeof t)throw new TypeError("Please pass an Error to err-code");r||(r={}),"object"==typeof e&&(r=e,e=void 0),null!=e&&(r.code=e);try{return a(t,r)}catch(e){r.message=t.message,r.stack=t.stack;const o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(t)),a(new o,r)}};function f(t,e){"boolean"==typeof e&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(t)),this._timeouts=t,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var p=f;f.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts},f.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null},f.prototype.retry=function(t){if(this._timeout&&clearTimeout(this._timeout),!t)return!1;var e=(new Date).getTime();if(t&&e-this._operationStart>=this._maxRetryTime)return this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(t);var r=this._timeouts.shift();if(void 0===r){if(!this._cachedTimeouts)return!1;this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),r=this._timeouts.shift()}var o=this,i=setTimeout((function(){o._attempts++,o._operationTimeoutCb&&(o._timeout=setTimeout((function(){o._operationTimeoutCb(o._attempts)}),o._operationTimeout),o._options.unref&&o._timeout.unref()),o._fn(o._attempts)}),r);return this._options.unref&&i.unref(),!0},f.prototype.attempt=function(t,e){this._fn=t,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){r._operationTimeoutCb()}),r._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},f.prototype.try=function(t){console.log("Using RetryOperation.try() is deprecated"),this.attempt(t)},f.prototype.start=function(t){console.log("Using RetryOperation.start() is deprecated"),this.attempt(t)},f.prototype.start=f.prototype.try,f.prototype.errors=function(){return this._errors},f.prototype.attempts=function(){return this._attempts},f.prototype.mainError=function(){if(0===this._errors.length)return null;for(var t={},e=null,r=0,o=0;o<this._errors.length;o++){var i=this._errors[o],n=i.message,s=(t[n]||0)+1;t[n]=s,s>=r&&(e=i,r=s)}return e};var m=function(t){var e={exports:{}};return t(e,e.exports),e.exports}((function(t,e){e.operation=function(t){var r=e.timeouts(t);return new p(r,{forever:t&&t.forever,unref:t&&t.unref,maxRetryTime:t&&t.maxRetryTime})},e.timeouts=function(t){if(t instanceof Array)return[].concat(t);var e={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var r in t)e[r]=t[r];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var o=[],i=0;i<e.retries;i++)o.push(this.createTimeout(i,e));return t&&t.forever&&!o.length&&o.push(this.createTimeout(i,e)),o.sort((function(t,e){return t-e})),o},e.createTimeout=function(t,e){var r=e.randomize?Math.random()+1:1,o=Math.round(r*e.minTimeout*Math.pow(e.factor,t));return o=Math.min(o,e.maxTimeout)},e.wrap=function(t,r,o){if(r instanceof Array&&(o=r,r=null),!o)for(var i in o=[],t)"function"==typeof t[i]&&o.push(i);for(var n=0;n<o.length;n++){var s=o[n],u=t[s];t[s]=function(o){var i=e.operation(r),n=Array.prototype.slice.call(arguments,1),s=n.pop();n.push((function(t){i.retry(t)||(t&&(arguments[0]=i.mainError()),s.apply(this,arguments))})),i.attempt((function(){o.apply(t,n)}))}.bind(t,u),t[s].options=r}}})),h=Object.prototype.hasOwnProperty;function l(t){return t&&"EPROMISERETRY"===t.code&&h.call(t,"retried")}var y=function(t,e){var r,o;return"object"==typeof t&&"function"==typeof e&&(r=e,e=t,t=r),o=m.operation(e),new Promise((function(e,r){o.attempt((function(i){Promise.resolve().then((function(){return t((function(t){throw l(t)&&(t=t.retried),c(new Error("Retrying"),"EPROMISERETRY",{retried:t})}),i)})).then(e,(function(t){l(t)&&(t=t.retried,o.retry(t||new Error))||r(t)}))}))}))};const{AbortController:_,AbortSignal:d}="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0;var b=_,T=d,g=_;b.AbortSignal=T,b.default=g;const v={timeout:6e4,retry:{retries:3,minTimeout:400,factor:2},doRetry:async(t,e,{url:r,options:o})=>{const{retry:i=v.retry}=o;if(t<=i.retries){const o=`${t}/${i.retries}`;if(!e.status||e.status>=400&&404!==e.status)return"message"in e?console.warn(`[fetch] Attempt ${o} ${e.name}: ${e.message} ${r}`):console.warn(`[fetch] Attempt ${o} ${e.status}: ${e.statusText} ${r}`),!0}return!1}},w=t=>"function"==typeof t,O="undefined"!=typeof window?window.fetch:o.default,j=(t=v)=>async(e,r={})=>await y((async(o,i)=>{const{retry:n=t.retry,timeout:a=t.timeout,doRetry:c=t.doRetry||v.doRetry}=r,f=u(r,["retry","timeout","doRetry"]),p=a||t.timeout||6e4,m=new b,h=setTimeout((()=>{m.abort()}),p),[l,y]=await(_=O(e,s(s(s({},f),await(async()=>{const t="undefined"!=typeof process&&process.env.http_proxy||!1;if(t){process.env.NODE_TLS_REJECT_UNAUTHORIZED="0";const{HttpsProxyAgent:e}=await"https-proxy-agent";return{agent:new e(t)}}return{}})()),{},{signal:m.signal})),_.then((function(t){return[null,t]})).catch((function(t){return d&&Object.assign(t,d),[t,void 0]})));var _,d;if(l)throw clearTimeout(h),w(c)&&await c(i,l,{url:e,options:r})&&o(l),l;return y.ok?(clearTimeout(h),y):(clearTimeout(h),w(c)&&await c(i,y,{url:e,options:r})&&o(y),y)}),r.retry||t.retry);var R=j(v);t.default=R,t.fetchWithDefaults=j,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
@@ -73,7 +73,7 @@ const proxyAgent = async () => {
|
|
|
73
73
|
const proxyUri = typeof process !== 'undefined' && process.env.http_proxy || false;
|
|
74
74
|
|
|
75
75
|
if (proxyUri) {
|
|
76
|
-
console.info(`Proxying via http_proxy: ${process.env.http_proxy}`);
|
|
76
|
+
// console.info(`Proxying via http_proxy: ${process.env.http_proxy}`);
|
|
77
77
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
78
78
|
const {
|
|
79
79
|
HttpsProxyAgent
|
|
@@ -107,7 +107,7 @@ const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
|
107
107
|
const timeoutMs = rtimeout || fetchDefaults$1.timeout || 60 * 1000; // Abort signal pattern
|
|
108
108
|
|
|
109
109
|
const controller = new AbortController__default['default']();
|
|
110
|
-
setTimeout(() => {
|
|
110
|
+
const timeoutId = setTimeout(() => {
|
|
111
111
|
controller.abort();
|
|
112
112
|
}, timeoutMs); // Try fetching, wait for error or response
|
|
113
113
|
|
|
@@ -120,6 +120,8 @@ const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
|
120
120
|
}));
|
|
121
121
|
|
|
122
122
|
if (error) {
|
|
123
|
+
clearTimeout(timeoutId);
|
|
124
|
+
|
|
123
125
|
if (isFunc(doRetry) && (await doRetry(attempt, error, {
|
|
124
126
|
url,
|
|
125
127
|
options: init
|
|
@@ -131,6 +133,8 @@ const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
if (!response.ok) {
|
|
136
|
+
clearTimeout(timeoutId);
|
|
137
|
+
|
|
134
138
|
if (isFunc(doRetry) && (await doRetry(attempt, response, {
|
|
135
139
|
url,
|
|
136
140
|
options: init
|
|
@@ -141,6 +145,7 @@ const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
|
141
145
|
return response;
|
|
142
146
|
}
|
|
143
147
|
|
|
148
|
+
clearTimeout(timeoutId);
|
|
144
149
|
return response;
|
|
145
150
|
}, init.retry || fetchDefaults$1.retry);
|
|
146
151
|
return fetchResponse;
|
|
@@ -42,7 +42,7 @@ const proxyAgent = async () => {
|
|
|
42
42
|
const proxyUri = typeof process !== 'undefined' && process.env.http_proxy || false;
|
|
43
43
|
|
|
44
44
|
if (proxyUri) {
|
|
45
|
-
console.info(`Proxying via http_proxy: ${process.env.http_proxy}`);
|
|
45
|
+
// console.info(`Proxying via http_proxy: ${process.env.http_proxy}`);
|
|
46
46
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
47
47
|
const {
|
|
48
48
|
HttpsProxyAgent
|
|
@@ -76,7 +76,7 @@ const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
|
76
76
|
const timeoutMs = rtimeout || fetchDefaults$1.timeout || 60 * 1000; // Abort signal pattern
|
|
77
77
|
|
|
78
78
|
const controller = new AbortController();
|
|
79
|
-
setTimeout(() => {
|
|
79
|
+
const timeoutId = setTimeout(() => {
|
|
80
80
|
controller.abort();
|
|
81
81
|
}, timeoutMs); // Try fetching, wait for error or response
|
|
82
82
|
|
|
@@ -89,6 +89,8 @@ const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
|
89
89
|
}));
|
|
90
90
|
|
|
91
91
|
if (error) {
|
|
92
|
+
clearTimeout(timeoutId);
|
|
93
|
+
|
|
92
94
|
if (isFunc(doRetry) && (await doRetry(attempt, error, {
|
|
93
95
|
url,
|
|
94
96
|
options: init
|
|
@@ -100,6 +102,8 @@ const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
if (!response.ok) {
|
|
105
|
+
clearTimeout(timeoutId);
|
|
106
|
+
|
|
103
107
|
if (isFunc(doRetry) && (await doRetry(attempt, response, {
|
|
104
108
|
url,
|
|
105
109
|
options: init
|
|
@@ -110,6 +114,7 @@ const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
|
110
114
|
return response;
|
|
111
115
|
}
|
|
112
116
|
|
|
117
|
+
clearTimeout(timeoutId);
|
|
113
118
|
return response;
|
|
114
119
|
}, init.retry || fetchDefaults$1.retry);
|
|
115
120
|
return fetchResponse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "enterprise-fetch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A fetch wrapper to leverage enterprise features such as retry policy and request timeout",
|
|
5
5
|
"browser": "dist/client/enterprise-fetch.esm.min.js",
|
|
6
6
|
"module": "dist/enterprise-fetch.esm.js",
|
|
@@ -18,10 +18,13 @@
|
|
|
18
18
|
"mocha:run": "mocha --es-module-specifier-resolution=node --require @babel/register --timeout 500000 --exit cypress/integration/node.spec.js",
|
|
19
19
|
"nyc:test": "nyc npm test",
|
|
20
20
|
"prestart": "npm run build",
|
|
21
|
-
"report:coverage": "nyc report --reporter=html",
|
|
21
|
+
"report:coverage": "nyc report --reporter=html && serve ./coverage",
|
|
22
22
|
"report:coverage:text": "nyc report --reporter=text",
|
|
23
23
|
"report:coverage:summary": "nyc report --reporter=text-summary",
|
|
24
|
-
"
|
|
24
|
+
"codecov:linux": "curl -Os https://uploader.codecov.io/latest/linux/codecov && chmod +x codecov",
|
|
25
|
+
"codecov:macos": "curl -Os https://uploader.codecov.io/latest/macos/codecov && chmod +x codecov",
|
|
26
|
+
"codecov:windows": "curl -Os https://uploader.codecov.io/latest/windows/codecov.exe",
|
|
27
|
+
"report-coverage": "npm run codecov:windows && codecov -t 9f816f9c-8faa-4812-9bb2-5235c8c11468",
|
|
25
28
|
"start": "npm run nyc:test",
|
|
26
29
|
"serve": "serve .",
|
|
27
30
|
"test": "start-server-and-test serve http://localhost:5000 cypress:run"
|
|
@@ -42,8 +45,8 @@
|
|
|
42
45
|
"repository": "https://github.com/neilflatley/enterprise-fetch",
|
|
43
46
|
"dependencies": {
|
|
44
47
|
"abort-controller": "^3.0.0",
|
|
45
|
-
"await-to-js": "^
|
|
46
|
-
"cross-fetch": "^3.
|
|
48
|
+
"await-to-js": "^3.0.0",
|
|
49
|
+
"cross-fetch": "^3.1.2",
|
|
47
50
|
"https-proxy-agent": "^5.0.0",
|
|
48
51
|
"promise-retry": "^2.0.1"
|
|
49
52
|
},
|
|
@@ -56,22 +59,22 @@
|
|
|
56
59
|
"@babel/plugin-transform-classes": "^7.13.0",
|
|
57
60
|
"@babel/plugin-transform-regenerator": "^7.12.13",
|
|
58
61
|
"@babel/plugin-transform-runtime": "^7.13.10",
|
|
59
|
-
"@babel/preset-env": "^7.13.
|
|
62
|
+
"@babel/preset-env": "^7.13.12",
|
|
60
63
|
"@babel/preset-typescript": "^7.13.0",
|
|
61
64
|
"@babel/register": "^7.13.8",
|
|
62
65
|
"@cypress/code-coverage": "^3.9.2",
|
|
63
66
|
"@rollup/plugin-babel": "^5.3.0",
|
|
64
67
|
"@rollup/plugin-commonjs": "^17.1.0",
|
|
65
68
|
"@rollup/plugin-node-resolve": "^11.2.0",
|
|
66
|
-
"@types/node": "^14.14.
|
|
69
|
+
"@types/node": "^14.14.35",
|
|
67
70
|
"@types/node-fetch": "^2.5.8",
|
|
68
71
|
"@types/promise-retry": "^1.1.3",
|
|
69
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
70
|
-
"@typescript-eslint/parser": "^4.
|
|
72
|
+
"@typescript-eslint/eslint-plugin": "^4.19.0",
|
|
73
|
+
"@typescript-eslint/parser": "^4.19.0",
|
|
71
74
|
"chai": "^4.3.4",
|
|
72
75
|
"cross-env": "^7.0.3",
|
|
73
|
-
"cypress": "^6.
|
|
74
|
-
"eslint": "^7.
|
|
76
|
+
"cypress": "^6.8.0",
|
|
77
|
+
"eslint": "^7.22.0",
|
|
75
78
|
"eslint-config-prettier": "^8.1.0",
|
|
76
79
|
"eslint-import-resolver-typescript": "^2.4.0",
|
|
77
80
|
"eslint-plugin-import": "^2.22.1",
|
|
@@ -81,10 +84,10 @@
|
|
|
81
84
|
"nyc": "^15.1.0",
|
|
82
85
|
"prettier": "^2.2.1",
|
|
83
86
|
"rimraf": "^3.0.2",
|
|
84
|
-
"rollup": "^2.
|
|
87
|
+
"rollup": "^2.42.3",
|
|
85
88
|
"rollup-plugin-terser": "^7.0.2",
|
|
86
89
|
"serve": "^11.3.2",
|
|
87
|
-
"start-server-and-test": "^1.12.
|
|
90
|
+
"start-server-and-test": "^1.12.1",
|
|
88
91
|
"tslint": "^6.1.3",
|
|
89
92
|
"typescript": "^4.2.3"
|
|
90
93
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default fetch;
|