@overmap-ai/core 1.0.78-view-sets.35 → 1.0.78-view-sets.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/overmap-core.js +56 -44
- package/dist/overmap-core.umd.cjs +1 -1
- package/dist/sdk/services/AssetProcedureAttachmentService.d.ts +1 -1
- package/dist/sdk/services/AssetProcedureFieldsAttachmentService.d.ts +1 -1
- package/dist/sdk/services/AssetProcedureFieldsService.d.ts +1 -1
- package/dist/sdk/services/AssetProcedureStepFieldsAttachmentService.d.ts +1 -1
- package/package.json +1 -1
package/dist/overmap-core.js
CHANGED
|
@@ -3406,18 +3406,21 @@ class $S extends Ce {
|
|
|
3406
3406
|
async delete(s) {
|
|
3407
3407
|
return this._delete(s);
|
|
3408
3408
|
}
|
|
3409
|
-
async refreshStore(s) {
|
|
3410
|
-
const
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3409
|
+
async refreshStore(s, i) {
|
|
3410
|
+
const a = await this.enqueueRequest(
|
|
3411
|
+
{
|
|
3412
|
+
description: "Get asset procedure attachments",
|
|
3413
|
+
method: u.GET,
|
|
3414
|
+
url: `${this.url}/`,
|
|
3415
|
+
queryParams: {
|
|
3416
|
+
asset_procedure__organization: s
|
|
3417
|
+
},
|
|
3418
|
+
blocks: [],
|
|
3419
|
+
blockers: []
|
|
3416
3420
|
},
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
return this.dispatch(gc(i)), i;
|
|
3421
|
+
i
|
|
3422
|
+
);
|
|
3423
|
+
return this.dispatch(gc(a)), a;
|
|
3421
3424
|
}
|
|
3422
3425
|
}
|
|
3423
3426
|
class GS extends z {
|
|
@@ -3471,18 +3474,21 @@ class GS extends z {
|
|
|
3471
3474
|
);
|
|
3472
3475
|
}), [n, d.then(({ attachments: c }) => c)];
|
|
3473
3476
|
}
|
|
3474
|
-
async refreshStore(e) {
|
|
3475
|
-
const
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3477
|
+
async refreshStore(e, s) {
|
|
3478
|
+
const i = await this.enqueueRequest(
|
|
3479
|
+
{
|
|
3480
|
+
description: "Get asset procedure fields attachments",
|
|
3481
|
+
method: u.GET,
|
|
3482
|
+
url: "/asset-procedure-fields-attachments/",
|
|
3483
|
+
queryParams: {
|
|
3484
|
+
fields_revision__asset_procedure__organization: e
|
|
3485
|
+
},
|
|
3486
|
+
blockers: [],
|
|
3487
|
+
blocks: []
|
|
3481
3488
|
},
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
return this.dispatch(wc(s)), s;
|
|
3489
|
+
s
|
|
3490
|
+
);
|
|
3491
|
+
return this.dispatch(wc(i)), i;
|
|
3486
3492
|
}
|
|
3487
3493
|
}
|
|
3488
3494
|
class BS extends w {
|
|
@@ -3508,18 +3514,21 @@ class BS extends w {
|
|
|
3508
3514
|
throw this.dispatch(Vc(n.uuid)), l;
|
|
3509
3515
|
}), [n, r];
|
|
3510
3516
|
}
|
|
3511
|
-
async refreshStore(e) {
|
|
3512
|
-
const
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3517
|
+
async refreshStore(e, s) {
|
|
3518
|
+
const i = await this.enqueueRequest(
|
|
3519
|
+
{
|
|
3520
|
+
description: "Get Asset Procedure Fields",
|
|
3521
|
+
method: u.GET,
|
|
3522
|
+
url: "/asset-procedure-fields/",
|
|
3523
|
+
queryParams: {
|
|
3524
|
+
asset_procedure__organization: e
|
|
3525
|
+
},
|
|
3526
|
+
blockers: [],
|
|
3527
|
+
blocks: []
|
|
3518
3528
|
},
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
return this.dispatch(Uc(s)), s;
|
|
3529
|
+
s
|
|
3530
|
+
);
|
|
3531
|
+
return this.dispatch(Uc(i)), i;
|
|
3523
3532
|
}
|
|
3524
3533
|
}
|
|
3525
3534
|
function $e(t, e) {
|
|
@@ -3995,18 +4004,21 @@ class KS extends z {
|
|
|
3995
4004
|
);
|
|
3996
4005
|
}), [n, d.then(({ attachments: c }) => c)];
|
|
3997
4006
|
}
|
|
3998
|
-
async refreshStore(e) {
|
|
3999
|
-
const
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4007
|
+
async refreshStore(e, s) {
|
|
4008
|
+
const i = await this.enqueueRequest(
|
|
4009
|
+
{
|
|
4010
|
+
description: "Get asset procedure step fields attachments",
|
|
4011
|
+
method: u.GET,
|
|
4012
|
+
url: "/asset-procedure-step-fields-attachments/",
|
|
4013
|
+
queryParams: {
|
|
4014
|
+
fields_revision__asset_procedure_step__organization: e
|
|
4015
|
+
},
|
|
4016
|
+
blockers: [],
|
|
4017
|
+
blocks: []
|
|
4005
4018
|
},
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
return this.dispatch(oo(s)), s;
|
|
4019
|
+
s
|
|
4020
|
+
);
|
|
4021
|
+
return this.dispatch(oo(i)), i;
|
|
4010
4022
|
}
|
|
4011
4023
|
}
|
|
4012
4024
|
class YS extends w {
|
|
@@ -5,7 +5,7 @@ Retries:`,a),!(t instanceof Error))throw console.error("ENCOUNTERED NON-ERROR ER
|
|
|
5
5
|
Action:`,e);const p=Ge();if(!p)throw new Error("Outbox coordinator not set");p.remove(e.payload.uuid),t.options.discard=!0,l()}}console.debug("Registering a retry for request:",e.payload.uuid);const m=Ge();if(!m)throw new Error("Outbox coordinator not set");return m.registerRetry(e.payload.uuid),!1}function cb(t,e,a){var i;return(i=Ge())==null?void 0:i.peek()}function nb(t,e){return ot().dispatch(Xl(new Date().getTime())),fc}const Ye="An unknown error occurred",rb=500,dm=["non_field_errors","detail"];function db(t,e){let a;if(t!=null&&t.body)if(typeof t.body=="object"){const i=t.body;if(typeof i.error=="string")a=i.error;else if(typeof i.message=="string")a=i.message;else try{a=Object.entries(i).map(([c,n])=>typeof n=="string"?dm.includes(c)?n:`${c}: ${n}`:Array.isArray(n)?dm.includes(c)?n.join(`
|
|
6
6
|
`):n.map(r=>`${c}: ${r}`).join(`
|
|
7
7
|
`):`${c}: ${JSON.stringify(n)}`).join(`
|
|
8
|
-
`)}catch(c){console.error("Failed to extract error message from response body",c)}}else typeof t.body=="string"&&(a=t.body);else t!=null&&t.text?a=t.text:e instanceof Error&&(a=e.message);return!a||a.length>rb?Ye:a}class D extends Error{constructor(a){super(Ye);S(this,"status");S(this,"response");S(this,"message");S(this,"options");const{response:i,innerError:c}=a;this.message=a.message??db(i,c)??Ye,this.status=(i==null?void 0:i.status)??0,this.response=i,a.discard=a.discard??!1,this.options=a}}class ub extends xh{constructor(e){super(e)}}class v extends xh{constructor(a,i){super(a);S(this,"auth");this.auth=i}}class ob extends v{async startConversation(e,a){return this.enqueueRequest({description:"Start agent conversation",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:a},blockers:["prompt"],blocks:["prompt"]}).then(i=>(this.dispatch(vc(i)),i))}async continueConversation(e,a,i){return this.enqueueRequest({description:"Prompt agent",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:i},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:a}}).then(c=>{this.dispatch(Mc(c))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:h.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(a=>{this.dispatch(wc(a))})}async rate(e,a){return this.enqueueRequest({description:"Rate agent response",method:h.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:a},blockers:["rate"],blocks:["rate"]})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get agent conversation history",method:h.GET,url:"/agents/conversations/",queryParams:{project:e},blockers:["agent-conversations"],blocks:["agent-conversations"]},a);return this.dispatch(Rc(i)),i}}const lb=5e4,E=1e3,hb="limit";class q extends v{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:a,assetAttachmentReducer:i,assetTypeAttachmentReducer:c,documentAttachmentReducer:n,projectAttachmentReducer:r,formRevisionAttachmentReducer:l,formSubmissionAttachmentReducer:m,geoImageReducer:u,assetTypeFieldsAttachmentReducer:o,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:A,issueTypeFieldValuesAttachmentReducer:y}=this.client.store.getState();return[].concat(Object.values(a.instances),Object.values(i.instances),Object.values(c.instances),Object.values(n.instances),Object.values(r.instances),Object.values(l.instances),Object.values(m.instances),Object.values(u.instances),Object.values(o.instances),Object.values(p.instances),Object.values(A.instances),Object.values(y.instances)).filter(P=>P.file_sha1===e).length}processPresignedUrls(e){const a={};for(const[i,c]of Object.entries(e))a[i]=this.enqueueRequest({url:c.url,description:"Upload file to S3",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:i,blockers:[`s3-${c.fields.key}`],blocks:[i],s3url:c});return a}async getFilePayload(e){const a=await He(e),i={sha1:a,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,a),i}}class ke extends q{async _bulkAdd(e){var u;const{store:a}=this.client,i=(u=a.getState().userReducer.currentUser)==null?void 0:u.id,c=new Date().toISOString(),n=[],r=[],l={};for(const o of e){const{modelUuid:p,file:A}=o,y=await this.getFilePayload(A);y.sha1 in l||(l[y.sha1]=y);const b=this.buildOfflineAttachment({file:A,file_sha1:y.sha1,submitted_at:c,created_by:i,description:"",modelUuid:p});n.push(b),r.push(this.buildAttachmentPayload({uuid:b.uuid,file_name:b.file_name,file_sha1:b.file_sha1,file_extension:y.extension,description:b.description,modelUuid:p}))}this.dispatch(this.addAttachments(n));const m=this.enqueueRequest({description:`Add ${this.name}`,method:h.POST,url:`${this.url}/bulk/`,payload:{submitted_at:c,attachments:r,files:Object.values(l)},blocks:n.map(o=>o.uuid),blockers:n.map(o=>o.file_sha1)});return m.then(({attachments:o,presigned_urls:p})=>{this.dispatch(this.updateAttachments(o)),this.processPresignedUrls(p)}).catch(()=>{this.dispatch(this.removeAttachments(n.map(o=>o.uuid)))}),[n,m.then(({attachments:o})=>o)]}async _delete(e){const{store:a}=this.client,i=this.selectAttachment(e)(a.getState());if(!i)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(i.uuid));const c=this.enqueueRequest({description:`Delete ${this.name}`,method:h.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return c.then(()=>{this.getNumberOfAttachmentsWithSha1(i.file_sha1)===0&&this.client.files.removeCache(i.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(i))}),c}}class mb extends ke{constructor(){super(...arguments);S(this,"name","Asset Attachment");S(this,"url","/asset-attachments");S(this,"initializeAttachments",Qt);S(this,"addAttachments",xt);S(this,"updateAttachments",Vc);S(this,"removeAttachments",es);S(this,"removeAttachment",zc);S(this,"setAttachment",qc);S(this,"selectAttachment",Cc)}buildOfflineAttachment(a){return T({file:URL.createObjectURL(a.file),file_sha1:a.file_sha1,created_by:a.created_by,file_name:a.file.name,file_type:a.file.type,submitted_at:a.submitted_at,description:a.description,asset:a.modelUuid})}buildAttachmentPayload(a){return{...a,asset:a.modelUuid}}async bulkAdd(a){return this._bulkAdd(a.map(i=>({modelUuid:i.assetUuid,file:i.file})))}async delete(a){return this._delete(a)}async refreshStore(a,i){const n=(await this.performPagination({immediate:!0,description:"Get asset attachments",method:h.GET,url:`${this.url}/`,queryParams:{limit:E,paginate:!0,asset__project:a},blocks:[],blockers:[]},r=>({immediate:!0,description:"Get asset attachments",method:h.GET,url:r,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Qt(n)),n}}class pb extends ke{constructor(){super(...arguments);S(this,"name","Asset Procedure Attachment");S(this,"url","/asset-procedure-attachments");S(this,"addAttachments",Lc);S(this,"updateAttachments",Hc);S(this,"removeAttachments",Yc);S(this,"removeAttachment",Wc);S(this,"setAttachment",Nc);S(this,"selectAttachment",Jc)}buildOfflineAttachment(a){return T({file:URL.createObjectURL(a.file),file_sha1:a.file_sha1,created_by:a.created_by,file_name:a.file.name,file_type:a.file.type,submitted_at:a.submitted_at,description:a.description,asset_procedure:a.modelUuid})}buildAttachmentPayload(a){return{...a,asset_procedure:a.modelUuid}}async bulkAdd(a){return this._bulkAdd(a.map(i=>({modelUuid:i.assetProcedureUuid,file:i.file})))}async delete(a){return this._delete(a)}async refreshStore(a){const i=await this.enqueueRequest({description:"Get asset procedure attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset_procedure__organization:a},blocks:[],blockers:[]});return this.dispatch($c(i)),i}}class Ab extends q{async bulkAdd(e){var m;const a=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:o,submitted_at:a,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(P)}this.dispatch(en(n));const l=this.enqueueRequest({description:"Add asset procedure fields attachments",method:h.POST,url:"/asset-procedure-fields-attachments/bulk/",payload:{submitted_at:a,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return l.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(tn(u.attachments))}).catch(()=>{this.dispatch(sn(n.map(u=>u.uuid)))}),[n,l.then(({attachments:u})=>u)]}async refreshStore(e){const a=await this.enqueueRequest({description:"Get asset procedure fields attachments",method:h.GET,url:"/asset-procedure-fields-attachments/",queryParams:{fields_revision__asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(xc(a)),a}}class yb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(un(n));const r=this.enqueueRequest({description:"Add Asset Procedure Fields",method:h.POST,url:"/asset-procedure-fields/",payload:w(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(on(m))}).catch(m=>{throw this.dispatch(ln(n.uuid)),m}),[n,r]}async refreshStore(e){const a=await this.enqueueRequest({description:"Get Asset Procedure Fields",method:h.GET,url:"/asset-procedure-fields/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]});return this.dispatch(dn(a)),a}}function $e(t,e){const a=[];let i=0;const c=t.length;for(;i<c;)a.push(t.slice(i,i+=e));return a}class fb extends q{async bulkAdd(e,a){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=$e(e,a??e.length),r=[],l=[];for(const o of n){const p={},A=[];for(const y of o){const{fieldValuesUuid:b,fieldIdentifier:P,file:_}=y,R=await this.getFilePayload(_);R.sha1 in p||(p[R.sha1]=R);const z=T({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:R.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(z);const De={uuid:z.uuid,file_name:_.name,file_sha1:R.sha1,file_extension:R.extension,field_identifier:P,field_values:b};A.push(De)}l.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(mt(r));const m=l.map(o=>this.enqueueRequest({description:"Add asset procedure field values attachments",method:h.POST,url:"/asset-procedure-field-values-attachments/bulk/",payload:o,blockers:o.attachments.map(p=>p.field_values),blocks:o.attachments.map(p=>p.uuid)}));return Promise.all(m).then(o=>{for(const A of o)this.processPresignedUrls(A.presigned_urls);const p=o.flatMap(A=>A.attachments);this.dispatch(yn(p))}).catch(o=>{throw this.dispatch(pt(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:a}=this.client,i=a.getState(),c=Sn(e)(i);this.dispatch(pt(e));try{await this.enqueueRequest({description:"Delete asset procedure field values attachments",method:h.DELETE,url:"/asset-procedure-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(mt(c)),n}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure field values attachments",method:h.GET,url:"/asset-procedure-field-values-attachments/",queryParams:{limit:E,paginate:!0,field_values__asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure field values attachments",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(An(c)),c}}class Sb extends v{add(e){var r;const{store:a}=this.client,i=a.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/",payload:w(c),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[c.uuid]});return this.dispatch(ds(c)),n.then(l=>(this.dispatch(Je(l)),l)).catch(()=>{this.dispatch(us(c.uuid))}),[c,n]}bulkAdd(e,a){var m;const i=new Date().toISOString(),c=[],n=$e(e.payloads,a??e.payloads.length),r=[];for(const u of n){const o=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),o.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure_instance:p.asset_procedure_instance,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:o})}this.dispatch(Tn(c));const l=[];for(const u of r){const o=u.field_values.map(P=>P.asset),p=u.field_values.map(P=>P.fields_revision),A=u.field_values.map(P=>P.asset_procedure_instance),y=u.field_values.map(P=>P.uuid),b=this.enqueueRequest({description:"Bulk add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/bulk/",payload:u,blockers:[...o,...p,...A],blocks:y});l.push(b)}return Promise.all(l).then(u=>{this.dispatch(In(u.flat()))}).catch(()=>{this.dispatch(On(c.map(u=>u.uuid)))}),[c,l]}update(e){const{store:a}=this.client,i=a.getState(),c=ls(e.uuid)(i);if(!c)throw new Error(`Expected AssetProcedureFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(Je(n));const r=this.enqueueRequest({description:"Update asset procedure field values",method:h.PATCH,url:`/asset-procedure-field-values/${e.uuid}/`,payload:e,blockers:[n.fields_revision,n.asset,n.asset_procedure_instance],blocks:[n.uuid]});return r.then(l=>{this.dispatch(Je(l))}).catch(()=>{this.dispatch(Je(c))}),[n,r]}async delete(e){const{store:a}=this.client,i=a.getState(),c=ls(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=gn(e)(i);this.dispatch(us(e)),this.dispatch(pt(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure field values",method:h.DELETE,url:`/asset-procedure-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ds(c)),this.dispatch(mt(n)),r}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure field values",method:h.GET,url:"/asset-procedure-field-values/",queryParams:{limit:E,paginate:!0,asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure field values",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(Fn(c)),c}}class gb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(ms(n));const r=this.enqueueRequest({description:"Create asset procedure instance",method:h.POST,url:"/asset-procedure-instances/",payload:w(n),blockers:[e.asset_procedure,e.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Xe(m))}).catch(()=>{this.dispatch(ps(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=fs(e.uuid)(a.getState());if(!i)throw new Error(`Expected asset procedure instance with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(Xe(c));const n=this.enqueueRequest({description:"Update asset procedure instance",method:h.PATCH,url:`/asset-procedure-instances/${e.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Xe(r))}).catch(()=>{this.dispatch(Xe(i))}),[c,n]}async remove(e){const{store:a}=this.client,i=a.getState(),c=fs(e)(i);if(!c)throw new Error(`Expected asset procedure instance with uuid ${e} to exist`);return this.dispatch(ps(e)),this.enqueueRequest({description:"Delete asset procedure instance",method:h.DELETE,url:`/asset-procedure-instances/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(ms(c)),n})}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure instances",method:h.GET,url:"/asset-procedure-instances/",queryParams:{limit:E,paginate:!0,project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure instances",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(wn(c)),c}}class bb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(gs(n));const r=this.enqueueRequest({description:"Create asset procedure",method:h.POST,url:"/asset-procedures/",payload:w(n),blockers:[],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Qe(m))}).catch(()=>{this.dispatch(bs(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=Fs(e.uuid)(a.getState());if(!i)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(Qe(c));const n=this.enqueueRequest({description:"Update asset procedure",method:h.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Qe(r))}).catch(()=>{this.dispatch(Qe(i))}),[c,n]}async remove(e){const{store:a}=this.client,i=a.getState(),c=Fs(e)(i);if(!c)throw new Error(`Expected asset procedure with uuid ${e} to exist`);const n=jn(e)(i);return this.dispatch(bs(e)),this.dispatch(En(n.map(r=>r.uuid))),this.enqueueRequest({description:"Delete asset procedure",method:h.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(gs(c)),this.dispatch(Mn(n)),r})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset procedures",method:h.GET,url:"/asset-procedures/",queryParams:{organization:e},blockers:[],blocks:[]},a);return this.dispatch(zn(i)),i}}class Pb extends q{async bulkAdd(e){var m;const a=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:o,submitted_at:a,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(P)}this.dispatch(Bn(n));const l=this.enqueueRequest({description:"Add asset procedure step fields attachments",method:h.POST,url:"/asset-procedure-step-fields-attachments/bulk/",payload:{submitted_at:a,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return l.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(Gn(u.attachments))}).catch(()=>{this.dispatch($n(n.map(u=>u.uuid)))}),[n,l.then(({attachments:u})=>u)]}async refreshStore(e){const a=await this.enqueueRequest({description:"Get asset procedure step fields attachments",method:h.GET,url:"/asset-procedure-step-fields-attachments/",queryParams:{fields_revision__asset_procedure_step__organization:e},blockers:[],blocks:[]});return this.dispatch(kn(a)),a}}class Fb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Os(n));const r=this.enqueueRequest({description:"Add Asset Procedure Step Fields",method:h.POST,url:"/asset-procedure-step-fields/",payload:w(n),blockers:[n.asset_procedure_step],blocks:[n.uuid]});return r.then(m=>{this.dispatch(xe(m))}).catch(m=>{throw this.dispatch(_s(n.uuid)),m}),[n,r]}update(e){const{store:a}=this.client,i=a.getState().assetProcedureStepFieldsReducer.instances[e.uuid];if(!i)throw new Error(`AssetProcedureStepFields with uuid ${e.uuid} not found`);const c={...i,...e};this.dispatch(xe(c));const n=this.enqueueRequest({description:"Update Asset Procedure Step Fields",method:h.PATCH,url:`/asset-procedure-step-fields/${i.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(xe(r))}).catch(r=>{throw this.dispatch(xe(i)),r}),[c,n]}delete(e){const{store:a}=this.client,i=a.getState().assetProcedureStepFieldsReducer.instances[e];if(!i)throw new Error(`AssetProcedureStepFields with uuid ${e} not found`);this.dispatch(_s(e));const c=this.enqueueRequest({description:"Delete Asset Procedure Step Fields",method:h.DELETE,url:`/asset-procedure-step-fields/${e}/`,blockers:[e],blocks:[e]});return c.catch(n=>{throw this.dispatch(Os(i)),n}),c}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get Asset Procedure Step Fields",method:h.GET,url:"/asset-procedure-step-fields/",queryParams:{asset_procedure_step__asset_procedure__organization:e},blockers:[],blocks:[]},a);return this.dispatch(Yn(i)),i}}class Tb extends q{async bulkAdd(e,a){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=$e(e,a??e.length),r=[],l=[];for(const o of n){const p={},A=[];for(const y of o){const{fieldValuesUuid:b,fieldIdentifier:P,file:_}=y,R=await this.getFilePayload(_);R.sha1 in p||(p[R.sha1]=R);const z=T({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:R.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(z);const De={uuid:z.uuid,file_name:_.name,file_sha1:R.sha1,file_extension:R.extension,field_identifier:P,field_values:b};A.push(De)}l.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(At(r));const m=l.map(o=>this.enqueueRequest({description:"Add asset procedure step field values attachments",method:h.POST,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:o,blockers:o.attachments.map(p=>p.field_values),blocks:o.attachments.map(p=>p.uuid)}));return Promise.all(m).then(o=>{for(const A of o)this.processPresignedUrls(A.presigned_urls);const p=o.flatMap(A=>A.attachments);this.dispatch(Xn(p))}).catch(o=>{throw this.dispatch(yt(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:a}=this.client,i=a.getState(),c=xn(e)(i);this.dispatch(yt(e));try{await this.enqueueRequest({description:"Delete asset procedure step field values attachments",method:h.DELETE,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(At(c)),n}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure step field values attachments",method:h.GET,url:"/asset-procedure-step-field-values-attachments/",queryParams:{limit:E,paginate:!0,field_values__asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure step field values attachments",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(Jn(c)),c}}class Ib extends v{add(e){var r;const{store:a}=this.client,i=a.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset procedure step field values",method:h.POST,url:"/asset-procedure-step-field-values/",payload:w(c),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[c.uuid]});return this.dispatch(js(c)),n.then(l=>(this.dispatch(et(l)),l)).catch(()=>{this.dispatch(qs(c.uuid))}),[c,n]}bulkAdd(e,a){var m;const i=new Date().toISOString(),c=[],n=$e(e.payloads,a??e.payloads.length),r=[];for(const u of n){const o=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),o.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure_instance:p.asset_procedure_instance,asset_procedure_step:p.asset_procedure_step,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:o})}this.dispatch(ir(c));const l=[];for(const u of r){const o=u.field_values.map(P=>P.asset),p=u.field_values.map(P=>P.fields_revision),A=u.field_values.map(P=>P.asset_procedure_instance),y=u.field_values.map(P=>P.uuid),b=this.enqueueRequest({description:"Bulk add asset procedure step field values",method:h.POST,url:"/asset-procedure-step-field-values/bulk/",payload:u,blockers:[...o,...p,...A],blocks:y});l.push(b)}return Promise.all(l).then(u=>{this.dispatch(cr(u.flat()))}).catch(()=>{this.dispatch(nr(c.map(u=>u.uuid)))}),[c,l]}update(e){const{store:a}=this.client,i=a.getState(),c=Vs(e.uuid)(i);if(!c)throw new Error(`Expected AssetProcedureStepFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(et(n));const r=this.enqueueRequest({description:"Update asset procedure step field values",method:h.PATCH,url:`/asset-procedure-step-field-values/${e.uuid}/`,payload:e,blockers:[n.fields_revision,n.asset,n.asset_procedure_instance],blocks:[n.uuid]});return r.then(l=>{this.dispatch(et(l))}).catch(()=>{this.dispatch(et(c))}),[n,r]}async delete(e){const{store:a}=this.client,i=a.getState(),c=Vs(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=er(e)(i);this.dispatch(qs(e)),this.dispatch(yt(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure step field values",method:h.DELETE,url:`/asset-procedure-step-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(js(c)),this.dispatch(At(n)),r}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure step field values",method:h.GET,url:"/asset-procedure-step-field-values/",queryParams:{limit:E,paginate:!0,asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure step field values",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(ar(c)),c}}class Ob extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Us(n));const r=this.enqueueRequest({description:"Create asset procedure step",method:h.POST,url:"/asset-procedure-steps/",payload:w(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(St(m))}).catch(()=>{this.dispatch(Ds(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=Cs(e.uuid)(a.getState());if(!i)throw new Error(`No asset procedure step with uuid ${e.uuid} found in the store`);const c={...i,...e};this.dispatch(St(c));const n=this.enqueueRequest({description:"Update asset procedure step",method:h.PATCH,url:`/asset-procedure-steps/${i.uuid}/`,payload:{name:e.name,description:e.description,priority:e.order,color:e.color},blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(St(r))}).catch(()=>{this.dispatch(lr(i))}),[c,n]}async delete(e){const{store:a}=this.client,i=a.getState(),c=Cs(e)(i);if(!c)throw new Error(`No asset procedure step with uuid ${e} found in the store`);return this.dispatch(Ds(e)),this.enqueueRequest({description:"Delete asset stage",method:h.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(Us(c)),n})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset procedure steps",method:h.GET,url:"/asset-procedure-steps/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]},a);return this.dispatch(or(i)),i}}class _b extends v{add(e){var l;const{store:a}=this.client;if(!e.canvas_marker&&!e.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");const i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Bs(n));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/assets/",payload:w(n),blockers:[n.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(tt(m))}).catch(()=>{this.dispatch(Gs(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=Hs(e.uuid)(a.getState());if(!i)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const c={...i,...e};if(!c.canvas_marker&&!c.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");this.dispatch(tt(c));const n=this.enqueueRequest({description:"Edit asset",method:h.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return n.then(r=>{this.dispatch(tt(r))}).catch(()=>{this.dispatch(tt(i))}),[c,n]}async delete(e){const{store:a}=this.client,i=a.getState(),c=Hs(e)(i);if(!c)throw new Error(`No asset with uuid ${e} found in the store`);const n=kc(e)(i),r=zu(e)(i),l=xu(e)(i);if(this.dispatch(Gs(e)),n.length>0){const m=n.map(({uuid:u})=>u);this.dispatch(es(m))}if(r.length>0){const m=r.map(({uuid:u})=>u);this.dispatch(qt(m))}if(l.length>0){const m=l.map(({uuid:u})=>u);this.dispatch(Xa(m))}return this.enqueueRequest({description:"Delete asset",method:h.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(Bs(c)),this.dispatch(xt(n)),this.dispatch(jt(r)),this.dispatch(Za(l)),m})}bulkAdd(e,a,i,c){const n=new Date().toISOString(),r=Ne.v4(),l=$e(e,c).map(o=>{const p=o.map(A=>T(A));return{batchId:Ne.v4(),payload:{transaction_id:r,submitted_at:n,asset_type:a,project:i,assets:p}}}),m=[];let u=null;for(const o of l){const{batchId:p,payload:A}=o,y=A.assets.map(R=>R.uuid),b=[a];u&&b.push(u);const P=y;P.push(p);const _=this.enqueueRequest({description:"Batch create assets",method:h.POST,url:"/assets/bulk/",payload:A,blockers:b,blocks:P});u=o.batchId,m.push(_)}return Promise.all(m).then(o=>{const p=o.flat();this.dispatch(bt(p))}),m}async bulkDelete(e){const{store:a}=this.client,i=a.getState(),c=fr(e)(i);this.dispatch($s(e));try{await this.enqueueRequest({description:"Bulk delete assets",method:h.DELETE,url:"/assets/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(bt(c)),n}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get assets",method:h.GET,url:"/assets/",queryParams:{limit:E,paginate:!0,project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get assets",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(Ar(c)),c}}class Rb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Ys(n));const r=this.enqueueRequest({description:"Add asset stage completion",method:h.POST,url:"/asset-stage-completions/",payload:w(n),blockers:[e.asset,e.stage],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Pr(m))}).catch(()=>{this.dispatch(Zs(n.uuid))}),[n,r]}delete(e){const{store:a}=this.client,i=Ir(e)(a.getState());if(!i)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(Zs(e));const c=this.enqueueRequest({description:"Delete asset stage completion",method:h.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return c.catch(()=>{this.dispatch(Ys(i))}),c}bulkAdd(e){var u;const{store:a}=this.client,i=new Date().toISOString(),c=(u=a.getState().userReducer.currentUser)==null?void 0:u.id,n=e.map(o=>T(o)),r=n.map(o=>({...o,created_by:c,submitted_at:i})),l=r.map(({uuid:o})=>o);this.dispatch(Ks(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:h.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:i,completions:n},blockers:[...e.map(o=>o.asset_procedure_instance),...e.map(o=>o.stage),...e.map(o=>o.asset)],blocks:l});return m.then(o=>{this.dispatch(Fr(o))}).catch(()=>{this.dispatch(Js(l))}),[r,m]}bulkDelete(e){const{store:a}=this.client,i=Or(e)(a.getState());this.dispatch(Js(e));const c=this.enqueueRequest({description:"Deleting asset stage completions",method:h.DELETE,url:"/asset-stage-completions/bulk/",payload:{uuids:e},blockers:e,blocks:[]});return c.catch(()=>{this.dispatch(Ks(i))}),c}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset stage completions",method:h.GET,url:"/asset-stage-completions/",queryParams:{limit:E,paginate:!0,asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset stage completions",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(br(c)),c}}class vb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(xs(n));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/asset-stages/",payload:w(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Pt(m))}).catch(()=>{this.dispatch(ea(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=ta(e.uuid)(a.getState());if(!i)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const c={...i,...e};this.dispatch(Pt(c));const n=this.enqueueRequest({description:"Update asset stage",method:h.PATCH,url:`/asset-stages/${i.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Pt(r))}).catch(()=>{this.dispatch(vr(i))}),[c,n]}async delete(e){const{store:a}=this.client,i=a.getState(),c=ta(e)(i);if(!c)throw new Error(`No asset stage with uuid ${e} found in the store`);return this.dispatch(ea(e)),this.enqueueRequest({description:"Delete asset stage",method:h.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(xs(c)),n})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset stages",method:h.GET,url:"/asset-stages/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]},a);return this.dispatch(Rr(i)),i}}class wb extends ke{constructor(){super(...arguments);S(this,"name","Asset Type Attachment");S(this,"url","/asset-type-attachments");S(this,"addAttachments",aa);S(this,"updateAttachments",Vr);S(this,"removeAttachments",ia);S(this,"removeAttachment",zr);S(this,"setAttachment",qr);S(this,"selectAttachment",Cr)}buildOfflineAttachment(a){return T({file:URL.createObjectURL(a.file),file_sha1:a.file_sha1,created_by:a.created_by,file_name:a.file.name,file_type:a.file.type,submitted_at:a.submitted_at,description:a.description,asset_type:a.modelUuid})}buildAttachmentPayload(a){return{...a,asset_type:a.modelUuid}}async bulkAdd(a){return this._bulkAdd(a.map(i=>({modelUuid:i.assetTypeUuid,file:i.file})))}async delete(a){return this._delete(a)}async refreshStore(a,i){const c=await this.enqueueRequest({description:"Get asset type attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset_type__organization:a},blocks:[],blockers:[]},i);return this.dispatch(jr(c)),c}}class Mb extends q{async bulkAdd(e){var m;const a=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:o,submitted_at:a,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(P)}this.dispatch(Lr(n));const l=this.enqueueRequest({description:"Add asset type fields attachments",method:h.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:a,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return l.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(Nr(u.attachments))}).catch(()=>{this.dispatch(Hr(n.map(u=>u.uuid)))}),[n,l.then(({attachments:u})=>u)]}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset type fields attachments",method:h.GET,url:"/asset-type-fields-attachments/",queryParams:{fields_revision__asset_type__organization:e},blockers:[e],blocks:[]},a);return this.dispatch($r(i)),i}}class Eb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Xr(n));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:h.POST,url:"/asset-type-fields/",payload:w(n),blockers:[n.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Qr(m))}).catch(m=>{throw this.dispatch(xr(n.uuid)),m}),[n,r]}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get Asset Type Fields",method:h.GET,url:"/asset-type-fields/",queryParams:{asset_type__organization:e},blockers:[],blocks:[]},a);return this.dispatch(Jr(i)),i}}class jb extends q{async bulkAdd(e,a){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=$e(e,a??e.length),r=[],l=[];for(const o of n){const p={},A=[];for(const y of o){const{fieldValuesUuid:b,fieldIdentifier:P,file:_}=y,R=await this.getFilePayload(_);R.sha1 in p||(p[R.sha1]=R);const z=T({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:R.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(z);const De={uuid:z.uuid,file_name:_.name,file_sha1:R.sha1,file_extension:R.extension,field_identifier:P,field_values:b};A.push(De)}l.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(It(r));const m=l.map(o=>this.enqueueRequest({description:"Add asset type field values attachments",method:h.POST,url:"/asset-type-field-values-attachments/bulk/",payload:o,blockers:o.attachments.map(p=>p.field_values),blocks:o.attachments.map(p=>p.uuid)}));return Promise.all(m).then(o=>{for(const A of o)this.processPresignedUrls(A.presigned_urls);const p=o.flatMap(A=>A.attachments);this.dispatch(id(p))}).catch(o=>{throw this.dispatch(Ot(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:a}=this.client,i=a.getState(),c=nd(e)(i);this.dispatch(Ot(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:h.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(It(c)),n}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset type field values attachments",method:h.GET,url:"/asset-type-field-values-attachments/",queryParams:{limit:E,paginate:!0,field_values__asset__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset type field values attachments",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(ad(c)),c}}class qb extends v{add(e){var r;const{store:a}=this.client,i=a.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset type field values",method:h.POST,url:"/asset-type-field-values/",payload:w(c),blockers:[e.asset,e.fields_revision],blocks:[c.uuid]});return this.dispatch(oa(c)),n.then(l=>(this.dispatch(st(l)),l)).catch(()=>{this.dispatch(la(c.uuid))}),[c,n]}bulkAdd(e,a){var m;const i=new Date().toISOString(),c=[],n=$e(e.payloads,a??e.payloads.length),r=[];for(const u of n){const o=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),o.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:o})}this.dispatch(ld(c));const l=[];for(const u of r){const o=u.field_values.map(b=>b.asset),p=u.field_values.map(b=>b.fields_revision),A=u.field_values.map(b=>b.uuid),y=this.enqueueRequest({description:"Bulk add asset type field values",method:h.POST,url:"/asset-type-field-values/bulk/",payload:u,blockers:[...o,...p],blocks:A});l.push(y)}return Promise.all(l).then(u=>{this.dispatch(hd(u.flat()))}).catch(()=>{this.dispatch(md(c.map(u=>u.uuid)))}),[c,l]}update(e){const{store:a}=this.client,i=a.getState(),c=ma(e.uuid)(i);if(!c)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(st(n));const r=this.enqueueRequest({description:"Delete asset type field values",method:h.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[n.uuid,n.fields_revision,n.asset],blocks:[n.uuid]});return r.then(l=>{this.dispatch(st(l))}).catch(()=>{this.dispatch(st(c))}),[n,r]}async delete(e){const{store:a}=this.client,i=a.getState(),c=ma(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=rd(e)(i);this.dispatch(la(e)),this.dispatch(Ot(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:h.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(oa(c)),this.dispatch(It(n)),r}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset type field values",method:h.GET,url:"/asset-type-field-values/",queryParams:{limit:E,paginate:!0,asset__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset type field values",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(od(c)),c}}class Vb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Aa(n));const r=this.enqueueRequest({description:"Create asset type",method:h.POST,url:"/asset-types/",payload:w(n),blockers:[],blocks:[n.uuid]});return r.then(m=>{this.dispatch(at(m))}).catch(()=>{this.dispatch(ya(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=Sa(e.uuid)(a.getState());if(!i)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(at(c));const n=this.enqueueRequest({description:"Update asset type",method:h.PATCH,url:`/asset-types/${e.uuid}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(at(r))}).catch(()=>{this.dispatch(at(i))}),[c,n]}async delete(e){const{store:a}=this.client,i=a.getState(),c=Sa(e)(i);if(!c)throw new Error(`Expected asset type with uuid ${e} to exist`);const n=Ns(e)(i),r=kr(e)(i);return this.dispatch(ya(e)),this.dispatch($s(n.map(l=>l.uuid))),this.dispatch(ia(r.map(({uuid:l})=>l))),this.enqueueRequest({description:"Delete asset type",method:h.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(l=>{throw this.dispatch(Aa(c)),this.dispatch(bt(n)),this.dispatch(aa(r)),l})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset types",method:h.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]},a);return this.dispatch(fd(i)),i}}class zb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(ba(n));const r=this.enqueueRequest({description:"Create Category",method:h.POST,url:"/categories/",payload:w(n),blockers:[e.project],blocks:[n.uuid]});return[n,r]}update(e){const a=this.client.store.getState(),i=Fa(e.uuid)(a);if(!i)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const c={...i,...e};this.dispatch(Od(c));const n=this.enqueueRequest({description:"Edit Category",method:h.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[c,n]}remove(e){const{store:a}=this.client,i=Fa(e)(a.getState());if(!i)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(_d(e));const c=this.enqueueRequest({description:"Delete Category",method:h.DELETE,url:`/categories/${i.uuid}/`,blockers:[i.uuid],blocks:[]});return c.catch(()=>{this.dispatch(ba(i))}),c}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get categories",method:h.GET,url:"/categories/",queryParams:{project__organization_owner:e},blocks:[],blockers:[]},a);return this.dispatch(Id(i)),i}}class Ub extends ke{constructor(){super(...arguments);S(this,"name","Document Attachment");S(this,"url","/document-attachments");S(this,"addAttachments",Ed);S(this,"updateAttachments",qd);S(this,"removeAttachments",zd);S(this,"removeAttachment",Vd);S(this,"setAttachment",jd);S(this,"selectAttachment",Cd)}buildOfflineAttachment(a){return T({file:URL.createObjectURL(a.file),file_sha1:a.file_sha1,created_by:a.created_by,file_name:a.file.name,file_type:a.file.type,submitted_at:a.submitted_at,description:a.description,document:a.modelUuid})}buildAttachmentPayload(a){return{...a,document:a.modelUuid}}async bulkAdd(a){var p;const{store:i}=this.client,c=(p=i.getState().userReducer.currentUser)==null?void 0:p.id,n=new Date().toISOString(),r=[],l=[],m={},u={};for(const A of a){const{documentUuid:y,file:b}=A,P=await this.getFilePayload(b);P.sha1 in m||(m[P.sha1]=P,u[P.sha1]=[]);const _=this.buildOfflineAttachment({file:b,file_sha1:P.sha1,submitted_at:n,created_by:c,description:"",modelUuid:y});r.push(_),l.push({uuid:_.uuid,file_name:_.file_name,file_sha1:_.file_sha1,file_extension:P.extension,description:_.description,document:y}),u[P.sha1].push(_.uuid)}this.dispatch(this.addAttachments(r));const o=this.enqueueRequest({description:"Attach files to document",method:h.POST,url:"/document-attachments/bulk/",payload:{submitted_at:n,attachments:l,files:Object.values(m)},blocks:r.map(A=>A.uuid),blockers:r.map(A=>A.file_sha1)});return o.then(({attachments:A,presigned_urls:y})=>{this.dispatch(this.updateAttachments(A));const b=this.processPresignedUrls(y);for(const[P,_]of Object.entries(b))_.then(()=>{const R=u[P];for(const z of R)this.makeReadable(z)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(A=>A.uuid)))}),[r,o.then(({attachments:A})=>A)]}async delete(a){return this._delete(a)}makeReadable(a){this.enqueueRequest({description:"Add attachment to AI assistant",method:h.PATCH,url:`/document-attachments/${a}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",a],blocks:["index-document-attachment"]})}async refreshStore(a,i){const c=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:"/document-attachments/",queryParams:{document__project__organization_owner:a},blocks:[],blockers:[]},i),n=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:"/document-attachments/",queryParams:{document__organization:a},blocks:[],blockers:[]},i),r=[...c,...n];return this.dispatch(Md(r)),r}}class Db extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch($d([n]));const r=this.enqueueRequest({description:"Create Document",method:h.POST,url:"/documents/",payload:w(n),queryParams:{parent_document:n.parent_document??void 0},blockers:n.parent_document?[n.parent_document]:[],blocks:[n.uuid]});return r.catch(()=>{this.dispatch(Oa([n.uuid]))}),[n,r]}update(e){const{store:a}=this.client,i=a.getState().documentsReducer.documents[e.uuid];if(!i)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const c={...i,...e};this.dispatch(We([c]));const n=this.enqueueRequest({description:"Update Document",method:h.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return n.catch(()=>{We([i])}),[c,n]}delete(e){const{store:a}=this.client,i=Rt(a.getState()),c=Ld(e)(a.getState());if(!c)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const n=c.parent_document?i[c.parent_document]:void 0;this.dispatch(Oa([e]));const r=this.enqueueRequest({description:"Delete Document",method:h.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(l=>{this.dispatch(We(l))}).catch(()=>{this.dispatch(We([c])),n&&this.dispatch(We([n]))}),r}async refreshStore(e,a){const i=this.enqueueRequest({description:"Get project documents",method:h.GET,url:"/documents/",queryParams:{project__organization_owner:e},blockers:[],blocks:[]},a),c=this.enqueueRequest({description:"Get organization documents",method:h.GET,url:"/documents/",queryParams:{organization:e},blockers:[],blocks:[]},a),n=[...await i,...await c];return this.dispatch(Gd(n)),n}}class Cb extends v{async add(e,a){return this.enqueueRequest({description:"Add email domain to organization",method:h.POST,url:"/organization-email-domains/",payload:{email:a,organization:e},blockers:[e,"create-org"],blocks:[]})}async remove(e){return this.dispatch(Kd(e.uuid)),this.enqueueRequest({description:"Remove email domain from organization",method:h.DELETE,url:`/organization-email-domains/${e.uuid}/`,blockers:[e.domain],blocks:[]}).catch(a=>{throw this.dispatch(Yd(e)),a})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Fetch email domains for organization",method:h.GET,url:"/organization-email-domains/",queryParams:{organization:e},blockers:[e],blocks:[]},a);return this.dispatch(Wd(i)),i}}class kb extends v{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:h.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,a=void 0){return this.enqueueRequest({description:"Validate verification code",method:h.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:a,blockers:[],blocks:[]})}}const Gt={},uc=new Set;let $t=0,oc=0,lc=0;const Bb=20;class Gb extends v{constructor(){super(...arguments);S(this,"host");S(this,"_dbPromise",Am.openDB("fileCache",1,{upgrade(a){a.createObjectStore("files")}}))}async renewUploadUrl(a){const i=await this.fetchCache(a);if(!i)throw new Error(`File with sha1 ${a} not found in cache`);const c=await Kt(i,a),n=await this.enqueueRequest({description:"Get S3 URL",method:h.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await He(i),file_type:i.type,extension:i.name.split(".").pop(),size:i.size.toString()},blockers:[],blocks:[`s3-${c}`]});return"url"in n&&this.dispatch(eu({sha1:a,...n})),n}async addCache(a,i){if(uc.has(i))return;if(!a.type){const r=a.name.split("."),l=r[r.length-1];a=new File([a],a.name,{type:l})}if(!a.name||!a.size||!a.type)throw new Error("Cannot add files to cache that do not have a name, size and type.");const c=await this._dbPromise;!!await c.get("files",i)?(console.error("File already cached (this is unexpected at this point):",a.name,i),$t++):(await c.put("files",a,i),oc++),uc.add(i),lc++,lc%Bb===0&&console.debug(`File cache summary: ${$t} hits and ${oc} misses, ${$t/($t+oc)*100}% hit rate over ${lc} calls to addCache.`)}async removeCache(a){await(await this._dbPromise).delete("files",a),uc.delete(a)}async fetchCache(a){return(await this._dbPromise).get("files",a)}async getOrRenewUploadUrl(a){const i=this.client.store.getState();return tu(a)(i)??await this.renewUploadUrl(a)}async uploadFileToS3(a){const i=await this.fetchCache(a);if(!i)throw new Error(`File with sha1 ${a} not found in cache`);const c=await Kt(i,a),n={file_name:i.name,file_sha1:a,file:c},r=await this.getOrRenewUploadUrl(a);if("warning"in r){if(r.warning==="already_uploaded")return[n,Promise.resolve(void 0).then()];throw new Error(r.warning)}const l=r.url,m=this.enqueueRequest({url:l,description:"Upload file",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:a,blockers:[`s3-${c}`],blocks:[a],s3url:r});return[n,m]}async fetchFileFromUrl(a,i,c){const n=a.split("?")[0]??a,r=await this.fetchCache(i);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(a.startsWith("blob:")){const o=await Pc(a),p=new File([o],c??i,{type:o.type});return await this.addCache(p,i),p}let l=Gt[n],m=!0;l?m=!1:(l=new Promise(o=>{this.enqueueRequest({description:"Download file",method:h.GET,url:a,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[i],blocks:[i]}).then(p=>{const A=new File([p],c??i,{type:p.type});o(A)})}),Gt[n]=l);let u;try{u=await l}catch(o){throw m&&o instanceof D&&delete Gt[n],o}if(m){const o=await He(u);if(o!==i){const y=`The hash of the file returned from the server (${o}) does not match the
|
|
8
|
+
`)}catch(c){console.error("Failed to extract error message from response body",c)}}else typeof t.body=="string"&&(a=t.body);else t!=null&&t.text?a=t.text:e instanceof Error&&(a=e.message);return!a||a.length>rb?Ye:a}class D extends Error{constructor(a){super(Ye);S(this,"status");S(this,"response");S(this,"message");S(this,"options");const{response:i,innerError:c}=a;this.message=a.message??db(i,c)??Ye,this.status=(i==null?void 0:i.status)??0,this.response=i,a.discard=a.discard??!1,this.options=a}}class ub extends xh{constructor(e){super(e)}}class v extends xh{constructor(a,i){super(a);S(this,"auth");this.auth=i}}class ob extends v{async startConversation(e,a){return this.enqueueRequest({description:"Start agent conversation",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:a},blockers:["prompt"],blocks:["prompt"]}).then(i=>(this.dispatch(vc(i)),i))}async continueConversation(e,a,i){return this.enqueueRequest({description:"Prompt agent",method:h.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:i},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:a}}).then(c=>{this.dispatch(Mc(c))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:h.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(a=>{this.dispatch(wc(a))})}async rate(e,a){return this.enqueueRequest({description:"Rate agent response",method:h.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:a},blockers:["rate"],blocks:["rate"]})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get agent conversation history",method:h.GET,url:"/agents/conversations/",queryParams:{project:e},blockers:["agent-conversations"],blocks:["agent-conversations"]},a);return this.dispatch(Rc(i)),i}}const lb=5e4,E=1e3,hb="limit";class q extends v{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:a,assetAttachmentReducer:i,assetTypeAttachmentReducer:c,documentAttachmentReducer:n,projectAttachmentReducer:r,formRevisionAttachmentReducer:l,formSubmissionAttachmentReducer:m,geoImageReducer:u,assetTypeFieldsAttachmentReducer:o,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:A,issueTypeFieldValuesAttachmentReducer:y}=this.client.store.getState();return[].concat(Object.values(a.instances),Object.values(i.instances),Object.values(c.instances),Object.values(n.instances),Object.values(r.instances),Object.values(l.instances),Object.values(m.instances),Object.values(u.instances),Object.values(o.instances),Object.values(p.instances),Object.values(A.instances),Object.values(y.instances)).filter(P=>P.file_sha1===e).length}processPresignedUrls(e){const a={};for(const[i,c]of Object.entries(e))a[i]=this.enqueueRequest({url:c.url,description:"Upload file to S3",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:i,blockers:[`s3-${c.fields.key}`],blocks:[i],s3url:c});return a}async getFilePayload(e){const a=await He(e),i={sha1:a,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,a),i}}class ke extends q{async _bulkAdd(e){var u;const{store:a}=this.client,i=(u=a.getState().userReducer.currentUser)==null?void 0:u.id,c=new Date().toISOString(),n=[],r=[],l={};for(const o of e){const{modelUuid:p,file:A}=o,y=await this.getFilePayload(A);y.sha1 in l||(l[y.sha1]=y);const b=this.buildOfflineAttachment({file:A,file_sha1:y.sha1,submitted_at:c,created_by:i,description:"",modelUuid:p});n.push(b),r.push(this.buildAttachmentPayload({uuid:b.uuid,file_name:b.file_name,file_sha1:b.file_sha1,file_extension:y.extension,description:b.description,modelUuid:p}))}this.dispatch(this.addAttachments(n));const m=this.enqueueRequest({description:`Add ${this.name}`,method:h.POST,url:`${this.url}/bulk/`,payload:{submitted_at:c,attachments:r,files:Object.values(l)},blocks:n.map(o=>o.uuid),blockers:n.map(o=>o.file_sha1)});return m.then(({attachments:o,presigned_urls:p})=>{this.dispatch(this.updateAttachments(o)),this.processPresignedUrls(p)}).catch(()=>{this.dispatch(this.removeAttachments(n.map(o=>o.uuid)))}),[n,m.then(({attachments:o})=>o)]}async _delete(e){const{store:a}=this.client,i=this.selectAttachment(e)(a.getState());if(!i)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(i.uuid));const c=this.enqueueRequest({description:`Delete ${this.name}`,method:h.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return c.then(()=>{this.getNumberOfAttachmentsWithSha1(i.file_sha1)===0&&this.client.files.removeCache(i.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(i))}),c}}class mb extends ke{constructor(){super(...arguments);S(this,"name","Asset Attachment");S(this,"url","/asset-attachments");S(this,"initializeAttachments",Qt);S(this,"addAttachments",xt);S(this,"updateAttachments",Vc);S(this,"removeAttachments",es);S(this,"removeAttachment",zc);S(this,"setAttachment",qc);S(this,"selectAttachment",Cc)}buildOfflineAttachment(a){return T({file:URL.createObjectURL(a.file),file_sha1:a.file_sha1,created_by:a.created_by,file_name:a.file.name,file_type:a.file.type,submitted_at:a.submitted_at,description:a.description,asset:a.modelUuid})}buildAttachmentPayload(a){return{...a,asset:a.modelUuid}}async bulkAdd(a){return this._bulkAdd(a.map(i=>({modelUuid:i.assetUuid,file:i.file})))}async delete(a){return this._delete(a)}async refreshStore(a,i){const n=(await this.performPagination({immediate:!0,description:"Get asset attachments",method:h.GET,url:`${this.url}/`,queryParams:{limit:E,paginate:!0,asset__project:a},blocks:[],blockers:[]},r=>({immediate:!0,description:"Get asset attachments",method:h.GET,url:r,blockers:[],blocks:[]}),i)).flat();return this.dispatch(Qt(n)),n}}class pb extends ke{constructor(){super(...arguments);S(this,"name","Asset Procedure Attachment");S(this,"url","/asset-procedure-attachments");S(this,"addAttachments",Lc);S(this,"updateAttachments",Hc);S(this,"removeAttachments",Yc);S(this,"removeAttachment",Wc);S(this,"setAttachment",Nc);S(this,"selectAttachment",Jc)}buildOfflineAttachment(a){return T({file:URL.createObjectURL(a.file),file_sha1:a.file_sha1,created_by:a.created_by,file_name:a.file.name,file_type:a.file.type,submitted_at:a.submitted_at,description:a.description,asset_procedure:a.modelUuid})}buildAttachmentPayload(a){return{...a,asset_procedure:a.modelUuid}}async bulkAdd(a){return this._bulkAdd(a.map(i=>({modelUuid:i.assetProcedureUuid,file:i.file})))}async delete(a){return this._delete(a)}async refreshStore(a,i){const c=await this.enqueueRequest({description:"Get asset procedure attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset_procedure__organization:a},blocks:[],blockers:[]},i);return this.dispatch($c(c)),c}}class Ab extends q{async bulkAdd(e){var m;const a=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:o,submitted_at:a,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(P)}this.dispatch(en(n));const l=this.enqueueRequest({description:"Add asset procedure fields attachments",method:h.POST,url:"/asset-procedure-fields-attachments/bulk/",payload:{submitted_at:a,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return l.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(tn(u.attachments))}).catch(()=>{this.dispatch(sn(n.map(u=>u.uuid)))}),[n,l.then(({attachments:u})=>u)]}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset procedure fields attachments",method:h.GET,url:"/asset-procedure-fields-attachments/",queryParams:{fields_revision__asset_procedure__organization:e},blockers:[],blocks:[]},a);return this.dispatch(xc(i)),i}}class yb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(un(n));const r=this.enqueueRequest({description:"Add Asset Procedure Fields",method:h.POST,url:"/asset-procedure-fields/",payload:w(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(on(m))}).catch(m=>{throw this.dispatch(ln(n.uuid)),m}),[n,r]}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get Asset Procedure Fields",method:h.GET,url:"/asset-procedure-fields/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]},a);return this.dispatch(dn(i)),i}}function $e(t,e){const a=[];let i=0;const c=t.length;for(;i<c;)a.push(t.slice(i,i+=e));return a}class fb extends q{async bulkAdd(e,a){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=$e(e,a??e.length),r=[],l=[];for(const o of n){const p={},A=[];for(const y of o){const{fieldValuesUuid:b,fieldIdentifier:P,file:_}=y,R=await this.getFilePayload(_);R.sha1 in p||(p[R.sha1]=R);const z=T({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:R.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(z);const De={uuid:z.uuid,file_name:_.name,file_sha1:R.sha1,file_extension:R.extension,field_identifier:P,field_values:b};A.push(De)}l.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(mt(r));const m=l.map(o=>this.enqueueRequest({description:"Add asset procedure field values attachments",method:h.POST,url:"/asset-procedure-field-values-attachments/bulk/",payload:o,blockers:o.attachments.map(p=>p.field_values),blocks:o.attachments.map(p=>p.uuid)}));return Promise.all(m).then(o=>{for(const A of o)this.processPresignedUrls(A.presigned_urls);const p=o.flatMap(A=>A.attachments);this.dispatch(yn(p))}).catch(o=>{throw this.dispatch(pt(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:a}=this.client,i=a.getState(),c=Sn(e)(i);this.dispatch(pt(e));try{await this.enqueueRequest({description:"Delete asset procedure field values attachments",method:h.DELETE,url:"/asset-procedure-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(mt(c)),n}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure field values attachments",method:h.GET,url:"/asset-procedure-field-values-attachments/",queryParams:{limit:E,paginate:!0,field_values__asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure field values attachments",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(An(c)),c}}class Sb extends v{add(e){var r;const{store:a}=this.client,i=a.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/",payload:w(c),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[c.uuid]});return this.dispatch(ds(c)),n.then(l=>(this.dispatch(Je(l)),l)).catch(()=>{this.dispatch(us(c.uuid))}),[c,n]}bulkAdd(e,a){var m;const i=new Date().toISOString(),c=[],n=$e(e.payloads,a??e.payloads.length),r=[];for(const u of n){const o=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),o.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure_instance:p.asset_procedure_instance,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:o})}this.dispatch(Tn(c));const l=[];for(const u of r){const o=u.field_values.map(P=>P.asset),p=u.field_values.map(P=>P.fields_revision),A=u.field_values.map(P=>P.asset_procedure_instance),y=u.field_values.map(P=>P.uuid),b=this.enqueueRequest({description:"Bulk add asset procedure field values",method:h.POST,url:"/asset-procedure-field-values/bulk/",payload:u,blockers:[...o,...p,...A],blocks:y});l.push(b)}return Promise.all(l).then(u=>{this.dispatch(In(u.flat()))}).catch(()=>{this.dispatch(On(c.map(u=>u.uuid)))}),[c,l]}update(e){const{store:a}=this.client,i=a.getState(),c=ls(e.uuid)(i);if(!c)throw new Error(`Expected AssetProcedureFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(Je(n));const r=this.enqueueRequest({description:"Update asset procedure field values",method:h.PATCH,url:`/asset-procedure-field-values/${e.uuid}/`,payload:e,blockers:[n.fields_revision,n.asset,n.asset_procedure_instance],blocks:[n.uuid]});return r.then(l=>{this.dispatch(Je(l))}).catch(()=>{this.dispatch(Je(c))}),[n,r]}async delete(e){const{store:a}=this.client,i=a.getState(),c=ls(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=gn(e)(i);this.dispatch(us(e)),this.dispatch(pt(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure field values",method:h.DELETE,url:`/asset-procedure-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ds(c)),this.dispatch(mt(n)),r}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure field values",method:h.GET,url:"/asset-procedure-field-values/",queryParams:{limit:E,paginate:!0,asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure field values",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(Fn(c)),c}}class gb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(ms(n));const r=this.enqueueRequest({description:"Create asset procedure instance",method:h.POST,url:"/asset-procedure-instances/",payload:w(n),blockers:[e.asset_procedure,e.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Xe(m))}).catch(()=>{this.dispatch(ps(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=fs(e.uuid)(a.getState());if(!i)throw new Error(`Expected asset procedure instance with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(Xe(c));const n=this.enqueueRequest({description:"Update asset procedure instance",method:h.PATCH,url:`/asset-procedure-instances/${e.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Xe(r))}).catch(()=>{this.dispatch(Xe(i))}),[c,n]}async remove(e){const{store:a}=this.client,i=a.getState(),c=fs(e)(i);if(!c)throw new Error(`Expected asset procedure instance with uuid ${e} to exist`);return this.dispatch(ps(e)),this.enqueueRequest({description:"Delete asset procedure instance",method:h.DELETE,url:`/asset-procedure-instances/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(ms(c)),n})}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure instances",method:h.GET,url:"/asset-procedure-instances/",queryParams:{limit:E,paginate:!0,project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure instances",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(wn(c)),c}}class bb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(gs(n));const r=this.enqueueRequest({description:"Create asset procedure",method:h.POST,url:"/asset-procedures/",payload:w(n),blockers:[],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Qe(m))}).catch(()=>{this.dispatch(bs(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=Fs(e.uuid)(a.getState());if(!i)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(Qe(c));const n=this.enqueueRequest({description:"Update asset procedure",method:h.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Qe(r))}).catch(()=>{this.dispatch(Qe(i))}),[c,n]}async remove(e){const{store:a}=this.client,i=a.getState(),c=Fs(e)(i);if(!c)throw new Error(`Expected asset procedure with uuid ${e} to exist`);const n=jn(e)(i);return this.dispatch(bs(e)),this.dispatch(En(n.map(r=>r.uuid))),this.enqueueRequest({description:"Delete asset procedure",method:h.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(gs(c)),this.dispatch(Mn(n)),r})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset procedures",method:h.GET,url:"/asset-procedures/",queryParams:{organization:e},blockers:[],blocks:[]},a);return this.dispatch(zn(i)),i}}class Pb extends q{async bulkAdd(e){var m;const a=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:o,submitted_at:a,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(P)}this.dispatch(Bn(n));const l=this.enqueueRequest({description:"Add asset procedure step fields attachments",method:h.POST,url:"/asset-procedure-step-fields-attachments/bulk/",payload:{submitted_at:a,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return l.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(Gn(u.attachments))}).catch(()=>{this.dispatch($n(n.map(u=>u.uuid)))}),[n,l.then(({attachments:u})=>u)]}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset procedure step fields attachments",method:h.GET,url:"/asset-procedure-step-fields-attachments/",queryParams:{fields_revision__asset_procedure_step__organization:e},blockers:[],blocks:[]},a);return this.dispatch(kn(i)),i}}class Fb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Os(n));const r=this.enqueueRequest({description:"Add Asset Procedure Step Fields",method:h.POST,url:"/asset-procedure-step-fields/",payload:w(n),blockers:[n.asset_procedure_step],blocks:[n.uuid]});return r.then(m=>{this.dispatch(xe(m))}).catch(m=>{throw this.dispatch(_s(n.uuid)),m}),[n,r]}update(e){const{store:a}=this.client,i=a.getState().assetProcedureStepFieldsReducer.instances[e.uuid];if(!i)throw new Error(`AssetProcedureStepFields with uuid ${e.uuid} not found`);const c={...i,...e};this.dispatch(xe(c));const n=this.enqueueRequest({description:"Update Asset Procedure Step Fields",method:h.PATCH,url:`/asset-procedure-step-fields/${i.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(xe(r))}).catch(r=>{throw this.dispatch(xe(i)),r}),[c,n]}delete(e){const{store:a}=this.client,i=a.getState().assetProcedureStepFieldsReducer.instances[e];if(!i)throw new Error(`AssetProcedureStepFields with uuid ${e} not found`);this.dispatch(_s(e));const c=this.enqueueRequest({description:"Delete Asset Procedure Step Fields",method:h.DELETE,url:`/asset-procedure-step-fields/${e}/`,blockers:[e],blocks:[e]});return c.catch(n=>{throw this.dispatch(Os(i)),n}),c}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get Asset Procedure Step Fields",method:h.GET,url:"/asset-procedure-step-fields/",queryParams:{asset_procedure_step__asset_procedure__organization:e},blockers:[],blocks:[]},a);return this.dispatch(Yn(i)),i}}class Tb extends q{async bulkAdd(e,a){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=$e(e,a??e.length),r=[],l=[];for(const o of n){const p={},A=[];for(const y of o){const{fieldValuesUuid:b,fieldIdentifier:P,file:_}=y,R=await this.getFilePayload(_);R.sha1 in p||(p[R.sha1]=R);const z=T({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:R.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(z);const De={uuid:z.uuid,file_name:_.name,file_sha1:R.sha1,file_extension:R.extension,field_identifier:P,field_values:b};A.push(De)}l.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(At(r));const m=l.map(o=>this.enqueueRequest({description:"Add asset procedure step field values attachments",method:h.POST,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:o,blockers:o.attachments.map(p=>p.field_values),blocks:o.attachments.map(p=>p.uuid)}));return Promise.all(m).then(o=>{for(const A of o)this.processPresignedUrls(A.presigned_urls);const p=o.flatMap(A=>A.attachments);this.dispatch(Xn(p))}).catch(o=>{throw this.dispatch(yt(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:a}=this.client,i=a.getState(),c=xn(e)(i);this.dispatch(yt(e));try{await this.enqueueRequest({description:"Delete asset procedure step field values attachments",method:h.DELETE,url:"/asset-procedure-step-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(At(c)),n}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure step field values attachments",method:h.GET,url:"/asset-procedure-step-field-values-attachments/",queryParams:{limit:E,paginate:!0,field_values__asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure step field values attachments",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(Jn(c)),c}}class Ib extends v{add(e){var r;const{store:a}=this.client,i=a.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset procedure step field values",method:h.POST,url:"/asset-procedure-step-field-values/",payload:w(c),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[c.uuid]});return this.dispatch(js(c)),n.then(l=>(this.dispatch(et(l)),l)).catch(()=>{this.dispatch(qs(c.uuid))}),[c,n]}bulkAdd(e,a){var m;const i=new Date().toISOString(),c=[],n=$e(e.payloads,a??e.payloads.length),r=[];for(const u of n){const o=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),o.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,asset_procedure_instance:p.asset_procedure_instance,asset_procedure_step:p.asset_procedure_step,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:o})}this.dispatch(ir(c));const l=[];for(const u of r){const o=u.field_values.map(P=>P.asset),p=u.field_values.map(P=>P.fields_revision),A=u.field_values.map(P=>P.asset_procedure_instance),y=u.field_values.map(P=>P.uuid),b=this.enqueueRequest({description:"Bulk add asset procedure step field values",method:h.POST,url:"/asset-procedure-step-field-values/bulk/",payload:u,blockers:[...o,...p,...A],blocks:y});l.push(b)}return Promise.all(l).then(u=>{this.dispatch(cr(u.flat()))}).catch(()=>{this.dispatch(nr(c.map(u=>u.uuid)))}),[c,l]}update(e){const{store:a}=this.client,i=a.getState(),c=Vs(e.uuid)(i);if(!c)throw new Error(`Expected AssetProcedureStepFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(et(n));const r=this.enqueueRequest({description:"Update asset procedure step field values",method:h.PATCH,url:`/asset-procedure-step-field-values/${e.uuid}/`,payload:e,blockers:[n.fields_revision,n.asset,n.asset_procedure_instance],blocks:[n.uuid]});return r.then(l=>{this.dispatch(et(l))}).catch(()=>{this.dispatch(et(c))}),[n,r]}async delete(e){const{store:a}=this.client,i=a.getState(),c=Vs(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=er(e)(i);this.dispatch(qs(e)),this.dispatch(yt(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure step field values",method:h.DELETE,url:`/asset-procedure-step-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(js(c)),this.dispatch(At(n)),r}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset procedure step field values",method:h.GET,url:"/asset-procedure-step-field-values/",queryParams:{limit:E,paginate:!0,asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset procedure step field values",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(ar(c)),c}}class Ob extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Us(n));const r=this.enqueueRequest({description:"Create asset procedure step",method:h.POST,url:"/asset-procedure-steps/",payload:w(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(St(m))}).catch(()=>{this.dispatch(Ds(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=Cs(e.uuid)(a.getState());if(!i)throw new Error(`No asset procedure step with uuid ${e.uuid} found in the store`);const c={...i,...e};this.dispatch(St(c));const n=this.enqueueRequest({description:"Update asset procedure step",method:h.PATCH,url:`/asset-procedure-steps/${i.uuid}/`,payload:{name:e.name,description:e.description,priority:e.order,color:e.color},blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(St(r))}).catch(()=>{this.dispatch(lr(i))}),[c,n]}async delete(e){const{store:a}=this.client,i=a.getState(),c=Cs(e)(i);if(!c)throw new Error(`No asset procedure step with uuid ${e} found in the store`);return this.dispatch(Ds(e)),this.enqueueRequest({description:"Delete asset stage",method:h.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(Us(c)),n})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset procedure steps",method:h.GET,url:"/asset-procedure-steps/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]},a);return this.dispatch(or(i)),i}}class _b extends v{add(e){var l;const{store:a}=this.client;if(!e.canvas_marker&&!e.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");const i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Bs(n));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/assets/",payload:w(n),blockers:[n.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(tt(m))}).catch(()=>{this.dispatch(Gs(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=Hs(e.uuid)(a.getState());if(!i)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const c={...i,...e};if(!c.canvas_marker&&!c.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");this.dispatch(tt(c));const n=this.enqueueRequest({description:"Edit asset",method:h.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return n.then(r=>{this.dispatch(tt(r))}).catch(()=>{this.dispatch(tt(i))}),[c,n]}async delete(e){const{store:a}=this.client,i=a.getState(),c=Hs(e)(i);if(!c)throw new Error(`No asset with uuid ${e} found in the store`);const n=kc(e)(i),r=zu(e)(i),l=xu(e)(i);if(this.dispatch(Gs(e)),n.length>0){const m=n.map(({uuid:u})=>u);this.dispatch(es(m))}if(r.length>0){const m=r.map(({uuid:u})=>u);this.dispatch(qt(m))}if(l.length>0){const m=l.map(({uuid:u})=>u);this.dispatch(Xa(m))}return this.enqueueRequest({description:"Delete asset",method:h.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(Bs(c)),this.dispatch(xt(n)),this.dispatch(jt(r)),this.dispatch(Za(l)),m})}bulkAdd(e,a,i,c){const n=new Date().toISOString(),r=Ne.v4(),l=$e(e,c).map(o=>{const p=o.map(A=>T(A));return{batchId:Ne.v4(),payload:{transaction_id:r,submitted_at:n,asset_type:a,project:i,assets:p}}}),m=[];let u=null;for(const o of l){const{batchId:p,payload:A}=o,y=A.assets.map(R=>R.uuid),b=[a];u&&b.push(u);const P=y;P.push(p);const _=this.enqueueRequest({description:"Batch create assets",method:h.POST,url:"/assets/bulk/",payload:A,blockers:b,blocks:P});u=o.batchId,m.push(_)}return Promise.all(m).then(o=>{const p=o.flat();this.dispatch(bt(p))}),m}async bulkDelete(e){const{store:a}=this.client,i=a.getState(),c=fr(e)(i);this.dispatch($s(e));try{await this.enqueueRequest({description:"Bulk delete assets",method:h.DELETE,url:"/assets/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(bt(c)),n}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get assets",method:h.GET,url:"/assets/",queryParams:{limit:E,paginate:!0,project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get assets",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(Ar(c)),c}}class Rb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Ys(n));const r=this.enqueueRequest({description:"Add asset stage completion",method:h.POST,url:"/asset-stage-completions/",payload:w(n),blockers:[e.asset,e.stage],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Pr(m))}).catch(()=>{this.dispatch(Zs(n.uuid))}),[n,r]}delete(e){const{store:a}=this.client,i=Ir(e)(a.getState());if(!i)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(Zs(e));const c=this.enqueueRequest({description:"Delete asset stage completion",method:h.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return c.catch(()=>{this.dispatch(Ys(i))}),c}bulkAdd(e){var u;const{store:a}=this.client,i=new Date().toISOString(),c=(u=a.getState().userReducer.currentUser)==null?void 0:u.id,n=e.map(o=>T(o)),r=n.map(o=>({...o,created_by:c,submitted_at:i})),l=r.map(({uuid:o})=>o);this.dispatch(Ks(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:h.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:i,completions:n},blockers:[...e.map(o=>o.asset_procedure_instance),...e.map(o=>o.stage),...e.map(o=>o.asset)],blocks:l});return m.then(o=>{this.dispatch(Fr(o))}).catch(()=>{this.dispatch(Js(l))}),[r,m]}bulkDelete(e){const{store:a}=this.client,i=Or(e)(a.getState());this.dispatch(Js(e));const c=this.enqueueRequest({description:"Deleting asset stage completions",method:h.DELETE,url:"/asset-stage-completions/bulk/",payload:{uuids:e},blockers:e,blocks:[]});return c.catch(()=>{this.dispatch(Ks(i))}),c}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset stage completions",method:h.GET,url:"/asset-stage-completions/",queryParams:{limit:E,paginate:!0,asset_procedure_instance__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset stage completions",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(br(c)),c}}class vb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(xs(n));const r=this.enqueueRequest({description:"Create asset",method:h.POST,url:"/asset-stages/",payload:w(n),blockers:[n.asset_procedure],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Pt(m))}).catch(()=>{this.dispatch(ea(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=ta(e.uuid)(a.getState());if(!i)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const c={...i,...e};this.dispatch(Pt(c));const n=this.enqueueRequest({description:"Update asset stage",method:h.PATCH,url:`/asset-stages/${i.uuid}/`,payload:e,blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(Pt(r))}).catch(()=>{this.dispatch(vr(i))}),[c,n]}async delete(e){const{store:a}=this.client,i=a.getState(),c=ta(e)(i);if(!c)throw new Error(`No asset stage with uuid ${e} found in the store`);return this.dispatch(ea(e)),this.enqueueRequest({description:"Delete asset stage",method:h.DELETE,url:`/asset-stages/${e}/`,blockers:[e],blocks:[]}).catch(n=>{throw this.dispatch(xs(c)),n})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset stages",method:h.GET,url:"/asset-stages/",queryParams:{asset_procedure__organization:e},blockers:[],blocks:[]},a);return this.dispatch(Rr(i)),i}}class wb extends ke{constructor(){super(...arguments);S(this,"name","Asset Type Attachment");S(this,"url","/asset-type-attachments");S(this,"addAttachments",aa);S(this,"updateAttachments",Vr);S(this,"removeAttachments",ia);S(this,"removeAttachment",zr);S(this,"setAttachment",qr);S(this,"selectAttachment",Cr)}buildOfflineAttachment(a){return T({file:URL.createObjectURL(a.file),file_sha1:a.file_sha1,created_by:a.created_by,file_name:a.file.name,file_type:a.file.type,submitted_at:a.submitted_at,description:a.description,asset_type:a.modelUuid})}buildAttachmentPayload(a){return{...a,asset_type:a.modelUuid}}async bulkAdd(a){return this._bulkAdd(a.map(i=>({modelUuid:i.assetTypeUuid,file:i.file})))}async delete(a){return this._delete(a)}async refreshStore(a,i){const c=await this.enqueueRequest({description:"Get asset type attachments",method:h.GET,url:`${this.url}/`,queryParams:{asset_type__organization:a},blocks:[],blockers:[]},i);return this.dispatch(jr(c)),c}}class Mb extends q{async bulkAdd(e){var m;const a=new Date().toISOString(),i=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c={},n=[],r=[];for(const u of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=u,y=await this.getFilePayload(A);y.sha1 in c||(c[y.sha1]=y);const b=T({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:i,fields_revision:o,submitted_at:a,field_identifier:p});n.push(b);const P={uuid:b.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(P)}this.dispatch(Lr(n));const l=this.enqueueRequest({description:"Add asset type fields attachments",method:h.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:a,attachments:r,files:Object.values(c)},blockers:n.map(u=>u.fields_revision),blocks:n.map(u=>u.uuid)});return l.then(u=>{this.processPresignedUrls(u.presigned_urls),this.dispatch(Nr(u.attachments))}).catch(()=>{this.dispatch(Hr(n.map(u=>u.uuid)))}),[n,l.then(({attachments:u})=>u)]}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset type fields attachments",method:h.GET,url:"/asset-type-fields-attachments/",queryParams:{fields_revision__asset_type__organization:e},blockers:[e],blocks:[]},a);return this.dispatch($r(i)),i}}class Eb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Xr(n));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:h.POST,url:"/asset-type-fields/",payload:w(n),blockers:[n.asset_type],blocks:[n.uuid]});return r.then(m=>{this.dispatch(Qr(m))}).catch(m=>{throw this.dispatch(xr(n.uuid)),m}),[n,r]}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get Asset Type Fields",method:h.GET,url:"/asset-type-fields/",queryParams:{asset_type__organization:e},blockers:[],blocks:[]},a);return this.dispatch(Jr(i)),i}}class jb extends q{async bulkAdd(e,a){var u;const i=new Date().toISOString(),c=(u=this.client.store.getState().userReducer.currentUser)==null?void 0:u.id,n=$e(e,a??e.length),r=[],l=[];for(const o of n){const p={},A=[];for(const y of o){const{fieldValuesUuid:b,fieldIdentifier:P,file:_}=y,R=await this.getFilePayload(_);R.sha1 in p||(p[R.sha1]=R);const z=T({file:URL.createObjectURL(_),file_type:_.type,file_name:_.name,file_sha1:R.sha1,created_by:c,field_values:b,submitted_at:i,field_identifier:P});r.push(z);const De={uuid:z.uuid,file_name:_.name,file_sha1:R.sha1,file_extension:R.extension,field_identifier:P,field_values:b};A.push(De)}l.push({submitted_at:i,attachments:A,files:Object.values(p)})}this.dispatch(It(r));const m=l.map(o=>this.enqueueRequest({description:"Add asset type field values attachments",method:h.POST,url:"/asset-type-field-values-attachments/bulk/",payload:o,blockers:o.attachments.map(p=>p.field_values),blocks:o.attachments.map(p=>p.uuid)}));return Promise.all(m).then(o=>{for(const A of o)this.processPresignedUrls(A.presigned_urls);const p=o.flatMap(A=>A.attachments);this.dispatch(id(p))}).catch(o=>{throw this.dispatch(Ot(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:a}=this.client,i=a.getState(),c=nd(e)(i);this.dispatch(Ot(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:h.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{uuids:e},blockers:e,blocks:[]})}catch(n){throw this.dispatch(It(c)),n}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset type field values attachments",method:h.GET,url:"/asset-type-field-values-attachments/",queryParams:{limit:E,paginate:!0,field_values__asset__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset type field values attachments",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(ad(c)),c}}class qb extends v{add(e){var r;const{store:a}=this.client,i=a.getState(),c=T({...e,created_by:(r=i.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),n=this.enqueueRequest({description:"Add asset type field values",method:h.POST,url:"/asset-type-field-values/",payload:w(c),blockers:[e.asset,e.fields_revision],blocks:[c.uuid]});return this.dispatch(oa(c)),n.then(l=>(this.dispatch(st(l)),l)).catch(()=>{this.dispatch(la(c.uuid))}),[c,n]}bulkAdd(e,a){var m;const i=new Date().toISOString(),c=[],n=$e(e.payloads,a??e.payloads.length),r=[];for(const u of n){const o=[];for(const p of u){const A=T({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:i});c.push(A),o.push({uuid:A.uuid,asset:p.asset,fields_revision:p.fields_revision,published_at:p.published_at,values:A.values})}r.push({submitted_at:i,values:e.values,field_values:o})}this.dispatch(ld(c));const l=[];for(const u of r){const o=u.field_values.map(b=>b.asset),p=u.field_values.map(b=>b.fields_revision),A=u.field_values.map(b=>b.uuid),y=this.enqueueRequest({description:"Bulk add asset type field values",method:h.POST,url:"/asset-type-field-values/bulk/",payload:u,blockers:[...o,...p],blocks:A});l.push(y)}return Promise.all(l).then(u=>{this.dispatch(hd(u.flat()))}).catch(()=>{this.dispatch(md(c.map(u=>u.uuid)))}),[c,l]}update(e){const{store:a}=this.client,i=a.getState(),c=ma(e.uuid)(i);if(!c)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const n={...c,...e};this.dispatch(st(n));const r=this.enqueueRequest({description:"Delete asset type field values",method:h.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[n.uuid,n.fields_revision,n.asset],blocks:[n.uuid]});return r.then(l=>{this.dispatch(st(l))}).catch(()=>{this.dispatch(st(c))}),[n,r]}async delete(e){const{store:a}=this.client,i=a.getState(),c=ma(e)(i);if(!c)throw new Error(`Expected submission with uuid ${e} to exist`);const n=rd(e)(i);this.dispatch(la(e)),this.dispatch(Ot(n.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:h.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(oa(c)),this.dispatch(It(n)),r}}async refreshStore(e,a){const c=(await this.performPagination({immediate:!0,description:"Get asset type field values",method:h.GET,url:"/asset-type-field-values/",queryParams:{limit:E,paginate:!0,asset__project:e},blockers:[],blocks:[]},n=>({immediate:!0,description:"Get asset type field values",method:h.GET,url:n,blockers:[],blocks:[]}),a)).flat();return this.dispatch(od(c)),c}}class Vb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(Aa(n));const r=this.enqueueRequest({description:"Create asset type",method:h.POST,url:"/asset-types/",payload:w(n),blockers:[],blocks:[n.uuid]});return r.then(m=>{this.dispatch(at(m))}).catch(()=>{this.dispatch(ya(n.uuid))}),[n,r]}update(e){const{store:a}=this.client,i=Sa(e.uuid)(a.getState());if(!i)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const c={...i,...e};this.dispatch(at(c));const n=this.enqueueRequest({description:"Update asset type",method:h.PATCH,url:`/asset-types/${e.uuid}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[i.uuid],blocks:[i.uuid]});return n.then(r=>{this.dispatch(at(r))}).catch(()=>{this.dispatch(at(i))}),[c,n]}async delete(e){const{store:a}=this.client,i=a.getState(),c=Sa(e)(i);if(!c)throw new Error(`Expected asset type with uuid ${e} to exist`);const n=Ns(e)(i),r=kr(e)(i);return this.dispatch(ya(e)),this.dispatch($s(n.map(l=>l.uuid))),this.dispatch(ia(r.map(({uuid:l})=>l))),this.enqueueRequest({description:"Delete asset type",method:h.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(l=>{throw this.dispatch(Aa(c)),this.dispatch(bt(n)),this.dispatch(aa(r)),l})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get asset types",method:h.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]},a);return this.dispatch(fd(i)),i}}class zb extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch(ba(n));const r=this.enqueueRequest({description:"Create Category",method:h.POST,url:"/categories/",payload:w(n),blockers:[e.project],blocks:[n.uuid]});return[n,r]}update(e){const a=this.client.store.getState(),i=Fa(e.uuid)(a);if(!i)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const c={...i,...e};this.dispatch(Od(c));const n=this.enqueueRequest({description:"Edit Category",method:h.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[c,n]}remove(e){const{store:a}=this.client,i=Fa(e)(a.getState());if(!i)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(_d(e));const c=this.enqueueRequest({description:"Delete Category",method:h.DELETE,url:`/categories/${i.uuid}/`,blockers:[i.uuid],blocks:[]});return c.catch(()=>{this.dispatch(ba(i))}),c}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Get categories",method:h.GET,url:"/categories/",queryParams:{project__organization_owner:e},blocks:[],blockers:[]},a);return this.dispatch(Id(i)),i}}class Ub extends ke{constructor(){super(...arguments);S(this,"name","Document Attachment");S(this,"url","/document-attachments");S(this,"addAttachments",Ed);S(this,"updateAttachments",qd);S(this,"removeAttachments",zd);S(this,"removeAttachment",Vd);S(this,"setAttachment",jd);S(this,"selectAttachment",Cd)}buildOfflineAttachment(a){return T({file:URL.createObjectURL(a.file),file_sha1:a.file_sha1,created_by:a.created_by,file_name:a.file.name,file_type:a.file.type,submitted_at:a.submitted_at,description:a.description,document:a.modelUuid})}buildAttachmentPayload(a){return{...a,document:a.modelUuid}}async bulkAdd(a){var p;const{store:i}=this.client,c=(p=i.getState().userReducer.currentUser)==null?void 0:p.id,n=new Date().toISOString(),r=[],l=[],m={},u={};for(const A of a){const{documentUuid:y,file:b}=A,P=await this.getFilePayload(b);P.sha1 in m||(m[P.sha1]=P,u[P.sha1]=[]);const _=this.buildOfflineAttachment({file:b,file_sha1:P.sha1,submitted_at:n,created_by:c,description:"",modelUuid:y});r.push(_),l.push({uuid:_.uuid,file_name:_.file_name,file_sha1:_.file_sha1,file_extension:P.extension,description:_.description,document:y}),u[P.sha1].push(_.uuid)}this.dispatch(this.addAttachments(r));const o=this.enqueueRequest({description:"Attach files to document",method:h.POST,url:"/document-attachments/bulk/",payload:{submitted_at:n,attachments:l,files:Object.values(m)},blocks:r.map(A=>A.uuid),blockers:r.map(A=>A.file_sha1)});return o.then(({attachments:A,presigned_urls:y})=>{this.dispatch(this.updateAttachments(A));const b=this.processPresignedUrls(y);for(const[P,_]of Object.entries(b))_.then(()=>{const R=u[P];for(const z of R)this.makeReadable(z)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(A=>A.uuid)))}),[r,o.then(({attachments:A})=>A)]}async delete(a){return this._delete(a)}makeReadable(a){this.enqueueRequest({description:"Add attachment to AI assistant",method:h.PATCH,url:`/document-attachments/${a}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",a],blocks:["index-document-attachment"]})}async refreshStore(a,i){const c=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:"/document-attachments/",queryParams:{document__project__organization_owner:a},blocks:[],blockers:[]},i),n=await this.enqueueRequest({description:"Get document attachments",method:h.GET,url:"/document-attachments/",queryParams:{document__organization:a},blocks:[],blockers:[]},i),r=[...c,...n];return this.dispatch(Md(r)),r}}class Db extends v{add(e){var l;const{store:a}=this.client,i=(l=a.getState().userReducer.currentUser)==null?void 0:l.id,c=new Date().toISOString(),n=T({...e,created_by:i,submitted_at:c});this.dispatch($d([n]));const r=this.enqueueRequest({description:"Create Document",method:h.POST,url:"/documents/",payload:w(n),queryParams:{parent_document:n.parent_document??void 0},blockers:n.parent_document?[n.parent_document]:[],blocks:[n.uuid]});return r.catch(()=>{this.dispatch(Oa([n.uuid]))}),[n,r]}update(e){const{store:a}=this.client,i=a.getState().documentsReducer.documents[e.uuid];if(!i)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const c={...i,...e};this.dispatch(We([c]));const n=this.enqueueRequest({description:"Update Document",method:h.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return n.catch(()=>{We([i])}),[c,n]}delete(e){const{store:a}=this.client,i=Rt(a.getState()),c=Ld(e)(a.getState());if(!c)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const n=c.parent_document?i[c.parent_document]:void 0;this.dispatch(Oa([e]));const r=this.enqueueRequest({description:"Delete Document",method:h.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(l=>{this.dispatch(We(l))}).catch(()=>{this.dispatch(We([c])),n&&this.dispatch(We([n]))}),r}async refreshStore(e,a){const i=this.enqueueRequest({description:"Get project documents",method:h.GET,url:"/documents/",queryParams:{project__organization_owner:e},blockers:[],blocks:[]},a),c=this.enqueueRequest({description:"Get organization documents",method:h.GET,url:"/documents/",queryParams:{organization:e},blockers:[],blocks:[]},a),n=[...await i,...await c];return this.dispatch(Gd(n)),n}}class Cb extends v{async add(e,a){return this.enqueueRequest({description:"Add email domain to organization",method:h.POST,url:"/organization-email-domains/",payload:{email:a,organization:e},blockers:[e,"create-org"],blocks:[]})}async remove(e){return this.dispatch(Kd(e.uuid)),this.enqueueRequest({description:"Remove email domain from organization",method:h.DELETE,url:`/organization-email-domains/${e.uuid}/`,blockers:[e.domain],blocks:[]}).catch(a=>{throw this.dispatch(Yd(e)),a})}async refreshStore(e,a){const i=await this.enqueueRequest({description:"Fetch email domains for organization",method:h.GET,url:"/organization-email-domains/",queryParams:{organization:e},blockers:[e],blocks:[]},a);return this.dispatch(Wd(i)),i}}class kb extends v{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:h.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,a=void 0){return this.enqueueRequest({description:"Validate verification code",method:h.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:a,blockers:[],blocks:[]})}}const Gt={},uc=new Set;let $t=0,oc=0,lc=0;const Bb=20;class Gb extends v{constructor(){super(...arguments);S(this,"host");S(this,"_dbPromise",Am.openDB("fileCache",1,{upgrade(a){a.createObjectStore("files")}}))}async renewUploadUrl(a){const i=await this.fetchCache(a);if(!i)throw new Error(`File with sha1 ${a} not found in cache`);const c=await Kt(i,a),n=await this.enqueueRequest({description:"Get S3 URL",method:h.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await He(i),file_type:i.type,extension:i.name.split(".").pop(),size:i.size.toString()},blockers:[],blocks:[`s3-${c}`]});return"url"in n&&this.dispatch(eu({sha1:a,...n})),n}async addCache(a,i){if(uc.has(i))return;if(!a.type){const r=a.name.split("."),l=r[r.length-1];a=new File([a],a.name,{type:l})}if(!a.name||!a.size||!a.type)throw new Error("Cannot add files to cache that do not have a name, size and type.");const c=await this._dbPromise;!!await c.get("files",i)?(console.error("File already cached (this is unexpected at this point):",a.name,i),$t++):(await c.put("files",a,i),oc++),uc.add(i),lc++,lc%Bb===0&&console.debug(`File cache summary: ${$t} hits and ${oc} misses, ${$t/($t+oc)*100}% hit rate over ${lc} calls to addCache.`)}async removeCache(a){await(await this._dbPromise).delete("files",a),uc.delete(a)}async fetchCache(a){return(await this._dbPromise).get("files",a)}async getOrRenewUploadUrl(a){const i=this.client.store.getState();return tu(a)(i)??await this.renewUploadUrl(a)}async uploadFileToS3(a){const i=await this.fetchCache(a);if(!i)throw new Error(`File with sha1 ${a} not found in cache`);const c=await Kt(i,a),n={file_name:i.name,file_sha1:a,file:c},r=await this.getOrRenewUploadUrl(a);if("warning"in r){if(r.warning==="already_uploaded")return[n,Promise.resolve(void 0).then()];throw new Error(r.warning)}const l=r.url,m=this.enqueueRequest({url:l,description:"Upload file",method:h.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:a,blockers:[`s3-${c}`],blocks:[a],s3url:r});return[n,m]}async fetchFileFromUrl(a,i,c){const n=a.split("?")[0]??a,r=await this.fetchCache(i);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(a.startsWith("blob:")){const o=await Pc(a),p=new File([o],c??i,{type:o.type});return await this.addCache(p,i),p}let l=Gt[n],m=!0;l?m=!1:(l=new Promise(o=>{this.enqueueRequest({description:"Download file",method:h.GET,url:a,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[i],blocks:[i]}).then(p=>{const A=new File([p],c??i,{type:p.type});o(A)})}),Gt[n]=l);let u;try{u=await l}catch(o){throw m&&o instanceof D&&delete Gt[n],o}if(m){const o=await He(u);if(o!==i){const y=`The hash of the file returned from the server (${o}) does not match the
|
|
9
9
|
expected hash (${i}). This can happen if you're using a local development server and the
|
|
10
10
|
isExternalUrl flag in the request details is set to true, because instead of requesting the local
|
|
11
11
|
REST API, you will be requesting localhost:80 (where this app runs), resulting in a transformed blob
|
|
@@ -36,5 +36,5 @@ export declare abstract class AssetProcedureAttachmentService<TState extends Ove
|
|
|
36
36
|
file: File;
|
|
37
37
|
}[]): Promise<OptimisticMultipleModelResult<AssetProcedureAttachment>>;
|
|
38
38
|
delete(uuid: AssetProcedureAttachment["uuid"]): Promise<void>;
|
|
39
|
-
refreshStore(organizationUuid: Organization["uuid"]): Promise<AssetProcedureAttachment[]>;
|
|
39
|
+
refreshStore(organizationUuid: Organization["uuid"], signal?: AbortSignal): Promise<AssetProcedureAttachment[]>;
|
|
40
40
|
}
|
|
@@ -9,5 +9,5 @@ export declare abstract class AssetProcedureFieldsAttachmentService<TState exten
|
|
|
9
9
|
fieldIdentifier: string;
|
|
10
10
|
file: File;
|
|
11
11
|
}[]): Promise<OptimisticMultipleModelResult<AssetProcedureFieldsAttachment>>;
|
|
12
|
-
refreshStore(organizationUuid: Organization["uuid"]): Promise<AssetProcedureFieldsAttachment[]>;
|
|
12
|
+
refreshStore(organizationUuid: Organization["uuid"], signal?: AbortSignal): Promise<AssetProcedureFieldsAttachment[]>;
|
|
13
13
|
}
|
|
@@ -5,5 +5,5 @@ import { OptimisticModelResult } from '../typings';
|
|
|
5
5
|
import { BaseApiService } from './BaseApiService';
|
|
6
6
|
export declare abstract class AssetProcedureFieldsService<TState extends OvermapRootState, TSDK extends BaseSDK<TState>> extends BaseApiService<TState, TSDK> {
|
|
7
7
|
add(payload: Payload<AssetProcedureFields>): OptimisticModelResult<AssetProcedureFields>;
|
|
8
|
-
refreshStore(organizationUuid: Organization["uuid"]): Promise<AssetProcedureFields[]>;
|
|
8
|
+
refreshStore(organizationUuid: Organization["uuid"], signal?: AbortSignal): Promise<AssetProcedureFields[]>;
|
|
9
9
|
}
|
|
@@ -9,5 +9,5 @@ export declare abstract class AssetProcedureStepFieldsAttachmentService<TState e
|
|
|
9
9
|
fieldIdentifier: string;
|
|
10
10
|
file: File;
|
|
11
11
|
}[]): Promise<OptimisticMultipleModelResult<AssetProcedureStepFieldsAttachment>>;
|
|
12
|
-
refreshStore(organizationUuid: Organization["uuid"]): Promise<AssetProcedureStepFieldsAttachment[]>;
|
|
12
|
+
refreshStore(organizationUuid: Organization["uuid"], signal?: AbortSignal): Promise<AssetProcedureStepFieldsAttachment[]>;
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Core functionality for Overmap",
|
|
4
4
|
"author": "Wôrdn Inc.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
|
-
"version": "1.0.78-view-sets.
|
|
6
|
+
"version": "1.0.78-view-sets.36",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/overmap-core.umd.cjs",
|
|
9
9
|
"module": "dist/overmap-core.js",
|