@overmap-ai/core 1.0.78-procedure-rename.5 → 1.0.78-procedure-rename.6

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.
@@ -4769,7 +4769,7 @@ class J_ extends v {
4769
4769
  method: d.POST,
4770
4770
  url: "/asset-stage-completions/",
4771
4771
  payload: k(n),
4772
- blockers: [e.asset, e.stage],
4772
+ blockers: [e.asset, e.asset_stage],
4773
4773
  blocks: [n.uuid]
4774
4774
  });
4775
4775
  return r.then((l) => {
@@ -4812,7 +4812,7 @@ class J_ extends v {
4812
4812
  },
4813
4813
  blockers: [
4814
4814
  ...e.map((u) => u.asset_procedure),
4815
- ...e.map((u) => u.stage),
4815
+ ...e.map((u) => u.asset_stage),
4816
4816
  ...e.map((u) => u.asset)
4817
4817
  ],
4818
4818
  blocks: c
@@ -5,7 +5,7 @@ Retries:`,i),!(t instanceof Error))throw console.error("ENCOUNTERED NON-ERROR ER
5
5
  Action:`,e);const p=Ze();if(!p)throw new Error("Outbox coordinator not set");p.remove(e.payload.uuid),t.options.discard=!0,u()}}console.debug("Registering a retry for request:",e.payload.uuid);const m=Ze();if(!m)throw new Error("Outbox coordinator not set");return m.registerRetry(e.payload.uuid),!1}function tb(t,e,i){var a;return(a=Ze())==null?void 0:a.peek()}function sb(t,e){return st().dispatch(mm(new Date().getTime())),cc}const et="An unknown error occurred",ib=500,Fp=["non_field_errors","detail"];function ab(t,e){let i;if(t!=null&&t.body)if(typeof t.body=="object"){const a=t.body;if(typeof a.error=="string")i=a.error;else if(typeof a.message=="string")i=a.message;else try{i=Object.entries(a).map(([n,c])=>typeof c=="string"?Fp.includes(n)?c:`${n}: ${c}`:Array.isArray(c)?Fp.includes(n)?c.join(`
6
6
  `):c.map(r=>`${n}: ${r}`).join(`
7
7
  `):`${n}: ${JSON.stringify(c)}`).join(`
8
- `)}catch(n){console.error("Failed to extract error message from response body",n)}}else typeof t.body=="string"&&(i=t.body);else t!=null&&t.text?i=t.text:e instanceof Error&&(i=e.message);return!i||i.length>ib?et:i}class D extends Error{constructor(i){super(et);S(this,"status");S(this,"response");S(this,"message");S(this,"options");const{response:a,innerError:n}=i;this.message=i.message??ab(a,n)??et,this.status=(a==null?void 0:a.status)??0,this.response=a,i.discard=i.discard??!1,this.options=i}}class nb extends yp{constructor(e){super(e)}}class R extends yp{constructor(i,a){super(i);S(this,"auth");this.auth=a}}class cb extends R{async startConversation(e,i){return this.enqueueRequest({description:"Start agent conversation",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:i},blockers:["prompt"],blocks:["prompt"]}).then(a=>(this.dispatch(fc(a)),a))}async continueConversation(e,i,a){return this.enqueueRequest({description:"Prompt agent",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:a},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:i}}).then(n=>{this.dispatch(Tc(n))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:l.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(i=>{this.dispatch(Sc(i))})}async rate(e,i){return this.enqueueRequest({description:"Rate agent response",method:l.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:i},blockers:["rate"],blocks:["rate"]})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get agent conversation history",method:l.GET,url:"/agents/conversations/",queryParams:{project:e},blockers:["agent-conversations"],blocks:["agent-conversations"]},i);return this.dispatch(Ac(a)),a}}const V=1e3,He=200;class j extends R{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:i,assetAttachmentReducer:a,assetTypeAttachmentReducer:n,documentAttachmentReducer:c,projectAttachmentReducer:r,formRevisionAttachmentReducer:u,formSubmissionAttachmentReducer:m,geoImageReducer:o,assetTypeFieldsAttachmentReducer:h,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:y,issueTypeFieldValuesAttachmentReducer:A}=this.client.store.getState();return[].concat(Object.values(i.instances),Object.values(a.instances),Object.values(n.instances),Object.values(c.instances),Object.values(r.instances),Object.values(u.instances),Object.values(m.instances),Object.values(o.instances),Object.values(h.instances),Object.values(p.instances),Object.values(y.instances),Object.values(A.instances)).filter(F=>F.file_sha1===e).length}processPresignedUrls(e){const i={};for(const[a,n]of Object.entries(e))i[a]=this.enqueueRequest({url:n.url,description:"Upload file to S3",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:a,blockers:[`s3-${n.fields.key}`],blocks:[a],s3url:n});return i}async getFilePayload(e){const i=await Qe(e),a={sha1:i,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,i),a}}class We extends j{async _bulkAdd(e){var o;const{store:i}=this.client,a=(o=i.getState().userReducer.currentUser)==null?void 0:o.id,n=new Date().toISOString(),c=[],r=[],u={};for(const h of e){const{modelUuid:p,file:y}=h,A=await this.getFilePayload(y);A.sha1 in u||(u[A.sha1]=A);const I=this.buildOfflineAttachment({file:y,file_sha1:A.sha1,submitted_at:n,created_by:a,description:"",modelUuid:p});c.push(I),r.push(this.buildAttachmentPayload({uuid:I.uuid,file_name:I.file_name,file_sha1:I.file_sha1,file_extension:A.extension,description:I.description,modelUuid:p}))}this.dispatch(this.addAttachments(c));const m=this.enqueueRequest({description:`Add ${this.name}`,method:l.POST,url:`${this.url}/bulk/`,payload:{submitted_at:n,attachments:r,files:Object.values(u)},blocks:c.map(h=>h.uuid),blockers:c.map(h=>h.file_sha1)});return m.then(({attachments:h,presigned_urls:p})=>{this.dispatch(this.updateAttachments(h)),this.processPresignedUrls(p)}).catch(()=>{this.dispatch(this.removeAttachments(c.map(h=>h.uuid)))}),[c,m.then(({attachments:h})=>h)]}async _delete(e){const{store:i}=this.client,a=this.selectAttachment(e)(i.getState());if(!a)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(a.uuid));const n=this.enqueueRequest({description:`Delete ${this.name}`,method:l.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return n.then(()=>{this.getNumberOfAttachmentsWithSha1(a.file_sha1)===0&&this.client.files.removeCache(a.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(a))}),n}}class rb extends We{constructor(){super(...arguments);S(this,"name","Asset Attachment");S(this,"url","/asset-attachments");S(this,"initializeAttachments",ds);S(this,"addAttachments",us);S(this,"updateAttachments",Fc);S(this,"removeAttachments",os);S(this,"removeAttachment",Pc);S(this,"setAttachment",bc);S(this,"selectAttachment",Rc)}buildOfflineAttachment(i){return b({file:URL.createObjectURL(i.file),file_sha1:i.file_sha1,created_by:i.created_by,file_name:i.file.name,file_type:i.file.type,submitted_at:i.submitted_at,description:i.description,asset:i.modelUuid})}buildAttachmentPayload(i){return{...i,asset:i.modelUuid}}async bulkAdd(i){return this._bulkAdd(i.map(a=>({modelUuid:a.assetUuid,file:a.file})))}async delete(i){return this._delete(i)}async refreshStore(i,a){const c=(await this.performPagination({immediate:!0,description:"Get asset attachments",method:l.GET,url:`${this.url}/`,queryParams:{limit:He,paginate:!0,asset__project:i},blocks:[],blockers:[]},r=>({immediate:!0,description:"Get asset attachments",method:l.GET,url:r,blockers:[],blocks:[]}),a)).flat();return this.dispatch(ds(c)),c}}class db extends We{constructor(){super(...arguments);S(this,"name","Asset Procedure Attachment");S(this,"url","/asset-procedure-type-attachments");S(this,"addAttachments",Vc);S(this,"updateAttachments",qc);S(this,"removeAttachments",Uc);S(this,"removeAttachment",zc);S(this,"setAttachment",jc);S(this,"selectAttachment",Bc)}buildOfflineAttachment(i){return b({file:URL.createObjectURL(i.file),file_sha1:i.file_sha1,created_by:i.created_by,file_name:i.file.name,file_type:i.file.type,submitted_at:i.submitted_at,description:i.description,asset_procedure_type:i.modelUuid})}buildAttachmentPayload(i){return{...i,asset_procedure_type:i.modelUuid}}async bulkAdd(i){return this._bulkAdd(i.map(a=>({modelUuid:a.assetProcedureTypeUuid,file:a.file})))}async delete(i){return this._delete(i)}async refreshStore(i,a){const n=await this.enqueueRequest({immediate:!0,description:"Get asset procedure attachments",method:l.GET,url:`${this.url}/`,queryParams:{asset_procedure_type__organization:i},blocks:[],blockers:[]},a);return this.dispatch(Ec(n)),n}}class ub extends j{async bulkAdd(e){var m;const i=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,n={},c=[],r=[];for(const o of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:y}=o,A=await this.getFilePayload(y);A.sha1 in n||(n[A.sha1]=A);const I=b({file:URL.createObjectURL(y),file_type:y.type,file_name:y.name,file_sha1:A.sha1,created_by:a,fields_revision:h,submitted_at:i,field_identifier:p});c.push(I);const F={uuid:I.uuid,file_name:y.name,field_identifier:p,file_extension:A.extension,file_sha1:A.sha1,fields_revision:h};r.push(F)}this.dispatch(Lc(c));const u=this.enqueueRequest({description:"Add asset procedure type fields attachments",method:l.POST,url:"/asset-procedure-type-fields-attachments/bulk/",payload:{submitted_at:i,attachments:r,files:Object.values(n)},blockers:c.map(o=>o.fields_revision),blocks:c.map(o=>o.uuid)});return u.then(o=>{this.processPresignedUrls(o.presigned_urls),this.dispatch(Nc(o.attachments))}).catch(()=>{this.dispatch(Hc(c.map(o=>o.uuid)))}),[c,u.then(({attachments:o})=>o)]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset procedure type fields attachments",method:l.GET,url:"/asset-procedure-type-fields-attachments/",queryParams:{fields_revision__asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Gc(a)),a}}class ob extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Xc(c));const r=this.enqueueRequest({description:"Add Asset Procedure Type Fields",method:l.POST,url:"/asset-procedure-type-fields/",payload:v(c),blockers:[c.asset_procedure_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Qc(m))}).catch(m=>{throw this.dispatch(xc(c.uuid)),m}),[c,r]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get Asset Procedure Type Fields",method:l.GET,url:"/asset-procedure-type-fields/",queryParams:{asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Jc(a)),a}}function Ye(t,e){const i=[];let a=0;const n=t.length;for(;a<n;)i.push(t.slice(a,a+=e));return i}class lb extends j{async bulkAdd(e,i){var o;const a=new Date().toISOString(),n=(o=this.client.store.getState().userReducer.currentUser)==null?void 0:o.id,c=Ye(e,i??e.length),r=[],u=[];for(const h of c){const p={},y=[];for(const A of h){const{fieldValuesUuid:I,fieldIdentifier:F,file:_}=A,w=await this.getFilePayload(_);w.sha1 in p||(p[w.sha1]=w);const z=b({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:w.sha1,created_by:n,field_values:I,submitted_at:a,field_identifier:F});r.push(z);const Le={uuid:z.uuid,file_name:_.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:F,field_values:I};y.push(Le)}u.push({submitted_at:a,attachments:y,files:Object.values(p)})}this.dispatch(_t(r));const m=u.map(h=>this.enqueueRequest({description:"Add asset procedure type field values attachments",method:l.POST,url:"/asset-procedure-type-field-values-attachments/bulk/",payload:h,blockers:h.attachments.map(p=>p.field_values),blocks:h.attachments.map(p=>p.uuid)}));return Promise.all(m).then(h=>{for(const y of h)this.processPresignedUrls(y.presigned_urls);const p=h.flatMap(y=>y.attachments);this.dispatch(ar(p))}).catch(h=>{throw this.dispatch(Rt(r.map(p=>p.uuid))),h}),[r,m.map(h=>h.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:i}=this.client,a=i.getState(),n=rr(e)(a);this.dispatch(Rt(e));try{await this.enqueueRequest({description:"Delete asset procedure type field values attachments",method:l.DELETE,url:"/asset-procedure-type-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(_t(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedure type field values attachments",method:l.GET,url:"/asset-procedure-type-field-values-attachments/",queryParams:{limit:He,paginate:!0,field_values__asset_procedure__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedure type field values attachments",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(ir(n)),n}}class hb extends R{add(e){var r;const{store:i}=this.client,a=i.getState(),n=b({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset procedure type field values",method:l.POST,url:"/asset-procedure-type-field-values/",payload:v(n),blockers:[e.asset,e.fields_revision,e.asset_procedure],blocks:[n.uuid]});return this.dispatch(Ss(n)),c.then(u=>(this.dispatch(at(u)),u)).catch(()=>{this.dispatch(Ts(n.uuid))}),[n,c]}bulkAdd(e,i){var m;const a=new Date().toISOString(),n=[],c=Ye(e.payloads,i??e.payloads.length),r=[];for(const o of c){const h=[];for(const p of o){const y=b({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:a});n.push(y),h.push({uuid:y.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure:p.asset_procedure,published_at:p.published_at,values:y.values})}r.push({submitted_at:a,values:e.values,field_values:h})}this.dispatch(lr(n));const u=[];for(const o of r){const h=o.field_values.map(F=>F.asset),p=o.field_values.map(F=>F.fields_revision),y=o.field_values.map(F=>F.asset_procedure),A=o.field_values.map(F=>F.uuid),I=this.enqueueRequest({description:"Bulk add asset procedure type field values",method:l.POST,url:"/asset-procedure-type-field-values/bulk/",payload:o,blockers:[...h,...p,...y],blocks:A});u.push(I)}return Promise.all(u).then(o=>{this.dispatch(hr(o.flat()))}).catch(()=>{this.dispatch(mr(n.map(o=>o.uuid)))}),[n,u]}update(e){const{store:i}=this.client,a=i.getState(),n=gs(e.uuid)(a);if(!n)throw new Error(`Expected AssetProcedureTypeFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(at(c));const r=this.enqueueRequest({description:"Update asset procedure type field values",method:l.PATCH,url:`/asset-procedure-type-field-values/${e.uuid}/`,payload:e,blockers:[c.fields_revision,c.asset,c.asset_procedure],blocks:[c.uuid]});return r.then(u=>{this.dispatch(at(u))}).catch(()=>{this.dispatch(at(n))}),[c,r]}async delete(e){const{store:i}=this.client,a=i.getState(),n=gs(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=dr(e)(a);this.dispatch(Ts(e)),this.dispatch(Rt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure type field values",method:l.DELETE,url:`/asset-procedure-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Ss(n)),this.dispatch(_t(c)),r}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedure type field values",method:l.GET,url:"/asset-procedure-type-field-values/",queryParams:{limit:V,paginate:!0,asset_procedure__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedure type field values",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(or(n)),n}}class mb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Fs(c));const r=this.enqueueRequest({description:"Create asset procedure",method:l.POST,url:"/asset-procedures/",payload:v(c),blockers:[e.asset_procedure_type,e.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(nt(m))}).catch(()=>{this.dispatch(Ps(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Rs(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(nt(n));const c=this.enqueueRequest({description:"Update asset procedure",method:l.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(nt(r))}).catch(()=>{this.dispatch(nt(a))}),[n,c]}async remove(e){const{store:i}=this.client,a=i.getState(),n=Rs(e)(a);if(!n)throw new Error(`Expected asset procedure with uuid ${e} to exist`);return this.dispatch(Ps(e)),this.enqueueRequest({description:"Delete asset procedure",method:l.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(Fs(n)),c})}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedures",method:l.GET,url:"/asset-procedures/",queryParams:{limit:V,paginate:!0,project:e},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedures",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(fr(n)),n}}class pb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ws(c));const r=this.enqueueRequest({description:"Create asset procedure type",method:l.POST,url:"/asset-procedure-types/",payload:v(c),blockers:[],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ct(m))}).catch(()=>{this.dispatch(Ms(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Vs(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset procedure type with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(ct(n));const c=this.enqueueRequest({description:"Update asset procedure type",method:l.PATCH,url:`/asset-procedure-types/${e.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(ct(r))}).catch(()=>{this.dispatch(ct(a))}),[n,c]}async remove(e){const{store:i}=this.client,a=i.getState(),n=Vs(e)(a);if(!n)throw new Error(`Expected asset procedure type with uuid ${e} to exist`);const c=gr(e)(a);return this.dispatch(Ms(e)),this.dispatch(Tr(c.map(({uuid:r})=>r))),this.enqueueRequest({description:"Delete asset procedure type",method:l.DELETE,url:`/asset-procedure-types/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(ws(n)),this.dispatch(Sr(c)),r})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset procedure types",method:l.GET,url:"/asset-procedure-types/",queryParams:{organization:e},blockers:[],blocks:[]},i);return this.dispatch(Fr(a)),a}}class yb extends j{async bulkAdd(e){var m;const i=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,n={},c=[],r=[];for(const o of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:y}=o,A=await this.getFilePayload(y);A.sha1 in n||(n[A.sha1]=A);const I=b({file:URL.createObjectURL(y),file_type:y.type,file_name:y.name,file_sha1:A.sha1,created_by:a,fields_revision:h,submitted_at:i,field_identifier:p});c.push(I);const F={uuid:I.uuid,file_name:y.name,field_identifier:p,file_extension:A.extension,file_sha1:A.sha1,fields_revision:h};r.push(F)}this.dispatch(vr(c));const u=this.enqueueRequest({description:"Add asset procedure step fields attachments",method:l.POST,url:"/asset-procedure-step-fields-attachments/bulk/",payload:{submitted_at:i,attachments:r,files:Object.values(n)},blockers:c.map(o=>o.fields_revision),blocks:c.map(o=>o.uuid)});return u.then(o=>{this.processPresignedUrls(o.presigned_urls),this.dispatch(wr(o.attachments))}).catch(()=>{this.dispatch(Mr(c.map(o=>o.uuid)))}),[c,u.then(({attachments:o})=>o)]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset procedure step fields attachments",method:l.GET,url:"/asset-procedure-step-fields-attachments/",queryParams:{fields_revision__asset_procedure_step__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Rr(a)),a}}class Ab extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(zs(c));const r=this.enqueueRequest({description:"Add Asset Procedure Step Fields",method:l.POST,url:"/asset-procedure-step-fields/",payload:v(c),blockers:[c.asset_procedure_step],blocks:[c.uuid]});return r.then(m=>{this.dispatch(rt(m))}).catch(m=>{throw this.dispatch(Us(c.uuid)),m}),[c,r]}update(e){const{store:i}=this.client,a=i.getState().assetProcedureStepFieldsReducer.instances[e.uuid];if(!a)throw new Error(`AssetProcedureStepFields with uuid ${e.uuid} not found`);const n={...a,...e};this.dispatch(rt(n));const c=this.enqueueRequest({description:"Update Asset Procedure Step Fields",method:l.PATCH,url:`/asset-procedure-step-fields/${a.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(rt(r))}).catch(r=>{throw this.dispatch(rt(a)),r}),[n,c]}delete(e){const{store:i}=this.client,a=i.getState().assetProcedureStepFieldsReducer.instances[e];if(!a)throw new Error(`AssetProcedureStepFields with uuid ${e} not found`);this.dispatch(Us(e));const n=this.enqueueRequest({description:"Delete Asset Procedure Step Fields",method:l.DELETE,url:`/asset-procedure-step-fields/${e}/`,blockers:[e],blocks:[e]});return n.catch(c=>{throw this.dispatch(zs(a)),c}),n}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get Asset Procedure Step Fields",method:l.GET,url:"/asset-procedure-step-fields/",queryParams:{asset_procedure_step__asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(zr(a)),a}}class fb extends j{async bulkAdd(e,i){var o;const a=new Date().toISOString(),n=(o=this.client.store.getState().userReducer.currentUser)==null?void 0:o.id,c=Ye(e,i??e.length),r=[],u=[];for(const h of c){const p={},y=[];for(const A of h){const{fieldValuesUuid:I,fieldIdentifier:F,file:_}=A,w=await this.getFilePayload(_);w.sha1 in p||(p[w.sha1]=w);const z=b({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:w.sha1,created_by:n,field_values:I,submitted_at:a,field_identifier:F});r.push(z);const Le={uuid:z.uuid,file_name:_.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:F,field_values:I};y.push(Le)}u.push({submitted_at:a,attachments:y,files:Object.values(p)})}this.dispatch(vt(r));const m=u.map(h=>this.enqueueRequest({description:"Add asset procedure step field values attachments",method:l.POST,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:h,blockers:h.attachments.map(p=>p.field_values),blocks:h.attachments.map(p=>p.uuid)}));return Promise.all(m).then(h=>{for(const y of h)this.processPresignedUrls(y.presigned_urls);const p=h.flatMap(y=>y.attachments);this.dispatch(kr(p))}).catch(h=>{throw this.dispatch(wt(r.map(p=>p.uuid))),h}),[r,m.map(h=>h.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:i}=this.client,a=i.getState(),n=$r(e)(a);this.dispatch(wt(e));try{await this.enqueueRequest({description:"Delete asset procedure step field values attachments",method:l.DELETE,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(vt(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedure step field values attachments",method:l.GET,url:"/asset-procedure-step-field-values-attachments/",queryParams:{limit:He,paginate:!0,field_values__asset_procedure__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedure step field values attachments",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Cr(n)),n}}class Sb extends R{add(e){var r;const{store:i}=this.client,a=i.getState(),n=b({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset procedure step field values",method:l.POST,url:"/asset-procedure-step-field-values/",payload:v(n),blockers:[e.asset,e.fields_revision,e.asset_procedure],blocks:[n.uuid]});return this.dispatch(Gs(n)),c.then(u=>(this.dispatch(dt(u)),u)).catch(()=>{this.dispatch(Ls(n.uuid))}),[n,c]}bulkAdd(e,i){var m;const a=new Date().toISOString(),n=[],c=Ye(e.payloads,i??e.payloads.length),r=[];for(const o of c){const h=[];for(const p of o){const y=b({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:a});n.push(y),h.push({uuid:y.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure:p.asset_procedure,asset_procedure_step:p.asset_procedure_step,published_at:p.published_at,values:y.values})}r.push({submitted_at:a,values:e.values,field_values:h})}this.dispatch(Wr(n));const u=[];for(const o of r){const h=o.field_values.map(F=>F.asset),p=o.field_values.map(F=>F.fields_revision),y=o.field_values.map(F=>F.asset_procedure),A=o.field_values.map(F=>F.uuid),I=this.enqueueRequest({description:"Bulk add asset procedure step field values",method:l.POST,url:"/asset-procedure-step-field-values/bulk/",payload:o,blockers:[...h,...p,...y],blocks:A});u.push(I)}return Promise.all(u).then(o=>{this.dispatch(Kr(o.flat()))}).catch(()=>{this.dispatch(Yr(n.map(o=>o.uuid)))}),[n,u]}update(e){const{store:i}=this.client,a=i.getState(),n=Ns(e.uuid)(a);if(!n)throw new Error(`Expected AssetProcedureStepFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(dt(c));const r=this.enqueueRequest({description:"Update asset procedure step field values",method:l.PATCH,url:`/asset-procedure-step-field-values/${e.uuid}/`,payload:e,blockers:[c.fields_revision,c.asset,c.asset_procedure],blocks:[c.uuid]});return r.then(u=>{this.dispatch(dt(u))}).catch(()=>{this.dispatch(dt(n))}),[c,r]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Ns(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Gr(e)(a);this.dispatch(Ls(e)),this.dispatch(wt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure step field values",method:l.DELETE,url:`/asset-procedure-step-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Gs(n)),this.dispatch(vt(c)),r}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedure step field values",method:l.GET,url:"/asset-procedure-step-field-values/",queryParams:{limit:V,paginate:!0,asset_procedure__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedure step field values",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Hr(n)),n}}class Tb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Ws(c));const r=this.enqueueRequest({description:"Create asset procedure step",method:l.POST,url:"/asset-procedure-steps/",payload:v(c),blockers:[c.asset_procedure_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Et(m))}).catch(()=>{this.dispatch(Ks(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Ys(e.uuid)(i.getState());if(!a)throw new Error(`No asset procedure step with uuid ${e.uuid} found in the store`);const n={...a,...e};this.dispatch(Et(n));const c=this.enqueueRequest({description:"Update asset procedure step",method:l.PATCH,url:`/asset-procedure-steps/${a.uuid}/`,payload:{name:e.name,description:e.description,priority:e.order,color:e.color},blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(Et(r))}).catch(()=>{this.dispatch(xr(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Ys(e)(a);if(!n)throw new Error(`No asset procedure step with uuid ${e} found in the store`);return this.dispatch(Ks(e)),this.enqueueRequest({description:"Delete asset stage",method:l.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(Ws(n)),c})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset procedure steps",method:l.GET,url:"/asset-procedure-steps/",queryParams:{asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Qr(a)),a}}class Ib extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Js(c));const r=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/assets/",payload:v(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ut(m))}).catch(()=>{this.dispatch(Xs(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=ti(e.uuid)(i.getState());if(!a)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const n={...a,...e};this.dispatch(ut(n));const c=this.enqueueRequest({description:"Edit asset",method:l.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(ut(r))}).catch(()=>{this.dispatch(ut(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=ti(e)(a);if(!n)throw new Error(`No asset with uuid ${e} found in the store`);const c=vc(e)(a),r=cl(e)(a);if(this.dispatch(Xs(e)),c.length>0){const u=c.map(({uuid:m})=>m);this.dispatch(os(u))}if(r.length>0){const u=r.map(({uuid:m})=>m);this.dispatch(_a(u))}return this.enqueueRequest({description:"Delete asset",method:l.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(u=>{throw this.dispatch(Js(n)),this.dispatch(us(c)),this.dispatch(Pa(r)),u})}bulkAdd(e,i,a,n){const c=new Date().toISOString(),r=Xe.v4(),u=Ye(e,n).map(h=>{const p=h.map(y=>b(y));return{batchId:Xe.v4(),payload:{transaction_id:r,submitted_at:c,asset_type:i,project:a,assets:p}}}),m=[];let o=null;for(const h of u){const{batchId:p,payload:y}=h,A=y.assets.map(w=>w.uuid),I=[i];o&&I.push(o);const F=A;F.push(p);const _=this.enqueueRequest({description:"Batch create assets",method:l.POST,url:"/assets/bulk/",payload:y,blockers:I,blocks:F});o=h.batchId,m.push(_)}return Promise.all(m).then(h=>{const p=h.flat();this.dispatch(jt(p))}),m}async bulkDelete(e){const{store:i}=this.client,a=i.getState(),n=nd(e)(a);this.dispatch(Qs(e));try{await this.enqueueRequest({description:"Bulk delete assets",method:l.DELETE,url:"/assets/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(jt(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get assets",method:l.GET,url:"/assets/",queryParams:{limit:V,paginate:!0,project:e},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get assets",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(id(n)),n}}class gb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ii(c));const r=this.enqueueRequest({description:"Add asset stage completion",method:l.POST,url:"/asset-stage-completions/",payload:v(c),blockers:[e.asset,e.stage],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ud(m))}).catch(()=>{this.dispatch(ni(c.uuid))}),[c,r]}delete(e){const{store:i}=this.client,a=hd(e)(i.getState());if(!a)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(ni(e));const n=this.enqueueRequest({description:"Delete asset stage completion",method:l.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return n.catch(()=>{this.dispatch(ii(a))}),n}bulkAdd(e){var o;const{store:i}=this.client,a=new Date().toISOString(),n=(o=i.getState().userReducer.currentUser)==null?void 0:o.id,c=e.map(h=>b(h)),r=c.map(h=>({...h,created_by:n,submitted_at:a})),u=r.map(({uuid:h})=>h);this.dispatch(ai(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:l.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:a,completions:c},blockers:[...e.map(h=>h.asset_procedure),...e.map(h=>h.stage),...e.map(h=>h.asset)],blocks:u});return m.then(h=>{this.dispatch(od(h))}).catch(()=>{this.dispatch(ci(u))}),[r,m]}bulkDelete(e){const{store:i}=this.client,a=md(e)(i.getState());this.dispatch(ci(e));const n=this.enqueueRequest({description:"Deleting asset stage completions",method:l.DELETE,url:"/asset-stage-completions/bulk/",payload:{uuids:e},blockers:e,blocks:[]});return n.catch(()=>{this.dispatch(ai(a))}),n}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset stage completions",method:l.GET,url:"/asset-stage-completions/",queryParams:{limit:V,paginate:!0,asset_procedure__project:e},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset stage completions",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(dd(n)),n}}class bb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ui(c));const r=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/asset-stages/",payload:v(c),blockers:[c.asset_procedure_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(qt(m))}).catch(()=>{this.dispatch(oi(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=li(e.uuid)(i.getState());if(!a)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const n={...a,...e};this.dispatch(qt(n));const c=this.enqueueRequest({description:"Update asset stage",method:l.PATCH,url:`/asset-stages/${a.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(qt(r))}).catch(()=>{this.dispatch(Ad(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=li(e)(a);if(!n)throw new Error(`No asset stage with uuid ${e} found in the store`);return this.dispatch(oi(e)),this.enqueueRequest({description:"Delete asset stage",method:l.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(ui(n)),c})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset stages",method:l.GET,url:"/asset-stages/",queryParams:{asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(yd(a)),a}}class Fb extends We{constructor(){super(...arguments);S(this,"name","Asset Type Attachment");S(this,"url","/asset-type-attachments");S(this,"addAttachments",mi);S(this,"updateAttachments",bd);S(this,"removeAttachments",pi);S(this,"removeAttachment",Fd);S(this,"setAttachment",gd);S(this,"selectAttachment",_d)}buildOfflineAttachment(i){return b({file:URL.createObjectURL(i.file),file_sha1:i.file_sha1,created_by:i.created_by,file_name:i.file.name,file_type:i.file.type,submitted_at:i.submitted_at,description:i.description,asset_type:i.modelUuid})}buildAttachmentPayload(i){return{...i,asset_type:i.modelUuid}}async bulkAdd(i){return this._bulkAdd(i.map(a=>({modelUuid:a.assetTypeUuid,file:a.file})))}async delete(i){return this._delete(i)}async refreshStore(i,a){const n=await this.enqueueRequest({immediate:!0,description:"Get asset type attachments",method:l.GET,url:`${this.url}/`,queryParams:{asset_type__organization:i},blocks:[],blockers:[]},a);return this.dispatch(Id(n)),n}}class Pb extends j{async bulkAdd(e){var m;const i=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,n={},c=[],r=[];for(const o of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:y}=o,A=await this.getFilePayload(y);A.sha1 in n||(n[A.sha1]=A);const I=b({file:URL.createObjectURL(y),file_type:y.type,file_name:y.name,file_sha1:A.sha1,created_by:a,fields_revision:h,submitted_at:i,field_identifier:p});c.push(I);const F={uuid:I.uuid,file_name:y.name,field_identifier:p,file_extension:A.extension,file_sha1:A.sha1,fields_revision:h};r.push(F)}this.dispatch(Ed(c));const u=this.enqueueRequest({description:"Add asset type fields attachments",method:l.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:i,attachments:r,files:Object.values(n)},blockers:c.map(o=>o.fields_revision),blocks:c.map(o=>o.uuid)});return u.then(o=>{this.processPresignedUrls(o.presigned_urls),this.dispatch(Vd(o.attachments))}).catch(()=>{this.dispatch(jd(c.map(o=>o.uuid)))}),[c,u.then(({attachments:o})=>o)]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset type fields attachments",method:l.GET,url:"/asset-type-fields-attachments/",queryParams:{fields_revision__asset_type__organization:e},blockers:[e],blocks:[]},i);return this.dispatch(Md(a)),a}}class Ob extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(kd(c));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:l.POST,url:"/asset-type-fields/",payload:v(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Bd(m))}).catch(m=>{throw this.dispatch($d(c.uuid)),m}),[c,r]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get Asset Type Fields",method:l.GET,url:"/asset-type-fields/",queryParams:{asset_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Cd(a)),a}}class _b extends j{async bulkAdd(e,i){var o;const a=new Date().toISOString(),n=(o=this.client.store.getState().userReducer.currentUser)==null?void 0:o.id,c=Ye(e,i??e.length),r=[],u=[];for(const h of c){const p={},y=[];for(const A of h){const{fieldValuesUuid:I,fieldIdentifier:F,file:_}=A,w=await this.getFilePayload(_);w.sha1 in p||(p[w.sha1]=w);const z=b({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:w.sha1,created_by:n,field_values:I,submitted_at:a,field_identifier:F});r.push(z);const Le={uuid:z.uuid,file_name:_.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:F,field_values:I};y.push(Le)}u.push({submitted_at:a,attachments:y,files:Object.values(p)})}this.dispatch(Dt(r));const m=u.map(h=>this.enqueueRequest({description:"Add asset type field values attachments",method:l.POST,url:"/asset-type-field-values-attachments/bulk/",payload:h,blockers:h.attachments.map(p=>p.field_values),blocks:h.attachments.map(p=>p.uuid)}));return Promise.all(m).then(h=>{for(const y of h)this.processPresignedUrls(y.presigned_urls);const p=h.flatMap(y=>y.attachments);this.dispatch(Wd(p))}).catch(h=>{throw this.dispatch(Ct(r.map(p=>p.uuid))),h}),[r,m.map(h=>h.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:i}=this.client,a=i.getState(),n=Yd(e)(a);this.dispatch(Ct(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:l.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(Dt(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset type field values attachments",method:l.GET,url:"/asset-type-field-values-attachments/",queryParams:{limit:He,paginate:!0,field_values__asset__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset type field values attachments",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Hd(n)),n}}class Rb extends R{add(e){var r;const{store:i}=this.client,a=i.getState(),n=b({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset type field values",method:l.POST,url:"/asset-type-field-values/",payload:v(n),blockers:[e.asset,e.fields_revision],blocks:[n.uuid]});return this.dispatch(Ii(n)),c.then(u=>(this.dispatch(ot(u)),u)).catch(()=>{this.dispatch(gi(n.uuid))}),[n,c]}bulkAdd(e,i){var m;const a=new Date().toISOString(),n=[],c=Ye(e.payloads,i??e.payloads.length),r=[];for(const o of c){const h=[];for(const p of o){const y=b({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:a});n.push(y),h.push({uuid:y.uuid,asset:p.asset,fields_revision:p.fields_revision,published_at:p.published_at,values:y.values})}r.push({submitted_at:a,values:e.values,field_values:h})}this.dispatch(xd(n));const u=[];for(const o of r){const h=o.field_values.map(I=>I.asset),p=o.field_values.map(I=>I.fields_revision),y=o.field_values.map(I=>I.uuid),A=this.enqueueRequest({description:"Bulk add asset type field values",method:l.POST,url:"/asset-type-field-values/bulk/",payload:o,blockers:[...h,...p],blocks:y});u.push(A)}return Promise.all(u).then(o=>{this.dispatch(eu(o.flat()))}).catch(()=>{this.dispatch(tu(n.map(o=>o.uuid)))}),[n,u]}update(e){const{store:i}=this.client,a=i.getState(),n=Fi(e.uuid)(a);if(!n)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(ot(c));const r=this.enqueueRequest({description:"Delete asset type field values",method:l.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.asset],blocks:[c.uuid]});return r.then(u=>{this.dispatch(ot(u))}).catch(()=>{this.dispatch(ot(n))}),[c,r]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Fi(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Zd(e)(a);this.dispatch(gi(e)),this.dispatch(Ct(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:l.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Ii(n)),this.dispatch(Dt(c)),r}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset type field values",method:l.GET,url:"/asset-type-field-values/",queryParams:{limit:V,paginate:!0,asset__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset type field values",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Qd(n)),n}}class vb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Oi(c));const r=this.enqueueRequest({description:"Create asset type identifier",method:l.POST,url:"/asset-type-identifiers/",payload:v(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(lt(m))}).catch(()=>{this.dispatch(_i(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Ri(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset type identifier with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(lt(n));const c=this.enqueueRequest({description:"Update asset type identifier",method:l.PATCH,url:`/asset-type-identifiers/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(lt(r))}).catch(()=>{this.dispatch(lt(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Ri(e)(a);if(!n)throw new Error(`Expected asset type identifier with uuid ${e} to exist`);this.dispatch(_i(e));try{return await this.enqueueRequest({description:"Delete asset type identifier",method:l.DELETE,url:`/asset-type-identifiers/${e}/`,blockers:[e],blocks:[]})}catch(c){throw this.dispatch(Oi(n)),c}}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset type identifiers",method:l.GET,url:"/asset-type-identifiers/",queryParams:{asset_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(nu(a)),a}}class wb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(wi(c));const r=this.enqueueRequest({description:"Create asset type identifier value",method:l.POST,url:"/asset-type-identifier-values/",payload:v(c),blockers:[e.asset,e.asset_type_identifier],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ht(m))}).catch(()=>{this.dispatch(Mi(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Vi(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset type identifier value with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(ht(n));const c=this.enqueueRequest({description:"Update asset type identifier value",method:l.PATCH,url:`/asset-type-identifier-values/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(ht(r))}).catch(()=>{this.dispatch(ht(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Vi(e)(a);if(!n)throw new Error(`Expected asset type identifier value with uuid ${e} to exist`);this.dispatch(Mi(e));try{return await this.enqueueRequest({description:"Delete asset type identifier value",method:l.DELETE,url:`/asset-type-identifier-values/${e}/`,blockers:[e],blocks:[]})}catch(c){throw this.dispatch(wi(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset type identifier values",method:l.GET,url:"/asset-type-identifier-values/",queryParams:{limit:V,paginate:!0,asset__project:e},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset type identifier values",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(ou(n)),n}}class Mb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(qi(c));const r=this.enqueueRequest({description:"Create asset type",method:l.POST,url:"/asset-types/",payload:v(c),blockers:[],blocks:[c.uuid]});return r.then(m=>{this.dispatch(mt(m))}).catch(()=>{this.dispatch(zi(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Di(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(mt(n));const c=this.enqueueRequest({description:"Update asset type",method:l.PATCH,url:`/asset-types/${e.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(mt(r))}).catch(()=>{this.dispatch(mt(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Di(e)(a);if(!n)throw new Error(`Expected asset type with uuid ${e} to exist`);const c=ei(e)(a),r=Rd(e)(a);return this.dispatch(zi(e)),this.dispatch(Qs(c.map(u=>u.uuid))),this.dispatch(pi(r.map(({uuid:u})=>u))),this.enqueueRequest({description:"Delete asset type",method:l.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(u=>{throw this.dispatch(qi(n)),this.dispatch(jt(c)),this.dispatch(mi(r)),u})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset types",method:l.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]},i);return this.dispatch(pu(a)),a}}class Eb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ki(c));const r=this.enqueueRequest({description:"Create Category",method:l.POST,url:"/categories/",payload:v(c),blockers:[e.project],blocks:[c.uuid]});return[c,r]}update(e){const i=this.client.store.getState(),a=$i(e.uuid)(i);if(!a)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const n={...a,...e};this.dispatch(bu(n));const c=this.enqueueRequest({description:"Edit Category",method:l.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[n,c]}remove(e){const{store:i}=this.client,a=$i(e)(i.getState());if(!a)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(Fu(e));const n=this.enqueueRequest({description:"Delete Category",method:l.DELETE,url:`/categories/${a.uuid}/`,blockers:[a.uuid],blocks:[]});return n.catch(()=>{this.dispatch(ki(a))}),n}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get categories",method:l.GET,url:"/categories/",queryParams:{project__organization:e},blocks:[],blockers:[]},i);return this.dispatch(gu(a)),a}}class Vb extends We{constructor(){super(...arguments);S(this,"name","Document Attachment");S(this,"url","/document-attachments");S(this,"addAttachments",vu);S(this,"updateAttachments",Mu);S(this,"removeAttachments",Vu);S(this,"removeAttachment",Eu);S(this,"setAttachment",wu);S(this,"selectAttachment",zu)}buildOfflineAttachment(i){return b({file:URL.createObjectURL(i.file),file_sha1:i.file_sha1,created_by:i.created_by,file_name:i.file.name,file_type:i.file.type,submitted_at:i.submitted_at,description:i.description,document:i.modelUuid})}buildAttachmentPayload(i){return{...i,document:i.modelUuid}}async bulkAdd(i){var p;const{store:a}=this.client,n=(p=a.getState().userReducer.currentUser)==null?void 0:p.id,c=new Date().toISOString(),r=[],u=[],m={},o={};for(const y of i){const{documentUuid:A,file:I}=y,F=await this.getFilePayload(I);F.sha1 in m||(m[F.sha1]=F,o[F.sha1]=[]);const _=this.buildOfflineAttachment({file:I,file_sha1:F.sha1,submitted_at:c,created_by:n,description:"",modelUuid:A});r.push(_),u.push({uuid:_.uuid,file_name:_.file_name,file_sha1:_.file_sha1,file_extension:F.extension,description:_.description,document:A}),o[F.sha1].push(_.uuid)}this.dispatch(this.addAttachments(r));const h=this.enqueueRequest({description:"Attach files to document",method:l.POST,url:"/document-attachments/bulk/",payload:{submitted_at:c,attachments:u,files:Object.values(m)},blocks:r.map(y=>y.uuid),blockers:r.map(y=>y.file_sha1)});return h.then(({attachments:y,presigned_urls:A})=>{this.dispatch(this.updateAttachments(y));const I=this.processPresignedUrls(A);for(const[F,_]of Object.entries(I))_.then(()=>{const w=o[F];for(const z of w)this.makeReadable(z)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(y=>y.uuid)))}),[r,h.then(({attachments:y})=>y)]}async delete(i){return this._delete(i)}makeReadable(i){this.enqueueRequest({description:"Add attachment to AI assistant",method:l.PATCH,url:`/document-attachments/${i}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",i],blocks:["index-document-attachment"]})}async refreshStore(i,a){const n=await this.enqueueRequest({immediate:!0,description:"Get document attachments",method:l.GET,url:"/document-attachments/",queryParams:{document__project__organization:i},blocks:[],blockers:[]},a),c=await this.enqueueRequest({immediate:!0,description:"Get document attachments",method:l.GET,url:"/document-attachments/",queryParams:{document__organization:i},blocks:[],blockers:[]},a),r=[...n,...c];return this.dispatch(Ru(r)),r}}class jb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ku([c]));const r=this.enqueueRequest({description:"Create Document",method:l.POST,url:"/documents/",payload:v(c),queryParams:{parent_document:c.parent_document??void 0},blockers:c.parent_document?[c.parent_document]:[],blocks:[c.uuid]});return r.catch(()=>{this.dispatch(Ni([c.uuid]))}),[c,r]}update(e){const{store:i}=this.client,a=i.getState().documentsReducer.documents[e.uuid];if(!a)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const n={...a,...e};this.dispatch(xe([n]));const c=this.enqueueRequest({description:"Update Document",method:l.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{xe([a])}),[n,c]}delete(e){const{store:i}=this.client,a=Bt(i.getState()),n=Bu(e)(i.getState());if(!n)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const c=n.parent_document?a[n.parent_document]:void 0;this.dispatch(Ni([e]));const r=this.enqueueRequest({description:"Delete Document",method:l.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(u=>{this.dispatch(xe(u))}).catch(()=>{this.dispatch(xe([n])),c&&this.dispatch(xe([c]))}),r}async refreshStore(e,i){const a=this.enqueueRequest({immediate:!0,description:"Get project documents",method:l.GET,url:"/documents/",queryParams:{project__organization:e},blockers:[],blocks:[]},i),n=this.enqueueRequest({immediate:!0,description:"Get organization documents",method:l.GET,url:"/documents/",queryParams:{organization:e},blockers:[],blocks:[]},i),c=[...await a,...await n];return this.dispatch(Cu(c)),c}}class qb extends R{async add(e,i){return this.enqueueRequest({description:"Add email domain to organization",method:l.POST,url:"/organization-email-domains/",payload:{email:i,organization:e},blockers:[e,"create-org"],blocks:[]})}async remove(e){return this.dispatch(Hu(e.uuid)),this.enqueueRequest({description:"Remove email domain from organization",method:l.DELETE,url:`/organization-email-domains/${e.uuid}/`,blockers:[e.domain],blocks:[]}).catch(i=>{throw this.dispatch(Nu(e)),i})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Fetch email domains for organization",method:l.GET,url:"/organization-email-domains/",queryParams:{organization:e},blockers:[e],blocks:[]},i);return this.dispatch(Lu(a)),a}}class zb extends R{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:l.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,i=void 0){return this.enqueueRequest({description:"Validate verification code",method:l.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:i,blockers:[],blocks:[]})}}const Xt={},Jn=new Set;let Qt=0,Xn=0,Qn=0;const Ub=20;class Db extends R{constructor(){super(...arguments);S(this,"host");S(this,"_dbPromise",Bp.openDB("fileCache",1,{upgrade(i){i.createObjectStore("files")}}))}async renewUploadUrl(i){const a=await this.fetchCache(i);if(!a)throw new Error(`File with sha1 ${i} not found in cache`);const n=await as(a,i),c=await this.enqueueRequest({description:"Get S3 URL",method:l.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await Qe(a),file_type:a.type,extension:a.name.split(".").pop(),size:a.size.toString()},blockers:[],blocks:[`s3-${n}`]});return"url"in c&&this.dispatch(Xu({sha1:i,...c})),c}async addCache(i,a){if(Jn.has(a))return;if(!i.type){const r=i.name.split("."),u=r[r.length-1];i=new File([i],i.name,{type:u})}if(!i.name||!i.size||!i.type)throw new Error("Cannot add files to cache that do not have a name, size and type.");const n=await this._dbPromise;!!await n.get("files",a)?(console.error("File already cached (this is unexpected at this point):",i.name,a),Qt++):(await n.put("files",i,a),Xn++),Jn.add(a),Qn++,Qn%Ub===0&&console.debug(`File cache summary: ${Qt} hits and ${Xn} misses, ${Qt/(Qt+Xn)*100}% hit rate over ${Qn} calls to addCache.`)}async removeCache(i){await(await this._dbPromise).delete("files",i),Jn.delete(i)}async fetchCache(i){return(await this._dbPromise).get("files",i)}async getOrRenewUploadUrl(i){const a=this.client.store.getState();return Qu(i)(a)??await this.renewUploadUrl(i)}async uploadFileToS3(i){const a=await this.fetchCache(i);if(!a)throw new Error(`File with sha1 ${i} not found in cache`);const n=await as(a,i),c={file_name:a.name,file_sha1:i,file:n},r=await this.getOrRenewUploadUrl(i);if("warning"in r){if(r.warning==="already_uploaded")return[c,Promise.resolve(void 0)];throw new Error(r.warning)}const u=r.url,m=this.enqueueRequest({url:u,description:"Upload file",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:i,blockers:[`s3-${n}`],blocks:[i],s3url:r});return[c,m]}async fetchFileFromUrl(i,a,n){const c=i.split("?")[0]??i,r=await this.fetchCache(a);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(i.startsWith("blob:")){const h=await oc(i),p=new File([h],n??a,{type:h.type});return await this.addCache(p,a),p}let u=Xt[c],m=!0;u?m=!1:(u=new Promise(h=>{this.enqueueRequest({description:"Download file",method:l.GET,url:i,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[a],blocks:[a]}).then(p=>{const y=new File([p],n??a,{type:p.type});h(y)})}),Xt[c]=u);let o;try{o=await u}catch(h){throw m&&h instanceof D&&delete Xt[c],h}if(m){const h=await Qe(o);if(h!==a){const A=`The hash of the file returned from the server (${h}) does not match the
8
+ `)}catch(n){console.error("Failed to extract error message from response body",n)}}else typeof t.body=="string"&&(i=t.body);else t!=null&&t.text?i=t.text:e instanceof Error&&(i=e.message);return!i||i.length>ib?et:i}class D extends Error{constructor(i){super(et);S(this,"status");S(this,"response");S(this,"message");S(this,"options");const{response:a,innerError:n}=i;this.message=i.message??ab(a,n)??et,this.status=(a==null?void 0:a.status)??0,this.response=a,i.discard=i.discard??!1,this.options=i}}class nb extends yp{constructor(e){super(e)}}class R extends yp{constructor(i,a){super(i);S(this,"auth");this.auth=a}}class cb extends R{async startConversation(e,i){return this.enqueueRequest({description:"Start agent conversation",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:i},blockers:["prompt"],blocks:["prompt"]}).then(a=>(this.dispatch(fc(a)),a))}async continueConversation(e,i,a){return this.enqueueRequest({description:"Prompt agent",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:a},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:i}}).then(n=>{this.dispatch(Tc(n))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:l.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(i=>{this.dispatch(Sc(i))})}async rate(e,i){return this.enqueueRequest({description:"Rate agent response",method:l.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:i},blockers:["rate"],blocks:["rate"]})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get agent conversation history",method:l.GET,url:"/agents/conversations/",queryParams:{project:e},blockers:["agent-conversations"],blocks:["agent-conversations"]},i);return this.dispatch(Ac(a)),a}}const V=1e3,He=200;class j extends R{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:i,assetAttachmentReducer:a,assetTypeAttachmentReducer:n,documentAttachmentReducer:c,projectAttachmentReducer:r,formRevisionAttachmentReducer:u,formSubmissionAttachmentReducer:m,geoImageReducer:o,assetTypeFieldsAttachmentReducer:h,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:y,issueTypeFieldValuesAttachmentReducer:A}=this.client.store.getState();return[].concat(Object.values(i.instances),Object.values(a.instances),Object.values(n.instances),Object.values(c.instances),Object.values(r.instances),Object.values(u.instances),Object.values(m.instances),Object.values(o.instances),Object.values(h.instances),Object.values(p.instances),Object.values(y.instances),Object.values(A.instances)).filter(F=>F.file_sha1===e).length}processPresignedUrls(e){const i={};for(const[a,n]of Object.entries(e))i[a]=this.enqueueRequest({url:n.url,description:"Upload file to S3",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:a,blockers:[`s3-${n.fields.key}`],blocks:[a],s3url:n});return i}async getFilePayload(e){const i=await Qe(e),a={sha1:i,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,i),a}}class We extends j{async _bulkAdd(e){var o;const{store:i}=this.client,a=(o=i.getState().userReducer.currentUser)==null?void 0:o.id,n=new Date().toISOString(),c=[],r=[],u={};for(const h of e){const{modelUuid:p,file:y}=h,A=await this.getFilePayload(y);A.sha1 in u||(u[A.sha1]=A);const I=this.buildOfflineAttachment({file:y,file_sha1:A.sha1,submitted_at:n,created_by:a,description:"",modelUuid:p});c.push(I),r.push(this.buildAttachmentPayload({uuid:I.uuid,file_name:I.file_name,file_sha1:I.file_sha1,file_extension:A.extension,description:I.description,modelUuid:p}))}this.dispatch(this.addAttachments(c));const m=this.enqueueRequest({description:`Add ${this.name}`,method:l.POST,url:`${this.url}/bulk/`,payload:{submitted_at:n,attachments:r,files:Object.values(u)},blocks:c.map(h=>h.uuid),blockers:c.map(h=>h.file_sha1)});return m.then(({attachments:h,presigned_urls:p})=>{this.dispatch(this.updateAttachments(h)),this.processPresignedUrls(p)}).catch(()=>{this.dispatch(this.removeAttachments(c.map(h=>h.uuid)))}),[c,m.then(({attachments:h})=>h)]}async _delete(e){const{store:i}=this.client,a=this.selectAttachment(e)(i.getState());if(!a)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(a.uuid));const n=this.enqueueRequest({description:`Delete ${this.name}`,method:l.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return n.then(()=>{this.getNumberOfAttachmentsWithSha1(a.file_sha1)===0&&this.client.files.removeCache(a.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(a))}),n}}class rb extends We{constructor(){super(...arguments);S(this,"name","Asset Attachment");S(this,"url","/asset-attachments");S(this,"initializeAttachments",ds);S(this,"addAttachments",us);S(this,"updateAttachments",Fc);S(this,"removeAttachments",os);S(this,"removeAttachment",Pc);S(this,"setAttachment",bc);S(this,"selectAttachment",Rc)}buildOfflineAttachment(i){return b({file:URL.createObjectURL(i.file),file_sha1:i.file_sha1,created_by:i.created_by,file_name:i.file.name,file_type:i.file.type,submitted_at:i.submitted_at,description:i.description,asset:i.modelUuid})}buildAttachmentPayload(i){return{...i,asset:i.modelUuid}}async bulkAdd(i){return this._bulkAdd(i.map(a=>({modelUuid:a.assetUuid,file:a.file})))}async delete(i){return this._delete(i)}async refreshStore(i,a){const c=(await this.performPagination({immediate:!0,description:"Get asset attachments",method:l.GET,url:`${this.url}/`,queryParams:{limit:He,paginate:!0,asset__project:i},blocks:[],blockers:[]},r=>({immediate:!0,description:"Get asset attachments",method:l.GET,url:r,blockers:[],blocks:[]}),a)).flat();return this.dispatch(ds(c)),c}}class db extends We{constructor(){super(...arguments);S(this,"name","Asset Procedure Attachment");S(this,"url","/asset-procedure-type-attachments");S(this,"addAttachments",Vc);S(this,"updateAttachments",qc);S(this,"removeAttachments",Uc);S(this,"removeAttachment",zc);S(this,"setAttachment",jc);S(this,"selectAttachment",Bc)}buildOfflineAttachment(i){return b({file:URL.createObjectURL(i.file),file_sha1:i.file_sha1,created_by:i.created_by,file_name:i.file.name,file_type:i.file.type,submitted_at:i.submitted_at,description:i.description,asset_procedure_type:i.modelUuid})}buildAttachmentPayload(i){return{...i,asset_procedure_type:i.modelUuid}}async bulkAdd(i){return this._bulkAdd(i.map(a=>({modelUuid:a.assetProcedureTypeUuid,file:a.file})))}async delete(i){return this._delete(i)}async refreshStore(i,a){const n=await this.enqueueRequest({immediate:!0,description:"Get asset procedure attachments",method:l.GET,url:`${this.url}/`,queryParams:{asset_procedure_type__organization:i},blocks:[],blockers:[]},a);return this.dispatch(Ec(n)),n}}class ub extends j{async bulkAdd(e){var m;const i=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,n={},c=[],r=[];for(const o of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:y}=o,A=await this.getFilePayload(y);A.sha1 in n||(n[A.sha1]=A);const I=b({file:URL.createObjectURL(y),file_type:y.type,file_name:y.name,file_sha1:A.sha1,created_by:a,fields_revision:h,submitted_at:i,field_identifier:p});c.push(I);const F={uuid:I.uuid,file_name:y.name,field_identifier:p,file_extension:A.extension,file_sha1:A.sha1,fields_revision:h};r.push(F)}this.dispatch(Lc(c));const u=this.enqueueRequest({description:"Add asset procedure type fields attachments",method:l.POST,url:"/asset-procedure-type-fields-attachments/bulk/",payload:{submitted_at:i,attachments:r,files:Object.values(n)},blockers:c.map(o=>o.fields_revision),blocks:c.map(o=>o.uuid)});return u.then(o=>{this.processPresignedUrls(o.presigned_urls),this.dispatch(Nc(o.attachments))}).catch(()=>{this.dispatch(Hc(c.map(o=>o.uuid)))}),[c,u.then(({attachments:o})=>o)]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset procedure type fields attachments",method:l.GET,url:"/asset-procedure-type-fields-attachments/",queryParams:{fields_revision__asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Gc(a)),a}}class ob extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Xc(c));const r=this.enqueueRequest({description:"Add Asset Procedure Type Fields",method:l.POST,url:"/asset-procedure-type-fields/",payload:v(c),blockers:[c.asset_procedure_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Qc(m))}).catch(m=>{throw this.dispatch(xc(c.uuid)),m}),[c,r]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get Asset Procedure Type Fields",method:l.GET,url:"/asset-procedure-type-fields/",queryParams:{asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Jc(a)),a}}function Ye(t,e){const i=[];let a=0;const n=t.length;for(;a<n;)i.push(t.slice(a,a+=e));return i}class lb extends j{async bulkAdd(e,i){var o;const a=new Date().toISOString(),n=(o=this.client.store.getState().userReducer.currentUser)==null?void 0:o.id,c=Ye(e,i??e.length),r=[],u=[];for(const h of c){const p={},y=[];for(const A of h){const{fieldValuesUuid:I,fieldIdentifier:F,file:_}=A,w=await this.getFilePayload(_);w.sha1 in p||(p[w.sha1]=w);const z=b({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:w.sha1,created_by:n,field_values:I,submitted_at:a,field_identifier:F});r.push(z);const Le={uuid:z.uuid,file_name:_.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:F,field_values:I};y.push(Le)}u.push({submitted_at:a,attachments:y,files:Object.values(p)})}this.dispatch(_t(r));const m=u.map(h=>this.enqueueRequest({description:"Add asset procedure type field values attachments",method:l.POST,url:"/asset-procedure-type-field-values-attachments/bulk/",payload:h,blockers:h.attachments.map(p=>p.field_values),blocks:h.attachments.map(p=>p.uuid)}));return Promise.all(m).then(h=>{for(const y of h)this.processPresignedUrls(y.presigned_urls);const p=h.flatMap(y=>y.attachments);this.dispatch(ar(p))}).catch(h=>{throw this.dispatch(Rt(r.map(p=>p.uuid))),h}),[r,m.map(h=>h.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:i}=this.client,a=i.getState(),n=rr(e)(a);this.dispatch(Rt(e));try{await this.enqueueRequest({description:"Delete asset procedure type field values attachments",method:l.DELETE,url:"/asset-procedure-type-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(_t(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedure type field values attachments",method:l.GET,url:"/asset-procedure-type-field-values-attachments/",queryParams:{limit:He,paginate:!0,field_values__asset_procedure__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedure type field values attachments",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(ir(n)),n}}class hb extends R{add(e){var r;const{store:i}=this.client,a=i.getState(),n=b({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset procedure type field values",method:l.POST,url:"/asset-procedure-type-field-values/",payload:v(n),blockers:[e.asset,e.fields_revision,e.asset_procedure],blocks:[n.uuid]});return this.dispatch(Ss(n)),c.then(u=>(this.dispatch(at(u)),u)).catch(()=>{this.dispatch(Ts(n.uuid))}),[n,c]}bulkAdd(e,i){var m;const a=new Date().toISOString(),n=[],c=Ye(e.payloads,i??e.payloads.length),r=[];for(const o of c){const h=[];for(const p of o){const y=b({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:a});n.push(y),h.push({uuid:y.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure:p.asset_procedure,published_at:p.published_at,values:y.values})}r.push({submitted_at:a,values:e.values,field_values:h})}this.dispatch(lr(n));const u=[];for(const o of r){const h=o.field_values.map(F=>F.asset),p=o.field_values.map(F=>F.fields_revision),y=o.field_values.map(F=>F.asset_procedure),A=o.field_values.map(F=>F.uuid),I=this.enqueueRequest({description:"Bulk add asset procedure type field values",method:l.POST,url:"/asset-procedure-type-field-values/bulk/",payload:o,blockers:[...h,...p,...y],blocks:A});u.push(I)}return Promise.all(u).then(o=>{this.dispatch(hr(o.flat()))}).catch(()=>{this.dispatch(mr(n.map(o=>o.uuid)))}),[n,u]}update(e){const{store:i}=this.client,a=i.getState(),n=gs(e.uuid)(a);if(!n)throw new Error(`Expected AssetProcedureTypeFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(at(c));const r=this.enqueueRequest({description:"Update asset procedure type field values",method:l.PATCH,url:`/asset-procedure-type-field-values/${e.uuid}/`,payload:e,blockers:[c.fields_revision,c.asset,c.asset_procedure],blocks:[c.uuid]});return r.then(u=>{this.dispatch(at(u))}).catch(()=>{this.dispatch(at(n))}),[c,r]}async delete(e){const{store:i}=this.client,a=i.getState(),n=gs(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=dr(e)(a);this.dispatch(Ts(e)),this.dispatch(Rt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure type field values",method:l.DELETE,url:`/asset-procedure-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Ss(n)),this.dispatch(_t(c)),r}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedure type field values",method:l.GET,url:"/asset-procedure-type-field-values/",queryParams:{limit:V,paginate:!0,asset_procedure__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedure type field values",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(or(n)),n}}class mb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Fs(c));const r=this.enqueueRequest({description:"Create asset procedure",method:l.POST,url:"/asset-procedures/",payload:v(c),blockers:[e.asset_procedure_type,e.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(nt(m))}).catch(()=>{this.dispatch(Ps(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Rs(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(nt(n));const c=this.enqueueRequest({description:"Update asset procedure",method:l.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(nt(r))}).catch(()=>{this.dispatch(nt(a))}),[n,c]}async remove(e){const{store:i}=this.client,a=i.getState(),n=Rs(e)(a);if(!n)throw new Error(`Expected asset procedure with uuid ${e} to exist`);return this.dispatch(Ps(e)),this.enqueueRequest({description:"Delete asset procedure",method:l.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(Fs(n)),c})}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedures",method:l.GET,url:"/asset-procedures/",queryParams:{limit:V,paginate:!0,project:e},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedures",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(fr(n)),n}}class pb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ws(c));const r=this.enqueueRequest({description:"Create asset procedure type",method:l.POST,url:"/asset-procedure-types/",payload:v(c),blockers:[],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ct(m))}).catch(()=>{this.dispatch(Ms(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Vs(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset procedure type with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(ct(n));const c=this.enqueueRequest({description:"Update asset procedure type",method:l.PATCH,url:`/asset-procedure-types/${e.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(ct(r))}).catch(()=>{this.dispatch(ct(a))}),[n,c]}async remove(e){const{store:i}=this.client,a=i.getState(),n=Vs(e)(a);if(!n)throw new Error(`Expected asset procedure type with uuid ${e} to exist`);const c=gr(e)(a);return this.dispatch(Ms(e)),this.dispatch(Tr(c.map(({uuid:r})=>r))),this.enqueueRequest({description:"Delete asset procedure type",method:l.DELETE,url:`/asset-procedure-types/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(ws(n)),this.dispatch(Sr(c)),r})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset procedure types",method:l.GET,url:"/asset-procedure-types/",queryParams:{organization:e},blockers:[],blocks:[]},i);return this.dispatch(Fr(a)),a}}class yb extends j{async bulkAdd(e){var m;const i=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,n={},c=[],r=[];for(const o of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:y}=o,A=await this.getFilePayload(y);A.sha1 in n||(n[A.sha1]=A);const I=b({file:URL.createObjectURL(y),file_type:y.type,file_name:y.name,file_sha1:A.sha1,created_by:a,fields_revision:h,submitted_at:i,field_identifier:p});c.push(I);const F={uuid:I.uuid,file_name:y.name,field_identifier:p,file_extension:A.extension,file_sha1:A.sha1,fields_revision:h};r.push(F)}this.dispatch(vr(c));const u=this.enqueueRequest({description:"Add asset procedure step fields attachments",method:l.POST,url:"/asset-procedure-step-fields-attachments/bulk/",payload:{submitted_at:i,attachments:r,files:Object.values(n)},blockers:c.map(o=>o.fields_revision),blocks:c.map(o=>o.uuid)});return u.then(o=>{this.processPresignedUrls(o.presigned_urls),this.dispatch(wr(o.attachments))}).catch(()=>{this.dispatch(Mr(c.map(o=>o.uuid)))}),[c,u.then(({attachments:o})=>o)]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset procedure step fields attachments",method:l.GET,url:"/asset-procedure-step-fields-attachments/",queryParams:{fields_revision__asset_procedure_step__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Rr(a)),a}}class Ab extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(zs(c));const r=this.enqueueRequest({description:"Add Asset Procedure Step Fields",method:l.POST,url:"/asset-procedure-step-fields/",payload:v(c),blockers:[c.asset_procedure_step],blocks:[c.uuid]});return r.then(m=>{this.dispatch(rt(m))}).catch(m=>{throw this.dispatch(Us(c.uuid)),m}),[c,r]}update(e){const{store:i}=this.client,a=i.getState().assetProcedureStepFieldsReducer.instances[e.uuid];if(!a)throw new Error(`AssetProcedureStepFields with uuid ${e.uuid} not found`);const n={...a,...e};this.dispatch(rt(n));const c=this.enqueueRequest({description:"Update Asset Procedure Step Fields",method:l.PATCH,url:`/asset-procedure-step-fields/${a.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(rt(r))}).catch(r=>{throw this.dispatch(rt(a)),r}),[n,c]}delete(e){const{store:i}=this.client,a=i.getState().assetProcedureStepFieldsReducer.instances[e];if(!a)throw new Error(`AssetProcedureStepFields with uuid ${e} not found`);this.dispatch(Us(e));const n=this.enqueueRequest({description:"Delete Asset Procedure Step Fields",method:l.DELETE,url:`/asset-procedure-step-fields/${e}/`,blockers:[e],blocks:[e]});return n.catch(c=>{throw this.dispatch(zs(a)),c}),n}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get Asset Procedure Step Fields",method:l.GET,url:"/asset-procedure-step-fields/",queryParams:{asset_procedure_step__asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(zr(a)),a}}class fb extends j{async bulkAdd(e,i){var o;const a=new Date().toISOString(),n=(o=this.client.store.getState().userReducer.currentUser)==null?void 0:o.id,c=Ye(e,i??e.length),r=[],u=[];for(const h of c){const p={},y=[];for(const A of h){const{fieldValuesUuid:I,fieldIdentifier:F,file:_}=A,w=await this.getFilePayload(_);w.sha1 in p||(p[w.sha1]=w);const z=b({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:w.sha1,created_by:n,field_values:I,submitted_at:a,field_identifier:F});r.push(z);const Le={uuid:z.uuid,file_name:_.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:F,field_values:I};y.push(Le)}u.push({submitted_at:a,attachments:y,files:Object.values(p)})}this.dispatch(vt(r));const m=u.map(h=>this.enqueueRequest({description:"Add asset procedure step field values attachments",method:l.POST,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:h,blockers:h.attachments.map(p=>p.field_values),blocks:h.attachments.map(p=>p.uuid)}));return Promise.all(m).then(h=>{for(const y of h)this.processPresignedUrls(y.presigned_urls);const p=h.flatMap(y=>y.attachments);this.dispatch(kr(p))}).catch(h=>{throw this.dispatch(wt(r.map(p=>p.uuid))),h}),[r,m.map(h=>h.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:i}=this.client,a=i.getState(),n=$r(e)(a);this.dispatch(wt(e));try{await this.enqueueRequest({description:"Delete asset procedure step field values attachments",method:l.DELETE,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(vt(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedure step field values attachments",method:l.GET,url:"/asset-procedure-step-field-values-attachments/",queryParams:{limit:He,paginate:!0,field_values__asset_procedure__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedure step field values attachments",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Cr(n)),n}}class Sb extends R{add(e){var r;const{store:i}=this.client,a=i.getState(),n=b({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset procedure step field values",method:l.POST,url:"/asset-procedure-step-field-values/",payload:v(n),blockers:[e.asset,e.fields_revision,e.asset_procedure],blocks:[n.uuid]});return this.dispatch(Gs(n)),c.then(u=>(this.dispatch(dt(u)),u)).catch(()=>{this.dispatch(Ls(n.uuid))}),[n,c]}bulkAdd(e,i){var m;const a=new Date().toISOString(),n=[],c=Ye(e.payloads,i??e.payloads.length),r=[];for(const o of c){const h=[];for(const p of o){const y=b({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:a});n.push(y),h.push({uuid:y.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure:p.asset_procedure,asset_procedure_step:p.asset_procedure_step,published_at:p.published_at,values:y.values})}r.push({submitted_at:a,values:e.values,field_values:h})}this.dispatch(Wr(n));const u=[];for(const o of r){const h=o.field_values.map(F=>F.asset),p=o.field_values.map(F=>F.fields_revision),y=o.field_values.map(F=>F.asset_procedure),A=o.field_values.map(F=>F.uuid),I=this.enqueueRequest({description:"Bulk add asset procedure step field values",method:l.POST,url:"/asset-procedure-step-field-values/bulk/",payload:o,blockers:[...h,...p,...y],blocks:A});u.push(I)}return Promise.all(u).then(o=>{this.dispatch(Kr(o.flat()))}).catch(()=>{this.dispatch(Yr(n.map(o=>o.uuid)))}),[n,u]}update(e){const{store:i}=this.client,a=i.getState(),n=Ns(e.uuid)(a);if(!n)throw new Error(`Expected AssetProcedureStepFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(dt(c));const r=this.enqueueRequest({description:"Update asset procedure step field values",method:l.PATCH,url:`/asset-procedure-step-field-values/${e.uuid}/`,payload:e,blockers:[c.fields_revision,c.asset,c.asset_procedure],blocks:[c.uuid]});return r.then(u=>{this.dispatch(dt(u))}).catch(()=>{this.dispatch(dt(n))}),[c,r]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Ns(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Gr(e)(a);this.dispatch(Ls(e)),this.dispatch(wt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure step field values",method:l.DELETE,url:`/asset-procedure-step-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Gs(n)),this.dispatch(vt(c)),r}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset procedure step field values",method:l.GET,url:"/asset-procedure-step-field-values/",queryParams:{limit:V,paginate:!0,asset_procedure__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset procedure step field values",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Hr(n)),n}}class Tb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Ws(c));const r=this.enqueueRequest({description:"Create asset procedure step",method:l.POST,url:"/asset-procedure-steps/",payload:v(c),blockers:[c.asset_procedure_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Et(m))}).catch(()=>{this.dispatch(Ks(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Ys(e.uuid)(i.getState());if(!a)throw new Error(`No asset procedure step with uuid ${e.uuid} found in the store`);const n={...a,...e};this.dispatch(Et(n));const c=this.enqueueRequest({description:"Update asset procedure step",method:l.PATCH,url:`/asset-procedure-steps/${a.uuid}/`,payload:{name:e.name,description:e.description,priority:e.order,color:e.color},blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(Et(r))}).catch(()=>{this.dispatch(xr(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Ys(e)(a);if(!n)throw new Error(`No asset procedure step with uuid ${e} found in the store`);return this.dispatch(Ks(e)),this.enqueueRequest({description:"Delete asset stage",method:l.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(Ws(n)),c})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset procedure steps",method:l.GET,url:"/asset-procedure-steps/",queryParams:{asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Qr(a)),a}}class Ib extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Js(c));const r=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/assets/",payload:v(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ut(m))}).catch(()=>{this.dispatch(Xs(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=ti(e.uuid)(i.getState());if(!a)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const n={...a,...e};this.dispatch(ut(n));const c=this.enqueueRequest({description:"Edit asset",method:l.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(ut(r))}).catch(()=>{this.dispatch(ut(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=ti(e)(a);if(!n)throw new Error(`No asset with uuid ${e} found in the store`);const c=vc(e)(a),r=cl(e)(a);if(this.dispatch(Xs(e)),c.length>0){const u=c.map(({uuid:m})=>m);this.dispatch(os(u))}if(r.length>0){const u=r.map(({uuid:m})=>m);this.dispatch(_a(u))}return this.enqueueRequest({description:"Delete asset",method:l.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(u=>{throw this.dispatch(Js(n)),this.dispatch(us(c)),this.dispatch(Pa(r)),u})}bulkAdd(e,i,a,n){const c=new Date().toISOString(),r=Xe.v4(),u=Ye(e,n).map(h=>{const p=h.map(y=>b(y));return{batchId:Xe.v4(),payload:{transaction_id:r,submitted_at:c,asset_type:i,project:a,assets:p}}}),m=[];let o=null;for(const h of u){const{batchId:p,payload:y}=h,A=y.assets.map(w=>w.uuid),I=[i];o&&I.push(o);const F=A;F.push(p);const _=this.enqueueRequest({description:"Batch create assets",method:l.POST,url:"/assets/bulk/",payload:y,blockers:I,blocks:F});o=h.batchId,m.push(_)}return Promise.all(m).then(h=>{const p=h.flat();this.dispatch(jt(p))}),m}async bulkDelete(e){const{store:i}=this.client,a=i.getState(),n=nd(e)(a);this.dispatch(Qs(e));try{await this.enqueueRequest({description:"Bulk delete assets",method:l.DELETE,url:"/assets/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(jt(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get assets",method:l.GET,url:"/assets/",queryParams:{limit:V,paginate:!0,project:e},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get assets",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(id(n)),n}}class gb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ii(c));const r=this.enqueueRequest({description:"Add asset stage completion",method:l.POST,url:"/asset-stage-completions/",payload:v(c),blockers:[e.asset,e.asset_stage],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ud(m))}).catch(()=>{this.dispatch(ni(c.uuid))}),[c,r]}delete(e){const{store:i}=this.client,a=hd(e)(i.getState());if(!a)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(ni(e));const n=this.enqueueRequest({description:"Delete asset stage completion",method:l.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return n.catch(()=>{this.dispatch(ii(a))}),n}bulkAdd(e){var o;const{store:i}=this.client,a=new Date().toISOString(),n=(o=i.getState().userReducer.currentUser)==null?void 0:o.id,c=e.map(h=>b(h)),r=c.map(h=>({...h,created_by:n,submitted_at:a})),u=r.map(({uuid:h})=>h);this.dispatch(ai(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:l.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:a,completions:c},blockers:[...e.map(h=>h.asset_procedure),...e.map(h=>h.asset_stage),...e.map(h=>h.asset)],blocks:u});return m.then(h=>{this.dispatch(od(h))}).catch(()=>{this.dispatch(ci(u))}),[r,m]}bulkDelete(e){const{store:i}=this.client,a=md(e)(i.getState());this.dispatch(ci(e));const n=this.enqueueRequest({description:"Deleting asset stage completions",method:l.DELETE,url:"/asset-stage-completions/bulk/",payload:{uuids:e},blockers:e,blocks:[]});return n.catch(()=>{this.dispatch(ai(a))}),n}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset stage completions",method:l.GET,url:"/asset-stage-completions/",queryParams:{limit:V,paginate:!0,asset_procedure__project:e},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset stage completions",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(dd(n)),n}}class bb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ui(c));const r=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/asset-stages/",payload:v(c),blockers:[c.asset_procedure_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(qt(m))}).catch(()=>{this.dispatch(oi(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=li(e.uuid)(i.getState());if(!a)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const n={...a,...e};this.dispatch(qt(n));const c=this.enqueueRequest({description:"Update asset stage",method:l.PATCH,url:`/asset-stages/${a.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(qt(r))}).catch(()=>{this.dispatch(Ad(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=li(e)(a);if(!n)throw new Error(`No asset stage with uuid ${e} found in the store`);return this.dispatch(oi(e)),this.enqueueRequest({description:"Delete asset stage",method:l.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(ui(n)),c})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset stages",method:l.GET,url:"/asset-stages/",queryParams:{asset_procedure_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(yd(a)),a}}class Fb extends We{constructor(){super(...arguments);S(this,"name","Asset Type Attachment");S(this,"url","/asset-type-attachments");S(this,"addAttachments",mi);S(this,"updateAttachments",bd);S(this,"removeAttachments",pi);S(this,"removeAttachment",Fd);S(this,"setAttachment",gd);S(this,"selectAttachment",_d)}buildOfflineAttachment(i){return b({file:URL.createObjectURL(i.file),file_sha1:i.file_sha1,created_by:i.created_by,file_name:i.file.name,file_type:i.file.type,submitted_at:i.submitted_at,description:i.description,asset_type:i.modelUuid})}buildAttachmentPayload(i){return{...i,asset_type:i.modelUuid}}async bulkAdd(i){return this._bulkAdd(i.map(a=>({modelUuid:a.assetTypeUuid,file:a.file})))}async delete(i){return this._delete(i)}async refreshStore(i,a){const n=await this.enqueueRequest({immediate:!0,description:"Get asset type attachments",method:l.GET,url:`${this.url}/`,queryParams:{asset_type__organization:i},blocks:[],blockers:[]},a);return this.dispatch(Id(n)),n}}class Pb extends j{async bulkAdd(e){var m;const i=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,n={},c=[],r=[];for(const o of e){const{fieldsRevisionUuid:h,fieldIdentifier:p,file:y}=o,A=await this.getFilePayload(y);A.sha1 in n||(n[A.sha1]=A);const I=b({file:URL.createObjectURL(y),file_type:y.type,file_name:y.name,file_sha1:A.sha1,created_by:a,fields_revision:h,submitted_at:i,field_identifier:p});c.push(I);const F={uuid:I.uuid,file_name:y.name,field_identifier:p,file_extension:A.extension,file_sha1:A.sha1,fields_revision:h};r.push(F)}this.dispatch(Ed(c));const u=this.enqueueRequest({description:"Add asset type fields attachments",method:l.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:i,attachments:r,files:Object.values(n)},blockers:c.map(o=>o.fields_revision),blocks:c.map(o=>o.uuid)});return u.then(o=>{this.processPresignedUrls(o.presigned_urls),this.dispatch(Vd(o.attachments))}).catch(()=>{this.dispatch(jd(c.map(o=>o.uuid)))}),[c,u.then(({attachments:o})=>o)]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset type fields attachments",method:l.GET,url:"/asset-type-fields-attachments/",queryParams:{fields_revision__asset_type__organization:e},blockers:[e],blocks:[]},i);return this.dispatch(Md(a)),a}}class Ob extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(kd(c));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:l.POST,url:"/asset-type-fields/",payload:v(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Bd(m))}).catch(m=>{throw this.dispatch($d(c.uuid)),m}),[c,r]}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get Asset Type Fields",method:l.GET,url:"/asset-type-fields/",queryParams:{asset_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(Cd(a)),a}}class _b extends j{async bulkAdd(e,i){var o;const a=new Date().toISOString(),n=(o=this.client.store.getState().userReducer.currentUser)==null?void 0:o.id,c=Ye(e,i??e.length),r=[],u=[];for(const h of c){const p={},y=[];for(const A of h){const{fieldValuesUuid:I,fieldIdentifier:F,file:_}=A,w=await this.getFilePayload(_);w.sha1 in p||(p[w.sha1]=w);const z=b({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:w.sha1,created_by:n,field_values:I,submitted_at:a,field_identifier:F});r.push(z);const Le={uuid:z.uuid,file_name:_.name,file_sha1:w.sha1,file_extension:w.extension,field_identifier:F,field_values:I};y.push(Le)}u.push({submitted_at:a,attachments:y,files:Object.values(p)})}this.dispatch(Dt(r));const m=u.map(h=>this.enqueueRequest({description:"Add asset type field values attachments",method:l.POST,url:"/asset-type-field-values-attachments/bulk/",payload:h,blockers:h.attachments.map(p=>p.field_values),blocks:h.attachments.map(p=>p.uuid)}));return Promise.all(m).then(h=>{for(const y of h)this.processPresignedUrls(y.presigned_urls);const p=h.flatMap(y=>y.attachments);this.dispatch(Wd(p))}).catch(h=>{throw this.dispatch(Ct(r.map(p=>p.uuid))),h}),[r,m.map(h=>h.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:i}=this.client,a=i.getState(),n=Yd(e)(a);this.dispatch(Ct(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:l.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(Dt(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset type field values attachments",method:l.GET,url:"/asset-type-field-values-attachments/",queryParams:{limit:He,paginate:!0,field_values__asset__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset type field values attachments",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Hd(n)),n}}class Rb extends R{add(e){var r;const{store:i}=this.client,a=i.getState(),n=b({...e,created_by:(r=a.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset type field values",method:l.POST,url:"/asset-type-field-values/",payload:v(n),blockers:[e.asset,e.fields_revision],blocks:[n.uuid]});return this.dispatch(Ii(n)),c.then(u=>(this.dispatch(ot(u)),u)).catch(()=>{this.dispatch(gi(n.uuid))}),[n,c]}bulkAdd(e,i){var m;const a=new Date().toISOString(),n=[],c=Ye(e.payloads,i??e.payloads.length),r=[];for(const o of c){const h=[];for(const p of o){const y=b({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:a});n.push(y),h.push({uuid:y.uuid,asset:p.asset,fields_revision:p.fields_revision,published_at:p.published_at,values:y.values})}r.push({submitted_at:a,values:e.values,field_values:h})}this.dispatch(xd(n));const u=[];for(const o of r){const h=o.field_values.map(I=>I.asset),p=o.field_values.map(I=>I.fields_revision),y=o.field_values.map(I=>I.uuid),A=this.enqueueRequest({description:"Bulk add asset type field values",method:l.POST,url:"/asset-type-field-values/bulk/",payload:o,blockers:[...h,...p],blocks:y});u.push(A)}return Promise.all(u).then(o=>{this.dispatch(eu(o.flat()))}).catch(()=>{this.dispatch(tu(n.map(o=>o.uuid)))}),[n,u]}update(e){const{store:i}=this.client,a=i.getState(),n=Fi(e.uuid)(a);if(!n)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const c={...n,...e};this.dispatch(ot(c));const r=this.enqueueRequest({description:"Delete asset type field values",method:l.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.asset],blocks:[c.uuid]});return r.then(u=>{this.dispatch(ot(u))}).catch(()=>{this.dispatch(ot(n))}),[c,r]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Fi(e)(a);if(!n)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Zd(e)(a);this.dispatch(gi(e)),this.dispatch(Ct(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:l.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Ii(n)),this.dispatch(Dt(c)),r}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset type field values",method:l.GET,url:"/asset-type-field-values/",queryParams:{limit:V,paginate:!0,asset__project:e,latest:!0},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset type field values",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Qd(n)),n}}class vb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(Oi(c));const r=this.enqueueRequest({description:"Create asset type identifier",method:l.POST,url:"/asset-type-identifiers/",payload:v(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(lt(m))}).catch(()=>{this.dispatch(_i(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Ri(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset type identifier with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(lt(n));const c=this.enqueueRequest({description:"Update asset type identifier",method:l.PATCH,url:`/asset-type-identifiers/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(lt(r))}).catch(()=>{this.dispatch(lt(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Ri(e)(a);if(!n)throw new Error(`Expected asset type identifier with uuid ${e} to exist`);this.dispatch(_i(e));try{return await this.enqueueRequest({description:"Delete asset type identifier",method:l.DELETE,url:`/asset-type-identifiers/${e}/`,blockers:[e],blocks:[]})}catch(c){throw this.dispatch(Oi(n)),c}}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset type identifiers",method:l.GET,url:"/asset-type-identifiers/",queryParams:{asset_type__organization:e},blockers:[],blocks:[]},i);return this.dispatch(nu(a)),a}}class wb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(wi(c));const r=this.enqueueRequest({description:"Create asset type identifier value",method:l.POST,url:"/asset-type-identifier-values/",payload:v(c),blockers:[e.asset,e.asset_type_identifier],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ht(m))}).catch(()=>{this.dispatch(Mi(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Vi(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset type identifier value with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(ht(n));const c=this.enqueueRequest({description:"Update asset type identifier value",method:l.PATCH,url:`/asset-type-identifier-values/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(ht(r))}).catch(()=>{this.dispatch(ht(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Vi(e)(a);if(!n)throw new Error(`Expected asset type identifier value with uuid ${e} to exist`);this.dispatch(Mi(e));try{return await this.enqueueRequest({description:"Delete asset type identifier value",method:l.DELETE,url:`/asset-type-identifier-values/${e}/`,blockers:[e],blocks:[]})}catch(c){throw this.dispatch(wi(n)),c}}async refreshStore(e,i){const n=(await this.performPagination({immediate:!0,description:"Get asset type identifier values",method:l.GET,url:"/asset-type-identifier-values/",queryParams:{limit:V,paginate:!0,asset__project:e},blockers:[],blocks:[]},c=>({immediate:!0,description:"Get asset type identifier values",method:l.GET,url:c,blockers:[],blocks:[]}),i)).flat();return this.dispatch(ou(n)),n}}class Mb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(qi(c));const r=this.enqueueRequest({description:"Create asset type",method:l.POST,url:"/asset-types/",payload:v(c),blockers:[],blocks:[c.uuid]});return r.then(m=>{this.dispatch(mt(m))}).catch(()=>{this.dispatch(zi(c.uuid))}),[c,r]}update(e){const{store:i}=this.client,a=Di(e.uuid)(i.getState());if(!a)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const n={...a,...e};this.dispatch(mt(n));const c=this.enqueueRequest({description:"Update asset type",method:l.PATCH,url:`/asset-types/${e.uuid}/`,payload:e,blockers:[a.uuid],blocks:[a.uuid]});return c.then(r=>{this.dispatch(mt(r))}).catch(()=>{this.dispatch(mt(a))}),[n,c]}async delete(e){const{store:i}=this.client,a=i.getState(),n=Di(e)(a);if(!n)throw new Error(`Expected asset type with uuid ${e} to exist`);const c=ei(e)(a),r=Rd(e)(a);return this.dispatch(zi(e)),this.dispatch(Qs(c.map(u=>u.uuid))),this.dispatch(pi(r.map(({uuid:u})=>u))),this.enqueueRequest({description:"Delete asset type",method:l.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(u=>{throw this.dispatch(qi(n)),this.dispatch(jt(c)),this.dispatch(mi(r)),u})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get asset types",method:l.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]},i);return this.dispatch(pu(a)),a}}class Eb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ki(c));const r=this.enqueueRequest({description:"Create Category",method:l.POST,url:"/categories/",payload:v(c),blockers:[e.project],blocks:[c.uuid]});return[c,r]}update(e){const i=this.client.store.getState(),a=$i(e.uuid)(i);if(!a)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const n={...a,...e};this.dispatch(bu(n));const c=this.enqueueRequest({description:"Edit Category",method:l.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[n,c]}remove(e){const{store:i}=this.client,a=$i(e)(i.getState());if(!a)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(Fu(e));const n=this.enqueueRequest({description:"Delete Category",method:l.DELETE,url:`/categories/${a.uuid}/`,blockers:[a.uuid],blocks:[]});return n.catch(()=>{this.dispatch(ki(a))}),n}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Get categories",method:l.GET,url:"/categories/",queryParams:{project__organization:e},blocks:[],blockers:[]},i);return this.dispatch(gu(a)),a}}class Vb extends We{constructor(){super(...arguments);S(this,"name","Document Attachment");S(this,"url","/document-attachments");S(this,"addAttachments",vu);S(this,"updateAttachments",Mu);S(this,"removeAttachments",Vu);S(this,"removeAttachment",Eu);S(this,"setAttachment",wu);S(this,"selectAttachment",zu)}buildOfflineAttachment(i){return b({file:URL.createObjectURL(i.file),file_sha1:i.file_sha1,created_by:i.created_by,file_name:i.file.name,file_type:i.file.type,submitted_at:i.submitted_at,description:i.description,document:i.modelUuid})}buildAttachmentPayload(i){return{...i,document:i.modelUuid}}async bulkAdd(i){var p;const{store:a}=this.client,n=(p=a.getState().userReducer.currentUser)==null?void 0:p.id,c=new Date().toISOString(),r=[],u=[],m={},o={};for(const y of i){const{documentUuid:A,file:I}=y,F=await this.getFilePayload(I);F.sha1 in m||(m[F.sha1]=F,o[F.sha1]=[]);const _=this.buildOfflineAttachment({file:I,file_sha1:F.sha1,submitted_at:c,created_by:n,description:"",modelUuid:A});r.push(_),u.push({uuid:_.uuid,file_name:_.file_name,file_sha1:_.file_sha1,file_extension:F.extension,description:_.description,document:A}),o[F.sha1].push(_.uuid)}this.dispatch(this.addAttachments(r));const h=this.enqueueRequest({description:"Attach files to document",method:l.POST,url:"/document-attachments/bulk/",payload:{submitted_at:c,attachments:u,files:Object.values(m)},blocks:r.map(y=>y.uuid),blockers:r.map(y=>y.file_sha1)});return h.then(({attachments:y,presigned_urls:A})=>{this.dispatch(this.updateAttachments(y));const I=this.processPresignedUrls(A);for(const[F,_]of Object.entries(I))_.then(()=>{const w=o[F];for(const z of w)this.makeReadable(z)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(y=>y.uuid)))}),[r,h.then(({attachments:y})=>y)]}async delete(i){return this._delete(i)}makeReadable(i){this.enqueueRequest({description:"Add attachment to AI assistant",method:l.PATCH,url:`/document-attachments/${i}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",i],blocks:["index-document-attachment"]})}async refreshStore(i,a){const n=await this.enqueueRequest({immediate:!0,description:"Get document attachments",method:l.GET,url:"/document-attachments/",queryParams:{document__project__organization:i},blocks:[],blockers:[]},a),c=await this.enqueueRequest({immediate:!0,description:"Get document attachments",method:l.GET,url:"/document-attachments/",queryParams:{document__organization:i},blocks:[],blockers:[]},a),r=[...n,...c];return this.dispatch(Ru(r)),r}}class jb extends R{add(e){var u;const{store:i}=this.client,a=(u=i.getState().userReducer.currentUser)==null?void 0:u.id,n=new Date().toISOString(),c=b({...e,created_by:a,submitted_at:n});this.dispatch(ku([c]));const r=this.enqueueRequest({description:"Create Document",method:l.POST,url:"/documents/",payload:v(c),queryParams:{parent_document:c.parent_document??void 0},blockers:c.parent_document?[c.parent_document]:[],blocks:[c.uuid]});return r.catch(()=>{this.dispatch(Ni([c.uuid]))}),[c,r]}update(e){const{store:i}=this.client,a=i.getState().documentsReducer.documents[e.uuid];if(!a)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const n={...a,...e};this.dispatch(xe([n]));const c=this.enqueueRequest({description:"Update Document",method:l.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{xe([a])}),[n,c]}delete(e){const{store:i}=this.client,a=Bt(i.getState()),n=Bu(e)(i.getState());if(!n)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const c=n.parent_document?a[n.parent_document]:void 0;this.dispatch(Ni([e]));const r=this.enqueueRequest({description:"Delete Document",method:l.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(u=>{this.dispatch(xe(u))}).catch(()=>{this.dispatch(xe([n])),c&&this.dispatch(xe([c]))}),r}async refreshStore(e,i){const a=this.enqueueRequest({immediate:!0,description:"Get project documents",method:l.GET,url:"/documents/",queryParams:{project__organization:e},blockers:[],blocks:[]},i),n=this.enqueueRequest({immediate:!0,description:"Get organization documents",method:l.GET,url:"/documents/",queryParams:{organization:e},blockers:[],blocks:[]},i),c=[...await a,...await n];return this.dispatch(Cu(c)),c}}class qb extends R{async add(e,i){return this.enqueueRequest({description:"Add email domain to organization",method:l.POST,url:"/organization-email-domains/",payload:{email:i,organization:e},blockers:[e,"create-org"],blocks:[]})}async remove(e){return this.dispatch(Hu(e.uuid)),this.enqueueRequest({description:"Remove email domain from organization",method:l.DELETE,url:`/organization-email-domains/${e.uuid}/`,blockers:[e.domain],blocks:[]}).catch(i=>{throw this.dispatch(Nu(e)),i})}async refreshStore(e,i){const a=await this.enqueueRequest({immediate:!0,description:"Fetch email domains for organization",method:l.GET,url:"/organization-email-domains/",queryParams:{organization:e},blockers:[e],blocks:[]},i);return this.dispatch(Lu(a)),a}}class zb extends R{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:l.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,i=void 0){return this.enqueueRequest({description:"Validate verification code",method:l.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:i,blockers:[],blocks:[]})}}const Xt={},Jn=new Set;let Qt=0,Xn=0,Qn=0;const Ub=20;class Db extends R{constructor(){super(...arguments);S(this,"host");S(this,"_dbPromise",Bp.openDB("fileCache",1,{upgrade(i){i.createObjectStore("files")}}))}async renewUploadUrl(i){const a=await this.fetchCache(i);if(!a)throw new Error(`File with sha1 ${i} not found in cache`);const n=await as(a,i),c=await this.enqueueRequest({description:"Get S3 URL",method:l.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await Qe(a),file_type:a.type,extension:a.name.split(".").pop(),size:a.size.toString()},blockers:[],blocks:[`s3-${n}`]});return"url"in c&&this.dispatch(Xu({sha1:i,...c})),c}async addCache(i,a){if(Jn.has(a))return;if(!i.type){const r=i.name.split("."),u=r[r.length-1];i=new File([i],i.name,{type:u})}if(!i.name||!i.size||!i.type)throw new Error("Cannot add files to cache that do not have a name, size and type.");const n=await this._dbPromise;!!await n.get("files",a)?(console.error("File already cached (this is unexpected at this point):",i.name,a),Qt++):(await n.put("files",i,a),Xn++),Jn.add(a),Qn++,Qn%Ub===0&&console.debug(`File cache summary: ${Qt} hits and ${Xn} misses, ${Qt/(Qt+Xn)*100}% hit rate over ${Qn} calls to addCache.`)}async removeCache(i){await(await this._dbPromise).delete("files",i),Jn.delete(i)}async fetchCache(i){return(await this._dbPromise).get("files",i)}async getOrRenewUploadUrl(i){const a=this.client.store.getState();return Qu(i)(a)??await this.renewUploadUrl(i)}async uploadFileToS3(i){const a=await this.fetchCache(i);if(!a)throw new Error(`File with sha1 ${i} not found in cache`);const n=await as(a,i),c={file_name:a.name,file_sha1:i,file:n},r=await this.getOrRenewUploadUrl(i);if("warning"in r){if(r.warning==="already_uploaded")return[c,Promise.resolve(void 0)];throw new Error(r.warning)}const u=r.url,m=this.enqueueRequest({url:u,description:"Upload file",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:i,blockers:[`s3-${n}`],blocks:[i],s3url:r});return[c,m]}async fetchFileFromUrl(i,a,n){const c=i.split("?")[0]??i,r=await this.fetchCache(a);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(i.startsWith("blob:")){const h=await oc(i),p=new File([h],n??a,{type:h.type});return await this.addCache(p,a),p}let u=Xt[c],m=!0;u?m=!1:(u=new Promise(h=>{this.enqueueRequest({description:"Download file",method:l.GET,url:i,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[a],blocks:[a]}).then(p=>{const y=new File([p],n??a,{type:p.type});h(y)})}),Xt[c]=u);let o;try{o=await u}catch(h){throw m&&h instanceof D&&delete Xt[c],h}if(m){const h=await Qe(o);if(h!==a){const A=`The hash of the file returned from the server (${h}) does not match the
9
9
  expected hash (${a}). 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
@@ -33,7 +33,7 @@ export interface AssetStage extends UUIDModel, TimestampedModel, SubmittedAtMode
33
33
  }
34
34
  export interface AssetStageCompletion extends UUIDModel, TimestampedModel, SubmittedAtModel, CreatedByModel {
35
35
  asset: Asset["uuid"];
36
- stage: AssetStage["uuid"];
36
+ asset_stage: AssetStage["uuid"];
37
37
  asset_procedure: AssetProcedure["uuid"];
38
38
  }
39
39
  export type CompletedStagesMapping = Record<Asset["uuid"], Record<AssetStage["uuid"], AssetStageCompletion["submitted_at"]>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overmap-ai/core",
3
- "version": "1.0.78-procedure-rename.5",
3
+ "version": "1.0.78-procedure-rename.6",
4
4
  "description": "Core functionality for Overmap",
5
5
  "keywords": [
6
6
  "components",