@overmap-ai/core 1.0.74-gcs.1 → 1.0.74-gcs.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,15 @@
1
- (function(i,j){typeof exports=="object"&&typeof module<"u"?j(exports,require("@redux-offline/redux-offline/lib/types"),require("@reduxjs/toolkit"),require("superagent"),require("uuid"),require("file-saver"),require("@redux-offline/redux-offline"),require("@redux-offline/redux-offline/lib/defaults"),require("buffer"),require("localforage"),require("redux-persist-migrate"),require("@overmap-ai/forms"),require("idb"),require("@redux-offline/redux-offline/lib/constants"),require("jwt-decode"),require("dependency-graph"),require("@tiptap/core")):typeof define=="function"&&define.amd?define(["exports","@redux-offline/redux-offline/lib/types","@reduxjs/toolkit","superagent","uuid","file-saver","@redux-offline/redux-offline","@redux-offline/redux-offline/lib/defaults","buffer","localforage","redux-persist-migrate","@overmap-ai/forms","idb","@redux-offline/redux-offline/lib/constants","jwt-decode","dependency-graph","@tiptap/core"],j):(i=typeof globalThis<"u"?globalThis:i||self,j(i["overmap-core"]={},null,i.toolkit,i.request,i.uuid,i.fileSaver,i.reduxOffline,i.offlineConfig,null,i.localforage,i.createMigration,null,i.idb,i.constants,i.jwtDecode,i.dependencyGraph))})(this,function(i,j,o,Pe,ye,Fl,Rl,ga,Kf,Pl,Ol,Yf,_l,vl,wl,El){"use strict";var Hf=Object.defineProperty;var Wf=(i,j,o)=>j in i?Hf(i,j,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[j]=o;var f=(i,j,o)=>Wf(i,typeof j!="symbol"?j+"":j,o);var Il;const Ta=Object.freeze([]),ba=Object.freeze({});var Ft=(t=>(t[t.GUEST=0]="GUEST",t[t.BASIC=2]="BASIC",t[t.ADMIN=4]="ADMIN",t))(Ft||{}),Rt=(t=>(t[t.GUEST=0]="GUEST",t[t.BASIC=2]="BASIC",t[t.ADMIN=4]="ADMIN",t))(Rt||{}),l=(t=>(t.GET="GET",t.POST="POST",t.PATCH="PATCH",t.PUT="PUT",t.DELETE="DELETE",t))(l||{}),Ia=(t=>(t.Issue="issue",t.Asset="asset",t.AssetType="asset_type",t.Project="project",t.Document="document",t))(Ia||{}),Pt=(t=>(t[t.LOWEST=0]="LOWEST",t[t.LOW=2]="LOW",t[t.MEDIUM=4]="MEDIUM",t[t.HIGH=6]="HIGH",t[t.HIGHEST=8]="HIGHEST",t))(Pt||{}),Ot=(t=>(t[t.BACKLOG=0]="BACKLOG",t[t.SELECTED=2]="SELECTED",t[t.DONE=4]="DONE",t))(Ot||{}),v=(t=>(t.STATUS="status",t.PRIORITY="priority",t.CATEGORY="category",t.DESCRIPTION="description",t.TITLE="title",t.ASSIGNED_TO="assigned_to",t.DUE_DATE="due_date",t))(v||{}),Fa=(t=>(t.COMPLETED="checkout.completed",t.CLOSED="checkout.closed",t))(Fa||{}),Ra=(t=>(t[t.PRO=0]="PRO",t))(Ra||{}),Pa=(t=>(t[t.ACTIVE=0]="ACTIVE",t[t.PAUSED=2]="PAUSED",t[t.CANCELLED=4]="CANCELLED",t[t.INACTIVE=6]="INACTIVE",t[t.PAST_DUE=8]="PAST_DUE",t))(Pa||{});const jl=Ot.BACKLOG,ql=Pt.MEDIUM,Oa=6e4;function F(t){return{addOne:(p,A)=>{const y=t(A.payload);p.instances[y]=A.payload},addMany:(p,A)=>{for(const y of A.payload){const b=t(y);p.instances[b]=y}},setOne:(p,A)=>{const y=t(A.payload);p.instances[y]=A.payload},setMany:(p,A)=>{for(const y of A.payload){const b=t(y);p.instances[b]=y}},updateOne:(p,A)=>{const y=t(A.payload);p.instances[y]=A.payload},updateMany:(p,A)=>{for(const y of A.payload){const b=t(y);p.instances[b]=y}},deleteOne:(p,A)=>{delete p.instances[A.payload]},deleteMany:(p,A)=>{for(const y of A.payload)delete p.instances[y]},initialize:(p,A)=>{p.instances={};for(const y of A.payload){const b=t(y);p.instances[b]=y}},getInitialState:p=>({...p,instances:{}})}}Il=Symbol.toStringTag;class _a{constructor(){f(this,Il,"Promise");f(this,"_promise");f(this,"_resolve");f(this,"_reject");f(this,"_state","pending");this._resolve=null,this._reject=null,this._promise=new Promise((e,s)=>{this._resolve=e,this._reject=s})}get state(){return this._state}then(e,s){return this._promise.then(e,s)}catch(e){return this._promise.catch(e)}resolve(e){if(!this._resolve)throw new Error("No resolve callback");this._resolve(e),this._state="fulfilled"}reject(e){if(!this._reject)throw e;this._reject(e),this._state="rejected"}finally(e){throw new Error("`finally` not implemented")}}const Ml=t=>({type:"Point",coordinates:t}),Cl=t=>({type:"MultiPoint",coordinates:t}),kl=(t,e)=>t[0]===e[0]&&t[1]===e[1];let _t=!1;["true","1"].includes("".toLowerCase())&&(_t=!0);function zl(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;const s=Object.keys(t),a=Object.keys(e),n=s.length;if(n!==a.length)return!1;for(let c=0;c<n;c++){const r=s[c];if(!Object.prototype.hasOwnProperty.call(e,r)||t[r]!==e[r])return!1}return!0}function vt(t){const e={};return function(){const s=Array.prototype.slice.call(arguments);return s in e?(_t&&console.debug(`Memoization debug: Using memorized return value for ${t.toString()}(`,s,")"),e[s]):(_t&&console.debug(`Memoization debug: Cache miss! Memoizing ${t.toString()}(`,s,")"),e[s]=t.apply(this,s))}}function Vl(t,e){if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0}const g=t=>t.length===0?Ta:t,Ce=t=>Object.keys(t).length===0?ba:t,va=vt(t=>{if(!t)return"";const e=new Date(t),s=e.getFullYear()===wt.getFullYear(),a={day:"numeric",month:"short"};return s||(a.year="numeric"),e.toLocaleDateString([],a)}),Dl=new Intl.RelativeTimeFormat([],{style:"long",numeric:"auto"}),Ul=1e3*86400,wt=new Date,$l=t=>new Date(t).toDateString()===wt.toDateString(),Bl=vt((t,e,s)=>{const a=Math.round((new Date(t).getTime()-wt.getTime())/Ul);return a<e||a>s?va(t):Dl.format(a,"days")});function Gl(t){return new Uint8Array(t).reduce((s,a)=>s+a.toString(16).padStart(2,"0"),"")}const Et=async(t,e)=>{e||(e=await Oe(t));let s=t.type;if(s.includes("/")&&(s=s.split("/")[1]),!s)throw new Error(`Could not extract file type from ${t.type}`);return`${e}.${s}`};function Oe(t){return new Promise((e,s)=>{const a=new FileReader;a.onload=()=>{const n=a.result;if(!n){s(new Error("FileReader did not return a valid ArrayBuffer."));return}crypto.subtle.digest("SHA-1",n).then(c=>{const r=Gl(c);e(r)})},a.readAsArrayBuffer(t)})}function Ll(t){if(!t.name||!t.type||!t.size){const e="File has no name, type, and/or size";throw new Error(e)}return`${t.name}&${t.type}${t.size}`}function wa(t,e){return new File([t],e,{type:t.type})}function Nl(t,e){const s=document.createElement("a");s.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(e)),s.setAttribute("download",t),s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s)}const Hl=async t=>{const e={};for(const s of t){const a=await Oe(s);e[a]={sha1:a,extension:s.name.split(".").pop()||"",file_type:s.type,size:s.size}}return Object.values(e)},Ea=async t=>(await fetch(t)).blob(),Wl=t=>new Promise((e,s)=>{const a=new FileReader;a.onloadend=()=>{var n;e(((n=a.result)==null?void 0:n.toString())||"")},a.readAsDataURL(t)});function Kl(t){const e=new Blob([t]);Fl.saveAs(e,t.name)}const ja={};function Yl(t,e,s,...a){const n=ja[t];let c=!1;n?n[e]||(n[e]=!0,c=!0):(ja[t]={[e]:!0},c=!0),c&&console[s](...a)}const qa=["created_at","updated_at","index","revision"];function R(t){return{...t,uuid:ye.v4()}}function Ma(t){const e={};for(const s of t)e[s.uuid]=s;return e}function Jl(t,e=void 0,s=255){let a=t.replace(/[^a-z0-9_\-.]/gi,"_").replace(/_{2,}/g,"_");if(!e){const c=t.split(".");c.length>1&&(e=c[c.length-1])}e&&!e.startsWith(".")&&(e="."+e);const n=e?e.length:0;return a.length+n>s&&(a=a.slice(0,s-n)+(e||"")),a}function Xl(t){return t.toLowerCase().replace(" ","-")}function Zl(t,e=!1){return t.normalize("NFKD").toLowerCase().replace(/[^\w\s-]/g,"").trim().replace(/[-\s]+/g,e?"_":"-")}function Ql(t,e){if(t.length<=e)return t;const s=t.slice(0,e-1);return s.slice(0,s.lastIndexOf(" "))+"…"}const S=t=>e=>s=>t(s,e);function Ca(t,e,s){return s.findIndex(a=>a.uuid===t.uuid)===e}function xl(t,e,s){return s.findIndex(a=>a.file_sha1===t.file_sha1)===e}const eh=/^.+@.+\..+$/;function _(t){const e={...t};for(const s of[...qa,"created_by"])s in e&&delete e[s];return e}const ke=F(t=>t.uuid),ka=ke.getInitialState({}),jt=o.createSlice({name:"agents",initialState:ka,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ka)),reducers:{initializeConversations:ke.initialize,addConversation:ke.addOne,setConversation:ke.setOne,updateConversation:ke.updateOne}}),{initializeConversations:za,addConversation:Va,setConversation:Da,updateConversation:Ua}=jt.actions,qt=t=>t.agentsReducer.instances,th=o.createSelector([qt],t=>Object.values(t)),sh=S(o.createSelector([qt,(t,e)=>e],(t,e)=>t[e])),$a=jt.reducer,k=F(t=>t.uuid),Ba=k.getInitialState({}),Mt=o.createSlice({name:"assetAttachments",initialState:Ba,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ba)),reducers:{initializeAssetAttachments:k.initialize,addAssetAttachment:k.addOne,addAssetAttachments:k.addMany,setAssetAttachment:k.setOne,setAssetAttachments:k.setMany,updateAssetAttachment:k.updateOne,updateAssetAttachments:k.updateMany,deleteAssetAttachment:k.deleteOne,deleteAssetAttachments:k.deleteMany}}),{initializeAssetAttachments:Ct,addAssetAttachment:ih,addAssetAttachments:kt,setAssetAttachment:Ga,setAssetAttachments:ah,updateAssetAttachment:nh,updateAssetAttachments:La,deleteAssetAttachment:Na,deleteAssetAttachments:zt}=Mt.actions,Ha=t=>t.assetAttachmentReducer.instances,Wa=o.createSelector([Ha],t=>Object.values(t)),Ka=t=>e=>e.assetAttachmentReducer.instances[t],Ya=S(o.createSelector([Wa,(t,e)=>e],(t,e)=>g(t.filter(({asset:s})=>e===s)))),Ja=Mt.reducer,z=F(t=>t.uuid),Xa=z.getInitialState({}),Vt=o.createSlice({name:"assetProcedureFieldsAttachments",initialState:Xa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Xa)),reducers:{initializeAssetProcedureFieldsAttachments:z.initialize,addAssetProcedureFieldsAttachment:z.addOne,addAssetProcedureFieldsAttachments:z.addMany,setAssetProcedureFieldsAttachment:z.setOne,setAssetProcedureFieldsAttachments:z.setMany,updateAssetProcedureFieldsAttachment:z.updateOne,updateAssetProcedureFieldsAttachments:z.updateMany,deleteAssetProcedureFieldsAttachment:z.deleteOne,deleteAssetProcedureFieldsAttachments:z.deleteMany}}),{initializeAssetProcedureFieldsAttachments:Za,addAssetProcedureFieldsAttachment:ch,addAssetProcedureFieldsAttachments:Qa,setAssetProcedureFieldsAttachment:rh,setAssetProcedureFieldsAttachments:dh,updateAssetProcedureFieldsAttachment:uh,updateAssetProcedureFieldsAttachments:xa,deleteAssetProcedureFieldsAttachment:oh,deleteAssetProcedureFieldsAttachments:en}=Vt.actions,tn=t=>t.assetProcedureFieldsAttachmentReducer.instances,sn=o.createSelector([tn],t=>Object.values(t)),lh=S(o.createSelector([sn,(t,e)=>e],(t,e)=>g(t.filter(s=>s.fields_revision===e)))),hh=t=>e=>e.assetProcedureFieldsAttachmentReducer.instances[t],an=Vt.reducer,V=F(t=>t.uuid),nn=V.getInitialState({}),Dt=o.createSlice({name:"assetProcedureFields",initialState:nn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,nn)),reducers:{initializeAssetProcedureFields:V.initialize,addAssetProcedureFields:V.addOne,addAssetProcedureFieldsMany:V.addMany,setAssetProcedureFields:V.setOne,setAssetProcedureFieldsMany:V.setMany,updateAssetProcedureFields:V.updateOne,updateAssetProcedureFieldsMany:V.updateMany,deleteAssetProcedureFields:V.deleteOne,deleteAssetProcedureFieldsMany:V.deleteMany}}),{initializeAssetProcedureFields:cn,addAssetProcedureFields:rn,addAssetProcedureFieldsMany:mh,setAssetProcedureFields:ph,setAssetProcedureFieldsMany:Ah,updateAssetProcedureFields:dn,updateAssetProcedureFieldsMany:yh,deleteAssetProcedureFields:un,deleteAssetProcedureFieldsMany:fh}=Dt.actions,on=t=>t.assetProcedureFieldsReducer.instances,Ut=o.createSelector([on],t=>Object.values(t)),Sh=S(o.createSelector([Ut,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_procedure===e)))),gh=S(o.createSelector([Ut,(t,e)=>e],(t,e)=>t.filter(s=>s.asset_procedure===e).sort((s,a)=>s.submitted_at>a.submitted_at?-1:1)[0])),Th=t=>e=>e.assetProcedureFieldsReducer.instances[t],ln=Dt.reducer,D=F(t=>t.uuid),hn=D.getInitialState({}),$t=o.createSlice({name:"assetProcedureFieldValuesAttachments",initialState:hn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,hn)),reducers:{initializeAssetProcedureFieldValuesAttachments:D.initialize,addAssetProcedureFieldValuesAttachment:D.addOne,addAssetProcedureFieldValuesAttachments:D.addMany,setAssetProcedureFieldValuesAttachment:D.setOne,setAssetProcedureFieldValuesAttachments:D.setMany,updateAssetProcedureFieldValuesAttachment:D.updateOne,updateAssetProcedureFieldValuesAttachments:D.updateMany,deleteAssetProcedureFieldValuesAttachment:D.deleteOne,deleteAssetProcedureFieldValuesAttachments:D.deleteMany}}),{initializeAssetProcedureFieldValuesAttachments:mn,addAssetProcedureFieldValuesAttachment:bh,addAssetProcedureFieldValuesAttachments:Qe,setAssetProcedureFieldValuesAttachment:Ih,setAssetProcedureFieldValuesAttachments:Fh,updateAssetProcedureFieldValuesAttachment:Rh,updateAssetProcedureFieldValuesAttachments:pn,deleteAssetProcedureFieldValuesAttachment:Ph,deleteAssetProcedureFieldValuesAttachments:xe}=$t.actions,Bt=t=>t.assetProcedureFieldValuesAttachmentReducer.instances,An=o.createSelector([Bt],t=>Object.values(t)),Oh=t=>e=>e.assetProcedureFieldValuesAttachmentReducer.instances[t],yn=S(o.createSelector([Bt,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(a=>s.has(a.uuid)))})),fn=S(o.createSelector([An,(t,e)=>e],(t,e)=>g(t.filter(s=>s.field_values===e)))),Sn=$t.reducer,U=F(t=>t.uuid),gn=U.getInitialState({}),Gt=o.createSlice({name:"assetProcedureFieldValues",initialState:gn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,gn)),reducers:{initializeAssetProcedureFieldValues:U.initialize,addAssetProcedureFieldValues:U.addOne,addAssetProcedureFieldValuesMany:U.addMany,setAssetProcedureFieldValues:U.setOne,setAssetProcedureFieldValuesMany:U.setMany,updateAssetProcedureFieldValues:U.updateOne,updateAssetProcedureFieldValuesMany:U.updateMany,deleteAssetProcedureFieldValues:U.deleteOne,deleteAssetProcedureFieldValuesMany:U.deleteMany}}),{initializeAssetProcedureFieldValues:Tn,addAssetProcedureFieldValues:Lt,addAssetProcedureFieldValuesMany:bn,setAssetProcedureFieldValues:_h,setAssetProcedureFieldValuesMany:vh,updateAssetProcedureFieldValues:ze,updateAssetProcedureFieldValuesMany:In,deleteAssetProcedureFieldValues:Nt,deleteAssetProcedureFieldValuesMany:Fn}=Gt.actions,Rn=t=>t.assetProcedureFieldValuesReducer.instances,Ht=o.createSelector([Rn],t=>Object.values(t)),wh=S(o.createSelector([Ht,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset===e)))),Eh=S(o.createSelector([Ht,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_procedure_instance===e)))),Wt=t=>e=>e.assetProcedureFieldValuesReducer.instances[t],Pn=Gt.reducer,$=F(t=>t.uuid),On=$.getInitialState({}),Kt=o.createSlice({name:"assetProcedureInstances",initialState:On,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,On)),reducers:{initializeAssetProcedureInstances:$.initialize,addAssetProcedureInstance:$.addOne,addAssetProcedureInstances:$.addMany,setAssetProcedureInstance:$.setOne,setAssetProcedureInstances:$.setMany,updateAssetProcedureInstance:$.updateOne,updateAssetProcedureInstances:$.updateMany,deleteAssetProcedureInstance:$.deleteOne,deleteAssetProcedureInstances:$.deleteMany}}),{initializeAssetProcedureInstances:_n,addAssetProcedureInstance:Yt,addAssetProcedureInstances:vn,updateAssetProcedureInstance:Ve,updateAssetProcedureInstances:jh,deleteAssetProcedureInstance:Jt,deleteAssetProcedureInstances:wn,setAssetProcedureInstance:qh,setAssetProcedureInstances:Mh}=Kt.actions,Xt=t=>t.assetProcedureInstanceReducer.instances,Zt=o.createSelector([Xt],t=>Object.values(t)),En=S(o.createSelector([Zt,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_procedure===e)))),Ch=S(o.createSelector([Zt,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_type===e)))),Qt=t=>e=>e.assetProcedureInstanceReducer.instances[t],kh=S(o.createSelector([Xt,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n&&s.push(n)}return g(s)})),jn=Kt.reducer,B=F(t=>t.uuid),qn=B.getInitialState({}),xt=o.createSlice({name:"assetProcedures",initialState:qn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,qn)),reducers:{initializeAssetProcedures:B.initialize,addAssetProcedure:B.addOne,addAssetProcedures:B.addMany,setAssetProcedure:B.setOne,setAssetProcedures:B.setMany,updateAssetProcedure:B.updateOne,updateAssetProcedures:B.updateMany,deleteAssetProcedure:B.deleteOne,deleteAssetProcedures:B.deleteMany}}),{initializeAssetProcedures:Mn,addAssetProcedure:es,addAssetProcedures:zh,updateAssetProcedure:De,updateAssetProcedures:Vh,deleteAssetProcedure:ts,deleteAssetProcedures:Dh,setAssetProcedure:Uh,setAssetProcedures:$h}=xt.actions,ss=t=>t.assetProcedureReducer.instances,Cn=o.createSelector([ss],t=>Object.values(t)),Bh=S(o.createSelector([Cn,(t,e)=>e],(t,e)=>g(t.filter(s=>s.organization===e)))),is=t=>e=>e.assetProcedureReducer.instances[t],Gh=S(o.createSelector([ss,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n&&s.push(n)}return g(s)})),kn=xt.reducer,G=F(t=>t.uuid),zn=G.getInitialState({}),as=o.createSlice({name:"assets",initialState:zn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,zn)),reducers:{initializeAssets:G.initialize,addAsset:G.addOne,addAssets:G.addMany,setAsset:G.setOne,setAssets:G.setMany,updateAsset:G.updateOne,updateAssets:G.updateMany,deleteAsset:G.deleteOne,deleteAssets:G.deleteMany}}),{initializeAssets:Vn,addAsset:ns,addAssets:cs,updateAsset:Ue,updateAssets:Lh,deleteAsset:rs,deleteAssets:Dn,setAsset:Nh,setAssets:Hh}=as.actions,ds=t=>t.assetReducer.instances,Un=o.createSelector([ds],t=>g(Object.values(t))),us=S(o.createSelector([Un,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_type===e)))),os=t=>e=>e.assetReducer.instances[t],Wh=S(o.createSelector([ds,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n&&s.push(n)}return g(s)})),Kh=t=>e=>us(t)(e).length,$n=as.reducer,pe=F(t=>t.uuid),Bn=pe.getInitialState({}),ls=o.createSlice({name:"assetStageCompletions",initialState:Bn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Bn)),reducers:{initializeAssetStageCompletions:pe.initialize,addAssetStageCompletion:pe.addOne,addAssetStageCompletions:pe.addMany,updateAssetStageCompletion:pe.updateOne,updateAssetStageCompletions:pe.updateMany,deleteAssetStageCompletion:pe.deleteOne,deleteAssetStageCompletions:pe.deleteMany}}),{initializeAssetStageCompletions:Gn,addAssetStageCompletion:hs,addAssetStageCompletions:ms,updateAssetStageCompletion:Ln,updateAssetStageCompletions:Nn,deleteAssetStageCompletion:ps,deleteAssetStageCompletions:As}=ls.actions,Hn=ls.reducer,ys=t=>t.assetStageCompletionReducer.instances,Yh=o.createSelector([ys],t=>Object.values(t)),Wn=t=>e=>e.assetStageCompletionReducer.instances[t],Kn=S(o.createSelector([ys,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(a=>s.has(a.uuid)))})),L=F(t=>t.uuid),Yn=L.getInitialState({}),fs=o.createSlice({name:"assetStages",initialState:Yn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Yn)),reducers:{initializeAssetStages:L.initialize,setAssetStage:L.setOne,setAssetStages:L.setMany,addAssetStage:L.addOne,addAssetStages:L.addMany,updateAssetStage:L.updateOne,updateAssetStages:L.updateMany,deleteAssetStage:L.deleteOne,deleteAssetStages:L.deleteMany}}),{initializeAssetStages:Jn,setAssetStage:Xn,setAssetStages:Jh,addAssetStage:Xh,addAssetStages:Ss,updateAssetStage:gs,updateAssetStages:et,deleteAssetStage:Zh,deleteAssetStages:Ts}=fs.actions,Zn=fs.reducer,tt=t=>t.assetStageReducer.instances,Qn=t=>e=>e.assetStageReducer.instances[t],xn=o.createSelector([tt],t=>Object.values(t)),Qh=S(o.createSelector([tt,(t,e)=>e],(t,e)=>{const s={};for(const[a,n]of Object.entries(t))n.asset_procedure===e&&(s[a]=n);return Ce(s)})),xh=S(o.createSelector([xn,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_procedure===e)))),bs=S(o.createSelector([tt,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n?s.push(n):console.warn("selectStagesFromStageIds: No stage exists with the id",a)}return g(s)})),N=F(t=>t.uuid),ec=N.getInitialState({}),Is=o.createSlice({name:"assetTypeAttachments",initialState:ec,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ec)),reducers:{initializeAssetTypeAttachments:N.initialize,addAssetTypeAttachment:N.addOne,addAssetTypeAttachments:N.addMany,setAssetTypeAttachment:N.setOne,setAssetTypeAttachments:N.setMany,updateAssetTypeAttachment:N.updateOne,updateAssetTypeAttachments:N.updateMany,deleteAssetTypeAttachment:N.deleteOne,deleteAssetTypeAttachments:N.deleteMany}}),{initializeAssetTypeAttachments:tc,addAssetTypeAttachment:em,addAssetTypeAttachments:Fs,setAssetTypeAttachment:sc,setAssetTypeAttachments:tm,updateAssetTypeAttachment:sm,updateAssetTypeAttachments:ic,deleteAssetTypeAttachment:ac,deleteAssetTypeAttachments:Rs}=Is.actions,nc=t=>t.assetTypeAttachmentReducer.instances,cc=o.createSelector([nc],t=>Object.values(t)),rc=t=>e=>e.assetTypeAttachmentReducer.instances[t],dc=S(o.createSelector([cc,(t,e)=>e],(t,e)=>g(t.filter(({asset_type:s})=>e===s)))),uc=Is.reducer,H=F(t=>t.uuid),oc=H.getInitialState({}),Ps=o.createSlice({name:"assetTypeFieldsAttachments",initialState:oc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,oc)),reducers:{initializeAssetTypeFieldsAttachments:H.initialize,addAssetTypeFieldsAttachment:H.addOne,addAssetTypeFieldsAttachments:H.addMany,setAssetTypeFieldsAttachment:H.setOne,setAssetTypeFieldsAttachments:H.setMany,updateAssetTypeFieldsAttachment:H.updateOne,updateAssetTypeFieldsAttachments:H.updateMany,deleteAssetTypeFieldsAttachment:H.deleteOne,deleteAssetTypeFieldsAttachments:H.deleteMany}}),{initializeAssetTypeFieldsAttachments:lc,addAssetTypeFieldsAttachment:im,addAssetTypeFieldsAttachments:hc,setAssetTypeFieldsAttachment:am,setAssetTypeFieldsAttachments:nm,updateAssetTypeFieldsAttachment:cm,updateAssetTypeFieldsAttachments:mc,deleteAssetTypeFieldsAttachment:rm,deleteAssetTypeFieldsAttachments:pc}=Ps.actions,Ac=t=>t.assetTypeFieldsAttachmentReducer.instances,yc=o.createSelector([Ac],t=>Object.values(t)),dm=S(o.createSelector([yc,(t,e)=>e],(t,e)=>g(t.filter(s=>s.fields_revision===e)))),um=t=>e=>e.assetTypeFieldsAttachmentReducer.instances[t],fc=Ps.reducer,W=F(t=>t.uuid),Sc=W.getInitialState({}),Os=o.createSlice({name:"assetTypeFields",initialState:Sc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Sc)),reducers:{initializeAssetTypeFields:W.initialize,addAssetTypeFields:W.addOne,addAssetTypeFieldsMany:W.addMany,setAssetTypeFields:W.setOne,setAssetTypeFieldsMany:W.setMany,updateAssetTypeFields:W.updateOne,updateAssetTypeFieldsMany:W.updateMany,deleteAssetTypeFields:W.deleteOne,deleteAssetTypeFieldsMany:W.deleteMany}}),{initializeAssetTypeFields:gc,addAssetTypeFields:Tc,addAssetTypeFieldsMany:om,setAssetTypeFields:lm,setAssetTypeFieldsMany:hm,updateAssetTypeFields:bc,updateAssetTypeFieldsMany:mm,deleteAssetTypeFields:Ic,deleteAssetTypeFieldsMany:pm}=Os.actions,Fc=t=>t.assetTypeFieldsReducer.instances,st=o.createSelector([Fc],t=>Object.values(t)),Am=S(o.createSelector([st,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_type===e)))),ym=S(o.createSelector([st,(t,e)=>e],(t,e)=>t.filter(s=>s.asset_type===e).sort((s,a)=>s.submitted_at>a.submitted_at?-1:1)[0])),fm=t=>e=>e.assetTypeFieldsReducer.instances[t],Rc=Os.reducer,K=F(t=>t.uuid),Pc=K.getInitialState({}),_s=o.createSlice({name:"assetTypeFieldValuesAttachments",initialState:Pc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Pc)),reducers:{initializeAssetTypeFieldValuesAttachments:K.initialize,addAssetTypeFieldValuesAttachment:K.addOne,addAssetTypeFieldValuesAttachments:K.addMany,setAssetTypeFieldValuesAttachment:K.setOne,setAssetTypeFieldValuesAttachments:K.setMany,updateAssetTypeFieldValuesAttachment:K.updateOne,updateAssetTypeFieldValuesAttachments:K.updateMany,deleteAssetTypeFieldValuesAttachment:K.deleteOne,deleteAssetTypeFieldValuesAttachments:K.deleteMany}}),{initializeAssetTypeFieldValuesAttachments:Oc,addAssetTypeFieldValuesAttachment:Sm,addAssetTypeFieldValuesAttachments:it,setAssetTypeFieldValuesAttachment:gm,setAssetTypeFieldValuesAttachments:Tm,updateAssetTypeFieldValuesAttachment:bm,updateAssetTypeFieldValuesAttachments:_c,deleteAssetTypeFieldValuesAttachment:Im,deleteAssetTypeFieldValuesAttachments:at}=_s.actions,vs=t=>t.assetTypeFieldValuesAttachmentReducer.instances,vc=o.createSelector([vs],t=>Object.values(t)),Fm=t=>e=>e.assetTypeFieldValuesAttachmentReducer.instances[t],wc=S(o.createSelector([vs,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(a=>s.has(a.uuid)))})),Ec=S(o.createSelector([vc,(t,e)=>e],(t,e)=>g(t.filter(s=>s.field_values===e)))),jc=_s.reducer,Y=F(t=>t.uuid),qc=Y.getInitialState({}),ws=o.createSlice({name:"assetTypeFieldValues",initialState:qc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,qc)),reducers:{initializeAssetTypeFieldValues:Y.initialize,addAssetTypeFieldValues:Y.addOne,addAssetTypeFieldValuesMany:Y.addMany,setAssetTypeFieldValues:Y.setOne,setAssetTypeFieldValuesMany:Y.setMany,updateAssetTypeFieldValues:Y.updateOne,updateAssetTypeFieldValuesMany:Y.updateMany,deleteAssetTypeFieldValues:Y.deleteOne,deleteAssetTypeFieldValuesMany:Y.deleteMany}}),{initializeAssetTypeFieldValues:Mc,addAssetTypeFieldValues:Es,addAssetTypeFieldValuesMany:Cc,setAssetTypeFieldValues:Rm,setAssetTypeFieldValuesMany:Pm,updateAssetTypeFieldValues:$e,updateAssetTypeFieldValuesMany:kc,deleteAssetTypeFieldValues:js,deleteAssetTypeFieldValuesMany:zc}=ws.actions,Vc=t=>t.assetTypeFieldValuesReducer.instances,qs=o.createSelector([Vc],t=>Object.values(t)),Om=S(o.createSelector([qs,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset===e)))),_m=S(o.createSelector([st,qs,(t,e)=>e],(t,e,s)=>{const a=new Set(t.filter(n=>n.asset_type===s).map(n=>n.uuid));return g(e.filter(n=>a.has(n.fields_revision)))})),Ms=t=>e=>e.assetTypeFieldValuesReducer.instances[t],Dc=ws.reducer,J=F(t=>t.uuid),Uc=J.getInitialState({}),Cs=o.createSlice({name:"assetTypes",initialState:Uc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Uc)),reducers:{initializeAssetTypes:J.initialize,setAssetType:J.setOne,setAssetTypes:J.setMany,addAssetType:J.addOne,addAssetTypes:J.addMany,updateAssetType:J.updateOne,updateAssetTypes:J.updateMany,deleteAssetType:J.deleteOne,deleteAssetTypes:J.deleteMany}}),{initializeAssetTypes:$c,setAssetType:vm,setAssetTypes:wm,addAssetType:ks,addAssetTypes:Em,updateAssetType:Be,updateAssetTypes:jm,deleteAssetType:zs,deleteAssetTypes:qm}=Cs.actions,Vs=t=>t.assetTypeReducer.instances,Mm=o.createSelector([Vs],t=>Object.values(t)),Ds=t=>e=>e.assetTypeReducer.instances[t],Cm=S(o.createSelector([Vs,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n?s.push(n):console.warn("selectAssetTypesByIds: No assetType exists with the id",a)}return g(s)})),Bc=Cs.reducer,Gc={accessToken:"",refreshToken:"",isLoggedIn:!1},nt=o.createSlice({name:"auth",initialState:Gc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Gc)),reducers:{setTokens:(t,e)=>{t.accessToken=e.payload.accessToken,t.refreshToken=e.payload.refreshToken},clearTokens:t=>{t.accessToken="",t.refreshToken=""},setLoggedIn:(t,e)=>{e.payload||nt.caseReducers.clearTokens(t),t.isLoggedIn=e.payload}}}),{setTokens:km,clearTokens:zm,setLoggedIn:Lc}=nt.actions,Vm=t=>t.authReducer.accessToken,Dm=t=>t.authReducer.isLoggedIn,Nc=nt.reducer,Ge=F(t=>t.uuid),Hc=Ge.getInitialState({}),Us=o.createSlice({name:"categories",initialState:Hc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Hc)),reducers:{initializeCategories:Ge.initialize,addCategory:Ge.addOne,updateCategory:Ge.updateOne,deleteCategory:Ge.deleteOne}}),{initializeCategories:Wc,addCategory:$s,updateCategory:Kc,deleteCategory:Yc}=Us.actions,Bs=t=>t.categoryReducer.instances,Um=o.createSelector([Bs],t=>Object.values(t)),Gs=t=>e=>e.categoryReducer.instances[t],$m=S(o.createSelector([Bs,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n?s.push(n):console.warn("selectCategoryByIds: No category exists with the id",a)}return g(s)})),Bm=t=>e=>Object.values(e.issueReducer.instances).filter(s=>s.category===t).length,Jc=Us.reducer,X=F(t=>t.uuid),Xc=X.getInitialState({}),Ls=o.createSlice({name:"documentAttachments",initialState:Xc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Xc)),reducers:{initializeDocumentAttachments:X.initialize,addDocumentAttachment:X.addOne,addDocumentAttachments:X.addMany,setDocumentAttachment:X.setOne,setDocumentAttachments:X.setMany,updateDocumentAttachment:X.updateOne,updateDocumentAttachments:X.updateMany,deleteDocumentAttachment:X.deleteOne,deleteDocumentAttachments:X.deleteMany}}),{initializeDocumentAttachments:Zc,addDocumentAttachment:Gm,addDocumentAttachments:Qc,setDocumentAttachment:xc,setDocumentAttachments:Lm,updateDocumentAttachment:Nm,updateDocumentAttachments:er,deleteDocumentAttachment:tr,deleteDocumentAttachments:sr}=Ls.actions,ir=t=>t.documentAttachmentReducer.instances,ar=o.createSelector([ir],t=>Object.values(t)),nr=t=>e=>e.documentAttachmentReducer.instances[t],Hm=S(o.createSelector([ar,(t,e)=>e],(t,e)=>g(t.filter(({document:s})=>e===s)))),cr=Ls.reducer,rr={documents:{}},Ns=o.createSlice({name:"documents",initialState:rr,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,rr)}),reducers:{setDocuments:(t,e)=>{if(e.payload.filter(Ca).length!==e.payload.length)throw new Error("Tried to use setIssues reducer with duplicate ID's");t.documents=Ma(e.payload)},addDocuments:(t,e)=>{for(const s of e.payload)if(s.uuid in t.documents)throw new Error(`attempting to add a document with uuid ${s.uuid} which already exists in state.documents.`);for(const s of e.payload){if(s.parent_document&&t.documents[s.parent_document]){const a=t.documents[s.parent_document];t.documents[s.parent_document]={...a,children_documents:[...a.children_documents,s.uuid]}}t.documents[s.uuid]=s}},updateDocuments:(t,e)=>{for(const s of e.payload)if(!(s.uuid in t.documents))throw new Error(`attempting to update a document with uuid ${s.uuid} which doesn't exists in state.documents.`);for(const s of e.payload){const a=t.documents[s.uuid];if(s.organization!==void 0&&s.organization!==a.organization)throw new Error("organization cannot be updated");if(s.project!==void 0&&s.project!==a.project)throw new Error("project cannot be updated");t.documents[s.uuid]={...a,...s}}},moveDocument:(t,e)=>{const{documentId:s,targetDocumentId:a,position:n}=e.payload;if(!(s in t.documents))throw new Error(`attempting to move a document with uuid ${s} which doesn't exist in state.documents`);const c=t.documents[s];if(c.parent_document&&t.documents[c.parent_document]){const{children_documents:r}=t.documents[c.parent_document];t.documents[c.parent_document].children_documents.splice(r.indexOf(c.uuid),1)}if(a){const r=t.documents[a],u=r!=null&&r.parent_document?t.documents[r.parent_document]:null;switch(n){case"left":if(!u)throw new Error("attempting to move a document to the left of a document with no parent_document");t.documents[r.parent_document].children_documents.splice(u.children_documents.indexOf(r.uuid),0,c.uuid),t.documents[s].parent_document=u.uuid;break;case"right":if(!u)throw new Error("attempting to move a document to the left of a document with no parent_document");t.documents[r.parent_document].children_documents.splice(u.children_documents.indexOf(r.uuid)+1,0,c.uuid),t.documents[s].parent_document=u.uuid;break;case"left-child":if(!r)throw new Error("attempting to move a document to the left-child of a document that doesn't exist");t.documents[a].children_documents.unshift(c.uuid),t.documents[s].parent_document=r.uuid;break;case"right-child":if(!r)throw new Error("attempting to move a document to the left-child of a document that doesn't exist");t.documents[a].children_documents.push(c.uuid),t.documents[s].parent_document=r.uuid}}else t.documents[s].parent_document=null},removeDocuments:(t,e)=>{for(const s of e.payload)if(!(s in t.documents))throw new Error(`attempting to delete a document with uuid ${s} which doesn't exists in state.documents.`);for(const s of e.payload){const a=t.documents[s];if(a.parent_document&&t.documents[a.parent_document]){const n=t.documents[a.parent_document];t.documents[a.parent_document]={...n,children_documents:n.children_documents.filter(c=>c!==a.uuid)}}delete t.documents[s]}}}}),{setDocuments:dr,addDocuments:ur,updateDocuments:Ae,moveDocument:or,removeDocuments:Hs}=Ns.actions,_e=t=>t.documentsReducer.documents,lr=o.createSelector([_e],t=>Object.values(t)),hr=t=>e=>e.documentsReducer.documents[t],Wm=S(o.createSelector([_e,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n?s.push(n):console.warn("selectDocumentByIds: No document exists with the id",a)}return g(s)})),Km=S(o.createSelector([_e,(t,e)=>e],(t,e)=>{const s=[],a=t[e];if(!a||!a.parent_document)return s;let n=t[a.parent_document];for(;n;)s.push(n.uuid),n=t[n.parent_document??""];return g(s)})),Ym=o.createSelector([lr],t=>g(t.filter(e=>!e.parent_document))),mr=Ns.reducer,pr={s3Urls:{}},Ar=1e3*60*60,Jm=Ar*24*7,Ws=o.createSlice({name:"file",initialState:pr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,pr)),reducers:{setUploadUrl:(t,e)=>{const{url:s,fields:a,sha1:n}=e.payload,c=new Date,r=new Date(c.getTime()+Jm);t.s3Urls[n]={url:s,fields:a,exp:r.getTime()}}}}),{setUploadUrl:yr}=Ws.actions,fr=t=>e=>{const s=e.fileReducer.s3Urls[t];if(!s)return;const a=new Date().getTime();if(!((s.exp??a)-a<Ar))return s},Sr=Ws.reducer,Z=F(t=>t.uuid),gr=Z.getInitialState({}),Ks=o.createSlice({name:"formRevisionAttachments",initialState:gr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,gr)),reducers:{initializeFormRevisionAttachments:Z.initialize,addFormRevisionAttachment:Z.addOne,addFormRevisionAttachments:Z.addMany,setFormRevisionAttachment:Z.setOne,setFormRevisionAttachments:Z.setMany,updateFormRevisionAttachment:Z.updateOne,updateFormRevisionAttachments:Z.updateMany,deleteFormRevisionAttachment:Z.deleteOne,deleteFormRevisionAttachments:Z.deleteMany}}),{initializeFormRevisionAttachments:Tr,addFormRevisionAttachment:Xm,addFormRevisionAttachments:br,setFormRevisionAttachment:Zm,setFormRevisionAttachments:Qm,updateFormRevisionAttachment:xm,updateFormRevisionAttachments:Ir,deleteFormRevisionAttachment:ep,deleteFormRevisionAttachments:Fr}=Ks.actions,Rr=t=>t.formRevisionAttachmentReducer.instances,tp=S(o.createSelector([Rr,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.form_revision===e)))),Pr=Ks.reducer,sp=(t,e)=>{const s=t.revision,a=e.revision;return s===void 0&&a===void 0?t.submitted_at<e.submitted_at?-1:1:s===void 0?1:a===void 0||s<a?-1:1},fe=F(t=>t.uuid),Or=fe.getInitialState({}),Ys=o.createSlice({name:"formRevisions",initialState:Or,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Or)),reducers:{initializeFormRevisions:fe.initialize,setFormRevision:fe.setOne,addFormRevision:fe.addOne,addFormRevisions:fe.addMany,deleteFormRevision:fe.deleteOne,deleteFormRevisions:fe.deleteMany}}),{setFormRevision:_r,initializeFormRevisions:vr,addFormRevision:Js,addFormRevisions:wr,deleteFormRevision:Xs,deleteFormRevisions:Er}=Ys.actions,ct=t=>t.formRevisionReducer.instances,jr=o.createSelector([ct],t=>Object.values(t)),ip=t=>e=>e.formRevisionReducer.instances[t],ap=S(o.createSelector([ct,(t,e)=>e],(t,e)=>{const s=Object.values(t).filter(c=>c.form===e);if(s.length===0)return;const n=s.sort(sp)[s.length-1];return t[n.uuid]})),qr=S(o.createSelector([jr,(t,e)=>e],(t,e)=>g(t.filter(s=>s.form===e)))),Mr=Ys.reducer,Se=F(t=>t.uuid),Cr=Se.getInitialState({}),Zs=o.createSlice({name:"forms",initialState:Cr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Cr)),reducers:{initializeForms:Se.initialize,setForm:Se.setOne,addForm:Se.addOne,addForms:Se.addMany,updateForm:Se.updateOne,deleteForm:Se.deleteOne}}),{initializeForms:kr,setForm:np,addForm:Qs,addForms:cp,updateForm:rp,deleteForm:xs}=Zs.actions,zr=Zs.reducer,Vr=t=>t.formReducer.instances,dp=o.createSelector([Vr],t=>Object.values(t)),Dr=t=>e=>e.formReducer.instances[t],Q=F(t=>t.uuid),Ur=Q.getInitialState({}),ei=o.createSlice({name:"formSubmissionAttachments",initialState:Ur,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ur)),reducers:{initializeFormSubmissionAttachments:Q.initialize,addFormSubmissionAttachment:Q.addOne,addFormSubmissionAttachments:Q.addMany,setFormSubmissionAttachment:Q.setOne,setFormSubmissionAttachments:Q.setMany,updateFormSubmissionAttachment:Q.updateOne,updateFormSubmissionAttachments:Q.updateMany,deleteFormSubmissionAttachment:Q.deleteOne,deleteFormSubmissionAttachments:Q.deleteMany}}),{initializeFormSubmissionAttachments:$r,addFormSubmissionAttachment:up,addFormSubmissionAttachments:rt,setFormSubmissionAttachment:op,setFormSubmissionAttachments:lp,updateFormSubmissionAttachment:hp,updateFormSubmissionAttachments:Br,deleteFormSubmissionAttachment:mp,deleteFormSubmissionAttachments:dt}=ei.actions,ti=t=>t.formSubmissionAttachmentReducer.instances,Gr=S(o.createSelector([ti,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(a=>s.has(a.uuid)))})),Lr=S(o.createSelector([ti,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.form_submission===e)))),Nr=ei.reducer,x=F(t=>t.uuid),Hr=x.getInitialState({}),si=o.createSlice({name:"formSubmissions",initialState:Hr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Hr)),reducers:{initializeFormSubmissions:x.initialize,setFormSubmission:x.setOne,setFormSubmissions:x.setMany,addFormSubmission:x.addOne,addFormSubmissions:x.addMany,updateFormSubmission:x.updateOne,updateFormSubmissions:x.updateMany,deleteFormSubmission:x.deleteOne,deleteFormSubmissions:x.deleteMany}}),{initializeFormSubmissions:Wr,setFormSubmission:ut,setFormSubmissions:pp,addFormSubmission:ii,addFormSubmissions:ot,updateFormSubmission:Kr,updateFormSubmissions:Ap,deleteFormSubmission:ai,deleteFormSubmissions:lt}=si.actions,ni=t=>t.formSubmissionReducer.instances,ci=o.createSelector([ni],t=>Object.values(t)),ri=t=>e=>e.formSubmissionReducer.instances[t],Yr=S(o.createSelector([ni,ct,(t,e)=>e],(t,e,s)=>{const a=new Set;for(const n of Object.values(e))n.form===s&&a.add(n.uuid);return Object.values(t).filter(n=>a.has(n.form_revision))})),Jr=S(o.createSelector([ci,(t,e)=>e],(t,e)=>Object.values(t).filter(s=>s.issue===e))),Xr=S(o.createSelector([ci,(t,e)=>e],(t,e)=>t.filter(s=>s.asset===e))),Zr=si.reducer,ee=F(t=>t.uuid),Qr=ee.getInitialState({}),di=o.createSlice({name:"geoImages",initialState:Qr,extraReducers:t=>{t.addCase("RESET",e=>{Object.assign(e,Qr)})},reducers:{initializeGeoImages:ee.initialize,setGeoImage:ee.setOne,setGeoImages:ee.setMany,addGeoImage:ee.addOne,addGeoImages:ee.addMany,updateGeoImage:ee.updateOne,updateGeoImages:ee.updateMany,deleteGeoImage:ee.deleteOne,deleteGeoImages:ee.deleteMany}}),{initializeGeoImages:xr,setGeoImage:Le,setGeoImages:ed,addGeoImage:td,addGeoImages:sd,updateGeoImage:id,updateGeoImages:yp,deleteGeoImage:ui,deleteGeoImages:ad}=di.actions,nd=t=>t.geoImageReducer.instances,cd=o.createSelector([nd],t=>Object.values(t)),oi=t=>e=>e.geoImageReducer.instances[t],fp=S(o.createSelector([cd,(t,e)=>e],(t,e)=>g(t.filter(s=>s.project===e)))),rd=di.reducer,te=F(t=>t.uuid),dd=te.getInitialState({}),li=o.createSlice({name:"issueAssociations",initialState:dd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,dd)),reducers:{initializeIssueAssociations:te.initialize,addIssueAssociation:te.addOne,addIssueAssociations:te.addMany,setIssueAssociation:te.setOne,setIssueAssociations:te.setMany,updateIssueAssociation:te.updateOne,updateIssueAssociations:te.updateMany,deleteIssueAssociation:te.deleteOne,deleteIssueAssociations:te.deleteMany}}),{initializeIssueAssociations:ud,setIssueAssociations:Sp,setIssueAssociation:gp,updateIssueAssociation:od,updateIssueAssociations:Tp,addIssueAssociation:hi,addIssueAssociations:mi,deleteIssueAssociation:pi,deleteIssueAssociations:Ai}=li.actions,Ne=t=>t.issueAssociationReducer.instances,bp=o.createSelector([Ne],t=>Object.values(t)),ld=t=>e=>e.issueAssociationReducer.instances[t],hd=S(o.createSelector([Ne,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.associated_issue===e)))),md=S(o.createSelector([Ne,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.issue===e)))),pd=S(o.createSelector([Ne,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.asset===e)))),Ad=li.reducer,se=F(t=>t.uuid),yd=se.getInitialState({}),yi=o.createSlice({name:"issueAttachments",initialState:yd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,yd)),reducers:{initializeIssueAttachments:se.initialize,addIssueAttachment:se.addOne,addIssueAttachments:se.addMany,setIssueAttachment:se.setOne,setIssueAttachments:se.setMany,updateIssueAttachment:se.updateOne,updateIssueAttachments:se.updateMany,deleteIssueAttachment:se.deleteOne,deleteIssueAttachments:se.deleteMany}}),{initializeIssueAttachments:fi,addIssueAttachment:Ip,addIssueAttachments:Si,setIssueAttachment:fd,setIssueAttachments:Fp,updateIssueAttachment:Rp,updateIssueAttachments:Sd,deleteIssueAttachment:gd,deleteIssueAttachments:gi}=yi.actions,Td=t=>t.issueAttachmentReducer.instances,bd=o.createSelector([Td],t=>Object.values(t)),Id=S(o.createSelector([bd,(t,e)=>e],(t,e)=>g(t.filter(({issue:s})=>e===s)))),Fd=t=>e=>e.issueAttachmentReducer.instances[t],Rd=yi.reducer,ie=F(t=>t.uuid),Pd=ie.getInitialState({}),Ti=o.createSlice({name:"issueCommentAttachments",initialState:Pd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Pd)),reducers:{initializeIssueCommentAttachments:ie.initialize,addIssueCommentAttachment:ie.addOne,addIssueCommentAttachments:ie.addMany,setIssueCommentAttachment:ie.setOne,setIssueCommentAttachments:ie.setMany,updateIssueCommentAttachment:ie.updateOne,updateIssueCommentAttachments:ie.updateMany,deleteIssueCommentAttachment:ie.deleteOne,deleteIssueCommentAttachments:ie.deleteMany}}),{initializeIssueCommentAttachments:bi,addIssueCommentAttachment:Pp,addIssueCommentAttachments:Od,setIssueCommentAttachment:_d,setIssueCommentAttachments:Op,updateIssueCommentAttachment:_p,updateIssueCommentAttachments:vd,deleteIssueCommentAttachment:wd,deleteIssueCommentAttachments:Ed}=Ti.actions,jd=t=>t.issueCommentAttachmentReducer.instances,qd=o.createSelector([jd],t=>Object.values(t)),Md=t=>e=>e.issueCommentAttachmentReducer.instances[t],vp=S(o.createSelector([qd,(t,e)=>e],(t,e)=>g(t.filter(({issue_comment:s})=>e===s)))),Cd=Ti.reducer,ge=F(t=>t.uuid),kd=ge.getInitialState({}),Ii=o.createSlice({name:"issueComments",initialState:kd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,kd)),reducers:{addIssueComment:ge.addOne,addIssueComments:ge.addMany,setIssueComment:ge.setOne,setIssueComments:ge.setMany,deleteIssueComment:ge.deleteOne,deleteIssueComments:ge.deleteMany}}),{setIssueComments:zd,setIssueComment:Fi,addIssueComment:Ri,addIssueComments:wp,deleteIssueComment:Pi,deleteIssueComments:Ep}=Ii.actions,Vd=t=>t.issueCommentReducer.instances,Oi=t=>e=>e.issueCommentReducer.instances[t],jp=S(o.createSelector([Vd,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.issue===e)))),Dd=Ii.reducer,Te=F(t=>t.uuid),Ud=Te.getInitialState({}),_i=o.createSlice({name:"issues",initialState:Ud,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,Ud)}),reducers:{initializeIssues:Te.initialize,addIssue:Te.addOne,addIssues:Te.addMany,updateIssue:Te.updateOne,deleteIssue:Te.deleteOne,deleteIssues:Te.deleteMany}}),{initializeIssues:$d,addIssue:vi,addIssues:Bd,updateIssue:ht,deleteIssue:wi,deleteIssues:Gd}=_i.actions,Ld=t=>t.issueReducer.instances,Ei=t=>e=>e.issueReducer.instances[t],qp=S(o.createSelector([Ld,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n?s.push(n):console.warn("selectIssuesByIds: No issue exists with the id",a)}return g(s)})),Nd=_i.reducer,ae=F(t=>t.uuid),Hd=ae.getInitialState({}),ji=o.createSlice({name:"issueTypeAttachments",initialState:Hd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Hd)),reducers:{initializeIssueTypeAttachments:ae.initialize,addIssueTypeAttachment:ae.addOne,addIssueTypeAttachments:ae.addMany,setIssueTypeAttachment:ae.setOne,setIssueTypeAttachments:ae.setMany,updateIssueTypeAttachment:ae.updateOne,updateIssueTypeAttachments:ae.updateMany,deleteIssueTypeAttachment:ae.deleteOne,deleteIssueTypeAttachments:ae.deleteMany}}),{initializeIssueTypeAttachments:qi,addIssueTypeAttachment:Mp,addIssueTypeAttachments:Wd,setIssueTypeAttachment:Kd,setIssueTypeAttachments:Cp,updateIssueTypeAttachment:kp,updateIssueTypeAttachments:Yd,deleteIssueTypeAttachment:Jd,deleteIssueTypeAttachments:Xd}=ji.actions,Zd=t=>t.issueTypeAttachmentReducer.instances,Qd=o.createSelector([Zd],t=>Object.values(t)),xd=t=>e=>e.issueTypeAttachmentReducer.instances[t],zp=S(o.createSelector([Qd,(t,e)=>e],(t,e)=>g(t.filter(({issue_type:s})=>e===s)))),eu=ji.reducer,ne=F(t=>t.uuid),tu=ne.getInitialState({}),Mi=o.createSlice({name:"issueTypeFieldsAttachments",initialState:tu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,tu)),reducers:{initializeIssueTypeFieldsAttachments:ne.initialize,addIssueTypeFieldsAttachment:ne.addOne,addIssueTypeFieldsAttachments:ne.addMany,setIssueTypeFieldsAttachment:ne.setOne,setIssueTypeFieldsAttachments:ne.setMany,updateIssueTypeFieldsAttachment:ne.updateOne,updateIssueTypeFieldsAttachments:ne.updateMany,deleteIssueTypeFieldsAttachment:ne.deleteOne,deleteIssueTypeFieldsAttachments:ne.deleteMany}}),{initializeIssueTypeFieldsAttachments:su,addIssueTypeFieldsAttachment:Vp,addIssueTypeFieldsAttachments:iu,setIssueTypeFieldsAttachment:Dp,setIssueTypeFieldsAttachments:Up,updateIssueTypeFieldsAttachment:$p,updateIssueTypeFieldsAttachments:au,deleteIssueTypeFieldsAttachment:Bp,deleteIssueTypeFieldsAttachments:nu}=Mi.actions,cu=t=>t.issueTypeFieldsAttachmentReducer.instances,ru=o.createSelector([cu],t=>Object.values(t)),Gp=S(o.createSelector([ru,(t,e)=>e],(t,e)=>g(t.filter(s=>s.fields_revision===e)))),Lp=t=>e=>e.issueTypeFieldsAttachmentReducer.instances[t],du=Mi.reducer,ce=F(t=>t.uuid),uu=ce.getInitialState({}),Ci=o.createSlice({name:"issueTypeFieldValues",initialState:uu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,uu)),reducers:{initializeIssueTypeFieldValues:ce.initialize,addIssueTypeFieldValues:ce.addOne,addIssueTypeFieldValuesMany:ce.addMany,setIssueTypeFieldValues:ce.setOne,setIssueTypeFieldValuesMany:ce.setMany,updateIssueTypeFieldValues:ce.updateOne,updateIssueTypeFieldValuesMany:ce.updateMany,deleteIssueTypeFieldValues:ce.deleteOne,deleteIssueTypeFieldValuesMany:ce.deleteMany}}),{initializeIssueTypeFieldValues:ou,addIssueTypeFieldValues:ki,addIssueTypeFieldValuesMany:Np,setIssueTypeFieldValues:Hp,setIssueTypeFieldValuesMany:Wp,updateIssueTypeFieldValues:He,updateIssueTypeFieldValuesMany:Kp,deleteIssueTypeFieldValues:zi,deleteIssueTypeFieldValuesMany:Yp}=Ci.actions,lu=t=>t.issueTypeFieldValuesReducer.instances,Vi=o.createSelector([lu],t=>Object.values(t)),Jp=S(o.createSelector([Vi,(t,e)=>e],(t,e)=>g(t.filter(s=>s.issue===e)))),Di=t=>e=>e.issueTypeFieldValuesReducer.instances[t],hu=Ci.reducer,re=F(t=>t.uuid),mu=re.getInitialState({}),Ui=o.createSlice({name:"issueTypeFields",initialState:mu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,mu)),reducers:{initializeIssueTypeFields:re.initialize,addIssueTypeFields:re.addOne,addIssueTypeFieldsMany:re.addMany,setIssueTypeFields:re.setOne,setIssueTypeFieldsMany:re.setMany,updateIssueTypeFields:re.updateOne,updateIssueTypeFieldsMany:re.updateMany,deleteIssueTypeFields:re.deleteOne,deleteIssueTypeFieldsMany:re.deleteMany}}),{initializeIssueTypeFields:pu,addIssueTypeFields:Au,addIssueTypeFieldsMany:Xp,setIssueTypeFields:Zp,setIssueTypeFieldsMany:Qp,updateIssueTypeFields:yu,updateIssueTypeFieldsMany:xp,deleteIssueTypeFields:fu,deleteIssueTypeFieldsMany:eA}=Ui.actions,Su=t=>t.issueTypeFieldsReducer.instances,mt=o.createSelector([Su],t=>Object.values(t)),tA=S(o.createSelector([mt,(t,e)=>e],(t,e)=>g(t.filter(s=>s.issue_type===e)))),sA=S(o.createSelector([mt,(t,e)=>e],(t,e)=>t.filter(s=>s.issue_type===e).sort((s,a)=>s.submitted_at>a.submitted_at?-1:1)[0])),iA=S(o.createSelector([mt,Vi,(t,e)=>e],(t,e,s)=>{const a=new Set(t.filter(n=>n.issue_type===s).map(n=>n.uuid));return g(e.filter(n=>a.has(n.fields_revision)))})),aA=t=>e=>e.issueTypeFieldsReducer.instances[t],gu=Ui.reducer,de=F(t=>t.uuid),Tu=de.getInitialState({}),$i=o.createSlice({name:"issueTypeFieldValuesAttachments",initialState:Tu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Tu)),reducers:{initializeIssueTypeFieldValuesAttachments:de.initialize,addIssueTypeFieldValuesAttachment:de.addOne,addIssueTypeFieldValuesAttachments:de.addMany,setIssueTypeFieldValuesAttachment:de.setOne,setIssueTypeFieldValuesAttachments:de.setMany,updateIssueTypeFieldValuesAttachment:de.updateOne,updateIssueTypeFieldValuesAttachments:de.updateMany,deleteIssueTypeFieldValuesAttachment:de.deleteOne,deleteIssueTypeFieldValuesAttachments:de.deleteMany}}),{initializeIssueTypeFieldValuesAttachments:bu,addIssueTypeFieldValuesAttachment:nA,addIssueTypeFieldValuesAttachments:pt,setIssueTypeFieldValuesAttachment:cA,setIssueTypeFieldValuesAttachments:rA,updateIssueTypeFieldValuesAttachment:dA,updateIssueTypeFieldValuesAttachments:Iu,deleteIssueTypeFieldValuesAttachment:uA,deleteIssueTypeFieldValuesAttachments:At}=$i.actions,Bi=t=>t.issueTypeFieldValuesAttachmentReducer.instances,Fu=o.createSelector([Bi],t=>Object.values(t)),oA=t=>e=>e.issueTypeFieldValuesAttachmentReducer.instances[t],Ru=S(o.createSelector([Bi,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(a=>s.has(a.uuid)))})),Pu=S(o.createSelector([Fu,(t,e)=>e],(t,e)=>g(t.filter(s=>s.field_values===e)))),Ou=$i.reducer,ve=F(t=>t.uuid),_u=ve.getInitialState({}),Gi=o.createSlice({name:"issueTypes",initialState:_u,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,_u)}),reducers:{initializeIssueTypes:ve.initialize,setIssueType:ve.setOne,addIssueType:ve.addOne,updateIssueType:ve.updateOne,removeIssueType:ve.deleteOne}}),{initializeIssueTypes:vu,setIssueType:We,addIssueType:wu,updateIssueType:Eu,removeIssueType:Li}=Gi.actions,ju=t=>t.issueTypeReducer.instances,qu=o.createSelector(ju,t=>Object.values(t)),Ni=t=>e=>e.issueTypeReducer.instances[t],lA=t=>e=>{const s=[];for(const a of t){const n=e.issueTypeReducer.instances[a];n?s.push(n):console.warn("selectIssueTypesByIds: No issue type exists with the id",a)}return s},hA=S(o.createSelector([qu,(t,e)=>e],(t,e)=>g(t.filter(s=>s.organization===e)))),Hi=S(o.createSelector([t=>t.issueReducer.instances,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.issue_type===e)))),mA=t=>e=>Hi(t)(e).length,Mu=Gi.reducer,be=F(t=>t.uuid),Cu=be.getInitialState({}),Wi=o.createSlice({name:"issueUpdates",initialState:Cu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Cu)),reducers:{initializeIssueUpdates:be.setMany,setIssueUpdate:be.setOne,addIssueUpdate:be.addOne,addIssueUpdates:be.addMany,deleteIssueUpdate:be.deleteOne,deleteIssueUpdates:be.deleteMany}}),{initializeIssueUpdates:ku,setIssueUpdate:pA,addIssueUpdate:zu,addIssueUpdates:Vu,deleteIssueUpdate:Du,deleteIssueUpdates:Uu}=Wi.actions,$u=t=>t.issueUpdateReducer.instances,Bu=S(o.createSelector([$u,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.issue===e)))),Gu=Wi.reducer,C=F(t=>t.uuid),Lu=C.getInitialState({currentUser:null}),Ki=o.createSlice({name:"users",initialState:Lu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Lu)),reducers:{initializeUsers:C.initialize,setUsers:C.setMany,setUser:C.setOne,addUsers:C.addMany,addUser:C.addOne,updateUsers:C.updateMany,updateUser:C.updateOne,deleteUser:C.deleteOne,deleteUsers:C.deleteMany,removeUser:C.deleteOne,setCurrentUser:(t,e)=>{t.currentUser=e.payload}}}),{initializeUsers:AA,setUsers:Nu,setUser:yA,addUsers:fA,addUser:SA,updateUsers:gA,updateUser:TA,deleteUser:bA,deleteUsers:IA,removeUser:Hu,setCurrentUser:FA}=Ki.actions,Wu=Ki.reducer,yt=t=>t.userReducer.currentUser,ft=t=>t.userReducer.instances,RA=t=>e=>e.userReducer.instances[t],PA=S(o.createSelector([ft,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n?s.push(n):console.warn("selectUsersByIds: No user exists with the uuid",a)}return g(s)})),St=F(t=>t.uuid),Ku=St.getInitialState({}),Yi=o.createSlice({name:"organizationAccess",initialState:Ku,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ku)),reducers:{initializeOrganizationAccesses:St.initialize,updateOrganizationAccess:St.updateOne,deleteOrganizationAccess:St.deleteOne}}),{initializeOrganizationAccesses:Yu,updateOrganizationAccess:Ju,deleteOrganizationAccess:Xu}=Yi.actions,Ji=t=>t.organizationAccessReducer.instances,OA=t=>e=>e.organizationAccessReducer.instances[t],_A=o.createSelector([yt,Ji],(t,e)=>Object.values(e).find(a=>a.user===(t==null?void 0:t.uuid))??null),vA=t=>e=>Object.values(e.organizationAccessReducer.instances).find(s=>s.user===t.uuid),Zu=t=>{const e={};for(const s of Object.values(t.organizationAccessReducer.instances))e[s.user]=s;return Ce(e)},Qu=Yi.reducer,Ke=F(t=>t.uuid),xu=Ke.getInitialState({}),Xi=o.createSlice({name:"projectAccess",initialState:xu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,xu)),reducers:{initializeProjectAccesses:Ke.initialize,updateProjectAccess:Ke.updateOne,deleteProjectAccess:Ke.deleteOne,deleteProjectAccesses:Ke.deleteMany}}),{initializeProjectAccesses:Zi,updateProjectAccess:eo,deleteProjectAccess:to,deleteProjectAccesses:so}=Xi.actions,Qi=t=>t.projectAccessReducer.instances,io=o.createSelector(Qi,t=>Object.values(t)),wA=t=>e=>e.projectAccessReducer.instances[t],EA=t=>e=>Object.values(e.projectAccessReducer.instances).find(s=>s.user===t.uuid),ao=t=>{const e={};for(const s of Object.values(t.projectAccessReducer.instances))e[s.user]=s;return Ce(e)},no=Xi.reducer,ue=F(t=>t.uuid),co=ue.getInitialState({}),xi=o.createSlice({name:"projects",initialState:co,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,co)),reducers:{initializeProjects:ue.initialize,setProjects:ue.setMany,setProject:ue.setOne,addProjects:ue.addMany,addProject:ue.addOne,updateProjects:ue.updateMany,updateProject:ue.updateOne,deleteProject:ue.deleteOne,deleteProjects:ue.deleteMany,acceptProjectInvite:(t,e)=>{if(e.payload in t.instances)t.instances[e.payload].invited=!1;else throw new Error("Accept project invite: user is not in this project")}}}),{initializeProjects:jA,setProjects:ro,setProject:qA,addProjects:MA,addProject:CA,updateProjects:kA,updateProject:uo,deleteProject:oo,deleteProjects:zA,acceptProjectInvite:lo}=xi.actions,ho=xi.reducer,gt=t=>t.projectReducer.instances,VA=o.createSelector([gt],t=>g(Object.values(t))),DA=t=>e=>e.projectReducer.instances[t],mo=o.createSelector([Qi],t=>Object.values(t).map(e=>e.user)),po=o.createSelector([mo,ft],(t,e)=>t.reduce((s,a)=>({...s,[a]:e[a]}),{})),UA=o.createSelector([yt,po,ao],(t,e,s)=>g(Object.values(e).sort((a,n)=>{if(a.uuid===(t==null?void 0:t.uuid))return-1;if(n.uuid===(t==null?void 0:t.uuid))return 1;const c=s[a.uuid],r=s[n.uuid];return(c==null?void 0:c.access_level)===(r==null?void 0:r.access_level)?a.first_name.localeCompare(n.first_name):(c==null?void 0:c.access_level)===Ft.ADMIN?-1:1}))),oe=F(t=>t.uuid),Ao=oe.getInitialState({}),ea=o.createSlice({name:"organizations",initialState:Ao,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ao)),reducers:{initializeOrganizations:oe.initialize,setOrganizations:oe.setMany,setOrganization:oe.setOne,addOrganizations:oe.addMany,addOrganization:oe.addOne,updateOrganizations:oe.updateMany,updateOrganization:oe.updateOne,deleteOrganization:oe.deleteOne,deleteOrganizations:oe.deleteMany}}),{initializeOrganizations:$A,setOrganizations:yo,setOrganization:BA,addOrganizations:GA,addOrganization:LA,updateOrganizations:NA,updateOrganization:HA,deleteOrganization:WA,deleteOrganizations:KA}=ea.actions,fo=t=>t.organizationReducer.instances,So=o.createSelector([fo],t=>Object.values(t)),YA=t=>e=>e.organizationReducer.instances[t],JA=o.createSelector([So],t=>g(Object.values(t).filter(e=>e.has_access))),go=o.createSelector([Ji],t=>Object.values(t).map(e=>e.user)),XA=S(o.createSelector([gt,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.organization_owner===e)))),To=o.createSelector([go,ft],(t,e)=>Ce(t.reduce((s,a)=>({...s,[a]:e[a]}),{}))),ZA=o.createSelector([yt,To,Zu],(t,e,s)=>g(Object.values(e).sort((a,n)=>{if(a.uuid===(t==null?void 0:t.uuid))return-1;if(n.uuid===(t==null?void 0:t.uuid))return 1;const c=s[a.uuid],r=s[n.uuid];return(c==null?void 0:c.access_level)===(r==null?void 0:r.access_level)?a.first_name.localeCompare(n.first_name):(c==null?void 0:c.access_level)===Rt.ADMIN?-1:1}))),bo=ea.reducer,Io=(t,e,s)=>{const a=t.uuid?t:{...t,uuid:ye.v4()};return{payload:a,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:a,BASE_URL:e,serviceName:s}}}}},Fo={deletedRequests:[],latestRetryTime:0},ta=o.createSlice({name:"outbox",initialState:Fo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Fo)),reducers:{enqueueRequest:{reducer:(t,e)=>t,prepare:t=>{console.debug("Preparing to enqueue request",t);const{BASE_URL:e,serviceName:s,...a}=t;return Io(a,e,s)}},markForDeletion(t,e){t.deletedRequests.push(e.payload)},markAsDeleted(t,e){const s=t.deletedRequests.indexOf(e.payload);s!==-1&&t.deletedRequests.splice(s,1)},_setLatestRetryTime:(t,e)=>{t.latestRetryTime=e.payload}}}),QA=t=>t.outboxReducer.deletedRequests,xA=t=>t.outboxReducer.latestRetryTime,{enqueueRequest:Ro,markForDeletion:ey,markAsDeleted:Po,_setLatestRetryTime:Oo}=ta.actions,_o=ta.reducer,le=F(t=>t.uuid),vo=le.getInitialState({}),sa=o.createSlice({name:"projectAttachments",initialState:vo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,vo)),reducers:{initializeProjectAttachments:le.initialize,addProjectAttachment:le.addOne,addProjectAttachments:le.addMany,setProjectAttachment:le.setOne,setProjectAttachments:le.setMany,updateProjectAttachment:le.updateOne,updateProjectAttachments:le.updateMany,deleteProjectAttachment:le.deleteOne,deleteProjectAttachments:le.deleteMany}}),{initializeProjectAttachments:wo,addProjectAttachment:ty,addProjectAttachments:Eo,setProjectAttachment:jo,setProjectAttachments:qo,updateProjectAttachment:sy,updateProjectAttachments:Mo,deleteProjectAttachment:Co,deleteProjectAttachments:ia}=sa.actions,ko=t=>t.projectAttachmentReducer.instances,zo=o.createSelector([ko],t=>Object.values(t)),Vo=t=>e=>e.projectAttachmentReducer.instances[t],Do=S(o.createSelector([zo,(t,e)=>e],(t,e)=>g(t.filter(({project:s})=>e===s)))),Uo=sa.reducer,he=F(t=>t.uuid),$o=he.getInitialState({activeProjectFileId:null,isImportingProjectFile:!1}),aa=o.createSlice({name:"projectFiles",initialState:$o,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,$o)),reducers:{initializeProjectFiles:he.initialize,setProjectFile:he.setOne,setProjectFiles:he.setMany,addProjectFile:he.addOne,addProjectFiles:he.addMany,updateProjectFile:he.updateOne,updateProjectFiles:he.updateMany,deleteProjectFile:he.deleteOne,deleteProjectFiles:he.deleteMany,setIsImportingProjectFile:(t,e)=>{t.isImportingProjectFile=e.payload},saveActiveProjectFileBounds:(t,e)=>{const s=t.activeProjectFileId;if(!s)throw new Error("Tried to save bounds for active project file, but no active project file was set.");if(!t.instances[s])throw new Error(`Tried to save bounds for active project file, but project file with ID ${s}
2
- doesn't exist.`);t.instances[s].bounds=e.payload},setActiveProjectFileId:(t,e)=>{t.activeProjectFileId=e.payload},resetProjectFileObjectUrls:(t,...e)=>{for(const s in t.instances)delete t.instances[s].objectURL}}}),{initializeProjectFiles:Bo,setProjectFile:iy,setProjectFiles:ay,addProjectFile:ny,addProjectFiles:Go,updateProjectFile:na,updateProjectFiles:cy,deleteProjectFile:Lo,deleteProjectFiles:No,setIsImportingProjectFile:Ho,setActiveProjectFileId:Wo,saveActiveProjectFileBounds:Ko,resetProjectFileObjectUrls:ry}=aa.actions,Yo=t=>t.projectFileReducer.instances,Jo=o.createSelector([Yo],t=>g(Object.values(t).sort((e,s)=>e.z_index-s.z_index))),dy=t=>e=>e.projectFileReducer.instances[t],uy=t=>t.projectFileReducer.activeProjectFileId,oy=t=>t.projectFileReducer.isImportingProjectFile,Xo=aa.reducer,ly={isRehydrated:!1},ca=o.createSlice({name:"rehydrated",initialState:ly,reducers:{setRehydrated:(t,e)=>{t.isRehydrated=e.payload}}}),{setRehydrated:hy}=ca.actions,my=t=>t.rehydratedReducer.isRehydrated,Zo=ca.reducer,we=F(t=>t.uuid),Qo=we.getInitialState({}),ra=o.createSlice({name:"teams",initialState:Qo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Qo)),reducers:{setTeam:we.setOne,initializeTeams:we.initialize,addTeam:we.addOne,updateTeam:we.updateOne,deleteTeam:we.deleteOne}}),{setTeam:Ee,initializeTeams:xo,addTeam:el,updateTeam:da,deleteTeam:ua}=ra.actions,oa=t=>t.teamReducer.instances,la=o.createSelector([oa],t=>Object.values(t)),je=t=>e=>e.teamReducer.instances[t],py=S(o.createSelector([oa,(t,e)=>e],(t,e)=>{const s=[];for(const a of e){const n=t[a];n?s.push(n):console.warn("selectTeamsByIds: No team exists with the id",a)}return g(s)})),Ay=S(o.createSelector([la,(t,e)=>e],(t,e)=>g(t.filter(s=>s.organization===e)))),yy=S(o.createSelector([la,(t,e)=>e],(t,e)=>g(t.filter(s=>s.members.includes(e))))),tl=ra.reducer,fy={version:0},sl=o.createSlice({name:"versioning",initialState:fy,reducers:{}}),il=sl.reducer;let al;function Sy(t){al=t}function Ye(){return al}let nl;function gy(t){nl=t}function Ty(){return nl}const cl={};class rl{constructor(e){f(this,"client");cl[this.constructor.name]=this,this.client=e}async enqueueRequest(e){return this.client.enqueueRequest(e,this.host,this.constructor.name)}dispatch(e){this.client.store.dispatch(e)}}const dl="versioning",ul=()=>hl.length-1,ol=t=>(t[dl]={version:ul()},t),ll=()=>ol({}),by=t=>(t.outboxReducer&&(t.outboxReducer.deletedRequests=[]),t),Iy=t=>e=>{var s;return e===void 0&&(e={}),((s=e[dl])==null?void 0:s.version)===ul()?e:t(e)},hl=[ol,ll,ll,by],Fy=Object.fromEntries(hl.map((t,e)=>[e,Iy(t)])),ha="versioning",ml={[ha]:il,fileReducer:Sr,authReducer:Nc,categoryReducer:Jc,assetReducer:$n,assetAttachmentReducer:Ja,assetStageCompletionReducer:Hn,assetStageReducer:Zn,assetTypeReducer:Bc,assetTypeAttachmentReducer:uc,issueReducer:Nd,issueAttachmentReducer:Rd,issueTypeReducer:Mu,issueTypeAttachmentReducer:eu,organizationReducer:bo,outboxReducer:_o,projectReducer:ho,projectAttachmentReducer:Uo,projectAccessReducer:no,organizationAccessReducer:Qu,projectFileReducer:Xo,rehydratedReducer:Zo,formReducer:zr,formRevisionReducer:Mr,formRevisionAttachmentReducer:Pr,formSubmissionAttachmentReducer:Nr,formSubmissionReducer:Zr,userReducer:Wu,documentsReducer:mr,documentAttachmentReducer:cr,teamReducer:tl,agentsReducer:$a,issueCommentReducer:Dd,issueCommentAttachmentReducer:Cd,issueUpdateReducer:Gu,geoImageReducer:rd,issueAssociationReducer:Ad,issueTypeFieldsReducer:gu,issueTypeFieldValuesReducer:hu,issueTypeFieldsAttachmentReducer:du,issueTypeFieldValuesAttachmentReducer:Ou,assetTypeFieldsReducer:Rc,assetTypeFieldValuesReducer:Dc,assetTypeFieldsAttachmentReducer:fc,assetTypeFieldValuesAttachmentReducer:jc,assetProcedureReducer:kn,assetProcedureInstanceReducer:jn,assetProcedureFieldsReducer:ln,assetProcedureFieldValuesReducer:Pn,assetProcedureFieldsAttachmentReducer:an,assetProcedureFieldValuesAttachmentReducer:Sn},pl=o.combineReducers(ml),Al="RESET",Ry=(t,e)=>e.type==="auth/setLoggedIn"&&!e.payload?pl(void 0,e):pl(t,e);let ma=null;function Ie(){const t=Ye();if(!t)return console.warn("Client store not set; cannot get outbox coordinator yet."),null;if(ma)return ma;const e=t.getState().offline.outbox,s=Me._fromOutbox(e);return ma=s,s}const Py=t=>{if(t)throw t;const e=Ye();e?e.dispatch({type:"rehydrated/setRehydrated",payload:!0}):console.error("Client store not set")},yl=(t,e,s)=>{const a=Ie();return a?(a.addRequest(e),a.getQueue()):(console.warn("Outbox coordinator not set; cannot enqueue request yet."),[])},fl=(t,e,s)=>{const a=Ie();if(!a)return console.warn("Outbox coordinator not set; cannot dequeue request yet."),[];const c=e.meta.offlineAction.payload.uuid;return a.remove(c),a.getQueue()};async function Oy(t,e){if(!e.payload)throw new Error("Received empty payload");return ky(e)}const _y={...ga,effect:Oy,discard:Aa,returnPromises:!0,persistCallback:Py,retry:Vy,persistOptions:{storage:Pl},queue:{...ga.queue,enqueue:yl,dequeue:fl,peek:(...t)=>zy(...t)}},vy=Ol(Fy,ha),wy=o.compose(Rl.offline(_y),vy);function Ey(t){function e(s){return typeof s=="object"&&s!==null&&["ok","redirect","clientError","serverError","error"].every(n=>n in s)}if(e(t))return t;if(typeof t=="object"&&t!==null){const s=t;if(e(s.response))return s.response;if(s.response&&e(s.response.response))return s.response.response}}async function pa(t,e){const s=cl[t.meta.offline.effect.serviceName];if(!s)throw new Error(`Service ${t.meta.offline.effect.serviceName} not found`);const a=s instanceof P;if(e.store.getState().outboxReducer.deletedRequests.includes(t.payload.uuid))throw new Error("Request was marked for deletion");a&&t.payload.checkAuth!==!1&&await s.auth.prepareAuth();const c={queryParams:"",isAuthNeeded:!0},r=t.meta.offline.effect,{payload:u,headers:m,method:d,queryParams:h,attachmentHash:p,isExternalUrl:A,isAuthNeeded:y,isResponseBlob:b}={...c,...r.request},I=r.request;let T=I.url;const O=p?await e.files.fetchCache(p):void 0;if(p&&!O)throw new Error(`Cannot upload file ${p} because it's not cached.`);!A&&!T.startsWith("http")&&(!T.startsWith("/")&&!T.startsWith("blob:")&&(T="/"+T),T=t.meta.offline.effect.BASE_URL+T);const M=w=>{if(p){const me=I.s3url;if(!me)throw new Error(`No S3 URL for file ${p}`);if("warning"in me)throw new Error(`S3 URL warning for file ${p}`);if(!O)throw new Error(`No file for file ${p}`);const Ze=me.fields["x-amz-checksum-sha1"];if(!Ze)throw new Error(`No checksum for file ${p}`);return w.set("x-amz-checksum-sha1",Ze).field({...u,...me.fields}).attach("file",O)}return w.send(u)},Nf={[l.GET]:()=>b?Pe.get(T.toString()).responseType("blob"):Pe.get(T.toString()),[l.POST]:()=>{const w=Pe.post(T.toString());return M(w)},[l.PATCH]:()=>{const w=Pe.patch(T.toString());return M(w)},[l.PUT]:()=>{const w=Pe.put(T.toString());return M(w)},[l.DELETE]:()=>{const w=Pe.delete(T.toString());return M(w)}}[d];let Re=Nf();if(y&&a){const w=s.auth.getAuthHeader();Re=Re.set("Authorization",w)}m&&(Re=Re.set(m));try{return await Re.query(h)}catch(w){const me=Ey(w),Ze=me==null?void 0:me.status;if(a&&Ze===401)return await s.auth.handleUnauthorized(Re,me),Re.query(h);throw new q({response:me,innerError:w,discard:gl.includes(Ze)})}}class jy{constructor(e){f(this,"_all");f(this,"_previous");this._all=[e],this._previous=e,this.then=this.then.bind(this),this.compile=this.compile.bind(this)}then(e){return this._previous&&(this._previous.next=e),this._all.push(e),this._previous=e,{then:this.then,compile:this.compile}}compile(){return this._all}}class Sl{constructor(){f(this,"next");this.next=null}then(e){return new jy(this).then(e)}async run(e){if(this.next)return this.next.run(e);{if(console.debug("Middleware finished. Performing request:",e),!Ye())throw new Error("Client store not set");const a=Ty();if(!a)throw new Error("Client SDK not set");return pa(e,a)}}}class qy extends Sl{async run(e){return super.run(e)}}class My extends Sl{async run(e){return super.run(e)}}const Cy=new qy().then(new My).compile();function ky(t){var e;return(e=Cy[0])==null?void 0:e.run(t)}const gl=[400,409,403,404,405,500];function Aa(t,e,s=0){var d;if(console.debug("Considering discarding request due to error:",t,`(${typeof t})`,`
1
+ (function(i,j){typeof exports=="object"&&typeof module<"u"?j(exports,require("@redux-offline/redux-offline/lib/types"),require("@reduxjs/toolkit"),require("superagent"),require("uuid"),require("file-saver"),require("@redux-offline/redux-offline"),require("@redux-offline/redux-offline/lib/defaults"),require("buffer"),require("localforage"),require("redux-persist-migrate"),require("@overmap-ai/forms"),require("idb"),require("@redux-offline/redux-offline/lib/constants"),require("jwt-decode"),require("dependency-graph"),require("@tiptap/core")):typeof define=="function"&&define.amd?define(["exports","@redux-offline/redux-offline/lib/types","@reduxjs/toolkit","superagent","uuid","file-saver","@redux-offline/redux-offline","@redux-offline/redux-offline/lib/defaults","buffer","localforage","redux-persist-migrate","@overmap-ai/forms","idb","@redux-offline/redux-offline/lib/constants","jwt-decode","dependency-graph","@tiptap/core"],j):(i=typeof globalThis<"u"?globalThis:i||self,j(i["overmap-core"]={},null,i.toolkit,i.request,i.uuid,i.fileSaver,i.reduxOffline,i.offlineConfig,null,i.localforage,i.createMigration,null,i.idb,i.constants,i.jwtDecode,i.dependencyGraph))})(this,function(i,j,l,Pe,ye,Fl,Rl,Tn,Yf,Pl,Ol,Jf,_l,vl,wl,El){"use strict";var Wf=Object.defineProperty;var Kf=(i,j,l)=>j in i?Wf(i,j,{enumerable:!0,configurable:!0,writable:!0,value:l}):i[j]=l;var f=(i,j,l)=>Kf(i,typeof j!="symbol"?j+"":j,l);var Il;const bn=Object.freeze([]),In=Object.freeze({});var Ft=(t=>(t[t.GUEST=0]="GUEST",t[t.BASIC=2]="BASIC",t[t.ADMIN=4]="ADMIN",t))(Ft||{}),Rt=(t=>(t[t.GUEST=0]="GUEST",t[t.BASIC=2]="BASIC",t[t.ADMIN=4]="ADMIN",t))(Rt||{}),h=(t=>(t.GET="GET",t.POST="POST",t.PATCH="PATCH",t.PUT="PUT",t.DELETE="DELETE",t))(h||{}),Fn=(t=>(t.Issue="issue",t.Asset="asset",t.AssetType="asset_type",t.Project="project",t.Document="document",t))(Fn||{}),Pt=(t=>(t[t.LOWEST=0]="LOWEST",t[t.LOW=2]="LOW",t[t.MEDIUM=4]="MEDIUM",t[t.HIGH=6]="HIGH",t[t.HIGHEST=8]="HIGHEST",t))(Pt||{}),Ot=(t=>(t[t.BACKLOG=0]="BACKLOG",t[t.SELECTED=2]="SELECTED",t[t.DONE=4]="DONE",t))(Ot||{}),v=(t=>(t.STATUS="status",t.PRIORITY="priority",t.CATEGORY="category",t.DESCRIPTION="description",t.TITLE="title",t.ASSIGNED_TO="assigned_to",t.DUE_DATE="due_date",t))(v||{}),Rn=(t=>(t.COMPLETED="checkout.completed",t.CLOSED="checkout.closed",t))(Rn||{}),Pn=(t=>(t[t.PRO=0]="PRO",t))(Pn||{}),On=(t=>(t[t.ACTIVE=0]="ACTIVE",t[t.PAUSED=2]="PAUSED",t[t.CANCELLED=4]="CANCELLED",t[t.INACTIVE=6]="INACTIVE",t[t.PAST_DUE=8]="PAST_DUE",t))(On||{});const jl=Ot.BACKLOG,ql=Pt.MEDIUM,_n=6e4;function F(t){return{addOne:(p,A)=>{const y=t(A.payload);p.instances[y]=A.payload},addMany:(p,A)=>{for(const y of A.payload){const b=t(y);p.instances[b]=y}},setOne:(p,A)=>{const y=t(A.payload);p.instances[y]=A.payload},setMany:(p,A)=>{for(const y of A.payload){const b=t(y);p.instances[b]=y}},updateOne:(p,A)=>{const y=t(A.payload);p.instances[y]=A.payload},updateMany:(p,A)=>{for(const y of A.payload){const b=t(y);p.instances[b]=y}},deleteOne:(p,A)=>{delete p.instances[A.payload]},deleteMany:(p,A)=>{for(const y of A.payload)delete p.instances[y]},initialize:(p,A)=>{p.instances={};for(const y of A.payload){const b=t(y);p.instances[b]=y}},getInitialState:p=>({...p,instances:{}})}}function Ml(){return{initializeSelection:(m,d)=>{m.selection=Array.from(new Set(d.payload))},selectOne:(m,d)=>{new Set(m.selection).has(d.payload)||m.selection.push(d.payload)},selectMany:(m,d)=>{const o=new Set(m.selection);for(const p of d.payload)o.has(p)||o.add(p);m.selection=Array.from(o)},unselectOne:(m,d)=>{const o=new Set(m.selection);o.has(d.payload)&&(o.delete(d.payload),m.selection=Array.from(o))},unselectMany:(m,d)=>{const o=new Set(m.selection);for(const p of d.payload)o.has(p)&&o.delete(p);m.selection=Array.from(o)},toggleOne:(m,d)=>{const o=new Set(m.selection);o.has(d.payload)?o.delete(d.payload):o.add(d.payload),m.selection=Array.from(o)},toggleMany:(m,d)=>{const o=new Set(m.selection);for(const p of d.payload)o.has(p)?o.delete(p):o.add(p);m.selection=Array.from(o)},getInitialState:m=>({...m,selection:[]})}}Il=Symbol.toStringTag;class vn{constructor(){f(this,Il,"Promise");f(this,"_promise");f(this,"_resolve");f(this,"_reject");f(this,"_state","pending");this._resolve=null,this._reject=null,this._promise=new Promise((e,s)=>{this._resolve=e,this._reject=s})}get state(){return this._state}then(e,s){return this._promise.then(e,s)}catch(e){return this._promise.catch(e)}resolve(e){if(!this._resolve)throw new Error("No resolve callback");this._resolve(e),this._state="fulfilled"}reject(e){if(!this._reject)throw e;this._reject(e),this._state="rejected"}finally(e){throw new Error("`finally` not implemented")}}const Cl=t=>({type:"Point",coordinates:t}),kl=t=>({type:"MultiPoint",coordinates:t}),zl=(t,e)=>t[0]===e[0]&&t[1]===e[1];let _t=!1;["true","1"].includes("".toLowerCase())&&(_t=!0);function Vl(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;const s=Object.keys(t),n=Object.keys(e),a=s.length;if(a!==n.length)return!1;for(let c=0;c<a;c++){const r=s[c];if(!Object.prototype.hasOwnProperty.call(e,r)||t[r]!==e[r])return!1}return!0}function vt(t){const e={};return function(){const s=Array.prototype.slice.call(arguments);return s in e?(_t&&console.debug(`Memoization debug: Using memorized return value for ${t.toString()}(`,s,")"),e[s]):(_t&&console.debug(`Memoization debug: Cache miss! Memoizing ${t.toString()}(`,s,")"),e[s]=t.apply(this,s))}}function Dl(t,e){if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0}const g=t=>t.length===0?bn:t,Ce=t=>Object.keys(t).length===0?In:t,wn=vt(t=>{if(!t)return"";const e=new Date(t),s=e.getFullYear()===wt.getFullYear(),n={day:"numeric",month:"short"};return s||(n.year="numeric"),e.toLocaleDateString([],n)}),Ul=new Intl.RelativeTimeFormat([],{style:"long",numeric:"auto"}),$l=1e3*86400,wt=new Date,Bl=t=>new Date(t).toDateString()===wt.toDateString(),Gl=vt((t,e,s)=>{const n=Math.round((new Date(t).getTime()-wt.getTime())/$l);return n<e||n>s?wn(t):Ul.format(n,"days")});function Ll(t){return new Uint8Array(t).reduce((s,n)=>s+n.toString(16).padStart(2,"0"),"")}const Et=async(t,e)=>{e||(e=await Oe(t));let s=t.type;if(s.includes("/")&&(s=s.split("/")[1]),!s)throw new Error(`Could not extract file type from ${t.type}`);return`${e}.${s}`};function Oe(t){return new Promise((e,s)=>{const n=new FileReader;n.onload=()=>{const a=n.result;if(!a){s(new Error("FileReader did not return a valid ArrayBuffer."));return}crypto.subtle.digest("SHA-1",a).then(c=>{const r=Ll(c);e(r)})},n.readAsArrayBuffer(t)})}function Nl(t){if(!t.name||!t.type||!t.size){const e="File has no name, type, and/or size";throw new Error(e)}return`${t.name}&${t.type}${t.size}`}function En(t,e){return new File([t],e,{type:t.type})}function Hl(t,e){const s=document.createElement("a");s.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(e)),s.setAttribute("download",t),s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s)}const Wl=async t=>{const e={};for(const s of t){const n=await Oe(s);e[n]={sha1:n,extension:s.name.split(".").pop()||"",file_type:s.type,size:s.size}}return Object.values(e)},jn=async t=>(await fetch(t)).blob(),Kl=t=>new Promise((e,s)=>{const n=new FileReader;n.onloadend=()=>{var a;e(((a=n.result)==null?void 0:a.toString())||"")},n.readAsDataURL(t)});function Yl(t){const e=new Blob([t]);Fl.saveAs(e,t.name)}const qn={};function Jl(t,e,s,...n){const a=qn[t];let c=!1;a?a[e]||(a[e]=!0,c=!0):(qn[t]={[e]:!0},c=!0),c&&console[s](...n)}const Mn=["created_at","updated_at","index","revision"];function R(t){return{...t,uuid:ye.v4()}}function Cn(t){const e={};for(const s of t)e[s.uuid]=s;return e}function Xl(t,e=void 0,s=255){let n=t.replace(/[^a-z0-9_\-.]/gi,"_").replace(/_{2,}/g,"_");if(!e){const c=t.split(".");c.length>1&&(e=c[c.length-1])}e&&!e.startsWith(".")&&(e="."+e);const a=e?e.length:0;return n.length+a>s&&(n=n.slice(0,s-a)+(e||"")),n}function Zl(t){return t.toLowerCase().replace(" ","-")}function Ql(t,e=!1){return t.normalize("NFKD").toLowerCase().replace(/[^\w\s-]/g,"").trim().replace(/[-\s]+/g,e?"_":"-")}function xl(t,e){if(t.length<=e)return t;const s=t.slice(0,e-1);return s.slice(0,s.lastIndexOf(" "))+"…"}const S=t=>e=>s=>t(s,e);function kn(t,e,s){return s.findIndex(n=>n.uuid===t.uuid)===e}function eh(t,e,s){return s.findIndex(n=>n.file_sha1===t.file_sha1)===e}const th=/^.+@.+\..+$/;function _(t){const e={...t};for(const s of[...Mn,"created_by"])s in e&&delete e[s];return e}const ke=F(t=>t.uuid),zn=ke.getInitialState({}),jt=l.createSlice({name:"agents",initialState:zn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,zn)),reducers:{initializeConversations:ke.initialize,addConversation:ke.addOne,setConversation:ke.setOne,updateConversation:ke.updateOne}}),{initializeConversations:Vn,addConversation:Dn,setConversation:Un,updateConversation:$n}=jt.actions,qt=t=>t.agentsReducer.instances,sh=l.createSelector([qt],t=>Object.values(t)),ih=S(l.createSelector([qt,(t,e)=>e],(t,e)=>t[e])),Bn=jt.reducer,k=F(t=>t.uuid),Gn=k.getInitialState({}),Mt=l.createSlice({name:"assetAttachments",initialState:Gn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Gn)),reducers:{initializeAssetAttachments:k.initialize,addAssetAttachment:k.addOne,addAssetAttachments:k.addMany,setAssetAttachment:k.setOne,setAssetAttachments:k.setMany,updateAssetAttachment:k.updateOne,updateAssetAttachments:k.updateMany,deleteAssetAttachment:k.deleteOne,deleteAssetAttachments:k.deleteMany}}),{initializeAssetAttachments:Ct,addAssetAttachment:nh,addAssetAttachments:kt,setAssetAttachment:Ln,setAssetAttachments:ah,updateAssetAttachment:ch,updateAssetAttachments:Nn,deleteAssetAttachment:Hn,deleteAssetAttachments:zt}=Mt.actions,Wn=t=>t.assetAttachmentReducer.instances,Kn=l.createSelector([Wn],t=>Object.values(t)),Yn=t=>e=>e.assetAttachmentReducer.instances[t],Jn=S(l.createSelector([Kn,(t,e)=>e],(t,e)=>g(t.filter(({asset:s})=>e===s)))),Xn=Mt.reducer,z=F(t=>t.uuid),Zn=z.getInitialState({}),Vt=l.createSlice({name:"assetProcedureFieldsAttachments",initialState:Zn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Zn)),reducers:{initializeAssetProcedureFieldsAttachments:z.initialize,addAssetProcedureFieldsAttachment:z.addOne,addAssetProcedureFieldsAttachments:z.addMany,setAssetProcedureFieldsAttachment:z.setOne,setAssetProcedureFieldsAttachments:z.setMany,updateAssetProcedureFieldsAttachment:z.updateOne,updateAssetProcedureFieldsAttachments:z.updateMany,deleteAssetProcedureFieldsAttachment:z.deleteOne,deleteAssetProcedureFieldsAttachments:z.deleteMany}}),{initializeAssetProcedureFieldsAttachments:Qn,addAssetProcedureFieldsAttachment:rh,addAssetProcedureFieldsAttachments:xn,setAssetProcedureFieldsAttachment:dh,setAssetProcedureFieldsAttachments:uh,updateAssetProcedureFieldsAttachment:oh,updateAssetProcedureFieldsAttachments:ea,deleteAssetProcedureFieldsAttachment:lh,deleteAssetProcedureFieldsAttachments:ta}=Vt.actions,sa=t=>t.assetProcedureFieldsAttachmentReducer.instances,ia=l.createSelector([sa],t=>Object.values(t)),hh=S(l.createSelector([ia,(t,e)=>e],(t,e)=>g(t.filter(s=>s.fields_revision===e)))),mh=t=>e=>e.assetProcedureFieldsAttachmentReducer.instances[t],na=Vt.reducer,V=F(t=>t.uuid),aa=V.getInitialState({}),Dt=l.createSlice({name:"assetProcedureFields",initialState:aa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,aa)),reducers:{initializeAssetProcedureFields:V.initialize,addAssetProcedureFields:V.addOne,addAssetProcedureFieldsMany:V.addMany,setAssetProcedureFields:V.setOne,setAssetProcedureFieldsMany:V.setMany,updateAssetProcedureFields:V.updateOne,updateAssetProcedureFieldsMany:V.updateMany,deleteAssetProcedureFields:V.deleteOne,deleteAssetProcedureFieldsMany:V.deleteMany}}),{initializeAssetProcedureFields:ca,addAssetProcedureFields:ra,addAssetProcedureFieldsMany:ph,setAssetProcedureFields:Ah,setAssetProcedureFieldsMany:yh,updateAssetProcedureFields:da,updateAssetProcedureFieldsMany:fh,deleteAssetProcedureFields:ua,deleteAssetProcedureFieldsMany:Sh}=Dt.actions,oa=t=>t.assetProcedureFieldsReducer.instances,Ut=l.createSelector([oa],t=>Object.values(t)),gh=S(l.createSelector([Ut,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_procedure===e)))),Th=S(l.createSelector([Ut,(t,e)=>e],(t,e)=>t.filter(s=>s.asset_procedure===e).sort((s,n)=>s.submitted_at>n.submitted_at?-1:1)[0])),bh=t=>e=>e.assetProcedureFieldsReducer.instances[t],la=Dt.reducer,D=F(t=>t.uuid),ha=D.getInitialState({}),$t=l.createSlice({name:"assetProcedureFieldValuesAttachments",initialState:ha,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ha)),reducers:{initializeAssetProcedureFieldValuesAttachments:D.initialize,addAssetProcedureFieldValuesAttachment:D.addOne,addAssetProcedureFieldValuesAttachments:D.addMany,setAssetProcedureFieldValuesAttachment:D.setOne,setAssetProcedureFieldValuesAttachments:D.setMany,updateAssetProcedureFieldValuesAttachment:D.updateOne,updateAssetProcedureFieldValuesAttachments:D.updateMany,deleteAssetProcedureFieldValuesAttachment:D.deleteOne,deleteAssetProcedureFieldValuesAttachments:D.deleteMany}}),{initializeAssetProcedureFieldValuesAttachments:ma,addAssetProcedureFieldValuesAttachment:Ih,addAssetProcedureFieldValuesAttachments:Qe,setAssetProcedureFieldValuesAttachment:Fh,setAssetProcedureFieldValuesAttachments:Rh,updateAssetProcedureFieldValuesAttachment:Ph,updateAssetProcedureFieldValuesAttachments:pa,deleteAssetProcedureFieldValuesAttachment:Oh,deleteAssetProcedureFieldValuesAttachments:xe}=$t.actions,Bt=t=>t.assetProcedureFieldValuesAttachmentReducer.instances,Aa=l.createSelector([Bt],t=>Object.values(t)),_h=t=>e=>e.assetProcedureFieldValuesAttachmentReducer.instances[t],ya=S(l.createSelector([Bt,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(n=>s.has(n.uuid)))})),fa=S(l.createSelector([Aa,(t,e)=>e],(t,e)=>g(t.filter(s=>s.field_values===e)))),Sa=$t.reducer,U=F(t=>t.uuid),ga=U.getInitialState({}),Gt=l.createSlice({name:"assetProcedureFieldValues",initialState:ga,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ga)),reducers:{initializeAssetProcedureFieldValues:U.initialize,addAssetProcedureFieldValues:U.addOne,addAssetProcedureFieldValuesMany:U.addMany,setAssetProcedureFieldValues:U.setOne,setAssetProcedureFieldValuesMany:U.setMany,updateAssetProcedureFieldValues:U.updateOne,updateAssetProcedureFieldValuesMany:U.updateMany,deleteAssetProcedureFieldValues:U.deleteOne,deleteAssetProcedureFieldValuesMany:U.deleteMany}}),{initializeAssetProcedureFieldValues:Ta,addAssetProcedureFieldValues:Lt,addAssetProcedureFieldValuesMany:ba,setAssetProcedureFieldValues:vh,setAssetProcedureFieldValuesMany:wh,updateAssetProcedureFieldValues:ze,updateAssetProcedureFieldValuesMany:Ia,deleteAssetProcedureFieldValues:Nt,deleteAssetProcedureFieldValuesMany:Fa}=Gt.actions,Ra=t=>t.assetProcedureFieldValuesReducer.instances,Ht=l.createSelector([Ra],t=>Object.values(t)),Eh=S(l.createSelector([Ht,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset===e)))),jh=S(l.createSelector([Ht,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_procedure_instance===e)))),Wt=t=>e=>e.assetProcedureFieldValuesReducer.instances[t],Pa=Gt.reducer,$=F(t=>t.uuid),Oa=$.getInitialState({}),Kt=l.createSlice({name:"assetProcedureInstances",initialState:Oa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Oa)),reducers:{initializeAssetProcedureInstances:$.initialize,addAssetProcedureInstance:$.addOne,addAssetProcedureInstances:$.addMany,setAssetProcedureInstance:$.setOne,setAssetProcedureInstances:$.setMany,updateAssetProcedureInstance:$.updateOne,updateAssetProcedureInstances:$.updateMany,deleteAssetProcedureInstance:$.deleteOne,deleteAssetProcedureInstances:$.deleteMany}}),{initializeAssetProcedureInstances:_a,addAssetProcedureInstance:Yt,addAssetProcedureInstances:va,updateAssetProcedureInstance:Ve,updateAssetProcedureInstances:qh,deleteAssetProcedureInstance:Jt,deleteAssetProcedureInstances:wa,setAssetProcedureInstance:Mh,setAssetProcedureInstances:Ch}=Kt.actions,Xt=t=>t.assetProcedureInstanceReducer.instances,Zt=l.createSelector([Xt],t=>Object.values(t)),Ea=S(l.createSelector([Zt,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_procedure===e)))),kh=S(l.createSelector([Zt,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_type===e)))),Qt=t=>e=>e.assetProcedureInstanceReducer.instances[t],zh=S(l.createSelector([Xt,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a&&s.push(a)}return g(s)})),ja=Kt.reducer,B=F(t=>t.uuid),qa=B.getInitialState({}),xt=l.createSlice({name:"assetProcedures",initialState:qa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,qa)),reducers:{initializeAssetProcedures:B.initialize,addAssetProcedure:B.addOne,addAssetProcedures:B.addMany,setAssetProcedure:B.setOne,setAssetProcedures:B.setMany,updateAssetProcedure:B.updateOne,updateAssetProcedures:B.updateMany,deleteAssetProcedure:B.deleteOne,deleteAssetProcedures:B.deleteMany}}),{initializeAssetProcedures:Ma,addAssetProcedure:es,addAssetProcedures:Vh,updateAssetProcedure:De,updateAssetProcedures:Dh,deleteAssetProcedure:ts,deleteAssetProcedures:Uh,setAssetProcedure:$h,setAssetProcedures:Bh}=xt.actions,ss=t=>t.assetProcedureReducer.instances,Ca=l.createSelector([ss],t=>Object.values(t)),Gh=S(l.createSelector([Ca,(t,e)=>e],(t,e)=>g(t.filter(s=>s.organization===e)))),is=t=>e=>e.assetProcedureReducer.instances[t],Lh=S(l.createSelector([ss,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a&&s.push(a)}return g(s)})),ka=xt.reducer,G=F(t=>t.uuid),za=G.getInitialState({}),ns=l.createSlice({name:"assets",initialState:za,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,za)),reducers:{initializeAssets:G.initialize,addAsset:G.addOne,addAssets:G.addMany,setAsset:G.setOne,setAssets:G.setMany,updateAsset:G.updateOne,updateAssets:G.updateMany,deleteAsset:G.deleteOne,deleteAssets:G.deleteMany}}),{initializeAssets:Va,addAsset:as,addAssets:cs,updateAsset:Ue,updateAssets:Nh,deleteAsset:rs,deleteAssets:Da,setAsset:Hh,setAssets:Wh}=ns.actions,ds=t=>t.assetReducer.instances,Ua=l.createSelector([ds],t=>g(Object.values(t))),us=S(l.createSelector([Ua,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_type===e)))),os=t=>e=>e.assetReducer.instances[t],Kh=S(l.createSelector([ds,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a&&s.push(a)}return g(s)})),Yh=t=>e=>us(t)(e).length,$a=ns.reducer,pe=F(t=>t.uuid),Ba=pe.getInitialState({}),ls=l.createSlice({name:"assetStageCompletions",initialState:Ba,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ba)),reducers:{initializeAssetStageCompletions:pe.initialize,addAssetStageCompletion:pe.addOne,addAssetStageCompletions:pe.addMany,updateAssetStageCompletion:pe.updateOne,updateAssetStageCompletions:pe.updateMany,deleteAssetStageCompletion:pe.deleteOne,deleteAssetStageCompletions:pe.deleteMany}}),{initializeAssetStageCompletions:Ga,addAssetStageCompletion:hs,addAssetStageCompletions:ms,updateAssetStageCompletion:La,updateAssetStageCompletions:Na,deleteAssetStageCompletion:ps,deleteAssetStageCompletions:As}=ls.actions,Ha=ls.reducer,ys=t=>t.assetStageCompletionReducer.instances,Jh=l.createSelector([ys],t=>Object.values(t)),Wa=t=>e=>e.assetStageCompletionReducer.instances[t],Ka=S(l.createSelector([ys,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(n=>s.has(n.uuid)))})),L=F(t=>t.uuid),Ya=L.getInitialState({}),fs=l.createSlice({name:"assetStages",initialState:Ya,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ya)),reducers:{initializeAssetStages:L.initialize,setAssetStage:L.setOne,setAssetStages:L.setMany,addAssetStage:L.addOne,addAssetStages:L.addMany,updateAssetStage:L.updateOne,updateAssetStages:L.updateMany,deleteAssetStage:L.deleteOne,deleteAssetStages:L.deleteMany}}),{initializeAssetStages:Ja,setAssetStage:Xa,setAssetStages:Xh,addAssetStage:Zh,addAssetStages:Ss,updateAssetStage:gs,updateAssetStages:et,deleteAssetStage:Qh,deleteAssetStages:Ts}=fs.actions,Za=fs.reducer,tt=t=>t.assetStageReducer.instances,Qa=t=>e=>e.assetStageReducer.instances[t],xa=l.createSelector([tt],t=>Object.values(t)),xh=S(l.createSelector([tt,(t,e)=>e],(t,e)=>{const s={};for(const[n,a]of Object.entries(t))a.asset_procedure===e&&(s[n]=a);return Ce(s)})),em=S(l.createSelector([xa,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_procedure===e)))),bs=S(l.createSelector([tt,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a?s.push(a):console.warn("selectStagesFromStageIds: No stage exists with the id",n)}return g(s)})),N=F(t=>t.uuid),ec=N.getInitialState({}),Is=l.createSlice({name:"assetTypeAttachments",initialState:ec,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ec)),reducers:{initializeAssetTypeAttachments:N.initialize,addAssetTypeAttachment:N.addOne,addAssetTypeAttachments:N.addMany,setAssetTypeAttachment:N.setOne,setAssetTypeAttachments:N.setMany,updateAssetTypeAttachment:N.updateOne,updateAssetTypeAttachments:N.updateMany,deleteAssetTypeAttachment:N.deleteOne,deleteAssetTypeAttachments:N.deleteMany}}),{initializeAssetTypeAttachments:tc,addAssetTypeAttachment:tm,addAssetTypeAttachments:Fs,setAssetTypeAttachment:sc,setAssetTypeAttachments:sm,updateAssetTypeAttachment:im,updateAssetTypeAttachments:ic,deleteAssetTypeAttachment:nc,deleteAssetTypeAttachments:Rs}=Is.actions,ac=t=>t.assetTypeAttachmentReducer.instances,cc=l.createSelector([ac],t=>Object.values(t)),rc=t=>e=>e.assetTypeAttachmentReducer.instances[t],dc=S(l.createSelector([cc,(t,e)=>e],(t,e)=>g(t.filter(({asset_type:s})=>e===s)))),uc=Is.reducer,H=F(t=>t.uuid),oc=H.getInitialState({}),Ps=l.createSlice({name:"assetTypeFieldsAttachments",initialState:oc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,oc)),reducers:{initializeAssetTypeFieldsAttachments:H.initialize,addAssetTypeFieldsAttachment:H.addOne,addAssetTypeFieldsAttachments:H.addMany,setAssetTypeFieldsAttachment:H.setOne,setAssetTypeFieldsAttachments:H.setMany,updateAssetTypeFieldsAttachment:H.updateOne,updateAssetTypeFieldsAttachments:H.updateMany,deleteAssetTypeFieldsAttachment:H.deleteOne,deleteAssetTypeFieldsAttachments:H.deleteMany}}),{initializeAssetTypeFieldsAttachments:lc,addAssetTypeFieldsAttachment:nm,addAssetTypeFieldsAttachments:hc,setAssetTypeFieldsAttachment:am,setAssetTypeFieldsAttachments:cm,updateAssetTypeFieldsAttachment:rm,updateAssetTypeFieldsAttachments:mc,deleteAssetTypeFieldsAttachment:dm,deleteAssetTypeFieldsAttachments:pc}=Ps.actions,Ac=t=>t.assetTypeFieldsAttachmentReducer.instances,yc=l.createSelector([Ac],t=>Object.values(t)),um=S(l.createSelector([yc,(t,e)=>e],(t,e)=>g(t.filter(s=>s.fields_revision===e)))),om=t=>e=>e.assetTypeFieldsAttachmentReducer.instances[t],fc=Ps.reducer,W=F(t=>t.uuid),Sc=W.getInitialState({}),Os=l.createSlice({name:"assetTypeFields",initialState:Sc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Sc)),reducers:{initializeAssetTypeFields:W.initialize,addAssetTypeFields:W.addOne,addAssetTypeFieldsMany:W.addMany,setAssetTypeFields:W.setOne,setAssetTypeFieldsMany:W.setMany,updateAssetTypeFields:W.updateOne,updateAssetTypeFieldsMany:W.updateMany,deleteAssetTypeFields:W.deleteOne,deleteAssetTypeFieldsMany:W.deleteMany}}),{initializeAssetTypeFields:gc,addAssetTypeFields:Tc,addAssetTypeFieldsMany:lm,setAssetTypeFields:hm,setAssetTypeFieldsMany:mm,updateAssetTypeFields:bc,updateAssetTypeFieldsMany:pm,deleteAssetTypeFields:Ic,deleteAssetTypeFieldsMany:Am}=Os.actions,Fc=t=>t.assetTypeFieldsReducer.instances,st=l.createSelector([Fc],t=>Object.values(t)),ym=S(l.createSelector([st,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset_type===e)))),fm=S(l.createSelector([st,(t,e)=>e],(t,e)=>t.filter(s=>s.asset_type===e).sort((s,n)=>s.submitted_at>n.submitted_at?-1:1)[0])),Sm=t=>e=>e.assetTypeFieldsReducer.instances[t],Rc=Os.reducer,K=F(t=>t.uuid),Pc=K.getInitialState({}),_s=l.createSlice({name:"assetTypeFieldValuesAttachments",initialState:Pc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Pc)),reducers:{initializeAssetTypeFieldValuesAttachments:K.initialize,addAssetTypeFieldValuesAttachment:K.addOne,addAssetTypeFieldValuesAttachments:K.addMany,setAssetTypeFieldValuesAttachment:K.setOne,setAssetTypeFieldValuesAttachments:K.setMany,updateAssetTypeFieldValuesAttachment:K.updateOne,updateAssetTypeFieldValuesAttachments:K.updateMany,deleteAssetTypeFieldValuesAttachment:K.deleteOne,deleteAssetTypeFieldValuesAttachments:K.deleteMany}}),{initializeAssetTypeFieldValuesAttachments:Oc,addAssetTypeFieldValuesAttachment:gm,addAssetTypeFieldValuesAttachments:it,setAssetTypeFieldValuesAttachment:Tm,setAssetTypeFieldValuesAttachments:bm,updateAssetTypeFieldValuesAttachment:Im,updateAssetTypeFieldValuesAttachments:_c,deleteAssetTypeFieldValuesAttachment:Fm,deleteAssetTypeFieldValuesAttachments:nt}=_s.actions,vs=t=>t.assetTypeFieldValuesAttachmentReducer.instances,vc=l.createSelector([vs],t=>Object.values(t)),Rm=t=>e=>e.assetTypeFieldValuesAttachmentReducer.instances[t],wc=S(l.createSelector([vs,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(n=>s.has(n.uuid)))})),Ec=S(l.createSelector([vc,(t,e)=>e],(t,e)=>g(t.filter(s=>s.field_values===e)))),jc=_s.reducer,Y=F(t=>t.uuid),qc=Y.getInitialState({}),ws=l.createSlice({name:"assetTypeFieldValues",initialState:qc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,qc)),reducers:{initializeAssetTypeFieldValues:Y.initialize,addAssetTypeFieldValues:Y.addOne,addAssetTypeFieldValuesMany:Y.addMany,setAssetTypeFieldValues:Y.setOne,setAssetTypeFieldValuesMany:Y.setMany,updateAssetTypeFieldValues:Y.updateOne,updateAssetTypeFieldValuesMany:Y.updateMany,deleteAssetTypeFieldValues:Y.deleteOne,deleteAssetTypeFieldValuesMany:Y.deleteMany}}),{initializeAssetTypeFieldValues:Mc,addAssetTypeFieldValues:Es,addAssetTypeFieldValuesMany:Cc,setAssetTypeFieldValues:Pm,setAssetTypeFieldValuesMany:Om,updateAssetTypeFieldValues:$e,updateAssetTypeFieldValuesMany:kc,deleteAssetTypeFieldValues:js,deleteAssetTypeFieldValuesMany:zc}=ws.actions,Vc=t=>t.assetTypeFieldValuesReducer.instances,qs=l.createSelector([Vc],t=>Object.values(t)),_m=S(l.createSelector([qs,(t,e)=>e],(t,e)=>g(t.filter(s=>s.asset===e)))),vm=S(l.createSelector([st,qs,(t,e)=>e],(t,e,s)=>{const n=new Set(t.filter(a=>a.asset_type===s).map(a=>a.uuid));return g(e.filter(a=>n.has(a.fields_revision)))})),Ms=t=>e=>e.assetTypeFieldValuesReducer.instances[t],Dc=ws.reducer,J=F(t=>t.uuid),Uc=J.getInitialState({}),Cs=l.createSlice({name:"assetTypes",initialState:Uc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Uc)),reducers:{initializeAssetTypes:J.initialize,setAssetType:J.setOne,setAssetTypes:J.setMany,addAssetType:J.addOne,addAssetTypes:J.addMany,updateAssetType:J.updateOne,updateAssetTypes:J.updateMany,deleteAssetType:J.deleteOne,deleteAssetTypes:J.deleteMany}}),{initializeAssetTypes:$c,setAssetType:wm,setAssetTypes:Em,addAssetType:ks,addAssetTypes:jm,updateAssetType:Be,updateAssetTypes:qm,deleteAssetType:zs,deleteAssetTypes:Mm}=Cs.actions,Vs=t=>t.assetTypeReducer.instances,Cm=l.createSelector([Vs],t=>Object.values(t)),Ds=t=>e=>e.assetTypeReducer.instances[t],km=S(l.createSelector([Vs,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a?s.push(a):console.warn("selectAssetTypesByIds: No assetType exists with the id",n)}return g(s)})),Bc=Cs.reducer,Gc={accessToken:"",refreshToken:"",isLoggedIn:!1},at=l.createSlice({name:"auth",initialState:Gc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Gc)),reducers:{setTokens:(t,e)=>{t.accessToken=e.payload.accessToken,t.refreshToken=e.payload.refreshToken},clearTokens:t=>{t.accessToken="",t.refreshToken=""},setLoggedIn:(t,e)=>{e.payload||at.caseReducers.clearTokens(t),t.isLoggedIn=e.payload}}}),{setTokens:zm,clearTokens:Vm,setLoggedIn:Lc}=at.actions,Dm=t=>t.authReducer.accessToken,Um=t=>t.authReducer.isLoggedIn,Nc=at.reducer,Ge=F(t=>t.uuid),Hc=Ge.getInitialState({}),Us=l.createSlice({name:"categories",initialState:Hc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Hc)),reducers:{initializeCategories:Ge.initialize,addCategory:Ge.addOne,updateCategory:Ge.updateOne,deleteCategory:Ge.deleteOne}}),{initializeCategories:Wc,addCategory:$s,updateCategory:Kc,deleteCategory:Yc}=Us.actions,Bs=t=>t.categoryReducer.instances,$m=l.createSelector([Bs],t=>Object.values(t)),Gs=t=>e=>e.categoryReducer.instances[t],Bm=S(l.createSelector([Bs,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a?s.push(a):console.warn("selectCategoryByIds: No category exists with the id",n)}return g(s)})),Gm=t=>e=>Object.values(e.issueReducer.instances).filter(s=>s.category===t).length,Jc=Us.reducer,X=F(t=>t.uuid),Xc=X.getInitialState({}),Ls=l.createSlice({name:"documentAttachments",initialState:Xc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Xc)),reducers:{initializeDocumentAttachments:X.initialize,addDocumentAttachment:X.addOne,addDocumentAttachments:X.addMany,setDocumentAttachment:X.setOne,setDocumentAttachments:X.setMany,updateDocumentAttachment:X.updateOne,updateDocumentAttachments:X.updateMany,deleteDocumentAttachment:X.deleteOne,deleteDocumentAttachments:X.deleteMany}}),{initializeDocumentAttachments:Zc,addDocumentAttachment:Lm,addDocumentAttachments:Qc,setDocumentAttachment:xc,setDocumentAttachments:Nm,updateDocumentAttachment:Hm,updateDocumentAttachments:er,deleteDocumentAttachment:tr,deleteDocumentAttachments:sr}=Ls.actions,ir=t=>t.documentAttachmentReducer.instances,nr=l.createSelector([ir],t=>Object.values(t)),ar=t=>e=>e.documentAttachmentReducer.instances[t],Wm=S(l.createSelector([nr,(t,e)=>e],(t,e)=>g(t.filter(({document:s})=>e===s)))),cr=Ls.reducer,rr={documents:{}},Ns=l.createSlice({name:"documents",initialState:rr,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,rr)}),reducers:{setDocuments:(t,e)=>{if(e.payload.filter(kn).length!==e.payload.length)throw new Error("Tried to use setIssues reducer with duplicate ID's");t.documents=Cn(e.payload)},addDocuments:(t,e)=>{for(const s of e.payload)if(s.uuid in t.documents)throw new Error(`attempting to add a document with uuid ${s.uuid} which already exists in state.documents.`);for(const s of e.payload){if(s.parent_document&&t.documents[s.parent_document]){const n=t.documents[s.parent_document];t.documents[s.parent_document]={...n,children_documents:[...n.children_documents,s.uuid]}}t.documents[s.uuid]=s}},updateDocuments:(t,e)=>{for(const s of e.payload)if(!(s.uuid in t.documents))throw new Error(`attempting to update a document with uuid ${s.uuid} which doesn't exists in state.documents.`);for(const s of e.payload){const n=t.documents[s.uuid];if(s.organization!==void 0&&s.organization!==n.organization)throw new Error("organization cannot be updated");if(s.project!==void 0&&s.project!==n.project)throw new Error("project cannot be updated");t.documents[s.uuid]={...n,...s}}},moveDocument:(t,e)=>{const{documentId:s,targetDocumentId:n,position:a}=e.payload;if(!(s in t.documents))throw new Error(`attempting to move a document with uuid ${s} which doesn't exist in state.documents`);const c=t.documents[s];if(c.parent_document&&t.documents[c.parent_document]){const{children_documents:r}=t.documents[c.parent_document];t.documents[c.parent_document].children_documents.splice(r.indexOf(c.uuid),1)}if(n){const r=t.documents[n],u=r!=null&&r.parent_document?t.documents[r.parent_document]:null;switch(a){case"left":if(!u)throw new Error("attempting to move a document to the left of a document with no parent_document");t.documents[r.parent_document].children_documents.splice(u.children_documents.indexOf(r.uuid),0,c.uuid),t.documents[s].parent_document=u.uuid;break;case"right":if(!u)throw new Error("attempting to move a document to the left of a document with no parent_document");t.documents[r.parent_document].children_documents.splice(u.children_documents.indexOf(r.uuid)+1,0,c.uuid),t.documents[s].parent_document=u.uuid;break;case"left-child":if(!r)throw new Error("attempting to move a document to the left-child of a document that doesn't exist");t.documents[n].children_documents.unshift(c.uuid),t.documents[s].parent_document=r.uuid;break;case"right-child":if(!r)throw new Error("attempting to move a document to the left-child of a document that doesn't exist");t.documents[n].children_documents.push(c.uuid),t.documents[s].parent_document=r.uuid}}else t.documents[s].parent_document=null},removeDocuments:(t,e)=>{for(const s of e.payload)if(!(s in t.documents))throw new Error(`attempting to delete a document with uuid ${s} which doesn't exists in state.documents.`);for(const s of e.payload){const n=t.documents[s];if(n.parent_document&&t.documents[n.parent_document]){const a=t.documents[n.parent_document];t.documents[n.parent_document]={...a,children_documents:a.children_documents.filter(c=>c!==n.uuid)}}delete t.documents[s]}}}}),{setDocuments:dr,addDocuments:ur,updateDocuments:Ae,moveDocument:or,removeDocuments:Hs}=Ns.actions,_e=t=>t.documentsReducer.documents,lr=l.createSelector([_e],t=>Object.values(t)),hr=t=>e=>e.documentsReducer.documents[t],Km=S(l.createSelector([_e,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a?s.push(a):console.warn("selectDocumentByIds: No document exists with the id",n)}return g(s)})),Ym=S(l.createSelector([_e,(t,e)=>e],(t,e)=>{const s=[],n=t[e];if(!n||!n.parent_document)return s;let a=t[n.parent_document];for(;a;)s.push(a.uuid),a=t[a.parent_document??""];return g(s)})),Jm=l.createSelector([lr],t=>g(t.filter(e=>!e.parent_document))),mr=Ns.reducer,pr={s3Urls:{}},Ar=1e3*60*60,Xm=Ar*24*7,Ws=l.createSlice({name:"file",initialState:pr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,pr)),reducers:{setUploadUrl:(t,e)=>{const{url:s,fields:n,sha1:a}=e.payload,c=new Date,r=new Date(c.getTime()+Xm);t.s3Urls[a]={url:s,fields:n,exp:r.getTime()}}}}),{setUploadUrl:yr}=Ws.actions,fr=t=>e=>{const s=e.fileReducer.s3Urls[t];if(!s)return;const n=new Date().getTime();if(!((s.exp??n)-n<Ar))return s},Sr=Ws.reducer,Z=F(t=>t.uuid),gr=Z.getInitialState({}),Ks=l.createSlice({name:"formRevisionAttachments",initialState:gr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,gr)),reducers:{initializeFormRevisionAttachments:Z.initialize,addFormRevisionAttachment:Z.addOne,addFormRevisionAttachments:Z.addMany,setFormRevisionAttachment:Z.setOne,setFormRevisionAttachments:Z.setMany,updateFormRevisionAttachment:Z.updateOne,updateFormRevisionAttachments:Z.updateMany,deleteFormRevisionAttachment:Z.deleteOne,deleteFormRevisionAttachments:Z.deleteMany}}),{initializeFormRevisionAttachments:Tr,addFormRevisionAttachment:Zm,addFormRevisionAttachments:br,setFormRevisionAttachment:Qm,setFormRevisionAttachments:xm,updateFormRevisionAttachment:ep,updateFormRevisionAttachments:Ir,deleteFormRevisionAttachment:tp,deleteFormRevisionAttachments:Fr}=Ks.actions,Rr=t=>t.formRevisionAttachmentReducer.instances,sp=S(l.createSelector([Rr,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.form_revision===e)))),Pr=Ks.reducer,ip=(t,e)=>{const s=t.revision,n=e.revision;return s===void 0&&n===void 0?t.submitted_at<e.submitted_at?-1:1:s===void 0?1:n===void 0||s<n?-1:1},fe=F(t=>t.uuid),Or=fe.getInitialState({}),Ys=l.createSlice({name:"formRevisions",initialState:Or,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Or)),reducers:{initializeFormRevisions:fe.initialize,setFormRevision:fe.setOne,addFormRevision:fe.addOne,addFormRevisions:fe.addMany,deleteFormRevision:fe.deleteOne,deleteFormRevisions:fe.deleteMany}}),{setFormRevision:_r,initializeFormRevisions:vr,addFormRevision:Js,addFormRevisions:wr,deleteFormRevision:Xs,deleteFormRevisions:Er}=Ys.actions,ct=t=>t.formRevisionReducer.instances,jr=l.createSelector([ct],t=>Object.values(t)),np=t=>e=>e.formRevisionReducer.instances[t],ap=S(l.createSelector([ct,(t,e)=>e],(t,e)=>{const s=Object.values(t).filter(c=>c.form===e);if(s.length===0)return;const a=s.sort(ip)[s.length-1];return t[a.uuid]})),qr=S(l.createSelector([jr,(t,e)=>e],(t,e)=>g(t.filter(s=>s.form===e)))),Mr=Ys.reducer,Se=F(t=>t.uuid),Cr=Se.getInitialState({}),Zs=l.createSlice({name:"forms",initialState:Cr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Cr)),reducers:{initializeForms:Se.initialize,setForm:Se.setOne,addForm:Se.addOne,addForms:Se.addMany,updateForm:Se.updateOne,deleteForm:Se.deleteOne}}),{initializeForms:kr,setForm:cp,addForm:Qs,addForms:rp,updateForm:dp,deleteForm:xs}=Zs.actions,zr=Zs.reducer,Vr=t=>t.formReducer.instances,up=l.createSelector([Vr],t=>Object.values(t)),Dr=t=>e=>e.formReducer.instances[t],Q=F(t=>t.uuid),Ur=Q.getInitialState({}),ei=l.createSlice({name:"formSubmissionAttachments",initialState:Ur,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ur)),reducers:{initializeFormSubmissionAttachments:Q.initialize,addFormSubmissionAttachment:Q.addOne,addFormSubmissionAttachments:Q.addMany,setFormSubmissionAttachment:Q.setOne,setFormSubmissionAttachments:Q.setMany,updateFormSubmissionAttachment:Q.updateOne,updateFormSubmissionAttachments:Q.updateMany,deleteFormSubmissionAttachment:Q.deleteOne,deleteFormSubmissionAttachments:Q.deleteMany}}),{initializeFormSubmissionAttachments:$r,addFormSubmissionAttachment:op,addFormSubmissionAttachments:rt,setFormSubmissionAttachment:lp,setFormSubmissionAttachments:hp,updateFormSubmissionAttachment:mp,updateFormSubmissionAttachments:Br,deleteFormSubmissionAttachment:pp,deleteFormSubmissionAttachments:dt}=ei.actions,ti=t=>t.formSubmissionAttachmentReducer.instances,Gr=S(l.createSelector([ti,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(n=>s.has(n.uuid)))})),Lr=S(l.createSelector([ti,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.form_submission===e)))),Nr=ei.reducer,x=F(t=>t.uuid),Hr=x.getInitialState({}),si=l.createSlice({name:"formSubmissions",initialState:Hr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Hr)),reducers:{initializeFormSubmissions:x.initialize,setFormSubmission:x.setOne,setFormSubmissions:x.setMany,addFormSubmission:x.addOne,addFormSubmissions:x.addMany,updateFormSubmission:x.updateOne,updateFormSubmissions:x.updateMany,deleteFormSubmission:x.deleteOne,deleteFormSubmissions:x.deleteMany}}),{initializeFormSubmissions:Wr,setFormSubmission:ut,setFormSubmissions:Ap,addFormSubmission:ii,addFormSubmissions:ot,updateFormSubmission:Kr,updateFormSubmissions:yp,deleteFormSubmission:ni,deleteFormSubmissions:lt}=si.actions,ai=t=>t.formSubmissionReducer.instances,ci=l.createSelector([ai],t=>Object.values(t)),ri=t=>e=>e.formSubmissionReducer.instances[t],Yr=S(l.createSelector([ai,ct,(t,e)=>e],(t,e,s)=>{const n=new Set;for(const a of Object.values(e))a.form===s&&n.add(a.uuid);return Object.values(t).filter(a=>n.has(a.form_revision))})),Jr=S(l.createSelector([ci,(t,e)=>e],(t,e)=>Object.values(t).filter(s=>s.issue===e))),Xr=S(l.createSelector([ci,(t,e)=>e],(t,e)=>t.filter(s=>s.asset===e))),Zr=si.reducer,ee=F(t=>t.uuid),Qr=ee.getInitialState({}),di=l.createSlice({name:"geoImages",initialState:Qr,extraReducers:t=>{t.addCase("RESET",e=>{Object.assign(e,Qr)})},reducers:{initializeGeoImages:ee.initialize,setGeoImage:ee.setOne,setGeoImages:ee.setMany,addGeoImage:ee.addOne,addGeoImages:ee.addMany,updateGeoImage:ee.updateOne,updateGeoImages:ee.updateMany,deleteGeoImage:ee.deleteOne,deleteGeoImages:ee.deleteMany}}),{initializeGeoImages:xr,setGeoImage:Le,setGeoImages:ed,addGeoImage:td,addGeoImages:sd,updateGeoImage:id,updateGeoImages:fp,deleteGeoImage:ui,deleteGeoImages:nd}=di.actions,ad=t=>t.geoImageReducer.instances,cd=l.createSelector([ad],t=>Object.values(t)),oi=t=>e=>e.geoImageReducer.instances[t],Sp=S(l.createSelector([cd,(t,e)=>e],(t,e)=>g(t.filter(s=>s.project===e)))),rd=di.reducer,te=F(t=>t.uuid),dd=te.getInitialState({}),li=l.createSlice({name:"issueAssociations",initialState:dd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,dd)),reducers:{initializeIssueAssociations:te.initialize,addIssueAssociation:te.addOne,addIssueAssociations:te.addMany,setIssueAssociation:te.setOne,setIssueAssociations:te.setMany,updateIssueAssociation:te.updateOne,updateIssueAssociations:te.updateMany,deleteIssueAssociation:te.deleteOne,deleteIssueAssociations:te.deleteMany}}),{initializeIssueAssociations:ud,setIssueAssociations:gp,setIssueAssociation:Tp,updateIssueAssociation:od,updateIssueAssociations:bp,addIssueAssociation:hi,addIssueAssociations:mi,deleteIssueAssociation:pi,deleteIssueAssociations:Ai}=li.actions,Ne=t=>t.issueAssociationReducer.instances,Ip=l.createSelector([Ne],t=>Object.values(t)),ld=t=>e=>e.issueAssociationReducer.instances[t],hd=S(l.createSelector([Ne,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.associated_issue===e)))),md=S(l.createSelector([Ne,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.issue===e)))),pd=S(l.createSelector([Ne,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.asset===e)))),Ad=li.reducer,se=F(t=>t.uuid),yd=se.getInitialState({}),yi=l.createSlice({name:"issueAttachments",initialState:yd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,yd)),reducers:{initializeIssueAttachments:se.initialize,addIssueAttachment:se.addOne,addIssueAttachments:se.addMany,setIssueAttachment:se.setOne,setIssueAttachments:se.setMany,updateIssueAttachment:se.updateOne,updateIssueAttachments:se.updateMany,deleteIssueAttachment:se.deleteOne,deleteIssueAttachments:se.deleteMany}}),{initializeIssueAttachments:fi,addIssueAttachment:Fp,addIssueAttachments:Si,setIssueAttachment:fd,setIssueAttachments:Rp,updateIssueAttachment:Pp,updateIssueAttachments:Sd,deleteIssueAttachment:gd,deleteIssueAttachments:gi}=yi.actions,Td=t=>t.issueAttachmentReducer.instances,bd=l.createSelector([Td],t=>Object.values(t)),Id=S(l.createSelector([bd,(t,e)=>e],(t,e)=>g(t.filter(({issue:s})=>e===s)))),Fd=t=>e=>e.issueAttachmentReducer.instances[t],Rd=yi.reducer,ie=F(t=>t.uuid),Pd=ie.getInitialState({}),Ti=l.createSlice({name:"issueCommentAttachments",initialState:Pd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Pd)),reducers:{initializeIssueCommentAttachments:ie.initialize,addIssueCommentAttachment:ie.addOne,addIssueCommentAttachments:ie.addMany,setIssueCommentAttachment:ie.setOne,setIssueCommentAttachments:ie.setMany,updateIssueCommentAttachment:ie.updateOne,updateIssueCommentAttachments:ie.updateMany,deleteIssueCommentAttachment:ie.deleteOne,deleteIssueCommentAttachments:ie.deleteMany}}),{initializeIssueCommentAttachments:bi,addIssueCommentAttachment:Op,addIssueCommentAttachments:Od,setIssueCommentAttachment:_d,setIssueCommentAttachments:_p,updateIssueCommentAttachment:vp,updateIssueCommentAttachments:vd,deleteIssueCommentAttachment:wd,deleteIssueCommentAttachments:Ed}=Ti.actions,jd=t=>t.issueCommentAttachmentReducer.instances,qd=l.createSelector([jd],t=>Object.values(t)),Md=t=>e=>e.issueCommentAttachmentReducer.instances[t],wp=S(l.createSelector([qd,(t,e)=>e],(t,e)=>g(t.filter(({issue_comment:s})=>e===s)))),Cd=Ti.reducer,ge=F(t=>t.uuid),kd=ge.getInitialState({}),Ii=l.createSlice({name:"issueComments",initialState:kd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,kd)),reducers:{addIssueComment:ge.addOne,addIssueComments:ge.addMany,setIssueComment:ge.setOne,setIssueComments:ge.setMany,deleteIssueComment:ge.deleteOne,deleteIssueComments:ge.deleteMany}}),{setIssueComments:zd,setIssueComment:Fi,addIssueComment:Ri,addIssueComments:Ep,deleteIssueComment:Pi,deleteIssueComments:jp}=Ii.actions,Vd=t=>t.issueCommentReducer.instances,Oi=t=>e=>e.issueCommentReducer.instances[t],qp=S(l.createSelector([Vd,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.issue===e)))),Dd=Ii.reducer,Te=F(t=>t.uuid),Ud=Te.getInitialState({}),_i=l.createSlice({name:"issues",initialState:Ud,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,Ud)}),reducers:{initializeIssues:Te.initialize,addIssue:Te.addOne,addIssues:Te.addMany,updateIssue:Te.updateOne,deleteIssue:Te.deleteOne,deleteIssues:Te.deleteMany}}),{initializeIssues:$d,addIssue:vi,addIssues:Bd,updateIssue:ht,deleteIssue:wi,deleteIssues:Gd}=_i.actions,Ld=t=>t.issueReducer.instances,Ei=t=>e=>e.issueReducer.instances[t],Mp=S(l.createSelector([Ld,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a?s.push(a):console.warn("selectIssuesByIds: No issue exists with the id",n)}return g(s)})),Nd=_i.reducer,ne=F(t=>t.uuid),Hd=ne.getInitialState({}),ji=l.createSlice({name:"issueTypeAttachments",initialState:Hd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Hd)),reducers:{initializeIssueTypeAttachments:ne.initialize,addIssueTypeAttachment:ne.addOne,addIssueTypeAttachments:ne.addMany,setIssueTypeAttachment:ne.setOne,setIssueTypeAttachments:ne.setMany,updateIssueTypeAttachment:ne.updateOne,updateIssueTypeAttachments:ne.updateMany,deleteIssueTypeAttachment:ne.deleteOne,deleteIssueTypeAttachments:ne.deleteMany}}),{initializeIssueTypeAttachments:qi,addIssueTypeAttachment:Cp,addIssueTypeAttachments:Wd,setIssueTypeAttachment:Kd,setIssueTypeAttachments:kp,updateIssueTypeAttachment:zp,updateIssueTypeAttachments:Yd,deleteIssueTypeAttachment:Jd,deleteIssueTypeAttachments:Xd}=ji.actions,Zd=t=>t.issueTypeAttachmentReducer.instances,Qd=l.createSelector([Zd],t=>Object.values(t)),xd=t=>e=>e.issueTypeAttachmentReducer.instances[t],Vp=S(l.createSelector([Qd,(t,e)=>e],(t,e)=>g(t.filter(({issue_type:s})=>e===s)))),eu=ji.reducer,ae=F(t=>t.uuid),tu=ae.getInitialState({}),Mi=l.createSlice({name:"issueTypeFieldsAttachments",initialState:tu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,tu)),reducers:{initializeIssueTypeFieldsAttachments:ae.initialize,addIssueTypeFieldsAttachment:ae.addOne,addIssueTypeFieldsAttachments:ae.addMany,setIssueTypeFieldsAttachment:ae.setOne,setIssueTypeFieldsAttachments:ae.setMany,updateIssueTypeFieldsAttachment:ae.updateOne,updateIssueTypeFieldsAttachments:ae.updateMany,deleteIssueTypeFieldsAttachment:ae.deleteOne,deleteIssueTypeFieldsAttachments:ae.deleteMany}}),{initializeIssueTypeFieldsAttachments:su,addIssueTypeFieldsAttachment:Dp,addIssueTypeFieldsAttachments:iu,setIssueTypeFieldsAttachment:Up,setIssueTypeFieldsAttachments:$p,updateIssueTypeFieldsAttachment:Bp,updateIssueTypeFieldsAttachments:nu,deleteIssueTypeFieldsAttachment:Gp,deleteIssueTypeFieldsAttachments:au}=Mi.actions,cu=t=>t.issueTypeFieldsAttachmentReducer.instances,ru=l.createSelector([cu],t=>Object.values(t)),Lp=S(l.createSelector([ru,(t,e)=>e],(t,e)=>g(t.filter(s=>s.fields_revision===e)))),Np=t=>e=>e.issueTypeFieldsAttachmentReducer.instances[t],du=Mi.reducer,ce=F(t=>t.uuid),uu=ce.getInitialState({}),Ci=l.createSlice({name:"issueTypeFieldValues",initialState:uu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,uu)),reducers:{initializeIssueTypeFieldValues:ce.initialize,addIssueTypeFieldValues:ce.addOne,addIssueTypeFieldValuesMany:ce.addMany,setIssueTypeFieldValues:ce.setOne,setIssueTypeFieldValuesMany:ce.setMany,updateIssueTypeFieldValues:ce.updateOne,updateIssueTypeFieldValuesMany:ce.updateMany,deleteIssueTypeFieldValues:ce.deleteOne,deleteIssueTypeFieldValuesMany:ce.deleteMany}}),{initializeIssueTypeFieldValues:ou,addIssueTypeFieldValues:ki,addIssueTypeFieldValuesMany:Hp,setIssueTypeFieldValues:Wp,setIssueTypeFieldValuesMany:Kp,updateIssueTypeFieldValues:He,updateIssueTypeFieldValuesMany:Yp,deleteIssueTypeFieldValues:zi,deleteIssueTypeFieldValuesMany:Jp}=Ci.actions,lu=t=>t.issueTypeFieldValuesReducer.instances,Vi=l.createSelector([lu],t=>Object.values(t)),Xp=S(l.createSelector([Vi,(t,e)=>e],(t,e)=>g(t.filter(s=>s.issue===e)))),Di=t=>e=>e.issueTypeFieldValuesReducer.instances[t],hu=Ci.reducer,re=F(t=>t.uuid),mu=re.getInitialState({}),Ui=l.createSlice({name:"issueTypeFields",initialState:mu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,mu)),reducers:{initializeIssueTypeFields:re.initialize,addIssueTypeFields:re.addOne,addIssueTypeFieldsMany:re.addMany,setIssueTypeFields:re.setOne,setIssueTypeFieldsMany:re.setMany,updateIssueTypeFields:re.updateOne,updateIssueTypeFieldsMany:re.updateMany,deleteIssueTypeFields:re.deleteOne,deleteIssueTypeFieldsMany:re.deleteMany}}),{initializeIssueTypeFields:pu,addIssueTypeFields:Au,addIssueTypeFieldsMany:Zp,setIssueTypeFields:Qp,setIssueTypeFieldsMany:xp,updateIssueTypeFields:yu,updateIssueTypeFieldsMany:eA,deleteIssueTypeFields:fu,deleteIssueTypeFieldsMany:tA}=Ui.actions,Su=t=>t.issueTypeFieldsReducer.instances,mt=l.createSelector([Su],t=>Object.values(t)),sA=S(l.createSelector([mt,(t,e)=>e],(t,e)=>g(t.filter(s=>s.issue_type===e)))),iA=S(l.createSelector([mt,(t,e)=>e],(t,e)=>t.filter(s=>s.issue_type===e).sort((s,n)=>s.submitted_at>n.submitted_at?-1:1)[0])),nA=S(l.createSelector([mt,Vi,(t,e)=>e],(t,e,s)=>{const n=new Set(t.filter(a=>a.issue_type===s).map(a=>a.uuid));return g(e.filter(a=>n.has(a.fields_revision)))})),aA=t=>e=>e.issueTypeFieldsReducer.instances[t],gu=Ui.reducer,de=F(t=>t.uuid),Tu=de.getInitialState({}),$i=l.createSlice({name:"issueTypeFieldValuesAttachments",initialState:Tu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Tu)),reducers:{initializeIssueTypeFieldValuesAttachments:de.initialize,addIssueTypeFieldValuesAttachment:de.addOne,addIssueTypeFieldValuesAttachments:de.addMany,setIssueTypeFieldValuesAttachment:de.setOne,setIssueTypeFieldValuesAttachments:de.setMany,updateIssueTypeFieldValuesAttachment:de.updateOne,updateIssueTypeFieldValuesAttachments:de.updateMany,deleteIssueTypeFieldValuesAttachment:de.deleteOne,deleteIssueTypeFieldValuesAttachments:de.deleteMany}}),{initializeIssueTypeFieldValuesAttachments:bu,addIssueTypeFieldValuesAttachment:cA,addIssueTypeFieldValuesAttachments:pt,setIssueTypeFieldValuesAttachment:rA,setIssueTypeFieldValuesAttachments:dA,updateIssueTypeFieldValuesAttachment:uA,updateIssueTypeFieldValuesAttachments:Iu,deleteIssueTypeFieldValuesAttachment:oA,deleteIssueTypeFieldValuesAttachments:At}=$i.actions,Bi=t=>t.issueTypeFieldValuesAttachmentReducer.instances,Fu=l.createSelector([Bi],t=>Object.values(t)),lA=t=>e=>e.issueTypeFieldValuesAttachmentReducer.instances[t],Ru=S(l.createSelector([Bi,(t,e)=>e],(t,e)=>{const s=new Set(e);return g(Object.values(t).filter(n=>s.has(n.uuid)))})),Pu=S(l.createSelector([Fu,(t,e)=>e],(t,e)=>g(t.filter(s=>s.field_values===e)))),Ou=$i.reducer,ve=F(t=>t.uuid),_u=ve.getInitialState({}),Gi=l.createSlice({name:"issueTypes",initialState:_u,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,_u)}),reducers:{initializeIssueTypes:ve.initialize,setIssueType:ve.setOne,addIssueType:ve.addOne,updateIssueType:ve.updateOne,removeIssueType:ve.deleteOne}}),{initializeIssueTypes:vu,setIssueType:We,addIssueType:wu,updateIssueType:Eu,removeIssueType:Li}=Gi.actions,ju=t=>t.issueTypeReducer.instances,qu=l.createSelector(ju,t=>Object.values(t)),Ni=t=>e=>e.issueTypeReducer.instances[t],hA=t=>e=>{const s=[];for(const n of t){const a=e.issueTypeReducer.instances[n];a?s.push(a):console.warn("selectIssueTypesByIds: No issue type exists with the id",n)}return s},mA=S(l.createSelector([qu,(t,e)=>e],(t,e)=>g(t.filter(s=>s.organization===e)))),Hi=S(l.createSelector([t=>t.issueReducer.instances,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.issue_type===e)))),pA=t=>e=>Hi(t)(e).length,Mu=Gi.reducer,be=F(t=>t.uuid),Cu=be.getInitialState({}),Wi=l.createSlice({name:"issueUpdates",initialState:Cu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Cu)),reducers:{initializeIssueUpdates:be.setMany,setIssueUpdate:be.setOne,addIssueUpdate:be.addOne,addIssueUpdates:be.addMany,deleteIssueUpdate:be.deleteOne,deleteIssueUpdates:be.deleteMany}}),{initializeIssueUpdates:ku,setIssueUpdate:AA,addIssueUpdate:zu,addIssueUpdates:Vu,deleteIssueUpdate:Du,deleteIssueUpdates:Uu}=Wi.actions,$u=t=>t.issueUpdateReducer.instances,Bu=S(l.createSelector([$u,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.issue===e)))),Gu=Wi.reducer,C=F(t=>t.uuid),Lu=C.getInitialState({currentUser:null}),Ki=l.createSlice({name:"users",initialState:Lu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Lu)),reducers:{initializeUsers:C.initialize,setUsers:C.setMany,setUser:C.setOne,addUsers:C.addMany,addUser:C.addOne,updateUsers:C.updateMany,updateUser:C.updateOne,deleteUser:C.deleteOne,deleteUsers:C.deleteMany,removeUser:C.deleteOne,setCurrentUser:(t,e)=>{t.currentUser=e.payload}}}),{initializeUsers:yA,setUsers:Nu,setUser:fA,addUsers:SA,addUser:gA,updateUsers:TA,updateUser:bA,deleteUser:IA,deleteUsers:FA,removeUser:Hu,setCurrentUser:RA}=Ki.actions,Wu=Ki.reducer,yt=t=>t.userReducer.currentUser,ft=t=>t.userReducer.instances,PA=t=>e=>e.userReducer.instances[t],OA=S(l.createSelector([ft,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a?s.push(a):console.warn("selectUsersByIds: No user exists with the uuid",n)}return g(s)})),St=F(t=>t.uuid),Ku=St.getInitialState({}),Yi=l.createSlice({name:"organizationAccess",initialState:Ku,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ku)),reducers:{initializeOrganizationAccesses:St.initialize,updateOrganizationAccess:St.updateOne,deleteOrganizationAccess:St.deleteOne}}),{initializeOrganizationAccesses:Yu,updateOrganizationAccess:Ju,deleteOrganizationAccess:Xu}=Yi.actions,Ji=t=>t.organizationAccessReducer.instances,_A=t=>e=>e.organizationAccessReducer.instances[t],vA=l.createSelector([yt,Ji],(t,e)=>Object.values(e).find(n=>n.user===(t==null?void 0:t.uuid))??null),wA=t=>e=>Object.values(e.organizationAccessReducer.instances).find(s=>s.user===t.uuid),Zu=t=>{const e={};for(const s of Object.values(t.organizationAccessReducer.instances))e[s.user]=s;return Ce(e)},Qu=Yi.reducer,Ke=F(t=>t.uuid),xu=Ke.getInitialState({}),Xi=l.createSlice({name:"projectAccess",initialState:xu,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,xu)),reducers:{initializeProjectAccesses:Ke.initialize,updateProjectAccess:Ke.updateOne,deleteProjectAccess:Ke.deleteOne,deleteProjectAccesses:Ke.deleteMany}}),{initializeProjectAccesses:Zi,updateProjectAccess:eo,deleteProjectAccess:to,deleteProjectAccesses:so}=Xi.actions,Qi=t=>t.projectAccessReducer.instances,io=l.createSelector(Qi,t=>Object.values(t)),EA=t=>e=>e.projectAccessReducer.instances[t],jA=t=>e=>Object.values(e.projectAccessReducer.instances).find(s=>s.user===t.uuid),no=t=>{const e={};for(const s of Object.values(t.projectAccessReducer.instances))e[s.user]=s;return Ce(e)},ao=Xi.reducer,ue=F(t=>t.uuid),co=ue.getInitialState({}),xi=l.createSlice({name:"projects",initialState:co,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,co)),reducers:{initializeProjects:ue.initialize,setProjects:ue.setMany,setProject:ue.setOne,addProjects:ue.addMany,addProject:ue.addOne,updateProjects:ue.updateMany,updateProject:ue.updateOne,deleteProject:ue.deleteOne,deleteProjects:ue.deleteMany,acceptProjectInvite:(t,e)=>{if(e.payload in t.instances)t.instances[e.payload].invited=!1;else throw new Error("Accept project invite: user is not in this project")}}}),{initializeProjects:qA,setProjects:ro,setProject:MA,addProjects:CA,addProject:kA,updateProjects:zA,updateProject:uo,deleteProject:oo,deleteProjects:VA,acceptProjectInvite:lo}=xi.actions,ho=xi.reducer,gt=t=>t.projectReducer.instances,DA=l.createSelector([gt],t=>g(Object.values(t))),UA=t=>e=>e.projectReducer.instances[t],mo=l.createSelector([Qi],t=>Object.values(t).map(e=>e.user)),po=l.createSelector([mo,ft],(t,e)=>t.reduce((s,n)=>({...s,[n]:e[n]}),{})),$A=l.createSelector([yt,po,no],(t,e,s)=>g(Object.values(e).sort((n,a)=>{if(n.uuid===(t==null?void 0:t.uuid))return-1;if(a.uuid===(t==null?void 0:t.uuid))return 1;const c=s[n.uuid],r=s[a.uuid];return(c==null?void 0:c.access_level)===(r==null?void 0:r.access_level)?n.first_name.localeCompare(a.first_name):(c==null?void 0:c.access_level)===Ft.ADMIN?-1:1}))),oe=F(t=>t.uuid),Ao=oe.getInitialState({}),en=l.createSlice({name:"organizations",initialState:Ao,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ao)),reducers:{initializeOrganizations:oe.initialize,setOrganizations:oe.setMany,setOrganization:oe.setOne,addOrganizations:oe.addMany,addOrganization:oe.addOne,updateOrganizations:oe.updateMany,updateOrganization:oe.updateOne,deleteOrganization:oe.deleteOne,deleteOrganizations:oe.deleteMany}}),{initializeOrganizations:BA,setOrganizations:yo,setOrganization:GA,addOrganizations:LA,addOrganization:NA,updateOrganizations:HA,updateOrganization:WA,deleteOrganization:KA,deleteOrganizations:YA}=en.actions,fo=t=>t.organizationReducer.instances,So=l.createSelector([fo],t=>Object.values(t)),JA=t=>e=>e.organizationReducer.instances[t],XA=l.createSelector([So],t=>g(Object.values(t).filter(e=>e.has_access))),go=l.createSelector([Ji],t=>Object.values(t).map(e=>e.user)),ZA=S(l.createSelector([gt,(t,e)=>e],(t,e)=>g(Object.values(t).filter(s=>s.organization_owner===e)))),To=l.createSelector([go,ft],(t,e)=>Ce(t.reduce((s,n)=>({...s,[n]:e[n]}),{}))),QA=l.createSelector([yt,To,Zu],(t,e,s)=>g(Object.values(e).sort((n,a)=>{if(n.uuid===(t==null?void 0:t.uuid))return-1;if(a.uuid===(t==null?void 0:t.uuid))return 1;const c=s[n.uuid],r=s[a.uuid];return(c==null?void 0:c.access_level)===(r==null?void 0:r.access_level)?n.first_name.localeCompare(a.first_name):(c==null?void 0:c.access_level)===Rt.ADMIN?-1:1}))),bo=en.reducer,Io=(t,e,s)=>{const n=t.uuid?t:{...t,uuid:ye.v4()};return{payload:n,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:n,BASE_URL:e,serviceName:s}}}}},Fo={deletedRequests:[],latestRetryTime:0},tn=l.createSlice({name:"outbox",initialState:Fo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Fo)),reducers:{enqueueRequest:{reducer:(t,e)=>t,prepare:t=>{console.debug("Preparing to enqueue request",t);const{BASE_URL:e,serviceName:s,...n}=t;return Io(n,e,s)}},markForDeletion(t,e){t.deletedRequests.push(e.payload)},markAsDeleted(t,e){const s=t.deletedRequests.indexOf(e.payload);s!==-1&&t.deletedRequests.splice(s,1)},_setLatestRetryTime:(t,e)=>{t.latestRetryTime=e.payload}}}),xA=t=>t.outboxReducer.deletedRequests,ey=t=>t.outboxReducer.latestRetryTime,{enqueueRequest:Ro,markForDeletion:ty,markAsDeleted:Po,_setLatestRetryTime:Oo}=tn.actions,_o=tn.reducer,le=F(t=>t.uuid),vo=le.getInitialState({}),sn=l.createSlice({name:"projectAttachments",initialState:vo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,vo)),reducers:{initializeProjectAttachments:le.initialize,addProjectAttachment:le.addOne,addProjectAttachments:le.addMany,setProjectAttachment:le.setOne,setProjectAttachments:le.setMany,updateProjectAttachment:le.updateOne,updateProjectAttachments:le.updateMany,deleteProjectAttachment:le.deleteOne,deleteProjectAttachments:le.deleteMany}}),{initializeProjectAttachments:wo,addProjectAttachment:sy,addProjectAttachments:Eo,setProjectAttachment:jo,setProjectAttachments:qo,updateProjectAttachment:iy,updateProjectAttachments:Mo,deleteProjectAttachment:Co,deleteProjectAttachments:nn}=sn.actions,ko=t=>t.projectAttachmentReducer.instances,zo=l.createSelector([ko],t=>Object.values(t)),Vo=t=>e=>e.projectAttachmentReducer.instances[t],Do=S(l.createSelector([zo,(t,e)=>e],(t,e)=>g(t.filter(({project:s})=>e===s)))),Uo=sn.reducer,he=F(t=>t.uuid),$o=he.getInitialState({activeProjectFileId:null,isImportingProjectFile:!1}),an=l.createSlice({name:"projectFiles",initialState:$o,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,$o)),reducers:{initializeProjectFiles:he.initialize,setProjectFile:he.setOne,setProjectFiles:he.setMany,addProjectFile:he.addOne,addProjectFiles:he.addMany,updateProjectFile:he.updateOne,updateProjectFiles:he.updateMany,deleteProjectFile:he.deleteOne,deleteProjectFiles:he.deleteMany,setIsImportingProjectFile:(t,e)=>{t.isImportingProjectFile=e.payload},saveActiveProjectFileBounds:(t,e)=>{const s=t.activeProjectFileId;if(!s)throw new Error("Tried to save bounds for active project file, but no active project file was set.");if(!t.instances[s])throw new Error(`Tried to save bounds for active project file, but project file with ID ${s}
2
+ doesn't exist.`);t.instances[s].bounds=e.payload},setActiveProjectFileId:(t,e)=>{t.activeProjectFileId=e.payload},resetProjectFileObjectUrls:(t,...e)=>{for(const s in t.instances)delete t.instances[s].objectURL}}}),{initializeProjectFiles:Bo,setProjectFile:ny,setProjectFiles:ay,addProjectFile:cy,addProjectFiles:Go,updateProjectFile:cn,updateProjectFiles:ry,deleteProjectFile:Lo,deleteProjectFiles:No,setIsImportingProjectFile:Ho,setActiveProjectFileId:Wo,saveActiveProjectFileBounds:Ko,resetProjectFileObjectUrls:dy}=an.actions,Yo=t=>t.projectFileReducer.instances,Jo=l.createSelector([Yo],t=>g(Object.values(t).sort((e,s)=>e.z_index-s.z_index))),uy=t=>e=>e.projectFileReducer.instances[t],oy=t=>t.projectFileReducer.activeProjectFileId,ly=t=>t.projectFileReducer.isImportingProjectFile,Xo=an.reducer,hy={isRehydrated:!1},rn=l.createSlice({name:"rehydrated",initialState:hy,reducers:{setRehydrated:(t,e)=>{t.isRehydrated=e.payload}}}),{setRehydrated:my}=rn.actions,py=t=>t.rehydratedReducer.isRehydrated,Zo=rn.reducer,we=F(t=>t.uuid),Qo=we.getInitialState({}),dn=l.createSlice({name:"teams",initialState:Qo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Qo)),reducers:{setTeam:we.setOne,initializeTeams:we.initialize,addTeam:we.addOne,updateTeam:we.updateOne,deleteTeam:we.deleteOne}}),{setTeam:Ee,initializeTeams:xo,addTeam:el,updateTeam:un,deleteTeam:on}=dn.actions,ln=t=>t.teamReducer.instances,hn=l.createSelector([ln],t=>Object.values(t)),je=t=>e=>e.teamReducer.instances[t],Ay=S(l.createSelector([ln,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a?s.push(a):console.warn("selectTeamsByIds: No team exists with the id",n)}return g(s)})),yy=S(l.createSelector([hn,(t,e)=>e],(t,e)=>g(t.filter(s=>s.organization===e)))),fy=S(l.createSelector([hn,(t,e)=>e],(t,e)=>g(t.filter(s=>s.members.includes(e))))),tl=dn.reducer,Sy={version:0},sl=l.createSlice({name:"versioning",initialState:Sy,reducers:{}}),il=sl.reducer;let nl;function gy(t){nl=t}function Ye(){return nl}let al;function Ty(t){al=t}function by(){return al}const cl={};class rl{constructor(e){f(this,"client");cl[this.constructor.name]=this,this.client=e}async enqueueRequest(e){return this.client.enqueueRequest(e,this.host,this.constructor.name)}dispatch(e){this.client.store.dispatch(e)}}const dl="versioning",ul=()=>hl.length-1,ol=t=>(t[dl]={version:ul()},t),ll=()=>ol({}),Iy=t=>(t.outboxReducer&&(t.outboxReducer.deletedRequests=[]),t),Fy=t=>e=>{var s;return e===void 0&&(e={}),((s=e[dl])==null?void 0:s.version)===ul()?e:t(e)},hl=[ol,ll,ll,Iy],Ry=Object.fromEntries(hl.map((t,e)=>[e,Fy(t)])),mn="versioning",ml={[mn]:il,fileReducer:Sr,authReducer:Nc,categoryReducer:Jc,assetReducer:$a,assetAttachmentReducer:Xn,assetStageCompletionReducer:Ha,assetStageReducer:Za,assetTypeReducer:Bc,assetTypeAttachmentReducer:uc,issueReducer:Nd,issueAttachmentReducer:Rd,issueTypeReducer:Mu,issueTypeAttachmentReducer:eu,organizationReducer:bo,outboxReducer:_o,projectReducer:ho,projectAttachmentReducer:Uo,projectAccessReducer:ao,organizationAccessReducer:Qu,projectFileReducer:Xo,rehydratedReducer:Zo,formReducer:zr,formRevisionReducer:Mr,formRevisionAttachmentReducer:Pr,formSubmissionAttachmentReducer:Nr,formSubmissionReducer:Zr,userReducer:Wu,documentsReducer:mr,documentAttachmentReducer:cr,teamReducer:tl,agentsReducer:Bn,issueCommentReducer:Dd,issueCommentAttachmentReducer:Cd,issueUpdateReducer:Gu,geoImageReducer:rd,issueAssociationReducer:Ad,issueTypeFieldsReducer:gu,issueTypeFieldValuesReducer:hu,issueTypeFieldsAttachmentReducer:du,issueTypeFieldValuesAttachmentReducer:Ou,assetTypeFieldsReducer:Rc,assetTypeFieldValuesReducer:Dc,assetTypeFieldsAttachmentReducer:fc,assetTypeFieldValuesAttachmentReducer:jc,assetProcedureReducer:ka,assetProcedureInstanceReducer:ja,assetProcedureFieldsReducer:la,assetProcedureFieldValuesReducer:Pa,assetProcedureFieldsAttachmentReducer:na,assetProcedureFieldValuesAttachmentReducer:Sa},pl=l.combineReducers(ml),Al="RESET",Py=(t,e)=>e.type==="auth/setLoggedIn"&&!e.payload?pl(void 0,e):pl(t,e);let pn=null;function Ie(){const t=Ye();if(!t)return console.warn("Client store not set; cannot get outbox coordinator yet."),null;if(pn)return pn;const e=t.getState().offline.outbox,s=Me._fromOutbox(e);return pn=s,s}const Oy=t=>{if(t)throw t;const e=Ye();e?e.dispatch({type:"rehydrated/setRehydrated",payload:!0}):console.error("Client store not set")},yl=(t,e,s)=>{const n=Ie();return n?(n.addRequest(e),n.getQueue()):(console.warn("Outbox coordinator not set; cannot enqueue request yet."),[])},fl=(t,e,s)=>{const n=Ie();if(!n)return console.warn("Outbox coordinator not set; cannot dequeue request yet."),[];const c=e.meta.offlineAction.payload.uuid;return n.remove(c),n.getQueue()};async function _y(t,e){if(!e.payload)throw new Error("Received empty payload");return zy(e)}const vy={...Tn,effect:_y,discard:yn,returnPromises:!0,persistCallback:Oy,retry:Dy,persistOptions:{storage:Pl},queue:{...Tn.queue,enqueue:yl,dequeue:fl,peek:(...t)=>Vy(...t)}},wy=Ol(Ry,mn),Ey=l.compose(Rl.offline(vy),wy);function jy(t){function e(s){return typeof s=="object"&&s!==null&&["ok","redirect","clientError","serverError","error"].every(a=>a in s)}if(e(t))return t;if(typeof t=="object"&&t!==null){const s=t;if(e(s.response))return s.response;if(s.response&&e(s.response.response))return s.response.response}}async function An(t,e){const s=cl[t.meta.offline.effect.serviceName];if(!s)throw new Error(`Service ${t.meta.offline.effect.serviceName} not found`);const n=s instanceof P;if(e.store.getState().outboxReducer.deletedRequests.includes(t.payload.uuid))throw new Error("Request was marked for deletion");n&&t.payload.checkAuth!==!1&&await s.auth.prepareAuth();const c={queryParams:"",isAuthNeeded:!0},r=t.meta.offline.effect,{payload:u,headers:m,method:d,queryParams:o,attachmentHash:p,isExternalUrl:A,isAuthNeeded:y,isResponseBlob:b}={...c,...r.request},I=r.request;let T=I.url;const O=p?await e.files.fetchCache(p):void 0;if(p&&!O)throw new Error(`Cannot upload file ${p} because it's not cached.`);!A&&!T.startsWith("http")&&(!T.startsWith("/")&&!T.startsWith("blob:")&&(T="/"+T),T=t.meta.offline.effect.BASE_URL+T);const M=w=>{if(p){const me=I.s3url;if(!me)throw new Error(`No S3 URL for file ${p}`);if("warning"in me)throw new Error(`S3 URL warning for file ${p}`);if(!O)throw new Error(`No file for file ${p}`);const Ze=me.fields["x-amz-checksum-sha1"];if(!Ze)throw new Error(`No checksum for file ${p}`);return w.set("x-amz-checksum-sha1",Ze).field({...u,...me.fields}).attach("file",O)}return w.send(u)},Hf={[h.GET]:()=>b?Pe.get(T.toString()).responseType("blob"):Pe.get(T.toString()),[h.POST]:()=>{const w=Pe.post(T.toString());return M(w)},[h.PATCH]:()=>{const w=Pe.patch(T.toString());return M(w)},[h.PUT]:()=>{const w=Pe.put(T.toString());return M(w)},[h.DELETE]:()=>{const w=Pe.delete(T.toString());return M(w)}}[d];let Re=Hf();if(y&&n){const w=s.auth.getAuthHeader();Re=Re.set("Authorization",w)}m&&(Re=Re.set(m));try{return await Re.query(o)}catch(w){const me=jy(w),Ze=me==null?void 0:me.status;if(n&&Ze===401)return await s.auth.handleUnauthorized(Re,me),Re.query(o);throw new q({response:me,innerError:w,discard:gl.includes(Ze)})}}class qy{constructor(e){f(this,"_all");f(this,"_previous");this._all=[e],this._previous=e,this.then=this.then.bind(this),this.compile=this.compile.bind(this)}then(e){return this._previous&&(this._previous.next=e),this._all.push(e),this._previous=e,{then:this.then,compile:this.compile}}compile(){return this._all}}class Sl{constructor(){f(this,"next");this.next=null}then(e){return new qy(this).then(e)}async run(e){if(this.next)return this.next.run(e);{if(console.debug("Middleware finished. Performing request:",e),!Ye())throw new Error("Client store not set");const n=by();if(!n)throw new Error("Client SDK not set");return An(e,n)}}}class My extends Sl{async run(e){return super.run(e)}}class Cy extends Sl{async run(e){return super.run(e)}}const ky=new My().then(new Cy).compile();function zy(t){var e;return(e=ky[0])==null?void 0:e.run(t)}const gl=[400,409,403,404,405,500];function yn(t,e,s=0){var d;if(console.debug("Considering discarding request due to error:",t,`(${typeof t})`,`
3
3
  Action:`,e,`
4
- Retries:`,s),!(t instanceof Error))throw console.error("ENCOUNTERED NON-ERROR ERROR:",t,"(throwing immediately, which may lead to unexpected behavior)"),t;const a=Ye(),c=a.getState().outboxReducer.deletedRequests,r=e.payload.uuid;function u(){a.dispatch(Po(r));const h=Ie();if(!h)throw new Error("Outbox coordinator not set");h.remove(e.payload.uuid);const p=e.meta.offline.rollback;throw p&&(console.warn("Rolling back request due to SDK error:",e),a.dispatch(p)),t}if(t instanceof q&&t.options.discard)return console.debug("Discarding request due to explicit discard:",e),u();if(c.includes(r))return console.debug("Discarding request due to deletion:",e),u();if(t instanceof q){const h=t.status||((d=t.response)==null?void 0:d.status);if(h||console.warn("Error has no status code:",t),h!==void 0&&gl.includes(h)){console.warn("Discarding request due to error:",t,`
5
- Action:`,e);const p=Ie();if(!p)throw new Error("Outbox coordinator not set");p.remove(e.payload.uuid),t.options.discard=!0,u()}}console.debug("Registering a retry for request:",e.payload.uuid);const m=Ie();if(!m)throw new Error("Outbox coordinator not set");return m.registerRetry(e.payload.uuid),!1}function zy(t,e,s){var a;return(a=Ie())==null?void 0:a.peek()}function Vy(t,e){return Ye().dispatch(Oo(new Date().getTime())),Oa}const qe="An unknown error occurred",Dy=500,Tl=["non_field_errors","detail"];function Uy(t,e){let s;if(t!=null&&t.body)if(typeof t.body=="object"){const a=t.body;if(typeof a.error=="string")s=a.error;else if(typeof a.message=="string")s=a.message;else try{s=Object.entries(a).map(([n,c])=>typeof c=="string"?Tl.includes(n)?c:`${n}: ${c}`:Array.isArray(c)?Tl.includes(n)?c.join(`
6
- `):c.map(r=>`${n}: ${r}`).join(`
7
- `):`${n}: ${JSON.stringify(c)}`).join(`
8
- `)}catch(n){console.error("Failed to extract error message from response body",n)}}else typeof t.body=="string"&&(s=t.body);else t!=null&&t.text?s=t.text:e instanceof Error&&(s=e.message);return!s||s.length>Dy?qe:s}class q extends Error{constructor(s){super(qe);f(this,"status");f(this,"response");f(this,"message");f(this,"options");const{response:a,innerError:n}=s;this.message=s.message??Uy(a,n)??qe,this.status=(a==null?void 0:a.status)??0,this.response=a,s.discard=s.discard??!1,this.options=s}}class $y extends rl{constructor(e){super(e)}}class P extends rl{constructor(s,a){super(s);f(this,"auth");this.auth=a}}class By extends P{async startConversation(e,s){return this.enqueueRequest({description:"Start agent conversation",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:s},blockers:["prompt"],blocks:["prompt"]}).then(a=>(this.dispatch(Va(a)),a))}async continueConversation(e,s,a){return this.enqueueRequest({description:"Prompt agent",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:a},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:s}}).then(n=>{this.dispatch(Ua(n))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:l.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(s=>{this.dispatch(Da(s))})}async rate(e,s){return this.enqueueRequest({description:"Rate agent response",method:l.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:s},blockers:["rate"],blocks:["rate"]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get agent conversation history",method:l.GET,url:`/projects/${e}/agent-conversations/`,blockers:["agent-conversations"],blocks:["agent-conversations"]});this.dispatch(za(s))}}class E extends P{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:s,assetAttachmentReducer:a,assetTypeAttachmentReducer:n,documentAttachmentReducer:c,projectAttachmentReducer:r,formRevisionAttachmentReducer:u,formSubmissionAttachmentReducer:m,geoImageReducer:d,assetTypeFieldsAttachmentReducer:h,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:A,issueTypeFieldValuesAttachmentReducer:y}=this.client.store.getState();return[].concat(Object.values(s.instances),Object.values(a.instances),Object.values(n.instances),Object.values(c.instances),Object.values(r.instances),Object.values(u.instances),Object.values(m.instances),Object.values(d.instances),Object.values(h.instances),Object.values(p.instances),Object.values(A.instances),Object.values(y.instances)).filter(I=>I.file_sha1===e).length}processPresignedUrls(e){const s={};for(const[a,n]of Object.entries(e))s[a]=this.enqueueRequest({url:n.url,description:"Upload file to S3",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:a,blockers:[`s3-${n.fields.key}`],blocks:[a],s3url:n});return s}async getFilePayload(e){const s=await Oe(e),a={sha1:s,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,s),a}}class Fe extends E{async _bulkAdd(e){var d;const{store:s}=this.client,a=(d=s.getState().userReducer.currentUser)==null?void 0:d.uuid,n=new Date().toISOString(),c=[],r=[],u={};for(const h of e){const{modelUuid:p,file:A}=h,y=await this.getFilePayload(A);y.sha1 in u||(u[y.sha1]=y);const b=this.buildOfflineAttachment({file:A,file_sha1:y.sha1,submitted_at:n,created_by:a,description:"",modelUuid:p});c.push(b),r.push(this.buildAttachmentPayload({uuid:b.uuid,file_name:b.file_name,file_sha1:b.file_sha1,file_extension:y.extension,description:b.description,modelUuid:p}))}this.dispatch(this.addAttachments(c));const m=this.enqueueRequest({description:`Add ${this.name}`,method:l.POST,url:`${this.url}/bulk/`,payload:{submitted_at:n,attachments:r,files:Object.values(u)},blocks:c.map(h=>h.uuid),blockers:c.map(h=>h.file_sha1)});return m.then(({attachments:h,presigned_urls:p})=>{this.dispatch(this.updateAttachments(h)),this.processPresignedUrls(p)}).catch(()=>{this.dispatch(this.removeAttachments(c.map(h=>h.uuid)))}),[c,m.then(({attachments:h})=>h)]}async _delete(e){const{store:s}=this.client,a=this.selectAttachment(e)(s.getState());if(!a)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(a.uuid));const n=this.enqueueRequest({description:`Delete ${this.name}`,method:l.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return n.then(()=>{this.getNumberOfAttachmentsWithSha1(a.file_sha1)===0&&this.client.files.removeCache(a.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(a))}),n}}class Gy extends Fe{constructor(){super(...arguments);f(this,"name","Asset Attachment");f(this,"url","/asset-attachments");f(this,"initializeAttachments",Ct);f(this,"addAttachments",kt);f(this,"updateAttachments",La);f(this,"removeAttachments",zt);f(this,"removeAttachment",Na);f(this,"setAttachment",Ga);f(this,"selectAttachment",Ka)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(a=>({modelUuid:a.assetUuid,file:a.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const a=await this.enqueueRequest({description:"Get asset attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(Ct(a))}}class Ly extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,n={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in n||(n[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:a,fields_revision:h,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:h};r.push(I)}this.dispatch(Qa(c));const u=this.enqueueRequest({description:"Add asset procedure fields attachments",method:l.POST,url:"/asset-procedure-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(n)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(xa(d.attachments))}).catch(()=>{this.dispatch(en(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure fields attachments",method:l.GET,url:"/asset-procedure-fields-attachments/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Za(s))}}class Ny extends P{add(e){var u;const{store:s}=this.client,a=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(rn(c));const r=this.enqueueRequest({description:"Add Asset Procedure Fields",method:l.POST,url:"/asset-procedure-fields/",payload:c,blockers:[c.asset_procedure],blocks:[c.uuid]});return r.then(m=>{this.dispatch(dn(m))}).catch(m=>{throw this.dispatch(un(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Procedure Fields",method:l.GET,url:"/asset-procedure-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(cn(s))}}function Je(t,e){const s=[];let a=0;const n=t.length;for(;a<n;)s.push(t.slice(a,a+=e));return s}class Hy extends E{async bulkAdd(e,s){var d;const a=new Date().toISOString(),n=(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.uuid,c=Je(e,s??e.length),r=[],u=[];for(const h of c){const p={},A=[];for(const y of h){const{fieldValuesUuid:b,fieldIdentifier:I,file:T}=y,O=await this.getFilePayload(T);O.sha1 in p||(p[O.sha1]=O);const M=R({file:URL.createObjectURL(T),file_type:T.type,file_name:T.name,file_sha1:O.sha1,created_by:n,field_values:b,submitted_at:a,field_identifier:I});r.push(M);const It={uuid:M.uuid,file_name:T.name,file_sha1:O.sha1,file_extension:O.extension,field_identifier:I,field_values:b};A.push(It)}u.push({submitted_at:a,attachments:A,files:Object.values(p)})}this.dispatch(Qe(r));const m=u.map(h=>this.enqueueRequest({description:"Add asset procedure field values attachments",method:l.POST,url:"/asset-procedure-field-values-attachments/bulk/",payload:h,blockers:h.attachments.map(p=>p.field_values),blocks:h.attachments.map(p=>p.uuid)}));return Promise.all(m).then(h=>{for(const A of h)this.processPresignedUrls(A.presigned_urls);const p=h.flatMap(A=>A.attachments);this.dispatch(pn(p))}).catch(h=>{throw this.dispatch(xe(r.map(p=>p.uuid))),h}),[r,m.map(h=>h.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,a=s.getState(),n=yn(e)(a);this.dispatch(xe(e));try{await this.enqueueRequest({description:"Delete asset procedure field values attachments",method:l.DELETE,url:"/asset-procedure-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(Qe(n)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values attachments",method:l.GET,url:"/asset-procedure-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(mn(s))}}const Wy=t=>Array.isArray(t)&&t[0]instanceof File,Xe=t=>{const e={},s={};for(const a in t){const n=t[a];n instanceof File?e[a]=[n]:Wy(n)?e[a]=n:n!==void 0&&(s[a]=n)}return{values:s,files:e}};class Ky extends E{add(e){var r;const{store:s}=this.client,a=s.getState(),n=R({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.uuid,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add form submission",method:l.POST,url:"/form-submissions/",payload:_(n),blockers:["add-form-entry",e.form_revision,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[n.uuid]});return this.dispatch(ii(n)),c.then(u=>(this.dispatch(ut(u)),u)).catch(()=>{this.dispatch(ai(n.uuid))}),[n,c]}update(e){const{store:s}=this.client,a=s.getState(),n=ri(e.uuid)(a);if(!n)throw new Error(`Expected submission with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(Kr(c));const r=this.enqueueRequest({description:"Delete user form submissions",method:l.PATCH,url:`/form-submissions/${c.uuid}/`,payload:e,blockers:[c.uuid],blocks:[c.uuid]});return r.then(u=>{this.dispatch(ut(u))}).catch(()=>{this.dispatch(ut(n))}),[c,r]}async delete(e){const{store:s}=this.client,a=s.getState(),n=ri(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Lr(e)(a);this.dispatch(ai(e)),this.dispatch(dt(c.map(r=>r.uuid)));try{return await this.enqueueRequest({description:"Delete user form submissions",method:l.DELETE,url:`/form-submissions/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ii(n)),this.dispatch(rt(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch form submissions",method:l.GET,url:"/form-submissions/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Wr(s))}}class Yy extends P{add(e){var r;const{store:s}=this.client,a=s.getState(),n=R({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.uuid,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset procedure field values",method:l.POST,url:"/asset-procedure-field-values/",payload:_(n),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[n.uuid]});return this.dispatch(Lt(n)),c.then(u=>(this.dispatch(ze(u)),u)).catch(()=>{this.dispatch(Nt(n.uuid))}),[n,c]}bulkAdd(e,s){var d;const a=new Date().toISOString(),{values:n}=Xe(e.values),c=[],r=Je(e.payloads,s??e.payloads.length),u=[];for(const h of r){const p=[];for(const A of h){const y=R({...A,values:Xe(A.values).values,created_by:(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.uuid,submitted_at:a});c.push(y),p.push({uuid:y.uuid,asset:A.asset,fields_revision:A.fields_revision,asset_procedure_instance:A.asset_procedure_instance,published_at:A.published_at,values:y.values})}u.push({submitted_at:a,values:n,field_values:p})}this.dispatch(bn(c));const m=[];for(const h of u){const p=h.field_values.map(T=>T.asset),A=h.field_values.map(T=>T.fields_revision),y=h.field_values.map(T=>T.asset_procedure_instance),b=h.field_values.map(T=>T.uuid),I=this.enqueueRequest({description:"Bulk add asset procedure field values",method:l.POST,url:"/asset-procedure-field-values/bulk/",payload:h,blockers:[...p,...A,...y],blocks:b});m.push(I)}return Promise.all(m).then(h=>{this.dispatch(In(h.flat()))}).catch(()=>{this.dispatch(Fn(c.map(h=>h.uuid)))}),[c,m]}update(e){const{store:s}=this.client,a=s.getState(),n=Wt(e.uuid)(a);if(!n)throw new Error(`Expected AssetProcedureFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(ze(c));const r=this.enqueueRequest({description:"Update asset procedure field values",method:l.PATCH,url:`/asset-procedure-field-values/${e.uuid}/`,payload:e,blockers:[c.fields_revision,c.asset,c.asset_procedure_instance],blocks:[c.uuid]});return r.then(u=>{this.dispatch(ze(u))}).catch(()=>{this.dispatch(ze(n))}),[c,r]}async delete(e){const{store:s}=this.client,a=s.getState(),n=Wt(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=fn(e)(a);this.dispatch(Nt(e)),this.dispatch(xe(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure field values",method:l.DELETE,url:`/asset-procedure-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Lt(n)),this.dispatch(Qe(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values",method:l.GET,url:"/asset-procedure-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Tn(s))}}class Jy extends P{add(e){const{store:s}=this.client,a=s.getState().userReducer.currentUser.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(Yt(c));const r=this.enqueueRequest({description:"Create asset procedure instance",method:l.POST,url:"/asset-procedure-instances/",payload:_(c),blockers:[e.asset_procedure,e.asset_type],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Ve(u))}).catch(()=>{this.dispatch(Jt(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,a=Qt(e.uuid)(s.getState());if(!a)throw new Error(`Expected asset procedure instance with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(Ve(n));const c=this.enqueueRequest({description:"Update asset procedure instance",method:l.PATCH,url:`/asset-procedure-instances/${e.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(Ve(r))}).catch(()=>{this.dispatch(Ve(a))}),[n,c]}async remove(e){const{store:s}=this.client,a=s.getState(),n=Qt(e)(a);if(!n)throw new Error(`Expected asset procedure instance with uuid ${e} to exist`);return this.dispatch(Jt(e)),this.enqueueRequest({description:"Delete asset procedure instance",method:l.DELETE,url:`/asset-procedure-instances/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(Yt(n)),c})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure instances",method:l.GET,url:"/asset-procedure-instances/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(_n(s))}}class Xy extends P{add(e){const{store:s}=this.client,a=s.getState().userReducer.currentUser.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(es(c));const r=this.enqueueRequest({description:"Create asset procedure",method:l.POST,url:"/asset-procedures/",payload:_(c),blockers:[],blocks:[c.uuid]});return r.then(u=>{this.dispatch(De(u))}).catch(()=>{this.dispatch(ts(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,a=is(e.uuid)(s.getState());if(!a)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(De(n));const c=this.enqueueRequest({description:"Update asset procedure",method:l.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(De(r))}).catch(()=>{this.dispatch(De(a))}),[n,c]}async remove(e){const{store:s}=this.client,a=s.getState(),n=is(e)(a);if(!n)throw new Error(`Expected asset procedure with uuid ${e} to exist`);const c=En(e)(a);return this.dispatch(ts(e)),this.dispatch(wn(c.map(r=>r.uuid))),this.enqueueRequest({description:"Delete asset procedure",method:l.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(es(n)),this.dispatch(vn(c)),r})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedures",method:l.GET,url:"/asset-procedures/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Mn(s))}}class Zy extends P{add(e){const{store:s}=this.client;if(!e.canvas_marker&&!e.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");const a=s.getState().userReducer.currentUser.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(ns(c));const r=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/assets/",payload:_(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Ue(u))}).catch(()=>{this.dispatch(rs(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,a=os(e.uuid)(s.getState());if(!a)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const n={...a,...e};if(!n.canvas_marker&&!n.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");this.dispatch(Ue(n));const c=this.enqueueRequest({description:"Edit asset",method:l.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(Ue(r))}).catch(()=>{this.dispatch(Ue(a))}),[n,c]}async remove(e){const{store:s}=this.client,a=s.getState(),n=os(e)(a);if(!n)throw new Error(`No asset with uuid ${e} found in the store`);const c=Ya(e)(a),r=Xr(e)(a),u=pd(e)(a);if(this.dispatch(rs(e)),c.length>0){const m=c.map(({uuid:d})=>d);this.dispatch(zt(m))}if(r.length>0){const m=r.map(({uuid:d})=>d);this.dispatch(lt(m))}if(u.length>0){const m=u.map(({uuid:d})=>d);this.dispatch(Ai(m))}return this.enqueueRequest({description:"Delete asset",method:l.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(ns(n)),this.dispatch(kt(c)),this.dispatch(ot(r)),this.dispatch(mi(u)),m})}bulkAdd(e,s,a,n){const c=new Date().toISOString(),r=ye.v4(),u=Je(e,n).map(h=>{const p=h.map(A=>R(A));return{batchId:ye.v4(),payload:{transaction_id:r,submitted_at:c,asset_type:s,project:a,assets:p}}}),m=[];let d=null;for(const h of u){const{batchId:p,payload:A}=h,y=A.assets.map(O=>O.uuid),b=[s];d&&b.push(d);const I=y;I.push(p);const T=this.enqueueRequest({description:"Batch create assets",method:l.POST,url:"/assets/bulk/",payload:A,blockers:b,blocks:I});d=h.batchId,m.push(T)}return Promise.all(m).then(h=>{const p=h.flat();this.dispatch(cs(p))}),m}async refreshStore(e){const s=await this.enqueueRequest({description:"Get assets",method:l.GET,url:"/assets/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Vn(s))}}class Qy extends P{add(e){const{store:s}=this.client,a=s.getState().userReducer.currentUser.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(hs(c));const r=this.enqueueRequest({description:"Add asset stage completion",method:l.POST,url:"/asset-stage-completions/",payload:_(c),blockers:[e.asset,e.stage],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Ln(u))}).catch(()=>{this.dispatch(ps(c.uuid))}),[c,r]}delete(e){const{store:s}=this.client,a=Wn(e)(s.getState());if(!a)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(ps(e));const n=this.enqueueRequest({description:"Delete asset stage completion",method:l.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return n.catch(()=>{this.dispatch(hs(a))}),n}bulkAdd(e){const{store:s}=this.client,a=new Date().toISOString(),n=s.getState().userReducer.currentUser.uuid,c=e.map(d=>R(d)),r=c.map(d=>({...d,created_by:n,submitted_at:a})),u=r.map(({uuid:d})=>d);this.dispatch(ms(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:l.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:a,completions:c},blockers:[...e.map(d=>d.asset_procedure_instance),...e.map(d=>d.stage),...e.map(d=>d.asset)],blocks:u});return m.then(d=>{this.dispatch(Nn(d))}).catch(()=>{this.dispatch(As(u))}),[r,m]}bulkDelete(e){const{store:s}=this.client,a=Kn(e)(s.getState());this.dispatch(As(e));const n=this.enqueueRequest({description:"Deleting asset stage completions",method:l.DELETE,url:"/asset-stage-completions/bulk/",payload:{completion_ids:e},blockers:e,blocks:[]});return n.catch(()=>{this.dispatch(ms(a))}),n}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stage completions",method:l.GET,url:"/asset-stage-completions/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Gn(s))}}class xy extends P{bulkAdd(e,s){const a=new Date().toISOString(),n=this.client.store.getState().userReducer.currentUser.uuid,c=e.map(m=>R(m)),r=c.map(m=>({...m,asset_procedure:s,created_by:n,submitted_at:a}));this.dispatch(Ss(r));const u=this.enqueueRequest({description:"Add asset stages",method:l.POST,url:"/asset-stages/bulk/",payload:{submitted_at:a,asset_procedure:s,stages:c},blockers:[s],blocks:c.map(({uuid:m})=>m)});return u.then(m=>{this.dispatch(et(m))}).catch(()=>{this.dispatch(Ts(r.map(({uuid:m})=>m)))}),[r,u]}async bulkUpdate(e,s){const n=this.client.store.getState(),c=bs(e.map(({uuid:r})=>r))(n);return this.dispatch(et(e)),this.enqueueRequest({description:"Edit asset stages",method:l.PATCH,url:`/asset-procedures/${s}/bulk-update-stages/`,payload:{stages:e},blockers:[s],blocks:e.map(({uuid:r})=>r)}).catch(r=>{throw this.dispatch(et(c)),r})}async bulkDelete(e){const{store:s}=this.client,a=bs(e)(s.getState());this.dispatch(Ts(e));const n=this.enqueueRequest({description:"Delete asset stages",method:l.DELETE,url:"/asset-stages/bulk/",payload:{stage_ids:e},blockers:e,blocks:[]});return n.catch(()=>{this.dispatch(Ss(a))}),n}update(e){const{store:s}=this.client,a=Qn(e.uuid)(s.getState());if(!a)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const n={...a,...e};this.dispatch(gs(n));const c=this.enqueueRequest({description:"Update asset stage",method:l.PATCH,url:`/asset-stages/${a.uuid}/`,payload:{name:e.name,description:e.description,priority:e.priority,color:e.color},blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(gs(r))}).catch(()=>{this.dispatch(Xn(a))}),[n,c]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stages",method:l.GET,url:"/asset-stages/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Jn(s))}}class ef extends Fe{constructor(){super(...arguments);f(this,"name","Asset Type Attachment");f(this,"url","/asset-type-attachments");f(this,"addAttachments",Fs);f(this,"updateAttachments",ic);f(this,"removeAttachments",Rs);f(this,"removeAttachment",ac);f(this,"setAttachment",sc);f(this,"selectAttachment",rc)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(a=>({modelUuid:a.assetTypeUuid,file:a.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const a=await this.enqueueRequest({description:"Get asset type attachments",method:l.GET,url:`${this.url}/`,queryParams:{organization:s},blocks:[],blockers:[]});this.dispatch(tc(a))}}class tf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,n={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in n||(n[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:a,fields_revision:h,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:h};r.push(I)}this.dispatch(hc(c));const u=this.enqueueRequest({description:"Add asset type fields attachments",method:l.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(n)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(mc(d.attachments))}).catch(()=>{this.dispatch(pc(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type fields attachments",method:l.GET,url:"/asset-type-fields-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(lc(s))}}class sf extends P{add(e){var u;const{store:s}=this.client,a=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(Tc(c));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:l.POST,url:"/asset-type-fields/",payload:c,blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(bc(m))}).catch(m=>{throw this.dispatch(Ic(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Type Fields",method:l.GET,url:"/asset-type-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(gc(s))}}class af extends E{async bulkAdd(e,s){var d;const a=new Date().toISOString(),n=(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.uuid,c=Je(e,s??e.length),r=[],u=[];for(const h of c){const p={},A=[];for(const y of h){const{fieldValuesUuid:b,fieldIdentifier:I,file:T}=y,O=await this.getFilePayload(T);O.sha1 in p||(p[O.sha1]=O);const M=R({file:URL.createObjectURL(T),file_type:T.type,file_name:T.name,file_sha1:O.sha1,created_by:n,field_values:b,submitted_at:a,field_identifier:I});r.push(M);const It={uuid:M.uuid,file_name:T.name,file_sha1:O.sha1,file_extension:O.extension,field_identifier:I,field_values:b};A.push(It)}u.push({submitted_at:a,attachments:A,files:Object.values(p)})}this.dispatch(it(r));const m=u.map(h=>this.enqueueRequest({description:"Add asset type field values attachments",method:l.POST,url:"/asset-type-field-values-attachments/bulk/",payload:h,blockers:h.attachments.map(p=>p.field_values),blocks:h.attachments.map(p=>p.uuid)}));return Promise.all(m).then(h=>{for(const A of h)this.processPresignedUrls(A.presigned_urls);const p=h.flatMap(A=>A.attachments);this.dispatch(_c(p))}).catch(h=>{throw this.dispatch(at(r.map(p=>p.uuid))),h}),[r,m.map(h=>h.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,a=s.getState(),n=wc(e)(a);this.dispatch(at(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:l.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(it(n)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values attachments",method:l.GET,url:"/asset-type-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Oc(s))}}class nf extends P{add(e){var r;const{store:s}=this.client,a=s.getState(),n=R({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.uuid,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset type field values",method:l.POST,url:"/asset-type-field-values/",payload:_(n),blockers:[e.asset,e.fields_revision],blocks:[n.uuid]});return this.dispatch(Es(n)),c.then(u=>(this.dispatch($e(u)),u)).catch(()=>{this.dispatch(js(n.uuid))}),[n,c]}bulkAdd(e,s){var d;const a=new Date().toISOString(),{values:n}=Xe(e.values),c=[],r=Je(e.payloads,s??e.payloads.length),u=[];for(const h of r){const p=[];for(const A of h){const y=R({...A,values:Xe(A.values).values,created_by:(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.uuid,submitted_at:a});c.push(y),p.push({uuid:y.uuid,asset:A.asset,fields_revision:A.fields_revision,published_at:A.published_at,values:y.values})}u.push({submitted_at:a,values:n,field_values:p})}this.dispatch(Cc(c));const m=[];for(const h of u){const p=h.field_values.map(I=>I.asset),A=h.field_values.map(I=>I.fields_revision),y=h.field_values.map(I=>I.uuid),b=this.enqueueRequest({description:"Bulk add asset type field values",method:l.POST,url:"/asset-type-field-values/bulk/",payload:h,blockers:[...p,...A],blocks:y});m.push(b)}return Promise.all(m).then(h=>{this.dispatch(kc(h.flat()))}).catch(()=>{this.dispatch(zc(c.map(h=>h.uuid)))}),[c,m]}update(e){const{store:s}=this.client,a=s.getState(),n=Ms(e.uuid)(a);if(!n)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch($e(c));const r=this.enqueueRequest({description:"Delete asset type field values",method:l.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.asset],blocks:[c.uuid]});return r.then(u=>{this.dispatch($e(u))}).catch(()=>{this.dispatch($e(n))}),[c,r]}async delete(e){const{store:s}=this.client,a=s.getState(),n=Ms(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Ec(e)(a);this.dispatch(js(e)),this.dispatch(at(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:l.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Es(n)),this.dispatch(it(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values",method:l.GET,url:"/asset-type-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Mc(s))}}class cf extends P{add(e){const{store:s}=this.client,a=s.getState().userReducer.currentUser.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(ks(c));const r=this.enqueueRequest({description:"Create asset type",method:l.POST,url:"/asset-types/",payload:_(c),blockers:[],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Be(u))}).catch(()=>{this.dispatch(zs(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,a=Ds(e.uuid)(s.getState());if(!a)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(Be(n));const c=this.enqueueRequest({description:"Update asset type",method:l.PATCH,url:`/asset-types/${e.uuid}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(Be(r))}).catch(()=>{this.dispatch(Be(a))}),[n,c]}async delete(e){const{store:s}=this.client,a=s.getState(),n=Ds(e)(a);if(!n)throw new Error(`Expected asset type with uuid ${e} to exist`);const c=us(e)(a),r=dc(e)(a);return this.dispatch(zs(e)),this.dispatch(Dn(c.map(u=>u.uuid))),this.dispatch(Rs(r.map(({uuid:u})=>u))),this.enqueueRequest({description:"Delete asset type",method:l.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(u=>{throw this.dispatch(ks(n)),this.dispatch(cs(c)),this.dispatch(Fs(r)),u})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset types",method:l.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch($c(s))}}class rf extends P{add(e){var u;const{store:s}=this.client,a=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch($s(c));const r=this.enqueueRequest({description:"Create Category",method:l.POST,url:"/categories/",payload:_(c),blockers:[e.project],blocks:[c.uuid]});return[c,r]}update(e){const s=this.client.store.getState(),a=Gs(e.uuid)(s);if(!a)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const n={...a,...e};this.dispatch(Kc(n));const c=this.enqueueRequest({description:"Edit Category",method:l.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[n,c]}remove(e){const{store:s}=this.client,a=Gs(e)(s.getState());if(!a)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(Yc(e));const n=this.enqueueRequest({description:"Delete Category",method:l.DELETE,url:`/categories/${a.uuid}/`,blockers:[a.uuid],blocks:[]});return n.catch(()=>{this.dispatch($s(a))}),n}async refreshStore(e){const s=await this.enqueueRequest({description:"Get categories",method:l.GET,url:"/categories/",queryParams:{project:e},blocks:[],blockers:[]});this.dispatch(Wc(s))}}class df extends Fe{constructor(){super(...arguments);f(this,"name","Document Attachment");f(this,"url","/document-attachments");f(this,"addAttachments",Qc);f(this,"updateAttachments",er);f(this,"removeAttachments",sr);f(this,"removeAttachment",tr);f(this,"setAttachment",xc);f(this,"selectAttachment",nr)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,document:s.modelUuid})}buildAttachmentPayload(s){return{...s,document:s.modelUuid}}async bulkAdd(s){var p;const{store:a}=this.client,n=(p=a.getState().userReducer.currentUser)==null?void 0:p.uuid,c=new Date().toISOString(),r=[],u=[],m={},d={};for(const A of s){const{documentUuid:y,file:b}=A,I=await this.getFilePayload(b);I.sha1 in m||(m[I.sha1]=I,d[I.sha1]=[]);const T=this.buildOfflineAttachment({file:b,file_sha1:I.sha1,submitted_at:c,created_by:n,description:"",modelUuid:y});r.push(T),u.push({uuid:T.uuid,file_name:T.file_name,file_sha1:T.file_sha1,file_extension:I.extension,description:T.description,document:y}),d[I.sha1].push(T.uuid)}this.dispatch(this.addAttachments(r));const h=this.enqueueRequest({description:"Attach files to document",method:l.POST,url:"/document-attachments/bulk/",payload:{submitted_at:c,attachments:u,files:Object.values(m)},blocks:r.map(A=>A.uuid),blockers:r.map(A=>A.file_sha1)});return h.then(({attachments:A,presigned_urls:y})=>{this.dispatch(this.updateAttachments(A));const b=this.processPresignedUrls(y);for(const[I,T]of Object.entries(b))T.then(()=>{const O=d[I];for(const M of O)this.makeReadable(M)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(A=>A.uuid)))}),[r,h.then(({attachments:A})=>A)]}async delete(s){return this._delete(s)}makeReadable(s){this.enqueueRequest({description:"Add attachment to AI assistant",method:l.PATCH,url:`/document-attachments/${s}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",s],blocks:["index-document-attachment"]})}async refreshStore(s,a){const n=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/projects/${s}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(Zc(n));const c=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/organizations/${a}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(this.addAttachments(c))}}class uf extends P{add(e){var u;const{store:s}=this.client,a=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(ur([c]));const r=this.enqueueRequest({description:"Create Document",method:l.POST,url:"/documents/",payload:_(c),queryParams:{parent_document:c.parent_document??void 0},blockers:c.parent_document?[c.parent_document]:[],blocks:[c.uuid]});return r.catch(()=>{this.dispatch(Hs([c.uuid]))}),[c,r]}update(e){const{store:s}=this.client,a=s.getState().documentsReducer.documents[e.uuid];if(!a)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const n={...a,...e};this.dispatch(Ae([n]));const c=this.enqueueRequest({description:"Update Document",method:l.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{Ae([a])}),[n,c]}move(e,s,a){const{store:n}=this.client,c=_e(n.getState()),r=[],u=c[e];if(!u)throw new Error(`attempting to move a document with uuid ${e} that does not exist in store.documents`);if(r.push(u),u.parent_document&&r.push(c[u.parent_document]),s){const d=c[s];if(!d)throw new Error(`attempting to move a document to target with uuid ${s} that does not exist in store.documents`);r.push(d),d.parent_document&&r.push(c[d.parent_document])}this.dispatch(or({documentId:e,targetDocumentId:s,position:a}));const m=this.enqueueRequest({description:"Move Document",method:l.PATCH,url:`/documents/${e}/move/`,queryParams:{target:s??void 0,position:a},blockers:[e],blocks:[]});return m.then(d=>{this.dispatch(Ae(d))}).catch(()=>{this.dispatch(Ae(r))}),m}delete(e){const{store:s}=this.client,a=_e(s.getState()),n=hr(e)(s.getState());if(!n)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const c=n.parent_document?a[n.parent_document]:void 0;this.dispatch(Hs([e]));const r=this.enqueueRequest({description:"Delete Document",method:l.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(u=>{this.dispatch(Ae(u))}).catch(()=>{this.dispatch(Ae([n])),c&&this.dispatch(Ae([c]))}),r}async refreshStore(e,s){const a=this.enqueueRequest({description:"Get project documents",method:l.GET,url:`/projects/${e}/documents/`,blockers:[],blocks:[]}),n=this.enqueueRequest({description:"Get organization documents",method:l.GET,url:`/organizations/${s}/documents/`,blockers:[],blocks:[]});this.dispatch(dr([...await a,...await n]))}}class of extends P{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:l.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,s=void 0){return this.enqueueRequest({description:"Validate verification code",method:l.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:s,blockers:[],blocks:[]})}}const Tt={},ya=new Set;let bt=0,fa=0,Sa=0;const lf=20;class hf extends P{constructor(){super(...arguments);f(this,"host");f(this,"_dbPromise",_l.openDB("fileCache",1,{upgrade(s){s.createObjectStore("files")}}))}async renewUploadUrl(s){const a=await this.fetchCache(s);if(!a)throw new Error(`File with sha1 ${s} not found in cache`);const n=await Et(a,s),c=await this.enqueueRequest({description:"Get S3 URL",method:l.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await Oe(a),file_type:a.type,extension:a.name.split(".").pop(),size:a.size.toString()},blockers:[],blocks:[`s3-${n}`]});return"url"in c&&this.dispatch(yr({sha1:s,...c})),c}async addCache(s,a){if(ya.has(a))return;if(!s.type){const r=s.name.split("."),u=r[r.length-1];s=new File([s],s.name,{type:u})}if(!s.name||!s.size||!s.type)throw new Error("Cannot add files to cache that do not have a name, size and type.");const n=await this._dbPromise;!!await n.get("files",a)?(console.error("File already cached (this is unexpected at this point):",s.name,a),bt++):(await n.put("files",s,a),fa++),ya.add(a),Sa++,Sa%lf===0&&console.debug(`File cache summary: ${bt} hits and ${fa} misses, ${bt/(bt+fa)*100}% hit rate over ${Sa} calls to addCache.`)}async removeCache(s){await(await this._dbPromise).delete("files",s),ya.delete(s)}async fetchCache(s){return(await this._dbPromise).get("files",s)}async getOrRenewUploadUrl(s){const a=this.client.store.getState();return fr(s)(a)??await this.renewUploadUrl(s)}async uploadFileToS3(s){const a=await this.fetchCache(s);if(!a)throw new Error(`File with sha1 ${s} not found in cache`);const n=await Et(a,s),c={file_name:a.name,file_sha1:s,file:n},r=await this.getOrRenewUploadUrl(s);if("warning"in r){if(r.warning==="already_uploaded")return[c,Promise.resolve(void 0).then()];throw new Error(r.warning)}const u=r.url,m=this.enqueueRequest({url:u,description:"Upload file",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:s,blockers:[`s3-${n}`],blocks:[s],s3url:r});return[c,m]}async fetchFileFromUrl(s,a,n){const c=s.split("?")[0]??s,r=await this.fetchCache(a);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(s.startsWith("blob:")){const h=await Ea(s),p=new File([h],n??a,{type:h.type});return await this.addCache(p,a),p}let u=Tt[c],m=!0;u?m=!1:(u=new Promise(h=>{this.enqueueRequest({description:"Download file",method:l.GET,url:s,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[a],blocks:[a]}).then(p=>{const A=new File([p],n??a,{type:p.type});h(A)})}),Tt[c]=u);let d;try{d=await u}catch(h){throw m&&h instanceof q&&delete Tt[c],h}if(m){const h=await Oe(d);if(h!==a){const y=`The hash of the file returned from the server (${h}) does not match the
9
- expected hash (${a}). This can happen if you're using a local development server and the
4
+ Retries:`,s),!(t instanceof Error))throw console.error("ENCOUNTERED NON-ERROR ERROR:",t,"(throwing immediately, which may lead to unexpected behavior)"),t;const n=Ye(),c=n.getState().outboxReducer.deletedRequests,r=e.payload.uuid;function u(){n.dispatch(Po(r));const o=Ie();if(!o)throw new Error("Outbox coordinator not set");o.remove(e.payload.uuid);const p=e.meta.offline.rollback;throw p&&(console.warn("Rolling back request due to SDK error:",e),n.dispatch(p)),t}if(t instanceof q&&t.options.discard)return console.debug("Discarding request due to explicit discard:",e),u();if(c.includes(r))return console.debug("Discarding request due to deletion:",e),u();if(t instanceof q){const o=t.status||((d=t.response)==null?void 0:d.status);if(o||console.warn("Error has no status code:",t),o!==void 0&&gl.includes(o)){console.warn("Discarding request due to error:",t,`
5
+ Action:`,e);const p=Ie();if(!p)throw new Error("Outbox coordinator not set");p.remove(e.payload.uuid),t.options.discard=!0,u()}}console.debug("Registering a retry for request:",e.payload.uuid);const m=Ie();if(!m)throw new Error("Outbox coordinator not set");return m.registerRetry(e.payload.uuid),!1}function Vy(t,e,s){var n;return(n=Ie())==null?void 0:n.peek()}function Dy(t,e){return Ye().dispatch(Oo(new Date().getTime())),_n}const qe="An unknown error occurred",Uy=500,Tl=["non_field_errors","detail"];function $y(t,e){let s;if(t!=null&&t.body)if(typeof t.body=="object"){const n=t.body;if(typeof n.error=="string")s=n.error;else if(typeof n.message=="string")s=n.message;else try{s=Object.entries(n).map(([a,c])=>typeof c=="string"?Tl.includes(a)?c:`${a}: ${c}`:Array.isArray(c)?Tl.includes(a)?c.join(`
6
+ `):c.map(r=>`${a}: ${r}`).join(`
7
+ `):`${a}: ${JSON.stringify(c)}`).join(`
8
+ `)}catch(a){console.error("Failed to extract error message from response body",a)}}else typeof t.body=="string"&&(s=t.body);else t!=null&&t.text?s=t.text:e instanceof Error&&(s=e.message);return!s||s.length>Uy?qe:s}class q extends Error{constructor(s){super(qe);f(this,"status");f(this,"response");f(this,"message");f(this,"options");const{response:n,innerError:a}=s;this.message=s.message??$y(n,a)??qe,this.status=(n==null?void 0:n.status)??0,this.response=n,s.discard=s.discard??!1,this.options=s}}class By extends rl{constructor(e){super(e)}}class P extends rl{constructor(s,n){super(s);f(this,"auth");this.auth=n}}class Gy extends P{async startConversation(e,s){return this.enqueueRequest({description:"Start agent conversation",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:s},blockers:["prompt"],blocks:["prompt"]}).then(n=>(this.dispatch(Dn(n)),n))}async continueConversation(e,s,n){return this.enqueueRequest({description:"Prompt agent",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:s}}).then(a=>{this.dispatch($n(a))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:h.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(s=>{this.dispatch(Un(s))})}async rate(e,s){return this.enqueueRequest({description:"Rate agent response",method:h.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:s},blockers:["rate"],blocks:["rate"]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get agent conversation history",method:h.GET,url:`/projects/${e}/agent-conversations/`,blockers:["agent-conversations"],blocks:["agent-conversations"]});this.dispatch(Vn(s))}}class E extends P{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:s,assetAttachmentReducer:n,assetTypeAttachmentReducer:a,documentAttachmentReducer:c,projectAttachmentReducer:r,formRevisionAttachmentReducer:u,formSubmissionAttachmentReducer:m,geoImageReducer:d,assetTypeFieldsAttachmentReducer:o,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:A,issueTypeFieldValuesAttachmentReducer:y}=this.client.store.getState();return[].concat(Object.values(s.instances),Object.values(n.instances),Object.values(a.instances),Object.values(c.instances),Object.values(r.instances),Object.values(u.instances),Object.values(m.instances),Object.values(d.instances),Object.values(o.instances),Object.values(p.instances),Object.values(A.instances),Object.values(y.instances)).filter(I=>I.file_sha1===e).length}processPresignedUrls(e){const s={};for(const[n,a]of Object.entries(e))s[n]=this.enqueueRequest({url:a.url,description:"Upload file to S3",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:n,blockers:[`s3-${a.fields.key}`],blocks:[n],s3url:a});return s}async getFilePayload(e){const s=await Oe(e),n={sha1:s,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,s),n}}class Fe extends E{async _bulkAdd(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.uuid,a=new Date().toISOString(),c=[],r=[],u={};for(const o of e){const{modelUuid:p,file:A}=o,y=await this.getFilePayload(A);y.sha1 in u||(u[y.sha1]=y);const b=this.buildOfflineAttachment({file:A,file_sha1:y.sha1,submitted_at:a,created_by:n,description:"",modelUuid:p});c.push(b),r.push(this.buildAttachmentPayload({uuid:b.uuid,file_name:b.file_name,file_sha1:b.file_sha1,file_extension:y.extension,description:b.description,modelUuid:p}))}this.dispatch(this.addAttachments(c));const m=this.enqueueRequest({description:`Add ${this.name}`,method:h.POST,url:`${this.url}/bulk/`,payload:{submitted_at:a,attachments:r,files:Object.values(u)},blocks:c.map(o=>o.uuid),blockers:c.map(o=>o.file_sha1)});return m.then(({attachments:o,presigned_urls:p})=>{this.dispatch(this.updateAttachments(o)),this.processPresignedUrls(p)}).catch(()=>{this.dispatch(this.removeAttachments(c.map(o=>o.uuid)))}),[c,m.then(({attachments:o})=>o)]}async _delete(e){const{store:s}=this.client,n=this.selectAttachment(e)(s.getState());if(!n)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(n.uuid));const a=this.enqueueRequest({description:`Delete ${this.name}`,method:h.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return a.then(()=>{this.getNumberOfAttachmentsWithSha1(n.file_sha1)===0&&this.client.files.removeCache(n.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(n))}),a}}class Ly extends Fe{constructor(){super(...arguments);f(this,"name","Asset Attachment");f(this,"url","/asset-attachments");f(this,"initializeAttachments",Ct);f(this,"addAttachments",kt);f(this,"updateAttachments",Nn);f(this,"removeAttachments",zt);f(this,"removeAttachment",Hn);f(this,"setAttachment",Ln);f(this,"selectAttachment",Yn)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.assetUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset attachments",method:h.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(Ct(n))}}class Ny extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(xn(c));const u=this.enqueueRequest({description:"Add asset procedure fields attachments",method:h.POST,url:"/asset-procedure-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(ea(d.attachments))}).catch(()=>{this.dispatch(ta(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure fields attachments",method:h.GET,url:"/asset-procedure-fields-attachments/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Qn(s))}}class Hy extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ra(c));const r=this.enqueueRequest({description:"Add Asset Procedure Fields",method:h.POST,url:"/asset-procedure-fields/",payload:c,blockers:[c.asset_procedure],blocks:[c.uuid]});return r.then(m=>{this.dispatch(da(m))}).catch(m=>{throw this.dispatch(ua(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Procedure Fields",method:h.GET,url:"/asset-procedure-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(ca(s))}}function Je(t,e){const s=[];let n=0;const a=t.length;for(;n<a;)s.push(t.slice(n,n+=e));return s}class Wy extends E{async bulkAdd(e,s){var d;const n=new Date().toISOString(),a=(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.uuid,c=Je(e,s??e.length),r=[],u=[];for(const o of c){const p={},A=[];for(const y of o){const{fieldValuesUuid:b,fieldIdentifier:I,file:T}=y,O=await this.getFilePayload(T);O.sha1 in p||(p[O.sha1]=O);const M=R({file:URL.createObjectURL(T),file_type:T.type,file_name:T.name,file_sha1:O.sha1,created_by:a,field_values:b,submitted_at:n,field_identifier:I});r.push(M);const It={uuid:M.uuid,file_name:T.name,file_sha1:O.sha1,file_extension:O.extension,field_identifier:I,field_values:b};A.push(It)}u.push({submitted_at:n,attachments:A,files:Object.values(p)})}this.dispatch(Qe(r));const m=u.map(o=>this.enqueueRequest({description:"Add asset procedure field values attachments",method:h.POST,url:"/asset-procedure-field-values-attachments/bulk/",payload:o,blockers:o.attachments.map(p=>p.field_values),blocks:o.attachments.map(p=>p.uuid)}));return Promise.all(m).then(o=>{for(const A of o)this.processPresignedUrls(A.presigned_urls);const p=o.flatMap(A=>A.attachments);this.dispatch(pa(p))}).catch(o=>{throw this.dispatch(xe(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=ya(e)(n);this.dispatch(xe(e));try{await this.enqueueRequest({description:"Delete asset procedure field values attachments",method:h.DELETE,url:"/asset-procedure-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(Qe(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values attachments",method:h.GET,url:"/asset-procedure-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(ma(s))}}const Ky=t=>Array.isArray(t)&&t[0]instanceof File,Xe=t=>{const e={},s={};for(const n in t){const a=t[n];a instanceof File?e[n]=[a]:Ky(a)?e[n]=a:a!==void 0&&(s[n]=a)}return{values:s,files:e}};class Yy extends E{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.uuid,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add form submission",method:h.POST,url:"/form-submissions/",payload:_(a),blockers:["add-form-entry",e.form_revision,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[a.uuid]});return this.dispatch(ii(a)),c.then(u=>(this.dispatch(ut(u)),u)).catch(()=>{this.dispatch(ni(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=ri(e.uuid)(n);if(!a)throw new Error(`Expected submission with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(Kr(c));const r=this.enqueueRequest({description:"Delete user form submissions",method:h.PATCH,url:`/form-submissions/${c.uuid}/`,payload:e,blockers:[c.uuid],blocks:[c.uuid]});return r.then(u=>{this.dispatch(ut(u))}).catch(()=>{this.dispatch(ut(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=ri(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Lr(e)(n);this.dispatch(ni(e)),this.dispatch(dt(c.map(r=>r.uuid)));try{return await this.enqueueRequest({description:"Delete user form submissions",method:h.DELETE,url:`/form-submissions/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ii(a)),this.dispatch(rt(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch form submissions",method:h.GET,url:"/form-submissions/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Wr(s))}}class Jy extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.uuid,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/",payload:_(a),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[a.uuid]});return this.dispatch(Lt(a)),c.then(u=>(this.dispatch(ze(u)),u)).catch(()=>{this.dispatch(Nt(a.uuid))}),[a,c]}bulkAdd(e,s){var d;const n=new Date().toISOString(),{values:a}=Xe(e.values),c=[],r=Je(e.payloads,s??e.payloads.length),u=[];for(const o of r){const p=[];for(const A of o){const y=R({...A,values:Xe(A.values).values,created_by:(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.uuid,submitted_at:n});c.push(y),p.push({uuid:y.uuid,asset:A.asset,fields_revision:A.fields_revision,asset_procedure_instance:A.asset_procedure_instance,published_at:A.published_at,values:y.values})}u.push({submitted_at:n,values:a,field_values:p})}this.dispatch(ba(c));const m=[];for(const o of u){const p=o.field_values.map(T=>T.asset),A=o.field_values.map(T=>T.fields_revision),y=o.field_values.map(T=>T.asset_procedure_instance),b=o.field_values.map(T=>T.uuid),I=this.enqueueRequest({description:"Bulk add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/bulk/",payload:o,blockers:[...p,...A,...y],blocks:b});m.push(I)}return Promise.all(m).then(o=>{this.dispatch(Ia(o.flat()))}).catch(()=>{this.dispatch(Fa(c.map(o=>o.uuid)))}),[c,m]}update(e){const{store:s}=this.client,n=s.getState(),a=Wt(e.uuid)(n);if(!a)throw new Error(`Expected AssetProcedureFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(ze(c));const r=this.enqueueRequest({description:"Update asset procedure field values",method:h.PATCH,url:`/asset-procedure-field-values/${e.uuid}/`,payload:e,blockers:[c.fields_revision,c.asset,c.asset_procedure_instance],blocks:[c.uuid]});return r.then(u=>{this.dispatch(ze(u))}).catch(()=>{this.dispatch(ze(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Wt(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=fa(e)(n);this.dispatch(Nt(e)),this.dispatch(xe(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure field values",method:h.DELETE,url:`/asset-procedure-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Lt(a)),this.dispatch(Qe(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values",method:h.GET,url:"/asset-procedure-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Ta(s))}}class Xy extends P{add(e){const{store:s}=this.client,n=s.getState().userReducer.currentUser.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Yt(c));const r=this.enqueueRequest({description:"Create asset procedure instance",method:h.POST,url:"/asset-procedure-instances/",payload:_(c),blockers:[e.asset_procedure,e.asset_type],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Ve(u))}).catch(()=>{this.dispatch(Jt(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=Qt(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset procedure instance with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(Ve(a));const c=this.enqueueRequest({description:"Update asset procedure instance",method:h.PATCH,url:`/asset-procedure-instances/${e.uuid}/`,payload:e,blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Ve(r))}).catch(()=>{this.dispatch(Ve(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=Qt(e)(n);if(!a)throw new Error(`Expected asset procedure instance with uuid ${e} to exist`);return this.dispatch(Jt(e)),this.enqueueRequest({description:"Delete asset procedure instance",method:h.DELETE,url:`/asset-procedure-instances/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(Yt(a)),c})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure instances",method:h.GET,url:"/asset-procedure-instances/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(_a(s))}}class Zy extends P{add(e){const{store:s}=this.client,n=s.getState().userReducer.currentUser.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(es(c));const r=this.enqueueRequest({description:"Create asset procedure",method:h.POST,url:"/asset-procedures/",payload:_(c),blockers:[],blocks:[c.uuid]});return r.then(u=>{this.dispatch(De(u))}).catch(()=>{this.dispatch(ts(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=is(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(De(a));const c=this.enqueueRequest({description:"Update asset procedure",method:h.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(De(r))}).catch(()=>{this.dispatch(De(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=is(e)(n);if(!a)throw new Error(`Expected asset procedure with uuid ${e} to exist`);const c=Ea(e)(n);return this.dispatch(ts(e)),this.dispatch(wa(c.map(r=>r.uuid))),this.enqueueRequest({description:"Delete asset procedure",method:h.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(es(a)),this.dispatch(va(c)),r})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedures",method:h.GET,url:"/asset-procedures/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Ma(s))}}class Qy extends P{add(e){const{store:s}=this.client;if(!e.canvas_marker&&!e.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");const n=s.getState().userReducer.currentUser.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(as(c));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/assets/",payload:_(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Ue(u))}).catch(()=>{this.dispatch(rs(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=os(e.uuid)(s.getState());if(!n)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const a={...n,...e};if(!a.canvas_marker&&!a.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");this.dispatch(Ue(a));const c=this.enqueueRequest({description:"Edit asset",method:h.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(Ue(r))}).catch(()=>{this.dispatch(Ue(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=os(e)(n);if(!a)throw new Error(`No asset with uuid ${e} found in the store`);const c=Jn(e)(n),r=Xr(e)(n),u=pd(e)(n);if(this.dispatch(rs(e)),c.length>0){const m=c.map(({uuid:d})=>d);this.dispatch(zt(m))}if(r.length>0){const m=r.map(({uuid:d})=>d);this.dispatch(lt(m))}if(u.length>0){const m=u.map(({uuid:d})=>d);this.dispatch(Ai(m))}return this.enqueueRequest({description:"Delete asset",method:h.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(as(a)),this.dispatch(kt(c)),this.dispatch(ot(r)),this.dispatch(mi(u)),m})}bulkAdd(e,s,n,a){const c=new Date().toISOString(),r=ye.v4(),u=Je(e,a).map(o=>{const p=o.map(A=>R(A));return{batchId:ye.v4(),payload:{transaction_id:r,submitted_at:c,asset_type:s,project:n,assets:p}}}),m=[];let d=null;for(const o of u){const{batchId:p,payload:A}=o,y=A.assets.map(O=>O.uuid),b=[s];d&&b.push(d);const I=y;I.push(p);const T=this.enqueueRequest({description:"Batch create assets",method:h.POST,url:"/assets/bulk/",payload:A,blockers:b,blocks:I});d=o.batchId,m.push(T)}return Promise.all(m).then(o=>{const p=o.flat();this.dispatch(cs(p))}),m}async refreshStore(e){const s=await this.enqueueRequest({description:"Get assets",method:h.GET,url:"/assets/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Va(s))}}class xy extends P{add(e){const{store:s}=this.client,n=s.getState().userReducer.currentUser.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(hs(c));const r=this.enqueueRequest({description:"Add asset stage completion",method:h.POST,url:"/asset-stage-completions/",payload:_(c),blockers:[e.asset,e.stage],blocks:[c.uuid]});return r.then(u=>{this.dispatch(La(u))}).catch(()=>{this.dispatch(ps(c.uuid))}),[c,r]}delete(e){const{store:s}=this.client,n=Wa(e)(s.getState());if(!n)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(ps(e));const a=this.enqueueRequest({description:"Delete asset stage completion",method:h.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(hs(n))}),a}bulkAdd(e){const{store:s}=this.client,n=new Date().toISOString(),a=s.getState().userReducer.currentUser.uuid,c=e.map(d=>R(d)),r=c.map(d=>({...d,created_by:a,submitted_at:n})),u=r.map(({uuid:d})=>d);this.dispatch(ms(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:h.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:n,completions:c},blockers:[...e.map(d=>d.asset_procedure_instance),...e.map(d=>d.stage),...e.map(d=>d.asset)],blocks:u});return m.then(d=>{this.dispatch(Na(d))}).catch(()=>{this.dispatch(As(u))}),[r,m]}bulkDelete(e){const{store:s}=this.client,n=Ka(e)(s.getState());this.dispatch(As(e));const a=this.enqueueRequest({description:"Deleting asset stage completions",method:h.DELETE,url:"/asset-stage-completions/bulk/",payload:{completion_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(ms(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stage completions",method:h.GET,url:"/asset-stage-completions/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Ga(s))}}class ef extends P{bulkAdd(e,s){const n=new Date().toISOString(),a=this.client.store.getState().userReducer.currentUser.uuid,c=e.map(m=>R(m)),r=c.map(m=>({...m,asset_procedure:s,created_by:a,submitted_at:n}));this.dispatch(Ss(r));const u=this.enqueueRequest({description:"Add asset stages",method:h.POST,url:"/asset-stages/bulk/",payload:{submitted_at:n,asset_procedure:s,stages:c},blockers:[s],blocks:c.map(({uuid:m})=>m)});return u.then(m=>{this.dispatch(et(m))}).catch(()=>{this.dispatch(Ts(r.map(({uuid:m})=>m)))}),[r,u]}async bulkUpdate(e,s){const a=this.client.store.getState(),c=bs(e.map(({uuid:r})=>r))(a);return this.dispatch(et(e)),this.enqueueRequest({description:"Edit asset stages",method:h.PATCH,url:`/asset-procedures/${s}/bulk-update-stages/`,payload:{stages:e},blockers:[s],blocks:e.map(({uuid:r})=>r)}).catch(r=>{throw this.dispatch(et(c)),r})}async bulkDelete(e){const{store:s}=this.client,n=bs(e)(s.getState());this.dispatch(Ts(e));const a=this.enqueueRequest({description:"Delete asset stages",method:h.DELETE,url:"/asset-stages/bulk/",payload:{stage_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(Ss(n))}),a}update(e){const{store:s}=this.client,n=Qa(e.uuid)(s.getState());if(!n)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const a={...n,...e};this.dispatch(gs(a));const c=this.enqueueRequest({description:"Update asset stage",method:h.PATCH,url:`/asset-stages/${n.uuid}/`,payload:{name:e.name,description:e.description,priority:e.priority,color:e.color},blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(gs(r))}).catch(()=>{this.dispatch(Xa(n))}),[a,c]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stages",method:h.GET,url:"/asset-stages/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Ja(s))}}class tf extends Fe{constructor(){super(...arguments);f(this,"name","Asset Type Attachment");f(this,"url","/asset-type-attachments");f(this,"addAttachments",Fs);f(this,"updateAttachments",ic);f(this,"removeAttachments",Rs);f(this,"removeAttachment",nc);f(this,"setAttachment",sc);f(this,"selectAttachment",rc)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.assetTypeUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset type attachments",method:h.GET,url:`${this.url}/`,queryParams:{organization:s},blocks:[],blockers:[]});this.dispatch(tc(n))}}class sf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(hc(c));const u=this.enqueueRequest({description:"Add asset type fields attachments",method:h.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(mc(d.attachments))}).catch(()=>{this.dispatch(pc(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type fields attachments",method:h.GET,url:"/asset-type-fields-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(lc(s))}}class nf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Tc(c));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:h.POST,url:"/asset-type-fields/",payload:c,blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(bc(m))}).catch(m=>{throw this.dispatch(Ic(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Type Fields",method:h.GET,url:"/asset-type-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(gc(s))}}class af extends E{async bulkAdd(e,s){var d;const n=new Date().toISOString(),a=(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.uuid,c=Je(e,s??e.length),r=[],u=[];for(const o of c){const p={},A=[];for(const y of o){const{fieldValuesUuid:b,fieldIdentifier:I,file:T}=y,O=await this.getFilePayload(T);O.sha1 in p||(p[O.sha1]=O);const M=R({file:URL.createObjectURL(T),file_type:T.type,file_name:T.name,file_sha1:O.sha1,created_by:a,field_values:b,submitted_at:n,field_identifier:I});r.push(M);const It={uuid:M.uuid,file_name:T.name,file_sha1:O.sha1,file_extension:O.extension,field_identifier:I,field_values:b};A.push(It)}u.push({submitted_at:n,attachments:A,files:Object.values(p)})}this.dispatch(it(r));const m=u.map(o=>this.enqueueRequest({description:"Add asset type field values attachments",method:h.POST,url:"/asset-type-field-values-attachments/bulk/",payload:o,blockers:o.attachments.map(p=>p.field_values),blocks:o.attachments.map(p=>p.uuid)}));return Promise.all(m).then(o=>{for(const A of o)this.processPresignedUrls(A.presigned_urls);const p=o.flatMap(A=>A.attachments);this.dispatch(_c(p))}).catch(o=>{throw this.dispatch(nt(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=wc(e)(n);this.dispatch(nt(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:h.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(it(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values attachments",method:h.GET,url:"/asset-type-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Oc(s))}}class cf extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.uuid,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset type field values",method:h.POST,url:"/asset-type-field-values/",payload:_(a),blockers:[e.asset,e.fields_revision],blocks:[a.uuid]});return this.dispatch(Es(a)),c.then(u=>(this.dispatch($e(u)),u)).catch(()=>{this.dispatch(js(a.uuid))}),[a,c]}bulkAdd(e,s){var d;const n=new Date().toISOString(),{values:a}=Xe(e.values),c=[],r=Je(e.payloads,s??e.payloads.length),u=[];for(const o of r){const p=[];for(const A of o){const y=R({...A,values:Xe(A.values).values,created_by:(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.uuid,submitted_at:n});c.push(y),p.push({uuid:y.uuid,asset:A.asset,fields_revision:A.fields_revision,published_at:A.published_at,values:y.values})}u.push({submitted_at:n,values:a,field_values:p})}this.dispatch(Cc(c));const m=[];for(const o of u){const p=o.field_values.map(I=>I.asset),A=o.field_values.map(I=>I.fields_revision),y=o.field_values.map(I=>I.uuid),b=this.enqueueRequest({description:"Bulk add asset type field values",method:h.POST,url:"/asset-type-field-values/bulk/",payload:o,blockers:[...p,...A],blocks:y});m.push(b)}return Promise.all(m).then(o=>{this.dispatch(kc(o.flat()))}).catch(()=>{this.dispatch(zc(c.map(o=>o.uuid)))}),[c,m]}update(e){const{store:s}=this.client,n=s.getState(),a=Ms(e.uuid)(n);if(!a)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch($e(c));const r=this.enqueueRequest({description:"Delete asset type field values",method:h.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.asset],blocks:[c.uuid]});return r.then(u=>{this.dispatch($e(u))}).catch(()=>{this.dispatch($e(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Ms(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Ec(e)(n);this.dispatch(js(e)),this.dispatch(nt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:h.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Es(a)),this.dispatch(it(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values",method:h.GET,url:"/asset-type-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Mc(s))}}class rf extends P{add(e){const{store:s}=this.client,n=s.getState().userReducer.currentUser.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ks(c));const r=this.enqueueRequest({description:"Create asset type",method:h.POST,url:"/asset-types/",payload:_(c),blockers:[],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Be(u))}).catch(()=>{this.dispatch(zs(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=Ds(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(Be(a));const c=this.enqueueRequest({description:"Update asset type",method:h.PATCH,url:`/asset-types/${e.uuid}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Be(r))}).catch(()=>{this.dispatch(Be(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Ds(e)(n);if(!a)throw new Error(`Expected asset type with uuid ${e} to exist`);const c=us(e)(n),r=dc(e)(n);return this.dispatch(zs(e)),this.dispatch(Da(c.map(u=>u.uuid))),this.dispatch(Rs(r.map(({uuid:u})=>u))),this.enqueueRequest({description:"Delete asset type",method:h.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(u=>{throw this.dispatch(ks(a)),this.dispatch(cs(c)),this.dispatch(Fs(r)),u})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset types",method:h.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch($c(s))}}class df extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch($s(c));const r=this.enqueueRequest({description:"Create Category",method:h.POST,url:"/categories/",payload:_(c),blockers:[e.project],blocks:[c.uuid]});return[c,r]}update(e){const s=this.client.store.getState(),n=Gs(e.uuid)(s);if(!n)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const a={...n,...e};this.dispatch(Kc(a));const c=this.enqueueRequest({description:"Edit Category",method:h.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[a,c]}remove(e){const{store:s}=this.client,n=Gs(e)(s.getState());if(!n)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(Yc(e));const a=this.enqueueRequest({description:"Delete Category",method:h.DELETE,url:`/categories/${n.uuid}/`,blockers:[n.uuid],blocks:[]});return a.catch(()=>{this.dispatch($s(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get categories",method:h.GET,url:"/categories/",queryParams:{project:e},blocks:[],blockers:[]});this.dispatch(Wc(s))}}class uf extends Fe{constructor(){super(...arguments);f(this,"name","Document Attachment");f(this,"url","/document-attachments");f(this,"addAttachments",Qc);f(this,"updateAttachments",er);f(this,"removeAttachments",sr);f(this,"removeAttachment",tr);f(this,"setAttachment",xc);f(this,"selectAttachment",ar)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,document:s.modelUuid})}buildAttachmentPayload(s){return{...s,document:s.modelUuid}}async bulkAdd(s){var p;const{store:n}=this.client,a=(p=n.getState().userReducer.currentUser)==null?void 0:p.uuid,c=new Date().toISOString(),r=[],u=[],m={},d={};for(const A of s){const{documentUuid:y,file:b}=A,I=await this.getFilePayload(b);I.sha1 in m||(m[I.sha1]=I,d[I.sha1]=[]);const T=this.buildOfflineAttachment({file:b,file_sha1:I.sha1,submitted_at:c,created_by:a,description:"",modelUuid:y});r.push(T),u.push({uuid:T.uuid,file_name:T.file_name,file_sha1:T.file_sha1,file_extension:I.extension,description:T.description,document:y}),d[I.sha1].push(T.uuid)}this.dispatch(this.addAttachments(r));const o=this.enqueueRequest({description:"Attach files to document",method:h.POST,url:"/document-attachments/bulk/",payload:{submitted_at:c,attachments:u,files:Object.values(m)},blocks:r.map(A=>A.uuid),blockers:r.map(A=>A.file_sha1)});return o.then(({attachments:A,presigned_urls:y})=>{this.dispatch(this.updateAttachments(A));const b=this.processPresignedUrls(y);for(const[I,T]of Object.entries(b))T.then(()=>{const O=d[I];for(const M of O)this.makeReadable(M)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(A=>A.uuid)))}),[r,o.then(({attachments:A})=>A)]}async delete(s){return this._delete(s)}makeReadable(s){this.enqueueRequest({description:"Add attachment to AI assistant",method:h.PATCH,url:`/document-attachments/${s}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",s],blocks:["index-document-attachment"]})}async refreshStore(s,n){const a=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:`/projects/${s}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(Zc(a));const c=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:`/organizations/${n}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(this.addAttachments(c))}}class of extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ur([c]));const r=this.enqueueRequest({description:"Create Document",method:h.POST,url:"/documents/",payload:_(c),queryParams:{parent_document:c.parent_document??void 0},blockers:c.parent_document?[c.parent_document]:[],blocks:[c.uuid]});return r.catch(()=>{this.dispatch(Hs([c.uuid]))}),[c,r]}update(e){const{store:s}=this.client,n=s.getState().documentsReducer.documents[e.uuid];if(!n)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const a={...n,...e};this.dispatch(Ae([a]));const c=this.enqueueRequest({description:"Update Document",method:h.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{Ae([n])}),[a,c]}move(e,s,n){const{store:a}=this.client,c=_e(a.getState()),r=[],u=c[e];if(!u)throw new Error(`attempting to move a document with uuid ${e} that does not exist in store.documents`);if(r.push(u),u.parent_document&&r.push(c[u.parent_document]),s){const d=c[s];if(!d)throw new Error(`attempting to move a document to target with uuid ${s} that does not exist in store.documents`);r.push(d),d.parent_document&&r.push(c[d.parent_document])}this.dispatch(or({documentId:e,targetDocumentId:s,position:n}));const m=this.enqueueRequest({description:"Move Document",method:h.PATCH,url:`/documents/${e}/move/`,queryParams:{target:s??void 0,position:n},blockers:[e],blocks:[]});return m.then(d=>{this.dispatch(Ae(d))}).catch(()=>{this.dispatch(Ae(r))}),m}delete(e){const{store:s}=this.client,n=_e(s.getState()),a=hr(e)(s.getState());if(!a)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const c=a.parent_document?n[a.parent_document]:void 0;this.dispatch(Hs([e]));const r=this.enqueueRequest({description:"Delete Document",method:h.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(u=>{this.dispatch(Ae(u))}).catch(()=>{this.dispatch(Ae([a])),c&&this.dispatch(Ae([c]))}),r}async refreshStore(e,s){const n=this.enqueueRequest({description:"Get project documents",method:h.GET,url:`/projects/${e}/documents/`,blockers:[],blocks:[]}),a=this.enqueueRequest({description:"Get organization documents",method:h.GET,url:`/organizations/${s}/documents/`,blockers:[],blocks:[]});this.dispatch(dr([...await n,...await a]))}}class lf extends P{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:h.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,s=void 0){return this.enqueueRequest({description:"Validate verification code",method:h.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:s,blockers:[],blocks:[]})}}const Tt={},fn=new Set;let bt=0,Sn=0,gn=0;const hf=20;class mf extends P{constructor(){super(...arguments);f(this,"host");f(this,"_dbPromise",_l.openDB("fileCache",1,{upgrade(s){s.createObjectStore("files")}}))}async renewUploadUrl(s){const n=await this.fetchCache(s);if(!n)throw new Error(`File with sha1 ${s} not found in cache`);const a=await Et(n,s),c=await this.enqueueRequest({description:"Get S3 URL",method:h.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await Oe(n),file_type:n.type,extension:n.name.split(".").pop(),size:n.size.toString()},blockers:[],blocks:[`s3-${a}`]});return"url"in c&&this.dispatch(yr({sha1:s,...c})),c}async addCache(s,n){if(fn.has(n))return;if(!s.type){const r=s.name.split("."),u=r[r.length-1];s=new File([s],s.name,{type:u})}if(!s.name||!s.size||!s.type)throw new Error("Cannot add files to cache that do not have a name, size and type.");const a=await this._dbPromise;!!await a.get("files",n)?(console.error("File already cached (this is unexpected at this point):",s.name,n),bt++):(await a.put("files",s,n),Sn++),fn.add(n),gn++,gn%hf===0&&console.debug(`File cache summary: ${bt} hits and ${Sn} misses, ${bt/(bt+Sn)*100}% hit rate over ${gn} calls to addCache.`)}async removeCache(s){await(await this._dbPromise).delete("files",s),fn.delete(s)}async fetchCache(s){return(await this._dbPromise).get("files",s)}async getOrRenewUploadUrl(s){const n=this.client.store.getState();return fr(s)(n)??await this.renewUploadUrl(s)}async uploadFileToS3(s){const n=await this.fetchCache(s);if(!n)throw new Error(`File with sha1 ${s} not found in cache`);const a=await Et(n,s),c={file_name:n.name,file_sha1:s,file:a},r=await this.getOrRenewUploadUrl(s);if("warning"in r){if(r.warning==="already_uploaded")return[c,Promise.resolve(void 0).then()];throw new Error(r.warning)}const u=r.url,m=this.enqueueRequest({url:u,description:"Upload file",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:s,blockers:[`s3-${a}`],blocks:[s],s3url:r});return[c,m]}async fetchFileFromUrl(s,n,a){const c=s.split("?")[0]??s,r=await this.fetchCache(n);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(s.startsWith("blob:")){const o=await jn(s),p=new File([o],a??n,{type:o.type});return await this.addCache(p,n),p}let u=Tt[c],m=!0;u?m=!1:(u=new Promise(o=>{this.enqueueRequest({description:"Download file",method:h.GET,url:s,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[n],blocks:[n]}).then(p=>{const A=new File([p],a??n,{type:p.type});o(A)})}),Tt[c]=u);let d;try{d=await u}catch(o){throw m&&o instanceof q&&delete Tt[c],o}if(m){const o=await Oe(d);if(o!==n){const y=`The hash of the file returned from the server (${o}) does not match the
9
+ expected hash (${n}). This can happen if you're using a local development server and the
10
10
  isExternalUrl flag in the request details is set to true, because instead of requesting the local
11
11
  REST API, you will be requesting localhost:80 (where this app runs), resulting in a transformed blob
12
12
  (with an uuid attached) being returned. Alternatively, you may be running with
13
13
  import.meta.env.PROD, which will result in some file requests being treated as
14
- external URLs and therefore not prepended with VITE_API_URL.`;throw new Error(y)}const p=d.type.split("/")[1];if(!p)throw new Error("File has no extension");const A=n??h+"."+p;if(d=wa(d,A),!d.name)throw new Error("Failed to set file's name");await this.addCache(d,h),Tt[c]=new Promise(y=>{y(d)})}return d}}class mf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,n={},c=[],r=[];for(const d of e){const{revisionUuid:h,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in n||(n[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:a,form_revision:h,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,form_revision:h};r.push(I)}this.dispatch(br(c));const u=this.enqueueRequest({description:"Attach files to form revision",method:l.POST,url:"/form-revision-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(n)},blockers:c.map(d=>d.form_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Ir(d.attachments))}).catch(()=>{this.dispatch(Fr(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization form revision attachments",method:l.GET,url:"/form-revision-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(Tr(s))}}class pf extends E{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,c=R({...e,created_by:n,submitted_at:new Date().toISOString()});this.dispatch(Js(c));const r=this.enqueueRequest({description:"Create form revision",method:l.POST,url:"/form-revisions/",payload:_(c),blockers:[e.form],blocks:[c.uuid]});return r.then(m=>{this.dispatch(_r(m))}).catch(()=>{this.dispatch(Xs(c.uuid))}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization form revisions",method:l.GET,url:"/form-revisions/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(vr(s))}}const Af=async t=>{const e={},s=[];for(const a of t){if(a.type!=="section")throw new Error(`Expected ISerializedField type to be a section. Got ${a.type} instead.`);const{fields:n}=a,c=[];for(const r of n){if(r.image){if(r.image instanceof Promise)try{e[r.identifier]=await r.image}catch(u){console.error("Failed to get image from promise",u)}else e[r.identifier]=r.image;delete r.image}c.push(r)}s.push({...a,fields:c})}return{fields:s,images:e}};class yf extends E{add(e,s){var d;const{store:a}=this.client,n=new Date().toISOString(),c=(d=a.getState().userReducer.currentUser)==null?void 0:d.uuid,r=R({...e,submitted_at:n,created_by:c}),u=R({...s,form:r.uuid,submitted_at:n,created_by:c});this.dispatch(Qs(r)),this.dispatch(Js(u));const m=this.enqueueRequest({description:"Create form",method:l.POST,url:"/forms/",payload:{..._(r),initial_revision:{uuid:u.uuid,submitted_at:u.submitted_at,title:u.title,description:u.description,fields:u.fields}},blockers:[],blocks:[r.uuid,u.uuid]});return m.catch(h=>{throw this.dispatch(xs(r.uuid)),this.dispatch(Xs(u.uuid)),h}),[r,u,m]}async delete(e){const{store:s}=this.client,a=s.getState(),n=Dr(e)(a);if(!n)throw new Error("Expected form to exist");const c=Yr(e)(a);c.length>0&&this.dispatch(lt(c.map(({uuid:u})=>u)));const r=qr(e)(a);r.length>0&&this.dispatch(Er(r.map(({uuid:u})=>u))),this.dispatch(xs(e));try{return await this.enqueueRequest({description:"Delete form",method:l.DELETE,url:`/forms/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(Qs(n)),r.length>0&&this.dispatch(wr(r)),c.length>0&&this.dispatch(ot(c)),u}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization forms",method:l.GET,url:"/forms/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(kr(s))}}class ff extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,n={},c=[],r=[];for(const d of e){const{submissionUuid:h,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in n||(n[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:a,form_submission:h,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:p,form_submission:h};r.push(I)}this.dispatch(rt(c));const u=this.enqueueRequest({description:"Attach files to form submission",method:l.POST,url:"/form-submission-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(n)},blockers:c.map(d=>d.form_submission),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Br(d.attachments))}).catch(d=>{throw this.dispatch(dt(c.map(h=>h.uuid))),d}),[c,u.then(({attachments:d})=>d)]}async bulkDelete(e){const{store:s}=this.client,a=s.getState(),n=Gr(e)(a);this.dispatch(dt(e));try{await this.enqueueRequest({description:"Delete form submission attachments",method:l.DELETE,url:"/form-submission-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(rt(n)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get form submission attachments",method:l.GET,url:"/form-submission-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch($r(s))}}class Sf extends E{async add(e){var p;const{store:s}=this.client,{file:a,...n}=e,c=new Date().toISOString(),r=(p=s.getState().userReducer.currentUser)==null?void 0:p.uuid,u=n.project,m=await this.getFilePayload(a),d=R({...n,file_name:a.name,file_sha1:m.sha1,file:URL.createObjectURL(a),submitted_at:c,created_by:r});this.dispatch(td(d));const h=this.enqueueRequest({description:"Add geo image",method:l.POST,url:"/geo-images/",payload:{uuid:d.uuid,submitted_at:c,title:d.title,description:d.description,geo_marker:d.geo_marker,canvas_marker:d.canvas_marker,sha1:d.file_sha1,project:d.project,file_name:d.file_name,direction:d.direction,original_date:d.original_date,file:m},blocks:[u],blockers:[u]});return h.then(A=>{this.processPresignedUrls(A.presigned_urls),this.dispatch(Le(A.geo_image))}).catch(()=>{this.dispatch(ui(d.uuid))}),[d,h.then(A=>A.geo_image)]}async bulkAdd(e,s){var p;const{store:a}=this.client,n=new Date().toISOString(),c=(p=a.getState().userReducer.currentUser)==null?void 0:p.uuid,r=[],u=[],m=[],d={};for(const A of e){const{file:y,...b}=A,I=await this.getFilePayload(y);I.sha1 in d||(d[I.sha1]=I);const T=R({...b,file_name:y.name,file_sha1:I.sha1,file:URL.createObjectURL(y),submitted_at:n,created_by:c,project:s});r.push(T),u.push(T.uuid),m.push({uuid:T.uuid,sha1:T.file_sha1,file_name:T.file_name,title:T.title,description:T.description,geo_marker:T.geo_marker,canvas_marker:T.canvas_marker,direction:T.direction,original_date:T.original_date})}this.dispatch(sd(r));const h=this.enqueueRequest({description:"Bulk add geo images",method:l.POST,url:"/geo-images/bulk/",payload:{submitted_at:n,project:s,geo_images:m,files:Object.values(d)},blocks:[s],blockers:u});return h.then(A=>{this.processPresignedUrls(A.presigned_urls),this.dispatch(ed(A.geo_images))}).catch(()=>{this.dispatch(ad(u))}),[r,h.then(A=>A.geo_images)]}update(e){const{store:s}=this.client,a=s.getState(),n=oi(e.uuid)(a);if(!n)throw new Error(`Map image with uuid ${e.uuid} does not exist in the store`);const c={...n,...e};this.dispatch(id(c));const r=this.enqueueRequest({description:"Update geo image",method:l.PATCH,url:`/geo-images/${e.uuid}/`,payload:e,blocks:[e.uuid],blockers:[e.uuid]});return r.then(u=>{this.dispatch(Le(u))}).catch(()=>{this.dispatch(Le(n))}),[c,r]}async delete(e){const{store:s}=this.client,a=s.getState(),n=oi(e)(a);if(!n)throw new Error(`Map image with uuid ${e} does not exist in the store`);this.dispatch(ui(e));const c=this.enqueueRequest({description:"Delete geo image",method:l.DELETE,url:`/geo-images/${e}/`,blocks:[e],blockers:[e]});return c.catch(()=>{this.dispatch(Le(n))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get geo images",method:l.GET,url:`/projects/${e}/geo-images/`,blocks:[e],blockers:[]});this.dispatch(xr(s))}}class gf extends P{add(e){var u;const{store:s}=this.client,a=new Date().toISOString(),n=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,c=R({...e,submitted_at:a,created_by:n});this.dispatch(hi(c));const r=this.enqueueRequest({description:"Add issue association",method:l.POST,url:"/issue-associations/",payload:_(c),blockers:[e.associated_issue,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[c.uuid]});return r.then(m=>{this.dispatch(od(m))}).catch(()=>{this.dispatch(pi(c.uuid))}),[c,r]}async delete(e){const{store:s}=this.client,a=ld(e)(s.getState());if(!a)throw new Error(`Issue association with uuid ${e} not found in store.`);this.dispatch(pi(e));const n=this.enqueueRequest({description:"Delete issue association",method:l.DELETE,url:`/issue-associations/${e}/`,blockers:[e],blocks:[]});return n.catch(()=>{this.dispatch(hi(a))}),n}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch issue associations",method:l.GET,url:"/issue-associations/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(ud(s))}}class Tf extends Fe{constructor(){super(...arguments);f(this,"name","Issue Attachment");f(this,"url","/issue-attachments");f(this,"initializeAttachments",fi);f(this,"addAttachments",Si);f(this,"updateAttachments",Sd);f(this,"removeAttachments",gi);f(this,"removeAttachment",gd);f(this,"setAttachment",fd);f(this,"selectAttachment",Fd)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(a=>({modelUuid:a.issueUuid,file:a.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const a=await this.enqueueRequest({description:"Get issue attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(fi(a))}}class bf extends Fe{constructor(){super(...arguments);f(this,"name","Issue Comment Attachment");f(this,"url","/issue-comment-attachments");f(this,"initializeAttachments",bi);f(this,"addAttachments",Od);f(this,"updateAttachments",vd);f(this,"removeAttachments",Ed);f(this,"removeAttachment",wd);f(this,"setAttachment",_d);f(this,"selectAttachment",Md)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue_comment:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue_comment:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(a=>({modelUuid:a.issueCommentUuid,file:a.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const a=await this.enqueueRequest({description:"Get issue comment attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(bi(a))}}class If extends P{add(e){var c;const{store:s}=this.client,a=R({...e,author:(c=s.getState().userReducer.currentUser)==null?void 0:c.uuid,submitted_at:new Date().toISOString()});this.dispatch(Ri(a));const n=this.enqueueRequest({description:"Add issue comment",method:l.POST,url:"/issue-comments/",payload:_(a),blockers:[e.issue],blocks:[a.uuid]});return n.catch(()=>{this.dispatch(Pi(a.uuid))}),[a,n]}update(e){const{store:s}=this.client,a=Oi(e.uuid)(s.getState());if(!a)throw new Error(`Comment with uuid ${e.uuid} not found in store`);const n={...a,...e};this.dispatch(Fi(n));const c=this.enqueueRequest({description:"Edit issue comment",method:l.PATCH,url:`/issue-comments/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{this.dispatch(Fi(a))}),[n,c]}remove(e){const{store:s}=this.client,a=Oi(e)(s.getState());if(!a)throw new Error(`Comment with uuid ${e} not found in store`);this.dispatch(Pi(e));const n=this.enqueueRequest({description:"Delete comment",method:l.DELETE,url:`/issue-comments/${e}/`,blockers:[e],blocks:[]});return n.catch(()=>{this.dispatch(Ri(a))}),n}async refreshStore(e){const s=await this.enqueueRequest({description:"Get comments",method:l.GET,url:"/issue-comments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(zd(s))}}class Ff extends P{add(e){var m;const{store:s}=this.client,a=s.getState(),n=new Date().toISOString(),c=(m=a.userReducer.currentUser)==null?void 0:m.uuid,r=R({...e,submitted_at:n,created_by:c});this.dispatch(vi(r));const u=this.enqueueRequest({description:"Create issue",method:l.POST,url:"/issues/",payload:_(r),blockers:["add-issue",r.project,r.issue_type,...r.category?[r.category]:[]],blocks:[r.uuid]});return u.then(d=>{this.dispatch(ht(d))}).catch(d=>{throw this.dispatch(wi(r.uuid)),d}),[r,u]}update(e){var m;const s=this.client.store.getState(),a=Ei(e.uuid)(s);if(!a)throw new Error(`Attempting to update an issue with uuid ${e.uuid} that doesn't exist in the store`);const n={...a,...e};this.dispatch(ht(n));const c={};for(const d of[v.TITLE,v.DESCRIPTION,v.STATUS,v.CATEGORY,v.PRIORITY,v.ASSIGNED_TO,v.DUE_DATE])if(d in e&&e[d]!==a[d])switch(d){case v.PRIORITY:case v.STATUS:{const h=e[d];c[d]=h!==void 0?Number(h):null;break}case v.DUE_DATE:case v.DESCRIPTION:case v.TITLE:c[d]=e[d]??null;break;case v.CATEGORY:{let h=null;const p=e[d];if(p&&(h=s.categoryReducer.instances[p]??null,!h))throw new Error(`Trying to update issue category to ${p} which does not exist in store`);c[d]=h?{name:h.name,color:h.color,uuid:h.uuid}:null;break}case v.ASSIGNED_TO:{let h=null;const p=e[d];if(p&&(h=s.userReducer.instances[p]??null,!h))throw new Error(`Trying to update issue assigned_to to ${p} which does not exist in store`);c[d]=h?{full_name:h.first_name,uuid:h.uuid}:null;break}}const r=R({created_by:(m=s.userReducer.currentUser)==null?void 0:m.uuid,submitted_at:new Date().toISOString(),issue:a.uuid,changes:c});this.dispatch(zu(r));const u=this.enqueueRequest({description:"Edit issue",method:l.PATCH,url:`/issues/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.catch(()=>{this.dispatch(ht(a)),this.dispatch(Du(r.uuid))}),[n,u]}async remove(e){const{store:s}=this.client,a=s.getState(),n=Ei(e)(a);if(!n)throw new Error(`No issue with uuid ${e} found in the store`);const c=Id(e)(a),r=Bu(e)(a),u=Jr(e)(a),m={};for(const h of hd(e)(a))m[h.uuid]=h;for(const h of md(e)(a))m[h.uuid]=h;const d=Object.values(m);this.dispatch(wi(e)),c.length>0&&this.dispatch(gi(c.map(({uuid:h})=>h))),r.length>0&&this.dispatch(Uu(r.map(({uuid:h})=>h))),u.length>0&&this.dispatch(lt(u.map(({uuid:h})=>h))),d.length>0&&this.dispatch(Ai(d.map(({uuid:h})=>h)));try{return await this.enqueueRequest({description:"Delete issue",method:l.DELETE,url:`/issues/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(vi(n)),this.dispatch(Si(c)),this.dispatch(Vu(r)),this.dispatch(ot(u)),this.dispatch(mi(d)),h}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issues",method:l.GET,url:"/issues/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch($d(s))}}class Rf extends Fe{constructor(){super(...arguments);f(this,"name","Issue Type Attachment");f(this,"url","/issue-type-attachments");f(this,"initializeAttachments",qi);f(this,"addAttachments",Wd);f(this,"updateAttachments",Yd);f(this,"removeAttachments",Xd);f(this,"removeAttachment",Jd);f(this,"setAttachment",Kd);f(this,"selectAttachment",xd)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(a=>({modelUuid:a.issueTypeUuid,file:a.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const a=await this.enqueueRequest({description:"Get issue type attachments",method:l.GET,url:`${this.url}/`,queryParams:{organization:s},blocks:[],blockers:[]});this.dispatch(qi(a))}}class Pf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,n={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in n||(n[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:a,fields_revision:h,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,file_extension:y.extension,field_identifier:p,file_sha1:y.sha1,fields_revision:h};r.push(I)}this.dispatch(iu(c));const u=this.enqueueRequest({description:"Add issue type fields attachments",method:l.POST,url:"/issue-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(n)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(au(d.attachments))}).catch(()=>{this.dispatch(nu(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"get issue type fields attachments",method:l.GET,url:"/issue-type-fields-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(su(s))}}class Of extends P{add(e){var u;const{store:s}=this.client,a=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,n=new Date().toISOString(),c=R({...e,created_by:a,submitted_at:n});this.dispatch(Au(c));const r=this.enqueueRequest({description:"Add Issue Type Fields",method:l.POST,url:"/issue-type-fields/",payload:_(c),blockers:[c.issue_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(yu(m))}).catch(m=>{throw this.dispatch(fu(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Issue Type Fields",method:l.GET,url:"/issue-type-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(pu(s))}}class _f extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,n={},c=[],r=[];for(const d of e){const{fieldValuesUuid:h,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in n||(n[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:a,field_values:h,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:p,field_values:h};r.push(I)}this.dispatch(pt(c));const u=this.enqueueRequest({description:"Add issue type field values attachments",method:l.POST,url:"/issue-type-field-values-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(n)},blockers:c.map(d=>d.field_values),blocks:c.map(d=>d.uuid)});return u.then(({presigned_urls:d,attachments:h})=>{this.processPresignedUrls(d),this.dispatch(Iu(h))}).catch(d=>{throw this.dispatch(At(c.map(h=>h.uuid))),d}),[c,u.then(({attachments:d})=>d)]}async bulkDelete(e){const{store:s}=this.client,a=s.getState(),n=Ru(e)(a);this.dispatch(At(e));try{await this.enqueueRequest({description:"Delete issue type field values attachments",method:l.DELETE,url:"/issue-type-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(pt(n)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue type field values attachments",method:l.GET,url:"/issue-type-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(bu(s))}}class vf extends P{add(e){var r;const{store:s}=this.client,a=s.getState(),n=R({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.uuid,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add issue type field values",method:l.POST,url:"/issue-type-field-values/",payload:_(n),blockers:[e.issue,e.fields_revision],blocks:[n.uuid]});return this.dispatch(ki(n)),c.then(u=>(this.dispatch(He(u)),u)).catch(()=>{this.dispatch(zi(n.uuid))}),[n,c]}update(e){const{store:s}=this.client,a=s.getState(),n=Di(e.uuid)(a);if(!n)throw new Error(`Expected IssueTypeFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(He(c));const r=this.enqueueRequest({description:"Update issue type field values",method:l.PATCH,url:`/issue-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.issue],blocks:[c.uuid]});return r.then(u=>{this.dispatch(He(u))}).catch(()=>{this.dispatch(He(n))}),[c,r]}async delete(e){const{store:s}=this.client,a=s.getState(),n=Di(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Pu(e)(a);this.dispatch(zi(e)),this.dispatch(At(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete issue type field values",method:l.DELETE,url:`/issue-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ki(n)),this.dispatch(pt(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue type field values",method:l.GET,url:"/issue-type-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(ou(s))}}class wf extends P{add(e){var r;const{store:s}=this.client,a=s.getState(),n=R({...e,submitted_at:new Date().toISOString(),created_by:(r=a.userReducer.currentUser)==null?void 0:r.uuid});this.dispatch(wu(n));const c=this.enqueueRequest({method:l.POST,url:"/issue-types/",payload:_(n),blockers:[],blocks:[n.uuid]});return c.then(u=>{this.dispatch(We(u))}).catch(()=>{this.dispatch(Li(n.uuid))}),[n,c]}update(e){const{store:s}=this.client,a=s.getState(),n=Ni(e.uuid)(a);if(!n)throw new Error(`IssueType with uuid ${e.uuid} does not exist in the store.`);const c={...n,...e};this.dispatch(Eu(c));const r=this.enqueueRequest({method:l.PATCH,url:`/issue-types/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(We(u))}).catch(()=>{this.dispatch(We(n))}),[c,r]}delete(e){const{store:s}=this.client,a=s.getState(),n=Ni(e)(a);if(!n)throw new Error(`IssueType with uuid ${e} does not exist in the store.`);const c=Hi(e)(a);this.dispatch(Li(e)),this.dispatch(Gd(c.map(u=>u.uuid)));const r=this.enqueueRequest({method:l.DELETE,url:`/issue-types/${e}/`,blockers:[e],blocks:[]});return r.catch(()=>{this.dispatch(We(n)),this.dispatch(Bd(c))}),r}async refreshStore(e){const s=await this.enqueueRequest({method:l.GET,url:"/issue-types/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(vu(s))}}class Ef extends P{async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue updates",method:l.GET,url:"/issue-updates/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(ku(s))}}const jf=1800;function qf(t){if(!t.access)throw new Error("Missing access token");if(!t.refresh)throw new Error("Missing refresh token");return{accessToken:t.access,refreshToken:t.refresh}}class Mf extends $y{constructor(){super(...arguments);f(this,"_getRenewedTokens",async s=>{const a=this.enqueueRequest({description:"Get renewed tokens",method:l.POST,url:this.refreshTokensUrl,payload:{refresh:s},isAuthNeeded:!1,blockers:[],blocks:[],checkAuth:!1,immediate:!0});let n;try{n=await a}catch(c){console.error("Could not renew tokens; clearing auth",c),this.clearAuth();return}if(!n.access)throw new Error("Missing access token");return{accessToken:n.access,refreshToken:n.refresh??this.getRefreshToken()}})}clearAuth(){console.debug(this.constructor.name,"clearing auth;"),this.dispatch(Lc(!1)),this.clearTokens(),this.dispatch({type:vl.RESET_STATE}),this.dispatch({type:Al})}async renewTokens(){const s=this.getRefreshToken();if(!s)throw new Error("No refresh token found");console.debug(this.constructor.name,"renewing tokens");try{const a=await this._getRenewedTokens(s);if(!a)return;console.log("Got renewed tokens"),this.setTokens(a)}catch(a){throw console.error("Could not renew tokens; clearing auth",a),this.clearAuth(),a}}tokenIsExpiringSoon(){const s=this.getAccessToken();if(!s)return!1;const a=Date.now()/1e3;let n;try{n=wl(s).exp??a}catch{n=a}return n-a<jf}getAuthHeader(){return`Bearer ${this.getAccessToken()}`}async prepareAuth(){if(this.tokenIsExpiringSoon()){console.debug(this.constructor.name,"preparing auth");try{await this.renewTokens()}catch(s){return s instanceof q&&this.clearAuth(),s instanceof Error?Promise.reject(s):Promise.reject(new Error((s??qe).toString()))}}}async handleUnauthorized(s,a){const n=this.client.store.getState();if(s.url.endsWith("/token/refresh/"))throw n.authReducer.isLoggedIn&&console.warn("No signed-in user to sign out."),this.clearAuth(),new q({message:"You have been signed out due to inactivity.",response:a,discard:!0});if(n.authReducer.isLoggedIn)await this.renewTokens();else throw console.debug("Forbidden; user is not logged in."),new q({message:"Incorrect username or password.",response:a,discard:!0})}async initAuth(s){const a=ye.v4();return console.debug(this.constructor.name,"Initiating auth"),this.enqueueRequest({uuid:a,description:"Get token pair",method:l.POST,url:this.initTokensUrl,payload:s,isAuthNeeded:!1,checkAuth:!1,immediate:!0,blockers:[],blocks:[]}).then(n=>{this.setTokens(qf(n))})}}class Cf extends P{async update(e){const s=this.enqueueRequest({description:"Edit organization access",method:l.PATCH,url:`/organizations/${e.organization}/access/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return s.then(()=>{this.dispatch(Ju(e))}),s}async remove(e){return this.dispatch(Xu(e.uuid)),this.dispatch(Hu(e.user)),this.enqueueRequest({description:"Remove organization access",method:l.DELETE,url:`/organizations/${e.organization}/access/${e.uuid}/`,blockers:[e.uuid],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization accesses",method:l.GET,url:`/organizations/${e}/access/`,blockers:[],blocks:[]});this.dispatch(Yu(s))}}class kf extends P{create(e){return this.enqueueRequest({description:"Create organization",method:l.POST,url:"/organizations/",payload:{name:e},blockers:[],blocks:[`add-org-${e}`,"create-org"]})}async update(e){return this.enqueueRequest({description:"Edit organization",method:l.PATCH,url:`/organizations/${e.uuid}/`,payload:e,blockers:[`add-org-${e.name}`,e.uuid],blocks:[e.uuid]})}async invite(e,s){return this.enqueueRequest({description:"Invite user to organization",method:l.POST,url:`/organizations/${e}/invite/${s}/`,blockers:[],blocks:[]})}async refreshStore(e,s){const a={},n=await this.enqueueRequest({description:"Get organizations",method:l.GET,url:`/projects/${e}/organizations/`,blockers:[],blocks:[]});for(const r of n)a[r.uuid]=r;const c=await this.enqueueRequest({description:"Get organization",method:l.GET,url:`/organizations/${s}/`,blockers:[],blocks:[]});a[c.uuid]=c,this.dispatch(yo(Object.values(a)))}}class zf extends P{async update(e){return this.dispatch(eo(e)),this.enqueueRequest({description:"Edit project access",method:l.PATCH,url:`/project-accesses/${e.uuid}/`,payload:e,blockers:[e.uuid,"change-access-level"],blocks:[e.uuid]})}async remove(e){return this.dispatch(to(e)),this.enqueueRequest({description:"Delete project access",method:l.DELETE,url:`/project-accesses/${e}/`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project accesses",method:l.GET,url:"/project-accesses/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Zi(s))}}class Vf extends Fe{constructor(){super(...arguments);f(this,"name","Project Attachment");f(this,"url","/project-attachments");f(this,"addAttachments",Eo);f(this,"updateAttachments",Mo);f(this,"removeAttachments",ia);f(this,"removeAttachment",Co);f(this,"setAttachment",jo);f(this,"selectAttachment",Vo)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,project:s.modelUuid})}buildAttachmentPayload(s){return{...s,project:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(a=>({modelUuid:a.projectUuid,file:a.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const a=await this.enqueueRequest({description:"Get project attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blockers:[],blocks:[]});this.dispatch(wo(a))}}class Df extends P{async saveExisting(e){if(!e.uuid)throw new Error("You can only use this method to save existing project files. The one provided has no uuid.");const s={...e};delete s.file;const a=this.enqueueRequest({method:l.PATCH,url:`/projects/files/${e.uuid}/`,payload:s,blockers:[e.uuid],blocks:[e.uuid]});return a.then(n=>{this.dispatch(na(n))}),a}saveActive(){const{store:e}=this.client,s=e.getState(),a=s.projectFileReducer.activeProjectFileId;if(!a)throw new Error("No active project file");const n=s.projectFileReducer.instances[a];if(!n)throw new Error("No active project file");if(!n.bounds&&!n.canvas_bounds)throw new Error("Project file must either have bounds or canvas_bounds set");let c;if(typeof n.file=="string"&&!n.file.startsWith("blob:")){const m={...n};delete m.file,c={method:l.PATCH,url:`/projects/files/${a}/`,payload:m,blockers:[a],blocks:[a]}}else c=new Promise((m,d)=>{this.client.files.uploadFileToS3(n.file_sha1).then(([h])=>{m({method:l.POST,url:`/projects/${n.project}/files/`,payload:{...n,...h},blockers:[a],blocks:[a]})}).catch(d)});const u=Promise.resolve(c).then(m=>this.enqueueRequest(m));return u.then(m=>{this.dispatch(na(m))}),this.dispatch(Ko),this.dispatch(Wo(null)),this.dispatch(Ho(!1)),[n,u]}delete(e){return this.dispatch(Lo(e)),this.enqueueRequest({method:l.DELETE,url:`/projects/files/${e}`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project files",method:l.GET,url:`/projects/${e}/files/`,blockers:[],blocks:[]});this.dispatch(Bo(s))}}class Uf extends P{async add(e){if(!e.bounds&&!e.canvas_bounds)throw new Error("Project must either have bounds or canvas_bounds set");return await this.enqueueRequest({description:"Create project",method:l.POST,url:"/projects/",payload:{name:e.name,bounds:e.bounds,organization_owner:e.organization_owner},blockers:[],blocks:[]})}async update(e){if(!e.bounds&&!e.canvas_bounds)throw new Error("Project must either have bounds or canvas_bounds set");return this.dispatch(uo(e)),await this.enqueueRequest({description:"Update project",method:l.PATCH,url:`/projects/${e.uuid}/`,payload:{name:e.name,bounds:e.bounds},blockers:[e.uuid],blocks:[e.uuid]})}async delete(e){const{store:s}=this.client,a=s.getState(),n=gt(a),c=n[e];if(!c)throw new Error("Expected project to exist");const r=Jo(a).filter(d=>d.project===e);this.dispatch(No(r.map(({uuid:d})=>d)));const u=Do(c.uuid)(a);this.dispatch(ia(u.map(({uuid:d})=>d)));const m=io(a);this.dispatch(so(m.map(({uuid:d})=>d))),this.dispatch({type:"rehydrated/setRehydrated",payload:!1}),this.dispatch(oo(c.uuid));try{await this.enqueueRequest({description:"Delete project",method:l.DELETE,url:`/projects/${e}/`,blockers:[e],blocks:[]}),this.dispatch({type:"rehydrated/setRehydrated",payload:!0})}catch(d){throw this.dispatch(ro(Object.values(n))),this.dispatch(Zi(Object.values(m))),this.dispatch(Go(r)),this.dispatch(qo(u)),this.dispatch({type:"rehydrated/setRehydrated",payload:!0}),d}}invite(e,s){const a=ye.v4();return this.enqueueRequest({description:"Invite user to project",method:l.POST,url:`/projects/${e}/invite/${s}/`,payload:{uuid:a},blockers:[],blocks:[a]})}joinProject(e,s,a){return this.enqueueRequest({description:"Join project",method:l.GET,url:`/projects/${e}/join-project/${s}/${a}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}async acceptInvite(e){return this.enqueueRequest({description:"Accept project invite",method:l.PATCH,url:`/projects/${e}/accept-invite/`,blockers:[e],blocks:[e]}).then(()=>{this.dispatch(lo(e))})}}class $f extends P{add(e){const s=R({...e,submitted_at:new Date().toISOString()});this.dispatch(el(s));const a=this.enqueueRequest({description:"Create team",method:l.POST,url:`/organizations/${e.organization}/teams/`,payload:s,blockers:[],blocks:[s.uuid]});return a.then(n=>{this.dispatch(Ee(n))}).catch(()=>{this.dispatch(ua(s.uuid))}),[s,a]}update(e){const{store:s}=this.client,a=je(e.uuid)(s.getState());if(!a)throw new Error(`Expected team with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(da(n));const c=this.enqueueRequest({description:"Update team",method:l.PATCH,url:`/organizations/teams/${e.uuid}/`,payload:_(e),blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(Ee(r))}).catch(()=>{this.dispatch(Ee(a))}),[n,c]}async delete(e){const{store:s}=this.client,a=s.getState(),n=je(e)(a);if(!n)throw new Error(`Expected team with uuid ${e} to exist`);this.dispatch(ua(e));try{return await this.enqueueRequest({description:"Delete team",method:l.DELETE,url:`/organizations/teams/${e}/`,blockers:[e],blocks:[e]})}catch(c){throw this.dispatch(Ee(n)),c}}async setMembers(e,s){const{store:a}=this.client,n=je(e)(a.getState());if(!n)throw new Error(`Expected team with uuid ${e} to exist`);if(s.length!==new Set(s).size)throw new Error("Duplicate members found in the list");this.dispatch(da({...n,members:s}));const c=this.enqueueRequest({description:"Set team members",method:l.PUT,url:`/organizations/teams/${e}/set-members/`,payload:{users:s},blockers:[e],blocks:[e]});return c.catch(()=>{this.dispatch(Ee(n))}),c}async addMembers(e,s){const{store:a}=this.client,n=je(e)(a.getState());if(!n)throw new Error(`Expected team with uuid ${e} to exist`);const c=[...n.members,...s];return this.setMembers(e,c)}async removeMembers(e,s){const{store:a}=this.client,n=je(e)(a.getState());if(!n)throw new Error(`Expected team with uuid ${e} to exist`);const c=n.members.filter(r=>!s.includes(r));return this.setMembers(e,c)}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch teams",method:l.GET,url:`/organizations/${e}/teams/`,blockers:[],blocks:[]});this.dispatch(xo(s))}}class Bf extends P{async refreshStore(e,s){const a={},n=await this.enqueueRequest({description:"Fetch organization users",method:l.GET,url:`/organizations/${s}/users/`,blockers:[],blocks:[]});for(const r of n)a[r.uuid]=r;const c=await this.enqueueRequest({description:"Fetch project users",method:l.GET,url:`/projects/${e}/users/`,blockers:[],blocks:[]});for(const r of c)a[r.uuid]=r;this.dispatch(Nu(Object.values(a)))}}class Gf{constructor(e){f(this,"store");this.store=e}async enqueueRequest(e,s,a){return this._enqueueRequest(e,s,a).then(n=>{if(n instanceof q)throw n;return n})}_enqueueRequest(e,s,a){const n=new _a,c={...e,BASE_URL:s,serviceName:a};if(e.immediate){const r={...c,uuid:e.uuid??ye.v4()},u={payload:r,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:r,BASE_URL:s,serviceName:a}}}};pa(u,this).then(m=>{n.resolve(m.body)}).catch(m=>{Aa(m,u),m instanceof Error?n.reject(m):n.reject(new Error((m??qe).toString()))})}else{const r=this.store.dispatch(Ro(c)),u=d=>{if(d)n.resolve(d.body);else{const h=new q({message:"Could not get a response from the server.",response:d,discard:!0});n.reject(h)}},m=d=>{d instanceof q?d.options.discard=!0:(console.error("Received an unexpected error while processing a request:",d,`
15
- Converting error to APIError and discarding.`),d=new q({message:"An error occurred while processing the request.",innerError:d,discard:!0})),n.reject(d)};r.then(u,m)}return n}}class Me{constructor(){f(this,"graph");f(this,"requestAttemptCounter");this.graph=new El.DepGraph,this.requestAttemptCounter={}}static _fromOutbox(e){const s=new Me;for(let a=0;a<e.length;a++){const n=e[a];if(!n){console.error("Outbox item was undefined");continue}s.sneakRequest(n);for(let c=0;c<a;c++){const r=e[c];if(!r){console.error("Previous outbox item was undefined");continue}r.payload.uuid!==n.payload.uuid&&r.payload.blocks.some(u=>n.payload.blockers.includes(u))&&Me._addDependency(n.payload.uuid,r.payload.uuid,s.graph)}}return s}_addDependency(e,s){Me._addDependency(e,s,this.graph)}static _addDependency(e,s,a){if(e===s)throw new Error(`Tried to add dependency from node to itself: ${e}`);if(!a.hasNode(e))throw new Error(`Tried to add dependency from non-existent node: ${e} (to node: ${s})`);if(!a.hasNode(s))throw new Error(`Tried to add dependency to non-existent node: ${s} (from node: ${e})`);a.addDependency(e,s)}addRequest(e){if(this.graph.addNode(e.payload.uuid,e),!(e.payload.blockers.length===0||this.graph.size()===1))for(const s of this.graph.overallOrder()){if(s===e.payload.uuid)continue;const a=this.graph.getNodeData(s);e.payload.blockers.some(n=>a.payload.blocks.includes(n))&&this._addDependency(e.payload.uuid,s)}}insertRequest(e){this.graph.addNode(e.payload.uuid,e);for(const s of this.graph.overallOrder()){if(s===e.payload.uuid)continue;this.graph.getNodeData(s).payload.blockers.some(n=>e.payload.blocks.includes(n))&&this._addDependency(s,e.payload.uuid)}}sneakRequest(e){this.graph.addNode(e.payload.uuid,e)}_getNextNode(){const e=this.graph.overallOrder(!0);let s=1/0,a;for(const n of e){const c=this.requestAttemptCounter[n]||0;c<s&&(s=c,a=n)}return a}peek(){const e=this._getNextNode();if(e)return this.graph.getNodeData(e)}remove(e){this.graph.removeNode(e),delete this.requestAttemptCounter[e]}pop(){const e=this.peek();return e&&this.graph.removeNode(e.payload.uuid),e}getQueue(){const e=this.graph.overallOrder().map(a=>this.graph.getNodeData(a)),s=this._getNextNode();if(s){const a=this.graph.getNodeData(s),n=e.findIndex(c=>c.payload.uuid===a.payload.uuid);n!==-1&&(e.splice(n,1),e.unshift(a))}return e}getReady(){let e=this.graph.overallOrder(!0).map(s=>this.graph.getNodeData(s));return e=e.sort((s,a)=>s.meta.offline.effect.timestamp.localeCompare(a.meta.offline.effect.timestamp)),e=e.sort((s,a)=>{const n=this.requestAttemptCounter[s.payload.uuid]||0,c=this.requestAttemptCounter[a.payload.uuid]||0;return n-c}),e}registerRetry(e){this.requestAttemptCounter[e]=(this.requestAttemptCounter[e]||0)+1}}const Lf=(t,e)=>{const s=new e(t);return gy(s),Sy(t),s};var bl=(t=>(t[t.USER_REGISTRATION=0]="USER_REGISTRATION",t[t.APPLICATION_INVITE=2]="APPLICATION_INVITE",t[t.PROJECT_INVITE=4]="PROJECT_INVITE",t[t.ORGANIZATION_INVITE=6]="ORGANIZATION_INVITE",t[t.ADD_EMAIL_DOMAIN=8]="ADD_EMAIL_DOMAIN",t[t.RESET_PASSWORD=10]="RESET_PASSWORD",t))(bl||{});i.APIError=q,i.AgentService=By,i.AssetAttachmentService=Gy,i.AssetProcedureFieldValuesAttachmentService=Hy,i.AssetProcedureFieldValuesService=Yy,i.AssetProcedureFieldsAttachmentService=Ly,i.AssetProcedureFieldsService=Ny,i.AssetProcedureInstanceService=Jy,i.AssetProcedureService=Xy,i.AssetService=Zy,i.AssetStageCompletionService=Qy,i.AssetStageService=xy,i.AssetTypeAttachmentService=ef,i.AssetTypeFieldValuesAttachmentService=af,i.AssetTypeFieldValuesService=nf,i.AssetTypeFieldsAttachmentService=tf,i.AssetTypeFieldsService=sf,i.AssetTypeService=cf,i.AttachmentModel=Ia,i.BaseApiService=P,i.BaseSDK=Gf,i.COMMON_AUTO_FIELDS=qa,i.CategoryService=rf,i.DEFAULT_ISSUE_PRIORITY=ql,i.DEFAULT_ISSUE_STATUS=jl,i.DeferredPromise=_a,i.DocumentAttachmentService=df,i.DocumentService=uf,i.EMPTY_ARRAY=Ta,i.EMPTY_OBJECT=ba,i.EmailVerificationService=of,i.FileService=hf,i.FormRevisionAttachmentService=mf,i.FormRevisionService=pf,i.FormService=yf,i.FormSubmissionAttachmentService=ff,i.FormSubmissionService=Ky,i.GeoImageService=Sf,i.HttpMethod=l,i.IssueAssociationService=gf,i.IssueAttachmentService=Tf,i.IssueCommentAttachmentService=bf,i.IssueCommentService=If,i.IssuePriority=Pt,i.IssueService=Ff,i.IssueStatus=Ot,i.IssueTypeAttachmentService=Rf,i.IssueTypeFieldValuesAttachmentService=_f,i.IssueTypeFieldValuesService=vf,i.IssueTypeFieldsAttachmentService=Pf,i.IssueTypeFieldsService=Of,i.IssueTypeService=wf,i.IssueUpdateChange=v,i.IssueUpdateService=Ef,i.JWTService=Mf,i.LicenseLevel=Ra,i.LicenseStatus=Pa,i.OUTBOX_RETRY_DELAY=Oa,i.OrganizationAccessLevel=Rt,i.OrganizationAccessService=Cf,i.OrganizationService=kf,i.OutboxCoordinator=Me,i.PaddleCheckoutEvent=Fa,i.ProjectAccessLevel=Ft,i.ProjectAccessService=zf,i.ProjectAttachmentService=Vf,i.ProjectFileService=Df,i.ProjectService=Uf,i.TeamService=$f,i.UNKNOWN_ERROR_MESSAGE=qe,i.UserService=Bf,i.VERSION_REDUCER_KEY=ha,i.VerificationCodeType=bl,i._setLatestRetryTime=Oo,i.acceptProjectInvite=lo,i.addAsset=ns,i.addAssetAttachment=ih,i.addAssetAttachments=kt,i.addAssetProcedure=es,i.addAssetProcedureFieldValues=Lt,i.addAssetProcedureFieldValuesAttachment=bh,i.addAssetProcedureFieldValuesAttachments=Qe,i.addAssetProcedureFieldValuesMany=bn,i.addAssetProcedureFields=rn,i.addAssetProcedureFieldsAttachment=ch,i.addAssetProcedureFieldsAttachments=Qa,i.addAssetProcedureFieldsMany=mh,i.addAssetProcedureInstance=Yt,i.addAssetProcedureInstances=vn,i.addAssetProcedures=zh,i.addAssetStage=Xh,i.addAssetStageCompletion=hs,i.addAssetStageCompletions=ms,i.addAssetStages=Ss,i.addAssetType=ks,i.addAssetTypeAttachment=em,i.addAssetTypeAttachments=Fs,i.addAssetTypeFieldValues=Es,i.addAssetTypeFieldValuesAttachment=Sm,i.addAssetTypeFieldValuesAttachments=it,i.addAssetTypeFieldValuesMany=Cc,i.addAssetTypeFields=Tc,i.addAssetTypeFieldsAttachment=im,i.addAssetTypeFieldsAttachments=hc,i.addAssetTypeFieldsMany=om,i.addAssetTypes=Em,i.addAssets=cs,i.addCategory=$s,i.addConversation=Va,i.addDocumentAttachment=Gm,i.addDocumentAttachments=Qc,i.addDocuments=ur,i.addForm=Qs,i.addFormRevision=Js,i.addFormRevisionAttachment=Xm,i.addFormRevisionAttachments=br,i.addFormRevisions=wr,i.addFormSubmission=ii,i.addFormSubmissionAttachment=up,i.addFormSubmissionAttachments=rt,i.addFormSubmissions=ot,i.addForms=cp,i.addGeoImage=td,i.addGeoImages=sd,i.addIssue=vi,i.addIssueAssociation=hi,i.addIssueAssociations=mi,i.addIssueAttachment=Ip,i.addIssueAttachments=Si,i.addIssueComment=Ri,i.addIssueCommentAttachment=Pp,i.addIssueCommentAttachments=Od,i.addIssueComments=wp,i.addIssueType=wu,i.addIssueTypeAttachment=Mp,i.addIssueTypeAttachments=Wd,i.addIssueTypeFieldValues=ki,i.addIssueTypeFieldValuesAttachment=nA,i.addIssueTypeFieldValuesAttachments=pt,i.addIssueTypeFieldValuesMany=Np,i.addIssueTypeFields=Au,i.addIssueTypeFieldsAttachment=Vp,i.addIssueTypeFieldsAttachments=iu,i.addIssueTypeFieldsMany=Xp,i.addIssueUpdate=zu,i.addIssueUpdates=Vu,i.addIssues=Bd,i.addOrganization=LA,i.addOrganizations=GA,i.addProject=CA,i.addProjectAttachment=ty,i.addProjectAttachments=Eo,i.addProjectFile=ny,i.addProjectFiles=Go,i.addProjects=MA,i.addTeam=el,i.addUser=SA,i.addUsers=fA,i.agentsReducer=$a,i.agentsSlice=jt,i.areArraysEqual=Vl,i.assetAttachmentReducer=Ja,i.assetAttachmentSlice=Mt,i.assetProcedureFieldValuesAttachmentReducer=Sn,i.assetProcedureFieldValuesAttachmentSlice=$t,i.assetProcedureFieldValuesReducer=Pn,i.assetProcedureFieldValuesSlice=Gt,i.assetProcedureFieldsAttachmentReducer=an,i.assetProcedureFieldsAttachmentSlice=Vt,i.assetProcedureFieldsReducer=ln,i.assetProcedureFieldsSlice=Dt,i.assetProcedureInstanceReducer=jn,i.assetProcedureInstanceSlice=Kt,i.assetProcedureReducer=kn,i.assetProcedureSlice=xt,i.assetReducer=$n,i.assetSlice=as,i.assetStageCompletionReducer=Hn,i.assetStageCompletionSlice=ls,i.assetStageReducer=Zn,i.assetStageSlice=fs,i.assetTypeAttachmentReducer=uc,i.assetTypeAttachmentSlice=Is,i.assetTypeFieldValuesAttachmentReducer=jc,i.assetTypeFieldValuesAttachmentSlice=_s,i.assetTypeFieldValuesReducer=Dc,i.assetTypeFieldValuesSlice=ws,i.assetTypeFieldsAttachmentReducer=fc,i.assetTypeFieldsAttachmentSlice=Ps,i.assetTypeFieldsReducer=Rc,i.assetTypeFieldsSlice=Os,i.assetTypeReducer=Bc,i.assetTypeSlice=Cs,i.authReducer=Nc,i.authSlice=nt,i.blobToBase64=Wl,i.categoryReducer=Jc,i.categorySlice=Us,i.clearTokens=zm,i.constructUploadedFilePayloads=Hl,i.coordinatesAreEqual=kl,i.createModelAdapter=F,i.createMultiPointGeometry=Cl,i.createOfflineAction=Io,i.createPayload=_,i.createPointGeometry=Ml,i.deleteAsset=rs,i.deleteAssetAttachment=Na,i.deleteAssetAttachments=zt,i.deleteAssetProcedure=ts,i.deleteAssetProcedureFieldValues=Nt,i.deleteAssetProcedureFieldValuesAttachment=Ph,i.deleteAssetProcedureFieldValuesAttachments=xe,i.deleteAssetProcedureFieldValuesMany=Fn,i.deleteAssetProcedureFields=un,i.deleteAssetProcedureFieldsAttachment=oh,i.deleteAssetProcedureFieldsAttachments=en,i.deleteAssetProcedureFieldsMany=fh,i.deleteAssetProcedureInstance=Jt,i.deleteAssetProcedureInstances=wn,i.deleteAssetProcedures=Dh,i.deleteAssetStage=Zh,i.deleteAssetStageCompletion=ps,i.deleteAssetStageCompletions=As,i.deleteAssetStages=Ts,i.deleteAssetType=zs,i.deleteAssetTypeAttachment=ac,i.deleteAssetTypeAttachments=Rs,i.deleteAssetTypeFieldValues=js,i.deleteAssetTypeFieldValuesAttachment=Im,i.deleteAssetTypeFieldValuesAttachments=at,i.deleteAssetTypeFieldValuesMany=zc,i.deleteAssetTypeFields=Ic,i.deleteAssetTypeFieldsAttachment=rm,i.deleteAssetTypeFieldsAttachments=pc,i.deleteAssetTypeFieldsMany=pm,i.deleteAssetTypes=qm,i.deleteAssets=Dn,i.deleteCategory=Yc,i.deleteDocumentAttachment=tr,i.deleteDocumentAttachments=sr,i.deleteForm=xs,i.deleteFormRevision=Xs,i.deleteFormRevisionAttachment=ep,i.deleteFormRevisionAttachments=Fr,i.deleteFormRevisions=Er,i.deleteFormSubmission=ai,i.deleteFormSubmissionAttachment=mp,i.deleteFormSubmissionAttachments=dt,i.deleteFormSubmissions=lt,i.deleteGeoImage=ui,i.deleteGeoImages=ad,i.deleteIssue=wi,i.deleteIssueAssociation=pi,i.deleteIssueAssociations=Ai,i.deleteIssueAttachment=gd,i.deleteIssueAttachments=gi,i.deleteIssueComment=Pi,i.deleteIssueCommentAttachment=wd,i.deleteIssueCommentAttachments=Ed,i.deleteIssueComments=Ep,i.deleteIssueTypeAttachment=Jd,i.deleteIssueTypeAttachments=Xd,i.deleteIssueTypeFieldValues=zi,i.deleteIssueTypeFieldValuesAttachment=uA,i.deleteIssueTypeFieldValuesAttachments=At,i.deleteIssueTypeFieldValuesMany=Yp,i.deleteIssueTypeFields=fu,i.deleteIssueTypeFieldsAttachment=Bp,i.deleteIssueTypeFieldsAttachments=nu,i.deleteIssueTypeFieldsMany=eA,i.deleteIssueUpdate=Du,i.deleteIssueUpdates=Uu,i.deleteIssues=Gd,i.deleteOrganization=WA,i.deleteOrganizationAccess=Xu,i.deleteOrganizations=KA,i.deleteProject=oo,i.deleteProjectAccess=to,i.deleteProjectAccesses=so,i.deleteProjectAttachment=Co,i.deleteProjectAttachments=ia,i.deleteProjectFile=Lo,i.deleteProjectFiles=No,i.deleteProjects=zA,i.deleteTeam=ua,i.deleteUser=bA,i.deleteUsers=IA,i.dequeue=fl,i.discard=Aa,i.documentAttachmentReducer=cr,i.documentAttachmentSlice=Ls,i.documentSlice=Ns,i.documentsReducer=mr,i.downloadFile=Kl,i.downloadInMemoryFile=Nl,i.emailRegex=eh,i.enqueue=yl,i.enqueueRequest=Ro,i.fallbackToEmptyArray=g,i.fallbackToEmptyObject=Ce,i.fileReducer=Sr,i.fileSlice=Ws,i.fileToBlob=Ea,i.formReducer=zr,i.formRevisionAttachmentReducer=Pr,i.formRevisionAttachmentSlice=Ks,i.formRevisionReducer=Mr,i.formRevisionsSlice=Ys,i.formSlice=Zs,i.formSubmissionAttachmentReducer=Nr,i.formSubmissionAttachmentSlice=ei,i.formSubmissionReducer=Zr,i.formSubmissionSlice=si,i.geoImageReducer=rd,i.geoImageSlice=di,i.getFileIdentifier=Ll,i.getFileS3Key=Et,i.getLocalDateString=va,i.getLocalRelativeDateString=Bl,i.getOutboxCoordinator=Ie,i.getRenamedFile=wa,i.hashFile=Oe,i.initSDK=Lf,i.initializeAssetAttachments=Ct,i.initializeAssetProcedureFieldValues=Tn,i.initializeAssetProcedureFieldValuesAttachments=mn,i.initializeAssetProcedureFields=cn,i.initializeAssetProcedureFieldsAttachments=Za,i.initializeAssetProcedureInstances=_n,i.initializeAssetProcedures=Mn,i.initializeAssetStageCompletions=Gn,i.initializeAssetStages=Jn,i.initializeAssetTypeAttachments=tc,i.initializeAssetTypeFieldValues=Mc,i.initializeAssetTypeFieldValuesAttachments=Oc,i.initializeAssetTypeFields=gc,i.initializeAssetTypeFieldsAttachments=lc,i.initializeAssetTypes=$c,i.initializeAssets=Vn,i.initializeCategories=Wc,i.initializeConversations=za,i.initializeDocumentAttachments=Zc,i.initializeFormRevisionAttachments=Tr,i.initializeFormRevisions=vr,i.initializeFormSubmissionAttachments=$r,i.initializeFormSubmissions=Wr,i.initializeForms=kr,i.initializeGeoImages=xr,i.initializeIssueAssociations=ud,i.initializeIssueAttachments=fi,i.initializeIssueCommentAttachments=bi,i.initializeIssueTypeAttachments=qi,i.initializeIssueTypeFieldValues=ou,i.initializeIssueTypeFieldValuesAttachments=bu,i.initializeIssueTypeFields=pu,i.initializeIssueTypeFieldsAttachments=su,i.initializeIssueTypes=vu,i.initializeIssueUpdates=ku,i.initializeIssues=$d,i.initializeOrganizationAccesses=Yu,i.initializeOrganizations=$A,i.initializeProjectAccesses=Zi,i.initializeProjectAttachments=wo,i.initializeProjectFiles=Bo,i.initializeProjects=jA,i.initializeTeams=xo,i.initializeUsers=AA,i.isToday=$l,i.issueAssociationReducer=Ad,i.issueAssociationSlice=li,i.issueAttachmentReducer=Rd,i.issueAttachmentSlice=yi,i.issueCommentAttachmentReducer=Cd,i.issueCommentAttachmentSlice=Ti,i.issueCommentReducer=Dd,i.issueCommentSlice=Ii,i.issueReducer=Nd,i.issueSlice=_i,i.issueTypeAttachmentReducer=eu,i.issueTypeAttachmentSlice=ji,i.issueTypeFieldValuesAttachmentReducer=Ou,i.issueTypeFieldValuesAttachmentSlice=$i,i.issueTypeFieldValuesReducer=hu,i.issueTypeFieldValuesSlice=Ci,i.issueTypeFieldsAttachmentReducer=du,i.issueTypeFieldsAttachmentSlice=Mi,i.issueTypeFieldsReducer=gu,i.issueTypeFieldsSlice=Ui,i.issueTypeReducer=Mu,i.issueTypeSlice=Gi,i.issueUpdateReducer=Gu,i.issueUpdateSlice=Wi,i.logOnlyOnce=Yl,i.markAsDeleted=Po,i.markForDeletion=ey,i.memoize=vt,i.moveDocument=or,i.offline=R,i.onlyUniqueHashes=xl,i.onlyUniqueOfflineIds=Ca,i.organizationAccessReducer=Qu,i.organizationAccessSlice=Yi,i.organizationReducer=bo,i.organizationSlice=ea,i.outboxReducer=_o,i.outboxSlice=ta,i.overmapEnhancer=wy,i.overmapReducers=ml,i.overmapRootReducer=Ry,i.performRequest=pa,i.projectAccessReducer=no,i.projectAccessSlice=Xi,i.projectAttachmentReducer=Uo,i.projectAttachmentSlice=sa,i.projectFileReducer=Xo,i.projectFileSlice=aa,i.projectReducer=ho,i.projectSlice=xi,i.rehydratedReducer=Zo,i.rehydratedSlice=ca,i.removeDocuments=Hs,i.removeIssueType=Li,i.removeUser=Hu,i.resetProjectFileObjectUrls=ry,i.resetStore=Al,i.restructureCreateSelectorWithArgs=S,i.saveActiveProjectFileBounds=Ko,i.selectAccessToken=Vm,i.selectActiveOrganizationAccess=_A,i.selectActiveProjectFileId=uy,i.selectAllDocumentAttachments=ar,i.selectAllProjectAttachments=zo,i.selectAncestorIdsOfDocument=Km,i.selectAssetAttachmentById=Ka,i.selectAssetAttachmentMapping=Ha,i.selectAssetAttachments=Wa,i.selectAssetById=os,i.selectAssetProcedureById=is,i.selectAssetProcedureFieldValues=Ht,i.selectAssetProcedureFieldValuesAttachmentById=Oh,i.selectAssetProcedureFieldValuesAttachments=An,i.selectAssetProcedureFieldValuesAttachmentsByIds=yn,i.selectAssetProcedureFieldValuesAttachmentsMapping=Bt,i.selectAssetProcedureFieldValuesById=Wt,i.selectAssetProcedureFieldValuesMapping=Rn,i.selectAssetProcedureFieldValuesOfAsset=wh,i.selectAssetProcedureFields=Ut,i.selectAssetProcedureFieldsAttachmentById=hh,i.selectAssetProcedureFieldsAttachments=sn,i.selectAssetProcedureFieldsAttachmentsMapping=tn,i.selectAssetProcedureFieldsById=Th,i.selectAssetProcedureFieldsMapping=on,i.selectAssetProcedureFieldsOfAssetProcedure=Sh,i.selectAssetProcedureInstanceById=Qt,i.selectAssetProcedureInstances=Zt,i.selectAssetProcedureInstancesByIds=kh,i.selectAssetProcedureInstancesMapping=Xt,i.selectAssetProcedureInstancesOfAssetProcedure=En,i.selectAssetProcedureInstancesOfAssetType=Ch,i.selectAssetProcedures=Cn,i.selectAssetProceduresByIds=Gh,i.selectAssetProceduresMapping=ss,i.selectAssetProceduresOfOrganization=Bh,i.selectAssetStageById=Qn,i.selectAssetStageCompletionById=Wn,i.selectAssetStageCompletionMapping=ys,i.selectAssetStageCompletions=Yh,i.selectAssetStageCompletionsByIds=Kn,i.selectAssetStages=xn,i.selectAssetStagesByIds=bs,i.selectAssetStagesMappingOfAssetProcedure=Qh,i.selectAssetStagesOfAssetProcedure=xh,i.selectAssetTypeAttachmentById=rc,i.selectAssetTypeAttachmentMapping=nc,i.selectAssetTypeAttachments=cc,i.selectAssetTypeById=Ds,i.selectAssetTypeFieldValues=qs,i.selectAssetTypeFieldValuesAttachmentById=Fm,i.selectAssetTypeFieldValuesAttachments=vc,i.selectAssetTypeFieldValuesAttachmentsByIds=wc,i.selectAssetTypeFieldValuesAttachmentsMapping=vs,i.selectAssetTypeFieldValuesById=Ms,i.selectAssetTypeFieldValuesMapping=Vc,i.selectAssetTypeFieldValuesOfAsset=Om,i.selectAssetTypeFields=st,i.selectAssetTypeFieldsAttachmentById=um,i.selectAssetTypeFieldsAttachments=yc,i.selectAssetTypeFieldsAttachmentsMapping=Ac,i.selectAssetTypeFieldsById=fm,i.selectAssetTypeFieldsMapping=Fc,i.selectAssetTypeFieldsOfAssetType=Am,i.selectAssetTypeValuesOfAssetType=_m,i.selectAssetTypes=Mm,i.selectAssetTypesByIds=Cm,i.selectAssetTypesMapping=Vs,i.selectAssets=Un,i.selectAssetsByIds=Wh,i.selectAssetsMapping=ds,i.selectAssetsOfAssetType=us,i.selectAttachmentsOfAsset=Ya,i.selectAttachmentsOfAssetProcedureFieldValues=fn,i.selectAttachmentsOfAssetProcedureFields=lh,i.selectAttachmentsOfAssetType=dc,i.selectAttachmentsOfAssetTypeFieldValues=Ec,i.selectAttachmentsOfAssetTypeFields=dm,i.selectAttachmentsOfDocument=Hm,i.selectAttachmentsOfFormRevision=tp,i.selectAttachmentsOfFormSubmission=Lr,i.selectAttachmentsOfIssue=Id,i.selectAttachmentsOfIssueComment=vp,i.selectAttachmentsOfIssueType=zp,i.selectAttachmentsOfIssueTypeFieldValues=Pu,i.selectAttachmentsOfIssueTypeFields=Gp,i.selectAttachmentsOfProject=Do,i.selectCategories=Um,i.selectCategoriesByIds=$m,i.selectCategoryById=Gs,i.selectCategoryMapping=Bs,i.selectCommentsOfIssue=jp,i.selectConversation=sh,i.selectConversationMapping=qt,i.selectConversations=th,i.selectCurrentUser=yt,i.selectDeletedRequests=QA,i.selectDocumentAttachmentById=nr,i.selectDocumentAttachmentMapping=ir,i.selectDocumentById=hr,i.selectDocuments=lr,i.selectDocumentsByIds=Wm,i.selectDocumentsMapping=_e,i.selectFieldValuesOfAssetProcedureInstance=Eh,i.selectFormById=Dr,i.selectFormMapping=Vr,i.selectFormRevisionAttachmentsMapping=Rr,i.selectFormRevisionById=ip,i.selectFormRevisionMapping=ct,i.selectFormRevisions=jr,i.selectFormRevisionsOfForm=qr,i.selectFormSubmissionAttachemntsByIds=Gr,i.selectFormSubmissionAttachmentsMapping=ti,i.selectFormSubmissionById=ri,i.selectFormSubmissions=ci,i.selectFormSubmissionsMapping=ni,i.selectFormSubmissionsOfAsset=Xr,i.selectFormSubmissionsOfForm=Yr,i.selectFormSubmissionsOfIssue=Jr,i.selectForms=dp,i.selectGeoImageById=oi,i.selectGeoImageMapping=nd,i.selectGeoImages=cd,i.selectGeoImagesOfProject=fp,i.selectIsImportingProjectFile=oy,i.selectIsLoggedIn=Dm,i.selectIssueAssociationById=ld,i.selectIssueAssociationMapping=Ne,i.selectIssueAssociations=bp,i.selectIssueAssociationsOfAsset=pd,i.selectIssueAssociationsOfIssue=md,i.selectIssueAssociationsToIssue=hd,i.selectIssueAttachmentById=Fd,i.selectIssueAttachmentMapping=Td,i.selectIssueAttachments=bd,i.selectIssueById=Ei,i.selectIssueCommentAttachmentById=Md,i.selectIssueCommentAttachmentMapping=jd,i.selectIssueCommentAttachments=qd,i.selectIssueCommentById=Oi,i.selectIssueCommentMapping=Vd,i.selectIssueCountOfCategory=Bm,i.selectIssueMapping=Ld,i.selectIssueTypeAttachmentById=xd,i.selectIssueTypeAttachmentMapping=Zd,i.selectIssueTypeAttachments=Qd,i.selectIssueTypeById=Ni,i.selectIssueTypeFieldValues=Vi,i.selectIssueTypeFieldValuesAttachmentById=oA,i.selectIssueTypeFieldValuesAttachments=Fu,i.selectIssueTypeFieldValuesAttachmentsByIds=Ru,i.selectIssueTypeFieldValuesAttachmentsMapping=Bi,i.selectIssueTypeFieldValuesById=Di,i.selectIssueTypeFieldValuesMapping=lu,i.selectIssueTypeFieldValuesOfIssue=Jp,i.selectIssueTypeFields=mt,i.selectIssueTypeFieldsAttachmentById=Lp,i.selectIssueTypeFieldsAttachments=ru,i.selectIssueTypeFieldsAttachmentsMapping=cu,i.selectIssueTypeFieldsById=aA,i.selectIssueTypeFieldsMapping=Su,i.selectIssueTypeFieldsOfIssueType=tA,i.selectIssueTypeMapping=ju,i.selectIssueTypeValuesOfIssueType=iA,i.selectIssueTypes=qu,i.selectIssueTypesByIds=lA,i.selectIssueTypesOfOrganization=hA,i.selectIssueUpdateMapping=$u,i.selectIssueUpdatesOfIssue=Bu,i.selectIssuesByIds=qp,i.selectIssuesOfIssueType=Hi,i.selectIssuesOfIssueTypeCount=mA,i.selectLatestAssetProcedureFieldsOfAssetProcedure=gh,i.selectLatestAssetTypeFieldsOfAssetType=ym,i.selectLatestFormRevisionOfForm=ap,i.selectLatestIssueTypeFieldsOfIssueType=sA,i.selectLatestRetryTime=xA,i.selectNumberOfAssetsOfAssetType=Kh,i.selectOrganizationAccessById=OA,i.selectOrganizationAccessForUser=vA,i.selectOrganizationAccessUserMapping=Zu,i.selectOrganizationAccesses=Ji,i.selectOrganizationById=YA,i.selectOrganizationUsersAsMapping=To,i.selectOrganizationUsersIds=go,i.selectOrganizations=So,i.selectOrganizationsMapping=fo,i.selectOrganizationsWithAccess=JA,i.selectProjectAccessById=wA,i.selectProjectAccessForUser=EA,i.selectProjectAccessMapping=Qi,i.selectProjectAccessUserMapping=ao,i.selectProjectAccesses=io,i.selectProjectAttachmentById=Vo,i.selectProjectAttachmentMapping=ko,i.selectProjectById=DA,i.selectProjectFileById=dy,i.selectProjectFileMapping=Yo,i.selectProjectFiles=Jo,i.selectProjectMapping=gt,i.selectProjectUsersAsMapping=po,i.selectProjectUsersIds=mo,i.selectProjects=VA,i.selectProjectsOfOrganization=XA,i.selectRehydrated=my,i.selectRootDocuments=Ym,i.selectSortedOrganizationUsers=ZA,i.selectSortedProjectUsers=UA,i.selectStageMapping=tt,i.selectTeamById=je,i.selectTeams=la,i.selectTeamsByIds=py,i.selectTeamsMapping=oa,i.selectTeamsOfOrganization=Ay,i.selectTeamsOfUser=yy,i.selectUploadUrl=fr,i.selectUserById=RA,i.selectUsersByIds=PA,i.selectUsersMapping=ft,i.separateFilesFromValues=Xe,i.separateImageFromFields=Af,i.setActiveProjectFileId=Wo,i.setAsset=Nh,i.setAssetAttachment=Ga,i.setAssetAttachments=ah,i.setAssetProcedure=Uh,i.setAssetProcedureFieldValues=_h,i.setAssetProcedureFieldValuesAttachment=Ih,i.setAssetProcedureFieldValuesAttachments=Fh,i.setAssetProcedureFieldValuesMany=vh,i.setAssetProcedureFields=ph,i.setAssetProcedureFieldsAttachment=rh,i.setAssetProcedureFieldsAttachments=dh,i.setAssetProcedureFieldsMany=Ah,i.setAssetProcedureInstance=qh,i.setAssetProcedureInstances=Mh,i.setAssetProcedures=$h,i.setAssetStage=Xn,i.setAssetStages=Jh,i.setAssetType=vm,i.setAssetTypeAttachment=sc,i.setAssetTypeAttachments=tm,i.setAssetTypeFieldValues=Rm,i.setAssetTypeFieldValuesAttachment=gm,i.setAssetTypeFieldValuesAttachments=Tm,i.setAssetTypeFieldValuesMany=Pm,i.setAssetTypeFields=lm,i.setAssetTypeFieldsAttachment=am,i.setAssetTypeFieldsAttachments=nm,i.setAssetTypeFieldsMany=hm,i.setAssetTypes=wm,i.setAssets=Hh,i.setConversation=Da,i.setCurrentUser=FA,i.setDocumentAttachment=xc,i.setDocumentAttachments=Lm,i.setDocuments=dr,i.setForm=np,i.setFormRevision=_r,i.setFormRevisionAttachment=Zm,i.setFormRevisionAttachments=Qm,i.setFormSubmission=ut,i.setFormSubmissionAttachment=op,i.setFormSubmissionAttachments=lp,i.setFormSubmissions=pp,i.setGeoImage=Le,i.setGeoImages=ed,i.setIsImportingProjectFile=Ho,i.setIssueAssociation=gp,i.setIssueAssociations=Sp,i.setIssueAttachment=fd,i.setIssueAttachments=Fp,i.setIssueComment=Fi,i.setIssueCommentAttachment=_d,i.setIssueCommentAttachments=Op,i.setIssueComments=zd,i.setIssueType=We,i.setIssueTypeAttachment=Kd,i.setIssueTypeAttachments=Cp,i.setIssueTypeFieldValues=Hp,i.setIssueTypeFieldValuesAttachment=cA,i.setIssueTypeFieldValuesAttachments=rA,i.setIssueTypeFieldValuesMany=Wp,i.setIssueTypeFields=Zp,i.setIssueTypeFieldsAttachment=Dp,i.setIssueTypeFieldsAttachments=Up,i.setIssueTypeFieldsMany=Qp,i.setIssueUpdate=pA,i.setLoggedIn=Lc,i.setOrganization=BA,i.setOrganizations=yo,i.setProject=qA,i.setProjectAttachment=jo,i.setProjectAttachments=qo,i.setProjectFile=iy,i.setProjectFiles=ay,i.setProjects=ro,i.setRehydrated=hy,i.setTeam=Ee,i.setTokens=km,i.setUploadUrl=yr,i.setUser=yA,i.setUsers=Nu,i.shallowEqual=zl,i.slugify=Zl,i.spacesToDashesLower=Xl,i.teamReducer=tl,i.teamSlice=ra,i.toFileNameSafeString=Jl,i.toOfflineIdRecord=Ma,i.truncate=Ql,i.updateAsset=Ue,i.updateAssetAttachment=nh,i.updateAssetAttachments=La,i.updateAssetProcedure=De,i.updateAssetProcedureFieldValues=ze,i.updateAssetProcedureFieldValuesAttachment=Rh,i.updateAssetProcedureFieldValuesAttachments=pn,i.updateAssetProcedureFieldValuesMany=In,i.updateAssetProcedureFields=dn,i.updateAssetProcedureFieldsAttachment=uh,i.updateAssetProcedureFieldsAttachments=xa,i.updateAssetProcedureFieldsMany=yh,i.updateAssetProcedureInstance=Ve,i.updateAssetProcedureInstances=jh,i.updateAssetProcedures=Vh,i.updateAssetStage=gs,i.updateAssetStageCompletion=Ln,i.updateAssetStageCompletions=Nn,i.updateAssetStages=et,i.updateAssetType=Be,i.updateAssetTypeAttachment=sm,i.updateAssetTypeAttachments=ic,i.updateAssetTypeFieldValues=$e,i.updateAssetTypeFieldValuesAttachment=bm,i.updateAssetTypeFieldValuesAttachments=_c,i.updateAssetTypeFieldValuesMany=kc,i.updateAssetTypeFields=bc,i.updateAssetTypeFieldsAttachment=cm,i.updateAssetTypeFieldsAttachments=mc,i.updateAssetTypeFieldsMany=mm,i.updateAssetTypes=jm,i.updateAssets=Lh,i.updateCategory=Kc,i.updateConversation=Ua,i.updateDocumentAttachment=Nm,i.updateDocumentAttachments=er,i.updateDocuments=Ae,i.updateForm=rp,i.updateFormRevisionAttachment=xm,i.updateFormRevisionAttachments=Ir,i.updateFormSubmission=Kr,i.updateFormSubmissionAttachment=hp,i.updateFormSubmissionAttachments=Br,i.updateFormSubmissions=Ap,i.updateGeoImage=id,i.updateGeoImages=yp,i.updateIssue=ht,i.updateIssueAssociation=od,i.updateIssueAssociations=Tp,i.updateIssueAttachment=Rp,i.updateIssueAttachments=Sd,i.updateIssueCommentAttachment=_p,i.updateIssueCommentAttachments=vd,i.updateIssueType=Eu,i.updateIssueTypeAttachment=kp,i.updateIssueTypeAttachments=Yd,i.updateIssueTypeFieldValues=He,i.updateIssueTypeFieldValuesAttachment=dA,i.updateIssueTypeFieldValuesAttachments=Iu,i.updateIssueTypeFieldValuesMany=Kp,i.updateIssueTypeFields=yu,i.updateIssueTypeFieldsAttachment=$p,i.updateIssueTypeFieldsAttachments=au,i.updateIssueTypeFieldsMany=xp,i.updateOrganization=HA,i.updateOrganizationAccess=Ju,i.updateOrganizations=NA,i.updateProject=uo,i.updateProjectAccess=eo,i.updateProjectAttachment=sy,i.updateProjectAttachments=Mo,i.updateProjectFile=na,i.updateProjectFiles=cy,i.updateProjects=kA,i.updateTeam=da,i.updateUser=TA,i.updateUsers=gA,i.userReducer=Wu,i.userSlice=Ki,i.versioningReducer=il,i.versioningSlice=sl,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
14
+ external URLs and therefore not prepended with VITE_API_URL.`;throw new Error(y)}const p=d.type.split("/")[1];if(!p)throw new Error("File has no extension");const A=a??o+"."+p;if(d=En(d,A),!d.name)throw new Error("Failed to set file's name");await this.addCache(d,o),Tt[c]=new Promise(y=>{y(d)})}return d}}class pf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,a={},c=[],r=[];for(const d of e){const{revisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,form_revision:o,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,form_revision:o};r.push(I)}this.dispatch(br(c));const u=this.enqueueRequest({description:"Attach files to form revision",method:h.POST,url:"/form-revision-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.form_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Ir(d.attachments))}).catch(()=>{this.dispatch(Fr(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization form revision attachments",method:h.GET,url:"/form-revision-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(Tr(s))}}class Af extends E{add(e){var u;const{store:s}=this.client,a=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,c=R({...e,created_by:a,submitted_at:new Date().toISOString()});this.dispatch(Js(c));const r=this.enqueueRequest({description:"Create form revision",method:h.POST,url:"/form-revisions/",payload:_(c),blockers:[e.form],blocks:[c.uuid]});return r.then(m=>{this.dispatch(_r(m))}).catch(()=>{this.dispatch(Xs(c.uuid))}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization form revisions",method:h.GET,url:"/form-revisions/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(vr(s))}}const yf=async t=>{const e={},s=[];for(const n of t){if(n.type!=="section")throw new Error(`Expected ISerializedField type to be a section. Got ${n.type} instead.`);const{fields:a}=n,c=[];for(const r of a){if(r.image){if(r.image instanceof Promise)try{e[r.identifier]=await r.image}catch(u){console.error("Failed to get image from promise",u)}else e[r.identifier]=r.image;delete r.image}c.push(r)}s.push({...n,fields:c})}return{fields:s,images:e}};class ff extends E{add(e,s){var d;const{store:n}=this.client,a=new Date().toISOString(),c=(d=n.getState().userReducer.currentUser)==null?void 0:d.uuid,r=R({...e,submitted_at:a,created_by:c}),u=R({...s,form:r.uuid,submitted_at:a,created_by:c});this.dispatch(Qs(r)),this.dispatch(Js(u));const m=this.enqueueRequest({description:"Create form",method:h.POST,url:"/forms/",payload:{..._(r),initial_revision:{uuid:u.uuid,submitted_at:u.submitted_at,title:u.title,description:u.description,fields:u.fields}},blockers:[],blocks:[r.uuid,u.uuid]});return m.catch(o=>{throw this.dispatch(xs(r.uuid)),this.dispatch(Xs(u.uuid)),o}),[r,u,m]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Dr(e)(n);if(!a)throw new Error("Expected form to exist");const c=Yr(e)(n);c.length>0&&this.dispatch(lt(c.map(({uuid:u})=>u)));const r=qr(e)(n);r.length>0&&this.dispatch(Er(r.map(({uuid:u})=>u))),this.dispatch(xs(e));try{return await this.enqueueRequest({description:"Delete form",method:h.DELETE,url:`/forms/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(Qs(a)),r.length>0&&this.dispatch(wr(r)),c.length>0&&this.dispatch(ot(c)),u}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization forms",method:h.GET,url:"/forms/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(kr(s))}}class Sf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,a={},c=[],r=[];for(const d of e){const{submissionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,form_submission:o,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:p,form_submission:o};r.push(I)}this.dispatch(rt(c));const u=this.enqueueRequest({description:"Attach files to form submission",method:h.POST,url:"/form-submission-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.form_submission),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Br(d.attachments))}).catch(d=>{throw this.dispatch(dt(c.map(o=>o.uuid))),d}),[c,u.then(({attachments:d})=>d)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=Gr(e)(n);this.dispatch(dt(e));try{await this.enqueueRequest({description:"Delete form submission attachments",method:h.DELETE,url:"/form-submission-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(rt(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get form submission attachments",method:h.GET,url:"/form-submission-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch($r(s))}}class gf extends E{async add(e){var p;const{store:s}=this.client,{file:n,...a}=e,c=new Date().toISOString(),r=(p=s.getState().userReducer.currentUser)==null?void 0:p.uuid,u=a.project,m=await this.getFilePayload(n),d=R({...a,file_name:n.name,file_sha1:m.sha1,file:URL.createObjectURL(n),submitted_at:c,created_by:r});this.dispatch(td(d));const o=this.enqueueRequest({description:"Add geo image",method:h.POST,url:"/geo-images/",payload:{uuid:d.uuid,submitted_at:c,title:d.title,description:d.description,geo_marker:d.geo_marker,canvas_marker:d.canvas_marker,sha1:d.file_sha1,project:d.project,file_name:d.file_name,direction:d.direction,original_date:d.original_date,file:m},blocks:[u],blockers:[u]});return o.then(A=>{this.processPresignedUrls(A.presigned_urls),this.dispatch(Le(A.geo_image))}).catch(()=>{this.dispatch(ui(d.uuid))}),[d,o.then(A=>A.geo_image)]}async bulkAdd(e,s){var p;const{store:n}=this.client,a=new Date().toISOString(),c=(p=n.getState().userReducer.currentUser)==null?void 0:p.uuid,r=[],u=[],m=[],d={};for(const A of e){const{file:y,...b}=A,I=await this.getFilePayload(y);I.sha1 in d||(d[I.sha1]=I);const T=R({...b,file_name:y.name,file_sha1:I.sha1,file:URL.createObjectURL(y),submitted_at:a,created_by:c,project:s});r.push(T),u.push(T.uuid),m.push({uuid:T.uuid,sha1:T.file_sha1,file_name:T.file_name,title:T.title,description:T.description,geo_marker:T.geo_marker,canvas_marker:T.canvas_marker,direction:T.direction,original_date:T.original_date})}this.dispatch(sd(r));const o=this.enqueueRequest({description:"Bulk add geo images",method:h.POST,url:"/geo-images/bulk/",payload:{submitted_at:a,project:s,geo_images:m,files:Object.values(d)},blocks:[s],blockers:u});return o.then(A=>{this.processPresignedUrls(A.presigned_urls),this.dispatch(ed(A.geo_images))}).catch(()=>{this.dispatch(nd(u))}),[r,o.then(A=>A.geo_images)]}update(e){const{store:s}=this.client,n=s.getState(),a=oi(e.uuid)(n);if(!a)throw new Error(`Map image with uuid ${e.uuid} does not exist in the store`);const c={...a,...e};this.dispatch(id(c));const r=this.enqueueRequest({description:"Update geo image",method:h.PATCH,url:`/geo-images/${e.uuid}/`,payload:e,blocks:[e.uuid],blockers:[e.uuid]});return r.then(u=>{this.dispatch(Le(u))}).catch(()=>{this.dispatch(Le(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=oi(e)(n);if(!a)throw new Error(`Map image with uuid ${e} does not exist in the store`);this.dispatch(ui(e));const c=this.enqueueRequest({description:"Delete geo image",method:h.DELETE,url:`/geo-images/${e}/`,blocks:[e],blockers:[e]});return c.catch(()=>{this.dispatch(Le(a))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get geo images",method:h.GET,url:`/projects/${e}/geo-images/`,blocks:[e],blockers:[]});this.dispatch(xr(s))}}class Tf extends P{add(e){var u;const{store:s}=this.client,n=new Date().toISOString(),a=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,c=R({...e,submitted_at:n,created_by:a});this.dispatch(hi(c));const r=this.enqueueRequest({description:"Add issue association",method:h.POST,url:"/issue-associations/",payload:_(c),blockers:[e.associated_issue,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[c.uuid]});return r.then(m=>{this.dispatch(od(m))}).catch(()=>{this.dispatch(pi(c.uuid))}),[c,r]}async delete(e){const{store:s}=this.client,n=ld(e)(s.getState());if(!n)throw new Error(`Issue association with uuid ${e} not found in store.`);this.dispatch(pi(e));const a=this.enqueueRequest({description:"Delete issue association",method:h.DELETE,url:`/issue-associations/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(hi(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch issue associations",method:h.GET,url:"/issue-associations/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(ud(s))}}class bf extends Fe{constructor(){super(...arguments);f(this,"name","Issue Attachment");f(this,"url","/issue-attachments");f(this,"initializeAttachments",fi);f(this,"addAttachments",Si);f(this,"updateAttachments",Sd);f(this,"removeAttachments",gi);f(this,"removeAttachment",gd);f(this,"setAttachment",fd);f(this,"selectAttachment",Fd)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue attachments",method:h.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(fi(n))}}class If extends Fe{constructor(){super(...arguments);f(this,"name","Issue Comment Attachment");f(this,"url","/issue-comment-attachments");f(this,"initializeAttachments",bi);f(this,"addAttachments",Od);f(this,"updateAttachments",vd);f(this,"removeAttachments",Ed);f(this,"removeAttachment",wd);f(this,"setAttachment",_d);f(this,"selectAttachment",Md)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue_comment:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue_comment:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueCommentUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue comment attachments",method:h.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(bi(n))}}class Ff extends P{add(e){var c;const{store:s}=this.client,n=R({...e,author:(c=s.getState().userReducer.currentUser)==null?void 0:c.uuid,submitted_at:new Date().toISOString()});this.dispatch(Ri(n));const a=this.enqueueRequest({description:"Add issue comment",method:h.POST,url:"/issue-comments/",payload:_(n),blockers:[e.issue],blocks:[n.uuid]});return a.catch(()=>{this.dispatch(Pi(n.uuid))}),[n,a]}update(e){const{store:s}=this.client,n=Oi(e.uuid)(s.getState());if(!n)throw new Error(`Comment with uuid ${e.uuid} not found in store`);const a={...n,...e};this.dispatch(Fi(a));const c=this.enqueueRequest({description:"Edit issue comment",method:h.PATCH,url:`/issue-comments/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{this.dispatch(Fi(n))}),[a,c]}remove(e){const{store:s}=this.client,n=Oi(e)(s.getState());if(!n)throw new Error(`Comment with uuid ${e} not found in store`);this.dispatch(Pi(e));const a=this.enqueueRequest({description:"Delete comment",method:h.DELETE,url:`/issue-comments/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(Ri(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get comments",method:h.GET,url:"/issue-comments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(zd(s))}}class Rf extends P{add(e){var m;const{store:s}=this.client,n=s.getState(),a=new Date().toISOString(),c=(m=n.userReducer.currentUser)==null?void 0:m.uuid,r=R({...e,submitted_at:a,created_by:c});this.dispatch(vi(r));const u=this.enqueueRequest({description:"Create issue",method:h.POST,url:"/issues/",payload:_(r),blockers:["add-issue",r.project,r.issue_type,...r.category?[r.category]:[]],blocks:[r.uuid]});return u.then(d=>{this.dispatch(ht(d))}).catch(d=>{throw this.dispatch(wi(r.uuid)),d}),[r,u]}update(e){var m;const s=this.client.store.getState(),n=Ei(e.uuid)(s);if(!n)throw new Error(`Attempting to update an issue with uuid ${e.uuid} that doesn't exist in the store`);const a={...n,...e};this.dispatch(ht(a));const c={};for(const d of[v.TITLE,v.DESCRIPTION,v.STATUS,v.CATEGORY,v.PRIORITY,v.ASSIGNED_TO,v.DUE_DATE])if(d in e&&e[d]!==n[d])switch(d){case v.PRIORITY:case v.STATUS:{const o=e[d];c[d]=o!==void 0?Number(o):null;break}case v.DUE_DATE:case v.DESCRIPTION:case v.TITLE:c[d]=e[d]??null;break;case v.CATEGORY:{let o=null;const p=e[d];if(p&&(o=s.categoryReducer.instances[p]??null,!o))throw new Error(`Trying to update issue category to ${p} which does not exist in store`);c[d]=o?{name:o.name,color:o.color,uuid:o.uuid}:null;break}case v.ASSIGNED_TO:{let o=null;const p=e[d];if(p&&(o=s.userReducer.instances[p]??null,!o))throw new Error(`Trying to update issue assigned_to to ${p} which does not exist in store`);c[d]=o?{full_name:o.first_name,uuid:o.uuid}:null;break}}const r=R({created_by:(m=s.userReducer.currentUser)==null?void 0:m.uuid,submitted_at:new Date().toISOString(),issue:n.uuid,changes:c});this.dispatch(zu(r));const u=this.enqueueRequest({description:"Edit issue",method:h.PATCH,url:`/issues/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.catch(()=>{this.dispatch(ht(n)),this.dispatch(Du(r.uuid))}),[a,u]}async remove(e){const{store:s}=this.client,n=s.getState(),a=Ei(e)(n);if(!a)throw new Error(`No issue with uuid ${e} found in the store`);const c=Id(e)(n),r=Bu(e)(n),u=Jr(e)(n),m={};for(const o of hd(e)(n))m[o.uuid]=o;for(const o of md(e)(n))m[o.uuid]=o;const d=Object.values(m);this.dispatch(wi(e)),c.length>0&&this.dispatch(gi(c.map(({uuid:o})=>o))),r.length>0&&this.dispatch(Uu(r.map(({uuid:o})=>o))),u.length>0&&this.dispatch(lt(u.map(({uuid:o})=>o))),d.length>0&&this.dispatch(Ai(d.map(({uuid:o})=>o)));try{return await this.enqueueRequest({description:"Delete issue",method:h.DELETE,url:`/issues/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(vi(a)),this.dispatch(Si(c)),this.dispatch(Vu(r)),this.dispatch(ot(u)),this.dispatch(mi(d)),o}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issues",method:h.GET,url:"/issues/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch($d(s))}}class Pf extends Fe{constructor(){super(...arguments);f(this,"name","Issue Type Attachment");f(this,"url","/issue-type-attachments");f(this,"initializeAttachments",qi);f(this,"addAttachments",Wd);f(this,"updateAttachments",Yd);f(this,"removeAttachments",Xd);f(this,"removeAttachment",Jd);f(this,"setAttachment",Kd);f(this,"selectAttachment",xd)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueTypeUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue type attachments",method:h.GET,url:`${this.url}/`,queryParams:{organization:s},blocks:[],blockers:[]});this.dispatch(qi(n))}}class Of extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,file_extension:y.extension,field_identifier:p,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(iu(c));const u=this.enqueueRequest({description:"Add issue type fields attachments",method:h.POST,url:"/issue-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(nu(d.attachments))}).catch(()=>{this.dispatch(au(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"get issue type fields attachments",method:h.GET,url:"/issue-type-fields-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(su(s))}}class _f extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.uuid,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Au(c));const r=this.enqueueRequest({description:"Add Issue Type Fields",method:h.POST,url:"/issue-type-fields/",payload:_(c),blockers:[c.issue_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(yu(m))}).catch(m=>{throw this.dispatch(fu(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Issue Type Fields",method:h.GET,url:"/issue-type-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(pu(s))}}class vf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.uuid,a={},c=[],r=[];for(const d of e){const{fieldValuesUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const b=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,field_values:o,submitted_at:s,field_identifier:p});c.push(b);const I={uuid:b.uuid,file_name:A.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:p,field_values:o};r.push(I)}this.dispatch(pt(c));const u=this.enqueueRequest({description:"Add issue type field values attachments",method:h.POST,url:"/issue-type-field-values-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.field_values),blocks:c.map(d=>d.uuid)});return u.then(({presigned_urls:d,attachments:o})=>{this.processPresignedUrls(d),this.dispatch(Iu(o))}).catch(d=>{throw this.dispatch(At(c.map(o=>o.uuid))),d}),[c,u.then(({attachments:d})=>d)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=Ru(e)(n);this.dispatch(At(e));try{await this.enqueueRequest({description:"Delete issue type field values attachments",method:h.DELETE,url:"/issue-type-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(pt(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue type field values attachments",method:h.GET,url:"/issue-type-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(bu(s))}}class wf extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.uuid,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add issue type field values",method:h.POST,url:"/issue-type-field-values/",payload:_(a),blockers:[e.issue,e.fields_revision],blocks:[a.uuid]});return this.dispatch(ki(a)),c.then(u=>(this.dispatch(He(u)),u)).catch(()=>{this.dispatch(zi(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=Di(e.uuid)(n);if(!a)throw new Error(`Expected IssueTypeFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(He(c));const r=this.enqueueRequest({description:"Update issue type field values",method:h.PATCH,url:`/issue-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.issue],blocks:[c.uuid]});return r.then(u=>{this.dispatch(He(u))}).catch(()=>{this.dispatch(He(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Di(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Pu(e)(n);this.dispatch(zi(e)),this.dispatch(At(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete issue type field values",method:h.DELETE,url:`/issue-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ki(a)),this.dispatch(pt(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue type field values",method:h.GET,url:"/issue-type-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(ou(s))}}class Ef extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,submitted_at:new Date().toISOString(),created_by:(r=n.userReducer.currentUser)==null?void 0:r.uuid});this.dispatch(wu(a));const c=this.enqueueRequest({method:h.POST,url:"/issue-types/",payload:_(a),blockers:[],blocks:[a.uuid]});return c.then(u=>{this.dispatch(We(u))}).catch(()=>{this.dispatch(Li(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=Ni(e.uuid)(n);if(!a)throw new Error(`IssueType with uuid ${e.uuid} does not exist in the store.`);const c={...a,...e};this.dispatch(Eu(c));const r=this.enqueueRequest({method:h.PATCH,url:`/issue-types/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(We(u))}).catch(()=>{this.dispatch(We(a))}),[c,r]}delete(e){const{store:s}=this.client,n=s.getState(),a=Ni(e)(n);if(!a)throw new Error(`IssueType with uuid ${e} does not exist in the store.`);const c=Hi(e)(n);this.dispatch(Li(e)),this.dispatch(Gd(c.map(u=>u.uuid)));const r=this.enqueueRequest({method:h.DELETE,url:`/issue-types/${e}/`,blockers:[e],blocks:[]});return r.catch(()=>{this.dispatch(We(a)),this.dispatch(Bd(c))}),r}async refreshStore(e){const s=await this.enqueueRequest({method:h.GET,url:"/issue-types/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(vu(s))}}class jf extends P{async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue updates",method:h.GET,url:"/issue-updates/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(ku(s))}}const qf=1800;function Mf(t){if(!t.access)throw new Error("Missing access token");if(!t.refresh)throw new Error("Missing refresh token");return{accessToken:t.access,refreshToken:t.refresh}}class Cf extends By{constructor(){super(...arguments);f(this,"_getRenewedTokens",async s=>{const n=this.enqueueRequest({description:"Get renewed tokens",method:h.POST,url:this.refreshTokensUrl,payload:{refresh:s},isAuthNeeded:!1,blockers:[],blocks:[],checkAuth:!1,immediate:!0});let a;try{a=await n}catch(c){console.error("Could not renew tokens; clearing auth",c),this.clearAuth();return}if(!a.access)throw new Error("Missing access token");return{accessToken:a.access,refreshToken:a.refresh??this.getRefreshToken()}})}clearAuth(){console.debug(this.constructor.name,"clearing auth;"),this.dispatch(Lc(!1)),this.clearTokens(),this.dispatch({type:vl.RESET_STATE}),this.dispatch({type:Al})}async renewTokens(){const s=this.getRefreshToken();if(!s)throw new Error("No refresh token found");console.debug(this.constructor.name,"renewing tokens");try{const n=await this._getRenewedTokens(s);if(!n)return;console.log("Got renewed tokens"),this.setTokens(n)}catch(n){throw console.error("Could not renew tokens; clearing auth",n),this.clearAuth(),n}}tokenIsExpiringSoon(){const s=this.getAccessToken();if(!s)return!1;const n=Date.now()/1e3;let a;try{a=wl(s).exp??n}catch{a=n}return a-n<qf}getAuthHeader(){return`Bearer ${this.getAccessToken()}`}async prepareAuth(){if(this.tokenIsExpiringSoon()){console.debug(this.constructor.name,"preparing auth");try{await this.renewTokens()}catch(s){return s instanceof q&&this.clearAuth(),s instanceof Error?Promise.reject(s):Promise.reject(new Error((s??qe).toString()))}}}async handleUnauthorized(s,n){const a=this.client.store.getState();if(s.url.endsWith("/token/refresh/"))throw a.authReducer.isLoggedIn&&console.warn("No signed-in user to sign out."),this.clearAuth(),new q({message:"You have been signed out due to inactivity.",response:n,discard:!0});if(a.authReducer.isLoggedIn)await this.renewTokens();else throw console.debug("Forbidden; user is not logged in."),new q({message:"Incorrect username or password.",response:n,discard:!0})}async initAuth(s){const n=ye.v4();return console.debug(this.constructor.name,"Initiating auth"),this.enqueueRequest({uuid:n,description:"Get token pair",method:h.POST,url:this.initTokensUrl,payload:s,isAuthNeeded:!1,checkAuth:!1,immediate:!0,blockers:[],blocks:[]}).then(a=>{this.setTokens(Mf(a))})}}class kf extends P{async update(e){const s=this.enqueueRequest({description:"Edit organization access",method:h.PATCH,url:`/organizations/${e.organization}/access/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return s.then(()=>{this.dispatch(Ju(e))}),s}async remove(e){return this.dispatch(Xu(e.uuid)),this.dispatch(Hu(e.user)),this.enqueueRequest({description:"Remove organization access",method:h.DELETE,url:`/organizations/${e.organization}/access/${e.uuid}/`,blockers:[e.uuid],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization accesses",method:h.GET,url:`/organizations/${e}/access/`,blockers:[],blocks:[]});this.dispatch(Yu(s))}}class zf extends P{create(e){return this.enqueueRequest({description:"Create organization",method:h.POST,url:"/organizations/",payload:{name:e},blockers:[],blocks:[`add-org-${e}`,"create-org"]})}async update(e){return this.enqueueRequest({description:"Edit organization",method:h.PATCH,url:`/organizations/${e.uuid}/`,payload:e,blockers:[`add-org-${e.name}`,e.uuid],blocks:[e.uuid]})}async invite(e,s){return this.enqueueRequest({description:"Invite user to organization",method:h.POST,url:`/organizations/${e}/invite/${s}/`,blockers:[],blocks:[]})}async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Get organizations",method:h.GET,url:`/projects/${e}/organizations/`,blockers:[],blocks:[]});for(const r of a)n[r.uuid]=r;const c=await this.enqueueRequest({description:"Get organization",method:h.GET,url:`/organizations/${s}/`,blockers:[],blocks:[]});n[c.uuid]=c,this.dispatch(yo(Object.values(n)))}}class Vf extends P{async update(e){return this.dispatch(eo(e)),this.enqueueRequest({description:"Edit project access",method:h.PATCH,url:`/project-accesses/${e.uuid}/`,payload:e,blockers:[e.uuid,"change-access-level"],blocks:[e.uuid]})}async remove(e){return this.dispatch(to(e)),this.enqueueRequest({description:"Delete project access",method:h.DELETE,url:`/project-accesses/${e}/`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project accesses",method:h.GET,url:"/project-accesses/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Zi(s))}}class Df extends Fe{constructor(){super(...arguments);f(this,"name","Project Attachment");f(this,"url","/project-attachments");f(this,"addAttachments",Eo);f(this,"updateAttachments",Mo);f(this,"removeAttachments",nn);f(this,"removeAttachment",Co);f(this,"setAttachment",jo);f(this,"selectAttachment",Vo)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,project:s.modelUuid})}buildAttachmentPayload(s){return{...s,project:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.projectUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get project attachments",method:h.GET,url:`${this.url}/`,queryParams:{project:s},blockers:[],blocks:[]});this.dispatch(wo(n))}}class Uf extends P{async saveExisting(e){if(!e.uuid)throw new Error("You can only use this method to save existing project files. The one provided has no uuid.");const s={...e};delete s.file;const n=this.enqueueRequest({method:h.PATCH,url:`/projects/files/${e.uuid}/`,payload:s,blockers:[e.uuid],blocks:[e.uuid]});return n.then(a=>{this.dispatch(cn(a))}),n}saveActive(){const{store:e}=this.client,s=e.getState(),n=s.projectFileReducer.activeProjectFileId;if(!n)throw new Error("No active project file");const a=s.projectFileReducer.instances[n];if(!a)throw new Error("No active project file");if(!a.bounds&&!a.canvas_bounds)throw new Error("Project file must either have bounds or canvas_bounds set");let c;if(typeof a.file=="string"&&!a.file.startsWith("blob:")){const m={...a};delete m.file,c={method:h.PATCH,url:`/projects/files/${n}/`,payload:m,blockers:[n],blocks:[n]}}else c=new Promise((m,d)=>{this.client.files.uploadFileToS3(a.file_sha1).then(([o])=>{m({method:h.POST,url:`/projects/${a.project}/files/`,payload:{...a,...o},blockers:[n],blocks:[n]})}).catch(d)});const u=Promise.resolve(c).then(m=>this.enqueueRequest(m));return u.then(m=>{this.dispatch(cn(m))}),this.dispatch(Ko),this.dispatch(Wo(null)),this.dispatch(Ho(!1)),[a,u]}delete(e){return this.dispatch(Lo(e)),this.enqueueRequest({method:h.DELETE,url:`/projects/files/${e}`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project files",method:h.GET,url:`/projects/${e}/files/`,blockers:[],blocks:[]});this.dispatch(Bo(s))}}class $f extends P{async add(e){if(!e.bounds&&!e.canvas_bounds)throw new Error("Project must either have bounds or canvas_bounds set");return await this.enqueueRequest({description:"Create project",method:h.POST,url:"/projects/",payload:{name:e.name,bounds:e.bounds,organization_owner:e.organization_owner},blockers:[],blocks:[]})}async update(e){if(!e.bounds&&!e.canvas_bounds)throw new Error("Project must either have bounds or canvas_bounds set");return this.dispatch(uo(e)),await this.enqueueRequest({description:"Update project",method:h.PATCH,url:`/projects/${e.uuid}/`,payload:{name:e.name,bounds:e.bounds},blockers:[e.uuid],blocks:[e.uuid]})}async delete(e){const{store:s}=this.client,n=s.getState(),a=gt(n),c=a[e];if(!c)throw new Error("Expected project to exist");const r=Jo(n).filter(d=>d.project===e);this.dispatch(No(r.map(({uuid:d})=>d)));const u=Do(c.uuid)(n);this.dispatch(nn(u.map(({uuid:d})=>d)));const m=io(n);this.dispatch(so(m.map(({uuid:d})=>d))),this.dispatch({type:"rehydrated/setRehydrated",payload:!1}),this.dispatch(oo(c.uuid));try{await this.enqueueRequest({description:"Delete project",method:h.DELETE,url:`/projects/${e}/`,blockers:[e],blocks:[]}),this.dispatch({type:"rehydrated/setRehydrated",payload:!0})}catch(d){throw this.dispatch(ro(Object.values(a))),this.dispatch(Zi(Object.values(m))),this.dispatch(Go(r)),this.dispatch(qo(u)),this.dispatch({type:"rehydrated/setRehydrated",payload:!0}),d}}invite(e,s){const n=ye.v4();return this.enqueueRequest({description:"Invite user to project",method:h.POST,url:`/projects/${e}/invite/${s}/`,payload:{uuid:n},blockers:[],blocks:[n]})}joinProject(e,s,n){return this.enqueueRequest({description:"Join project",method:h.GET,url:`/projects/${e}/join-project/${s}/${n}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}async acceptInvite(e){return this.enqueueRequest({description:"Accept project invite",method:h.PATCH,url:`/projects/${e}/accept-invite/`,blockers:[e],blocks:[e]}).then(()=>{this.dispatch(lo(e))})}}class Bf extends P{add(e){const s=R({...e,submitted_at:new Date().toISOString()});this.dispatch(el(s));const n=this.enqueueRequest({description:"Create team",method:h.POST,url:`/organizations/${e.organization}/teams/`,payload:s,blockers:[],blocks:[s.uuid]});return n.then(a=>{this.dispatch(Ee(a))}).catch(()=>{this.dispatch(on(s.uuid))}),[s,n]}update(e){const{store:s}=this.client,n=je(e.uuid)(s.getState());if(!n)throw new Error(`Expected team with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(un(a));const c=this.enqueueRequest({description:"Update team",method:h.PATCH,url:`/organizations/teams/${e.uuid}/`,payload:_(e),blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(Ee(r))}).catch(()=>{this.dispatch(Ee(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=je(e)(n);if(!a)throw new Error(`Expected team with uuid ${e} to exist`);this.dispatch(on(e));try{return await this.enqueueRequest({description:"Delete team",method:h.DELETE,url:`/organizations/teams/${e}/`,blockers:[e],blocks:[e]})}catch(c){throw this.dispatch(Ee(a)),c}}async setMembers(e,s){const{store:n}=this.client,a=je(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);if(s.length!==new Set(s).size)throw new Error("Duplicate members found in the list");this.dispatch(un({...a,members:s}));const c=this.enqueueRequest({description:"Set team members",method:h.PUT,url:`/organizations/teams/${e}/set-members/`,payload:{users:s},blockers:[e],blocks:[e]});return c.catch(()=>{this.dispatch(Ee(a))}),c}async addMembers(e,s){const{store:n}=this.client,a=je(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);const c=[...a.members,...s];return this.setMembers(e,c)}async removeMembers(e,s){const{store:n}=this.client,a=je(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);const c=a.members.filter(r=>!s.includes(r));return this.setMembers(e,c)}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch teams",method:h.GET,url:`/organizations/${e}/teams/`,blockers:[],blocks:[]});this.dispatch(xo(s))}}class Gf extends P{async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Fetch organization users",method:h.GET,url:`/organizations/${s}/users/`,blockers:[],blocks:[]});for(const r of a)n[r.uuid]=r;const c=await this.enqueueRequest({description:"Fetch project users",method:h.GET,url:`/projects/${e}/users/`,blockers:[],blocks:[]});for(const r of c)n[r.uuid]=r;this.dispatch(Nu(Object.values(n)))}}class Lf{constructor(e){f(this,"store");this.store=e}async enqueueRequest(e,s,n){return this._enqueueRequest(e,s,n).then(a=>{if(a instanceof q)throw a;return a})}_enqueueRequest(e,s,n){const a=new vn,c={...e,BASE_URL:s,serviceName:n};if(e.immediate){const r={...c,uuid:e.uuid??ye.v4()},u={payload:r,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:r,BASE_URL:s,serviceName:n}}}};An(u,this).then(m=>{a.resolve(m.body)}).catch(m=>{yn(m,u),m instanceof Error?a.reject(m):a.reject(new Error((m??qe).toString()))})}else{const r=this.store.dispatch(Ro(c)),u=d=>{if(d)a.resolve(d.body);else{const o=new q({message:"Could not get a response from the server.",response:d,discard:!0});a.reject(o)}},m=d=>{d instanceof q?d.options.discard=!0:(console.error("Received an unexpected error while processing a request:",d,`
15
+ Converting error to APIError and discarding.`),d=new q({message:"An error occurred while processing the request.",innerError:d,discard:!0})),a.reject(d)};r.then(u,m)}return a}}class Me{constructor(){f(this,"graph");f(this,"requestAttemptCounter");this.graph=new El.DepGraph,this.requestAttemptCounter={}}static _fromOutbox(e){const s=new Me;for(let n=0;n<e.length;n++){const a=e[n];if(!a){console.error("Outbox item was undefined");continue}s.sneakRequest(a);for(let c=0;c<n;c++){const r=e[c];if(!r){console.error("Previous outbox item was undefined");continue}r.payload.uuid!==a.payload.uuid&&r.payload.blocks.some(u=>a.payload.blockers.includes(u))&&Me._addDependency(a.payload.uuid,r.payload.uuid,s.graph)}}return s}_addDependency(e,s){Me._addDependency(e,s,this.graph)}static _addDependency(e,s,n){if(e===s)throw new Error(`Tried to add dependency from node to itself: ${e}`);if(!n.hasNode(e))throw new Error(`Tried to add dependency from non-existent node: ${e} (to node: ${s})`);if(!n.hasNode(s))throw new Error(`Tried to add dependency to non-existent node: ${s} (from node: ${e})`);n.addDependency(e,s)}addRequest(e){if(this.graph.addNode(e.payload.uuid,e),!(e.payload.blockers.length===0||this.graph.size()===1))for(const s of this.graph.overallOrder()){if(s===e.payload.uuid)continue;const n=this.graph.getNodeData(s);e.payload.blockers.some(a=>n.payload.blocks.includes(a))&&this._addDependency(e.payload.uuid,s)}}insertRequest(e){this.graph.addNode(e.payload.uuid,e);for(const s of this.graph.overallOrder()){if(s===e.payload.uuid)continue;this.graph.getNodeData(s).payload.blockers.some(a=>e.payload.blocks.includes(a))&&this._addDependency(s,e.payload.uuid)}}sneakRequest(e){this.graph.addNode(e.payload.uuid,e)}_getNextNode(){const e=this.graph.overallOrder(!0);let s=1/0,n;for(const a of e){const c=this.requestAttemptCounter[a]||0;c<s&&(s=c,n=a)}return n}peek(){const e=this._getNextNode();if(e)return this.graph.getNodeData(e)}remove(e){this.graph.removeNode(e),delete this.requestAttemptCounter[e]}pop(){const e=this.peek();return e&&this.graph.removeNode(e.payload.uuid),e}getQueue(){const e=this.graph.overallOrder().map(n=>this.graph.getNodeData(n)),s=this._getNextNode();if(s){const n=this.graph.getNodeData(s),a=e.findIndex(c=>c.payload.uuid===n.payload.uuid);a!==-1&&(e.splice(a,1),e.unshift(n))}return e}getReady(){let e=this.graph.overallOrder(!0).map(s=>this.graph.getNodeData(s));return e=e.sort((s,n)=>s.meta.offline.effect.timestamp.localeCompare(n.meta.offline.effect.timestamp)),e=e.sort((s,n)=>{const a=this.requestAttemptCounter[s.payload.uuid]||0,c=this.requestAttemptCounter[n.payload.uuid]||0;return a-c}),e}registerRetry(e){this.requestAttemptCounter[e]=(this.requestAttemptCounter[e]||0)+1}}const Nf=(t,e)=>{const s=new e(t);return Ty(s),gy(t),s};var bl=(t=>(t[t.USER_REGISTRATION=0]="USER_REGISTRATION",t[t.APPLICATION_INVITE=2]="APPLICATION_INVITE",t[t.PROJECT_INVITE=4]="PROJECT_INVITE",t[t.ORGANIZATION_INVITE=6]="ORGANIZATION_INVITE",t[t.ADD_EMAIL_DOMAIN=8]="ADD_EMAIL_DOMAIN",t[t.RESET_PASSWORD=10]="RESET_PASSWORD",t))(bl||{});i.APIError=q,i.AgentService=Gy,i.AssetAttachmentService=Ly,i.AssetProcedureFieldValuesAttachmentService=Wy,i.AssetProcedureFieldValuesService=Jy,i.AssetProcedureFieldsAttachmentService=Ny,i.AssetProcedureFieldsService=Hy,i.AssetProcedureInstanceService=Xy,i.AssetProcedureService=Zy,i.AssetService=Qy,i.AssetStageCompletionService=xy,i.AssetStageService=ef,i.AssetTypeAttachmentService=tf,i.AssetTypeFieldValuesAttachmentService=af,i.AssetTypeFieldValuesService=cf,i.AssetTypeFieldsAttachmentService=sf,i.AssetTypeFieldsService=nf,i.AssetTypeService=rf,i.AttachmentModel=Fn,i.BaseApiService=P,i.BaseSDK=Lf,i.COMMON_AUTO_FIELDS=Mn,i.CategoryService=df,i.DEFAULT_ISSUE_PRIORITY=ql,i.DEFAULT_ISSUE_STATUS=jl,i.DeferredPromise=vn,i.DocumentAttachmentService=uf,i.DocumentService=of,i.EMPTY_ARRAY=bn,i.EMPTY_OBJECT=In,i.EmailVerificationService=lf,i.FileService=mf,i.FormRevisionAttachmentService=pf,i.FormRevisionService=Af,i.FormService=ff,i.FormSubmissionAttachmentService=Sf,i.FormSubmissionService=Yy,i.GeoImageService=gf,i.HttpMethod=h,i.IssueAssociationService=Tf,i.IssueAttachmentService=bf,i.IssueCommentAttachmentService=If,i.IssueCommentService=Ff,i.IssuePriority=Pt,i.IssueService=Rf,i.IssueStatus=Ot,i.IssueTypeAttachmentService=Pf,i.IssueTypeFieldValuesAttachmentService=vf,i.IssueTypeFieldValuesService=wf,i.IssueTypeFieldsAttachmentService=Of,i.IssueTypeFieldsService=_f,i.IssueTypeService=Ef,i.IssueUpdateChange=v,i.IssueUpdateService=jf,i.JWTService=Cf,i.LicenseLevel=Pn,i.LicenseStatus=On,i.OUTBOX_RETRY_DELAY=_n,i.OrganizationAccessLevel=Rt,i.OrganizationAccessService=kf,i.OrganizationService=zf,i.OutboxCoordinator=Me,i.PaddleCheckoutEvent=Rn,i.ProjectAccessLevel=Ft,i.ProjectAccessService=Vf,i.ProjectAttachmentService=Df,i.ProjectFileService=Uf,i.ProjectService=$f,i.TeamService=Bf,i.UNKNOWN_ERROR_MESSAGE=qe,i.UserService=Gf,i.VERSION_REDUCER_KEY=mn,i.VerificationCodeType=bl,i._setLatestRetryTime=Oo,i.acceptProjectInvite=lo,i.addAsset=as,i.addAssetAttachment=nh,i.addAssetAttachments=kt,i.addAssetProcedure=es,i.addAssetProcedureFieldValues=Lt,i.addAssetProcedureFieldValuesAttachment=Ih,i.addAssetProcedureFieldValuesAttachments=Qe,i.addAssetProcedureFieldValuesMany=ba,i.addAssetProcedureFields=ra,i.addAssetProcedureFieldsAttachment=rh,i.addAssetProcedureFieldsAttachments=xn,i.addAssetProcedureFieldsMany=ph,i.addAssetProcedureInstance=Yt,i.addAssetProcedureInstances=va,i.addAssetProcedures=Vh,i.addAssetStage=Zh,i.addAssetStageCompletion=hs,i.addAssetStageCompletions=ms,i.addAssetStages=Ss,i.addAssetType=ks,i.addAssetTypeAttachment=tm,i.addAssetTypeAttachments=Fs,i.addAssetTypeFieldValues=Es,i.addAssetTypeFieldValuesAttachment=gm,i.addAssetTypeFieldValuesAttachments=it,i.addAssetTypeFieldValuesMany=Cc,i.addAssetTypeFields=Tc,i.addAssetTypeFieldsAttachment=nm,i.addAssetTypeFieldsAttachments=hc,i.addAssetTypeFieldsMany=lm,i.addAssetTypes=jm,i.addAssets=cs,i.addCategory=$s,i.addConversation=Dn,i.addDocumentAttachment=Lm,i.addDocumentAttachments=Qc,i.addDocuments=ur,i.addForm=Qs,i.addFormRevision=Js,i.addFormRevisionAttachment=Zm,i.addFormRevisionAttachments=br,i.addFormRevisions=wr,i.addFormSubmission=ii,i.addFormSubmissionAttachment=op,i.addFormSubmissionAttachments=rt,i.addFormSubmissions=ot,i.addForms=rp,i.addGeoImage=td,i.addGeoImages=sd,i.addIssue=vi,i.addIssueAssociation=hi,i.addIssueAssociations=mi,i.addIssueAttachment=Fp,i.addIssueAttachments=Si,i.addIssueComment=Ri,i.addIssueCommentAttachment=Op,i.addIssueCommentAttachments=Od,i.addIssueComments=Ep,i.addIssueType=wu,i.addIssueTypeAttachment=Cp,i.addIssueTypeAttachments=Wd,i.addIssueTypeFieldValues=ki,i.addIssueTypeFieldValuesAttachment=cA,i.addIssueTypeFieldValuesAttachments=pt,i.addIssueTypeFieldValuesMany=Hp,i.addIssueTypeFields=Au,i.addIssueTypeFieldsAttachment=Dp,i.addIssueTypeFieldsAttachments=iu,i.addIssueTypeFieldsMany=Zp,i.addIssueUpdate=zu,i.addIssueUpdates=Vu,i.addIssues=Bd,i.addOrganization=NA,i.addOrganizations=LA,i.addProject=kA,i.addProjectAttachment=sy,i.addProjectAttachments=Eo,i.addProjectFile=cy,i.addProjectFiles=Go,i.addProjects=CA,i.addTeam=el,i.addUser=gA,i.addUsers=SA,i.agentsReducer=Bn,i.agentsSlice=jt,i.areArraysEqual=Dl,i.assetAttachmentReducer=Xn,i.assetAttachmentSlice=Mt,i.assetProcedureFieldValuesAttachmentReducer=Sa,i.assetProcedureFieldValuesAttachmentSlice=$t,i.assetProcedureFieldValuesReducer=Pa,i.assetProcedureFieldValuesSlice=Gt,i.assetProcedureFieldsAttachmentReducer=na,i.assetProcedureFieldsAttachmentSlice=Vt,i.assetProcedureFieldsReducer=la,i.assetProcedureFieldsSlice=Dt,i.assetProcedureInstanceReducer=ja,i.assetProcedureInstanceSlice=Kt,i.assetProcedureReducer=ka,i.assetProcedureSlice=xt,i.assetReducer=$a,i.assetSlice=ns,i.assetStageCompletionReducer=Ha,i.assetStageCompletionSlice=ls,i.assetStageReducer=Za,i.assetStageSlice=fs,i.assetTypeAttachmentReducer=uc,i.assetTypeAttachmentSlice=Is,i.assetTypeFieldValuesAttachmentReducer=jc,i.assetTypeFieldValuesAttachmentSlice=_s,i.assetTypeFieldValuesReducer=Dc,i.assetTypeFieldValuesSlice=ws,i.assetTypeFieldsAttachmentReducer=fc,i.assetTypeFieldsAttachmentSlice=Ps,i.assetTypeFieldsReducer=Rc,i.assetTypeFieldsSlice=Os,i.assetTypeReducer=Bc,i.assetTypeSlice=Cs,i.authReducer=Nc,i.authSlice=at,i.blobToBase64=Kl,i.categoryReducer=Jc,i.categorySlice=Us,i.clearTokens=Vm,i.constructUploadedFilePayloads=Wl,i.coordinatesAreEqual=zl,i.createModelAdapter=F,i.createMultiPointGeometry=kl,i.createOfflineAction=Io,i.createPayload=_,i.createPointGeometry=Cl,i.createSelectionAdapter=Ml,i.deleteAsset=rs,i.deleteAssetAttachment=Hn,i.deleteAssetAttachments=zt,i.deleteAssetProcedure=ts,i.deleteAssetProcedureFieldValues=Nt,i.deleteAssetProcedureFieldValuesAttachment=Oh,i.deleteAssetProcedureFieldValuesAttachments=xe,i.deleteAssetProcedureFieldValuesMany=Fa,i.deleteAssetProcedureFields=ua,i.deleteAssetProcedureFieldsAttachment=lh,i.deleteAssetProcedureFieldsAttachments=ta,i.deleteAssetProcedureFieldsMany=Sh,i.deleteAssetProcedureInstance=Jt,i.deleteAssetProcedureInstances=wa,i.deleteAssetProcedures=Uh,i.deleteAssetStage=Qh,i.deleteAssetStageCompletion=ps,i.deleteAssetStageCompletions=As,i.deleteAssetStages=Ts,i.deleteAssetType=zs,i.deleteAssetTypeAttachment=nc,i.deleteAssetTypeAttachments=Rs,i.deleteAssetTypeFieldValues=js,i.deleteAssetTypeFieldValuesAttachment=Fm,i.deleteAssetTypeFieldValuesAttachments=nt,i.deleteAssetTypeFieldValuesMany=zc,i.deleteAssetTypeFields=Ic,i.deleteAssetTypeFieldsAttachment=dm,i.deleteAssetTypeFieldsAttachments=pc,i.deleteAssetTypeFieldsMany=Am,i.deleteAssetTypes=Mm,i.deleteAssets=Da,i.deleteCategory=Yc,i.deleteDocumentAttachment=tr,i.deleteDocumentAttachments=sr,i.deleteForm=xs,i.deleteFormRevision=Xs,i.deleteFormRevisionAttachment=tp,i.deleteFormRevisionAttachments=Fr,i.deleteFormRevisions=Er,i.deleteFormSubmission=ni,i.deleteFormSubmissionAttachment=pp,i.deleteFormSubmissionAttachments=dt,i.deleteFormSubmissions=lt,i.deleteGeoImage=ui,i.deleteGeoImages=nd,i.deleteIssue=wi,i.deleteIssueAssociation=pi,i.deleteIssueAssociations=Ai,i.deleteIssueAttachment=gd,i.deleteIssueAttachments=gi,i.deleteIssueComment=Pi,i.deleteIssueCommentAttachment=wd,i.deleteIssueCommentAttachments=Ed,i.deleteIssueComments=jp,i.deleteIssueTypeAttachment=Jd,i.deleteIssueTypeAttachments=Xd,i.deleteIssueTypeFieldValues=zi,i.deleteIssueTypeFieldValuesAttachment=oA,i.deleteIssueTypeFieldValuesAttachments=At,i.deleteIssueTypeFieldValuesMany=Jp,i.deleteIssueTypeFields=fu,i.deleteIssueTypeFieldsAttachment=Gp,i.deleteIssueTypeFieldsAttachments=au,i.deleteIssueTypeFieldsMany=tA,i.deleteIssueUpdate=Du,i.deleteIssueUpdates=Uu,i.deleteIssues=Gd,i.deleteOrganization=KA,i.deleteOrganizationAccess=Xu,i.deleteOrganizations=YA,i.deleteProject=oo,i.deleteProjectAccess=to,i.deleteProjectAccesses=so,i.deleteProjectAttachment=Co,i.deleteProjectAttachments=nn,i.deleteProjectFile=Lo,i.deleteProjectFiles=No,i.deleteProjects=VA,i.deleteTeam=on,i.deleteUser=IA,i.deleteUsers=FA,i.dequeue=fl,i.discard=yn,i.documentAttachmentReducer=cr,i.documentAttachmentSlice=Ls,i.documentSlice=Ns,i.documentsReducer=mr,i.downloadFile=Yl,i.downloadInMemoryFile=Hl,i.emailRegex=th,i.enqueue=yl,i.enqueueRequest=Ro,i.fallbackToEmptyArray=g,i.fallbackToEmptyObject=Ce,i.fileReducer=Sr,i.fileSlice=Ws,i.fileToBlob=jn,i.formReducer=zr,i.formRevisionAttachmentReducer=Pr,i.formRevisionAttachmentSlice=Ks,i.formRevisionReducer=Mr,i.formRevisionsSlice=Ys,i.formSlice=Zs,i.formSubmissionAttachmentReducer=Nr,i.formSubmissionAttachmentSlice=ei,i.formSubmissionReducer=Zr,i.formSubmissionSlice=si,i.geoImageReducer=rd,i.geoImageSlice=di,i.getFileIdentifier=Nl,i.getFileS3Key=Et,i.getLocalDateString=wn,i.getLocalRelativeDateString=Gl,i.getOutboxCoordinator=Ie,i.getRenamedFile=En,i.hashFile=Oe,i.initSDK=Nf,i.initializeAssetAttachments=Ct,i.initializeAssetProcedureFieldValues=Ta,i.initializeAssetProcedureFieldValuesAttachments=ma,i.initializeAssetProcedureFields=ca,i.initializeAssetProcedureFieldsAttachments=Qn,i.initializeAssetProcedureInstances=_a,i.initializeAssetProcedures=Ma,i.initializeAssetStageCompletions=Ga,i.initializeAssetStages=Ja,i.initializeAssetTypeAttachments=tc,i.initializeAssetTypeFieldValues=Mc,i.initializeAssetTypeFieldValuesAttachments=Oc,i.initializeAssetTypeFields=gc,i.initializeAssetTypeFieldsAttachments=lc,i.initializeAssetTypes=$c,i.initializeAssets=Va,i.initializeCategories=Wc,i.initializeConversations=Vn,i.initializeDocumentAttachments=Zc,i.initializeFormRevisionAttachments=Tr,i.initializeFormRevisions=vr,i.initializeFormSubmissionAttachments=$r,i.initializeFormSubmissions=Wr,i.initializeForms=kr,i.initializeGeoImages=xr,i.initializeIssueAssociations=ud,i.initializeIssueAttachments=fi,i.initializeIssueCommentAttachments=bi,i.initializeIssueTypeAttachments=qi,i.initializeIssueTypeFieldValues=ou,i.initializeIssueTypeFieldValuesAttachments=bu,i.initializeIssueTypeFields=pu,i.initializeIssueTypeFieldsAttachments=su,i.initializeIssueTypes=vu,i.initializeIssueUpdates=ku,i.initializeIssues=$d,i.initializeOrganizationAccesses=Yu,i.initializeOrganizations=BA,i.initializeProjectAccesses=Zi,i.initializeProjectAttachments=wo,i.initializeProjectFiles=Bo,i.initializeProjects=qA,i.initializeTeams=xo,i.initializeUsers=yA,i.isToday=Bl,i.issueAssociationReducer=Ad,i.issueAssociationSlice=li,i.issueAttachmentReducer=Rd,i.issueAttachmentSlice=yi,i.issueCommentAttachmentReducer=Cd,i.issueCommentAttachmentSlice=Ti,i.issueCommentReducer=Dd,i.issueCommentSlice=Ii,i.issueReducer=Nd,i.issueSlice=_i,i.issueTypeAttachmentReducer=eu,i.issueTypeAttachmentSlice=ji,i.issueTypeFieldValuesAttachmentReducer=Ou,i.issueTypeFieldValuesAttachmentSlice=$i,i.issueTypeFieldValuesReducer=hu,i.issueTypeFieldValuesSlice=Ci,i.issueTypeFieldsAttachmentReducer=du,i.issueTypeFieldsAttachmentSlice=Mi,i.issueTypeFieldsReducer=gu,i.issueTypeFieldsSlice=Ui,i.issueTypeReducer=Mu,i.issueTypeSlice=Gi,i.issueUpdateReducer=Gu,i.issueUpdateSlice=Wi,i.logOnlyOnce=Jl,i.markAsDeleted=Po,i.markForDeletion=ty,i.memoize=vt,i.moveDocument=or,i.offline=R,i.onlyUniqueHashes=eh,i.onlyUniqueOfflineIds=kn,i.organizationAccessReducer=Qu,i.organizationAccessSlice=Yi,i.organizationReducer=bo,i.organizationSlice=en,i.outboxReducer=_o,i.outboxSlice=tn,i.overmapEnhancer=Ey,i.overmapReducers=ml,i.overmapRootReducer=Py,i.performRequest=An,i.projectAccessReducer=ao,i.projectAccessSlice=Xi,i.projectAttachmentReducer=Uo,i.projectAttachmentSlice=sn,i.projectFileReducer=Xo,i.projectFileSlice=an,i.projectReducer=ho,i.projectSlice=xi,i.rehydratedReducer=Zo,i.rehydratedSlice=rn,i.removeDocuments=Hs,i.removeIssueType=Li,i.removeUser=Hu,i.resetProjectFileObjectUrls=dy,i.resetStore=Al,i.restructureCreateSelectorWithArgs=S,i.saveActiveProjectFileBounds=Ko,i.selectAccessToken=Dm,i.selectActiveOrganizationAccess=vA,i.selectActiveProjectFileId=oy,i.selectAllDocumentAttachments=nr,i.selectAllProjectAttachments=zo,i.selectAncestorIdsOfDocument=Ym,i.selectAssetAttachmentById=Yn,i.selectAssetAttachmentMapping=Wn,i.selectAssetAttachments=Kn,i.selectAssetById=os,i.selectAssetProcedureById=is,i.selectAssetProcedureFieldValues=Ht,i.selectAssetProcedureFieldValuesAttachmentById=_h,i.selectAssetProcedureFieldValuesAttachments=Aa,i.selectAssetProcedureFieldValuesAttachmentsByIds=ya,i.selectAssetProcedureFieldValuesAttachmentsMapping=Bt,i.selectAssetProcedureFieldValuesById=Wt,i.selectAssetProcedureFieldValuesMapping=Ra,i.selectAssetProcedureFieldValuesOfAsset=Eh,i.selectAssetProcedureFields=Ut,i.selectAssetProcedureFieldsAttachmentById=mh,i.selectAssetProcedureFieldsAttachments=ia,i.selectAssetProcedureFieldsAttachmentsMapping=sa,i.selectAssetProcedureFieldsById=bh,i.selectAssetProcedureFieldsMapping=oa,i.selectAssetProcedureFieldsOfAssetProcedure=gh,i.selectAssetProcedureInstanceById=Qt,i.selectAssetProcedureInstances=Zt,i.selectAssetProcedureInstancesByIds=zh,i.selectAssetProcedureInstancesMapping=Xt,i.selectAssetProcedureInstancesOfAssetProcedure=Ea,i.selectAssetProcedureInstancesOfAssetType=kh,i.selectAssetProcedures=Ca,i.selectAssetProceduresByIds=Lh,i.selectAssetProceduresMapping=ss,i.selectAssetProceduresOfOrganization=Gh,i.selectAssetStageById=Qa,i.selectAssetStageCompletionById=Wa,i.selectAssetStageCompletionMapping=ys,i.selectAssetStageCompletions=Jh,i.selectAssetStageCompletionsByIds=Ka,i.selectAssetStages=xa,i.selectAssetStagesByIds=bs,i.selectAssetStagesMappingOfAssetProcedure=xh,i.selectAssetStagesOfAssetProcedure=em,i.selectAssetTypeAttachmentById=rc,i.selectAssetTypeAttachmentMapping=ac,i.selectAssetTypeAttachments=cc,i.selectAssetTypeById=Ds,i.selectAssetTypeFieldValues=qs,i.selectAssetTypeFieldValuesAttachmentById=Rm,i.selectAssetTypeFieldValuesAttachments=vc,i.selectAssetTypeFieldValuesAttachmentsByIds=wc,i.selectAssetTypeFieldValuesAttachmentsMapping=vs,i.selectAssetTypeFieldValuesById=Ms,i.selectAssetTypeFieldValuesMapping=Vc,i.selectAssetTypeFieldValuesOfAsset=_m,i.selectAssetTypeFields=st,i.selectAssetTypeFieldsAttachmentById=om,i.selectAssetTypeFieldsAttachments=yc,i.selectAssetTypeFieldsAttachmentsMapping=Ac,i.selectAssetTypeFieldsById=Sm,i.selectAssetTypeFieldsMapping=Fc,i.selectAssetTypeFieldsOfAssetType=ym,i.selectAssetTypeValuesOfAssetType=vm,i.selectAssetTypes=Cm,i.selectAssetTypesByIds=km,i.selectAssetTypesMapping=Vs,i.selectAssets=Ua,i.selectAssetsByIds=Kh,i.selectAssetsMapping=ds,i.selectAssetsOfAssetType=us,i.selectAttachmentsOfAsset=Jn,i.selectAttachmentsOfAssetProcedureFieldValues=fa,i.selectAttachmentsOfAssetProcedureFields=hh,i.selectAttachmentsOfAssetType=dc,i.selectAttachmentsOfAssetTypeFieldValues=Ec,i.selectAttachmentsOfAssetTypeFields=um,i.selectAttachmentsOfDocument=Wm,i.selectAttachmentsOfFormRevision=sp,i.selectAttachmentsOfFormSubmission=Lr,i.selectAttachmentsOfIssue=Id,i.selectAttachmentsOfIssueComment=wp,i.selectAttachmentsOfIssueType=Vp,i.selectAttachmentsOfIssueTypeFieldValues=Pu,i.selectAttachmentsOfIssueTypeFields=Lp,i.selectAttachmentsOfProject=Do,i.selectCategories=$m,i.selectCategoriesByIds=Bm,i.selectCategoryById=Gs,i.selectCategoryMapping=Bs,i.selectCommentsOfIssue=qp,i.selectConversation=ih,i.selectConversationMapping=qt,i.selectConversations=sh,i.selectCurrentUser=yt,i.selectDeletedRequests=xA,i.selectDocumentAttachmentById=ar,i.selectDocumentAttachmentMapping=ir,i.selectDocumentById=hr,i.selectDocuments=lr,i.selectDocumentsByIds=Km,i.selectDocumentsMapping=_e,i.selectFieldValuesOfAssetProcedureInstance=jh,i.selectFormById=Dr,i.selectFormMapping=Vr,i.selectFormRevisionAttachmentsMapping=Rr,i.selectFormRevisionById=np,i.selectFormRevisionMapping=ct,i.selectFormRevisions=jr,i.selectFormRevisionsOfForm=qr,i.selectFormSubmissionAttachemntsByIds=Gr,i.selectFormSubmissionAttachmentsMapping=ti,i.selectFormSubmissionById=ri,i.selectFormSubmissions=ci,i.selectFormSubmissionsMapping=ai,i.selectFormSubmissionsOfAsset=Xr,i.selectFormSubmissionsOfForm=Yr,i.selectFormSubmissionsOfIssue=Jr,i.selectForms=up,i.selectGeoImageById=oi,i.selectGeoImageMapping=ad,i.selectGeoImages=cd,i.selectGeoImagesOfProject=Sp,i.selectIsImportingProjectFile=ly,i.selectIsLoggedIn=Um,i.selectIssueAssociationById=ld,i.selectIssueAssociationMapping=Ne,i.selectIssueAssociations=Ip,i.selectIssueAssociationsOfAsset=pd,i.selectIssueAssociationsOfIssue=md,i.selectIssueAssociationsToIssue=hd,i.selectIssueAttachmentById=Fd,i.selectIssueAttachmentMapping=Td,i.selectIssueAttachments=bd,i.selectIssueById=Ei,i.selectIssueCommentAttachmentById=Md,i.selectIssueCommentAttachmentMapping=jd,i.selectIssueCommentAttachments=qd,i.selectIssueCommentById=Oi,i.selectIssueCommentMapping=Vd,i.selectIssueCountOfCategory=Gm,i.selectIssueMapping=Ld,i.selectIssueTypeAttachmentById=xd,i.selectIssueTypeAttachmentMapping=Zd,i.selectIssueTypeAttachments=Qd,i.selectIssueTypeById=Ni,i.selectIssueTypeFieldValues=Vi,i.selectIssueTypeFieldValuesAttachmentById=lA,i.selectIssueTypeFieldValuesAttachments=Fu,i.selectIssueTypeFieldValuesAttachmentsByIds=Ru,i.selectIssueTypeFieldValuesAttachmentsMapping=Bi,i.selectIssueTypeFieldValuesById=Di,i.selectIssueTypeFieldValuesMapping=lu,i.selectIssueTypeFieldValuesOfIssue=Xp,i.selectIssueTypeFields=mt,i.selectIssueTypeFieldsAttachmentById=Np,i.selectIssueTypeFieldsAttachments=ru,i.selectIssueTypeFieldsAttachmentsMapping=cu,i.selectIssueTypeFieldsById=aA,i.selectIssueTypeFieldsMapping=Su,i.selectIssueTypeFieldsOfIssueType=sA,i.selectIssueTypeMapping=ju,i.selectIssueTypeValuesOfIssueType=nA,i.selectIssueTypes=qu,i.selectIssueTypesByIds=hA,i.selectIssueTypesOfOrganization=mA,i.selectIssueUpdateMapping=$u,i.selectIssueUpdatesOfIssue=Bu,i.selectIssuesByIds=Mp,i.selectIssuesOfIssueType=Hi,i.selectIssuesOfIssueTypeCount=pA,i.selectLatestAssetProcedureFieldsOfAssetProcedure=Th,i.selectLatestAssetTypeFieldsOfAssetType=fm,i.selectLatestFormRevisionOfForm=ap,i.selectLatestIssueTypeFieldsOfIssueType=iA,i.selectLatestRetryTime=ey,i.selectNumberOfAssetsOfAssetType=Yh,i.selectOrganizationAccessById=_A,i.selectOrganizationAccessForUser=wA,i.selectOrganizationAccessUserMapping=Zu,i.selectOrganizationAccesses=Ji,i.selectOrganizationById=JA,i.selectOrganizationUsersAsMapping=To,i.selectOrganizationUsersIds=go,i.selectOrganizations=So,i.selectOrganizationsMapping=fo,i.selectOrganizationsWithAccess=XA,i.selectProjectAccessById=EA,i.selectProjectAccessForUser=jA,i.selectProjectAccessMapping=Qi,i.selectProjectAccessUserMapping=no,i.selectProjectAccesses=io,i.selectProjectAttachmentById=Vo,i.selectProjectAttachmentMapping=ko,i.selectProjectById=UA,i.selectProjectFileById=uy,i.selectProjectFileMapping=Yo,i.selectProjectFiles=Jo,i.selectProjectMapping=gt,i.selectProjectUsersAsMapping=po,i.selectProjectUsersIds=mo,i.selectProjects=DA,i.selectProjectsOfOrganization=ZA,i.selectRehydrated=py,i.selectRootDocuments=Jm,i.selectSortedOrganizationUsers=QA,i.selectSortedProjectUsers=$A,i.selectStageMapping=tt,i.selectTeamById=je,i.selectTeams=hn,i.selectTeamsByIds=Ay,i.selectTeamsMapping=ln,i.selectTeamsOfOrganization=yy,i.selectTeamsOfUser=fy,i.selectUploadUrl=fr,i.selectUserById=PA,i.selectUsersByIds=OA,i.selectUsersMapping=ft,i.separateFilesFromValues=Xe,i.separateImageFromFields=yf,i.setActiveProjectFileId=Wo,i.setAsset=Hh,i.setAssetAttachment=Ln,i.setAssetAttachments=ah,i.setAssetProcedure=$h,i.setAssetProcedureFieldValues=vh,i.setAssetProcedureFieldValuesAttachment=Fh,i.setAssetProcedureFieldValuesAttachments=Rh,i.setAssetProcedureFieldValuesMany=wh,i.setAssetProcedureFields=Ah,i.setAssetProcedureFieldsAttachment=dh,i.setAssetProcedureFieldsAttachments=uh,i.setAssetProcedureFieldsMany=yh,i.setAssetProcedureInstance=Mh,i.setAssetProcedureInstances=Ch,i.setAssetProcedures=Bh,i.setAssetStage=Xa,i.setAssetStages=Xh,i.setAssetType=wm,i.setAssetTypeAttachment=sc,i.setAssetTypeAttachments=sm,i.setAssetTypeFieldValues=Pm,i.setAssetTypeFieldValuesAttachment=Tm,i.setAssetTypeFieldValuesAttachments=bm,i.setAssetTypeFieldValuesMany=Om,i.setAssetTypeFields=hm,i.setAssetTypeFieldsAttachment=am,i.setAssetTypeFieldsAttachments=cm,i.setAssetTypeFieldsMany=mm,i.setAssetTypes=Em,i.setAssets=Wh,i.setConversation=Un,i.setCurrentUser=RA,i.setDocumentAttachment=xc,i.setDocumentAttachments=Nm,i.setDocuments=dr,i.setForm=cp,i.setFormRevision=_r,i.setFormRevisionAttachment=Qm,i.setFormRevisionAttachments=xm,i.setFormSubmission=ut,i.setFormSubmissionAttachment=lp,i.setFormSubmissionAttachments=hp,i.setFormSubmissions=Ap,i.setGeoImage=Le,i.setGeoImages=ed,i.setIsImportingProjectFile=Ho,i.setIssueAssociation=Tp,i.setIssueAssociations=gp,i.setIssueAttachment=fd,i.setIssueAttachments=Rp,i.setIssueComment=Fi,i.setIssueCommentAttachment=_d,i.setIssueCommentAttachments=_p,i.setIssueComments=zd,i.setIssueType=We,i.setIssueTypeAttachment=Kd,i.setIssueTypeAttachments=kp,i.setIssueTypeFieldValues=Wp,i.setIssueTypeFieldValuesAttachment=rA,i.setIssueTypeFieldValuesAttachments=dA,i.setIssueTypeFieldValuesMany=Kp,i.setIssueTypeFields=Qp,i.setIssueTypeFieldsAttachment=Up,i.setIssueTypeFieldsAttachments=$p,i.setIssueTypeFieldsMany=xp,i.setIssueUpdate=AA,i.setLoggedIn=Lc,i.setOrganization=GA,i.setOrganizations=yo,i.setProject=MA,i.setProjectAttachment=jo,i.setProjectAttachments=qo,i.setProjectFile=ny,i.setProjectFiles=ay,i.setProjects=ro,i.setRehydrated=my,i.setTeam=Ee,i.setTokens=zm,i.setUploadUrl=yr,i.setUser=fA,i.setUsers=Nu,i.shallowEqual=Vl,i.slugify=Ql,i.spacesToDashesLower=Zl,i.teamReducer=tl,i.teamSlice=dn,i.toFileNameSafeString=Xl,i.toOfflineIdRecord=Cn,i.truncate=xl,i.updateAsset=Ue,i.updateAssetAttachment=ch,i.updateAssetAttachments=Nn,i.updateAssetProcedure=De,i.updateAssetProcedureFieldValues=ze,i.updateAssetProcedureFieldValuesAttachment=Ph,i.updateAssetProcedureFieldValuesAttachments=pa,i.updateAssetProcedureFieldValuesMany=Ia,i.updateAssetProcedureFields=da,i.updateAssetProcedureFieldsAttachment=oh,i.updateAssetProcedureFieldsAttachments=ea,i.updateAssetProcedureFieldsMany=fh,i.updateAssetProcedureInstance=Ve,i.updateAssetProcedureInstances=qh,i.updateAssetProcedures=Dh,i.updateAssetStage=gs,i.updateAssetStageCompletion=La,i.updateAssetStageCompletions=Na,i.updateAssetStages=et,i.updateAssetType=Be,i.updateAssetTypeAttachment=im,i.updateAssetTypeAttachments=ic,i.updateAssetTypeFieldValues=$e,i.updateAssetTypeFieldValuesAttachment=Im,i.updateAssetTypeFieldValuesAttachments=_c,i.updateAssetTypeFieldValuesMany=kc,i.updateAssetTypeFields=bc,i.updateAssetTypeFieldsAttachment=rm,i.updateAssetTypeFieldsAttachments=mc,i.updateAssetTypeFieldsMany=pm,i.updateAssetTypes=qm,i.updateAssets=Nh,i.updateCategory=Kc,i.updateConversation=$n,i.updateDocumentAttachment=Hm,i.updateDocumentAttachments=er,i.updateDocuments=Ae,i.updateForm=dp,i.updateFormRevisionAttachment=ep,i.updateFormRevisionAttachments=Ir,i.updateFormSubmission=Kr,i.updateFormSubmissionAttachment=mp,i.updateFormSubmissionAttachments=Br,i.updateFormSubmissions=yp,i.updateGeoImage=id,i.updateGeoImages=fp,i.updateIssue=ht,i.updateIssueAssociation=od,i.updateIssueAssociations=bp,i.updateIssueAttachment=Pp,i.updateIssueAttachments=Sd,i.updateIssueCommentAttachment=vp,i.updateIssueCommentAttachments=vd,i.updateIssueType=Eu,i.updateIssueTypeAttachment=zp,i.updateIssueTypeAttachments=Yd,i.updateIssueTypeFieldValues=He,i.updateIssueTypeFieldValuesAttachment=uA,i.updateIssueTypeFieldValuesAttachments=Iu,i.updateIssueTypeFieldValuesMany=Yp,i.updateIssueTypeFields=yu,i.updateIssueTypeFieldsAttachment=Bp,i.updateIssueTypeFieldsAttachments=nu,i.updateIssueTypeFieldsMany=eA,i.updateOrganization=WA,i.updateOrganizationAccess=Ju,i.updateOrganizations=HA,i.updateProject=uo,i.updateProjectAccess=eo,i.updateProjectAttachment=iy,i.updateProjectAttachments=Mo,i.updateProjectFile=cn,i.updateProjectFiles=ry,i.updateProjects=zA,i.updateTeam=un,i.updateUser=bA,i.updateUsers=TA,i.userReducer=Wu,i.userSlice=Ki,i.versioningReducer=il,i.versioningSlice=sl,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});