define("metaserver/static/js/modules/clean/deprecated_ajax/ajax_jquery",["require","exports","tslib","@dropbox-performance/ttvc","metaserver/static/js/modules/clean/devtools/panels/performance/perf_hub_action_types","metaserver/static/js/modules/clean/deprecated_ajax/job_progress","metaserver/static/js/modules/clean/deprecated_ajax/util","metaserver/static/js/modules/core/persistence/storage","metaserver/static/js/modules/constants/ajax_strings","metaserver/static/js/modules/constants/page_load","metaserver/static/js/modules/constants/request","metaserver/static/js/modules/core/assert","metaserver/static/js/modules/core/browser","metaserver/static/js/modules/core/html","metaserver/static/js/modules/core/notify","metaserver/static/js/modules/core/uri","metaserver/static/js/modules/clean/csrf","metaserver/static/js/modules/clean/viewer"],(function(e,t,s,r,o,n,i,a,c,d,u,l,h,_,p,m,f,g){"use strict";function b(e){return e}Object.defineProperty(t,"__esModule",{value:!0}),t.SilentBackgroundBeaconRequest=t.ValidationSchemaRequest=t.SilentBackgroundRequest=t.BackgroundRequest=t.WebProgressRequest=t.FormWebRequest=t.WebRequestOref=t.WebRequest=t.Request=t.RESPONSE_PREFIX_NOTIFY_ERROR=t.getFakeJQXHR=void 0,n=s.__importStar(n),a=s.__importStar(a),c=s.__importStar(c),d=s.__importStar(d),u=s.__importStar(u),h=s.__importStar(h),t.getFakeJQXHR=e=>({response:void 0,responseText:"",status:0,statusText:"",getResponseHeader:function(e){return this.response?this.response.headers.get(e):null},readyState:XMLHttpRequest.UNSENT,abortController:e,thens:[],catches:[],abort:()=>e&&e.abort(),then:function(e,t){return this.thens.push(e),this.catches.push(t),this},catch:function(e){return this.catches.push(e),this},resolve:function(e){this.thens.forEach(t=>{t&&t(e)})},reject:function(e){this.catches.forEach(t=>{t&&t(e)})}});t.RESPONSE_PREFIX_NOTIFY_ERROR="err:";function x(e,s){var o;null==e&&(e={}),null==s&&(s=[]);const n=new E(e),a=w(n,s),c=a.options().type||"POST",d=a.data(),u=a.dataType(),l=a.headers();l.has("Content-Type")||l.append("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");let h=String(a.url());const _=new AbortController,p={method:c,mode:"cors",credentials:e.credentials||"include",headers:l,signal:_.signal};if("POST"===c){const e=null===(o=l.get("Content-Type"))||void 0===o?void 0:o.includes("application/x-www-form-urlencoded");p.body=e?i.jqParam(d,!0):d}else h=i.mergeQueryParams(h,d);const m=t.getFakeJQXHR(_);r.incrementAjaxCount();const f=fetch(h,p).then(e=>e.text().then(t=>({response:e,responseText:t}))).then(({response:e,responseText:s})=>{const{ok:r,status:o,statusText:n}=e;if(m.response=e,m.readyState=XMLHttpRequest.DONE,m.responseText=s,m.status=o,m.statusText=n,r)if("abort"===n)a.error(m,"aborted","abort"),a.complete(m,"aborted");else if("failed"===n)a.error(m,"failed",n),a.complete(m,"failed");else if("json"===u)try{const e=s.startsWith(t.RESPONSE_PREFIX_NOTIFY_ERROR)?s:JSON.parse(s);a.success(e,"success",m),a.complete(m,"success"),m.resolve(e)}catch(e){a.error(m,"parsererror",e.message),a.complete(m,"parsererror")}else a.success(s,"success",m),a.complete(m,"success"),m.resolve(s);else{m.status=e.status;const t=500===e.status?"":s;m.responseText=t,a.error(m,"error",t||m.statusText),a.complete(m,"error"),m.reject(m.responseText)}return e}).catch(e=>{"AbortError"===e.name?(m.statusText="abort",a.error(m,"aborted","abort"),a.complete(m,"aborted")):(a.error(m,"error",e.message),a.complete(m,"error")),m.reject(e)}).finally(r.decrementAjaxCount);return a.request(f),m}function y(e){return e.type===v.CHAINED}t.Request=x;const w=function(e,t){const s=[e];for(const e of Array.from(t.slice(0).reverse()))s.push(new e);let r=e;for(const e of s)r&&y(e)&&(e.next=r),r=e;return r};var v;(function(e){e.BASE="base",e.CHAINED="chained"})(v||(v={}));class E{constructor(e){this.type=v.BASE;const t=e||{},s=new Headers,r=t.headers||{};Object.keys(r).forEach(e=>{const t=r[e]||"";s.append(e,String(t))}),this.options=()=>t,this.url=()=>String(t.url||""),this.data=()=>t.data||{},this.dataType=()=>t.dataType||"text",this.headers=()=>s,this.success=t.success||b,this.error=t.error||b,this.complete=t.complete||b,this.request=b}}class R{constructor(){this.type=v.CHAINED}options(){return this.next.options()}url(){return this.next.url()}contentType(){return this.next.contentType()}data(){return this.next.data()}dataType(){return this.next.dataType()}headers(){return this.next.headers()}success(e,t,s){this.next.success(e,t,s)}error(e,t,s){this.next.error(e,t,s)}complete(e,t){this.next.complete(e,t)}request(e){this.next.request(e)}}class j extends R{constructor(){super(...arguments),this.SUPPORTED_TLDS=["dropbox.com"]}static initClass(){}data(){if(this.options().skipInjectCsrf)return this.next.data();l.assert(this._is_db_domain(),"injecting CSRF token into request to non-dropbox domain");const e={is_xhr:!0};return"GET"!==(this.options().type||"POST").toUpperCase()&&(e.t=f.readCsrfToken()),Object.assign(Object.assign({},e),this.next.data())}_is_db_domain(){const e=m.URI.parse(String(this.url())).getAuthority();if(!e)return!0;const t=e.split(".");return this.SUPPORTED_TLDS.reduce((function(e,s){const r=s.split("."),o=t.slice(-1*r.length).join(".");return e||s===o}),!1)}}j.initClass();class S extends R{data(){const e=this.next.data(),t=this.options();return t.subject_user&&!e._subject_uid&&(e._subject_uid=String(t.subject_user)),e}headers(){const e=this.next.headers(),t=this.options();return t.subject_user&&e.set("X-DROPBOX-UID",String(t.subject_user)),e}}class O extends R{headers(){var e,t;const s=this.next.headers(),r=this.options().teamAuthParams||{},o=r.team_id||g.Viewer.get_viewer().team_id;if(o){const{subject_user:r}=this.options(),n=null===(e=this.next.data())||void 0===e?void 0:e._subject_uid,i=("number"==typeof r?r:null==r?void 0:r.id)||("string"==typeof n?parseInt(n,10):n);i&&i===(null===(t=g.Viewer.get_viewer().work_user)||void 0===t?void 0:t.id)&&s.set("X-Dropbox-Teamid",String(o))}const n=r.auth_role||g.Viewer.get_viewer().auth_role,i=r.auth_action_type||g.Viewer.get_viewer().auth_action_type;return(n||i)&&s.set("X-Dropbox-Team-Authorization",JSON.stringify({auth_role:String(n),auth_action_type:String(i)})),s}}class T extends R{data(){const e=this.next.data();return u.REQUEST_TRACING_ENABLED?Object.assign({parent_request_id:u.REQUEST_ID},e):e}headers(){const e=this.next.headers(),t=this.options().type||"POST";return u.REQUEST_TRACING_ENABLED&&"POST"===t.toUpperCase()&&e.append(o.PerfHubHeaderNames.FORCE_REQUEST_TRACING_HEADER,"ON"),e}}class P extends R{success(e,s,r){let o;if(!r.responseText.length)return this.next.error(r,s,"AJAX Response was empty.");const n=this.options();let i=!0,a=!1;if(0===r.responseText.indexOf(t.RESPONSE_PREFIX_NOTIFY_ERROR))o=r.responseText.substr(t.RESPONSE_PREFIX_NOTIFY_ERROR.length),["{","["].includes(o[0])&&(i=!1);else{if(0!==r.responseText.indexOf("htmlerr:"))return this.next.success(e,s,r);o=r.responseText.substr("htmlerr:".length),a=!0}const c=this.next.error(r,s,o);if(i&&!n.skipNotifyError){let e=o;a&&(e=new _.HTML(o)),p.Notify.error(e)}return c}error(e,t,s){const r=this.options();return"aborted"===t||r.skipNotifyError||p.Notify.error(c.PROBLEM_COMPLETING_REQUEST),this.next.error(e,t,s)}}class N extends R{constructor(){super(),this._watch=this._watch.bind(this)}data(){this.job_id=N.generate_job_id();const e=this.next.data(),t=e._subject_uid,s=this.options(),{subject_user:r}=s;return t&&"string"==typeof t?this.uid=t:r&&(this.uid=String(r)),Object.assign({job_id:this.job_id},e)}request(e){return this._interval=1e3,this._failures=0,this._watch_count=0,this._watch_id=setInterval(this._watch,this._interval),this.next.request(e)}success(e,t,s){return this.next.success(e,t,s)}error(e,t,s){return this.next.error(e,t,s)}complete(e,t){return this._stop(),n.Job.handled(this.job_id),this.next.complete(e,t)}_watch(){return n.Job.peek(this.job_id)?this._stop():(this._watch_count++,this._watch_count%10==0&&(clearInterval(this._watch_id),this._interval=Math.min(Math.floor(1.5*this._interval),3e4),this._watch_id=setInterval(this._watch,this._interval)),this._show_progress_modal(),this._fetch_progress())}_stop(){clearInterval(this._watch_id),n.ModalProgress.hide()}_show_progress_modal(){if(this._modal_shown)return;this._modal_shown=!0;const e=this.options();e.progress_text&&n.ModalProgress.show(e.progress_text)}_fetch_progress(){const e={};return this.uid&&(e._subject_uid=this.uid),X({url:`/job_status/${this.job_id}`,data:e,dataType:"text",success(e,t,s){let r;r=0===s.responseText.indexOf("done")?"1/1":s.responseText,n.ModalProgress.update(r)},error:(e,t,s)=>{if(this._failures++,!(this._failures<3))return this._stop(),this.next.error(e,t,s)}})}static generate_job_id(){const e=(new Date).getTime().toString();let t=Math.floor(1e6*Math.random()).toString();return t=`000000${t}`.substring(t.length),e+t}}class I extends R{data(){var e;const t=h.get_uri().getQuery().oref;return!(null===(e=this.next.data())||void 0===e?void 0:e.oref)&&t?Object.assign({oref:t},this.next.data()):this.next.data()}}const q=[class extends R{constructor(){super(),this.browser_unload_handler=this.browser_unload_handler.bind(this),this.is_browser_unloading=!1}browser_unload_handler(){this.is_browser_unloading=!0}request(e){return window.addEventListener("beforeunload",this.browser_unload_handler),this.next.request(e)}error(e,t,s){return"error"===t&&this.is_browser_unloading?this.next.error(e,"aborted","unload"):this.next.error(e,t,s)}complete(e,t){return window.removeEventListener("beforeunload",this.browser_unload_handler),this.next.complete(e,t)}}],C=[S,O,j,class extends R{error(e,t,s){if(403===e.status){const e=a.SessionStorage.get("reload-timestamp"),t=(new Date).getTime();(!e||t-e>3e4)&&(a.SessionStorage.set("reload-timestamp",t),window.location.reload())}return this.next.error(e,t,s)}}],k=[class extends R{constructor(){super(),this._clear_working_msg=this._clear_working_msg.bind(this)}request(e){let t=!1;return e.catch(()=>{}).then(()=>{t=!0}),setTimeout(()=>{t||this._should_show_working_msg()&&(this._show_working_msg(),e.catch(()=>{}).then(()=>{this._clear_working_msg()}))},4e3),this.next.request(e)}_should_show_working_msg(){return p.Notify.isShown()}_show_working_msg(){return this.notification=p.Notify.success(c.STILL_WORKING),this.notification}_clear_working_msg(){if(p.Notify.isShown()&&this.notification===p.Notify.current())return p.Notify.clear()}}],L=[class extends R{error(e,t,s){return this._notify_dev(e,t,s),this.next.error(e,t,s)}_notify_dev(e,t,s){e.getResponseHeader("X-Debug-Url")}},T,class extends R{data(){const e=this.next.data(),t={};return d.PUBLIC_MODE_OVERRIDE&&(t.public_mode_override="1"),d.COUNTRY_OVERRIDE&&(t.country_override=d.COUNTRY_OVERRIDE),Object.assign(Object.assign({},t),e)}}],A=[class extends R{constructor(){super(),this._watch=this._watch.bind(this)}data(){const e=this.next.data();this.uid=e._subject_uid?String(e._subject_uid):"";const{subject_user:t}=this.options();return!this.uid&&t&&(this.uid=String(t)),e}success(e,t,s){return this._is_async_job_response(s.responseText)?(this.job_id=s.responseText.split(":")[1],this._interval=1e3,this._failures=0,this._watch_count=0,this._watch_id=setInterval(this._watch,this._interval)):this.next.success(e,t,s)}complete(e,t){if(!this._is_async_job_response(e.responseText))return this.next.complete(e,t)}_is_async_job_response(e){if(!e||0!==e.indexOf("async_task_started:"))return!1;return e.split(":")[1].match(/^[A-Za-z0-9_\-=]*$/)}_watch(){return n.Job.peek(this.job_id)?this._stop():(this._watch_count++,this._watch_count%10==0&&(clearInterval(this._watch_id),this._interval=Math.min(Math.floor(1.5*this._interval),3e4),this._watch_id=setInterval(this._watch,this._interval)),this._show_progress_modal(),this._fetch_progress())}_stop(){clearInterval(this._watch_id),n.ModalProgress.hide()}_show_progress_modal(){if(this._modal_shown)return;this._modal_shown=!0;const{progress_text:e}=this.options();e&&n.ModalProgress.show(e)}_fetch_progress(){const e={};return this.uid&&(e._subject_uid=this.uid),H({url:`/async_task_status/${this.job_id}`,data:e,dataType:"text",success:(e,s,r)=>{let o=r.responseText;if(0===o.indexOf("done:"))return n.Job.handled(this.job_id),this._stop(),o=o.substr("done:".length),r.responseText=o,this.next.success(e,s,r),this.next.complete(r,s);if(0===o.indexOf(t.RESPONSE_PREFIX_NOTIFY_ERROR)){n.Job.handled(this.job_id),this._stop();const e=o.substr(t.RESPONSE_PREFIX_NOTIFY_ERROR.length);return p.Notify.error(e),this.next.error(r,s,e),this.next.complete(r,s)}if(0===o.indexOf("async_task_err:")){n.Job.handled(this.job_id),this._stop();const e=o.substr("async_task_err:".length),{skipNotifyError:t}=this.options();return t||p.Notify.error(new _.HTML(e)),this.next.error(r,s,e),this.next.complete(r,s)}n.ModalProgress.update(o)},error:(e,t,s)=>{if(this._failures++,!(this._failures<3))return this._stop(),this.next.error(e,t,s),this.next.complete(e,t)}})}}],F=[].concat(q,k,P,L,C,A);t.WebRequest=function(e){return null==e&&(e={}),x(e,F)},t.WebRequestOref=function(e){return null==e&&(e={}),x(e,[].concat(I,F))};const D=[].concat(q,k,class extends R{success(e,s,r){if(!this.options().skipErrorHandling){if(!r.responseText.length)return this.next.error(r,s,"AJAX Form response was empty.");if(0===r.responseText.indexOf(t.RESPONSE_PREFIX_NOTIFY_ERROR)){const e=r.responseText.substr(t.RESPONSE_PREFIX_NOTIFY_ERROR.length);return this.next.error(r,s,e)}}return this.next.success(e,s,r)}},L,C,A);t.FormWebRequest=function(e){return null==e&&(e={}),x(e,D)};const M=[].concat(q,k,P,L,C,N,A);function X(e){return null==e&&(e={}),x(e,[].concat(q,L,C))}t.WebProgressRequest=function(e){return null==e&&(e={}),x(e,M)},t.BackgroundRequest=X;const U=[S,O,j],B=[].concat(q,L,U);function H(e){return null==e&&(e={}),x(e,B)}t.SilentBackgroundRequest=H,t.ValidationSchemaRequest=function(e){return e.type="OPTIONS",x(e,C)},t.SilentBackgroundBeaconRequest=function(e){var t;null==e&&(e={});const s=null===(t=navigator.sendBeacon)||void 0===t?void 0:t.bind(navigator);if(!s)return H(e);const r=new E(e),o=w(r,[].concat(U,T)),n=o.url(),i=(e=>{const t=new FormData;for(const s of Object.keys(e)){const r=e[s];(null===r?[]:Array.isArray(r)?r:[r]).forEach(e=>{let r;void 0!==e&&(r=!0===e?"true":!1===e?"false":"number"==typeof e?String(e):e,t.append(s,r))})}return t})(o.data());s(String(n),i)||console.warn(`Beacon request failed: ${n}`)}})),define("metaserver/static/js/modules/clean/deprecated_ajax/job_progress",["require","exports","metaserver/static/js/modules/clean/dbmodal_stack"],(function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Job=t.ModalProgress=void 0;const r={complete:{},handled(e){if(!e)return!1;const t=!!r.complete[e];return r.complete[e]=!0,t},peek:e=>!!e&&!!r.complete[e]};t.Job=r;const o={show(e){var t;if(!e)return;null===(t=s.DBModalStack.top())||void 0===t||t.hide();const r=document.createElement("div");r.id="modal-progress-overlay",r.style.position="fixed",r.style.width="100%",r.style.height="100%",r.style.display="none",r.classList.add("fade-out"),document.body.appendChild(r);const o=document.createElement("div");o.id="modal-progress-content",o.style.display="none",o.classList.add("fade-out");const n=document.createElement("div");n.id="modal-progress-bar";const i=(function(e,t=300){const s=t.toString()+"px",r=document.createElement("div");r.classList.add("outer-progress-bar");const o=document.createElement("div");o.style.width=s,o.id=`pb_${e}`,o.classList.add("inner-progress-bar");const n=document.createElement("div");n.style.width=s,n.classList.add("under-pb"),n.classList.add("progress-bar");const i=document.createElement("div");i.style.display="none",i.id=`pb_${e}_over`,i.classList.add("over-pb"),i.classList.add("progress-bar");const a=document.createElement("div");a.style.width=s,a.id=`pb_${e}_upct`,a.classList.add("pb-percentage");const c=document.createElement("div");return c.style.width=s,c.id=`pb_${e}_opct`,c.classList.add("pb-percentage"),n.appendChild(a),i.appendChild(c),o.appendChild(n),o.appendChild(i),r.appendChild(o),r})("modal-progress",150);n.appendChild(i);const a=document.createElement("div");a.id="modal-progress-text",a.textContent=e;const c=document.createElement("modal-progress-container");c.id="modal-progress-container",c.appendChild(n),c.appendChild(a),o.appendChild(c),document.body.appendChild(o),r.style.display="",r.classList.add("fade-to"),r.classList.remove("fade-out"),o.style.display="",o.classList.add("fade-in"),o.classList.remove("fade-out")},update(e){e.indexOf("progress")>-1&&(e=e.substring("progress".length)),(function(e,t){const s=document.querySelector(`#pb_${e}_over`);if(!s)return;const r=t.split("/").map(Number),o=r.length>1?r[0]/r[1]:r[0],n=isNaN(o)?0:o;s.style.width=`${100*Math.min(n,1)}%`,s.style.display="",s.style.backgroundColor="#348DD3",s.style.overflow="hidden"})("modal-progress",e)},hide(){const e=document.querySelector("#modal-progress-overlay");e&&(e.classList.add("fade-out"),e.classList.remove("fade-to"),window.setTimeout(()=>{e.remove()},250));const t=document.querySelector("#modal-progress-content");t&&(t.classList.add("fade-out"),t.classList.remove("fade-in"),window.setTimeout(()=>{t.remove()},250))}};t.ModalProgress=o})),define("metaserver/static/js/modules/clean/deprecated_ajax/util",["require","exports"],(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.mergeQueryParams=t.jqParam=void 0;const s={};function r(e){return null===e?String(e):s[toString.call(e)]||"object"}function o(e){return(function(e){return"object"===r(e)})(e)&&!(function(e){return null!==e&&e===e.window})(e)&&Object.getPrototypeOf(e)===Object.prototype}["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"].forEach(e=>{s["[object "+e+"]"]=e.toLowerCase()}),t.jqParam=function(e,t=!1){const s=[];return s.add=function(e,t){(function(e){return"function"===r(e)})(t)&&(t=t()),void 0!==t&&(null===t&&(t=""),s.push(encodeURIComponent(e)+"="+encodeURIComponent(t)))},(function e(t,s,n=!1,i=""){let a;const c=Array.isArray(s),d=o(s);Object.entries(s).forEach(([s,o])=>{a=r(o),i&&(s=n?i:i+"["+(d||"object"===a||"array"===a?s:"")+"]"),!i&&c?t.add(o.name,o.value):"array"===a||!n&&"object"===a?e(t,o,n,s):t.add(s,o)})})(s,e,t),s.join("&").replace(/%20/g,"+")},t.mergeQueryParams=function(e,s){const r=e.startsWith("//"),o=!r&&!e.includes("://")?"http://example":r?"http:":"",n=new URL(o+e),i={};n.searchParams.forEach((function(e,t){i[t]=e})),Object.keys(s).forEach(e=>{let t=s[e];null===t&&(t=""),void 0!==t&&(i[e]=t)});const a=[];Object.entries(i).forEach(([e,s])=>{a.push(t.jqParam({[e]:s},!0))}),n.search=a.join("&");let c=n.toString();return c=c.slice(o.length),c}})); //# sourceMappingURL=pkg-core-deprecated.min.js-vflXLWiuU.map