@overmap-ai/core 1.0.74-form-changes.0 → 1.0.74-form-changes.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4401,8 +4401,8 @@ class ib extends I {
4401
4401
  return this.enqueueRequest({
4402
4402
  description: "Add email domain to organization",
4403
4403
  method: u.POST,
4404
- url: `/organizations/${e}/email-domains/`,
4405
- payload: { email: s },
4404
+ url: "/organization-email-domains/",
4405
+ payload: { email: s, organization: e },
4406
4406
  blockers: [e, "create-org"],
4407
4407
  blocks: []
4408
4408
  });
@@ -4411,7 +4411,7 @@ class ib extends I {
4411
4411
  return this.dispatch(wo(e.uuid)), this.enqueueRequest({
4412
4412
  description: "Remove email domain from organization",
4413
4413
  method: u.DELETE,
4414
- url: `/organizations/${e.organization}/email-domains/${e.uuid}/`,
4414
+ url: `/organization-email-domains/${e.uuid}/`,
4415
4415
  blockers: [e.domain],
4416
4416
  blocks: []
4417
4417
  }).catch((s) => {
@@ -4422,7 +4422,10 @@ class ib extends I {
4422
4422
  const s = await this.enqueueRequest({
4423
4423
  description: "Fetch email domains for organization",
4424
4424
  method: u.GET,
4425
- url: `/organizations/${e}/email-domains/`,
4425
+ url: "/organization-email-domains/",
4426
+ queryParams: {
4427
+ organization: e
4428
+ },
4426
4429
  blockers: [e],
4427
4430
  blocks: []
4428
4431
  });
@@ -5067,7 +5070,10 @@ class lb extends E {
5067
5070
  const s = await this.enqueueRequest({
5068
5071
  description: "Get geo images",
5069
5072
  method: u.GET,
5070
- url: `/projects/${e}/geo-images/`,
5073
+ url: "/geo-images/",
5074
+ queryParams: {
5075
+ project: e
5076
+ },
5071
5077
  blocks: [e],
5072
5078
  blockers: []
5073
5079
  });
@@ -6080,7 +6086,7 @@ class Fb extends I {
6080
6086
  const s = this.enqueueRequest({
6081
6087
  description: "Edit organization access",
6082
6088
  method: u.PATCH,
6083
- url: `/organizations/${e.organization}/access/${e.uuid}/`,
6089
+ url: `/organization-accesses/${e.uuid}/`,
6084
6090
  payload: e,
6085
6091
  blockers: [e.uuid],
6086
6092
  blocks: [e.uuid]
@@ -6093,7 +6099,7 @@ class Fb extends I {
6093
6099
  return this.dispatch(Xu(e.uuid)), this.dispatch(Ku(e.user)), this.enqueueRequest({
6094
6100
  description: "Remove organization access",
6095
6101
  method: u.DELETE,
6096
- url: `/organizations/${e.organization}/access/${e.uuid}/`,
6102
+ url: `/organization-accesses/${e.uuid}/`,
6097
6103
  blockers: [e.uuid],
6098
6104
  blocks: []
6099
6105
  });
@@ -6102,7 +6108,10 @@ class Fb extends I {
6102
6108
  const s = await this.enqueueRequest({
6103
6109
  description: "Get organization accesses",
6104
6110
  method: u.GET,
6105
- url: `/organizations/${e}/access/`,
6111
+ url: "/organization-accesses/",
6112
+ queryParams: {
6113
+ organization: e
6114
+ },
6106
6115
  blockers: [],
6107
6116
  blocks: []
6108
6117
  });
@@ -6425,9 +6434,8 @@ class qb extends I {
6425
6434
  const i = this.enqueueRequest({
6426
6435
  description: "Create team",
6427
6436
  method: u.POST,
6428
- url: `/organizations/${e.organization}/teams/`,
6437
+ url: "/teams/",
6429
6438
  payload: s,
6430
- // No blocks since users and organizations are not offline
6431
6439
  blockers: [],
6432
6440
  blocks: [s.uuid]
6433
6441
  });
@@ -6449,7 +6457,7 @@ class qb extends I {
6449
6457
  const a = this.enqueueRequest({
6450
6458
  description: "Update team",
6451
6459
  method: u.PATCH,
6452
- url: `/organizations/teams/${e.uuid}/`,
6460
+ url: `/teams/${e.uuid}/`,
6453
6461
  payload: P(e),
6454
6462
  blockers: [e.uuid],
6455
6463
  blocks: [e.uuid]
@@ -6469,7 +6477,7 @@ class qb extends I {
6469
6477
  return await this.enqueueRequest({
6470
6478
  description: "Delete team",
6471
6479
  method: u.DELETE,
6472
- url: `/organizations/teams/${e}/`,
6480
+ url: `/teams/${e}/`,
6473
6481
  blockers: [e],
6474
6482
  blocks: [e]
6475
6483
  });
@@ -6487,7 +6495,7 @@ class qb extends I {
6487
6495
  const a = this.enqueueRequest({
6488
6496
  description: "Set team members",
6489
6497
  method: u.PUT,
6490
- url: `/organizations/teams/${e}/set-members/`,
6498
+ url: `/teams/${e}/set-members/`,
6491
6499
  payload: {
6492
6500
  users: s
6493
6501
  },
@@ -6516,7 +6524,10 @@ class qb extends I {
6516
6524
  const s = await this.enqueueRequest({
6517
6525
  description: "Fetch teams",
6518
6526
  method: u.GET,
6519
- url: `/organizations/${e}/teams/`,
6527
+ url: "/teams/",
6528
+ queryParams: {
6529
+ organization: e
6530
+ },
6520
6531
  blockers: [],
6521
6532
  blocks: []
6522
6533
  });
@@ -5,11 +5,11 @@ Retries:`,s),!(t instanceof Error))throw console.error("ENCOUNTERED NON-ERROR ER
5
5
  Action:`,e);const p=Fe();if(!p)throw new Error("Outbox coordinator not set");p.remove(e.payload.uuid),t.options.discard=!0,u()}}console.debug("Registering a retry for request:",e.payload.uuid);const m=Fe();if(!m)throw new Error("Outbox coordinator not set");return m.registerRetry(e.payload.uuid),!1}function rf(t,e,s){var n;return(n=Fe())==null?void 0:n.peek()}function df(t,e){return Je().dispatch(Bo(new Date().getTime())),qn}const ke="An unknown error occurred",uf=500,Cl=["non_field_errors","detail"];function of(t,e){let s;if(t!=null&&t.body)if(typeof t.body=="object"){const n=t.body;if(typeof n.error=="string")s=n.error;else if(typeof n.message=="string")s=n.message;else try{s=Object.entries(n).map(([a,c])=>typeof c=="string"?Cl.includes(a)?c:`${a}: ${c}`:Array.isArray(c)?Cl.includes(a)?c.join(`
6
6
  `):c.map(r=>`${a}: ${r}`).join(`
7
7
  `):`${a}: ${JSON.stringify(c)}`).join(`
8
- `)}catch(a){console.error("Failed to extract error message from response body",a)}}else typeof t.body=="string"&&(s=t.body);else t!=null&&t.text?s=t.text:e instanceof Error&&(s=e.message);return!s||s.length>uf?ke:s}class q extends Error{constructor(s){super(ke);f(this,"status");f(this,"response");f(this,"message");f(this,"options");const{response:n,innerError:a}=s;this.message=s.message??of(n,a)??ke,this.status=(n==null?void 0:n.status)??0,this.response=n,s.discard=s.discard??!1,this.options=s}}class lf extends Il{constructor(e){super(e)}}class P extends Il{constructor(s,n){super(s);f(this,"auth");this.auth=n}}class hf extends P{async startConversation(e,s){return this.enqueueRequest({description:"Start agent conversation",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:s},blockers:["prompt"],blocks:["prompt"]}).then(n=>(this.dispatch(Ln(n)),n))}async continueConversation(e,s,n){return this.enqueueRequest({description:"Prompt agent",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:s}}).then(a=>{this.dispatch(Hn(a))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:l.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(s=>{this.dispatch(Nn(s))})}async rate(e,s){return this.enqueueRequest({description:"Rate agent response",method:l.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:s},blockers:["rate"],blocks:["rate"]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get agent conversation history",method:l.GET,url:`/projects/${e}/agent-conversations/`,blockers:["agent-conversations"],blocks:["agent-conversations"]});this.dispatch(Gn(s))}}class E extends P{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:s,assetAttachmentReducer:n,assetTypeAttachmentReducer:a,documentAttachmentReducer:c,projectAttachmentReducer:r,formRevisionAttachmentReducer:u,formSubmissionAttachmentReducer:m,geoImageReducer:d,assetTypeFieldsAttachmentReducer:o,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:A,issueTypeFieldValuesAttachmentReducer:y}=this.client.store.getState();return[].concat(Object.values(s.instances),Object.values(n.instances),Object.values(a.instances),Object.values(c.instances),Object.values(r.instances),Object.values(u.instances),Object.values(m.instances),Object.values(d.instances),Object.values(o.instances),Object.values(p.instances),Object.values(A.instances),Object.values(y.instances)).filter(I=>I.file_sha1===e).length}processPresignedUrls(e){const s={};for(const[n,a]of Object.entries(e))s[n]=this.enqueueRequest({url:a.url,description:"Upload file to S3",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:n,blockers:[`s3-${a.fields.key}`],blocks:[n],s3url:a});return s}async getFilePayload(e){const s=await _e(e),n={sha1:s,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,s),n}}class Re extends E{async _bulkAdd(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=[],r=[],u={};for(const o of e){const{modelUuid:p,file:A}=o,y=await this.getFilePayload(A);y.sha1 in u||(u[y.sha1]=y);const T=this.buildOfflineAttachment({file:A,file_sha1:y.sha1,submitted_at:a,created_by:n,description:"",modelUuid:p});c.push(T),r.push(this.buildAttachmentPayload({uuid:T.uuid,file_name:T.file_name,file_sha1:T.file_sha1,file_extension:y.extension,description:T.description,modelUuid:p}))}this.dispatch(this.addAttachments(c));const m=this.enqueueRequest({description:`Add ${this.name}`,method:l.POST,url:`${this.url}/bulk/`,payload:{submitted_at:a,attachments:r,files:Object.values(u)},blocks:c.map(o=>o.uuid),blockers:c.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(c.map(o=>o.uuid)))}),[c,m.then(({attachments:o})=>o)]}async _delete(e){const{store:s}=this.client,n=this.selectAttachment(e)(s.getState());if(!n)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(n.uuid));const a=this.enqueueRequest({description:`Delete ${this.name}`,method:l.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return a.then(()=>{this.getNumberOfAttachmentsWithSha1(n.file_sha1)===0&&this.client.files.removeCache(n.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(n))}),a}}class mf extends Re{constructor(){super(...arguments);f(this,"name","Asset Attachment");f(this,"url","/asset-attachments");f(this,"initializeAttachments",Dt);f(this,"addAttachments",Vt);f(this,"updateAttachments",Jn);f(this,"removeAttachments",Ut);f(this,"removeAttachment",Xn);f(this,"setAttachment",Yn);f(this,"selectAttachment",xn)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.assetUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(Dt(n))}}class pf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(na(c));const u=this.enqueueRequest({description:"Add asset procedure fields attachments",method:l.POST,url:"/asset-procedure-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(aa(d.attachments))}).catch(()=>{this.dispatch(ca(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure fields attachments",method:l.GET,url:"/asset-procedure-fields-attachments/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(ia(s))}}class Af extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ha(c));const r=this.enqueueRequest({description:"Add Asset Procedure Fields",method:l.POST,url:"/asset-procedure-fields/",payload:c,blockers:[c.asset_procedure],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ma(m))}).catch(m=>{throw this.dispatch(pa(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Procedure Fields",method:l.GET,url:"/asset-procedure-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(la(s))}}function Xe(t,e){const s=[];let n=0;const a=t.length;for(;n<a;)s.push(t.slice(n,n+=e));return s}class yf extends E{async bulkAdd(e,s){var d;const n=new Date().toISOString(),a=(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.id,c=Xe(e,s??e.length),r=[],u=[];for(const o of c){const p={},A=[];for(const y of o){const{fieldValuesUuid:T,fieldIdentifier:I,file:F}=y,O=await this.getFilePayload(F);O.sha1 in p||(p[O.sha1]=O);const M=R({file:URL.createObjectURL(F),file_type:F.type,file_name:F.name,file_sha1:O.sha1,created_by:a,field_values:T,submitted_at:n,field_identifier:I});r.push(M);const Pt={uuid:M.uuid,file_name:F.name,file_sha1:O.sha1,file_extension:O.extension,field_identifier:I,field_values:T};A.push(Pt)}u.push({submitted_at:n,attachments:A,files:Object.values(p)})}this.dispatch(Ze(r));const m=u.map(o=>this.enqueueRequest({description:"Add asset procedure field values attachments",method:l.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(ga(p))}).catch(o=>{throw this.dispatch(xe(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=ba(e)(n);this.dispatch(xe(e));try{await this.enqueueRequest({description:"Delete asset procedure field values attachments",method:l.DELETE,url:"/asset-procedure-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(Ze(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values attachments",method:l.GET,url:"/asset-procedure-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Sa(s))}}class ff extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset procedure field values",method:l.POST,url:"/asset-procedure-field-values/",payload:v(a),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[a.uuid]});return this.dispatch(Wt(a)),c.then(u=>(this.dispatch(De(u)),u)).catch(()=>{this.dispatch(Kt(a.uuid))}),[a,c]}bulkAdd(e,s){var m;const n=new Date().toISOString(),a=[],c=Xe(e.payloads,s??e.payloads.length),r=[];for(const d of c){const o=[];for(const p of d){const A=R({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:n});a.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:n,values:e.values,field_values:o})}this.dispatch(Oa(a));const u=[];for(const d of r){const o=d.field_values.map(I=>I.asset),p=d.field_values.map(I=>I.fields_revision),A=d.field_values.map(I=>I.asset_procedure_instance),y=d.field_values.map(I=>I.uuid),T=this.enqueueRequest({description:"Bulk add asset procedure field values",method:l.POST,url:"/asset-procedure-field-values/bulk/",payload:d,blockers:[...o,...p,...A],blocks:y});u.push(T)}return Promise.all(u).then(d=>{this.dispatch(va(d.flat()))}).catch(()=>{this.dispatch(_a(a.map(d=>d.uuid)))}),[a,u]}update(e){const{store:s}=this.client,n=s.getState(),a=Jt(e.uuid)(n);if(!a)throw new Error(`Expected AssetProcedureFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(De(c));const r=this.enqueueRequest({description:"Update asset procedure field values",method:l.PATCH,url:`/asset-procedure-field-values/${e.uuid}/`,payload:e,blockers:[c.fields_revision,c.asset,c.asset_procedure_instance],blocks:[c.uuid]});return r.then(u=>{this.dispatch(De(u))}).catch(()=>{this.dispatch(De(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Jt(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Ia(e)(n);this.dispatch(Kt(e)),this.dispatch(xe(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure field values",method:l.DELETE,url:`/asset-procedure-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Wt(a)),this.dispatch(Ze(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values",method:l.GET,url:"/asset-procedure-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Pa(s))}}class Sf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Qt(c));const r=this.enqueueRequest({description:"Create asset procedure instance",method:l.POST,url:"/asset-procedure-instances/",payload:v(c),blockers:[e.asset_procedure,e.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Ve(m))}).catch(()=>{this.dispatch(Zt(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=ts(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset procedure instance with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(Ve(a));const c=this.enqueueRequest({description:"Update asset procedure instance",method:l.PATCH,url:`/asset-procedure-instances/${e.uuid}/`,payload:e,blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Ve(r))}).catch(()=>{this.dispatch(Ve(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=ts(e)(n);if(!a)throw new Error(`Expected asset procedure instance with uuid ${e} to exist`);return this.dispatch(Zt(e)),this.enqueueRequest({description:"Delete asset procedure instance",method:l.DELETE,url:`/asset-procedure-instances/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(Qt(a)),c})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure instances",method:l.GET,url:"/asset-procedure-instances/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(qa(s))}}class gf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(is(c));const r=this.enqueueRequest({description:"Create asset procedure",method:l.POST,url:"/asset-procedures/",payload:v(c),blockers:[],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Ue(m))}).catch(()=>{this.dispatch(ns(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=cs(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(Ue(a));const c=this.enqueueRequest({description:"Update asset procedure",method:l.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Ue(r))}).catch(()=>{this.dispatch(Ue(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=cs(e)(n);if(!a)throw new Error(`Expected asset procedure with uuid ${e} to exist`);const c=Ca(e)(n);return this.dispatch(ns(e)),this.dispatch(ka(c.map(r=>r.uuid))),this.enqueueRequest({description:"Delete asset procedure",method:l.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(is(a)),this.dispatch(Ma(c)),r})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedures",method:l.GET,url:"/asset-procedures/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Va(s))}}class Tf extends P{add(e){var u;const{store:s}=this.client;if(!e.canvas_marker&&!e.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");const n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ds(c));const r=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/assets/",payload:v(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch($e(m))}).catch(()=>{this.dispatch(os(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=ms(e.uuid)(s.getState());if(!n)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const a={...n,...e};if(!a.canvas_marker&&!a.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");this.dispatch($e(a));const c=this.enqueueRequest({description:"Edit asset",method:l.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch($e(r))}).catch(()=>{this.dispatch($e(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=ms(e)(n);if(!a)throw new Error(`No asset with uuid ${e} found in the store`);const c=ea(e)(n),r=rd(e)(n),u=Pd(e)(n);if(this.dispatch(os(e)),c.length>0){const m=c.map(({uuid:d})=>d);this.dispatch(Ut(m))}if(r.length>0){const m=r.map(({uuid:d})=>d);this.dispatch(ht(m))}if(u.length>0){const m=u.map(({uuid:d})=>d);this.dispatch(gi(m))}return this.enqueueRequest({description:"Delete asset",method:l.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(ds(a)),this.dispatch(Vt(c)),this.dispatch(lt(r)),this.dispatch(fi(u)),m})}bulkAdd(e,s,n,a){const c=new Date().toISOString(),r=fe.v4(),u=Xe(e,a).map(o=>{const p=o.map(A=>R(A));return{batchId:fe.v4(),payload:{transaction_id:r,submitted_at:c,asset_type:s,project:n,assets:p}}}),m=[];let d=null;for(const o of u){const{batchId:p,payload:A}=o,y=A.assets.map(O=>O.uuid),T=[s];d&&T.push(d);const I=y;I.push(p);const F=this.enqueueRequest({description:"Batch create assets",method:l.POST,url:"/assets/bulk/",payload:A,blockers:T,blocks:I});d=o.batchId,m.push(F)}return Promise.all(m).then(o=>{const p=o.flat();this.dispatch(us(p))}),m}async refreshStore(e){const s=await this.enqueueRequest({description:"Get assets",method:l.GET,url:"/assets/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Ga(s))}}class bf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(As(c));const r=this.enqueueRequest({description:"Add asset stage completion",method:l.POST,url:"/asset-stage-completions/",payload:v(c),blockers:[e.asset,e.stage],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Ya(m))}).catch(()=>{this.dispatch(fs(c.uuid))}),[c,r]}delete(e){const{store:s}=this.client,n=Qa(e)(s.getState());if(!n)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(fs(e));const a=this.enqueueRequest({description:"Delete asset stage completion",method:l.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(As(n))}),a}bulkAdd(e){var d;const{store:s}=this.client,n=new Date().toISOString(),a=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,c=e.map(o=>R(o)),r=c.map(o=>({...o,created_by:a,submitted_at:n})),u=r.map(({uuid:o})=>o);this.dispatch(ys(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:l.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:n,completions:c},blockers:[...e.map(o=>o.asset_procedure_instance),...e.map(o=>o.stage),...e.map(o=>o.asset)],blocks:u});return m.then(o=>{this.dispatch(Ja(o))}).catch(()=>{this.dispatch(Ss(u))}),[r,m]}bulkDelete(e){const{store:s}=this.client,n=Za(e)(s.getState());this.dispatch(Ss(e));const a=this.enqueueRequest({description:"Deleting asset stage completions",method:l.DELETE,url:"/asset-stage-completions/bulk/",payload:{completion_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(ys(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stage completions",method:l.GET,url:"/asset-stage-completions/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Ka(s))}}class If extends P{bulkAdd(e,s){var m;const n=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c=e.map(d=>R(d)),r=c.map(d=>({...d,asset_procedure:s,created_by:a,submitted_at:n}));this.dispatch(bs(r));const u=this.enqueueRequest({description:"Add asset stages",method:l.POST,url:"/asset-stages/bulk/",payload:{submitted_at:n,asset_procedure:s,stages:c},blockers:[s],blocks:c.map(({uuid:d})=>d)});return u.then(d=>{this.dispatch(et(d))}).catch(()=>{this.dispatch(Fs(r.map(({uuid:d})=>d)))}),[r,u]}async bulkUpdate(e,s){const a=this.client.store.getState(),c=Rs(e.map(({uuid:r})=>r))(a);return this.dispatch(et(e)),this.enqueueRequest({description:"Edit asset stages",method:l.PATCH,url:`/asset-procedures/${s}/bulk-update-stages/`,payload:{stages:e},blockers:[s],blocks:e.map(({uuid:r})=>r)}).catch(r=>{throw this.dispatch(et(c)),r})}async bulkDelete(e){const{store:s}=this.client,n=Rs(e)(s.getState());this.dispatch(Fs(e));const a=this.enqueueRequest({description:"Delete asset stages",method:l.DELETE,url:"/asset-stages/bulk/",payload:{stage_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(bs(n))}),a}update(e){const{store:s}=this.client,n=ic(e.uuid)(s.getState());if(!n)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const a={...n,...e};this.dispatch(Is(a));const c=this.enqueueRequest({description:"Update asset stage",method:l.PATCH,url:`/asset-stages/${n.uuid}/`,payload:{name:e.name,description:e.description,priority:e.priority,color:e.color},blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Is(r))}).catch(()=>{this.dispatch(tc(n))}),[a,c]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stages",method:l.GET,url:"/asset-stages/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(ec(s))}}class Ff extends Re{constructor(){super(...arguments);f(this,"name","Asset Type Attachment");f(this,"url","/asset-type-attachments");f(this,"addAttachments",Os);f(this,"updateAttachments",dc);f(this,"removeAttachments",vs);f(this,"removeAttachment",uc);f(this,"setAttachment",rc);f(this,"selectAttachment",hc)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.assetTypeUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset type attachments",method:l.GET,url:`${this.url}/`,queryParams:{organization:s},blocks:[],blockers:[]});this.dispatch(cc(n))}}class Rf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(fc(c));const u=this.enqueueRequest({description:"Add asset type fields attachments",method:l.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Sc(d.attachments))}).catch(()=>{this.dispatch(gc(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type fields attachments",method:l.GET,url:"/asset-type-fields-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(yc(s))}}class Pf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Pc(c));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:l.POST,url:"/asset-type-fields/",payload:c,blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Oc(m))}).catch(m=>{throw this.dispatch(vc(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Type Fields",method:l.GET,url:"/asset-type-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Rc(s))}}class Of extends E{async bulkAdd(e,s){var d;const n=new Date().toISOString(),a=(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.id,c=Xe(e,s??e.length),r=[],u=[];for(const o of c){const p={},A=[];for(const y of o){const{fieldValuesUuid:T,fieldIdentifier:I,file:F}=y,O=await this.getFilePayload(F);O.sha1 in p||(p[O.sha1]=O);const M=R({file:URL.createObjectURL(F),file_type:F.type,file_name:F.name,file_sha1:O.sha1,created_by:a,field_values:T,submitted_at:n,field_identifier:I});r.push(M);const Pt={uuid:M.uuid,file_name:F.name,file_sha1:O.sha1,file_extension:O.extension,field_identifier:I,field_values:T};A.push(Pt)}u.push({submitted_at:n,attachments:A,files:Object.values(p)})}this.dispatch(it(r));const m=u.map(o=>this.enqueueRequest({description:"Add asset type field values attachments",method:l.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(qc(p))}).catch(o=>{throw this.dispatch(nt(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=kc(e)(n);this.dispatch(nt(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:l.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(it(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values attachments",method:l.GET,url:"/asset-type-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(jc(s))}}class vf extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset type field values",method:l.POST,url:"/asset-type-field-values/",payload:v(a),blockers:[e.asset,e.fields_revision],blocks:[a.uuid]});return this.dispatch(Ms(a)),c.then(u=>(this.dispatch(Be(u)),u)).catch(()=>{this.dispatch(ks(a.uuid))}),[a,c]}bulkAdd(e,s){var m;const n=new Date().toISOString(),a=[],c=Xe(e.payloads,s??e.payloads.length),r=[];for(const d of c){const o=[];for(const p of d){const A=R({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:n});a.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:n,values:e.values,field_values:o})}this.dispatch(Uc(a));const u=[];for(const d of r){const o=d.field_values.map(T=>T.asset),p=d.field_values.map(T=>T.fields_revision),A=d.field_values.map(T=>T.uuid),y=this.enqueueRequest({description:"Bulk add asset type field values",method:l.POST,url:"/asset-type-field-values/bulk/",payload:d,blockers:[...o,...p],blocks:A});u.push(y)}return Promise.all(u).then(d=>{this.dispatch($c(d.flat()))}).catch(()=>{this.dispatch(Bc(a.map(d=>d.uuid)))}),[a,u]}update(e){const{store:s}=this.client,n=s.getState(),a=zs(e.uuid)(n);if(!a)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(Be(c));const r=this.enqueueRequest({description:"Delete asset type field values",method:l.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.asset],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Be(u))}).catch(()=>{this.dispatch(Be(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=zs(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Cc(e)(n);this.dispatch(ks(e)),this.dispatch(nt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:l.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Ms(a)),this.dispatch(it(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values",method:l.GET,url:"/asset-type-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Vc(s))}}class _f extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Vs(c));const r=this.enqueueRequest({description:"Create asset type",method:l.POST,url:"/asset-types/",payload:v(c),blockers:[],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Ge(m))}).catch(()=>{this.dispatch(Us(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=Bs(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(Ge(a));const c=this.enqueueRequest({description:"Update asset type",method:l.PATCH,url:`/asset-types/${e.uuid}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Ge(r))}).catch(()=>{this.dispatch(Ge(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Bs(e)(n);if(!a)throw new Error(`Expected asset type with uuid ${e} to exist`);const c=hs(e)(n),r=mc(e)(n);return this.dispatch(Us(e)),this.dispatch(La(c.map(u=>u.uuid))),this.dispatch(vs(r.map(({uuid:u})=>u))),this.enqueueRequest({description:"Delete asset type",method:l.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(u=>{throw this.dispatch(Vs(a)),this.dispatch(us(c)),this.dispatch(Os(r)),u})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset types",method:l.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Hc(s))}}class wf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Ls(c));const r=this.enqueueRequest({description:"Create Category",method:l.POST,url:"/categories/",payload:v(c),blockers:[e.project],blocks:[c.uuid]});return[c,r]}update(e){const s=this.client.store.getState(),n=Hs(e.uuid)(s);if(!n)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const a={...n,...e};this.dispatch(Zc(a));const c=this.enqueueRequest({description:"Edit Category",method:l.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[a,c]}remove(e){const{store:s}=this.client,n=Hs(e)(s.getState());if(!n)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(xc(e));const a=this.enqueueRequest({description:"Delete Category",method:l.DELETE,url:`/categories/${n.uuid}/`,blockers:[n.uuid],blocks:[]});return a.catch(()=>{this.dispatch(Ls(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get categories",method:l.GET,url:"/categories/",queryParams:{project:e},blocks:[],blockers:[]});this.dispatch(Qc(s))}}class Ef extends Re{constructor(){super(...arguments);f(this,"name","Document Attachment");f(this,"url","/document-attachments");f(this,"addAttachments",ir);f(this,"updateAttachments",ar);f(this,"removeAttachments",rr);f(this,"removeAttachment",cr);f(this,"setAttachment",nr);f(this,"selectAttachment",or)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,document:s.modelUuid})}buildAttachmentPayload(s){return{...s,document:s.modelUuid}}async bulkAdd(s){var p;const{store:n}=this.client,a=(p=n.getState().userReducer.currentUser)==null?void 0:p.id,c=new Date().toISOString(),r=[],u=[],m={},d={};for(const A of s){const{documentUuid:y,file:T}=A,I=await this.getFilePayload(T);I.sha1 in m||(m[I.sha1]=I,d[I.sha1]=[]);const F=this.buildOfflineAttachment({file:T,file_sha1:I.sha1,submitted_at:c,created_by:a,description:"",modelUuid:y});r.push(F),u.push({uuid:F.uuid,file_name:F.file_name,file_sha1:F.file_sha1,file_extension:I.extension,description:F.description,document:y}),d[I.sha1].push(F.uuid)}this.dispatch(this.addAttachments(r));const o=this.enqueueRequest({description:"Attach files to document",method:l.POST,url:"/document-attachments/bulk/",payload:{submitted_at:c,attachments:u,files:Object.values(m)},blocks:r.map(A=>A.uuid),blockers:r.map(A=>A.file_sha1)});return o.then(({attachments:A,presigned_urls:y})=>{this.dispatch(this.updateAttachments(A));const T=this.processPresignedUrls(y);for(const[I,F]of Object.entries(T))F.then(()=>{const O=d[I];for(const M of O)this.makeReadable(M)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(A=>A.uuid)))}),[r,o.then(({attachments:A})=>A)]}async delete(s){return this._delete(s)}makeReadable(s){this.enqueueRequest({description:"Add attachment to AI assistant",method:l.PATCH,url:`/document-attachments/${s}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",s],blocks:["index-document-attachment"]})}async refreshStore(s,n){const a=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/projects/${s}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(sr(a));const c=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/organizations/${n}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(this.addAttachments(c))}}class jf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(pr([c]));const r=this.enqueueRequest({description:"Create Document",method:l.POST,url:"/documents/",payload:v(c),queryParams:{parent_document:c.parent_document??void 0},blockers:c.parent_document?[c.parent_document]:[],blocks:[c.uuid]});return r.catch(()=>{this.dispatch(Ys([c.uuid]))}),[c,r]}update(e){const{store:s}=this.client,n=s.getState().documentsReducer.documents[e.uuid];if(!n)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const a={...n,...e};this.dispatch(ye([a]));const c=this.enqueueRequest({description:"Update Document",method:l.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{ye([n])}),[a,c]}move(e,s,n){const{store:a}=this.client,c=we(a.getState()),r=[],u=c[e];if(!u)throw new Error(`attempting to move a document with uuid ${e} that does not exist in store.documents`);if(r.push(u),u.parent_document&&r.push(c[u.parent_document]),s){const d=c[s];if(!d)throw new Error(`attempting to move a document to target with uuid ${s} that does not exist in store.documents`);r.push(d),d.parent_document&&r.push(c[d.parent_document])}this.dispatch(Ar({documentId:e,targetDocumentId:s,position:n}));const m=this.enqueueRequest({description:"Move Document",method:l.PATCH,url:`/documents/${e}/move/`,queryParams:{target:s??void 0,position:n},blockers:[e],blocks:[]});return m.then(d=>{this.dispatch(ye(d))}).catch(()=>{this.dispatch(ye(r))}),m}delete(e){const{store:s}=this.client,n=we(s.getState()),a=fr(e)(s.getState());if(!a)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const c=a.parent_document?n[a.parent_document]:void 0;this.dispatch(Ys([e]));const r=this.enqueueRequest({description:"Delete Document",method:l.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(u=>{this.dispatch(ye(u))}).catch(()=>{this.dispatch(ye([a])),c&&this.dispatch(ye([c]))}),r}async refreshStore(e,s){const n=this.enqueueRequest({description:"Get project documents",method:l.GET,url:`/projects/${e}/documents/`,blockers:[],blocks:[]}),a=this.enqueueRequest({description:"Get organization documents",method:l.GET,url:`/organizations/${s}/documents/`,blockers:[],blocks:[]});this.dispatch(mr([...await n,...await a]))}}class qf extends P{async add(e,s){return this.enqueueRequest({description:"Add email domain to organization",method:l.POST,url:`/organizations/${e}/email-domains/`,payload:{email:s},blockers:[e,"create-org"],blocks:[]})}async remove(e){return this.dispatch(br(e.uuid)),this.enqueueRequest({description:"Remove email domain from organization",method:l.DELETE,url:`/organizations/${e.organization}/email-domains/${e.uuid}/`,blockers:[e.domain],blocks:[]}).catch(s=>{throw this.dispatch(Tr(e)),s})}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch email domains for organization",method:l.GET,url:`/organizations/${e}/email-domains/`,blockers:[e],blocks:[]});this.dispatch(gr(s))}}class Mf extends P{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:l.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,s=void 0){return this.enqueueRequest({description:"Validate verification code",method:l.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:s,blockers:[],blocks:[]})}}const Ft={},In=new Set;let Rt=0,Fn=0,Rn=0;const kf=20;class Cf extends P{constructor(){super(...arguments);f(this,"host");f(this,"_dbPromise",Gl.openDB("fileCache",1,{upgrade(s){s.createObjectStore("files")}}))}async renewUploadUrl(s){const n=await this.fetchCache(s);if(!n)throw new Error(`File with sha1 ${s} not found in cache`);const a=await Mt(n,s),c=await this.enqueueRequest({description:"Get S3 URL",method:l.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await _e(n),file_type:n.type,extension:n.name.split(".").pop(),size:n.size.toString()},blockers:[],blocks:[`s3-${a}`]});return"url"in c&&this.dispatch(vr({sha1:s,...c})),c}async addCache(s,n){if(In.has(n))return;if(!s.type){const r=s.name.split("."),u=r[r.length-1];s=new File([s],s.name,{type:u})}if(!s.name||!s.size||!s.type)throw new Error("Cannot add files to cache that do not have a name, size and type.");const a=await this._dbPromise;!!await a.get("files",n)?(console.error("File already cached (this is unexpected at this point):",s.name,n),Rt++):(await a.put("files",s,n),Fn++),In.add(n),Rn++,Rn%kf===0&&console.debug(`File cache summary: ${Rt} hits and ${Fn} misses, ${Rt/(Rt+Fn)*100}% hit rate over ${Rn} calls to addCache.`)}async removeCache(s){await(await this._dbPromise).delete("files",s),In.delete(s)}async fetchCache(s){return(await this._dbPromise).get("files",s)}async getOrRenewUploadUrl(s){const n=this.client.store.getState();return _r(s)(n)??await this.renewUploadUrl(s)}async uploadFileToS3(s){const n=await this.fetchCache(s);if(!n)throw new Error(`File with sha1 ${s} not found in cache`);const a=await Mt(n,s),c={file_name:n.name,file_sha1:s,file:a},r=await this.getOrRenewUploadUrl(s);if("warning"in r){if(r.warning==="already_uploaded")return[c,Promise.resolve(void 0).then()];throw new Error(r.warning)}const u=r.url,m=this.enqueueRequest({url:u,description:"Upload file",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:s,blockers:[`s3-${a}`],blocks:[s],s3url:r});return[c,m]}async fetchFileFromUrl(s,n,a){const c=s.split("?")[0]??s,r=await this.fetchCache(n);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(s.startsWith("blob:")){const o=await zn(s),p=new File([o],a??n,{type:o.type});return await this.addCache(p,n),p}let u=Ft[c],m=!0;u?m=!1:(u=new Promise(o=>{this.enqueueRequest({description:"Download file",method:l.GET,url:s,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[n],blocks:[n]}).then(p=>{const A=new File([p],a??n,{type:p.type});o(A)})}),Ft[c]=u);let d;try{d=await u}catch(o){throw m&&o instanceof q&&delete Ft[c],o}if(m){const o=await _e(d);if(o!==n){const y=`The hash of the file returned from the server (${o}) does not match the
8
+ `)}catch(a){console.error("Failed to extract error message from response body",a)}}else typeof t.body=="string"&&(s=t.body);else t!=null&&t.text?s=t.text:e instanceof Error&&(s=e.message);return!s||s.length>uf?ke:s}class q extends Error{constructor(s){super(ke);f(this,"status");f(this,"response");f(this,"message");f(this,"options");const{response:n,innerError:a}=s;this.message=s.message??of(n,a)??ke,this.status=(n==null?void 0:n.status)??0,this.response=n,s.discard=s.discard??!1,this.options=s}}class lf extends Il{constructor(e){super(e)}}class P extends Il{constructor(s,n){super(s);f(this,"auth");this.auth=n}}class hf extends P{async startConversation(e,s){return this.enqueueRequest({description:"Start agent conversation",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:s},blockers:["prompt"],blocks:["prompt"]}).then(n=>(this.dispatch(Ln(n)),n))}async continueConversation(e,s,n){return this.enqueueRequest({description:"Prompt agent",method:l.POST,url:"/agents/prompt/",payload:{prompt:e,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:s}}).then(a=>{this.dispatch(Hn(a))})}async fetchDetails(e){return this.enqueueRequest({description:"Get agent conversation",method:l.GET,url:`/agents/conversations/${e}/`,blockers:["conversation"],blocks:["conversation"]}).then(s=>{this.dispatch(Nn(s))})}async rate(e,s){return this.enqueueRequest({description:"Rate agent response",method:l.PUT,url:`/agents/responses/${e}/rate/`,payload:{rating:s},blockers:["rate"],blocks:["rate"]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get agent conversation history",method:l.GET,url:`/projects/${e}/agent-conversations/`,blockers:["agent-conversations"],blocks:["agent-conversations"]});this.dispatch(Gn(s))}}class E extends P{getNumberOfAttachmentsWithSha1(e){const{issueAttachmentReducer:s,assetAttachmentReducer:n,assetTypeAttachmentReducer:a,documentAttachmentReducer:c,projectAttachmentReducer:r,formRevisionAttachmentReducer:u,formSubmissionAttachmentReducer:m,geoImageReducer:d,assetTypeFieldsAttachmentReducer:o,assetTypeFieldValuesAttachmentReducer:p,issueTypeFieldsAttachmentReducer:A,issueTypeFieldValuesAttachmentReducer:y}=this.client.store.getState();return[].concat(Object.values(s.instances),Object.values(n.instances),Object.values(a.instances),Object.values(c.instances),Object.values(r.instances),Object.values(u.instances),Object.values(m.instances),Object.values(d.instances),Object.values(o.instances),Object.values(p.instances),Object.values(A.instances),Object.values(y.instances)).filter(I=>I.file_sha1===e).length}processPresignedUrls(e){const s={};for(const[n,a]of Object.entries(e))s[n]=this.enqueueRequest({url:a.url,description:"Upload file to S3",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:n,blockers:[`s3-${a.fields.key}`],blocks:[n],s3url:a});return s}async getFilePayload(e){const s=await _e(e),n={sha1:s,file_type:e.type,extension:e.name.split(".").pop(),size:e.size};return await this.client.files.addCache(e,s),n}}class Re extends E{async _bulkAdd(e){var d;const{store:s}=this.client,n=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,a=new Date().toISOString(),c=[],r=[],u={};for(const o of e){const{modelUuid:p,file:A}=o,y=await this.getFilePayload(A);y.sha1 in u||(u[y.sha1]=y);const T=this.buildOfflineAttachment({file:A,file_sha1:y.sha1,submitted_at:a,created_by:n,description:"",modelUuid:p});c.push(T),r.push(this.buildAttachmentPayload({uuid:T.uuid,file_name:T.file_name,file_sha1:T.file_sha1,file_extension:y.extension,description:T.description,modelUuid:p}))}this.dispatch(this.addAttachments(c));const m=this.enqueueRequest({description:`Add ${this.name}`,method:l.POST,url:`${this.url}/bulk/`,payload:{submitted_at:a,attachments:r,files:Object.values(u)},blocks:c.map(o=>o.uuid),blockers:c.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(c.map(o=>o.uuid)))}),[c,m.then(({attachments:o})=>o)]}async _delete(e){const{store:s}=this.client,n=this.selectAttachment(e)(s.getState());if(!n)throw new Error(`Attempting to delete attachment with uuid ${e} that does not exist in the store`);this.dispatch(this.removeAttachment(n.uuid));const a=this.enqueueRequest({description:`Delete ${this.name}`,method:l.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]});return a.then(()=>{this.getNumberOfAttachmentsWithSha1(n.file_sha1)===0&&this.client.files.removeCache(n.file_sha1)}).catch(()=>{this.dispatch(this.setAttachment(n))}),a}}class mf extends Re{constructor(){super(...arguments);f(this,"name","Asset Attachment");f(this,"url","/asset-attachments");f(this,"initializeAttachments",Dt);f(this,"addAttachments",Vt);f(this,"updateAttachments",Jn);f(this,"removeAttachments",Ut);f(this,"removeAttachment",Xn);f(this,"setAttachment",Yn);f(this,"selectAttachment",xn)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.assetUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(Dt(n))}}class pf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(na(c));const u=this.enqueueRequest({description:"Add asset procedure fields attachments",method:l.POST,url:"/asset-procedure-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(aa(d.attachments))}).catch(()=>{this.dispatch(ca(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure fields attachments",method:l.GET,url:"/asset-procedure-fields-attachments/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(ia(s))}}class Af extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ha(c));const r=this.enqueueRequest({description:"Add Asset Procedure Fields",method:l.POST,url:"/asset-procedure-fields/",payload:c,blockers:[c.asset_procedure],blocks:[c.uuid]});return r.then(m=>{this.dispatch(ma(m))}).catch(m=>{throw this.dispatch(pa(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Procedure Fields",method:l.GET,url:"/asset-procedure-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(la(s))}}function Xe(t,e){const s=[];let n=0;const a=t.length;for(;n<a;)s.push(t.slice(n,n+=e));return s}class yf extends E{async bulkAdd(e,s){var d;const n=new Date().toISOString(),a=(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.id,c=Xe(e,s??e.length),r=[],u=[];for(const o of c){const p={},A=[];for(const y of o){const{fieldValuesUuid:T,fieldIdentifier:I,file:F}=y,O=await this.getFilePayload(F);O.sha1 in p||(p[O.sha1]=O);const M=R({file:URL.createObjectURL(F),file_type:F.type,file_name:F.name,file_sha1:O.sha1,created_by:a,field_values:T,submitted_at:n,field_identifier:I});r.push(M);const Pt={uuid:M.uuid,file_name:F.name,file_sha1:O.sha1,file_extension:O.extension,field_identifier:I,field_values:T};A.push(Pt)}u.push({submitted_at:n,attachments:A,files:Object.values(p)})}this.dispatch(Ze(r));const m=u.map(o=>this.enqueueRequest({description:"Add asset procedure field values attachments",method:l.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(ga(p))}).catch(o=>{throw this.dispatch(xe(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=ba(e)(n);this.dispatch(xe(e));try{await this.enqueueRequest({description:"Delete asset procedure field values attachments",method:l.DELETE,url:"/asset-procedure-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(Ze(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values attachments",method:l.GET,url:"/asset-procedure-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Sa(s))}}class ff extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset procedure field values",method:l.POST,url:"/asset-procedure-field-values/",payload:v(a),blockers:[e.asset,e.fields_revision,e.asset_procedure_instance],blocks:[a.uuid]});return this.dispatch(Wt(a)),c.then(u=>(this.dispatch(De(u)),u)).catch(()=>{this.dispatch(Kt(a.uuid))}),[a,c]}bulkAdd(e,s){var m;const n=new Date().toISOString(),a=[],c=Xe(e.payloads,s??e.payloads.length),r=[];for(const d of c){const o=[];for(const p of d){const A=R({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:n});a.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:n,values:e.values,field_values:o})}this.dispatch(Oa(a));const u=[];for(const d of r){const o=d.field_values.map(I=>I.asset),p=d.field_values.map(I=>I.fields_revision),A=d.field_values.map(I=>I.asset_procedure_instance),y=d.field_values.map(I=>I.uuid),T=this.enqueueRequest({description:"Bulk add asset procedure field values",method:l.POST,url:"/asset-procedure-field-values/bulk/",payload:d,blockers:[...o,...p,...A],blocks:y});u.push(T)}return Promise.all(u).then(d=>{this.dispatch(va(d.flat()))}).catch(()=>{this.dispatch(_a(a.map(d=>d.uuid)))}),[a,u]}update(e){const{store:s}=this.client,n=s.getState(),a=Jt(e.uuid)(n);if(!a)throw new Error(`Expected AssetProcedureFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(De(c));const r=this.enqueueRequest({description:"Update asset procedure field values",method:l.PATCH,url:`/asset-procedure-field-values/${e.uuid}/`,payload:e,blockers:[c.fields_revision,c.asset,c.asset_procedure_instance],blocks:[c.uuid]});return r.then(u=>{this.dispatch(De(u))}).catch(()=>{this.dispatch(De(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Jt(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Ia(e)(n);this.dispatch(Kt(e)),this.dispatch(xe(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset procedure field values",method:l.DELETE,url:`/asset-procedure-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Wt(a)),this.dispatch(Ze(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure field values",method:l.GET,url:"/asset-procedure-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Pa(s))}}class Sf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Qt(c));const r=this.enqueueRequest({description:"Create asset procedure instance",method:l.POST,url:"/asset-procedure-instances/",payload:v(c),blockers:[e.asset_procedure,e.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Ve(m))}).catch(()=>{this.dispatch(Zt(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=ts(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset procedure instance with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(Ve(a));const c=this.enqueueRequest({description:"Update asset procedure instance",method:l.PATCH,url:`/asset-procedure-instances/${e.uuid}/`,payload:e,blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Ve(r))}).catch(()=>{this.dispatch(Ve(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=ts(e)(n);if(!a)throw new Error(`Expected asset procedure instance with uuid ${e} to exist`);return this.dispatch(Zt(e)),this.enqueueRequest({description:"Delete asset procedure instance",method:l.DELETE,url:`/asset-procedure-instances/${e}/`,blockers:[e],blocks:[]}).catch(c=>{throw this.dispatch(Qt(a)),c})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedure instances",method:l.GET,url:"/asset-procedure-instances/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(qa(s))}}class gf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(is(c));const r=this.enqueueRequest({description:"Create asset procedure",method:l.POST,url:"/asset-procedures/",payload:v(c),blockers:[],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Ue(m))}).catch(()=>{this.dispatch(ns(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=cs(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset procedure with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(Ue(a));const c=this.enqueueRequest({description:"Update asset procedure",method:l.PATCH,url:`/asset-procedures/${e.uuid}/`,payload:e,blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Ue(r))}).catch(()=>{this.dispatch(Ue(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=cs(e)(n);if(!a)throw new Error(`Expected asset procedure with uuid ${e} to exist`);const c=Ca(e)(n);return this.dispatch(ns(e)),this.dispatch(ka(c.map(r=>r.uuid))),this.enqueueRequest({description:"Delete asset procedure",method:l.DELETE,url:`/asset-procedures/${e}/`,blockers:[e],blocks:[]}).catch(r=>{throw this.dispatch(is(a)),this.dispatch(Ma(c)),r})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset procedures",method:l.GET,url:"/asset-procedures/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Va(s))}}class Tf extends P{add(e){var u;const{store:s}=this.client;if(!e.canvas_marker&&!e.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");const n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(ds(c));const r=this.enqueueRequest({description:"Create asset",method:l.POST,url:"/assets/",payload:v(c),blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch($e(m))}).catch(()=>{this.dispatch(os(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=ms(e.uuid)(s.getState());if(!n)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const a={...n,...e};if(!a.canvas_marker&&!a.geo_marker)throw new Error("Asset must have either a canvas_marker or geo_marker");this.dispatch($e(a));const c=this.enqueueRequest({description:"Edit asset",method:l.PATCH,url:`/assets/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch($e(r))}).catch(()=>{this.dispatch($e(n))}),[a,c]}async remove(e){const{store:s}=this.client,n=s.getState(),a=ms(e)(n);if(!a)throw new Error(`No asset with uuid ${e} found in the store`);const c=ea(e)(n),r=rd(e)(n),u=Pd(e)(n);if(this.dispatch(os(e)),c.length>0){const m=c.map(({uuid:d})=>d);this.dispatch(Ut(m))}if(r.length>0){const m=r.map(({uuid:d})=>d);this.dispatch(ht(m))}if(u.length>0){const m=u.map(({uuid:d})=>d);this.dispatch(gi(m))}return this.enqueueRequest({description:"Delete asset",method:l.DELETE,url:`/assets/${e}/`,blockers:[e],blocks:[]}).catch(m=>{throw this.dispatch(ds(a)),this.dispatch(Vt(c)),this.dispatch(lt(r)),this.dispatch(fi(u)),m})}bulkAdd(e,s,n,a){const c=new Date().toISOString(),r=fe.v4(),u=Xe(e,a).map(o=>{const p=o.map(A=>R(A));return{batchId:fe.v4(),payload:{transaction_id:r,submitted_at:c,asset_type:s,project:n,assets:p}}}),m=[];let d=null;for(const o of u){const{batchId:p,payload:A}=o,y=A.assets.map(O=>O.uuid),T=[s];d&&T.push(d);const I=y;I.push(p);const F=this.enqueueRequest({description:"Batch create assets",method:l.POST,url:"/assets/bulk/",payload:A,blockers:T,blocks:I});d=o.batchId,m.push(F)}return Promise.all(m).then(o=>{const p=o.flat();this.dispatch(us(p))}),m}async refreshStore(e){const s=await this.enqueueRequest({description:"Get assets",method:l.GET,url:"/assets/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Ga(s))}}class bf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(As(c));const r=this.enqueueRequest({description:"Add asset stage completion",method:l.POST,url:"/asset-stage-completions/",payload:v(c),blockers:[e.asset,e.stage],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Ya(m))}).catch(()=>{this.dispatch(fs(c.uuid))}),[c,r]}delete(e){const{store:s}=this.client,n=Qa(e)(s.getState());if(!n)throw new Error(`Expected asset stage completion with uuid ${e} to exist`);this.dispatch(fs(e));const a=this.enqueueRequest({description:"Delete asset stage completion",method:l.DELETE,url:`/asset-stage-completions/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(As(n))}),a}bulkAdd(e){var d;const{store:s}=this.client,n=new Date().toISOString(),a=(d=s.getState().userReducer.currentUser)==null?void 0:d.id,c=e.map(o=>R(o)),r=c.map(o=>({...o,created_by:a,submitted_at:n})),u=r.map(({uuid:o})=>o);this.dispatch(ys(r));const m=this.enqueueRequest({description:"Bulk create asset stage completions",method:l.POST,url:"/asset-stage-completions/bulk/",payload:{submitted_at:n,completions:c},blockers:[...e.map(o=>o.asset_procedure_instance),...e.map(o=>o.stage),...e.map(o=>o.asset)],blocks:u});return m.then(o=>{this.dispatch(Ja(o))}).catch(()=>{this.dispatch(Ss(u))}),[r,m]}bulkDelete(e){const{store:s}=this.client,n=Za(e)(s.getState());this.dispatch(Ss(e));const a=this.enqueueRequest({description:"Deleting asset stage completions",method:l.DELETE,url:"/asset-stage-completions/bulk/",payload:{completion_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(ys(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stage completions",method:l.GET,url:"/asset-stage-completions/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Ka(s))}}class If extends P{bulkAdd(e,s){var m;const n=new Date().toISOString(),a=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,c=e.map(d=>R(d)),r=c.map(d=>({...d,asset_procedure:s,created_by:a,submitted_at:n}));this.dispatch(bs(r));const u=this.enqueueRequest({description:"Add asset stages",method:l.POST,url:"/asset-stages/bulk/",payload:{submitted_at:n,asset_procedure:s,stages:c},blockers:[s],blocks:c.map(({uuid:d})=>d)});return u.then(d=>{this.dispatch(et(d))}).catch(()=>{this.dispatch(Fs(r.map(({uuid:d})=>d)))}),[r,u]}async bulkUpdate(e,s){const a=this.client.store.getState(),c=Rs(e.map(({uuid:r})=>r))(a);return this.dispatch(et(e)),this.enqueueRequest({description:"Edit asset stages",method:l.PATCH,url:`/asset-procedures/${s}/bulk-update-stages/`,payload:{stages:e},blockers:[s],blocks:e.map(({uuid:r})=>r)}).catch(r=>{throw this.dispatch(et(c)),r})}async bulkDelete(e){const{store:s}=this.client,n=Rs(e)(s.getState());this.dispatch(Fs(e));const a=this.enqueueRequest({description:"Delete asset stages",method:l.DELETE,url:"/asset-stages/bulk/",payload:{stage_ids:e},blockers:e,blocks:[]});return a.catch(()=>{this.dispatch(bs(n))}),a}update(e){const{store:s}=this.client,n=ic(e.uuid)(s.getState());if(!n)throw new Error(`No asset stage with uuid ${e.uuid} found in the store`);const a={...n,...e};this.dispatch(Is(a));const c=this.enqueueRequest({description:"Update asset stage",method:l.PATCH,url:`/asset-stages/${n.uuid}/`,payload:{name:e.name,description:e.description,priority:e.priority,color:e.color},blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Is(r))}).catch(()=>{this.dispatch(tc(n))}),[a,c]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset stages",method:l.GET,url:"/asset-stages/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(ec(s))}}class Ff extends Re{constructor(){super(...arguments);f(this,"name","Asset Type Attachment");f(this,"url","/asset-type-attachments");f(this,"addAttachments",Os);f(this,"updateAttachments",dc);f(this,"removeAttachments",vs);f(this,"removeAttachment",uc);f(this,"setAttachment",rc);f(this,"selectAttachment",hc)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,asset_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,asset_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.assetTypeUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get asset type attachments",method:l.GET,url:`${this.url}/`,queryParams:{organization:s},blocks:[],blockers:[]});this.dispatch(cc(n))}}class Rf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(fc(c));const u=this.enqueueRequest({description:"Add asset type fields attachments",method:l.POST,url:"/asset-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Sc(d.attachments))}).catch(()=>{this.dispatch(gc(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type fields attachments",method:l.GET,url:"/asset-type-fields-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(yc(s))}}class Pf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Pc(c));const r=this.enqueueRequest({description:"Add Asset Type Fields",method:l.POST,url:"/asset-type-fields/",payload:c,blockers:[c.asset_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Oc(m))}).catch(m=>{throw this.dispatch(vc(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Asset Type Fields",method:l.GET,url:"/asset-type-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Rc(s))}}class Of extends E{async bulkAdd(e,s){var d;const n=new Date().toISOString(),a=(d=this.client.store.getState().userReducer.currentUser)==null?void 0:d.id,c=Xe(e,s??e.length),r=[],u=[];for(const o of c){const p={},A=[];for(const y of o){const{fieldValuesUuid:T,fieldIdentifier:I,file:F}=y,O=await this.getFilePayload(F);O.sha1 in p||(p[O.sha1]=O);const M=R({file:URL.createObjectURL(F),file_type:F.type,file_name:F.name,file_sha1:O.sha1,created_by:a,field_values:T,submitted_at:n,field_identifier:I});r.push(M);const Pt={uuid:M.uuid,file_name:F.name,file_sha1:O.sha1,file_extension:O.extension,field_identifier:I,field_values:T};A.push(Pt)}u.push({submitted_at:n,attachments:A,files:Object.values(p)})}this.dispatch(it(r));const m=u.map(o=>this.enqueueRequest({description:"Add asset type field values attachments",method:l.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(qc(p))}).catch(o=>{throw this.dispatch(nt(r.map(p=>p.uuid))),o}),[r,m.map(o=>o.then(({attachments:p})=>p))]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=kc(e)(n);this.dispatch(nt(e));try{await this.enqueueRequest({description:"Delete asset type field values attachments",method:l.DELETE,url:"/asset-type-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(it(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values attachments",method:l.GET,url:"/asset-type-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(jc(s))}}class vf extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add asset type field values",method:l.POST,url:"/asset-type-field-values/",payload:v(a),blockers:[e.asset,e.fields_revision],blocks:[a.uuid]});return this.dispatch(Ms(a)),c.then(u=>(this.dispatch(Be(u)),u)).catch(()=>{this.dispatch(ks(a.uuid))}),[a,c]}bulkAdd(e,s){var m;const n=new Date().toISOString(),a=[],c=Xe(e.payloads,s??e.payloads.length),r=[];for(const d of c){const o=[];for(const p of d){const A=R({...p,values:p.values,created_by:(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,submitted_at:n});a.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:n,values:e.values,field_values:o})}this.dispatch(Uc(a));const u=[];for(const d of r){const o=d.field_values.map(T=>T.asset),p=d.field_values.map(T=>T.fields_revision),A=d.field_values.map(T=>T.uuid),y=this.enqueueRequest({description:"Bulk add asset type field values",method:l.POST,url:"/asset-type-field-values/bulk/",payload:d,blockers:[...o,...p],blocks:A});u.push(y)}return Promise.all(u).then(d=>{this.dispatch($c(d.flat()))}).catch(()=>{this.dispatch(Bc(a.map(d=>d.uuid)))}),[a,u]}update(e){const{store:s}=this.client,n=s.getState(),a=zs(e.uuid)(n);if(!a)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(Be(c));const r=this.enqueueRequest({description:"Delete asset type field values",method:l.PATCH,url:`/asset-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.asset],blocks:[c.uuid]});return r.then(u=>{this.dispatch(Be(u))}).catch(()=>{this.dispatch(Be(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=zs(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=Cc(e)(n);this.dispatch(ks(e)),this.dispatch(nt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete asset type field values",method:l.DELETE,url:`/asset-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Ms(a)),this.dispatch(it(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset type field values",method:l.GET,url:"/asset-type-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Vc(s))}}class _f extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Vs(c));const r=this.enqueueRequest({description:"Create asset type",method:l.POST,url:"/asset-types/",payload:v(c),blockers:[],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Ge(m))}).catch(()=>{this.dispatch(Us(c.uuid))}),[c,r]}update(e){const{store:s}=this.client,n=Bs(e.uuid)(s.getState());if(!n)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(Ge(a));const c=this.enqueueRequest({description:"Update asset type",method:l.PATCH,url:`/asset-types/${e.uuid}/`,payload:{icon:e.icon,color:e.color,name:e.name,description:e.description},blockers:[n.uuid],blocks:[n.uuid]});return c.then(r=>{this.dispatch(Ge(r))}).catch(()=>{this.dispatch(Ge(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Bs(e)(n);if(!a)throw new Error(`Expected asset type with uuid ${e} to exist`);const c=hs(e)(n),r=mc(e)(n);return this.dispatch(Us(e)),this.dispatch(La(c.map(u=>u.uuid))),this.dispatch(vs(r.map(({uuid:u})=>u))),this.enqueueRequest({description:"Delete asset type",method:l.DELETE,url:`/asset-types/${e}/`,blockers:[e],blocks:[]}).catch(u=>{throw this.dispatch(Vs(a)),this.dispatch(us(c)),this.dispatch(Os(r)),u})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get asset types",method:l.GET,url:"/asset-types/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Hc(s))}}class wf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Ls(c));const r=this.enqueueRequest({description:"Create Category",method:l.POST,url:"/categories/",payload:v(c),blockers:[e.project],blocks:[c.uuid]});return[c,r]}update(e){const s=this.client.store.getState(),n=Hs(e.uuid)(s);if(!n)throw new Error(`Expected an existing category with uuid ${e.uuid}`);const a={...n,...e};this.dispatch(Zc(a));const c=this.enqueueRequest({description:"Edit Category",method:l.PATCH,url:`/categories/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return[a,c]}remove(e){const{store:s}=this.client,n=Hs(e)(s.getState());if(!n)throw new Error(`No category with uuid ${e} found in the store`);this.dispatch(xc(e));const a=this.enqueueRequest({description:"Delete Category",method:l.DELETE,url:`/categories/${n.uuid}/`,blockers:[n.uuid],blocks:[]});return a.catch(()=>{this.dispatch(Ls(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get categories",method:l.GET,url:"/categories/",queryParams:{project:e},blocks:[],blockers:[]});this.dispatch(Qc(s))}}class Ef extends Re{constructor(){super(...arguments);f(this,"name","Document Attachment");f(this,"url","/document-attachments");f(this,"addAttachments",ir);f(this,"updateAttachments",ar);f(this,"removeAttachments",rr);f(this,"removeAttachment",cr);f(this,"setAttachment",nr);f(this,"selectAttachment",or)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,document:s.modelUuid})}buildAttachmentPayload(s){return{...s,document:s.modelUuid}}async bulkAdd(s){var p;const{store:n}=this.client,a=(p=n.getState().userReducer.currentUser)==null?void 0:p.id,c=new Date().toISOString(),r=[],u=[],m={},d={};for(const A of s){const{documentUuid:y,file:T}=A,I=await this.getFilePayload(T);I.sha1 in m||(m[I.sha1]=I,d[I.sha1]=[]);const F=this.buildOfflineAttachment({file:T,file_sha1:I.sha1,submitted_at:c,created_by:a,description:"",modelUuid:y});r.push(F),u.push({uuid:F.uuid,file_name:F.file_name,file_sha1:F.file_sha1,file_extension:I.extension,description:F.description,document:y}),d[I.sha1].push(F.uuid)}this.dispatch(this.addAttachments(r));const o=this.enqueueRequest({description:"Attach files to document",method:l.POST,url:"/document-attachments/bulk/",payload:{submitted_at:c,attachments:u,files:Object.values(m)},blocks:r.map(A=>A.uuid),blockers:r.map(A=>A.file_sha1)});return o.then(({attachments:A,presigned_urls:y})=>{this.dispatch(this.updateAttachments(A));const T=this.processPresignedUrls(y);for(const[I,F]of Object.entries(T))F.then(()=>{const O=d[I];for(const M of O)this.makeReadable(M)})}).catch(()=>{this.dispatch(this.removeAttachments(r.map(A=>A.uuid)))}),[r,o.then(({attachments:A})=>A)]}async delete(s){return this._delete(s)}makeReadable(s){this.enqueueRequest({description:"Add attachment to AI assistant",method:l.PATCH,url:`/document-attachments/${s}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",s],blocks:["index-document-attachment"]})}async refreshStore(s,n){const a=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/projects/${s}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(sr(a));const c=await this.enqueueRequest({description:"Get document attachments",method:l.GET,url:`/organizations/${n}/document-attachments/`,blocks:[],blockers:[]});this.dispatch(this.addAttachments(c))}}class jf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(pr([c]));const r=this.enqueueRequest({description:"Create Document",method:l.POST,url:"/documents/",payload:v(c),queryParams:{parent_document:c.parent_document??void 0},blockers:c.parent_document?[c.parent_document]:[],blocks:[c.uuid]});return r.catch(()=>{this.dispatch(Ys([c.uuid]))}),[c,r]}update(e){const{store:s}=this.client,n=s.getState().documentsReducer.documents[e.uuid];if(!n)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const a={...n,...e};this.dispatch(ye([a]));const c=this.enqueueRequest({description:"Update Document",method:l.PATCH,url:`/documents/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{ye([n])}),[a,c]}move(e,s,n){const{store:a}=this.client,c=we(a.getState()),r=[],u=c[e];if(!u)throw new Error(`attempting to move a document with uuid ${e} that does not exist in store.documents`);if(r.push(u),u.parent_document&&r.push(c[u.parent_document]),s){const d=c[s];if(!d)throw new Error(`attempting to move a document to target with uuid ${s} that does not exist in store.documents`);r.push(d),d.parent_document&&r.push(c[d.parent_document])}this.dispatch(Ar({documentId:e,targetDocumentId:s,position:n}));const m=this.enqueueRequest({description:"Move Document",method:l.PATCH,url:`/documents/${e}/move/`,queryParams:{target:s??void 0,position:n},blockers:[e],blocks:[]});return m.then(d=>{this.dispatch(ye(d))}).catch(()=>{this.dispatch(ye(r))}),m}delete(e){const{store:s}=this.client,n=we(s.getState()),a=fr(e)(s.getState());if(!a)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const c=a.parent_document?n[a.parent_document]:void 0;this.dispatch(Ys([e]));const r=this.enqueueRequest({description:"Delete Document",method:l.DELETE,url:`/documents/${e}/`,blockers:[e],blocks:[]});return r.then(u=>{this.dispatch(ye(u))}).catch(()=>{this.dispatch(ye([a])),c&&this.dispatch(ye([c]))}),r}async refreshStore(e,s){const n=this.enqueueRequest({description:"Get project documents",method:l.GET,url:`/projects/${e}/documents/`,blockers:[],blocks:[]}),a=this.enqueueRequest({description:"Get organization documents",method:l.GET,url:`/organizations/${s}/documents/`,blockers:[],blocks:[]});this.dispatch(mr([...await n,...await a]))}}class qf extends P{async add(e,s){return this.enqueueRequest({description:"Add email domain to organization",method:l.POST,url:"/organization-email-domains/",payload:{email:s,organization:e},blockers:[e,"create-org"],blocks:[]})}async remove(e){return this.dispatch(br(e.uuid)),this.enqueueRequest({description:"Remove email domain from organization",method:l.DELETE,url:`/organization-email-domains/${e.uuid}/`,blockers:[e.domain],blocks:[]}).catch(s=>{throw this.dispatch(Tr(e)),s})}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch email domains for organization",method:l.GET,url:"/organization-email-domains/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(gr(s))}}class Mf extends P{async getVerificationCode(e){return this.enqueueRequest({description:"Get verification code",method:l.GET,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(e,s=void 0){return this.enqueueRequest({description:"Validate verification code",method:l.POST,url:`/verification/email-verification/${e}/`,isAuthNeeded:!1,payload:s,blockers:[],blocks:[]})}}const Ft={},In=new Set;let Rt=0,Fn=0,Rn=0;const kf=20;class Cf extends P{constructor(){super(...arguments);f(this,"host");f(this,"_dbPromise",Gl.openDB("fileCache",1,{upgrade(s){s.createObjectStore("files")}}))}async renewUploadUrl(s){const n=await this.fetchCache(s);if(!n)throw new Error(`File with sha1 ${s} not found in cache`);const a=await Mt(n,s),c=await this.enqueueRequest({description:"Get S3 URL",method:l.GET,url:"/authentication/files/presigned-upload-url/",queryParams:{sha1:await _e(n),file_type:n.type,extension:n.name.split(".").pop(),size:n.size.toString()},blockers:[],blocks:[`s3-${a}`]});return"url"in c&&this.dispatch(vr({sha1:s,...c})),c}async addCache(s,n){if(In.has(n))return;if(!s.type){const r=s.name.split("."),u=r[r.length-1];s=new File([s],s.name,{type:u})}if(!s.name||!s.size||!s.type)throw new Error("Cannot add files to cache that do not have a name, size and type.");const a=await this._dbPromise;!!await a.get("files",n)?(console.error("File already cached (this is unexpected at this point):",s.name,n),Rt++):(await a.put("files",s,n),Fn++),In.add(n),Rn++,Rn%kf===0&&console.debug(`File cache summary: ${Rt} hits and ${Fn} misses, ${Rt/(Rt+Fn)*100}% hit rate over ${Rn} calls to addCache.`)}async removeCache(s){await(await this._dbPromise).delete("files",s),In.delete(s)}async fetchCache(s){return(await this._dbPromise).get("files",s)}async getOrRenewUploadUrl(s){const n=this.client.store.getState();return _r(s)(n)??await this.renewUploadUrl(s)}async uploadFileToS3(s){const n=await this.fetchCache(s);if(!n)throw new Error(`File with sha1 ${s} not found in cache`);const a=await Mt(n,s),c={file_name:n.name,file_sha1:s,file:a},r=await this.getOrRenewUploadUrl(s);if("warning"in r){if(r.warning==="already_uploaded")return[c,Promise.resolve(void 0).then()];throw new Error(r.warning)}const u=r.url,m=this.enqueueRequest({url:u,description:"Upload file",method:l.POST,isExternalUrl:!0,isAuthNeeded:!1,attachmentHash:s,blockers:[`s3-${a}`],blocks:[s],s3url:r});return[c,m]}async fetchFileFromUrl(s,n,a){const c=s.split("?")[0]??s,r=await this.fetchCache(n);if(r){if(!r.name)throw new Error("Cached file unexpectedly has no name.");return r}if(s.startsWith("blob:")){const o=await zn(s),p=new File([o],a??n,{type:o.type});return await this.addCache(p,n),p}let u=Ft[c],m=!0;u?m=!1:(u=new Promise(o=>{this.enqueueRequest({description:"Download file",method:l.GET,url:s,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1,blockers:[n],blocks:[n]}).then(p=>{const A=new File([p],a??n,{type:p.type});o(A)})}),Ft[c]=u);let d;try{d=await u}catch(o){throw m&&o instanceof q&&delete Ft[c],o}if(m){const o=await _e(d);if(o!==n){const y=`The hash of the file returned from the server (${o}) does not match the
9
9
  expected hash (${n}). 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
12
12
  (with an uuid attached) being returned. Alternatively, you may be running with
13
13
  import.meta.env.PROD, which will result in some file requests being treated as
14
- external URLs and therefore not prepended with VITE_API_URL.`;throw new Error(y)}const p=d.type.split("/")[1];if(!p)throw new Error("File has no extension");const A=a??o+"."+p;if(d=Cn(d,A),!d.name)throw new Error("Failed to set file's name");await this.addCache(d,o),Ft[c]=new Promise(y=>{y(d)})}return d}}class zf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{revisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,form_revision:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,form_revision:o};r.push(I)}this.dispatch(qr(c));const u=this.enqueueRequest({description:"Attach files to form revision",method:l.POST,url:"/form-revision-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.form_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Mr(d.attachments))}).catch(()=>{this.dispatch(kr(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization form revision attachments",method:l.GET,url:"/form-revision-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(jr(s))}}class Df extends E{add(e){var u;const{store:s}=this.client,a=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,c=R({...e,created_by:a,submitted_at:new Date().toISOString()});this.dispatch(xs(c));const r=this.enqueueRequest({description:"Create form revision",method:l.POST,url:"/form-revisions/",payload:v(c),blockers:[e.form],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Vr(m))}).catch(()=>{this.dispatch(ei(c.uuid))}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization form revisions",method:l.GET,url:"/form-revisions/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(Ur(s))}}class Vf extends E{add(e,s){var d;const{store:n}=this.client,a=new Date().toISOString(),c=(d=n.getState().userReducer.currentUser)==null?void 0:d.id,r=R({...e,submitted_at:a,created_by:c}),u=R({...s,form:r.uuid,submitted_at:a,created_by:c});this.dispatch(si(r)),this.dispatch(xs(u));const m=this.enqueueRequest({description:"Create form",method:l.POST,url:"/forms/",payload:{...v(r),initial_revision:{uuid:u.uuid,submitted_at:u.submitted_at,title:u.title,description:u.description,fields:u.fields}},blockers:[],blocks:[r.uuid,u.uuid]});return m.catch(o=>{throw this.dispatch(ii(r.uuid)),this.dispatch(ei(u.uuid)),o}),[r,u,m]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Jr(e)(n);if(!a)throw new Error("Expected form to exist");const c=ad(e)(n);c.length>0&&this.dispatch(ht(c.map(({uuid:u})=>u)));const r=Lr(e)(n);r.length>0&&this.dispatch(Br(r.map(({uuid:u})=>u))),this.dispatch(ii(e));try{return await this.enqueueRequest({description:"Delete form",method:l.DELETE,url:`/forms/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(si(a)),r.length>0&&this.dispatch($r(r)),c.length>0&&this.dispatch(lt(c)),u}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization forms",method:l.GET,url:"/forms/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(Wr(s))}}class Uf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{submissionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,form_submission:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:p,form_submission:o};r.push(I)}this.dispatch(dt(c));const u=this.enqueueRequest({description:"Attach files to form submission",method:l.POST,url:"/form-submission-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.form_submission),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Zr(d.attachments))}).catch(d=>{throw this.dispatch(ut(c.map(o=>o.uuid))),d}),[c,u.then(({attachments:d})=>d)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=xr(e)(n);this.dispatch(ut(e));try{await this.enqueueRequest({description:"Delete form submission attachments",method:l.DELETE,url:"/form-submission-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(dt(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get form submission attachments",method:l.GET,url:"/form-submission-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Qr(s))}}class $f extends E{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add form submission",method:l.POST,url:"/form-submissions/",payload:v(a),blockers:["add-form-entry",e.form_revision,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[a.uuid]});return this.dispatch(ri(a)),c.then(u=>(this.dispatch(ot(u)),u)).catch(()=>{this.dispatch(di(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=li(e.uuid)(n);if(!a)throw new Error(`Expected submission with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(nd(c));const r=this.enqueueRequest({description:"Delete user form submissions",method:l.PATCH,url:`/form-submissions/${c.uuid}/`,payload:e,blockers:[c.uuid],blocks:[c.uuid]});return r.then(u=>{this.dispatch(ot(u))}).catch(()=>{this.dispatch(ot(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=li(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=ed(e)(n);this.dispatch(di(e)),this.dispatch(ut(c.map(r=>r.uuid)));try{return await this.enqueueRequest({description:"Delete user form submissions",method:l.DELETE,url:`/form-submissions/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ri(a)),this.dispatch(dt(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch form submissions",method:l.GET,url:"/form-submissions/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(id(s))}}class Bf extends E{async add(e){var p;const{store:s}=this.client,{file:n,...a}=e,c=new Date().toISOString(),r=(p=s.getState().userReducer.currentUser)==null?void 0:p.id,u=a.project,m=await this.getFilePayload(n),d=R({...a,file_name:n.name,file_sha1:m.sha1,file:URL.createObjectURL(n),submitted_at:c,created_by:r});this.dispatch(hd(d));const o=this.enqueueRequest({description:"Add geo image",method:l.POST,url:"/geo-images/",payload:{uuid:d.uuid,submitted_at:c,title:d.title,description:d.description,geo_marker:d.geo_marker,canvas_marker:d.canvas_marker,sha1:d.file_sha1,project:d.project,file_name:d.file_name,direction:d.direction,original_date:d.original_date,file:m},blocks:[u],blockers:[u]});return o.then(A=>{this.processPresignedUrls(A.presigned_urls),this.dispatch(Ne(A.geo_image))}).catch(()=>{this.dispatch(mi(d.uuid))}),[d,o.then(A=>A.geo_image)]}async bulkAdd(e,s){var p;const{store:n}=this.client,a=new Date().toISOString(),c=(p=n.getState().userReducer.currentUser)==null?void 0:p.id,r=[],u=[],m=[],d={};for(const A of e){const{file:y,...T}=A,I=await this.getFilePayload(y);I.sha1 in d||(d[I.sha1]=I);const F=R({...T,file_name:y.name,file_sha1:I.sha1,file:URL.createObjectURL(y),submitted_at:a,created_by:c,project:s});r.push(F),u.push(F.uuid),m.push({uuid:F.uuid,sha1:F.file_sha1,file_name:F.file_name,title:F.title,description:F.description,geo_marker:F.geo_marker,canvas_marker:F.canvas_marker,direction:F.direction,original_date:F.original_date})}this.dispatch(md(r));const o=this.enqueueRequest({description:"Bulk add geo images",method:l.POST,url:"/geo-images/bulk/",payload:{submitted_at:a,project:s,geo_images:m,files:Object.values(d)},blocks:[s],blockers:u});return o.then(A=>{this.processPresignedUrls(A.presigned_urls),this.dispatch(ld(A.geo_images))}).catch(()=>{this.dispatch(Ad(u))}),[r,o.then(A=>A.geo_images)]}update(e){const{store:s}=this.client,n=s.getState(),a=pi(e.uuid)(n);if(!a)throw new Error(`Map image with uuid ${e.uuid} does not exist in the store`);const c={...a,...e};this.dispatch(pd(c));const r=this.enqueueRequest({description:"Update geo image",method:l.PATCH,url:`/geo-images/${e.uuid}/`,payload:e,blocks:[e.uuid],blockers:[e.uuid]});return r.then(u=>{this.dispatch(Ne(u))}).catch(()=>{this.dispatch(Ne(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=pi(e)(n);if(!a)throw new Error(`Map image with uuid ${e} does not exist in the store`);this.dispatch(mi(e));const c=this.enqueueRequest({description:"Delete geo image",method:l.DELETE,url:`/geo-images/${e}/`,blocks:[e],blockers:[e]});return c.catch(()=>{this.dispatch(Ne(a))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get geo images",method:l.GET,url:`/projects/${e}/geo-images/`,blocks:[e],blockers:[]});this.dispatch(od(s))}}class Gf extends P{add(e){var u;const{store:s}=this.client,n=new Date().toISOString(),a=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,c=R({...e,submitted_at:n,created_by:a});this.dispatch(yi(c));const r=this.enqueueRequest({description:"Add issue association",method:l.POST,url:"/issue-associations/",payload:v(c),blockers:[e.associated_issue,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[c.uuid]});return r.then(m=>{this.dispatch(bd(m))}).catch(()=>{this.dispatch(Si(c.uuid))}),[c,r]}async delete(e){const{store:s}=this.client,n=Id(e)(s.getState());if(!n)throw new Error(`Issue association with uuid ${e} not found in store.`);this.dispatch(Si(e));const a=this.enqueueRequest({description:"Delete issue association",method:l.DELETE,url:`/issue-associations/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(yi(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch issue associations",method:l.GET,url:"/issue-associations/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Td(s))}}class Lf extends Re{constructor(){super(...arguments);f(this,"name","Issue Attachment");f(this,"url","/issue-attachments");f(this,"initializeAttachments",bi);f(this,"addAttachments",Ii);f(this,"updateAttachments",wd);f(this,"removeAttachments",Fi);f(this,"removeAttachment",Ed);f(this,"setAttachment",_d);f(this,"selectAttachment",kd)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(bi(n))}}class Nf extends Re{constructor(){super(...arguments);f(this,"name","Issue Comment Attachment");f(this,"url","/issue-comment-attachments");f(this,"initializeAttachments",Pi);f(this,"addAttachments",Dd);f(this,"updateAttachments",Ud);f(this,"removeAttachments",Bd);f(this,"removeAttachment",$d);f(this,"setAttachment",Vd);f(this,"selectAttachment",Nd)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue_comment:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue_comment:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueCommentUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue comment attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(Pi(n))}}class Hf extends P{add(e){var c;const{store:s}=this.client,n=R({...e,author:(c=s.getState().userReducer.currentUser)==null?void 0:c.id,submitted_at:new Date().toISOString()});this.dispatch(_i(n));const a=this.enqueueRequest({description:"Add issue comment",method:l.POST,url:"/issue-comments/",payload:v(n),blockers:[e.issue],blocks:[n.uuid]});return a.catch(()=>{this.dispatch(wi(n.uuid))}),[n,a]}update(e){const{store:s}=this.client,n=Ei(e.uuid)(s.getState());if(!n)throw new Error(`Comment with uuid ${e.uuid} not found in store`);const a={...n,...e};this.dispatch(vi(a));const c=this.enqueueRequest({description:"Edit issue comment",method:l.PATCH,url:`/issue-comments/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{this.dispatch(vi(n))}),[a,c]}remove(e){const{store:s}=this.client,n=Ei(e)(s.getState());if(!n)throw new Error(`Comment with uuid ${e} not found in store`);this.dispatch(wi(e));const a=this.enqueueRequest({description:"Delete comment",method:l.DELETE,url:`/issue-comments/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(_i(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get comments",method:l.GET,url:"/issue-comments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Kd(s))}}class Wf extends P{add(e){var m;const{store:s}=this.client,n=s.getState(),a=new Date().toISOString(),c=(m=n.userReducer.currentUser)==null?void 0:m.id,r=R({...e,submitted_at:a,created_by:c});this.dispatch(qi(r));const u=this.enqueueRequest({description:"Create issue",method:l.POST,url:"/issues/",payload:v(r),blockers:["add-issue",r.project,r.issue_type,...r.category?[r.category]:[]],blocks:[r.uuid]});return u.then(d=>{this.dispatch(mt(d))}).catch(d=>{throw this.dispatch(Mi(r.uuid)),d}),[r,u]}update(e){var m;const s=this.client.store.getState(),n=ki(e.uuid)(s);if(!n)throw new Error(`Attempting to update an issue with uuid ${e.uuid} that doesn't exist in the store`);const a={...n,...e};this.dispatch(mt(a));const c={};for(const d of[_.TITLE,_.DESCRIPTION,_.STATUS,_.CATEGORY,_.PRIORITY,_.ASSIGNED_TO,_.DUE_DATE])if(d in e&&e[d]!==n[d])switch(d){case _.PRIORITY:case _.STATUS:{const o=e[d];c[d]=o!==void 0?Number(o):null;break}case _.DUE_DATE:case _.DESCRIPTION:case _.TITLE:c[d]=e[d]??null;break;case _.CATEGORY:{let o=null;const p=e[d];if(p&&(o=s.categoryReducer.instances[p]??null,!o))throw new Error(`Trying to update issue category to ${p} which does not exist in store`);c[d]=o?{name:o.name,color:o.color,uuid:o.uuid}:null;break}case _.ASSIGNED_TO:{let o=null;const p=e[d];if(p&&(o=s.userReducer.instances[p]??null,!o))throw new Error(`Trying to update issue assigned_to to ${p} which does not exist in store`);c[d]=o?{full_name:o.username,id:o.id}:null;break}}const r=R({created_by:(m=s.userReducer.currentUser)==null?void 0:m.id,submitted_at:new Date().toISOString(),issue:n.uuid,changes:c});this.dispatch(Ku(r));const u=this.enqueueRequest({description:"Edit issue",method:l.PATCH,url:`/issues/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.catch(()=>{this.dispatch(mt(n)),this.dispatch(Ju(r.uuid))}),[a,u]}async remove(e){const{store:s}=this.client,n=s.getState(),a=ki(e)(n);if(!a)throw new Error(`No issue with uuid ${e} found in the store`);const c=Md(e)(n),r=Zu(e)(n),u=cd(e)(n),m={};for(const o of Fd(e)(n))m[o.uuid]=o;for(const o of Rd(e)(n))m[o.uuid]=o;const d=Object.values(m);this.dispatch(Mi(e)),c.length>0&&this.dispatch(Fi(c.map(({uuid:o})=>o))),r.length>0&&this.dispatch(Xu(r.map(({uuid:o})=>o))),u.length>0&&this.dispatch(ht(u.map(({uuid:o})=>o))),d.length>0&&this.dispatch(gi(d.map(({uuid:o})=>o)));try{return await this.enqueueRequest({description:"Delete issue",method:l.DELETE,url:`/issues/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(qi(a)),this.dispatch(Ii(c)),this.dispatch(Yu(r)),this.dispatch(lt(u)),this.dispatch(fi(d)),o}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issues",method:l.GET,url:"/issues/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Qd(s))}}class Kf extends Re{constructor(){super(...arguments);f(this,"name","Issue Type Attachment");f(this,"url","/issue-type-attachments");f(this,"initializeAttachments",zi);f(this,"addAttachments",iu);f(this,"updateAttachments",au);f(this,"removeAttachments",ru);f(this,"removeAttachment",cu);f(this,"setAttachment",nu);f(this,"selectAttachment",ou)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueTypeUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue type attachments",method:l.GET,url:`${this.url}/`,queryParams:{organization:s},blocks:[],blockers:[]});this.dispatch(zi(n))}}class Yf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,file_extension:y.extension,field_identifier:p,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(pu(c));const u=this.enqueueRequest({description:"Add issue type fields attachments",method:l.POST,url:"/issue-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Au(d.attachments))}).catch(()=>{this.dispatch(yu(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"get issue type fields attachments",method:l.GET,url:"/issue-type-fields-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(mu(s))}}class Jf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Ou(c));const r=this.enqueueRequest({description:"Add Issue Type Fields",method:l.POST,url:"/issue-type-fields/",payload:v(c),blockers:[c.issue_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(vu(m))}).catch(m=>{throw this.dispatch(_u(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Issue Type Fields",method:l.GET,url:"/issue-type-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Pu(s))}}class Xf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{fieldValuesUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,field_values:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:p,field_values:o};r.push(I)}this.dispatch(At(c));const u=this.enqueueRequest({description:"Add issue type field values attachments",method:l.POST,url:"/issue-type-field-values-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.field_values),blocks:c.map(d=>d.uuid)});return u.then(({presigned_urls:d,attachments:o})=>{this.processPresignedUrls(d),this.dispatch(Mu(o))}).catch(d=>{throw this.dispatch(yt(c.map(o=>o.uuid))),d}),[c,u.then(({attachments:d})=>d)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=Cu(e)(n);this.dispatch(yt(e));try{await this.enqueueRequest({description:"Delete issue type field values attachments",method:l.DELETE,url:"/issue-type-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(At(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue type field values attachments",method:l.GET,url:"/issue-type-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(qu(s))}}class Qf extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add issue type field values",method:l.POST,url:"/issue-type-field-values/",payload:v(a),blockers:[e.issue,e.fields_revision],blocks:[a.uuid]});return this.dispatch(Ui(a)),c.then(u=>(this.dispatch(We(u)),u)).catch(()=>{this.dispatch($i(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=Gi(e.uuid)(n);if(!a)throw new Error(`Expected IssueTypeFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(We(c));const r=this.enqueueRequest({description:"Update issue type field values",method:l.PATCH,url:`/issue-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.issue],blocks:[c.uuid]});return r.then(u=>{this.dispatch(We(u))}).catch(()=>{this.dispatch(We(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Gi(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=zu(e)(n);this.dispatch($i(e)),this.dispatch(yt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete issue type field values",method:l.DELETE,url:`/issue-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Ui(a)),this.dispatch(At(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue type field values",method:l.GET,url:"/issue-type-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(bu(s))}}class Zf extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,submitted_at:new Date().toISOString(),created_by:(r=n.userReducer.currentUser)==null?void 0:r.id});this.dispatch($u(a));const c=this.enqueueRequest({method:l.POST,url:"/issue-types/",payload:v(a),blockers:[],blocks:[a.uuid]});return c.then(u=>{this.dispatch(Ke(u))}).catch(()=>{this.dispatch(Ki(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=Yi(e.uuid)(n);if(!a)throw new Error(`IssueType with uuid ${e.uuid} does not exist in the store.`);const c={...a,...e};this.dispatch(Bu(c));const r=this.enqueueRequest({method:l.PATCH,url:`/issue-types/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(Ke(u))}).catch(()=>{this.dispatch(Ke(a))}),[c,r]}delete(e){const{store:s}=this.client,n=s.getState(),a=Yi(e)(n);if(!a)throw new Error(`IssueType with uuid ${e} does not exist in the store.`);const c=Ji(e)(n);this.dispatch(Ki(e)),this.dispatch(xd(c.map(u=>u.uuid)));const r=this.enqueueRequest({method:l.DELETE,url:`/issue-types/${e}/`,blockers:[e],blocks:[]});return r.catch(()=>{this.dispatch(Ke(a)),this.dispatch(Zd(c))}),r}async refreshStore(e){const s=await this.enqueueRequest({method:l.GET,url:"/issue-types/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Uu(s))}}class xf extends P{async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue updates",method:l.GET,url:"/issue-updates/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Wu(s))}}const eS=1800;function tS(t){if(!t.access)throw new Error("Missing access token");if(!t.refresh)throw new Error("Missing refresh token");return{accessToken:t.access,refreshToken:t.refresh}}class sS extends lf{constructor(){super(...arguments);f(this,"_getRenewedTokens",async s=>{const n=this.enqueueRequest({description:"Get renewed tokens",method:l.POST,url:this.refreshTokensUrl,payload:{refresh:s},isAuthNeeded:!1,blockers:[],blocks:[],checkAuth:!1,immediate:!0});let a;try{a=await n}catch(c){console.error("Could not renew tokens; clearing auth",c),this.clearAuth();return}if(!a.access)throw new Error("Missing access token");return{accessToken:a.access,refreshToken:a.refresh??this.getRefreshToken()}})}clearAuth(){console.debug(this.constructor.name,"clearing auth;"),this.dispatch(Yc(!1)),this.clearTokens(),this.dispatch({type:Ll.RESET_STATE}),this.dispatch({type:El})}async renewTokens(){const s=this.getRefreshToken();if(!s)throw new Error("No refresh token found");console.debug(this.constructor.name,"renewing tokens");try{const n=await this._getRenewedTokens(s);if(!n)return;console.log("Got renewed tokens"),this.setTokens(n)}catch(n){throw console.error("Could not renew tokens; clearing auth",n),this.clearAuth(),n}}tokenIsExpiringSoon(){const s=this.getAccessToken();if(!s)return!1;const n=Date.now()/1e3;let a;try{a=Nl(s).exp??n}catch{a=n}return a-n<eS}getAuthHeader(){return`Bearer ${this.getAccessToken()}`}async prepareAuth(){if(this.tokenIsExpiringSoon()){console.debug(this.constructor.name,"preparing auth");try{await this.renewTokens()}catch(s){return s instanceof q&&this.clearAuth(),s instanceof Error?Promise.reject(s):Promise.reject(new Error((s??ke).toString()))}}}async handleUnauthorized(s,n){const a=this.client.store.getState();if(s.url.endsWith("/token/refresh/"))throw a.authReducer.isLoggedIn&&console.warn("No signed-in user to sign out."),this.clearAuth(),new q({message:"You have been signed out due to inactivity.",response:n,discard:!0});if(a.authReducer.isLoggedIn)await this.renewTokens();else throw console.debug("Forbidden; user is not logged in."),new q({message:"Incorrect username or password.",response:n,discard:!0})}async initAuth(s){const n=fe.v4();return console.debug(this.constructor.name,"Initiating auth"),this.enqueueRequest({uuid:n,description:"Get token pair",method:l.POST,url:this.initTokensUrl,payload:s,isAuthNeeded:!1,checkAuth:!1,immediate:!0,blockers:[],blocks:[]}).then(a=>{this.setTokens(tS(a))})}}class iS extends P{async getLicense(e){const s=await this.enqueueRequest({description:"Get license",method:l.GET,url:`/billing/${e.uuid}/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:[]});return this.dispatch(pe(s)),s}async pauseLicense(e){const s=await this.enqueueRequest({description:"Pause license",method:l.DELETE,url:`/billing/${e.uuid}/suspend/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:[]});return this.dispatch(pe(s)),s}async resumeLicense(e){const s=await this.enqueueRequest({description:"Resume license",method:l.PATCH,url:`/billing/${e.uuid}/suspend/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:[]});return this.dispatch(pe(s)),s}async cancelLicense(e){const s=await this.enqueueRequest({description:"Cancel license",method:l.DELETE,url:`/billing/${e.uuid}/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:[]});return this.dispatch(pe(s)),s}async attachLicenseToProject(e,s){const n=await this.enqueueRequest({description:"Attach license",method:l.PATCH,url:`/billing/${e.uuid}/project/`,isAuthNeeded:!0,payload:{project:s.uuid},blockers:[e.organization_owner,s.uuid],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});return this.dispatch(pe(n)),n}async detachLicenseFromProject(e){const s=await this.enqueueRequest({description:"Detach license",method:l.DELETE,url:`/billing/${e.uuid}/project/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});return this.dispatch(pe(s)),s}async getLatestTransaction(e){return await this.enqueueRequest({description:"Get latest transaction",method:l.GET,url:`/billing/${e.uuid}/transaction/`,isAuthNeeded:!0,blockers:[e.uuid],blocks:[e.uuid]})}async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Get licenses",method:l.GET,url:`/organizations/${s}/licenses/`,isAuthNeeded:!0,blockers:[s],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});for(const r of a)n[r.uuid]=r;const c=await this.enqueueRequest({description:"Get licenses",method:l.GET,url:`/projects/${e}/licenses/`,isAuthNeeded:!0,blockers:[e],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});for(const r of c)n[r.uuid]=r;this.dispatch(to(Object.values(n)))}}class nS extends P{async update(e){const s=this.enqueueRequest({description:"Edit organization access",method:l.PATCH,url:`/organizations/${e.organization}/access/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return s.then(()=>{this.dispatch(lo(e))}),s}async remove(e){return this.dispatch(ho(e.uuid)),this.dispatch(co(e.user)),this.enqueueRequest({description:"Remove organization access",method:l.DELETE,url:`/organizations/${e.organization}/access/${e.uuid}/`,blockers:[e.uuid],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization accesses",method:l.GET,url:`/organizations/${e}/access/`,blockers:[],blocks:[]});this.dispatch(oo(s))}}class aS extends P{create(e){return this.enqueueRequest({description:"Create organization",method:l.POST,url:"/organizations/",payload:{name:e},blockers:[],blocks:[`add-org-${e}`,"create-org"]})}async update(e){return this.enqueueRequest({description:"Edit organization",method:l.PATCH,url:`/organizations/${e.uuid}/`,payload:e,blockers:[`add-org-${e.name}`,e.uuid],blocks:[e.uuid]})}async invite(e,s){return this.enqueueRequest({description:"Invite user to organization",method:l.POST,url:`/organizations/${e}/invite/${s}/`,blockers:[],blocks:[]})}async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Get organizations",method:l.GET,url:`/projects/${e}/organizations/`,blockers:[],blocks:[]});for(const r of a)n[r.uuid]=r;const c=await this.enqueueRequest({description:"Get organization",method:l.GET,url:`/organizations/${s}/`,blockers:[],blocks:[]});n[c.uuid]=c,this.dispatch(jo(Object.values(n)))}}class cS extends P{async update(e){return this.dispatch(yo(e)),this.enqueueRequest({description:"Edit project access",method:l.PATCH,url:`/project-accesses/${e.uuid}/`,payload:e,blockers:[e.uuid,"change-access-level"],blocks:[e.uuid]})}async remove(e){return this.dispatch(fo(e)),this.enqueueRequest({description:"Delete project access",method:l.DELETE,url:`/project-accesses/${e}/`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project accesses",method:l.GET,url:"/project-accesses/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(sn(s))}}class rS extends Re{constructor(){super(...arguments);f(this,"name","Project Attachment");f(this,"url","/project-attachments");f(this,"addAttachments",Ho);f(this,"updateAttachments",Yo);f(this,"removeAttachments",un);f(this,"removeAttachment",Jo);f(this,"setAttachment",Wo);f(this,"selectAttachment",Zo)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,project:s.modelUuid})}buildAttachmentPayload(s){return{...s,project:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.projectUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get project attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blockers:[],blocks:[]});this.dispatch(No(n))}}class dS extends P{async saveExisting(e){if(!e.uuid)throw new Error("You can only use this method to save existing project files. The one provided has no uuid.");const s={...e};delete s.file;const n=this.enqueueRequest({method:l.PATCH,url:`/projects/files/${e.uuid}/`,payload:s,blockers:[e.uuid],blocks:[e.uuid]});return n.then(a=>{this.dispatch(ln(a))}),n}saveActive(){const{store:e}=this.client,s=e.getState(),n=s.projectFileReducer.activeProjectFileId;if(!n)throw new Error("No active project file");const a=s.projectFileReducer.instances[n];if(!a)throw new Error("No active project file");if(!a.bounds&&!a.canvas_bounds)throw new Error("Project file must either have bounds or canvas_bounds set");let c;if(typeof a.file=="string"&&!a.file.startsWith("blob:")){const m={...a};delete m.file,c={method:l.PATCH,url:`/projects/files/${n}/`,payload:m,blockers:[n],blocks:[n]}}else c=new Promise((m,d)=>{this.client.files.uploadFileToS3(a.file_sha1).then(([o])=>{m({method:l.POST,url:`/projects/${a.project}/files/`,payload:{...a,...o},blockers:[n],blocks:[n]})}).catch(d)});const u=Promise.resolve(c).then(m=>this.enqueueRequest(m));return u.then(m=>{this.dispatch(ln(m))}),this.dispatch(dl),this.dispatch(rl(null)),this.dispatch(cl(!1)),[a,u]}delete(e){return this.dispatch(nl(e)),this.enqueueRequest({method:l.DELETE,url:`/projects/files/${e}`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project files",method:l.GET,url:`/projects/${e}/files/`,blockers:[],blocks:[]});this.dispatch(sl(s))}}class uS extends P{async add(e){if(!e.bounds&&!e.canvas_bounds)throw new Error("Project must either have bounds or canvas_bounds set");return await this.enqueueRequest({description:"Create project",method:l.POST,url:"/projects/",payload:{name:e.name,bounds:e.bounds,organization_owner:e.organization_owner},blockers:[],blocks:[]})}async update(e){if(!e.bounds&&!e.canvas_bounds)throw new Error("Project must either have bounds or canvas_bounds set");return this.dispatch(Ro(e)),await this.enqueueRequest({description:"Update project",method:l.PATCH,url:`/projects/${e.uuid}/`,payload:{name:e.name,bounds:e.bounds},blockers:[e.uuid],blocks:[e.uuid]})}async delete(e){const{store:s}=this.client,n=s.getState(),a=It(n),c=a[e];if(!c)throw new Error("Expected project to exist");const r=ol(n).filter(o=>o.project===e);this.dispatch(al(r.map(({uuid:o})=>o)));const u=xo(c.uuid)(n);this.dispatch(un(u.map(({uuid:o})=>o)));const m=go(n);this.dispatch(So(m.map(({uuid:o})=>o))),this.dispatch({type:"rehydrated/setRehydrated",payload:!1}),this.dispatch(Po(c.uuid));const d=so(c.uuid)(n);d&&this.dispatch(pe({...d,project:null}));try{await this.enqueueRequest({description:"Delete project",method:l.DELETE,url:`/projects/${e}/`,blockers:[e],blocks:[]}),this.dispatch({type:"rehydrated/setRehydrated",payload:!0})}catch(o){throw this.dispatch(Fo(Object.values(a))),this.dispatch(sn(Object.values(m))),this.dispatch(il(r)),this.dispatch(Ko(u)),this.dispatch({type:"rehydrated/setRehydrated",payload:!0}),d&&this.dispatch(pe({...d,project:c.uuid})),o}}invite(e,s){const n=fe.v4();return this.enqueueRequest({description:"Invite user to project",method:l.POST,url:`/projects/${e}/invite/${s}/`,payload:{uuid:n},blockers:[],blocks:[n]})}joinProject(e,s,n){return this.enqueueRequest({description:"Join project",method:l.GET,url:`/projects/${e}/join-project/${s}/${n}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}async acceptInvite(e){return this.enqueueRequest({description:"Accept project invite",method:l.PATCH,url:`/projects/${e}/accept-invite/`,blockers:[e],blocks:[e]}).then(()=>{this.dispatch(Oo(e))})}}class oS extends P{add(e){const s=R({...e,submitted_at:new Date().toISOString()});this.dispatch(Al(s));const n=this.enqueueRequest({description:"Create team",method:l.POST,url:`/organizations/${e.organization}/teams/`,payload:s,blockers:[],blocks:[s.uuid]});return n.then(a=>{this.dispatch(qe(a))}).catch(()=>{this.dispatch(An(s.uuid))}),[s,n]}update(e){const{store:s}=this.client,n=Me(e.uuid)(s.getState());if(!n)throw new Error(`Expected team with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(pn(a));const c=this.enqueueRequest({description:"Update team",method:l.PATCH,url:`/organizations/teams/${e.uuid}/`,payload:v(e),blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(qe(r))}).catch(()=>{this.dispatch(qe(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Me(e)(n);if(!a)throw new Error(`Expected team with uuid ${e} to exist`);this.dispatch(An(e));try{return await this.enqueueRequest({description:"Delete team",method:l.DELETE,url:`/organizations/teams/${e}/`,blockers:[e],blocks:[e]})}catch(c){throw this.dispatch(qe(a)),c}}async setMembers(e,s){const{store:n}=this.client,a=Me(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);if(s.length!==new Set(s).size)throw new Error("Duplicate members found in the list");this.dispatch(pn({...a,members:s}));const c=this.enqueueRequest({description:"Set team members",method:l.PUT,url:`/organizations/teams/${e}/set-members/`,payload:{users:s},blockers:[e],blocks:[e]});return c.catch(()=>{this.dispatch(qe(a))}),c}async addMembers(e,s){const{store:n}=this.client,a=Me(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);const c=[...a.members,...s];return this.setMembers(e,c)}async removeMembers(e,s){const{store:n}=this.client,a=Me(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);const c=a.members.filter(r=>!s.includes(r));return this.setMembers(e,c)}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch teams",method:l.GET,url:`/organizations/${e}/teams/`,blockers:[],blocks:[]});this.dispatch(pl(s))}}class lS extends P{async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Fetch organization users",method:l.GET,url:`/organizations/${s}/users/`,blockers:[],blocks:[]});for(const r of a)n[r.id]=r;const c=await this.enqueueRequest({description:"Fetch project users",method:l.GET,url:`/projects/${e}/users/`,blockers:[],blocks:[]});for(const r of c)n[r.id]=r;this.dispatch(ao(Object.values(n)))}}class hS{constructor(e){f(this,"store");this.store=e}async enqueueRequest(e,s,n){return this._enqueueRequest(e,s,n).then(a=>{if(a instanceof q)throw a;return a})}_enqueueRequest(e,s,n){const a=new Mn,c={...e,BASE_URL:s,serviceName:n};if(e.immediate){const r={...c,uuid:e.uuid??fe.v4()},u={payload:r,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:r,BASE_URL:s,serviceName:n}}}};Tn(u,this).then(m=>{a.resolve(m.body)}).catch(m=>{bn(m,u),m instanceof Error?a.reject(m):a.reject(new Error((m??ke).toString()))})}else{const r=this.store.dispatch(Uo(c)),u=d=>{if(d)a.resolve(d.body);else{const o=new q({message:"Could not get a response from the server.",response:d,discard:!0});a.reject(o)}},m=d=>{d instanceof q?d.options.discard=!0:(console.error("Received an unexpected error while processing a request:",d,`
14
+ external URLs and therefore not prepended with VITE_API_URL.`;throw new Error(y)}const p=d.type.split("/")[1];if(!p)throw new Error("File has no extension");const A=a??o+"."+p;if(d=Cn(d,A),!d.name)throw new Error("Failed to set file's name");await this.addCache(d,o),Ft[c]=new Promise(y=>{y(d)})}return d}}class zf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{revisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,form_revision:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,field_identifier:p,file_extension:y.extension,file_sha1:y.sha1,form_revision:o};r.push(I)}this.dispatch(qr(c));const u=this.enqueueRequest({description:"Attach files to form revision",method:l.POST,url:"/form-revision-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.form_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Mr(d.attachments))}).catch(()=>{this.dispatch(kr(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization form revision attachments",method:l.GET,url:"/form-revision-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(jr(s))}}class Df extends E{add(e){var u;const{store:s}=this.client,a=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,c=R({...e,created_by:a,submitted_at:new Date().toISOString()});this.dispatch(xs(c));const r=this.enqueueRequest({description:"Create form revision",method:l.POST,url:"/form-revisions/",payload:v(c),blockers:[e.form],blocks:[c.uuid]});return r.then(m=>{this.dispatch(Vr(m))}).catch(()=>{this.dispatch(ei(c.uuid))}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization form revisions",method:l.GET,url:"/form-revisions/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(Ur(s))}}class Vf extends E{add(e,s){var d;const{store:n}=this.client,a=new Date().toISOString(),c=(d=n.getState().userReducer.currentUser)==null?void 0:d.id,r=R({...e,submitted_at:a,created_by:c}),u=R({...s,form:r.uuid,submitted_at:a,created_by:c});this.dispatch(si(r)),this.dispatch(xs(u));const m=this.enqueueRequest({description:"Create form",method:l.POST,url:"/forms/",payload:{...v(r),initial_revision:{uuid:u.uuid,submitted_at:u.submitted_at,title:u.title,description:u.description,fields:u.fields}},blockers:[],blocks:[r.uuid,u.uuid]});return m.catch(o=>{throw this.dispatch(ii(r.uuid)),this.dispatch(ei(u.uuid)),o}),[r,u,m]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Jr(e)(n);if(!a)throw new Error("Expected form to exist");const c=ad(e)(n);c.length>0&&this.dispatch(ht(c.map(({uuid:u})=>u)));const r=Lr(e)(n);r.length>0&&this.dispatch(Br(r.map(({uuid:u})=>u))),this.dispatch(ii(e));try{return await this.enqueueRequest({description:"Delete form",method:l.DELETE,url:`/forms/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(si(a)),r.length>0&&this.dispatch($r(r)),c.length>0&&this.dispatch(lt(c)),u}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch organization forms",method:l.GET,url:"/forms/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(Wr(s))}}class Uf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{submissionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,form_submission:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:p,form_submission:o};r.push(I)}this.dispatch(dt(c));const u=this.enqueueRequest({description:"Attach files to form submission",method:l.POST,url:"/form-submission-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.form_submission),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Zr(d.attachments))}).catch(d=>{throw this.dispatch(ut(c.map(o=>o.uuid))),d}),[c,u.then(({attachments:d})=>d)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=xr(e)(n);this.dispatch(ut(e));try{await this.enqueueRequest({description:"Delete form submission attachments",method:l.DELETE,url:"/form-submission-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(dt(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get form submission attachments",method:l.GET,url:"/form-submission-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Qr(s))}}class $f extends E{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add form submission",method:l.POST,url:"/form-submissions/",payload:v(a),blockers:["add-form-entry",e.form_revision,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[a.uuid]});return this.dispatch(ri(a)),c.then(u=>(this.dispatch(ot(u)),u)).catch(()=>{this.dispatch(di(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=li(e.uuid)(n);if(!a)throw new Error(`Expected submission with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(nd(c));const r=this.enqueueRequest({description:"Delete user form submissions",method:l.PATCH,url:`/form-submissions/${c.uuid}/`,payload:e,blockers:[c.uuid],blocks:[c.uuid]});return r.then(u=>{this.dispatch(ot(u))}).catch(()=>{this.dispatch(ot(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=li(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=ed(e)(n);this.dispatch(di(e)),this.dispatch(ut(c.map(r=>r.uuid)));try{return await this.enqueueRequest({description:"Delete user form submissions",method:l.DELETE,url:`/form-submissions/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(ri(a)),this.dispatch(dt(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch form submissions",method:l.GET,url:"/form-submissions/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(id(s))}}class Bf extends E{async add(e){var p;const{store:s}=this.client,{file:n,...a}=e,c=new Date().toISOString(),r=(p=s.getState().userReducer.currentUser)==null?void 0:p.id,u=a.project,m=await this.getFilePayload(n),d=R({...a,file_name:n.name,file_sha1:m.sha1,file:URL.createObjectURL(n),submitted_at:c,created_by:r});this.dispatch(hd(d));const o=this.enqueueRequest({description:"Add geo image",method:l.POST,url:"/geo-images/",payload:{uuid:d.uuid,submitted_at:c,title:d.title,description:d.description,geo_marker:d.geo_marker,canvas_marker:d.canvas_marker,sha1:d.file_sha1,project:d.project,file_name:d.file_name,direction:d.direction,original_date:d.original_date,file:m},blocks:[u],blockers:[u]});return o.then(A=>{this.processPresignedUrls(A.presigned_urls),this.dispatch(Ne(A.geo_image))}).catch(()=>{this.dispatch(mi(d.uuid))}),[d,o.then(A=>A.geo_image)]}async bulkAdd(e,s){var p;const{store:n}=this.client,a=new Date().toISOString(),c=(p=n.getState().userReducer.currentUser)==null?void 0:p.id,r=[],u=[],m=[],d={};for(const A of e){const{file:y,...T}=A,I=await this.getFilePayload(y);I.sha1 in d||(d[I.sha1]=I);const F=R({...T,file_name:y.name,file_sha1:I.sha1,file:URL.createObjectURL(y),submitted_at:a,created_by:c,project:s});r.push(F),u.push(F.uuid),m.push({uuid:F.uuid,sha1:F.file_sha1,file_name:F.file_name,title:F.title,description:F.description,geo_marker:F.geo_marker,canvas_marker:F.canvas_marker,direction:F.direction,original_date:F.original_date})}this.dispatch(md(r));const o=this.enqueueRequest({description:"Bulk add geo images",method:l.POST,url:"/geo-images/bulk/",payload:{submitted_at:a,project:s,geo_images:m,files:Object.values(d)},blocks:[s],blockers:u});return o.then(A=>{this.processPresignedUrls(A.presigned_urls),this.dispatch(ld(A.geo_images))}).catch(()=>{this.dispatch(Ad(u))}),[r,o.then(A=>A.geo_images)]}update(e){const{store:s}=this.client,n=s.getState(),a=pi(e.uuid)(n);if(!a)throw new Error(`Map image with uuid ${e.uuid} does not exist in the store`);const c={...a,...e};this.dispatch(pd(c));const r=this.enqueueRequest({description:"Update geo image",method:l.PATCH,url:`/geo-images/${e.uuid}/`,payload:e,blocks:[e.uuid],blockers:[e.uuid]});return r.then(u=>{this.dispatch(Ne(u))}).catch(()=>{this.dispatch(Ne(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=pi(e)(n);if(!a)throw new Error(`Map image with uuid ${e} does not exist in the store`);this.dispatch(mi(e));const c=this.enqueueRequest({description:"Delete geo image",method:l.DELETE,url:`/geo-images/${e}/`,blocks:[e],blockers:[e]});return c.catch(()=>{this.dispatch(Ne(a))}),c}async refreshStore(e){const s=await this.enqueueRequest({description:"Get geo images",method:l.GET,url:"/geo-images/",queryParams:{project:e},blocks:[e],blockers:[]});this.dispatch(od(s))}}class Gf extends P{add(e){var u;const{store:s}=this.client,n=new Date().toISOString(),a=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,c=R({...e,submitted_at:n,created_by:a});this.dispatch(yi(c));const r=this.enqueueRequest({description:"Add issue association",method:l.POST,url:"/issue-associations/",payload:v(c),blockers:[e.associated_issue,...e.issue?[e.issue]:[],...e.asset?[e.asset]:[]],blocks:[c.uuid]});return r.then(m=>{this.dispatch(bd(m))}).catch(()=>{this.dispatch(Si(c.uuid))}),[c,r]}async delete(e){const{store:s}=this.client,n=Id(e)(s.getState());if(!n)throw new Error(`Issue association with uuid ${e} not found in store.`);this.dispatch(Si(e));const a=this.enqueueRequest({description:"Delete issue association",method:l.DELETE,url:`/issue-associations/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(yi(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch issue associations",method:l.GET,url:"/issue-associations/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Td(s))}}class Lf extends Re{constructor(){super(...arguments);f(this,"name","Issue Attachment");f(this,"url","/issue-attachments");f(this,"initializeAttachments",bi);f(this,"addAttachments",Ii);f(this,"updateAttachments",wd);f(this,"removeAttachments",Fi);f(this,"removeAttachment",Ed);f(this,"setAttachment",_d);f(this,"selectAttachment",kd)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(bi(n))}}class Nf extends Re{constructor(){super(...arguments);f(this,"name","Issue Comment Attachment");f(this,"url","/issue-comment-attachments");f(this,"initializeAttachments",Pi);f(this,"addAttachments",Dd);f(this,"updateAttachments",Ud);f(this,"removeAttachments",Bd);f(this,"removeAttachment",$d);f(this,"setAttachment",Vd);f(this,"selectAttachment",Nd)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue_comment:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue_comment:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueCommentUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue comment attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blocks:[],blockers:[]});this.dispatch(Pi(n))}}class Hf extends P{add(e){var c;const{store:s}=this.client,n=R({...e,author:(c=s.getState().userReducer.currentUser)==null?void 0:c.id,submitted_at:new Date().toISOString()});this.dispatch(_i(n));const a=this.enqueueRequest({description:"Add issue comment",method:l.POST,url:"/issue-comments/",payload:v(n),blockers:[e.issue],blocks:[n.uuid]});return a.catch(()=>{this.dispatch(wi(n.uuid))}),[n,a]}update(e){const{store:s}=this.client,n=Ei(e.uuid)(s.getState());if(!n)throw new Error(`Comment with uuid ${e.uuid} not found in store`);const a={...n,...e};this.dispatch(vi(a));const c=this.enqueueRequest({description:"Edit issue comment",method:l.PATCH,url:`/issue-comments/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return c.catch(()=>{this.dispatch(vi(n))}),[a,c]}remove(e){const{store:s}=this.client,n=Ei(e)(s.getState());if(!n)throw new Error(`Comment with uuid ${e} not found in store`);this.dispatch(wi(e));const a=this.enqueueRequest({description:"Delete comment",method:l.DELETE,url:`/issue-comments/${e}/`,blockers:[e],blocks:[]});return a.catch(()=>{this.dispatch(_i(n))}),a}async refreshStore(e){const s=await this.enqueueRequest({description:"Get comments",method:l.GET,url:"/issue-comments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Kd(s))}}class Wf extends P{add(e){var m;const{store:s}=this.client,n=s.getState(),a=new Date().toISOString(),c=(m=n.userReducer.currentUser)==null?void 0:m.id,r=R({...e,submitted_at:a,created_by:c});this.dispatch(qi(r));const u=this.enqueueRequest({description:"Create issue",method:l.POST,url:"/issues/",payload:v(r),blockers:["add-issue",r.project,r.issue_type,...r.category?[r.category]:[]],blocks:[r.uuid]});return u.then(d=>{this.dispatch(mt(d))}).catch(d=>{throw this.dispatch(Mi(r.uuid)),d}),[r,u]}update(e){var m;const s=this.client.store.getState(),n=ki(e.uuid)(s);if(!n)throw new Error(`Attempting to update an issue with uuid ${e.uuid} that doesn't exist in the store`);const a={...n,...e};this.dispatch(mt(a));const c={};for(const d of[_.TITLE,_.DESCRIPTION,_.STATUS,_.CATEGORY,_.PRIORITY,_.ASSIGNED_TO,_.DUE_DATE])if(d in e&&e[d]!==n[d])switch(d){case _.PRIORITY:case _.STATUS:{const o=e[d];c[d]=o!==void 0?Number(o):null;break}case _.DUE_DATE:case _.DESCRIPTION:case _.TITLE:c[d]=e[d]??null;break;case _.CATEGORY:{let o=null;const p=e[d];if(p&&(o=s.categoryReducer.instances[p]??null,!o))throw new Error(`Trying to update issue category to ${p} which does not exist in store`);c[d]=o?{name:o.name,color:o.color,uuid:o.uuid}:null;break}case _.ASSIGNED_TO:{let o=null;const p=e[d];if(p&&(o=s.userReducer.instances[p]??null,!o))throw new Error(`Trying to update issue assigned_to to ${p} which does not exist in store`);c[d]=o?{full_name:o.username,id:o.id}:null;break}}const r=R({created_by:(m=s.userReducer.currentUser)==null?void 0:m.id,submitted_at:new Date().toISOString(),issue:n.uuid,changes:c});this.dispatch(Ku(r));const u=this.enqueueRequest({description:"Edit issue",method:l.PATCH,url:`/issues/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.catch(()=>{this.dispatch(mt(n)),this.dispatch(Ju(r.uuid))}),[a,u]}async remove(e){const{store:s}=this.client,n=s.getState(),a=ki(e)(n);if(!a)throw new Error(`No issue with uuid ${e} found in the store`);const c=Md(e)(n),r=Zu(e)(n),u=cd(e)(n),m={};for(const o of Fd(e)(n))m[o.uuid]=o;for(const o of Rd(e)(n))m[o.uuid]=o;const d=Object.values(m);this.dispatch(Mi(e)),c.length>0&&this.dispatch(Fi(c.map(({uuid:o})=>o))),r.length>0&&this.dispatch(Xu(r.map(({uuid:o})=>o))),u.length>0&&this.dispatch(ht(u.map(({uuid:o})=>o))),d.length>0&&this.dispatch(gi(d.map(({uuid:o})=>o)));try{return await this.enqueueRequest({description:"Delete issue",method:l.DELETE,url:`/issues/${e}/`,blockers:[e],blocks:[]})}catch(o){throw this.dispatch(qi(a)),this.dispatch(Ii(c)),this.dispatch(Yu(r)),this.dispatch(lt(u)),this.dispatch(fi(d)),o}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issues",method:l.GET,url:"/issues/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Qd(s))}}class Kf extends Re{constructor(){super(...arguments);f(this,"name","Issue Type Attachment");f(this,"url","/issue-type-attachments");f(this,"initializeAttachments",zi);f(this,"addAttachments",iu);f(this,"updateAttachments",au);f(this,"removeAttachments",ru);f(this,"removeAttachment",cu);f(this,"setAttachment",nu);f(this,"selectAttachment",ou)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,issue_type:s.modelUuid})}buildAttachmentPayload(s){return{...s,issue_type:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.issueTypeUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get issue type attachments",method:l.GET,url:`${this.url}/`,queryParams:{organization:s},blocks:[],blockers:[]});this.dispatch(zi(n))}}class Yf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{fieldsRevisionUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,fields_revision:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,file_extension:y.extension,field_identifier:p,file_sha1:y.sha1,fields_revision:o};r.push(I)}this.dispatch(pu(c));const u=this.enqueueRequest({description:"Add issue type fields attachments",method:l.POST,url:"/issue-type-fields-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.fields_revision),blocks:c.map(d=>d.uuid)});return u.then(d=>{this.processPresignedUrls(d.presigned_urls),this.dispatch(Au(d.attachments))}).catch(()=>{this.dispatch(yu(c.map(d=>d.uuid)))}),[c,u.then(({attachments:d})=>d)]}async refreshStore(e){const s=await this.enqueueRequest({description:"get issue type fields attachments",method:l.GET,url:"/issue-type-fields-attachments/",queryParams:{organization:e},blockers:[e],blocks:[]});this.dispatch(mu(s))}}class Jf extends P{add(e){var u;const{store:s}=this.client,n=(u=s.getState().userReducer.currentUser)==null?void 0:u.id,a=new Date().toISOString(),c=R({...e,created_by:n,submitted_at:a});this.dispatch(Ou(c));const r=this.enqueueRequest({description:"Add Issue Type Fields",method:l.POST,url:"/issue-type-fields/",payload:v(c),blockers:[c.issue_type],blocks:[c.uuid]});return r.then(m=>{this.dispatch(vu(m))}).catch(m=>{throw this.dispatch(_u(c.uuid)),m}),[c,r]}async refreshStore(e){const s=await this.enqueueRequest({description:"Get Issue Type Fields",method:l.GET,url:"/issue-type-fields/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Pu(s))}}class Xf extends E{async bulkAdd(e){var m;const s=new Date().toISOString(),n=(m=this.client.store.getState().userReducer.currentUser)==null?void 0:m.id,a={},c=[],r=[];for(const d of e){const{fieldValuesUuid:o,fieldIdentifier:p,file:A}=d,y=await this.getFilePayload(A);y.sha1 in a||(a[y.sha1]=y);const T=R({file:URL.createObjectURL(A),file_type:A.type,file_name:A.name,file_sha1:y.sha1,created_by:n,field_values:o,submitted_at:s,field_identifier:p});c.push(T);const I={uuid:T.uuid,file_name:A.name,file_sha1:y.sha1,file_extension:y.extension,field_identifier:p,field_values:o};r.push(I)}this.dispatch(At(c));const u=this.enqueueRequest({description:"Add issue type field values attachments",method:l.POST,url:"/issue-type-field-values-attachments/bulk/",payload:{submitted_at:s,attachments:r,files:Object.values(a)},blockers:c.map(d=>d.field_values),blocks:c.map(d=>d.uuid)});return u.then(({presigned_urls:d,attachments:o})=>{this.processPresignedUrls(d),this.dispatch(Mu(o))}).catch(d=>{throw this.dispatch(yt(c.map(o=>o.uuid))),d}),[c,u.then(({attachments:d})=>d)]}async bulkDelete(e){const{store:s}=this.client,n=s.getState(),a=Cu(e)(n);this.dispatch(yt(e));try{await this.enqueueRequest({description:"Delete issue type field values attachments",method:l.DELETE,url:"/issue-type-field-values-attachments/bulk/",payload:{attachment_ids:e},blockers:e,blocks:[]})}catch(c){throw this.dispatch(At(a)),c}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue type field values attachments",method:l.GET,url:"/issue-type-field-values-attachments/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(qu(s))}}class Qf extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,created_by:(r=n.userReducer.currentUser)==null?void 0:r.id,submitted_at:new Date().toISOString()}),c=this.enqueueRequest({description:"Add issue type field values",method:l.POST,url:"/issue-type-field-values/",payload:v(a),blockers:[e.issue,e.fields_revision],blocks:[a.uuid]});return this.dispatch(Ui(a)),c.then(u=>(this.dispatch(We(u)),u)).catch(()=>{this.dispatch($i(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=Gi(e.uuid)(n);if(!a)throw new Error(`Expected IssueTypeFieldValues with uuid ${e.uuid} to exist`);const c={...a,...e};this.dispatch(We(c));const r=this.enqueueRequest({description:"Update issue type field values",method:l.PATCH,url:`/issue-type-field-values/${e.uuid}/`,payload:e,blockers:[c.uuid,c.fields_revision,c.issue],blocks:[c.uuid]});return r.then(u=>{this.dispatch(We(u))}).catch(()=>{this.dispatch(We(a))}),[c,r]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Gi(e)(n);if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const c=zu(e)(n);this.dispatch($i(e)),this.dispatch(yt(c.map(r=>r.uuid)));try{await this.enqueueRequest({description:"Delete issue type field values",method:l.DELETE,url:`/issue-type-field-values/${e}/`,blockers:[e],blocks:[]})}catch(r){throw this.dispatch(Ui(a)),this.dispatch(At(c)),r}}async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue type field values",method:l.GET,url:"/issue-type-field-values/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(bu(s))}}class Zf extends P{add(e){var r;const{store:s}=this.client,n=s.getState(),a=R({...e,submitted_at:new Date().toISOString(),created_by:(r=n.userReducer.currentUser)==null?void 0:r.id});this.dispatch($u(a));const c=this.enqueueRequest({method:l.POST,url:"/issue-types/",payload:v(a),blockers:[],blocks:[a.uuid]});return c.then(u=>{this.dispatch(Ke(u))}).catch(()=>{this.dispatch(Ki(a.uuid))}),[a,c]}update(e){const{store:s}=this.client,n=s.getState(),a=Yi(e.uuid)(n);if(!a)throw new Error(`IssueType with uuid ${e.uuid} does not exist in the store.`);const c={...a,...e};this.dispatch(Bu(c));const r=this.enqueueRequest({method:l.PATCH,url:`/issue-types/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return r.then(u=>{this.dispatch(Ke(u))}).catch(()=>{this.dispatch(Ke(a))}),[c,r]}delete(e){const{store:s}=this.client,n=s.getState(),a=Yi(e)(n);if(!a)throw new Error(`IssueType with uuid ${e} does not exist in the store.`);const c=Ji(e)(n);this.dispatch(Ki(e)),this.dispatch(xd(c.map(u=>u.uuid)));const r=this.enqueueRequest({method:l.DELETE,url:`/issue-types/${e}/`,blockers:[e],blocks:[]});return r.catch(()=>{this.dispatch(Ke(a)),this.dispatch(Zd(c))}),r}async refreshStore(e){const s=await this.enqueueRequest({method:l.GET,url:"/issue-types/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(Uu(s))}}class xf extends P{async refreshStore(e){const s=await this.enqueueRequest({description:"Get issue updates",method:l.GET,url:"/issue-updates/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(Wu(s))}}const eS=1800;function tS(t){if(!t.access)throw new Error("Missing access token");if(!t.refresh)throw new Error("Missing refresh token");return{accessToken:t.access,refreshToken:t.refresh}}class sS extends lf{constructor(){super(...arguments);f(this,"_getRenewedTokens",async s=>{const n=this.enqueueRequest({description:"Get renewed tokens",method:l.POST,url:this.refreshTokensUrl,payload:{refresh:s},isAuthNeeded:!1,blockers:[],blocks:[],checkAuth:!1,immediate:!0});let a;try{a=await n}catch(c){console.error("Could not renew tokens; clearing auth",c),this.clearAuth();return}if(!a.access)throw new Error("Missing access token");return{accessToken:a.access,refreshToken:a.refresh??this.getRefreshToken()}})}clearAuth(){console.debug(this.constructor.name,"clearing auth;"),this.dispatch(Yc(!1)),this.clearTokens(),this.dispatch({type:Ll.RESET_STATE}),this.dispatch({type:El})}async renewTokens(){const s=this.getRefreshToken();if(!s)throw new Error("No refresh token found");console.debug(this.constructor.name,"renewing tokens");try{const n=await this._getRenewedTokens(s);if(!n)return;console.log("Got renewed tokens"),this.setTokens(n)}catch(n){throw console.error("Could not renew tokens; clearing auth",n),this.clearAuth(),n}}tokenIsExpiringSoon(){const s=this.getAccessToken();if(!s)return!1;const n=Date.now()/1e3;let a;try{a=Nl(s).exp??n}catch{a=n}return a-n<eS}getAuthHeader(){return`Bearer ${this.getAccessToken()}`}async prepareAuth(){if(this.tokenIsExpiringSoon()){console.debug(this.constructor.name,"preparing auth");try{await this.renewTokens()}catch(s){return s instanceof q&&this.clearAuth(),s instanceof Error?Promise.reject(s):Promise.reject(new Error((s??ke).toString()))}}}async handleUnauthorized(s,n){const a=this.client.store.getState();if(s.url.endsWith("/token/refresh/"))throw a.authReducer.isLoggedIn&&console.warn("No signed-in user to sign out."),this.clearAuth(),new q({message:"You have been signed out due to inactivity.",response:n,discard:!0});if(a.authReducer.isLoggedIn)await this.renewTokens();else throw console.debug("Forbidden; user is not logged in."),new q({message:"Incorrect username or password.",response:n,discard:!0})}async initAuth(s){const n=fe.v4();return console.debug(this.constructor.name,"Initiating auth"),this.enqueueRequest({uuid:n,description:"Get token pair",method:l.POST,url:this.initTokensUrl,payload:s,isAuthNeeded:!1,checkAuth:!1,immediate:!0,blockers:[],blocks:[]}).then(a=>{this.setTokens(tS(a))})}}class iS extends P{async getLicense(e){const s=await this.enqueueRequest({description:"Get license",method:l.GET,url:`/billing/${e.uuid}/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:[]});return this.dispatch(pe(s)),s}async pauseLicense(e){const s=await this.enqueueRequest({description:"Pause license",method:l.DELETE,url:`/billing/${e.uuid}/suspend/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:[]});return this.dispatch(pe(s)),s}async resumeLicense(e){const s=await this.enqueueRequest({description:"Resume license",method:l.PATCH,url:`/billing/${e.uuid}/suspend/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:[]});return this.dispatch(pe(s)),s}async cancelLicense(e){const s=await this.enqueueRequest({description:"Cancel license",method:l.DELETE,url:`/billing/${e.uuid}/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:[]});return this.dispatch(pe(s)),s}async attachLicenseToProject(e,s){const n=await this.enqueueRequest({description:"Attach license",method:l.PATCH,url:`/billing/${e.uuid}/project/`,isAuthNeeded:!0,payload:{project:s.uuid},blockers:[e.organization_owner,s.uuid],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});return this.dispatch(pe(n)),n}async detachLicenseFromProject(e){const s=await this.enqueueRequest({description:"Detach license",method:l.DELETE,url:`/billing/${e.uuid}/project/`,isAuthNeeded:!0,blockers:[e.organization_owner],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});return this.dispatch(pe(s)),s}async getLatestTransaction(e){return await this.enqueueRequest({description:"Get latest transaction",method:l.GET,url:`/billing/${e.uuid}/transaction/`,isAuthNeeded:!0,blockers:[e.uuid],blocks:[e.uuid]})}async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Get licenses",method:l.GET,url:`/organizations/${s}/licenses/`,isAuthNeeded:!0,blockers:[s],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});for(const r of a)n[r.uuid]=r;const c=await this.enqueueRequest({description:"Get licenses",method:l.GET,url:`/projects/${e}/licenses/`,isAuthNeeded:!0,blockers:[e],blocks:["add-issue","add-form-entry","change-access-level","add-workspace"]});for(const r of c)n[r.uuid]=r;this.dispatch(to(Object.values(n)))}}class nS extends P{async update(e){const s=this.enqueueRequest({description:"Edit organization access",method:l.PATCH,url:`/organization-accesses/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return s.then(()=>{this.dispatch(lo(e))}),s}async remove(e){return this.dispatch(ho(e.uuid)),this.dispatch(co(e.user)),this.enqueueRequest({description:"Remove organization access",method:l.DELETE,url:`/organization-accesses/${e.uuid}/`,blockers:[e.uuid],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get organization accesses",method:l.GET,url:"/organization-accesses/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(oo(s))}}class aS extends P{create(e){return this.enqueueRequest({description:"Create organization",method:l.POST,url:"/organizations/",payload:{name:e},blockers:[],blocks:[`add-org-${e}`,"create-org"]})}async update(e){return this.enqueueRequest({description:"Edit organization",method:l.PATCH,url:`/organizations/${e.uuid}/`,payload:e,blockers:[`add-org-${e.name}`,e.uuid],blocks:[e.uuid]})}async invite(e,s){return this.enqueueRequest({description:"Invite user to organization",method:l.POST,url:`/organizations/${e}/invite/${s}/`,blockers:[],blocks:[]})}async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Get organizations",method:l.GET,url:`/projects/${e}/organizations/`,blockers:[],blocks:[]});for(const r of a)n[r.uuid]=r;const c=await this.enqueueRequest({description:"Get organization",method:l.GET,url:`/organizations/${s}/`,blockers:[],blocks:[]});n[c.uuid]=c,this.dispatch(jo(Object.values(n)))}}class cS extends P{async update(e){return this.dispatch(yo(e)),this.enqueueRequest({description:"Edit project access",method:l.PATCH,url:`/project-accesses/${e.uuid}/`,payload:e,blockers:[e.uuid,"change-access-level"],blocks:[e.uuid]})}async remove(e){return this.dispatch(fo(e)),this.enqueueRequest({description:"Delete project access",method:l.DELETE,url:`/project-accesses/${e}/`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project accesses",method:l.GET,url:"/project-accesses/",queryParams:{project:e},blockers:[],blocks:[]});this.dispatch(sn(s))}}class rS extends Re{constructor(){super(...arguments);f(this,"name","Project Attachment");f(this,"url","/project-attachments");f(this,"addAttachments",Ho);f(this,"updateAttachments",Yo);f(this,"removeAttachments",un);f(this,"removeAttachment",Jo);f(this,"setAttachment",Wo);f(this,"selectAttachment",Zo)}buildOfflineAttachment(s){return R({file:URL.createObjectURL(s.file),file_sha1:s.file_sha1,created_by:s.created_by,file_name:s.file.name,file_type:s.file.type,submitted_at:s.submitted_at,description:s.description,project:s.modelUuid})}buildAttachmentPayload(s){return{...s,project:s.modelUuid}}async bulkAdd(s){return this._bulkAdd(s.map(n=>({modelUuid:n.projectUuid,file:n.file})))}async delete(s){return this._delete(s)}async refreshStore(s){const n=await this.enqueueRequest({description:"Get project attachments",method:l.GET,url:`${this.url}/`,queryParams:{project:s},blockers:[],blocks:[]});this.dispatch(No(n))}}class dS extends P{async saveExisting(e){if(!e.uuid)throw new Error("You can only use this method to save existing project files. The one provided has no uuid.");const s={...e};delete s.file;const n=this.enqueueRequest({method:l.PATCH,url:`/projects/files/${e.uuid}/`,payload:s,blockers:[e.uuid],blocks:[e.uuid]});return n.then(a=>{this.dispatch(ln(a))}),n}saveActive(){const{store:e}=this.client,s=e.getState(),n=s.projectFileReducer.activeProjectFileId;if(!n)throw new Error("No active project file");const a=s.projectFileReducer.instances[n];if(!a)throw new Error("No active project file");if(!a.bounds&&!a.canvas_bounds)throw new Error("Project file must either have bounds or canvas_bounds set");let c;if(typeof a.file=="string"&&!a.file.startsWith("blob:")){const m={...a};delete m.file,c={method:l.PATCH,url:`/projects/files/${n}/`,payload:m,blockers:[n],blocks:[n]}}else c=new Promise((m,d)=>{this.client.files.uploadFileToS3(a.file_sha1).then(([o])=>{m({method:l.POST,url:`/projects/${a.project}/files/`,payload:{...a,...o},blockers:[n],blocks:[n]})}).catch(d)});const u=Promise.resolve(c).then(m=>this.enqueueRequest(m));return u.then(m=>{this.dispatch(ln(m))}),this.dispatch(dl),this.dispatch(rl(null)),this.dispatch(cl(!1)),[a,u]}delete(e){return this.dispatch(nl(e)),this.enqueueRequest({method:l.DELETE,url:`/projects/files/${e}`,blockers:[e],blocks:[]})}async refreshStore(e){const s=await this.enqueueRequest({description:"Get project files",method:l.GET,url:`/projects/${e}/files/`,blockers:[],blocks:[]});this.dispatch(sl(s))}}class uS extends P{async add(e){if(!e.bounds&&!e.canvas_bounds)throw new Error("Project must either have bounds or canvas_bounds set");return await this.enqueueRequest({description:"Create project",method:l.POST,url:"/projects/",payload:{name:e.name,bounds:e.bounds,organization_owner:e.organization_owner},blockers:[],blocks:[]})}async update(e){if(!e.bounds&&!e.canvas_bounds)throw new Error("Project must either have bounds or canvas_bounds set");return this.dispatch(Ro(e)),await this.enqueueRequest({description:"Update project",method:l.PATCH,url:`/projects/${e.uuid}/`,payload:{name:e.name,bounds:e.bounds},blockers:[e.uuid],blocks:[e.uuid]})}async delete(e){const{store:s}=this.client,n=s.getState(),a=It(n),c=a[e];if(!c)throw new Error("Expected project to exist");const r=ol(n).filter(o=>o.project===e);this.dispatch(al(r.map(({uuid:o})=>o)));const u=xo(c.uuid)(n);this.dispatch(un(u.map(({uuid:o})=>o)));const m=go(n);this.dispatch(So(m.map(({uuid:o})=>o))),this.dispatch({type:"rehydrated/setRehydrated",payload:!1}),this.dispatch(Po(c.uuid));const d=so(c.uuid)(n);d&&this.dispatch(pe({...d,project:null}));try{await this.enqueueRequest({description:"Delete project",method:l.DELETE,url:`/projects/${e}/`,blockers:[e],blocks:[]}),this.dispatch({type:"rehydrated/setRehydrated",payload:!0})}catch(o){throw this.dispatch(Fo(Object.values(a))),this.dispatch(sn(Object.values(m))),this.dispatch(il(r)),this.dispatch(Ko(u)),this.dispatch({type:"rehydrated/setRehydrated",payload:!0}),d&&this.dispatch(pe({...d,project:c.uuid})),o}}invite(e,s){const n=fe.v4();return this.enqueueRequest({description:"Invite user to project",method:l.POST,url:`/projects/${e}/invite/${s}/`,payload:{uuid:n},blockers:[],blocks:[n]})}joinProject(e,s,n){return this.enqueueRequest({description:"Join project",method:l.GET,url:`/projects/${e}/join-project/${s}/${n}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}async acceptInvite(e){return this.enqueueRequest({description:"Accept project invite",method:l.PATCH,url:`/projects/${e}/accept-invite/`,blockers:[e],blocks:[e]}).then(()=>{this.dispatch(Oo(e))})}}class oS extends P{add(e){const s=R({...e,submitted_at:new Date().toISOString()});this.dispatch(Al(s));const n=this.enqueueRequest({description:"Create team",method:l.POST,url:"/teams/",payload:s,blockers:[],blocks:[s.uuid]});return n.then(a=>{this.dispatch(qe(a))}).catch(()=>{this.dispatch(An(s.uuid))}),[s,n]}update(e){const{store:s}=this.client,n=Me(e.uuid)(s.getState());if(!n)throw new Error(`Expected team with uuid ${e.uuid} to exist`);const a={...n,...e};this.dispatch(pn(a));const c=this.enqueueRequest({description:"Update team",method:l.PATCH,url:`/teams/${e.uuid}/`,payload:v(e),blockers:[e.uuid],blocks:[e.uuid]});return c.then(r=>{this.dispatch(qe(r))}).catch(()=>{this.dispatch(qe(n))}),[a,c]}async delete(e){const{store:s}=this.client,n=s.getState(),a=Me(e)(n);if(!a)throw new Error(`Expected team with uuid ${e} to exist`);this.dispatch(An(e));try{return await this.enqueueRequest({description:"Delete team",method:l.DELETE,url:`/teams/${e}/`,blockers:[e],blocks:[e]})}catch(c){throw this.dispatch(qe(a)),c}}async setMembers(e,s){const{store:n}=this.client,a=Me(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);if(s.length!==new Set(s).size)throw new Error("Duplicate members found in the list");this.dispatch(pn({...a,members:s}));const c=this.enqueueRequest({description:"Set team members",method:l.PUT,url:`/teams/${e}/set-members/`,payload:{users:s},blockers:[e],blocks:[e]});return c.catch(()=>{this.dispatch(qe(a))}),c}async addMembers(e,s){const{store:n}=this.client,a=Me(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);const c=[...a.members,...s];return this.setMembers(e,c)}async removeMembers(e,s){const{store:n}=this.client,a=Me(e)(n.getState());if(!a)throw new Error(`Expected team with uuid ${e} to exist`);const c=a.members.filter(r=>!s.includes(r));return this.setMembers(e,c)}async refreshStore(e){const s=await this.enqueueRequest({description:"Fetch teams",method:l.GET,url:"/teams/",queryParams:{organization:e},blockers:[],blocks:[]});this.dispatch(pl(s))}}class lS extends P{async refreshStore(e,s){const n={},a=await this.enqueueRequest({description:"Fetch organization users",method:l.GET,url:`/organizations/${s}/users/`,blockers:[],blocks:[]});for(const r of a)n[r.id]=r;const c=await this.enqueueRequest({description:"Fetch project users",method:l.GET,url:`/projects/${e}/users/`,blockers:[],blocks:[]});for(const r of c)n[r.id]=r;this.dispatch(ao(Object.values(n)))}}class hS{constructor(e){f(this,"store");this.store=e}async enqueueRequest(e,s,n){return this._enqueueRequest(e,s,n).then(a=>{if(a instanceof q)throw a;return a})}_enqueueRequest(e,s,n){const a=new Mn,c={...e,BASE_URL:s,serviceName:n};if(e.immediate){const r={...c,uuid:e.uuid??fe.v4()},u={payload:r,type:"",meta:{offline:{effect:{timestamp:new Date().toISOString(),request:r,BASE_URL:s,serviceName:n}}}};Tn(u,this).then(m=>{a.resolve(m.body)}).catch(m=>{bn(m,u),m instanceof Error?a.reject(m):a.reject(new Error((m??ke).toString()))})}else{const r=this.store.dispatch(Uo(c)),u=d=>{if(d)a.resolve(d.body);else{const o=new q({message:"Could not get a response from the server.",response:d,discard:!0});a.reject(o)}},m=d=>{d instanceof q?d.options.discard=!0:(console.error("Received an unexpected error while processing a request:",d,`
15
15
  Converting error to APIError and discarding.`),d=new q({message:"An error occurred while processing the request.",innerError:d,discard:!0})),a.reject(d)};r.then(u,m)}return a}}class Ce{constructor(){f(this,"graph");f(this,"requestAttemptCounter");this.graph=new Hl.DepGraph,this.requestAttemptCounter={}}static _fromOutbox(e){const s=new Ce;for(let n=0;n<e.length;n++){const a=e[n];if(!a){console.error("Outbox item was undefined");continue}s.sneakRequest(a);for(let c=0;c<n;c++){const r=e[c];if(!r){console.error("Previous outbox item was undefined");continue}r.payload.uuid!==a.payload.uuid&&r.payload.blocks.some(u=>a.payload.blockers.includes(u))&&Ce._addDependency(a.payload.uuid,r.payload.uuid,s.graph)}}return s}_addDependency(e,s){Ce._addDependency(e,s,this.graph)}static _addDependency(e,s,n){if(e===s)throw new Error(`Tried to add dependency from node to itself: ${e}`);if(!n.hasNode(e))throw new Error(`Tried to add dependency from non-existent node: ${e} (to node: ${s})`);if(!n.hasNode(s))throw new Error(`Tried to add dependency to non-existent node: ${s} (from node: ${e})`);n.addDependency(e,s)}addRequest(e){if(this.graph.addNode(e.payload.uuid,e),!(e.payload.blockers.length===0||this.graph.size()===1))for(const s of this.graph.overallOrder()){if(s===e.payload.uuid)continue;const n=this.graph.getNodeData(s);e.payload.blockers.some(a=>n.payload.blocks.includes(a))&&this._addDependency(e.payload.uuid,s)}}insertRequest(e){this.graph.addNode(e.payload.uuid,e);for(const s of this.graph.overallOrder()){if(s===e.payload.uuid)continue;this.graph.getNodeData(s).payload.blockers.some(a=>e.payload.blocks.includes(a))&&this._addDependency(s,e.payload.uuid)}}sneakRequest(e){this.graph.addNode(e.payload.uuid,e)}_getNextNode(){const e=this.graph.overallOrder(!0);let s=1/0,n;for(const a of e){const c=this.requestAttemptCounter[a]||0;c<s&&(s=c,n=a)}return n}peek(){const e=this._getNextNode();if(e)return this.graph.getNodeData(e)}remove(e){this.graph.removeNode(e),delete this.requestAttemptCounter[e]}pop(){const e=this.peek();return e&&this.graph.removeNode(e.payload.uuid),e}getQueue(){const e=this.graph.overallOrder().map(n=>this.graph.getNodeData(n)),s=this._getNextNode();if(s){const n=this.graph.getNodeData(s),a=e.findIndex(c=>c.payload.uuid===n.payload.uuid);a!==-1&&(e.splice(a,1),e.unshift(n))}return e}getReady(){let e=this.graph.overallOrder(!0).map(s=>this.graph.getNodeData(s));return e=e.sort((s,n)=>s.meta.offline.effect.timestamp.localeCompare(n.meta.offline.effect.timestamp)),e=e.sort((s,n)=>{const a=this.requestAttemptCounter[s.payload.uuid]||0,c=this.requestAttemptCounter[n.payload.uuid]||0;return a-c}),e}registerRetry(e){this.requestAttemptCounter[e]=(this.requestAttemptCounter[e]||0)+1}}const mS=(t,e)=>{const s=new e(t);return Ly(s),Gy(t),s};var zl=(t=>(t[t.USER_REGISTRATION=0]="USER_REGISTRATION",t[t.APPLICATION_INVITE=2]="APPLICATION_INVITE",t[t.PROJECT_INVITE=4]="PROJECT_INVITE",t[t.ORGANIZATION_INVITE=6]="ORGANIZATION_INVITE",t[t.ADD_EMAIL_DOMAIN=8]="ADD_EMAIL_DOMAIN",t[t.RESET_PASSWORD=10]="RESET_PASSWORD",t))(zl||{});i.APIError=q,i.AgentService=hf,i.AssetAttachmentService=mf,i.AssetProcedureFieldValuesAttachmentService=yf,i.AssetProcedureFieldValuesService=ff,i.AssetProcedureFieldsAttachmentService=pf,i.AssetProcedureFieldsService=Af,i.AssetProcedureInstanceService=Sf,i.AssetProcedureService=gf,i.AssetService=Tf,i.AssetStageCompletionService=bf,i.AssetStageService=If,i.AssetTypeAttachmentService=Ff,i.AssetTypeFieldValuesAttachmentService=Of,i.AssetTypeFieldValuesService=vf,i.AssetTypeFieldsAttachmentService=Rf,i.AssetTypeFieldsService=Pf,i.AssetTypeService=_f,i.AttachmentModel=_n,i.BaseApiService=P,i.BaseSDK=hS,i.COMMON_AUTO_FIELDS=Vn,i.CategoryService=wf,i.DEFAULT_ISSUE_PRIORITY=Kl,i.DEFAULT_ISSUE_STATUS=Wl,i.DeferredPromise=Mn,i.DocumentAttachmentService=Ef,i.DocumentService=jf,i.EMPTY_ARRAY=On,i.EMPTY_OBJECT=vn,i.EmailDomainsService=qf,i.EmailVerificationService=Mf,i.FileService=Cf,i.FormRevisionAttachmentService=zf,i.FormRevisionService=Df,i.FormService=Vf,i.FormSubmissionAttachmentService=Uf,i.FormSubmissionService=$f,i.GeoImageService=Bf,i.HttpMethod=l,i.IssueAssociationService=Gf,i.IssueAttachmentService=Lf,i.IssueCommentAttachmentService=Nf,i.IssueCommentService=Hf,i.IssuePriority=_t,i.IssueService=Wf,i.IssueStatus=wt,i.IssueTypeAttachmentService=Kf,i.IssueTypeFieldValuesAttachmentService=Xf,i.IssueTypeFieldValuesService=Qf,i.IssueTypeFieldsAttachmentService=Yf,i.IssueTypeFieldsService=Jf,i.IssueTypeService=Zf,i.IssueUpdateChange=_,i.IssueUpdateService=xf,i.JWTService=sS,i.LicenseLevel=En,i.LicenseService=iS,i.LicenseStatus=jn,i.OUTBOX_RETRY_DELAY=qn,i.OrganizationAccessLevel=vt,i.OrganizationAccessService=nS,i.OrganizationService=aS,i.OutboxCoordinator=Ce,i.PaddleCheckoutEvent=wn,i.ProjectAccessLevel=Ot,i.ProjectAccessService=cS,i.ProjectAttachmentService=rS,i.ProjectFileService=dS,i.ProjectService=uS,i.TeamService=oS,i.UNKNOWN_ERROR_MESSAGE=ke,i.UserService=lS,i.VERSION_REDUCER_KEY=Sn,i.VerificationCodeType=zl,i._setLatestRetryTime=Bo,i.acceptProjectInvite=Oo,i.addAsset=ds,i.addAssetAttachment=gh,i.addAssetAttachments=Vt,i.addAssetProcedure=is,i.addAssetProcedureFieldValues=Wt,i.addAssetProcedureFieldValuesAttachment=Dh,i.addAssetProcedureFieldValuesAttachments=Ze,i.addAssetProcedureFieldValuesMany=Oa,i.addAssetProcedureFields=ha,i.addAssetProcedureFieldsAttachment=Ih,i.addAssetProcedureFieldsAttachments=na,i.addAssetProcedureFieldsMany=wh,i.addAssetProcedureInstance=Qt,i.addAssetProcedureInstances=Ma,i.addAssetProcedures=Zh,i.addAssetStage=hm,i.addAssetStageCompletion=As,i.addAssetStageCompletions=ys,i.addAssetStages=bs,i.addAssetType=Vs,i.addAssetTypeAttachment=ym,i.addAssetTypeAttachments=Os,i.addAssetTypeFieldValues=Ms,i.addAssetTypeFieldValuesAttachment=km,i.addAssetTypeFieldValuesAttachments=it,i.addAssetTypeFieldValuesMany=Uc,i.addAssetTypeFields=Pc,i.addAssetTypeFieldsAttachment=gm,i.addAssetTypeFieldsAttachments=fc,i.addAssetTypeFieldsMany=Om,i.addAssetTypes=Wm,i.addAssets=us,i.addCategory=Ls,i.addConversation=Ln,i.addDocumentAttachment=np,i.addDocumentAttachments=ir,i.addDocuments=pr,i.addEmailDomain=Tr,i.addForm=si,i.addFormRevision=xs,i.addFormRevisionAttachment=pp,i.addFormRevisionAttachments=qr,i.addFormRevisions=$r,i.addFormSubmission=ri,i.addFormSubmissionAttachment=vp,i.addFormSubmissionAttachments=dt,i.addFormSubmissions=lt,i.addForms=Rp,i.addGeoImage=hd,i.addGeoImages=md,i.addIssue=qi,i.addIssueAssociation=yi,i.addIssueAssociations=fi,i.addIssueAttachment=$p,i.addIssueAttachments=Ii,i.addIssueComment=_i,i.addIssueCommentAttachment=Lp,i.addIssueCommentAttachments=Dd,i.addIssueComments=Kp,i.addIssueType=$u,i.addIssueTypeAttachment=Qp,i.addIssueTypeAttachments=iu,i.addIssueTypeFieldValues=Ui,i.addIssueTypeFieldValuesAttachment=FA,i.addIssueTypeFieldValuesAttachments=At,i.addIssueTypeFieldValuesMany=dA,i.addIssueTypeFields=Ou,i.addIssueTypeFieldsAttachment=tA,i.addIssueTypeFieldsAttachments=pu,i.addIssueTypeFieldsMany=pA,i.addIssueUpdate=Ku,i.addIssueUpdates=Yu,i.addIssues=Zd,i.addLicenses=MA,i.addOrganization=hy,i.addOrganizations=ly,i.addProject=iy,i.addProjectAttachment=Py,i.addProjectAttachments=Ho,i.addProjectFile=wy,i.addProjectFiles=il,i.addProjects=sy,i.addTeam=Al,i.addUser=$A,i.addUsers=UA,i.agentsReducer=Wn,i.agentsSlice=kt,i.areArraysEqual=xl,i.assetAttachmentReducer=ta,i.assetAttachmentSlice=zt,i.assetProcedureFieldValuesAttachmentReducer=Fa,i.assetProcedureFieldValuesAttachmentSlice=Lt,i.assetProcedureFieldValuesReducer=Ea,i.assetProcedureFieldValuesSlice=Ht,i.assetProcedureFieldsAttachmentReducer=ua,i.assetProcedureFieldsAttachmentSlice=$t,i.assetProcedureFieldsReducer=ya,i.assetProcedureFieldsSlice=Bt,i.assetProcedureInstanceReducer=za,i.assetProcedureInstanceSlice=Xt,i.assetProcedureReducer=$a,i.assetProcedureSlice=ss,i.assetReducer=Ha,i.assetSlice=rs,i.assetStageCompletionReducer=Xa,i.assetStageCompletionSlice=ps,i.assetStageReducer=sc,i.assetStageSlice=Ts,i.assetTypeAttachmentReducer=pc,i.assetTypeAttachmentSlice=Ps,i.assetTypeFieldValuesAttachmentReducer=zc,i.assetTypeFieldValuesAttachmentSlice=Es,i.assetTypeFieldValuesReducer=Lc,i.assetTypeFieldValuesSlice=qs,i.assetTypeFieldsAttachmentReducer=Ic,i.assetTypeFieldsAttachmentSlice=_s,i.assetTypeFieldsReducer=wc,i.assetTypeFieldsSlice=ws,i.assetTypeReducer=Wc,i.assetTypeSlice=Ds,i.authReducer=Jc,i.authSlice=at,i.blobToBase64=dh,i.categoryReducer=er,i.categorySlice=Gs,i.clearTokens=Zm,i.constructUploadedFilePayloads=rh,i.coordinatesAreEqual=Ql,i.createModelAdapter=b,i.createMultiPointGeometry=Xl,i.createOfflineAction=Do,i.createPayload=v,i.createPointGeometry=Jl,i.createSelectionAdapter=Yl,i.deleteAsset=os,i.deleteAssetAttachment=Xn,i.deleteAssetAttachments=Ut,i.deleteAssetProcedure=ns,i.deleteAssetProcedureFieldValues=Kt,i.deleteAssetProcedureFieldValuesAttachment=Bh,i.deleteAssetProcedureFieldValuesAttachments=xe,i.deleteAssetProcedureFieldValuesMany=_a,i.deleteAssetProcedureFields=pa,i.deleteAssetProcedureFieldsAttachment=Oh,i.deleteAssetProcedureFieldsAttachments=ca,i.deleteAssetProcedureFieldsMany=Mh,i.deleteAssetProcedureInstance=Zt,i.deleteAssetProcedureInstances=ka,i.deleteAssetProcedures=em,i.deleteAssetStage=mm,i.deleteAssetStageCompletion=fs,i.deleteAssetStageCompletions=Ss,i.deleteAssetStages=Fs,i.deleteAssetType=Us,i.deleteAssetTypeAttachment=uc,i.deleteAssetTypeAttachments=vs,i.deleteAssetTypeFieldValues=ks,i.deleteAssetTypeFieldValuesAttachment=Vm,i.deleteAssetTypeFieldValuesAttachments=nt,i.deleteAssetTypeFieldValuesMany=Bc,i.deleteAssetTypeFields=vc,i.deleteAssetTypeFieldsAttachment=Fm,i.deleteAssetTypeFieldsAttachments=gc,i.deleteAssetTypeFieldsMany=Em,i.deleteAssetTypes=Ym,i.deleteAssets=La,i.deleteCategory=xc,i.deleteDocumentAttachment=cr,i.deleteDocumentAttachments=rr,i.deleteEmailDomain=br,i.deleteForm=ii,i.deleteFormRevision=ei,i.deleteFormRevisionAttachment=Sp,i.deleteFormRevisionAttachments=kr,i.deleteFormRevisions=Br,i.deleteFormSubmission=di,i.deleteFormSubmissionAttachment=jp,i.deleteFormSubmissionAttachments=ut,i.deleteFormSubmissions=ht,i.deleteGeoImage=mi,i.deleteGeoImages=Ad,i.deleteIssue=Mi,i.deleteIssueAssociation=Si,i.deleteIssueAssociations=gi,i.deleteIssueAttachment=Ed,i.deleteIssueAttachments=Fi,i.deleteIssueComment=wi,i.deleteIssueCommentAttachment=$d,i.deleteIssueCommentAttachments=Bd,i.deleteIssueComments=Yp,i.deleteIssueTypeAttachment=cu,i.deleteIssueTypeAttachments=ru,i.deleteIssueTypeFieldValues=$i,i.deleteIssueTypeFieldValuesAttachment=vA,i.deleteIssueTypeFieldValuesAttachments=yt,i.deleteIssueTypeFieldValuesMany=hA,i.deleteIssueTypeFields=_u,i.deleteIssueTypeFieldsAttachment=aA,i.deleteIssueTypeFieldsAttachments=yu,i.deleteIssueTypeFieldsMany=SA,i.deleteIssueUpdate=Ju,i.deleteIssueUpdates=Xu,i.deleteIssues=xd,i.deleteOrganization=Ay,i.deleteOrganizationAccess=ho,i.deleteOrganizations=yy,i.deleteProject=Po,i.deleteProjectAccess=fo,i.deleteProjectAccesses=So,i.deleteProjectAttachment=Jo,i.deleteProjectAttachments=un,i.deleteProjectFile=nl,i.deleteProjectFiles=al,i.deleteProjects=ay,i.deleteTeam=An,i.deleteUser=LA,i.deleteUsers=NA,i.dequeue=ql,i.discard=bn,i.documentAttachmentReducer=lr,i.documentAttachmentSlice=Ws,i.documentSlice=Ks,i.documentsReducer=Sr,i.downloadFile=uh,i.downloadInMemoryFile=ch,i.emailDomainsReducer=Rr,i.emailDomainsSlice=Js,i.emailRegex=yh,i.enqueue=jl,i.enqueueRequest=Uo,i.fallbackToEmptyArray=g,i.fallbackToEmptyObject=ve,i.fileReducer=wr,i.fileSlice=Xs,i.fileToBlob=zn,i.formReducer=Kr,i.formRevisionAttachmentReducer=zr,i.formRevisionAttachmentSlice=Qs,i.formRevisionReducer=Nr,i.formRevisionsSlice=Zs,i.formSlice=ti,i.formSubmissionAttachmentReducer=td,i.formSubmissionAttachmentSlice=ni,i.formSubmissionReducer=dd,i.formSubmissionSlice=ci,i.geoImageReducer=Sd,i.geoImageSlice=hi,i.getFileIdentifier=ah,i.getFileS3Key=Mt,i.getLocalDateString=kn,i.getLocalRelativeDateString=ih,i.getOutboxCoordinator=Fe,i.getRenamedFile=Cn,i.hashFile=_e,i.initSDK=mS,i.initializeAssetAttachments=Dt,i.initializeAssetProcedureFieldValues=Pa,i.initializeAssetProcedureFieldValuesAttachments=Sa,i.initializeAssetProcedureFields=la,i.initializeAssetProcedureFieldsAttachments=ia,i.initializeAssetProcedureInstances=qa,i.initializeAssetProcedures=Va,i.initializeAssetStageCompletions=Ka,i.initializeAssetStages=ec,i.initializeAssetTypeAttachments=cc,i.initializeAssetTypeFieldValues=Vc,i.initializeAssetTypeFieldValuesAttachments=jc,i.initializeAssetTypeFields=Rc,i.initializeAssetTypeFieldsAttachments=yc,i.initializeAssetTypes=Hc,i.initializeAssets=Ga,i.initializeCategories=Qc,i.initializeConversations=Gn,i.initializeDocumentAttachments=sr,i.initializeEmailDomains=gr,i.initializeFormRevisionAttachments=jr,i.initializeFormRevisions=Ur,i.initializeFormSubmissionAttachments=Qr,i.initializeFormSubmissions=id,i.initializeForms=Wr,i.initializeGeoImages=od,i.initializeIssueAssociations=Td,i.initializeIssueAttachments=bi,i.initializeIssueCommentAttachments=Pi,i.initializeIssueTypeAttachments=zi,i.initializeIssueTypeFieldValues=bu,i.initializeIssueTypeFieldValuesAttachments=qu,i.initializeIssueTypeFields=Pu,i.initializeIssueTypeFieldsAttachments=mu,i.initializeIssueTypes=Uu,i.initializeIssueUpdates=Wu,i.initializeIssues=Qd,i.initializeLicences=to,i.initializeOrganizationAccesses=oo,i.initializeOrganizations=uy,i.initializeProjectAccesses=sn,i.initializeProjectAttachments=No,i.initializeProjectFiles=sl,i.initializeProjects=ey,i.initializeTeams=pl,i.initializeUsers=ao,i.isToday=sh,i.issueAssociationReducer=Od,i.issueAssociationSlice=Ai,i.issueAttachmentReducer=Cd,i.issueAttachmentSlice=Ti,i.issueCommentAttachmentReducer=Hd,i.issueCommentAttachmentSlice=Ri,i.issueCommentReducer=Jd,i.issueCommentSlice=Oi,i.issueReducer=tu,i.issueSlice=ji,i.issueTypeAttachmentReducer=lu,i.issueTypeAttachmentSlice=Ci,i.issueTypeFieldValuesAttachmentReducer=Du,i.issueTypeFieldValuesAttachmentSlice=Ni,i.issueTypeFieldValuesReducer=Fu,i.issueTypeFieldValuesSlice=Vi,i.issueTypeFieldsAttachmentReducer=gu,i.issueTypeFieldsAttachmentSlice=Di,i.issueTypeFieldsReducer=Eu,i.issueTypeFieldsSlice=Li,i.issueTypeReducer=Nu,i.issueTypeSlice=Wi,i.issueUpdateReducer=xu,i.issueUpdateSlice=Xi,i.licenseReducer=io,i.licenseSlice=Qi,i.logOnlyOnce=oh,i.markAsDeleted=$o,i.markForDeletion=Ry,i.memoize=jt,i.moveDocument=Ar,i.offline=R,i.onlyUniqueHashes=Ah,i.onlyUniqueOfflineIds=$n,i.organizationAccessReducer=po,i.organizationAccessSlice=xi,i.organizationReducer=zo,i.organizationSlice=cn,i.outboxReducer=Go,i.outboxSlice=rn,i.overmapEnhancer=xy,i.overmapReducers=_l,i.overmapRootReducer=Yy,i.performRequest=Tn,i.projectAccessReducer=bo,i.projectAccessSlice=tn,i.projectAttachmentReducer=el,i.projectAttachmentSlice=dn,i.projectFileReducer=ll,i.projectFileSlice=on,i.projectReducer=vo,i.projectSlice=an,i.rehydratedReducer=hl,i.rehydratedSlice=hn,i.removeDocuments=Ys,i.removeIssueType=Ki,i.removeUser=co,i.resetProjectFileObjectUrls=jy,i.resetStore=El,i.restructureCreateSelectorWithArgs=S,i.saveActiveProjectFileBounds=dl,i.selectAccessToken=xm,i.selectActiveOrganizationAccess=XA,i.selectActiveProjectFileId=My,i.selectActiveStatusLicenses=CA,i.selectAllDocumentAttachments=ur,i.selectAllProjectAttachments=Qo,i.selectAncestorIdsOfDocument=up,i.selectAssetAttachmentById=xn,i.selectAssetAttachmentMapping=Qn,i.selectAssetAttachments=Zn,i.selectAssetById=ms,i.selectAssetProcedureById=cs,i.selectAssetProcedureFieldValues=Yt,i.selectAssetProcedureFieldValuesAttachmentById=Gh,i.selectAssetProcedureFieldValuesAttachments=Ta,i.selectAssetProcedureFieldValuesAttachmentsByIds=ba,i.selectAssetProcedureFieldValuesAttachmentsMapping=Nt,i.selectAssetProcedureFieldValuesById=Jt,i.selectAssetProcedureFieldValuesMapping=wa,i.selectAssetProcedureFieldValuesOfAsset=Hh,i.selectAssetProcedureFields=Gt,i.selectAssetProcedureFieldsAttachmentById=_h,i.selectAssetProcedureFieldsAttachments=da,i.selectAssetProcedureFieldsAttachmentsMapping=ra,i.selectAssetProcedureFieldsById=zh,i.selectAssetProcedureFieldsMapping=Aa,i.selectAssetProcedureFieldsOfAssetProcedure=kh,i.selectAssetProcedureInstanceById=ts,i.selectAssetProcedureInstances=es,i.selectAssetProcedureInstancesByIds=Qh,i.selectAssetProcedureInstancesMapping=xt,i.selectAssetProcedureInstancesOfAssetProcedure=Ca,i.selectAssetProcedureInstancesOfAssetType=Xh,i.selectAssetProcedures=Ua,i.selectAssetProceduresByIds=nm,i.selectAssetProceduresMapping=as,i.selectAssetProceduresOfOrganization=im,i.selectAssetStageById=ic,i.selectAssetStageCompletionById=Qa,i.selectAssetStageCompletionMapping=gs,i.selectAssetStageCompletions=om,i.selectAssetStageCompletionsByIds=Za,i.selectAssetStages=nc,i.selectAssetStagesByIds=Rs,i.selectAssetStagesMappingOfAssetProcedure=pm,i.selectAssetStagesOfAssetProcedure=Am,i.selectAssetTypeAttachmentById=hc,i.selectAssetTypeAttachmentMapping=oc,i.selectAssetTypeAttachments=lc,i.selectAssetTypeById=Bs,i.selectAssetTypeFieldValues=Cs,i.selectAssetTypeFieldValuesAttachmentById=Um,i.selectAssetTypeFieldValuesAttachments=Mc,i.selectAssetTypeFieldValuesAttachmentsByIds=kc,i.selectAssetTypeFieldValuesAttachmentsMapping=js,i.selectAssetTypeFieldValuesById=zs,i.selectAssetTypeFieldValuesMapping=Gc,i.selectAssetTypeFieldValuesOfAsset=Gm,i.selectAssetTypeFields=st,i.selectAssetTypeFieldsAttachmentById=Pm,i.selectAssetTypeFieldsAttachments=bc,i.selectAssetTypeFieldsAttachmentsMapping=Tc,i.selectAssetTypeFieldsById=Mm,i.selectAssetTypeFieldsMapping=_c,i.selectAssetTypeFieldsOfAssetType=jm,i.selectAssetTypeValuesOfAssetType=Lm,i.selectAssetTypes=Jm,i.selectAssetTypesByIds=Xm,i.selectAssetTypesMapping=$s,i.selectAssets=Na,i.selectAssetsByIds=dm,i.selectAssetsMapping=ls,i.selectAssetsOfAssetType=hs,i.selectAttachmentsOfAsset=ea,i.selectAttachmentsOfAssetProcedureFieldValues=Ia,i.selectAttachmentsOfAssetProcedureFields=vh,i.selectAttachmentsOfAssetType=mc,i.selectAttachmentsOfAssetTypeFieldValues=Cc,i.selectAttachmentsOfAssetTypeFields=Rm,i.selectAttachmentsOfDocument=rp,i.selectAttachmentsOfFormRevision=gp,i.selectAttachmentsOfFormSubmission=ed,i.selectAttachmentsOfIssue=Md,i.selectAttachmentsOfIssueComment=Wp,i.selectAttachmentsOfIssueType=eA,i.selectAttachmentsOfIssueTypeFieldValues=zu,i.selectAttachmentsOfIssueTypeFields=cA,i.selectAttachmentsOfProject=xo,i.selectCategories=tp,i.selectCategoriesByIds=sp,i.selectCategoryById=Hs,i.selectCategoryMapping=Ns,i.selectCommentsOfIssue=Jp,i.selectConversation=Sh,i.selectConversationMapping=Ct,i.selectConversations=fh,i.selectCurrentUser=gt,i.selectDeletedRequests=Iy,i.selectDocumentAttachmentById=or,i.selectDocumentAttachmentMapping=dr,i.selectDocumentById=fr,i.selectDocuments=yr,i.selectDocumentsByIds=dp,i.selectDocumentsMapping=we,i.selectEmailDomains=Fr,i.selectEmailDomainsAsMapping=Ir,i.selectEmailDomainsOfOrganization=hp,i.selectFieldValuesOfAssetProcedureInstance=Wh,i.selectFormById=Jr,i.selectFormMapping=Yr,i.selectFormRevisionAttachmentsMapping=Cr,i.selectFormRevisionById=bp,i.selectFormRevisionMapping=rt,i.selectFormRevisions=Gr,i.selectFormRevisionsOfForm=Lr,i.selectFormSubmissionAttachemntsByIds=xr,i.selectFormSubmissionAttachmentsMapping=ai,i.selectFormSubmissionById=li,i.selectFormSubmissions=oi,i.selectFormSubmissionsMapping=ui,i.selectFormSubmissionsOfAsset=rd,i.selectFormSubmissionsOfForm=ad,i.selectFormSubmissionsOfIssue=cd,i.selectForms=Op,i.selectGeoImageById=pi,i.selectGeoImageMapping=yd,i.selectGeoImages=fd,i.selectGeoImagesOfProject=Cp,i.selectIsImportingProjectFile=ky,i.selectIsLoggedIn=ep,i.selectIssueAssociationById=Id,i.selectIssueAssociationMapping=He,i.selectIssueAssociations=Up,i.selectIssueAssociationsOfAsset=Pd,i.selectIssueAssociationsOfIssue=Rd,i.selectIssueAssociationsToIssue=Fd,i.selectIssueAttachmentById=kd,i.selectIssueAttachmentMapping=jd,i.selectIssueAttachments=qd,i.selectIssueById=ki,i.selectIssueCommentAttachmentById=Nd,i.selectIssueCommentAttachmentMapping=Gd,i.selectIssueCommentAttachments=Ld,i.selectIssueCommentById=Ei,i.selectIssueCommentMapping=Yd,i.selectIssueCountOfCategory=ip,i.selectIssueMapping=eu,i.selectIssueTypeAttachmentById=ou,i.selectIssueTypeAttachmentMapping=du,i.selectIssueTypeAttachments=uu,i.selectIssueTypeById=Yi,i.selectIssueTypeFieldValues=Bi,i.selectIssueTypeFieldValuesAttachmentById=_A,i.selectIssueTypeFieldValuesAttachments=ku,i.selectIssueTypeFieldValuesAttachmentsByIds=Cu,i.selectIssueTypeFieldValuesAttachmentsMapping=Hi,i.selectIssueTypeFieldValuesById=Gi,i.selectIssueTypeFieldValuesMapping=Iu,i.selectIssueTypeFieldValuesOfIssue=mA,i.selectIssueTypeFields=pt,i.selectIssueTypeFieldsAttachmentById=rA,i.selectIssueTypeFieldsAttachments=Su,i.selectIssueTypeFieldsAttachmentsMapping=fu,i.selectIssueTypeFieldsById=IA,i.selectIssueTypeFieldsMapping=wu,i.selectIssueTypeFieldsOfIssueType=gA,i.selectIssueTypeMapping=Gu,i.selectIssueTypeValuesOfIssueType=bA,i.selectIssueTypes=Lu,i.selectIssueTypesByIds=wA,i.selectIssueTypesOfOrganization=EA,i.selectIssueUpdateMapping=Qu,i.selectIssueUpdatesOfIssue=Zu,i.selectIssuesByIds=Xp,i.selectIssuesOfIssueType=Ji,i.selectIssuesOfIssueTypeCount=jA,i.selectLatestAssetProcedureFieldsOfAssetProcedure=Ch,i.selectLatestAssetTypeFieldsOfAssetType=qm,i.selectLatestFormRevisionOfForm=Ip,i.selectLatestIssueTypeFieldsOfIssueType=TA,i.selectLatestRetryTime=Fy,i.selectLicense=kA,i.selectLicenseForProject=so,i.selectLicenses=St,i.selectLicensesForProjectsMapping=zA,i.selectLicensesOfOrganization=Ty,i.selectNumberOfAssetsOfAssetType=um,i.selectOrganizationAccessById=JA,i.selectOrganizationAccessForUser=QA,i.selectOrganizationAccessUserMapping=mo,i.selectOrganizationAccesses=en,i.selectOrganizationById=fy,i.selectOrganizationUsersAsMapping=Co,i.selectOrganizationUsersIds=ko,i.selectOrganizations=Mo,i.selectOrganizationsMapping=qo,i.selectOrganizationsWithAccess=Sy,i.selectProjectAccessById=ZA,i.selectProjectAccessForUser=xA,i.selectProjectAccessMapping=nn,i.selectProjectAccessUserMapping=To,i.selectProjectAccesses=go,i.selectProjectAttachmentById=Zo,i.selectProjectAttachmentMapping=Xo,i.selectProjectById=ry,i.selectProjectFileById=qy,i.selectProjectFileMapping=ul,i.selectProjectFiles=ol,i.selectProjectMapping=It,i.selectProjectUsersAsMapping=wo,i.selectProjectUsersIds=_o,i.selectProjects=cy,i.selectProjectsOfOrganization=gy,i.selectRehydrated=Dy,i.selectRootDocuments=op,i.selectSortedOrganizationUsers=by,i.selectSortedProjectUsers=dy,i.selectStageMapping=tt,i.selectTeamById=Me,i.selectTeams=fn,i.selectTeamsByIds=Vy,i.selectTeamsMapping=yn,i.selectTeamsOfOrganization=Uy,i.selectTeamsOfUser=$y,i.selectUploadUrl=_r,i.selectUserById=KA,i.selectUsersByIds=YA,i.selectUsersMapping=Tt,i.setActiveProjectFileId=rl,i.setAsset=cm,i.setAssetAttachment=Yn,i.setAssetAttachments=Th,i.setAssetProcedure=tm,i.setAssetProcedureFieldValues=Lh,i.setAssetProcedureFieldValuesAttachment=Vh,i.setAssetProcedureFieldValuesAttachments=Uh,i.setAssetProcedureFieldValuesMany=Nh,i.setAssetProcedureFields=Eh,i.setAssetProcedureFieldsAttachment=Fh,i.setAssetProcedureFieldsAttachments=Rh,i.setAssetProcedureFieldsMany=jh,i.setAssetProcedureInstance=Yh,i.setAssetProcedureInstances=Jh,i.setAssetProcedures=sm,i.setAssetStage=tc,i.setAssetStages=lm,i.setAssetType=Nm,i.setAssetTypeAttachment=rc,i.setAssetTypeAttachments=fm,i.setAssetTypeFieldValues=$m,i.setAssetTypeFieldValuesAttachment=Cm,i.setAssetTypeFieldValuesAttachments=zm,i.setAssetTypeFieldValuesMany=Bm,i.setAssetTypeFields=vm,i.setAssetTypeFieldsAttachment=Tm,i.setAssetTypeFieldsAttachments=bm,i.setAssetTypeFieldsMany=_m,i.setAssetTypes=Hm,i.setAssets=rm,i.setConversation=Nn,i.setCurrentUser=HA,i.setDocumentAttachment=nr,i.setDocumentAttachments=ap,i.setDocuments=mr,i.setForm=Fp,i.setFormRevision=Vr,i.setFormRevisionAttachment=Ap,i.setFormRevisionAttachments=yp,i.setFormSubmission=ot,i.setFormSubmissionAttachment=_p,i.setFormSubmissionAttachments=wp,i.setFormSubmissions=qp,i.setGeoImage=Ne,i.setGeoImages=ld,i.setIsImportingProjectFile=cl,i.setIssueAssociation=Dp,i.setIssueAssociations=zp,i.setIssueAttachment=_d,i.setIssueAttachments=Bp,i.setIssueComment=vi,i.setIssueCommentAttachment=Vd,i.setIssueCommentAttachments=Np,i.setIssueComments=Kd,i.setIssueType=Ke,i.setIssueTypeAttachment=nu,i.setIssueTypeAttachments=Zp,i.setIssueTypeFieldValues=uA,i.setIssueTypeFieldValuesAttachment=RA,i.setIssueTypeFieldValuesAttachments=PA,i.setIssueTypeFieldValuesMany=oA,i.setIssueTypeFields=AA,i.setIssueTypeFieldsAttachment=sA,i.setIssueTypeFieldsAttachments=iA,i.setIssueTypeFieldsMany=yA,i.setIssueUpdate=qA,i.setLoggedIn=Yc,i.setOrganization=oy,i.setOrganizations=jo,i.setProfilePicture=WA,i.setProject=ty,i.setProjectAttachment=Wo,i.setProjectAttachments=Ko,i.setProjectFile=vy,i.setProjectFiles=_y,i.setProjects=Fo,i.setRehydrated=zy,i.setTeam=qe,i.setTokens=Qm,i.setUploadUrl=vr,i.setUser=VA,i.setUsers=DA,i.shallowEqual=Zl,i.slugify=mh,i.spacesToDashesLower=hh,i.teamReducer=yl,i.teamSlice=mn,i.toFileNameSafeString=lh,i.toOfflineIdRecord=Un,i.truncate=ph,i.updateAsset=$e,i.updateAssetAttachment=bh,i.updateAssetAttachments=Jn,i.updateAssetProcedure=Ue,i.updateAssetProcedureFieldValues=De,i.updateAssetProcedureFieldValuesAttachment=$h,i.updateAssetProcedureFieldValuesAttachments=ga,i.updateAssetProcedureFieldValuesMany=va,i.updateAssetProcedureFields=ma,i.updateAssetProcedureFieldsAttachment=Ph,i.updateAssetProcedureFieldsAttachments=aa,i.updateAssetProcedureFieldsMany=qh,i.updateAssetProcedureInstance=Ve,i.updateAssetProcedureInstances=Kh,i.updateAssetProcedures=xh,i.updateAssetStage=Is,i.updateAssetStageCompletion=Ya,i.updateAssetStageCompletions=Ja,i.updateAssetStages=et,i.updateAssetType=Ge,i.updateAssetTypeAttachment=Sm,i.updateAssetTypeAttachments=dc,i.updateAssetTypeFieldValues=Be,i.updateAssetTypeFieldValuesAttachment=Dm,i.updateAssetTypeFieldValuesAttachments=qc,i.updateAssetTypeFieldValuesMany=$c,i.updateAssetTypeFields=Oc,i.updateAssetTypeFieldsAttachment=Im,i.updateAssetTypeFieldsAttachments=Sc,i.updateAssetTypeFieldsMany=wm,i.updateAssetTypes=Km,i.updateAssets=am,i.updateCategory=Zc,i.updateConversation=Hn,i.updateDocumentAttachment=cp,i.updateDocumentAttachments=ar,i.updateDocuments=ye,i.updateForm=Pp,i.updateFormRevisionAttachment=fp,i.updateFormRevisionAttachments=Mr,i.updateFormSubmission=nd,i.updateFormSubmissionAttachment=Ep,i.updateFormSubmissionAttachments=Zr,i.updateFormSubmissions=Mp,i.updateGeoImage=pd,i.updateGeoImages=kp,i.updateIssue=mt,i.updateIssueAssociation=bd,i.updateIssueAssociations=Vp,i.updateIssueAttachment=Gp,i.updateIssueAttachments=wd,i.updateIssueCommentAttachment=Hp,i.updateIssueCommentAttachments=Ud,i.updateIssueType=Bu,i.updateIssueTypeAttachment=xp,i.updateIssueTypeAttachments=au,i.updateIssueTypeFieldValues=We,i.updateIssueTypeFieldValuesAttachment=OA,i.updateIssueTypeFieldValuesAttachments=Mu,i.updateIssueTypeFieldValuesMany=lA,i.updateIssueTypeFields=vu,i.updateIssueTypeFieldsAttachment=nA,i.updateIssueTypeFieldsAttachments=Au,i.updateIssueTypeFieldsMany=fA,i.updateLicense=pe,i.updateOrganization=py,i.updateOrganizationAccess=lo,i.updateOrganizations=my,i.updateProject=Ro,i.updateProjectAccess=yo,i.updateProjectAttachment=Oy,i.updateProjectAttachments=Yo,i.updateProjectFile=ln,i.updateProjectFiles=Ey,i.updateProjects=ny,i.updateTeam=pn,i.updateUser=GA,i.updateUsers=BA,i.userReducer=ro,i.userSlice=Zi,i.versioningReducer=Sl,i.versioningSlice=fl,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
@@ -1,4 +1,4 @@
1
- import { FieldValue } from '@overmap-ai/forms';
1
+ import { SerializedFieldValues } from '@overmap-ai/forms';
2
2
  import { Asset, AssetProcedureFields, AssetProcedureFieldValues, AssetProcedureInstance, Created, OvermapRootState, Payload, Project, Stored, UUID } from '../../typings';
3
3
  import { BaseSDK } from '../base';
4
4
  import { OptimisticModelResult } from '../typings';
@@ -6,9 +6,9 @@ import { BaseApiService } from './BaseApiService';
6
6
  export declare abstract class AssetProcedureFieldValuesService<TState extends OvermapRootState, TSDK extends BaseSDK<TState>> extends BaseApiService<TState, TSDK> {
7
7
  add(payload: Payload<AssetProcedureFieldValues>): OptimisticModelResult<AssetProcedureFieldValues>;
8
8
  bulkAdd(payload: {
9
- values: Record<string, FieldValue>;
9
+ values: SerializedFieldValues;
10
10
  payloads: {
11
- values: Record<string, FieldValue>;
11
+ values: SerializedFieldValues;
12
12
  asset: Asset["uuid"];
13
13
  fields_revision: AssetProcedureFields["uuid"];
14
14
  asset_procedure_instance: AssetProcedureInstance["uuid"];
@@ -1,4 +1,4 @@
1
- import { FieldValue } from '@overmap-ai/forms';
1
+ import { SerializedFieldValues } from '@overmap-ai/forms';
2
2
  import { Asset, AssetTypeFields, AssetTypeFieldValues, Created, OvermapRootState, Payload, Project, Stored, UUID } from '../../typings';
3
3
  import { BaseSDK } from '../base';
4
4
  import { OptimisticModelResult } from '../typings';
@@ -6,9 +6,9 @@ import { BaseApiService } from './BaseApiService';
6
6
  export declare abstract class AssetTypeFieldValuesService<TState extends OvermapRootState, TSDK extends BaseSDK<TState>> extends BaseApiService<TState, TSDK> {
7
7
  add(payload: Payload<AssetTypeFieldValues>): OptimisticModelResult<AssetTypeFieldValues>;
8
8
  bulkAdd(payload: {
9
- values: Record<string, FieldValue>;
9
+ values: SerializedFieldValues;
10
10
  payloads: {
11
- values: Record<string, FieldValue>;
11
+ values: SerializedFieldValues;
12
12
  asset: Asset["uuid"];
13
13
  fields_revision: AssetTypeFields["uuid"];
14
14
  published_at: string;
@@ -2,7 +2,7 @@ import { EmailDomain, Organization, OvermapRootState } from '../../typings';
2
2
  import { BaseSDK } from '../base';
3
3
  import { BaseApiService } from './BaseApiService';
4
4
  export declare abstract class EmailDomainsService<TState extends OvermapRootState, TSDK extends BaseSDK<TState>> extends BaseApiService<TState, TSDK> {
5
- add(orgUuid: Organization["uuid"], email: string): Promise<undefined>;
5
+ add(organizationUuid: Organization["uuid"], email: string): Promise<undefined>;
6
6
  remove(emailDomain: EmailDomain): Promise<undefined>;
7
7
  refreshStore(organizationUuid: Organization["uuid"]): Promise<undefined>;
8
8
  }
@@ -1,9 +1,6 @@
1
1
  import { Organization, OrganizationAccess, OvermapRootState } from '../../typings';
2
2
  import { BaseSDK } from '../base';
3
3
  import { BaseApiService } from './BaseApiService';
4
- /**
5
- * Handles the creation of OrganizationAccess Service
6
- */
7
4
  export declare abstract class OrganizationAccessService<TState extends OvermapRootState, TSDK extends BaseSDK<TState>> extends BaseApiService<TState, TSDK> {
8
5
  update(organizationAccess: OrganizationAccess): Promise<OrganizationAccess>;
9
6
  remove(organizationAccess: OrganizationAccess): Promise<undefined>;
@@ -1,9 +1,6 @@
1
1
  import { OvermapRootState, Project, ProjectAccess } from '../../typings';
2
2
  import { BaseSDK } from '../base';
3
3
  import { BaseApiService } from './BaseApiService';
4
- /**
5
- * Handles the creation of ProjectAccess Service
6
- */
7
4
  export declare abstract class ProjectAccessService<TState extends OvermapRootState, TSDK extends BaseSDK<TState>> extends BaseApiService<TState, TSDK> {
8
5
  update(projectAccess: ProjectAccess): Promise<ProjectAccess>;
9
6
  remove(uuid: ProjectAccess["uuid"]): Promise<undefined>;
@@ -1,4 +1,4 @@
1
- import { FieldValue, SerializedFieldSection } from '@overmap-ai/forms';
1
+ import { SerializedFieldSection, SerializedFieldValues } from '@overmap-ai/forms';
2
2
  import { FileWithNameModel } from '../files';
3
3
  export interface FieldsModel {
4
4
  fields: SerializedFieldSection[];
@@ -6,7 +6,7 @@ export interface FieldsModel {
6
6
  }
7
7
  export interface FieldValuesModel {
8
8
  published_at?: string | null;
9
- values: Record<string, FieldValue>;
9
+ values: SerializedFieldValues;
10
10
  }
11
11
  export interface FieldsAttachmentModel extends FileWithNameModel {
12
12
  field_identifier: string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core functionality for Overmap",
4
4
  "author": "Wôrdn Inc.",
5
5
  "license": "UNLICENSED",
6
- "version": "1.0.74-form-changes.0",
6
+ "version": "1.0.74-form-changes.2",
7
7
  "type": "module",
8
8
  "main": "dist/overmap-core.umd.cjs",
9
9
  "module": "dist/overmap-core.js",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@overmap-ai/blocks": "1.0.40-alpha.1",
39
- "@overmap-ai/forms": "1.0.32-react-flow-david-fixes.2",
39
+ "@overmap-ai/forms": "1.0.32-react-flow-david-fixes.6",
40
40
  "@rollup/plugin-commonjs": "^28.0.6",
41
41
  "@tiptap/core": "^3.0.7",
42
42
  "@types/add": "^2",
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "peerDependencies": {
80
80
  "@overmap-ai/blocks": "1.0.40-alpha.1",
81
- "@overmap-ai/forms": "1.0.32-react-flow-david-fixes.2",
81
+ "@overmap-ai/forms": "1.0.32-react-flow-david-fixes.6",
82
82
  "@tiptap/core": "^2.4.0",
83
83
  "react": ">=18.2.0 <20.0.0",
84
84
  "react-dom": ">=18.2.0 <20.0.0"