define(["require","exports","tslib","../../deps/bluebird_fork","../../Validation","../../Errors","../core/ChannelProvider","../../Hooks"],function(e,t,r,c,s,f,n,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),c=r.__importDefault(c);var l=function(){this.inputs={}},n=(o.prototype.execute=function(r,n,i){var o=this,a=s.validation.string("url",r.url,s.validation.never);return this.getWorkflowSchema(a,i).then(function(e){var t=o.validateInputs(r.arguments,e);if(t)return c.default.reject(t);var l=i.create(void 0,"geocortex");l.request.url=a+"/run",l.timeout=s.validation.number("timeout",r.timeout,6e4),l.request.method="POST",l.request.headers["Content-Type"]="application/x-www-form-urlencoded",l.request.json={inargs:o.constructInArgs(r.arguments,e),f:"json"},n.cancellationToken.finally(function(){l.cancel()});var p=(new Date).valueOf();return l.send().then(function(u){return c.default.attempt(function(){var e=(new Date).valueOf()-p,t={result:{}};if(u){var r=l.getResponseData(l.response.payload);if("Completed"===r.status){var n=r.outputs;if(n)for(var i=0,o=n;i<o.length;i++){var a=o[i],s=a.name,a=a.value;t.result[s]=a}return t}}n=new f.GenericActivityError(void 0,"Error running Essentials Workflow activity.");return n.timedOut=e>=l.timeout,n.elapsed=e,n.error=l.response.error,n.partialResult=t,c.default.reject(n)})})})},o.prototype.isString=function(e){return"string"==typeof e},o.prototype.getWorkflowSchema=function(e,t){var s=this,u=t.create(void 0,"geocortex");return u.request.url=e,u.request.json={f:"json",deep:!0},u.send().then(function(e){if(e){var t=new l,r=u.getResponseData(u.response.payload).inputs;if(r)for(var n=0,i=r;n<i.length;n++){var o=i[n],a=o.name,o=o.typeName;s.isString(a)&&s.isString(o)&&(t.inputs[a]={name:a,typeName:o})}return c.default.resolve(t)}r=new f.GenericActivityError(void 0,"Error running Essentials Workflow activity. Error retrieving workflow schema.");return c.default.reject(r)})},o.prototype.validateInputs=function(e,t){var r,n,i=[],o=[];for(r in t.inputs)e.hasOwnProperty(r)||i.push(r);for(n in e)t.inputs.hasOwnProperty(n)||o.push(n);if(0<i.length+o.length){var a="",s="";return i.length&&(a=" Missing parameters: "+i),o.length&&(s=" Unexpected parameters: "+o),new f.GenericActivityError(void 0,"Invalid parameters supplied to Essentials Workflow activity."+a+s)}},o.prototype.constructInArgs=function(e,t){var r,n=[];for(r in e)n.push({name:r,typeName:t.inputs[r].typeName,value:e[r]});return n},o.action="gcx:wf:essentials::RunEssentialsWorkflow",o.suite="gcx:wf:builtin",r.__decorate([i.activate(n.ChannelProvider)],o));function o(){}t.RunEssentialsWorkflow=n});