@overmap-ai/core 1.0.74-remove-workspaces.0 → 1.0.74

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,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("uuid"),require("@reduxjs/toolkit"),require("file-saver"),require("@redux-offline/redux-offline"),require("@redux-offline/redux-offline/lib/defaults"),require("localforage"),require("redux-persist-migrate"),require("superagent"),require("dependency-graph"),require("idb"),require("@redux-offline/redux-offline/lib/constants"),require("jwt-decode")):typeof define=="function"&&define.amd?define(["exports","uuid","@reduxjs/toolkit","file-saver","@redux-offline/redux-offline","@redux-offline/redux-offline/lib/defaults","localforage","redux-persist-migrate","superagent","dependency-graph","idb","@redux-offline/redux-offline/lib/constants","jwt-decode"],O):(i=typeof globalThis<"u"?globalThis:i||self,O(i["overmap-core"]={},i.uuid,i.toolkit,i.fileSaver,i.reduxOffline,i.offlineConfig,i.localforage,i.createMigration,i.request,i.dependencyGraph,i.idb,i.constants,i.jwtDecode))})(this,function(i,O,u,Yd,Kd,Vi,Jd,Xd,me,Zd,Qd,xd,el){"use strict";var rp=Object.defineProperty;var dp=(i,O,u)=>O in i?rp(i,O,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[O]=u;var A=(i,O,u)=>dp(i,typeof O!="symbol"?O+"":O,u);var Hd;const $i=Object.freeze([]),Bi=Object.freeze({});var ot=(t=>(t[t.BASIC=0]="BASIC",t[t.ADMIN=2]="ADMIN",t))(ot||{}),rt=(t=>(t[t.BASIC=0]="BASIC",t[t.ADMIN=2]="ADMIN",t))(rt||{}),l=(t=>(t.GET="GET",t.POST="POST",t.PATCH="PATCH",t.PUT="PUT",t.DELETE="DELETE",t))(l||{}),Gi=(t=>(t.Issue="issue",t.Asset="asset",t.AssetType="asset_type",t.Project="project",t.Document="document",t))(Gi||{}),dt=(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))(dt||{}),lt=(t=>(t[t.BACKLOG=0]="BACKLOG",t[t.SELECTED=2]="SELECTED",t[t.DONE=4]="DONE",t))(lt||{}),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||{}),Li=(t=>(t.COMPLETED="checkout.completed",t.CLOSED="checkout.closed",t))(Li||{}),Ni=(t=>(t[t.PRO=0]="PRO",t))(Ni||{}),Hi=(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))(Hi||{});const tl=lt.BACKLOG,sl=dt.MEDIUM,Wi=6e4;function I(t){return{addOne:(f,p)=>{const y=t(p.payload);f.instances[y]=p.payload},addMany:(f,p)=>{for(const y of p.payload){const T=t(y);f.instances[T]=y}},setOne:(f,p)=>{const y=t(p.payload);f.instances[y]=p.payload},setMany:(f,p)=>{for(const y of p.payload){const T=t(y);f.instances[T]=y}},updateOne:(f,p)=>{const y=t(p.payload);f.instances[y]=p.payload},updateMany:(f,p)=>{for(const y of p.payload){const T=t(y);f.instances[T]=y}},deleteOne:(f,p)=>{delete f.instances[p.payload]},deleteMany:(f,p)=>{for(const y of p.payload)delete f.instances[y]},initialize:(f,p)=>{f.instances={};for(const y of p.payload){const T=t(y);f.instances[T]=y}},getInitialState:f=>({...f,instances:{}})}}Hd=Symbol.toStringTag;class Yi{constructor(){A(this,Hd,"Promise");A(this,"_promise");A(this,"_resolve");A(this,"_reject");A(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 il=t=>({type:"Point",coordinates:t}),nl=t=>({type:"MultiPoint",coordinates:t}),al=(t,e)=>t[0]===e[0]&&t[1]===e[1];let ut=!1;["true","1"].includes("".toLowerCase())&&(ut=!0);function Ki(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 o=s[c];if(!Object.prototype.hasOwnProperty.call(e,o)||t[o]!==e[o])return!1}return!0}function ht(t){const e={};return function(){const s=Array.prototype.slice.call(arguments);return s in e?(ut&&console.debug(`Memoization debug: Using memorized return value for ${t.toString()}(`,s,")"),e[s]):(ut&&console.debug(`Memoization debug: Cache miss! Memoizing ${t.toString()}(`,s,")"),e[s]=t.apply(this,s))}}function cl(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 S=t=>t.length===0?$i:t,ae=t=>Object.keys(t).length===0?Bi:t,Ji=ht(t=>{if(!t)return"";const e=new Date(t),s=e.getFullYear()===mt.getFullYear(),n={day:"numeric",month:"short"};return s||(n.year="numeric"),e.toLocaleDateString([],n)}),ol=new Intl.RelativeTimeFormat([],{style:"long",numeric:"auto"}),rl=1e3*86400,mt=new Date,dl=t=>new Date(t).toDateString()===mt.toDateString(),ll=ht((t,e,s)=>{const n=Math.round((new Date(t).getTime()-mt.getTime())/rl);return n<e||n>s?Ji(t):ol.format(n,"days")});function ul(t){return new Uint8Array(t).reduce((s,n)=>s+n.toString(16).padStart(2,"0"),"")}const ft=async(t,e)=>{e||(e=await fe(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 fe(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 o=ul(c);e(o)})},n.readAsArrayBuffer(t)})}function hl(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 Xi(t,e){return new File([t],e,{type:t.type})}function ml(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 fl=async t=>{const e={};for(const s of t){const n=await fe(s);e[n]={sha1:n,extension:s.name.split(".").pop()||"",file_type:s.type,size:s.size}}return Object.values(e)},Zi=async t=>(await fetch(t)).blob(),pl=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]);Yd.saveAs(e,t.name)}const Qi={};function Al(t,e,s,...n){const a=Qi[t];let c=!1;a?a[e]||(a[e]=!0,c=!0):(Qi[t]={[e]:!0},c=!0),c&&console[s](...n)}function R(t){return{...t,offline_id:O.v4()}}function xi(t){const e={};for(const s of t)e[s.offline_id]=s;return e}function gl(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 Sl(t){return t.toLowerCase().replace(" ","-")}function Tl(t,e=!1){return t.normalize("NFKD").toLowerCase().replace(/[^\w\s-]/g,"").trim().replace(/[-\s]+/g,e?"_":"-")}function bl(t,e){if(t.length<=e)return t;const s=t.slice(0,e-1);return s.slice(0,s.lastIndexOf(" "))+"…"}const g=t=>e=>s=>t(s,e);function en(t,e,s){return s.findIndex(n=>n.offline_id===t.offline_id)===e}function _l(t,e,s){return s.findIndex(n=>n.file_sha1===t.file_sha1)===e}const Il=/^.+@.+\..+$/,_e=I(t=>t.offline_id),tn=_e.getInitialState({}),pt=u.createSlice({name:"agents",initialState:tn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,tn)),reducers:{initializeConversations:_e.initialize,addConversation:_e.addOne,setConversation:_e.setOne,updateConversation:_e.updateOne}}),{initializeConversations:sn,addConversation:nn,setConversation:an,updateConversation:cn}=pt.actions,yt=t=>t.agentsReducer.instances,Rl=u.createSelector([yt],t=>Object.values(t)),Fl=g(u.createSelector([yt,(t,e)=>e],(t,e)=>t[e])),on=pt.reducer,q=I(t=>t.offline_id),rn=q.getInitialState({}),At=u.createSlice({name:"assetAttachments",initialState:rn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,rn)),reducers:{initializeAssetAttachments:q.initialize,addAssetAttachment:q.addOne,addAssetAttachments:q.addMany,setAssetAttachment:q.setOne,setAssetAttachments:q.setMany,updateAssetAttachment:q.updateOne,updateAssetAttachments:q.updateMany,deleteAssetAttachment:q.deleteOne,deleteAssetAttachments:q.deleteMany}}),{initializeAssetAttachments:gt,addAssetAttachment:Ol,addAssetAttachments:St,setAssetAttachment:dn,setAssetAttachments:vl,updateAssetAttachment:wl,updateAssetAttachments:ln,deleteAssetAttachment:un,deleteAssetAttachments:Tt}=At.actions,hn=t=>t.assetAttachmentReducer.instances,bt=u.createSelector([hn],t=>Object.values(t)),mn=t=>e=>e.assetAttachmentReducer.instances[t],fn=g(u.createSelector([bt,(t,e)=>e],(t,e)=>S(t.filter(({asset:s})=>e===s)))),El=g(u.createSelector([bt,(t,e)=>e],(t,e)=>{const s=t.filter(({asset:c})=>e===c),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),pn=At.reducer,k=I(t=>t.offline_id),yn=k.getInitialState({}),_t=u.createSlice({name:"assets",initialState:yn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,yn)),reducers:{initializeAssets:k.initialize,addAsset:k.addOne,addAssets:k.addMany,setAsset:k.setOne,setAssets:k.setMany,updateAsset:k.updateOne,updateAssets:k.updateMany,deleteAsset:k.deleteOne,deleteAssets:k.deleteMany}}),{initializeAssets:An,addAsset:It,addAssets:Rt,updateAsset:Ie,updateAssets:jl,deleteAsset:Ft,deleteAssets:gn,setAsset:Pl,setAssets:ql}=_t.actions,Ot=t=>t.assetReducer.instances,Sn=u.createSelector([Ot],t=>S(Object.values(t))),vt=g(u.createSelector([Sn,(t,e)=>e],(t,e)=>S(t.filter(s=>s.asset_type===e)))),wt=t=>e=>e.assetReducer.instances[t],kl=g(u.createSelector([Ot,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a&&s.push(a)}return S(s)})),Dl=t=>e=>vt(t)(e).length,Tn=_t.reducer,ie=I(t=>t.offline_id),bn=ie.getInitialState({}),Et=u.createSlice({name:"assetStageCompletions",initialState:bn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,bn)),reducers:{initializeAssetStageCompletions:ie.initialize,addAssetStageCompletion:ie.addOne,addAssetStageCompletions:ie.addMany,updateAssetStageCompletion:ie.updateOne,updateAssetStageCompletions:ie.updateMany,deleteAssetStageCompletion:ie.deleteOne,deleteAssetStageCompletions:ie.deleteMany}}),{initializeAssetStageCompletions:_n,addAssetStageCompletion:jt,addAssetStageCompletions:Pt,updateAssetStageCompletion:In,updateAssetStageCompletions:Rn,deleteAssetStageCompletion:qt,deleteAssetStageCompletions:kt}=Et.actions,Dt=t=>t.assetStageCompletionReducer.instances,Cl=u.createSelector([Dt],t=>{const e={};for(const s of Object.values(t)){const{asset:n,stage:a,submitted_at:c}=s;e[n]||(e[n]={}),e[n][a]=c}return ae(e)}),Fn=t=>e=>e.assetStageCompletionReducer.instances[t],On=g(u.createSelector([Dt,(t,e)=>e],(t,e)=>{const s=new Set(e);return S(Object.values(t).filter(n=>s.has(n.offline_id)))})),vn=Et.reducer,D=I(t=>t.offline_id),wn=D.getInitialState({}),Ct=u.createSlice({name:"assetStages",initialState:wn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,wn)),reducers:{initializeAssetStages:D.initialize,setAssetStage:D.setOne,setAssetStages:D.setMany,addAssetStage:D.addOne,addAssetStages:D.addMany,updateAssetStage:D.updateOne,updateAssetStages:D.updateMany,deleteAssetStage:D.deleteOne,deleteAssetStages:D.deleteMany}}),{initializeAssetStages:En,setAssetStage:jn,setAssetStages:Ml,addAssetStage:zl,addAssetStages:Ce,updateAssetStage:Mt,updateAssetStages:Me,deleteAssetStage:Ul,deleteAssetStages:ze}=Ct.actions,Pn=Ct.reducer,Ue=t=>t.assetStageReducer.instances,qn=t=>e=>e.assetStageReducer.instances[t],kn=u.createSelector([Ue],t=>Object.values(t)),Vl=g(u.createSelector([Ue,(t,e)=>e],(t,e)=>{const s={};for(const[n,a]of Object.entries(t))a.asset_type===e&&(s[n]=a);return ae(s)})),Dn=g(u.createSelector([kn,(t,e)=>e],(t,e)=>S(t.filter(s=>s.asset_type===e).sort((s,n)=>s.priority-n.priority)))),zt=g(u.createSelector([Ue,(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 S(s)})),C=I(t=>t.offline_id),Cn=C.getInitialState({}),Ut=u.createSlice({name:"assetTypeAttachments",initialState:Cn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Cn)),reducers:{initializeAssetTypeAttachments:C.initialize,addAssetTypeAttachment:C.addOne,addAssetTypeAttachments:C.addMany,setAssetTypeAttachment:C.setOne,setAssetTypeAttachments:C.setMany,updateAssetTypeAttachment:C.updateOne,updateAssetTypeAttachments:C.updateMany,deleteAssetTypeAttachment:C.deleteOne,deleteAssetTypeAttachments:C.deleteMany}}),{initializeAssetTypeAttachments:Mn,addAssetTypeAttachment:$l,addAssetTypeAttachments:Vt,setAssetTypeAttachment:zn,setAssetTypeAttachments:Bl,updateAssetTypeAttachment:Gl,updateAssetTypeAttachments:Un,deleteAssetTypeAttachment:Vn,deleteAssetTypeAttachments:$t}=Ut.actions,$n=t=>t.assetTypeAttachmentReducer.instances,Bt=u.createSelector([$n],t=>Object.values(t)),Bn=t=>e=>e.assetTypeAttachmentReducer.instances[t],Gn=g(u.createSelector([Bt,(t,e)=>e],(t,e)=>S(t.filter(({asset_type:s})=>e===s)))),Ll=g(u.createSelector([Bt,(t,e)=>e],(t,e)=>{const s=t.filter(({asset_type:c})=>c===e),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),Ln=Ut.reducer,M=I(t=>t.offline_id),Nn=M.getInitialState({}),Gt=u.createSlice({name:"assetTypeFieldsAttachments",initialState:Nn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Nn)),reducers:{initializeAssetTypeFieldsAttachments:M.initialize,addAssetTypeFieldsAttachment:M.addOne,addAssetTypeFieldsAttachments:M.addMany,setAssetTypeFieldsAttachment:M.setOne,setAssetTypeFieldsAttachments:M.setMany,updateAssetTypeFieldsAttachment:M.updateOne,updateAssetTypeFieldsAttachments:M.updateMany,deleteAssetTypeFieldsAttachment:M.deleteOne,deleteAssetTypeFieldsAttachments:M.deleteMany}}),{initializeAssetTypeFieldsAttachments:Hn,addAssetTypeFieldsAttachment:Nl,addAssetTypeFieldsAttachments:Wn,setAssetTypeFieldsAttachment:Hl,setAssetTypeFieldsAttachments:Wl,updateAssetTypeFieldsAttachment:Yl,updateAssetTypeFieldsAttachments:Yn,deleteAssetTypeFieldsAttachment:Kl,deleteAssetTypeFieldsAttachments:Kn}=Gt.actions,Jn=t=>t.assetTypeFieldsAttachmentReducer.instances,Xn=u.createSelector([Jn],t=>Object.values(t)),Jl=g(u.createSelector([Xn,(t,e)=>e],(t,e)=>S(t.filter(s=>s.fields_revision===e)))),Xl=t=>e=>e.assetTypeFieldsAttachmentReducer.instances[t],Zn=Gt.reducer,z=I(t=>t.offline_id),Qn=z.getInitialState({}),Lt=u.createSlice({name:"assetTypeFields",initialState:Qn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Qn)),reducers:{initializeAssetTypeFields:z.initialize,addAssetTypeFields:z.addOne,addAssetTypeFieldsMany:z.addMany,setAssetTypeFields:z.setOne,setAssetTypeFieldsMany:z.setMany,updateAssetTypeFields:z.updateOne,updateAssetTypeFieldsMany:z.updateMany,deleteAssetTypeFields:z.deleteOne,deleteAssetTypeFieldsMany:z.deleteMany}}),{initializeAssetTypeFields:xn,addAssetTypeFields:ea,addAssetTypeFieldsMany:Zl,setAssetTypeFields:Ql,setAssetTypeFieldsMany:xl,updateAssetTypeFields:ta,updateAssetTypeFieldsMany:eu,deleteAssetTypeFields:sa,deleteAssetTypeFieldsMany:tu}=Lt.actions,ia=t=>t.assetTypeFieldsReducer.instances,Ve=u.createSelector([ia],t=>Object.values(t)),su=g(u.createSelector([Ve,(t,e)=>e],(t,e)=>S(t.filter(s=>s.asset_type===e)))),iu=g(u.createSelector([Ve,(t,e)=>e],(t,e)=>t.filter(s=>s.asset_type===e).sort((s,n)=>s.submitted_at>n.submitted_at?-1:1)[0])),nu=t=>e=>e.assetTypeFieldsReducer.instances[t],na=Lt.reducer,U=I(t=>t.offline_id),aa=U.getInitialState({}),Nt=u.createSlice({name:"assetTypeFieldValuesAttachments",initialState:aa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,aa)),reducers:{initializeAssetTypeFieldValuesAttachments:U.initialize,addAssetTypeFieldValuesAttachment:U.addOne,addAssetTypeFieldValuesAttachments:U.addMany,setAssetTypeFieldValuesAttachment:U.setOne,setAssetTypeFieldValuesAttachments:U.setMany,updateAssetTypeFieldValuesAttachment:U.updateOne,updateAssetTypeFieldValuesAttachments:U.updateMany,deleteAssetTypeFieldValuesAttachment:U.deleteOne,deleteAssetTypeFieldValuesAttachments:U.deleteMany}}),{initializeAssetTypeFieldValuesAttachments:ca,addAssetTypeFieldValuesAttachment:au,addAssetTypeFieldValuesAttachments:$e,setAssetTypeFieldValuesAttachment:cu,setAssetTypeFieldValuesAttachments:ou,updateAssetTypeFieldValuesAttachment:ru,updateAssetTypeFieldValuesAttachments:oa,deleteAssetTypeFieldValuesAttachment:du,deleteAssetTypeFieldValuesAttachments:Be}=Nt.actions,Ht=t=>t.assetTypeFieldValuesAttachmentReducer.instances,ra=u.createSelector([Ht],t=>Object.values(t)),lu=t=>e=>e.assetTypeFieldValuesAttachmentReducer.instances[t],da=g(u.createSelector([Ht,(t,e)=>e],(t,e)=>{const s=new Set(e);return S(Object.values(t).filter(n=>s.has(n.offline_id)))})),la=g(u.createSelector([ra,(t,e)=>e],(t,e)=>S(t.filter(s=>s.field_values===e)))),ua=Nt.reducer,V=I(t=>t.offline_id),ha=V.getInitialState({}),Wt=u.createSlice({name:"assetTypeFieldValues",initialState:ha,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ha)),reducers:{initializeAssetTypeFieldValues:V.initialize,addAssetTypeFieldValues:V.addOne,addAssetTypeFieldValuesMany:V.addMany,setAssetTypeFieldValues:V.setOne,setAssetTypeFieldValuesMany:V.setMany,updateAssetTypeFieldValues:V.updateOne,updateAssetTypeFieldValuesMany:V.updateMany,deleteAssetTypeFieldValues:V.deleteOne,deleteAssetTypeFieldValuesMany:V.deleteMany}}),{initializeAssetTypeFieldValues:ma,addAssetTypeFieldValues:Yt,addAssetTypeFieldValuesMany:fa,setAssetTypeFieldValues:uu,setAssetTypeFieldValuesMany:hu,updateAssetTypeFieldValues:Re,updateAssetTypeFieldValuesMany:pa,deleteAssetTypeFieldValues:Kt,deleteAssetTypeFieldValuesMany:ya}=Wt.actions,Aa=t=>t.assetTypeFieldValuesReducer.instances,Jt=u.createSelector([Aa],t=>Object.values(t)),mu=g(u.createSelector([Jt,(t,e)=>e],(t,e)=>S(t.filter(s=>s.asset===e)))),fu=g(u.createSelector([Ve,Jt,(t,e)=>e],(t,e,s)=>{const n=new Set(t.filter(a=>a.asset_type===s).map(a=>a.offline_id));return S(e.filter(a=>n.has(a.fields_revision)))})),Xt=t=>e=>e.assetTypeFieldValuesReducer.instances[t],ga=Wt.reducer,$=I(t=>t.offline_id),Sa=$.getInitialState({}),Zt=u.createSlice({name:"assetTypes",initialState:Sa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Sa)),reducers:{initializeAssetTypes:$.initialize,setAssetType:$.setOne,setAssetTypes:$.setMany,addAssetType:$.addOne,addAssetTypes:$.addMany,updateAssetType:$.updateOne,updateAssetTypes:$.updateMany,deleteAssetType:$.deleteOne,deleteAssetTypes:$.deleteMany}}),{initializeAssetTypes:Ta,setAssetType:pu,setAssetTypes:yu,addAssetType:Qt,addAssetTypes:Au,updateAssetType:Fe,updateAssetTypes:gu,deleteAssetType:xt,deleteAssetTypes:Su}=Zt.actions,es=t=>t.assetTypeReducer.instances,Tu=u.createSelector([es],t=>Object.values(t)),ts=t=>e=>e.assetTypeReducer.instances[t],bu=g(u.createSelector([es,(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 S(s)})),ba=Zt.reducer,_a={accessToken:"",refreshToken:"",isLoggedIn:!1},Ge=u.createSlice({name:"auth",initialState:_a,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,_a)),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||Ge.caseReducers.clearTokens(t),t.isLoggedIn=e.payload}}}),{setTokens:_u,clearTokens:Iu,setLoggedIn:Ia}=Ge.actions,Ru=t=>t.authReducer.accessToken,Fu=t=>t.authReducer.isLoggedIn,Ra=Ge.reducer,Oe=I(t=>t.offline_id),Fa=Oe.getInitialState({}),ss=u.createSlice({name:"categories",initialState:Fa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Fa)),reducers:{initializeCategories:Oe.initialize,addCategory:Oe.addOne,updateCategory:Oe.updateOne,deleteCategory:Oe.deleteOne}}),{initializeCategories:Oa,addCategory:is,updateCategory:va,deleteCategory:wa}=ss.actions,ns=t=>t.categoryReducer.instances,Ou=u.createSelector([ns],t=>Object.values(t)),as=t=>e=>e.categoryReducer.instances[t],vu=g(u.createSelector([ns,(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 S(s)})),wu=t=>e=>Object.values(e.issueReducer.instances).filter(s=>s.category===t).length,Ea=ss.reducer,B=I(t=>t.offline_id),ja=B.getInitialState({}),cs=u.createSlice({name:"documentAttachments",initialState:ja,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ja)),reducers:{initializeDocumentAttachments:B.initialize,addDocumentAttachment:B.addOne,addDocumentAttachments:B.addMany,setDocumentAttachment:B.setOne,setDocumentAttachments:B.setMany,updateDocumentAttachment:B.updateOne,updateDocumentAttachments:B.updateMany,deleteDocumentAttachment:B.deleteOne,deleteDocumentAttachments:B.deleteMany}}),{initializeDocumentAttachments:Pa,addDocumentAttachment:Eu,addDocumentAttachments:qa,setDocumentAttachment:ka,setDocumentAttachments:ju,updateDocumentAttachment:Pu,updateDocumentAttachments:Da,deleteDocumentAttachment:Ca,deleteDocumentAttachments:Ma}=cs.actions,za=t=>t.documentAttachmentReducer.instances,os=u.createSelector([za],t=>Object.values(t)),Ua=t=>e=>e.documentAttachmentReducer.instances[t],qu=g(u.createSelector([os,(t,e)=>e],(t,e)=>S(t.filter(({document:s})=>e===s)))),ku=g(u.createSelector([os,(t,e)=>e],(t,e)=>{const s=t.filter(({document:c})=>e===c),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),Va=cs.reducer,$a={documents:{}},rs=u.createSlice({name:"documents",initialState:$a,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,$a)}),reducers:{setDocuments:(t,e)=>{if(e.payload.filter(en).length!==e.payload.length)throw new Error("Tried to use setIssues reducer with duplicate ID's");t.documents=xi(e.payload)},addDocuments:(t,e)=>{for(const s of e.payload)if(s.offline_id in t.documents)throw new Error(`attempting to add a document with offline_id ${s.offline_id} 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.offline_id]}}t.documents[s.offline_id]=s}},updateDocuments:(t,e)=>{for(const s of e.payload)if(!(s.offline_id in t.documents))throw new Error(`attempting to update a document with offline_id ${s.offline_id} which doesn't exists in state.documents.`);for(const s of e.payload){const n=t.documents[s.offline_id];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.offline_id]={...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 offline_id ${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:o}=t.documents[c.parent_document];t.documents[c.parent_document].children_documents.splice(o.indexOf(c.offline_id),1)}if(n){const o=t.documents[n],d=o!=null&&o.parent_document?t.documents[o.parent_document]:null;switch(a){case"left":if(!d)throw new Error("attempting to move a document to the left of a document with no parent_document");t.documents[o.parent_document].children_documents.splice(d.children_documents.indexOf(o.offline_id),0,c.offline_id),t.documents[s].parent_document=d.offline_id;break;case"right":if(!d)throw new Error("attempting to move a document to the left of a document with no parent_document");t.documents[o.parent_document].children_documents.splice(d.children_documents.indexOf(o.offline_id)+1,0,c.offline_id),t.documents[s].parent_document=d.offline_id;break;case"left-child":if(!o)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.offline_id),t.documents[s].parent_document=o.offline_id;break;case"right-child":if(!o)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.offline_id),t.documents[s].parent_document=o.offline_id}}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 offline_id ${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.offline_id)}}delete t.documents[s]}}}}),{setDocuments:Ba,addDocuments:ds,updateDocuments:ne,moveDocument:Ga,removeDocuments:ls}=rs.actions,pe=t=>t.documentsReducer.documents,La=u.createSelector([pe],t=>Object.values(t)),Na=t=>e=>e.documentsReducer.documents[t],Du=g(u.createSelector([pe,(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 S(s)})),Cu=g(u.createSelector([pe,(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.offline_id),a=t[a.parent_document??""];return S(s)})),Mu=u.createSelector([La],t=>S(t.filter(e=>!e.parent_document))),Ha=rs.reducer,Le=I(t=>t.offline_id),zu=Le.getInitialState({}),us=u.createSlice({name:"emailDomains",initialState:zu,reducers:{initializeEmailDomains:Le.initialize,addEmailDomain:Le.addOne,deleteEmailDomain:Le.deleteOne}}),{initializeEmailDomains:Wa,addEmailDomain:Ya,deleteEmailDomain:Ka}=us.actions,Ja=t=>t.emailDomainsReducer.instances,Xa=u.createSelector([Ja],t=>Object.values(t)),Uu=g(u.createSelector([Xa,(t,e)=>e],(t,e)=>S(t.filter(s=>s.organization===e)))),Za=us.reducer,Qa={s3Urls:{}},xa=1e3*60*60,Vu=xa*24*7,hs=u.createSlice({name:"file",initialState:Qa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Qa)),reducers:{setUploadUrl:(t,e)=>{const{url:s,fields:n,sha1:a}=e.payload,c=new Date,o=new Date(c.getTime()+Vu);t.s3Urls[a]={url:s,fields:n,exp:o.getTime()}}}}),{setUploadUrl:ec}=hs.actions,tc=t=>e=>{const s=e.fileReducer.s3Urls[t];if(!s)return;const n=new Date().getTime();if(!((s.exp??n)-n<xa))return s},sc=hs.reducer,G=I(t=>t.offline_id),ic=G.getInitialState({}),ms=u.createSlice({name:"formRevisionAttachments",initialState:ic,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ic)),reducers:{initializeFormRevisionAttachments:G.initialize,addFormRevisionAttachment:G.addOne,addFormRevisionAttachments:G.addMany,setFormRevisionAttachment:G.setOne,setFormRevisionAttachments:G.setMany,updateFormRevisionAttachment:G.updateOne,updateFormRevisionAttachments:G.updateMany,deleteFormRevisionAttachment:G.deleteOne,deleteFormRevisionAttachments:G.deleteMany}}),{initializeFormRevisionAttachments:nc,addFormRevisionAttachment:$u,addFormRevisionAttachments:ac,setFormRevisionAttachment:Bu,setFormRevisionAttachments:Gu,updateFormRevisionAttachment:Lu,updateFormRevisionAttachments:cc,deleteFormRevisionAttachment:Nu,deleteFormRevisionAttachments:oc}=ms.actions,rc=t=>t.formRevisionAttachmentReducer.instances,Hu=g(u.createSelector([rc,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.form_revision===e)))),dc=ms.reducer,Wu=(t,e)=>{const s=t.revision,n=e.revision;return s==="Pending"&&n==="Pending"?t.submitted_at<e.submitted_at?-1:1:s==="Pending"?1:n==="Pending"||s<n?-1:1},ce=I(t=>t.offline_id),lc=ce.getInitialState({}),fs=u.createSlice({name:"formRevisions",initialState:lc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,lc)),reducers:{initializeFormRevisions:ce.initialize,setFormRevision:ce.setOne,addFormRevision:ce.addOne,addFormRevisions:ce.addMany,deleteFormRevision:ce.deleteOne,deleteFormRevisions:ce.deleteMany}}),{setFormRevision:uc,initializeFormRevisions:hc,addFormRevision:ps,addFormRevisions:mc,deleteFormRevision:ys,deleteFormRevisions:fc}=fs.actions,Ne=t=>t.formRevisionReducer.instances,pc=u.createSelector([Ne],t=>Object.values(t)),Yu=t=>e=>e.formRevisionReducer.instances[t],yc=(t,e)=>{let s=null;for(const n of Object.values(t))n.form===e&&(!s||s.revision<n.revision)&&(s=n);if(!s)throw new Error("No form revision found for form "+e);return s},Ku=g(u.createSelector([Ne,(t,e)=>e],(t,e)=>{const s=Object.values(t).filter(c=>c.form===e);if(s.length===0)return;const a=s.sort(Wu)[s.length-1];return t[a.offline_id]})),Ac=g(u.createSelector([pc,(t,e)=>e],(t,e)=>S(t.filter(s=>s.form===e)))),gc=fs.reducer,oe=I(t=>t.offline_id),Sc=oe.getInitialState({}),As=u.createSlice({name:"forms",initialState:Sc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Sc)),reducers:{initializeForms:oe.initialize,setForm:oe.setOne,addForm:oe.addOne,addForms:oe.addMany,updateForm:oe.updateOne,deleteForm:oe.deleteOne}}),{initializeForms:Tc,setForm:Ju,addForm:gs,addForms:Xu,updateForm:Zu,deleteForm:Ss}=As.actions,bc=As.reducer,_c=t=>t.formReducer.instances,Qu=u.createSelector([_c],t=>Object.values(t)),Ic=t=>e=>e.formReducer.instances[t],xu=g(u.createSelector([t=>t.formReducer.instances,t=>t.formRevisionReducer.instances,(t,e)=>e],(t,e,s)=>{const{searchTerm:n,maxResults:a,organization:c}=s,o=[];for(const[d,m]of Object.entries(t)){if(Number.isInteger(c)&&c!==m.organization)continue;yc(e,d).title.toLowerCase().includes(n.toLowerCase())&&o.push(m)}return[...o.slice(0,a)]},{memoizeOptions:{resultEqualityCheck:Ki}})),L=I(t=>t.offline_id),Rc=L.getInitialState({}),Ts=u.createSlice({name:"formSubmissionAttachments",initialState:Rc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Rc)),reducers:{initializeFormSubmissionAttachments:L.initialize,addFormSubmissionAttachment:L.addOne,addFormSubmissionAttachments:L.addMany,setFormSubmissionAttachment:L.setOne,setFormSubmissionAttachments:L.setMany,updateFormSubmissionAttachment:L.updateOne,updateFormSubmissionAttachments:L.updateMany,deleteFormSubmissionAttachment:L.deleteOne,deleteFormSubmissionAttachments:L.deleteMany}}),{initializeFormSubmissionAttachments:Fc,addFormSubmissionAttachment:eh,addFormSubmissionAttachments:He,setFormSubmissionAttachment:th,setFormSubmissionAttachments:sh,updateFormSubmissionAttachment:ih,updateFormSubmissionAttachments:Oc,deleteFormSubmissionAttachment:nh,deleteFormSubmissionAttachments:We}=Ts.actions,bs=t=>t.formSubmissionAttachmentReducer.instances,vc=g(u.createSelector([bs,(t,e)=>e],(t,e)=>{const s=new Set(e);return S(Object.values(t).filter(n=>s.has(n.offline_id)))})),wc=g(u.createSelector([bs,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.form_submission===e)))),Ec=Ts.reducer,N=I(t=>t.offline_id),jc=N.getInitialState({}),_s=u.createSlice({name:"formSubmissions",initialState:jc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,jc)),reducers:{initializeFormSubmissions:N.initialize,setFormSubmission:N.setOne,setFormSubmissions:N.setMany,addFormSubmission:N.addOne,addFormSubmissions:N.addMany,updateFormSubmission:N.updateOne,updateFormSubmissions:N.updateMany,deleteFormSubmission:N.deleteOne,deleteFormSubmissions:N.deleteMany}}),{initializeFormSubmissions:Pc,setFormSubmission:Ye,setFormSubmissions:ah,addFormSubmission:Is,addFormSubmissions:Ke,updateFormSubmission:qc,updateFormSubmissions:ch,deleteFormSubmission:Rs,deleteFormSubmissions:Je}=_s.actions,Fs=t=>t.formSubmissionReducer.instances,Os=u.createSelector([Fs],t=>Object.values(t)),vs=t=>e=>e.formSubmissionReducer.instances[t],kc=g(u.createSelector([Fs,Ne,(t,e)=>e],(t,e,s)=>{const n=new Set;for(const a of Object.values(e))a.form===s&&n.add(a.offline_id);return Object.values(t).filter(a=>n.has(a.form_revision))})),Dc=g(u.createSelector([Os,(t,e)=>e],(t,e)=>Object.values(t).filter(s=>s.issue===e))),Cc=g(u.createSelector([Os,(t,e)=>e],(t,e)=>t.filter(s=>s.asset===e))),Mc=_s.reducer,H=I(t=>t.offline_id),zc=H.getInitialState({}),ws=u.createSlice({name:"geoImages",initialState:zc,extraReducers:t=>{t.addCase("RESET",e=>{Object.assign(e,zc)})},reducers:{initializeGeoImages:H.initialize,setGeoImage:H.setOne,setGeoImages:H.setMany,addGeoImage:H.addOne,addGeoImages:H.addMany,updateGeoImage:H.updateOne,updateGeoImages:H.updateMany,deleteGeoImage:H.deleteOne,deleteGeoImages:H.deleteMany}}),{initializeGeoImages:Uc,setGeoImage:ve,setGeoImages:Vc,addGeoImage:$c,addGeoImages:Bc,updateGeoImage:Gc,updateGeoImages:oh,deleteGeoImage:Es,deleteGeoImages:Lc}=ws.actions,Nc=t=>t.geoImageReducer.instances,Hc=u.createSelector([Nc],t=>Object.values(t)),js=t=>e=>e.geoImageReducer.instances[t],rh=g(u.createSelector([Hc,(t,e)=>e],(t,e)=>S(t.filter(s=>s.project===e)))),Wc=ws.reducer,W=I(t=>t.offline_id),Yc=W.getInitialState({}),Ps=u.createSlice({name:"issueAssociations",initialState:Yc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Yc)),reducers:{initializeIssueAssociations:W.initialize,addIssueAssociation:W.addOne,addIssueAssociations:W.addMany,setIssueAssociation:W.setOne,setIssueAssociations:W.setMany,updateIssueAssociation:W.updateOne,updateIssueAssociations:W.updateMany,deleteIssueAssociation:W.deleteOne,deleteIssueAssociations:W.deleteMany}}),{initializeIssueAssociations:Kc,setIssueAssociations:dh,setIssueAssociation:lh,updateIssueAssociation:Jc,updateIssueAssociations:uh,addIssueAssociation:qs,addIssueAssociations:ks,deleteIssueAssociation:Ds,deleteIssueAssociations:Cs}=Ps.actions,we=t=>t.issueAssociationReducer.instances,hh=u.createSelector([we],t=>Object.values(t)),Xc=t=>e=>e.issueAssociationReducer.instances[t],Zc=g(u.createSelector([we,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.associated_issue===e)))),Qc=g(u.createSelector([we,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.issue===e)))),xc=g(u.createSelector([we,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.asset===e)))),eo=Ps.reducer,Y=I(t=>t.offline_id),to=Y.getInitialState({}),Ms=u.createSlice({name:"issueAttachments",initialState:to,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,to)),reducers:{initializeIssueAttachments:Y.initialize,addIssueAttachment:Y.addOne,addIssueAttachments:Y.addMany,setIssueAttachment:Y.setOne,setIssueAttachments:Y.setMany,updateIssueAttachment:Y.updateOne,updateIssueAttachments:Y.updateMany,deleteIssueAttachment:Y.deleteOne,deleteIssueAttachments:Y.deleteMany}}),{initializeIssueAttachments:so,addIssueAttachment:mh,addIssueAttachments:zs,setIssueAttachment:io,setIssueAttachments:fh,updateIssueAttachment:ph,updateIssueAttachments:no,deleteIssueAttachment:ao,deleteIssueAttachments:Us}=Ms.actions,co=t=>t.issueAttachmentReducer.instances,Vs=u.createSelector([co],t=>Object.values(t)),oo=g(u.createSelector([Vs,(t,e)=>e],(t,e)=>S(t.filter(({issue:s})=>e===s)))),ro=t=>e=>e.issueAttachmentReducer.instances[t],yh=g(u.createSelector([Vs,(t,e)=>e],(t,e)=>{const s=t.filter(({issue:c})=>c===e),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),lo=Ms.reducer,re=I(t=>t.offline_id),uo=re.getInitialState({}),$s=u.createSlice({name:"issueComments",initialState:uo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,uo)),reducers:{addIssueComment:re.addOne,addIssueComments:re.addMany,setIssueComment:re.setOne,setIssueComments:re.setMany,deleteIssueComment:re.deleteOne,deleteIssueComments:re.deleteMany}}),{setIssueComments:ho,setIssueComment:Bs,addIssueComment:Gs,addIssueComments:Ah,deleteIssueComment:Ls,deleteIssueComments:gh}=$s.actions,mo=t=>t.issueCommentReducer.instances,fo=t=>e=>e.issueCommentReducer.instances[t],Sh=g(u.createSelector([mo,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.issue===e)))),po=$s.reducer,de=I(t=>t.offline_id),yo=de.getInitialState({}),Ns=u.createSlice({name:"issues",initialState:yo,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,yo)}),reducers:{initializeIssues:de.initialize,addIssue:de.addOne,addIssues:de.addMany,updateIssue:de.updateOne,deleteIssue:de.deleteOne,deleteIssues:de.deleteMany}}),{initializeIssues:Ao,addIssue:Hs,addIssues:go,updateIssue:Xe,deleteIssue:Ws,deleteIssues:So}=Ns.actions,To=t=>t.issueReducer.instances,Ys=t=>e=>e.issueReducer.instances[t],Th=g(u.createSelector([To,(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 S(s)})),bo=Ns.reducer,K=I(t=>t.offline_id),_o=K.getInitialState({}),Ks=u.createSlice({name:"issueTypeFieldsAttachments",initialState:_o,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,_o)),reducers:{initializeIssueTypeFieldsAttachments:K.initialize,addIssueTypeFieldsAttachment:K.addOne,addIssueTypeFieldsAttachments:K.addMany,setIssueTypeFieldsAttachment:K.setOne,setIssueTypeFieldsAttachments:K.setMany,updateIssueTypeFieldsAttachment:K.updateOne,updateIssueTypeFieldsAttachments:K.updateMany,deleteIssueTypeFieldsAttachment:K.deleteOne,deleteIssueTypeFieldsAttachments:K.deleteMany}}),{initializeIssueTypeFieldsAttachments:Io,addIssueTypeFieldsAttachment:bh,addIssueTypeFieldsAttachments:Ro,setIssueTypeFieldsAttachment:_h,setIssueTypeFieldsAttachments:Ih,updateIssueTypeFieldsAttachment:Rh,updateIssueTypeFieldsAttachments:Fo,deleteIssueTypeFieldsAttachment:Fh,deleteIssueTypeFieldsAttachments:Oo}=Ks.actions,vo=t=>t.issueTypeFieldsAttachmentReducer.instances,wo=u.createSelector([vo],t=>Object.values(t)),Oh=g(u.createSelector([wo,(t,e)=>e],(t,e)=>S(t.filter(s=>s.fields_revision===e)))),vh=t=>e=>e.issueTypeFieldsAttachmentReducer.instances[t],Eo=Ks.reducer,J=I(t=>t.offline_id),jo=J.getInitialState({}),Js=u.createSlice({name:"issueTypeFieldValues",initialState:jo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,jo)),reducers:{initializeIssueTypeFieldValues:J.initialize,addIssueTypeFieldValues:J.addOne,addIssueTypeFieldValuesMany:J.addMany,setIssueTypeFieldValues:J.setOne,setIssueTypeFieldValuesMany:J.setMany,updateIssueTypeFieldValues:J.updateOne,updateIssueTypeFieldValuesMany:J.updateMany,deleteIssueTypeFieldValues:J.deleteOne,deleteIssueTypeFieldValuesMany:J.deleteMany}}),{initializeIssueTypeFieldValues:Po,addIssueTypeFieldValues:Xs,addIssueTypeFieldValuesMany:wh,setIssueTypeFieldValues:Eh,setIssueTypeFieldValuesMany:jh,updateIssueTypeFieldValues:Ee,updateIssueTypeFieldValuesMany:Ph,deleteIssueTypeFieldValues:Zs,deleteIssueTypeFieldValuesMany:qh}=Js.actions,qo=t=>t.issueTypeFieldValuesReducer.instances,Qs=u.createSelector([qo],t=>Object.values(t)),kh=g(u.createSelector([Qs,(t,e)=>e],(t,e)=>S(t.filter(s=>s.issue===e)))),xs=t=>e=>e.issueTypeFieldValuesReducer.instances[t],ko=Js.reducer,X=I(t=>t.offline_id),Do=X.getInitialState({}),ei=u.createSlice({name:"issueTypeFields",initialState:Do,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Do)),reducers:{initializeIssueTypeFields:X.initialize,addIssueTypeFields:X.addOne,addIssueTypeFieldsMany:X.addMany,setIssueTypeFields:X.setOne,setIssueTypeFieldsMany:X.setMany,updateIssueTypeFields:X.updateOne,updateIssueTypeFieldsMany:X.updateMany,deleteIssueTypeFields:X.deleteOne,deleteIssueTypeFieldsMany:X.deleteMany}}),{initializeIssueTypeFields:Co,addIssueTypeFields:Mo,addIssueTypeFieldsMany:Dh,setIssueTypeFields:Ch,setIssueTypeFieldsMany:Mh,updateIssueTypeFields:zo,updateIssueTypeFieldsMany:zh,deleteIssueTypeFields:Uo,deleteIssueTypeFieldsMany:Uh}=ei.actions,Vo=t=>t.issueTypeFieldsReducer.instances,Ze=u.createSelector([Vo],t=>Object.values(t)),Vh=g(u.createSelector([Ze,(t,e)=>e],(t,e)=>S(t.filter(s=>s.issue_type===e)))),$h=g(u.createSelector([Ze,(t,e)=>e],(t,e)=>t.filter(s=>s.issue_type===e).sort((s,n)=>s.submitted_at>n.submitted_at?-1:1)[0])),Bh=g(u.createSelector([Ze,Qs,(t,e)=>e],(t,e,s)=>{const n=new Set(t.filter(a=>a.issue_type===s).map(a=>a.offline_id));return S(e.filter(a=>n.has(a.fields_revision)))})),Gh=t=>e=>e.issueTypeFieldsReducer.instances[t],$o=ei.reducer,Z=I(t=>t.offline_id),Bo=Z.getInitialState({}),ti=u.createSlice({name:"issueTypeFieldValuesAttachments",initialState:Bo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Bo)),reducers:{initializeIssueTypeFieldValuesAttachments:Z.initialize,addIssueTypeFieldValuesAttachment:Z.addOne,addIssueTypeFieldValuesAttachments:Z.addMany,setIssueTypeFieldValuesAttachment:Z.setOne,setIssueTypeFieldValuesAttachments:Z.setMany,updateIssueTypeFieldValuesAttachment:Z.updateOne,updateIssueTypeFieldValuesAttachments:Z.updateMany,deleteIssueTypeFieldValuesAttachment:Z.deleteOne,deleteIssueTypeFieldValuesAttachments:Z.deleteMany}}),{initializeIssueTypeFieldValuesAttachments:Go,addIssueTypeFieldValuesAttachment:Lh,addIssueTypeFieldValuesAttachments:Qe,setIssueTypeFieldValuesAttachment:Nh,setIssueTypeFieldValuesAttachments:Hh,updateIssueTypeFieldValuesAttachment:Wh,updateIssueTypeFieldValuesAttachments:Lo,deleteIssueTypeFieldValuesAttachment:Yh,deleteIssueTypeFieldValuesAttachments:xe}=ti.actions,si=t=>t.issueTypeFieldValuesAttachmentReducer.instances,No=u.createSelector([si],t=>Object.values(t)),Kh=t=>e=>e.issueTypeFieldValuesAttachmentReducer.instances[t],Ho=g(u.createSelector([si,(t,e)=>e],(t,e)=>{const s=new Set(e);return S(Object.values(t).filter(n=>s.has(n.offline_id)))})),Wo=g(u.createSelector([No,(t,e)=>e],(t,e)=>S(t.filter(s=>s.field_values===e)))),Yo=ti.reducer,ye=I(t=>t.offline_id),Ko=ye.getInitialState({}),ii=u.createSlice({name:"issueTypes",initialState:Ko,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,Ko)}),reducers:{initializeIssueTypes:ye.initialize,setIssueType:ye.setOne,addIssueType:ye.addOne,updateIssueType:ye.updateOne,removeIssueType:ye.deleteOne}}),{initializeIssueTypes:Jo,setIssueType:je,addIssueType:Xo,updateIssueType:Zo,removeIssueType:ni}=ii.actions,Qo=t=>t.issueTypeReducer.instances,xo=u.createSelector(Qo,t=>Object.values(t)),ai=t=>e=>e.issueTypeReducer.instances[t],Jh=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},Xh=g(u.createSelector([xo,(t,e)=>e],(t,e)=>S(t.filter(s=>s.organization===e)))),ci=g(u.createSelector([t=>t.issueReducer.instances,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.issue_type===e)))),Zh=t=>e=>ci(t)(e).length,er=ii.reducer,le=I(t=>t.offline_id),tr=le.getInitialState({}),oi=u.createSlice({name:"issueUpdates",initialState:tr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,tr)),reducers:{initializeIssueUpdates:le.setMany,setIssueUpdate:le.setOne,addIssueUpdate:le.addOne,addIssueUpdates:le.addMany,deleteIssueUpdate:le.deleteOne,deleteIssueUpdates:le.deleteMany}}),{initializeIssueUpdates:sr,setIssueUpdate:Qh,addIssueUpdate:ir,addIssueUpdates:nr,deleteIssueUpdate:ar,deleteIssueUpdates:cr}=oi.actions,or=t=>t.issueUpdateReducer.instances,rr=g(u.createSelector([or,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.issue===e)))),dr=oi.reducer,et=I(t=>t.offline_id),lr=et.getInitialState({}),ri=u.createSlice({name:"license",initialState:lr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,lr)),reducers:{initializeLicences:et.initialize,addLicenses:et.addMany,updateLicense:et.updateOne}}),{initializeLicences:ur,addLicenses:xh,updateLicense:te}=ri.actions,tt=t=>t.licenseReducer.instances,em=t=>e=>e.licenseReducer.instances[t],hr=t=>e=>Object.values(e.licenseReducer.instances).find(s=>s.project===t),tm=u.createSelector([tt],t=>S(Object.values(t).filter(e=>e.is_active))),sm=u.createSelector([tt],t=>ae(Object.values(t).filter(e=>e.project).reduce((e,s)=>({...e,[s.project]:s}),{}))),mr=ri.reducer,fr={users:{},currentUser:null},di=u.createSlice({name:"users",initialState:fr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,fr)),reducers:{setUsers:(t,e)=>{const s={};e.payload.forEach(n=>{s[n.id]=n}),t.users=s},addUsers:(t,e)=>{for(const s of e.payload)t.users[s.id]=s},setCurrentUser:(t,e)=>{t.currentUser=e.payload},setProfilePicture:(t,e)=>{if(!t.currentUser)return;t.currentUser.profile.file=e.payload.file??null,t.currentUser.profile.file_sha1=e.payload.file_sha1??null;const s=t.users[t.currentUser.id];if(!s)throw new Error("Unable to find current user in users slice");s.profile.file=e.payload.file??null,s.profile.file_sha1=e.payload.file_sha1??null},removeUser:(t,e)=>{delete t.users[e.payload]}}}),{setCurrentUser:im,setProfilePicture:nm,setUsers:pr,addUsers:am,removeUser:yr}=di.actions,Ar=di.reducer,st=t=>t.userReducer.currentUser,it=t=>t.userReducer.users,cm=t=>e=>e.userReducer.users[t],om=g(u.createSelector([it,(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 id",n)}return S(s)})),nt=I(t=>t.offline_id),gr=nt.getInitialState({}),li=u.createSlice({name:"organizationAccess",initialState:gr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,gr)),reducers:{initializeOrganizationAccesses:nt.initialize,updateOrganizationAccess:nt.updateOne,deleteOrganizationAccess:nt.deleteOne}}),{initializeOrganizationAccesses:Sr,updateOrganizationAccess:Tr,deleteOrganizationAccess:br}=li.actions,ui=t=>t.organizationAccessReducer.instances,rm=t=>e=>e.organizationAccessReducer.instances[t],dm=u.createSelector([st,ui],(t,e)=>Object.values(e).find(n=>n.user===(t==null?void 0:t.id))??null),lm=t=>e=>Object.values(e.organizationAccessReducer.instances).find(s=>s.user===t.id),_r=t=>{const e={};for(const s of Object.values(t.organizationAccessReducer.instances))e[s.user]=s;return ae(e)},Ir=li.reducer,Pe=I(t=>t.offline_id),Rr=Pe.getInitialState({}),hi=u.createSlice({name:"projectAccess",initialState:Rr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Rr)),reducers:{initializeProjectAccesses:Pe.initialize,updateProjectAccess:Pe.updateOne,deleteProjectAccess:Pe.deleteOne,deleteProjectAccesses:Pe.deleteMany}}),{initializeProjectAccesses:mi,updateProjectAccess:Fr,deleteProjectAccess:Or,deleteProjectAccesses:vr}=hi.actions,fi=t=>t.projectAccessReducer.instances,wr=u.createSelector(fi,t=>Object.values(t)),um=t=>e=>e.projectAccessReducer.instances[t],hm=t=>e=>Object.values(e.projectAccessReducer.instances).find(s=>s.user===t.id),Er=t=>{const e={};for(const s of Object.values(t.projectAccessReducer.instances))e[s.user]=s;return ae(e)},jr=hi.reducer,Pr={projects:{}},pi=u.createSlice({name:"projects",initialState:Pr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Pr)),reducers:{setProjects:(t,e)=>{const s={};e.payload.forEach(n=>{s[n.id]=n}),t.projects=s},updateProject:(t,e)=>{t.projects[e.payload.id]=e.payload},deleteProject:(t,e)=>{delete t.projects[e.payload.id]},acceptProjectInvite:(t,e)=>{if(e.payload in t.projects)t.projects[e.payload].invited=!1;else throw new Error("Accept project invite: user is not in this project")}}}),{setProjects:qr,updateProject:kr,deleteProject:Dr,acceptProjectInvite:Cr}=pi.actions,Mr=pi.reducer,yi=t=>t.projectReducer.projects,mm=t=>e=>e.projectReducer.projects[t],zr=u.createSelector([fi],t=>Object.values(t).map(e=>e.user)),Ur=u.createSelector([zr,it],(t,e)=>t.reduce((s,n)=>({...s,[n]:e[n]}),{})),fm=u.createSelector([st,Ur,Er],(t,e,s)=>S(Object.values(e).sort((n,a)=>{if(n.id===(t==null?void 0:t.id))return-1;if(a.id===(t==null?void 0:t.id))return 1;const c=s[n.id],o=s[a.id];return(c==null?void 0:c.access_level)===(o==null?void 0:o.access_level)?n.username.localeCompare(a.username):(c==null?void 0:c.access_level)===ot.ADMIN?-1:1}))),Vr={organizations:{}},Ai=u.createSlice({name:"organizations",initialState:Vr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Vr)),reducers:{setOrganizations:(t,e)=>{for(const s of e.payload)t.organizations[s.id]=s}}}),{setOrganizations:$r}=Ai.actions,Br=t=>t.organizationReducer.organizations,Gr=u.createSelector([Br],t=>Object.values(t)),pm=t=>e=>e.organizationReducer.organizations[t],ym=u.createSelector([Gr],t=>S(Object.values(t).filter(e=>e.has_access))),Lr=u.createSelector([ui],t=>Object.values(t).map(e=>e.user)),Am=g(u.createSelector([yi,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.organization_owner===e)))),gm=g(u.createSelector([tt,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.organization_owner===e)))),Nr=u.createSelector([Lr,it],(t,e)=>ae(t.reduce((s,n)=>({...s,[n]:e[n]}),{}))),Sm=u.createSelector([st,Nr,_r],(t,e,s)=>S(Object.values(e).sort((n,a)=>{if(n.id===(t==null?void 0:t.id))return-1;if(a.id===(t==null?void 0:t.id))return 1;const c=s[n.id],o=s[a.id];return(c==null?void 0:c.access_level)===(o==null?void 0:o.access_level)?n.username.localeCompare(a.username):(c==null?void 0:c.access_level)===rt.ADMIN?-1:1}))),Hr=Ai.reducer,Wr=(t,e,s)=>{const n=t.uuid?t:{...t,uuid:O.v4()};return{payload:n,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:n,BASE_URL:e,serviceName:s}}}}},Yr={deletedRequests:[],latestRetryTime:0},gi=u.createSlice({name:"outbox",initialState:Yr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Yr)),reducers:{enqueueRequest:{reducer:(t,e)=>t,prepare:t=>{console.debug("Preparing to enqueue request",t);const{BASE_URL:e,serviceName:s,...n}=t;return Wr(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}}}),Tm=t=>t.outboxReducer.deletedRequests,bm=t=>t.outboxReducer.latestRetryTime,{enqueueRequest:Kr,markForDeletion:_m,markAsDeleted:Jr,_setLatestRetryTime:Xr}=gi.actions,Zr=gi.reducer,Q=I(t=>t.offline_id),Qr=Q.getInitialState({}),Si=u.createSlice({name:"projectAttachments",initialState:Qr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Qr)),reducers:{initializeProjectAttachments:Q.initialize,addProjectAttachment:Q.addOne,addProjectAttachments:Q.addMany,setProjectAttachment:Q.setOne,setProjectAttachments:Q.setMany,updateProjectAttachment:Q.updateOne,updateProjectAttachments:Q.updateMany,deleteProjectAttachment:Q.deleteOne,deleteProjectAttachments:Q.deleteMany}}),{initializeProjectAttachments:xr,addProjectAttachment:Im,addProjectAttachments:ed,setProjectAttachment:td,setProjectAttachments:sd,updateProjectAttachment:Rm,updateProjectAttachments:id,deleteProjectAttachment:nd,deleteProjectAttachments:Ti}=Si.actions,ad=t=>t.projectAttachmentReducer.instances,bi=u.createSelector([ad],t=>Object.values(t)),cd=t=>e=>e.projectAttachmentReducer.instances[t],od=g(u.createSelector([bi,(t,e)=>e],(t,e)=>S(t.filter(({project:s})=>e===s)))),Fm=g(u.createSelector([bi,(t,e)=>e],(t,e)=>{const s=t.filter(({project:c})=>e===c),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),rd=Si.reducer,x=I(t=>t.offline_id),dd=x.getInitialState({activeProjectFileId:null,isImportingProjectFile:!1}),_i=u.createSlice({name:"projectFiles",initialState:dd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,dd)),reducers:{initializeProjectFiles:x.initialize,setProjectFile:x.setOne,setProjectFiles:x.setMany,addProjectFile:x.addOne,addProjectFiles:x.addMany,updateProjectFile:x.updateOne,updateProjectFiles:x.updateMany,deleteProjectFile:x.deleteOne,deleteProjectFiles:x.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:ld,setProjectFile:Om,setProjectFiles:vm,addProjectFile:wm,addProjectFiles:ud,updateProjectFile:Ii,updateProjectFiles:Em,deleteProjectFile:hd,deleteProjectFiles:md,setIsImportingProjectFile:fd,setActiveProjectFileId:pd,saveActiveProjectFileBounds:yd,resetProjectFileObjectUrls:jm}=_i.actions,Ad=t=>t.projectFileReducer.instances,gd=u.createSelector([Ad],t=>S(Object.values(t).sort((e,s)=>e.z_index-s.z_index))),Pm=t=>e=>e.projectFileReducer.instances[t],qm=t=>t.projectFileReducer.activeProjectFileId,km=t=>t.projectFileReducer.isImportingProjectFile,Sd=_i.reducer,Dm={isRehydrated:!1},Ri=u.createSlice({name:"rehydrated",initialState:Dm,reducers:{setRehydrated:(t,e)=>{t.isRehydrated=e.payload}}}),{setRehydrated:Cm}=Ri.actions,Mm=t=>t.rehydratedReducer.isRehydrated,Td=Ri.reducer,Ae=I(t=>t.offline_id),bd=Ae.getInitialState({}),Fi=u.createSlice({name:"teams",initialState:bd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,bd)),reducers:{setTeam:Ae.setOne,initializeTeams:Ae.initialize,addTeam:Ae.addOne,updateTeam:Ae.updateOne,deleteTeam:Ae.deleteOne}}),{setTeam:ge,initializeTeams:_d,addTeam:Id,updateTeam:Oi,deleteTeam:vi}=Fi.actions,wi=t=>t.teamReducer.instances,Ei=u.createSelector([wi],t=>Object.values(t)),Se=t=>e=>e.teamReducer.instances[t],zm=g(u.createSelector([wi,(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 S(s)})),Um=g(u.createSelector([Ei,(t,e)=>e],(t,e)=>S(t.filter(s=>s.organization===e)))),Vm=g(u.createSelector([Ei,(t,e)=>e],(t,e)=>S(t.filter(s=>s.members.includes(e))))),Rd=Fi.reducer,$m={version:0},Fd=u.createSlice({name:"versioning",initialState:$m,reducers:{}}),Od=Fd.reducer;let vd;function Bm(t){vd=t}function qe(){return vd}let wd;function Gm(t){wd=t}function Lm(){return wd}const Ed={};class jd{constructor(e){A(this,"client");Ed[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 Pd="versioning",qd=()=>Cd.length-1,kd=t=>(t[Pd]={version:qd()},t),Dd=()=>kd({}),Nm=t=>(t.outboxReducer&&(t.outboxReducer.deletedRequests=[]),t),Hm=t=>e=>{var s;return e===void 0&&(e={}),((s=e[Pd])==null?void 0:s.version)===qd()?e:t(e)},Cd=[kd,Dd,Dd,Nm],Wm=Object.fromEntries(Cd.map((t,e)=>[e,Hm(t)])),ji="versioning",Md={[ji]:Od,fileReducer:sc,authReducer:Ra,categoryReducer:Ea,assetReducer:Tn,assetAttachmentReducer:pn,assetStageCompletionReducer:vn,assetStageReducer:Pn,assetTypeReducer:ba,assetTypeAttachmentReducer:Ln,issueReducer:bo,issueAttachmentReducer:lo,issueTypeReducer:er,organizationReducer:Hr,outboxReducer:Zr,projectReducer:Mr,projectAttachmentReducer:rd,projectAccessReducer:jr,organizationAccessReducer:Ir,projectFileReducer:Sd,rehydratedReducer:Td,formReducer:bc,formRevisionReducer:gc,formRevisionAttachmentReducer:dc,formSubmissionAttachmentReducer:Ec,formSubmissionReducer:Mc,userReducer:Ar,emailDomainsReducer:Za,licenseReducer:mr,documentsReducer:Ha,documentAttachmentReducer:Va,teamReducer:Rd,agentsReducer:on,issueCommentReducer:po,issueUpdateReducer:dr,geoImageReducer:Wc,issueAssociationReducer:eo,issueTypeFieldsReducer:$o,issueTypeFieldValuesReducer:ko,issueTypeFieldsAttachmentReducer:Eo,issueTypeFieldValuesAttachmentReducer:Yo,assetTypeFieldsReducer:na,assetTypeFieldValuesReducer:ga,assetTypeFieldsAttachmentReducer:Zn,assetTypeFieldValuesAttachmentReducer:ua},zd=u.combineReducers(Md),Ud="RESET",Ym=(t,e)=>e.type==="auth/setLoggedIn"&&!e.payload?zd(void 0,e):zd(t,e);let Pi=null;function ue(){const t=qe();if(!t)return console.warn("Client store not set; cannot get outbox coordinator yet."),null;if(Pi)return Pi;const e=t.getState().offline.outbox,s=be._fromOutbox(e);return Pi=s,s}const Km=t=>{if(t)throw t;const e=qe();e?e.dispatch({type:"rehydrated/setRehydrated",payload:!0}):console.error("Client store not set")},Vd=(t,e,s)=>{const n=ue();return n?(n.addRequest(e),n.getQueue()):(console.warn("Outbox coordinator not set; cannot enqueue request yet."),[])},$d=(t,e,s)=>{const n=ue();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 Jm(t,e){if(!e.payload)throw new Error("Received empty payload");return af(e)}const Xm={...Vi,effect:Jm,discard:ki,returnPromises:!0,persistCallback:Km,retry:of,persistOptions:{storage:Jd},queue:{...Vi.queue,enqueue:Vd,dequeue:$d,peek:(...t)=>cf(...t)}},Zm=Xd(Wm,ji),Qm=u.compose(Kd.offline(Xm),Zm);function xm(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 qi(t,e){const s=Ed[t.meta.offline.effect.serviceName];if(!s)throw new Error(`Service ${t.meta.offline.effect.serviceName} not found`);const n=s instanceof F;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},o=t.meta.offline.effect,{payload:d,headers:m,method:r,queryParams:h,attachmentHash:f,isExternalUrl:p,isAuthNeeded:y,isResponseBlob:T}={...c,...o.request},_=o.request;let b=_.url;const E=f?await e.files.fetchCache(f):void 0;if(f&&!E)throw new Error(`Cannot upload file ${f} because it's not cached.`);!p&&!b.startsWith("http")&&(!b.startsWith("/")&&!b.startsWith("blob:")&&(b="/"+b),b=t.meta.offline.effect.BASE_URL+b);const se=w=>{if(f){const ee=_.s3url;if(!ee)throw new Error(`No S3 URL for file ${f}`);if("warning"in ee)throw new Error(`S3 URL warning for file ${f}`);if(!E)throw new Error(`No file for file ${f}`);const De=ee.fields["x-amz-checksum-sha1"];if(!De)throw new Error(`No checksum for file ${f}`);return w.set("x-amz-checksum-sha1",De).field({...d,...ee.fields}).attach("file",E)}return w.send(d)},op={[l.GET]:()=>T?me.get(b.toString()).responseType("blob"):me.get(b.toString()),[l.POST]:()=>{const w=me.post(b.toString());return se(w)},[l.PATCH]:()=>{const w=me.patch(b.toString());return se(w)},[l.PUT]:()=>{const w=me.put(b.toString());return se(w)},[l.DELETE]:()=>{const w=me.delete(b.toString());return se(w)}}[r];let he=op();if(y&&n){const w=s.auth.getAuthHeader();he=he.set("Authorization",w)}m&&(he=he.set(m));try{return await he.query(h)}catch(w){const ee=xm(w),De=ee==null?void 0:ee.status;if(n&&De===401)return await s.auth.handleUnauthorized(he,ee),he.query(h);throw new j({response:ee,innerError:w,discard:Gd.includes(De)})}}class ef{constructor(e){A(this,"_all");A(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 Bd{constructor(){A(this,"next");this.next=null}then(e){return new ef(this).then(e)}async run(e){if(this.next)return this.next.run(e);{if(console.debug("Middleware finished. Performing request:",e),!qe())throw new Error("Client store not set");const n=Lm();if(!n)throw new Error("Client SDK not set");return qi(e,n)}}}class tf extends Bd{async run(e){return super.run(e)}}class sf extends Bd{async run(e){return super.run(e)}}const nf=new tf().then(new sf).compile();function af(t){var e;return(e=nf[0])==null?void 0:e.run(t)}const Gd=[400,409,403,404,405,500];function ki(t,e,s=0){var r;if(console.debug("Considering discarding request due to error:",t,`(${typeof t})`,`
1
+ (function(i,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("uuid"),require("@reduxjs/toolkit"),require("file-saver"),require("@redux-offline/redux-offline"),require("@redux-offline/redux-offline/lib/defaults"),require("localforage"),require("redux-persist-migrate"),require("superagent"),require("dependency-graph"),require("idb"),require("@redux-offline/redux-offline/lib/constants"),require("jwt-decode")):typeof define=="function"&&define.amd?define(["exports","uuid","@reduxjs/toolkit","file-saver","@redux-offline/redux-offline","@redux-offline/redux-offline/lib/defaults","localforage","redux-persist-migrate","superagent","dependency-graph","idb","@redux-offline/redux-offline/lib/constants","jwt-decode"],O):(i=typeof globalThis<"u"?globalThis:i||self,O(i["overmap-core"]={},i.uuid,i.toolkit,i.fileSaver,i.reduxOffline,i.offlineConfig,i.localforage,i.createMigration,i.request,i.dependencyGraph,i.idb,i.constants,i.jwtDecode))})(this,function(i,O,u,Yd,Kd,Ui,Jd,Xd,me,Zd,Qd,xd,el){"use strict";var rp=Object.defineProperty;var dp=(i,O,u)=>O in i?rp(i,O,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[O]=u;var A=(i,O,u)=>dp(i,typeof O!="symbol"?O+"":O,u);var Hd;const Vi=Object.freeze([]),$i=Object.freeze({});var ot=(t=>(t[t.GUEST=0]="GUEST",t[t.BASIC=2]="BASIC",t[t.ADMIN=4]="ADMIN",t))(ot||{}),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||{}),Bi=(t=>(t.Issue="issue",t.Asset="asset",t.AssetType="asset_type",t.Project="project",t.Document="document",t))(Bi||{}),dt=(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))(dt||{}),lt=(t=>(t[t.BACKLOG=0]="BACKLOG",t[t.SELECTED=2]="SELECTED",t[t.DONE=4]="DONE",t))(lt||{}),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||{}),Gi=(t=>(t.COMPLETED="checkout.completed",t.CLOSED="checkout.closed",t))(Gi||{}),Li=(t=>(t[t.PRO=0]="PRO",t))(Li||{}),Ni=(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))(Ni||{});const tl=lt.BACKLOG,sl=dt.MEDIUM,Hi=6e4;function I(t){return{addOne:(f,p)=>{const y=t(p.payload);f.instances[y]=p.payload},addMany:(f,p)=>{for(const y of p.payload){const T=t(y);f.instances[T]=y}},setOne:(f,p)=>{const y=t(p.payload);f.instances[y]=p.payload},setMany:(f,p)=>{for(const y of p.payload){const T=t(y);f.instances[T]=y}},updateOne:(f,p)=>{const y=t(p.payload);f.instances[y]=p.payload},updateMany:(f,p)=>{for(const y of p.payload){const T=t(y);f.instances[T]=y}},deleteOne:(f,p)=>{delete f.instances[p.payload]},deleteMany:(f,p)=>{for(const y of p.payload)delete f.instances[y]},initialize:(f,p)=>{f.instances={};for(const y of p.payload){const T=t(y);f.instances[T]=y}},getInitialState:f=>({...f,instances:{}})}}Hd=Symbol.toStringTag;class Wi{constructor(){A(this,Hd,"Promise");A(this,"_promise");A(this,"_resolve");A(this,"_reject");A(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 il=t=>({type:"Point",coordinates:t}),nl=t=>({type:"MultiPoint",coordinates:t}),al=(t,e)=>t[0]===e[0]&&t[1]===e[1];let ut=!1;["true","1"].includes("".toLowerCase())&&(ut=!0);function Yi(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 o=s[c];if(!Object.prototype.hasOwnProperty.call(e,o)||t[o]!==e[o])return!1}return!0}function ht(t){const e={};return function(){const s=Array.prototype.slice.call(arguments);return s in e?(ut&&console.debug(`Memoization debug: Using memorized return value for ${t.toString()}(`,s,")"),e[s]):(ut&&console.debug(`Memoization debug: Cache miss! Memoizing ${t.toString()}(`,s,")"),e[s]=t.apply(this,s))}}function cl(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 S=t=>t.length===0?Vi:t,ae=t=>Object.keys(t).length===0?$i:t,Ki=ht(t=>{if(!t)return"";const e=new Date(t),s=e.getFullYear()===mt.getFullYear(),n={day:"numeric",month:"short"};return s||(n.year="numeric"),e.toLocaleDateString([],n)}),ol=new Intl.RelativeTimeFormat([],{style:"long",numeric:"auto"}),rl=1e3*86400,mt=new Date,dl=t=>new Date(t).toDateString()===mt.toDateString(),ll=ht((t,e,s)=>{const n=Math.round((new Date(t).getTime()-mt.getTime())/rl);return n<e||n>s?Ki(t):ol.format(n,"days")});function ul(t){return new Uint8Array(t).reduce((s,n)=>s+n.toString(16).padStart(2,"0"),"")}const ft=async(t,e)=>{e||(e=await fe(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 fe(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 o=ul(c);e(o)})},n.readAsArrayBuffer(t)})}function hl(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 Ji(t,e){return new File([t],e,{type:t.type})}function ml(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 fl=async t=>{const e={};for(const s of t){const n=await fe(s);e[n]={sha1:n,extension:s.name.split(".").pop()||"",file_type:s.type,size:s.size}}return Object.values(e)},Xi=async t=>(await fetch(t)).blob(),pl=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]);Yd.saveAs(e,t.name)}const Zi={};function Al(t,e,s,...n){const a=Zi[t];let c=!1;a?a[e]||(a[e]=!0,c=!0):(Zi[t]={[e]:!0},c=!0),c&&console[s](...n)}function R(t){return{...t,offline_id:O.v4()}}function Qi(t){const e={};for(const s of t)e[s.offline_id]=s;return e}function gl(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 Sl(t){return t.toLowerCase().replace(" ","-")}function Tl(t,e=!1){return t.normalize("NFKD").toLowerCase().replace(/[^\w\s-]/g,"").trim().replace(/[-\s]+/g,e?"_":"-")}function bl(t,e){if(t.length<=e)return t;const s=t.slice(0,e-1);return s.slice(0,s.lastIndexOf(" "))+"…"}const g=t=>e=>s=>t(s,e);function xi(t,e,s){return s.findIndex(n=>n.offline_id===t.offline_id)===e}function _l(t,e,s){return s.findIndex(n=>n.file_sha1===t.file_sha1)===e}const Il=/^.+@.+\..+$/,_e=I(t=>t.offline_id),en=_e.getInitialState({}),pt=u.createSlice({name:"agents",initialState:en,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,en)),reducers:{initializeConversations:_e.initialize,addConversation:_e.addOne,setConversation:_e.setOne,updateConversation:_e.updateOne}}),{initializeConversations:tn,addConversation:sn,setConversation:nn,updateConversation:an}=pt.actions,yt=t=>t.agentsReducer.instances,Rl=u.createSelector([yt],t=>Object.values(t)),Fl=g(u.createSelector([yt,(t,e)=>e],(t,e)=>t[e])),cn=pt.reducer,q=I(t=>t.offline_id),on=q.getInitialState({}),At=u.createSlice({name:"assetAttachments",initialState:on,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,on)),reducers:{initializeAssetAttachments:q.initialize,addAssetAttachment:q.addOne,addAssetAttachments:q.addMany,setAssetAttachment:q.setOne,setAssetAttachments:q.setMany,updateAssetAttachment:q.updateOne,updateAssetAttachments:q.updateMany,deleteAssetAttachment:q.deleteOne,deleteAssetAttachments:q.deleteMany}}),{initializeAssetAttachments:gt,addAssetAttachment:Ol,addAssetAttachments:St,setAssetAttachment:rn,setAssetAttachments:vl,updateAssetAttachment:wl,updateAssetAttachments:dn,deleteAssetAttachment:ln,deleteAssetAttachments:Tt}=At.actions,un=t=>t.assetAttachmentReducer.instances,bt=u.createSelector([un],t=>Object.values(t)),hn=t=>e=>e.assetAttachmentReducer.instances[t],mn=g(u.createSelector([bt,(t,e)=>e],(t,e)=>S(t.filter(({asset:s})=>e===s)))),El=g(u.createSelector([bt,(t,e)=>e],(t,e)=>{const s=t.filter(({asset:c})=>e===c),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),fn=At.reducer,k=I(t=>t.offline_id),pn=k.getInitialState({}),_t=u.createSlice({name:"assets",initialState:pn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,pn)),reducers:{initializeAssets:k.initialize,addAsset:k.addOne,addAssets:k.addMany,setAsset:k.setOne,setAssets:k.setMany,updateAsset:k.updateOne,updateAssets:k.updateMany,deleteAsset:k.deleteOne,deleteAssets:k.deleteMany}}),{initializeAssets:yn,addAsset:It,addAssets:Rt,updateAsset:Ie,updateAssets:jl,deleteAsset:Ft,deleteAssets:An,setAsset:Pl,setAssets:ql}=_t.actions,Ot=t=>t.assetReducer.instances,gn=u.createSelector([Ot],t=>S(Object.values(t))),vt=g(u.createSelector([gn,(t,e)=>e],(t,e)=>S(t.filter(s=>s.asset_type===e)))),wt=t=>e=>e.assetReducer.instances[t],kl=g(u.createSelector([Ot,(t,e)=>e],(t,e)=>{const s=[];for(const n of e){const a=t[n];a&&s.push(a)}return S(s)})),Dl=t=>e=>vt(t)(e).length,Sn=_t.reducer,ie=I(t=>t.offline_id),Tn=ie.getInitialState({}),Et=u.createSlice({name:"assetStageCompletions",initialState:Tn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Tn)),reducers:{initializeAssetStageCompletions:ie.initialize,addAssetStageCompletion:ie.addOne,addAssetStageCompletions:ie.addMany,updateAssetStageCompletion:ie.updateOne,updateAssetStageCompletions:ie.updateMany,deleteAssetStageCompletion:ie.deleteOne,deleteAssetStageCompletions:ie.deleteMany}}),{initializeAssetStageCompletions:bn,addAssetStageCompletion:jt,addAssetStageCompletions:Pt,updateAssetStageCompletion:_n,updateAssetStageCompletions:In,deleteAssetStageCompletion:qt,deleteAssetStageCompletions:kt}=Et.actions,Dt=t=>t.assetStageCompletionReducer.instances,Cl=u.createSelector([Dt],t=>{const e={};for(const s of Object.values(t)){const{asset:n,stage:a,submitted_at:c}=s;e[n]||(e[n]={}),e[n][a]=c}return ae(e)}),Rn=t=>e=>e.assetStageCompletionReducer.instances[t],Fn=g(u.createSelector([Dt,(t,e)=>e],(t,e)=>{const s=new Set(e);return S(Object.values(t).filter(n=>s.has(n.offline_id)))})),On=Et.reducer,D=I(t=>t.offline_id),vn=D.getInitialState({}),Ct=u.createSlice({name:"assetStages",initialState:vn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,vn)),reducers:{initializeAssetStages:D.initialize,setAssetStage:D.setOne,setAssetStages:D.setMany,addAssetStage:D.addOne,addAssetStages:D.addMany,updateAssetStage:D.updateOne,updateAssetStages:D.updateMany,deleteAssetStage:D.deleteOne,deleteAssetStages:D.deleteMany}}),{initializeAssetStages:wn,setAssetStage:En,setAssetStages:Ml,addAssetStage:zl,addAssetStages:Ce,updateAssetStage:Mt,updateAssetStages:Me,deleteAssetStage:Ul,deleteAssetStages:ze}=Ct.actions,jn=Ct.reducer,Ue=t=>t.assetStageReducer.instances,Pn=t=>e=>e.assetStageReducer.instances[t],qn=u.createSelector([Ue],t=>Object.values(t)),Vl=g(u.createSelector([Ue,(t,e)=>e],(t,e)=>{const s={};for(const[n,a]of Object.entries(t))a.asset_type===e&&(s[n]=a);return ae(s)})),kn=g(u.createSelector([qn,(t,e)=>e],(t,e)=>S(t.filter(s=>s.asset_type===e).sort((s,n)=>s.priority-n.priority)))),zt=g(u.createSelector([Ue,(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 S(s)})),C=I(t=>t.offline_id),Dn=C.getInitialState({}),Ut=u.createSlice({name:"assetTypeAttachments",initialState:Dn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Dn)),reducers:{initializeAssetTypeAttachments:C.initialize,addAssetTypeAttachment:C.addOne,addAssetTypeAttachments:C.addMany,setAssetTypeAttachment:C.setOne,setAssetTypeAttachments:C.setMany,updateAssetTypeAttachment:C.updateOne,updateAssetTypeAttachments:C.updateMany,deleteAssetTypeAttachment:C.deleteOne,deleteAssetTypeAttachments:C.deleteMany}}),{initializeAssetTypeAttachments:Cn,addAssetTypeAttachment:$l,addAssetTypeAttachments:Vt,setAssetTypeAttachment:Mn,setAssetTypeAttachments:Bl,updateAssetTypeAttachment:Gl,updateAssetTypeAttachments:zn,deleteAssetTypeAttachment:Un,deleteAssetTypeAttachments:$t}=Ut.actions,Vn=t=>t.assetTypeAttachmentReducer.instances,Bt=u.createSelector([Vn],t=>Object.values(t)),$n=t=>e=>e.assetTypeAttachmentReducer.instances[t],Bn=g(u.createSelector([Bt,(t,e)=>e],(t,e)=>S(t.filter(({asset_type:s})=>e===s)))),Ll=g(u.createSelector([Bt,(t,e)=>e],(t,e)=>{const s=t.filter(({asset_type:c})=>c===e),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),Gn=Ut.reducer,M=I(t=>t.offline_id),Ln=M.getInitialState({}),Gt=u.createSlice({name:"assetTypeFieldsAttachments",initialState:Ln,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ln)),reducers:{initializeAssetTypeFieldsAttachments:M.initialize,addAssetTypeFieldsAttachment:M.addOne,addAssetTypeFieldsAttachments:M.addMany,setAssetTypeFieldsAttachment:M.setOne,setAssetTypeFieldsAttachments:M.setMany,updateAssetTypeFieldsAttachment:M.updateOne,updateAssetTypeFieldsAttachments:M.updateMany,deleteAssetTypeFieldsAttachment:M.deleteOne,deleteAssetTypeFieldsAttachments:M.deleteMany}}),{initializeAssetTypeFieldsAttachments:Nn,addAssetTypeFieldsAttachment:Nl,addAssetTypeFieldsAttachments:Hn,setAssetTypeFieldsAttachment:Hl,setAssetTypeFieldsAttachments:Wl,updateAssetTypeFieldsAttachment:Yl,updateAssetTypeFieldsAttachments:Wn,deleteAssetTypeFieldsAttachment:Kl,deleteAssetTypeFieldsAttachments:Yn}=Gt.actions,Kn=t=>t.assetTypeFieldsAttachmentReducer.instances,Jn=u.createSelector([Kn],t=>Object.values(t)),Jl=g(u.createSelector([Jn,(t,e)=>e],(t,e)=>S(t.filter(s=>s.fields_revision===e)))),Xl=t=>e=>e.assetTypeFieldsAttachmentReducer.instances[t],Xn=Gt.reducer,z=I(t=>t.offline_id),Zn=z.getInitialState({}),Lt=u.createSlice({name:"assetTypeFields",initialState:Zn,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Zn)),reducers:{initializeAssetTypeFields:z.initialize,addAssetTypeFields:z.addOne,addAssetTypeFieldsMany:z.addMany,setAssetTypeFields:z.setOne,setAssetTypeFieldsMany:z.setMany,updateAssetTypeFields:z.updateOne,updateAssetTypeFieldsMany:z.updateMany,deleteAssetTypeFields:z.deleteOne,deleteAssetTypeFieldsMany:z.deleteMany}}),{initializeAssetTypeFields:Qn,addAssetTypeFields:xn,addAssetTypeFieldsMany:Zl,setAssetTypeFields:Ql,setAssetTypeFieldsMany:xl,updateAssetTypeFields:ea,updateAssetTypeFieldsMany:eu,deleteAssetTypeFields:ta,deleteAssetTypeFieldsMany:tu}=Lt.actions,sa=t=>t.assetTypeFieldsReducer.instances,Ve=u.createSelector([sa],t=>Object.values(t)),su=g(u.createSelector([Ve,(t,e)=>e],(t,e)=>S(t.filter(s=>s.asset_type===e)))),iu=g(u.createSelector([Ve,(t,e)=>e],(t,e)=>t.filter(s=>s.asset_type===e).sort((s,n)=>s.submitted_at>n.submitted_at?-1:1)[0])),nu=t=>e=>e.assetTypeFieldsReducer.instances[t],ia=Lt.reducer,U=I(t=>t.offline_id),na=U.getInitialState({}),Nt=u.createSlice({name:"assetTypeFieldValuesAttachments",initialState:na,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,na)),reducers:{initializeAssetTypeFieldValuesAttachments:U.initialize,addAssetTypeFieldValuesAttachment:U.addOne,addAssetTypeFieldValuesAttachments:U.addMany,setAssetTypeFieldValuesAttachment:U.setOne,setAssetTypeFieldValuesAttachments:U.setMany,updateAssetTypeFieldValuesAttachment:U.updateOne,updateAssetTypeFieldValuesAttachments:U.updateMany,deleteAssetTypeFieldValuesAttachment:U.deleteOne,deleteAssetTypeFieldValuesAttachments:U.deleteMany}}),{initializeAssetTypeFieldValuesAttachments:aa,addAssetTypeFieldValuesAttachment:au,addAssetTypeFieldValuesAttachments:$e,setAssetTypeFieldValuesAttachment:cu,setAssetTypeFieldValuesAttachments:ou,updateAssetTypeFieldValuesAttachment:ru,updateAssetTypeFieldValuesAttachments:ca,deleteAssetTypeFieldValuesAttachment:du,deleteAssetTypeFieldValuesAttachments:Be}=Nt.actions,Ht=t=>t.assetTypeFieldValuesAttachmentReducer.instances,oa=u.createSelector([Ht],t=>Object.values(t)),lu=t=>e=>e.assetTypeFieldValuesAttachmentReducer.instances[t],ra=g(u.createSelector([Ht,(t,e)=>e],(t,e)=>{const s=new Set(e);return S(Object.values(t).filter(n=>s.has(n.offline_id)))})),da=g(u.createSelector([oa,(t,e)=>e],(t,e)=>S(t.filter(s=>s.field_values===e)))),la=Nt.reducer,V=I(t=>t.offline_id),ua=V.getInitialState({}),Wt=u.createSlice({name:"assetTypeFieldValues",initialState:ua,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ua)),reducers:{initializeAssetTypeFieldValues:V.initialize,addAssetTypeFieldValues:V.addOne,addAssetTypeFieldValuesMany:V.addMany,setAssetTypeFieldValues:V.setOne,setAssetTypeFieldValuesMany:V.setMany,updateAssetTypeFieldValues:V.updateOne,updateAssetTypeFieldValuesMany:V.updateMany,deleteAssetTypeFieldValues:V.deleteOne,deleteAssetTypeFieldValuesMany:V.deleteMany}}),{initializeAssetTypeFieldValues:ha,addAssetTypeFieldValues:Yt,addAssetTypeFieldValuesMany:ma,setAssetTypeFieldValues:uu,setAssetTypeFieldValuesMany:hu,updateAssetTypeFieldValues:Re,updateAssetTypeFieldValuesMany:fa,deleteAssetTypeFieldValues:Kt,deleteAssetTypeFieldValuesMany:pa}=Wt.actions,ya=t=>t.assetTypeFieldValuesReducer.instances,Jt=u.createSelector([ya],t=>Object.values(t)),mu=g(u.createSelector([Jt,(t,e)=>e],(t,e)=>S(t.filter(s=>s.asset===e)))),fu=g(u.createSelector([Ve,Jt,(t,e)=>e],(t,e,s)=>{const n=new Set(t.filter(a=>a.asset_type===s).map(a=>a.offline_id));return S(e.filter(a=>n.has(a.fields_revision)))})),Xt=t=>e=>e.assetTypeFieldValuesReducer.instances[t],Aa=Wt.reducer,$=I(t=>t.offline_id),ga=$.getInitialState({}),Zt=u.createSlice({name:"assetTypes",initialState:ga,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ga)),reducers:{initializeAssetTypes:$.initialize,setAssetType:$.setOne,setAssetTypes:$.setMany,addAssetType:$.addOne,addAssetTypes:$.addMany,updateAssetType:$.updateOne,updateAssetTypes:$.updateMany,deleteAssetType:$.deleteOne,deleteAssetTypes:$.deleteMany}}),{initializeAssetTypes:Sa,setAssetType:pu,setAssetTypes:yu,addAssetType:Qt,addAssetTypes:Au,updateAssetType:Fe,updateAssetTypes:gu,deleteAssetType:xt,deleteAssetTypes:Su}=Zt.actions,es=t=>t.assetTypeReducer.instances,Tu=u.createSelector([es],t=>Object.values(t)),ts=t=>e=>e.assetTypeReducer.instances[t],bu=g(u.createSelector([es,(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 S(s)})),Ta=Zt.reducer,ba={accessToken:"",refreshToken:"",isLoggedIn:!1},Ge=u.createSlice({name:"auth",initialState:ba,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ba)),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||Ge.caseReducers.clearTokens(t),t.isLoggedIn=e.payload}}}),{setTokens:_u,clearTokens:Iu,setLoggedIn:_a}=Ge.actions,Ru=t=>t.authReducer.accessToken,Fu=t=>t.authReducer.isLoggedIn,Ia=Ge.reducer,Oe=I(t=>t.offline_id),Ra=Oe.getInitialState({}),ss=u.createSlice({name:"categories",initialState:Ra,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ra)),reducers:{initializeCategories:Oe.initialize,addCategory:Oe.addOne,updateCategory:Oe.updateOne,deleteCategory:Oe.deleteOne}}),{initializeCategories:Fa,addCategory:is,updateCategory:Oa,deleteCategory:va}=ss.actions,ns=t=>t.categoryReducer.instances,Ou=u.createSelector([ns],t=>Object.values(t)),as=t=>e=>e.categoryReducer.instances[t],vu=g(u.createSelector([ns,(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 S(s)})),wu=t=>e=>Object.values(e.issueReducer.instances).filter(s=>s.category===t).length,wa=ss.reducer,B=I(t=>t.offline_id),Ea=B.getInitialState({}),cs=u.createSlice({name:"documentAttachments",initialState:Ea,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Ea)),reducers:{initializeDocumentAttachments:B.initialize,addDocumentAttachment:B.addOne,addDocumentAttachments:B.addMany,setDocumentAttachment:B.setOne,setDocumentAttachments:B.setMany,updateDocumentAttachment:B.updateOne,updateDocumentAttachments:B.updateMany,deleteDocumentAttachment:B.deleteOne,deleteDocumentAttachments:B.deleteMany}}),{initializeDocumentAttachments:ja,addDocumentAttachment:Eu,addDocumentAttachments:Pa,setDocumentAttachment:qa,setDocumentAttachments:ju,updateDocumentAttachment:Pu,updateDocumentAttachments:ka,deleteDocumentAttachment:Da,deleteDocumentAttachments:Ca}=cs.actions,Ma=t=>t.documentAttachmentReducer.instances,os=u.createSelector([Ma],t=>Object.values(t)),za=t=>e=>e.documentAttachmentReducer.instances[t],qu=g(u.createSelector([os,(t,e)=>e],(t,e)=>S(t.filter(({document:s})=>e===s)))),ku=g(u.createSelector([os,(t,e)=>e],(t,e)=>{const s=t.filter(({document:c})=>e===c),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),Ua=cs.reducer,Va={documents:{}},rs=u.createSlice({name:"documents",initialState:Va,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,Va)}),reducers:{setDocuments:(t,e)=>{if(e.payload.filter(xi).length!==e.payload.length)throw new Error("Tried to use setIssues reducer with duplicate ID's");t.documents=Qi(e.payload)},addDocuments:(t,e)=>{for(const s of e.payload)if(s.offline_id in t.documents)throw new Error(`attempting to add a document with offline_id ${s.offline_id} 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.offline_id]}}t.documents[s.offline_id]=s}},updateDocuments:(t,e)=>{for(const s of e.payload)if(!(s.offline_id in t.documents))throw new Error(`attempting to update a document with offline_id ${s.offline_id} which doesn't exists in state.documents.`);for(const s of e.payload){const n=t.documents[s.offline_id];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.offline_id]={...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 offline_id ${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:o}=t.documents[c.parent_document];t.documents[c.parent_document].children_documents.splice(o.indexOf(c.offline_id),1)}if(n){const o=t.documents[n],d=o!=null&&o.parent_document?t.documents[o.parent_document]:null;switch(a){case"left":if(!d)throw new Error("attempting to move a document to the left of a document with no parent_document");t.documents[o.parent_document].children_documents.splice(d.children_documents.indexOf(o.offline_id),0,c.offline_id),t.documents[s].parent_document=d.offline_id;break;case"right":if(!d)throw new Error("attempting to move a document to the left of a document with no parent_document");t.documents[o.parent_document].children_documents.splice(d.children_documents.indexOf(o.offline_id)+1,0,c.offline_id),t.documents[s].parent_document=d.offline_id;break;case"left-child":if(!o)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.offline_id),t.documents[s].parent_document=o.offline_id;break;case"right-child":if(!o)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.offline_id),t.documents[s].parent_document=o.offline_id}}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 offline_id ${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.offline_id)}}delete t.documents[s]}}}}),{setDocuments:$a,addDocuments:Ba,updateDocuments:ne,moveDocument:Ga,removeDocuments:ds}=rs.actions,pe=t=>t.documentsReducer.documents,La=u.createSelector([pe],t=>Object.values(t)),Na=t=>e=>e.documentsReducer.documents[t],Du=g(u.createSelector([pe,(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 S(s)})),Cu=g(u.createSelector([pe,(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.offline_id),a=t[a.parent_document??""];return S(s)})),Mu=u.createSelector([La],t=>S(t.filter(e=>!e.parent_document))),Ha=rs.reducer,Le=I(t=>t.offline_id),zu=Le.getInitialState({}),ls=u.createSlice({name:"emailDomains",initialState:zu,reducers:{initializeEmailDomains:Le.initialize,addEmailDomain:Le.addOne,deleteEmailDomain:Le.deleteOne}}),{initializeEmailDomains:Wa,addEmailDomain:Ya,deleteEmailDomain:Ka}=ls.actions,Ja=t=>t.emailDomainsReducer.instances,Xa=u.createSelector([Ja],t=>Object.values(t)),Uu=g(u.createSelector([Xa,(t,e)=>e],(t,e)=>S(t.filter(s=>s.organization===e)))),Za=ls.reducer,Qa={s3Urls:{}},xa=1e3*60*60,Vu=xa*24*7,us=u.createSlice({name:"file",initialState:Qa,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Qa)),reducers:{setUploadUrl:(t,e)=>{const{url:s,fields:n,sha1:a}=e.payload,c=new Date,o=new Date(c.getTime()+Vu);t.s3Urls[a]={url:s,fields:n,exp:o.getTime()}}}}),{setUploadUrl:ec}=us.actions,tc=t=>e=>{const s=e.fileReducer.s3Urls[t];if(!s)return;const n=new Date().getTime();if(!((s.exp??n)-n<xa))return s},sc=us.reducer,G=I(t=>t.offline_id),ic=G.getInitialState({}),hs=u.createSlice({name:"formRevisionAttachments",initialState:ic,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,ic)),reducers:{initializeFormRevisionAttachments:G.initialize,addFormRevisionAttachment:G.addOne,addFormRevisionAttachments:G.addMany,setFormRevisionAttachment:G.setOne,setFormRevisionAttachments:G.setMany,updateFormRevisionAttachment:G.updateOne,updateFormRevisionAttachments:G.updateMany,deleteFormRevisionAttachment:G.deleteOne,deleteFormRevisionAttachments:G.deleteMany}}),{initializeFormRevisionAttachments:nc,addFormRevisionAttachment:$u,addFormRevisionAttachments:ac,setFormRevisionAttachment:Bu,setFormRevisionAttachments:Gu,updateFormRevisionAttachment:Lu,updateFormRevisionAttachments:cc,deleteFormRevisionAttachment:Nu,deleteFormRevisionAttachments:oc}=hs.actions,rc=t=>t.formRevisionAttachmentReducer.instances,Hu=g(u.createSelector([rc,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.form_revision===e)))),dc=hs.reducer,Wu=(t,e)=>{const s=t.revision,n=e.revision;return s==="Pending"&&n==="Pending"?t.submitted_at<e.submitted_at?-1:1:s==="Pending"?1:n==="Pending"||s<n?-1:1},ce=I(t=>t.offline_id),lc=ce.getInitialState({}),ms=u.createSlice({name:"formRevisions",initialState:lc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,lc)),reducers:{initializeFormRevisions:ce.initialize,setFormRevision:ce.setOne,addFormRevision:ce.addOne,addFormRevisions:ce.addMany,deleteFormRevision:ce.deleteOne,deleteFormRevisions:ce.deleteMany}}),{setFormRevision:uc,initializeFormRevisions:hc,addFormRevision:fs,addFormRevisions:mc,deleteFormRevision:ps,deleteFormRevisions:fc}=ms.actions,Ne=t=>t.formRevisionReducer.instances,pc=u.createSelector([Ne],t=>Object.values(t)),Yu=t=>e=>e.formRevisionReducer.instances[t],yc=(t,e)=>{let s=null;for(const n of Object.values(t))n.form===e&&(!s||s.revision<n.revision)&&(s=n);if(!s)throw new Error("No form revision found for form "+e);return s},Ku=g(u.createSelector([Ne,(t,e)=>e],(t,e)=>{const s=Object.values(t).filter(c=>c.form===e);if(s.length===0)return;const a=s.sort(Wu)[s.length-1];return t[a.offline_id]})),Ac=g(u.createSelector([pc,(t,e)=>e],(t,e)=>S(t.filter(s=>s.form===e)))),gc=ms.reducer,oe=I(t=>t.offline_id),Sc=oe.getInitialState({}),ys=u.createSlice({name:"forms",initialState:Sc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Sc)),reducers:{initializeForms:oe.initialize,setForm:oe.setOne,addForm:oe.addOne,addForms:oe.addMany,updateForm:oe.updateOne,deleteForm:oe.deleteOne}}),{initializeForms:Tc,setForm:Ju,addForm:As,addForms:Xu,updateForm:Zu,deleteForm:gs}=ys.actions,bc=ys.reducer,_c=t=>t.formReducer.instances,Qu=u.createSelector([_c],t=>Object.values(t)),Ic=t=>e=>e.formReducer.instances[t],xu=g(u.createSelector([t=>t.formReducer.instances,t=>t.formRevisionReducer.instances,(t,e)=>e],(t,e,s)=>{const{searchTerm:n,maxResults:a,organization:c}=s,o=[];for(const[d,m]of Object.entries(t)){if(Number.isInteger(c)&&c!==m.organization)continue;yc(e,d).title.toLowerCase().includes(n.toLowerCase())&&o.push(m)}return[...o.slice(0,a)]},{memoizeOptions:{resultEqualityCheck:Yi}})),L=I(t=>t.offline_id),Rc=L.getInitialState({}),Ss=u.createSlice({name:"formSubmissionAttachments",initialState:Rc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Rc)),reducers:{initializeFormSubmissionAttachments:L.initialize,addFormSubmissionAttachment:L.addOne,addFormSubmissionAttachments:L.addMany,setFormSubmissionAttachment:L.setOne,setFormSubmissionAttachments:L.setMany,updateFormSubmissionAttachment:L.updateOne,updateFormSubmissionAttachments:L.updateMany,deleteFormSubmissionAttachment:L.deleteOne,deleteFormSubmissionAttachments:L.deleteMany}}),{initializeFormSubmissionAttachments:Fc,addFormSubmissionAttachment:eh,addFormSubmissionAttachments:He,setFormSubmissionAttachment:th,setFormSubmissionAttachments:sh,updateFormSubmissionAttachment:ih,updateFormSubmissionAttachments:Oc,deleteFormSubmissionAttachment:nh,deleteFormSubmissionAttachments:We}=Ss.actions,Ts=t=>t.formSubmissionAttachmentReducer.instances,vc=g(u.createSelector([Ts,(t,e)=>e],(t,e)=>{const s=new Set(e);return S(Object.values(t).filter(n=>s.has(n.offline_id)))})),wc=g(u.createSelector([Ts,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.form_submission===e)))),Ec=Ss.reducer,N=I(t=>t.offline_id),jc=N.getInitialState({}),bs=u.createSlice({name:"formSubmissions",initialState:jc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,jc)),reducers:{initializeFormSubmissions:N.initialize,setFormSubmission:N.setOne,setFormSubmissions:N.setMany,addFormSubmission:N.addOne,addFormSubmissions:N.addMany,updateFormSubmission:N.updateOne,updateFormSubmissions:N.updateMany,deleteFormSubmission:N.deleteOne,deleteFormSubmissions:N.deleteMany}}),{initializeFormSubmissions:Pc,setFormSubmission:Ye,setFormSubmissions:ah,addFormSubmission:_s,addFormSubmissions:Ke,updateFormSubmission:qc,updateFormSubmissions:ch,deleteFormSubmission:Is,deleteFormSubmissions:Je}=bs.actions,Rs=t=>t.formSubmissionReducer.instances,Fs=u.createSelector([Rs],t=>Object.values(t)),Os=t=>e=>e.formSubmissionReducer.instances[t],kc=g(u.createSelector([Rs,Ne,(t,e)=>e],(t,e,s)=>{const n=new Set;for(const a of Object.values(e))a.form===s&&n.add(a.offline_id);return Object.values(t).filter(a=>n.has(a.form_revision))})),Dc=g(u.createSelector([Fs,(t,e)=>e],(t,e)=>Object.values(t).filter(s=>s.issue===e))),Cc=g(u.createSelector([Fs,(t,e)=>e],(t,e)=>t.filter(s=>s.asset===e))),Mc=bs.reducer,H=I(t=>t.offline_id),zc=H.getInitialState({}),vs=u.createSlice({name:"geoImages",initialState:zc,extraReducers:t=>{t.addCase("RESET",e=>{Object.assign(e,zc)})},reducers:{initializeGeoImages:H.initialize,setGeoImage:H.setOne,setGeoImages:H.setMany,addGeoImage:H.addOne,addGeoImages:H.addMany,updateGeoImage:H.updateOne,updateGeoImages:H.updateMany,deleteGeoImage:H.deleteOne,deleteGeoImages:H.deleteMany}}),{initializeGeoImages:Uc,setGeoImage:ve,setGeoImages:Vc,addGeoImage:$c,addGeoImages:Bc,updateGeoImage:Gc,updateGeoImages:oh,deleteGeoImage:ws,deleteGeoImages:Lc}=vs.actions,Nc=t=>t.geoImageReducer.instances,Hc=u.createSelector([Nc],t=>Object.values(t)),Es=t=>e=>e.geoImageReducer.instances[t],rh=g(u.createSelector([Hc,(t,e)=>e],(t,e)=>S(t.filter(s=>s.project===e)))),Wc=vs.reducer,W=I(t=>t.offline_id),Yc=W.getInitialState({}),js=u.createSlice({name:"issueAssociations",initialState:Yc,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Yc)),reducers:{initializeIssueAssociations:W.initialize,addIssueAssociation:W.addOne,addIssueAssociations:W.addMany,setIssueAssociation:W.setOne,setIssueAssociations:W.setMany,updateIssueAssociation:W.updateOne,updateIssueAssociations:W.updateMany,deleteIssueAssociation:W.deleteOne,deleteIssueAssociations:W.deleteMany}}),{initializeIssueAssociations:Kc,setIssueAssociations:dh,setIssueAssociation:lh,updateIssueAssociation:Jc,updateIssueAssociations:uh,addIssueAssociation:Ps,addIssueAssociations:qs,deleteIssueAssociation:ks,deleteIssueAssociations:Ds}=js.actions,we=t=>t.issueAssociationReducer.instances,hh=u.createSelector([we],t=>Object.values(t)),Xc=t=>e=>e.issueAssociationReducer.instances[t],Zc=g(u.createSelector([we,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.associated_issue===e)))),Qc=g(u.createSelector([we,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.issue===e)))),xc=g(u.createSelector([we,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.asset===e)))),eo=js.reducer,Y=I(t=>t.offline_id),to=Y.getInitialState({}),Cs=u.createSlice({name:"issueAttachments",initialState:to,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,to)),reducers:{initializeIssueAttachments:Y.initialize,addIssueAttachment:Y.addOne,addIssueAttachments:Y.addMany,setIssueAttachment:Y.setOne,setIssueAttachments:Y.setMany,updateIssueAttachment:Y.updateOne,updateIssueAttachments:Y.updateMany,deleteIssueAttachment:Y.deleteOne,deleteIssueAttachments:Y.deleteMany}}),{initializeIssueAttachments:so,addIssueAttachment:mh,addIssueAttachments:Ms,setIssueAttachment:io,setIssueAttachments:fh,updateIssueAttachment:ph,updateIssueAttachments:no,deleteIssueAttachment:ao,deleteIssueAttachments:zs}=Cs.actions,co=t=>t.issueAttachmentReducer.instances,Us=u.createSelector([co],t=>Object.values(t)),oo=g(u.createSelector([Us,(t,e)=>e],(t,e)=>S(t.filter(({issue:s})=>e===s)))),ro=t=>e=>e.issueAttachmentReducer.instances[t],yh=g(u.createSelector([Us,(t,e)=>e],(t,e)=>{const s=t.filter(({issue:c})=>c===e),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),lo=Cs.reducer,re=I(t=>t.offline_id),uo=re.getInitialState({}),Vs=u.createSlice({name:"issueComments",initialState:uo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,uo)),reducers:{addIssueComment:re.addOne,addIssueComments:re.addMany,setIssueComment:re.setOne,setIssueComments:re.setMany,deleteIssueComment:re.deleteOne,deleteIssueComments:re.deleteMany}}),{setIssueComments:ho,setIssueComment:$s,addIssueComment:Bs,addIssueComments:Ah,deleteIssueComment:Gs,deleteIssueComments:gh}=Vs.actions,mo=t=>t.issueCommentReducer.instances,fo=t=>e=>e.issueCommentReducer.instances[t],Sh=g(u.createSelector([mo,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.issue===e)))),po=Vs.reducer,de=I(t=>t.offline_id),yo=de.getInitialState({}),Ls=u.createSlice({name:"issues",initialState:yo,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,yo)}),reducers:{initializeIssues:de.initialize,addIssue:de.addOne,addIssues:de.addMany,updateIssue:de.updateOne,deleteIssue:de.deleteOne,deleteIssues:de.deleteMany}}),{initializeIssues:Ao,addIssue:Ns,addIssues:go,updateIssue:Xe,deleteIssue:Hs,deleteIssues:So}=Ls.actions,To=t=>t.issueReducer.instances,Ws=t=>e=>e.issueReducer.instances[t],Th=g(u.createSelector([To,(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 S(s)})),bo=Ls.reducer,K=I(t=>t.offline_id),_o=K.getInitialState({}),Ys=u.createSlice({name:"issueTypeFieldsAttachments",initialState:_o,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,_o)),reducers:{initializeIssueTypeFieldsAttachments:K.initialize,addIssueTypeFieldsAttachment:K.addOne,addIssueTypeFieldsAttachments:K.addMany,setIssueTypeFieldsAttachment:K.setOne,setIssueTypeFieldsAttachments:K.setMany,updateIssueTypeFieldsAttachment:K.updateOne,updateIssueTypeFieldsAttachments:K.updateMany,deleteIssueTypeFieldsAttachment:K.deleteOne,deleteIssueTypeFieldsAttachments:K.deleteMany}}),{initializeIssueTypeFieldsAttachments:Io,addIssueTypeFieldsAttachment:bh,addIssueTypeFieldsAttachments:Ro,setIssueTypeFieldsAttachment:_h,setIssueTypeFieldsAttachments:Ih,updateIssueTypeFieldsAttachment:Rh,updateIssueTypeFieldsAttachments:Fo,deleteIssueTypeFieldsAttachment:Fh,deleteIssueTypeFieldsAttachments:Oo}=Ys.actions,vo=t=>t.issueTypeFieldsAttachmentReducer.instances,wo=u.createSelector([vo],t=>Object.values(t)),Oh=g(u.createSelector([wo,(t,e)=>e],(t,e)=>S(t.filter(s=>s.fields_revision===e)))),vh=t=>e=>e.issueTypeFieldsAttachmentReducer.instances[t],Eo=Ys.reducer,J=I(t=>t.offline_id),jo=J.getInitialState({}),Ks=u.createSlice({name:"issueTypeFieldValues",initialState:jo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,jo)),reducers:{initializeIssueTypeFieldValues:J.initialize,addIssueTypeFieldValues:J.addOne,addIssueTypeFieldValuesMany:J.addMany,setIssueTypeFieldValues:J.setOne,setIssueTypeFieldValuesMany:J.setMany,updateIssueTypeFieldValues:J.updateOne,updateIssueTypeFieldValuesMany:J.updateMany,deleteIssueTypeFieldValues:J.deleteOne,deleteIssueTypeFieldValuesMany:J.deleteMany}}),{initializeIssueTypeFieldValues:Po,addIssueTypeFieldValues:Js,addIssueTypeFieldValuesMany:wh,setIssueTypeFieldValues:Eh,setIssueTypeFieldValuesMany:jh,updateIssueTypeFieldValues:Ee,updateIssueTypeFieldValuesMany:Ph,deleteIssueTypeFieldValues:Xs,deleteIssueTypeFieldValuesMany:qh}=Ks.actions,qo=t=>t.issueTypeFieldValuesReducer.instances,Zs=u.createSelector([qo],t=>Object.values(t)),kh=g(u.createSelector([Zs,(t,e)=>e],(t,e)=>S(t.filter(s=>s.issue===e)))),Qs=t=>e=>e.issueTypeFieldValuesReducer.instances[t],ko=Ks.reducer,X=I(t=>t.offline_id),Do=X.getInitialState({}),xs=u.createSlice({name:"issueTypeFields",initialState:Do,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Do)),reducers:{initializeIssueTypeFields:X.initialize,addIssueTypeFields:X.addOne,addIssueTypeFieldsMany:X.addMany,setIssueTypeFields:X.setOne,setIssueTypeFieldsMany:X.setMany,updateIssueTypeFields:X.updateOne,updateIssueTypeFieldsMany:X.updateMany,deleteIssueTypeFields:X.deleteOne,deleteIssueTypeFieldsMany:X.deleteMany}}),{initializeIssueTypeFields:Co,addIssueTypeFields:Mo,addIssueTypeFieldsMany:Dh,setIssueTypeFields:Ch,setIssueTypeFieldsMany:Mh,updateIssueTypeFields:zo,updateIssueTypeFieldsMany:zh,deleteIssueTypeFields:Uo,deleteIssueTypeFieldsMany:Uh}=xs.actions,Vo=t=>t.issueTypeFieldsReducer.instances,Ze=u.createSelector([Vo],t=>Object.values(t)),Vh=g(u.createSelector([Ze,(t,e)=>e],(t,e)=>S(t.filter(s=>s.issue_type===e)))),$h=g(u.createSelector([Ze,(t,e)=>e],(t,e)=>t.filter(s=>s.issue_type===e).sort((s,n)=>s.submitted_at>n.submitted_at?-1:1)[0])),Bh=g(u.createSelector([Ze,Zs,(t,e)=>e],(t,e,s)=>{const n=new Set(t.filter(a=>a.issue_type===s).map(a=>a.offline_id));return S(e.filter(a=>n.has(a.fields_revision)))})),Gh=t=>e=>e.issueTypeFieldsReducer.instances[t],$o=xs.reducer,Z=I(t=>t.offline_id),Bo=Z.getInitialState({}),ei=u.createSlice({name:"issueTypeFieldValuesAttachments",initialState:Bo,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Bo)),reducers:{initializeIssueTypeFieldValuesAttachments:Z.initialize,addIssueTypeFieldValuesAttachment:Z.addOne,addIssueTypeFieldValuesAttachments:Z.addMany,setIssueTypeFieldValuesAttachment:Z.setOne,setIssueTypeFieldValuesAttachments:Z.setMany,updateIssueTypeFieldValuesAttachment:Z.updateOne,updateIssueTypeFieldValuesAttachments:Z.updateMany,deleteIssueTypeFieldValuesAttachment:Z.deleteOne,deleteIssueTypeFieldValuesAttachments:Z.deleteMany}}),{initializeIssueTypeFieldValuesAttachments:Go,addIssueTypeFieldValuesAttachment:Lh,addIssueTypeFieldValuesAttachments:Qe,setIssueTypeFieldValuesAttachment:Nh,setIssueTypeFieldValuesAttachments:Hh,updateIssueTypeFieldValuesAttachment:Wh,updateIssueTypeFieldValuesAttachments:Lo,deleteIssueTypeFieldValuesAttachment:Yh,deleteIssueTypeFieldValuesAttachments:xe}=ei.actions,ti=t=>t.issueTypeFieldValuesAttachmentReducer.instances,No=u.createSelector([ti],t=>Object.values(t)),Kh=t=>e=>e.issueTypeFieldValuesAttachmentReducer.instances[t],Ho=g(u.createSelector([ti,(t,e)=>e],(t,e)=>{const s=new Set(e);return S(Object.values(t).filter(n=>s.has(n.offline_id)))})),Wo=g(u.createSelector([No,(t,e)=>e],(t,e)=>S(t.filter(s=>s.field_values===e)))),Yo=ei.reducer,ye=I(t=>t.offline_id),Ko=ye.getInitialState({}),si=u.createSlice({name:"issueTypes",initialState:Ko,extraReducers:t=>t.addCase("RESET",e=>{Object.assign(e,Ko)}),reducers:{initializeIssueTypes:ye.initialize,setIssueType:ye.setOne,addIssueType:ye.addOne,updateIssueType:ye.updateOne,removeIssueType:ye.deleteOne}}),{initializeIssueTypes:Jo,setIssueType:je,addIssueType:Xo,updateIssueType:Zo,removeIssueType:ii}=si.actions,Qo=t=>t.issueTypeReducer.instances,xo=u.createSelector(Qo,t=>Object.values(t)),ni=t=>e=>e.issueTypeReducer.instances[t],Jh=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},Xh=g(u.createSelector([xo,(t,e)=>e],(t,e)=>S(t.filter(s=>s.organization===e)))),ai=g(u.createSelector([t=>t.issueReducer.instances,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.issue_type===e)))),Zh=t=>e=>ai(t)(e).length,er=si.reducer,le=I(t=>t.offline_id),tr=le.getInitialState({}),ci=u.createSlice({name:"issueUpdates",initialState:tr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,tr)),reducers:{initializeIssueUpdates:le.setMany,setIssueUpdate:le.setOne,addIssueUpdate:le.addOne,addIssueUpdates:le.addMany,deleteIssueUpdate:le.deleteOne,deleteIssueUpdates:le.deleteMany}}),{initializeIssueUpdates:sr,setIssueUpdate:Qh,addIssueUpdate:ir,addIssueUpdates:nr,deleteIssueUpdate:ar,deleteIssueUpdates:cr}=ci.actions,or=t=>t.issueUpdateReducer.instances,rr=g(u.createSelector([or,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.issue===e)))),dr=ci.reducer,et=I(t=>t.offline_id),lr=et.getInitialState({}),oi=u.createSlice({name:"license",initialState:lr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,lr)),reducers:{initializeLicences:et.initialize,addLicenses:et.addMany,updateLicense:et.updateOne}}),{initializeLicences:ur,addLicenses:xh,updateLicense:te}=oi.actions,tt=t=>t.licenseReducer.instances,em=t=>e=>e.licenseReducer.instances[t],hr=t=>e=>Object.values(e.licenseReducer.instances).find(s=>s.project===t),tm=u.createSelector([tt],t=>S(Object.values(t).filter(e=>e.is_active))),sm=u.createSelector([tt],t=>ae(Object.values(t).filter(e=>e.project).reduce((e,s)=>({...e,[s.project]:s}),{}))),mr=oi.reducer,fr={users:{},currentUser:null},ri=u.createSlice({name:"users",initialState:fr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,fr)),reducers:{setUsers:(t,e)=>{const s={};e.payload.forEach(n=>{s[n.id]=n}),t.users=s},addUsers:(t,e)=>{for(const s of e.payload)t.users[s.id]=s},setCurrentUser:(t,e)=>{t.currentUser=e.payload},setProfilePicture:(t,e)=>{if(!t.currentUser)return;t.currentUser.profile.file=e.payload.file??null,t.currentUser.profile.file_sha1=e.payload.file_sha1??null;const s=t.users[t.currentUser.id];if(!s)throw new Error("Unable to find current user in users slice");s.profile.file=e.payload.file??null,s.profile.file_sha1=e.payload.file_sha1??null},removeUser:(t,e)=>{delete t.users[e.payload]}}}),{setCurrentUser:im,setProfilePicture:nm,setUsers:pr,addUsers:am,removeUser:yr}=ri.actions,Ar=ri.reducer,st=t=>t.userReducer.currentUser,it=t=>t.userReducer.users,cm=t=>e=>e.userReducer.users[t],om=g(u.createSelector([it,(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 id",n)}return S(s)})),nt=I(t=>t.offline_id),gr=nt.getInitialState({}),di=u.createSlice({name:"organizationAccess",initialState:gr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,gr)),reducers:{initializeOrganizationAccesses:nt.initialize,updateOrganizationAccess:nt.updateOne,deleteOrganizationAccess:nt.deleteOne}}),{initializeOrganizationAccesses:Sr,updateOrganizationAccess:Tr,deleteOrganizationAccess:br}=di.actions,li=t=>t.organizationAccessReducer.instances,rm=t=>e=>e.organizationAccessReducer.instances[t],dm=u.createSelector([st,li],(t,e)=>Object.values(e).find(n=>n.user===(t==null?void 0:t.id))??null),lm=t=>e=>Object.values(e.organizationAccessReducer.instances).find(s=>s.user===t.id),_r=t=>{const e={};for(const s of Object.values(t.organizationAccessReducer.instances))e[s.user]=s;return ae(e)},Ir=di.reducer,Pe=I(t=>t.offline_id),Rr=Pe.getInitialState({}),ui=u.createSlice({name:"projectAccess",initialState:Rr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Rr)),reducers:{initializeProjectAccesses:Pe.initialize,updateProjectAccess:Pe.updateOne,deleteProjectAccess:Pe.deleteOne,deleteProjectAccesses:Pe.deleteMany}}),{initializeProjectAccesses:hi,updateProjectAccess:Fr,deleteProjectAccess:Or,deleteProjectAccesses:vr}=ui.actions,mi=t=>t.projectAccessReducer.instances,wr=u.createSelector(mi,t=>Object.values(t)),um=t=>e=>e.projectAccessReducer.instances[t],hm=t=>e=>Object.values(e.projectAccessReducer.instances).find(s=>s.user===t.id),Er=t=>{const e={};for(const s of Object.values(t.projectAccessReducer.instances))e[s.user]=s;return ae(e)},jr=ui.reducer,Pr={projects:{}},fi=u.createSlice({name:"projects",initialState:Pr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Pr)),reducers:{setProjects:(t,e)=>{const s={};e.payload.forEach(n=>{s[n.id]=n}),t.projects=s},updateProject:(t,e)=>{t.projects[e.payload.id]=e.payload},deleteProject:(t,e)=>{delete t.projects[e.payload.id]},acceptProjectInvite:(t,e)=>{if(e.payload in t.projects)t.projects[e.payload].invited=!1;else throw new Error("Accept project invite: user is not in this project")}}}),{setProjects:qr,updateProject:kr,deleteProject:Dr,acceptProjectInvite:Cr}=fi.actions,Mr=fi.reducer,pi=t=>t.projectReducer.projects,mm=t=>e=>e.projectReducer.projects[t],zr=u.createSelector([mi],t=>Object.values(t).map(e=>e.user)),Ur=u.createSelector([zr,it],(t,e)=>t.reduce((s,n)=>({...s,[n]:e[n]}),{})),fm=u.createSelector([st,Ur,Er],(t,e,s)=>S(Object.values(e).sort((n,a)=>{if(n.id===(t==null?void 0:t.id))return-1;if(a.id===(t==null?void 0:t.id))return 1;const c=s[n.id],o=s[a.id];return(c==null?void 0:c.access_level)===(o==null?void 0:o.access_level)?n.username.localeCompare(a.username):(c==null?void 0:c.access_level)===ot.ADMIN?-1:1}))),Vr={organizations:{}},yi=u.createSlice({name:"organizations",initialState:Vr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Vr)),reducers:{setOrganizations:(t,e)=>{for(const s of e.payload)t.organizations[s.id]=s}}}),{setOrganizations:$r}=yi.actions,Br=t=>t.organizationReducer.organizations,Gr=u.createSelector([Br],t=>Object.values(t)),pm=t=>e=>e.organizationReducer.organizations[t],ym=u.createSelector([Gr],t=>S(Object.values(t).filter(e=>e.has_access))),Lr=u.createSelector([li],t=>Object.values(t).map(e=>e.user)),Am=g(u.createSelector([pi,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.organization_owner===e)))),gm=g(u.createSelector([tt,(t,e)=>e],(t,e)=>S(Object.values(t).filter(s=>s.organization_owner===e)))),Nr=u.createSelector([Lr,it],(t,e)=>ae(t.reduce((s,n)=>({...s,[n]:e[n]}),{}))),Sm=u.createSelector([st,Nr,_r],(t,e,s)=>S(Object.values(e).sort((n,a)=>{if(n.id===(t==null?void 0:t.id))return-1;if(a.id===(t==null?void 0:t.id))return 1;const c=s[n.id],o=s[a.id];return(c==null?void 0:c.access_level)===(o==null?void 0:o.access_level)?n.username.localeCompare(a.username):(c==null?void 0:c.access_level)===rt.ADMIN?-1:1}))),Hr=yi.reducer,Wr=(t,e,s)=>{const n=t.uuid?t:{...t,uuid:O.v4()};return{payload:n,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:n,BASE_URL:e,serviceName:s}}}}},Yr={deletedRequests:[],latestRetryTime:0},Ai=u.createSlice({name:"outbox",initialState:Yr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Yr)),reducers:{enqueueRequest:{reducer:(t,e)=>t,prepare:t=>{console.debug("Preparing to enqueue request",t);const{BASE_URL:e,serviceName:s,...n}=t;return Wr(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}}}),Tm=t=>t.outboxReducer.deletedRequests,bm=t=>t.outboxReducer.latestRetryTime,{enqueueRequest:Kr,markForDeletion:_m,markAsDeleted:Jr,_setLatestRetryTime:Xr}=Ai.actions,Zr=Ai.reducer,Q=I(t=>t.offline_id),Qr=Q.getInitialState({}),gi=u.createSlice({name:"projectAttachments",initialState:Qr,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,Qr)),reducers:{initializeProjectAttachments:Q.initialize,addProjectAttachment:Q.addOne,addProjectAttachments:Q.addMany,setProjectAttachment:Q.setOne,setProjectAttachments:Q.setMany,updateProjectAttachment:Q.updateOne,updateProjectAttachments:Q.updateMany,deleteProjectAttachment:Q.deleteOne,deleteProjectAttachments:Q.deleteMany}}),{initializeProjectAttachments:xr,addProjectAttachment:Im,addProjectAttachments:ed,setProjectAttachment:td,setProjectAttachments:sd,updateProjectAttachment:Rm,updateProjectAttachments:id,deleteProjectAttachment:nd,deleteProjectAttachments:Si}=gi.actions,ad=t=>t.projectAttachmentReducer.instances,Ti=u.createSelector([ad],t=>Object.values(t)),cd=t=>e=>e.projectAttachmentReducer.instances[t],od=g(u.createSelector([Ti,(t,e)=>e],(t,e)=>S(t.filter(({project:s})=>e===s)))),Fm=g(u.createSelector([Ti,(t,e)=>e],(t,e)=>{const s=t.filter(({project:c})=>e===c),n=s.filter(({file_type:c})=>!c.startsWith("image/")),a=s.filter(({file_type:c})=>c.startsWith("image/"));return{fileAttachments:n,imageAttachments:a}})),rd=gi.reducer,x=I(t=>t.offline_id),dd=x.getInitialState({activeProjectFileId:null,isImportingProjectFile:!1}),bi=u.createSlice({name:"projectFiles",initialState:dd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,dd)),reducers:{initializeProjectFiles:x.initialize,setProjectFile:x.setOne,setProjectFiles:x.setMany,addProjectFile:x.addOne,addProjectFiles:x.addMany,updateProjectFile:x.updateOne,updateProjectFiles:x.updateMany,deleteProjectFile:x.deleteOne,deleteProjectFiles:x.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:ld,setProjectFile:Om,setProjectFiles:vm,addProjectFile:wm,addProjectFiles:ud,updateProjectFile:_i,updateProjectFiles:Em,deleteProjectFile:hd,deleteProjectFiles:md,setIsImportingProjectFile:fd,setActiveProjectFileId:pd,saveActiveProjectFileBounds:yd,resetProjectFileObjectUrls:jm}=bi.actions,Ad=t=>t.projectFileReducer.instances,gd=u.createSelector([Ad],t=>S(Object.values(t).sort((e,s)=>e.z_index-s.z_index))),Pm=t=>e=>e.projectFileReducer.instances[t],qm=t=>t.projectFileReducer.activeProjectFileId,km=t=>t.projectFileReducer.isImportingProjectFile,Sd=bi.reducer,Dm={isRehydrated:!1},Ii=u.createSlice({name:"rehydrated",initialState:Dm,reducers:{setRehydrated:(t,e)=>{t.isRehydrated=e.payload}}}),{setRehydrated:Cm}=Ii.actions,Mm=t=>t.rehydratedReducer.isRehydrated,Td=Ii.reducer,Ae=I(t=>t.offline_id),bd=Ae.getInitialState({}),Ri=u.createSlice({name:"teams",initialState:bd,extraReducers:t=>t.addCase("RESET",e=>Object.assign(e,bd)),reducers:{setTeam:Ae.setOne,initializeTeams:Ae.initialize,addTeam:Ae.addOne,updateTeam:Ae.updateOne,deleteTeam:Ae.deleteOne}}),{setTeam:ge,initializeTeams:_d,addTeam:Id,updateTeam:Fi,deleteTeam:Oi}=Ri.actions,vi=t=>t.teamReducer.instances,wi=u.createSelector([vi],t=>Object.values(t)),Se=t=>e=>e.teamReducer.instances[t],zm=g(u.createSelector([vi,(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 S(s)})),Um=g(u.createSelector([wi,(t,e)=>e],(t,e)=>S(t.filter(s=>s.organization===e)))),Vm=g(u.createSelector([wi,(t,e)=>e],(t,e)=>S(t.filter(s=>s.members.includes(e))))),Rd=Ri.reducer,$m={version:0},Fd=u.createSlice({name:"versioning",initialState:$m,reducers:{}}),Od=Fd.reducer;let vd;function Bm(t){vd=t}function qe(){return vd}let wd;function Gm(t){wd=t}function Lm(){return wd}const Ed={};class jd{constructor(e){A(this,"client");Ed[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 Pd="versioning",qd=()=>Cd.length-1,kd=t=>(t[Pd]={version:qd()},t),Dd=()=>kd({}),Nm=t=>(t.outboxReducer&&(t.outboxReducer.deletedRequests=[]),t),Hm=t=>e=>{var s;return e===void 0&&(e={}),((s=e[Pd])==null?void 0:s.version)===qd()?e:t(e)},Cd=[kd,Dd,Dd,Nm],Wm=Object.fromEntries(Cd.map((t,e)=>[e,Hm(t)])),Ei="versioning",Md={[Ei]:Od,fileReducer:sc,authReducer:Ia,categoryReducer:wa,assetReducer:Sn,assetAttachmentReducer:fn,assetStageCompletionReducer:On,assetStageReducer:jn,assetTypeReducer:Ta,assetTypeAttachmentReducer:Gn,issueReducer:bo,issueAttachmentReducer:lo,issueTypeReducer:er,organizationReducer:Hr,outboxReducer:Zr,projectReducer:Mr,projectAttachmentReducer:rd,projectAccessReducer:jr,organizationAccessReducer:Ir,projectFileReducer:Sd,rehydratedReducer:Td,formReducer:bc,formRevisionReducer:gc,formRevisionAttachmentReducer:dc,formSubmissionAttachmentReducer:Ec,formSubmissionReducer:Mc,userReducer:Ar,emailDomainsReducer:Za,licenseReducer:mr,documentsReducer:Ha,documentAttachmentReducer:Ua,teamReducer:Rd,agentsReducer:cn,issueCommentReducer:po,issueUpdateReducer:dr,geoImageReducer:Wc,issueAssociationReducer:eo,issueTypeFieldsReducer:$o,issueTypeFieldValuesReducer:ko,issueTypeFieldsAttachmentReducer:Eo,issueTypeFieldValuesAttachmentReducer:Yo,assetTypeFieldsReducer:ia,assetTypeFieldValuesReducer:Aa,assetTypeFieldsAttachmentReducer:Xn,assetTypeFieldValuesAttachmentReducer:la},zd=u.combineReducers(Md),Ud="RESET",Ym=(t,e)=>e.type==="auth/setLoggedIn"&&!e.payload?zd(void 0,e):zd(t,e);let ji=null;function ue(){const t=qe();if(!t)return console.warn("Client store not set; cannot get outbox coordinator yet."),null;if(ji)return ji;const e=t.getState().offline.outbox,s=be._fromOutbox(e);return ji=s,s}const Km=t=>{if(t)throw t;const e=qe();e?e.dispatch({type:"rehydrated/setRehydrated",payload:!0}):console.error("Client store not set")},Vd=(t,e,s)=>{const n=ue();return n?(n.addRequest(e),n.getQueue()):(console.warn("Outbox coordinator not set; cannot enqueue request yet."),[])},$d=(t,e,s)=>{const n=ue();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 Jm(t,e){if(!e.payload)throw new Error("Received empty payload");return af(e)}const Xm={...Ui,effect:Jm,discard:qi,returnPromises:!0,persistCallback:Km,retry:of,persistOptions:{storage:Jd},queue:{...Ui.queue,enqueue:Vd,dequeue:$d,peek:(...t)=>cf(...t)}},Zm=Xd(Wm,Ei),Qm=u.compose(Kd.offline(Xm),Zm);function xm(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 Pi(t,e){const s=Ed[t.meta.offline.effect.serviceName];if(!s)throw new Error(`Service ${t.meta.offline.effect.serviceName} not found`);const n=s instanceof F;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},o=t.meta.offline.effect,{payload:d,headers:m,method:r,queryParams:h,attachmentHash:f,isExternalUrl:p,isAuthNeeded:y,isResponseBlob:T}={...c,...o.request},_=o.request;let b=_.url;const E=f?await e.files.fetchCache(f):void 0;if(f&&!E)throw new Error(`Cannot upload file ${f} because it's not cached.`);!p&&!b.startsWith("http")&&(!b.startsWith("/")&&!b.startsWith("blob:")&&(b="/"+b),b=t.meta.offline.effect.BASE_URL+b);const se=w=>{if(f){const ee=_.s3url;if(!ee)throw new Error(`No S3 URL for file ${f}`);if("warning"in ee)throw new Error(`S3 URL warning for file ${f}`);if(!E)throw new Error(`No file for file ${f}`);const De=ee.fields["x-amz-checksum-sha1"];if(!De)throw new Error(`No checksum for file ${f}`);return w.set("x-amz-checksum-sha1",De).field({...d,...ee.fields}).attach("file",E)}return w.send(d)},op={[l.GET]:()=>T?me.get(b.toString()).responseType("blob"):me.get(b.toString()),[l.POST]:()=>{const w=me.post(b.toString());return se(w)},[l.PATCH]:()=>{const w=me.patch(b.toString());return se(w)},[l.PUT]:()=>{const w=me.put(b.toString());return se(w)},[l.DELETE]:()=>{const w=me.delete(b.toString());return se(w)}}[r];let he=op();if(y&&n){const w=s.auth.getAuthHeader();he=he.set("Authorization",w)}m&&(he=he.set(m));try{return await he.query(h)}catch(w){const ee=xm(w),De=ee==null?void 0:ee.status;if(n&&De===401)return await s.auth.handleUnauthorized(he,ee),he.query(h);throw new j({response:ee,innerError:w,discard:Gd.includes(De)})}}class ef{constructor(e){A(this,"_all");A(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 Bd{constructor(){A(this,"next");this.next=null}then(e){return new ef(this).then(e)}async run(e){if(this.next)return this.next.run(e);{if(console.debug("Middleware finished. Performing request:",e),!qe())throw new Error("Client store not set");const n=Lm();if(!n)throw new Error("Client SDK not set");return Pi(e,n)}}}class tf extends Bd{async run(e){return super.run(e)}}class sf extends Bd{async run(e){return super.run(e)}}const nf=new tf().then(new sf).compile();function af(t){var e;return(e=nf[0])==null?void 0:e.run(t)}const Gd=[400,409,403,404,405,500];function qi(t,e,s=0){var r;if(console.debug("Considering discarding request due to error:",t,`(${typeof t})`,`
3
3
  Action:`,e,`
4
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=qe(),c=n.getState().outboxReducer.deletedRequests,o=e.payload.uuid;function d(){n.dispatch(Jr(o));const h=ue();if(!h)throw new Error("Outbox coordinator not set");h.remove(e.payload.uuid);const f=e.meta.offline.rollback;throw f&&(console.warn("Rolling back request due to SDK error:",e),n.dispatch(f)),t}if(t instanceof j&&t.options.discard)return console.debug("Discarding request due to explicit discard:",e),d();if(c.includes(o))return console.debug("Discarding request due to deletion:",e),d();if(t instanceof j){const h=t.status||((r=t.response)==null?void 0:r.status);if(h||console.warn("Error has no status code:",t),h!==void 0&&Gd.includes(h)){console.warn("Discarding request due to error:",t,`
5
- Action:`,e);const f=ue();if(!f)throw new Error("Outbox coordinator not set");f.remove(e.payload.uuid),t.options.discard=!0,d()}}console.debug("Registering a retry for request:",e.payload.uuid);const m=ue();if(!m)throw new Error("Outbox coordinator not set");return m.registerRetry(e.payload.uuid),!1}function cf(t,e,s){var n;return(n=ue())==null?void 0:n.peek()}function of(t,e){return qe().dispatch(Xr(new Date().getTime())),Wi}const Te="An unknown error occurred",rf=500,Ld=["non_field_errors","detail"];function df(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"?Ld.includes(a)?c:`${a}: ${c}`:Array.isArray(c)?Ld.includes(a)?c.join(`
5
+ Action:`,e);const f=ue();if(!f)throw new Error("Outbox coordinator not set");f.remove(e.payload.uuid),t.options.discard=!0,d()}}console.debug("Registering a retry for request:",e.payload.uuid);const m=ue();if(!m)throw new Error("Outbox coordinator not set");return m.registerRetry(e.payload.uuid),!1}function cf(t,e,s){var n;return(n=ue())==null?void 0:n.peek()}function of(t,e){return qe().dispatch(Xr(new Date().getTime())),Hi}const Te="An unknown error occurred",rf=500,Ld=["non_field_errors","detail"];function df(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"?Ld.includes(a)?c:`${a}: ${c}`:Array.isArray(c)?Ld.includes(a)?c.join(`
6
6
  `):c.map(o=>`${a}: ${o}`).join(`
7
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>rf?Te:s}class j extends Error{constructor(s){super(Te);A(this,"status");A(this,"response");A(this,"message");A(this,"options");const{response:n,innerError:a}=s;this.message=s.message??df(n,a)??Te,this.status=(n==null?void 0:n.status)??0,this.response=n,s.discard=s.discard??!1,this.options=s}}class lf{constructor(e){A(this,"store");this.store=e}async enqueueRequest(e,s,n){return this._enqueueRequest(e,s,n).then(a=>{if(a instanceof j)throw a;return a})}_enqueueRequest(e,s,n){const a=new Yi,c={...e,BASE_URL:s,serviceName:n};if(e.immediate){const o={...c,uuid:e.uuid??O.v4()},d={payload:o,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:o,BASE_URL:s,serviceName:n}}}};qi(d,this).then(m=>{a.resolve(m.body)}).catch(m=>{ki(m,d),m instanceof Error?a.reject(m):a.reject(new Error((m??Te).toString()))})}else{const o=this.store.dispatch(Kr(c)),d=r=>{if(r)a.resolve(r.body);else{const h=new j({message:"Could not get a response from the server.",response:r,discard:!0});a.reject(h)}},m=r=>{r instanceof j?r.options.discard=!0:(console.error("Received an unexpected error while processing a request:",r,`
9
- Converting error to APIError and discarding.`),r=new j({message:"An error occurred while processing the request.",innerError:r,discard:!0})),a.reject(r)};o.then(d,m)}return a}}class be{constructor(){A(this,"graph");A(this,"requestAttemptCounter");this.graph=new Zd.DepGraph,this.requestAttemptCounter={}}static _fromOutbox(e){const s=new be;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 o=e[c];if(!o){console.error("Previous outbox item was undefined");continue}o.payload.uuid!==a.payload.uuid&&o.payload.blocks.some(d=>a.payload.blockers.includes(d))&&be._addDependency(a.payload.uuid,o.payload.uuid,s.graph)}}return s}_addDependency(e,s){be._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 uf=(t,e)=>{const s=new e(t);return Gm(s),Bm(t),s};class F extends jd{constructor(s,n){super(s);A(this,"auth");this.auth=n}}class hf extends F{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(n=>(this.dispatch(nn(n)),n))}async continueConversation(e,s,n){return this.enqueueRequest({description:"Prompt agent",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:s}}).then(a=>{this.dispatch(cn(a))})}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(an(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(sn(s))}}class P extends F{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:s,assetAttachmentReducer:n,assetTypeAttachmentReducer:a,documentAttachmentReducer:c,projectAttachmentReducer:o,formRevisionAttachmentReducer:d,formSubmissionAttachmentReducer:m,geoImageReducer:r,assetTypeFieldsAttachmentReducer:h,assetTypeFieldValuesAttachmentReducer:f,issueTypeFieldsAttachmentReducer:p,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(o.instances),Object.values(d.instances),Object.values(m.instances),Object.values(r.instances),Object.values(h.instances),Object.values(f.instances),Object.values(p.instances),Object.values(y.instances)).filter(_=>_.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:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:n,blockers:[`s3-${a.fields.key}`],blocks:[n],s3url:a});return s}async getFilePayload(e){const s=await fe(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 ke extends P{async _bulkAdd(e){var r;const{store:s}=this.client,n=(r=s.getState().userReducer.currentUser)==null?void 0:r.id,a=new Date().toISOString(),c=[],o=[],d={};for(const h of e){const{modelId:f,file:p}=h,y=await this.getFilePayload(p);y.sha1 in d||(d[y.sha1]=y);const T=this.buildOfflineAttachment({file:p,file_sha1:y.sha1,submitted_at:a,created_by:n,description:"",modelId:f});c.push(T),o.push(this.buildAttachmentPayload({offline_id:T.offline_id,file_name:T.file_name,file_sha1:T.file_sha1,file_extension:y.extension,description:T.description,modelId:f}))}this.dispatch(this.addAttachments(c));const m=this.enqueueRequest({description:`Add ${this.name}`,method:l.POST,url:`${this.url}/bulk/`,payload:{submitted_at:a,attachments:o,files:Object.values(d)},blocks:c.map(h=>h.offline_id),blockers:c.map(h=>h.file_sha1)});return m.then(({attachments:h,presigned_urls:f})=>{this.dispatch(this.updateAttachments(h)),this.processPresignedUrls(f)}).catch(()=>{this.dispatch(this.removeAttachments(c.map(h=>h.offline_id)))}),[c,m.then(({attachments:h})=>h)]}async _delete(e){const{store:s}=this.client,n=this.selectAttachment(e)(s.getState());if(!n)throw new Error(`Attempting to delete attachment with offline_id ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(n.offline_id));const a=this.enqueueRequest({description:`Delete ${this.name}`,method:l.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 mf extends ke{constructor(){super(...arguments);A(this,"name","Asset Attachment");A(this,"url","/asset-attachments");A(this,"initializeAttachments",gt);A(this,"addAttachments",St);A(this,"updateAttachments",ln);A(this,"removeAttachments",Tt);A(this,"removeAttachment",un);A(this,"setAttachment",dn);A(this,"selectAttachment",mn)}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.modelId})}buildAttachmentPayload(s){return{...s,asset:s.modelId}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelId:n.assetId,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s.toString()},blocks:[],blockers:[]});this.dispatch(gt(n))}}function Di(t,e){const s=[];let n=0;const a=t.length;for(;n<a;)s.push(t.slice(n,n+=e));return s}class ff extends F{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.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(It(c));const o=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/assets/",payload:c,blockers:[c.asset_type],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Ie(d))}).catch(()=>{this.dispatch(Ft(c.offline_id))}),[c,o]}update(e){const{store:s}=this.client,n=wt(e.offline_id)(s.getState());if(!n)throw new Error(`No asset with id ${e.offline_id} 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(Ie(a));const c=this.enqueueRequest({description:"Edit asset",method:l.PATCH,url:`/assets/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return c.then(o=>{this.dispatch(Ie(o))}).catch(()=>{this.dispatch(Ie(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=wt(e)(n);if(!a)throw new Error(`No asset with id ${e} found in the store`);const c=fn(e)(n),o=Cc(e)(n),d=xc(e)(n);if(this.dispatch(Ft(e)),c.length>0){const m=c.map(({offline_id:r})=>r);this.dispatch(Tt(m))}if(o.length>0){const m=o.map(({offline_id:r})=>r);this.dispatch(Je(m))}if(d.length>0){const m=d.map(({offline_id:r})=>r);this.dispatch(Cs(m))}return this.enqueueRequest({description:"Delete asset",method:l.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(It(a)),this.dispatch(St(c)),this.dispatch(Ke(o)),this.dispatch(ks(d)),m})}bulkAdd(e,s,n,a){const c=new Date().toISOString(),o=O.v4(),d=Di(e,a).map(h=>{const f=h.map(p=>R(p));return{batchId:O.v4(),payload:{transaction_id:o,submitted_at:c,asset_type:s,project:n,assets:f}}}),m=[];let r=null;for(const h of d){const{batchId:f,payload:p}=h,y=p.assets.map(E=>E.offline_id),T=[s];r&&T.push(r);const _=y;_.push(f);const b=this.enqueueRequest({description:"Batch create assets",method:l.POST,url:"/assets/bulk/",payload:p,blockers:T,blocks:_});r=h.batchId,m.push(b)}return Promise.all(m).then(h=>{const f=h.flat();this.dispatch(Rt(f))}),m}async refreshStore(e){const s=await this.enqueueRequest({description:"Get assets",method:l.GET,url:"/assets/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(An(s))}}class pf extends F{add(e){const{store:s}=this.client,n=s.getState().userReducer.currentUser.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(jt(c));const o=this.enqueueRequest({description:"Add asset stage completion",method:l.POST,url:"/asset-stage-completions/",payload:{offline_id:c.offline_id,submitted_at:a,asset:e.asset,stage:e.stage},blockers:[e.asset,e.stage],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(In(d))}).catch(()=>{this.dispatch(qt(c.offline_id))}),[c,o]}delete(e){const{store:s}=this.client,n=Fn(e)(s.getState());if(!n)throw new Error(`Expected asset stage completion with id ${e} to exist`);this.dispatch(qt(e));const a=this.enqueueRequest({description:"Delete asset stage completion",method:l.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(jt(n))}),a}bulkAdd(e){const{store:s}=this.client,n=new Date().toISOString(),a=s.getState().userReducer.currentUser.id,c=e.map(r=>R(r)),o=c.map(r=>({...r,created_by:a,submitted_at:n})),d=o.map(({offline_id:r})=>r);this.dispatch(Pt(o));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:l.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:n,completions:c},blockers:[...e.map(r=>r.asset),...e.map(r=>r.stage)],blocks:d});return m.then(r=>{this.dispatch(Rn(r))}).catch(()=>{this.dispatch(kt(d))}),[o,m]}bulkDelete(e){const{store:s}=this.client,n=On(e)(s.getState());this.dispatch(kt(e));const a=this.enqueueRequest({description:"Deleting asset stage completions",method:l.DELETE,url:"/asset-stage-completions/bulk/",payload:{completion_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(Pt(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stage completions",method:l.GET,url:"/asset-stage-completions/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(_n(s))}}class yf extends F{bulkAdd(e,s){const n=new Date().toISOString(),a=this.client.store.getState().userReducer.currentUser.id,c=e.map(m=>R(m)),o=c.map(m=>({...m,asset_type:s,created_by:a,submitted_at:n}));this.dispatch(Ce(o));const d=this.enqueueRequest({description:"Add asset stages",method:l.POST,url:"/asset-stages/bulk/",payload:{submitted_at:n,asset_type:s,stages:c},blockers:[s],blocks:c.map(({offline_id:m})=>m)});return d.then(m=>{this.dispatch(Me(m))}).catch(()=>{this.dispatch(ze(o.map(({offline_id:m})=>m)))}),[o,d]}async bulkUpdate(e,s){const a=this.client.store.getState(),c=zt(e.map(({offline_id:o})=>o))(a);return this.dispatch(Me(e)),this.enqueueRequest({description:"Edit asset stages",method:l.PATCH,url:`/asset-types/${s}/bulk-update-stages/`,payload:{stages:e},blockers:[s],blocks:e.map(({offline_id:o})=>o)}).catch(o=>{throw this.dispatch(Me(c)),o})}async bulkDelete(e){const{store:s}=this.client,n=zt(e)(s.getState());this.dispatch(ze(e));const a=this.enqueueRequest({description:"Delete asset stages",method:l.DELETE,url:"/asset-stages/bulk/",payload:{stage_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(Ce(n))}),a}update(e){const{store:s}=this.client,n=qn(e.offline_id)(s.getState());if(!n)throw new Error(`No asset stage with id ${e.offline_id} found in the store`);const a={...n,...e};this.dispatch(Mt(a));const c=this.enqueueRequest({description:"Update asset stage",method:l.PATCH,url:`/asset-stages/${n.offline_id}/`,payload:{name:e.name,description:e.description,priority:e.priority,color:e.color},blockers:[n.offline_id],blocks:[n.offline_id]});return c.then(o=>{this.dispatch(Mt(o))}).catch(()=>{this.dispatch(jn(n))}),[a,c]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stages",method:l.GET,url:"/asset-stages/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(En(s))}}class Af extends ke{constructor(){super(...arguments);A(this,"name","Asset Type Attachment");A(this,"url","/asset-type-attachments");A(this,"addAttachments",Vt);A(this,"updateAttachments",Un);A(this,"removeAttachments",$t);A(this,"removeAttachment",Vn);A(this,"setAttachment",zn);A(this,"selectAttachment",Bn)}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.modelId})}buildAttachmentPayload(s){return{...s,asset_type:s.modelId}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelId:n.assetTypeId,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset type attachments",method:l.GET,url:`${this.url}/`,queryParams:{organization:s.toString()},blocks:[],blockers:[]});this.dispatch(Mn(n))}}class gf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{fieldsRevisionId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,fields_revision:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,field_identifier:f,file_extension:y.extension,file_sha1:y.sha1,fields_revision:h};o.push(_)}this.dispatch(Wn(c));const d=this.enqueueRequest({description:"Add asset type fields attachments",method:l.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.fields_revision),blocks:c.map(r=>r.offline_id)});return d.then(r=>{this.processPresignedUrls(r.presigned_urls),this.dispatch(Yn(r.attachments))}).catch(()=>{this.dispatch(Kn(c.map(r=>r.offline_id)))}),[c,d.then(({attachments:r})=>r)]}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.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(Hn(s))}}class Sf extends F{add(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ea(c));const o=this.enqueueRequest({description:"Add Asset Type Fields",method:l.POST,url:"/asset-type-fields/",payload:c,blockers:[c.asset_type],blocks:[c.offline_id]});return o.then(m=>{this.dispatch(ta(m))}).catch(m=>{throw this.dispatch(sa(c.offline_id)),m}),[c,o]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Type Fields",method:l.GET,url:"/asset-type-fields/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(xn(s))}}class Tf extends P{async bulkAdd(e,s){var r;const n=new Date().toISOString(),a=(r=this.client.store.getState().userReducer.currentUser)==null?void 0:r.id,c=Di(e,s??e.length),o=[],d=[];for(const h of c){const f={},p=[];for(const y of h){const{fieldValuesId:T,fieldIdentifier:_,file:b}=y,E=await this.getFilePayload(b);E.sha1 in f||(f[E.sha1]=E);const se=R({file:URL.createObjectURL(b),file_type:b.type,file_name:b.name,file_sha1:E.sha1,created_by:a,field_values:T,submitted_at:n,field_identifier:_});o.push(se);const Wd={offline_id:se.offline_id,file_name:b.name,file_sha1:E.sha1,file_extension:E.extension,field_identifier:_,field_values:T};p.push(Wd)}d.push({submitted_at:n,attachments:p,files:Object.values(f)})}this.dispatch($e(o));const m=d.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(f=>f.field_values),blocks:h.attachments.map(f=>f.offline_id)}));return Promise.all(m).then(h=>{for(const p of h)this.processPresignedUrls(p.presigned_urls);const f=h.flatMap(p=>p.attachments);this.dispatch(oa(f))}).catch(h=>{throw this.dispatch(Be(o.map(f=>f.offline_id))),h}),[o,m.map(h=>h.then(({attachments:f})=>f))]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=da(e)(n);this.dispatch(Be(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($e(a)),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.toString()},blockers:[],blocks:[]});this.dispatch(ca(s))}}const bf=t=>Array.isArray(t)&&t[0]instanceof File,Ci=t=>{const e={},s={};for(const n in t){const a=t[n];a instanceof File?e[n]=[a]:bf(a)?e[n]=a:a!==void 0&&(s[n]=a)}return{values:s,files:e}};class _f extends P{add(e){var o;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(o=n.userReducer.currentUser)==null?void 0:o.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add form submission",method:l.POST,url:"/form-submissions/",payload:a,blockers:["add-form-entry",e.form_revision,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[a.offline_id]});return this.dispatch(Is(a)),c.then(d=>(this.dispatch(Ye(d)),d)).catch(()=>{this.dispatch(Rs(a.offline_id))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=vs(e.offline_id)(n);if(!a)throw new Error(`Expected submission with offline_id ${e.offline_id} to exist`);const c={...a,...e};this.dispatch(qc(c));const o=this.enqueueRequest({description:"Delete user form submissions",method:l.PATCH,url:`/form-submissions/${c.offline_id}/`,payload:e,blockers:[c.offline_id],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Ye(d))}).catch(()=>{this.dispatch(Ye(a))}),[c,o]}async delete(e){const{store:s}=this.client,n=s.getState(),a=vs(e)(n);if(!a)throw new Error(`Expected submission with offline_id ${e} to exist`);const c=wc(e)(n);this.dispatch(Rs(e)),this.dispatch(We(c.map(o=>o.offline_id)));try{return await this.enqueueRequest({description:"Delete user form submissions",method:l.DELETE,url:`/form-submissions/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(Is(a)),this.dispatch(He(c)),o}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch form submissions",method:l.GET,url:"/form-submissions/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(Pc(s))}}class If extends F{add(e){var o;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(o=n.userReducer.currentUser)==null?void 0:o.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset type field values",method:l.POST,url:"/asset-type-field-values/",payload:a,blockers:[e.asset,e.fields_revision],blocks:[a.offline_id]});return this.dispatch(Yt(a)),c.then(d=>(this.dispatch(Re(d)),d)).catch(()=>{this.dispatch(Kt(a.offline_id))}),[a,c]}bulkAdd(e,s){var r;const n=new Date().toISOString(),{values:a}=Ci(e.values),c=[],o=Di(e.payloads,s??e.payloads.length),d=[];for(const h of o){const f=[];for(const p of h){const y=R({...p,values:Ci(p.values).values,created_by:(r=this.client.store.getState().userReducer.currentUser)==null?void 0:r.id,submitted_at:n});c.push(y),f.push({offline_id:y.offline_id,asset:p.asset,fields_revision:p.fields_revision,published_at:p.published_at,values:y.values})}d.push({submitted_at:n,values:a,field_values:f})}this.dispatch(fa(c));const m=[];for(const h of d){const f=h.field_values.map(_=>_.asset),p=h.field_values.map(_=>_.fields_revision),y=h.field_values.map(_=>_.offline_id),T=this.enqueueRequest({description:"Bulk add asset type field values",method:l.POST,url:"/asset-type-field-values/bulk/",payload:h,blockers:[...f,...p],blocks:y});m.push(T)}return Promise.all(m).then(h=>{this.dispatch(pa(h.flat()))}).catch(()=>{this.dispatch(ya(c.map(h=>h.offline_id)))}),[c,m]}update(e){const{store:s}=this.client,n=s.getState(),a=Xt(e.offline_id)(n);if(!a)throw new Error(`Expected AssetTypeFieldValues with offline_id ${e.offline_id} to exist`);const c={...a,...e};this.dispatch(Re(c));const o=this.enqueueRequest({description:"Delete asset type field values",method:l.PATCH,url:`/asset-type-field-values/${e.offline_id}/`,payload:e,blockers:[c.offline_id,c.fields_revision,c.asset],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Re(d))}).catch(()=>{this.dispatch(Re(a))}),[c,o]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Xt(e)(n);if(!a)throw new Error(`Expected submission with offline_id ${e} to exist`);const c=la(e)(n);this.dispatch(Kt(e)),this.dispatch(Be(c.map(o=>o.offline_id)));try{await this.enqueueRequest({description:"Delete asset type field values",method:l.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(Yt(a)),this.dispatch($e(c)),o}}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.toString()},blockers:[],blocks:[]});this.dispatch(ma(s))}}class Rf extends F{add(e){const{store:s}=this.client,n=s.getState().userReducer.currentUser.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Qt(c));const o=this.enqueueRequest({description:"Create asset type",method:l.POST,url:"/asset-types/",payload:c,blockers:[],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Fe(d))}).catch(()=>{this.dispatch(xt(c.offline_id))}),[c,o]}update(e){const{store:s}=this.client,n=ts(e.offline_id)(s.getState());if(!n)throw new Error(`Expected asset type with offline_id ${e.offline_id} to exist`);const a={...n,...e};this.dispatch(Fe(a));const c=this.enqueueRequest({description:"Update asset type",method:l.PATCH,url:`/asset-types/${e.offline_id}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[n.offline_id],blocks:[n.offline_id]});return c.then(o=>{this.dispatch(Fe(o))}).catch(()=>{this.dispatch(Fe(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=ts(e)(n);if(!a)throw new Error(`Expected asset type with offline_id ${e} to exist`);const c=vt(e)(n),o=Dn(e)(n),d=Gn(e)(n);return this.dispatch(xt(e)),this.dispatch(gn(c.map(m=>m.offline_id))),this.dispatch(ze(o.map(m=>m.offline_id))),this.dispatch($t(d.map(({offline_id:m})=>m))),this.enqueueRequest({description:"Delete asset type",method:l.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(Qt(a)),this.dispatch(Rt(c)),this.dispatch(Ce(o)),this.dispatch(Vt(d)),m})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset types",method:l.GET,url:"/asset-types/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(Ta(s))}}class Ff extends F{add(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(is(c));const o=this.enqueueRequest({description:"Create Category",method:l.POST,url:"/categories/",payload:c,blockers:[e.project.toString()],blocks:[c.offline_id]});return[c,o]}update(e){const s=this.client.store.getState(),n=as(e.offline_id)(s);if(!n)throw new Error(`Expected an existing category with offline_id ${e.offline_id}`);const a={...n,...e};this.dispatch(va(a));const c=this.enqueueRequest({description:"Edit Category",method:l.PATCH,url:`/categories/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return[a,c]}remove(e){const{store:s}=this.client,n=as(e)(s.getState());if(!n)throw new Error(`No category with id ${e} found in the store`);this.dispatch(wa(e));const a=this.enqueueRequest({description:"Delete Category",method:l.DELETE,url:`/categories/${n.offline_id}/`,blockers:[n.offline_id],blocks:[]});return a.catch(()=>{this.dispatch(is(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get categories",method:l.GET,url:"/categories/",queryParams:{project:e.toString()},blocks:[],blockers:[]});this.dispatch(Oa(s))}}class Of extends ke{constructor(){super(...arguments);A(this,"name","Document Attachment");A(this,"url","/document-attachments");A(this,"addAttachments",qa);A(this,"updateAttachments",Da);A(this,"removeAttachments",Ma);A(this,"removeAttachment",Ca);A(this,"setAttachment",ka);A(this,"selectAttachment",Ua)}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.modelId})}buildAttachmentPayload(s){return{...s,document:s.modelId}}async bulkAdd(s){var f;const{store:n}=this.client,a=(f=n.getState().userReducer.currentUser)==null?void 0:f.id,c=new Date().toISOString(),o=[],d=[],m={},r={};for(const p of s){const{documentId:y,file:T}=p,_=await this.getFilePayload(T);_.sha1 in m||(m[_.sha1]=_,r[_.sha1]=[]);const b=this.buildOfflineAttachment({file:T,file_sha1:_.sha1,submitted_at:c,created_by:a,description:"",modelId:y});o.push(b),d.push({offline_id:b.offline_id,file_name:b.file_name,file_sha1:b.file_sha1,file_extension:_.extension,description:b.description,document:y}),r[_.sha1].push(b.offline_id)}this.dispatch(this.addAttachments(o));const h=this.enqueueRequest({description:"Attach files to document",method:l.POST,url:"/document-attachments/bulk/",payload:{submitted_at:c,attachments:d,files:Object.values(m)},blocks:o.map(p=>p.offline_id),blockers:o.map(p=>p.file_sha1)});return h.then(({attachments:p,presigned_urls:y})=>{this.dispatch(this.updateAttachments(p));const T=this.processPresignedUrls(y);for(const[_,b]of Object.entries(T))b.then(()=>{const E=r[_];for(const se of E)this.makeReadable(se)})}).catch(()=>{this.dispatch(this.removeAttachments(o.map(p=>p.offline_id)))}),[o,h.then(({attachments:p})=>p)]}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,n){const a=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/projects/${s}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(Pa(a));const c=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/organizations/${n}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(this.addAttachments(c))}}class vf extends F{add(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ds([c]));const o=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.offline_id]});return o.catch(()=>{this.dispatch(ls([c.offline_id]))}),[c,o]}update(e){const{store:s}=this.client,n=s.getState().documentsReducer.documents[e.offline_id];if(!n)throw new Error(`attempting to update a document with offline_id ${e.offline_id} that does not exist in store.documents`);const a={...n,...e};this.dispatch(ne([a]));const c=this.enqueueRequest({description:"Update Document",method:l.PATCH,url:`/documents/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return c.catch(()=>{ne([n])}),[a,c]}move(e,s,n){const{store:a}=this.client,c=pe(a.getState()),o=[],d=c[e];if(!d)throw new Error(`attempting to move a document with offline_id ${e} that does not exist in store.documents`);if(o.push(d),d.parent_document&&o.push(c[d.parent_document]),s){const r=c[s];if(!r)throw new Error(`attempting to move a document to target with offline_id ${s} that does not exist in store.documents`);o.push(r),r.parent_document&&o.push(c[r.parent_document])}this.dispatch(Ga({documentId:e,targetDocumentId:s,position:n}));const m=this.enqueueRequest({description:"Move Document",method:l.PATCH,url:`/documents/${e}/move/`,queryParams:{target:s??void 0,position:n},blockers:[e],blocks:[]});return m.then(r=>{this.dispatch(ne(r))}).catch(()=>{this.dispatch(ne(o))}),m}delete(e){const{store:s}=this.client,n=pe(s.getState()),a=Na(e)(s.getState());if(!a)throw new Error(`attempting to delete a document with offline_id ${e} that does not exist in store.documents`);const c=a.parent_document?n[a.parent_document]:void 0;this.dispatch(ls([e]));const o=this.enqueueRequest({description:"Delete Document",method:l.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return o.then(d=>{this.dispatch(ne(d))}).catch(()=>{this.dispatch(ne([a])),c&&this.dispatch(ne([c]))}),o}async refreshStore(e,s){const n=this.enqueueRequest({description:"Get project documents",method:l.GET,url:`/projects/${e}/documents/`,blockers:[],blocks:[]}),a=this.enqueueRequest({description:"Get organization documents",method:l.GET,url:`/organizations/${s}/documents/`,blockers:[],blocks:[]});this.dispatch(Ba(await n)),this.dispatch(ds(await a))}}class wf extends F{async add(e,s){return this.enqueueRequest({description:"Add email domain to organization",method:l.POST,url:`/organizations/${e}/email-domains/`,payload:{email:s},blockers:[e.toString(),"create-org"],blocks:[]})}async remove(e){return this.dispatch(Ka(e.offline_id)),this.enqueueRequest({description:"Remove email domain from organization",method:l.DELETE,url:`/organizations/${e.organization}/email-domains/${e.offline_id}/`,blockers:[e.domain],blocks:[]}).catch(s=>{throw this.dispatch(Ya(e)),s})}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch email domains for organization",method:l.GET,url:`/organizations/${e}/email-domains/`,blockers:[e.toString()],blocks:[]});this.dispatch(Wa(s))}}class Ef extends F{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 at={},Mi=new Set;let ct=0,zi=0,Ui=0;const jf=20;class Pf extends F{constructor(){super(...arguments);A(this,"host");A(this,"_dbPromise",Qd.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 ft(n,s),c=await this.enqueueRequest({description:"Get S3 URL",method:l.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await fe(n),file_type:n.type,extension:n.name.split(".").pop(),size:n.size.toString()},blockers:[],blocks:[`s3-${a}`]});return"url"in c&&this.dispatch(ec({sha1:s,...c})),c}async addCache(s,n){if(Mi.has(n))return;if(!s.type){const o=s.name.split("."),d=o[o.length-1];s=new File([s],s.name,{type:d})}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),ct++):(await a.put("files",s,n),zi++),Mi.add(n),Ui++,Ui%jf===0&&console.debug(`File cache summary: ${ct} hits and ${zi} misses, ${ct/(ct+zi)*100}% hit rate over ${Ui} calls to addCache.`)}async removeCache(s){await(await this._dbPromise).delete("files",s),Mi.delete(s)}async fetchCache(s){return(await this._dbPromise).get("files",s)}async getOrRenewUploadUrl(s){const n=this.client.store.getState();return tc(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 ft(n,s),c={file_name:n.name,file_sha1:s,file:a},o=await this.getOrRenewUploadUrl(s);if("warning"in o){if(o.warning==="already_uploaded")return[c,Promise.resolve(void 0).then()];throw new Error(o.warning)}const d=o.url,m=this.enqueueRequest({url:d,description:"Upload file",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:s,blockers:[`s3-${a}`],blocks:[s],s3url:o});return[c,m]}async fetchFileFromUrl(s,n,a){const c=s.split("?")[0]??s,o=await this.fetchCache(n);if(o){if(!o.name)throw new Error("Cached file unexpectedly has no name.");return o}if(s.startsWith("blob:")){const h=await Zi(s),f=new File([h],a??n,{type:h.type});return await this.addCache(f,n),f}let d=at[c],m=!0;d?m=!1:(d=new Promise(h=>{this.enqueueRequest({description:"Download file",method:l.GET,url:s,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[n],blocks:[n]}).then(f=>{const p=new File([f],a??n,{type:f.type});h(p)})}),at[c]=d);let r;try{r=await d}catch(h){throw m&&h instanceof j&&delete at[c],h}if(m){const h=await fe(r);if(h!==n){const y=`The hash of the file returned from the server (${h}) does not match the
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>rf?Te:s}class j extends Error{constructor(s){super(Te);A(this,"status");A(this,"response");A(this,"message");A(this,"options");const{response:n,innerError:a}=s;this.message=s.message??df(n,a)??Te,this.status=(n==null?void 0:n.status)??0,this.response=n,s.discard=s.discard??!1,this.options=s}}class lf{constructor(e){A(this,"store");this.store=e}async enqueueRequest(e,s,n){return this._enqueueRequest(e,s,n).then(a=>{if(a instanceof j)throw a;return a})}_enqueueRequest(e,s,n){const a=new Wi,c={...e,BASE_URL:s,serviceName:n};if(e.immediate){const o={...c,uuid:e.uuid??O.v4()},d={payload:o,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:o,BASE_URL:s,serviceName:n}}}};Pi(d,this).then(m=>{a.resolve(m.body)}).catch(m=>{qi(m,d),m instanceof Error?a.reject(m):a.reject(new Error((m??Te).toString()))})}else{const o=this.store.dispatch(Kr(c)),d=r=>{if(r)a.resolve(r.body);else{const h=new j({message:"Could not get a response from the server.",response:r,discard:!0});a.reject(h)}},m=r=>{r instanceof j?r.options.discard=!0:(console.error("Received an unexpected error while processing a request:",r,`
9
+ Converting error to APIError and discarding.`),r=new j({message:"An error occurred while processing the request.",innerError:r,discard:!0})),a.reject(r)};o.then(d,m)}return a}}class be{constructor(){A(this,"graph");A(this,"requestAttemptCounter");this.graph=new Zd.DepGraph,this.requestAttemptCounter={}}static _fromOutbox(e){const s=new be;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 o=e[c];if(!o){console.error("Previous outbox item was undefined");continue}o.payload.uuid!==a.payload.uuid&&o.payload.blocks.some(d=>a.payload.blockers.includes(d))&&be._addDependency(a.payload.uuid,o.payload.uuid,s.graph)}}return s}_addDependency(e,s){be._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 uf=(t,e)=>{const s=new e(t);return Gm(s),Bm(t),s};class F extends jd{constructor(s,n){super(s);A(this,"auth");this.auth=n}}class hf extends F{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(n=>(this.dispatch(sn(n)),n))}async continueConversation(e,s,n){return this.enqueueRequest({description:"Prompt agent",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:s}}).then(a=>{this.dispatch(an(a))})}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(nn(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(tn(s))}}class P extends F{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:s,assetAttachmentReducer:n,assetTypeAttachmentReducer:a,documentAttachmentReducer:c,projectAttachmentReducer:o,formRevisionAttachmentReducer:d,formSubmissionAttachmentReducer:m,geoImageReducer:r,assetTypeFieldsAttachmentReducer:h,assetTypeFieldValuesAttachmentReducer:f,issueTypeFieldsAttachmentReducer:p,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(o.instances),Object.values(d.instances),Object.values(m.instances),Object.values(r.instances),Object.values(h.instances),Object.values(f.instances),Object.values(p.instances),Object.values(y.instances)).filter(_=>_.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:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:n,blockers:[`s3-${a.fields.key}`],blocks:[n],s3url:a});return s}async getFilePayload(e){const s=await fe(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 ke extends P{async _bulkAdd(e){var r;const{store:s}=this.client,n=(r=s.getState().userReducer.currentUser)==null?void 0:r.id,a=new Date().toISOString(),c=[],o=[],d={};for(const h of e){const{modelId:f,file:p}=h,y=await this.getFilePayload(p);y.sha1 in d||(d[y.sha1]=y);const T=this.buildOfflineAttachment({file:p,file_sha1:y.sha1,submitted_at:a,created_by:n,description:"",modelId:f});c.push(T),o.push(this.buildAttachmentPayload({offline_id:T.offline_id,file_name:T.file_name,file_sha1:T.file_sha1,file_extension:y.extension,description:T.description,modelId:f}))}this.dispatch(this.addAttachments(c));const m=this.enqueueRequest({description:`Add ${this.name}`,method:l.POST,url:`${this.url}/bulk/`,payload:{submitted_at:a,attachments:o,files:Object.values(d)},blocks:c.map(h=>h.offline_id),blockers:c.map(h=>h.file_sha1)});return m.then(({attachments:h,presigned_urls:f})=>{this.dispatch(this.updateAttachments(h)),this.processPresignedUrls(f)}).catch(()=>{this.dispatch(this.removeAttachments(c.map(h=>h.offline_id)))}),[c,m.then(({attachments:h})=>h)]}async _delete(e){const{store:s}=this.client,n=this.selectAttachment(e)(s.getState());if(!n)throw new Error(`Attempting to delete attachment with offline_id ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(n.offline_id));const a=this.enqueueRequest({description:`Delete ${this.name}`,method:l.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 mf extends ke{constructor(){super(...arguments);A(this,"name","Asset Attachment");A(this,"url","/asset-attachments");A(this,"initializeAttachments",gt);A(this,"addAttachments",St);A(this,"updateAttachments",dn);A(this,"removeAttachments",Tt);A(this,"removeAttachment",ln);A(this,"setAttachment",rn);A(this,"selectAttachment",hn)}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.modelId})}buildAttachmentPayload(s){return{...s,asset:s.modelId}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelId:n.assetId,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s.toString()},blocks:[],blockers:[]});this.dispatch(gt(n))}}function ki(t,e){const s=[];let n=0;const a=t.length;for(;n<a;)s.push(t.slice(n,n+=e));return s}class ff extends F{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.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(It(c));const o=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/assets/",payload:c,blockers:[c.asset_type],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Ie(d))}).catch(()=>{this.dispatch(Ft(c.offline_id))}),[c,o]}update(e){const{store:s}=this.client,n=wt(e.offline_id)(s.getState());if(!n)throw new Error(`No asset with id ${e.offline_id} 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(Ie(a));const c=this.enqueueRequest({description:"Edit asset",method:l.PATCH,url:`/assets/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return c.then(o=>{this.dispatch(Ie(o))}).catch(()=>{this.dispatch(Ie(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=wt(e)(n);if(!a)throw new Error(`No asset with id ${e} found in the store`);const c=mn(e)(n),o=Cc(e)(n),d=xc(e)(n);if(this.dispatch(Ft(e)),c.length>0){const m=c.map(({offline_id:r})=>r);this.dispatch(Tt(m))}if(o.length>0){const m=o.map(({offline_id:r})=>r);this.dispatch(Je(m))}if(d.length>0){const m=d.map(({offline_id:r})=>r);this.dispatch(Ds(m))}return this.enqueueRequest({description:"Delete asset",method:l.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(It(a)),this.dispatch(St(c)),this.dispatch(Ke(o)),this.dispatch(qs(d)),m})}bulkAdd(e,s,n,a){const c=new Date().toISOString(),o=O.v4(),d=ki(e,a).map(h=>{const f=h.map(p=>R(p));return{batchId:O.v4(),payload:{transaction_id:o,submitted_at:c,asset_type:s,project:n,assets:f}}}),m=[];let r=null;for(const h of d){const{batchId:f,payload:p}=h,y=p.assets.map(E=>E.offline_id),T=[s];r&&T.push(r);const _=y;_.push(f);const b=this.enqueueRequest({description:"Batch create assets",method:l.POST,url:"/assets/bulk/",payload:p,blockers:T,blocks:_});r=h.batchId,m.push(b)}return Promise.all(m).then(h=>{const f=h.flat();this.dispatch(Rt(f))}),m}async refreshStore(e){const s=await this.enqueueRequest({description:"Get assets",method:l.GET,url:"/assets/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(yn(s))}}class pf extends F{add(e){const{store:s}=this.client,n=s.getState().userReducer.currentUser.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(jt(c));const o=this.enqueueRequest({description:"Add asset stage completion",method:l.POST,url:"/asset-stage-completions/",payload:{offline_id:c.offline_id,submitted_at:a,asset:e.asset,stage:e.stage},blockers:[e.asset,e.stage],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(_n(d))}).catch(()=>{this.dispatch(qt(c.offline_id))}),[c,o]}delete(e){const{store:s}=this.client,n=Rn(e)(s.getState());if(!n)throw new Error(`Expected asset stage completion with id ${e} to exist`);this.dispatch(qt(e));const a=this.enqueueRequest({description:"Delete asset stage completion",method:l.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(jt(n))}),a}bulkAdd(e){const{store:s}=this.client,n=new Date().toISOString(),a=s.getState().userReducer.currentUser.id,c=e.map(r=>R(r)),o=c.map(r=>({...r,created_by:a,submitted_at:n})),d=o.map(({offline_id:r})=>r);this.dispatch(Pt(o));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:l.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:n,completions:c},blockers:[...e.map(r=>r.asset),...e.map(r=>r.stage)],blocks:d});return m.then(r=>{this.dispatch(In(r))}).catch(()=>{this.dispatch(kt(d))}),[o,m]}bulkDelete(e){const{store:s}=this.client,n=Fn(e)(s.getState());this.dispatch(kt(e));const a=this.enqueueRequest({description:"Deleting asset stage completions",method:l.DELETE,url:"/asset-stage-completions/bulk/",payload:{completion_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(Pt(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stage completions",method:l.GET,url:"/asset-stage-completions/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(bn(s))}}class yf extends F{bulkAdd(e,s){const n=new Date().toISOString(),a=this.client.store.getState().userReducer.currentUser.id,c=e.map(m=>R(m)),o=c.map(m=>({...m,asset_type:s,created_by:a,submitted_at:n}));this.dispatch(Ce(o));const d=this.enqueueRequest({description:"Add asset stages",method:l.POST,url:"/asset-stages/bulk/",payload:{submitted_at:n,asset_type:s,stages:c},blockers:[s],blocks:c.map(({offline_id:m})=>m)});return d.then(m=>{this.dispatch(Me(m))}).catch(()=>{this.dispatch(ze(o.map(({offline_id:m})=>m)))}),[o,d]}async bulkUpdate(e,s){const a=this.client.store.getState(),c=zt(e.map(({offline_id:o})=>o))(a);return this.dispatch(Me(e)),this.enqueueRequest({description:"Edit asset stages",method:l.PATCH,url:`/asset-types/${s}/bulk-update-stages/`,payload:{stages:e},blockers:[s],blocks:e.map(({offline_id:o})=>o)}).catch(o=>{throw this.dispatch(Me(c)),o})}async bulkDelete(e){const{store:s}=this.client,n=zt(e)(s.getState());this.dispatch(ze(e));const a=this.enqueueRequest({description:"Delete asset stages",method:l.DELETE,url:"/asset-stages/bulk/",payload:{stage_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(Ce(n))}),a}update(e){const{store:s}=this.client,n=Pn(e.offline_id)(s.getState());if(!n)throw new Error(`No asset stage with id ${e.offline_id} found in the store`);const a={...n,...e};this.dispatch(Mt(a));const c=this.enqueueRequest({description:"Update asset stage",method:l.PATCH,url:`/asset-stages/${n.offline_id}/`,payload:{name:e.name,description:e.description,priority:e.priority,color:e.color},blockers:[n.offline_id],blocks:[n.offline_id]});return c.then(o=>{this.dispatch(Mt(o))}).catch(()=>{this.dispatch(En(n))}),[a,c]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stages",method:l.GET,url:"/asset-stages/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(wn(s))}}class Af extends ke{constructor(){super(...arguments);A(this,"name","Asset Type Attachment");A(this,"url","/asset-type-attachments");A(this,"addAttachments",Vt);A(this,"updateAttachments",zn);A(this,"removeAttachments",$t);A(this,"removeAttachment",Un);A(this,"setAttachment",Mn);A(this,"selectAttachment",$n)}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.modelId})}buildAttachmentPayload(s){return{...s,asset_type:s.modelId}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelId:n.assetTypeId,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset type attachments",method:l.GET,url:`${this.url}/`,queryParams:{organization:s.toString()},blocks:[],blockers:[]});this.dispatch(Cn(n))}}class gf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{fieldsRevisionId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,fields_revision:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,field_identifier:f,file_extension:y.extension,file_sha1:y.sha1,fields_revision:h};o.push(_)}this.dispatch(Hn(c));const d=this.enqueueRequest({description:"Add asset type fields attachments",method:l.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.fields_revision),blocks:c.map(r=>r.offline_id)});return d.then(r=>{this.processPresignedUrls(r.presigned_urls),this.dispatch(Wn(r.attachments))}).catch(()=>{this.dispatch(Yn(c.map(r=>r.offline_id)))}),[c,d.then(({attachments:r})=>r)]}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.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(Nn(s))}}class Sf extends F{add(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(xn(c));const o=this.enqueueRequest({description:"Add Asset Type Fields",method:l.POST,url:"/asset-type-fields/",payload:c,blockers:[c.asset_type],blocks:[c.offline_id]});return o.then(m=>{this.dispatch(ea(m))}).catch(m=>{throw this.dispatch(ta(c.offline_id)),m}),[c,o]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Type Fields",method:l.GET,url:"/asset-type-fields/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(Qn(s))}}class Tf extends P{async bulkAdd(e,s){var r;const n=new Date().toISOString(),a=(r=this.client.store.getState().userReducer.currentUser)==null?void 0:r.id,c=ki(e,s??e.length),o=[],d=[];for(const h of c){const f={},p=[];for(const y of h){const{fieldValuesId:T,fieldIdentifier:_,file:b}=y,E=await this.getFilePayload(b);E.sha1 in f||(f[E.sha1]=E);const se=R({file:URL.createObjectURL(b),file_type:b.type,file_name:b.name,file_sha1:E.sha1,created_by:a,field_values:T,submitted_at:n,field_identifier:_});o.push(se);const Wd={offline_id:se.offline_id,file_name:b.name,file_sha1:E.sha1,file_extension:E.extension,field_identifier:_,field_values:T};p.push(Wd)}d.push({submitted_at:n,attachments:p,files:Object.values(f)})}this.dispatch($e(o));const m=d.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(f=>f.field_values),blocks:h.attachments.map(f=>f.offline_id)}));return Promise.all(m).then(h=>{for(const p of h)this.processPresignedUrls(p.presigned_urls);const f=h.flatMap(p=>p.attachments);this.dispatch(ca(f))}).catch(h=>{throw this.dispatch(Be(o.map(f=>f.offline_id))),h}),[o,m.map(h=>h.then(({attachments:f})=>f))]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=ra(e)(n);this.dispatch(Be(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($e(a)),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.toString()},blockers:[],blocks:[]});this.dispatch(aa(s))}}const bf=t=>Array.isArray(t)&&t[0]instanceof File,Di=t=>{const e={},s={};for(const n in t){const a=t[n];a instanceof File?e[n]=[a]:bf(a)?e[n]=a:a!==void 0&&(s[n]=a)}return{values:s,files:e}};class _f extends P{add(e){var o;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(o=n.userReducer.currentUser)==null?void 0:o.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add form submission",method:l.POST,url:"/form-submissions/",payload:a,blockers:["add-form-entry",e.form_revision,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[a.offline_id]});return this.dispatch(_s(a)),c.then(d=>(this.dispatch(Ye(d)),d)).catch(()=>{this.dispatch(Is(a.offline_id))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=Os(e.offline_id)(n);if(!a)throw new Error(`Expected submission with offline_id ${e.offline_id} to exist`);const c={...a,...e};this.dispatch(qc(c));const o=this.enqueueRequest({description:"Delete user form submissions",method:l.PATCH,url:`/form-submissions/${c.offline_id}/`,payload:e,blockers:[c.offline_id],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Ye(d))}).catch(()=>{this.dispatch(Ye(a))}),[c,o]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Os(e)(n);if(!a)throw new Error(`Expected submission with offline_id ${e} to exist`);const c=wc(e)(n);this.dispatch(Is(e)),this.dispatch(We(c.map(o=>o.offline_id)));try{return await this.enqueueRequest({description:"Delete user form submissions",method:l.DELETE,url:`/form-submissions/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(_s(a)),this.dispatch(He(c)),o}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch form submissions",method:l.GET,url:"/form-submissions/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(Pc(s))}}class If extends F{add(e){var o;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(o=n.userReducer.currentUser)==null?void 0:o.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset type field values",method:l.POST,url:"/asset-type-field-values/",payload:a,blockers:[e.asset,e.fields_revision],blocks:[a.offline_id]});return this.dispatch(Yt(a)),c.then(d=>(this.dispatch(Re(d)),d)).catch(()=>{this.dispatch(Kt(a.offline_id))}),[a,c]}bulkAdd(e,s){var r;const n=new Date().toISOString(),{values:a}=Di(e.values),c=[],o=ki(e.payloads,s??e.payloads.length),d=[];for(const h of o){const f=[];for(const p of h){const y=R({...p,values:Di(p.values).values,created_by:(r=this.client.store.getState().userReducer.currentUser)==null?void 0:r.id,submitted_at:n});c.push(y),f.push({offline_id:y.offline_id,asset:p.asset,fields_revision:p.fields_revision,published_at:p.published_at,values:y.values})}d.push({submitted_at:n,values:a,field_values:f})}this.dispatch(ma(c));const m=[];for(const h of d){const f=h.field_values.map(_=>_.asset),p=h.field_values.map(_=>_.fields_revision),y=h.field_values.map(_=>_.offline_id),T=this.enqueueRequest({description:"Bulk add asset type field values",method:l.POST,url:"/asset-type-field-values/bulk/",payload:h,blockers:[...f,...p],blocks:y});m.push(T)}return Promise.all(m).then(h=>{this.dispatch(fa(h.flat()))}).catch(()=>{this.dispatch(pa(c.map(h=>h.offline_id)))}),[c,m]}update(e){const{store:s}=this.client,n=s.getState(),a=Xt(e.offline_id)(n);if(!a)throw new Error(`Expected AssetTypeFieldValues with offline_id ${e.offline_id} to exist`);const c={...a,...e};this.dispatch(Re(c));const o=this.enqueueRequest({description:"Delete asset type field values",method:l.PATCH,url:`/asset-type-field-values/${e.offline_id}/`,payload:e,blockers:[c.offline_id,c.fields_revision,c.asset],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Re(d))}).catch(()=>{this.dispatch(Re(a))}),[c,o]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Xt(e)(n);if(!a)throw new Error(`Expected submission with offline_id ${e} to exist`);const c=da(e)(n);this.dispatch(Kt(e)),this.dispatch(Be(c.map(o=>o.offline_id)));try{await this.enqueueRequest({description:"Delete asset type field values",method:l.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(Yt(a)),this.dispatch($e(c)),o}}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.toString()},blockers:[],blocks:[]});this.dispatch(ha(s))}}class Rf extends F{add(e){const{store:s}=this.client,n=s.getState().userReducer.currentUser.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Qt(c));const o=this.enqueueRequest({description:"Create asset type",method:l.POST,url:"/asset-types/",payload:c,blockers:[],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Fe(d))}).catch(()=>{this.dispatch(xt(c.offline_id))}),[c,o]}update(e){const{store:s}=this.client,n=ts(e.offline_id)(s.getState());if(!n)throw new Error(`Expected asset type with offline_id ${e.offline_id} to exist`);const a={...n,...e};this.dispatch(Fe(a));const c=this.enqueueRequest({description:"Update asset type",method:l.PATCH,url:`/asset-types/${e.offline_id}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[n.offline_id],blocks:[n.offline_id]});return c.then(o=>{this.dispatch(Fe(o))}).catch(()=>{this.dispatch(Fe(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=ts(e)(n);if(!a)throw new Error(`Expected asset type with offline_id ${e} to exist`);const c=vt(e)(n),o=kn(e)(n),d=Bn(e)(n);return this.dispatch(xt(e)),this.dispatch(An(c.map(m=>m.offline_id))),this.dispatch(ze(o.map(m=>m.offline_id))),this.dispatch($t(d.map(({offline_id:m})=>m))),this.enqueueRequest({description:"Delete asset type",method:l.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(Qt(a)),this.dispatch(Rt(c)),this.dispatch(Ce(o)),this.dispatch(Vt(d)),m})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset types",method:l.GET,url:"/asset-types/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(Sa(s))}}class Ff extends F{add(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(is(c));const o=this.enqueueRequest({description:"Create Category",method:l.POST,url:"/categories/",payload:c,blockers:[e.project.toString()],blocks:[c.offline_id]});return[c,o]}update(e){const s=this.client.store.getState(),n=as(e.offline_id)(s);if(!n)throw new Error(`Expected an existing category with offline_id ${e.offline_id}`);const a={...n,...e};this.dispatch(Oa(a));const c=this.enqueueRequest({description:"Edit Category",method:l.PATCH,url:`/categories/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return[a,c]}remove(e){const{store:s}=this.client,n=as(e)(s.getState());if(!n)throw new Error(`No category with id ${e} found in the store`);this.dispatch(va(e));const a=this.enqueueRequest({description:"Delete Category",method:l.DELETE,url:`/categories/${n.offline_id}/`,blockers:[n.offline_id],blocks:[]});return a.catch(()=>{this.dispatch(is(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get categories",method:l.GET,url:"/categories/",queryParams:{project:e.toString()},blocks:[],blockers:[]});this.dispatch(Fa(s))}}class Of extends ke{constructor(){super(...arguments);A(this,"name","Document Attachment");A(this,"url","/document-attachments");A(this,"addAttachments",Pa);A(this,"updateAttachments",ka);A(this,"removeAttachments",Ca);A(this,"removeAttachment",Da);A(this,"setAttachment",qa);A(this,"selectAttachment",za)}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.modelId})}buildAttachmentPayload(s){return{...s,document:s.modelId}}async bulkAdd(s){var f;const{store:n}=this.client,a=(f=n.getState().userReducer.currentUser)==null?void 0:f.id,c=new Date().toISOString(),o=[],d=[],m={},r={};for(const p of s){const{documentId:y,file:T}=p,_=await this.getFilePayload(T);_.sha1 in m||(m[_.sha1]=_,r[_.sha1]=[]);const b=this.buildOfflineAttachment({file:T,file_sha1:_.sha1,submitted_at:c,created_by:a,description:"",modelId:y});o.push(b),d.push({offline_id:b.offline_id,file_name:b.file_name,file_sha1:b.file_sha1,file_extension:_.extension,description:b.description,document:y}),r[_.sha1].push(b.offline_id)}this.dispatch(this.addAttachments(o));const h=this.enqueueRequest({description:"Attach files to document",method:l.POST,url:"/document-attachments/bulk/",payload:{submitted_at:c,attachments:d,files:Object.values(m)},blocks:o.map(p=>p.offline_id),blockers:o.map(p=>p.file_sha1)});return h.then(({attachments:p,presigned_urls:y})=>{this.dispatch(this.updateAttachments(p));const T=this.processPresignedUrls(y);for(const[_,b]of Object.entries(T))b.then(()=>{const E=r[_];for(const se of E)this.makeReadable(se)})}).catch(()=>{this.dispatch(this.removeAttachments(o.map(p=>p.offline_id)))}),[o,h.then(({attachments:p})=>p)]}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,n){const a=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/projects/${s}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(ja(a));const c=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/organizations/${n}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(this.addAttachments(c))}}class vf extends F{add(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Ba([c]));const o=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.offline_id]});return o.catch(()=>{this.dispatch(ds([c.offline_id]))}),[c,o]}update(e){const{store:s}=this.client,n=s.getState().documentsReducer.documents[e.offline_id];if(!n)throw new Error(`attempting to update a document with offline_id ${e.offline_id} that does not exist in store.documents`);const a={...n,...e};this.dispatch(ne([a]));const c=this.enqueueRequest({description:"Update Document",method:l.PATCH,url:`/documents/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return c.catch(()=>{ne([n])}),[a,c]}move(e,s,n){const{store:a}=this.client,c=pe(a.getState()),o=[],d=c[e];if(!d)throw new Error(`attempting to move a document with offline_id ${e} that does not exist in store.documents`);if(o.push(d),d.parent_document&&o.push(c[d.parent_document]),s){const r=c[s];if(!r)throw new Error(`attempting to move a document to target with offline_id ${s} that does not exist in store.documents`);o.push(r),r.parent_document&&o.push(c[r.parent_document])}this.dispatch(Ga({documentId:e,targetDocumentId:s,position:n}));const m=this.enqueueRequest({description:"Move Document",method:l.PATCH,url:`/documents/${e}/move/`,queryParams:{target:s??void 0,position:n},blockers:[e],blocks:[]});return m.then(r=>{this.dispatch(ne(r))}).catch(()=>{this.dispatch(ne(o))}),m}delete(e){const{store:s}=this.client,n=pe(s.getState()),a=Na(e)(s.getState());if(!a)throw new Error(`attempting to delete a document with offline_id ${e} that does not exist in store.documents`);const c=a.parent_document?n[a.parent_document]:void 0;this.dispatch(ds([e]));const o=this.enqueueRequest({description:"Delete Document",method:l.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return o.then(d=>{this.dispatch(ne(d))}).catch(()=>{this.dispatch(ne([a])),c&&this.dispatch(ne([c]))}),o}async refreshStore(e,s){const n=this.enqueueRequest({description:"Get project documents",method:l.GET,url:`/projects/${e}/documents/`,blockers:[],blocks:[]}),a=this.enqueueRequest({description:"Get organization documents",method:l.GET,url:`/organizations/${s}/documents/`,blockers:[],blocks:[]});this.dispatch($a([...await n,...await a]))}}class wf extends F{async add(e,s){return this.enqueueRequest({description:"Add email domain to organization",method:l.POST,url:`/organizations/${e}/email-domains/`,payload:{email:s},blockers:[e.toString(),"create-org"],blocks:[]})}async remove(e){return this.dispatch(Ka(e.offline_id)),this.enqueueRequest({description:"Remove email domain from organization",method:l.DELETE,url:`/organizations/${e.organization}/email-domains/${e.offline_id}/`,blockers:[e.domain],blocks:[]}).catch(s=>{throw this.dispatch(Ya(e)),s})}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch email domains for organization",method:l.GET,url:`/organizations/${e}/email-domains/`,blockers:[e.toString()],blocks:[]});this.dispatch(Wa(s))}}class Ef extends F{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 at={},Ci=new Set;let ct=0,Mi=0,zi=0;const jf=20;class Pf extends F{constructor(){super(...arguments);A(this,"host");A(this,"_dbPromise",Qd.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 ft(n,s),c=await this.enqueueRequest({description:"Get S3 URL",method:l.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await fe(n),file_type:n.type,extension:n.name.split(".").pop(),size:n.size.toString()},blockers:[],blocks:[`s3-${a}`]});return"url"in c&&this.dispatch(ec({sha1:s,...c})),c}async addCache(s,n){if(Ci.has(n))return;if(!s.type){const o=s.name.split("."),d=o[o.length-1];s=new File([s],s.name,{type:d})}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),ct++):(await a.put("files",s,n),Mi++),Ci.add(n),zi++,zi%jf===0&&console.debug(`File cache summary: ${ct} hits and ${Mi} misses, ${ct/(ct+Mi)*100}% hit rate over ${zi} calls to addCache.`)}async removeCache(s){await(await this._dbPromise).delete("files",s),Ci.delete(s)}async fetchCache(s){return(await this._dbPromise).get("files",s)}async getOrRenewUploadUrl(s){const n=this.client.store.getState();return tc(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 ft(n,s),c={file_name:n.name,file_sha1:s,file:a},o=await this.getOrRenewUploadUrl(s);if("warning"in o){if(o.warning==="already_uploaded")return[c,Promise.resolve(void 0).then()];throw new Error(o.warning)}const d=o.url,m=this.enqueueRequest({url:d,description:"Upload file",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:s,blockers:[`s3-${a}`],blocks:[s],s3url:o});return[c,m]}async fetchFileFromUrl(s,n,a){const c=s.split("?")[0]??s,o=await this.fetchCache(n);if(o){if(!o.name)throw new Error("Cached file unexpectedly has no name.");return o}if(s.startsWith("blob:")){const h=await Xi(s),f=new File([h],a??n,{type:h.type});return await this.addCache(f,n),f}let d=at[c],m=!0;d?m=!1:(d=new Promise(h=>{this.enqueueRequest({description:"Download file",method:l.GET,url:s,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[n],blocks:[n]}).then(f=>{const p=new File([f],a??n,{type:f.type});h(p)})}),at[c]=d);let r;try{r=await d}catch(h){throw m&&h instanceof j&&delete at[c],h}if(m){const h=await fe(r);if(h!==n){const y=`The hash of the file returned from the server (${h}) does not match the
10
10
  expected hash (${n}). This can happen if you're using a local development server and the
11
11
  isExternalUrl flag in the request details is set to true, because instead of requesting the local
12
12
  REST API, you will be requesting localhost:80 (where this app runs), resulting in a transformed blob
13
13
  (with an offline_id attached) being returned. Alternatively, you may be running with
14
14
  import.meta.env.PROD, which will result in some file requests being treated as
15
- external URLs and therefore not prepended with VITE_API_URL.`;throw new Error(y)}const f=r.type.split("/")[1];if(!f)throw new Error("File has no extension");const p=a??h+"."+f;if(r=Xi(r,p),!r.name)throw new Error("Failed to set file's name");await this.addCache(r,h),at[c]=new Promise(y=>{y(r)})}return r}}class qf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{revisionId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,form_revision:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,field_identifier:f,file_extension:y.extension,file_sha1:y.sha1,form_revision:h};o.push(_)}this.dispatch(ac(c));const d=this.enqueueRequest({description:"Attach files to form revision",method:l.POST,url:"/form-revision-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.form_revision),blocks:c.map(r=>r.offline_id)});return d.then(r=>{this.processPresignedUrls(r.presigned_urls),this.dispatch(cc(r.attachments))}).catch(()=>{this.dispatch(oc(c.map(r=>r.offline_id)))}),[c,d.then(({attachments:r})=>r)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization form revision attachments",method:l.GET,url:"/form-revision-attachments/",queryParams:{organization:e.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(nc(s))}}class kf extends P{add(e){var d;const{store:s}=this.client,a=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,c=R({...e,created_by:a,revision:"Pending",submitted_at:new Date().toISOString()});this.dispatch(ps(c));const o=this.enqueueRequest({description:"Create form revision",method:l.POST,url:"/form-revisions/",payload:c,blockers:[e.form],blocks:[c.offline_id]});return o.then(m=>{this.dispatch(uc(m))}).catch(()=>{this.dispatch(ys(c.offline_id))}),[c,o]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization form revisions",method:l.GET,url:"/form-revisions/",queryParams:{organization:e.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(hc(s))}}const Df=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 o of a){if(o.image){if(o.image instanceof Promise)try{e[o.identifier]=await o.image}catch(d){console.error("Failed to get image from promise",d)}else e[o.identifier]=o.image;delete o.image}c.push(o)}s.push({...n,fields:c})}return{fields:s,images:e}};class Cf extends P{add(e,s){var r;const{store:n}=this.client,a=new Date().toISOString(),c=(r=n.getState().userReducer.currentUser)==null?void 0:r.id,o=R({...e,submitted_at:a,created_by:c}),d=R({...s,form:o.offline_id,revision:"Pending",submitted_at:a,created_by:c});this.dispatch(gs(o)),this.dispatch(ps(d));const m=this.enqueueRequest({description:"Create form",method:l.POST,url:"/forms/",payload:{...o,initial_revision:{offline_id:d.offline_id,submitted_at:d.submitted_at,title:d.title,description:d.description,fields:d.fields}},blockers:[],blocks:[o.offline_id,d.offline_id]});return m.catch(h=>{throw this.dispatch(Ss(o.offline_id)),this.dispatch(ys(d.offline_id)),h}),[o,d,m]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Ic(e)(n);if(!a)throw new Error("Expected form to exist");const c=kc(e)(n);c.length>0&&this.dispatch(Je(c.map(({offline_id:d})=>d)));const o=Ac(e)(n);o.length>0&&this.dispatch(fc(o.map(({offline_id:d})=>d))),this.dispatch(Ss(e));try{return await this.enqueueRequest({description:"Delete form",method:l.DELETE,url:`/forms/${e}/`,blockers:[e],blocks:[]})}catch(d){throw this.dispatch(gs(a)),o.length>0&&this.dispatch(mc(o)),c.length>0&&this.dispatch(Ke(c)),d}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization forms",method:l.GET,url:"/forms/",queryParams:{organization:e.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(Tc(s))}}class Mf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{submissionId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,form_submission:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:f,form_submission:h};o.push(_)}this.dispatch(He(c));const d=this.enqueueRequest({description:"Attach files to form submission",method:l.POST,url:"/form-submission-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.form_submission),blocks:c.map(r=>r.offline_id)});return d.then(r=>{this.processPresignedUrls(r.presigned_urls),this.dispatch(Oc(r.attachments))}).catch(r=>{throw this.dispatch(We(c.map(h=>h.offline_id))),r}),[c,d.then(({attachments:r})=>r)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=vc(e)(n);this.dispatch(We(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(He(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get form submission attachments",method:l.GET,url:"/form-submission-attachments/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(Fc(s))}}class zf extends P{async add(e){var f;const{store:s}=this.client,{file:n,...a}=e,c=new Date().toISOString(),o=(f=s.getState().userReducer.currentUser)==null?void 0:f.id,d=a.project,m=await this.getFilePayload(n),r=R({...a,file_name:n.name,file_sha1:m.sha1,file:URL.createObjectURL(n),submitted_at:c,created_by:o});this.dispatch($c(r));const h=this.enqueueRequest({description:"Add geo image",method:l.POST,url:"/geo-images/",payload:{offline_id:r.offline_id,submitted_at:c,title:r.title,description:r.description,geo_marker:r.geo_marker,canvas_marker:r.canvas_marker,sha1:r.file_sha1,project:r.project,file_name:r.file_name,direction:r.direction,original_date:r.original_date,file:m},blocks:[d.toString()],blockers:[d.toString()]});return h.then(p=>{this.processPresignedUrls(p.presigned_urls),this.dispatch(ve(p.geo_image))}).catch(()=>{this.dispatch(Es(r.offline_id))}),[r,h.then(p=>p.geo_image)]}async bulkAdd(e,s){var f;const{store:n}=this.client,a=new Date().toISOString(),c=(f=n.getState().userReducer.currentUser)==null?void 0:f.id,o=[],d=[],m=[],r={};for(const p of e){const{file:y,...T}=p,_=await this.getFilePayload(y);_.sha1 in r||(r[_.sha1]=_);const b=R({...T,file_name:y.name,file_sha1:_.sha1,file:URL.createObjectURL(y),submitted_at:a,created_by:c,project:s});o.push(b),d.push(b.offline_id),m.push({offline_id:b.offline_id,sha1:b.file_sha1,file_name:b.file_name,title:b.title,description:b.description,geo_marker:b.geo_marker,canvas_marker:b.canvas_marker,direction:b.direction,original_date:b.original_date})}this.dispatch(Bc(o));const h=this.enqueueRequest({description:"Bulk add geo images",method:l.POST,url:"/geo-images/bulk/",payload:{submitted_at:a,project:s,geo_images:m,files:Object.values(r)},blocks:[s.toString()],blockers:d});return h.then(p=>{this.processPresignedUrls(p.presigned_urls),this.dispatch(Vc(p.geo_images))}).catch(()=>{this.dispatch(Lc(d))}),[o,h.then(p=>p.geo_images)]}update(e){const{store:s}=this.client,n=s.getState(),a=js(e.offline_id)(n);if(!a)throw new Error(`Map image with offline_id ${e.offline_id} does not exist in the store`);const c={...a,...e};this.dispatch(Gc(c));const o=this.enqueueRequest({description:"Update geo image",method:l.PATCH,url:`/geo-images/${e.offline_id}/`,payload:e,blocks:[e.offline_id],blockers:[e.offline_id]});return o.then(d=>{this.dispatch(ve(d))}).catch(()=>{this.dispatch(ve(a))}),[c,o]}async delete(e){const{store:s}=this.client,n=s.getState(),a=js(e)(n);if(!a)throw new Error(`Map image with offline_id ${e} does not exist in the store`);this.dispatch(Es(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(ve(a))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get geo images",method:l.GET,url:`/projects/${e}/geo-images/`,blocks:[e.toString()],blockers:[]});this.dispatch(Uc(s))}}class Uf extends F{add(e){var d;const{store:s}=this.client,n=new Date().toISOString(),a=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,c=R({...e,submitted_at:n,created_by:a});this.dispatch(qs(c));const o=this.enqueueRequest({description:"Add issue association",method:l.POST,url:"/issue-associations/",payload:{offline_id:c.offline_id,submitted_at:n,...e},blockers:[e.associated_issue,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[c.offline_id]});return o.then(m=>{this.dispatch(Jc(m))}).catch(()=>{this.dispatch(Ds(c.offline_id))}),[c,o]}async delete(e){const{store:s}=this.client,n=Xc(e)(s.getState());if(!n)throw new Error(`Issue association with id ${e} not found in store.`);this.dispatch(Ds(e));const a=this.enqueueRequest({description:"Delete issue association",method:l.DELETE,url:`/issue-associations/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(qs(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch issue associations",method:l.GET,url:"/issue-associations/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(Kc(s))}}class Vf extends ke{constructor(){super(...arguments);A(this,"name","Issue Attachment");A(this,"url","/issue-attachments");A(this,"addAttachments",zs);A(this,"updateAttachments",no);A(this,"removeAttachments",Us);A(this,"removeAttachment",ao);A(this,"setAttachment",io);A(this,"selectAttachment",ro)}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.modelId})}buildAttachmentPayload(s){return{...s,issue:s.modelId}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelId:n.issueId,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s.toString()},blocks:[],blockers:[]});this.dispatch(so(n))}}class $f extends F{add(e){var c;const{store:s}=this.client,n=R({...e,author:(c=s.getState().userReducer.currentUser)==null?void 0:c.id,submitted_at:new Date().toISOString()});this.dispatch(Gs(n));const a=this.enqueueRequest({description:"Add issue comment",method:l.POST,url:"/issue-comments/",payload:n,blockers:[e.issue],blocks:[n.offline_id]});return a.catch(()=>{this.dispatch(Ls(n.offline_id))}),[n,a]}update(e){const{store:s}=this.client,n=fo(e.offline_id)(s.getState());if(!n)throw new Error(`Comment with offline_id ${e.offline_id} not found in store`);const a={...n,...e};this.dispatch(Bs(a));const c=this.enqueueRequest({description:"Edit issue comment",method:l.PATCH,url:`/issue-comments/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return c.catch(()=>{this.dispatch(Bs(n))}),[a,c]}remove(e){const s=this.client.store.getState().issueCommentReducer.instances[e];if(!s)throw new Error(`Comment with offline_id ${e} not found in store`);this.dispatch(Ls(e));const n=this.enqueueRequest({description:"Delete comment",method:l.DELETE,url:`/issue-comments/${e}/`,blockers:[e],blocks:[]});return n.catch(()=>{this.dispatch(Gs(s))}),n}async refreshStore(e){const s=await this.enqueueRequest({description:"Get comments",method:l.GET,url:"/issue-comments/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(ho(s))}}class Bf extends F{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.id,o=R({...e,submitted_at:a,created_by:c});this.dispatch(Hs(o));const d=this.enqueueRequest({description:"Create issue",method:l.POST,url:"/issues/",payload:o,blockers:["add-issue",o.project.toString()],blocks:[o.offline_id]});return d.then(r=>{this.dispatch(Xe(r))}).catch(r=>{throw this.dispatch(Ws(o.offline_id)),r}),[o,d]}update(e){var m;const s=this.client.store.getState(),n=Ys(e.offline_id)(s);if(!n)throw new Error(`Attempting to update an issue with offline_id ${e.offline_id} that doesn't exist in the store`);const a={...n,...e};this.dispatch(Xe(a));const c={};for(const r of[v.TITLE,v.DESCRIPTION,v.STATUS,v.CATEGORY,v.PRIORITY,v.ASSIGNED_TO,v.DUE_DATE])if(r in e&&e[r]!==n[r])switch(r){case v.PRIORITY:case v.STATUS:{const h=e[r];c[r]=h!==void 0?Number(h):null;break}case v.DUE_DATE:case v.DESCRIPTION:case v.TITLE:c[r]=e[r]??null;break;case v.CATEGORY:{let h=null;const f=e[r];if(f&&(h=s.categoryReducer.instances[f]??null,!h))throw new Error(`Trying to update issue category to ${f} which does not exist in store`);c[r]=h?{name:h.name,color:h.color,offline_id:h.offline_id}:null;break}case v.ASSIGNED_TO:{let h=null;const f=e[r];if(f&&(h=s.userReducer.users[f]??null,!h))throw new Error(`Trying to update issue assigned_to to ${f} which does not exist in store`);c[r]=h?{full_name:h.username,id:h.id}:null;break}}const o=R({created_by:(m=s.userReducer.currentUser)==null?void 0:m.id,submitted_at:new Date().toISOString(),issue:n.offline_id,changes:c});this.dispatch(ir(o));const d=this.enqueueRequest({description:"Edit issue",method:l.PATCH,url:`/issues/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return d.catch(()=>{this.dispatch(Xe(n)),this.dispatch(ar(o.offline_id))}),[a,d]}async remove(e){const{store:s}=this.client,n=s.getState(),a=Ys(e)(n);if(!a)throw new Error(`No issue with id ${e} found in the store`);const c=oo(e)(n),o=rr(e)(n),d=Dc(e)(n),m={};for(const h of Zc(e)(n))m[h.offline_id]=h;for(const h of Qc(e)(n))m[h.offline_id]=h;const r=Object.values(m);this.dispatch(Ws(e)),c.length>0&&this.dispatch(Us(c.map(({offline_id:h})=>h))),o.length>0&&this.dispatch(cr(o.map(({offline_id:h})=>h))),d.length>0&&this.dispatch(Je(d.map(({offline_id:h})=>h))),r.length>0&&this.dispatch(Cs(r.map(({offline_id:h})=>h)));try{return await this.enqueueRequest({description:"Delete issue",method:l.DELETE,url:`/issues/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(Hs(a)),this.dispatch(zs(c)),this.dispatch(nr(o)),this.dispatch(Ke(d)),this.dispatch(ks(r)),h}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issues",method:l.GET,url:"/issues/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(Ao(s))}}class Gf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{fieldsRevisionId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,fields_revision:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,file_extension:y.extension,field_identifier:f,file_sha1:y.sha1,fields_revision:h};o.push(_)}this.dispatch(Ro(c));const d=this.enqueueRequest({description:"Add issue type fields attachments",method:l.POST,url:"/issue-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.fields_revision),blocks:c.map(r=>r.offline_id)});return d.then(r=>{this.processPresignedUrls(r.presigned_urls),this.dispatch(Fo(r.attachments))}).catch(()=>{this.dispatch(Oo(c.map(r=>r.offline_id)))}),[c,d.then(({attachments:r})=>r)]}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.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(Io(s))}}class Lf extends F{add(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Mo(c));const o=this.enqueueRequest({description:"Add Issue Type Fields",method:l.POST,url:"/issue-type-fields/",payload:c,blockers:[c.issue_type],blocks:[c.offline_id]});return o.then(m=>{this.dispatch(zo(m))}).catch(m=>{throw this.dispatch(Uo(c.offline_id)),m}),[c,o]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Issue Type Fields",method:l.GET,url:"/issue-type-fields/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(Co(s))}}class Nf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{fieldValuesId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,field_values:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:f,field_values:h};o.push(_)}this.dispatch(Qe(c));const d=this.enqueueRequest({description:"Add issue type field values attachments",method:l.POST,url:"/issue-type-field-values-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.field_values),blocks:c.map(r=>r.offline_id)});return d.then(({presigned_urls:r,attachments:h})=>{this.processPresignedUrls(r),this.dispatch(Lo(h))}).catch(r=>{throw this.dispatch(xe(c.map(h=>h.offline_id))),r}),[c,d.then(({attachments:r})=>r)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=Ho(e)(n);this.dispatch(xe(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(Qe(a)),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.toString()},blockers:[],blocks:[]});this.dispatch(Go(s))}}class Hf extends F{add(e){var o;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(o=n.userReducer.currentUser)==null?void 0:o.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add issue type field values",method:l.POST,url:"/issue-type-field-values/",payload:a,blockers:[e.issue,e.fields_revision],blocks:[a.offline_id]});return this.dispatch(Xs(a)),c.then(d=>(this.dispatch(Ee(d)),d)).catch(()=>{this.dispatch(Zs(a.offline_id))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=xs(e.offline_id)(n);if(!a)throw new Error(`Expected IssueTypeFieldValues with offline_id ${e.offline_id} to exist`);const c={...a,...e};this.dispatch(Ee(c));const o=this.enqueueRequest({description:"Update issue type field values",method:l.PATCH,url:`/issue-type-field-values/${e.offline_id}/`,payload:e,blockers:[c.offline_id,c.fields_revision,c.issue],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Ee(d))}).catch(()=>{this.dispatch(Ee(a))}),[c,o]}async delete(e){const{store:s}=this.client,n=s.getState(),a=xs(e)(n);if(!a)throw new Error(`Expected submission with offline_id ${e} to exist`);const c=Wo(e)(n);this.dispatch(Zs(e)),this.dispatch(xe(c.map(o=>o.offline_id)));try{await this.enqueueRequest({description:"Delete issue type field values",method:l.DELETE,url:`/issue-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(Xs(a)),this.dispatch(Qe(c)),o}}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.toString()},blockers:[],blocks:[]});this.dispatch(Po(s))}}class Wf extends F{add(e){var o;const{store:s}=this.client,n=s.getState(),a=R({...e,submitted_at:new Date().toISOString(),created_by:(o=n.userReducer.currentUser)==null?void 0:o.id});this.dispatch(Xo(a));const c=this.enqueueRequest({method:l.POST,url:"/issue-types/",payload:a,blockers:[],blocks:[a.offline_id]});return c.then(d=>{this.dispatch(je(d))}).catch(()=>{this.dispatch(ni(a.offline_id))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=ai(e.offline_id)(n);if(!a)throw new Error(`IssueType with offline_id ${e.offline_id} does not exist in the store.`);const c={...a,...e};this.dispatch(Zo(c));const o=this.enqueueRequest({method:l.PATCH,url:`/issue-types/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return o.then(d=>{this.dispatch(je(d))}).catch(()=>{this.dispatch(je(a))}),[c,o]}delete(e){const{store:s}=this.client,n=s.getState(),a=ai(e)(n);if(!a)throw new Error(`IssueType with offline_id ${e} does not exist in the store.`);const c=ci(e)(n);this.dispatch(ni(e)),this.dispatch(So(c.map(d=>d.offline_id)));const o=this.enqueueRequest({method:l.DELETE,url:`/issue-types/${e}/`,blockers:[e],blocks:[]});return o.catch(()=>{this.dispatch(je(a)),this.dispatch(go(c))}),o}async refreshStore(e){const s=await this.enqueueRequest({method:l.GET,url:"/issue-types/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(Jo(s))}}class Yf extends F{async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue updates",method:l.GET,url:"/issue-updates/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(sr(s))}}class Kf extends jd{constructor(e){super(e)}}const Jf=1800;function Xf(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 Zf extends Kf{constructor(){super(...arguments);A(this,"_getRenewedTokens",async s=>{const n=this.enqueueRequest({description:"Get renewed tokens",method:l.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(Ia(!1)),this.clearTokens(),this.dispatch({type:xd.RESET_STATE}),this.dispatch({type:Ud})}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=el(s).exp??n}catch{a=n}return a-n<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 j&&this.clearAuth(),s instanceof Error?Promise.reject(s):Promise.reject(new Error((s??Te).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 j({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 j({message:"Incorrect username or password.",response:n,discard:!0})}async initAuth(s){const n=O.v4();return console.debug(this.constructor.name,"Initiating auth"),this.enqueueRequest({uuid:n,description:"Get token pair",method:l.POST,url:this.initTokensUrl,payload:s,isAuthNeeded:!1,checkAuth:!1,immediate:!0,blockers:[],blocks:[]}).then(a=>{this.setTokens(Xf(a))})}}class Qf extends F{async getLicense(e){const s=await this.enqueueRequest({description:"Get license",method:l.GET,url:`/billing/${e.offline_id}/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:[]});return this.dispatch(te(s)),s}async pauseLicense(e){const s=await this.enqueueRequest({description:"Pause license",method:l.DELETE,url:`/billing/${e.offline_id}/suspend/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:[]});return this.dispatch(te(s)),s}async resumeLicense(e){const s=await this.enqueueRequest({description:"Resume license",method:l.PATCH,url:`/billing/${e.offline_id}/suspend/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:[]});return this.dispatch(te(s)),s}async cancelLicense(e){const s=await this.enqueueRequest({description:"Cancel license",method:l.DELETE,url:`/billing/${e.offline_id}/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:[]});return this.dispatch(te(s)),s}async attachLicenseToProject(e,s){const n=await this.enqueueRequest({description:"Attach license",method:l.PATCH,url:`/billing/${e.offline_id}/project/`,isAuthNeeded:!0,payload:{project:s.id},blockers:[e.organization_owner?e.organization_owner.toString():"",s.id?s.id.toString():""],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});return this.dispatch(te(n)),n}async detachLicenseFromProject(e){const s=await this.enqueueRequest({description:"Detach license",method:l.DELETE,url:`/billing/${e.offline_id}/project/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});return this.dispatch(te(s)),s}async getLatestTransaction(e){return await this.enqueueRequest({description:"Get latest transaction",method:l.GET,url:`/billing/${e.offline_id}/transaction/`,isAuthNeeded:!0,blockers:[e.offline_id],blocks:[e.offline_id]})}async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Get licenses",method:l.GET,url:`/organizations/${s}/licenses/`,isAuthNeeded:!0,blockers:[s.toString()],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});for(const o of a)n[o.offline_id]=o;const c=await this.enqueueRequest({description:"Get licenses",method:l.GET,url:`/projects/${e}/licenses/`,isAuthNeeded:!0,blockers:[e.toString()],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});for(const o of c)n[o.offline_id]=o;this.dispatch(ur(Object.values(n)))}}class xf extends F{async update(e){const s=this.enqueueRequest({description:"Edit organization access",method:l.PATCH,url:`/organizations/${e.organization}/access/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return s.then(()=>{this.dispatch(Tr(e))}),s}async remove(e){return this.dispatch(br(e.offline_id)),this.dispatch(yr(e.user)),this.enqueueRequest({description:"Remove organization access",method:l.DELETE,url:`/organizations/${e.organization}/access/${e.offline_id}/`,blockers:[e.offline_id],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization accesses",method:l.GET,url:`/organizations/${e}/access/`,blockers:[],blocks:[]});this.dispatch(Sr(s))}}class ep extends F{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.id}/`,payload:e,blockers:[`add-org-${e.name}`,e.id.toString()],blocks:[e.id.toString()]})}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 n={},a=await this.enqueueRequest({description:"Get organizations",method:l.GET,url:`/projects/${e}/organizations/`,blockers:[],blocks:[]});for(const o of a)n[o.id]=o;const c=await this.enqueueRequest({description:"Get organization",method:l.GET,url:`/organizations/${s}/`,blockers:[],blocks:[]});n[c.id]=c,this.dispatch($r(Object.values(n)))}}class tp extends F{async update(e){return this.dispatch(Fr(e)),this.enqueueRequest({description:"Edit project access",method:l.PATCH,url:`/access/${e.offline_id}/`,payload:e,blockers:[e.offline_id,"change-access-level"],blocks:[e.offline_id]})}async remove(e){return this.dispatch(Or(e)),this.enqueueRequest({description:"Delete project access",method:l.DELETE,url:`/access/${e}/`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project accesses",method:l.GET,url:`/projects/${e}/access/`,blockers:[],blocks:[]});this.dispatch(mi(s))}}class sp extends ke{constructor(){super(...arguments);A(this,"name","Project Attachment");A(this,"url","/project-attachments");A(this,"addAttachments",ed);A(this,"updateAttachments",id);A(this,"removeAttachments",Ti);A(this,"removeAttachment",nd);A(this,"setAttachment",td);A(this,"selectAttachment",cd)}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.modelId})}buildAttachmentPayload(s){return{...s,project:s.modelId}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelId:n.projectId,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get project attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s.toString()},blockers:[],blocks:[]});this.dispatch(xr(n))}}class ip extends F{async saveExisting(e){if(!e.offline_id)throw new Error("You can only use this method to save existing project files. The one provided has no offline_id.");const s={...e};delete s.file;const n=this.enqueueRequest({method:l.PATCH,url:`/projects/files/${e.offline_id}/`,payload:s,blockers:[e.offline_id],blocks:[e.offline_id]});return n.then(a=>{this.dispatch(Ii(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:l.PATCH,url:`/projects/files/${n}/`,payload:m,blockers:[n],blocks:[n]}}else c=new Promise((m,r)=>{this.client.files.uploadFileToS3(a.file_sha1).then(([h])=>{m({method:l.POST,url:`/projects/${a.project}/files/`,payload:{...a,...h},blockers:[n],blocks:[n]})}).catch(r)});const d=Promise.resolve(c).then(m=>this.enqueueRequest(m));return d.then(m=>{this.dispatch(Ii(m))}),this.dispatch(yd),this.dispatch(pd(null)),this.dispatch(fd(!1)),[a,d]}delete(e){return this.dispatch(hd(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(ld(s))}}class np extends F{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(kr(e)),await this.enqueueRequest({description:"Update project",method:l.PATCH,url:`/projects/${e.id}/`,payload:{name:e.name,bounds:e.bounds},blockers:[e.id.toString()],blocks:[e.id.toString()]})}async delete(e){const{store:s}=this.client,n=s.getState(),a=yi(n),c=a[e];if(!c)throw new Error("Expected project to exist");const o=gd(n).filter(h=>h.project===e);this.dispatch(md(o.map(({offline_id:h})=>h)));const d=od(c.id)(n);this.dispatch(Ti(d.map(({offline_id:h})=>h)));const m=wr(n);this.dispatch(vr(m.map(({offline_id:h})=>h))),this.dispatch({type:"rehydrated/setRehydrated",payload:!1}),this.dispatch(Dr(c));const r=hr(c.id)(n);r&&this.dispatch(te({...r,project:null}));try{await this.enqueueRequest({description:"Delete project",method:l.DELETE,url:`/projects/${e}/`,blockers:[e.toString()],blocks:[]}),this.dispatch({type:"rehydrated/setRehydrated",payload:!0})}catch(h){throw this.dispatch(qr(Object.values(a))),this.dispatch(mi(Object.values(m))),this.dispatch(ud(o)),this.dispatch(sd(d)),this.dispatch({type:"rehydrated/setRehydrated",payload:!0}),r&&this.dispatch(te({...r,project:c.id})),h}}invite(e,s){const n=O.v4();return this.enqueueRequest({description:"Invite user to project",method:l.POST,url:`/projects/${e}/invite/${s}/`,payload:{offline_id:n},blockers:[],blocks:[n]})}joinProject(e,s,n){return this.enqueueRequest({description:"Join project",method:l.GET,url:`/projects/${e}/join-project/${s}/${n}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}async acceptInvite(e){return this.enqueueRequest({description:"Accept project invite",method:l.PATCH,url:`/projects/${e}/accept-invite/`,blockers:[e.toString()],blocks:[e.toString()]}).then(()=>{this.dispatch(Cr(e))})}}class ap extends F{add(e){const s=R({...e,submitted_at:new Date().toISOString()});this.dispatch(Id(s));const n=this.enqueueRequest({description:"Create team",method:l.POST,url:`/organizations/${e.organization}/teams/`,payload:s,blockers:[],blocks:[s.offline_id]});return n.then(a=>{this.dispatch(ge(a))}).catch(()=>{this.dispatch(vi(s.offline_id))}),[s,n]}update(e){const{store:s}=this.client,n=Se(e.offline_id)(s.getState());if(!n)throw new Error(`Expected team with offline_id ${e.offline_id} to exist`);const a={...n,...e};this.dispatch(Oi(a));const c=this.enqueueRequest({description:"Update team",method:l.PATCH,url:`/organizations/teams/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return c.then(o=>{this.dispatch(ge(o))}).catch(()=>{this.dispatch(ge(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Se(e)(n);if(!a)throw new Error(`Expected team with id ${e} to exist`);this.dispatch(vi(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(ge(a)),c}}async setMembers(e,s){const{store:n}=this.client,a=Se(e)(n.getState());if(!a)throw new Error(`Expected team with id ${e} to exist`);if(s.length!==new Set(s).size)throw new Error("Duplicate members found in the list");this.dispatch(Oi({...a,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(ge(a))}),c}async addMembers(e,s){const{store:n}=this.client,a=Se(e)(n.getState());if(!a)throw new Error(`Expected team with id ${e} to exist`);const c=[...a.members,...s];return this.setMembers(e,c)}async removeMembers(e,s){const{store:n}=this.client,a=Se(e)(n.getState());if(!a)throw new Error(`Expected team with id ${e} to exist`);const c=a.members.filter(o=>!s.includes(o));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(_d(s))}}class cp extends F{async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Fetch organization users",method:l.GET,url:`/organizations/${s}/users/`,blockers:[],blocks:[]});for(const o of a)n[o.id]=o;const c=await this.enqueueRequest({description:"Fetch project users",method:l.GET,url:`/projects/${e}/users/`,blockers:[],blocks:[]});for(const o of c)n[o.id]=o;this.dispatch(pr(Object.values(n)))}}var Nd=(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))(Nd||{});i.APIError=j,i.AgentService=hf,i.AssetAttachmentService=mf,i.AssetService=ff,i.AssetStageCompletionService=pf,i.AssetStageService=yf,i.AssetTypeAttachmentService=Af,i.AssetTypeFieldValuesAttachmentService=Tf,i.AssetTypeFieldValuesService=If,i.AssetTypeFieldsAttachmentService=gf,i.AssetTypeFieldsService=Sf,i.AssetTypeService=Rf,i.AttachmentModel=Gi,i.BaseApiService=F,i.BaseSDK=lf,i.CategoryService=Ff,i.DEFAULT_ISSUE_PRIORITY=sl,i.DEFAULT_ISSUE_STATUS=tl,i.DeferredPromise=Yi,i.DocumentAttachmentService=Of,i.DocumentService=vf,i.EMPTY_ARRAY=$i,i.EMPTY_OBJECT=Bi,i.EmailDomainsService=wf,i.EmailVerificationService=Ef,i.FileService=Pf,i.FormRevisionAttachmentService=qf,i.FormRevisionService=kf,i.FormService=Cf,i.FormSubmissionAttachmentService=Mf,i.FormSubmissionService=_f,i.GeoImageService=zf,i.HttpMethod=l,i.IssueAssociationService=Uf,i.IssueAttachmentService=Vf,i.IssueCommentService=$f,i.IssuePriority=dt,i.IssueService=Bf,i.IssueStatus=lt,i.IssueTypeFieldValuesAttachmentService=Nf,i.IssueTypeFieldValuesService=Hf,i.IssueTypeFieldsAttachmentService=Gf,i.IssueTypeFieldsService=Lf,i.IssueTypeService=Wf,i.IssueUpdateChange=v,i.IssueUpdateService=Yf,i.JWTService=Zf,i.LicenseLevel=Ni,i.LicenseService=Qf,i.LicenseStatus=Hi,i.OUTBOX_RETRY_DELAY=Wi,i.OrganizationAccessLevel=rt,i.OrganizationAccessService=xf,i.OrganizationService=ep,i.OutboxCoordinator=be,i.PaddleCheckoutEvent=Li,i.ProjectAccessLevel=ot,i.ProjectAccessService=tp,i.ProjectAttachmentService=sp,i.ProjectFileService=ip,i.ProjectService=np,i.TeamService=ap,i.UNKNOWN_ERROR_MESSAGE=Te,i.UserService=cp,i.VERSION_REDUCER_KEY=ji,i.VerificationCodeType=Nd,i._selectLatestFormRevision=yc,i._setLatestRetryTime=Xr,i.acceptProjectInvite=Cr,i.addAsset=It,i.addAssetAttachment=Ol,i.addAssetAttachments=St,i.addAssetStage=zl,i.addAssetStageCompletion=jt,i.addAssetStageCompletions=Pt,i.addAssetStages=Ce,i.addAssetType=Qt,i.addAssetTypeAttachment=$l,i.addAssetTypeAttachments=Vt,i.addAssetTypeFieldValues=Yt,i.addAssetTypeFieldValuesAttachment=au,i.addAssetTypeFieldValuesAttachments=$e,i.addAssetTypeFieldValuesMany=fa,i.addAssetTypeFields=ea,i.addAssetTypeFieldsAttachment=Nl,i.addAssetTypeFieldsAttachments=Wn,i.addAssetTypeFieldsMany=Zl,i.addAssetTypes=Au,i.addAssets=Rt,i.addCategory=is,i.addConversation=nn,i.addDocumentAttachment=Eu,i.addDocumentAttachments=qa,i.addDocuments=ds,i.addEmailDomain=Ya,i.addForm=gs,i.addFormRevision=ps,i.addFormRevisionAttachment=$u,i.addFormRevisionAttachments=ac,i.addFormRevisions=mc,i.addFormSubmission=Is,i.addFormSubmissionAttachment=eh,i.addFormSubmissionAttachments=He,i.addFormSubmissions=Ke,i.addForms=Xu,i.addGeoImage=$c,i.addGeoImages=Bc,i.addIssue=Hs,i.addIssueAssociation=qs,i.addIssueAssociations=ks,i.addIssueAttachment=mh,i.addIssueAttachments=zs,i.addIssueComment=Gs,i.addIssueComments=Ah,i.addIssueType=Xo,i.addIssueTypeFieldValues=Xs,i.addIssueTypeFieldValuesAttachment=Lh,i.addIssueTypeFieldValuesAttachments=Qe,i.addIssueTypeFieldValuesMany=wh,i.addIssueTypeFields=Mo,i.addIssueTypeFieldsAttachment=bh,i.addIssueTypeFieldsAttachments=Ro,i.addIssueTypeFieldsMany=Dh,i.addIssueUpdate=ir,i.addIssueUpdates=nr,i.addIssues=go,i.addLicenses=xh,i.addProjectAttachment=Im,i.addProjectAttachments=ed,i.addProjectFile=wm,i.addProjectFiles=ud,i.addTeam=Id,i.addUsers=am,i.agentsReducer=on,i.agentsSlice=pt,i.areArraysEqual=cl,i.assetAttachmentReducer=pn,i.assetAttachmentSlice=At,i.assetReducer=Tn,i.assetSlice=_t,i.assetStageCompletionReducer=vn,i.assetStageCompletionSlice=Et,i.assetStageReducer=Pn,i.assetStageSlice=Ct,i.assetTypeAttachmentReducer=Ln,i.assetTypeAttachmentSlice=Ut,i.assetTypeFieldValuesAttachmentReducer=ua,i.assetTypeFieldValuesAttachmentSlice=Nt,i.assetTypeFieldValuesReducer=ga,i.assetTypeFieldValuesSlice=Wt,i.assetTypeFieldsAttachmentReducer=Zn,i.assetTypeFieldsAttachmentSlice=Gt,i.assetTypeFieldsReducer=na,i.assetTypeFieldsSlice=Lt,i.assetTypeReducer=ba,i.assetTypeSlice=Zt,i.authReducer=Ra,i.authSlice=Ge,i.blobToBase64=pl,i.categoryReducer=Ea,i.categorySlice=ss,i.clearTokens=Iu,i.constructUploadedFilePayloads=fl,i.coordinatesAreEqual=al,i.createModelAdapter=I,i.createMultiPointGeometry=nl,i.createOfflineAction=Wr,i.createPointGeometry=il,i.deleteAsset=Ft,i.deleteAssetAttachment=un,i.deleteAssetAttachments=Tt,i.deleteAssetStage=Ul,i.deleteAssetStageCompletion=qt,i.deleteAssetStageCompletions=kt,i.deleteAssetStages=ze,i.deleteAssetType=xt,i.deleteAssetTypeAttachment=Vn,i.deleteAssetTypeAttachments=$t,i.deleteAssetTypeFieldValues=Kt,i.deleteAssetTypeFieldValuesAttachment=du,i.deleteAssetTypeFieldValuesAttachments=Be,i.deleteAssetTypeFieldValuesMany=ya,i.deleteAssetTypeFields=sa,i.deleteAssetTypeFieldsAttachment=Kl,i.deleteAssetTypeFieldsAttachments=Kn,i.deleteAssetTypeFieldsMany=tu,i.deleteAssetTypes=Su,i.deleteAssets=gn,i.deleteCategory=wa,i.deleteDocumentAttachment=Ca,i.deleteDocumentAttachments=Ma,i.deleteEmailDomain=Ka,i.deleteForm=Ss,i.deleteFormRevision=ys,i.deleteFormRevisionAttachment=Nu,i.deleteFormRevisionAttachments=oc,i.deleteFormRevisions=fc,i.deleteFormSubmission=Rs,i.deleteFormSubmissionAttachment=nh,i.deleteFormSubmissionAttachments=We,i.deleteFormSubmissions=Je,i.deleteGeoImage=Es,i.deleteGeoImages=Lc,i.deleteIssue=Ws,i.deleteIssueAssociation=Ds,i.deleteIssueAssociations=Cs,i.deleteIssueAttachment=ao,i.deleteIssueAttachments=Us,i.deleteIssueComment=Ls,i.deleteIssueComments=gh,i.deleteIssueTypeFieldValues=Zs,i.deleteIssueTypeFieldValuesAttachment=Yh,i.deleteIssueTypeFieldValuesAttachments=xe,i.deleteIssueTypeFieldValuesMany=qh,i.deleteIssueTypeFields=Uo,i.deleteIssueTypeFieldsAttachment=Fh,i.deleteIssueTypeFieldsAttachments=Oo,i.deleteIssueTypeFieldsMany=Uh,i.deleteIssueUpdate=ar,i.deleteIssueUpdates=cr,i.deleteIssues=So,i.deleteOrganizationAccess=br,i.deleteProject=Dr,i.deleteProjectAccess=Or,i.deleteProjectAccesses=vr,i.deleteProjectAttachment=nd,i.deleteProjectAttachments=Ti,i.deleteProjectFile=hd,i.deleteProjectFiles=md,i.deleteTeam=vi,i.dequeue=$d,i.discard=ki,i.documentAttachmentReducer=Va,i.documentAttachmentSlice=cs,i.documentSlice=rs,i.documentsReducer=Ha,i.downloadFile=yl,i.downloadInMemoryFile=ml,i.emailDomainsReducer=Za,i.emailDomainsSlice=us,i.emailRegex=Il,i.enqueue=Vd,i.enqueueRequest=Kr,i.fallbackToEmptyArray=S,i.fallbackToEmptyObject=ae,i.fileReducer=sc,i.fileSlice=hs,i.fileToBlob=Zi,i.formReducer=bc,i.formRevisionAttachmentReducer=dc,i.formRevisionAttachmentSlice=ms,i.formRevisionReducer=gc,i.formRevisionsSlice=fs,i.formSlice=As,i.formSubmissionAttachmentReducer=Ec,i.formSubmissionAttachmentSlice=Ts,i.formSubmissionReducer=Mc,i.formSubmissionSlice=_s,i.geoImageReducer=Wc,i.geoImageSlice=ws,i.getFileIdentifier=hl,i.getFileS3Key=ft,i.getLocalDateString=Ji,i.getLocalRelativeDateString=ll,i.getOutboxCoordinator=ue,i.getRenamedFile=Xi,i.hashFile=fe,i.initSDK=uf,i.initializeAssetAttachments=gt,i.initializeAssetStageCompletions=_n,i.initializeAssetStages=En,i.initializeAssetTypeAttachments=Mn,i.initializeAssetTypeFieldValues=ma,i.initializeAssetTypeFieldValuesAttachments=ca,i.initializeAssetTypeFields=xn,i.initializeAssetTypeFieldsAttachments=Hn,i.initializeAssetTypes=Ta,i.initializeAssets=An,i.initializeCategories=Oa,i.initializeConversations=sn,i.initializeDocumentAttachments=Pa,i.initializeEmailDomains=Wa,i.initializeFormRevisionAttachments=nc,i.initializeFormRevisions=hc,i.initializeFormSubmissionAttachments=Fc,i.initializeFormSubmissions=Pc,i.initializeForms=Tc,i.initializeGeoImages=Uc,i.initializeIssueAssociations=Kc,i.initializeIssueAttachments=so,i.initializeIssueTypeFieldValues=Po,i.initializeIssueTypeFieldValuesAttachments=Go,i.initializeIssueTypeFields=Co,i.initializeIssueTypeFieldsAttachments=Io,i.initializeIssueTypes=Jo,i.initializeIssueUpdates=sr,i.initializeIssues=Ao,i.initializeLicences=ur,i.initializeOrganizationAccesses=Sr,i.initializeProjectAccesses=mi,i.initializeProjectAttachments=xr,i.initializeProjectFiles=ld,i.initializeTeams=_d,i.isToday=dl,i.issueAssociationReducer=eo,i.issueAssociationSlice=Ps,i.issueAttachmentReducer=lo,i.issueAttachmentSlice=Ms,i.issueCommentReducer=po,i.issueCommentSlice=$s,i.issueReducer=bo,i.issueSlice=Ns,i.issueTypeFieldValuesAttachmentReducer=Yo,i.issueTypeFieldValuesAttachmentSlice=ti,i.issueTypeFieldValuesReducer=ko,i.issueTypeFieldValuesSlice=Js,i.issueTypeFieldsAttachmentReducer=Eo,i.issueTypeFieldsAttachmentSlice=Ks,i.issueTypeFieldsReducer=$o,i.issueTypeFieldsSlice=ei,i.issueTypeReducer=er,i.issueTypeSlice=ii,i.issueUpdateReducer=dr,i.issueUpdateSlice=oi,i.licenseReducer=mr,i.licenseSlice=ri,i.logOnlyOnce=Al,i.markAsDeleted=Jr,i.markForDeletion=_m,i.memoize=ht,i.moveDocument=Ga,i.offline=R,i.onlyUniqueHashes=_l,i.onlyUniqueOfflineIds=en,i.organizationAccessReducer=Ir,i.organizationAccessSlice=li,i.organizationReducer=Hr,i.organizationSlice=Ai,i.outboxReducer=Zr,i.outboxSlice=gi,i.overmapEnhancer=Qm,i.overmapReducers=Md,i.overmapRootReducer=Ym,i.performRequest=qi,i.projectAccessReducer=jr,i.projectAccessSlice=hi,i.projectAttachmentReducer=rd,i.projectAttachmentSlice=Si,i.projectFileReducer=Sd,i.projectFileSlice=_i,i.projectReducer=Mr,i.projectSlice=pi,i.rehydratedReducer=Td,i.rehydratedSlice=Ri,i.removeDocuments=ls,i.removeIssueType=ni,i.removeUser=yr,i.resetProjectFileObjectUrls=jm,i.resetStore=Ud,i.restructureCreateSelectorWithArgs=g,i.saveActiveProjectFileBounds=yd,i.selectAccessToken=Ru,i.selectActiveOrganizationAccess=dm,i.selectActiveProjectFileId=qm,i.selectActiveStatusLicenses=tm,i.selectAllDocumentAttachments=os,i.selectAllProjectAttachments=bi,i.selectAncestorIdsOfDocument=Cu,i.selectAssetAttachmentById=mn,i.selectAssetAttachmentMapping=hn,i.selectAssetAttachments=bt,i.selectAssetById=wt,i.selectAssetStageById=qn,i.selectAssetStageCompletionById=Fn,i.selectAssetStageCompletionMapping=Dt,i.selectAssetStageCompletionsByIds=On,i.selectAssetStages=kn,i.selectAssetStagesByIds=zt,i.selectAssetTypeAttachmentById=Bn,i.selectAssetTypeAttachmentMapping=$n,i.selectAssetTypeAttachments=Bt,i.selectAssetTypeById=ts,i.selectAssetTypeFieldValues=Jt,i.selectAssetTypeFieldValuesAttachmentById=lu,i.selectAssetTypeFieldValuesAttachments=ra,i.selectAssetTypeFieldValuesAttachmentsByIds=da,i.selectAssetTypeFieldValuesAttachmentsMapping=Ht,i.selectAssetTypeFieldValuesById=Xt,i.selectAssetTypeFieldValuesMapping=Aa,i.selectAssetTypeFieldValuesOfAsset=mu,i.selectAssetTypeFields=Ve,i.selectAssetTypeFieldsAttachmentById=Xl,i.selectAssetTypeFieldsAttachments=Xn,i.selectAssetTypeFieldsAttachmentsMapping=Jn,i.selectAssetTypeFieldsById=nu,i.selectAssetTypeFieldsMapping=ia,i.selectAssetTypeFieldsOfAssetType=su,i.selectAssetTypeStagesMapping=Vl,i.selectAssetTypeValuesOfAssetType=fu,i.selectAssetTypes=Tu,i.selectAssetTypesByIds=bu,i.selectAssetTypesMapping=es,i.selectAssets=Sn,i.selectAssetsByIds=kl,i.selectAssetsMapping=Ot,i.selectAssetsOfAssetType=vt,i.selectAttachmentsOfAsset=fn,i.selectAttachmentsOfAssetByType=El,i.selectAttachmentsOfAssetType=Gn,i.selectAttachmentsOfAssetTypeByType=Ll,i.selectAttachmentsOfAssetTypeFieldValues=la,i.selectAttachmentsOfAssetTypeFields=Jl,i.selectAttachmentsOfDocument=qu,i.selectAttachmentsOfDocumentByType=ku,i.selectAttachmentsOfFormRevision=Hu,i.selectAttachmentsOfFormSubmission=wc,i.selectAttachmentsOfIssue=oo,i.selectAttachmentsOfIssueByType=yh,i.selectAttachmentsOfIssueTypeFieldValues=Wo,i.selectAttachmentsOfIssueTypeFields=Oh,i.selectAttachmentsOfProject=od,i.selectAttachmentsOfProjectByType=Fm,i.selectCategories=Ou,i.selectCategoriesByIds=vu,i.selectCategoryById=as,i.selectCategoryMapping=ns,i.selectCommentsOfIssue=Sh,i.selectCompletedStagesByAsset=Cl,i.selectConversation=Fl,i.selectConversationMapping=yt,i.selectConversations=Rl,i.selectCurrentUser=st,i.selectDeletedRequests=Tm,i.selectDocumentAttachmentById=Ua,i.selectDocumentAttachmentMapping=za,i.selectDocumentById=Na,i.selectDocuments=La,i.selectDocumentsByIds=Du,i.selectDocumentsMapping=pe,i.selectEmailDomains=Xa,i.selectEmailDomainsAsMapping=Ja,i.selectEmailDomainsOfOrganization=Uu,i.selectFilteredForms=xu,i.selectFormById=Ic,i.selectFormMapping=_c,i.selectFormRevisionAttachmentsMapping=rc,i.selectFormRevisionById=Yu,i.selectFormRevisionMapping=Ne,i.selectFormRevisions=pc,i.selectFormRevisionsOfForm=Ac,i.selectFormSubmissionAttachemntsByIds=vc,i.selectFormSubmissionAttachmentsMapping=bs,i.selectFormSubmissionById=vs,i.selectFormSubmissions=Os,i.selectFormSubmissionsMapping=Fs,i.selectFormSubmissionsOfAsset=Cc,i.selectFormSubmissionsOfForm=kc,i.selectFormSubmissionsOfIssue=Dc,i.selectForms=Qu,i.selectGeoImageById=js,i.selectGeoImageMapping=Nc,i.selectGeoImages=Hc,i.selectGeoImagesOfProject=rh,i.selectIsImportingProjectFile=km,i.selectIsLoggedIn=Fu,i.selectIssueAssociationById=Xc,i.selectIssueAssociationMapping=we,i.selectIssueAssociations=hh,i.selectIssueAssociationsOfAsset=xc,i.selectIssueAssociationsOfIssue=Qc,i.selectIssueAssociationsToIssue=Zc,i.selectIssueAttachmentById=ro,i.selectIssueAttachmentMapping=co,i.selectIssueAttachments=Vs,i.selectIssueById=Ys,i.selectIssueCommentById=fo,i.selectIssueCommentMapping=mo,i.selectIssueCountOfCategory=wu,i.selectIssueMapping=To,i.selectIssueTypeById=ai,i.selectIssueTypeFieldValues=Qs,i.selectIssueTypeFieldValuesAttachmentById=Kh,i.selectIssueTypeFieldValuesAttachments=No,i.selectIssueTypeFieldValuesAttachmentsByIds=Ho,i.selectIssueTypeFieldValuesAttachmentsMapping=si,i.selectIssueTypeFieldValuesById=xs,i.selectIssueTypeFieldValuesMapping=qo,i.selectIssueTypeFieldValuesOfIssue=kh,i.selectIssueTypeFields=Ze,i.selectIssueTypeFieldsAttachmentById=vh,i.selectIssueTypeFieldsAttachments=wo,i.selectIssueTypeFieldsAttachmentsMapping=vo,i.selectIssueTypeFieldsById=Gh,i.selectIssueTypeFieldsMapping=Vo,i.selectIssueTypeFieldsOfIssueType=Vh,i.selectIssueTypeMapping=Qo,i.selectIssueTypeValuesOfIssueType=Bh,i.selectIssueTypes=xo,i.selectIssueTypesByIds=Jh,i.selectIssueTypesOfOrganization=Xh,i.selectIssueUpdateMapping=or,i.selectIssueUpdatesOfIssue=rr,i.selectIssuesByIds=Th,i.selectIssuesOfIssueType=ci,i.selectIssuesOfIssueTypeCount=Zh,i.selectLatestAssetTypeFieldsOfAssetType=iu,i.selectLatestFormRevisionOfForm=Ku,i.selectLatestIssueTypeFieldsOfIssueType=$h,i.selectLatestRetryTime=bm,i.selectLicense=em,i.selectLicenseForProject=hr,i.selectLicenses=tt,i.selectLicensesForProjectsMapping=sm,i.selectLicensesOfOrganization=gm,i.selectNumberOfAssetsOfAssetType=Dl,i.selectOrganizationAccessById=rm,i.selectOrganizationAccessForUser=lm,i.selectOrganizationAccessUserMapping=_r,i.selectOrganizationAccesses=ui,i.selectOrganizationById=pm,i.selectOrganizationUsersAsMapping=Nr,i.selectOrganizationUsersIds=Lr,i.selectOrganizations=Gr,i.selectOrganizationsMapping=Br,i.selectOrganizationsWithAccess=ym,i.selectProjectAccessById=um,i.selectProjectAccessForUser=hm,i.selectProjectAccessMapping=fi,i.selectProjectAccessUserMapping=Er,i.selectProjectAccesses=wr,i.selectProjectAttachmentById=cd,i.selectProjectAttachmentMapping=ad,i.selectProjectById=mm,i.selectProjectFileById=Pm,i.selectProjectFileMapping=Ad,i.selectProjectFiles=gd,i.selectProjectMapping=yi,i.selectProjectUsersAsMapping=Ur,i.selectProjectUsersIds=zr,i.selectProjectsOfOrganization=Am,i.selectRehydrated=Mm,i.selectRootDocuments=Mu,i.selectSortedOrganizationUsers=Sm,i.selectSortedProjectUsers=fm,i.selectStageMapping=Ue,i.selectStagesOfAssetType=Dn,i.selectTeamById=Se,i.selectTeams=Ei,i.selectTeamsByIds=zm,i.selectTeamsMapping=wi,i.selectTeamsOfOrganization=Um,i.selectTeamsOfUser=Vm,i.selectUploadUrl=tc,i.selectUserById=cm,i.selectUsersByIds=om,i.selectUsersMapping=it,i.separateFilesFromValues=Ci,i.separateImageFromFields=Df,i.setActiveProjectFileId=pd,i.setAsset=Pl,i.setAssetAttachment=dn,i.setAssetAttachments=vl,i.setAssetStage=jn,i.setAssetStages=Ml,i.setAssetType=pu,i.setAssetTypeAttachment=zn,i.setAssetTypeAttachments=Bl,i.setAssetTypeFieldValues=uu,i.setAssetTypeFieldValuesAttachment=cu,i.setAssetTypeFieldValuesAttachments=ou,i.setAssetTypeFieldValuesMany=hu,i.setAssetTypeFields=Ql,i.setAssetTypeFieldsAttachment=Hl,i.setAssetTypeFieldsAttachments=Wl,i.setAssetTypeFieldsMany=xl,i.setAssetTypes=yu,i.setAssets=ql,i.setConversation=an,i.setCurrentUser=im,i.setDocumentAttachment=ka,i.setDocumentAttachments=ju,i.setDocuments=Ba,i.setForm=Ju,i.setFormRevision=uc,i.setFormRevisionAttachment=Bu,i.setFormRevisionAttachments=Gu,i.setFormSubmission=Ye,i.setFormSubmissionAttachment=th,i.setFormSubmissionAttachments=sh,i.setFormSubmissions=ah,i.setGeoImage=ve,i.setGeoImages=Vc,i.setIsImportingProjectFile=fd,i.setIssueAssociation=lh,i.setIssueAssociations=dh,i.setIssueAttachment=io,i.setIssueAttachments=fh,i.setIssueComment=Bs,i.setIssueComments=ho,i.setIssueType=je,i.setIssueTypeFieldValues=Eh,i.setIssueTypeFieldValuesAttachment=Nh,i.setIssueTypeFieldValuesAttachments=Hh,i.setIssueTypeFieldValuesMany=jh,i.setIssueTypeFields=Ch,i.setIssueTypeFieldsAttachment=_h,i.setIssueTypeFieldsAttachments=Ih,i.setIssueTypeFieldsMany=Mh,i.setIssueUpdate=Qh,i.setLoggedIn=Ia,i.setOrganizations=$r,i.setProfilePicture=nm,i.setProjectAttachment=td,i.setProjectAttachments=sd,i.setProjectFile=Om,i.setProjectFiles=vm,i.setProjects=qr,i.setRehydrated=Cm,i.setTeam=ge,i.setTokens=_u,i.setUploadUrl=ec,i.setUsers=pr,i.shallowEqual=Ki,i.slugify=Tl,i.spacesToDashesLower=Sl,i.teamReducer=Rd,i.teamSlice=Fi,i.toFileNameSafeString=gl,i.toOfflineIdRecord=xi,i.truncate=bl,i.updateAsset=Ie,i.updateAssetAttachment=wl,i.updateAssetAttachments=ln,i.updateAssetStage=Mt,i.updateAssetStageCompletion=In,i.updateAssetStageCompletions=Rn,i.updateAssetStages=Me,i.updateAssetType=Fe,i.updateAssetTypeAttachment=Gl,i.updateAssetTypeAttachments=Un,i.updateAssetTypeFieldValues=Re,i.updateAssetTypeFieldValuesAttachment=ru,i.updateAssetTypeFieldValuesAttachments=oa,i.updateAssetTypeFieldValuesMany=pa,i.updateAssetTypeFields=ta,i.updateAssetTypeFieldsAttachment=Yl,i.updateAssetTypeFieldsAttachments=Yn,i.updateAssetTypeFieldsMany=eu,i.updateAssetTypes=gu,i.updateAssets=jl,i.updateCategory=va,i.updateConversation=cn,i.updateDocumentAttachment=Pu,i.updateDocumentAttachments=Da,i.updateDocuments=ne,i.updateForm=Zu,i.updateFormRevisionAttachment=Lu,i.updateFormRevisionAttachments=cc,i.updateFormSubmission=qc,i.updateFormSubmissionAttachment=ih,i.updateFormSubmissionAttachments=Oc,i.updateFormSubmissions=ch,i.updateGeoImage=Gc,i.updateGeoImages=oh,i.updateIssue=Xe,i.updateIssueAssociation=Jc,i.updateIssueAssociations=uh,i.updateIssueAttachment=ph,i.updateIssueAttachments=no,i.updateIssueType=Zo,i.updateIssueTypeFieldValues=Ee,i.updateIssueTypeFieldValuesAttachment=Wh,i.updateIssueTypeFieldValuesAttachments=Lo,i.updateIssueTypeFieldValuesMany=Ph,i.updateIssueTypeFields=zo,i.updateIssueTypeFieldsAttachment=Rh,i.updateIssueTypeFieldsAttachments=Fo,i.updateIssueTypeFieldsMany=zh,i.updateLicense=te,i.updateOrganizationAccess=Tr,i.updateProject=kr,i.updateProjectAccess=Fr,i.updateProjectAttachment=Rm,i.updateProjectAttachments=id,i.updateProjectFile=Ii,i.updateProjectFiles=Em,i.updateTeam=Oi,i.userReducer=Ar,i.userSlice=di,i.versioningReducer=Od,i.versioningSlice=Fd,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
15
+ external URLs and therefore not prepended with VITE_API_URL.`;throw new Error(y)}const f=r.type.split("/")[1];if(!f)throw new Error("File has no extension");const p=a??h+"."+f;if(r=Ji(r,p),!r.name)throw new Error("Failed to set file's name");await this.addCache(r,h),at[c]=new Promise(y=>{y(r)})}return r}}class qf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{revisionId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,form_revision:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,field_identifier:f,file_extension:y.extension,file_sha1:y.sha1,form_revision:h};o.push(_)}this.dispatch(ac(c));const d=this.enqueueRequest({description:"Attach files to form revision",method:l.POST,url:"/form-revision-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.form_revision),blocks:c.map(r=>r.offline_id)});return d.then(r=>{this.processPresignedUrls(r.presigned_urls),this.dispatch(cc(r.attachments))}).catch(()=>{this.dispatch(oc(c.map(r=>r.offline_id)))}),[c,d.then(({attachments:r})=>r)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization form revision attachments",method:l.GET,url:"/form-revision-attachments/",queryParams:{organization:e.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(nc(s))}}class kf extends P{add(e){var d;const{store:s}=this.client,a=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,c=R({...e,created_by:a,revision:"Pending",submitted_at:new Date().toISOString()});this.dispatch(fs(c));const o=this.enqueueRequest({description:"Create form revision",method:l.POST,url:"/form-revisions/",payload:c,blockers:[e.form],blocks:[c.offline_id]});return o.then(m=>{this.dispatch(uc(m))}).catch(()=>{this.dispatch(ps(c.offline_id))}),[c,o]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization form revisions",method:l.GET,url:"/form-revisions/",queryParams:{organization:e.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(hc(s))}}const Df=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 o of a){if(o.image){if(o.image instanceof Promise)try{e[o.identifier]=await o.image}catch(d){console.error("Failed to get image from promise",d)}else e[o.identifier]=o.image;delete o.image}c.push(o)}s.push({...n,fields:c})}return{fields:s,images:e}};class Cf extends P{add(e,s){var r;const{store:n}=this.client,a=new Date().toISOString(),c=(r=n.getState().userReducer.currentUser)==null?void 0:r.id,o=R({...e,submitted_at:a,created_by:c}),d=R({...s,form:o.offline_id,revision:"Pending",submitted_at:a,created_by:c});this.dispatch(As(o)),this.dispatch(fs(d));const m=this.enqueueRequest({description:"Create form",method:l.POST,url:"/forms/",payload:{...o,initial_revision:{offline_id:d.offline_id,submitted_at:d.submitted_at,title:d.title,description:d.description,fields:d.fields}},blockers:[],blocks:[o.offline_id,d.offline_id]});return m.catch(h=>{throw this.dispatch(gs(o.offline_id)),this.dispatch(ps(d.offline_id)),h}),[o,d,m]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Ic(e)(n);if(!a)throw new Error("Expected form to exist");const c=kc(e)(n);c.length>0&&this.dispatch(Je(c.map(({offline_id:d})=>d)));const o=Ac(e)(n);o.length>0&&this.dispatch(fc(o.map(({offline_id:d})=>d))),this.dispatch(gs(e));try{return await this.enqueueRequest({description:"Delete form",method:l.DELETE,url:`/forms/${e}/`,blockers:[e],blocks:[]})}catch(d){throw this.dispatch(As(a)),o.length>0&&this.dispatch(mc(o)),c.length>0&&this.dispatch(Ke(c)),d}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization forms",method:l.GET,url:"/forms/",queryParams:{organization:e.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(Tc(s))}}class Mf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{submissionId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,form_submission:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:f,form_submission:h};o.push(_)}this.dispatch(He(c));const d=this.enqueueRequest({description:"Attach files to form submission",method:l.POST,url:"/form-submission-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.form_submission),blocks:c.map(r=>r.offline_id)});return d.then(r=>{this.processPresignedUrls(r.presigned_urls),this.dispatch(Oc(r.attachments))}).catch(r=>{throw this.dispatch(We(c.map(h=>h.offline_id))),r}),[c,d.then(({attachments:r})=>r)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=vc(e)(n);this.dispatch(We(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(He(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get form submission attachments",method:l.GET,url:"/form-submission-attachments/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(Fc(s))}}class zf extends P{async add(e){var f;const{store:s}=this.client,{file:n,...a}=e,c=new Date().toISOString(),o=(f=s.getState().userReducer.currentUser)==null?void 0:f.id,d=a.project,m=await this.getFilePayload(n),r=R({...a,file_name:n.name,file_sha1:m.sha1,file:URL.createObjectURL(n),submitted_at:c,created_by:o});this.dispatch($c(r));const h=this.enqueueRequest({description:"Add geo image",method:l.POST,url:"/geo-images/",payload:{offline_id:r.offline_id,submitted_at:c,title:r.title,description:r.description,geo_marker:r.geo_marker,canvas_marker:r.canvas_marker,sha1:r.file_sha1,project:r.project,file_name:r.file_name,direction:r.direction,original_date:r.original_date,file:m},blocks:[d.toString()],blockers:[d.toString()]});return h.then(p=>{this.processPresignedUrls(p.presigned_urls),this.dispatch(ve(p.geo_image))}).catch(()=>{this.dispatch(ws(r.offline_id))}),[r,h.then(p=>p.geo_image)]}async bulkAdd(e,s){var f;const{store:n}=this.client,a=new Date().toISOString(),c=(f=n.getState().userReducer.currentUser)==null?void 0:f.id,o=[],d=[],m=[],r={};for(const p of e){const{file:y,...T}=p,_=await this.getFilePayload(y);_.sha1 in r||(r[_.sha1]=_);const b=R({...T,file_name:y.name,file_sha1:_.sha1,file:URL.createObjectURL(y),submitted_at:a,created_by:c,project:s});o.push(b),d.push(b.offline_id),m.push({offline_id:b.offline_id,sha1:b.file_sha1,file_name:b.file_name,title:b.title,description:b.description,geo_marker:b.geo_marker,canvas_marker:b.canvas_marker,direction:b.direction,original_date:b.original_date})}this.dispatch(Bc(o));const h=this.enqueueRequest({description:"Bulk add geo images",method:l.POST,url:"/geo-images/bulk/",payload:{submitted_at:a,project:s,geo_images:m,files:Object.values(r)},blocks:[s.toString()],blockers:d});return h.then(p=>{this.processPresignedUrls(p.presigned_urls),this.dispatch(Vc(p.geo_images))}).catch(()=>{this.dispatch(Lc(d))}),[o,h.then(p=>p.geo_images)]}update(e){const{store:s}=this.client,n=s.getState(),a=Es(e.offline_id)(n);if(!a)throw new Error(`Map image with offline_id ${e.offline_id} does not exist in the store`);const c={...a,...e};this.dispatch(Gc(c));const o=this.enqueueRequest({description:"Update geo image",method:l.PATCH,url:`/geo-images/${e.offline_id}/`,payload:e,blocks:[e.offline_id],blockers:[e.offline_id]});return o.then(d=>{this.dispatch(ve(d))}).catch(()=>{this.dispatch(ve(a))}),[c,o]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Es(e)(n);if(!a)throw new Error(`Map image with offline_id ${e} does not exist in the store`);this.dispatch(ws(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(ve(a))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get geo images",method:l.GET,url:`/projects/${e}/geo-images/`,blocks:[e.toString()],blockers:[]});this.dispatch(Uc(s))}}class Uf extends F{add(e){var d;const{store:s}=this.client,n=new Date().toISOString(),a=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,c=R({...e,submitted_at:n,created_by:a});this.dispatch(Ps(c));const o=this.enqueueRequest({description:"Add issue association",method:l.POST,url:"/issue-associations/",payload:{offline_id:c.offline_id,submitted_at:n,...e},blockers:[e.associated_issue,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[c.offline_id]});return o.then(m=>{this.dispatch(Jc(m))}).catch(()=>{this.dispatch(ks(c.offline_id))}),[c,o]}async delete(e){const{store:s}=this.client,n=Xc(e)(s.getState());if(!n)throw new Error(`Issue association with id ${e} not found in store.`);this.dispatch(ks(e));const a=this.enqueueRequest({description:"Delete issue association",method:l.DELETE,url:`/issue-associations/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(Ps(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch issue associations",method:l.GET,url:"/issue-associations/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(Kc(s))}}class Vf extends ke{constructor(){super(...arguments);A(this,"name","Issue Attachment");A(this,"url","/issue-attachments");A(this,"addAttachments",Ms);A(this,"updateAttachments",no);A(this,"removeAttachments",zs);A(this,"removeAttachment",ao);A(this,"setAttachment",io);A(this,"selectAttachment",ro)}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.modelId})}buildAttachmentPayload(s){return{...s,issue:s.modelId}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelId:n.issueId,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s.toString()},blocks:[],blockers:[]});this.dispatch(so(n))}}class $f extends F{add(e){var c;const{store:s}=this.client,n=R({...e,author:(c=s.getState().userReducer.currentUser)==null?void 0:c.id,submitted_at:new Date().toISOString()});this.dispatch(Bs(n));const a=this.enqueueRequest({description:"Add issue comment",method:l.POST,url:"/issue-comments/",payload:n,blockers:[e.issue],blocks:[n.offline_id]});return a.catch(()=>{this.dispatch(Gs(n.offline_id))}),[n,a]}update(e){const{store:s}=this.client,n=fo(e.offline_id)(s.getState());if(!n)throw new Error(`Comment with offline_id ${e.offline_id} not found in store`);const a={...n,...e};this.dispatch($s(a));const c=this.enqueueRequest({description:"Edit issue comment",method:l.PATCH,url:`/issue-comments/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return c.catch(()=>{this.dispatch($s(n))}),[a,c]}remove(e){const s=this.client.store.getState().issueCommentReducer.instances[e];if(!s)throw new Error(`Comment with offline_id ${e} not found in store`);this.dispatch(Gs(e));const n=this.enqueueRequest({description:"Delete comment",method:l.DELETE,url:`/issue-comments/${e}/`,blockers:[e],blocks:[]});return n.catch(()=>{this.dispatch(Bs(s))}),n}async refreshStore(e){const s=await this.enqueueRequest({description:"Get comments",method:l.GET,url:"/issue-comments/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(ho(s))}}class Bf extends F{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.id,o=R({...e,submitted_at:a,created_by:c});this.dispatch(Ns(o));const d=this.enqueueRequest({description:"Create issue",method:l.POST,url:"/issues/",payload:o,blockers:["add-issue",o.project.toString()],blocks:[o.offline_id]});return d.then(r=>{this.dispatch(Xe(r))}).catch(r=>{throw this.dispatch(Hs(o.offline_id)),r}),[o,d]}update(e){var m;const s=this.client.store.getState(),n=Ws(e.offline_id)(s);if(!n)throw new Error(`Attempting to update an issue with offline_id ${e.offline_id} that doesn't exist in the store`);const a={...n,...e};this.dispatch(Xe(a));const c={};for(const r of[v.TITLE,v.DESCRIPTION,v.STATUS,v.CATEGORY,v.PRIORITY,v.ASSIGNED_TO,v.DUE_DATE])if(r in e&&e[r]!==n[r])switch(r){case v.PRIORITY:case v.STATUS:{const h=e[r];c[r]=h!==void 0?Number(h):null;break}case v.DUE_DATE:case v.DESCRIPTION:case v.TITLE:c[r]=e[r]??null;break;case v.CATEGORY:{let h=null;const f=e[r];if(f&&(h=s.categoryReducer.instances[f]??null,!h))throw new Error(`Trying to update issue category to ${f} which does not exist in store`);c[r]=h?{name:h.name,color:h.color,offline_id:h.offline_id}:null;break}case v.ASSIGNED_TO:{let h=null;const f=e[r];if(f&&(h=s.userReducer.users[f]??null,!h))throw new Error(`Trying to update issue assigned_to to ${f} which does not exist in store`);c[r]=h?{full_name:h.username,id:h.id}:null;break}}const o=R({created_by:(m=s.userReducer.currentUser)==null?void 0:m.id,submitted_at:new Date().toISOString(),issue:n.offline_id,changes:c});this.dispatch(ir(o));const d=this.enqueueRequest({description:"Edit issue",method:l.PATCH,url:`/issues/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return d.catch(()=>{this.dispatch(Xe(n)),this.dispatch(ar(o.offline_id))}),[a,d]}async remove(e){const{store:s}=this.client,n=s.getState(),a=Ws(e)(n);if(!a)throw new Error(`No issue with id ${e} found in the store`);const c=oo(e)(n),o=rr(e)(n),d=Dc(e)(n),m={};for(const h of Zc(e)(n))m[h.offline_id]=h;for(const h of Qc(e)(n))m[h.offline_id]=h;const r=Object.values(m);this.dispatch(Hs(e)),c.length>0&&this.dispatch(zs(c.map(({offline_id:h})=>h))),o.length>0&&this.dispatch(cr(o.map(({offline_id:h})=>h))),d.length>0&&this.dispatch(Je(d.map(({offline_id:h})=>h))),r.length>0&&this.dispatch(Ds(r.map(({offline_id:h})=>h)));try{return await this.enqueueRequest({description:"Delete issue",method:l.DELETE,url:`/issues/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(Ns(a)),this.dispatch(Ms(c)),this.dispatch(nr(o)),this.dispatch(Ke(d)),this.dispatch(qs(r)),h}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issues",method:l.GET,url:"/issues/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(Ao(s))}}class Gf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{fieldsRevisionId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,fields_revision:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,file_extension:y.extension,field_identifier:f,file_sha1:y.sha1,fields_revision:h};o.push(_)}this.dispatch(Ro(c));const d=this.enqueueRequest({description:"Add issue type fields attachments",method:l.POST,url:"/issue-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.fields_revision),blocks:c.map(r=>r.offline_id)});return d.then(r=>{this.processPresignedUrls(r.presigned_urls),this.dispatch(Fo(r.attachments))}).catch(()=>{this.dispatch(Oo(c.map(r=>r.offline_id)))}),[c,d.then(({attachments:r})=>r)]}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.toString()},blockers:[e.toString()],blocks:[]});this.dispatch(Io(s))}}class Lf extends F{add(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Mo(c));const o=this.enqueueRequest({description:"Add Issue Type Fields",method:l.POST,url:"/issue-type-fields/",payload:c,blockers:[c.issue_type],blocks:[c.offline_id]});return o.then(m=>{this.dispatch(zo(m))}).catch(m=>{throw this.dispatch(Uo(c.offline_id)),m}),[c,o]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Issue Type Fields",method:l.GET,url:"/issue-type-fields/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(Co(s))}}class Nf extends P{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],o=[];for(const r of e){const{fieldValuesId:h,fieldIdentifier:f,file:p}=r,y=await this.getFilePayload(p);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(p),file_type:p.type,file_name:p.name,file_sha1:y.sha1,created_by:n,field_values:h,submitted_at:s,field_identifier:f});c.push(T);const _={offline_id:T.offline_id,file_name:p.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:f,field_values:h};o.push(_)}this.dispatch(Qe(c));const d=this.enqueueRequest({description:"Add issue type field values attachments",method:l.POST,url:"/issue-type-field-values-attachments/bulk/",payload:{submitted_at:s,attachments:o,files:Object.values(a)},blockers:c.map(r=>r.field_values),blocks:c.map(r=>r.offline_id)});return d.then(({presigned_urls:r,attachments:h})=>{this.processPresignedUrls(r),this.dispatch(Lo(h))}).catch(r=>{throw this.dispatch(xe(c.map(h=>h.offline_id))),r}),[c,d.then(({attachments:r})=>r)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=Ho(e)(n);this.dispatch(xe(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(Qe(a)),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.toString()},blockers:[],blocks:[]});this.dispatch(Go(s))}}class Hf extends F{add(e){var o;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(o=n.userReducer.currentUser)==null?void 0:o.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add issue type field values",method:l.POST,url:"/issue-type-field-values/",payload:a,blockers:[e.issue,e.fields_revision],blocks:[a.offline_id]});return this.dispatch(Js(a)),c.then(d=>(this.dispatch(Ee(d)),d)).catch(()=>{this.dispatch(Xs(a.offline_id))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=Qs(e.offline_id)(n);if(!a)throw new Error(`Expected IssueTypeFieldValues with offline_id ${e.offline_id} to exist`);const c={...a,...e};this.dispatch(Ee(c));const o=this.enqueueRequest({description:"Update issue type field values",method:l.PATCH,url:`/issue-type-field-values/${e.offline_id}/`,payload:e,blockers:[c.offline_id,c.fields_revision,c.issue],blocks:[c.offline_id]});return o.then(d=>{this.dispatch(Ee(d))}).catch(()=>{this.dispatch(Ee(a))}),[c,o]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Qs(e)(n);if(!a)throw new Error(`Expected submission with offline_id ${e} to exist`);const c=Wo(e)(n);this.dispatch(Xs(e)),this.dispatch(xe(c.map(o=>o.offline_id)));try{await this.enqueueRequest({description:"Delete issue type field values",method:l.DELETE,url:`/issue-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(Js(a)),this.dispatch(Qe(c)),o}}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.toString()},blockers:[],blocks:[]});this.dispatch(Po(s))}}class Wf extends F{add(e){var o;const{store:s}=this.client,n=s.getState(),a=R({...e,submitted_at:new Date().toISOString(),created_by:(o=n.userReducer.currentUser)==null?void 0:o.id});this.dispatch(Xo(a));const c=this.enqueueRequest({method:l.POST,url:"/issue-types/",payload:a,blockers:[],blocks:[a.offline_id]});return c.then(d=>{this.dispatch(je(d))}).catch(()=>{this.dispatch(ii(a.offline_id))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=ni(e.offline_id)(n);if(!a)throw new Error(`IssueType with offline_id ${e.offline_id} does not exist in the store.`);const c={...a,...e};this.dispatch(Zo(c));const o=this.enqueueRequest({method:l.PATCH,url:`/issue-types/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return o.then(d=>{this.dispatch(je(d))}).catch(()=>{this.dispatch(je(a))}),[c,o]}delete(e){const{store:s}=this.client,n=s.getState(),a=ni(e)(n);if(!a)throw new Error(`IssueType with offline_id ${e} does not exist in the store.`);const c=ai(e)(n);this.dispatch(ii(e)),this.dispatch(So(c.map(d=>d.offline_id)));const o=this.enqueueRequest({method:l.DELETE,url:`/issue-types/${e}/`,blockers:[e],blocks:[]});return o.catch(()=>{this.dispatch(je(a)),this.dispatch(go(c))}),o}async refreshStore(e){const s=await this.enqueueRequest({method:l.GET,url:"/issue-types/",queryParams:{organization:e.toString()},blockers:[],blocks:[]});this.dispatch(Jo(s))}}class Yf extends F{async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue updates",method:l.GET,url:"/issue-updates/",queryParams:{project:e.toString()},blockers:[],blocks:[]});this.dispatch(sr(s))}}class Kf extends jd{constructor(e){super(e)}}const Jf=1800;function Xf(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 Zf extends Kf{constructor(){super(...arguments);A(this,"_getRenewedTokens",async s=>{const n=this.enqueueRequest({description:"Get renewed tokens",method:l.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(_a(!1)),this.clearTokens(),this.dispatch({type:xd.RESET_STATE}),this.dispatch({type:Ud})}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=el(s).exp??n}catch{a=n}return a-n<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 j&&this.clearAuth(),s instanceof Error?Promise.reject(s):Promise.reject(new Error((s??Te).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 j({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 j({message:"Incorrect username or password.",response:n,discard:!0})}async initAuth(s){const n=O.v4();return console.debug(this.constructor.name,"Initiating auth"),this.enqueueRequest({uuid:n,description:"Get token pair",method:l.POST,url:this.initTokensUrl,payload:s,isAuthNeeded:!1,checkAuth:!1,immediate:!0,blockers:[],blocks:[]}).then(a=>{this.setTokens(Xf(a))})}}class Qf extends F{async getLicense(e){const s=await this.enqueueRequest({description:"Get license",method:l.GET,url:`/billing/${e.offline_id}/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:[]});return this.dispatch(te(s)),s}async pauseLicense(e){const s=await this.enqueueRequest({description:"Pause license",method:l.DELETE,url:`/billing/${e.offline_id}/suspend/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:[]});return this.dispatch(te(s)),s}async resumeLicense(e){const s=await this.enqueueRequest({description:"Resume license",method:l.PATCH,url:`/billing/${e.offline_id}/suspend/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:[]});return this.dispatch(te(s)),s}async cancelLicense(e){const s=await this.enqueueRequest({description:"Cancel license",method:l.DELETE,url:`/billing/${e.offline_id}/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:[]});return this.dispatch(te(s)),s}async attachLicenseToProject(e,s){const n=await this.enqueueRequest({description:"Attach license",method:l.PATCH,url:`/billing/${e.offline_id}/project/`,isAuthNeeded:!0,payload:{project:s.id},blockers:[e.organization_owner?e.organization_owner.toString():"",s.id?s.id.toString():""],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});return this.dispatch(te(n)),n}async detachLicenseFromProject(e){const s=await this.enqueueRequest({description:"Detach license",method:l.DELETE,url:`/billing/${e.offline_id}/project/`,isAuthNeeded:!0,blockers:[e.organization_owner?e.organization_owner.toString():""],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});return this.dispatch(te(s)),s}async getLatestTransaction(e){return await this.enqueueRequest({description:"Get latest transaction",method:l.GET,url:`/billing/${e.offline_id}/transaction/`,isAuthNeeded:!0,blockers:[e.offline_id],blocks:[e.offline_id]})}async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Get licenses",method:l.GET,url:`/organizations/${s}/licenses/`,isAuthNeeded:!0,blockers:[s.toString()],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});for(const o of a)n[o.offline_id]=o;const c=await this.enqueueRequest({description:"Get licenses",method:l.GET,url:`/projects/${e}/licenses/`,isAuthNeeded:!0,blockers:[e.toString()],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});for(const o of c)n[o.offline_id]=o;this.dispatch(ur(Object.values(n)))}}class xf extends F{async update(e){const s=this.enqueueRequest({description:"Edit organization access",method:l.PATCH,url:`/organizations/${e.organization}/access/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return s.then(()=>{this.dispatch(Tr(e))}),s}async remove(e){return this.dispatch(br(e.offline_id)),this.dispatch(yr(e.user)),this.enqueueRequest({description:"Remove organization access",method:l.DELETE,url:`/organizations/${e.organization}/access/${e.offline_id}/`,blockers:[e.offline_id],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization accesses",method:l.GET,url:`/organizations/${e}/access/`,blockers:[],blocks:[]});this.dispatch(Sr(s))}}class ep extends F{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.id}/`,payload:e,blockers:[`add-org-${e.name}`,e.id.toString()],blocks:[e.id.toString()]})}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 n={},a=await this.enqueueRequest({description:"Get organizations",method:l.GET,url:`/projects/${e}/organizations/`,blockers:[],blocks:[]});for(const o of a)n[o.id]=o;const c=await this.enqueueRequest({description:"Get organization",method:l.GET,url:`/organizations/${s}/`,blockers:[],blocks:[]});n[c.id]=c,this.dispatch($r(Object.values(n)))}}class tp extends F{async update(e){return this.dispatch(Fr(e)),this.enqueueRequest({description:"Edit project access",method:l.PATCH,url:`/access/${e.offline_id}/`,payload:e,blockers:[e.offline_id,"change-access-level"],blocks:[e.offline_id]})}async remove(e){return this.dispatch(Or(e)),this.enqueueRequest({description:"Delete project access",method:l.DELETE,url:`/access/${e}/`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project accesses",method:l.GET,url:`/projects/${e}/access/`,blockers:[],blocks:[]});this.dispatch(hi(s))}}class sp extends ke{constructor(){super(...arguments);A(this,"name","Project Attachment");A(this,"url","/project-attachments");A(this,"addAttachments",ed);A(this,"updateAttachments",id);A(this,"removeAttachments",Si);A(this,"removeAttachment",nd);A(this,"setAttachment",td);A(this,"selectAttachment",cd)}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.modelId})}buildAttachmentPayload(s){return{...s,project:s.modelId}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelId:n.projectId,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get project attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s.toString()},blockers:[],blocks:[]});this.dispatch(xr(n))}}class ip extends F{async saveExisting(e){if(!e.offline_id)throw new Error("You can only use this method to save existing project files. The one provided has no offline_id.");const s={...e};delete s.file;const n=this.enqueueRequest({method:l.PATCH,url:`/projects/files/${e.offline_id}/`,payload:s,blockers:[e.offline_id],blocks:[e.offline_id]});return n.then(a=>{this.dispatch(_i(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:l.PATCH,url:`/projects/files/${n}/`,payload:m,blockers:[n],blocks:[n]}}else c=new Promise((m,r)=>{this.client.files.uploadFileToS3(a.file_sha1).then(([h])=>{m({method:l.POST,url:`/projects/${a.project}/files/`,payload:{...a,...h},blockers:[n],blocks:[n]})}).catch(r)});const d=Promise.resolve(c).then(m=>this.enqueueRequest(m));return d.then(m=>{this.dispatch(_i(m))}),this.dispatch(yd),this.dispatch(pd(null)),this.dispatch(fd(!1)),[a,d]}delete(e){return this.dispatch(hd(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(ld(s))}}class np extends F{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(kr(e)),await this.enqueueRequest({description:"Update project",method:l.PATCH,url:`/projects/${e.id}/`,payload:{name:e.name,bounds:e.bounds},blockers:[e.id.toString()],blocks:[e.id.toString()]})}async delete(e){const{store:s}=this.client,n=s.getState(),a=pi(n),c=a[e];if(!c)throw new Error("Expected project to exist");const o=gd(n).filter(h=>h.project===e);this.dispatch(md(o.map(({offline_id:h})=>h)));const d=od(c.id)(n);this.dispatch(Si(d.map(({offline_id:h})=>h)));const m=wr(n);this.dispatch(vr(m.map(({offline_id:h})=>h))),this.dispatch({type:"rehydrated/setRehydrated",payload:!1}),this.dispatch(Dr(c));const r=hr(c.id)(n);r&&this.dispatch(te({...r,project:null}));try{await this.enqueueRequest({description:"Delete project",method:l.DELETE,url:`/projects/${e}/`,blockers:[e.toString()],blocks:[]}),this.dispatch({type:"rehydrated/setRehydrated",payload:!0})}catch(h){throw this.dispatch(qr(Object.values(a))),this.dispatch(hi(Object.values(m))),this.dispatch(ud(o)),this.dispatch(sd(d)),this.dispatch({type:"rehydrated/setRehydrated",payload:!0}),r&&this.dispatch(te({...r,project:c.id})),h}}invite(e,s){const n=O.v4();return this.enqueueRequest({description:"Invite user to project",method:l.POST,url:`/projects/${e}/invite/${s}/`,payload:{offline_id:n},blockers:[],blocks:[n]})}joinProject(e,s,n){return this.enqueueRequest({description:"Join project",method:l.GET,url:`/projects/${e}/join-project/${s}/${n}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}async acceptInvite(e){return this.enqueueRequest({description:"Accept project invite",method:l.PATCH,url:`/projects/${e}/accept-invite/`,blockers:[e.toString()],blocks:[e.toString()]}).then(()=>{this.dispatch(Cr(e))})}}class ap extends F{add(e){const s=R({...e,submitted_at:new Date().toISOString()});this.dispatch(Id(s));const n=this.enqueueRequest({description:"Create team",method:l.POST,url:`/organizations/${e.organization}/teams/`,payload:s,blockers:[],blocks:[s.offline_id]});return n.then(a=>{this.dispatch(ge(a))}).catch(()=>{this.dispatch(Oi(s.offline_id))}),[s,n]}update(e){const{store:s}=this.client,n=Se(e.offline_id)(s.getState());if(!n)throw new Error(`Expected team with offline_id ${e.offline_id} to exist`);const a={...n,...e};this.dispatch(Fi(a));const c=this.enqueueRequest({description:"Update team",method:l.PATCH,url:`/organizations/teams/${e.offline_id}/`,payload:e,blockers:[e.offline_id],blocks:[e.offline_id]});return c.then(o=>{this.dispatch(ge(o))}).catch(()=>{this.dispatch(ge(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Se(e)(n);if(!a)throw new Error(`Expected team with id ${e} to exist`);this.dispatch(Oi(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(ge(a)),c}}async setMembers(e,s){const{store:n}=this.client,a=Se(e)(n.getState());if(!a)throw new Error(`Expected team with id ${e} to exist`);if(s.length!==new Set(s).size)throw new Error("Duplicate members found in the list");this.dispatch(Fi({...a,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(ge(a))}),c}async addMembers(e,s){const{store:n}=this.client,a=Se(e)(n.getState());if(!a)throw new Error(`Expected team with id ${e} to exist`);const c=[...a.members,...s];return this.setMembers(e,c)}async removeMembers(e,s){const{store:n}=this.client,a=Se(e)(n.getState());if(!a)throw new Error(`Expected team with id ${e} to exist`);const c=a.members.filter(o=>!s.includes(o));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(_d(s))}}class cp extends F{async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Fetch organization users",method:l.GET,url:`/organizations/${s}/users/`,blockers:[],blocks:[]});for(const o of a)n[o.id]=o;const c=await this.enqueueRequest({description:"Fetch project users",method:l.GET,url:`/projects/${e}/users/`,blockers:[],blocks:[]});for(const o of c)n[o.id]=o;this.dispatch(pr(Object.values(n)))}}var Nd=(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))(Nd||{});i.APIError=j,i.AgentService=hf,i.AssetAttachmentService=mf,i.AssetService=ff,i.AssetStageCompletionService=pf,i.AssetStageService=yf,i.AssetTypeAttachmentService=Af,i.AssetTypeFieldValuesAttachmentService=Tf,i.AssetTypeFieldValuesService=If,i.AssetTypeFieldsAttachmentService=gf,i.AssetTypeFieldsService=Sf,i.AssetTypeService=Rf,i.AttachmentModel=Bi,i.BaseApiService=F,i.BaseSDK=lf,i.CategoryService=Ff,i.DEFAULT_ISSUE_PRIORITY=sl,i.DEFAULT_ISSUE_STATUS=tl,i.DeferredPromise=Wi,i.DocumentAttachmentService=Of,i.DocumentService=vf,i.EMPTY_ARRAY=Vi,i.EMPTY_OBJECT=$i,i.EmailDomainsService=wf,i.EmailVerificationService=Ef,i.FileService=Pf,i.FormRevisionAttachmentService=qf,i.FormRevisionService=kf,i.FormService=Cf,i.FormSubmissionAttachmentService=Mf,i.FormSubmissionService=_f,i.GeoImageService=zf,i.HttpMethod=l,i.IssueAssociationService=Uf,i.IssueAttachmentService=Vf,i.IssueCommentService=$f,i.IssuePriority=dt,i.IssueService=Bf,i.IssueStatus=lt,i.IssueTypeFieldValuesAttachmentService=Nf,i.IssueTypeFieldValuesService=Hf,i.IssueTypeFieldsAttachmentService=Gf,i.IssueTypeFieldsService=Lf,i.IssueTypeService=Wf,i.IssueUpdateChange=v,i.IssueUpdateService=Yf,i.JWTService=Zf,i.LicenseLevel=Li,i.LicenseService=Qf,i.LicenseStatus=Ni,i.OUTBOX_RETRY_DELAY=Hi,i.OrganizationAccessLevel=rt,i.OrganizationAccessService=xf,i.OrganizationService=ep,i.OutboxCoordinator=be,i.PaddleCheckoutEvent=Gi,i.ProjectAccessLevel=ot,i.ProjectAccessService=tp,i.ProjectAttachmentService=sp,i.ProjectFileService=ip,i.ProjectService=np,i.TeamService=ap,i.UNKNOWN_ERROR_MESSAGE=Te,i.UserService=cp,i.VERSION_REDUCER_KEY=Ei,i.VerificationCodeType=Nd,i._selectLatestFormRevision=yc,i._setLatestRetryTime=Xr,i.acceptProjectInvite=Cr,i.addAsset=It,i.addAssetAttachment=Ol,i.addAssetAttachments=St,i.addAssetStage=zl,i.addAssetStageCompletion=jt,i.addAssetStageCompletions=Pt,i.addAssetStages=Ce,i.addAssetType=Qt,i.addAssetTypeAttachment=$l,i.addAssetTypeAttachments=Vt,i.addAssetTypeFieldValues=Yt,i.addAssetTypeFieldValuesAttachment=au,i.addAssetTypeFieldValuesAttachments=$e,i.addAssetTypeFieldValuesMany=ma,i.addAssetTypeFields=xn,i.addAssetTypeFieldsAttachment=Nl,i.addAssetTypeFieldsAttachments=Hn,i.addAssetTypeFieldsMany=Zl,i.addAssetTypes=Au,i.addAssets=Rt,i.addCategory=is,i.addConversation=sn,i.addDocumentAttachment=Eu,i.addDocumentAttachments=Pa,i.addDocuments=Ba,i.addEmailDomain=Ya,i.addForm=As,i.addFormRevision=fs,i.addFormRevisionAttachment=$u,i.addFormRevisionAttachments=ac,i.addFormRevisions=mc,i.addFormSubmission=_s,i.addFormSubmissionAttachment=eh,i.addFormSubmissionAttachments=He,i.addFormSubmissions=Ke,i.addForms=Xu,i.addGeoImage=$c,i.addGeoImages=Bc,i.addIssue=Ns,i.addIssueAssociation=Ps,i.addIssueAssociations=qs,i.addIssueAttachment=mh,i.addIssueAttachments=Ms,i.addIssueComment=Bs,i.addIssueComments=Ah,i.addIssueType=Xo,i.addIssueTypeFieldValues=Js,i.addIssueTypeFieldValuesAttachment=Lh,i.addIssueTypeFieldValuesAttachments=Qe,i.addIssueTypeFieldValuesMany=wh,i.addIssueTypeFields=Mo,i.addIssueTypeFieldsAttachment=bh,i.addIssueTypeFieldsAttachments=Ro,i.addIssueTypeFieldsMany=Dh,i.addIssueUpdate=ir,i.addIssueUpdates=nr,i.addIssues=go,i.addLicenses=xh,i.addProjectAttachment=Im,i.addProjectAttachments=ed,i.addProjectFile=wm,i.addProjectFiles=ud,i.addTeam=Id,i.addUsers=am,i.agentsReducer=cn,i.agentsSlice=pt,i.areArraysEqual=cl,i.assetAttachmentReducer=fn,i.assetAttachmentSlice=At,i.assetReducer=Sn,i.assetSlice=_t,i.assetStageCompletionReducer=On,i.assetStageCompletionSlice=Et,i.assetStageReducer=jn,i.assetStageSlice=Ct,i.assetTypeAttachmentReducer=Gn,i.assetTypeAttachmentSlice=Ut,i.assetTypeFieldValuesAttachmentReducer=la,i.assetTypeFieldValuesAttachmentSlice=Nt,i.assetTypeFieldValuesReducer=Aa,i.assetTypeFieldValuesSlice=Wt,i.assetTypeFieldsAttachmentReducer=Xn,i.assetTypeFieldsAttachmentSlice=Gt,i.assetTypeFieldsReducer=ia,i.assetTypeFieldsSlice=Lt,i.assetTypeReducer=Ta,i.assetTypeSlice=Zt,i.authReducer=Ia,i.authSlice=Ge,i.blobToBase64=pl,i.categoryReducer=wa,i.categorySlice=ss,i.clearTokens=Iu,i.constructUploadedFilePayloads=fl,i.coordinatesAreEqual=al,i.createModelAdapter=I,i.createMultiPointGeometry=nl,i.createOfflineAction=Wr,i.createPointGeometry=il,i.deleteAsset=Ft,i.deleteAssetAttachment=ln,i.deleteAssetAttachments=Tt,i.deleteAssetStage=Ul,i.deleteAssetStageCompletion=qt,i.deleteAssetStageCompletions=kt,i.deleteAssetStages=ze,i.deleteAssetType=xt,i.deleteAssetTypeAttachment=Un,i.deleteAssetTypeAttachments=$t,i.deleteAssetTypeFieldValues=Kt,i.deleteAssetTypeFieldValuesAttachment=du,i.deleteAssetTypeFieldValuesAttachments=Be,i.deleteAssetTypeFieldValuesMany=pa,i.deleteAssetTypeFields=ta,i.deleteAssetTypeFieldsAttachment=Kl,i.deleteAssetTypeFieldsAttachments=Yn,i.deleteAssetTypeFieldsMany=tu,i.deleteAssetTypes=Su,i.deleteAssets=An,i.deleteCategory=va,i.deleteDocumentAttachment=Da,i.deleteDocumentAttachments=Ca,i.deleteEmailDomain=Ka,i.deleteForm=gs,i.deleteFormRevision=ps,i.deleteFormRevisionAttachment=Nu,i.deleteFormRevisionAttachments=oc,i.deleteFormRevisions=fc,i.deleteFormSubmission=Is,i.deleteFormSubmissionAttachment=nh,i.deleteFormSubmissionAttachments=We,i.deleteFormSubmissions=Je,i.deleteGeoImage=ws,i.deleteGeoImages=Lc,i.deleteIssue=Hs,i.deleteIssueAssociation=ks,i.deleteIssueAssociations=Ds,i.deleteIssueAttachment=ao,i.deleteIssueAttachments=zs,i.deleteIssueComment=Gs,i.deleteIssueComments=gh,i.deleteIssueTypeFieldValues=Xs,i.deleteIssueTypeFieldValuesAttachment=Yh,i.deleteIssueTypeFieldValuesAttachments=xe,i.deleteIssueTypeFieldValuesMany=qh,i.deleteIssueTypeFields=Uo,i.deleteIssueTypeFieldsAttachment=Fh,i.deleteIssueTypeFieldsAttachments=Oo,i.deleteIssueTypeFieldsMany=Uh,i.deleteIssueUpdate=ar,i.deleteIssueUpdates=cr,i.deleteIssues=So,i.deleteOrganizationAccess=br,i.deleteProject=Dr,i.deleteProjectAccess=Or,i.deleteProjectAccesses=vr,i.deleteProjectAttachment=nd,i.deleteProjectAttachments=Si,i.deleteProjectFile=hd,i.deleteProjectFiles=md,i.deleteTeam=Oi,i.dequeue=$d,i.discard=qi,i.documentAttachmentReducer=Ua,i.documentAttachmentSlice=cs,i.documentSlice=rs,i.documentsReducer=Ha,i.downloadFile=yl,i.downloadInMemoryFile=ml,i.emailDomainsReducer=Za,i.emailDomainsSlice=ls,i.emailRegex=Il,i.enqueue=Vd,i.enqueueRequest=Kr,i.fallbackToEmptyArray=S,i.fallbackToEmptyObject=ae,i.fileReducer=sc,i.fileSlice=us,i.fileToBlob=Xi,i.formReducer=bc,i.formRevisionAttachmentReducer=dc,i.formRevisionAttachmentSlice=hs,i.formRevisionReducer=gc,i.formRevisionsSlice=ms,i.formSlice=ys,i.formSubmissionAttachmentReducer=Ec,i.formSubmissionAttachmentSlice=Ss,i.formSubmissionReducer=Mc,i.formSubmissionSlice=bs,i.geoImageReducer=Wc,i.geoImageSlice=vs,i.getFileIdentifier=hl,i.getFileS3Key=ft,i.getLocalDateString=Ki,i.getLocalRelativeDateString=ll,i.getOutboxCoordinator=ue,i.getRenamedFile=Ji,i.hashFile=fe,i.initSDK=uf,i.initializeAssetAttachments=gt,i.initializeAssetStageCompletions=bn,i.initializeAssetStages=wn,i.initializeAssetTypeAttachments=Cn,i.initializeAssetTypeFieldValues=ha,i.initializeAssetTypeFieldValuesAttachments=aa,i.initializeAssetTypeFields=Qn,i.initializeAssetTypeFieldsAttachments=Nn,i.initializeAssetTypes=Sa,i.initializeAssets=yn,i.initializeCategories=Fa,i.initializeConversations=tn,i.initializeDocumentAttachments=ja,i.initializeEmailDomains=Wa,i.initializeFormRevisionAttachments=nc,i.initializeFormRevisions=hc,i.initializeFormSubmissionAttachments=Fc,i.initializeFormSubmissions=Pc,i.initializeForms=Tc,i.initializeGeoImages=Uc,i.initializeIssueAssociations=Kc,i.initializeIssueAttachments=so,i.initializeIssueTypeFieldValues=Po,i.initializeIssueTypeFieldValuesAttachments=Go,i.initializeIssueTypeFields=Co,i.initializeIssueTypeFieldsAttachments=Io,i.initializeIssueTypes=Jo,i.initializeIssueUpdates=sr,i.initializeIssues=Ao,i.initializeLicences=ur,i.initializeOrganizationAccesses=Sr,i.initializeProjectAccesses=hi,i.initializeProjectAttachments=xr,i.initializeProjectFiles=ld,i.initializeTeams=_d,i.isToday=dl,i.issueAssociationReducer=eo,i.issueAssociationSlice=js,i.issueAttachmentReducer=lo,i.issueAttachmentSlice=Cs,i.issueCommentReducer=po,i.issueCommentSlice=Vs,i.issueReducer=bo,i.issueSlice=Ls,i.issueTypeFieldValuesAttachmentReducer=Yo,i.issueTypeFieldValuesAttachmentSlice=ei,i.issueTypeFieldValuesReducer=ko,i.issueTypeFieldValuesSlice=Ks,i.issueTypeFieldsAttachmentReducer=Eo,i.issueTypeFieldsAttachmentSlice=Ys,i.issueTypeFieldsReducer=$o,i.issueTypeFieldsSlice=xs,i.issueTypeReducer=er,i.issueTypeSlice=si,i.issueUpdateReducer=dr,i.issueUpdateSlice=ci,i.licenseReducer=mr,i.licenseSlice=oi,i.logOnlyOnce=Al,i.markAsDeleted=Jr,i.markForDeletion=_m,i.memoize=ht,i.moveDocument=Ga,i.offline=R,i.onlyUniqueHashes=_l,i.onlyUniqueOfflineIds=xi,i.organizationAccessReducer=Ir,i.organizationAccessSlice=di,i.organizationReducer=Hr,i.organizationSlice=yi,i.outboxReducer=Zr,i.outboxSlice=Ai,i.overmapEnhancer=Qm,i.overmapReducers=Md,i.overmapRootReducer=Ym,i.performRequest=Pi,i.projectAccessReducer=jr,i.projectAccessSlice=ui,i.projectAttachmentReducer=rd,i.projectAttachmentSlice=gi,i.projectFileReducer=Sd,i.projectFileSlice=bi,i.projectReducer=Mr,i.projectSlice=fi,i.rehydratedReducer=Td,i.rehydratedSlice=Ii,i.removeDocuments=ds,i.removeIssueType=ii,i.removeUser=yr,i.resetProjectFileObjectUrls=jm,i.resetStore=Ud,i.restructureCreateSelectorWithArgs=g,i.saveActiveProjectFileBounds=yd,i.selectAccessToken=Ru,i.selectActiveOrganizationAccess=dm,i.selectActiveProjectFileId=qm,i.selectActiveStatusLicenses=tm,i.selectAllDocumentAttachments=os,i.selectAllProjectAttachments=Ti,i.selectAncestorIdsOfDocument=Cu,i.selectAssetAttachmentById=hn,i.selectAssetAttachmentMapping=un,i.selectAssetAttachments=bt,i.selectAssetById=wt,i.selectAssetStageById=Pn,i.selectAssetStageCompletionById=Rn,i.selectAssetStageCompletionMapping=Dt,i.selectAssetStageCompletionsByIds=Fn,i.selectAssetStages=qn,i.selectAssetStagesByIds=zt,i.selectAssetTypeAttachmentById=$n,i.selectAssetTypeAttachmentMapping=Vn,i.selectAssetTypeAttachments=Bt,i.selectAssetTypeById=ts,i.selectAssetTypeFieldValues=Jt,i.selectAssetTypeFieldValuesAttachmentById=lu,i.selectAssetTypeFieldValuesAttachments=oa,i.selectAssetTypeFieldValuesAttachmentsByIds=ra,i.selectAssetTypeFieldValuesAttachmentsMapping=Ht,i.selectAssetTypeFieldValuesById=Xt,i.selectAssetTypeFieldValuesMapping=ya,i.selectAssetTypeFieldValuesOfAsset=mu,i.selectAssetTypeFields=Ve,i.selectAssetTypeFieldsAttachmentById=Xl,i.selectAssetTypeFieldsAttachments=Jn,i.selectAssetTypeFieldsAttachmentsMapping=Kn,i.selectAssetTypeFieldsById=nu,i.selectAssetTypeFieldsMapping=sa,i.selectAssetTypeFieldsOfAssetType=su,i.selectAssetTypeStagesMapping=Vl,i.selectAssetTypeValuesOfAssetType=fu,i.selectAssetTypes=Tu,i.selectAssetTypesByIds=bu,i.selectAssetTypesMapping=es,i.selectAssets=gn,i.selectAssetsByIds=kl,i.selectAssetsMapping=Ot,i.selectAssetsOfAssetType=vt,i.selectAttachmentsOfAsset=mn,i.selectAttachmentsOfAssetByType=El,i.selectAttachmentsOfAssetType=Bn,i.selectAttachmentsOfAssetTypeByType=Ll,i.selectAttachmentsOfAssetTypeFieldValues=da,i.selectAttachmentsOfAssetTypeFields=Jl,i.selectAttachmentsOfDocument=qu,i.selectAttachmentsOfDocumentByType=ku,i.selectAttachmentsOfFormRevision=Hu,i.selectAttachmentsOfFormSubmission=wc,i.selectAttachmentsOfIssue=oo,i.selectAttachmentsOfIssueByType=yh,i.selectAttachmentsOfIssueTypeFieldValues=Wo,i.selectAttachmentsOfIssueTypeFields=Oh,i.selectAttachmentsOfProject=od,i.selectAttachmentsOfProjectByType=Fm,i.selectCategories=Ou,i.selectCategoriesByIds=vu,i.selectCategoryById=as,i.selectCategoryMapping=ns,i.selectCommentsOfIssue=Sh,i.selectCompletedStagesByAsset=Cl,i.selectConversation=Fl,i.selectConversationMapping=yt,i.selectConversations=Rl,i.selectCurrentUser=st,i.selectDeletedRequests=Tm,i.selectDocumentAttachmentById=za,i.selectDocumentAttachmentMapping=Ma,i.selectDocumentById=Na,i.selectDocuments=La,i.selectDocumentsByIds=Du,i.selectDocumentsMapping=pe,i.selectEmailDomains=Xa,i.selectEmailDomainsAsMapping=Ja,i.selectEmailDomainsOfOrganization=Uu,i.selectFilteredForms=xu,i.selectFormById=Ic,i.selectFormMapping=_c,i.selectFormRevisionAttachmentsMapping=rc,i.selectFormRevisionById=Yu,i.selectFormRevisionMapping=Ne,i.selectFormRevisions=pc,i.selectFormRevisionsOfForm=Ac,i.selectFormSubmissionAttachemntsByIds=vc,i.selectFormSubmissionAttachmentsMapping=Ts,i.selectFormSubmissionById=Os,i.selectFormSubmissions=Fs,i.selectFormSubmissionsMapping=Rs,i.selectFormSubmissionsOfAsset=Cc,i.selectFormSubmissionsOfForm=kc,i.selectFormSubmissionsOfIssue=Dc,i.selectForms=Qu,i.selectGeoImageById=Es,i.selectGeoImageMapping=Nc,i.selectGeoImages=Hc,i.selectGeoImagesOfProject=rh,i.selectIsImportingProjectFile=km,i.selectIsLoggedIn=Fu,i.selectIssueAssociationById=Xc,i.selectIssueAssociationMapping=we,i.selectIssueAssociations=hh,i.selectIssueAssociationsOfAsset=xc,i.selectIssueAssociationsOfIssue=Qc,i.selectIssueAssociationsToIssue=Zc,i.selectIssueAttachmentById=ro,i.selectIssueAttachmentMapping=co,i.selectIssueAttachments=Us,i.selectIssueById=Ws,i.selectIssueCommentById=fo,i.selectIssueCommentMapping=mo,i.selectIssueCountOfCategory=wu,i.selectIssueMapping=To,i.selectIssueTypeById=ni,i.selectIssueTypeFieldValues=Zs,i.selectIssueTypeFieldValuesAttachmentById=Kh,i.selectIssueTypeFieldValuesAttachments=No,i.selectIssueTypeFieldValuesAttachmentsByIds=Ho,i.selectIssueTypeFieldValuesAttachmentsMapping=ti,i.selectIssueTypeFieldValuesById=Qs,i.selectIssueTypeFieldValuesMapping=qo,i.selectIssueTypeFieldValuesOfIssue=kh,i.selectIssueTypeFields=Ze,i.selectIssueTypeFieldsAttachmentById=vh,i.selectIssueTypeFieldsAttachments=wo,i.selectIssueTypeFieldsAttachmentsMapping=vo,i.selectIssueTypeFieldsById=Gh,i.selectIssueTypeFieldsMapping=Vo,i.selectIssueTypeFieldsOfIssueType=Vh,i.selectIssueTypeMapping=Qo,i.selectIssueTypeValuesOfIssueType=Bh,i.selectIssueTypes=xo,i.selectIssueTypesByIds=Jh,i.selectIssueTypesOfOrganization=Xh,i.selectIssueUpdateMapping=or,i.selectIssueUpdatesOfIssue=rr,i.selectIssuesByIds=Th,i.selectIssuesOfIssueType=ai,i.selectIssuesOfIssueTypeCount=Zh,i.selectLatestAssetTypeFieldsOfAssetType=iu,i.selectLatestFormRevisionOfForm=Ku,i.selectLatestIssueTypeFieldsOfIssueType=$h,i.selectLatestRetryTime=bm,i.selectLicense=em,i.selectLicenseForProject=hr,i.selectLicenses=tt,i.selectLicensesForProjectsMapping=sm,i.selectLicensesOfOrganization=gm,i.selectNumberOfAssetsOfAssetType=Dl,i.selectOrganizationAccessById=rm,i.selectOrganizationAccessForUser=lm,i.selectOrganizationAccessUserMapping=_r,i.selectOrganizationAccesses=li,i.selectOrganizationById=pm,i.selectOrganizationUsersAsMapping=Nr,i.selectOrganizationUsersIds=Lr,i.selectOrganizations=Gr,i.selectOrganizationsMapping=Br,i.selectOrganizationsWithAccess=ym,i.selectProjectAccessById=um,i.selectProjectAccessForUser=hm,i.selectProjectAccessMapping=mi,i.selectProjectAccessUserMapping=Er,i.selectProjectAccesses=wr,i.selectProjectAttachmentById=cd,i.selectProjectAttachmentMapping=ad,i.selectProjectById=mm,i.selectProjectFileById=Pm,i.selectProjectFileMapping=Ad,i.selectProjectFiles=gd,i.selectProjectMapping=pi,i.selectProjectUsersAsMapping=Ur,i.selectProjectUsersIds=zr,i.selectProjectsOfOrganization=Am,i.selectRehydrated=Mm,i.selectRootDocuments=Mu,i.selectSortedOrganizationUsers=Sm,i.selectSortedProjectUsers=fm,i.selectStageMapping=Ue,i.selectStagesOfAssetType=kn,i.selectTeamById=Se,i.selectTeams=wi,i.selectTeamsByIds=zm,i.selectTeamsMapping=vi,i.selectTeamsOfOrganization=Um,i.selectTeamsOfUser=Vm,i.selectUploadUrl=tc,i.selectUserById=cm,i.selectUsersByIds=om,i.selectUsersMapping=it,i.separateFilesFromValues=Di,i.separateImageFromFields=Df,i.setActiveProjectFileId=pd,i.setAsset=Pl,i.setAssetAttachment=rn,i.setAssetAttachments=vl,i.setAssetStage=En,i.setAssetStages=Ml,i.setAssetType=pu,i.setAssetTypeAttachment=Mn,i.setAssetTypeAttachments=Bl,i.setAssetTypeFieldValues=uu,i.setAssetTypeFieldValuesAttachment=cu,i.setAssetTypeFieldValuesAttachments=ou,i.setAssetTypeFieldValuesMany=hu,i.setAssetTypeFields=Ql,i.setAssetTypeFieldsAttachment=Hl,i.setAssetTypeFieldsAttachments=Wl,i.setAssetTypeFieldsMany=xl,i.setAssetTypes=yu,i.setAssets=ql,i.setConversation=nn,i.setCurrentUser=im,i.setDocumentAttachment=qa,i.setDocumentAttachments=ju,i.setDocuments=$a,i.setForm=Ju,i.setFormRevision=uc,i.setFormRevisionAttachment=Bu,i.setFormRevisionAttachments=Gu,i.setFormSubmission=Ye,i.setFormSubmissionAttachment=th,i.setFormSubmissionAttachments=sh,i.setFormSubmissions=ah,i.setGeoImage=ve,i.setGeoImages=Vc,i.setIsImportingProjectFile=fd,i.setIssueAssociation=lh,i.setIssueAssociations=dh,i.setIssueAttachment=io,i.setIssueAttachments=fh,i.setIssueComment=$s,i.setIssueComments=ho,i.setIssueType=je,i.setIssueTypeFieldValues=Eh,i.setIssueTypeFieldValuesAttachment=Nh,i.setIssueTypeFieldValuesAttachments=Hh,i.setIssueTypeFieldValuesMany=jh,i.setIssueTypeFields=Ch,i.setIssueTypeFieldsAttachment=_h,i.setIssueTypeFieldsAttachments=Ih,i.setIssueTypeFieldsMany=Mh,i.setIssueUpdate=Qh,i.setLoggedIn=_a,i.setOrganizations=$r,i.setProfilePicture=nm,i.setProjectAttachment=td,i.setProjectAttachments=sd,i.setProjectFile=Om,i.setProjectFiles=vm,i.setProjects=qr,i.setRehydrated=Cm,i.setTeam=ge,i.setTokens=_u,i.setUploadUrl=ec,i.setUsers=pr,i.shallowEqual=Yi,i.slugify=Tl,i.spacesToDashesLower=Sl,i.teamReducer=Rd,i.teamSlice=Ri,i.toFileNameSafeString=gl,i.toOfflineIdRecord=Qi,i.truncate=bl,i.updateAsset=Ie,i.updateAssetAttachment=wl,i.updateAssetAttachments=dn,i.updateAssetStage=Mt,i.updateAssetStageCompletion=_n,i.updateAssetStageCompletions=In,i.updateAssetStages=Me,i.updateAssetType=Fe,i.updateAssetTypeAttachment=Gl,i.updateAssetTypeAttachments=zn,i.updateAssetTypeFieldValues=Re,i.updateAssetTypeFieldValuesAttachment=ru,i.updateAssetTypeFieldValuesAttachments=ca,i.updateAssetTypeFieldValuesMany=fa,i.updateAssetTypeFields=ea,i.updateAssetTypeFieldsAttachment=Yl,i.updateAssetTypeFieldsAttachments=Wn,i.updateAssetTypeFieldsMany=eu,i.updateAssetTypes=gu,i.updateAssets=jl,i.updateCategory=Oa,i.updateConversation=an,i.updateDocumentAttachment=Pu,i.updateDocumentAttachments=ka,i.updateDocuments=ne,i.updateForm=Zu,i.updateFormRevisionAttachment=Lu,i.updateFormRevisionAttachments=cc,i.updateFormSubmission=qc,i.updateFormSubmissionAttachment=ih,i.updateFormSubmissionAttachments=Oc,i.updateFormSubmissions=ch,i.updateGeoImage=Gc,i.updateGeoImages=oh,i.updateIssue=Xe,i.updateIssueAssociation=Jc,i.updateIssueAssociations=uh,i.updateIssueAttachment=ph,i.updateIssueAttachments=no,i.updateIssueType=Zo,i.updateIssueTypeFieldValues=Ee,i.updateIssueTypeFieldValuesAttachment=Wh,i.updateIssueTypeFieldValuesAttachments=Lo,i.updateIssueTypeFieldValuesMany=Ph,i.updateIssueTypeFields=zo,i.updateIssueTypeFieldsAttachment=Rh,i.updateIssueTypeFieldsAttachments=Fo,i.updateIssueTypeFieldsMany=zh,i.updateLicense=te,i.updateOrganizationAccess=Tr,i.updateProject=kr,i.updateProjectAccess=Fr,i.updateProjectAttachment=Rm,i.updateProjectAttachments=id,i.updateProjectFile=_i,i.updateProjectFiles=Em,i.updateTeam=Fi,i.userReducer=Ar,i.userSlice=ri,i.versioningReducer=Od,i.versioningSlice=Fd,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});