@overmap-ai/core 1.0.78-attachment-model-improvements.11 → 1.0.78-attachment-model-improvements.12

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.
@@ -4692,6 +4692,9 @@ class bg extends D {
4692
4692
  getBlockers(e) {
4693
4693
  return [e.field_values];
4694
4694
  }
4695
+ getBlocks(e) {
4696
+ return [e.uuid];
4697
+ }
4695
4698
  buildModel(e) {
4696
4699
  var r;
4697
4700
  const { store: n } = this.client, i = ((r = n.getState().userReducer.currentUser) == null ? void 0 : r.id) ?? null, a = (/* @__PURE__ */ new Date()).toISOString();
@@ -4,7 +4,7 @@ Retries:`,e),!(t instanceof Error))throw console.error("ENCOUNTERED NON-ERROR ER
4
4
  Action:`,s);const p=nt();if(!p)throw new Error("Outbox coordinator not set");p.remove(s.payload.uuid),t.options.discard=!0,l()}}console.debug("Registering a retry for request:",s.payload.uuid);const r=nt();if(!r)throw new Error("Outbox coordinator not set");return r.registerRetry(s.payload.uuid),!1}function BF(t,s,e){var n;return(n=nt())==null?void 0:n.peek()}function vF(t,s){return ut().dispatch(sT(new Date().getTime())),Yn}const ct="An unknown error occurred",VF=500,JI=["non_field_errors","detail"];function zF(t,s){let e;if(t!=null&&t.body)if(typeof t.body=="object"){const n=t.body;if(typeof n.error=="string")e=n.error;else if(typeof n.message=="string")e=n.message;else try{e=Object.entries(n).map(([a,c])=>typeof c=="string"?JI.includes(a)?c:`${a}: ${c}`:Array.isArray(c)?JI.includes(a)?c.join(`
5
5
  `):c.map(d=>`${a}: ${d}`).join(`
6
6
  `):`${a}: ${JSON.stringify(c)}`).join(`
7
- `)}catch(a){console.error("Failed to extract error message from response body",a)}}else typeof t.body=="string"&&(e=t.body);else t!=null&&t.text?e=t.text:s instanceof Error&&(e=s.message);return!e||e.length>VF?ct:e}class C extends Error{constructor(e){super(ct);y(this,"status");y(this,"response");y(this,"message");y(this,"options");const{response:n,innerError:a}=e;this.message=e.message??zF(n,a)??ct,this.status=(n==null?void 0:n.status)??0,this.response=n,e.discard=e.discard??!1,this.options=e}}function XI(t){function s(e){return typeof e=="object"&&e!==null&&["ok","redirect","clientError","serverError","error"].every(a=>a in e)}if(s(t))return t;if(typeof t=="object"&&t!==null){const e=t;if(s(e.response))return e.response;if(e.response&&s(e.response.response))return e.response.response}}class jF extends LI{constructor(s){super(s)}}class st extends LI{constructor(e,n){super(e);y(this,"auth");this.auth=n}}class DF extends st{async startConversation(s,e){return this.enqueueRequest({description:"Start agent conversation",method:m.POST,url:"/agents/prompt/",payload:{prompt:s,active_project:e},blockers:["prompt"],blocks:["prompt"]}).then(n=>(this.dispatch(ua(n)),n))}async continueConversation(s,e,n){return this.enqueueRequest({description:"Prompt agent",method:m.POST,url:"/agents/prompt/",payload:{prompt:s,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:e}}).then(a=>{this.dispatch(oa(a))})}async fetchDetails(s){return this.enqueueRequest({description:"Get agent conversation",method:m.GET,url:`/agents/conversations/${s}/`,blockers:["conversation"],blocks:["conversation"]}).then(e=>{this.dispatch(la(e))})}async rate(s,e){return this.enqueueRequest({description:"Rate agent response",method:m.PUT,url:`/agents/responses/${s}/rate/`,payload:{rating:e},blockers:["rate"],blocks:["rate"]})}async list(s,e){return this.performRequest({method:m.GET,url:"/agents/conversations/",...s},e)}async refreshStore(s,e){const n=await this.list({queryParams:{project:s}},e);return this.dispatch(ra(n)),n}}function it(t,s){const e=[];let n=0;const a=t.length;for(;n<a;)e.push(t.slice(n,n+=s));return e}function T(t,s,e){const n=`${s}${e?"s":""}`;switch(t){case m.GET:return`Get ${n}`;case m.POST:return`Create ${n}`;case m.PATCH:return`Update ${n}`;case m.PUT:return`Update ${n}`;case m.DELETE:return`Delete ${n}`}}class B extends st{async get(s,e){return this.performRequest({url:`${this.url}/${s}/`,method:m.GET},e)}async list(s,e){return this.performRequest({url:`${this.url}/`,method:m.GET,...s},e)}async listPaginated(s,e){return this.performPagination({url:`${this.url}/`,method:m.GET,...s},e)}}class D extends B{constructor(){super(...arguments);y(this,"pageSize",CI)}async add(e){const{addOne:n,updateOne:a,deleteOne:c}=this.actions;let d,l=null,r=null;if("file"in e){const{file:_,...w}=e;l=await this.client.files.getFilePayload(_),r=URL.createObjectURL(_),d={...w,file_sha1:l.sha1,file_type:l.file_type,file_name:_.name,file_extension:l.extension,file_url:r}}else d=e;const u=this.buildModel(d),h=this.buildPayload(u);this.dispatch(n(u));const p=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:{...h,...l?{file:l}:{}},blockers:this.getBlockers(u),blocks:this.getBlocks(u)});p.then(({instance:_})=>{this.dispatch(a(_))}).catch(_=>{throw this.dispatch(c(this.getId(u))),_}).finally(()=>{r&&URL.revokeObjectURL(r)});const A=p.then(({instance:_})=>_),I=p.then(async({instance:_,presigned_url:w})=>{try{return w&&await this.client.files.processPresignedUrl(_.file_sha1,w),_.file_sha1}catch(b){throw console.error("Upload to s3 using presigned url failed.",b),b}});return[u,A,I]}async bulkAdd(e,n){const{addMany:a,updateMany:c,deleteMany:d}=this.actions,l=new Date().toISOString(),r=[],u=new Set,h=it(e,Math.min(n??e.length,Qe)),p=[];for(const w of h){const b=[],R={},M=[],q=[];for(const z of w){let k;if("file"in z){const{file:Cn,...Qg}=z,lt=await this.client.files.getFilePayload(Cn);lt.sha1 in R||(R[lt.sha1]=lt);const uO=URL.createObjectURL(Cn);u.add(uO),k={...Qg,file_sha1:lt.sha1,file_type:lt.file_type,file_name:Cn.name,file_extension:lt.extension,file_url:uO}}else k=z;const v=this.buildModel(k);r.push(v);const N=this.buildBulkPayload(v);b.push(N);const kt=this.getBlockers(v);M.push(...kt);const Xg=this.getBlocks(v);q.push(...Xg)}const U={payloads:b,submittedAt:l,files:Object.values(R),blockers:M,blocks:q};p.push(U)}this.dispatch(a(r));const A=p.map(w=>{const{submittedAt:b,files:R,payloads:M,blocks:q,blockers:U}=w;return this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:{submitted_at:b,files:R,payloads:M},blockers:U,blocks:q})});Promise.all(A).then(w=>{const b=w.flatMap(R=>R.instances);this.dispatch(c(b))}).catch(w=>{throw this.dispatch(d(r.map(b=>this.getId(b)))),console.error(w),w}).finally(()=>{for(const w of u)URL.revokeObjectURL(w)});const I=Promise.all(A).then(w=>w.flatMap(({instances:b})=>b)),_=Promise.all(A).then(async w=>{const b=[];for(const{presigned_urls:R}of w){const M=this.client.files.processPresignedUrls(R);for(const[q,U]of Object.entries(M))try{await U,b.push(q)}catch(z){throw console.error("Upload to s3 using presigned url failed.",z),z}}return b});return[r,I,_]}async delete(e){const{store:n}=this.client,{addOne:a,deleteOne:c}=this.actions,{selectById:d}=this.selectors,l=d(e)(n.getState());if(!l)throw new Error(`Attempting to delete ${this.name} with pk ${e} that does not exist in the store`);this.dispatch(c(this.getId(l)));const r=this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return r.then(()=>{this.client.files.removeCache(l.file_sha1)}).catch(()=>{this.dispatch(a(l))}),r}}class qF extends D{constructor(){super(...arguments);y(this,"name","Asset attachment");y(this,"url","/asset-attachments");y(this,"actions",{addOne:pa,addMany:es,setOne:Aa,setMany:fa,updateOne:Sa,updateMany:Ta,deleteOne:Ia,deleteMany:ts,initialize:ya});y(this,"selectors",{selectById:Pa,selectByIds:Fa})}getId(e){return e.uuid}getBlockers(e){const{asset:n}=e;return[n]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset:e.asset}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset:e.asset}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset__project:e}},n)).flat();return this.dispatch(a(d)),d}}class $F extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Attachment");y(this,"url","/asset-procedure-type-attachments");y(this,"actions",{addOne:Ra,addMany:wa,setOne:Ea,setMany:Ba,updateOne:va,updateMany:Va,deleteOne:za,deleteMany:ja,initialize:Ma});y(this,"selectors",{selectById:$a,selectByIds:Ca})}getId(e){return e.uuid}getBlockers(e){return[e.asset_procedure_type]}getBlocks(e){return[e.uuid]}buildModel(e){var A;const{store:n}=this.client,{asset_procedure_type:a,file_sha1:c,file_extension:d,file_name:l,file_type:r,file_url:u}=e,h=((A=n.getState().userReducer.currentUser)==null?void 0:A.id)??null,p=new Date().toISOString();return P({file_url:u,file_sha1:c,file_extension:d,file_name:l,file_type:r,created_by:h,submitted_at:p,asset_procedure_type:a})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_procedure_type:e.asset_procedure_type}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_procedure_type:e.asset_procedure_type}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class CF extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Type Fields Attachment");y(this,"url","/asset-procedure-type-fields-attachments");y(this,"actions",{addOne:ka,addMany:Na,setOne:Ga,setMany:Ha,updateOne:Ka,updateMany:Wa,deleteOne:Ya,deleteMany:Za,initialize:La});y(this,"selectors",{selectById:Qa,selectByIds:xa})}getId(e){return e.uuid}getBlockers(e){return[e.fields_revision]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{fields_revision__asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class UF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Type Fields");y(this,"url","/asset-procedure-type-fields");y(this,"actions",{addOne:sc,addMany:ic,setOne:nc,setMany:ac,updateOne:cc,updateMany:dc,deleteOne:rc,deleteMany:uc,initialize:tc});y(this,"selectors",{selectById:hc,selectByIds:mc})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_procedure_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(A=>{throw this.dispatch(d(u.uuid)),A}),[u,h]}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class LF extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Type Field Values Attachment");y(this,"url","/asset-procedure-type-field-values-attachments");y(this,"actions",{addOne:Ac,addMany:us,setOne:fc,setMany:Sc,updateOne:Tc,updateMany:Ic,deleteOne:Oc,deleteMany:ls,initialize:pc});y(this,"selectors",{selectById:gc,selectByIds:_c})}getId(e){return e.uuid}getBlockers(e){return[e.field_values]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}async bulkDelete(e){const{store:n}=this.client,{deleteMany:a,addMany:c}=this.actions,{selectByIds:d}=this.selectors,l=n.getState(),r=d(e)(l);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{field_values__asset_procedure__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class kF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Type Field Values");y(this,"url","/asset-procedure-type-field-values");y(this,"actions",{addOne:wc,addMany:Ec,setOne:Bc,setMany:vc,updateOne:Vc,updateMany:zc,deleteOne:jc,deleteMany:Dc,initialize:Rc});y(this,"selectors",{selectById:Cc,selectByIds:Uc})}add(e){var A;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,r=((A=n.getState().userReducer.currentUser)==null?void 0:A.id)??null,u=new Date().toISOString(),h=P({...e,created_by:r,submitted_at:u}),p=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(h),blockers:[e.asset,e.fields_revision,e.asset_procedure],blocks:[h.uuid]});return this.dispatch(a(h)),p.then(I=>{this.dispatch(c(I))}).catch(()=>{this.dispatch(d(h.uuid))}),[h,p]}bulkAdd(e,n){var w;const{values:a,payloads:c}=e,{addMany:d,setMany:l,deleteMany:r}=this.actions,u=new Date().toISOString(),h=((w=this.client.store.getState().userReducer.currentUser)==null?void 0:w.id)??null,p=[],A=it(c,Math.min(n??c.length,Qe)),I=[];for(const b of A){const R=[];for(const M of b){const q=P({...M,values:M.values,created_by:h,submitted_at:u});p.push(q),R.push({uuid:q.uuid,asset:M.asset,fields_revision:M.fields_revision,asset_procedure:M.asset_procedure,published_at:M.published_at,values:q.values})}I.push({submitted_at:u,values:a,field_values:R})}this.dispatch(d(p));const _=[];for(const b of I){const{field_values:R}=b,M=R.map(({asset:v})=>v),q=R.map(({fields_revision:v})=>v),U=R.map(({asset_procedure:v})=>v),z=R.map(({uuid:v})=>v),k=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:b,blockers:M.concat(q).concat(U),blocks:z});_.push(k)}return Promise.all(_).then(b=>{this.dispatch(l(b.flat()))}).catch(()=>{this.dispatch(r(V(p)))}),[p,_]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=n.getState(),l=c(e.uuid)(d);if(!l)throw new Error(`Expected AssetProcedureTypeFieldValues with uuid ${e.uuid} to exist`);const r={...l,...e};this.dispatch(a(r));const u=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[r.fields_revision,r.asset,r.asset_procedure],blocks:[r.uuid]});return u.then(h=>{this.dispatch(a(h))}).catch(()=>{this.dispatch(a(l))}),[r,u]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected submission with uuid ${e} to exist`);const u=bc(e)(l);this.dispatch(a(e)),this.dispatch(ls(V(u)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(c(r)),this.dispatch(us(u)),h}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset_procedure__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class NF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure");y(this,"url","/asset-procedures");y(this,"actions",{addOne:Nc,addMany:ys,setOne:Wc,setMany:Yc,updateOne:Gc,updateMany:Hc,deleteOne:Kc,deleteMany:ps,initialize:kc});y(this,"selectors",{selectById:Qc,selectByIds:xc})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[e.asset_procedure_type,e.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset procedure with uuid ${e} to exist`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{project:e}},n)).flat();return this.dispatch(a(d)),d}}class GF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Type");y(this,"url","/asset-procedure-types");y(this,"actions",{addOne:sd,addMany:id,setOne:rd,setMany:ud,updateOne:nd,updateMany:ad,deleteOne:cd,deleteMany:dd,initialize:td});y(this,"selectors",{selectById:hd,selectByIds:md})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`Expected asset procedure type with uuid ${e.uuid} to exist`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset procedure type with uuid ${e} to exist`);const u=Xc(e)(l);this.dispatch(a(e)),this.dispatch(ps(V(u)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(c(r)),this.dispatch(ys(u)),h}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{organization:e}},n);return this.dispatch(a(c)),c}}class HF extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Step Fields Attachment");y(this,"url","/asset-procedure-step-fields-attachments");y(this,"actions",{addOne:Ad,addMany:fd,setOne:Sd,setMany:Td,updateOne:Id,updateMany:Od,deleteOne:Pd,deleteMany:Fd,initialize:pd});y(this,"selectors",{selectById:_d,selectByIds:bd})}getId(e){return e.uuid}getBlockers(e){return[e.fields_revision]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,field_identifier:e.field_identifier,fields_revision:e.fields_revision,file_sha1:e.file_sha1,file_name:e.file_name,file_extension:e.file_extension}}buildBulkPayload(e){return{uuid:e.uuid,field_identifier:e.field_identifier,fields_revision:e.fields_revision,file_sha1:e.file_sha1,file_name:e.file_name,file_extension:e.file_extension}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{fields_revision__asset_procedure_step__organization:e}},n);return this.dispatch(a(c)),c}}class KF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Step Fields");y(this,"url","/asset-procedure-step-fields");y(this,"actions",{addOne:Ed,addMany:Bd,setOne:vd,setMany:Vd,updateOne:zd,updateMany:jd,deleteOne:Dd,deleteMany:qd,initialize:wd});y(this,"selectors",{selectById:$d,selectByIds:Cd})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_procedure_step],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(A=>{throw this.dispatch(d(u.uuid)),A}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,c=n.getState().assetProcedureStepFieldsReducer.instances[e.uuid];if(!c)throw new Error(`AssetProcedureStepFields with uuid ${e.uuid} not found`);const d={...c,...e};this.dispatch(a(d));const l=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${c.uuid}/`,payload:e,blockers:[c.uuid],blocks:[c.uuid]});return l.then(r=>{this.dispatch(a(r))}).catch(r=>{throw this.dispatch(a(c)),r}),[d,l]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,d=n.getState().assetProcedureStepFieldsReducer.instances[e];if(!d)throw new Error(`AssetProcedureStepFields with uuid ${e} not found`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[e]})}catch(l){throw this.dispatch(c(d)),l}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_step__asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class WF extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Step Field Values Attachment");y(this,"url","/asset-procedure-step-field-values-attachments");y(this,"actions",{addOne:Nd,addMany:Fs,setOne:Gd,setMany:Hd,updateOne:Kd,updateMany:Wd,deleteOne:Yd,deleteMany:gs,initialize:kd});y(this,"selectors",{selectById:Jd,selectByIds:Xd})}getId(e){return e.uuid}getBlockers(e){return[e.field_values]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}async bulkDelete(e){const{store:n}=this.client,{deleteMany:a,addMany:c}=this.actions,{selectByIds:d}=this.selectors,l=n.getState(),r=d(e)(l);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{field_values__asset_procedure__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class YF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Step Field Values");y(this,"url","/asset-procedure-step-field-values");y(this,"actions",{addOne:sr,addMany:ir,setOne:nr,setMany:ar,updateOne:cr,updateMany:dr,deleteOne:rr,deleteMany:ur,initialize:tr});y(this,"selectors",{selectById:or,selectByIds:hr})}add(e){var A;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,r=((A=n.getState().userReducer.currentUser)==null?void 0:A.id)??null,u=new Date().toISOString(),h=P({...e,created_by:r,submitted_at:u}),p=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(h),blockers:[e.asset,e.fields_revision,e.asset_procedure],blocks:[h.uuid]});return this.dispatch(a(h)),p.then(I=>{this.dispatch(c(I))}).catch(()=>{this.dispatch(d(h.uuid))}),[h,p]}bulkAdd(e,n){var w;const{payloads:a,values:c}=e,{addMany:d,setMany:l,deleteMany:r}=this.actions,u=new Date().toISOString(),h=((w=this.client.store.getState().userReducer.currentUser)==null?void 0:w.id)??null,p=[],A=it(a,Math.min(n??a.length,Qe)),I=[];for(const b of A){const R=[];for(const M of b){const q=P({...M,values:M.values,created_by:h,submitted_at:u});p.push(q),R.push({uuid:q.uuid,asset:M.asset,fields_revision:M.fields_revision,asset_procedure:M.asset_procedure,asset_procedure_step:M.asset_procedure_step,published_at:M.published_at,values:q.values})}I.push({submitted_at:u,values:c,field_values:R})}this.dispatch(d(p));const _=[];for(const b of I){const{field_values:R}=b,M=R.map(({asset:v})=>v),q=R.map(({fields_revision:v})=>v),U=R.map(({asset_procedure:v})=>v),z=R.map(({uuid:v})=>v),k=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:b,blockers:M.concat(q).concat(U),blocks:z});_.push(k)}return Promise.all(_).then(b=>{this.dispatch(l(b.flat()))}).catch(()=>{this.dispatch(r(V(p)))}),[p,_]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=n.getState(),l=c(e.uuid)(d);if(!l)throw new Error(`Expected AssetProcedureStepFieldValues with uuid ${e.uuid} to exist`);const r={...l,...e};this.dispatch(a(r));const u=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[r.fields_revision,r.asset,r.asset_procedure],blocks:[r.uuid]});return u.then(h=>{this.dispatch(a(h))}).catch(()=>{this.dispatch(a(l))}),[r,u]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected submission with uuid ${e} to exist`);const u=Qd(e)(l);this.dispatch(a(e)),this.dispatch(gs(V(u)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(c(r)),this.dispatch(Fs(u)),h}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset_procedure__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class ZF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Step");y(this,"url","/asset-procedure-steps");y(this,"actions",{addOne:Sr,addMany:Tr,setOne:Ar,setMany:fr,updateOne:Ir,updateMany:Or,deleteOne:Pr,deleteMany:Fr,initialize:pr});y(this,"selectors",{selectById:_r,selectByIds:br})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_procedure_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`No asset procedure step with uuid ${e.uuid} found in the store`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${d.uuid}/`,payload:{name:e.name,description:e.description,priority:e.order,color:e.color},blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteMany:a,addMany:c,addOne:d,deleteOne:l}=this.actions,{selectById:r}=this.selectors,u=n.getState(),h=r(e)(u);if(!h)throw new Error(`No asset procedure step with uuid ${e} found in the store`);const p=Mr(e)(u);this.dispatch(l(e)),this.dispatch(a(V(p)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(A){throw this.dispatch(d(h)),this.dispatch(c(p)),A}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class JF extends B{constructor(){super(...arguments);y(this,"url","/assets");y(this,"name","Asset");y(this,"actions",{addOne:Er,addMany:Es,setOne:zr,setMany:jr,updateOne:Br,updateMany:vr,deleteOne:Vr,deleteMany:Bs,initialize:wr});y(this,"selectors",{selectById:$r,selectByIds:Cr})}add(e){var p;const{store:n}=this.client,{addOne:a,updateOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{updateOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{addOne:a,deleteOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`No asset with uuid ${e} found in the store`);const u=ga(e)(l),h=$y(e)(l);this.dispatch(c(e)),this.dispatch(ts(V(u))),this.dispatch(et(V(h)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(p){throw this.dispatch(a(r)),this.dispatch(es(u)),this.dispatch(xe(h)),p}}bulkAdd(e,n){const{addMany:a}=this.actions,c=new Date().toISOString(),d=Xe.v4(),l=it(e,Math.min(n??e.length,Qe)).map(h=>{const p=h.map(A=>P(A));return{batchId:Xe.v4(),payload:{transaction_id:d,submitted_at:c,assets:p}}}),r=[];let u=null;for(const h of l){const{batchId:p,payload:A}=h,I=A.assets.map(({uuid:M})=>M),_=A.assets.map(({asset_type:M})=>M),w=A.assets.map(({project:M})=>M),b=A.assets.map(({status:M})=>M),R=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:A,blockers:(u?[u]:[]).concat(_).concat(w).concat(b),blocks:[p].concat(I)});u=h.batchId,r.push(R)}return Promise.all(r).then(h=>{const p=h.flat();this.dispatch(a(p))}),r}bulkUpdate(e,n){const{store:a}=this.client,{updateMany:c}=this.actions,{selectByIds:d}=this.selectors,l=V(e).toSorted(It);if(l.length!==e.length)throw new Error("payloads contains duplicate uuids.");const r=d(l)(a.getState()).toSorted(Jt);if(l.length!=r.length)throw new Error(`Attempting to bulk update ${l.length-r.length} assets that dont exist in the store`);const u=[];for(let I=0;I<l.length;I++)u.push({...r[I],...e[I]});this.dispatch(c(u));const h=it(e,Math.min(n??e.length,Qe)),p=[];let A=null;for(const I of h){const _=Xe.v4(),w=V(I),b=I.map(({status:M})=>M).filter(Boolean),R=this.enqueueRequest({description:T(m.PATCH,this.name,!0),method:m.PATCH,url:`${this.url}/bulk/`,payload:{payloads:I},blockers:(A?[A]:[]).concat(w).concat(b),blocks:[_].concat(w)});p.push(R),A=_}return Promise.all(p).then(I=>{this.dispatch(c(I.flat()))}).catch(()=>{this.dispatch(c(r))}),[u,p]}async bulkDelete(e){const{store:n}=this.client,{addMany:a,deleteMany:c}=this.actions,{selectByIds:d}=this.selectors,l=n.getState(),r=d(e)(l);this.dispatch(c(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(a(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{project:e}},n)).flat();return this.dispatch(a(d)),d}}class XF extends B{constructor(){super(...arguments);y(this,"name","Asset Stage Completion");y(this,"url","/asset-stage-completions");y(this,"actions",{addOne:Nr,addMany:Gr,setOne:Hr,setMany:Kr,updateOne:Wr,updateMany:Yr,deleteOne:Zr,deleteMany:Jr,initialize:kr});y(this,"selectors",{selectById:eu,selectByIds:tu})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[e.asset,e.asset_stage],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=d(e)(n.getState());if(!l)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(c(l)),r}}bulkAdd(e){var I;const{store:n}=this.client,{addMany:a,setMany:c,deleteMany:d}=this.actions,l=new Date().toISOString(),r=((I=n.getState().userReducer.currentUser)==null?void 0:I.id)??null,u=e.map(_=>P(_)),h=u.map(_=>({..._,created_by:r,submitted_at:l})),p=h.map(({uuid:_})=>_);this.dispatch(a(h));const A=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:{submitted_at:l,completions:u},blockers:[...e.map(_=>_.asset_procedure),...e.map(_=>_.asset_stage),...e.map(_=>_.asset)],blocks:p});return A.then(_=>{this.dispatch(c(_))}).catch(()=>{this.dispatch(d(p))}),[h,A]}async bulkDelete(e){const{store:n}=this.client,{deleteMany:a,addMany:c}=this.actions,{selectByIds:d}=this.selectors,l=d(e)(n.getState());this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(r){throw this.dispatch(c(l)),r}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset_procedure__project:e}},n)).flat();return this.dispatch(a(d)),d}}class QF extends B{constructor(){super(...arguments);y(this,"name","Asset Stage");y(this,"url","/asset-stages");y(this,"actions",{addOne:cu,addMany:du,setOne:nu,setMany:au,updateOne:ru,updateMany:uu,deleteOne:lu,deleteMany:ou,initialize:iu});y(this,"selectors",{selectById:mu,selectByIds:yu})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_procedure_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${d.uuid}/`,payload:e,blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`No asset stage with uuid ${e} found in the store`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class xF extends D{constructor(){super(...arguments);y(this,"name","Asset Type Attachment");y(this,"url","/asset-type-attachments");y(this,"actions",{addOne:fu,addMany:qs,setOne:Su,setMany:Tu,updateOne:Iu,updateMany:Ou,deleteOne:Pu,deleteMany:$s,initialize:Au});y(this,"selectors",{selectById:gu,selectByIds:_u})}getId(e){return e.uuid}getBlockers(e){return[e.asset_type]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_type:e.asset_type}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_type:e.asset_type}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class eg extends D{constructor(){super(...arguments);y(this,"name","Asset Type Fields Attachment");y(this,"url","/asset-type-fields-attachments");y(this,"actions",{addOne:Eu,addMany:Bu,setOne:vu,setMany:Vu,updateOne:zu,updateMany:ju,deleteOne:Du,deleteMany:qu,initialize:wu});y(this,"selectors",{selectById:Cu,selectByIds:Uu})}getId(e){return e.uuid}getBlockers(e){return[e.fields_revision]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{fields_revision__asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class tg extends B{constructor(){super(...arguments);y(this,"name","Asset Type Fields");y(this,"url","/asset-type-fields");y(this,"actions",{addOne:Gu,addMany:Hu,setOne:Ku,setMany:Wu,updateOne:Yu,updateMany:Zu,deleteOne:Ju,deleteMany:Xu,initialize:Nu});y(this,"selectors",{selectById:xu,selectByIds:el})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(A=>{throw this.dispatch(d(u.uuid)),A}),[u,h]}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class sg extends D{constructor(){super(...arguments);y(this,"name","Asset Type Field Values Attachment");y(this,"url","/asset-type-field-values-attachments");y(this,"actions",{addOne:nl,addMany:Gs,setOne:al,setMany:cl,updateOne:dl,updateMany:rl,deleteOne:ul,deleteMany:Hs,initialize:il});y(this,"selectors",{selectById:ol,selectByIds:hl})}getId(e){return e.uuid}getBlockers(e){return[e.field_values]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}async bulkDelete(e){const{store:n}=this.client,{deleteMany:a,addMany:c}=this.actions,{selectByIds:d}=this.selectors,l=n.getState(),r=d(e)(l);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{field_values__asset__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class ig extends B{constructor(){super(...arguments);y(this,"name","Asset Type Field Values");y(this,"url","/asset-type-field-values");y(this,"actions",{addOne:fl,addMany:Sl,setOne:Tl,setMany:Il,updateOne:Ol,updateMany:Pl,deleteOne:Fl,deleteMany:gl,initialize:Al});y(this,"selectors",{selectById:bl,selectByIds:Ml})}add(e){var A;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,r=((A=n.getState().userReducer.currentUser)==null?void 0:A.id)??null,u=new Date().toISOString(),h=P({...e,created_by:r,submitted_at:u}),p=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(h),blockers:[e.asset,e.fields_revision],blocks:[h.uuid]});return this.dispatch(a(h)),p.then(I=>{this.dispatch(c(I))}).catch(()=>{this.dispatch(d(h.uuid))}),[h,p]}bulkAdd(e,n){var _;const{payloads:a,values:c}=e,{addMany:d,setMany:l,deleteMany:r}=this.actions,u=new Date().toISOString(),h=[],p=it(a,Math.min(n??a.length,Qe)),A=[];for(const w of p){const b=[];for(const R of w){const M=P({...R,values:R.values,created_by:((_=this.client.store.getState().userReducer.currentUser)==null?void 0:_.id)??null,submitted_at:u});h.push(M),b.push({uuid:M.uuid,asset:R.asset,fields_revision:R.fields_revision,published_at:R.published_at,values:M.values})}A.push({submitted_at:u,values:c,field_values:b})}this.dispatch(d(h));const I=[];for(const w of A){const{field_values:b}=w,R=b.map(({asset:z})=>z),M=b.map(({fields_revision:z})=>z),q=b.map(({uuid:z})=>z),U=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:w,blockers:R.concat(M),blocks:q});I.push(U)}return Promise.all(I).then(w=>{this.dispatch(l(w.flat()))}).catch(()=>{this.dispatch(r(V(h)))}),[h,I]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=n.getState(),l=c(e.uuid)(d);if(!l)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const r={...l,...e};this.dispatch(a(r));const u=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[r.uuid,r.fields_revision,r.asset],blocks:[r.uuid]});return u.then(h=>{this.dispatch(a(h))}).catch(()=>{this.dispatch(a(l))}),[r,u]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected submission with uuid ${e} to exist`);const u=ml(e)(l);this.dispatch(a(e)),this.dispatch(Hs(V(u)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(c(r)),this.dispatch(Gs(u)),h}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class ng extends B{constructor(){super(...arguments);y(this,"name","Asset Type Identifier");y(this,"url","/asset-type-identifiers");y(this,"actions",{addOne:Bl,addMany:vl,setOne:Vl,setMany:zl,updateOne:jl,updateMany:Dl,deleteOne:ql,deleteMany:$l,initialize:El});y(this,"selectors",{selectById:Ul,selectByIds:Ll})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`Expected asset type identifier with uuid ${e.uuid} to exist`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset type identifier with uuid ${e} to exist`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class ag extends B{constructor(){super(...arguments);y(this,"name","Asset Type Identifier Value");y(this,"url","/asset-type-identifier-values");y(this,"actions",{addOne:Hl,addMany:Kl,setOne:Wl,setMany:Yl,updateOne:Zl,updateMany:Jl,deleteOne:Xl,deleteMany:Ql,initialize:Gl});y(this,"selectors",{selectById:eo,selectByIds:to})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[e.asset,e.asset_type_identifier],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset type identifier value with uuid ${e} to exist`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class cg extends B{constructor(){super(...arguments);y(this,"name","Asset Type");y(this,"url","/asset-types");y(this,"actions",{addOne:ro,addMany:uo,setOne:ao,setMany:co,updateOne:lo,updateMany:oo,deleteOne:ho,deleteMany:mo,initialize:no});y(this,"selectors",{selectById:po,selectByIds:Ao})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset type with uuid ${e} to exist`);const u=qr(e)(l),h=bu(e)(l);this.dispatch(a(e)),this.dispatch(Bs(V(u))),this.dispatch($s(V(h)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(p){throw this.dispatch(c(r)),this.dispatch(Es(u)),this.dispatch(qs(h)),p}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{organization:e}},n);return this.dispatch(a(c)),c}}class dg extends B{constructor(){super(...arguments);y(this,"name","Asset Type Status");y(this,"url","/asset-type-statuses");y(this,"actions",{addOne:Io,addMany:Oo,setOne:Po,setMany:Fo,updateOne:go,updateMany:_o,deleteOne:bo,deleteMany:Mo,initialize:To});y(this,"selectors",{selectById:wo,selectByIds:Eo})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[e.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{setOne:n}=this.actions,{selectById:a}=this.selectors,c=this.client.store.getState(),d=a(e.uuid)(c);if(!d)throw new Error(`Expected an existing asset type status with uuid ${e.uuid}`);const l={...d,...e};this.dispatch(n(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(n(u))}).catch(()=>{this.dispatch(n(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=d(e)(n.getState());if(!l)throw new Error(`No asset type status with uuid ${e} found in the store`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(c(l)),r}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class rg extends D{constructor(){super(...arguments);y(this,"name","Document Attachment");y(this,"url","/document-attachments");y(this,"actions",{addOne:qo,addMany:$o,setOne:Co,setMany:Uo,updateOne:Lo,updateMany:ko,deleteOne:No,deleteMany:Go,initialize:Do});y(this,"selectors",{selectById:Ko,selectByIds:Wo})}getId(e){return e.uuid}getBlockers(e){return[e.document]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,document:e.document}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,document:e.document}}async bulkAdd(e,n){const[a,c,d]=await super.bulkAdd(e,n),l={};for(const{file_sha1:r,uuid:u}of a)r in l||(l[r]=[]),l[r].push(u);return d.then(r=>{const u=r.flatMap(h=>l[h]??[]);for(const h of u)this.makeReadable(h)}),[a,c,d]}makeReadable(e){this.enqueueRequest({description:"Add attachment to AI assistant",method:m.PATCH,url:`${this.url}/${e}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",e],blocks:["index-document-attachment"]})}async refreshStore(e,n){const{initialize:a}=this.actions,c=this.list({queryParams:{document__project__organization:e}},n),d=this.list({queryParams:{document__organization:e}},n),r=(await Promise.all([c,d])).flat();return this.dispatch(a(r)),r}}class ug extends B{constructor(){super(...arguments);y(this,"name","Document");y(this,"url","/documents");y(this,"actions",{addOne:Xo,addMany:Qo,setOne:xo,setMany:eh,updateOne:th,updateMany:sh,deleteOne:ih,deleteMany:nh,initialize:Jo});y(this,"selectors",{selectById:ch,selectByIds:dh})}add(e){var p;const{store:n}=this.client,{addOne:a,deleteOne:c,updateOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:u.parent_document?[u.parent_document]:[],blocks:[u.uuid]});return h.then(A=>{this.dispatch(d(A))}).catch(()=>{this.dispatch(c(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{updateOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c,addMany:d,deleteMany:l}=this.actions,{selectById:r}=this.selectors,u=n.getState(),h=r(e)(u);if(!h)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const p=rh(e)(u);this.dispatch(a(e)),this.dispatch(l(V(p)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(A){throw this.dispatch(c(h)),this.dispatch(d(p)),A}}async refreshStore(e,n){const{initialize:a}=this.actions,c=this.list({queryParams:{project__organization:e}},n),d=this.list({queryParams:{organization:e}},n),r=(await Promise.all([c,d])).flat();return this.dispatch(a(r)),r}}class dt extends st{async get(s,e){return this.performRequest({url:`${this.url}/${s}/`,method:m.GET},e)}async list(s,e){return this.performRequest({url:`${this.url}/`,method:m.GET,...s},e)}async listPaginated(s,e){return this.performPagination({url:`${this.url}/`,method:m.GET,...s},e)}}class lg extends dt{constructor(){super(...arguments);y(this,"name","Email Domains");y(this,"url","/organization-email-domains");y(this,"actions",{addOne:oh,addMany:hh,setOne:mh,setMany:yh,updateOne:ph,updateMany:Ah,deleteOne:fh,deleteMany:Sh,initialize:lh});y(this,"selectors",{selectById:Ih,selectByIds:Oh})}async add(e,n){return this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:{email:n,organization:e},blockers:[e,"create-org"],blocks:[]})}async delete(e){const{deleteOne:n,addOne:a}=this.actions;this.dispatch(n(e.uuid));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e.uuid}/`,blockers:[e.domain],blocks:[]})}catch(c){throw this.dispatch(a(e)),c}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{organization:e}},n);return this.dispatch(a(c)),c}}class og extends st{async getVerificationCode(s){return this.enqueueRequest({description:"Get verification code",method:m.GET,url:`/verification/email-verification/${s}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(s,e=void 0){return this.enqueueRequest({description:"Validate verification code",method:m.POST,url:`/verification/email-verification/${s}/`,isAuthNeeded:!1,payload:e,blockers:[],blocks:[]})}}const At={},jn=new Set;class hg extends st{constructor(){super(...arguments);y(this,"host");y(this,"dbPromise",pO.openDB("fileCache",1,{upgrade(e){e.createObjectStore("files")}}))}async getDB(){return await this.dbPromise}async addCache(e){if(!e.name)throw new Error(`Cant add a file without a name to cache: ${e.name}`);if(!e.type)throw new Error(`Cant add a file without a type to cache: ${e.name}`);if(!e.size)throw new Error(`Cant add an empty file to cache: ${e.name}`);const n=await Tt(e);if(jn.has(n))return;const a=await this.getDB();!!await a.get("files",n)?console.warn(`Attempting to add a file already cached, ${e.name}`):await a.put("files",e,n),jn.add(n)}async removeCache(e){await(await this.getDB()).delete("files",e),jn.delete(e)}async fetchCache(e){return(await this.getDB()).get("files",e)}async getPresignedUploadUrl(e){const{sha1:n,file_type:a,size:c,extension:d}=await this.getFilePayload(e),l=Yt(n,d),r={sha1:n,file_type:a,extension:d,size:c};return await this.enqueueRequest({description:"Create S3 upload url",method:m.POST,url:"/authentication/files/presigned-upload-url/",payload:r,blockers:[],blocks:[`s3-${l}`]})}async uploadFileToS3(e){const n=await this.fetchCache(e);if(!n)throw new Error(`File with sha1 ${e} not found in cache`);const a=Yt(e,Zt(n)),c={file_name:n.name,file_sha1:e,file:a},d=await this.getPresignedUploadUrl(n);if("warning"in d){if(d.warning==="already_uploaded")return[c,Promise.resolve(void 0)];throw new Error(d.warning)}const l=d.url,r=this.enqueueRequest({url:l,description:"Upload file",method:m.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:e,blockers:[`s3-${a}`],blocks:[e],s3url:d});return[c,r]}async fetchFileFromUrl(e,n,a=n){const c=e.split("?")[0]??e,d=await this.fetchCache(n);if(d)return d;let l;c in At?l=At[c]:Qn(e)?(l=Xn(e,a),At[c]=l):(l=new Promise(h=>{this.performRequest({method:m.GET,url:e,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1}).then(p=>{const A=new File([p],a,{type:p.type});h(A)})}),At[c]=l);let r;try{r=await l}catch(h){throw h instanceof C&&delete At[c],h}const u=await Tt(r);if(u!==n){const h=`The hash of the file returned from the server (${u}) does not match the
7
+ `)}catch(a){console.error("Failed to extract error message from response body",a)}}else typeof t.body=="string"&&(e=t.body);else t!=null&&t.text?e=t.text:s instanceof Error&&(e=s.message);return!e||e.length>VF?ct:e}class C extends Error{constructor(e){super(ct);y(this,"status");y(this,"response");y(this,"message");y(this,"options");const{response:n,innerError:a}=e;this.message=e.message??zF(n,a)??ct,this.status=(n==null?void 0:n.status)??0,this.response=n,e.discard=e.discard??!1,this.options=e}}function XI(t){function s(e){return typeof e=="object"&&e!==null&&["ok","redirect","clientError","serverError","error"].every(a=>a in e)}if(s(t))return t;if(typeof t=="object"&&t!==null){const e=t;if(s(e.response))return e.response;if(e.response&&s(e.response.response))return e.response.response}}class jF extends LI{constructor(s){super(s)}}class st extends LI{constructor(e,n){super(e);y(this,"auth");this.auth=n}}class DF extends st{async startConversation(s,e){return this.enqueueRequest({description:"Start agent conversation",method:m.POST,url:"/agents/prompt/",payload:{prompt:s,active_project:e},blockers:["prompt"],blocks:["prompt"]}).then(n=>(this.dispatch(ua(n)),n))}async continueConversation(s,e,n){return this.enqueueRequest({description:"Prompt agent",method:m.POST,url:"/agents/prompt/",payload:{prompt:s,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:e}}).then(a=>{this.dispatch(oa(a))})}async fetchDetails(s){return this.enqueueRequest({description:"Get agent conversation",method:m.GET,url:`/agents/conversations/${s}/`,blockers:["conversation"],blocks:["conversation"]}).then(e=>{this.dispatch(la(e))})}async rate(s,e){return this.enqueueRequest({description:"Rate agent response",method:m.PUT,url:`/agents/responses/${s}/rate/`,payload:{rating:e},blockers:["rate"],blocks:["rate"]})}async list(s,e){return this.performRequest({method:m.GET,url:"/agents/conversations/",...s},e)}async refreshStore(s,e){const n=await this.list({queryParams:{project:s}},e);return this.dispatch(ra(n)),n}}function it(t,s){const e=[];let n=0;const a=t.length;for(;n<a;)e.push(t.slice(n,n+=s));return e}function T(t,s,e){const n=`${s}${e?"s":""}`;switch(t){case m.GET:return`Get ${n}`;case m.POST:return`Create ${n}`;case m.PATCH:return`Update ${n}`;case m.PUT:return`Update ${n}`;case m.DELETE:return`Delete ${n}`}}class B extends st{async get(s,e){return this.performRequest({url:`${this.url}/${s}/`,method:m.GET},e)}async list(s,e){return this.performRequest({url:`${this.url}/`,method:m.GET,...s},e)}async listPaginated(s,e){return this.performPagination({url:`${this.url}/`,method:m.GET,...s},e)}}class D extends B{constructor(){super(...arguments);y(this,"pageSize",CI)}async add(e){const{addOne:n,updateOne:a,deleteOne:c}=this.actions;let d,l=null,r=null;if("file"in e){const{file:_,...w}=e;l=await this.client.files.getFilePayload(_),r=URL.createObjectURL(_),d={...w,file_sha1:l.sha1,file_type:l.file_type,file_name:_.name,file_extension:l.extension,file_url:r}}else d=e;const u=this.buildModel(d),h=this.buildPayload(u);this.dispatch(n(u));const p=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:{...h,...l?{file:l}:{}},blockers:this.getBlockers(u),blocks:this.getBlocks(u)});p.then(({instance:_})=>{this.dispatch(a(_))}).catch(_=>{throw this.dispatch(c(this.getId(u))),_}).finally(()=>{r&&URL.revokeObjectURL(r)});const A=p.then(({instance:_})=>_),I=p.then(async({instance:_,presigned_url:w})=>{try{return w&&await this.client.files.processPresignedUrl(_.file_sha1,w),_.file_sha1}catch(b){throw console.error("Upload to s3 using presigned url failed.",b),b}});return[u,A,I]}async bulkAdd(e,n){const{addMany:a,updateMany:c,deleteMany:d}=this.actions,l=new Date().toISOString(),r=[],u=new Set,h=it(e,Math.min(n??e.length,Qe)),p=[];for(const w of h){const b=[],R={},M=[],q=[];for(const z of w){let k;if("file"in z){const{file:Cn,...Qg}=z,lt=await this.client.files.getFilePayload(Cn);lt.sha1 in R||(R[lt.sha1]=lt);const uO=URL.createObjectURL(Cn);u.add(uO),k={...Qg,file_sha1:lt.sha1,file_type:lt.file_type,file_name:Cn.name,file_extension:lt.extension,file_url:uO}}else k=z;const v=this.buildModel(k);r.push(v);const N=this.buildBulkPayload(v);b.push(N);const kt=this.getBlockers(v);M.push(...kt);const Xg=this.getBlocks(v);q.push(...Xg)}const U={payloads:b,submittedAt:l,files:Object.values(R),blockers:M,blocks:q};p.push(U)}this.dispatch(a(r));const A=p.map(w=>{const{submittedAt:b,files:R,payloads:M,blocks:q,blockers:U}=w;return this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:{submitted_at:b,files:R,payloads:M},blockers:U,blocks:q})});Promise.all(A).then(w=>{const b=w.flatMap(R=>R.instances);this.dispatch(c(b))}).catch(w=>{throw this.dispatch(d(r.map(b=>this.getId(b)))),console.error(w),w}).finally(()=>{for(const w of u)URL.revokeObjectURL(w)});const I=Promise.all(A).then(w=>w.flatMap(({instances:b})=>b)),_=Promise.all(A).then(async w=>{const b=[];for(const{presigned_urls:R}of w){const M=this.client.files.processPresignedUrls(R);for(const[q,U]of Object.entries(M))try{await U,b.push(q)}catch(z){throw console.error("Upload to s3 using presigned url failed.",z),z}}return b});return[r,I,_]}async delete(e){const{store:n}=this.client,{addOne:a,deleteOne:c}=this.actions,{selectById:d}=this.selectors,l=d(e)(n.getState());if(!l)throw new Error(`Attempting to delete ${this.name} with pk ${e} that does not exist in the store`);this.dispatch(c(this.getId(l)));const r=this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return r.then(()=>{this.client.files.removeCache(l.file_sha1)}).catch(()=>{this.dispatch(a(l))}),r}}class qF extends D{constructor(){super(...arguments);y(this,"name","Asset attachment");y(this,"url","/asset-attachments");y(this,"actions",{addOne:pa,addMany:es,setOne:Aa,setMany:fa,updateOne:Sa,updateMany:Ta,deleteOne:Ia,deleteMany:ts,initialize:ya});y(this,"selectors",{selectById:Pa,selectByIds:Fa})}getId(e){return e.uuid}getBlockers(e){const{asset:n}=e;return[n]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset:e.asset}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset:e.asset}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset__project:e}},n)).flat();return this.dispatch(a(d)),d}}class $F extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Attachment");y(this,"url","/asset-procedure-type-attachments");y(this,"actions",{addOne:Ra,addMany:wa,setOne:Ea,setMany:Ba,updateOne:va,updateMany:Va,deleteOne:za,deleteMany:ja,initialize:Ma});y(this,"selectors",{selectById:$a,selectByIds:Ca})}getId(e){return e.uuid}getBlockers(e){return[e.asset_procedure_type]}getBlocks(e){return[e.uuid]}buildModel(e){var A;const{store:n}=this.client,{asset_procedure_type:a,file_sha1:c,file_extension:d,file_name:l,file_type:r,file_url:u}=e,h=((A=n.getState().userReducer.currentUser)==null?void 0:A.id)??null,p=new Date().toISOString();return P({file_url:u,file_sha1:c,file_extension:d,file_name:l,file_type:r,created_by:h,submitted_at:p,asset_procedure_type:a})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_procedure_type:e.asset_procedure_type}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_procedure_type:e.asset_procedure_type}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class CF extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Type Fields Attachment");y(this,"url","/asset-procedure-type-fields-attachments");y(this,"actions",{addOne:ka,addMany:Na,setOne:Ga,setMany:Ha,updateOne:Ka,updateMany:Wa,deleteOne:Ya,deleteMany:Za,initialize:La});y(this,"selectors",{selectById:Qa,selectByIds:xa})}getId(e){return e.uuid}getBlockers(e){return[e.fields_revision]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{fields_revision__asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class UF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Type Fields");y(this,"url","/asset-procedure-type-fields");y(this,"actions",{addOne:sc,addMany:ic,setOne:nc,setMany:ac,updateOne:cc,updateMany:dc,deleteOne:rc,deleteMany:uc,initialize:tc});y(this,"selectors",{selectById:hc,selectByIds:mc})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_procedure_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(A=>{throw this.dispatch(d(u.uuid)),A}),[u,h]}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class LF extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Type Field Values Attachment");y(this,"url","/asset-procedure-type-field-values-attachments");y(this,"actions",{addOne:Ac,addMany:us,setOne:fc,setMany:Sc,updateOne:Tc,updateMany:Ic,deleteOne:Oc,deleteMany:ls,initialize:pc});y(this,"selectors",{selectById:gc,selectByIds:_c})}getId(e){return e.uuid}getBlockers(e){return[e.field_values]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}async bulkDelete(e){const{store:n}=this.client,{deleteMany:a,addMany:c}=this.actions,{selectByIds:d}=this.selectors,l=n.getState(),r=d(e)(l);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{field_values__asset_procedure__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class kF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Type Field Values");y(this,"url","/asset-procedure-type-field-values");y(this,"actions",{addOne:wc,addMany:Ec,setOne:Bc,setMany:vc,updateOne:Vc,updateMany:zc,deleteOne:jc,deleteMany:Dc,initialize:Rc});y(this,"selectors",{selectById:Cc,selectByIds:Uc})}add(e){var A;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,r=((A=n.getState().userReducer.currentUser)==null?void 0:A.id)??null,u=new Date().toISOString(),h=P({...e,created_by:r,submitted_at:u}),p=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(h),blockers:[e.asset,e.fields_revision,e.asset_procedure],blocks:[h.uuid]});return this.dispatch(a(h)),p.then(I=>{this.dispatch(c(I))}).catch(()=>{this.dispatch(d(h.uuid))}),[h,p]}bulkAdd(e,n){var w;const{values:a,payloads:c}=e,{addMany:d,setMany:l,deleteMany:r}=this.actions,u=new Date().toISOString(),h=((w=this.client.store.getState().userReducer.currentUser)==null?void 0:w.id)??null,p=[],A=it(c,Math.min(n??c.length,Qe)),I=[];for(const b of A){const R=[];for(const M of b){const q=P({...M,values:M.values,created_by:h,submitted_at:u});p.push(q),R.push({uuid:q.uuid,asset:M.asset,fields_revision:M.fields_revision,asset_procedure:M.asset_procedure,published_at:M.published_at,values:q.values})}I.push({submitted_at:u,values:a,field_values:R})}this.dispatch(d(p));const _=[];for(const b of I){const{field_values:R}=b,M=R.map(({asset:v})=>v),q=R.map(({fields_revision:v})=>v),U=R.map(({asset_procedure:v})=>v),z=R.map(({uuid:v})=>v),k=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:b,blockers:M.concat(q).concat(U),blocks:z});_.push(k)}return Promise.all(_).then(b=>{this.dispatch(l(b.flat()))}).catch(()=>{this.dispatch(r(V(p)))}),[p,_]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=n.getState(),l=c(e.uuid)(d);if(!l)throw new Error(`Expected AssetProcedureTypeFieldValues with uuid ${e.uuid} to exist`);const r={...l,...e};this.dispatch(a(r));const u=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[r.fields_revision,r.asset,r.asset_procedure],blocks:[r.uuid]});return u.then(h=>{this.dispatch(a(h))}).catch(()=>{this.dispatch(a(l))}),[r,u]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected submission with uuid ${e} to exist`);const u=bc(e)(l);this.dispatch(a(e)),this.dispatch(ls(V(u)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(c(r)),this.dispatch(us(u)),h}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset_procedure__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class NF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure");y(this,"url","/asset-procedures");y(this,"actions",{addOne:Nc,addMany:ys,setOne:Wc,setMany:Yc,updateOne:Gc,updateMany:Hc,deleteOne:Kc,deleteMany:ps,initialize:kc});y(this,"selectors",{selectById:Qc,selectByIds:xc})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[e.asset_procedure_type,e.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset procedure with uuid ${e} to exist`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{project:e}},n)).flat();return this.dispatch(a(d)),d}}class GF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Type");y(this,"url","/asset-procedure-types");y(this,"actions",{addOne:sd,addMany:id,setOne:rd,setMany:ud,updateOne:nd,updateMany:ad,deleteOne:cd,deleteMany:dd,initialize:td});y(this,"selectors",{selectById:hd,selectByIds:md})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`Expected asset procedure type with uuid ${e.uuid} to exist`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset procedure type with uuid ${e} to exist`);const u=Xc(e)(l);this.dispatch(a(e)),this.dispatch(ps(V(u)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(c(r)),this.dispatch(ys(u)),h}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{organization:e}},n);return this.dispatch(a(c)),c}}class HF extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Step Fields Attachment");y(this,"url","/asset-procedure-step-fields-attachments");y(this,"actions",{addOne:Ad,addMany:fd,setOne:Sd,setMany:Td,updateOne:Id,updateMany:Od,deleteOne:Pd,deleteMany:Fd,initialize:pd});y(this,"selectors",{selectById:_d,selectByIds:bd})}getId(e){return e.uuid}getBlockers(e){return[e.fields_revision]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,field_identifier:e.field_identifier,fields_revision:e.fields_revision,file_sha1:e.file_sha1,file_name:e.file_name,file_extension:e.file_extension}}buildBulkPayload(e){return{uuid:e.uuid,field_identifier:e.field_identifier,fields_revision:e.fields_revision,file_sha1:e.file_sha1,file_name:e.file_name,file_extension:e.file_extension}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{fields_revision__asset_procedure_step__organization:e}},n);return this.dispatch(a(c)),c}}class KF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Step Fields");y(this,"url","/asset-procedure-step-fields");y(this,"actions",{addOne:Ed,addMany:Bd,setOne:vd,setMany:Vd,updateOne:zd,updateMany:jd,deleteOne:Dd,deleteMany:qd,initialize:wd});y(this,"selectors",{selectById:$d,selectByIds:Cd})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_procedure_step],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(A=>{throw this.dispatch(d(u.uuid)),A}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,c=n.getState().assetProcedureStepFieldsReducer.instances[e.uuid];if(!c)throw new Error(`AssetProcedureStepFields with uuid ${e.uuid} not found`);const d={...c,...e};this.dispatch(a(d));const l=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${c.uuid}/`,payload:e,blockers:[c.uuid],blocks:[c.uuid]});return l.then(r=>{this.dispatch(a(r))}).catch(r=>{throw this.dispatch(a(c)),r}),[d,l]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,d=n.getState().assetProcedureStepFieldsReducer.instances[e];if(!d)throw new Error(`AssetProcedureStepFields with uuid ${e} not found`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[e]})}catch(l){throw this.dispatch(c(d)),l}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_step__asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class WF extends D{constructor(){super(...arguments);y(this,"name","Asset Procedure Step Field Values Attachment");y(this,"url","/asset-procedure-step-field-values-attachments");y(this,"actions",{addOne:Nd,addMany:Fs,setOne:Gd,setMany:Hd,updateOne:Kd,updateMany:Wd,deleteOne:Yd,deleteMany:gs,initialize:kd});y(this,"selectors",{selectById:Jd,selectByIds:Xd})}getId(e){return e.uuid}getBlockers(e){return[e.field_values]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}async bulkDelete(e){const{store:n}=this.client,{deleteMany:a,addMany:c}=this.actions,{selectByIds:d}=this.selectors,l=n.getState(),r=d(e)(l);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{field_values__asset_procedure__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class YF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Step Field Values");y(this,"url","/asset-procedure-step-field-values");y(this,"actions",{addOne:sr,addMany:ir,setOne:nr,setMany:ar,updateOne:cr,updateMany:dr,deleteOne:rr,deleteMany:ur,initialize:tr});y(this,"selectors",{selectById:or,selectByIds:hr})}add(e){var A;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,r=((A=n.getState().userReducer.currentUser)==null?void 0:A.id)??null,u=new Date().toISOString(),h=P({...e,created_by:r,submitted_at:u}),p=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(h),blockers:[e.asset,e.fields_revision,e.asset_procedure],blocks:[h.uuid]});return this.dispatch(a(h)),p.then(I=>{this.dispatch(c(I))}).catch(()=>{this.dispatch(d(h.uuid))}),[h,p]}bulkAdd(e,n){var w;const{payloads:a,values:c}=e,{addMany:d,setMany:l,deleteMany:r}=this.actions,u=new Date().toISOString(),h=((w=this.client.store.getState().userReducer.currentUser)==null?void 0:w.id)??null,p=[],A=it(a,Math.min(n??a.length,Qe)),I=[];for(const b of A){const R=[];for(const M of b){const q=P({...M,values:M.values,created_by:h,submitted_at:u});p.push(q),R.push({uuid:q.uuid,asset:M.asset,fields_revision:M.fields_revision,asset_procedure:M.asset_procedure,asset_procedure_step:M.asset_procedure_step,published_at:M.published_at,values:q.values})}I.push({submitted_at:u,values:c,field_values:R})}this.dispatch(d(p));const _=[];for(const b of I){const{field_values:R}=b,M=R.map(({asset:v})=>v),q=R.map(({fields_revision:v})=>v),U=R.map(({asset_procedure:v})=>v),z=R.map(({uuid:v})=>v),k=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:b,blockers:M.concat(q).concat(U),blocks:z});_.push(k)}return Promise.all(_).then(b=>{this.dispatch(l(b.flat()))}).catch(()=>{this.dispatch(r(V(p)))}),[p,_]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=n.getState(),l=c(e.uuid)(d);if(!l)throw new Error(`Expected AssetProcedureStepFieldValues with uuid ${e.uuid} to exist`);const r={...l,...e};this.dispatch(a(r));const u=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[r.fields_revision,r.asset,r.asset_procedure],blocks:[r.uuid]});return u.then(h=>{this.dispatch(a(h))}).catch(()=>{this.dispatch(a(l))}),[r,u]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected submission with uuid ${e} to exist`);const u=Qd(e)(l);this.dispatch(a(e)),this.dispatch(gs(V(u)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(c(r)),this.dispatch(Fs(u)),h}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset_procedure__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class ZF extends B{constructor(){super(...arguments);y(this,"name","Asset Procedure Step");y(this,"url","/asset-procedure-steps");y(this,"actions",{addOne:Sr,addMany:Tr,setOne:Ar,setMany:fr,updateOne:Ir,updateMany:Or,deleteOne:Pr,deleteMany:Fr,initialize:pr});y(this,"selectors",{selectById:_r,selectByIds:br})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_procedure_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`No asset procedure step with uuid ${e.uuid} found in the store`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${d.uuid}/`,payload:{name:e.name,description:e.description,priority:e.order,color:e.color},blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteMany:a,addMany:c,addOne:d,deleteOne:l}=this.actions,{selectById:r}=this.selectors,u=n.getState(),h=r(e)(u);if(!h)throw new Error(`No asset procedure step with uuid ${e} found in the store`);const p=Mr(e)(u);this.dispatch(l(e)),this.dispatch(a(V(p)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(A){throw this.dispatch(d(h)),this.dispatch(c(p)),A}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class JF extends B{constructor(){super(...arguments);y(this,"url","/assets");y(this,"name","Asset");y(this,"actions",{addOne:Er,addMany:Es,setOne:zr,setMany:jr,updateOne:Br,updateMany:vr,deleteOne:Vr,deleteMany:Bs,initialize:wr});y(this,"selectors",{selectById:$r,selectByIds:Cr})}add(e){var p;const{store:n}=this.client,{addOne:a,updateOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{updateOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{addOne:a,deleteOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`No asset with uuid ${e} found in the store`);const u=ga(e)(l),h=$y(e)(l);this.dispatch(c(e)),this.dispatch(ts(V(u))),this.dispatch(et(V(h)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(p){throw this.dispatch(a(r)),this.dispatch(es(u)),this.dispatch(xe(h)),p}}bulkAdd(e,n){const{addMany:a}=this.actions,c=new Date().toISOString(),d=Xe.v4(),l=it(e,Math.min(n??e.length,Qe)).map(h=>{const p=h.map(A=>P(A));return{batchId:Xe.v4(),payload:{transaction_id:d,submitted_at:c,assets:p}}}),r=[];let u=null;for(const h of l){const{batchId:p,payload:A}=h,I=A.assets.map(({uuid:M})=>M),_=A.assets.map(({asset_type:M})=>M),w=A.assets.map(({project:M})=>M),b=A.assets.map(({status:M})=>M),R=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:A,blockers:(u?[u]:[]).concat(_).concat(w).concat(b),blocks:[p].concat(I)});u=h.batchId,r.push(R)}return Promise.all(r).then(h=>{const p=h.flat();this.dispatch(a(p))}),r}bulkUpdate(e,n){const{store:a}=this.client,{updateMany:c}=this.actions,{selectByIds:d}=this.selectors,l=V(e).toSorted(It);if(l.length!==e.length)throw new Error("payloads contains duplicate uuids.");const r=d(l)(a.getState()).toSorted(Jt);if(l.length!=r.length)throw new Error(`Attempting to bulk update ${l.length-r.length} assets that dont exist in the store`);const u=[];for(let I=0;I<l.length;I++)u.push({...r[I],...e[I]});this.dispatch(c(u));const h=it(e,Math.min(n??e.length,Qe)),p=[];let A=null;for(const I of h){const _=Xe.v4(),w=V(I),b=I.map(({status:M})=>M).filter(Boolean),R=this.enqueueRequest({description:T(m.PATCH,this.name,!0),method:m.PATCH,url:`${this.url}/bulk/`,payload:{payloads:I},blockers:(A?[A]:[]).concat(w).concat(b),blocks:[_].concat(w)});p.push(R),A=_}return Promise.all(p).then(I=>{this.dispatch(c(I.flat()))}).catch(()=>{this.dispatch(c(r))}),[u,p]}async bulkDelete(e){const{store:n}=this.client,{addMany:a,deleteMany:c}=this.actions,{selectByIds:d}=this.selectors,l=n.getState(),r=d(e)(l);this.dispatch(c(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(a(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{project:e}},n)).flat();return this.dispatch(a(d)),d}}class XF extends B{constructor(){super(...arguments);y(this,"name","Asset Stage Completion");y(this,"url","/asset-stage-completions");y(this,"actions",{addOne:Nr,addMany:Gr,setOne:Hr,setMany:Kr,updateOne:Wr,updateMany:Yr,deleteOne:Zr,deleteMany:Jr,initialize:kr});y(this,"selectors",{selectById:eu,selectByIds:tu})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[e.asset,e.asset_stage],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=d(e)(n.getState());if(!l)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(c(l)),r}}bulkAdd(e){var I;const{store:n}=this.client,{addMany:a,setMany:c,deleteMany:d}=this.actions,l=new Date().toISOString(),r=((I=n.getState().userReducer.currentUser)==null?void 0:I.id)??null,u=e.map(_=>P(_)),h=u.map(_=>({..._,created_by:r,submitted_at:l})),p=h.map(({uuid:_})=>_);this.dispatch(a(h));const A=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:{submitted_at:l,completions:u},blockers:[...e.map(_=>_.asset_procedure),...e.map(_=>_.asset_stage),...e.map(_=>_.asset)],blocks:p});return A.then(_=>{this.dispatch(c(_))}).catch(()=>{this.dispatch(d(p))}),[h,A]}async bulkDelete(e){const{store:n}=this.client,{deleteMany:a,addMany:c}=this.actions,{selectByIds:d}=this.selectors,l=d(e)(n.getState());this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(r){throw this.dispatch(c(l)),r}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset_procedure__project:e}},n)).flat();return this.dispatch(a(d)),d}}class QF extends B{constructor(){super(...arguments);y(this,"name","Asset Stage");y(this,"url","/asset-stages");y(this,"actions",{addOne:cu,addMany:du,setOne:nu,setMany:au,updateOne:ru,updateMany:uu,deleteOne:lu,deleteMany:ou,initialize:iu});y(this,"selectors",{selectById:mu,selectByIds:yu})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_procedure_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${d.uuid}/`,payload:e,blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`No asset stage with uuid ${e} found in the store`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_procedure_type__organization:e}},n);return this.dispatch(a(c)),c}}class xF extends D{constructor(){super(...arguments);y(this,"name","Asset Type Attachment");y(this,"url","/asset-type-attachments");y(this,"actions",{addOne:fu,addMany:qs,setOne:Su,setMany:Tu,updateOne:Iu,updateMany:Ou,deleteOne:Pu,deleteMany:$s,initialize:Au});y(this,"selectors",{selectById:gu,selectByIds:_u})}getId(e){return e.uuid}getBlockers(e){return[e.asset_type]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_type:e.asset_type}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_type:e.asset_type}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class eg extends D{constructor(){super(...arguments);y(this,"name","Asset Type Fields Attachment");y(this,"url","/asset-type-fields-attachments");y(this,"actions",{addOne:Eu,addMany:Bu,setOne:vu,setMany:Vu,updateOne:zu,updateMany:ju,deleteOne:Du,deleteMany:qu,initialize:wu});y(this,"selectors",{selectById:Cu,selectByIds:Uu})}getId(e){return e.uuid}getBlockers(e){return[e.fields_revision]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,fields_revision:c,file_sha1:d,file_name:l,file_extension:r}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{fields_revision__asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class tg extends B{constructor(){super(...arguments);y(this,"name","Asset Type Fields");y(this,"url","/asset-type-fields");y(this,"actions",{addOne:Gu,addMany:Hu,setOne:Ku,setMany:Wu,updateOne:Yu,updateMany:Zu,deleteOne:Ju,deleteMany:Xu,initialize:Nu});y(this,"selectors",{selectById:xu,selectByIds:el})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(A=>{throw this.dispatch(d(u.uuid)),A}),[u,h]}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class sg extends D{constructor(){super(...arguments);y(this,"name","Asset Type Field Values Attachment");y(this,"url","/asset-type-field-values-attachments");y(this,"actions",{addOne:nl,addMany:Gs,setOne:al,setMany:cl,updateOne:dl,updateMany:rl,deleteOne:ul,deleteMany:Hs,initialize:il});y(this,"selectors",{selectById:ol,selectByIds:hl})}getId(e){return e.uuid}getBlockers(e){return[e.field_values]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}buildBulkPayload(e){const{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}=e;return{uuid:n,field_identifier:a,field_values:c,file_sha1:d,file_name:l,file_extension:r}}async bulkDelete(e){const{store:n}=this.client,{deleteMany:a,addMany:c}=this.actions,{selectByIds:d}=this.selectors,l=n.getState(),r=d(e)(l);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!0),method:m.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{field_values__asset__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class ig extends B{constructor(){super(...arguments);y(this,"name","Asset Type Field Values");y(this,"url","/asset-type-field-values");y(this,"actions",{addOne:fl,addMany:Sl,setOne:Tl,setMany:Il,updateOne:Ol,updateMany:Pl,deleteOne:Fl,deleteMany:gl,initialize:Al});y(this,"selectors",{selectById:bl,selectByIds:Ml})}add(e){var A;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,r=((A=n.getState().userReducer.currentUser)==null?void 0:A.id)??null,u=new Date().toISOString(),h=P({...e,created_by:r,submitted_at:u}),p=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(h),blockers:[e.asset,e.fields_revision],blocks:[h.uuid]});return this.dispatch(a(h)),p.then(I=>{this.dispatch(c(I))}).catch(()=>{this.dispatch(d(h.uuid))}),[h,p]}bulkAdd(e,n){var _;const{payloads:a,values:c}=e,{addMany:d,setMany:l,deleteMany:r}=this.actions,u=new Date().toISOString(),h=[],p=it(a,Math.min(n??a.length,Qe)),A=[];for(const w of p){const b=[];for(const R of w){const M=P({...R,values:R.values,created_by:((_=this.client.store.getState().userReducer.currentUser)==null?void 0:_.id)??null,submitted_at:u});h.push(M),b.push({uuid:M.uuid,asset:R.asset,fields_revision:R.fields_revision,published_at:R.published_at,values:M.values})}A.push({submitted_at:u,values:c,field_values:b})}this.dispatch(d(h));const I=[];for(const w of A){const{field_values:b}=w,R=b.map(({asset:z})=>z),M=b.map(({fields_revision:z})=>z),q=b.map(({uuid:z})=>z),U=this.enqueueRequest({description:T(m.POST,this.name,!0),method:m.POST,url:`${this.url}/bulk/`,payload:w,blockers:R.concat(M),blocks:q});I.push(U)}return Promise.all(I).then(w=>{this.dispatch(l(w.flat()))}).catch(()=>{this.dispatch(r(V(h)))}),[h,I]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=n.getState(),l=c(e.uuid)(d);if(!l)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const r={...l,...e};this.dispatch(a(r));const u=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[r.uuid,r.fields_revision,r.asset],blocks:[r.uuid]});return u.then(h=>{this.dispatch(a(h))}).catch(()=>{this.dispatch(a(l))}),[r,u]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected submission with uuid ${e} to exist`);const u=ml(e)(l);this.dispatch(a(e)),this.dispatch(Hs(V(u)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(h){throw this.dispatch(c(r)),this.dispatch(Gs(u)),h}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class ng extends B{constructor(){super(...arguments);y(this,"name","Asset Type Identifier");y(this,"url","/asset-type-identifiers");y(this,"actions",{addOne:Bl,addMany:vl,setOne:Vl,setMany:zl,updateOne:jl,updateMany:Dl,deleteOne:ql,deleteMany:$l,initialize:El});y(this,"selectors",{selectById:Ul,selectByIds:Ll})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[u.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`Expected asset type identifier with uuid ${e.uuid} to exist`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset type identifier with uuid ${e} to exist`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class ag extends B{constructor(){super(...arguments);y(this,"name","Asset Type Identifier Value");y(this,"url","/asset-type-identifier-values");y(this,"actions",{addOne:Hl,addMany:Kl,setOne:Wl,setMany:Yl,updateOne:Zl,updateMany:Jl,deleteOne:Xl,deleteMany:Ql,initialize:Gl});y(this,"selectors",{selectById:eo,selectByIds:to})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[e.asset,e.asset_type_identifier],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset type identifier value with uuid ${e} to exist`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(r)),u}}async refreshStore(e,n){const{initialize:a}=this.actions,d=(await this.listPaginated({queryParams:{asset__project:e,latest:!0}},n)).flat();return this.dispatch(a(d)),d}}class cg extends B{constructor(){super(...arguments);y(this,"name","Asset Type");y(this,"url","/asset-types");y(this,"actions",{addOne:ro,addMany:uo,setOne:ao,setMany:co,updateOne:lo,updateMany:oo,deleteOne:ho,deleteMany:mo,initialize:no});y(this,"selectors",{selectById:po,selectByIds:Ao})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{setOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[d.uuid],blocks:[d.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=n.getState(),r=d(e)(l);if(!r)throw new Error(`Expected asset type with uuid ${e} to exist`);const u=qr(e)(l),h=bu(e)(l);this.dispatch(a(e)),this.dispatch(Bs(V(u))),this.dispatch($s(V(h)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(p){throw this.dispatch(c(r)),this.dispatch(Es(u)),this.dispatch(qs(h)),p}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{organization:e}},n);return this.dispatch(a(c)),c}}class dg extends B{constructor(){super(...arguments);y(this,"name","Asset Type Status");y(this,"url","/asset-type-statuses");y(this,"actions",{addOne:Io,addMany:Oo,setOne:Po,setMany:Fo,updateOne:go,updateMany:_o,deleteOne:bo,deleteMany:Mo,initialize:To});y(this,"selectors",{selectById:wo,selectByIds:Eo})}add(e){var p;const{store:n}=this.client,{addOne:a,setOne:c,deleteOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:[e.asset_type],blocks:[u.uuid]});return h.then(A=>{this.dispatch(c(A))}).catch(()=>{this.dispatch(d(u.uuid))}),[u,h]}update(e){const{setOne:n}=this.actions,{selectById:a}=this.selectors,c=this.client.store.getState(),d=a(e.uuid)(c);if(!d)throw new Error(`Expected an existing asset type status with uuid ${e.uuid}`);const l={...d,...e};this.dispatch(n(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(n(u))}).catch(()=>{this.dispatch(n(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c}=this.actions,{selectById:d}=this.selectors,l=d(e)(n.getState());if(!l)throw new Error(`No asset type status with uuid ${e} found in the store`);this.dispatch(a(e));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(c(l)),r}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(a(c)),c}}class rg extends D{constructor(){super(...arguments);y(this,"name","Document Attachment");y(this,"url","/document-attachments");y(this,"actions",{addOne:qo,addMany:$o,setOne:Co,setMany:Uo,updateOne:Lo,updateMany:ko,deleteOne:No,deleteMany:Go,initialize:Do});y(this,"selectors",{selectById:Ko,selectByIds:Wo})}getId(e){return e.uuid}getBlockers(e){return[e.document]}getBlocks(e){return[e.uuid]}buildModel(e){var d;const{store:n}=this.client,a=((d=n.getState().userReducer.currentUser)==null?void 0:d.id)??null,c=new Date().toISOString();return P({...e,created_by:a,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,document:e.document}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,document:e.document}}async bulkAdd(e,n){const[a,c,d]=await super.bulkAdd(e,n),l={};for(const{file_sha1:r,uuid:u}of a)r in l||(l[r]=[]),l[r].push(u);return d.then(r=>{const u=r.flatMap(h=>l[h]??[]);for(const h of u)this.makeReadable(h)}),[a,c,d]}makeReadable(e){this.enqueueRequest({description:"Add attachment to AI assistant",method:m.PATCH,url:`${this.url}/${e}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",e],blocks:["index-document-attachment"]})}async refreshStore(e,n){const{initialize:a}=this.actions,c=this.list({queryParams:{document__project__organization:e}},n),d=this.list({queryParams:{document__organization:e}},n),r=(await Promise.all([c,d])).flat();return this.dispatch(a(r)),r}}class ug extends B{constructor(){super(...arguments);y(this,"name","Document");y(this,"url","/documents");y(this,"actions",{addOne:Xo,addMany:Qo,setOne:xo,setMany:eh,updateOne:th,updateMany:sh,deleteOne:ih,deleteMany:nh,initialize:Jo});y(this,"selectors",{selectById:ch,selectByIds:dh})}add(e){var p;const{store:n}=this.client,{addOne:a,deleteOne:c,updateOne:d}=this.actions,l=((p=n.getState().userReducer.currentUser)==null?void 0:p.id)??null,r=new Date().toISOString(),u=P({...e,created_by:l,submitted_at:r});this.dispatch(a(u));const h=this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:E(u),blockers:u.parent_document?[u.parent_document]:[],blocks:[u.uuid]});return h.then(A=>{this.dispatch(d(A))}).catch(()=>{this.dispatch(c(u.uuid))}),[u,h]}update(e){const{store:n}=this.client,{updateOne:a}=this.actions,{selectById:c}=this.selectors,d=c(e.uuid)(n.getState());if(!d)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const l={...d,...e};this.dispatch(a(l));const r=this.enqueueRequest({description:T(m.PATCH,this.name,!1),method:m.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(a(u))}).catch(()=>{this.dispatch(a(d))}),[l,r]}async delete(e){const{store:n}=this.client,{deleteOne:a,addOne:c,addMany:d,deleteMany:l}=this.actions,{selectById:r}=this.selectors,u=n.getState(),h=r(e)(u);if(!h)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const p=rh(e)(u);this.dispatch(a(e)),this.dispatch(l(V(p)));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(A){throw this.dispatch(c(h)),this.dispatch(d(p)),A}}async refreshStore(e,n){const{initialize:a}=this.actions,c=this.list({queryParams:{project__organization:e}},n),d=this.list({queryParams:{organization:e}},n),r=(await Promise.all([c,d])).flat();return this.dispatch(a(r)),r}}class dt extends st{async get(s,e){return this.performRequest({url:`${this.url}/${s}/`,method:m.GET},e)}async list(s,e){return this.performRequest({url:`${this.url}/`,method:m.GET,...s},e)}async listPaginated(s,e){return this.performPagination({url:`${this.url}/`,method:m.GET,...s},e)}}class lg extends dt{constructor(){super(...arguments);y(this,"name","Email Domains");y(this,"url","/organization-email-domains");y(this,"actions",{addOne:oh,addMany:hh,setOne:mh,setMany:yh,updateOne:ph,updateMany:Ah,deleteOne:fh,deleteMany:Sh,initialize:lh});y(this,"selectors",{selectById:Ih,selectByIds:Oh})}async add(e,n){return this.enqueueRequest({description:T(m.POST,this.name,!1),method:m.POST,url:`${this.url}/`,payload:{email:n,organization:e},blockers:[e,"create-org"],blocks:[]})}async delete(e){const{deleteOne:n,addOne:a}=this.actions;this.dispatch(n(e.uuid));try{return await this.enqueueRequest({description:T(m.DELETE,this.name,!1),method:m.DELETE,url:`${this.url}/${e.uuid}/`,blockers:[e.domain],blocks:[]})}catch(c){throw this.dispatch(a(e)),c}}async refreshStore(e,n){const{initialize:a}=this.actions,c=await this.list({queryParams:{organization:e}},n);return this.dispatch(a(c)),c}}class og extends st{async getVerificationCode(s){return this.enqueueRequest({description:"Get verification code",method:m.GET,url:`/verification/email-verification/${s}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(s,e=void 0){return this.enqueueRequest({description:"Validate verification code",method:m.POST,url:`/verification/email-verification/${s}/`,isAuthNeeded:!1,payload:e,blockers:[],blocks:[]})}}const At={},jn=new Set;class hg extends st{constructor(){super(...arguments);y(this,"host");y(this,"dbPromise",pO.openDB("fileCache",1,{upgrade(e){e.createObjectStore("files")}}))}async getDB(){return await this.dbPromise}async addCache(e){if(!e.name)throw new Error(`Cant add a file without a name to cache: ${e.name}`);if(!e.type)throw new Error(`Cant add a file without a type to cache: ${e.name}`);if(!e.size)throw new Error(`Cant add an empty file to cache: ${e.name}`);const n=await Tt(e);if(jn.has(n))return;const a=await this.getDB();!!await a.get("files",n)?console.warn(`Attempting to add a file already cached, ${e.name}`):await a.put("files",e,n),jn.add(n)}async removeCache(e){await(await this.getDB()).delete("files",e),jn.delete(e)}async fetchCache(e){return(await this.getDB()).get("files",e)}async getPresignedUploadUrl(e){const{sha1:n,file_type:a,size:c,extension:d}=await this.getFilePayload(e),l=Yt(n,d),r={sha1:n,file_type:a,extension:d,size:c};return await this.enqueueRequest({description:"Create S3 upload url",method:m.POST,url:"/authentication/files/presigned-upload-url/",payload:r,blockers:[],blocks:[`s3-${l}`]})}async uploadFileToS3(e){const n=await this.fetchCache(e);if(!n)throw new Error(`File with sha1 ${e} not found in cache`);const a=Yt(e,Zt(n)),c={file_name:n.name,file_sha1:e,file:a},d=await this.getPresignedUploadUrl(n);if("warning"in d){if(d.warning==="already_uploaded")return[c,Promise.resolve(void 0)];throw new Error(d.warning)}const l=d.url,r=this.enqueueRequest({url:l,description:"Upload file",method:m.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:e,blockers:[`s3-${a}`],blocks:[e],s3url:d});return[c,r]}async fetchFileFromUrl(e,n,a=n){const c=e.split("?")[0]??e,d=await this.fetchCache(n);if(d)return d;let l;c in At?l=At[c]:Qn(e)?(l=Xn(e,a),At[c]=l):(l=new Promise(h=>{this.performRequest({method:m.GET,url:e,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1}).then(p=>{const A=new File([p],a,{type:p.type});h(A)})}),At[c]=l);let r;try{r=await l}catch(h){throw h instanceof C&&delete At[c],h}const u=await Tt(r);if(u!==n){const h=`The hash of the file returned from the server (${u}) does not match the
8
8
  expected hash (${n}). This can happen if you're using a local development server and the
9
9
  isExternalUrl flag in the request details is set to true, because instead of requesting the local
10
10
  REST API, you will be requesting localhost:80 (where this app runs), resulting in a transformed blob
@@ -22,6 +22,7 @@ export declare abstract class AssetProcedureStepFieldValuesAttachmentService<TSt
22
22
  };
23
23
  protected getId(model: Stored<AssetProcedureStepFieldValuesAttachment>): string;
24
24
  protected getBlockers(payload: UUID<Omit<Payload<AssetProcedureStepFieldValuesAttachment>, "file_type" | "file_url">>): string[];
25
+ protected getBlocks(model: Stored<AssetProcedureStepFieldValuesAttachment>): string[];
25
26
  protected buildModel(data: Payload<AssetProcedureStepFieldValuesAttachment>): Submitted<AssetProcedureStepFieldValuesAttachment>;
26
27
  protected buildPayload(model: Submitted<AssetProcedureStepFieldValuesAttachment>): object;
27
28
  protected buildBulkPayload(model: Submitted<AssetProcedureStepFieldValuesAttachment>): object;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overmap-ai/core",
3
- "version": "1.0.78-attachment-model-improvements.11",
3
+ "version": "1.0.78-attachment-model-improvements.12",
4
4
  "description": "Core functionality for Overmap",
5
5
  "keywords": [
6
6
  "components",