!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&define(["require","exports","tslib","../../deps/bluebird_fork","../../Validation","../../Errors","../core/ChannelProvider","../../Hooks"],e)}(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=e("tslib"),f=r.__importDefault(e("../../deps/bluebird_fork")),s=e("../../Validation"),c=e("../../Errors"),n=e("../core/ChannelProvider"),e=e("../../Hooks"),l=function(){this.inputs={}},n=(o.prototype.execute=function(r,n,o){var i=this,a=s.validation.string("url",r.url,s.validation.never);return this.getWorkflowSchema(a,o).then(function(e){var t=i.validateInputs(r.arguments,e);if(t)return f.default.reject(t);var l=o.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:i.constructInArgs(r.arguments,e),f:"json"},n.cancellationToken.finally(function(){l.cancel()});var p=(new Date).valueOf();return l.send().then(function(u){return f.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 o=0,i=n;o<i.length;o++){var a=i[o],s=a.name,a=a.value;t.result[s]=a}return t}}n=new c.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,f.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,o=r;n<o.length;n++){var i=o[n],a=i.name,i=i.typeName;s.isString(a)&&s.isString(i)&&(t.inputs[a]={name:a,typeName:i})}return f.default.resolve(t)}r=new c.GenericActivityError(void 0,"Error running Essentials Workflow activity. Error retrieving workflow schema.");return f.default.reject(r)})},o.prototype.validateInputs=function(e,t){var r,n,o=[],i=[];for(r in t.inputs)e.hasOwnProperty(r)||o.push(r);for(n in e)t.inputs.hasOwnProperty(n)||i.push(n);if(0<o.length+i.length){var a="",s="";return o.length&&(a=" Missing parameters: "+o),i.length&&(s=" Unexpected parameters: "+i),new c.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([e.activate(n.ChannelProvider)],o));function o(){}t.RunEssentialsWorkflow=n});