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