"use strict";var a=b(require("isomorphic-fetch"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.retrieveDocHtml=j;function b(a){return a&&a.__esModule?a:{default:a}}function c(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function d(a){return function(){var b=this,d=arguments;return new Promise(function(e,f){function g(a){c(i,e,f,g,h,"next",a)}function h(a){c(i,e,f,g,h,"throw",a)}var i=a.apply(b,d);g(void 0)})}}var e=10;function f(){return g.apply(this,arguments)}function g(){return g=d(regeneratorRuntime.mark(function a(b,c,d,f,g,h,i,j){var m,n,o,p;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!(f instanceof Error)){a.next=4;break}return console.error(f),m=f.toString?f.toString():""+f,a.abrupt("return",i(m));case 4:return a.next=6,f.text();case 6:if(n=a.sent,!(200>=f.status)){a.next=12;break}n=c?k(n):l(n),i(n),a.next=22;break;case 12:if(!(300<=f.status&&307>=f.status)){a.next=22;break}if(f.headers&&(o=f.headers.get("Location")),!o){a.next=21;break}if(p=d+1,!(p<e)){a.next=20;break}this.invokeHelper(o,c,p,i,j),a.next=21;break;case 20:return a.abrupt("return",j("Too many redirects, count: "+p+" last URL: "+o));case 21:return a.abrupt("return",j("No target url in the Location header, HTTP redirect status code: "+f.status));case 22:return n=l(n),(null===n||""===n)&&(n="<h2>"+f.status+"</h2><h3>"+f.statusText+"</h3>"),a.abrupt("return",j(n));case 25:case"end":return a.stop();}},a,this)})),g.apply(this,arguments)}function h(){return i.apply(this,arguments)}function i(){return i=d(regeneratorRuntime.mark(function b(c,d,e,g,h){var i,j,k;return regeneratorRuntime.wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return i=new Headers,i.set("Accept","text/html"),j={method:"get",url:c,headers:i},b.prev=3,b.next=6,(0,a["default"])(c,j);case 6:k=b.sent,f(c,d,e,k,j,!1,g,h),b.next=13;break;case 10:b.prev=10,b.t0=b["catch"](3),f(c,d,e,b.t0,j,!0,h,h);case 13:case"end":return b.stop();}},b,null,[[3,10]])})),i.apply(this,arguments)}function j(a,b){return new Promise(function(c,d){h(a,b,0,c,d)})}function k(a){if(!a)return null;var b=new DOMParser,c=b.parseFromString(a,"text/html"),d=c.querySelector(".apicMainContent");return d?d.innerHTML:a}function l(a){if(!a)return null;var b=new DOMParser,c=b.parseFromString(a,"text/html");return c.body?c.body.innerHTML:a}