define(["require","exports","tslib","esri/config","./ArcGisApiVersion","../../Validation"],function(r,e,i,t,s,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),t=i.__importDefault(t);n.prototype.execute=function(r){var e=o.validation.string("url",r.url,o.validation.never),r=o.validation.boolean("withCredentials",r.withCredentials,!1);return{success:this.registerCorsUrl(e,r)}},n.prototype.registerCorsUrl=function(r,e){void 0===e&&(e=!1);var i=this.isApi3x?this.esriConfig.defaults&&this.esriConfig.defaults.io:this.esriConfig.request;return!!i&&(this.isApiAtLeast49?this.tryAddTrustedServer(this.esriConfig.request.trustedServers,r,e):(this.configureCorsSupport(i,e),this.tryAddCorsEnabledServer(i.corsEnabledServers,r,e)))},n.prototype.configureCorsSupport=function(r,e){var i="with-credentials";(!r.useCors||e&&r.useCors!==i)&&(r.useCors=!e||i)},n.prototype.tryAddCorsEnabledServer=function(r,e,i){if(!r||!e)return!1;var i=(i=void 0===i?!1:i)?{host:e,withCredentials:i}:e,t=r.indexOf(e);if(-1===t)for(var s=0;s<r.length;s++){var o=r[s];if("object"==typeof o&&o.host===e){t=s;break}}return-1===t?r.push(i):r[t]=i,!0},n.prototype.tryAddTrustedServer=function(r,e,i){if(!e)return!1;if(i){if(!r)return!1;-1===r.indexOf(e)&&r.push(e)}return!0},n.action="gcx:wf:arcgis::RegisterCorsUrl",n.suite="gcx:wf:builtin",i=n;function n(){this.esriConfig=t.default,this.isApi3x=s.isArcGisApiVersion3x,this.isApiAtLeast49=s.isArcGisApiVersionAtLeast("4.9")}e.RegisterCorsUrl=i});