@overmap-ai/core 1.0.78-view-sets.24 → 1.0.78-view-sets.26

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.
@@ -5223,7 +5223,7 @@ class n_ extends De {
5223
5223
  method: u.GET,
5224
5224
  url: "/document-attachments/",
5225
5225
  queryParams: {
5226
- project__organization: s
5226
+ document__project__owner_organization: s
5227
5227
  },
5228
5228
  blocks: [],
5229
5229
  blockers: []
@@ -5232,14 +5232,12 @@ class n_ extends De {
5232
5232
  method: u.GET,
5233
5233
  url: "/document-attachments/",
5234
5234
  queryParams: {
5235
- organization: s
5235
+ document__organization: s
5236
5236
  },
5237
5237
  blocks: [],
5238
5238
  blockers: []
5239
- });
5240
- return this.dispatch(
5241
- Dd([...i, ...a])
5242
- ), [...i, ...a];
5239
+ }), n = [...i, ...a];
5240
+ return this.dispatch(Dd(n)), n;
5243
5241
  }
5244
5242
  }
5245
5243
  class c_ extends v {
@@ -5315,7 +5313,7 @@ class c_ extends v {
5315
5313
  method: u.GET,
5316
5314
  url: "/documents/",
5317
5315
  queryParams: {
5318
- project__organization: e
5316
+ project__owner_organization: e
5319
5317
  },
5320
5318
  blockers: [],
5321
5319
  blocks: []
@@ -5,7 +5,7 @@ Retries:`,s),!(t instanceof Error))throw console.error("ENCOUNTERED NON-ERROR ER
5
5
  Action:`,e);const p=Ce();if(!p)throw new Error("Outbox coordinator not set");p.remove(e.payload.uuid),t.options.discard=!0,o()}}console.debug("Registering a retry for request:",e.payload.uuid);const m=Ce();if(!m)throw new Error("Outbox coordinator not set");return m.registerRetry(e.payload.uuid),!1}function ib(t,e,s){var i;return(i=Ce())==null?void 0:i.peek()}function cb(t,e){return ut().dispatch(Zl(new Date().getTime())),yc}const He="An unknown error occurred",nb=500,rm=["non_field_errors","detail"];function rb(t,e){let s;if(t!=null&&t.body)if(typeof t.body=="object"){const i=t.body;if(typeof i.error=="string")s=i.error;else if(typeof i.message=="string")s=i.message;else try{s=Object.entries(i).map(([c,n])=>typeof n=="string"?rm.includes(c)?n:`${c}: ${n}`:Array.isArray(n)?rm.includes(c)?n.join(`
6
6
  `):n.map(r=>`${c}: ${r}`).join(`
7
7
  `):`${c}: ${JSON.stringify(n)}`).join(`
8
- `)}catch(c){console.error("Failed to extract error message from response body",c)}}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>nb?He:s}class U extends Error{constructor(s){super(He);S(this,"status");S(this,"response");S(this,"message");S(this,"options");const{response:i,innerError:c}=s;this.message=s.message??rb(i,c)??He,this.status=(i==null?void 0:i.status)??0,this.response=i,s.discard=s.discard??!1,this.options=s}}class db extends Qh{constructor(e){super(e)}}class R extends Qh{constructor(s,i){super(s);S(this,"auth");this.auth=i}}class ub extends R{async startConversation(e,s){return this.enqueueRequest({description:"Start agent conversation",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:s},blockers:["prompt"],blocks:["prompt"]}).then(i=>(this.dispatch(Rc(i)),i))}async continueConversation(e,s,i){return this.enqueueRequest({description:"Prompt agent",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:i},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:s}}).then(c=>{this.dispatch(wc(c))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:h.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(s=>{this.dispatch(vc(s))})}async rate(e,s){return this.enqueueRequest({description:"Rate agent response",method:h.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:s},blockers:["rate"],blocks:["rate"]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get agent conversation history",method:h.GET,url:"/agents/conversations/",queryParams:{project:e},blockers:["agent-conversations"],blocks:["agent-conversations"]});return this.dispatch(_c(s)),s}}class j extends R{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:s,assetAttachmentReducer:i,assetTypeAttachmentReducer:c,documentAttachmentReducer:n,projectAttachmentReducer:r,formRevisionAttachmentReducer:o,formSubmissionAttachmentReducer:m,geoImageReducer:u,assetTypeFieldsAttachmentReducer:l,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:A,issueTypeFieldValuesAttachmentReducer:y}=this.client.store.getState();return[].concat(Object.values(s.instances),Object.values(i.instances),Object.values(c.instances),Object.values(n.instances),Object.values(r.instances),Object.values(o.instances),Object.values(m.instances),Object.values(u.instances),Object.values(l.instances),Object.values(p.instances),Object.values(A.instances),Object.values(y.instances)).filter(P=>P.file_sha1===e).length}processPresignedUrls(e){const s={};for(const[i,c]of Object.entries(e))s[i]=this.enqueueRequest({url:c.url,description:"Upload file to S3",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:i,blockers:[`s3-${c.fields.key}`],blocks:[i],s3url:c});return s}async getFilePayload(e){const s=await Le(e),i={sha1:s,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,s),i}}class De extends j{async _bulkAdd(e){var u;const{store:s}=this.client,i=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,c=new Date().toISOString(),n=[],r=[],o={};for(const l of e){const{modelUuid:p,file:A}=l,y=await this.getFilePayload(A);y.sha1 in o||(o[y.sha1]=y);const b=this.buildOfflineAttachment({file:A,file_sha1:y.sha1,submitted_at:c,created_by:i,description:"",modelUuid:p});n.push(b),r.push(this.buildAttachmentPayload({uuid:b.uuid,file_name:b.file_name,file_sha1:b.file_sha1,file_extension:y.extension,description:b.description,modelUuid:p}))}this.dispatch(this.addAttachments(n));const m=this.enqueueRequest({description:`Add ${this.name}`,method:h.POST,url:`${this.url}/bulk/`,payload:{submitted_at:c,attachments:r,files:Object.values(o)},blocks:n.map(l=>l.uuid),blockers:n.map(l=>l.file_sha1)});return m.then(({attachments:l,presigned_urls:p})=>{this.dispatch(this.updateAttachments(l)),this.processPresignedUrls(p)}).catch(()=>{this.dispatch(this.removeAttachments(n.map(l=>l.uuid)))}),[n,m.then(({attachments:l})=>l)]}async _delete(e){const{store:s}=this.client,i=this.selectAttachment(e)(s.getState());if(!i)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(i.uuid));const c=this.enqueueRequest({description:`Delete ${this.name}`,method:h.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return c.then(()=>{this.getNumberOfAttachmentsWithSha1(i.file_sha1)===0&&this.client.files.removeCache(i.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(i))}),c}}class ob extends De{constructor(){super(...arguments);S(this,"name","Asset Attachment");S(this,"url","/asset-attachments");S(this,"initializeAttachments",Xt);S(this,"addAttachments",Qt);S(this,"updateAttachments",qc);S(this,"removeAttachments",xt);S(this,"removeAttachment",Vc);S(this,"setAttachment",jc);S(this,"selectAttachment",Dc)}buildOfflineAttachment(s){return T({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(i=>({modelUuid:i.assetUuid,file:i.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const i=await this.enqueueRequest({description:"Get asset attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset__project:s},blocks:[],blockers:[]});return this.dispatch(Xt(i)),i}}class lb extends De{constructor(){super(...arguments);S(this,"name","Asset Procedure Attachment");S(this,"url","/asset-procedure-attachments");S(this,"addAttachments",Gc);S(this,"updateAttachments",Nc);S(this,"removeAttachments",Wc);S(this,"removeAttachment",Hc);S(this,"setAttachment",Lc);S(this,"selectAttachment",Jc)}buildOfflineAttachment(s){return T({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_procedure:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset_procedure:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(i=>({modelUuid:i.assetProcedureUuid,file:i.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const i=await this.enqueueRequest({description:"Get asset procedure attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset_procedure__organization:s},blocks:[],blockers:[]});return this.dispatch($c(i)),i}}class hb extends j{async bulkAdd(e){var m;const s=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:l,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:l,submitted_at:s,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:l};r.push(P)}this.dispatch(xc(n));const o=this.enqueueRequest({description:"Add asset procedure fields attachments",method:h.POST,url:"/asset-procedure-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return o.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(en(u.attachments))}).catch(()=>{this.dispatch(tn(n.map(u=>u.uuid)))}),[n,o.then(({attachments:u})=>u)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure fields attachments",method:h.GET,url:"/asset-procedure-fields-attachments/",queryParams:{fields_revision__asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(Qc(s)),s}}class mb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(dn(n));const r=this.enqueueRequest({description:"Add Asset Procedure Fields",method:h.POST,url:"/asset-procedure-fields/",payload:v(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(un(m))}).catch(m=>{throw this.dispatch(on(n.uuid)),m}),[n,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Procedure Fields",method:h.GET,url:"/asset-procedure-fields/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(rn(s)),s}}function ke(t,e){const s=[];let i=0;const c=t.length;for(;i<c;)s.push(t.slice(i,i+=e));return s}class pb extends j{async bulkAdd(e,s){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=ke(e,s??e.length),r=[],o=[];for(const l of n){const p={},A=[];for(const y of l){const{fieldValuesUuid:b,fieldIdentifier:P,file:O}=y,w=await this.getFilePayload(O);w.sha1 in p||(p[w.sha1]=w);const q=T({file:URL.createObjectURL(O),file_type:O.type,file_name:O.name,file_sha1:w.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(q);const Ke={uuid:q.uuid,file_name:O.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:P,field_values:b};A.push(Ke)}o.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(ht(r));const m=o.map(l=>this.enqueueRequest({description:"Add asset procedure field values attachments",method:h.POST,url:"/asset-procedure-field-values-attachments/bulk/",payload:l,blockers:l.attachments.map(p=>p.field_values),blocks:l.attachments.map(p=>p.uuid)}));return Promise.all(m).then(l=>{for(const A of l)this.processPresignedUrls(A.presigned_urls);const p=l.flatMap(A=>A.attachments);this.dispatch(An(p))}).catch(l=>{throw this.dispatch(mt(r.map(p=>p.uuid))),l}),[r,m.map(l=>l.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,i=s.getState(),c=fn(e)(i);this.dispatch(mt(e));try{await this.enqueueRequest({description:"Delete asset procedure field values attachments",method:h.DELETE,url:"/asset-procedure-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(ht(c)),n}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values attachments",method:h.GET,url:"/asset-procedure-field-values-attachments/",queryParams:{field_values__asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(pn(s)),s}}class Ab extends R{add(e){var r;const{store:s}=this.client,i=s.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/",payload:v(c),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[c.uuid]});return this.dispatch(rs(c)),n.then(o=>(this.dispatch(Je(o)),o)).catch(()=>{this.dispatch(ds(c.uuid))}),[c,n]}bulkAdd(e,s){var m;const i=new Date().toISOString(),c=[],n=ke(e.payloads,s??e.payloads.length),r=[];for(const u of n){const l=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),l.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure_instance:p.asset_procedure_instance,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:l})}this.dispatch(Fn(c));const o=[];for(const u of r){const l=u.field_values.map(P=>P.asset),p=u.field_values.map(P=>P.fields_revision),A=u.field_values.map(P=>P.asset_procedure_instance),y=u.field_values.map(P=>P.uuid),b=this.enqueueRequest({description:"Bulk add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/bulk/",payload:u,blockers:[...l,...p,...A],blocks:y});o.push(b)}return Promise.all(o).then(u=>{this.dispatch(Tn(u.flat()))}).catch(()=>{this.dispatch(In(c.map(u=>u.uuid)))}),[c,o]}update(e){const{store:s}=this.client,i=s.getState(),c=os(e.uuid)(i);if(!c)throw new Error(`Expected AssetProcedureFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(Je(n));const r=this.enqueueRequest({description:"Update asset procedure field values",method:h.PATCH,url:`/asset-procedure-field-values/${e.uuid}/`,payload:e,blockers:[n.fields_revision,n.asset,n.asset_procedure_instance],blocks:[n.uuid]});return r.then(o=>{this.dispatch(Je(o))}).catch(()=>{this.dispatch(Je(c))}),[n,r]}async delete(e){const{store:s}=this.client,i=s.getState(),c=os(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=Sn(e)(i);this.dispatch(ds(e)),this.dispatch(mt(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure field values",method:h.DELETE,url:`/asset-procedure-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(rs(c)),this.dispatch(ht(n)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values",method:h.GET,url:"/asset-procedure-field-values/",queryParams:{asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(Pn(s)),s}}class yb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(hs(n));const r=this.enqueueRequest({description:"Create asset procedure instance",method:h.POST,url:"/asset-procedure-instances/",payload:v(n),blockers:[e.asset_procedure,e.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Ze(m))}).catch(()=>{this.dispatch(ms(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=ys(e.uuid)(s.getState());if(!i)throw new Error(`Expected asset procedure instance with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(Ze(c));const n=this.enqueueRequest({description:"Update asset procedure instance",method:h.PATCH,url:`/asset-procedure-instances/${e.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Ze(r))}).catch(()=>{this.dispatch(Ze(i))}),[c,n]}async remove(e){const{store:s}=this.client,i=s.getState(),c=ys(e)(i);if(!c)throw new Error(`Expected asset procedure instance with uuid ${e} to exist`);return this.dispatch(ms(e)),this.enqueueRequest({description:"Delete asset procedure instance",method:h.DELETE,url:`/asset-procedure-instances/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(hs(c)),n})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure instances",method:h.GET,url:"/asset-procedure-instances/",queryParams:{project:e},blockers:[],blocks:[]});return this.dispatch(vn(s)),s}}class fb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Ss(n));const r=this.enqueueRequest({description:"Create asset procedure",method:h.POST,url:"/asset-procedures/",payload:v(n),blockers:[],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Xe(m))}).catch(()=>{this.dispatch(gs(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=Ps(e.uuid)(s.getState());if(!i)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(Xe(c));const n=this.enqueueRequest({description:"Update asset procedure",method:h.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Xe(r))}).catch(()=>{this.dispatch(Xe(i))}),[c,n]}async remove(e){const{store:s}=this.client,i=s.getState(),c=Ps(e)(i);if(!c)throw new Error(`Expected asset procedure with uuid ${e} to exist`);const n=En(e)(i);return this.dispatch(gs(e)),this.dispatch(Mn(n.map(r=>r.uuid))),this.enqueueRequest({description:"Delete asset procedure",method:h.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(Ss(c)),this.dispatch(wn(n)),r})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedures",method:h.GET,url:"/asset-procedures/",queryParams:{organization:e},blockers:[],blocks:[]});return this.dispatch(Vn(s)),s}}class Sb extends j{async bulkAdd(e){var m;const s=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:l,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:l,submitted_at:s,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:l};r.push(P)}this.dispatch(kn(n));const o=this.enqueueRequest({description:"Add asset procedure step fields attachments",method:h.POST,url:"/asset-procedure-step-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return o.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(Bn(u.attachments))}).catch(()=>{this.dispatch($n(n.map(u=>u.uuid)))}),[n,o.then(({attachments:u})=>u)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure step fields attachments",method:h.GET,url:"/asset-procedure-step-fields-attachments/",queryParams:{fields_revision__asset_procedure_step__organization:e},blockers:[],blocks:[]});return this.dispatch(Cn(s)),s}}class gb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Is(n));const r=this.enqueueRequest({description:"Add Asset Procedure Step Fields",method:h.POST,url:"/asset-procedure-step-fields/",payload:v(n),blockers:[n.asset_procedure_step],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Qe(m))}).catch(m=>{throw this.dispatch(Os(n.uuid)),m}),[n,r]}update(e){const{store:s}=this.client,i=s.getState().assetProcedureStepFieldsReducer.instances[e.uuid];if(!i)throw new Error(`AssetProcedureStepFields with uuid ${e.uuid} not found`);const c={...i,...e};this.dispatch(Qe(c));const n=this.enqueueRequest({description:"Update Asset Procedure Step Fields",method:h.PATCH,url:`/asset-procedure-step-fields/${i.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Qe(r))}).catch(r=>{throw this.dispatch(Qe(i)),r}),[c,n]}delete(e){const{store:s}=this.client,i=s.getState().assetProcedureStepFieldsReducer.instances[e];if(!i)throw new Error(`AssetProcedureStepFields with uuid ${e} not found`);this.dispatch(Os(e));const c=this.enqueueRequest({description:"Delete Asset Procedure Step Fields",method:h.DELETE,url:`/asset-procedure-step-fields/${e}/`,blockers:[e],blocks:[e]});return c.catch(n=>{throw this.dispatch(Is(i)),n}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Procedure Step Fields",method:h.GET,url:"/asset-procedure-step-fields/",queryParams:{asset_procedure_step__asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(Wn(s)),s}}class bb extends j{async bulkAdd(e,s){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=ke(e,s??e.length),r=[],o=[];for(const l of n){const p={},A=[];for(const y of l){const{fieldValuesUuid:b,fieldIdentifier:P,file:O}=y,w=await this.getFilePayload(O);w.sha1 in p||(p[w.sha1]=w);const q=T({file:URL.createObjectURL(O),file_type:O.type,file_name:O.name,file_sha1:w.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(q);const Ke={uuid:q.uuid,file_name:O.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:P,field_values:b};A.push(Ke)}o.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(pt(r));const m=o.map(l=>this.enqueueRequest({description:"Add asset procedure step field values attachments",method:h.POST,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:l,blockers:l.attachments.map(p=>p.field_values),blocks:l.attachments.map(p=>p.uuid)}));return Promise.all(m).then(l=>{for(const A of l)this.processPresignedUrls(A.presigned_urls);const p=l.flatMap(A=>A.attachments);this.dispatch(Zn(p))}).catch(l=>{throw this.dispatch(At(r.map(p=>p.uuid))),l}),[r,m.map(l=>l.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,i=s.getState(),c=Qn(e)(i);this.dispatch(At(e));try{await this.enqueueRequest({description:"Delete asset procedure step field values attachments",method:h.DELETE,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(pt(c)),n}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure step field values attachments",method:h.GET,url:"/asset-procedure-step-field-values-attachments/",queryParams:{field_values__asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(Jn(s)),s}}class Pb extends R{add(e){var r;const{store:s}=this.client,i=s.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset procedure step field values",method:h.POST,url:"/asset-procedure-step-field-values/",payload:v(c),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[c.uuid]});return this.dispatch(Es(c)),n.then(o=>(this.dispatch(xe(o)),o)).catch(()=>{this.dispatch(js(c.uuid))}),[c,n]}bulkAdd(e,s){var m;const i=new Date().toISOString(),c=[],n=ke(e.payloads,s??e.payloads.length),r=[];for(const u of n){const l=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),l.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure_instance:p.asset_procedure_instance,asset_procedure_step:p.asset_procedure_step,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:l})}this.dispatch(ar(c));const o=[];for(const u of r){const l=u.field_values.map(P=>P.asset),p=u.field_values.map(P=>P.fields_revision),A=u.field_values.map(P=>P.asset_procedure_instance),y=u.field_values.map(P=>P.uuid),b=this.enqueueRequest({description:"Bulk add asset procedure step field values",method:h.POST,url:"/asset-procedure-step-field-values/bulk/",payload:u,blockers:[...l,...p,...A],blocks:y});o.push(b)}return Promise.all(o).then(u=>{this.dispatch(ir(u.flat()))}).catch(()=>{this.dispatch(cr(c.map(u=>u.uuid)))}),[c,o]}update(e){const{store:s}=this.client,i=s.getState(),c=qs(e.uuid)(i);if(!c)throw new Error(`Expected AssetProcedureStepFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(xe(n));const r=this.enqueueRequest({description:"Update asset procedure step field values",method:h.PATCH,url:`/asset-procedure-step-field-values/${e.uuid}/`,payload:e,blockers:[n.fields_revision,n.asset,n.asset_procedure_instance],blocks:[n.uuid]});return r.then(o=>{this.dispatch(xe(o))}).catch(()=>{this.dispatch(xe(c))}),[n,r]}async delete(e){const{store:s}=this.client,i=s.getState(),c=qs(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=xn(e)(i);this.dispatch(js(e)),this.dispatch(At(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure step field values",method:h.DELETE,url:`/asset-procedure-step-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Es(c)),this.dispatch(pt(n)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure step field values",method:h.GET,url:"/asset-procedure-step-field-values/",queryParams:{asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(sr(s)),s}}class Fb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(zs(n));const r=this.enqueueRequest({description:"Create asset procedure step",method:h.POST,url:"/asset-procedure-steps/",payload:v(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(ft(m))}).catch(()=>{this.dispatch(Us(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=Ds(e.uuid)(s.getState());if(!i)throw new Error(`No asset procedure step with uuid ${e.uuid} found in the store`);const c={...i,...e};this.dispatch(ft(c));const n=this.enqueueRequest({description:"Update asset procedure step",method:h.PATCH,url:`/asset-procedure-steps/${i.uuid}/`,payload:{name:e.name,description:e.description,priority:e.order,color:e.color},blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(ft(r))}).catch(()=>{this.dispatch(or(i))}),[c,n]}async delete(e){const{store:s}=this.client,i=s.getState(),c=Ds(e)(i);if(!c)throw new Error(`No asset procedure step with uuid ${e} found in the store`);return this.dispatch(Us(e)),this.enqueueRequest({description:"Delete asset stage",method:h.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(zs(c)),n})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure steps",method:h.GET,url:"/asset-procedure-steps/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(ur(s)),s}}class Tb extends R{add(e){var o;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 i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(ks(n));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/assets/",payload:v(n),blockers:[n.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(et(m))}).catch(()=>{this.dispatch(Bs(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=Ns(e.uuid)(s.getState());if(!i)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const c={...i,...e};if(!c.canvas_marker&&!c.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");this.dispatch(et(c));const n=this.enqueueRequest({description:"Edit asset",method:h.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return n.then(r=>{this.dispatch(et(r))}).catch(()=>{this.dispatch(et(i))}),[c,n]}async delete(e){const{store:s}=this.client,i=s.getState(),c=Ns(e)(i);if(!c)throw new Error(`No asset with uuid ${e} found in the store`);const n=Cc(e)(i),r=Vu(e)(i),o=Qu(e)(i);if(this.dispatch(Bs(e)),n.length>0){const m=n.map(({uuid:u})=>u);this.dispatch(xt(m))}if(r.length>0){const m=r.map(({uuid:u})=>u);this.dispatch(jt(m))}if(o.length>0){const m=o.map(({uuid:u})=>u);this.dispatch(Za(m))}return this.enqueueRequest({description:"Delete asset",method:h.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(ks(c)),this.dispatch(Qt(n)),this.dispatch(Et(r)),this.dispatch(Ya(o)),m})}bulkAdd(e,s,i,c){const n=new Date().toISOString(),r=Ge.v4(),o=ke(e,c).map(l=>{const p=l.map(A=>T(A));return{batchId:Ge.v4(),payload:{transaction_id:r,submitted_at:n,asset_type:s,project:i,assets:p}}}),m=[];let u=null;for(const l of o){const{batchId:p,payload:A}=l,y=A.assets.map(w=>w.uuid),b=[s];u&&b.push(u);const P=y;P.push(p);const O=this.enqueueRequest({description:"Batch create assets",method:h.POST,url:"/assets/bulk/",payload:A,blockers:b,blocks:P});u=l.batchId,m.push(O)}return Promise.all(m).then(l=>{const p=l.flat();this.dispatch(gt(p))}),m}async bulkDelete(e){const{store:s}=this.client,i=s.getState(),c=yr(e)(i);this.dispatch($s(e));try{await this.enqueueRequest({description:"Bulk delete assets",method:h.DELETE,url:"/assets/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(gt(c)),n}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get assets",method:h.GET,url:"/assets/",queryParams:{project:e},blockers:[],blocks:[]});return this.dispatch(pr(s)),s}}class Ib extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Ws(n));const r=this.enqueueRequest({description:"Add asset stage completion",method:h.POST,url:"/asset-stage-completions/",payload:v(n),blockers:[e.asset,e.stage],blocks:[n.uuid]});return r.then(m=>{this.dispatch(br(m))}).catch(()=>{this.dispatch(Ys(n.uuid))}),[n,r]}delete(e){const{store:s}=this.client,i=Tr(e)(s.getState());if(!i)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(Ys(e));const c=this.enqueueRequest({description:"Delete asset stage completion",method:h.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return c.catch(()=>{this.dispatch(Ws(i))}),c}bulkAdd(e){var u;const{store:s}=this.client,i=new Date().toISOString(),c=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,n=e.map(l=>T(l)),r=n.map(l=>({...l,created_by:c,submitted_at:i})),o=r.map(({uuid:l})=>l);this.dispatch(Ks(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:h.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:i,completions:n},blockers:[...e.map(l=>l.asset_procedure_instance),...e.map(l=>l.stage),...e.map(l=>l.asset)],blocks:o});return m.then(l=>{this.dispatch(Pr(l))}).catch(()=>{this.dispatch(Js(o))}),[r,m]}bulkDelete(e){const{store:s}=this.client,i=Ir(e)(s.getState());this.dispatch(Js(e));const c=this.enqueueRequest({description:"Deleting asset stage completions",method:h.DELETE,url:"/asset-stage-completions/bulk/",payload:{uuids:e},blockers:e,blocks:[]});return c.catch(()=>{this.dispatch(Ks(i))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stage completions",method:h.GET,url:"/asset-stage-completions/",queryParams:{asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(gr(s)),s}}class Ob extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Qs(n));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/asset-stages/",payload:v(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(bt(m))}).catch(()=>{this.dispatch(xs(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=ea(e.uuid)(s.getState());if(!i)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const c={...i,...e};this.dispatch(bt(c));const n=this.enqueueRequest({description:"Update asset stage",method:h.PATCH,url:`/asset-stages/${i.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(bt(r))}).catch(()=>{this.dispatch(Rr(i))}),[c,n]}async delete(e){const{store:s}=this.client,i=s.getState(),c=ea(e)(i);if(!c)throw new Error(`No asset stage with uuid ${e} found in the store`);return this.dispatch(xs(e)),this.enqueueRequest({description:"Delete asset stage",method:h.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(Qs(c)),n})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stages",method:h.GET,url:"/asset-stages/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(_r(s)),s}}class _b extends De{constructor(){super(...arguments);S(this,"name","Asset Type Attachment");S(this,"url","/asset-type-attachments");S(this,"addAttachments",sa);S(this,"updateAttachments",qr);S(this,"removeAttachments",aa);S(this,"removeAttachment",Vr);S(this,"setAttachment",jr);S(this,"selectAttachment",Dr)}buildOfflineAttachment(s){return T({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(i=>({modelUuid:i.assetTypeUuid,file:i.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const i=await this.enqueueRequest({description:"Get asset type attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset_type__organization:s},blocks:[],blockers:[]});return this.dispatch(Er(i)),i}}class Rb extends j{async bulkAdd(e){var m;const s=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:l,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:l,submitted_at:s,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:l};r.push(P)}this.dispatch(Gr(n));const o=this.enqueueRequest({description:"Add asset type fields attachments",method:h.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return o.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(Lr(u.attachments))}).catch(()=>{this.dispatch(Nr(n.map(u=>u.uuid)))}),[n,o.then(({attachments:u})=>u)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type fields attachments",method:h.GET,url:"/asset-type-fields-attachments/",queryParams:{fields_revision__asset_type__organization:e},blockers:[e],blocks:[]});return this.dispatch($r(s)),s}}class vb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Zr(n));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:h.POST,url:"/asset-type-fields/",payload:v(n),blockers:[n.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Xr(m))}).catch(m=>{throw this.dispatch(Qr(n.uuid)),m}),[n,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Type Fields",method:h.GET,url:"/asset-type-fields/",queryParams:{asset_type__organization:e},blockers:[],blocks:[]});return this.dispatch(Jr(s)),s}}class wb extends j{async bulkAdd(e,s){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=ke(e,s??e.length),r=[],o=[];for(const l of n){const p={},A=[];for(const y of l){const{fieldValuesUuid:b,fieldIdentifier:P,file:O}=y,w=await this.getFilePayload(O);w.sha1 in p||(p[w.sha1]=w);const q=T({file:URL.createObjectURL(O),file_type:O.type,file_name:O.name,file_sha1:w.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(q);const Ke={uuid:q.uuid,file_name:O.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:P,field_values:b};A.push(Ke)}o.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(Tt(r));const m=o.map(l=>this.enqueueRequest({description:"Add asset type field values attachments",method:h.POST,url:"/asset-type-field-values-attachments/bulk/",payload:l,blockers:l.attachments.map(p=>p.field_values),blocks:l.attachments.map(p=>p.uuid)}));return Promise.all(m).then(l=>{for(const A of l)this.processPresignedUrls(A.presigned_urls);const p=l.flatMap(A=>A.attachments);this.dispatch(ad(p))}).catch(l=>{throw this.dispatch(It(r.map(p=>p.uuid))),l}),[r,m.map(l=>l.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,i=s.getState(),c=cd(e)(i);this.dispatch(It(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:h.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(Tt(c)),n}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values attachments",method:h.GET,url:"/asset-type-field-values-attachments/",queryParams:{field_values__asset__project:e},blockers:[],blocks:[]});return this.dispatch(sd(s)),s}}class Mb extends R{add(e){var r;const{store:s}=this.client,i=s.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset type field values",method:h.POST,url:"/asset-type-field-values/",payload:v(c),blockers:[e.asset,e.fields_revision],blocks:[c.uuid]});return this.dispatch(ua(c)),n.then(o=>(this.dispatch(tt(o)),o)).catch(()=>{this.dispatch(oa(c.uuid))}),[c,n]}bulkAdd(e,s){var m;const i=new Date().toISOString(),c=[],n=ke(e.payloads,s??e.payloads.length),r=[];for(const u of n){const l=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),l.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:l})}this.dispatch(od(c));const o=[];for(const u of r){const l=u.field_values.map(b=>b.asset),p=u.field_values.map(b=>b.fields_revision),A=u.field_values.map(b=>b.uuid),y=this.enqueueRequest({description:"Bulk add asset type field values",method:h.POST,url:"/asset-type-field-values/bulk/",payload:u,blockers:[...l,...p],blocks:A});o.push(y)}return Promise.all(o).then(u=>{this.dispatch(ld(u.flat()))}).catch(()=>{this.dispatch(hd(c.map(u=>u.uuid)))}),[c,o]}update(e){const{store:s}=this.client,i=s.getState(),c=ha(e.uuid)(i);if(!c)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(tt(n));const r=this.enqueueRequest({description:"Delete asset type field values",method:h.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[n.uuid,n.fields_revision,n.asset],blocks:[n.uuid]});return r.then(o=>{this.dispatch(tt(o))}).catch(()=>{this.dispatch(tt(c))}),[n,r]}async delete(e){const{store:s}=this.client,i=s.getState(),c=ha(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=nd(e)(i);this.dispatch(oa(e)),this.dispatch(It(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:h.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ua(c)),this.dispatch(Tt(n)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values",method:h.GET,url:"/asset-type-field-values/",queryParams:{asset__project:e},blockers:[],blocks:[]});return this.dispatch(ud(s)),s}}class Eb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(pa(n));const r=this.enqueueRequest({description:"Create asset type",method:h.POST,url:"/asset-types/",payload:v(n),blockers:[],blocks:[n.uuid]});return r.then(m=>{this.dispatch(st(m))}).catch(()=>{this.dispatch(Aa(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=fa(e.uuid)(s.getState());if(!i)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(st(c));const n=this.enqueueRequest({description:"Update asset type",method:h.PATCH,url:`/asset-types/${e.uuid}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(st(r))}).catch(()=>{this.dispatch(st(i))}),[c,n]}async delete(e){const{store:s}=this.client,i=s.getState(),c=fa(e)(i);if(!c)throw new Error(`Expected asset type with uuid ${e} to exist`);const n=Ls(e)(i),r=Cr(e)(i);return this.dispatch(Aa(e)),this.dispatch($s(n.map(o=>o.uuid))),this.dispatch(aa(r.map(({uuid:o})=>o))),this.enqueueRequest({description:"Delete asset type",method:h.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(o=>{throw this.dispatch(pa(c)),this.dispatch(gt(n)),this.dispatch(sa(r)),o})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset types",method:h.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]});return this.dispatch(yd(s)),s}}class jb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(ga(n));const r=this.enqueueRequest({description:"Create Category",method:h.POST,url:"/categories/",payload:v(n),blockers:[e.project],blocks:[n.uuid]});return[n,r]}update(e){const s=this.client.store.getState(),i=Pa(e.uuid)(s);if(!i)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const c={...i,...e};this.dispatch(Id(c));const n=this.enqueueRequest({description:"Edit Category",method:h.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[c,n]}remove(e){const{store:s}=this.client,i=Pa(e)(s.getState());if(!i)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(Od(e));const c=this.enqueueRequest({description:"Delete Category",method:h.DELETE,url:`/categories/${i.uuid}/`,blockers:[i.uuid],blocks:[]});return c.catch(()=>{this.dispatch(ga(i))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get categories",method:h.GET,url:"/categories/",queryParams:{project__organization_owner:e},blocks:[],blockers:[]});return this.dispatch(Td(s)),s}}class qb extends De{constructor(){super(...arguments);S(this,"name","Document Attachment");S(this,"url","/document-attachments");S(this,"addAttachments",Md);S(this,"updateAttachments",jd);S(this,"removeAttachments",Vd);S(this,"removeAttachment",qd);S(this,"setAttachment",Ed);S(this,"selectAttachment",Dd)}buildOfflineAttachment(s){return T({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,document:s.modelUuid})}buildAttachmentPayload(s){return{...s,document:s.modelUuid}}async bulkAdd(s){var p;const{store:i}=this.client,c=(p=i.getState().userReducer.currentUser)==null?void 0:p.id,n=new Date().toISOString(),r=[],o=[],m={},u={};for(const A of s){const{documentUuid:y,file:b}=A,P=await this.getFilePayload(b);P.sha1 in m||(m[P.sha1]=P,u[P.sha1]=[]);const O=this.buildOfflineAttachment({file:b,file_sha1:P.sha1,submitted_at:n,created_by:c,description:"",modelUuid:y});r.push(O),o.push({uuid:O.uuid,file_name:O.file_name,file_sha1:O.file_sha1,file_extension:P.extension,description:O.description,document:y}),u[P.sha1].push(O.uuid)}this.dispatch(this.addAttachments(r));const l=this.enqueueRequest({description:"Attach files to document",method:h.POST,url:"/document-attachments/bulk/",payload:{submitted_at:n,attachments:o,files:Object.values(m)},blocks:r.map(A=>A.uuid),blockers:r.map(A=>A.file_sha1)});return l.then(({attachments:A,presigned_urls:y})=>{this.dispatch(this.updateAttachments(A));const b=this.processPresignedUrls(y);for(const[P,O]of Object.entries(b))O.then(()=>{const w=u[P];for(const q of w)this.makeReadable(q)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(A=>A.uuid)))}),[r,l.then(({attachments:A})=>A)]}async delete(s){return this._delete(s)}makeReadable(s){this.enqueueRequest({description:"Add attachment to AI assistant",method:h.PATCH,url:`/document-attachments/${s}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",s],blocks:["index-document-attachment"]})}async refreshStore(s){const i=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:"/document-attachments/",queryParams:{project__organization:s},blocks:[],blockers:[]}),c=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:"/document-attachments/",queryParams:{organization:s},blocks:[],blockers:[]});return this.dispatch(wd([...i,...c])),[...i,...c]}}class Vb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch($d([n]));const r=this.enqueueRequest({description:"Create Document",method:h.POST,url:"/documents/",payload:v(n),queryParams:{parent_document:n.parent_document??void 0},blockers:n.parent_document?[n.parent_document]:[],blocks:[n.uuid]});return r.catch(()=>{this.dispatch(Ia([n.uuid]))}),[n,r]}update(e){const{store:s}=this.client,i=s.getState().documentsReducer.documents[e.uuid];if(!i)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const c={...i,...e};this.dispatch(Ne([c]));const n=this.enqueueRequest({description:"Update Document",method:h.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return n.catch(()=>{Ne([i])}),[c,n]}delete(e){const{store:s}=this.client,i=_t(s.getState()),c=Gd(e)(s.getState());if(!c)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const n=c.parent_document?i[c.parent_document]:void 0;this.dispatch(Ia([e]));const r=this.enqueueRequest({description:"Delete Document",method:h.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(o=>{this.dispatch(Ne(o))}).catch(()=>{this.dispatch(Ne([c])),n&&this.dispatch(Ne([n]))}),r}async refreshStore(e){const s=this.enqueueRequest({description:"Get project documents",method:h.GET,url:"/documents/",queryParams:{project__organization:e},blockers:[],blocks:[]}),i=this.enqueueRequest({description:"Get organization documents",method:h.GET,url:"/documents/",queryParams:{organization:e},blockers:[],blocks:[]}),c=[...await s,...await i];return this.dispatch(Bd(c)),c}}class zb extends R{async add(e,s){return this.enqueueRequest({description:"Add email domain to organization",method:h.POST,url:"/organization-email-domains/",payload:{email:s,organization:e},blockers:[e,"create-org"],blocks:[]})}async remove(e){return this.dispatch(Kd(e.uuid)),this.enqueueRequest({description:"Remove email domain from organization",method:h.DELETE,url:`/organization-email-domains/${e.uuid}/`,blockers:[e.domain],blocks:[]}).catch(s=>{throw this.dispatch(Wd(e)),s})}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch email domains for organization",method:h.GET,url:"/organization-email-domains/",queryParams:{organization:e},blockers:[e],blocks:[]});return this.dispatch(Hd(s)),s}}class Ub extends R{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:h.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,s=void 0){return this.enqueueRequest({description:"Validate verification code",method:h.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:s,blockers:[],blocks:[]})}}const Bt={},dc=new Set;let $t=0,uc=0,oc=0;const Db=20;class Cb extends R{constructor(){super(...arguments);S(this,"host");S(this,"_dbPromise",pm.openDB("fileCache",1,{upgrade(s){s.createObjectStore("files")}}))}async renewUploadUrl(s){const i=await this.fetchCache(s);if(!i)throw new Error(`File with sha1 ${s} not found in cache`);const c=await Kt(i,s),n=await this.enqueueRequest({description:"Get S3 URL",method:h.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await Le(i),file_type:i.type,extension:i.name.split(".").pop(),size:i.size.toString()},blockers:[],blocks:[`s3-${c}`]});return"url"in n&&this.dispatch(xd({sha1:s,...n})),n}async addCache(s,i){if(dc.has(i))return;if(!s.type){const r=s.name.split("."),o=r[r.length-1];s=new File([s],s.name,{type:o})}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 c=await this._dbPromise;!!await c.get("files",i)?(console.error("File already cached (this is unexpected at this point):",s.name,i),$t++):(await c.put("files",s,i),uc++),dc.add(i),oc++,oc%Db===0&&console.debug(`File cache summary: ${$t} hits and ${uc} misses, ${$t/($t+uc)*100}% hit rate over ${oc} calls to addCache.`)}async removeCache(s){await(await this._dbPromise).delete("files",s),dc.delete(s)}async fetchCache(s){return(await this._dbPromise).get("files",s)}async getOrRenewUploadUrl(s){const i=this.client.store.getState();return eu(s)(i)??await this.renewUploadUrl(s)}async uploadFileToS3(s){const i=await this.fetchCache(s);if(!i)throw new Error(`File with sha1 ${s} not found in cache`);const c=await Kt(i,s),n={file_name:i.name,file_sha1:s,file:c},r=await this.getOrRenewUploadUrl(s);if("warning"in r){if(r.warning==="already_uploaded")return[n,Promise.resolve(void 0).then()];throw new Error(r.warning)}const o=r.url,m=this.enqueueRequest({url:o,description:"Upload file",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:s,blockers:[`s3-${c}`],blocks:[s],s3url:r});return[n,m]}async fetchFileFromUrl(s,i,c){const n=s.split("?")[0]??s,r=await this.fetchCache(i);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(s.startsWith("blob:")){const l=await bc(s),p=new File([l],c??i,{type:l.type});return await this.addCache(p,i),p}let o=Bt[n],m=!0;o?m=!1:(o=new Promise(l=>{this.enqueueRequest({description:"Download file",method:h.GET,url:s,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[i],blocks:[i]}).then(p=>{const A=new File([p],c??i,{type:p.type});l(A)})}),Bt[n]=o);let u;try{u=await o}catch(l){throw m&&l instanceof U&&delete Bt[n],l}if(m){const l=await Le(u);if(l!==i){const y=`The hash of the file returned from the server (${l}) does not match the
8
+ `)}catch(c){console.error("Failed to extract error message from response body",c)}}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>nb?He:s}class U extends Error{constructor(s){super(He);S(this,"status");S(this,"response");S(this,"message");S(this,"options");const{response:i,innerError:c}=s;this.message=s.message??rb(i,c)??He,this.status=(i==null?void 0:i.status)??0,this.response=i,s.discard=s.discard??!1,this.options=s}}class db extends Qh{constructor(e){super(e)}}class R extends Qh{constructor(s,i){super(s);S(this,"auth");this.auth=i}}class ub extends R{async startConversation(e,s){return this.enqueueRequest({description:"Start agent conversation",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:s},blockers:["prompt"],blocks:["prompt"]}).then(i=>(this.dispatch(Rc(i)),i))}async continueConversation(e,s,i){return this.enqueueRequest({description:"Prompt agent",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:i},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:s}}).then(c=>{this.dispatch(wc(c))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:h.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(s=>{this.dispatch(vc(s))})}async rate(e,s){return this.enqueueRequest({description:"Rate agent response",method:h.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:s},blockers:["rate"],blocks:["rate"]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get agent conversation history",method:h.GET,url:"/agents/conversations/",queryParams:{project:e},blockers:["agent-conversations"],blocks:["agent-conversations"]});return this.dispatch(_c(s)),s}}class j extends R{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:s,assetAttachmentReducer:i,assetTypeAttachmentReducer:c,documentAttachmentReducer:n,projectAttachmentReducer:r,formRevisionAttachmentReducer:o,formSubmissionAttachmentReducer:m,geoImageReducer:u,assetTypeFieldsAttachmentReducer:l,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:A,issueTypeFieldValuesAttachmentReducer:y}=this.client.store.getState();return[].concat(Object.values(s.instances),Object.values(i.instances),Object.values(c.instances),Object.values(n.instances),Object.values(r.instances),Object.values(o.instances),Object.values(m.instances),Object.values(u.instances),Object.values(l.instances),Object.values(p.instances),Object.values(A.instances),Object.values(y.instances)).filter(P=>P.file_sha1===e).length}processPresignedUrls(e){const s={};for(const[i,c]of Object.entries(e))s[i]=this.enqueueRequest({url:c.url,description:"Upload file to S3",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:i,blockers:[`s3-${c.fields.key}`],blocks:[i],s3url:c});return s}async getFilePayload(e){const s=await Le(e),i={sha1:s,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,s),i}}class De extends j{async _bulkAdd(e){var u;const{store:s}=this.client,i=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,c=new Date().toISOString(),n=[],r=[],o={};for(const l of e){const{modelUuid:p,file:A}=l,y=await this.getFilePayload(A);y.sha1 in o||(o[y.sha1]=y);const b=this.buildOfflineAttachment({file:A,file_sha1:y.sha1,submitted_at:c,created_by:i,description:"",modelUuid:p});n.push(b),r.push(this.buildAttachmentPayload({uuid:b.uuid,file_name:b.file_name,file_sha1:b.file_sha1,file_extension:y.extension,description:b.description,modelUuid:p}))}this.dispatch(this.addAttachments(n));const m=this.enqueueRequest({description:`Add ${this.name}`,method:h.POST,url:`${this.url}/bulk/`,payload:{submitted_at:c,attachments:r,files:Object.values(o)},blocks:n.map(l=>l.uuid),blockers:n.map(l=>l.file_sha1)});return m.then(({attachments:l,presigned_urls:p})=>{this.dispatch(this.updateAttachments(l)),this.processPresignedUrls(p)}).catch(()=>{this.dispatch(this.removeAttachments(n.map(l=>l.uuid)))}),[n,m.then(({attachments:l})=>l)]}async _delete(e){const{store:s}=this.client,i=this.selectAttachment(e)(s.getState());if(!i)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(i.uuid));const c=this.enqueueRequest({description:`Delete ${this.name}`,method:h.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return c.then(()=>{this.getNumberOfAttachmentsWithSha1(i.file_sha1)===0&&this.client.files.removeCache(i.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(i))}),c}}class ob extends De{constructor(){super(...arguments);S(this,"name","Asset Attachment");S(this,"url","/asset-attachments");S(this,"initializeAttachments",Xt);S(this,"addAttachments",Qt);S(this,"updateAttachments",qc);S(this,"removeAttachments",xt);S(this,"removeAttachment",Vc);S(this,"setAttachment",jc);S(this,"selectAttachment",Dc)}buildOfflineAttachment(s){return T({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(i=>({modelUuid:i.assetUuid,file:i.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const i=await this.enqueueRequest({description:"Get asset attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset__project:s},blocks:[],blockers:[]});return this.dispatch(Xt(i)),i}}class lb extends De{constructor(){super(...arguments);S(this,"name","Asset Procedure Attachment");S(this,"url","/asset-procedure-attachments");S(this,"addAttachments",Gc);S(this,"updateAttachments",Nc);S(this,"removeAttachments",Wc);S(this,"removeAttachment",Hc);S(this,"setAttachment",Lc);S(this,"selectAttachment",Jc)}buildOfflineAttachment(s){return T({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_procedure:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset_procedure:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(i=>({modelUuid:i.assetProcedureUuid,file:i.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const i=await this.enqueueRequest({description:"Get asset procedure attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset_procedure__organization:s},blocks:[],blockers:[]});return this.dispatch($c(i)),i}}class hb extends j{async bulkAdd(e){var m;const s=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:l,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:l,submitted_at:s,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:l};r.push(P)}this.dispatch(xc(n));const o=this.enqueueRequest({description:"Add asset procedure fields attachments",method:h.POST,url:"/asset-procedure-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return o.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(en(u.attachments))}).catch(()=>{this.dispatch(tn(n.map(u=>u.uuid)))}),[n,o.then(({attachments:u})=>u)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure fields attachments",method:h.GET,url:"/asset-procedure-fields-attachments/",queryParams:{fields_revision__asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(Qc(s)),s}}class mb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(dn(n));const r=this.enqueueRequest({description:"Add Asset Procedure Fields",method:h.POST,url:"/asset-procedure-fields/",payload:v(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(un(m))}).catch(m=>{throw this.dispatch(on(n.uuid)),m}),[n,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Procedure Fields",method:h.GET,url:"/asset-procedure-fields/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(rn(s)),s}}function ke(t,e){const s=[];let i=0;const c=t.length;for(;i<c;)s.push(t.slice(i,i+=e));return s}class pb extends j{async bulkAdd(e,s){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=ke(e,s??e.length),r=[],o=[];for(const l of n){const p={},A=[];for(const y of l){const{fieldValuesUuid:b,fieldIdentifier:P,file:O}=y,w=await this.getFilePayload(O);w.sha1 in p||(p[w.sha1]=w);const q=T({file:URL.createObjectURL(O),file_type:O.type,file_name:O.name,file_sha1:w.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(q);const Ke={uuid:q.uuid,file_name:O.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:P,field_values:b};A.push(Ke)}o.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(ht(r));const m=o.map(l=>this.enqueueRequest({description:"Add asset procedure field values attachments",method:h.POST,url:"/asset-procedure-field-values-attachments/bulk/",payload:l,blockers:l.attachments.map(p=>p.field_values),blocks:l.attachments.map(p=>p.uuid)}));return Promise.all(m).then(l=>{for(const A of l)this.processPresignedUrls(A.presigned_urls);const p=l.flatMap(A=>A.attachments);this.dispatch(An(p))}).catch(l=>{throw this.dispatch(mt(r.map(p=>p.uuid))),l}),[r,m.map(l=>l.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,i=s.getState(),c=fn(e)(i);this.dispatch(mt(e));try{await this.enqueueRequest({description:"Delete asset procedure field values attachments",method:h.DELETE,url:"/asset-procedure-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(ht(c)),n}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values attachments",method:h.GET,url:"/asset-procedure-field-values-attachments/",queryParams:{field_values__asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(pn(s)),s}}class Ab extends R{add(e){var r;const{store:s}=this.client,i=s.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/",payload:v(c),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[c.uuid]});return this.dispatch(rs(c)),n.then(o=>(this.dispatch(Je(o)),o)).catch(()=>{this.dispatch(ds(c.uuid))}),[c,n]}bulkAdd(e,s){var m;const i=new Date().toISOString(),c=[],n=ke(e.payloads,s??e.payloads.length),r=[];for(const u of n){const l=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),l.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure_instance:p.asset_procedure_instance,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:l})}this.dispatch(Fn(c));const o=[];for(const u of r){const l=u.field_values.map(P=>P.asset),p=u.field_values.map(P=>P.fields_revision),A=u.field_values.map(P=>P.asset_procedure_instance),y=u.field_values.map(P=>P.uuid),b=this.enqueueRequest({description:"Bulk add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/bulk/",payload:u,blockers:[...l,...p,...A],blocks:y});o.push(b)}return Promise.all(o).then(u=>{this.dispatch(Tn(u.flat()))}).catch(()=>{this.dispatch(In(c.map(u=>u.uuid)))}),[c,o]}update(e){const{store:s}=this.client,i=s.getState(),c=os(e.uuid)(i);if(!c)throw new Error(`Expected AssetProcedureFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(Je(n));const r=this.enqueueRequest({description:"Update asset procedure field values",method:h.PATCH,url:`/asset-procedure-field-values/${e.uuid}/`,payload:e,blockers:[n.fields_revision,n.asset,n.asset_procedure_instance],blocks:[n.uuid]});return r.then(o=>{this.dispatch(Je(o))}).catch(()=>{this.dispatch(Je(c))}),[n,r]}async delete(e){const{store:s}=this.client,i=s.getState(),c=os(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=Sn(e)(i);this.dispatch(ds(e)),this.dispatch(mt(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure field values",method:h.DELETE,url:`/asset-procedure-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(rs(c)),this.dispatch(ht(n)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values",method:h.GET,url:"/asset-procedure-field-values/",queryParams:{asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(Pn(s)),s}}class yb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(hs(n));const r=this.enqueueRequest({description:"Create asset procedure instance",method:h.POST,url:"/asset-procedure-instances/",payload:v(n),blockers:[e.asset_procedure,e.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Ze(m))}).catch(()=>{this.dispatch(ms(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=ys(e.uuid)(s.getState());if(!i)throw new Error(`Expected asset procedure instance with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(Ze(c));const n=this.enqueueRequest({description:"Update asset procedure instance",method:h.PATCH,url:`/asset-procedure-instances/${e.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Ze(r))}).catch(()=>{this.dispatch(Ze(i))}),[c,n]}async remove(e){const{store:s}=this.client,i=s.getState(),c=ys(e)(i);if(!c)throw new Error(`Expected asset procedure instance with uuid ${e} to exist`);return this.dispatch(ms(e)),this.enqueueRequest({description:"Delete asset procedure instance",method:h.DELETE,url:`/asset-procedure-instances/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(hs(c)),n})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure instances",method:h.GET,url:"/asset-procedure-instances/",queryParams:{project:e},blockers:[],blocks:[]});return this.dispatch(vn(s)),s}}class fb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Ss(n));const r=this.enqueueRequest({description:"Create asset procedure",method:h.POST,url:"/asset-procedures/",payload:v(n),blockers:[],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Xe(m))}).catch(()=>{this.dispatch(gs(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=Ps(e.uuid)(s.getState());if(!i)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(Xe(c));const n=this.enqueueRequest({description:"Update asset procedure",method:h.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Xe(r))}).catch(()=>{this.dispatch(Xe(i))}),[c,n]}async remove(e){const{store:s}=this.client,i=s.getState(),c=Ps(e)(i);if(!c)throw new Error(`Expected asset procedure with uuid ${e} to exist`);const n=En(e)(i);return this.dispatch(gs(e)),this.dispatch(Mn(n.map(r=>r.uuid))),this.enqueueRequest({description:"Delete asset procedure",method:h.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(Ss(c)),this.dispatch(wn(n)),r})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedures",method:h.GET,url:"/asset-procedures/",queryParams:{organization:e},blockers:[],blocks:[]});return this.dispatch(Vn(s)),s}}class Sb extends j{async bulkAdd(e){var m;const s=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:l,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:l,submitted_at:s,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:l};r.push(P)}this.dispatch(kn(n));const o=this.enqueueRequest({description:"Add asset procedure step fields attachments",method:h.POST,url:"/asset-procedure-step-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return o.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(Bn(u.attachments))}).catch(()=>{this.dispatch($n(n.map(u=>u.uuid)))}),[n,o.then(({attachments:u})=>u)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure step fields attachments",method:h.GET,url:"/asset-procedure-step-fields-attachments/",queryParams:{fields_revision__asset_procedure_step__organization:e},blockers:[],blocks:[]});return this.dispatch(Cn(s)),s}}class gb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Is(n));const r=this.enqueueRequest({description:"Add Asset Procedure Step Fields",method:h.POST,url:"/asset-procedure-step-fields/",payload:v(n),blockers:[n.asset_procedure_step],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Qe(m))}).catch(m=>{throw this.dispatch(Os(n.uuid)),m}),[n,r]}update(e){const{store:s}=this.client,i=s.getState().assetProcedureStepFieldsReducer.instances[e.uuid];if(!i)throw new Error(`AssetProcedureStepFields with uuid ${e.uuid} not found`);const c={...i,...e};this.dispatch(Qe(c));const n=this.enqueueRequest({description:"Update Asset Procedure Step Fields",method:h.PATCH,url:`/asset-procedure-step-fields/${i.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Qe(r))}).catch(r=>{throw this.dispatch(Qe(i)),r}),[c,n]}delete(e){const{store:s}=this.client,i=s.getState().assetProcedureStepFieldsReducer.instances[e];if(!i)throw new Error(`AssetProcedureStepFields with uuid ${e} not found`);this.dispatch(Os(e));const c=this.enqueueRequest({description:"Delete Asset Procedure Step Fields",method:h.DELETE,url:`/asset-procedure-step-fields/${e}/`,blockers:[e],blocks:[e]});return c.catch(n=>{throw this.dispatch(Is(i)),n}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Procedure Step Fields",method:h.GET,url:"/asset-procedure-step-fields/",queryParams:{asset_procedure_step__asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(Wn(s)),s}}class bb extends j{async bulkAdd(e,s){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=ke(e,s??e.length),r=[],o=[];for(const l of n){const p={},A=[];for(const y of l){const{fieldValuesUuid:b,fieldIdentifier:P,file:O}=y,w=await this.getFilePayload(O);w.sha1 in p||(p[w.sha1]=w);const q=T({file:URL.createObjectURL(O),file_type:O.type,file_name:O.name,file_sha1:w.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(q);const Ke={uuid:q.uuid,file_name:O.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:P,field_values:b};A.push(Ke)}o.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(pt(r));const m=o.map(l=>this.enqueueRequest({description:"Add asset procedure step field values attachments",method:h.POST,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:l,blockers:l.attachments.map(p=>p.field_values),blocks:l.attachments.map(p=>p.uuid)}));return Promise.all(m).then(l=>{for(const A of l)this.processPresignedUrls(A.presigned_urls);const p=l.flatMap(A=>A.attachments);this.dispatch(Zn(p))}).catch(l=>{throw this.dispatch(At(r.map(p=>p.uuid))),l}),[r,m.map(l=>l.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,i=s.getState(),c=Qn(e)(i);this.dispatch(At(e));try{await this.enqueueRequest({description:"Delete asset procedure step field values attachments",method:h.DELETE,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(pt(c)),n}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure step field values attachments",method:h.GET,url:"/asset-procedure-step-field-values-attachments/",queryParams:{field_values__asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(Jn(s)),s}}class Pb extends R{add(e){var r;const{store:s}=this.client,i=s.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset procedure step field values",method:h.POST,url:"/asset-procedure-step-field-values/",payload:v(c),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[c.uuid]});return this.dispatch(Es(c)),n.then(o=>(this.dispatch(xe(o)),o)).catch(()=>{this.dispatch(js(c.uuid))}),[c,n]}bulkAdd(e,s){var m;const i=new Date().toISOString(),c=[],n=ke(e.payloads,s??e.payloads.length),r=[];for(const u of n){const l=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),l.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure_instance:p.asset_procedure_instance,asset_procedure_step:p.asset_procedure_step,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:l})}this.dispatch(ar(c));const o=[];for(const u of r){const l=u.field_values.map(P=>P.asset),p=u.field_values.map(P=>P.fields_revision),A=u.field_values.map(P=>P.asset_procedure_instance),y=u.field_values.map(P=>P.uuid),b=this.enqueueRequest({description:"Bulk add asset procedure step field values",method:h.POST,url:"/asset-procedure-step-field-values/bulk/",payload:u,blockers:[...l,...p,...A],blocks:y});o.push(b)}return Promise.all(o).then(u=>{this.dispatch(ir(u.flat()))}).catch(()=>{this.dispatch(cr(c.map(u=>u.uuid)))}),[c,o]}update(e){const{store:s}=this.client,i=s.getState(),c=qs(e.uuid)(i);if(!c)throw new Error(`Expected AssetProcedureStepFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(xe(n));const r=this.enqueueRequest({description:"Update asset procedure step field values",method:h.PATCH,url:`/asset-procedure-step-field-values/${e.uuid}/`,payload:e,blockers:[n.fields_revision,n.asset,n.asset_procedure_instance],blocks:[n.uuid]});return r.then(o=>{this.dispatch(xe(o))}).catch(()=>{this.dispatch(xe(c))}),[n,r]}async delete(e){const{store:s}=this.client,i=s.getState(),c=qs(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=xn(e)(i);this.dispatch(js(e)),this.dispatch(At(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure step field values",method:h.DELETE,url:`/asset-procedure-step-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Es(c)),this.dispatch(pt(n)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure step field values",method:h.GET,url:"/asset-procedure-step-field-values/",queryParams:{asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(sr(s)),s}}class Fb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(zs(n));const r=this.enqueueRequest({description:"Create asset procedure step",method:h.POST,url:"/asset-procedure-steps/",payload:v(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(ft(m))}).catch(()=>{this.dispatch(Us(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=Ds(e.uuid)(s.getState());if(!i)throw new Error(`No asset procedure step with uuid ${e.uuid} found in the store`);const c={...i,...e};this.dispatch(ft(c));const n=this.enqueueRequest({description:"Update asset procedure step",method:h.PATCH,url:`/asset-procedure-steps/${i.uuid}/`,payload:{name:e.name,description:e.description,priority:e.order,color:e.color},blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(ft(r))}).catch(()=>{this.dispatch(or(i))}),[c,n]}async delete(e){const{store:s}=this.client,i=s.getState(),c=Ds(e)(i);if(!c)throw new Error(`No asset procedure step with uuid ${e} found in the store`);return this.dispatch(Us(e)),this.enqueueRequest({description:"Delete asset stage",method:h.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(zs(c)),n})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure steps",method:h.GET,url:"/asset-procedure-steps/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(ur(s)),s}}class Tb extends R{add(e){var o;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 i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(ks(n));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/assets/",payload:v(n),blockers:[n.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(et(m))}).catch(()=>{this.dispatch(Bs(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=Ns(e.uuid)(s.getState());if(!i)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const c={...i,...e};if(!c.canvas_marker&&!c.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");this.dispatch(et(c));const n=this.enqueueRequest({description:"Edit asset",method:h.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return n.then(r=>{this.dispatch(et(r))}).catch(()=>{this.dispatch(et(i))}),[c,n]}async delete(e){const{store:s}=this.client,i=s.getState(),c=Ns(e)(i);if(!c)throw new Error(`No asset with uuid ${e} found in the store`);const n=Cc(e)(i),r=Vu(e)(i),o=Qu(e)(i);if(this.dispatch(Bs(e)),n.length>0){const m=n.map(({uuid:u})=>u);this.dispatch(xt(m))}if(r.length>0){const m=r.map(({uuid:u})=>u);this.dispatch(jt(m))}if(o.length>0){const m=o.map(({uuid:u})=>u);this.dispatch(Za(m))}return this.enqueueRequest({description:"Delete asset",method:h.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(ks(c)),this.dispatch(Qt(n)),this.dispatch(Et(r)),this.dispatch(Ya(o)),m})}bulkAdd(e,s,i,c){const n=new Date().toISOString(),r=Ge.v4(),o=ke(e,c).map(l=>{const p=l.map(A=>T(A));return{batchId:Ge.v4(),payload:{transaction_id:r,submitted_at:n,asset_type:s,project:i,assets:p}}}),m=[];let u=null;for(const l of o){const{batchId:p,payload:A}=l,y=A.assets.map(w=>w.uuid),b=[s];u&&b.push(u);const P=y;P.push(p);const O=this.enqueueRequest({description:"Batch create assets",method:h.POST,url:"/assets/bulk/",payload:A,blockers:b,blocks:P});u=l.batchId,m.push(O)}return Promise.all(m).then(l=>{const p=l.flat();this.dispatch(gt(p))}),m}async bulkDelete(e){const{store:s}=this.client,i=s.getState(),c=yr(e)(i);this.dispatch($s(e));try{await this.enqueueRequest({description:"Bulk delete assets",method:h.DELETE,url:"/assets/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(gt(c)),n}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get assets",method:h.GET,url:"/assets/",queryParams:{project:e},blockers:[],blocks:[]});return this.dispatch(pr(s)),s}}class Ib extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Ws(n));const r=this.enqueueRequest({description:"Add asset stage completion",method:h.POST,url:"/asset-stage-completions/",payload:v(n),blockers:[e.asset,e.stage],blocks:[n.uuid]});return r.then(m=>{this.dispatch(br(m))}).catch(()=>{this.dispatch(Ys(n.uuid))}),[n,r]}delete(e){const{store:s}=this.client,i=Tr(e)(s.getState());if(!i)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(Ys(e));const c=this.enqueueRequest({description:"Delete asset stage completion",method:h.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return c.catch(()=>{this.dispatch(Ws(i))}),c}bulkAdd(e){var u;const{store:s}=this.client,i=new Date().toISOString(),c=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,n=e.map(l=>T(l)),r=n.map(l=>({...l,created_by:c,submitted_at:i})),o=r.map(({uuid:l})=>l);this.dispatch(Ks(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:h.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:i,completions:n},blockers:[...e.map(l=>l.asset_procedure_instance),...e.map(l=>l.stage),...e.map(l=>l.asset)],blocks:o});return m.then(l=>{this.dispatch(Pr(l))}).catch(()=>{this.dispatch(Js(o))}),[r,m]}bulkDelete(e){const{store:s}=this.client,i=Ir(e)(s.getState());this.dispatch(Js(e));const c=this.enqueueRequest({description:"Deleting asset stage completions",method:h.DELETE,url:"/asset-stage-completions/bulk/",payload:{uuids:e},blockers:e,blocks:[]});return c.catch(()=>{this.dispatch(Ks(i))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stage completions",method:h.GET,url:"/asset-stage-completions/",queryParams:{asset_procedure_instance__project:e},blockers:[],blocks:[]});return this.dispatch(gr(s)),s}}class Ob extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Qs(n));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/asset-stages/",payload:v(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(bt(m))}).catch(()=>{this.dispatch(xs(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=ea(e.uuid)(s.getState());if(!i)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const c={...i,...e};this.dispatch(bt(c));const n=this.enqueueRequest({description:"Update asset stage",method:h.PATCH,url:`/asset-stages/${i.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(bt(r))}).catch(()=>{this.dispatch(Rr(i))}),[c,n]}async delete(e){const{store:s}=this.client,i=s.getState(),c=ea(e)(i);if(!c)throw new Error(`No asset stage with uuid ${e} found in the store`);return this.dispatch(xs(e)),this.enqueueRequest({description:"Delete asset stage",method:h.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(Qs(c)),n})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stages",method:h.GET,url:"/asset-stages/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(_r(s)),s}}class _b extends De{constructor(){super(...arguments);S(this,"name","Asset Type Attachment");S(this,"url","/asset-type-attachments");S(this,"addAttachments",sa);S(this,"updateAttachments",qr);S(this,"removeAttachments",aa);S(this,"removeAttachment",Vr);S(this,"setAttachment",jr);S(this,"selectAttachment",Dr)}buildOfflineAttachment(s){return T({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(i=>({modelUuid:i.assetTypeUuid,file:i.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const i=await this.enqueueRequest({description:"Get asset type attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset_type__organization:s},blocks:[],blockers:[]});return this.dispatch(Er(i)),i}}class Rb extends j{async bulkAdd(e){var m;const s=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:l,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:l,submitted_at:s,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:l};r.push(P)}this.dispatch(Gr(n));const o=this.enqueueRequest({description:"Add asset type fields attachments",method:h.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return o.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(Lr(u.attachments))}).catch(()=>{this.dispatch(Nr(n.map(u=>u.uuid)))}),[n,o.then(({attachments:u})=>u)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type fields attachments",method:h.GET,url:"/asset-type-fields-attachments/",queryParams:{fields_revision__asset_type__organization:e},blockers:[e],blocks:[]});return this.dispatch($r(s)),s}}class vb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Zr(n));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:h.POST,url:"/asset-type-fields/",payload:v(n),blockers:[n.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Xr(m))}).catch(m=>{throw this.dispatch(Qr(n.uuid)),m}),[n,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Type Fields",method:h.GET,url:"/asset-type-fields/",queryParams:{asset_type__organization:e},blockers:[],blocks:[]});return this.dispatch(Jr(s)),s}}class wb extends j{async bulkAdd(e,s){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=ke(e,s??e.length),r=[],o=[];for(const l of n){const p={},A=[];for(const y of l){const{fieldValuesUuid:b,fieldIdentifier:P,file:O}=y,w=await this.getFilePayload(O);w.sha1 in p||(p[w.sha1]=w);const q=T({file:URL.createObjectURL(O),file_type:O.type,file_name:O.name,file_sha1:w.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(q);const Ke={uuid:q.uuid,file_name:O.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:P,field_values:b};A.push(Ke)}o.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(Tt(r));const m=o.map(l=>this.enqueueRequest({description:"Add asset type field values attachments",method:h.POST,url:"/asset-type-field-values-attachments/bulk/",payload:l,blockers:l.attachments.map(p=>p.field_values),blocks:l.attachments.map(p=>p.uuid)}));return Promise.all(m).then(l=>{for(const A of l)this.processPresignedUrls(A.presigned_urls);const p=l.flatMap(A=>A.attachments);this.dispatch(ad(p))}).catch(l=>{throw this.dispatch(It(r.map(p=>p.uuid))),l}),[r,m.map(l=>l.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,i=s.getState(),c=cd(e)(i);this.dispatch(It(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:h.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(Tt(c)),n}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values attachments",method:h.GET,url:"/asset-type-field-values-attachments/",queryParams:{field_values__asset__project:e},blockers:[],blocks:[]});return this.dispatch(sd(s)),s}}class Mb extends R{add(e){var r;const{store:s}=this.client,i=s.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset type field values",method:h.POST,url:"/asset-type-field-values/",payload:v(c),blockers:[e.asset,e.fields_revision],blocks:[c.uuid]});return this.dispatch(ua(c)),n.then(o=>(this.dispatch(tt(o)),o)).catch(()=>{this.dispatch(oa(c.uuid))}),[c,n]}bulkAdd(e,s){var m;const i=new Date().toISOString(),c=[],n=ke(e.payloads,s??e.payloads.length),r=[];for(const u of n){const l=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),l.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:l})}this.dispatch(od(c));const o=[];for(const u of r){const l=u.field_values.map(b=>b.asset),p=u.field_values.map(b=>b.fields_revision),A=u.field_values.map(b=>b.uuid),y=this.enqueueRequest({description:"Bulk add asset type field values",method:h.POST,url:"/asset-type-field-values/bulk/",payload:u,blockers:[...l,...p],blocks:A});o.push(y)}return Promise.all(o).then(u=>{this.dispatch(ld(u.flat()))}).catch(()=>{this.dispatch(hd(c.map(u=>u.uuid)))}),[c,o]}update(e){const{store:s}=this.client,i=s.getState(),c=ha(e.uuid)(i);if(!c)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(tt(n));const r=this.enqueueRequest({description:"Delete asset type field values",method:h.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[n.uuid,n.fields_revision,n.asset],blocks:[n.uuid]});return r.then(o=>{this.dispatch(tt(o))}).catch(()=>{this.dispatch(tt(c))}),[n,r]}async delete(e){const{store:s}=this.client,i=s.getState(),c=ha(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=nd(e)(i);this.dispatch(oa(e)),this.dispatch(It(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:h.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ua(c)),this.dispatch(Tt(n)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values",method:h.GET,url:"/asset-type-field-values/",queryParams:{asset__project:e},blockers:[],blocks:[]});return this.dispatch(ud(s)),s}}class Eb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(pa(n));const r=this.enqueueRequest({description:"Create asset type",method:h.POST,url:"/asset-types/",payload:v(n),blockers:[],blocks:[n.uuid]});return r.then(m=>{this.dispatch(st(m))}).catch(()=>{this.dispatch(Aa(n.uuid))}),[n,r]}update(e){const{store:s}=this.client,i=fa(e.uuid)(s.getState());if(!i)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(st(c));const n=this.enqueueRequest({description:"Update asset type",method:h.PATCH,url:`/asset-types/${e.uuid}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(st(r))}).catch(()=>{this.dispatch(st(i))}),[c,n]}async delete(e){const{store:s}=this.client,i=s.getState(),c=fa(e)(i);if(!c)throw new Error(`Expected asset type with uuid ${e} to exist`);const n=Ls(e)(i),r=Cr(e)(i);return this.dispatch(Aa(e)),this.dispatch($s(n.map(o=>o.uuid))),this.dispatch(aa(r.map(({uuid:o})=>o))),this.enqueueRequest({description:"Delete asset type",method:h.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(o=>{throw this.dispatch(pa(c)),this.dispatch(gt(n)),this.dispatch(sa(r)),o})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset types",method:h.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]});return this.dispatch(yd(s)),s}}class jb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(ga(n));const r=this.enqueueRequest({description:"Create Category",method:h.POST,url:"/categories/",payload:v(n),blockers:[e.project],blocks:[n.uuid]});return[n,r]}update(e){const s=this.client.store.getState(),i=Pa(e.uuid)(s);if(!i)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const c={...i,...e};this.dispatch(Id(c));const n=this.enqueueRequest({description:"Edit Category",method:h.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[c,n]}remove(e){const{store:s}=this.client,i=Pa(e)(s.getState());if(!i)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(Od(e));const c=this.enqueueRequest({description:"Delete Category",method:h.DELETE,url:`/categories/${i.uuid}/`,blockers:[i.uuid],blocks:[]});return c.catch(()=>{this.dispatch(ga(i))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get categories",method:h.GET,url:"/categories/",queryParams:{project__organization_owner:e},blocks:[],blockers:[]});return this.dispatch(Td(s)),s}}class qb extends De{constructor(){super(...arguments);S(this,"name","Document Attachment");S(this,"url","/document-attachments");S(this,"addAttachments",Md);S(this,"updateAttachments",jd);S(this,"removeAttachments",Vd);S(this,"removeAttachment",qd);S(this,"setAttachment",Ed);S(this,"selectAttachment",Dd)}buildOfflineAttachment(s){return T({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,document:s.modelUuid})}buildAttachmentPayload(s){return{...s,document:s.modelUuid}}async bulkAdd(s){var p;const{store:i}=this.client,c=(p=i.getState().userReducer.currentUser)==null?void 0:p.id,n=new Date().toISOString(),r=[],o=[],m={},u={};for(const A of s){const{documentUuid:y,file:b}=A,P=await this.getFilePayload(b);P.sha1 in m||(m[P.sha1]=P,u[P.sha1]=[]);const O=this.buildOfflineAttachment({file:b,file_sha1:P.sha1,submitted_at:n,created_by:c,description:"",modelUuid:y});r.push(O),o.push({uuid:O.uuid,file_name:O.file_name,file_sha1:O.file_sha1,file_extension:P.extension,description:O.description,document:y}),u[P.sha1].push(O.uuid)}this.dispatch(this.addAttachments(r));const l=this.enqueueRequest({description:"Attach files to document",method:h.POST,url:"/document-attachments/bulk/",payload:{submitted_at:n,attachments:o,files:Object.values(m)},blocks:r.map(A=>A.uuid),blockers:r.map(A=>A.file_sha1)});return l.then(({attachments:A,presigned_urls:y})=>{this.dispatch(this.updateAttachments(A));const b=this.processPresignedUrls(y);for(const[P,O]of Object.entries(b))O.then(()=>{const w=u[P];for(const q of w)this.makeReadable(q)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(A=>A.uuid)))}),[r,l.then(({attachments:A})=>A)]}async delete(s){return this._delete(s)}makeReadable(s){this.enqueueRequest({description:"Add attachment to AI assistant",method:h.PATCH,url:`/document-attachments/${s}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",s],blocks:["index-document-attachment"]})}async refreshStore(s){const i=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:"/document-attachments/",queryParams:{document__project__owner_organization:s},blocks:[],blockers:[]}),c=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:"/document-attachments/",queryParams:{document__organization:s},blocks:[],blockers:[]}),n=[...i,...c];return this.dispatch(wd(n)),n}}class Vb extends R{add(e){var o;const{store:s}=this.client,i=(o=s.getState().userReducer.currentUser)==null?void 0:o.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch($d([n]));const r=this.enqueueRequest({description:"Create Document",method:h.POST,url:"/documents/",payload:v(n),queryParams:{parent_document:n.parent_document??void 0},blockers:n.parent_document?[n.parent_document]:[],blocks:[n.uuid]});return r.catch(()=>{this.dispatch(Ia([n.uuid]))}),[n,r]}update(e){const{store:s}=this.client,i=s.getState().documentsReducer.documents[e.uuid];if(!i)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const c={...i,...e};this.dispatch(Ne([c]));const n=this.enqueueRequest({description:"Update Document",method:h.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return n.catch(()=>{Ne([i])}),[c,n]}delete(e){const{store:s}=this.client,i=_t(s.getState()),c=Gd(e)(s.getState());if(!c)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const n=c.parent_document?i[c.parent_document]:void 0;this.dispatch(Ia([e]));const r=this.enqueueRequest({description:"Delete Document",method:h.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(o=>{this.dispatch(Ne(o))}).catch(()=>{this.dispatch(Ne([c])),n&&this.dispatch(Ne([n]))}),r}async refreshStore(e){const s=this.enqueueRequest({description:"Get project documents",method:h.GET,url:"/documents/",queryParams:{project__owner_organization:e},blockers:[],blocks:[]}),i=this.enqueueRequest({description:"Get organization documents",method:h.GET,url:"/documents/",queryParams:{organization:e},blockers:[],blocks:[]}),c=[...await s,...await i];return this.dispatch(Bd(c)),c}}class zb extends R{async add(e,s){return this.enqueueRequest({description:"Add email domain to organization",method:h.POST,url:"/organization-email-domains/",payload:{email:s,organization:e},blockers:[e,"create-org"],blocks:[]})}async remove(e){return this.dispatch(Kd(e.uuid)),this.enqueueRequest({description:"Remove email domain from organization",method:h.DELETE,url:`/organization-email-domains/${e.uuid}/`,blockers:[e.domain],blocks:[]}).catch(s=>{throw this.dispatch(Wd(e)),s})}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch email domains for organization",method:h.GET,url:"/organization-email-domains/",queryParams:{organization:e},blockers:[e],blocks:[]});return this.dispatch(Hd(s)),s}}class Ub extends R{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:h.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,s=void 0){return this.enqueueRequest({description:"Validate verification code",method:h.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:s,blockers:[],blocks:[]})}}const Bt={},dc=new Set;let $t=0,uc=0,oc=0;const Db=20;class Cb extends R{constructor(){super(...arguments);S(this,"host");S(this,"_dbPromise",pm.openDB("fileCache",1,{upgrade(s){s.createObjectStore("files")}}))}async renewUploadUrl(s){const i=await this.fetchCache(s);if(!i)throw new Error(`File with sha1 ${s} not found in cache`);const c=await Kt(i,s),n=await this.enqueueRequest({description:"Get S3 URL",method:h.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await Le(i),file_type:i.type,extension:i.name.split(".").pop(),size:i.size.toString()},blockers:[],blocks:[`s3-${c}`]});return"url"in n&&this.dispatch(xd({sha1:s,...n})),n}async addCache(s,i){if(dc.has(i))return;if(!s.type){const r=s.name.split("."),o=r[r.length-1];s=new File([s],s.name,{type:o})}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 c=await this._dbPromise;!!await c.get("files",i)?(console.error("File already cached (this is unexpected at this point):",s.name,i),$t++):(await c.put("files",s,i),uc++),dc.add(i),oc++,oc%Db===0&&console.debug(`File cache summary: ${$t} hits and ${uc} misses, ${$t/($t+uc)*100}% hit rate over ${oc} calls to addCache.`)}async removeCache(s){await(await this._dbPromise).delete("files",s),dc.delete(s)}async fetchCache(s){return(await this._dbPromise).get("files",s)}async getOrRenewUploadUrl(s){const i=this.client.store.getState();return eu(s)(i)??await this.renewUploadUrl(s)}async uploadFileToS3(s){const i=await this.fetchCache(s);if(!i)throw new Error(`File with sha1 ${s} not found in cache`);const c=await Kt(i,s),n={file_name:i.name,file_sha1:s,file:c},r=await this.getOrRenewUploadUrl(s);if("warning"in r){if(r.warning==="already_uploaded")return[n,Promise.resolve(void 0).then()];throw new Error(r.warning)}const o=r.url,m=this.enqueueRequest({url:o,description:"Upload file",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:s,blockers:[`s3-${c}`],blocks:[s],s3url:r});return[n,m]}async fetchFileFromUrl(s,i,c){const n=s.split("?")[0]??s,r=await this.fetchCache(i);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(s.startsWith("blob:")){const l=await bc(s),p=new File([l],c??i,{type:l.type});return await this.addCache(p,i),p}let o=Bt[n],m=!0;o?m=!1:(o=new Promise(l=>{this.enqueueRequest({description:"Download file",method:h.GET,url:s,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[i],blocks:[i]}).then(p=>{const A=new File([p],c??i,{type:p.type});l(A)})}),Bt[n]=o);let u;try{u=await o}catch(l){throw m&&l instanceof U&&delete Bt[n],l}if(m){const l=await Le(u);if(l!==i){const y=`The hash of the file returned from the server (${l}) does not match the
9
9
  expected hash (${i}). This can happen if you're using a local development server and the
10
10
  isExternalUrl flag in the request details is set to true, because instead of requesting the local
11
11
  REST API, you will be requesting localhost:80 (where this app runs), resulting in a transformed blob
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.78-view-sets.24",
6
+ "version": "1.0.78-view-sets.26",
7
7
  "type": "module",
8
8
  "main": "dist/overmap-core.umd.cjs",
9
9
  "module": "dist/overmap-core.js",