@junobuild/core 0.1.14 → 0.1.15-next-2025-05-25

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