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