@overmap-ai/core 1.0.74-model-indexes.0 → 1.0.74-model-indexes.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/overmap-core.js
CHANGED
|
@@ -2756,6 +2756,7 @@ class Mp extends w {
|
|
|
2756
2756
|
throw new Error("Asset must have either a canvas_marker or geo_marker");
|
|
2757
2757
|
const i = s.getState().userReducer.currentUser.id, n = (/* @__PURE__ */ new Date()).toISOString(), a = R({
|
|
2758
2758
|
...e,
|
|
2759
|
+
index: null,
|
|
2759
2760
|
created_by: i,
|
|
2760
2761
|
submitted_at: n
|
|
2761
2762
|
});
|
|
@@ -3322,6 +3323,7 @@ class Bp extends k {
|
|
|
3322
3323
|
var o;
|
|
3323
3324
|
const { store: s } = this.client, i = s.getState(), n = R({
|
|
3324
3325
|
...e,
|
|
3326
|
+
index: null,
|
|
3325
3327
|
created_by: (o = i.userReducer.currentUser) == null ? void 0 : o.id,
|
|
3326
3328
|
submitted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3327
3329
|
}), a = this.enqueueRequest({
|
|
@@ -4398,6 +4400,7 @@ class af extends k {
|
|
|
4398
4400
|
file_name: i.name,
|
|
4399
4401
|
file_sha1: u.sha1,
|
|
4400
4402
|
file: URL.createObjectURL(i),
|
|
4403
|
+
index: null,
|
|
4401
4404
|
submitted_at: a,
|
|
4402
4405
|
created_by: o
|
|
4403
4406
|
});
|
|
@@ -4441,6 +4444,7 @@ class af extends k {
|
|
|
4441
4444
|
file_sha1: T.sha1,
|
|
4442
4445
|
file: URL.createObjectURL(f),
|
|
4443
4446
|
submitted_at: n,
|
|
4447
|
+
index: null,
|
|
4444
4448
|
created_by: a,
|
|
4445
4449
|
project: s
|
|
4446
4450
|
});
|
|
@@ -4709,6 +4713,7 @@ class df extends w {
|
|
|
4709
4713
|
var u;
|
|
4710
4714
|
const { store: s } = this.client, i = s.getState(), n = (/* @__PURE__ */ new Date()).toISOString(), a = (u = i.userReducer.currentUser) == null ? void 0 : u.id, o = R({
|
|
4711
4715
|
...e,
|
|
4716
|
+
index: null,
|
|
4712
4717
|
submitted_at: n,
|
|
4713
4718
|
created_by: a
|
|
4714
4719
|
});
|
|
@@ -6,10 +6,10 @@ Action:`,e);const f=ue();if(!f)throw new Error("Outbox coordinator not set");f.r
|
|
|
6
6
|
`):c.map(o=>`${a}: ${o}`).join(`
|
|
7
7
|
`):`${a}: ${JSON.stringify(c)}`).join(`
|
|
8
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
|
|
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,index:null,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,index:null,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
|
|
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=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),index:null,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,index:null,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,index:null,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"})});
|
|
@@ -16,7 +16,7 @@ export type Offline<T> = T & {
|
|
|
16
16
|
offline_id: string;
|
|
17
17
|
};
|
|
18
18
|
export type OfflineIdMapping<TModel extends OfflineModel> = Record<TModel["offline_id"], TModel>;
|
|
19
|
-
export type Payload<TModel> = Omit<TModel, "offline_id" | "created_at" | "updated_at" | "id" | "submitted_at" | "created_by">;
|
|
19
|
+
export type Payload<TModel> = Omit<TModel, "offline_id" | "created_at" | "updated_at" | "id" | "submitted_at" | "created_by" | "index">;
|
|
20
20
|
export type MaybePayload<TModel extends OfflineModel> = Payload<TModel> & {
|
|
21
21
|
offline_id?: string | null;
|
|
22
22
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FileWithNameModel } from '../files';
|
|
2
|
-
import { CreatedByModel, IndexedModel, OfflineModel, SubmittedAtModel } from './base';
|
|
2
|
+
import { CreatedByModel, IndexedModel, OfflineModel, Payload, SubmittedAtModel } from './base';
|
|
3
3
|
import { CanvasMarkableModel, MarkableModel } from './geo';
|
|
4
4
|
export interface GeoImage extends OfflineModel, SubmittedAtModel, CreatedByModel, MarkableModel, CanvasMarkableModel, FileWithNameModel, IndexedModel {
|
|
5
5
|
title?: string;
|
|
@@ -8,7 +8,7 @@ export interface GeoImage extends OfflineModel, SubmittedAtModel, CreatedByModel
|
|
|
8
8
|
direction?: number;
|
|
9
9
|
original_date?: string;
|
|
10
10
|
}
|
|
11
|
-
export type GeoImagePayload = Omit<GeoImage
|
|
11
|
+
export type GeoImagePayload = Omit<Payload<GeoImage>, "file_name" | "file_sha1" | "file"> & {
|
|
12
12
|
file: File;
|
|
13
13
|
};
|
|
14
14
|
export type BulkGeoImagePayload = Omit<GeoImagePayload, "project">;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Core functionality for Overmap",
|
|
4
4
|
"author": "Wôrdn Inc.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
|
-
"version": "1.0.74-model-indexes.
|
|
6
|
+
"version": "1.0.74-model-indexes.2",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/overmap-core.umd.cjs",
|
|
9
9
|
"module": "dist/overmap-core.js",
|