@junobuild/core-peer 0.0.18 → 0.0.20
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.
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +4 -4
- package/dist/types/api/storage.api.d.ts +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/services/storage.services.d.ts +18 -1
- package/dist/types/types/storage.types.d.ts +1 -135
- package/package.json +3 -2
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
-
import{Principal as ot}from"@dfinity/principal";var c=t=>t==null,l=t=>!c(t),te=class extends Error{},F=(t,e)=>{if(c(t))throw new te(e)},z="__bigint__",W="__principal__",G="__uint8array__",ee=(t,e)=>typeof e=="bigint"?{[z]:`${e}`}:l(e)&&e instanceof ot?{[W]:e.toText()}:l(e)&&e instanceof Uint8Array?{[G]:Array.from(e)}:e,se=(t,e)=>{let s=o=>e[o];return l(e)&&typeof e=="object"&&z in e?BigInt(s(z)):l(e)&&typeof e=="object"&&W in e?ot.fromText(s(W)):l(e)&&typeof e=="object"&&G in e?Uint8Array.from(s(G)):e},m=t=>l(t)?[t]:[],p=t=>t?.[0],nt=async t=>{let e=new Blob([JSON.stringify(t,ee)],{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(),se)},M=()=>typeof window<"u";var b=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:s})=>s(e))}subscribe(e){let s=Symbol();return this.callbacks.push({id:s,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:o})=>o!==s)}};var w=class t extends b{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let s=super.subscribe(e);return e(this.authUser),s}reset(){this.authUser=null,this.populate(this.authUser)}};var Y=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var it=BigInt(144e11),rt=!1,at={width:576,height:576},ct={width:505,height:705},lt="internetcomputer.org";var R="http://127.0.0.1:5987",pt="rdmx6-jaaaa-aaaaa-aaadq-cai";var x=class t extends b{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var J=({width:t,height:e})=>{if(!M()||c(window)||c(window.top))return;let{top:{innerWidth:s,innerHeight:o}}=window,n=o/2+screenY-e/2,i=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=${n}, left=${i}`};var $=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=x.getInstance().get()?.container;if(c(o)||o===!1)return`https://identity.${this.#t??lt}`;let n=x.getInstance().get(),i=l(n)&&l(n?.internetIdentityId)?n.internetIdentityId:pt,{host:r,protocol:a}=new URL(o===!0?R:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${i}`:`${a}//${i}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:J(at)},identityProvider:s()}}},dt=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:J(ct)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as oe}from"@dfinity/auth-client";var B=()=>oe.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var ut=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}};var X=async t=>{let{data:e,version:s,description:o}=t;return{description:m(o),data:await nt(e),version:m(s)}},Q=t=>{let{version:e}=t;return{version:m(e)}},U=async({doc:t,key:e})=>{let{owner:s,version:o,description:n,data:i,...r}=t;return{key:e,description:p(n),owner:s.toText(),data:await V(i),version:p(o),...r}};import{Principal as ne}from"@dfinity/principal";var K=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:c(t)?[]:[{key:m(t.key),description:m(t.description)}],paginate:m(c(e)?void 0:{start_after:m(e.startAfter),limit:m(c(e.limit)?void 0:BigInt(e.limit))}),order:m(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:m(c(o)?void 0:typeof o=="string"?ne.fromText(o):o)});var mt=({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.Record({controllers:t.Vec(t.Principal)}),o=t.Variant({Write:t.Null,Admin:t.Null}),n=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:o,expires_at:t.Opt(t.Nat64)}),i=t.Record({version:t.Opt(t.Nat64)}),r=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({cycles:t.Nat,destination_id:t.Principal}),d=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}),h=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),y=t.Record({key:d,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,h)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),T=t.Record({derivation_origin:t.Opt(t.Text)}),_=t.Record({internet_identity:t.Opt(T)}),v=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),O=t.Variant({Deny:t.Null,Allow:t.Null}),N=t.Record({status_code:t.Nat16,location:t.Text}),S=t.Record({iframe:t.Opt(v),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),raw_access:t.Opt(O),redirects:t.Opt(t.Vec(t.Tuple(t.Text,N)))}),u=t.Record({storage:S}),A=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)}),j=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)}),k=t.Variant({Heap:t.Null,Stable:t.Null}),C=t.Record({memory:k,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}),H=t.Variant({Callback:t.Record({token:C,callback:t.Func([],[],["query"])})}),Mt=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(H),status_code:t.Nat16}),$t=t.Record({token:t.Opt(C),body:t.Vec(t.Nat8)}),Bt=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}),Kt=t.Record({batch_id:t.Nat}),qt=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),jt=t.Record({field:qt,desc:t.Bool}),Ht=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),zt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),et=t.Record({order:t.Opt(jt),owner:t.Opt(t.Principal),matcher:t.Opt(Ht),paginate:t.Opt(zt)}),Wt=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,y)),items_length:t.Nat64}),Gt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),Yt=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,A)),items_length:t.Nat64}),E=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Jt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(k),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:E,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:E}),Xt=t.Record({stable:t.Nat64,heap:t.Nat64}),Qt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),Zt=t.Record({controller:Qt,controllers:t.Vec(t.Principal)}),st=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),Dt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(k),max_size:t.Opt(t.Nat),read:E,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:E}),It=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Lt=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],[t.Nat64],["query"]),count_docs:t.Func([t.Text],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([s],[t.Vec(t.Tuple(t.Principal,n))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,i],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,i))],[],[]),del_rule:t.Func([r,t.Text,i],[],[]),deposit_cycles:t.Func([a],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(y)],["query"]),get_auth_config:t.Func([],[t.Opt(_)],["query"]),get_config:t.Func([],[u],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(A)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(y)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(A)))],["query"]),http_request:t.Func([j],[Mt],["query"]),http_request_streaming_callback:t.Func([C],[$t],["query"]),init_asset_upload:t.Func([Bt],[Kt],[]),list_assets:t.Func([t.Text,et],[Wt],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,n))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Gt))],["query"]),list_docs:t.Func([t.Text,et],[Yt],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,Jt))],["query"]),memory_size:t.Func([],[Xt],["query"]),set_auth_config:t.Func([_],[],[]),set_config:t.Func([u],[],[]),set_controllers:t.Func([Zt],[t.Vec(t.Tuple(t.Principal,n))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,st],[A],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,st))],[t.Vec(t.Tuple(t.Text,A))],[]),set_rule:t.Func([r,t.Text,Dt],[],[]),upload_asset_chunk:t.Func([It],[Lt],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as ie,HttpAgent as re}from"@dfinity/agent";var yt=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:n})=>{let r=l(n)&&n!==!1?n===!0?R:n:"https://icp-api.io",a=new re({identity:s,host:r,...o&&{fetch:o}});return l(n)&&await a.fetchRootKey(),ie.createActor(e,{agent:a,canisterId:t})};var Z=({satelliteId:t,container:e})=>{let{satelliteId:s}=D({satelliteId:t}),{container:o}=I({container:e});if(l(o)&&o!==!1){let{host:n,protocol:i}=new URL(o===!0?R:o);return`${i}//${s??"unknown"}.${n.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},D=({satelliteId:t})=>l(t)?{satelliteId:t}:x.getInstance().get()??{satelliteId:void 0},I=({container:t})=>l(t)?{container:t}:x.getInstance().get()??{container:void 0};var f=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=D({satelliteId:t});F(o,"No satellite ID defined. Did you initialize Juno?");let{container:n}=I({container:e});return yt({satelliteId:o,container:n,idlFactory:mt,...s})};var ft=async({collection:t,key:e,satellite:s})=>{let o=await f(s),n=p(await o.get_doc(t,e));if(!c(n))return U({doc:n,key:e})},gt=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await f(e),o=t.map(({collection:r,key:a})=>[r,a]),n=await s(o),i=[];for(let[r,a]of n){let d=p(a);i.push(l(d)?await U({key:r,doc:d}):void 0)}return i},ht=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await f(s),{key:n}=e,i=await X(e),r=await o(t,n,i);return await U({key:n,doc:r})},Tt=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await f(e),o=[];for(let{collection:r,doc:a}of t){let{key:d}=a;o.push([r,d,await X(a)])}let n=await s(o),i=[];for(let[r,a]of n)i.push(await U({key:r,doc:a}));return i},_t=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await f(s),{key:n}=e;return o(t,n,Q(e))},At=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await f(e),o=t.map(({collection:n,doc:i})=>[n,i.key,Q(i)]);await s(o)},xt=async({collection:t,filter:e,satellite:s})=>{let o=await f(s),{items:n,items_page:i,items_length:r,matches_length:a,matches_pages:d}=await o.list_docs(t,K(e)),h=[];for(let[y,T]of n){let{data:_,owner:v,description:O,version:N,...S}=T;h.push({key:y,description:p(O),owner:v.toText(),data:await ut({data:_}),version:p(N),...S})}return{items:h,items_length:r,items_page:p(i),matches_length:a,matches_pages:p(d)}};import{AnonymousIdentity as ae}from"@dfinity/agent";var g=t=>t!==void 0?t:q()??new ae;var Pt=async({satellite:t,...e})=>{let s=g(t?.identity);return ft({...e,satellite:{...t,identity:s}})},ys=async({satellite:t,...e})=>{let s=g(t?.identity);return gt({...e,satellite:{...t,identity:s}})},Nt=async({satellite:t,...e})=>{let s=g(t?.identity);return ht({...e,satellite:{...t,identity:s}})},fs=async({satellite:t,...e})=>{let s=g(t?.identity);return Tt({...e,satellite:{...t,identity:s}})},gs=async({satellite:t,...e})=>{let s=g(t?.identity);return _t({...e,satellite:{...t,identity:s}})},hs=async({satellite:t,...e})=>{let s=g(t?.identity);return At({...e,satellite:{...t,identity:s}})},Ts=async({satellite:t,filter:e,...s})=>{let o=g(t?.identity);return xt({...s,filter:e??{},satellite:{...t,identity:o}})};var wt=async t=>{let e=q();if(c(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await Pt({collection:"#user",key:s});return c(o)?await ce({userId:s,provider:t}):o},ce=async({userId:t,...e})=>Nt({collection:"#user",doc:{key:t,data:e}});var P,L=async t=>{if(P=P??await B(),!(await P?.isAuthenticated()??!1))return;let s=await wt(t);w.getInstance().set(s)},le=async t=>new Promise(async(e,s)=>{P=P??await B();let o=t?.provider??new $({});await P.login({onSuccess:async()=>{await L(o.id),e()},onError:n=>s(n),maxTimeToLive:t?.maxTimeToLive??it,allowPinAuthentication:t?.allowPin??rt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),tt=async()=>{await P?.logout(),P=void 0,w.getInstance().reset()},q=()=>P?.getIdentity(),pe=async()=>(P??await B()).getIdentity();var vt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{Y({message:"junoSignOutAuthTimer"}),await tt()};return s.onmessage=async({data:n})=>{let{msg:i,data:r}=n;switch(i){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":Y({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},w.getInstance().subscribe(n=>{if(c(n)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Ot=()=>{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()},St=()=>{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 bt=async({data:t,filename:e,collection:s,headers:o,token:n,fullPath:i,encoding:r,description:a,satellite:d})=>{let h=await f(d),{batch_id:y}=await h.init_asset_upload({collection:s,full_path:i,name:e,token:m(n),encoding_type:m(r),description:m(a)}),T=19e5,_=[],v=M()?new Blob([await t.arrayBuffer()]):t,O=0n;for(let u=0;u<v.size;u+=T){let A=v.slice(u,u+T);_.push({batchId:y,chunk:A,actor:h,orderId:O}),O++}let N=[];for await(let u of de({uploadChunks:_}))N=[...N,...u];let S=o.find(([u,A])=>u.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await h.commit_asset_upload({batch_id:y,chunk_ids:N.map(({chunk_id:u})=>u),headers:[...o,...S||[]]})};async function*de({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=>ue(i)))}}var ue=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:m(o)}),Rt=async({collection:t,satellite:e,filter:s})=>{let o=await f(e),{items:n,items_length:i,items_page:r,matches_length:a,matches_pages:d}=await o.list_assets(t,K(s));return{items:n.map(([h,y])=>y),items_length:i,items_page:p(r),matches_length:a,matches_pages:p(d)}},kt=async({collection:t,fullPath:e,satellite:s})=>(await f(s)).del_asset(t,e),Ct=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await f(e),o=t.map(({collection:n,fullPath:i})=>[n,i]);await s(o)},Ut=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await f(s);return p(await o(t,e))},Et=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await f(e),o=t.map(({collection:i,fullPath:r})=>[i,r]);return(await s(o)).map(([i,r])=>p(r))};var Ft=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Ys=async t=>Vt(t),Js=async t=>Vt({filename:t.data.name,...t}),Vt=async({filename:t,data:e,collection:s,headers:o=[],fullPath:n,token:i,satellite:r,encoding:a,description:d})=>{let h=g(r?.identity),y=decodeURI(t),T=n??`/${s}/${y}`,_={...r,identity:h};return await bt({data:e,filename:y,collection:s,token:i,headers:o,fullPath:T,encoding:a,satellite:_,description:d}),{downloadUrl:`${Z(_)}${T}${i!==void 0?`?token=${i}`:""}`,fullPath:T,name:y}},Xs=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:g(e?.identity)},{items:n,...i}=await Rt({collection:t,satellite:o,filter:s??{}}),r=Z(o),a=n.map(({key:{full_path:d,token:h,name:y,owner:T,description:_},headers:v,encodings:O,created_at:N,updated_at:S})=>{let u=p(h);return{fullPath:d,description:p(_),name:y,downloadUrl:`${r}${d}${u!==void 0?`?token=${u}`:""}`,token:u,headers:v,encodings:O.reduce((A,[j,{modified:k,sha256:C,total_length:H}])=>({...A,[j]:{modified:k,sha256:Ft(C),total_length:H}}),{}),owner:T.toText(),created_at:N,updated_at:S}});return{items:a,assets:a,...i}},Qs=async({collection:t,fullPath:e,satellite:s})=>kt({collection:t,fullPath:e,satellite:{...s,identity:g(s?.identity)}}),Zs=async({assets:t,satellite:e})=>Ct({assets:t,satellite:{...e,identity:g(e?.identity)}}),Ds=async({satellite:t,...e})=>{let s=g(t?.identity);return Ut({...e,satellite:{...t,identity:s}})},Is=async({satellite:t,...e})=>{let s=g(t?.identity);return Et({...e,satellite:{...t,identity:s}})};var me=t=>{let e=t?.satelliteId??Ot();F(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??St();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},ro=async t=>ye(t),ye=async t=>{let e=me(t);x.getInstance().set(e),await L();let s=e.workers?.auth!==void 0?vt(e.workers.auth):void 0;return[...s?[s]:[]]},ao=t=>w.getInstance().subscribe(t);export{$ as InternetIdentityProvider,dt as NFIDProvider,ao as authSubscribe,Qs as deleteAsset,gs as deleteDoc,Zs as deleteManyAssets,hs as deleteManyDocs,Ds as getAsset,Pt as getDoc,Is as getManyAssets,ys as getManyDocs,ro as initJuno,ye as initSatellite,Xs as listAssets,Ts as listDocs,Nt as setDoc,fs as setManyDocs,le as signIn,tt as signOut,pe as unsafeIdentity,Ys as uploadBlob,Js as uploadFile};
|
|
3
|
+
import{Principal as et}from"@dfinity/principal";var l=t=>t==null,c=t=>!l(t),oe=class extends Error{},F=(t,e)=>{if(l(t))throw new oe(e)},H="__bigint__",z="__principal__",W="__uint8array__",ie=(t,e)=>typeof e=="bigint"?{[H]:`${e}`}:c(e)&&e instanceof et?{[z]:e.toText()}:c(e)&&e instanceof Uint8Array?{[W]:Array.from(e)}:e,ne=(t,e)=>{let s=o=>e[o];return c(e)&&typeof e=="object"&&H in e?BigInt(s(H)):c(e)&&typeof e=="object"&&z in e?et.fromText(s(z)):c(e)&&typeof e=="object"&&W in e?Uint8Array.from(s(W)):e},_=t=>c(t)?[t]:[],p=t=>t?.[0],st=async t=>{let e=new Blob([JSON.stringify(t,ie)],{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(),ne)},ot=()=>typeof window<"u";var b=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:s})=>s(e))}subscribe(e){let s=Symbol();return this.callbacks.push({id:s,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:o})=>o!==s)}};var w=class t extends b{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let s=super.subscribe(e);return e(this.authUser),s}reset(){this.authUser=null,this.populate(this.authUser)}};var Y=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var it=BigInt(144e11),nt=!1,rt={width:576,height:576},at={width:505,height:705},ct="internetcomputer.org";var R="http://127.0.0.1:5987",lt="rdmx6-jaaaa-aaaaa-aaadq-cai";var x=class t extends b{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var G=({width:t,height:e})=>{if(!ot()||l(window)||l(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 M=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=x.getInstance().get()?.container;if(l(o)||o===!1)return`https://identity.${this.#t??ct}`;let i=x.getInstance().get(),n=c(i)&&c(i?.internetIdentityId)?i.internetIdentityId:lt,{host:r,protocol:a}=new URL(o===!0?R:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:G(rt)},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:G(at)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as re}from"@dfinity/auth-client";var K=()=>re.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var dt=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}};var J=async t=>{let{data:e,version:s,description:o}=t;return{description:_(o),data:await st(e),version:_(s)}},X=t=>{let{version:e}=t;return{version:_(e)}},U=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:p(i),owner:s.toText(),data:await V(n),version:p(o),...r}};import{Principal as ae}from"@dfinity/principal";var $=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:l(t)?[]:[{key:_(t.key),description:_(t.description)}],paginate:_(l(e)?void 0:{start_after:_(e.startAfter),limit:_(l(e.limit)?void 0:BigInt(e.limit))}),order:_(l(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:_(l(o)?void 0:typeof o=="string"?ae.fromText(o):o)});var ut=({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.Record({controllers:t.Vec(t.Principal)}),o=t.Variant({Write:t.Null,Admin:t.Null}),i=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:o,expires_at:t.Opt(t.Nat64)}),n=t.Record({version:t.Opt(t.Nat64)}),r=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({cycles:t.Nat,destination_id:t.Principal}),d=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}),A=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),u=t.Record({key:d,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,A)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),g=t.Record({derivation_origin:t.Opt(t.Text)}),h=t.Record({internet_identity:t.Opt(g)}),v=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),O=t.Variant({Deny:t.Null,Allow:t.Null}),P=t.Record({status_code:t.Nat16,location:t.Text}),S=t.Record({iframe:t.Opt(v),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),raw_access:t.Opt(O),redirects:t.Opt(t.Vec(t.Tuple(t.Text,P)))}),y=t.Record({storage:S}),T=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)}),j=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)}),k=t.Variant({Heap:t.Null,Stable:t.Null}),E=t.Record({memory:k,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}),$t=t.Variant({Callback:t.Record({token:E,callback:t.Func([],[],["query"])})}),Bt=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt($t),status_code:t.Nat16}),qt=t.Record({token:t.Opt(E),body:t.Vec(t.Nat8)}),jt=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}),Ht=t.Record({batch_id:t.Nat}),zt=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),Wt=t.Record({field:zt,desc:t.Bool}),Yt=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),Gt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),L=t.Record({order:t.Opt(Wt),owner:t.Opt(t.Principal),matcher:t.Opt(Yt),paginate:t.Opt(Gt)}),Jt=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}),Xt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),Qt=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,T)),items_length:t.Nat64}),C=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Zt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(k),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:C,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:C}),It=t.Record({stable:t.Nat64,heap:t.Nat64}),Dt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),Lt=t.Record({controller:Dt,controllers:t.Vec(t.Principal)}),tt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),te=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(k),max_size:t.Opt(t.Nat),read:C,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:C}),ee=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),se=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],[t.Nat64],["query"]),count_docs:t.Func([t.Text],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([s],[t.Vec(t.Tuple(t.Principal,i))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,n],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,n))],[],[]),del_rule:t.Func([r,t.Text,n],[],[]),deposit_cycles:t.Func([a],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(u)],["query"]),get_auth_config:t.Func([],[t.Opt(h)],["query"]),get_config:t.Func([],[y],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(T)],["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(T)))],["query"]),http_request:t.Func([j],[Bt],["query"]),http_request_streaming_callback:t.Func([E],[qt],["query"]),init_asset_upload:t.Func([jt],[Ht],[]),list_assets:t.Func([t.Text,L],[Jt],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Xt))],["query"]),list_docs:t.Func([t.Text,L],[Qt],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,Zt))],["query"]),memory_size:t.Func([],[It],["query"]),set_auth_config:t.Func([h],[],[]),set_config:t.Func([y],[],[]),set_controllers:t.Func([Lt],[t.Vec(t.Tuple(t.Principal,i))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,tt],[T],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,tt))],[t.Vec(t.Tuple(t.Text,T))],[]),set_rule:t.Func([r,t.Text,te],[],[]),upload_asset_chunk:t.Func([ee],[se],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as ce,HttpAgent as le}from"@dfinity/agent";var mt=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:i})=>{let r=c(i)&&i!==!1?i===!0?R:i:"https://icp-api.io",a=new le({identity:s,host:r,...o&&{fetch:o}});return c(i)&&await a.fetchRootKey(),ce.createActor(e,{agent:a,canisterId:t})};var yt=({satelliteId:t,container:e})=>{let{satelliteId:s}=Q({satelliteId:t}),{container:o}=Z({container:e});if(c(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?R:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},Q=({satelliteId:t})=>c(t)?{satelliteId:t}:x.getInstance().get()??{satelliteId:void 0},Z=({container:t})=>c(t)?{container:t}:x.getInstance().get()??{container:void 0};var f=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=Q({satelliteId:t});F(o,"No satellite ID defined. Did you initialize Juno?");let{container:i}=Z({container:e});return mt({satelliteId:o,container:i,idlFactory:ut,...s})};var ft=async({collection:t,key:e,satellite:s})=>{let o=await f(s),i=p(await o.get_doc(t,e));if(!l(i))return U({doc:i,key:e})},gt=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await f(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let d=p(a);n.push(c(d)?await U({key:r,doc:d}):void 0)}return n},ht=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await f(s),{key:i}=e,n=await J(e),r=await o(t,i,n);return await U({key:i,doc:r})},_t=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await f(e),o=[];for(let{collection:r,doc:a}of t){let{key:d}=a;o.push([r,d,await J(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await U({key:r,doc:a}));return n},At=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await f(s),{key:i}=e;return o(t,i,X(e))},Tt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await f(e),o=t.map(({collection:i,doc:n})=>[i,n.key,X(n)]);await s(o)},xt=async({collection:t,filter:e,satellite:s})=>{let o=await f(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:d}=await o.list_docs(t,$(e)),A=[];for(let[u,g]of i){let{data:h,owner:v,description:O,version:P,...S}=g;A.push({key:u,description:p(O),owner:v.toText(),data:await dt({data:h}),version:p(P),...S})}return{items:A,items_length:r,items_page:p(n),matches_length:a,matches_pages:p(d)}};import{AnonymousIdentity as pe}from"@dfinity/agent";var m=t=>t!==void 0?t:B()??new pe;var Nt=async({satellite:t,...e})=>{let s=m(t?.identity);return ft({...e,satellite:{...t,identity:s}})},Ts=async({satellite:t,...e})=>{let s=m(t?.identity);return gt({...e,satellite:{...t,identity:s}})},Pt=async({satellite:t,...e})=>{let s=m(t?.identity);return ht({...e,satellite:{...t,identity:s}})},xs=async({satellite:t,...e})=>{let s=m(t?.identity);return _t({...e,satellite:{...t,identity:s}})},Ns=async({satellite:t,...e})=>{let s=m(t?.identity);return At({...e,satellite:{...t,identity:s}})},Ps=async({satellite:t,...e})=>{let s=m(t?.identity);return Tt({...e,satellite:{...t,identity:s}})},ws=async({satellite:t,filter:e,...s})=>{let o=m(t?.identity);return xt({...s,filter:e??{},satellite:{...t,identity:o}})};var wt=async t=>{let e=B();if(l(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await Nt({collection:"#user",key:s});return l(o)?await de({userId:s,provider:t}):o},de=async({userId:t,...e})=>Pt({collection:"#user",doc:{key:t,data:e}});var N,I=async t=>{if(N=N??await K(),!(await N?.isAuthenticated()??!1))return;let s=await wt(t);w.getInstance().set(s)},ue=async t=>new Promise(async(e,s)=>{N=N??await K();let o=t?.provider??new M({});await N.login({onSuccess:async()=>{await I(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??it,allowPinAuthentication:t?.allowPin??nt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),D=async()=>{await N?.logout(),N=void 0,w.getInstance().reset()},B=()=>N?.getIdentity(),me=async()=>(N??await K()).getIdentity();var vt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{Y({message:"junoSignOutAuthTimer"}),await D()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":Y({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},w.getInstance().subscribe(i=>{if(l(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Ot=()=>{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()},St=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};import"@dfinity/principal";var ye=t=>t==null,fe=t=>!ye(t),q=t=>fe(t)?[t]:[],ge=()=>typeof window<"u",bt=async({asset:{data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a},actor:d,init_asset_upload:A})=>{let{batch_id:u}=await A({collection:s,full_path:n,name:e,token:q(i),encoding_type:q(r),description:q(a)}),g=19e5,h=[],v=ge()?new Blob([await t.arrayBuffer()]):t,O=0n;for(let y=0;y<v.size;y+=g){let T=v.slice(y,y+g);h.push({batchId:u,chunk:T,actor:d,orderId:O}),O++}let P=[];for await(let y of he({uploadChunks:h}))P=[...P,...y];let S=o.find(([y,T])=>y.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await d.commit_asset_upload({batch_id:u,chunk_ids:P.map(({chunk_id:y})=>y),headers:[...o,...S||[]]})};async function*he({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=>_e(i)))}}var _e=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:q(o)});var Rt=async({satellite:t,...e})=>{let s=await f(t);await bt({actor:s,asset:e,init_asset_upload:async i=>await s.init_asset_upload(i)})},kt=async({collection:t,satellite:e,filter:s})=>{let o=await f(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:d}=await o.list_assets(t,$(s));return{items:i.map(([A,u])=>u),items_length:n,items_page:p(r),matches_length:a,matches_pages:p(d)}},Et=async({collection:t,fullPath:e,satellite:s})=>(await f(s)).del_asset(t,e),Ut=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await f(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Ct=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await f(s);return p(await o(t,e))},Ft=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await f(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>p(r))};var Vt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var so=async t=>Mt(t),oo=async t=>Mt({filename:t.data.name,...t}),Mt=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:d})=>{let A=m(r?.identity),u=decodeURI(t),g=i??`/${s}/${u}`,h={...r,identity:A};return await Rt({data:e,filename:u,collection:s,token:n,headers:o,fullPath:g,encoding:a,satellite:h,description:d}),{downloadUrl:Kt({satellite:h,assetKey:{fullPath:g,token:n}}),fullPath:g,name:u}},io=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:m(e?.identity)},{items:i,...n}=await kt({collection:t,satellite:o,filter:s??{}}),r=i.map(({key:{full_path:a,token:d,name:A,owner:u,description:g},headers:h,encodings:v,created_at:O,updated_at:P})=>{let S=p(d);return{fullPath:a,description:p(g),name:A,downloadUrl:Kt({satellite:o,assetKey:{fullPath:a,token:S}}),token:S,headers:h,encodings:v.reduce((y,[T,{modified:j,sha256:k,total_length:E}])=>({...y,[T]:{modified:j,sha256:Vt(k),total_length:E}}),{}),owner:u.toText(),created_at:O,updated_at:P}});return{items:r,assets:r,...n}},no=async({collection:t,fullPath:e,satellite:s})=>Et({collection:t,fullPath:e,satellite:{...s,identity:m(s?.identity)}}),ro=async({assets:t,satellite:e})=>Ut({assets:t,satellite:{...e,identity:m(e?.identity)}}),ao=async({satellite:t,...e})=>{let s=m(t?.identity);return Ct({...e,satellite:{...t,identity:s}})},co=async({satellite:t,...e})=>{let s=m(t?.identity);return Ft({...e,satellite:{...t,identity:s}})},Kt=({assetKey:{fullPath:t,token:e},satellite:s})=>{let o={...s,identity:m(s?.identity)};return`${yt(o)}${t}${c(e)?`?token=${e}`:""}`};var Ae=t=>{let e=t?.satelliteId??Ot();F(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??St();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},ho=async t=>Te(t),Te=async t=>{let e=Ae(t);x.getInstance().set(e),await I();let s=e.workers?.auth!==void 0?vt(e.workers.auth):void 0;return[...s?[s]:[]]},_o=t=>w.getInstance().subscribe(t);export{M as InternetIdentityProvider,pt as NFIDProvider,_o as authSubscribe,no as deleteAsset,Ns as deleteDoc,ro as deleteManyAssets,Ps as deleteManyDocs,Kt as downloadUrl,ao as getAsset,Nt as getDoc,co as getManyAssets,Ts as getManyDocs,ho as initJuno,Te as initSatellite,io as listAssets,ws as listDocs,Pt as setDoc,xs as setManyDocs,ue as signIn,D as signOut,me as unsafeIdentity,so as uploadBlob,oo as uploadFile};
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|