@junobuild/core-peer 0.0.26 → 0.0.27

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.
@@ -1,4 +1,4 @@
1
1
  import { createRequire as topLevelCreateRequire } from 'module';
2
2
  const require = topLevelCreateRequire(import.meta.url);
3
- import{Principal as it}from"@dfinity/principal";var c=t=>t==null,l=t=>!c(t),pe=class extends Error{},K=(t,e)=>{if(c(t))throw new pe(e)},Y="__bigint__",J="__principal__",X="__uint8array__",de=(t,e)=>typeof e=="bigint"?{[Y]:`${e}`}:l(e)&&e instanceof it?{[J]:e.toText()}:l(e)&&e instanceof Uint8Array?{[X]:Array.from(e)}:e,ue=(t,e)=>{let s=o=>e[o];return l(e)&&typeof e=="object"&&Y in e?BigInt(s(Y)):l(e)&&typeof e=="object"&&J in e?it.fromText(s(J)):l(e)&&typeof e=="object"&&X in e?Uint8Array.from(s(X)):e},m=t=>l(t)?[t]:[],d=t=>t?.[0],nt=async t=>{let e=new Blob([JSON.stringify(t,de)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},q=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),ue)},rt=()=>typeof window<"u";var b=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:s})=>s(e))}subscribe(e){let s=Symbol();return this.callbacks.push({id:s,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:o})=>o!==s)}};var P=class t extends b{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let s=super.subscribe(e);return e(this.authUser),s}reset(){this.authUser=null,this.populate(this.authUser)}};var Q=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var at=BigInt(144e11),ct=!1,lt={width:576,height:576},pt={width:505,height:705},dt="internetcomputer.org";var R="http://127.0.0.1:5987",ut="rdmx6-jaaaa-aaaaa-aaadq-cai";var x=class t extends b{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var Z=({width:t,height:e})=>{if(!rt()||c(window)||c(window.top))return;let{top:{innerWidth:s,innerHeight:o}}=window,i=o/2+screenY-e/2,n=s/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${n}`};var B=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=x.getInstance().get()?.container;if(c(o)||o===!1)return`https://identity.${this.#t??dt}`;let i=x.getInstance().get(),n=l(i)&&l(i?.internetIdentityId)?i.internetIdentityId:ut,{host:r,protocol:a}=new URL(o===!0?R:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:Z(lt)},identityProvider:s()}}},mt=class{#t;#e;constructor({appName:e,logoUrl:s}){this.#t=e,this.#e=s}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:Z(pt)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as me}from"@dfinity/auth-client";var $=()=>me.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var yt=async({data:t})=>{try{return await q(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var D=async t=>{let{data:e,version:s,description:o}=t;return{description:m(o),data:await nt(e),version:m(s)}},I=t=>{let{version:e}=t;return{version:m(e)}},F=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:d(i),owner:s.toText(),data:await q(n),version:d(o),...r}};import{Principal as ye}from"@dfinity/principal";var ft=t=>{if(c(t))return m();switch(t.matcher){case"equal":return m({Equal:t.timestamp});case"greaterThan":return m({GreaterThan:t.timestamp});case"lessThan":return m({LessThan:t.timestamp});case"between":return m({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},k=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:c(t)?[]:[{key:m(t.key),description:m(t.description),created_at:ft(t.createdAt),updated_at:ft(t.updatedAt)}],paginate:m(c(e)?void 0:{start_after:m(e.startAfter),limit:m(c(e.limit)?void 0:BigInt(e.limit))}),order:m(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:m(c(o)?void 0:typeof o=="string"?ye.fromText(o):o)});var gt=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),s=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),o=t.Record({field:s,desc:t.Bool}),i=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),n=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(i),description:t.Opt(t.Text),created_at:t.Opt(i)}),r=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(o),owner:t.Opt(t.Principal),matcher:t.Opt(n),paginate:t.Opt(r)}),p=t.Record({controllers:t.Vec(t.Principal)}),T=t.Variant({Write:t.Null,Admin:t.Null}),f=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:T,expires_at:t.Opt(t.Nat64)}),h=t.Record({version:t.Opt(t.Nat64)}),_=t.Variant({Db:t.Null,Storage:t.Null}),w=t.Record({version:t.Opt(t.Nat64)}),v=t.Record({cycles:t.Nat,destination_id:t.Principal}),N=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),O=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),g=t.Record({key:N,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,O)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),S=t.Record({derivation_origin:t.Opt(t.Text)}),E=t.Record({internet_identity:t.Opt(S)}),V=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),U=t.Record({max_memory_size:t.Opt(V)}),Wt=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),Gt=t.Variant({Deny:t.Null,Allow:t.Null}),Yt=t.Record({status_code:t.Nat16,location:t.Text}),H=t.Record({iframe:t.Opt(Wt),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),max_memory_size:t.Opt(V),raw_access:t.Opt(Gt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,Yt)))}),Jt=t.Record({db:t.Opt(U),authentication:t.Opt(E),storage:H}),C=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),Xt=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),W=t.Variant({Heap:t.Null,Stable:t.Null}),G=t.Record({memory:W,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),Qt=t.Variant({Callback:t.Record({token:G,callback:t.Func([],[],["query"])})}),Zt=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Qt),status_code:t.Nat16}),Dt=t.Record({token:t.Opt(G),body:t.Vec(t.Nat8)}),It=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),Lt=t.Record({batch_id:t.Nat}),te=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,g)),items_length:t.Nat64}),ee=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),se=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,C)),items_length:t.Nat64}),M=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),oe=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(W),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:M,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:M}),ie=t.Record({stable:t.Nat64,heap:t.Nat64}),ne=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:T,expires_at:t.Opt(t.Nat64)}),re=t.Record({controller:ne,controllers:t.Vec(t.Principal)}),ot=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),ae=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(W),max_size:t.Opt(t.Nat),read:M,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:M}),ce=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),le=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text,a],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,a],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([p],[t.Vec(t.Tuple(t.Principal,f))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,h],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,h))],[],[]),del_rule:t.Func([_,t.Text,w],[],[]),deposit_cycles:t.Func([v],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(g)],["query"]),get_auth_config:t.Func([],[t.Opt(E)],["query"]),get_config:t.Func([],[Jt],[]),get_db_config:t.Func([],[t.Opt(U)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(C)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(g)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(C)))],["query"]),get_storage_config:t.Func([],[H],["query"]),http_request:t.Func([Xt],[Zt],["query"]),http_request_streaming_callback:t.Func([G],[Dt],["query"]),init_asset_upload:t.Func([It],[Lt],[]),list_assets:t.Func([t.Text,a],[te],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,f))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,ee))],["query"]),list_docs:t.Func([t.Text,a],[se],["query"]),list_rules:t.Func([_],[t.Vec(t.Tuple(t.Text,oe))],["query"]),memory_size:t.Func([],[ie],["query"]),set_auth_config:t.Func([E],[],[]),set_controllers:t.Func([re],[t.Vec(t.Tuple(t.Principal,f))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([U],[],[]),set_doc:t.Func([t.Text,t.Text,ot],[C],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,ot))],[t.Vec(t.Tuple(t.Text,C))],[]),set_rule:t.Func([_,t.Text,ae],[],[]),set_storage_config:t.Func([H],[],[]),upload_asset_chunk:t.Func([ce],[le],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as fe,HttpAgent as ge}from"@dfinity/agent";var ht=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:i})=>{let r=l(i)&&i!==!1?i===!0?R:i:"https://icp-api.io",a=l(i),p=await ge.create({identity:s,shouldFetchRootKey:a,host:r,...o&&{fetch:o}});return fe.createActor(e,{agent:p,canisterId:t})};var _t=({satelliteId:t,container:e})=>{let{satelliteId:s}=L({satelliteId:t}),{container:o}=tt({container:e});if(l(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?R:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},L=({satelliteId:t})=>l(t)?{satelliteId:t}:x.getInstance().get()??{satelliteId:void 0},tt=({container:t})=>l(t)?{container:t}:x.getInstance().get()??{container:void 0};var y=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=L({satelliteId:t});K(o,"No satellite ID defined. Did you initialize Juno?");let{container:i}=tt({container:e});return ht({satelliteId:o,container:i,idlFactory:gt,...s})};var Tt=async({collection:t,key:e,satellite:s})=>{let{get_doc:o}=await y(s),i=d(await o(t,e));if(!c(i))return F({doc:i,key:e})},xt=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await y(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let p=d(a);n.push(l(p)?await F({key:r,doc:p}):void 0)}return n},At=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await y(s),{key:i}=e,n=await D(e),r=await o(t,i,n);return await F({key:i,doc:r})},Nt=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await y(e),o=[];for(let{collection:r,doc:a}of t){let{key:p}=a;o.push([r,p,await D(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await F({key:r,doc:a}));return n},Pt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await y(s),{key:i}=e;return o(t,i,I(e))},wt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await y(e),o=t.map(({collection:i,doc:n})=>[i,n.key,I(n)]);await s(o)},vt=async({collection:t,filter:e,satellite:s})=>{let{list_docs:o}=await y(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:p}=await o(t,k(e)),T=[];for(let[f,h]of i){let{data:_,owner:w,description:v,version:N,...O}=h;T.push({key:f,description:d(v),owner:w.toText(),data:await yt({data:_}),version:d(N),...O})}return{items:T,items_length:r,items_page:d(n),matches_length:a,matches_pages:d(p)}},Ot=async({collection:t,filter:e,satellite:s})=>{let{count_docs:o}=await y(s);return o(t,k(e))};import{AnonymousIdentity as he}from"@dfinity/agent";var u=t=>t!==void 0?t:j()??new he;var St=async({satellite:t,...e})=>{let s=u(t?.identity);return Tt({...e,satellite:{...t,identity:s}})},Ss=async({satellite:t,...e})=>{let s=u(t?.identity);return xt({...e,satellite:{...t,identity:s}})},bt=async({satellite:t,...e})=>{let s=u(t?.identity);return At({...e,satellite:{...t,identity:s}})},bs=async({satellite:t,...e})=>{let s=u(t?.identity);return Nt({...e,satellite:{...t,identity:s}})},Rs=async({satellite:t,...e})=>{let s=u(t?.identity);return Pt({...e,satellite:{...t,identity:s}})},ks=async({satellite:t,...e})=>{let s=u(t?.identity);return wt({...e,satellite:{...t,identity:s}})},Es=async({satellite:t,filter:e,...s})=>{let o=u(t?.identity);return vt({...s,filter:e??{},satellite:{...t,identity:o}})},Us=async({satellite:t,filter:e,...s})=>{let o=u(t?.identity);return Ot({...s,filter:e??{},satellite:{...t,identity:o}})};var Rt=async t=>{let e=j();if(c(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await St({collection:"#user",key:s});return c(o)?await _e({userId:s,provider:t}):o},_e=async({userId:t,...e})=>bt({collection:"#user",doc:{key:t,data:e}});var A,et=async t=>{if(A=A??await $(),!(await A?.isAuthenticated()??!1))return;let s=await Rt(t);P.getInstance().set(s)},Te=async t=>new Promise(async(e,s)=>{A=A??await $();let o=t?.provider??new B({});await A.login({onSuccess:async()=>{await et(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??at,allowPinAuthentication:t?.allowPin??ct,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),st=async()=>{await A?.logout(),A=void 0,P.getInstance().reset()},j=()=>A?.getIdentity(),xe=async()=>(A??await $()).getIdentity();var kt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{Q({message:"junoSignOutAuthTimer"}),await st()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":Q({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},P.getInstance().subscribe(i=>{if(c(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Et=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_SATELLITE_ID??t():t()},Ut=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};import"@dfinity/principal";var Ae=t=>t==null,Ne=t=>!Ae(t),z=t=>Ne(t)?[t]:[],Pe=()=>typeof window<"u",Ct=async({asset:{data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a},actor:p,init_asset_upload:T})=>{let{batch_id:f}=await T({collection:s,full_path:n,name:e,token:z(i),encoding_type:z(r),description:z(a)}),h=19e5,_=[],w=Pe()?new Blob([await t.arrayBuffer()]):t,v=0n;for(let g=0;g<w.size;g+=h){let S=w.slice(g,g+h);_.push({batchId:f,chunk:S,actor:p,orderId:v}),v++}let N=[];for await(let g of we({uploadChunks:_}))N=[...N,...g];let O=o.find(([g,S])=>g.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await p.commit_asset_upload({batch_id:f,chunk_ids:N.map(({chunk_id:g})=>g),headers:[...o,...O||[]]})};async function*we({uploadChunks:t,limit:e=12}){for(let s=0;s<t.length;s=s+e){let o=t.slice(s,s+e);yield await Promise.all(o.map(i=>ve(i)))}}var ve=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:z(o)});var Ft=async({satellite:t,...e})=>{let s=await y(t);await Ct({actor:s,asset:e,init_asset_upload:async i=>await s.init_asset_upload(i)})},Vt=async({collection:t,satellite:e,filter:s})=>{let{list_assets:o}=await y(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:p}=await o(t,k(s));return{items:i.map(([T,f])=>f),items_length:n,items_page:d(r),matches_length:a,matches_pages:d(p)}},Mt=async({collection:t,satellite:e,filter:s})=>{let{count_assets:o}=await y(e);return o(t,k(s))},Kt=async({collection:t,fullPath:e,satellite:s})=>(await y(s)).del_asset(t,e),qt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await y(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Bt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await y(s);return d(await o(t,e))},$t=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await y(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>d(r))};var jt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var po=async t=>zt(t),uo=async t=>zt({filename:t.data.name,...t}),zt=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:p})=>{let T=u(r?.identity),f=decodeURI(t),h=i??`/${s}/${f}`,_={...r,identity:T};return await Ft({data:e,filename:f,collection:s,token:n,headers:o,fullPath:h,encoding:a,satellite:_,description:p}),{downloadUrl:Ht({satellite:_,assetKey:{fullPath:h,token:n}}),fullPath:h,name:f}},mo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:u(e?.identity)},{items:i,...n}=await Vt({collection:t,satellite:o,filter:s??{}}),r=i.map(({key:{full_path:a,token:p,name:T,owner:f,description:h},headers:_,encodings:w,created_at:v,updated_at:N})=>{let O=d(p);return{fullPath:a,description:d(h),name:T,downloadUrl:Ht({satellite:o,assetKey:{fullPath:a,token:O}}),token:O,headers:_,encodings:w.reduce((g,[S,{modified:E,sha256:V,total_length:U}])=>({...g,[S]:{modified:E,sha256:jt(V),total_length:U}}),{}),owner:f.toText(),created_at:v,updated_at:N}});return{items:r,assets:r,...n}},yo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:u(e?.identity)};return Mt({collection:t,satellite:o,filter:s??{}})},fo=async({collection:t,fullPath:e,satellite:s})=>Kt({collection:t,fullPath:e,satellite:{...s,identity:u(s?.identity)}}),go=async({assets:t,satellite:e})=>qt({assets:t,satellite:{...e,identity:u(e?.identity)}}),ho=async({satellite:t,...e})=>{let s=u(t?.identity);return Bt({...e,satellite:{...t,identity:s}})},_o=async({satellite:t,...e})=>{let s=u(t?.identity);return $t({...e,satellite:{...t,identity:s}})},Ht=({assetKey:{fullPath:t,token:e},satellite:s})=>{let o={...s,identity:u(s?.identity)};return`${_t(o)}${t}${l(e)?`?token=${e}`:""}`};var Oe=t=>{let e=t?.satelliteId??Et();K(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??Ut();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},Oo=async t=>Se(t),Se=async t=>{let e=Oe(t);x.getInstance().set(e),await et();let s=e.workers?.auth!==void 0?kt(e.workers.auth):void 0;return[...s?[s]:[]]},So=t=>P.getInstance().subscribe(t);export{B as InternetIdentityProvider,mt as NFIDProvider,So as authSubscribe,yo as countAssets,Us as countDocs,fo as deleteAsset,Rs as deleteDoc,go as deleteManyAssets,ks as deleteManyDocs,Ht as downloadUrl,ho as getAsset,St as getDoc,_o as getManyAssets,Ss as getManyDocs,Oo as initJuno,Se as initSatellite,mo as listAssets,Es as listDocs,bt as setDoc,bs as setManyDocs,Te as signIn,st as signOut,xe as unsafeIdentity,po as uploadBlob,uo as uploadFile};
3
+ import{Principal as rt}from"@dfinity/principal";var a=t=>t==null,l=t=>!a(t),me=class extends Error{},B=(t,e)=>{if(a(t))throw new me(e)},X="__bigint__",Q="__principal__",Z="__uint8array__",ye=(t,e)=>typeof e=="bigint"?{[X]:`${e}`}:l(e)&&e instanceof rt?{[Q]:e.toText()}:l(e)&&e instanceof Uint8Array?{[Z]:Array.from(e)}:e,fe=(t,e)=>{let s=o=>e[o];return l(e)&&typeof e=="object"&&X in e?BigInt(s(X)):l(e)&&typeof e=="object"&&Q in e?rt.fromText(s(Q)):l(e)&&typeof e=="object"&&Z in e?Uint8Array.from(s(Z)):e},m=t=>l(t)?[t]:[],d=t=>t?.[0],at=async t=>{let e=new Blob([JSON.stringify(t,ye)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},$=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),fe)},ct=()=>typeof window<"u";var O=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:s})=>s(e))}subscribe(e){let s=Symbol();return this.callbacks.push({id:s,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:o})=>o!==s)}};var N=class t extends O{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let s=super.subscribe(e);return e(this.authUser),s}reset(){this.authUser=null,this.populate(this.authUser)}};var I=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var lt=BigInt(144e11),pt=!1,dt={width:576,height:576},ut={width:505,height:705},mt="internetcomputer.org";var R="http://127.0.0.1:5987",yt="rdmx6-jaaaa-aaaaa-aaadq-cai";var _=class t extends O{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var D=({width:t,height:e})=>{if(!ct()||a(window)||a(window.top))return;let{top:{innerWidth:s,innerHeight:o}}=window,i=o/2+screenY-e/2,n=s/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${n}`};var j=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=_.getInstance().get()?.container;if(a(o)||o===!1)return`https://identity.${this.#t??mt}`;let i=_.getInstance().get(),n=l(i)&&l(i?.internetIdentityId)?i.internetIdentityId:yt,{host:r,protocol:c}=new URL(o===!0?R:o);return/apple/i.test(navigator?.vendor)?`${c}//${r}?canisterId=${n}`:`${c}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:D(dt)},identityProvider:s()}}},ft=class{#t;#e;constructor({appName:e,logoUrl:s}){this.#t=e,this.#e=s}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:D(ut)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{Actor as he}from"@dfinity/agent";import{HttpAgent as ge}from"@dfinity/agent";var k=class t{static instance;#t=void 0;constructor(){}static getInstance(){return a(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...s}){let o=e.getPrincipal().toText();if(a(this.#t)||a(this.#t[o])){let i=await this.createAgent({identity:e,...s});return this.#t={...this.#t??{},[o]:i},i}return this.#t[o]}reset(){this.#t=null}async createAgent({identity:e,fetch:s,container:o}){let n=l(o)&&o!==!1?o===!0?R:o:"https://icp-api.io",r=l(o);return await ge.create({identity:e,shouldFetchRootKey:r,host:n,...s&&{fetch:s}})}};var E=class t{static instance;#t=void 0;constructor(){}static getInstance(){return a(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:s,buildType:o,...i}){let n=`${o}#${s.getPrincipal().toText()}#${e};`;if(a(this.#t)||a(this.#t[n])){let r=await this.createActor({satelliteId:e,identity:s,...i});return this.#t={...this.#t??{},[n]:r},r}return this.#t[n]}reset(){this.#t=null}async createActor({idlFactory:e,satelliteId:s,...o}){let i=await k.getInstance().getAgent(o);return he.createActor(e,{agent:i,canisterId:s})}};import{AuthClient as Ae}from"@dfinity/auth-client";var H=()=>Ae.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var gt=async({data:t})=>{try{return await $(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var L=async t=>{let{data:e,version:s,description:o}=t;return{description:m(o),data:await at(e),version:m(s)}},tt=t=>{let{version:e}=t;return{version:m(e)}},V=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:d(i),owner:s.toText(),data:await $(n),version:d(o),...r}};import{Principal as Te}from"@dfinity/principal";var ht=t=>{if(a(t))return m();switch(t.matcher){case"equal":return m({Equal:t.timestamp});case"greaterThan":return m({GreaterThan:t.timestamp});case"lessThan":return m({LessThan:t.timestamp});case"between":return m({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},U=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:a(t)?[]:[{key:m(t.key),description:m(t.description),created_at:ht(t.createdAt),updated_at:ht(t.updatedAt)}],paginate:m(a(e)?void 0:{start_after:m(e.startAfter),limit:m(a(e.limit)?void 0:BigInt(e.limit))}),order:m(a(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:m(a(o)?void 0:typeof o=="string"?Te.fromText(o):o)});var At=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),s=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),o=t.Record({field:s,desc:t.Bool}),i=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),n=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(i),description:t.Opt(t.Text),created_at:t.Opt(i)}),r=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),c=t.Record({order:t.Opt(o),owner:t.Opt(t.Principal),matcher:t.Opt(n),paginate:t.Opt(r)}),u=t.Record({controllers:t.Vec(t.Principal)}),T=t.Variant({Write:t.Null,Admin:t.Null}),f=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:T,expires_at:t.Opt(t.Nat64)}),h=t.Record({version:t.Opt(t.Nat64)}),A=t.Variant({Db:t.Null,Storage:t.Null}),w=t.Record({version:t.Opt(t.Nat64)}),S=t.Record({cycles:t.Nat,destination_id:t.Principal}),P=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),v=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),g=t.Record({key:P,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,v)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),b=t.Record({derivation_origin:t.Opt(t.Text)}),C=t.Record({internet_identity:t.Opt(b)}),K=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),F=t.Record({max_memory_size:t.Opt(K)}),Jt=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),Xt=t.Variant({Deny:t.Null,Allow:t.Null}),Qt=t.Record({status_code:t.Nat16,location:t.Text}),G=t.Record({iframe:t.Opt(Jt),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),max_memory_size:t.Opt(K),raw_access:t.Opt(Xt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,Qt)))}),Zt=t.Record({db:t.Opt(F),authentication:t.Opt(C),storage:G}),M=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),It=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),Y=t.Variant({Heap:t.Null,Stable:t.Null}),J=t.Record({memory:Y,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),Dt=t.Variant({Callback:t.Record({token:J,callback:t.Func([],[],["query"])})}),Lt=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Dt),status_code:t.Nat16}),te=t.Record({token:t.Opt(J),body:t.Vec(t.Nat8)}),ee=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),se=t.Record({batch_id:t.Nat}),oe=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,g)),items_length:t.Nat64}),ie=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),ne=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,M)),items_length:t.Nat64}),q=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),re=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(Y),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:q,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:q}),ae=t.Record({stable:t.Nat64,heap:t.Nat64}),ce=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:T,expires_at:t.Opt(t.Nat64)}),le=t.Record({controller:ce,controllers:t.Vec(t.Principal)}),nt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),pe=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(Y),max_size:t.Opt(t.Nat),read:q,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:q}),de=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),ue=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text,c],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,c],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([u],[t.Vec(t.Tuple(t.Principal,f))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,h],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,h))],[],[]),del_rule:t.Func([A,t.Text,w],[],[]),deposit_cycles:t.Func([S],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(g)],["query"]),get_auth_config:t.Func([],[t.Opt(C)],["query"]),get_config:t.Func([],[Zt],[]),get_db_config:t.Func([],[t.Opt(F)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(M)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(g)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(M)))],["query"]),get_storage_config:t.Func([],[G],["query"]),http_request:t.Func([It],[Lt],["query"]),http_request_streaming_callback:t.Func([J],[te],["query"]),init_asset_upload:t.Func([ee],[se],[]),list_assets:t.Func([t.Text,c],[oe],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,f))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,ie))],["query"]),list_docs:t.Func([t.Text,c],[ne],["query"]),list_rules:t.Func([A],[t.Vec(t.Tuple(t.Text,re))],["query"]),memory_size:t.Func([],[ae],["query"]),set_auth_config:t.Func([C],[],[]),set_controllers:t.Func([le],[t.Vec(t.Tuple(t.Principal,f))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([F],[],[]),set_doc:t.Func([t.Text,t.Text,nt],[M],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,nt))],[t.Vec(t.Tuple(t.Text,M))],[]),set_rule:t.Func([A,t.Text,pe],[],[]),set_storage_config:t.Func([G],[],[]),upload_asset_chunk:t.Func([de],[ue],[]),version:t.Func([],[t.Text],["query"])})};var Tt=({satelliteId:t,container:e})=>{let{satelliteId:s}=et({satelliteId:t}),{container:o}=st({container:e});if(l(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?R:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},et=({satelliteId:t})=>l(t)?{satelliteId:t}:_.getInstance().get()??{satelliteId:void 0},st=({container:t})=>l(t)?{container:t}:_.getInstance().get()??{container:void 0};var y=async t=>xt({idlFactory:At,buildType:"stock",...t}),_t=async({idlFactory:t,...e})=>xt({idlFactory:t,buildType:"extended",...e}),xt=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=et({satelliteId:t});B(o,"No satellite ID defined. Did you initialize Juno?");let{container:i}=st({container:e});return await E.getInstance().getActor({satelliteId:o,container:i,...s})};var Pt=async({collection:t,key:e,satellite:s})=>{let{get_doc:o}=await y(s),i=d(await o(t,e));if(!a(i))return V({doc:i,key:e})},Nt=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await y(e),o=t.map(({collection:r,key:c})=>[r,c]),i=await s(o),n=[];for(let[r,c]of i){let u=d(c);n.push(l(u)?await V({key:r,doc:u}):void 0)}return n},wt=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await y(s),{key:i}=e,n=await L(e),r=await o(t,i,n);return await V({key:i,doc:r})},St=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await y(e),o=[];for(let{collection:r,doc:c}of t){let{key:u}=c;o.push([r,u,await L(c)])}let i=await s(o),n=[];for(let[r,c]of i)n.push(await V({key:r,doc:c}));return n},vt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await y(s),{key:i}=e;return o(t,i,tt(e))},bt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await y(e),o=t.map(({collection:i,doc:n})=>[i,n.key,tt(n)]);await s(o)},Ot=async({collection:t,filter:e,satellite:s})=>{let{list_docs:o}=await y(s),{items:i,items_page:n,items_length:r,matches_length:c,matches_pages:u}=await o(t,U(e)),T=[];for(let[f,h]of i){let{data:A,owner:w,description:S,version:P,...v}=h;T.push({key:f,description:d(S),owner:w.toText(),data:await gt({data:A}),version:d(P),...v})}return{items:T,items_length:r,items_page:d(n),matches_length:c,matches_pages:d(u)}},Rt=async({collection:t,filter:e,satellite:s})=>{let{count_docs:o}=await y(s);return o(t,U(e))};import{AnonymousIdentity as _e}from"@dfinity/agent";var p=t=>t!==void 0?t:z()??new _e;var kt=async({satellite:t,...e})=>{let s=p(t?.identity);return Pt({...e,satellite:{...t,identity:s}})},Fs=async({satellite:t,...e})=>{let s=p(t?.identity);return Nt({...e,satellite:{...t,identity:s}})},Et=async({satellite:t,...e})=>{let s=p(t?.identity);return wt({...e,satellite:{...t,identity:s}})},Ms=async({satellite:t,...e})=>{let s=p(t?.identity);return St({...e,satellite:{...t,identity:s}})},Vs=async({satellite:t,...e})=>{let s=p(t?.identity);return vt({...e,satellite:{...t,identity:s}})},Ks=async({satellite:t,...e})=>{let s=p(t?.identity);return bt({...e,satellite:{...t,identity:s}})},qs=async({satellite:t,filter:e,...s})=>{let o=p(t?.identity);return Ot({...s,filter:e??{},satellite:{...t,identity:o}})},Bs=async({satellite:t,filter:e,...s})=>{let o=p(t?.identity);return Rt({...s,filter:e??{},satellite:{...t,identity:o}})};var Ut=async t=>{let e=z();if(a(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await kt({collection:"#user",key:s});return a(o)?await xe({userId:s,provider:t}):o},xe=async({userId:t,...e})=>Et({collection:"#user",doc:{key:t,data:e}});var x,ot=async t=>{if(x=x??await H(),!(await x?.isAuthenticated()??!1))return;let s=await Ut(t);N.getInstance().set(s)},Pe=async t=>new Promise(async(e,s)=>{x=x??await H();let o=t?.provider??new j({});await x.login({onSuccess:async()=>{await ot(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??lt,allowPinAuthentication:t?.allowPin??pt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),it=async()=>{await x?.logout(),x=void 0,N.getInstance().reset(),E.getInstance().reset(),k.getInstance().reset()},z=()=>x?.getIdentity(),Ne=async()=>(x??await H()).getIdentity();var Ct=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{I({message:"junoSignOutAuthTimer"}),await it()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":I({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},N.getInstance().subscribe(i=>{if(a(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Ft=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_SATELLITE_ID??t():t()},Mt=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};var ao=async({idlFactory:t,satellite:e})=>{let s=p(e?.identity);return _t({idlFactory:t,...e,identity:s})};import"@dfinity/principal";var we=t=>t==null,Se=t=>!we(t),W=t=>Se(t)?[t]:[],ve=()=>typeof window<"u",Vt=async({asset:{data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:c},actor:u,init_asset_upload:T})=>{let{batch_id:f}=await T({collection:s,full_path:n,name:e,token:W(i),encoding_type:W(r),description:W(c)}),h=19e5,A=[],w=ve()?new Blob([await t.arrayBuffer()]):t,S=0n;for(let g=0;g<w.size;g+=h){let b=w.slice(g,g+h);A.push({batchId:f,chunk:b,actor:u,orderId:S}),S++}let P=[];for await(let g of be({uploadChunks:A}))P=[...P,...g];let v=o.find(([g,b])=>g.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await u.commit_asset_upload({batch_id:f,chunk_ids:P.map(({chunk_id:g})=>g),headers:[...o,...v||[]]})};async function*be({uploadChunks:t,limit:e=12}){for(let s=0;s<t.length;s=s+e){let o=t.slice(s,s+e);yield await Promise.all(o.map(i=>Oe(i)))}}var Oe=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:W(o)});var Kt=async({satellite:t,...e})=>{let s=await y(t);await Vt({actor:s,asset:e,init_asset_upload:async i=>await s.init_asset_upload(i)})},qt=async({collection:t,satellite:e,filter:s})=>{let{list_assets:o}=await y(e),{items:i,items_length:n,items_page:r,matches_length:c,matches_pages:u}=await o(t,U(s));return{items:i.map(([T,f])=>f),items_length:n,items_page:d(r),matches_length:c,matches_pages:d(u)}},Bt=async({collection:t,satellite:e,filter:s})=>{let{count_assets:o}=await y(e);return o(t,U(s))},$t=async({collection:t,fullPath:e,satellite:s})=>(await y(s)).del_asset(t,e),jt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await y(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Ht=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await y(s);return d(await o(t,e))},zt=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await y(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>d(r))};var Wt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var wo=async t=>Gt(t),So=async t=>Gt({filename:t.data.name,...t}),Gt=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:c,description:u})=>{let T=p(r?.identity),f=decodeURI(t),h=i??`/${s}/${f}`,A={...r,identity:T};return await Kt({data:e,filename:f,collection:s,token:n,headers:o,fullPath:h,encoding:c,satellite:A,description:u}),{downloadUrl:Yt({satellite:A,assetKey:{fullPath:h,token:n}}),fullPath:h,name:f}},vo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:p(e?.identity)},{items:i,...n}=await qt({collection:t,satellite:o,filter:s??{}}),r=i.map(({key:{full_path:c,token:u,name:T,owner:f,description:h},headers:A,encodings:w,created_at:S,updated_at:P})=>{let v=d(u);return{fullPath:c,description:d(h),name:T,downloadUrl:Yt({satellite:o,assetKey:{fullPath:c,token:v}}),token:v,headers:A,encodings:w.reduce((g,[b,{modified:C,sha256:K,total_length:F}])=>({...g,[b]:{modified:C,sha256:Wt(K),total_length:F}}),{}),owner:f.toText(),created_at:S,updated_at:P}});return{items:r,assets:r,...n}},bo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:p(e?.identity)};return Bt({collection:t,satellite:o,filter:s??{}})},Oo=async({collection:t,fullPath:e,satellite:s})=>$t({collection:t,fullPath:e,satellite:{...s,identity:p(s?.identity)}}),Ro=async({assets:t,satellite:e})=>jt({assets:t,satellite:{...e,identity:p(e?.identity)}}),ko=async({satellite:t,...e})=>{let s=p(t?.identity);return Ht({...e,satellite:{...t,identity:s}})},Eo=async({satellite:t,...e})=>{let s=p(t?.identity);return zt({...e,satellite:{...t,identity:s}})},Yt=({assetKey:{fullPath:t,token:e},satellite:s})=>{let o={...s,identity:p(s?.identity)};return`${Tt(o)}${t}${l(e)?`?token=${e}`:""}`};var Re=t=>{let e=t?.satelliteId??Ft();B(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??Mt();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},Bo=async t=>ke(t),ke=async t=>{let e=Re(t);_.getInstance().set(e),await ot();let s=e.workers?.auth!==void 0?Ct(e.workers.auth):void 0;return[...s?[s]:[]]},$o=t=>N.getInstance().subscribe(t);export{j as InternetIdentityProvider,ft as NFIDProvider,$o as authSubscribe,bo as countAssets,Bs as countDocs,Oo as deleteAsset,Vs as deleteDoc,Ro as deleteManyAssets,Ks as deleteManyDocs,Yt as downloadUrl,ko as getAsset,kt as getDoc,Eo as getManyAssets,Fs as getManyDocs,ao as getSatelliteExtendedActor,Bo as initJuno,ke as initSatellite,vo as listAssets,qs as listDocs,Et as setDoc,Ms as setManyDocs,Pe as signIn,it as signOut,Ne as unsafeIdentity,wo as uploadBlob,So as uploadFile};
4
4
  //# sourceMappingURL=index.mjs.map