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