@overmap-ai/core 1.0.80-clean-ups.0 → 1.0.80-presigned-get-improvements.0

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.
@@ -4143,6 +4143,12 @@ class V extends k {
4143
4143
  super(...arguments);
4144
4144
  u(this, "pageSize", cb);
4145
4145
  }
4146
+ async getFileUrl(e, i) {
4147
+ const n = await this.get(e, i);
4148
+ if (!n.file_url)
4149
+ throw new Error(`Unable to obtain file_url for ${this.name}: ${e}`);
4150
+ return n.file_url;
4151
+ }
4146
4152
  async add(e) {
4147
4153
  const { addOne: i, updateOne: n, deleteOne: a } = this.actions;
4148
4154
  let r, d = null, c = null;
@@ -4,7 +4,7 @@ Retries:`,e),!(t instanceof Error))throw console.error("ENCOUNTERED NON-ERROR ER
4
4
  Action:`,s);const f=ft();if(!f)throw new Error("Outbox coordinator not set");f.remove(s.payload.uuid),t.options.discard=!0,u()}}console.debug("Registering a retry for request:",s.payload.uuid);const d=ft();if(!d)throw new Error("Outbox coordinator not set");return d.registerRetry(s.payload.uuid),!1}function $g(t,s,e){var n;return(n=ft())==null?void 0:n.peek()}function Ug(t,s){return gt().dispatch(zf(new Date().getTime())),Sc}const bt="An unknown error occurred",Lg=500,kF=["non_field_errors","detail"];function kg(t,s){let e;if(t!=null&&t.body)if(typeof t.body=="object"){const n=t.body;if(typeof n.error=="string")e=n.error;else if(typeof n.message=="string")e=n.message;else try{e=Object.entries(n).map(([c,r])=>typeof r=="string"?kF.includes(c)?r:`${c}: ${r}`:Array.isArray(r)?kF.includes(c)?r.join(`
5
5
  `):r.map(a=>`${c}: ${a}`).join(`
6
6
  `):`${c}: ${JSON.stringify(r)}`).join(`
7
- `)}catch(c){console.error("Failed to extract error message from response body",c)}}else typeof t.body=="string"&&(e=t.body);else t!=null&&t.text?e=t.text:s instanceof Error&&(e=s.message);return!e||e.length>Lg?bt:e}class U extends Error{constructor(e){super(bt);h(this,"status");h(this,"response");h(this,"message");h(this,"options");const{response:n,innerError:c}=e;this.message=e.message??kg(n,c)??bt,this.status=(n==null?void 0:n.status)??0,this.response=n,e.discard=e.discard??!1,this.options=e}}function NF(t){function s(e){return typeof e=="object"&&e!==null&&["ok","redirect","clientError","serverError","error"].every(c=>c in e)}if(s(t))return t;if(typeof t=="object"&&t!==null){const e=t;if(s(e.response))return e.response;if(e.response&&s(e.response.response))return e.response.response}}class Ng extends qF{constructor(s){super(s)}}class pt extends qF{constructor(e,n){super(e);h(this,"auth");this.auth=n}}class Gg extends pt{async startConversation(s,e){return this.enqueueRequest({description:"Start agent conversation",method:o.POST,url:"/agents/prompt/",payload:{prompt:s,active_project:e},blockers:["prompt"],blocks:["prompt"]}).then(n=>(this.dispatch(Cc(n)),n))}async continueConversation(s,e,n){return this.enqueueRequest({description:"Prompt agent",method:o.POST,url:"/agents/prompt/",payload:{prompt:s,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:e}}).then(c=>{this.dispatch(Uc(c))})}async fetchDetails(s){return this.enqueueRequest({description:"Get agent conversation",method:o.GET,url:`/agents/conversations/${s}/`,blockers:["conversation"],blocks:["conversation"]}).then(e=>{this.dispatch($c(e))})}async rate(s,e){return this.enqueueRequest({description:"Rate agent response",method:o.PUT,url:`/agents/responses/${s}/rate/`,payload:{rating:e},blockers:["rate"],blocks:["rate"]})}async list(s,e){return this.performRequest({method:o.GET,url:"/agents/conversations/",...s},e)}async refreshStore(s,e){const n=await this.list({queryParams:{project:s}},e);return this.dispatch(qc(n)),n}}function rt(t,s){const e=[];let n=0;const c=t.length;for(;n<c;)e.push(t.slice(n,n+=s));return e}function A(t,s,e){const n=`${s}${e?"s":""}`;switch(t){case o.GET:return`Get ${n}`;case o.POST:return`Create ${n}`;case o.PATCH:return`Update ${n}`;case o.PUT:return`Update ${n}`;case o.DELETE:return`Delete ${n}`}}function M(t){const s={...t};for(const e of[...Ac,"created_by"])e in s&&delete s[e];return s}class E extends pt{async get(s,e){return this.performRequest({url:`${this.url}/${s}/`,method:o.GET},e)}async list(s,e){return this.performRequest({url:`${this.url}/`,method:o.GET,...s},e)}async listPaginated(s,e){return this.performPagination({url:`${this.url}/`,method:o.GET,...s},e)}}class j extends E{constructor(){super(...arguments);h(this,"pageSize",DF)}async add(e){const{addOne:n,updateOne:c,deleteOne:r}=this.actions;let a,u=null,d=null;if("file"in e){const{file:b,...g}=e;u=await this.client.files.getFilePayload(b),d=URL.createObjectURL(b),a={...g,file_sha1:u.sha1,file_type:u.file_type,file_name:b.name,file_extension:u.extension,file_url:d}}else a=e;const p=this.buildModel(a),m=this.buildPayload(p);this.dispatch(n(p));const f=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:{...m,...u?{file:u}:{}},blockers:this.getBlockers(p),blocks:this.getBlocks(p)});f.then(({instance:b})=>{this.dispatch(c(b))}).catch(b=>{throw this.dispatch(r(this.getId(p))),b}).finally(()=>{d&&URL.revokeObjectURL(d)});const I=f.then(({instance:b})=>b),R=f.then(async({instance:b,presigned_url:g})=>{try{return g&&await this.client.files.processPresignedUrl(b.file_sha1,g),b.file_sha1}catch(_){throw console.error("Upload to s3 using presigned url failed.",_),_}});return[p,I,R]}async bulkAdd(e,n){const{addMany:c,updateMany:r,deleteMany:a}=this.actions,u=new Date().toISOString(),d=[],p=new Set,m=rt(e,Math.min(n??e.length,N)),f=[];for(const g of m){const _=[],v={},B=[],C=[];for(const z of g){let Mt;if("file"in z){const{file:hc,...yR}=z,Rt=await this.client.files.getFilePayload(hc);Rt.sha1 in v||(v[Rt.sha1]=Rt);const tb=URL.createObjectURL(hc);p.add(tb),Mt={...yR,file_sha1:Rt.sha1,file_type:Rt.file_type,file_name:hc.name,file_extension:Rt.extension,file_url:tb}}else Mt=z;const q=this.buildModel(Mt);d.push(q);const G=this.buildBulkPayload(q);_.push(G);const ds=this.getBlockers(q);B.push(...ds);const pR=this.getBlocks(q);C.push(...pR)}const D={payloads:_,submittedAt:u,files:Object.values(v),blockers:B,blocks:C};f.push(D)}this.dispatch(c(d));const I=f.map(g=>{const{submittedAt:_,files:v,payloads:B,blocks:C,blockers:D}=g;return this.enqueueRequest({description:A(o.POST,this.name,!0),method:o.POST,url:`${this.url}/bulk/`,payload:{submitted_at:_,files:v,payloads:B},blockers:D,blocks:C})});Promise.all(I).then(g=>{const _=g.flatMap(v=>v.instances);this.dispatch(r(_))}).catch(g=>{throw this.dispatch(a(d.map(_=>this.getId(_)))),console.error(g),g}).finally(()=>{for(const g of p)URL.revokeObjectURL(g)});const R=Promise.all(I).then(g=>g.flatMap(({instances:_})=>_)),b=Promise.all(I).then(async g=>{const _=[];for(const{presigned_urls:v}of g){const B=this.client.files.processPresignedUrls(v);for(const[C,D]of Object.entries(B))try{await D,_.push(C)}catch(z){throw console.error("Upload to s3 using presigned url failed.",z),z}}return _});return[d,R,b]}async delete(e){const{addOne:n,deleteOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Attempting to delete ${this.name} with pk ${e} that does not exist in the store`);this.dispatch(c(this.getId(a)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(n(a)),u}}}class Hg extends j{constructor(){super(...arguments);h(this,"name","Asset attachment");h(this,"url","/asset-attachments");h(this,"actions",{addOne:Gc,addMany:As,setOne:Hc,setMany:Wc,updateOne:Kc,updateMany:Yc,deleteOne:Zc,deleteMany:Is,initialize:Nc});h(this,"selectors",{selectById:Xc,selectByIds:Qc})}getId(e){return e.uuid}getBlockers(e){const{asset:n}=e;return[n]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset:e.asset}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset:e.asset}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{asset__project:e}},n)).flat();return this.dispatch(c(a)),a}}class Wg extends E{constructor(){super(...arguments);h(this,"name","Asset Comment");h(this,"url","/asset-comments");h(this,"actions",{addOne:ia,addMany:$t,setOne:na,setMany:ca,updateOne:aa,updateMany:ra,deleteOne:da,deleteMany:Ut,initialize:sa});h(this,"selectors",{selectById:la,selectByIds:oa})}add(e){const{addOne:n,updateOne:c,deleteOne:r}=this.actions,a=O({...e,created_by:this.select(d=>{var p;return((p=d.userReducer.currentUser)==null?void 0:p.id)??null}),submitted_at:new Date().toISOString()});this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(a),blockers:[a.asset],blocks:[a.uuid]});return u.then(d=>{this.dispatch(c(d))}).catch(()=>{this.dispatch(r(a.uuid))}),[a,u]}update(e){const{updateOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Asset comment with uuid ${e.uuid} not found in store`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Asset comment with uuid ${e} not found in store`);this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{asset__project:e}},n)).flat();return this.dispatch(c(a)),a}}class Kg extends E{constructor(){super(...arguments);h(this,"url","/assets");h(this,"name","Asset");h(this,"actions",{addOne:Sa,addMany:Fs,setOne:Oa,setMany:Pa,updateOne:Aa,updateMany:Ia,deleteOne:Ta,deleteMany:bs,initialize:fa});h(this,"selectors",{selectById:_a,selectByIds:ga})}add(e){const{addOne:n,updateOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[d.asset_type],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}update(e){const{updateOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{addOne:n,deleteOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`No asset with uuid ${e} found in the store`);const u=this.select(xc(e)),d=this.select(ha(e)),p=this.select(sh(e)),m=this.select(_A(e)),f=this.select(go(e));this.dispatch(c(e)),this.dispatch(Is(w(u))),this.dispatch(Ut(w(d))),this.dispatch(Tt(w(p))),this.dispatch(Ft(w(m))),this.dispatch(lt(w(f)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(I){throw this.dispatch(n(a)),this.dispatch(As(u)),this.dispatch($t(d)),this.dispatch(It(p)),this.dispatch(Pt(m)),this.dispatch(ut(f)),I}}bulkAdd(e,n){const{addMany:c}=this.actions,r=new Date().toISOString(),a=rt(e,Math.min(n??e.length,N)).map(p=>{const m=p.map(f=>O(f));return{batchId:dt.v4(),payload:{submitted_at:r,assets:m}}}),u=[];let d=null;for(const p of a){const{batchId:m,payload:f}=p,I=f.assets.map(({uuid:v})=>v),R=f.assets.map(({asset_type:v})=>v),b=f.assets.map(({project:v})=>v),g=f.assets.map(({status:v})=>v),_=this.enqueueRequest({description:A(o.POST,this.name,!0),method:o.POST,url:`${this.url}/bulk/`,payload:f,blockers:(d?[d]:[]).concat(R).concat(b).concat(g),blocks:[m].concat(I)});d=p.batchId,u.push(_)}return Promise.all(u).then(p=>{const m=p.flat();this.dispatch(c(m))}),u}bulkUpdate(e,n){const{updateMany:c}=this.actions,{selectByIds:r}=this.selectors,a=w(e).toSorted(Ct);if(a.length!==e.length)throw new Error("payloads contains duplicate uuids.");const u=this.select(r(a)).toSorted(ps);if(a.length!=u.length)throw new Error(`Attempting to bulk update ${a.length-u.length} assets that dont exist in the store`);const d=[];for(let I=0;I<a.length;I++)d.push({...u[I],...e[I]});this.dispatch(c(d));const p=rt(e,Math.min(n??e.length,N)),m=[];let f=null;for(const I of p){const R=dt.v4(),b=w(I),g=I.map(({status:v})=>v).filter(Boolean),_=this.enqueueRequest({description:A(o.PATCH,this.name,!0),method:o.PATCH,url:`${this.url}/bulk/`,payload:{payloads:I},blockers:(f?[f]:[]).concat(b).concat(g),blocks:[R].concat(b)});m.push(_),f=R}return Promise.all(m).then(I=>{this.dispatch(c(I.flat()))}).catch(()=>{this.dispatch(c(u))}),[d,m]}async bulkDelete(e){const{addMany:n,deleteMany:c}=this.actions,{selectByIds:r}=this.selectors,a=this.select(r(e)),u=this.select(ma(e)),d=this.select(ih(e)),p=this.select(gA(e)),m=this.select(Mo(e));this.dispatch(c(e)),this.dispatch(Ut(w(u))),this.dispatch(Tt(w(d))),this.dispatch(Ft(w(p))),this.dispatch(lt(w(m)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!0),method:o.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(f){throw this.dispatch(n(a)),this.dispatch($t(u)),this.dispatch(It(d)),this.dispatch(Pt(p)),this.dispatch(ut(m)),f}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{project:e}},n)).flat();return this.dispatch(c(a)),a}}class Yg extends j{constructor(){super(...arguments);h(this,"name","Asset Type Attachment");h(this,"url","/asset-type-attachments");h(this,"actions",{addOne:va,addMany:gs,setOne:Ea,setMany:Ba,updateOne:Va,updateMany:za,deleteOne:Da,deleteMany:Ms,initialize:wa});h(this,"selectors",{selectById:qa,selectByIds:Ca})}getId(e){return e.uuid}getBlockers(e){return[e.asset_type]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_type:e.asset_type}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_type:e.asset_type}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class Zg extends j{constructor(){super(...arguments);h(this,"name","Asset Type Fields Attachment");h(this,"url","/asset-type-fields-attachments");h(this,"actions",{addOne:Na,addMany:Ga,setOne:Ha,setMany:Wa,updateOne:Ka,updateMany:Ya,deleteOne:Za,deleteMany:Ja,initialize:ka});h(this,"selectors",{selectById:Qa,selectByIds:xa})}getId(e){return e.uuid}getBlockers(e){return[e.fields_revision]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:c,fields_revision:r,file_sha1:a,file_name:u,file_extension:d}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:c,fields_revision:r,file_sha1:a,file_name:u,file_extension:d}}buildBulkPayload(e){const{uuid:n,field_identifier:c,fields_revision:r,file_sha1:a,file_name:u,file_extension:d}=e;return{uuid:n,field_identifier:c,fields_revision:r,file_sha1:a,file_name:u,file_extension:d}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{fields_revision__asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class Jg extends E{constructor(){super(...arguments);h(this,"name","Asset Type Fields");h(this,"url","/asset-type-fields");h(this,"actions",{addOne:ir,addMany:nr,setOne:cr,setMany:ar,updateOne:rr,updateMany:dr,deleteOne:ur,deleteMany:lr,initialize:sr});h(this,"selectors",{selectById:hr,selectByIds:mr})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[d.asset_type],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(m=>{throw this.dispatch(r(d.uuid)),m}),[d,p]}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class Xg extends j{constructor(){super(...arguments);h(this,"name","Asset Type Field Values Attachment");h(this,"url","/asset-type-field-values-attachments");h(this,"actions",{addOne:Sr,addMany:Vs,setOne:Ar,setMany:Ir,updateOne:Tr,updateMany:Or,deleteOne:Pr,deleteMany:zs,initialize:fr});h(this,"selectors",{selectById:br,selectByIds:_r})}getId(e){return e.uuid}getBlockers(e){return[e.field_values]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:c,field_values:r,file_sha1:a,file_name:u,file_extension:d}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:c,field_values:r,file_sha1:a,file_name:u,file_extension:d}}buildBulkPayload(e){const{uuid:n,field_identifier:c,field_values:r,file_sha1:a,file_name:u,file_extension:d}=e;return{uuid:n,field_identifier:c,field_values:r,file_sha1:a,file_name:u,file_extension:d}}async bulkDelete(e){const{deleteMany:n,addMany:c}=this.actions,{selectByIds:r}=this.selectors,a=this.select(r(e));this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!0),method:o.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{field_values__asset__project:e,latest:!0}},n)).flat();return this.dispatch(c(a)),a}}class Qg extends E{constructor(){super(...arguments);h(this,"name","Asset Type Field Values");h(this,"url","/asset-type-field-values");h(this,"actions",{addOne:vr,addMany:Er,setOne:Br,setMany:Vr,updateOne:zr,updateMany:Dr,deleteOne:jr,deleteMany:qr,initialize:wr});h(this,"selectors",{selectById:$r,selectByIds:Ur})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u}),p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[e.asset,e.fields_revision],blocks:[d.uuid]});return this.dispatch(n(d)),p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}bulkAdd(e,n){const{payloads:c,values:r}=e,{addMany:a,setMany:u,deleteMany:d}=this.actions,p=new Date().toISOString(),m=[],f=rt(c,Math.min(n??c.length,N)),I=[];for(const b of f){const g=[];for(const _ of b){const v=O({..._,values:_.values,created_by:this.select(B=>{var C;return((C=B.userReducer.currentUser)==null?void 0:C.id)??null}),submitted_at:p});m.push(v),g.push({uuid:v.uuid,asset:_.asset,fields_revision:_.fields_revision,published_at:_.published_at,values:v.values})}I.push({submitted_at:p,values:r,field_values:g})}this.dispatch(a(m));const R=[];for(const b of I){const{field_values:g}=b,_=g.map(({asset:D})=>D),v=g.map(({fields_revision:D})=>D),B=g.map(({uuid:D})=>D),C=this.enqueueRequest({description:A(o.POST,this.name,!0),method:o.POST,url:`${this.url}/bulk/`,payload:b,blockers:_.concat(v),blocks:B});R.push(C)}return Promise.all(R).then(b=>{this.dispatch(u(b.flat()))}).catch(()=>{this.dispatch(d(w(m)))}),[m,R]}update(e){const{setOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[a.uuid,a.fields_revision,a.asset],blocks:[a.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const u=this.select(gr(e));this.dispatch(n(e)),this.dispatch(zs(w(u)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(d){throw this.dispatch(c(a)),this.dispatch(Vs(u)),d}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{asset__project:e,latest:!0}},n)).flat();return this.dispatch(c(a)),a}}class xg extends E{constructor(){super(...arguments);h(this,"name","Asset Type Identifier");h(this,"url","/asset-type-identifiers");h(this,"actions",{addOne:Gr,addMany:Hr,setOne:Wr,setMany:Kr,updateOne:Yr,updateMany:Zr,deleteOne:Jr,deleteMany:Xr,initialize:Nr});h(this,"selectors",{selectById:xr,selectByIds:ed})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[d.asset_type],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}update(e){const{setOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Expected asset type identifier with uuid ${e.uuid} to exist`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Expected asset type identifier with uuid ${e} to exist`);this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class eM extends E{constructor(){super(...arguments);h(this,"name","Asset Type Identifier Value");h(this,"url","/asset-type-identifier-values");h(this,"actions",{addOne:nd,addMany:cd,setOne:ad,setMany:rd,updateOne:dd,updateMany:ud,deleteOne:ld,deleteMany:od,initialize:id});h(this,"selectors",{selectById:md,selectByIds:pd})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[e.asset,e.asset_type_identifier],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}bulkAdd(e,n){const{addMany:c,updateMany:r,deleteMany:a}=this.actions,u=new Date().toISOString(),d=this.select(b=>{var g;return((g=b.userReducer.currentUser)==null?void 0:g.id)??null}),p=rt(e,Math.min(n??e.length,N)),m=[],f=[];for(const b of p){const g=[],_=[],v=[];for(const C of b){const D=O({...C,submitted_at:u,created_by:d});f.push(D);const z={uuid:D.uuid,asset:D.asset,asset_type_identifier:D.asset_type_identifier,value:D.value};g.push(z),_.push(D.asset),_.push(D.asset_type_identifier),v.push(D.uuid)}const B={payloads:g,submitted_at:u,blockers:_,blocks:v};m.push(B)}this.dispatch(c(f));const I=m.map(b=>{const{payloads:g,submitted_at:_,blockers:v,blocks:B}=b;return this.enqueueRequest({description:A(o.POST,this.name,!0),method:o.POST,url:`${this.url}/bulk/`,payload:{submitted_at:_,payloads:g},blockers:v,blocks:B})});Promise.all(I).then(b=>{this.dispatch(r(b.flat()))}).catch(b=>{throw this.dispatch(a(w(f))),b});const R=Promise.all(I).then(b=>b.flat());return[f,R]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Expected asset type identifier value with uuid ${e} to exist`);this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{asset__project:e,latest:!0}},n)).flat();return this.dispatch(c(a)),a}}class tM extends E{constructor(){super(...arguments);h(this,"name","Asset Type");h(this,"url","/asset-types");h(this,"actions",{addOne:Td,addMany:Od,setOne:Ad,setMany:Id,updateOne:Pd,updateMany:Fd,deleteOne:bd,deleteMany:_d,initialize:Sd});h(this,"selectors",{selectById:Md,selectByIds:Rd})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}update(e){const{setOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[r.uuid],blocks:[r.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Expected asset type with uuid ${e} to exist`);const u=this.select(ba(e)),d=this.select($a(e));this.dispatch(n(e)),this.dispatch(bs(w(u))),this.dispatch(Ms(w(d)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(p){throw this.dispatch(c(a)),this.dispatch(Fs(u)),this.dispatch(gs(d)),p}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{organization:e}},n);return this.dispatch(c(r)),r}}class sM extends E{constructor(){super(...arguments);h(this,"name","Asset Type Status");h(this,"url","/asset-type-statuses");h(this,"actions",{addOne:Bd,addMany:Vd,setOne:zd,setMany:Dd,updateOne:jd,updateMany:qd,deleteOne:Cd,deleteMany:$d,initialize:Ed});h(this,"selectors",{selectById:Ld,selectByIds:kd})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[e.asset_type],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}update(e){const{setOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Expected an existing asset type status with uuid ${e.uuid}`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`No asset type status with uuid ${e} found in the store`);this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class iM extends j{constructor(){super(...arguments);h(this,"name","Document Attachment");h(this,"url","/document-attachments");h(this,"actions",{addOne:Zd,addMany:Jd,setOne:Xd,setMany:Qd,updateOne:xd,updateMany:eu,deleteOne:tu,deleteMany:su,initialize:Yd});h(this,"selectors",{selectById:nu,selectByIds:cu})}getId(e){return e.uuid}getBlockers(e){return[e.document]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,document:e.document}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,document:e.document}}async bulkAdd(e,n){const[c,r,a]=await super.bulkAdd(e,n),u={};for(const{file_sha1:d,uuid:p}of c)d in u||(u[d]=[]),u[d].push(p);return a.then(d=>{const p=d.flatMap(m=>u[m]??[]);for(const m of p)this.makeReadable(m)}),[c,r,a]}makeReadable(e){this.enqueueRequest({description:"Add attachment to AI assistant",method:o.PATCH,url:`${this.url}/${e}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",e],blocks:["index-document-attachment"]})}async refreshStore(e,n){const{initialize:c}=this.actions,r=this.list({queryParams:{document__project__organization:e}},n),a=this.list({queryParams:{document__organization:e}},n),d=(await Promise.all([r,a])).flat();return this.dispatch(c(d)),d}}class nM extends E{constructor(){super(...arguments);h(this,"name","Document");h(this,"url","/documents");h(this,"actions",{addOne:uu,addMany:lu,setOne:ou,setMany:hu,updateOne:mu,updateMany:pu,deleteOne:yu,deleteMany:fu,initialize:du});h(this,"selectors",{selectById:Au,selectByIds:Iu})}add(e){const{addOne:n,deleteOne:c,updateOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:d.parent_document?[d.parent_document]:[],blocks:[d.uuid]});return p.then(m=>{this.dispatch(r(m))}).catch(()=>{this.dispatch(c(d.uuid))}),[d,p]}update(e){const{updateOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c,addMany:r,deleteMany:a}=this.actions,{selectById:u}=this.selectors,d=this.select(u(e));if(!d)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const p=this.select(Tu(e));this.dispatch(n(e)),this.dispatch(a(w(p)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(m){throw this.dispatch(c(d)),this.dispatch(r(p)),m}}async refreshStore(e,n){const{initialize:c}=this.actions,r=this.list({queryParams:{project__organization:e}},n),a=this.list({queryParams:{organization:e}},n),d=(await Promise.all([r,a])).flat();return this.dispatch(c(d)),d}}class yt extends pt{async get(s,e){return this.performRequest({url:`${this.url}/${s}/`,method:o.GET},e)}async list(s,e){return this.performRequest({url:`${this.url}/`,method:o.GET,...s},e)}async listPaginated(s,e){return this.performPagination({url:`${this.url}/`,method:o.GET,...s},e)}}class cM extends yt{constructor(){super(...arguments);h(this,"name","Email Domains");h(this,"url","/organization-email-domains");h(this,"actions",{addOne:Fu,addMany:bu,setOne:_u,setMany:gu,updateOne:Mu,updateMany:Ru,deleteOne:wu,deleteMany:vu,initialize:Pu});h(this,"selectors",{selectById:Bu,selectByIds:Vu})}async add(e,n){return this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:{email:n,organization:e},blockers:[e,"create-org"],blocks:[]})}async delete(e){const{deleteOne:n,addOne:c}=this.actions;this.dispatch(n(e.uuid));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e.uuid}/`,blockers:[e.domain],blocks:[]})}catch(r){throw this.dispatch(c(e)),r}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{organization:e}},n);return this.dispatch(c(r)),r}}class aM extends pt{async getVerificationCode(s){return this.enqueueRequest({description:"Get verification code",method:o.GET,url:`/verification/email-verification/${s}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(s,e=void 0){return this.enqueueRequest({description:"Validate verification code",method:o.POST,url:`/verification/email-verification/${s}/`,isAuthNeeded:!1,payload:e,blockers:[],blocks:[]})}}const jt={},dc=new Set;class rM extends pt{constructor(){super(...arguments);h(this,"host");h(this,"dbPromise",ab.openDB("fileCache",1,{upgrade(e){e.createObjectStore("files")}}))}async getDB(){return await this.dbPromise}async addCache(e){if(!e.name)throw new Error(`Cant add a file without a name to cache: ${e.name}`);if(!e.type)throw new Error(`Cant add a file without a type to cache: ${e.name}`);if(!e.size)throw new Error(`Cant add an empty file to cache: ${e.name}`);const n=await qt(e);if(dc.has(n))return;const c=await this.getDB();!!await c.get("files",n)?console.warn(`Attempting to add a file already cached, ${e.name}`):await c.put("files",e,n),dc.add(n)}async removeCache(e){await(await this.getDB()).delete("files",e),dc.delete(e)}async fetchCache(e){return(await this.getDB()).get("files",e)}async fetchFileFromUrl(e,n,c=n){const r=e.split("?")[0]??e,a=await this.fetchCache(n);if(a)return a;let u;r in jt?u=jt[r]:wc(e)?(u=Rc(e,c),jt[r]=u):(u=new Promise(m=>{this.performRequest({method:o.GET,url:e,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1}).then(f=>{const I=new File([f],c,{type:f.type});m(I)})}),jt[r]=u);let d;try{d=await u}catch(m){throw m instanceof U&&delete jt[r],m}const p=await qt(d);if(p!==n){const m=`The hash of the file returned from the server (${p}) does not match the
7
+ `)}catch(c){console.error("Failed to extract error message from response body",c)}}else typeof t.body=="string"&&(e=t.body);else t!=null&&t.text?e=t.text:s instanceof Error&&(e=s.message);return!e||e.length>Lg?bt:e}class U extends Error{constructor(e){super(bt);h(this,"status");h(this,"response");h(this,"message");h(this,"options");const{response:n,innerError:c}=e;this.message=e.message??kg(n,c)??bt,this.status=(n==null?void 0:n.status)??0,this.response=n,e.discard=e.discard??!1,this.options=e}}function NF(t){function s(e){return typeof e=="object"&&e!==null&&["ok","redirect","clientError","serverError","error"].every(c=>c in e)}if(s(t))return t;if(typeof t=="object"&&t!==null){const e=t;if(s(e.response))return e.response;if(e.response&&s(e.response.response))return e.response.response}}class Ng extends qF{constructor(s){super(s)}}class pt extends qF{constructor(e,n){super(e);h(this,"auth");this.auth=n}}class Gg extends pt{async startConversation(s,e){return this.enqueueRequest({description:"Start agent conversation",method:o.POST,url:"/agents/prompt/",payload:{prompt:s,active_project:e},blockers:["prompt"],blocks:["prompt"]}).then(n=>(this.dispatch(Cc(n)),n))}async continueConversation(s,e,n){return this.enqueueRequest({description:"Prompt agent",method:o.POST,url:"/agents/prompt/",payload:{prompt:s,active_project:n},blockers:["prompt"],blocks:["prompt"],queryParams:{conversation_id:e}}).then(c=>{this.dispatch(Uc(c))})}async fetchDetails(s){return this.enqueueRequest({description:"Get agent conversation",method:o.GET,url:`/agents/conversations/${s}/`,blockers:["conversation"],blocks:["conversation"]}).then(e=>{this.dispatch($c(e))})}async rate(s,e){return this.enqueueRequest({description:"Rate agent response",method:o.PUT,url:`/agents/responses/${s}/rate/`,payload:{rating:e},blockers:["rate"],blocks:["rate"]})}async list(s,e){return this.performRequest({method:o.GET,url:"/agents/conversations/",...s},e)}async refreshStore(s,e){const n=await this.list({queryParams:{project:s}},e);return this.dispatch(qc(n)),n}}function rt(t,s){const e=[];let n=0;const c=t.length;for(;n<c;)e.push(t.slice(n,n+=s));return e}function A(t,s,e){const n=`${s}${e?"s":""}`;switch(t){case o.GET:return`Get ${n}`;case o.POST:return`Create ${n}`;case o.PATCH:return`Update ${n}`;case o.PUT:return`Update ${n}`;case o.DELETE:return`Delete ${n}`}}function M(t){const s={...t};for(const e of[...Ac,"created_by"])e in s&&delete s[e];return s}class E extends pt{async get(s,e){return this.performRequest({url:`${this.url}/${s}/`,method:o.GET},e)}async list(s,e){return this.performRequest({url:`${this.url}/`,method:o.GET,...s},e)}async listPaginated(s,e){return this.performPagination({url:`${this.url}/`,method:o.GET,...s},e)}}class j extends E{constructor(){super(...arguments);h(this,"pageSize",DF)}async getFileUrl(e,n){const c=await this.get(e,n);if(!c.file_url)throw new Error(`Unable to obtain file_url for ${this.name}: ${e}`);return c.file_url}async add(e){const{addOne:n,updateOne:c,deleteOne:r}=this.actions;let a,u=null,d=null;if("file"in e){const{file:b,...g}=e;u=await this.client.files.getFilePayload(b),d=URL.createObjectURL(b),a={...g,file_sha1:u.sha1,file_type:u.file_type,file_name:b.name,file_extension:u.extension,file_url:d}}else a=e;const p=this.buildModel(a),m=this.buildPayload(p);this.dispatch(n(p));const f=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:{...m,...u?{file:u}:{}},blockers:this.getBlockers(p),blocks:this.getBlocks(p)});f.then(({instance:b})=>{this.dispatch(c(b))}).catch(b=>{throw this.dispatch(r(this.getId(p))),b}).finally(()=>{d&&URL.revokeObjectURL(d)});const I=f.then(({instance:b})=>b),R=f.then(async({instance:b,presigned_url:g})=>{try{return g&&await this.client.files.processPresignedUrl(b.file_sha1,g),b.file_sha1}catch(_){throw console.error("Upload to s3 using presigned url failed.",_),_}});return[p,I,R]}async bulkAdd(e,n){const{addMany:c,updateMany:r,deleteMany:a}=this.actions,u=new Date().toISOString(),d=[],p=new Set,m=rt(e,Math.min(n??e.length,N)),f=[];for(const g of m){const _=[],v={},B=[],C=[];for(const z of g){let Mt;if("file"in z){const{file:hc,...yR}=z,Rt=await this.client.files.getFilePayload(hc);Rt.sha1 in v||(v[Rt.sha1]=Rt);const tb=URL.createObjectURL(hc);p.add(tb),Mt={...yR,file_sha1:Rt.sha1,file_type:Rt.file_type,file_name:hc.name,file_extension:Rt.extension,file_url:tb}}else Mt=z;const q=this.buildModel(Mt);d.push(q);const G=this.buildBulkPayload(q);_.push(G);const ds=this.getBlockers(q);B.push(...ds);const pR=this.getBlocks(q);C.push(...pR)}const D={payloads:_,submittedAt:u,files:Object.values(v),blockers:B,blocks:C};f.push(D)}this.dispatch(c(d));const I=f.map(g=>{const{submittedAt:_,files:v,payloads:B,blocks:C,blockers:D}=g;return this.enqueueRequest({description:A(o.POST,this.name,!0),method:o.POST,url:`${this.url}/bulk/`,payload:{submitted_at:_,files:v,payloads:B},blockers:D,blocks:C})});Promise.all(I).then(g=>{const _=g.flatMap(v=>v.instances);this.dispatch(r(_))}).catch(g=>{throw this.dispatch(a(d.map(_=>this.getId(_)))),console.error(g),g}).finally(()=>{for(const g of p)URL.revokeObjectURL(g)});const R=Promise.all(I).then(g=>g.flatMap(({instances:_})=>_)),b=Promise.all(I).then(async g=>{const _=[];for(const{presigned_urls:v}of g){const B=this.client.files.processPresignedUrls(v);for(const[C,D]of Object.entries(B))try{await D,_.push(C)}catch(z){throw console.error("Upload to s3 using presigned url failed.",z),z}}return _});return[d,R,b]}async delete(e){const{addOne:n,deleteOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Attempting to delete ${this.name} with pk ${e} that does not exist in the store`);this.dispatch(c(this.getId(a)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(n(a)),u}}}class Hg extends j{constructor(){super(...arguments);h(this,"name","Asset attachment");h(this,"url","/asset-attachments");h(this,"actions",{addOne:Gc,addMany:As,setOne:Hc,setMany:Wc,updateOne:Kc,updateMany:Yc,deleteOne:Zc,deleteMany:Is,initialize:Nc});h(this,"selectors",{selectById:Xc,selectByIds:Qc})}getId(e){return e.uuid}getBlockers(e){const{asset:n}=e;return[n]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset:e.asset}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset:e.asset}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{asset__project:e}},n)).flat();return this.dispatch(c(a)),a}}class Wg extends E{constructor(){super(...arguments);h(this,"name","Asset Comment");h(this,"url","/asset-comments");h(this,"actions",{addOne:ia,addMany:$t,setOne:na,setMany:ca,updateOne:aa,updateMany:ra,deleteOne:da,deleteMany:Ut,initialize:sa});h(this,"selectors",{selectById:la,selectByIds:oa})}add(e){const{addOne:n,updateOne:c,deleteOne:r}=this.actions,a=O({...e,created_by:this.select(d=>{var p;return((p=d.userReducer.currentUser)==null?void 0:p.id)??null}),submitted_at:new Date().toISOString()});this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(a),blockers:[a.asset],blocks:[a.uuid]});return u.then(d=>{this.dispatch(c(d))}).catch(()=>{this.dispatch(r(a.uuid))}),[a,u]}update(e){const{updateOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Asset comment with uuid ${e.uuid} not found in store`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Asset comment with uuid ${e} not found in store`);this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{asset__project:e}},n)).flat();return this.dispatch(c(a)),a}}class Kg extends E{constructor(){super(...arguments);h(this,"url","/assets");h(this,"name","Asset");h(this,"actions",{addOne:Sa,addMany:Fs,setOne:Oa,setMany:Pa,updateOne:Aa,updateMany:Ia,deleteOne:Ta,deleteMany:bs,initialize:fa});h(this,"selectors",{selectById:_a,selectByIds:ga})}add(e){const{addOne:n,updateOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[d.asset_type],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}update(e){const{updateOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`No asset with uuid ${e.uuid} found in the store`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{addOne:n,deleteOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`No asset with uuid ${e} found in the store`);const u=this.select(xc(e)),d=this.select(ha(e)),p=this.select(sh(e)),m=this.select(_A(e)),f=this.select(go(e));this.dispatch(c(e)),this.dispatch(Is(w(u))),this.dispatch(Ut(w(d))),this.dispatch(Tt(w(p))),this.dispatch(Ft(w(m))),this.dispatch(lt(w(f)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(I){throw this.dispatch(n(a)),this.dispatch(As(u)),this.dispatch($t(d)),this.dispatch(It(p)),this.dispatch(Pt(m)),this.dispatch(ut(f)),I}}bulkAdd(e,n){const{addMany:c}=this.actions,r=new Date().toISOString(),a=rt(e,Math.min(n??e.length,N)).map(p=>{const m=p.map(f=>O(f));return{batchId:dt.v4(),payload:{submitted_at:r,assets:m}}}),u=[];let d=null;for(const p of a){const{batchId:m,payload:f}=p,I=f.assets.map(({uuid:v})=>v),R=f.assets.map(({asset_type:v})=>v),b=f.assets.map(({project:v})=>v),g=f.assets.map(({status:v})=>v),_=this.enqueueRequest({description:A(o.POST,this.name,!0),method:o.POST,url:`${this.url}/bulk/`,payload:f,blockers:(d?[d]:[]).concat(R).concat(b).concat(g),blocks:[m].concat(I)});d=p.batchId,u.push(_)}return Promise.all(u).then(p=>{const m=p.flat();this.dispatch(c(m))}),u}bulkUpdate(e,n){const{updateMany:c}=this.actions,{selectByIds:r}=this.selectors,a=w(e).toSorted(Ct);if(a.length!==e.length)throw new Error("payloads contains duplicate uuids.");const u=this.select(r(a)).toSorted(ps);if(a.length!=u.length)throw new Error(`Attempting to bulk update ${a.length-u.length} assets that dont exist in the store`);const d=[];for(let I=0;I<a.length;I++)d.push({...u[I],...e[I]});this.dispatch(c(d));const p=rt(e,Math.min(n??e.length,N)),m=[];let f=null;for(const I of p){const R=dt.v4(),b=w(I),g=I.map(({status:v})=>v).filter(Boolean),_=this.enqueueRequest({description:A(o.PATCH,this.name,!0),method:o.PATCH,url:`${this.url}/bulk/`,payload:{payloads:I},blockers:(f?[f]:[]).concat(b).concat(g),blocks:[R].concat(b)});m.push(_),f=R}return Promise.all(m).then(I=>{this.dispatch(c(I.flat()))}).catch(()=>{this.dispatch(c(u))}),[d,m]}async bulkDelete(e){const{addMany:n,deleteMany:c}=this.actions,{selectByIds:r}=this.selectors,a=this.select(r(e)),u=this.select(ma(e)),d=this.select(ih(e)),p=this.select(gA(e)),m=this.select(Mo(e));this.dispatch(c(e)),this.dispatch(Ut(w(u))),this.dispatch(Tt(w(d))),this.dispatch(Ft(w(p))),this.dispatch(lt(w(m)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!0),method:o.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(f){throw this.dispatch(n(a)),this.dispatch($t(u)),this.dispatch(It(d)),this.dispatch(Pt(p)),this.dispatch(ut(m)),f}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{project:e}},n)).flat();return this.dispatch(c(a)),a}}class Yg extends j{constructor(){super(...arguments);h(this,"name","Asset Type Attachment");h(this,"url","/asset-type-attachments");h(this,"actions",{addOne:va,addMany:gs,setOne:Ea,setMany:Ba,updateOne:Va,updateMany:za,deleteOne:Da,deleteMany:Ms,initialize:wa});h(this,"selectors",{selectById:qa,selectByIds:Ca})}getId(e){return e.uuid}getBlockers(e){return[e.asset_type]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_type:e.asset_type}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,asset_type:e.asset_type}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class Zg extends j{constructor(){super(...arguments);h(this,"name","Asset Type Fields Attachment");h(this,"url","/asset-type-fields-attachments");h(this,"actions",{addOne:Na,addMany:Ga,setOne:Ha,setMany:Wa,updateOne:Ka,updateMany:Ya,deleteOne:Za,deleteMany:Ja,initialize:ka});h(this,"selectors",{selectById:Qa,selectByIds:xa})}getId(e){return e.uuid}getBlockers(e){return[e.fields_revision]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:c,fields_revision:r,file_sha1:a,file_name:u,file_extension:d}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:c,fields_revision:r,file_sha1:a,file_name:u,file_extension:d}}buildBulkPayload(e){const{uuid:n,field_identifier:c,fields_revision:r,file_sha1:a,file_name:u,file_extension:d}=e;return{uuid:n,field_identifier:c,fields_revision:r,file_sha1:a,file_name:u,file_extension:d}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{fields_revision__asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class Jg extends E{constructor(){super(...arguments);h(this,"name","Asset Type Fields");h(this,"url","/asset-type-fields");h(this,"actions",{addOne:ir,addMany:nr,setOne:cr,setMany:ar,updateOne:rr,updateMany:dr,deleteOne:ur,deleteMany:lr,initialize:sr});h(this,"selectors",{selectById:hr,selectByIds:mr})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[d.asset_type],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(m=>{throw this.dispatch(r(d.uuid)),m}),[d,p]}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class Xg extends j{constructor(){super(...arguments);h(this,"name","Asset Type Field Values Attachment");h(this,"url","/asset-type-field-values-attachments");h(this,"actions",{addOne:Sr,addMany:Vs,setOne:Ar,setMany:Ir,updateOne:Tr,updateMany:Or,deleteOne:Pr,deleteMany:zs,initialize:fr});h(this,"selectors",{selectById:br,selectByIds:_r})}getId(e){return e.uuid}getBlockers(e){return[e.field_values]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){const{uuid:n,field_identifier:c,field_values:r,file_sha1:a,file_name:u,file_extension:d}=e;return{uuid:n,submitted_at:e.submitted_at,field_identifier:c,field_values:r,file_sha1:a,file_name:u,file_extension:d}}buildBulkPayload(e){const{uuid:n,field_identifier:c,field_values:r,file_sha1:a,file_name:u,file_extension:d}=e;return{uuid:n,field_identifier:c,field_values:r,file_sha1:a,file_name:u,file_extension:d}}async bulkDelete(e){const{deleteMany:n,addMany:c}=this.actions,{selectByIds:r}=this.selectors,a=this.select(r(e));this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!0),method:o.DELETE,url:`${this.url}/bulk/`,payload:{uuids:e},blockers:e,blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{field_values__asset__project:e,latest:!0}},n)).flat();return this.dispatch(c(a)),a}}class Qg extends E{constructor(){super(...arguments);h(this,"name","Asset Type Field Values");h(this,"url","/asset-type-field-values");h(this,"actions",{addOne:vr,addMany:Er,setOne:Br,setMany:Vr,updateOne:zr,updateMany:Dr,deleteOne:jr,deleteMany:qr,initialize:wr});h(this,"selectors",{selectById:$r,selectByIds:Ur})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u}),p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[e.asset,e.fields_revision],blocks:[d.uuid]});return this.dispatch(n(d)),p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}bulkAdd(e,n){const{payloads:c,values:r}=e,{addMany:a,setMany:u,deleteMany:d}=this.actions,p=new Date().toISOString(),m=[],f=rt(c,Math.min(n??c.length,N)),I=[];for(const b of f){const g=[];for(const _ of b){const v=O({..._,values:_.values,created_by:this.select(B=>{var C;return((C=B.userReducer.currentUser)==null?void 0:C.id)??null}),submitted_at:p});m.push(v),g.push({uuid:v.uuid,asset:_.asset,fields_revision:_.fields_revision,published_at:_.published_at,values:v.values})}I.push({submitted_at:p,values:r,field_values:g})}this.dispatch(a(m));const R=[];for(const b of I){const{field_values:g}=b,_=g.map(({asset:D})=>D),v=g.map(({fields_revision:D})=>D),B=g.map(({uuid:D})=>D),C=this.enqueueRequest({description:A(o.POST,this.name,!0),method:o.POST,url:`${this.url}/bulk/`,payload:b,blockers:_.concat(v),blocks:B});R.push(C)}return Promise.all(R).then(b=>{this.dispatch(u(b.flat()))}).catch(()=>{this.dispatch(d(w(m)))}),[m,R]}update(e){const{setOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Expected AssetTypeFieldValues with uuid ${e.uuid} to exist`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[a.uuid,a.fields_revision,a.asset],blocks:[a.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Expected submission with uuid ${e} to exist`);const u=this.select(gr(e));this.dispatch(n(e)),this.dispatch(zs(w(u)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(d){throw this.dispatch(c(a)),this.dispatch(Vs(u)),d}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{asset__project:e,latest:!0}},n)).flat();return this.dispatch(c(a)),a}}class xg extends E{constructor(){super(...arguments);h(this,"name","Asset Type Identifier");h(this,"url","/asset-type-identifiers");h(this,"actions",{addOne:Gr,addMany:Hr,setOne:Wr,setMany:Kr,updateOne:Yr,updateMany:Zr,deleteOne:Jr,deleteMany:Xr,initialize:Nr});h(this,"selectors",{selectById:xr,selectByIds:ed})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[d.asset_type],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}update(e){const{setOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Expected asset type identifier with uuid ${e.uuid} to exist`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Expected asset type identifier with uuid ${e} to exist`);this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class eM extends E{constructor(){super(...arguments);h(this,"name","Asset Type Identifier Value");h(this,"url","/asset-type-identifier-values");h(this,"actions",{addOne:nd,addMany:cd,setOne:ad,setMany:rd,updateOne:dd,updateMany:ud,deleteOne:ld,deleteMany:od,initialize:id});h(this,"selectors",{selectById:md,selectByIds:pd})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[e.asset,e.asset_type_identifier],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}bulkAdd(e,n){const{addMany:c,updateMany:r,deleteMany:a}=this.actions,u=new Date().toISOString(),d=this.select(b=>{var g;return((g=b.userReducer.currentUser)==null?void 0:g.id)??null}),p=rt(e,Math.min(n??e.length,N)),m=[],f=[];for(const b of p){const g=[],_=[],v=[];for(const C of b){const D=O({...C,submitted_at:u,created_by:d});f.push(D);const z={uuid:D.uuid,asset:D.asset,asset_type_identifier:D.asset_type_identifier,value:D.value};g.push(z),_.push(D.asset),_.push(D.asset_type_identifier),v.push(D.uuid)}const B={payloads:g,submitted_at:u,blockers:_,blocks:v};m.push(B)}this.dispatch(c(f));const I=m.map(b=>{const{payloads:g,submitted_at:_,blockers:v,blocks:B}=b;return this.enqueueRequest({description:A(o.POST,this.name,!0),method:o.POST,url:`${this.url}/bulk/`,payload:{submitted_at:_,payloads:g},blockers:v,blocks:B})});Promise.all(I).then(b=>{this.dispatch(r(b.flat()))}).catch(b=>{throw this.dispatch(a(w(f))),b});const R=Promise.all(I).then(b=>b.flat());return[f,R]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Expected asset type identifier value with uuid ${e} to exist`);this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,a=(await this.listPaginated({queryParams:{asset__project:e,latest:!0}},n)).flat();return this.dispatch(c(a)),a}}class tM extends E{constructor(){super(...arguments);h(this,"name","Asset Type");h(this,"url","/asset-types");h(this,"actions",{addOne:Td,addMany:Od,setOne:Ad,setMany:Id,updateOne:Pd,updateMany:Fd,deleteOne:bd,deleteMany:_d,initialize:Sd});h(this,"selectors",{selectById:Md,selectByIds:Rd})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}update(e){const{setOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Expected asset type with uuid ${e.uuid} to exist`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[r.uuid],blocks:[r.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`Expected asset type with uuid ${e} to exist`);const u=this.select(ba(e)),d=this.select($a(e));this.dispatch(n(e)),this.dispatch(bs(w(u))),this.dispatch(Ms(w(d)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(p){throw this.dispatch(c(a)),this.dispatch(Fs(u)),this.dispatch(gs(d)),p}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{organization:e}},n);return this.dispatch(c(r)),r}}class sM extends E{constructor(){super(...arguments);h(this,"name","Asset Type Status");h(this,"url","/asset-type-statuses");h(this,"actions",{addOne:Bd,addMany:Vd,setOne:zd,setMany:Dd,updateOne:jd,updateMany:qd,deleteOne:Cd,deleteMany:$d,initialize:Ed});h(this,"selectors",{selectById:Ld,selectByIds:kd})}add(e){const{addOne:n,setOne:c,deleteOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:[e.asset_type],blocks:[d.uuid]});return p.then(m=>{this.dispatch(c(m))}).catch(()=>{this.dispatch(r(d.uuid))}),[d,p]}update(e){const{setOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`Expected an existing asset type status with uuid ${e.uuid}`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c}=this.actions,{selectById:r}=this.selectors,a=this.select(r(e));if(!a)throw new Error(`No asset type status with uuid ${e} found in the store`);this.dispatch(n(e));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(u){throw this.dispatch(c(a)),u}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{asset_type__organization:e}},n);return this.dispatch(c(r)),r}}class iM extends j{constructor(){super(...arguments);h(this,"name","Document Attachment");h(this,"url","/document-attachments");h(this,"actions",{addOne:Zd,addMany:Jd,setOne:Xd,setMany:Qd,updateOne:xd,updateMany:eu,deleteOne:tu,deleteMany:su,initialize:Yd});h(this,"selectors",{selectById:nu,selectByIds:cu})}getId(e){return e.uuid}getBlockers(e){return[e.document]}getBlocks(e){return[e.uuid]}buildModel(e){const n=this.select(r=>{var a;return((a=r.userReducer.currentUser)==null?void 0:a.id)??null}),c=new Date().toISOString();return O({...e,created_by:n,submitted_at:c})}buildPayload(e){return{uuid:e.uuid,submitted_at:e.submitted_at,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,document:e.document}}buildBulkPayload(e){return{uuid:e.uuid,file_name:e.file_name,file_sha1:e.file_sha1,file_extension:e.file_extension,document:e.document}}async bulkAdd(e,n){const[c,r,a]=await super.bulkAdd(e,n),u={};for(const{file_sha1:d,uuid:p}of c)d in u||(u[d]=[]),u[d].push(p);return a.then(d=>{const p=d.flatMap(m=>u[m]??[]);for(const m of p)this.makeReadable(m)}),[c,r,a]}makeReadable(e){this.enqueueRequest({description:"Add attachment to AI assistant",method:o.PATCH,url:`${this.url}/${e}/`,payload:{readable_to_assistant:!0},blockers:["index-document-attachment",e],blocks:["index-document-attachment"]})}async refreshStore(e,n){const{initialize:c}=this.actions,r=this.list({queryParams:{document__project__organization:e}},n),a=this.list({queryParams:{document__organization:e}},n),d=(await Promise.all([r,a])).flat();return this.dispatch(c(d)),d}}class nM extends E{constructor(){super(...arguments);h(this,"name","Document");h(this,"url","/documents");h(this,"actions",{addOne:uu,addMany:lu,setOne:ou,setMany:hu,updateOne:mu,updateMany:pu,deleteOne:yu,deleteMany:fu,initialize:du});h(this,"selectors",{selectById:Au,selectByIds:Iu})}add(e){const{addOne:n,deleteOne:c,updateOne:r}=this.actions,a=this.select(m=>{var f;return((f=m.userReducer.currentUser)==null?void 0:f.id)??null}),u=new Date().toISOString(),d=O({...e,created_by:a,submitted_at:u});this.dispatch(n(d));const p=this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:M(d),blockers:d.parent_document?[d.parent_document]:[],blocks:[d.uuid]});return p.then(m=>{this.dispatch(r(m))}).catch(()=>{this.dispatch(c(d.uuid))}),[d,p]}update(e){const{updateOne:n}=this.actions,{selectById:c}=this.selectors,r=this.select(c(e.uuid));if(!r)throw new Error(`attempting to update a document with uuid ${e.uuid} that does not exist in store.documents`);const a={...r,...e};this.dispatch(n(a));const u=this.enqueueRequest({description:A(o.PATCH,this.name,!1),method:o.PATCH,url:`${this.url}/${e.uuid}/`,payload:e,blockers:[e.uuid],blocks:[e.uuid]});return u.then(d=>{this.dispatch(n(d))}).catch(()=>{this.dispatch(n(r))}),[a,u]}async delete(e){const{deleteOne:n,addOne:c,addMany:r,deleteMany:a}=this.actions,{selectById:u}=this.selectors,d=this.select(u(e));if(!d)throw new Error(`attempting to delete a document with uuid ${e} that does not exist in store.documents`);const p=this.select(Tu(e));this.dispatch(n(e)),this.dispatch(a(w(p)));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e}/`,blockers:[e],blocks:[]})}catch(m){throw this.dispatch(c(d)),this.dispatch(r(p)),m}}async refreshStore(e,n){const{initialize:c}=this.actions,r=this.list({queryParams:{project__organization:e}},n),a=this.list({queryParams:{organization:e}},n),d=(await Promise.all([r,a])).flat();return this.dispatch(c(d)),d}}class yt extends pt{async get(s,e){return this.performRequest({url:`${this.url}/${s}/`,method:o.GET},e)}async list(s,e){return this.performRequest({url:`${this.url}/`,method:o.GET,...s},e)}async listPaginated(s,e){return this.performPagination({url:`${this.url}/`,method:o.GET,...s},e)}}class cM extends yt{constructor(){super(...arguments);h(this,"name","Email Domains");h(this,"url","/organization-email-domains");h(this,"actions",{addOne:Fu,addMany:bu,setOne:_u,setMany:gu,updateOne:Mu,updateMany:Ru,deleteOne:wu,deleteMany:vu,initialize:Pu});h(this,"selectors",{selectById:Bu,selectByIds:Vu})}async add(e,n){return this.enqueueRequest({description:A(o.POST,this.name,!1),method:o.POST,url:`${this.url}/`,payload:{email:n,organization:e},blockers:[e,"create-org"],blocks:[]})}async delete(e){const{deleteOne:n,addOne:c}=this.actions;this.dispatch(n(e.uuid));try{return await this.enqueueRequest({description:A(o.DELETE,this.name,!1),method:o.DELETE,url:`${this.url}/${e.uuid}/`,blockers:[e.domain],blocks:[]})}catch(r){throw this.dispatch(c(e)),r}}async refreshStore(e,n){const{initialize:c}=this.actions,r=await this.list({queryParams:{organization:e}},n);return this.dispatch(c(r)),r}}class aM extends pt{async getVerificationCode(s){return this.enqueueRequest({description:"Get verification code",method:o.GET,url:`/verification/email-verification/${s}/`,isAuthNeeded:!1,blockers:[],blocks:[]})}validateVerificationCode(s,e=void 0){return this.enqueueRequest({description:"Validate verification code",method:o.POST,url:`/verification/email-verification/${s}/`,isAuthNeeded:!1,payload:e,blockers:[],blocks:[]})}}const jt={},dc=new Set;class rM extends pt{constructor(){super(...arguments);h(this,"host");h(this,"dbPromise",ab.openDB("fileCache",1,{upgrade(e){e.createObjectStore("files")}}))}async getDB(){return await this.dbPromise}async addCache(e){if(!e.name)throw new Error(`Cant add a file without a name to cache: ${e.name}`);if(!e.type)throw new Error(`Cant add a file without a type to cache: ${e.name}`);if(!e.size)throw new Error(`Cant add an empty file to cache: ${e.name}`);const n=await qt(e);if(dc.has(n))return;const c=await this.getDB();!!await c.get("files",n)?console.warn(`Attempting to add a file already cached, ${e.name}`):await c.put("files",e,n),dc.add(n)}async removeCache(e){await(await this.getDB()).delete("files",e),dc.delete(e)}async fetchCache(e){return(await this.getDB()).get("files",e)}async fetchFileFromUrl(e,n,c=n){const r=e.split("?")[0]??e,a=await this.fetchCache(n);if(a)return a;let u;r in jt?u=jt[r]:wc(e)?(u=Rc(e,c),jt[r]=u):(u=new Promise(m=>{this.performRequest({method:o.GET,url:e,isExternalUrl:!0,isResponseBlob:!0,isAuthNeeded:!1}).then(f=>{const I=new File([f],c,{type:f.type});m(I)})}),jt[r]=u);let d;try{d=await u}catch(m){throw m instanceof U&&delete jt[r],m}const p=await qt(d);if(p!==n){const m=`The hash of the file returned from the server (${p}) does not match the
8
8
  expected hash (${n}). This can happen if you're using a local development server and the
9
9
  isExternalUrl flag in the request details is set to true, because instead of requesting the local
10
10
  REST API, you will be requesting localhost:80 (where this app runs), resulting in a transformed blob
@@ -11,6 +11,7 @@ export declare abstract class BaseOfflineFileModelApiService<TModelId extends st
11
11
  protected abstract buildModel(data: Payload<TModel>): Submitted<TModel>;
12
12
  protected abstract buildPayload(model: Submitted<TModel>): object;
13
13
  protected abstract buildBulkPayload(model: Submitted<TModel>): object;
14
+ getFileUrl(uuid: TModelId, signal?: AbortSignal): Promise<string>;
14
15
  add(payload: Payload<TModel> | FileAnnotated<Omit<Payload<TModel>, keyof RequiredFileModel>>): Promise<OptimisticFileModelResult<TModel>>;
15
16
  bulkAdd(payloads: (Payload<TModel> | FileAnnotated<Omit<Payload<TModel>, keyof RequiredFileModel>>)[], batchSize?: number): Promise<OptimisticMultipleFileModelResult<TModel>>;
16
17
  delete(uuid: TModelId): Promise<void>;
@@ -101,7 +101,7 @@ export interface OptionalFileModel extends Model {
101
101
  file_name: string | null;
102
102
  }
103
103
  export interface RequiredFileModel extends Model {
104
- file_url: NonNullable<OptionalFileModel["file_url"]>;
104
+ file_url: NonNullable<OptionalFileModel["file_url"]> | null;
105
105
  file_sha1: NonNullable<OptionalFileModel["file_sha1"]>;
106
106
  file_extension: NonNullable<OptionalFileModel["file_extension"]>;
107
107
  file_name: NonNullable<OptionalFileModel["file_name"]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overmap-ai/core",
3
- "version": "1.0.80-clean-ups.0",
3
+ "version": "1.0.80-presigned-get-improvements.0",
4
4
  "description": "Core functionality for Overmap",
5
5
  "keywords": [
6
6
  "components",
@@ -58,6 +58,7 @@
58
58
  "@types/node": "22.17.0",
59
59
  "@types/superagent": "4.1.24",
60
60
  "@types/uuid": "9.0.8",
61
+ "@vitejs/plugin-react-swc": "3.11.0",
61
62
  "globals": "16.3.0",
62
63
  "happy-dom": "20.8.9",
63
64
  "oxfmt": "0.23.0",