@junobuild/core-peer 0.1.16 → 1.0.0

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