(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-771be51c"],{d81c8:function(e,t,r){"use strict";r.r(t),r.d(t,"default",(function(){return Re}));var s=r("f7be"),i=r("a4ee"),n=r("1325"),o=r("2eab"),a=r("ce50"),c=r("ce6d"),l=r("9d83"),h=r("7ffa"),u=r("9d1d"),d=r("f4cc"),p=r("e041"),f=r("59b2"),v=(r("cea0"),r("d386")),g=(r("b50f"),r("c120"),r("255d")),_=r("121a"),m=r("702a"),b=r("755e"),w=(r("e92d"),r("d822"));const y={base:"esri-identity-form",group:"esri-identity-form__group",label:"esri-identity-form__label",footer:"esri-identity-form__footer",esriInput:"esri-input",esriButton:"esri-button",esriButtonSecondary:"esri-button--secondary"},O="ArcGIS Online";let S=class extends _["a"]{constructor(e,t){super(e,t),this._usernameInputNode=null,this._passwordInputNode=null,this.messages=null,this.signingIn=!1,this.server=null,this.resource=null,this.error=null,this.oAuthPrompt=!1}render(){const{error:e,server:t,resource:r,signingIn:s,oAuthPrompt:i,messages:n}=this,o=Object(w["a"])("div",{class:y.group},Object(g["a"])(i?n.oAuthInfo:n.info,{server:/\.arcgis\.com/i.test(t)?O:t,resource:`(${r||n.lblItem})`})),a=i?null:Object(w["a"])("div",{class:y.group,key:"username"},Object(w["a"])("label",{class:y.label},n.lblUser,Object(w["a"])("input",{value:"",required:!0,autocomplete:"off",spellcheck:!1,type:"text",bind:this,afterCreate:m["g"],"data-node-ref":"_usernameInputNode",class:y.esriInput}))),c=i?null:Object(w["a"])("div",{class:y.group,key:"password"},Object(w["a"])("label",{class:y.label},n.lblPwd,Object(w["a"])("input",{value:"",required:!0,type:"password",bind:this,afterCreate:m["g"],"data-node-ref":"_passwordInputNode",class:y.esriInput}))),l=Object(w["a"])("div",{class:this.classes(y.group,y.footer)},Object(w["a"])("input",{type:"submit",disabled:!!s,value:s?n.lblSigning:n.lblOk,class:y.esriButton}),Object(w["a"])("input",{type:"button",value:n.lblCancel,bind:this,onclick:this._cancel,class:this.classes(y.esriButton,y.esriButtonSecondary)})),h=e?Object(w["a"])("div",null,e.details&&e.details.httpStatus?n.invalidUser:n.noAuthService):null;return Object(w["a"])("form",{class:y.base,bind:this,onsubmit:this._submit},o,h,a,c,l)}_cancel(){this._set("signingIn",!1),this._usernameInputNode&&(this._usernameInputNode.value=""),this._passwordInputNode&&(this._passwordInputNode.value=""),this.emit("cancel")}_submit(e){e.preventDefault(),this._set("signingIn",!0);const t=this.oAuthPrompt?{}:{username:this._usernameInputNode&&this._usernameInputNode.value,password:this._passwordInputNode&&this._passwordInputNode.value};this.emit("submit",t)}};Object(i["a"])([Object(f["b"])(),Object(b["a"])("esri/identity/t9n/identity")],S.prototype,"messages",void 0),Object(i["a"])([Object(f["b"])()],S.prototype,"signingIn",void 0),Object(i["a"])([Object(f["b"])()],S.prototype,"server",void 0),Object(i["a"])([Object(f["b"])()],S.prototype,"resource",void 0),Object(i["a"])([Object(f["b"])()],S.prototype,"error",void 0),Object(i["a"])([Object(f["b"])()],S.prototype,"oAuthPrompt",void 0),S=Object(i["a"])([Object(v["a"])("esri.identity.IdentityForm")],S);const I=S;var k=r("c649"),j=r("2772"),A=["input","select","textarea","a[href]","button","[tabindex]:not(slot)","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"details>summary:first-of-type","details"],T=A.join(","),U="undefined"===typeof Element,x=U?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,P=!U&&Element.prototype.getRootNode?function(e){return e.getRootNode()}:function(e){return e.ownerDocument},R=function(e,t,r){var s=Array.prototype.slice.apply(e.querySelectorAll(T));return t&&x.call(e,T)&&s.unshift(e),s=s.filter(r),s},C=function e(t,r,s){var i=[],n=Array.from(t);while(n.length){var o=n.shift();if("SLOT"===o.tagName){var a=o.assignedElements(),c=a.length?a:o.children,l=e(c,!0,s);s.flatten?i.push.apply(i,l):i.push({scope:o,candidates:l})}else{var h=x.call(o,T);h&&s.filter(o)&&(r||!t.includes(o))&&i.push(o);var u=o.shadowRoot||"function"===typeof s.getShadowRoot&&s.getShadowRoot(o),d=!s.shadowRootFilter||s.shadowRootFilter(o);if(u&&d){var p=e(!0===u?o.children:u.children,!0,s);s.flatten?i.push.apply(i,p):i.push({scope:o,candidates:p})}else n.unshift.apply(n,o.children)}}return i},D=function(e,t){return e.tabIndex<0&&(t||/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||e.isContentEditable)&&isNaN(parseInt(e.getAttribute("tabindex"),10))?0:e.tabIndex},E=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},N=function(e){return"INPUT"===e.tagName},q=function(e){return N(e)&&"hidden"===e.type},F=function(e){var t="DETAILS"===e.tagName&&Array.prototype.slice.apply(e.children).some((function(e){return"SUMMARY"===e.tagName}));return t},L=function(e,t){for(var r=0;rsummary:first-of-type"),n=i?e.parentElement:e;if(x.call(n,"details:not([open]) *"))return!0;var o=P(e).host,a=(null===o||void 0===o?void 0:o.ownerDocument.contains(o))||e.ownerDocument.contains(e);if(r&&"full"!==r){if("non-zero-area"===r)return G(e)}else{if("function"===typeof s){var c=e;while(e){var l=e.parentElement,h=P(e);if(l&&!l.shadowRoot&&!0===s(l))return G(e);e=e.assignedSlot?e.assignedSlot:l||h===e.ownerDocument?l:h.host}e=c}if(a)return!e.getClientRects().length}return!1},H=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName)){var t=e.parentElement;while(t){if("FIELDSET"===t.tagName&&t.disabled){for(var r=0;r=0)},Y=function e(t){var r=[],s=[];return t.forEach((function(t,i){var n=!!t.scope,o=n?t.scope:t,a=D(o,n),c=n?e(t.candidates):o;0===a?n?r.push.apply(r,c):r.push(o):s.push({documentOrder:i,tabIndex:a,item:t,isScope:n,content:c})})),s.sort(E).reduce((function(e,t){return t.isScope?e.push.apply(e,t.content):e.push(t.content),e}),[]).concat(r)},K=function(e,t){var r;return t=t||{},r=t.getShadowRoot?C([e],t.includeContainer,{filter:$.bind(null,t),flatten:!1,getShadowRoot:t.getShadowRoot,shadowRootFilter:W}):R(e,t.includeContainer,$.bind(null,t)),Y(r)},X=function(e,t){var r;return t=t||{},r=t.getShadowRoot?C([e],t.includeContainer,{filter:J.bind(null,t),flatten:!0,getShadowRoot:t.getShadowRoot}):R(e,t.includeContainer,J.bind(null,t)),r},Q=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return!1!==x.call(e,T)&&$(t,e)},Z=A.concat("iframe").join(","),ee=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return!1!==x.call(e,Z)&&J(t,e)}; /*! * focus-trap 6.7.3 * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE */ function te(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,s)}return r}function re(e){for(var t=1;t0){var r=e[e.length-1];r!==t&&r.pause()}var s=e.indexOf(t);-1===s||e.splice(s,1),e.push(t)},deactivateTrap:function(t){var r=e.indexOf(t);-1!==r&&e.splice(r,1),e.length>0&&e[e.length-1].unpause()}}}(),ne=function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"===typeof e.select},oe=function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode},ae=function(e){return"Tab"===e.key||9===e.keyCode},ce=function(e){return setTimeout(e,0)},le=function(e,t){var r=-1;return e.every((function(e,s){return!t(e)||(r=s,!1)})),r},he=function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),s=1;s1?r-1:0),o=1;o0)return{container:e,firstTabbableNode:t[0],lastTabbableNode:t[t.length-1],nextTabbableNode:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],s=r.findIndex((function(t){return t===e}));return t?r.slice(s+1).find((function(e){return Q(e)})):r.slice(0,s).reverse().find((function(e){return Q(e)}))}}})).filter((function(e){return!!e})),n.tabbableGroups.length<=0&&!c("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},u=function e(t){!1!==t&&t!==s.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!i.preventScroll}),n.mostRecentlyFocusedNode=t,ne(t)&&t.select()):e(l()))},d=function(e){var t=c("setReturnFocus",e);return t||!1!==t&&e},p=function(e){var t=ue(e);a(t)||(he(i.clickOutsideDeactivates,e)?r.deactivate({returnFocus:i.returnFocusOnDeactivate&&!ee(t)}):he(i.allowOutsideClick,e)||e.preventDefault())},f=function(e){var t=ue(e),r=a(t);r||t instanceof Document?r&&(n.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),u(n.mostRecentlyFocusedNode||l()))},v=function(e){var t=ue(e);h();var r=null;if(n.tabbableGroups.length>0){var s=le(n.tabbableGroups,(function(e){var r=e.container;return r.contains(t)})),i=s>=0?n.tabbableGroups[s]:void 0;if(s<0)r=e.shiftKey?n.tabbableGroups[n.tabbableGroups.length-1].lastTabbableNode:n.tabbableGroups[0].firstTabbableNode;else if(e.shiftKey){var o=le(n.tabbableGroups,(function(e){var r=e.firstTabbableNode;return t===r}));if(o<0&&(i.container===t||ee(t)&&!Q(t)&&!i.nextTabbableNode(t,!1))&&(o=s),o>=0){var a=0===o?n.tabbableGroups.length-1:o-1,l=n.tabbableGroups[a];r=l.lastTabbableNode}}else{var d=le(n.tabbableGroups,(function(e){var r=e.lastTabbableNode;return t===r}));if(d<0&&(i.container===t||ee(t)&&!Q(t)&&!i.nextTabbableNode(t))&&(d=s),d>=0){var p=d===n.tabbableGroups.length-1?0:d+1,f=n.tabbableGroups[p];r=f.firstTabbableNode}}}else r=c("fallbackFocus");r&&(e.preventDefault(),u(r))},g=function(e){if(oe(e)&&!1!==he(i.escapeDeactivates,e))return e.preventDefault(),void r.deactivate();ae(e)&&v(e)},_=function(e){if(!he(i.clickOutsideDeactivates,e)){var t=ue(e);a(t)||he(i.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())}},m=function(){if(n.active)return ie.activateTrap(r),n.delayInitialFocusTimer=i.delayInitialFocus?ce((function(){u(l())})):u(l()),s.addEventListener("focusin",f,!0),s.addEventListener("mousedown",p,{capture:!0,passive:!1}),s.addEventListener("touchstart",p,{capture:!0,passive:!1}),s.addEventListener("click",_,{capture:!0,passive:!1}),s.addEventListener("keydown",g,{capture:!0,passive:!1}),r},b=function(){if(n.active)return s.removeEventListener("focusin",f,!0),s.removeEventListener("mousedown",p,!0),s.removeEventListener("touchstart",p,!0),s.removeEventListener("click",_,!0),s.removeEventListener("keydown",g,!0),r};return r={activate:function(e){if(n.active)return this;var t=o(e,"onActivate"),r=o(e,"onPostActivate"),i=o(e,"checkCanFocusTrap");i||h(),n.active=!0,n.paused=!1,n.nodeFocusedBeforeActivation=s.activeElement,t&&t();var a=function(){i&&h(),m(),r&&r()};return i?(i(n.containers.concat()).then(a,a),this):(a(),this)},deactivate:function(e){if(!n.active)return this;clearTimeout(n.delayInitialFocusTimer),n.delayInitialFocusTimer=void 0,b(),n.active=!1,n.paused=!1,ie.deactivateTrap(r);var t=o(e,"onDeactivate"),s=o(e,"onPostDeactivate"),i=o(e,"checkCanReturnFocus");t&&t();var a=o(e,"returnFocus","returnFocusOnDeactivate"),c=function(){ce((function(){a&&u(d(n.nodeFocusedBeforeActivation)),s&&s()}))};return a&&i?(i(d(n.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(){return n.paused||!n.active||(n.paused=!0,b()),this},unpause:function(){return n.paused&&n.active?(n.paused=!1,h(),m(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return n.containers=t.map((function(e){return"string"===typeof e?s.querySelector(e):e})),n.active&&h(),this}},r.updateContainerElements(e),r};const pe={base:"esri-identity-modal",open:"esri-identity-modal--open",closed:"esri-identity-modal--closed",title:"esri-identity-modal__title",dialog:"esri-identity-modal__dialog",content:"esri-identity-modal__content",closeButton:"esri-identity-modal__close-button",iconClose:"esri-icon-close"};let fe=class extends _["a"]{constructor(e,t){super(e,t),this.container=document.createElement("div"),this.content=null,this.open=!1,this._close=()=>{this.open=!1},document.body.appendChild(this.container),this.own(this.watch("open",()=>this._toggleFocusTrap()))}destroy(){this._destroyFocusTrap()}render(){const e=this.id,{open:t,content:r,title:s,messages:i}=this,n=t&&!!r,o={[pe.open]:n,[pe.closed]:!n},a=Object(w["a"])("button",{class:pe.closeButton,"aria-label":i.close,title:i.close,bind:this,onclick:this._close},Object(w["a"])("span",{"aria-hidden":"true",class:pe.iconClose})),c=e+"_title",l=e+"_content",h=s?Object(w["a"])("h1",{id:c,class:pe.title},s):null,u=n?Object(w["a"])("div",{bind:this,class:pe.dialog,role:"dialog","aria-labelledby":c,"aria-describedby":l,afterCreate:this._createFocusTrap},a,h,this._renderContent(l)):null;return Object(w["a"])("div",{tabIndex:-1,class:this.classes(pe.base,o)},u)}_destroyFocusTrap(){var e;null==(e=this._focusTrap)||e.deactivate({onDeactivate:null}),this._focusTrap=null}_toggleFocusTrap(){const{_focusTrap:e,open:t}=this;e&&(t?e.activate():e.deactivate())}_createFocusTrap(e){this._destroyFocusTrap();const t=requestAnimationFrame(()=>{this._focusTrap=de(e,{initialFocus:"input",onDeactivate:this._close}),this._toggleFocusTrap()});this.own(Object(k["b"])(()=>cancelAnimationFrame(t)))}_renderContent(e){const t=this.content;return"string"==typeof t?Object(w["a"])("div",{class:pe.content,id:e,innerHTML:t}):Object(j["b"])(t)?Object(w["a"])("div",{class:pe.content,id:e},t.render()):t instanceof HTMLElement?Object(w["a"])("div",{class:pe.content,id:e,bind:t,afterCreate:this._attachToNode}):null}_attachToNode(e){const t=this;e.appendChild(t)}};Object(i["a"])([Object(f["b"])({readOnly:!0})],fe.prototype,"container",void 0),Object(i["a"])([Object(f["b"])()],fe.prototype,"content",void 0),Object(i["a"])([Object(f["b"])()],fe.prototype,"open",void 0),Object(i["a"])([Object(f["b"])(),Object(b["a"])("esri/t9n/common")],fe.prototype,"messages",void 0),Object(i["a"])([Object(f["b"])({aliasOf:"messages.auth.signIn"})],fe.prototype,"title",void 0),fe=Object(i["a"])([Object(v["a"])("esri.identity.IdentityModal")],fe);const ve=fe,ge="esriJSAPIOAuth";class _e{constructor(e,t){this.oAuthInfo=null,this.storage=null,this.appId=null,this.codeVerifier=null,this.expires=null,this.refreshToken=null,this.ssl=null,this.stateUID=null,this.token=null,this.userId=null,this.oAuthInfo=e,this.storage=t,this._init()}isValid(){let e=!1;if(this.oAuthInfo&&this.userId&&(this.refreshToken||this.token))if(null==this.expires&&this.refreshToken)e=!0;else{const t=Date.now();this.expires>t&&(this.expires-t)/1e3>60*this.oAuthInfo.minTimeUntilExpiration&&(e=!0)}return e}save(){if(!this.storage)return!1;const e=this._load(),t=this.oAuthInfo;if(t&&t.authNamespace&&t.portalUrl){let s=e[t.authNamespace];s||(s=e[t.authNamespace]={}),this.appId||(this.appId=t.appId),s[t.portalUrl]={appId:this.appId,codeVerifier:this.codeVerifier,expires:this.expires,refreshToken:this.refreshToken,ssl:this.ssl,stateUID:this.stateUID,token:this.token,userId:this.userId};try{this.storage.setItem(ge,JSON.stringify(e))}catch(r){return console.warn(r),!1}return!0}return!1}destroy(){const e=this._load(),t=this.oAuthInfo;if(t&&t.appId&&t.portalUrl&&(null==this.expires||this.expires>Date.now())&&(this.refreshToken||this.token)){const e=t.portalUrl.replace(/^http:/i,"https:")+"/sharing/rest/oauth2/revokeToken",r=new FormData;if(r.append("f","json"),r.append("auth_token",this.refreshToken||this.token),r.append("client_id",t.appId),r.append("token_type_hint",this.refreshToken?"refresh_token":"access_token"),"function"==typeof navigator.sendBeacon)navigator.sendBeacon(e,r);else{const t=new XMLHttpRequest;t.open("POST",e),t.send(r)}}if(t&&t.authNamespace&&t.portalUrl&&this.storage){const s=e[t.authNamespace];if(s){delete s[t.portalUrl];try{this.storage.setItem(ge,JSON.stringify(e))}catch(r){console.log(r)}}}t&&(t._oAuthCred=null,this.oAuthInfo=null)}_init(){const e=this._load(),t=this.oAuthInfo;if(t&&t.authNamespace&&t.portalUrl){let r=e[t.authNamespace];r&&(r=r[t.portalUrl],r&&(this.appId=r.appId,this.codeVerifier=r.codeVerifier,this.expires=r.expires,this.refreshToken=r.refreshToken,this.ssl=r.ssl,this.stateUID=r.stateUID,this.token=r.token,this.userId=r.userId))}}_load(){let e={};if(this.storage){const r=this.storage.getItem(ge);if(r)try{e=JSON.parse(r)}catch(t){console.warn(t)}}return e}}_e.prototype.declaredClass="esri.identity.OAuthCredential";var me,be=r("6a0ed");let we=me=class extends be["a"]{constructor(e){super(e),this._oAuthCred=null,this.appId=null,this.authNamespace="/",this.expiration=20160,this.flowType="auto",this.forceLogin=!1,this.forceUserId=!1,this.locale=null,this.minTimeUntilExpiration=30,this.popup=!1,this.popupCallbackUrl="oauth-callback.html",this.popupWindowFeatures="height=490,width=800,resizable,scrollbars,status",this.portalUrl="https://www.arcgis.com",this.preserveUrlHash=!1,this.userId=null}clone(){return me.fromJSON(this.toJSON())}};Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"appId",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"authNamespace",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"expiration",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"flowType",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"forceLogin",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"forceUserId",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"locale",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"minTimeUntilExpiration",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"popup",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"popupCallbackUrl",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"popupWindowFeatures",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"portalUrl",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"preserveUrlHash",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],we.prototype,"userId",void 0),we=me=Object(i["a"])([Object(v["a"])("esri.identity.OAuthInfo")],we);const ye=we;let Oe=class extends be["a"]{constructor(e){super(e),this.adminTokenServiceUrl=null,this.currentVersion=null,this.hasPortal=null,this.hasServer=null,this.owningSystemUrl=null,this.owningTenant=null,this.server=null,this.shortLivedTokenValidity=null,this.tokenServiceUrl=null,this.webTierAuth=null}};Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"adminTokenServiceUrl",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"currentVersion",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"hasPortal",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"hasServer",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"owningSystemUrl",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"owningTenant",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"server",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"shortLivedTokenValidity",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"tokenServiceUrl",void 0),Object(i["a"])([Object(f["b"])({json:{write:!0}})],Oe.prototype,"webTierAuth",void 0),Oe=Object(i["a"])([Object(v["a"])("esri.identity.ServerInfo")],Oe);const Se=Oe,Ie={},ke=e=>{const t=new p["a"](e.owningSystemUrl).host,r=new p["a"](e.server).host,s=/.+\.arcgis\.com$/i;return s.test(t)&&s.test(r)},je=(e,t)=>!!(ke(e)&&t&&t.some(t=>t.test(e.server)));let Ae=null,Te=null;try{Ae=window.localStorage,Te=window.sessionStorage}catch{}class Ue extends c["a"]{constructor(){super(),this._portalConfig=globalThis.esriGeowConfig,this.serverInfos=[],this.oAuthInfos=[],this.credentials=[],this._soReqs=[],this._xoReqs=[],this._portals=[],this.defaultOAuthInfo=null,this.defaultTokenValidity=60,this.dialog=null,this.formConstructor=I,this.tokenValidity=null,this.normalizeWebTierAuth=!1,this._appOrigin="null"!==window.origin?window.origin:window.location.origin,this._appUrlObj=Object(p["M"])(window.location.href),this._busy=null,this._rejectOnPersistedPageShow=!1,this._oAuthLocationParams=null,this._gwTokenUrl="/sharing/rest/generateToken",this._agsRest="/rest/services",this._agsPortal=/\/sharing(\/|$)/i,this._agsAdmin=/(https?:\/\/[^\/]+\/[^\/]+)\/admin\/?(\/.*)?$/i,this._adminSvcs=/\/rest\/admin\/services(\/|$)/i,this._gwDomains=[{regex:/^https?:\/\/www\.arcgis\.com/i,customBaseUrl:"maps.arcgis.com",tokenServiceUrl:"https://www.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:dev|[a-z\d-]+\.mapsdev)\.arcgis\.com/i,customBaseUrl:"mapsdev.arcgis.com",tokenServiceUrl:"https://dev.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:devext|[a-z\d-]+\.mapsdevext)\.arcgis\.com/i,customBaseUrl:"mapsdevext.arcgis.com",tokenServiceUrl:"https://devext.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:qaext|[a-z\d-]+\.mapsqa)\.arcgis\.com/i,customBaseUrl:"mapsqa.arcgis.com",tokenServiceUrl:"https://qaext.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/[a-z\d-]+\.maps\.arcgis\.com/i,customBaseUrl:"maps.arcgis.com",tokenServiceUrl:"https://www.arcgis.com/sharing/rest/generateToken"}],this._legacyFed=[],this._regexSDirUrl=/http.+\/rest\/services\/?/gi,this._regexServerType=/(\/(FeatureServer|GPServer|GeoDataServer|GeocodeServer|GeoenrichmentServer|GeometryServer|GlobeServer|ImageServer|MapServer|MobileServer|NAServer|NetworkDiagramServer|OGCFeatureServer|ParcelFabricServer|RelationalCatalogServer|SceneServer|StreamServer|UtilityNetworkServer|ValidationServer|VectorTileServer|VersionManagementServer)).*/gi,this._gwUser=/http.+\/users\/([^\/]+)\/?.*/i,this._gwItem=/http.+\/items\/([^\/]+)\/?.*/i,this._gwGroup=/http.+\/groups\/([^\/]+)\/?.*/i,this._rePortalTokenSvc=/\/sharing(\/rest)?\/generatetoken/i,this._createDefaultOAuthInfo=!0,this._hasTestedIfAppIsOnPortal=!1,this._getOAuthLocationParams(),window.addEventListener("pageshow",e=>{this._pageShowHandler(e)})}registerServers(e){const t=this.serverInfos;t?(e=e.filter(e=>!this.findServerInfo(e.server)),this.serverInfos=t.concat(e)):this.serverInfos=e,e.forEach(e=>{e.owningSystemUrl&&this._portals.push(e.owningSystemUrl),e.hasPortal&&this._portals.push(e.server)})}registerOAuthInfos(e){const t=this.oAuthInfos;if(t){for(const r of e){const e=this.findOAuthInfo(r.portalUrl);e&&t.splice(t.indexOf(e),1)}this.oAuthInfos=t.concat(e)}else this.oAuthInfos=e}registerToken(e){e={...e};const t=this._sanitizeUrl(e.server),r=this._isServerRsrc(t);let s,i=this.findServerInfo(t),n=!0;i||(i=new Se,i.server=this._getServerInstanceRoot(t),r?i.hasServer=!0:(i.tokenServiceUrl=this._getTokenSvcUrl(t),i.hasPortal=!0),this.registerServers([i])),s=this._findCredential(t),s?(delete e.server,Object.assign(s,e),n=!1):(s=new xe({userId:e.userId,server:i.server,token:e.token,expires:e.expires,ssl:e.ssl,scope:r?"server":"portal"}),s.resources=[t],this.credentials.push(s)),s.emitTokenChange(!1),n||s.refreshServerTokens()}toJSON(){return Object(h["c"])({serverInfos:this.serverInfos.map(e=>e.toJSON()),oAuthInfos:this.oAuthInfos.map(e=>e.toJSON()),credentials:this.credentials.map(e=>e.toJSON())})}initialize(e){if(!e)return;"string"==typeof e&&(e=JSON.parse(e));const t=e.serverInfos,r=e.oAuthInfos,s=e.credentials;if(t){const e=[];t.forEach(t=>{t.server&&t.tokenServiceUrl&&e.push(t.declaredClass?t:new Se(t))}),e.length&&this.registerServers(e)}if(r){const e=[];r.forEach(t=>{t.appId&&e.push(t.declaredClass?t:new ye(t))}),e.length&&this.registerOAuthInfos(e)}s&&s.forEach(e=>{e.server&&e.token&&e.expires&&e.expires>Date.now()&&((e=e.declaredClass?e:new xe(e)).emitTokenChange(),this.credentials.push(e))})}findServerInfo(e){let t;e=this._sanitizeUrl(e);for(const r of this.serverInfos)if(this._hasSameServerInstance(r.server,e)){t=r;break}return t}findOAuthInfo(e){let t;e=this._sanitizeUrl(e);for(const r of this.oAuthInfos)if(this._hasSameServerInstance(r.portalUrl,e)){t=r;break}return t}findCredential(e,t){let r;e=this._sanitizeUrl(e);const s=this._isServerRsrc(e)?"server":"portal";if(t){for(const i of this.credentials)if(this._hasSameServerInstance(i.server,e)&&t===i.userId&&i.scope===s){r=i;break}}else for(const i of this.credentials)if(this._hasSameServerInstance(i.server,e)&&-1!==this._getIdenticalSvcIdx(e,i)&&i.scope===s){r=i;break}return r}getCredential(e,t){let r,s,i=!0;t&&(r=!!t.token,s=t.error,i=!1!==t.prompt),t={...t},e=this._sanitizeUrl(e);const n=new AbortController,o=Object(d["g"])();if(t.signal&&Object(d["q"])(t.signal,()=>{n.abort()}),Object(d["q"])(n,()=>{o.reject(new a["a"]("identity-manager:user-aborted","ABORTED"))}),Object(d["n"])(n))return o.promise;t.signal=n.signal;const c=this._isAdminResource(e),l=r?this.findCredential(e):null;let h;if(l&&s&&s.details&&498===s.details.httpStatus)l.destroy();else if(l)return h=new a["a"]("identity-manager:not-authorized","You are currently signed in as: '"+l.userId+"'. You do not have access to this resource: "+e,{error:s}),o.reject(h),o.promise;const u=this._findCredential(e,t);if(u)return o.resolve(u),o.promise;let f=this.findServerInfo(e);if(f)!f.hasServer&&this._isServerRsrc(e)&&(f._restInfoPms=this._getTokenSvcUrl(e),f.hasServer=!0);else{const t=this._getTokenSvcUrl(e);if(!t)return h=new a["a"]("identity-manager:unknown-resource","Unknown resource - could not find token service endpoint."),o.reject(h),o.promise;f=new Se,f.server=this._getServerInstanceRoot(e),"string"==typeof t?(f.tokenServiceUrl=t,f.hasPortal=!0):(f._restInfoPms=t,f.hasServer=!0),this.registerServers([f])}return f.hasPortal&&void 0===f._selfReq&&(i||Object(p["s"])(f.tokenServiceUrl,this._appOrigin)||this._gwDomains.some(e=>e.tokenServiceUrl===f.tokenServiceUrl))&&(f._selfReq={owningTenant:t&&t.owningTenant,selfDfd:this._getPortalSelf(f.tokenServiceUrl.replace(this._rePortalTokenSvc,"/sharing/rest/portals/self"),e)}),this._enqueue(e,f,t,o,c)}getResourceName(e){return this._isRESTService(e)?e.replace(this._regexSDirUrl,"").replace(this._regexServerType,"")||"":this._gwUser.test(e)&&e.replace(this._gwUser,"$1")||this._gwItem.test(e)&&e.replace(this._gwItem,"$1")||this._gwGroup.test(e)&&e.replace(this._gwGroup,"$1")||""}generateToken(e,t,r){const s=this._rePortalTokenSvc.test(e.tokenServiceUrl),i=new p["a"](this._appOrigin),n=e.shortLivedTokenValidity;let c,l,h,u,d,f,v,g;t&&(g=this.tokenValidity||n||this.defaultTokenValidity,g>n&&n>0&&(g=n)),r&&(c=r.isAdmin,l=r.serverUrl,h=r.token,f=r.signal,v=r.ssl,e.customParameters=r.customParameters),c?u=e.adminTokenServiceUrl:(u=e.tokenServiceUrl,d=new p["a"](u.toLowerCase()),e.webTierAuth&&null!=r&&r.serverUrl&&!v&&"http"===i.scheme&&(Object(p["s"])(i.uri,u,!0)||"https"===d.scheme&&i.host===d.host&&"7080"===i.port&&"7443"===d.port)&&(u=u.replace(/^https:/i,"http:").replace(/:7443/i,":7080")));const _={query:{request:"getToken",username:null==t?void 0:t.username,password:null==t?void 0:t.password,serverUrl:l,token:h,expiration:g,referer:c||s?this._appOrigin:null,client:c?"referer":null,f:"json",...e.customParameters},method:"post",authMode:"anonymous",useProxy:this._useProxy(e,r),signal:f,...null==r?void 0:r.ioArgs};return s||(_.withCredentials=!1),Object(o["default"])(u,_).then(r=>{const s=r.data;if(!s||!s.token)return new a["a"]("identity-manager:authentication-failed","Unable to generate token");const i=e.server;return Ie[i]||(Ie[i]={}),t&&(Ie[i][t.username]=t.password),s.validity=g,s})}isBusy(){return!!this._busy}checkSignInStatus(e){return this.checkAppAccess(e,"").then(e=>e.credential)}checkAppAccess(e,t,r){let s=!1;return this.getCredential(e,{prompt:!1}).then(i=>{let n;const c={f:"json"};if("portal"===i.scope)if(t&&(this._doPortalSignIn(e)||r&&r.force))n=i.server+"/sharing/rest/oauth2/validateAppAccess",c.client_id=t;else{if(!i.token)return{credential:i};n=i.server+"/sharing/rest"}else{if(!i.token)return{credential:i};n=i.server+"/rest/services"}return i.token&&(c.token=i.token),Object(o["default"])(n,{query:c,authMode:"anonymous"}).then(e=>{if(!1===e.data.valid)throw new a["a"]("identity-manager:not-authorized",`You are currently signed in as: '${i.userId}'.`,e.data);return s=!!e.data.viewOnlyUserTypeApp,{credential:i}}).catch(e=>{if("identity-manager:not-authorized"===e.name)throw e;const t=e.details&&e.details.httpStatus;if(498===t)throw i.destroy(),new a["a"]("identity-manager:not-authenticated","User is not signed in.");if(400===t)throw new a["a"]("identity-manager:invalid-request");return{credential:i}})}).then(e=>({credential:e.credential,viewOnly:s}))}setOAuthResponseHash(e){e&&("#"===e.charAt(0)&&(e=e.substring(1)),this._processOAuthPopupParams(Object(p["H"])(e)))}setOAuthRedirectionHandler(e){this._oAuthRedirectFunc=e}setProtocolErrorHandler(e){this._protocolFunc=e}signIn(e,t,r={}){const s=Object(d["g"])(),i=()=>{var e,t,r,s,i;null==(e=c)||e.remove(),null==(t=l)||t.remove(),null==(r=h)||r.remove(),null==(s=o)||s.destroy(),null==(i=this.dialog)||i.destroy(),this.dialog=o=c=l=h=null},n=()=>{i(),this._oAuthDfd=null,s.reject(new a["a"]("identity-manager:user-aborted","ABORTED"))};r.signal&&Object(d["q"])(r.signal,()=>{n()});let o=new this.formConstructor;o.resource=this.getResourceName(e),o.server=t.server,this.dialog=new ve,this.dialog.content=o,this.dialog.open=!0,this.emit("dialog-create");let c=o.on("cancel",n),l=this.dialog.watch("open",n),h=o.on("submit",e=>{this.generateToken(t,e,{isAdmin:r.isAdmin,signal:r.signal}).then(n=>{i();const o=new xe({userId:e.username,server:t.server,token:n.token,expires:null!=n.expires?Number(n.expires):null,ssl:!!n.ssl,isAdmin:r.isAdmin,validity:n.validity});s.resolve(o)}).catch(e=>{o.error=e,o.signingIn=!1})});return s.promise}oAuthSignIn(e,t,r,s){this._oAuthDfd=Object(d["g"])();const i=this._oAuthDfd;let n;null!=s&&s.signal&&Object(d["q"])(s.signal,()=>{const e=this._oAuthDfd&&this._oAuthDfd.oAuthWin_;e&&!e.closed?e.close():this.dialog&&f()}),i.resUrl_=e,i.sinfo_=t,i.oinfo_=r;const o=r._oAuthCred;if(o.storage&&("authorization-code"===r.flowType||"auto"===r.flowType&&!r.popup&&t.currentVersion>=8.4)){let e=crypto.getRandomValues(new Uint8Array(32));n=Object(p["f"])(e),o.codeVerifier=n,e=crypto.getRandomValues(new Uint8Array(32)),o.stateUID=Object(p["f"])(e),o.save()||(o.codeVerifier=n=null)}else o.codeVerifier=null;let c,l,h,u;this._getCodeChallenge(n).then(i=>{const n=!s||!1!==s.oAuthPopupConfirmation;r.popup&&n?(c=new this.formConstructor,c.oAuthPrompt=!0,c.server=t.server,this.dialog=new ve,this.dialog.content=c,this.dialog.open=!0,this.emit("dialog-create"),l=c.on("cancel",f),h=this.dialog.watch("open",f),u=c.on("submit",()=>{v(),this._doOAuthSignIn(e,t,r,i)})):this._doOAuthSignIn(e,t,r,i)});const f=()=>{v(),this._oAuthDfd=null,i.reject(new a["a"]("identity-manager:user-aborted","ABORTED"))},v=()=>{var e,t,r,s,i;null==(e=l)||e.remove(),null==(t=h)||t.remove(),null==(r=u)||r.remove(),null==(s=c)||s.destroy(),null==(i=this.dialog)||i.destroy(),this.dialog=null};return i.promise}destroyCredentials(){this.credentials&&this.credentials.slice().forEach(e=>{e.destroy()}),this.emit("credentials-destroy")}enablePostMessageAuth(e="https://www.arcgis.com/sharing/rest"){this._postMessageAuthHandle&&this._postMessageAuthHandle.remove(),this._postMessageAuthHandle=Object(l["c"])(window,"message",t=>{var r;if((t.origin===this._appOrigin||t.origin.endsWith(".arcgis.com"))&&"arcgis:auth:requestCredential"===(null==(r=t.data)?void 0:r.type)){const r=t.source;this.getCredential(e).then(e=>{r.postMessage({type:"arcgis:auth:credential",credential:{expires:e.expires,server:e.server,ssl:e.ssl,token:e.token,userId:e.userId}},t.origin)}).catch(e=>{r.postMessage({type:"arcgis:auth:error",error:{name:e.name,message:e.message}},t.origin)})}})}disablePostMessageAuth(){this._postMessageAuthHandle&&(this._postMessageAuthHandle.remove(),this._postMessageAuthHandle=null)}_getOAuthLocationParams(){let e=window.location.hash;if(e){"#"===e.charAt(0)&&(e=e.substring(1));const r=Object(p["H"])(e);let s=!1;if(r.access_token&&r.expires_in&&r.state&&r.hasOwnProperty("username"))try{r.state=JSON.parse(r.state),r.state.portalUrl&&(this._oAuthLocationParams=r,s=!0)}catch{}else if(r.error&&r.error_description&&(console.log("IdentityManager OAuth Error: ",r.error," - ",r.error_description),"access_denied"===r.error&&(s=!0,r.state)))try{r.state=JSON.parse(r.state)}catch{}var t;s&&(window.location.hash=(null==(t=r.state)?void 0:t.hash)||"")}let r=window.location.search;if(r){"?"===r.charAt(0)&&(r=r.substring(1));const e=Object(p["H"])(r);let t=!1;if(e.code&&e.state)try{e.state=JSON.parse(e.state),e.state.portalUrl&&e.state.uid&&(this._oAuthLocationParams=e,t=!0)}catch{}else if(e.error&&e.error_description&&(console.log("IdentityManager OAuth Error: ",e.error," - ",e.error_description),"access_denied"===e.error&&(t=!0,e.state)))try{e.state=JSON.parse(e.state)}catch{}if(t){var s;const t={...e};["code","error","error_description","message_code","persist","state"].forEach(e=>{delete t[e]});const r=Object(p["G"])(t),i=window.location.pathname+(r?"?"+r:"")+((null==(s=e.state)?void 0:s.hash)||"");window.history.replaceState(window.history.state,"",i)}}}_getOAuthToken(e,t,r,s,i){return e=e.replace(/^http:/i,"https:"),Object(o["default"])(e+"/sharing/rest/oauth2/token",{authMode:"anonymous",method:"post",query:s&&i?{grant_type:"authorization_code",code:t,redirect_uri:s,client_id:r,code_verifier:i}:{grant_type:"refresh_token",refresh_token:t,client_id:r}}).then(e=>e.data)}_getCodeChallenge(e){if(e&&globalThis.isSecureContext){const t=(new TextEncoder).encode(e);return crypto.subtle.digest("SHA-256",t).then(e=>Object(p["f"])(new Uint8Array(e)))}return Promise.resolve(null)}_pageShowHandler(e){if(e.persisted&&this.isBusy()&&this._rejectOnPersistedPageShow){const e=new a["a"]("identity-manager:user-aborted","ABORTED");this._errbackFunc(e)}}_findCredential(e,t){let r,s,i,n,o=-1;const a=t&&t.token,c=t&&t.resource,l=this._isServerRsrc(e)?"server":"portal",h=this.credentials.filter(t=>this._hasSameServerInstance(t.server,e)&&t.scope===l);if(e=c||e,h.length)if(1===h.length){if(r=h[0],n=this.findServerInfo(r.server),s=n&&n.owningSystemUrl,i=s&&this.findCredential(s,r.userId),o=this._getIdenticalSvcIdx(e,r),!a)return-1===o&&r.resources.push(e),this._addResource(e,i),r;-1!==o&&(r.resources.splice(o,1),this._removeResource(e,i))}else{let t,r;if(h.some(a=>(r=this._getIdenticalSvcIdx(e,a),-1!==r&&(t=a,n=this.findServerInfo(t.server),s=n&&n.owningSystemUrl,i=s&&this.findCredential(s,t.userId),o=r,!0))),a)t&&(t.resources.splice(o,1),this._removeResource(e,i));else if(t)return this._addResource(e,i),t}}_findOAuthInfo(e){let t=this.findOAuthInfo(e);if(!t)for(const r of this.oAuthInfos)if(this._isIdProvider(r.portalUrl,e)){t=r;break}return t}_addResource(e,t){t&&-1===this._getIdenticalSvcIdx(e,t)&&t.resources.push(e)}_removeResource(e,t){let r=-1;t&&(r=this._getIdenticalSvcIdx(e,t),r>-1&&t.resources.splice(r,1))}_useProxy(e,t){return t&&t.isAdmin&&!Object(p["s"])(e.adminTokenServiceUrl,this._appOrigin)||!this._isPortalDomain(e.tokenServiceUrl)&&"10.1"===String(e.currentVersion)&&!Object(p["s"])(e.tokenServiceUrl,this._appOrigin)}_getOrigin(e){const t=new p["a"](e);return t.scheme+"://"+t.host+(null!=t.port?":"+t.port:"")}_getServerInstanceRoot(e){const t=e.toLowerCase();let r=t.indexOf(this._agsRest);return-1===r&&this._isAdminResource(e)&&(r=this._agsAdmin.test(e)?e.replace(this._agsAdmin,"$1").length:e.search(this._adminSvcs)),-1===r&&(r=t.indexOf("/sharing")),-1===r&&"/"===t.substr(-1)&&(r=t.length-1),r>-1?e.substring(0,r):e}_hasSameServerInstance(e,t){return"/"===e.substr(-1)&&(e=e.slice(0,-1)),e=e.toLowerCase(),t=this._getServerInstanceRoot(t).toLowerCase(),e=this._normalizeAGOLorgDomain(e),t=this._normalizeAGOLorgDomain(t),(e=e.substr(e.indexOf(":")))===t.substr(t.indexOf(":"))}_normalizeAGOLorgDomain(e){const t=/^https?:\/\/(?:cdn|[a-z\d-]+\.maps)\.arcgis\.com/i,r=/^https?:\/\/(?:cdndev|[a-z\d-]+\.mapsdevext)\.arcgis\.com/i,s=/^https?:\/\/(?:cdnqa|[a-z\d-]+\.mapsqa)\.arcgis\.com/i;return t.test(e)?e=e.replace(t,"https://www.arcgis.com"):r.test(e)?e=e.replace(r,"https://devext.arcgis.com"):s.test(e)&&(e=e.replace(s,"https://qaext.arcgis.com")),e}_sanitizeUrl(e){const t=(n["a"].request.proxyUrl||"").toLowerCase(),r=t?e.toLowerCase().indexOf(t+"?"):-1;return-1!==r&&(e=e.substring(r+t.length+1)),e=Object(p["F"])(e),Object(p["M"])(e).path}_isRESTService(e){return e.indexOf(this._agsRest)>-1}_isAdminResource(e){return this._agsAdmin.test(e)||this._adminSvcs.test(e)}_isServerRsrc(e){return this._isRESTService(e)||this._isAdminResource(e)}_isIdenticalService(e,t){let r;if(this._isRESTService(e)&&this._isRESTService(t)){const s=this._getSuffix(e).toLowerCase(),i=this._getSuffix(t).toLowerCase();if(r=s===i,!r){const e=/(.*)\/(MapServer|FeatureServer|UtilityNetworkServer).*/gi;r=s.replace(e,"$1")===i.replace(e,"$1")}}else this._isAdminResource(e)&&this._isAdminResource(t)?r=!0:this._isServerRsrc(e)||this._isServerRsrc(t)||!this._isPortalDomain(e)||(r=!0);return r}_isPortalDomain(e){const t=new p["a"](e.toLowerCase()),r=this._portalConfig;let s=this._gwDomains.some(e=>e.regex.test(t.uri));return!s&&r&&(s=this._hasSameServerInstance(this._getServerInstanceRoot(r.restBaseUrl),t.uri)),s||n["a"].portalUrl&&(s=Object(p["s"])(t,n["a"].portalUrl,!0)),s||(s=this._portals.some(e=>this._hasSameServerInstance(e,t.uri))),s=s||this._agsPortal.test(t.path),s}_isIdProvider(e,t){let r=-1,s=-1;this._gwDomains.forEach((i,n)=>{-1===r&&i.regex.test(e)&&(r=n),-1===s&&i.regex.test(t)&&(s=n)});let i=!1;if(r>-1&&s>-1&&(0===r||4===r?0!==s&&4!==s||(i=!0):1===r?1!==s&&2!==s||(i=!0):2===r?2===s&&(i=!0):3===r&&3===s&&(i=!0)),!i){const r=this.findServerInfo(t),s=r&&r.owningSystemUrl;s&&ke(r)&&this._isPortalDomain(s)&&this._isIdProvider(e,s)&&(i=!0)}return i}_getIdenticalSvcIdx(e,t){let r=-1;for(let s=0;se.data),{adminUrl:t,promise:r}}if(this._isPortalDomain(e)){let t="";if(this._gwDomains.some(r=>(r.regex.test(e)&&(t=r.tokenServiceUrl),!!t)),t||this._portals.some(r=>(this._hasSameServerInstance(r,e)&&(t=r+this._gwTokenUrl),!!t)),t||(s=e.toLowerCase().indexOf("/sharing"),-1!==s&&(t=e.substring(0,s)+this._gwTokenUrl)),t||(t=this._getOrigin(e)+this._gwTokenUrl),t){const r=new p["a"](e).port;/^http:\/\//i.test(e)&&"7080"===r&&(t=t.replace(/:7080/i,":7443")),t=t.replace(/http:/i,"https:")}return t}if(-1!==e.toLowerCase().indexOf("premium.arcgisonline.com"))return"https://premium.arcgisonline.com/server/tokens"}_processOAuthResponseParams(e,t,r){const s=t._oAuthCred;if(e.code){const i=s.codeVerifier;return s.codeVerifier=null,s.stateUID=null,s.save(),this._getOAuthToken(r.server,e.code,t.appId,this._getRedirectURI(t,!0),i).then(i=>{const n=new xe({userId:i.username,server:r.server,token:i.access_token,expires:Date.now()+1e3*i.expires_in,ssl:i.ssl,oAuthState:e.state,_oAuthCred:s});return t.userId=n.userId,s.storage=i.persist?Ae:Te,s.refreshToken=i.refresh_token,s.token=null,s.expires=i.refresh_token_expires_in?Date.now()+1e3*i.refresh_token_expires_in:null,s.userId=n.userId,s.ssl=n.ssl,s.save(),n})}const i=new xe({userId:e.username,server:r.server,token:e.access_token,expires:Date.now()+1e3*Number(e.expires_in),ssl:"true"===e.ssl,oAuthState:e.state,_oAuthCred:s});return t.userId=i.userId,s.storage=e.persist?Ae:Te,s.refreshToken=null,s.token=i.token,s.expires=i.expires,s.userId=i.userId,s.ssl=i.ssl,s.save(),Promise.resolve(i)}_processOAuthPopupParams(e){var t;const r=this._oAuthDfd;if(this._oAuthDfd=null,r)if(clearInterval(this._oAuthIntervalId),null==(t=this._oAuthOnPopupHandle)||t.remove(),e.error){const t="access_denied"===e.error,s=new a["a"](t?"identity-manager:user-aborted":"identity-manager:authentication-failed",t?"ABORTED":"OAuth: "+e.error+" - "+e.error_description);r.reject(s)}else this._processOAuthResponseParams(e,r.oinfo_,r.sinfo_).then(e=>{r.resolve(e)}).catch(e=>{r.reject(e)})}_setOAuthResponseQueryString(e){e&&("?"===e.charAt(0)&&(e=e.substring(1)),this._processOAuthPopupParams(Object(p["H"])(e)))}_exchangeToken(e,t,r){return Object(o["default"])(e+"/sharing/rest/oauth2/exchangeToken",{authMode:"anonymous",method:"post",query:{f:"json",client_id:t,token:r}}).then(e=>e.data.token)}_getPlatformSelf(e,t){return e=e.replace(/^http:/i,"https:"),Object(o["default"])(e+"/sharing/rest/oauth2/platformSelf",{authMode:"anonymous",headers:{"X-Esri-Auth-Client-Id":t,"X-Esri-Auth-Redirect-Uri":window.location.href.replace(/#.*$/,"")},method:"post",query:{f:"json",expiration:30},withCredentials:!0}).then(e=>e.data)}_getPortalSelf(e,t){let r;return this._gwDomains.some(t=>(t.regex.test(e)&&(r=t.customBaseUrl),!!r)),r?Promise.resolve({allSSL:!0,currentVersion:"8.4",customBaseUrl:r,portalMode:"multitenant",supportsOAuth:!0}):(this._appOrigin.startsWith("https:")?e=e.replace(/^http:/i,"https:").replace(/:7080/i,":7443"):/^http:/i.test(t)&&(e=e.replace(/^https:/i,"http:").replace(/:7443/i,":7080")),Object(o["default"])(e,{query:{f:"json"},authMode:"anonymous",withCredentials:!0}).then(e=>e.data))}_doPortalSignIn(e){const t=this._portalConfig,r=window.location.href,s=this.findServerInfo(e);return!(!t&&!this._isPortalDomain(r)||!(s?s.hasPortal||s.owningSystemUrl&&this._isPortalDomain(s.owningSystemUrl):this._isPortalDomain(e))||!(this._isIdProvider(r,e)||t&&(this._hasSameServerInstance(this._getServerInstanceRoot(t.restBaseUrl),e)||this._isIdProvider(t.restBaseUrl,e))||Object(p["s"])(r,e,!0)))}_checkProtocol(e,t,r,s){let i=!0;const n=s?t.adminTokenServiceUrl:t.tokenServiceUrl;return n.trim().toLowerCase().startsWith("https:")&&!this._appOrigin.startsWith("https:")&&Object(p["q"])(n)&&(i=!!this._protocolFunc&&!!this._protocolFunc({resourceUrl:e,serverInfo:t}),!i)&&r(new a["a"]("identity-manager:aborted","Aborted the Sign-In process to avoid sending password over insecure connection.")),i}_enqueue(e,t,r,s,i,n){return s||(s=Object(d["g"])()),s.resUrl_=e,s.sinfo_=t,s.options_=r,s.admin_=i,s.refresh_=n,this._busy?this._hasSameServerInstance(this._getServerInstanceRoot(e),this._busy.resUrl_)?(this._oAuthDfd&&this._oAuthDfd.oAuthWin_&&this._oAuthDfd.oAuthWin_.focus(),this._soReqs.push(s)):this._xoReqs.push(s):this._doSignIn(s),s.promise}_doSignIn(e){this._busy=e,this._rejectOnPersistedPageShow=!1;const t=t=>{const r=e.options_&&e.options_.resource,s=e.resUrl_,i=e.refresh_;let n=!1;-1===this.credentials.indexOf(t)&&(i&&-1!==this.credentials.indexOf(i)?(i.userId=t.userId,i.token=t.token,i.expires=t.expires,i.validity=t.validity,i.ssl=t.ssl,i.creationTime=t.creationTime,n=!0,t=i):this.credentials.push(t)),t.resources||(t.resources=[]),t.resources.includes(r||s)||t.resources.push(r||s),t.scope=this._isServerRsrc(s)?"server":"portal",t.emitTokenChange();const o=this._soReqs,a={};this._soReqs=[],o.forEach(e=>{if(!this._isIdenticalService(s,e.resUrl_)){const r=this._getSuffix(e.resUrl_);a[r]||(a[r]=!0,t.resources.push(e.resUrl_))}}),e.resolve(t),o.forEach(e=>{this._hasSameServerInstance(this._getServerInstanceRoot(s),e.resUrl_)?e.resolve(t):this._soReqs.push(e)}),this._busy=e.resUrl_=e.sinfo_=e.refresh_=null,n||this.emit("credential-create",{credential:t}),this._soReqs.length?this._doSignIn(this._soReqs.shift()):this._xoReqs.length&&this._doSignIn(this._xoReqs.shift())},r=t=>{e.reject(t),this._busy=e.resUrl_=e.sinfo_=e.refresh_=null,this._soReqs.length?this._doSignIn(this._soReqs.shift()):this._xoReqs.length&&this._doSignIn(this._xoReqs.shift())},s=(i,n,o,c)=>{var h,u;const f=e.sinfo_,v=!e.options_||!1!==e.options_.prompt,g=f.hasPortal&&this._findOAuthInfo(e.resUrl_);let _,m;if(i)t(new xe({userId:i,server:f.server,token:o||null,expires:null!=c?Number(c):null,ssl:!!n}));else if(window!==window.parent&&null!=(h=this._appUrlObj.query)&&h["arcgis-auth-origin"]&&null!=(u=this._appUrlObj.query)&&u["arcgis-auth-portal"]&&this._hasSameServerInstance(this._getServerInstanceRoot(this._appUrlObj.query["arcgis-auth-portal"]),e.resUrl_)){var b;window.parent.postMessage({type:"arcgis:auth:requestCredential"},this._appUrlObj.query["arcgis-auth-origin"]);const s=Object(l["c"])(window,"message",e=>{e.source===window.parent&&e.data&&("arcgis:auth:credential"===e.data.type?(s.remove(),e.data.credential.expires{s.remove()})}else if(g){let i=g._oAuthCred;if(!i){const e=new _e(g,Ae),t=new _e(g,Te);e.isValid()&&t.isValid()?e.expires>t.expires?(i=e,t.destroy()):(i=t,e.destroy()):i=e.isValid()?e:t,g._oAuthCred=i}if(i.isValid()){_=new xe({userId:i.userId,server:f.server,token:i.token,expires:i.expires,ssl:i.ssl,_oAuthCred:i});const r=g.appId!==i.appId&&this._doPortalSignIn(e.resUrl_);r||i.refreshToken?(e._pendingDfd=i.refreshToken?this._getOAuthToken(f.server,i.refreshToken,i.appId).then(e=>(_.expires=Date.now()+1e3*e.expires_in,_.token=e.access_token,_)):Promise.resolve(_),e._pendingDfd.then(e=>r?this._exchangeToken(e.server,g.appId,e.token).then(t=>(e.token=t,e)).catch(()=>e):e).then(e=>{t(e)}).catch(()=>{i.destroy(),s()})):t(_)}else if(this._oAuthLocationParams&&this._hasSameServerInstance(g.portalUrl,this._oAuthLocationParams.state.portalUrl)&&(this._oAuthLocationParams.access_token||this._oAuthLocationParams.code&&this._oAuthLocationParams.state.uid===i.stateUID&&i.codeVerifier)){const s=this._oAuthLocationParams;this._oAuthLocationParams=null,e._pendingDfd=this._processOAuthResponseParams(s,g,f).then(e=>{t(e)}).catch(r)}else{const s=()=>{v?e._pendingDfd=this.oAuthSignIn(e.resUrl_,f,g,e.options_).then(t,r):(m=new a["a"]("identity-manager:not-authenticated","User is not signed in."),r(m))};this._doPortalSignIn(e.resUrl_)?e._pendingDfd=this._getPlatformSelf(f.server,g.appId).then(e=>{Object(p["s"])(e.portalUrl,this._appOrigin,!0)?(_=new xe({userId:e.username,server:f.server,expires:Date.now()+1e3*e.expires_in,token:e.token}),t(_)):s()}).catch(s):s()}}else if(v){if(this._checkProtocol(e.resUrl_,f,r,e.admin_)){let s=e.options_;e.admin_&&(s=s||{},s.isAdmin=!0),e._pendingDfd=this.signIn(e.resUrl_,f,s).then(t,r)}}else m=new a["a"]("identity-manager:not-authenticated","User is not signed in."),r(m)},i=()=>{const s=e.sinfo_,i=s.owningSystemUrl,n=e.options_;let o,a,c,l;if(n&&(o=n.token,a=n.error,c=n.prompt),l=this._findCredential(i,{token:o,resource:e.resUrl_}),!l)for(const e of this.credentials)if(this._isIdProvider(i,e.server)){l=e;break}if(l){const i=this.findCredential(e.resUrl_,l.userId);if(i)t(i);else if(je(s,this._legacyFed)){const e=l.toJSON();e.server=s.server,e.resources=null,t(new xe(e))}else(e._pendingDfd=this.generateToken(this.findServerInfo(l.server),null,{serverUrl:e.resUrl_,token:l.token,signal:e.options_.signal,ssl:l.ssl})).then(r=>{t(new xe({userId:l.userId,server:s.server,token:r.token,expires:null!=r.expires?Number(r.expires):null,ssl:!!r.ssl,isAdmin:e.admin_,validity:r.validity}))},r)}else this._busy=null,o&&(e.options_.token=null),(e._pendingDfd=this.getCredential(i.replace(/\/?$/,"/sharing"),{resource:e.resUrl_,owningTenant:s.owningTenant,signal:e.options_.signal,token:o,error:a,prompt:c})).then(()=>{this._enqueue(e.resUrl_,e.sinfo_,e.options_,e,e.admin_)},t=>{e.resUrl_=e.sinfo_=e.refresh_=null,e.reject(t)})};this._errbackFunc=r;const n=e.sinfo_.owningSystemUrl,o=this._isServerRsrc(e.resUrl_),c=e.sinfo_._restInfoPms;c?c.promise.then(t=>{const r=e.sinfo_;if(r._restInfoPms){r.adminTokenServiceUrl=r._restInfoPms.adminUrl,r._restInfoPms=null,r.tokenServiceUrl=Object(u["b"])("authInfo.tokenServicesUrl",t)||Object(u["b"])("authInfo.tokenServiceUrl",t)||Object(u["b"])("tokenServiceUrl",t),r.shortLivedTokenValidity=Object(u["b"])("authInfo.shortLivedTokenValidity",t),r.currentVersion=t.currentVersion,r.owningTenant=t.owningTenant;const e=r.owningSystemUrl=t.owningSystemUrl;e&&this._portals.push(e)}o&&r.owningSystemUrl?i():s()},()=>{e.sinfo_._restInfoPms=null;const t=new a["a"]("identity-manager:server-identification-failed","Unknown resource - could not find token service endpoint.");r(t)}):o&&n?i():e.sinfo_._selfReq?e.sinfo_._selfReq.selfDfd.then(t=>{const r={};let s,i,n,o;return t&&(s=t.user&&t.user.username,r.username=s,r.allSSL=t.allSSL,i=t.supportsOAuth,n=parseFloat(t.currentVersion),"multitenant"===t.portalMode&&(o=t.customBaseUrl),e.sinfo_.currentVersion=n),e.sinfo_.webTierAuth=!!s,s&&this.normalizeWebTierAuth?this.generateToken(e.sinfo_,null,{ssl:r.allSSL}).catch(()=>null).then(e=>(r.portalToken=e&&e.token,r.tokenExpiration=e&&e.expires,r)):!s&&i&&n>=4.4&&!this._findOAuthInfo(e.resUrl_)?this._generateOAuthInfo({portalUrl:e.sinfo_.server,customBaseUrl:o,owningTenant:e.sinfo_._selfReq.owningTenant}).catch(()=>null).then(()=>r):r}).catch(()=>null).then(t=>{e.sinfo_._selfReq=null,t?s(t.username,t.allSSL,t.portalToken,t.tokenExpiration):s()}):s()}_generateOAuthInfo(e){let t,r,s=e.portalUrl;const i=e.customBaseUrl,n=e.owningTenant,a=!this.defaultOAuthInfo&&this._createDefaultOAuthInfo&&!this._hasTestedIfAppIsOnPortal;if(a){r=window.location.href;let e=r.indexOf("?");e>-1&&(r=r.slice(0,e)),e=r.search(/\/(apps|home)\//),r=e>-1?r.slice(0,e):null}return a&&r?(this._hasTestedIfAppIsOnPortal=!0,t=Object(o["default"])(r+"/sharing/rest",{query:{f:"json"}}).then(()=>{this.defaultOAuthInfo=new ye({appId:"arcgisonline",popupCallbackUrl:r+"/home/oauth-callback.html"})})):t=Promise.resolve(),t.then(()=>{if(this.defaultOAuthInfo)return s=s.replace(/^http:/i,"https:"),Object(o["default"])(s+"/sharing/rest/oauth2/validateRedirectUri",{query:{accountId:n,client_id:this.defaultOAuthInfo.appId,redirect_uri:Object(p["C"])(this.defaultOAuthInfo.popupCallbackUrl),f:"json"}}).then(e=>{if(e.data.valid){const t=this.defaultOAuthInfo.clone();e.data.urlKey&&i?t.portalUrl="https://"+e.data.urlKey.toLowerCase()+"."+i:t.portalUrl=s,t.popup=window!==window.top||!(Object(p["s"])(s,this._appOrigin)||this._gwDomains.some(e=>e.regex.test(s)&&e.regex.test(this._appOrigin))),this.oAuthInfos.push(t)}})})}_doOAuthSignIn(e,t,r,s){const i=r._oAuthCred,n={portalUrl:r.portalUrl};!r.popup&&r.preserveUrlHash&&window.location.hash&&(n.hash=window.location.hash),i.stateUID&&(n.uid=i.stateUID);const o={client_id:r.appId,response_type:i.codeVerifier?"code":"token",state:JSON.stringify(n),expiration:r.expiration,locale:r.locale,redirect_uri:this._getRedirectURI(r,!!i.codeVerifier)};r.forceLogin&&(o.force_login=!0),r.forceUserId&&r.userId&&(o.prepopulatedusername=r.userId),!r.popup&&this._doPortalSignIn(e)&&(o.redirectToUserOrgUrl=!0),i.codeVerifier&&(o.code_challenge=s||i.codeVerifier,o.code_challenge_method=s?"S256":"plain");const c=r.portalUrl.replace(/^http:/i,"https:")+"/sharing/oauth2/authorize",h=c+"?"+Object(p["G"])(o);if(r.popup){const e=window.open(h,"esriJSAPIOAuth",r.popupWindowFeatures);if(e)e.focus(),this._oAuthDfd.oAuthWin_=e,this._oAuthIntervalId=setInterval(()=>{if(e.closed){clearInterval(this._oAuthIntervalId),this._oAuthOnPopupHandle.remove();const e=this._oAuthDfd;if(e){const t=new a["a"]("identity-manager:user-aborted","ABORTED");e.reject(t)}}},500),this._oAuthOnPopupHandle=Object(l["c"])(window,["arcgis:auth:hash","arcgis:auth:location:search"],e=>{"arcgis:auth:hash"===e.type?this.setOAuthResponseHash(e.detail):this._setOAuthResponseQueryString(e.detail)});else{const e=new a["a"]("identity-manager:popup-blocked","ABORTED");this._oAuthDfd.reject(e)}}else this._rejectOnPersistedPageShow=!0,this._oAuthRedirectFunc?this._oAuthRedirectFunc({authorizeParams:o,authorizeUrl:c,resourceUrl:e,serverInfo:t,oAuthInfo:r}):window.location.href=h}_getRedirectURI(e,t){const r=window.location.href.replace(/#.*$/,"");if(e.popup)return Object(p["C"])(e.popupCallbackUrl);if(t){const e=Object(p["M"])(r);return e.query&&["code","error","error_description","message_code","persist","state"].forEach(t=>{delete e.query[t]}),Object(p["e"])(e.path,e.query)}return r}}Ue.prototype.declaredClass="esri.identity.IdentityManagerBase";let xe=class extends c["a"].EventedAccessor{constructor(e){super(e),this._oAuthCred=null,this.tokenRefreshBuffer=2,e&&e._oAuthCred&&(this._oAuthCred=e._oAuthCred)}initialize(){this.resources=this.resources||[],null==this.creationTime&&(this.creationTime=Date.now())}refreshToken(){const e=s["b"].findServerInfo(this.server),t=e&&e.owningSystemUrl,r=!!t&&"server"===this.scope,i=r&&je(e,s["b"]._legacyFed),n=e.webTierAuth,o=n&&s["b"].normalizeWebTierAuth,a=Ie[this.server],c=a&&a[this.userId];let l,h=this.resources&&this.resources[0],u=r&&s["b"].findServerInfo(t),d={username:this.userId,password:c};if(n&&!o)return;r&&!u&&s["b"].serverInfos.some(e=>(s["b"]._isIdProvider(t,e.server)&&(u=e),!!u));const p=u&&s["b"].findCredential(u.server,this.userId);if(!r||p){if(!i){if(r)l={serverUrl:h,token:p&&p.token,ssl:p&&p.ssl};else if(o)d=null,l={ssl:this.ssl};else{if(!c){let t;return h&&(h=s["b"]._sanitizeUrl(h),this._enqueued=1,t=s["b"]._enqueue(h,e,null,null,this.isAdmin,this),t.then(()=>{this._enqueued=0,this.refreshServerTokens()}).catch(()=>{this._enqueued=0})),t}this.isAdmin&&(l={isAdmin:!0})}return s["b"].generateToken(r?u:e,r?null:d,l).then(e=>{this.token=e.token,this.expires=null!=e.expires?Number(e.expires):null,this.creationTime=Date.now(),this.validity=e.validity,this.emitTokenChange(),this.refreshServerTokens()}).catch(()=>{})}p.refreshToken()}}refreshServerTokens(){"portal"===this.scope&&s["b"].credentials.forEach(e=>{const t=s["b"].findServerInfo(e.server),r=t&&t.owningSystemUrl;e!==this&&e.userId===this.userId&&r&&"server"===e.scope&&(s["b"]._hasSameServerInstance(this.server,r)||s["b"]._isIdProvider(r,this.server))&&(je(t,s["b"]._legacyFed)?(e.token=this.token,e.expires=this.expires,e.creationTime=this.creationTime,e.validity=this.validity,e.emitTokenChange()):e.refreshToken())})}emitTokenChange(e){clearTimeout(this._refreshTimer);const t=this.server&&s["b"].findServerInfo(this.server),r=t&&t.owningSystemUrl,i=r&&s["b"].findServerInfo(r);!1===e||r&&"portal"!==this.scope&&(!i||!i.webTierAuth||s["b"].normalizeWebTierAuth)||null==this.expires&&null==this.validity||this._startRefreshTimer(),this.emit("token-change")}destroy(){this.userId=this.server=this.token=this.expires=this.validity=this.resources=this.creationTime=null,this._oAuthCred&&(this._oAuthCred.destroy(),this._oAuthCred=null);const e=s["b"].credentials.indexOf(this);e>-1&&s["b"].credentials.splice(e,1),this.emitTokenChange(),this.emit("destroy")}toJSON(){const e=Object(h["c"])({userId:this.userId,server:this.server,token:this.token,expires:this.expires,validity:this.validity,ssl:this.ssl,isAdmin:this.isAdmin,creationTime:this.creationTime,scope:this.scope}),t=this.resources;return t&&t.length>0&&(e.resources=t.slice()),e}_startRefreshTimer(){clearTimeout(this._refreshTimer);const e=6e4*this.tokenRefreshBuffer,t=2**31-1;let r=(this.validity?this.creationTime+6e4*this.validity:this.expires)-Date.now();r<0?r=0:r>t&&(r=t),this._refreshTimer=setTimeout(this.refreshToken.bind(this),r>e?r-e:r)}};Object(i["a"])([Object(f["b"])()],xe.prototype,"creationTime",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"expires",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"isAdmin",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"oAuthState",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"resources",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"scope",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"server",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"ssl",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"token",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"tokenRefreshBuffer",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"userId",void 0),Object(i["a"])([Object(f["b"])()],xe.prototype,"validity",void 0),xe=Object(i["a"])([Object(v["a"])("esri.identity.Credential")],xe);class Pe extends Ue{}Pe.prototype.declaredClass="esri.identity.IdentityManager";const Re=new Pe;Object(s["c"])(Re)}}]); //# sourceMappingURL=chunk-771be51c.fa1da948.js.map