@junobuild/core-peer 0.1.2 → 0.1.4

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{assertNonNullish as ze}from"@dfinity/utils";import{isNullish as Be}from"@dfinity/utils";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 T=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)};import{isNullish as Ve}from"@dfinity/utils";var ut=BigInt(144e11),mt=!1,yt={width:576,height:576},ft={width:505,height:705},gt="internetcomputer.org";import{isNullish as Oe,nonNullish as xt}from"@dfinity/utils";var v="http://127.0.0.1:5987",ht="rdmx6-jaaaa-aaaaa-aaadq-cai";var h=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}};import{isNullish as Tt}from"@dfinity/utils";import{jsonReplacer as Ne,jsonReviver as Se}from"@dfinity/utils";var At=async t=>{let e=new Blob([JSON.stringify(t,Ne)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},B=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(),Se)},$=()=>typeof window<"u";var D=({width:t,height:e})=>{if(!$()||Tt(window)||Tt(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 H=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=h.getInstance().get()?.container;if(Oe(o)||o===!1)return`https://identity.${this.#t??gt}`;let i=h.getInstance().get(),n=xt(i)&&xt(i?.internetIdentityId)?i.internetIdentityId:ht,{host:r,protocol:a}=new URL(o===!0?v:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:D(yt)},identityProvider:s()}}},_t=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(ft)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{Actor as be}from"@dfinity/agent";import{isNullish as tt}from"@dfinity/utils";import{HttpAgent as ve}from"@dfinity/agent";import{isNullish as L,nonNullish as Pt}from"@dfinity/utils";var b=class t{static instance;#t=void 0;constructor(){}static getInstance(){return L(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...s}){let o=e.getPrincipal().toText();if(L(this.#t)||L(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=Pt(o)&&o!==!1?o===!0?v:o:"https://icp-api.io",r=Pt(o);return await ve.create({identity:e,shouldFetchRootKey:r,host:n,...s&&{fetch:s}})}};var R=class t{static instance;#t=void 0;constructor(){}static getInstance(){return tt(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(tt(this.#t)||tt(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 b.getInstance().getAgent(o);return be.createActor(e,{agent:i,canisterId:s})}};var M=class extends Error{},j=class extends Error{},z=class extends Error{};import{AuthClient as Re}from"@dfinity/auth-client";var et=()=>Re.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});import{isNullish as Ht}from"@dfinity/utils";import{fromNullable as E,isNullish as Ce,nonNullish as Ue}from"@dfinity/utils";var wt=async({data:t})=>{try{return await B(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};import{fromNullable as Nt,toNullable as st}from"@dfinity/utils";var ot=async t=>{let{data:e,version:s,description:o}=t;return{description:st(o),data:await At(e),version:st(s)}},it=t=>{let{version:e}=t;return{version:st(e)}},V=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:Nt(i),owner:s.toText(),data:await B(n),version:Nt(o),...r}};import{Principal as ke}from"@dfinity/principal";import{isNullish as k,toNullable as g}from"@dfinity/utils";var St=t=>{if(k(t))return g();switch(t.matcher){case"equal":return g({Equal:t.timestamp});case"greaterThan":return g({GreaterThan:t.timestamp});case"lessThan":return g({LessThan:t.timestamp});case"between":return g({Between:[t.timestamps.start,t.timestamps.end]});default:throw new z("Invalid list matcher for timestamp",t)}},N=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:k(t)?[]:[{key:g(t.key),description:g(t.description),created_at:St(t.createdAt),updated_at:St(t.updatedAt)}],paginate:g(k(e)?void 0:{start_after:g(e.startAfter),limit:g(k(e.limit)?void 0:BigInt(e.limit))}),order:g(k(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:g(k(o)?void 0:typeof o=="string"?ke.fromText(o):o)});import{assertNonNullish as Ee}from"@dfinity/utils";var Ot=({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)}),f=t.Variant({Write:t.Null,Admin:t.Null}),d=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:f,expires_at:t.Opt(t.Nat64)}),y=t.Record({version:t.Opt(t.Nat64)}),m=t.Variant({Db:t.Null,Storage:t.Null}),_=t.Record({version:t.Opt(t.Nat64)}),P=t.Record({cycles:t.Nat,destination_id:t.Principal}),A=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}),w=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),u=t.Record({key:A,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,w)),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)}),C=t.Record({internet_identity:t.Opt(S)}),K=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),U=t.Record({max_memory_size:t.Opt(K)}),ne=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),re=t.Variant({Deny:t.Null,Allow:t.Null}),ae=t.Record({status_code:t.Nat16,location:t.Text}),J=t.Record({iframe:t.Opt(ne),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(re),redirects:t.Opt(t.Vec(t.Tuple(t.Text,ae)))}),ce=t.Record({db:t.Opt(U),authentication:t.Opt(C),storage:J}),F=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)}),X=t.Variant({Heap:t.Null,Stable:t.Null}),q=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),pt=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),Q=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(X),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),rate_config:t.Opt(pt),write:q}),le=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)}),Z=t.Record({memory:X,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}),pe=t.Variant({Callback:t.Record({token:Z,callback:t.Func([],[],["query"])})}),de=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(pe),status_code:t.Nat16}),ue=t.Record({token:t.Opt(Z),body:t.Vec(t.Nat8)}),me=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}),ye=t.Record({batch_id:t.Nat}),fe=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,u)),items_length:t.Nat64}),ge=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),he=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,F)),items_length:t.Nat64}),Ae=t.Record({stable:t.Nat64,heap:t.Nat64}),Te=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:f,expires_at:t.Opt(t.Nat64)}),xe=t.Record({controller:Te,controllers:t.Vec(t.Principal)}),dt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),_e=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(X),max_size:t.Opt(t.Nat),read:q,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(pt),write:q}),Pe=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),we=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,d))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,y],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,a],[],[]),del_filtered_docs:t.Func([t.Text,a],[],[]),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,y))],[],[]),del_rule:t.Func([m,t.Text,_],[],[]),deposit_cycles:t.Func([P],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(u)],["query"]),get_auth_config:t.Func([],[t.Opt(C)],["query"]),get_config:t.Func([],[ce],[]),get_db_config:t.Func([],[t.Opt(U)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(F)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(u)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(F)))],["query"]),get_rule:t.Func([m,t.Text],[t.Opt(Q)],["query"]),get_storage_config:t.Func([],[J],["query"]),http_request:t.Func([le],[de],["query"]),http_request_streaming_callback:t.Func([Z],[ue],["query"]),init_asset_upload:t.Func([me],[ye],[]),list_assets:t.Func([t.Text,a],[fe],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,d))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,ge))],["query"]),list_docs:t.Func([t.Text,a],[he],["query"]),list_rules:t.Func([m],[t.Vec(t.Tuple(t.Text,Q))],["query"]),memory_size:t.Func([],[Ae],["query"]),set_auth_config:t.Func([C],[],[]),set_controllers:t.Func([xe],[t.Vec(t.Tuple(t.Principal,d))],[]),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,dt],[F],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,dt))],[t.Vec(t.Tuple(t.Text,F))],[]),set_rule:t.Func([m,t.Text,_e],[Q],[]),set_storage_config:t.Func([J],[],[]),upload_asset_chunk:t.Func([Pe],[we],[]),version:t.Func([],[t.Text],["query"])})};import{nonNullish as nt}from"@dfinity/utils";var vt=({satelliteId:t,container:e})=>{let{satelliteId:s}=rt({satelliteId:t}),{container:o}=at({container:e});if(nt(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?v:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},rt=({satelliteId:t})=>nt(t)?{satelliteId:t}:h.getInstance().get()??{satelliteId:void 0},at=({container:t})=>nt(t)?{container:t}:h.getInstance().get()??{container:void 0};var l=t=>Rt({idlFactory:Ot,buildType:"stock",...t}),bt=({idlFactory:t,...e})=>Rt({idlFactory:t,buildType:"extended",...e}),Rt=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=rt({satelliteId:t});Ee(o,"No satellite ID defined. Did you initialize Juno?");let{container:i}=at({container:e});return await R.getInstance().getActor({satelliteId:o,container:i,...s})};var kt=async({collection:t,key:e,satellite:s})=>{let{get_doc:o}=await l(s),i=E(await o(t,e));if(!Ce(i))return V({doc:i,key:e})},Et=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await l(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let p=E(a);n.push(Ue(p)?await V({key:r,doc:p}):void 0)}return n},Ct=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await l(s),{key:i}=e,n=await ot(e),r=await o(t,i,n);return await V({key:i,doc:r})},Ut=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await l(e),o=[];for(let{collection:r,doc:a}of t){let{key:p}=a;o.push([r,p,await ot(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await V({key:r,doc:a}));return n},Ft=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await l(s),{key:i}=e;return o(t,i,it(e))},Mt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await l(e),o=t.map(({collection:i,doc:n})=>[i,n.key,it(n)]);await s(o)},Vt=async({collection:t,filter:e,satellite:s})=>{let{del_filtered_docs:o}=await l(s);return o(t,N(e))},Kt=async({collection:t,filter:e,satellite:s})=>{let{list_docs:o}=await l(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:p}=await o(t,N(e)),f=[];for(let[d,y]of i){let{data:m,owner:_,description:P,version:A,...w}=y;f.push({key:d,description:E(P),owner:_.toText(),data:await wt({data:m}),version:E(A),...w})}return{items:f,items_length:r,items_page:E(n),matches_length:a,matches_pages:E(p)}},qt=async({collection:t,filter:e,satellite:s})=>{let{count_docs:o}=await l(s);return o(t,N(e))};import{AnonymousIdentity as Fe}from"@dfinity/agent";var c=t=>t!==void 0?t:W()??new Fe;var Bt=async({satellite:t,...e})=>{let s=c(t?.identity);return await kt({...e,satellite:{...t,identity:s}})},Ds=async({satellite:t,...e})=>{let s=c(t?.identity);return await Et({...e,satellite:{...t,identity:s}})},$t=async({satellite:t,...e})=>{let s=c(t?.identity);return await Ct({...e,satellite:{...t,identity:s}})},Ls=async({satellite:t,...e})=>{let s=c(t?.identity);return await Ut({...e,satellite:{...t,identity:s}})},to=async({satellite:t,...e})=>{let s=c(t?.identity);return await Ft({...e,satellite:{...t,identity:s}})},eo=async({satellite:t,...e})=>{let s=c(t?.identity);return await Mt({...e,satellite:{...t,identity:s}})},so=async({satellite:t,filter:e,...s})=>{let o=c(t?.identity);return await Vt({...s,filter:e??{},satellite:{...t,identity:o}})},oo=async({satellite:t,filter:e,...s})=>{let o=c(t?.identity);return await Kt({...s,filter:e??{},satellite:{...t,identity:o}})},io=async({satellite:t,filter:e,...s})=>{let o=c(t?.identity);return await qt({...s,filter:e??{},satellite:{...t,identity:o}})};var jt=async t=>{let e=W();if(Ht(e))throw new j("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await Bt({collection:"#user",key:s});return Ht(o)?await Me({userId:s,provider:t}):o},Me=({userId:t,...e})=>$t({collection:"#user",doc:{key:t,data:e}});var x,ct=async t=>{if(x=x??await et(),!(await x?.isAuthenticated()??!1))return;let s=await jt(t);T.getInstance().set(s)},Ke=t=>new Promise(async(e,s)=>{if(Ve(x)){s(new M("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}let o=t?.provider??new H({});await x.login({onSuccess:async()=>{await ct(o.id),e()},onError:i=>s(new M(i)),maxTimeToLive:t?.maxTimeToLive??ut,allowPinAuthentication:t?.allowPin??mt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),lt=async()=>{await x?.logout(),x=void 0,T.getInstance().reset(),R.getInstance().reset(),b.getInstance().reset()},W=()=>x?.getIdentity(),qe=async()=>(x??await et()).getIdentity();var zt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{I({message:"junoSignOutAuthTimer"}),await lt()};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}},T.getInstance().subscribe(i=>{if(Be(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Wt=()=>{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()},Gt=()=>{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 ko=async({idlFactory:t,satellite:e})=>{let s=c(e?.identity);return await bt({idlFactory:t,...e,identity:s})};import{fromNullable as se,nonNullish as je}from"@dfinity/utils";import{fromNullable as Y}from"@dfinity/utils";import{toNullable as G}from"@dfinity/utils";var Yt=async({asset:{data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a},actor:p,init_asset_upload:f})=>{let{batch_id:d}=await f({collection:s,full_path:n,name:e,token:G(i),encoding_type:G(r),description:G(a)}),y=19e5,m=[],_=$()?new Blob([await t.arrayBuffer()]):t,P=0n;for(let u=0;u<_.size;u+=y){let S=_.slice(u,u+y);m.push({batchId:d,chunk:S,actor:p,orderId:P}),P++}let A=[];for await(let u of $e({uploadChunks:m}))A=[...A,...u];let w=o.find(([u,S])=>u.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await p.commit_asset_upload({batch_id:d,chunk_ids:A.map(({chunk_id:u})=>u),headers:[...o,...w||[]]})};async function*$e({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=>He(i)))}}var He=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:G(o)});var Jt=async({satellite:t,...e})=>{let s=await l(t);await Yt({actor:s,asset:e,init_asset_upload:async i=>await s.init_asset_upload(i)})},Xt=async({collection:t,satellite:e,filter:s})=>{let{list_assets:o}=await l(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:p}=await o(t,N(s));return{items:i.map(([f,d])=>d),items_length:n,items_page:Y(r),matches_length:a,matches_pages:Y(p)}},Qt=async({collection:t,satellite:e,filter:s})=>{let{count_assets:o}=await l(e);return o(t,N(s))},Zt=async({collection:t,fullPath:e,satellite:s})=>(await l(s)).del_asset(t,e),It=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await l(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Dt=async({collection:t,satellite:e,filter:s})=>{let{del_filtered_assets:o}=await l(e);return o(t,N(s))},Lt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await l(s);return Y(await o(t,e))},te=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await l(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>Y(r))};var ee=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Yo=t=>oe(t),Jo=t=>oe({filename:t.data.name,...t}),oe=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:p})=>{let f=c(r?.identity),d=decodeURI(t),y=i??`/${s}/${d}`,m={...r,identity:f};return await Jt({data:e,filename:d,collection:s,token:n,headers:o,fullPath:y,encoding:a,satellite:m,description:p}),{downloadUrl:ie({satellite:m,assetKey:{fullPath:y,token:n}}),fullPath:y,name:d}},Xo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:c(e?.identity)},{items:i,...n}=await Xt({collection:t,satellite:o,filter:s??{}}),r=i.map(({key:{full_path:a,token:p,name:f,owner:d,description:y},headers:m,encodings:_,created_at:P,updated_at:A})=>{let w=se(p);return{fullPath:a,description:se(y),name:f,downloadUrl:ie({satellite:o,assetKey:{fullPath:a,token:w}}),token:w,headers:m,encodings:_.reduce((u,[S,{modified:C,sha256:K,total_length:U}])=>({...u,[S]:{modified:C,sha256:ee(K),total_length:U}}),{}),owner:d.toText(),created_at:P,updated_at:A}});return{items:r,assets:r,...n}},Qo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:c(e?.identity)};return await Qt({collection:t,satellite:o,filter:s??{}})},Zo=({collection:t,fullPath:e,satellite:s})=>Zt({collection:t,fullPath:e,satellite:{...s,identity:c(s?.identity)}}),Io=({assets:t,satellite:e})=>It({assets:t,satellite:{...e,identity:c(e?.identity)}}),Do=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:c(e?.identity)};return await Dt({collection:t,satellite:o,filter:s??{}})},Lo=async({satellite:t,...e})=>{let s=c(t?.identity);return await Lt({...e,satellite:{...t,identity:s}})},ti=async({satellite:t,...e})=>{let s=c(t?.identity);return await te({...e,satellite:{...t,identity:s}})},ie=({assetKey:{fullPath:t,token:e},satellite:s})=>{let o={...s,identity:c(s?.identity)};return`${vt(o)}${t}${je(e)?`?token=${e}`:""}`};var We=t=>{let e=t?.satelliteId??Wt();ze(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??Gt();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},ci=t=>Ge(t),Ge=async t=>{let e=We(t);h.getInstance().set(e),await ct();let s=e.workers?.auth!==void 0?zt(e.workers.auth):void 0;return[...s?[s]:[]]},li=t=>T.getInstance().subscribe(t);export{j as InitError,H as InternetIdentityProvider,z as ListError,_t as NFIDProvider,M as SignInError,li as authSubscribe,Qo as countAssets,io as countDocs,Zo as deleteAsset,to as deleteDoc,Do as deleteFilteredAssets,so as deleteFilteredDocs,Io as deleteManyAssets,eo as deleteManyDocs,ie as downloadUrl,Lo as getAsset,Bt as getDoc,ti as getManyAssets,Ds as getManyDocs,ko as getSatelliteExtendedActor,ci as initJuno,Ge as initSatellite,Xo as listAssets,oo as listDocs,$t as setDoc,Ls as setManyDocs,Ke as signIn,lt as signOut,qe as unsafeIdentity,Yo as uploadBlob,Jo as uploadFile};
3
+ import{assertNonNullish as Ge}from"@dfinity/utils";import{isNullish as He}from"@dfinity/utils";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 x=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 L=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};import{ERROR_USER_INTERRUPT as Ke}from"@dfinity/auth-client";import{isNullish as qe}from"@dfinity/utils";var mt=BigInt(144e11),yt=!1,ft={width:576,height:576},gt={width:505,height:705},ht="internetcomputer.org";import{isNullish as ve,nonNullish as _t}from"@dfinity/utils";var v="http://127.0.0.1:5987",At="rdmx6-jaaaa-aaaaa-aaadq-cai";var h=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}};import{isNullish as xt}from"@dfinity/utils";import{jsonReplacer as Se,jsonReviver as Oe}from"@dfinity/utils";var Tt=async t=>{let e=new Blob([JSON.stringify(t,Se)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},B=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(),Oe)},$=()=>typeof window<"u";var tt=({width:t,height:e})=>{if(!$()||xt(window)||xt(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 H=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=h.getInstance().get()?.container;if(ve(o)||o===!1)return`https://identity.${this.#t??ht}`;let i=h.getInstance().get(),n=_t(i)&&_t(i?.internetIdentityId)?i.internetIdentityId:At,{host:r,protocol:a}=new URL(o===!0?v:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:tt(ft)},identityProvider:s()}}},Pt=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:tt(gt)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{Actor as Re}from"@dfinity/agent";import{isNullish as st}from"@dfinity/utils";import{HttpAgent as be}from"@dfinity/agent";import{isNullish as et,nonNullish as wt}from"@dfinity/utils";var b=class t{static instance;#t=void 0;constructor(){}static getInstance(){return et(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...s}){let o=e.getPrincipal().toText();if(et(this.#t)||et(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=wt(o)&&o!==!1?o===!0?v:o:"https://icp-api.io",r=wt(o);return await be.create({identity:e,shouldFetchRootKey:r,host:n,...s&&{fetch:s}})}};var R=class t{static instance;#t=void 0;constructor(){}static getInstance(){return st(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(st(this.#t)||st(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 b.getInstance().getAgent(o);return Re.createActor(e,{agent:i,canisterId:s})}};var M=class extends Error{},z=class extends Error{},j=class extends Error{},W=class extends Error{};import{AuthClient as ke}from"@dfinity/auth-client";var G=()=>ke.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});import{isNullish as zt}from"@dfinity/utils";import{fromNullable as E,isNullish as Ue,nonNullish as Fe}from"@dfinity/utils";var Nt=async({data:t})=>{try{return await B(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};import{fromNullable as St,toNullable as ot}from"@dfinity/utils";var it=async t=>{let{data:e,version:s,description:o}=t;return{description:ot(o),data:await Tt(e),version:ot(s)}},nt=t=>{let{version:e}=t;return{version:ot(e)}},V=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:St(i),owner:s.toText(),data:await B(n),version:St(o),...r}};import{Principal as Ee}from"@dfinity/principal";import{isNullish as k,toNullable as g}from"@dfinity/utils";var Ot=t=>{if(k(t))return g();switch(t.matcher){case"equal":return g({Equal:t.timestamp});case"greaterThan":return g({GreaterThan:t.timestamp});case"lessThan":return g({LessThan:t.timestamp});case"between":return g({Between:[t.timestamps.start,t.timestamps.end]});default:throw new W("Invalid list matcher for timestamp",t)}},N=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:k(t)?[]:[{key:g(t.key),description:g(t.description),created_at:Ot(t.createdAt),updated_at:Ot(t.updatedAt)}],paginate:g(k(e)?void 0:{start_after:g(e.startAfter),limit:g(k(e.limit)?void 0:BigInt(e.limit))}),order:g(k(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:g(k(o)?void 0:typeof o=="string"?Ee.fromText(o):o)});import{assertNonNullish as Ce}from"@dfinity/utils";var vt=({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)}),f=t.Variant({Write:t.Null,Admin:t.Null}),d=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:f,expires_at:t.Opt(t.Nat64)}),y=t.Record({version:t.Opt(t.Nat64)}),m=t.Variant({Db:t.Null,Storage:t.Null}),_=t.Record({version:t.Opt(t.Nat64)}),P=t.Record({cycles:t.Nat,destination_id:t.Principal}),T=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}),w=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),u=t.Record({key:T,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,w)),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)}),C=t.Record({internet_identity:t.Opt(S)}),K=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),U=t.Record({max_memory_size:t.Opt(K)}),re=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),ae=t.Variant({Deny:t.Null,Allow:t.Null}),ce=t.Record({status_code:t.Nat16,location:t.Text}),Q=t.Record({iframe:t.Opt(re),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(ae),redirects:t.Opt(t.Vec(t.Tuple(t.Text,ce)))}),le=t.Record({db:t.Opt(U),authentication:t.Opt(C),storage:Q}),F=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)}),Z=t.Variant({Heap:t.Null,Stable:t.Null}),q=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),dt=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),I=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(Z),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),rate_config:t.Opt(dt),write:q}),pe=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)}),D=t.Record({memory:Z,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}),de=t.Variant({Callback:t.Record({token:D,callback:t.Func([],[],["query"])})}),ue=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(de),status_code:t.Nat16}),me=t.Record({token:t.Opt(D),body:t.Vec(t.Nat8)}),ye=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}),fe=t.Record({batch_id:t.Nat}),ge=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,u)),items_length:t.Nat64}),he=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),Ae=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,F)),items_length:t.Nat64}),Te=t.Record({stable:t.Nat64,heap:t.Nat64}),xe=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:f,expires_at:t.Opt(t.Nat64)}),_e=t.Record({controller:xe,controllers:t.Vec(t.Principal)}),ut=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(Z),max_size:t.Opt(t.Nat),read:q,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(dt),write:q}),we=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Ne=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,d))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,y],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,a],[],[]),del_filtered_docs:t.Func([t.Text,a],[],[]),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,y))],[],[]),del_rule:t.Func([m,t.Text,_],[],[]),deposit_cycles:t.Func([P],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(u)],["query"]),get_auth_config:t.Func([],[t.Opt(C)],["query"]),get_config:t.Func([],[le],[]),get_db_config:t.Func([],[t.Opt(U)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(F)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(u)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(F)))],["query"]),get_rule:t.Func([m,t.Text],[t.Opt(I)],["query"]),get_storage_config:t.Func([],[Q],["query"]),http_request:t.Func([pe],[ue],["query"]),http_request_streaming_callback:t.Func([D],[me],["query"]),init_asset_upload:t.Func([ye],[fe],[]),list_assets:t.Func([t.Text,a],[ge],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,d))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,he))],["query"]),list_docs:t.Func([t.Text,a],[Ae],["query"]),list_rules:t.Func([m],[t.Vec(t.Tuple(t.Text,I))],["query"]),memory_size:t.Func([],[Te],["query"]),set_auth_config:t.Func([C],[],[]),set_controllers:t.Func([_e],[t.Vec(t.Tuple(t.Principal,d))],[]),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,ut],[F],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,ut))],[t.Vec(t.Tuple(t.Text,F))],[]),set_rule:t.Func([m,t.Text,Pe],[I],[]),set_storage_config:t.Func([Q],[],[]),upload_asset_chunk:t.Func([we],[Ne],[]),version:t.Func([],[t.Text],["query"])})};import{nonNullish as rt}from"@dfinity/utils";var bt=({satelliteId:t,container:e})=>{let{satelliteId:s}=at({satelliteId:t}),{container:o}=ct({container:e});if(rt(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?v:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},at=({satelliteId:t})=>rt(t)?{satelliteId:t}:h.getInstance().get()??{satelliteId:void 0},ct=({container:t})=>rt(t)?{container:t}:h.getInstance().get()??{container:void 0};var l=t=>kt({idlFactory:vt,buildType:"stock",...t}),Rt=({idlFactory:t,...e})=>kt({idlFactory:t,buildType:"extended",...e}),kt=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=at({satelliteId:t});Ce(o,"No satellite ID defined. Did you initialize Juno?");let{container:i}=ct({container:e});return await R.getInstance().getActor({satelliteId:o,container:i,...s})};var Et=async({collection:t,key:e,satellite:s})=>{let{get_doc:o}=await l(s),i=E(await o(t,e));if(!Ue(i))return V({doc:i,key:e})},Ct=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await l(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let p=E(a);n.push(Fe(p)?await V({key:r,doc:p}):void 0)}return n},Ut=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await l(s),{key:i}=e,n=await it(e),r=await o(t,i,n);return await V({key:i,doc:r})},Ft=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await l(e),o=[];for(let{collection:r,doc:a}of t){let{key:p}=a;o.push([r,p,await it(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await V({key:r,doc:a}));return n},Mt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await l(s),{key:i}=e;return o(t,i,nt(e))},Vt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await l(e),o=t.map(({collection:i,doc:n})=>[i,n.key,nt(n)]);await s(o)},Kt=async({collection:t,filter:e,satellite:s})=>{let{del_filtered_docs:o}=await l(s);return o(t,N(e))},qt=async({collection:t,filter:e,satellite:s})=>{let{list_docs:o}=await l(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:p}=await o(t,N(e)),f=[];for(let[d,y]of i){let{data:m,owner:_,description:P,version:T,...w}=y;f.push({key:d,description:E(P),owner:_.toText(),data:await Nt({data:m}),version:E(T),...w})}return{items:f,items_length:r,items_page:E(n),matches_length:a,matches_pages:E(p)}},Bt=async({collection:t,filter:e,satellite:s})=>{let{count_docs:o}=await l(s);return o(t,N(e))};import{AnonymousIdentity as Me}from"@dfinity/agent";var c=t=>t!==void 0?t:Y()??new Me;var $t=async({satellite:t,...e})=>{let s=c(t?.identity);return await Et({...e,satellite:{...t,identity:s}})},to=async({satellite:t,...e})=>{let s=c(t?.identity);return await Ct({...e,satellite:{...t,identity:s}})},Ht=async({satellite:t,...e})=>{let s=c(t?.identity);return await Ut({...e,satellite:{...t,identity:s}})},eo=async({satellite:t,...e})=>{let s=c(t?.identity);return await Ft({...e,satellite:{...t,identity:s}})},so=async({satellite:t,...e})=>{let s=c(t?.identity);return await Mt({...e,satellite:{...t,identity:s}})},oo=async({satellite:t,...e})=>{let s=c(t?.identity);return await Vt({...e,satellite:{...t,identity:s}})},io=async({satellite:t,filter:e,...s})=>{let o=c(t?.identity);return await Kt({...s,filter:e??{},satellite:{...t,identity:o}})},no=async({satellite:t,filter:e,...s})=>{let o=c(t?.identity);return await qt({...s,filter:e??{},satellite:{...t,identity:o}})},ro=async({satellite:t,filter:e,...s})=>{let o=c(t?.identity);return await Bt({...s,filter:e??{},satellite:{...t,identity:o}})};var jt=async t=>{let e=Y();if(zt(e))throw new j("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await $t({collection:"#user",key:s});return zt(o)?await Ve({userId:s,provider:t}):o},Ve=({userId:t,...e})=>Ht({collection:"#user",doc:{key:t,data:e}});var A,lt=async t=>{if(A=A??await G(),!(await A?.isAuthenticated()??!1))return;let s=await jt(t);x.getInstance().set(s)},Be=t=>new Promise(async(e,s)=>{if(qe(A)){s(new M("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}let o=t?.provider??new H({});await A.login({onSuccess:async()=>{await lt(o.id),e()},onError:i=>{if(i===Ke){s(new z(i));return}s(new M(i))},maxTimeToLive:t?.maxTimeToLive??mt,allowPinAuthentication:t?.allowPin??yt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),pt=async()=>{await A?.logout(),A=null,x.getInstance().reset(),R.getInstance().reset(),b.getInstance().reset(),A=await G()},Y=()=>A?.getIdentity(),$e=async()=>(A??await G()).getIdentity();var Wt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{L({message:"junoSignOutAuthTimer"}),await pt()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":L({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},x.getInstance().subscribe(i=>{if(He(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Gt=()=>{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()},Yt=()=>{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 Fo=async({idlFactory:t,satellite:e})=>{let s=c(e?.identity);return await Rt({idlFactory:t,...e,identity:s})};import{fromNullable as oe,nonNullish as We}from"@dfinity/utils";import{fromNullable as X}from"@dfinity/utils";import{toNullable as J}from"@dfinity/utils";var Jt=async({asset:{data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a},actor:p,init_asset_upload:f})=>{let{batch_id:d}=await f({collection:s,full_path:n,name:e,token:J(i),encoding_type:J(r),description:J(a)}),y=19e5,m=[],_=$()?new Blob([await t.arrayBuffer()]):t,P=0n;for(let u=0;u<_.size;u+=y){let S=_.slice(u,u+y);m.push({batchId:d,chunk:S,actor:p,orderId:P}),P++}let T=[];for await(let u of ze({uploadChunks:m}))T=[...T,...u];let w=o.find(([u,S])=>u.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await p.commit_asset_upload({batch_id:d,chunk_ids:T.map(({chunk_id:u})=>u),headers:[...o,...w||[]]})};async function*ze({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=>je(i)))}}var je=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:J(o)});var Xt=async({satellite:t,...e})=>{let s=await l(t);await Jt({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 l(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:p}=await o(t,N(s));return{items:i.map(([f,d])=>d),items_length:n,items_page:X(r),matches_length:a,matches_pages:X(p)}},Zt=async({collection:t,satellite:e,filter:s})=>{let{count_assets:o}=await l(e);return o(t,N(s))},It=async({collection:t,fullPath:e,satellite:s})=>(await l(s)).del_asset(t,e),Dt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await l(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Lt=async({collection:t,satellite:e,filter:s})=>{let{del_filtered_assets:o}=await l(e);return o(t,N(s))},te=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await l(s);return X(await o(t,e))},ee=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await l(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>X(r))};var se=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Zo=t=>ie(t),Io=t=>ie({filename:t.data.name,...t}),ie=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:p})=>{let f=c(r?.identity),d=decodeURI(t),y=i??`/${s}/${d}`,m={...r,identity:f};return await Xt({data:e,filename:d,collection:s,token:n,headers:o,fullPath:y,encoding:a,satellite:m,description:p}),{downloadUrl:ne({satellite:m,assetKey:{fullPath:y,token:n}}),fullPath:y,name:d}},Do=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:c(e?.identity)},{items:i,...n}=await Qt({collection:t,satellite:o,filter:s??{}}),r=i.map(({key:{full_path:a,token:p,name:f,owner:d,description:y},headers:m,encodings:_,created_at:P,updated_at:T})=>{let w=oe(p);return{fullPath:a,description:oe(y),name:f,downloadUrl:ne({satellite:o,assetKey:{fullPath:a,token:w}}),token:w,headers:m,encodings:_.reduce((u,[S,{modified:C,sha256:K,total_length:U}])=>({...u,[S]:{modified:C,sha256:se(K),total_length:U}}),{}),owner:d.toText(),created_at:P,updated_at:T}});return{items:r,assets:r,...n}},Lo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:c(e?.identity)};return await Zt({collection:t,satellite:o,filter:s??{}})},ti=({collection:t,fullPath:e,satellite:s})=>It({collection:t,fullPath:e,satellite:{...s,identity:c(s?.identity)}}),ei=({assets:t,satellite:e})=>Dt({assets:t,satellite:{...e,identity:c(e?.identity)}}),si=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:c(e?.identity)};return await Lt({collection:t,satellite:o,filter:s??{}})},oi=async({satellite:t,...e})=>{let s=c(t?.identity);return await te({...e,satellite:{...t,identity:s}})},ii=async({satellite:t,...e})=>{let s=c(t?.identity);return await ee({...e,satellite:{...t,identity:s}})},ne=({assetKey:{fullPath:t,token:e},satellite:s})=>{let o={...s,identity:c(s?.identity)};return`${bt(o)}${t}${We(e)?`?token=${e}`:""}`};var Ye=t=>{let e=t?.satelliteId??Gt();Ge(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??Yt();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},ui=t=>Je(t),Je=async t=>{let e=Ye(t);h.getInstance().set(e),await lt();let s=e.workers?.auth!==void 0?Wt(e.workers.auth):void 0;return[...s?[s]:[]]},mi=t=>x.getInstance().subscribe(t);export{j as InitError,H as InternetIdentityProvider,W as ListError,Pt as NFIDProvider,M as SignInError,z as SignInUserInterruptError,mi as authSubscribe,Lo as countAssets,ro as countDocs,ti as deleteAsset,so as deleteDoc,si as deleteFilteredAssets,io as deleteFilteredDocs,ei as deleteManyAssets,oo as deleteManyDocs,ne as downloadUrl,oi as getAsset,$t as getDoc,ii as getManyAssets,to as getManyDocs,Fo as getSatelliteExtendedActor,ui as initJuno,Je as initSatellite,Do as listAssets,no as listDocs,Ht as setDoc,eo as setManyDocs,Be as signIn,pt as signOut,$e as unsafeIdentity,Zo as uploadBlob,Io as uploadFile};
4
4
  //# sourceMappingURL=index.mjs.map