!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&define(["require","exports","tslib"],e)}(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var f=e("tslib");function c(n,o,s,a,i){return f.__awaiter(this,void 0,void 0,function(){var t,r;return f.__generator(this,function(e){switch(e.label){case 0:return t=a.new(),i.finally(function(){t.cancel()}),t.request.url=n+"/job/artifacts?ticket="+s,o&&(t.request.headers.Authorization="Bearer "+o),[4,t.send()];case 1:if(!e.sent())throw console.error("Unable to check job status.",t.response.message),new Error("Unable to check job status.");if(r=JSON.parse(t.response.content),console.debug(r),r.results&&r.results.some(function(e){return"JobQuit"===e.$type})){if(r=r.results.filter(function(e){return"JobResult"===e.$type})[0])return[2,n+"/job/result?ticket="+s+"&tag="+r.tag];throw console.error("Job failed."),new Error("Job failed.")}return[2,null]}})})}t.checkJobStatus=c,t.checkResult=function r(n,o,s,a,i,u){return f.__awaiter(this,void 0,void 0,function(){var t;return f.__generator(this,function(e){switch(e.label){case 0:return[4,c(n,o,s,i,u)];case 1:return(t=e.sent())?[2,t]:[3,2];case 2:return[4,function(t){return f.__awaiter(this,void 0,void 0,function(){return f.__generator(this,function(e){return[2,new Promise(function(e){return setTimeout(e,t)})]})})}(a)];case 3:return e.sent(),[4,r(n,o,s,1.1*a,i,u)];case 4:return[2,e.sent()]}})})},t.getMapControlNames=function(a,i,u,c,l){return f.__awaiter(this,void 0,void 0,function(){var t,r,n,o,s;return f.__generator(this,function(e){switch(e.label){case 0:return t=[],[4,function(n,o,s,a,i){return f.__awaiter(this,void 0,void 0,function(){var t,r;return f.__generator(this,function(e){switch(e.label){case 0:return t=a.new(),i.finally(function(){t.cancel()}),t.request.url=o+"/job/metadata",t.request.method="POST",t.request.json={template:{itemId:n.itemId,portalUrl:n.portalUrl}},t.request.headers["Content-Type"]="application/json",s&&(t.request.headers.Authorization="Bearer "+s),[4,t.send()];case 1:if(!e.sent())throw console.error("Unable to retrieve template metadata.",t.response.message),new Error("Unable to retrieve template metadata.");return r=JSON.parse(t.response.content),console.debug(r),[2,r]}})})}(a,i,u,c,l)];case 1:if((r=e.sent())&&r.response&&r.response.controls)for(n=0,o=r.response.controls;n<o.length;n++)"Map"===(s=o[n]).controlType&&(s=s.purpose,t.push(s.substring(0,s.indexOf("."))));return[2,t]}})})},t.getServiceToken=function(n,o,s,a){return f.__awaiter(this,void 0,void 0,function(){var t,r;return f.__generator(this,function(e){switch(e.label){case 0:return(t=a.new()).request.url=n+"/auth/token/run",t.request.method="POST",t.request.headers={"Content-Type":"application/json"},t.request.json={accessToken:s,portalUrl:o},[4,t.send()];case 1:if(!e.sent())throw console.error("Unable to generate run token.",t.response.message),Error("Unable to generate run token");return[2,((r=JSON.parse(t.response.content)).response||r).token]}})})},t.runJob=function(n,o,s,a){return f.__awaiter(this,void 0,void 0,function(){var t,r;return f.__generator(this,function(e){switch(e.label){case 0:return(t=a.new()).request.url=n+"/job/run",t.request.method="POST",t.request.headers={"Content-Type":"application/json"},o&&(t.request.headers.Authorization="Bearer "+o),t.request.json=s,[4,t.send()];case 1:if(!e.sent())throw console.error("Unable to run job.",t.response.message),Error("Unable to run job");return r=JSON.parse(t.response.content),console.debug("job/run",r),[2,r]}})})},t.getServiceUrl=function(e,t){var r=e;return r?0===r.toLowerCase().indexOf("http://localhost:3000/")?r="http://localhost:43222/":-1!==(e=r.indexOf("#"))&&(r=r.substring(0,e)):r="https://apps.geocortex.com/"+t+"/",r+="/"===r.slice(-1)?"service":"/service"}});