!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","./ChannelProvider","../../Hooks"],e)}(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e("tslib"),s=n.__importDefault(e("../../deps/bluebird_fork")),r=e("../../Validation"),u=e("../../Errors"),o=e("./ChannelProvider"),e=e("../../Hooks");function l(e){return null==e?"":"boolean"==typeof e?!0===e?"true":"false":"number"==typeof e?encodeURIComponent(e.toString()):"string"==typeof e?encodeURIComponent(e):"object"==typeof e?encodeURIComponent(JSON.stringify(e)):""}function f(e){var t,n=[];for(t in e){var r=e[t];if(r instanceof Array)for(var o=0,i=r;o<i.length;o++){var a=i[o];n.push(t+"="+l(a))}else n.push(t+"="+l(r))}return n.join("&")}i.prototype.execute=function(o,e,t){var i=t.create(o.channel,o.channelName),n=i.request.url=r.validation.string("url",o.url,r.validation.never);i.request.headers=o.headers||{},i.timeout=r.validation.number("timeout",o.timeout,6e4),i.corsWithCredentials=r.validation.boolean("corsWithCredentials",o.corsWithCredentials,!1);t=o.query;null!=t&&(n=n.split("#")[0],t=f(t),n=0<=n.indexOf("?")?n+"&"+t:n+"?"+t,i.request.url=n);n=o.method;i.request.method="string"==typeof n?n:"GET";n=o.blob;n instanceof ArrayBuffer&&(i.request.content=n);n=o.text;"string"==typeof n&&(i.request.content=n);n=o.json;void 0!==n&&(i.request.json=n);n=o.form;null!=n&&(i.request.content=f(n)),"blob"===o.expect&&(i.binary=!0),e.cancellationToken.finally(function(){i.cancel()});var a=(new Date).valueOf();return i.send().then(function(r){return s.default.attempt(function(){var e,t={channel:i,elapsed:(new Date).valueOf()-a},n=i.response.content;"string"==typeof n&&(t.text=n,"json"===o.expect&&(r||"string"==typeof(e=(e=i).response.headers["Content-Type"])&&"application/json"===e.split(";")[0].trim())&&(t.json=JSON.parse(n))),n instanceof ArrayBuffer&&(t.blob=n);n=i.response.payload;if(null!=n&&(t.json=n),r)return t;n=new u.GenericActivityError("WF0014","Cannot perform web request.");return n.timedOut=t.elapsed>=i.timeout,n.elapsed=t.elapsed,n.error=i.response.error,n.partialResult=t,s.default.reject(n)})})},i.action="gcx:wf:core:request:WebRequest",i.suite="gcx:wf:builtin",o=n.__decorate([e.activate(o.ChannelProvider)],i);function i(){}t.WebRequest=o});