@junobuild/core 5.3.0 → 5.3.1
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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{uint8ArrayToArrayOfNumber as sn}from"@junobuild/utils";import{DER_COSE_OID as dn,wrapDER as pn}from"@icp-sdk/core/agent";import{uint8ArrayToBase64 as Nn}from"@junobuild/utils";import{Cbor as Fr,SignIdentity as Vn}from"@icp-sdk/core/agent";import{arrayBufferToUint8Array as oa,isNullish as ga,uint8ArraysEqual as An}from"@junobuild/utils";import{nonNullish as Cn}from"@junobuild/utils";var cn=({authData:e})=>{if(e.byteLength<37)return{invalidAuthData:null};if(e.byteLength<53)return{invalidAuthData:null};let a=e.slice(37,53),r=ln({bytes:a});return"aaguid"in r?{aaguidBytes:a,aaguidText:r.aaguid}:{unknownProvider:null}},ln=({bytes:e})=>{if(e.length!==16)return{invalidBytes:null};let a=(e instanceof Uint8Array?sn(e):e).map(r=>r.toString(16).padStart(2,"0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5");return a==="00000000-0000-0000-0000-000000000000"?{unknownProvider:null}:{aaguid:a}};function un(e){let a=new DataView(new ArrayBuffer(2)),r=e.slice(53,55);[...new Uint8Array(r)].forEach((n,o)=>a.setUint8(o,n));let i=a.getUint16(0);return e.slice(55+i)}function _n(e){return pn(e,dn)}var mn=class{constructor(e){this._cose=e,this.#e=_n(e)}_cose;#e;toDer(){return this.#e}toRaw(){return new Uint8Array(this.#e)}},vr=class{#e;#a;constructor({rawId:e,cose:a}){this.#e=e,this.#a=new mn(a)}getPublicKey(){return this.#a}getCredentialId(){return this.#e}getCredentialIdText(){return Nn(this.#e)}},Tn=class extends vr{#e;#a;constructor({authData:e,...a}){super(a);let r=cn({authData:e});this.#e="aaguidText"in r?r.aaguidText:void 0,this.#a="aaguidBytes"in r?r.aaguidBytes:void 0}getAAGUID(){return this.#a}getAAGUIDText(){return this.#e}},On=class extends vr{},yn=class extends Error{},gn=class extends Error{},xn=class extends Error{},Rn=class extends Error{},hn=class extends Error{},fn=class extends Error{},Fn=class extends Error{},fr=class extends Error{};var wn={ECDSA_WITH_SHA256:-7,RSA_WITH_SHA256:-257},vn=6e4,Ir=()=>window.crypto.getRandomValues(new Uint8Array(16)),In=()=>Ir(),Pn=()=>Ir(),En=()=>{let{location:{href:e}}=window;try{let{hostname:a}=new URL(e);return a}catch{throw new yn}},Pr=({appId:e})=>e?.id??En(),bn=({appId:e,user:a}={})=>{let{document:{title:r}}=window,i=()=>({rp:{name:e?.name??r,id:Pr({appId:e})}}),n=()=>({user:{id:Pn(),name:a?.name??a?.displayName??r,displayName:a?.displayName??r}});return{attestation:"direct",challenge:In(),...i(),...n(),pubKeyCredParams:Object.values(wn).map(o=>({type:"public-key",alg:o})),excludeCredentials:[],authenticatorSelection:{authenticatorAttachment:"platform",userVerification:"preferred",residentKey:"required",requireResidentKey:!0}}},Sn=(e={})=>({rpId:Pr(e),allowCredentials:[],userVerification:"required"}),ar=async({fn:e,step:a,onProgress:r})=>{r?.({step:a,state:"in_progress"});try{let i=await e();return r?.({step:a,state:"success"}),i}catch(i){throw r?.({step:a,state:"error"}),i}},Fe=(e=>(e[e.RequestingUserCredential=0]="RequestingUserCredential",e[e.FinalizingCredential=1]="FinalizingCredential",e[e.Signing=2]="Signing",e))(Fe||{}),Er=({timeout:e})=>AbortSignal.timeout(e??vn),Dn=async({challenge:e,credentialIds:a,passkeyOptions:r,timeout:i})=>await navigator.credentials.get({publicKey:{...Sn(r),challenge:e.buffer,allowCredentials:(a??[]).map(n=>({id:n.buffer,type:"public-key"}))},signal:Er({timeout:i})}),Vr=e=>{if(e.status!=="initialized")throw new gn},Ar=e=>{if(ga(e))throw new xn},wr=({type:e})=>{if(e!=="public-key")throw new Rn},rr=class xa extends Vn{#e;#a;constructor({onProgress:a,...r}){if(super(),this.#e=a,"retrievePublicKey"in r){let{retrievePublicKey:i}=r;this.#a={status:"pending",retrievePublicKey:i};return}this.#a=xa.#r({credential:new Tn(r)})}static#r({credential:a}){return{status:"initialized",credential:a}}static async createWithNewCredential({passkeyOptions:a,timeout:r,...i}={}){let n=await navigator.credentials.create({publicKey:bn(a),signal:Er({timeout:r})});Ar(n),wr(n);let{response:{attestationObject:o},rawId:t}=n;if(ga(o))throw new hn;let{authData:s}=Fr.decode(oa(o)),c=un(s);return new xa({...i,rawId:oa(t),cose:c,authData:s})}static async createWithExistingCredential(a){return new xa(a)}getPublicKey(){Vr(this.#a);let{credential:a}=this.#a;return a.getPublicKey()}getCredential(){Vr(this.#a);let{credential:a}=this.#a;return a}async sign(a){let r=await ar({fn:async()=>{let i=await Dn({challenge:a,...this.#a.status==="initialized"&&{credentialIds:[this.#a.credential.getCredentialId()]}});return Ar(i),wr(i),i},step:0,onProgress:this.#e});return await ar({fn:async()=>{let{rawId:i}=r;if(this.#a.status==="initialized"){if(!An({a:this.#a.credential.getCredentialId(),b:oa(i)}))throw new fn;return}let{retrievePublicKey:n}=this.#a,o=await n({credentialId:oa(i)});this.#a=xa.#r({credential:new On({rawId:oa(i),cose:o})})},step:1,onProgress:this.#e}),await ar({fn:async()=>{let{response:i}=r,{clientDataJSON:n}=i,{authenticatorData:o,signature:t}="authenticatorData"in i&&"signature"in i?i:{};if(ga(o))throw new fr;if(ga(t))throw new fr;let s=Fr.encode({authenticator_data:o,client_data_json:new TextDecoder().decode(n),signature:oa(t)});if(ga(s))throw new Fn;return Object.assign(s,{__signature__:void 0}),s},step:2,onProgress:this.#e})}},kn=async()=>Cn(window.PublicKeyCredential)&&"isUserVerifyingPlatformAuthenticatorAvailable"in PublicKeyCredential?await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():!1;import{assertNonNullish as ts,nonNullish as tn}from"@junobuild/utils";import{isNullish as jn}from"@junobuild/utils";var ta=class{callbacks=[];populate(a){this.callbacks.forEach(({callback:r})=>r(a))}subscribe(a){let r=Symbol();return this.callbacks.push({id:r,callback:a}),()=>this.callbacks=this.callbacks.filter(({id:i})=>i!==r)}};var R=class e extends ta{static instance;authUser=null;constructor(){super()}static getInstance(){return e.instance||(e.instance=new e),e.instance}set(a){this.authUser=a,this.populate(a)}get(){return this.authUser}subscribe(a){let r=super.subscribe(a);return a(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var Ra=({message:e,detail:a})=>{let r=new CustomEvent(e,{detail:a,bubbles:!0});document.dispatchEvent(r)};import{Actor as Ln}from"@icp-sdk/core/agent";import{isNullish as nr}from"@junobuild/utils";import{isNullish as ir}from"@junobuild/utils";import{HttpAgent as Un}from"@icp-sdk/core/agent";import{nonNullish as Sr}from"@junobuild/utils";var sa="http://127.0.0.1:5987",br="rdmx6-jaaaa-aaaaa-aaadq-cai";var Dr=async({identity:e,container:a})=>{let i=Sr(a)&&a!==!1?a===!0?sa:a:"https://icp-api.io",n=Sr(a);return await Un.create({identity:e,shouldFetchRootKey:n,host:i})};var ca=class e{static instance;#e=void 0;constructor(){}static getInstance(){return ir(e.instance)&&(e.instance=new e),e.instance}async getAgent({identity:a,...r}){let i=a.getPrincipal().toText();if(ir(this.#e)||ir(this.#e[i])){let n=await Dr({identity:a,...r});return this.#e={...this.#e??{},[i]:n},n}return this.#e[i]}reset(){this.#e=null}};var la=class e{static instance;#e=void 0;constructor(){}static getInstance(){return nr(e.instance)&&(e.instance=new e),e.instance}async getActor({satelliteId:a,identity:r,actorKey:i,...n}){let o=`${i}#${r.getPrincipal().toText()}#${a};`;if(nr(this.#e)||nr(this.#e[o])){let t=await this.createActor({satelliteId:a,identity:r,...n});return this.#e={...this.#e??{},[o]:t},t}return this.#e[o]}reset(){this.#e=null}async createActor({idlFactory:a,satelliteId:r,...i}){let n=await ca.getInstance().getAgent(i);return Ln.createActor(a,{agent:n,canisterId:r})}};import{AuthClient as qn,IdbStorage as Cr,KEY_STORAGE_DELEGATION as kr,KEY_STORAGE_KEY as Ur}from"@icp-sdk/auth/client";import{isNullish as Bn}from"@junobuild/utils";var x=class e{static#e;#a;constructor(){}static getInstance(){return Bn(this.#e)&&(this.#e=new e),this.#e}createAuthClient=async()=>(this.#a=await qn.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}}),this.#a);safeCreateAuthClient=async()=>{let a=new Cr;return await Promise.all([a.remove(Ur),a.remove(kr)]),await this.createAuthClient()};getAuthClient=()=>this.#a;logout=async()=>{await this.#a?.logout(),this.#a=null};setAuthClientStorage=async({delegationChain:a,sessionKey:r})=>{let i=new Cr;await Promise.all([i.set(Ur,r.getKeyPair()),i.set(kr,JSON.stringify(a.toJSON()))])}};var or=async e=>{await Jn(),await x.getInstance().createAuthClient(),e?.windowReload!==!1&&window.location.reload()},Jn=async()=>{await x.getInstance().logout(),R.getInstance().reset(),la.getInstance().reset(),ca.getInstance().reset()};var Lr=e=>{let a=e===!0?"./workers/auth.worker.js":e,r=new Worker(a),i=async()=>{Ra({message:"junoSignOutAuthTimer"}),await or()};return r.onmessage=async({data:n})=>{let{msg:o,data:t}=n;switch(o){case"junoSignOutAuthTimer":await i();return;case"junoDelegationRemainingTime":Ra({message:"junoDelegationRemainingTime",detail:t?.authRemainingTime})}},R.getInstance().subscribe(n=>{if(jn(n)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};import{isNullish as Mn,nonNullish as Kn,notEmptyString as Gn}from"@junobuild/utils";var da=class e{static#e;#a;#r;static CHANNEL_NAME="juno_core_auth_channel";static MESSAGE_LOGIN_SUCCESS="authClientLoginSuccess";constructor(){this.#a=new BroadcastChannel(e.CHANNEL_NAME),this.#r=window.crypto.randomUUID()}static getInstance(){return Mn(this.#e)&&(this.#e=new e),this.#e}onLoginSuccess=a=>{let{location:{origin:r}}=window;this.#a.onmessage=async({origin:i,data:n})=>{i===r&&Kn(n)&&n.msg==="authClientLoginSuccess"&&Gn(n.emitterId)&&n.emitterId!==this.#r&&await a()}};destroy=()=>{this.#a.close(),e.#e=null};postLoginSuccess=()=>{let a={emitterId:this.#r,msg:e.MESSAGE_LOGIN_SUCCESS};this.#a.postMessage(a)};get __test__only__emitter_id__(){return this.#r}};var g=class e extends ta{static instance;env;constructor(){super()}static getInstance(){return e.instance||(e.instance=new e),e.instance}set(a){this.env=a,this.populate(a)}get(){return this.env}reset(){this.env=null}subscribe(a){let r=super.subscribe(a);return a(this.env),r}};var ha=async({fn:e,syncTabsOnSuccess:a})=>{let{authenticated:r}=await Wn({fn:e});!r||!a||g.getInstance().get()?.syncTabs===!1||Hn()},qr=async({fn:e})=>{let{createAuthClient:a}=x.getInstance(),i=await(await a()).isAuthenticated();await e({authenticated:i})},Wn=async({fn:e})=>{let{createAuthClient:a,safeCreateAuthClient:r}=x.getInstance();return await(await a()).isAuthenticated()?(await e(),{authenticated:!0}):(await r(),{authenticated:!1})},Hn=()=>{try{da.getInstance().postLoginSuccess()}catch(e){console.warn("Auth BroadcastChannel posting failed",e)}};var tr=({error:e,type:a})=>typeof e=="string"?e.includes(a):e instanceof Error?e.message.includes(a):!1;var Br="juno.datastore.error.user.cannot_update";import{isNullish as Oo,nonNullish as si}from"@junobuild/utils";var Z={certified:!1};import{AnonymousIdentity as Xn}from"@icp-sdk/core/agent";import{nonNullish as Qn}from"@junobuild/utils";import{isNullish as zn}from"@junobuild/utils";var Fa=()=>x.getInstance().getAuthClient()?.getIdentity(),$n=async()=>{let{getAuthClient:e,createAuthClient:a}=x.getInstance();return(e()??await a()).getIdentity()},Yn=async()=>{let e=R.getInstance().get();if(zn(e))return null;let a=x.getInstance().getAuthClient();return await a?.isAuthenticated()??!1?a?.getIdentity()??null:null};var _=e=>Qn(e)?e:Fa()??new Xn;import{fromNullable as _a,isNullish as No,nonNullish as To}from"@junobuild/utils";import{Actor as Zn}from"@icp-sdk/core/agent";import{isNullish as eo}from"@junobuild/utils";import{nonNullish as io}from"@junobuild/utils";import{HttpAgent as no}from"@icp-sdk/core/agent";var sr=({IDL:e})=>{let a=e.Variant({Heap:e.Null,Stable:e.Null}),r=e.Record({system_memory:e.Opt(a)}),i=e.Record({controllers:e.Vec(e.Principal),storage:e.Opt(r)}),n=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),o=e.Variant({OpenId:n}),t=e.Record({updated_at:e.Nat64,owner:e.Principal,data:e.Vec(e.Nat8),description:e.Opt(e.Text),created_at:e.Nat64,version:e.Opt(e.Nat64)}),s=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),c=e.Record({doc:t,delegation:s}),l=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),d=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),p=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),u=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,JwtVerify:d,GetOrFetchJwks:p,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),m=e.Variant({PrepareDelegation:u,RegisterUser:e.Text}),y=e.Variant({Ok:c,Err:m}),V=e.Record({jwt:e.Text,salt:e.Vec(e.Nat8)}),h=e.Variant({OpenId:V}),C=e.Variant({Write:e.Null,Submit:e.Null}),U=e.Record({scope:C,expires_at:e.Nat64}),L=e.Variant({JwtFindProvider:l,InvalidController:e.Text,GetCachedJwks:e.Null,JwtVerify:d,GetOrFetchJwks:p,ControllerAlreadyExists:e.Null,InvalidObservatoryId:e.Text,TooManyControllers:e.Text}),ae=e.Variant({PrepareAutomation:L,RegisterController:e.Text,SaveWorkflowMetadata:e.Text,SaveUniqueJtiToken:e.Text}),re=e.Variant({Ok:e.Tuple(e.Principal,U),Err:ae}),q=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),ie=e.Variant({Heap:e.Record({offset:e.Nat64}),Stable:e.Record({key:e.Opt(q)})}),Ae=e.Variant({Append:e.Null,Clear:e.Null,AppendWithRouting:e.Null}),we=e.Record({cursor:ie,strategy:Ae,chunk_size:e.Opt(e.Nat32)}),ve=e.Record({next_cursor:e.Opt(ie)}),B=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),ne=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),oe=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),te=e.Record({field:oe,desc:e.Bool}),J=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),j=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(J),description:e.Opt(e.Text),created_at:e.Opt(J)}),se=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),T=e.Record({order:e.Opt(te),owner:e.Opt(e.Principal),matcher:e.Opt(j),paginate:e.Opt(se)}),ce=e.Record({controllers:e.Vec(e.Principal)}),M=e.Variant({Emulator:e.Null,Automation:e.Null}),A=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),K=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(M),created_at:e.Nat64,scope:A,expires_at:e.Opt(e.Nat64)}),G=e.Record({version:e.Opt(e.Nat64)}),w=e.Variant({Db:e.Null,Storage:e.Null}),Ie=e.Record({version:e.Opt(e.Nat64)}),Pe=e.Record({proposal_ids:e.Vec(e.Nat)}),Ee=e.Record({cycles:e.Nat,destination_id:e.Principal}),be=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),W=e.Record({key:q,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,be)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),v=e.Variant({GitHub:e.Null,Google:e.Null}),le=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),Se=e.Record({delegation:e.Opt(le),client_id:e.Text}),de=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(v,Se))}),pe=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),ue=e.Record({allowed_callers:e.Vec(e.Principal)}),I=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(de),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(pe),rules:e.Opt(ue)}),P=e.Variant({GitHub:e.Null}),_e=e.Record({scope:e.Opt(C),max_time_to_live:e.Opt(e.Nat64)}),De=e.Record({owner:e.Text,name:e.Text}),Ce=e.Record({refs:e.Opt(e.Vec(e.Text))}),H=e.Record({controller:e.Opt(_e),repositories:e.Vec(e.Tuple(De,Ce))}),me=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(P,H))}),z=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(me),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64)}),E=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),b=e.Record({updated_at:e.Opt(e.Nat64),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E)}),$=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),Ne=e.Variant({Deny:e.Null,Allow:e.Null}),Te=e.Record({status_code:e.Nat16,location:e.Text}),f=e.Record({iframe:e.Opt($),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E),raw_access:e.Opt(Ne),redirects:e.Opt(e.Vec(e.Tuple(e.Text,Te)))}),ke=e.Record({db:e.Opt(b),authentication:e.Opt(I),storage:f,automation:e.Opt(z)}),Ue=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Le=e.Variant({OpenId:Ue}),qe=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),Be=e.Record({signature:e.Vec(e.Nat8),delegation:qe}),Je=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:d,GetOrFetchJwks:p,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),je=e.Variant({Ok:Be,Err:Je}),Oe=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),ye=e.Record({clear_existing_assets:e.Opt(e.Bool)}),Me=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),ge=e.Variant({AssetsUpgrade:ye,SegmentsDeployment:Me}),F=e.Record({status:Oe,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:ge}),S=e.Variant({Controllers:e.Null,Private:e.Null,Public:e.Null,Managed:e.Null}),xe=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),Y=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(a),updated_at:e.Nat64,max_size:e.Opt(e.Nat),read:S,created_at:e.Nat64,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(xe),write:S,max_changes_per_user:e.Opt(e.Nat32)}),Ke=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),X=e.Record({memory:a,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),Ge=e.Variant({Callback:e.Record({token:X,callback:e.Func([],[],["query"])})}),We=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(Ge),status_code:e.Nat16}),He=e.Record({token:e.Opt(X),body:e.Vec(e.Nat8)}),Q=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),O=e.Record({batch_id:e.Nat}),ze=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,W)),items_length:e.Nat64}),$e=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),D=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,t)),items_length:e.Nat64}),Ye=e.Record({desc:e.Bool}),Xe=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),Qe=e.Record({order:e.Opt(Ye),paginate:e.Opt(Xe)}),Ze=e.Record({proposal_id:e.Nat}),Re=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(Ze,F)),items_length:e.Nat64}),ea=e.Record({include_system:e.Bool}),aa=e.Record({matcher:e.Opt(ea)}),he=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(e.Text,Y)),items_length:e.Nat64}),ra=e.Record({stable:e.Nat64,heap:e.Nat64}),ia=e.Record({openid:e.Opt(de),version:e.Opt(e.Nat64),internet_identity:e.Opt(pe),rules:e.Opt(ue)}),za=e.Record({openid:e.Opt(me),version:e.Opt(e.Nat64)}),$a=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(M),scope:A,expires_at:e.Opt(e.Nat64)}),Ya=e.Record({controller:$a,controllers:e.Vec(e.Principal)}),Xa=e.Record({version:e.Opt(e.Nat64),max_memory_size:e.Opt(E)}),Na=e.Record({data:e.Vec(e.Nat8),description:e.Opt(e.Text),version:e.Opt(e.Nat64)}),Qa=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(a),max_size:e.Opt(e.Nat),read:S,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(xe),write:S,max_changes_per_user:e.Opt(e.Nat32)}),Ta=e.Record({iframe:e.Opt($),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E),raw_access:e.Opt(Ne),redirects:e.Opt(e.Vec(e.Tuple(e.Text,Te)))}),Za=e.Record({skip_certification:e.Opt(e.Bool)}),er=e.Record({config:Ta,options:Za}),Oa=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),ya=e.Record({chunk_id:e.Nat});return e.Service({authenticate:e.Func([o],[y],[]),authenticate_automation:e.Func([h],[re],[]),certify_assets_chunk:e.Func([we],[ve],[]),commit_asset_upload:e.Func([B],[],[]),commit_proposal:e.Func([ne],[e.Null],[]),commit_proposal_asset_upload:e.Func([B],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(B)],[],[]),count_assets:e.Func([e.Text,T],[e.Nat64],["query"]),count_collection_assets:e.Func([e.Text],[e.Nat64],["query"]),count_collection_docs:e.Func([e.Text],[e.Nat64],["query"]),count_docs:e.Func([e.Text,T],[e.Nat64],["query"]),count_proposals:e.Func([],[e.Nat64],["query"]),del_asset:e.Func([e.Text,e.Text],[],[]),del_assets:e.Func([e.Text],[],[]),del_controller_self:e.Func([],[],[]),del_controllers:e.Func([ce],[e.Vec(e.Tuple(e.Principal,K))],[]),del_custom_domain:e.Func([e.Text],[],[]),del_doc:e.Func([e.Text,e.Text,G],[],[]),del_docs:e.Func([e.Text],[],[]),del_filtered_assets:e.Func([e.Text,T],[],[]),del_filtered_docs:e.Func([e.Text,T],[],[]),del_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[],[]),del_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,G))],[],[]),del_rule:e.Func([w,e.Text,Ie],[],[]),delete_proposal_assets:e.Func([Pe],[],[]),deposit_cycles:e.Func([Ee],[],[]),get_asset:e.Func([e.Text,e.Text],[e.Opt(W)],["query"]),get_auth_config:e.Func([],[e.Opt(I)],["query"]),get_automation_config:e.Func([],[e.Opt(z)],["query"]),get_config:e.Func([],[ke],[]),get_db_config:e.Func([],[e.Opt(b)],["query"]),get_delegation:e.Func([Le],[je],["query"]),get_doc:e.Func([e.Text,e.Text],[e.Opt(t)],["query"]),get_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(W)))],["query"]),get_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(t)))],["query"]),get_proposal:e.Func([e.Nat],[e.Opt(F)],["query"]),get_rule:e.Func([w,e.Text],[e.Opt(Y)],["query"]),get_storage_config:e.Func([],[f],["query"]),http_request:e.Func([Ke],[We],["query"]),http_request_streaming_callback:e.Func([X],[He],["query"]),init_asset_upload:e.Func([Q],[O],[]),init_proposal:e.Func([ge],[e.Nat,F],[]),init_proposal_asset_upload:e.Func([Q,e.Nat],[O],[]),init_proposal_many_assets_upload:e.Func([e.Vec(Q),e.Nat],[e.Vec(e.Tuple(e.Text,O))],[]),list_assets:e.Func([e.Text,T],[ze],["query"]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,K))],["query"]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,$e))],["query"]),list_docs:e.Func([e.Text,T],[D],["query"]),list_proposals:e.Func([Qe],[Re],["query"]),list_rules:e.Func([w,aa],[he],["query"]),memory_size:e.Func([],[ra],["query"]),reject_proposal:e.Func([ne],[e.Null],[]),set_asset_token:e.Func([e.Text,e.Text,e.Opt(e.Text)],[],[]),set_auth_config:e.Func([ia],[I],[]),set_automation_config:e.Func([za],[z],[]),set_controllers:e.Func([Ya],[e.Vec(e.Tuple(e.Principal,K))],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_db_config:e.Func([Xa],[b],[]),set_doc:e.Func([e.Text,e.Text,Na],[t],[]),set_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,Na))],[e.Vec(e.Tuple(e.Text,t))],[]),set_rule:e.Func([w,e.Text,Qa],[Y],[]),set_storage_config:e.Func([Ta],[f],[]),set_storage_config_with_options:e.Func([er],[f],[]),submit_proposal:e.Func([e.Nat],[e.Nat,F],[]),switch_storage_system_memory:e.Func([],[],[]),upload_asset_chunk:e.Func([Oa],[ya],[]),upload_proposal_asset_chunk:e.Func([Oa],[ya],[])})},cr=({IDL:e})=>{let a=e.Variant({Heap:e.Null,Stable:e.Null}),r=e.Record({system_memory:e.Opt(a)}),i=e.Record({controllers:e.Vec(e.Principal),storage:e.Opt(r)}),n=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),o=e.Variant({OpenId:n}),t=e.Record({updated_at:e.Nat64,owner:e.Principal,data:e.Vec(e.Nat8),description:e.Opt(e.Text),created_at:e.Nat64,version:e.Opt(e.Nat64)}),s=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),c=e.Record({doc:t,delegation:s}),l=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),d=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),p=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),u=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,JwtVerify:d,GetOrFetchJwks:p,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),m=e.Variant({PrepareDelegation:u,RegisterUser:e.Text}),y=e.Variant({Ok:c,Err:m}),V=e.Record({jwt:e.Text,salt:e.Vec(e.Nat8)}),h=e.Variant({OpenId:V}),C=e.Variant({Write:e.Null,Submit:e.Null}),U=e.Record({scope:C,expires_at:e.Nat64}),L=e.Variant({JwtFindProvider:l,InvalidController:e.Text,GetCachedJwks:e.Null,JwtVerify:d,GetOrFetchJwks:p,ControllerAlreadyExists:e.Null,InvalidObservatoryId:e.Text,TooManyControllers:e.Text}),ae=e.Variant({PrepareAutomation:L,RegisterController:e.Text,SaveWorkflowMetadata:e.Text,SaveUniqueJtiToken:e.Text}),re=e.Variant({Ok:e.Tuple(e.Principal,U),Err:ae}),q=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),ie=e.Variant({Heap:e.Record({offset:e.Nat64}),Stable:e.Record({key:e.Opt(q)})}),Ae=e.Variant({Append:e.Null,Clear:e.Null,AppendWithRouting:e.Null}),we=e.Record({cursor:ie,strategy:Ae,chunk_size:e.Opt(e.Nat32)}),ve=e.Record({next_cursor:e.Opt(ie)}),B=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),ne=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),oe=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),te=e.Record({field:oe,desc:e.Bool}),J=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),j=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(J),description:e.Opt(e.Text),created_at:e.Opt(J)}),se=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),T=e.Record({order:e.Opt(te),owner:e.Opt(e.Principal),matcher:e.Opt(j),paginate:e.Opt(se)}),ce=e.Record({controllers:e.Vec(e.Principal)}),M=e.Variant({Emulator:e.Null,Automation:e.Null}),A=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),K=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(M),created_at:e.Nat64,scope:A,expires_at:e.Opt(e.Nat64)}),G=e.Record({version:e.Opt(e.Nat64)}),w=e.Variant({Db:e.Null,Storage:e.Null}),Ie=e.Record({version:e.Opt(e.Nat64)}),Pe=e.Record({proposal_ids:e.Vec(e.Nat)}),Ee=e.Record({cycles:e.Nat,destination_id:e.Principal}),be=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),W=e.Record({key:q,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,be)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),v=e.Variant({GitHub:e.Null,Google:e.Null}),le=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),Se=e.Record({delegation:e.Opt(le),client_id:e.Text}),de=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(v,Se))}),pe=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),ue=e.Record({allowed_callers:e.Vec(e.Principal)}),I=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(de),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(pe),rules:e.Opt(ue)}),P=e.Variant({GitHub:e.Null}),_e=e.Record({scope:e.Opt(C),max_time_to_live:e.Opt(e.Nat64)}),De=e.Record({owner:e.Text,name:e.Text}),Ce=e.Record({refs:e.Opt(e.Vec(e.Text))}),H=e.Record({controller:e.Opt(_e),repositories:e.Vec(e.Tuple(De,Ce))}),me=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(P,H))}),z=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(me),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64)}),E=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),b=e.Record({updated_at:e.Opt(e.Nat64),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E)}),$=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),Ne=e.Variant({Deny:e.Null,Allow:e.Null}),Te=e.Record({status_code:e.Nat16,location:e.Text}),f=e.Record({iframe:e.Opt($),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E),raw_access:e.Opt(Ne),redirects:e.Opt(e.Vec(e.Tuple(e.Text,Te)))}),ke=e.Record({db:e.Opt(b),authentication:e.Opt(I),storage:f,automation:e.Opt(z)}),Ue=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Le=e.Variant({OpenId:Ue}),qe=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),Be=e.Record({signature:e.Vec(e.Nat8),delegation:qe}),Je=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:d,GetOrFetchJwks:p,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),je=e.Variant({Ok:Be,Err:Je}),Oe=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),ye=e.Record({clear_existing_assets:e.Opt(e.Bool)}),Me=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),ge=e.Variant({AssetsUpgrade:ye,SegmentsDeployment:Me}),F=e.Record({status:Oe,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:ge}),S=e.Variant({Controllers:e.Null,Private:e.Null,Public:e.Null,Managed:e.Null}),xe=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),Y=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(a),updated_at:e.Nat64,max_size:e.Opt(e.Nat),read:S,created_at:e.Nat64,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(xe),write:S,max_changes_per_user:e.Opt(e.Nat32)}),Ke=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),X=e.Record({memory:a,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),Ge=e.Variant({Callback:e.Record({token:X,callback:e.Func([],[],[])})}),We=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(Ge),status_code:e.Nat16}),He=e.Record({token:e.Opt(X),body:e.Vec(e.Nat8)}),Q=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),O=e.Record({batch_id:e.Nat}),ze=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,W)),items_length:e.Nat64}),$e=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),D=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,t)),items_length:e.Nat64}),Ye=e.Record({desc:e.Bool}),Xe=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),Qe=e.Record({order:e.Opt(Ye),paginate:e.Opt(Xe)}),Ze=e.Record({proposal_id:e.Nat}),Re=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(Ze,F)),items_length:e.Nat64}),ea=e.Record({include_system:e.Bool}),aa=e.Record({matcher:e.Opt(ea)}),he=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(e.Text,Y)),items_length:e.Nat64}),ra=e.Record({stable:e.Nat64,heap:e.Nat64}),ia=e.Record({openid:e.Opt(de),version:e.Opt(e.Nat64),internet_identity:e.Opt(pe),rules:e.Opt(ue)}),za=e.Record({openid:e.Opt(me),version:e.Opt(e.Nat64)}),$a=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(M),scope:A,expires_at:e.Opt(e.Nat64)}),Ya=e.Record({controller:$a,controllers:e.Vec(e.Principal)}),Xa=e.Record({version:e.Opt(e.Nat64),max_memory_size:e.Opt(E)}),Na=e.Record({data:e.Vec(e.Nat8),description:e.Opt(e.Text),version:e.Opt(e.Nat64)}),Qa=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(a),max_size:e.Opt(e.Nat),read:S,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(xe),write:S,max_changes_per_user:e.Opt(e.Nat32)}),Ta=e.Record({iframe:e.Opt($),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E),raw_access:e.Opt(Ne),redirects:e.Opt(e.Vec(e.Tuple(e.Text,Te)))}),Za=e.Record({skip_certification:e.Opt(e.Bool)}),er=e.Record({config:Ta,options:Za}),Oa=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),ya=e.Record({chunk_id:e.Nat});return e.Service({authenticate:e.Func([o],[y],[]),authenticate_automation:e.Func([h],[re],[]),certify_assets_chunk:e.Func([we],[ve],[]),commit_asset_upload:e.Func([B],[],[]),commit_proposal:e.Func([ne],[e.Null],[]),commit_proposal_asset_upload:e.Func([B],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(B)],[],[]),count_assets:e.Func([e.Text,T],[e.Nat64],[]),count_collection_assets:e.Func([e.Text],[e.Nat64],[]),count_collection_docs:e.Func([e.Text],[e.Nat64],[]),count_docs:e.Func([e.Text,T],[e.Nat64],[]),count_proposals:e.Func([],[e.Nat64],[]),del_asset:e.Func([e.Text,e.Text],[],[]),del_assets:e.Func([e.Text],[],[]),del_controller_self:e.Func([],[],[]),del_controllers:e.Func([ce],[e.Vec(e.Tuple(e.Principal,K))],[]),del_custom_domain:e.Func([e.Text],[],[]),del_doc:e.Func([e.Text,e.Text,G],[],[]),del_docs:e.Func([e.Text],[],[]),del_filtered_assets:e.Func([e.Text,T],[],[]),del_filtered_docs:e.Func([e.Text,T],[],[]),del_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[],[]),del_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,G))],[],[]),del_rule:e.Func([w,e.Text,Ie],[],[]),delete_proposal_assets:e.Func([Pe],[],[]),deposit_cycles:e.Func([Ee],[],[]),get_asset:e.Func([e.Text,e.Text],[e.Opt(W)],[]),get_auth_config:e.Func([],[e.Opt(I)],[]),get_automation_config:e.Func([],[e.Opt(z)],[]),get_config:e.Func([],[ke],[]),get_db_config:e.Func([],[e.Opt(b)],[]),get_delegation:e.Func([Le],[je],[]),get_doc:e.Func([e.Text,e.Text],[e.Opt(t)],[]),get_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(W)))],[]),get_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(t)))],[]),get_proposal:e.Func([e.Nat],[e.Opt(F)],[]),get_rule:e.Func([w,e.Text],[e.Opt(Y)],[]),get_storage_config:e.Func([],[f],[]),http_request:e.Func([Ke],[We],[]),http_request_streaming_callback:e.Func([X],[He],[]),init_asset_upload:e.Func([Q],[O],[]),init_proposal:e.Func([ge],[e.Nat,F],[]),init_proposal_asset_upload:e.Func([Q,e.Nat],[O],[]),init_proposal_many_assets_upload:e.Func([e.Vec(Q),e.Nat],[e.Vec(e.Tuple(e.Text,O))],[]),list_assets:e.Func([e.Text,T],[ze],[]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,K))],[]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,$e))],[]),list_docs:e.Func([e.Text,T],[D],[]),list_proposals:e.Func([Qe],[Re],[]),list_rules:e.Func([w,aa],[he],[]),memory_size:e.Func([],[ra],[]),reject_proposal:e.Func([ne],[e.Null],[]),set_asset_token:e.Func([e.Text,e.Text,e.Opt(e.Text)],[],[]),set_auth_config:e.Func([ia],[I],[]),set_automation_config:e.Func([za],[z],[]),set_controllers:e.Func([Ya],[e.Vec(e.Tuple(e.Principal,K))],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_db_config:e.Func([Xa],[b],[]),set_doc:e.Func([e.Text,e.Text,Na],[t],[]),set_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,Na))],[e.Vec(e.Tuple(e.Text,t))],[]),set_rule:e.Func([w,e.Text,Qa],[Y],[]),set_storage_config:e.Func([Ta],[f],[]),set_storage_config_with_options:e.Func([er],[f],[]),submit_proposal:e.Func([e.Nat],[e.Nat,F],[]),switch_storage_system_memory:e.Func([],[],[]),upload_asset_chunk:e.Func([Oa],[ya],[]),upload_proposal_asset_chunk:e.Func([Oa],[ya],[])})},ao=({IDL:e})=>{let a=e.Record({e8s:e.Nat64}),r=e.Record({mission_control_id:e.Principal,user:e.Principal}),i=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),n=e.Variant({OpenId:i}),o=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),t=e.Variant({GitHub:e.Null,Google:e.Null}),s=e.Record({name:e.Opt(e.Text),locale:e.Opt(e.Text),family_name:e.Opt(e.Text),email:e.Opt(e.Text),picture:e.Opt(e.Text),given_name:e.Opt(e.Text),preferred_username:e.Opt(e.Text)}),c=e.Record({provider:t,data:s}),l=e.Variant({InternetIdentity:e.Null,OpenId:c}),d=e.Record({updated_at:e.Nat64,credits:a,mission_control_id:e.Opt(e.Principal),provider:e.Opt(l),owner:e.Principal,created_at:e.Nat64}),p=e.Record({delegation:o,account:d}),u=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),m=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),y=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),V=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,JwtVerify:m,GetOrFetchJwks:y,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),h=e.Variant({PrepareDelegation:V,RegisterUser:e.Text}),C=e.Variant({Ok:p,Err:h}),U=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),L=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),ae=e.Record({subnet_id:e.Opt(e.Principal)}),re=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),name:e.Opt(e.Text),user:e.Principal}),q=e.Variant({Heap:e.Null,Stable:e.Null}),ie=e.Record({system_memory:e.Opt(q)}),Ae=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),storage:e.Opt(ie),name:e.Opt(e.Text),user:e.Principal}),we=e.Record({controllers:e.Vec(e.Principal)}),ve=e.Record({proposal_ids:e.Vec(e.Nat)}),B=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),ne=e.Record({delegation:e.Opt(B),client_id:e.Text}),oe=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(t,ne))}),te=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),J=e.Record({allowed_callers:e.Vec(e.Principal)}),j=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(oe),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(te),rules:e.Opt(J)}),se=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),T=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),ce=e.Variant({Deny:e.Null,Allow:e.Null}),M=e.Record({status_code:e.Nat16,location:e.Text}),A=e.Record({iframe:e.Opt(se),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(T),raw_access:e.Opt(ce),redirects:e.Opt(e.Vec(e.Tuple(e.Text,M)))}),K=e.Record({authentication:e.Opt(j),storage:A}),G=e.Record({user:e.Principal}),w=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Ie=e.Variant({OpenId:w}),Pe=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),Ee=e.Record({signature:e.Vec(e.Nat8),delegation:Pe}),be=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:m,GetOrFetchJwks:y,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),W=e.Variant({Ok:Ee,Err:be}),v=e.Variant({Orbiter:e.Null,MissionControl:e.Null,Satellite:e.Null}),le=e.Record({e12s:e.Nat64}),Se=e.Record({updated_at:e.Nat64,fee_cycles:le,fee_icp:e.Opt(a)}),de=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),pe=e.Record({clear_existing_assets:e.Opt(e.Bool)}),ue=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),I=e.Variant({AssetsUpgrade:pe,SegmentsDeployment:ue}),P=e.Record({status:de,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:I}),_e=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),De=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),Ce=e.Variant({Heap:e.Null,Stable:e.Null}),H=e.Record({memory:Ce,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),me=e.Variant({Callback:e.Record({token:H,callback:e.Func([],[],["query"])})}),z=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(me),status_code:e.Nat16}),E=e.Record({token:e.Opt(H),body:e.Vec(e.Nat8)}),b=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),$=e.Record({batch_id:e.Nat}),Ne=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),Te=e.Record({field:Ne,desc:e.Bool}),f=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),ke=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(f),description:e.Opt(e.Text),created_at:e.Opt(f)}),Ue=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),Le=e.Record({order:e.Opt(Te),owner:e.Opt(e.Principal),matcher:e.Opt(ke),paginate:e.Opt(Ue)}),qe=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),Be=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),Je=e.Record({key:qe,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,Be)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),je=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,Je)),items_length:e.Nat64}),Oe=e.Variant({Emulator:e.Null,Automation:e.Null}),ye=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),Me=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(Oe),created_at:e.Nat64,scope:ye,expires_at:e.Opt(e.Nat64)}),ge=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),F=e.Variant({Refunded:e.Null,Acknowledged:e.Null,Completed:e.Null}),S=e.Record({status:F,updated_at:e.Nat64,block_index_payment:e.Nat64,mission_control_id:e.Opt(e.Principal),created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64)}),xe=e.Record({block_index:e.Nat64,ledger_id:e.Principal}),Y=e.Record({owner:e.Principal,subaccount:e.Opt(e.Vec(e.Nat8))}),Ke=e.Record({status:F,updated_at:e.Nat64,created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64),purchaser:Y}),X=e.Record({desc:e.Bool}),Ge=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),We=e.Record({order:e.Opt(X),paginate:e.Opt(Ge)}),He=e.Record({proposal_id:e.Nat}),Q=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(He,P)),items_length:e.Nat64}),O=e.Variant({Orbiter:e.Null,Satellite:e.Null}),ze=e.Record({segment_id:e.Opt(e.Principal),segment_kind:e.Opt(O)}),$e=e.Record({user:e.Principal,segment_id:e.Principal,segment_kind:O}),D=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),segment_id:e.Principal,created_at:e.Nat64}),Ye=e.Record({openid:e.Opt(oe),version:e.Opt(e.Nat64),internet_identity:e.Opt(te),rules:e.Opt(J)}),Xe=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(Oe),scope:ye,expires_at:e.Opt(e.Nat64)}),Qe=e.Record({controller:Xe,controllers:e.Vec(e.Principal)}),Ze=e.Record({fee_cycles:le,fee_icp:e.Opt(a)}),Re=e.Record({metadata:e.Opt(e.Vec(e.Tuple(e.Text,e.Text))),segment_id:e.Principal,segment_kind:O}),ea=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),segment_id:e.Principal,segment_kind:O}),aa=e.Record({iframe:e.Opt(se),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(T),raw_access:e.Opt(ce),redirects:e.Opt(e.Vec(e.Tuple(e.Text,M)))}),he=e.Record({segment_id:e.Principal,segment_kind:O}),ra=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),ia=e.Record({chunk_id:e.Nat});return e.Service({add_credits:e.Func([e.Principal,a],[],[]),add_invitation_code:e.Func([e.Text],[],[]),assert_mission_control_center:e.Func([r],[],["query"]),authenticate:e.Func([n],[C],[]),commit_proposal:e.Func([U],[e.Null],[]),commit_proposal_asset_upload:e.Func([L],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(L)],[],[]),count_proposals:e.Func([],[e.Nat64],["query"]),create_mission_control:e.Func([ae],[e.Principal],[]),create_orbiter:e.Func([re],[e.Principal],[]),create_satellite:e.Func([Ae],[e.Principal],[]),del_controllers:e.Func([we],[],[]),del_custom_domain:e.Func([e.Text],[],[]),delete_proposal_assets:e.Func([ve],[],[]),get_account:e.Func([],[e.Opt(d)],["query"]),get_auth_config:e.Func([],[e.Opt(j)],["query"]),get_config:e.Func([],[K],["query"]),get_create_orbiter_fee:e.Func([G],[e.Opt(a)],["query"]),get_create_satellite_fee:e.Func([G],[e.Opt(a)],["query"]),get_credits:e.Func([],[a],["query"]),get_delegation:e.Func([Ie],[W],["query"]),get_fee:e.Func([v],[Se],["query"]),get_or_init_account:e.Func([],[d],[]),get_proposal:e.Func([e.Nat],[e.Opt(P)],["query"]),get_rate_config:e.Func([v],[_e],["query"]),get_storage_config:e.Func([],[A],["query"]),http_request:e.Func([De],[z],["query"]),http_request_streaming_callback:e.Func([H],[E],["query"]),init_proposal:e.Func([I],[e.Nat,P],[]),init_proposal_asset_upload:e.Func([b,e.Nat],[$],[]),init_proposal_many_assets_upload:e.Func([e.Vec(b),e.Nat],[e.Vec(e.Tuple(e.Text,$))],[]),list_accounts:e.Func([],[e.Vec(e.Tuple(e.Principal,d))],["query"]),list_assets:e.Func([e.Text,Le],[je],["query"]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,Me))],["query"]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,ge))],["query"]),list_icp_payments:e.Func([],[e.Vec(e.Tuple(e.Nat64,S))],["query"]),list_icrc_payments:e.Func([],[e.Vec(e.Tuple(xe,Ke))],["query"]),list_proposals:e.Func([We],[Q],["query"]),list_segments:e.Func([ze],[e.Vec(e.Tuple($e,D))],["query"]),reject_proposal:e.Func([U],[e.Null],[]),set_auth_config:e.Func([Ye],[j],[]),set_controllers:e.Func([Qe],[],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_fee:e.Func([v,Ze],[],[]),set_many_segments:e.Func([e.Vec(Re)],[e.Vec(D)],[]),set_rate_config:e.Func([v,_e],[],[]),set_segment:e.Func([Re],[D],[]),set_segment_metadata:e.Func([ea],[D],[]),set_storage_config:e.Func([aa],[A],[]),submit_proposal:e.Func([e.Nat],[e.Nat,P],[]),unset_many_segments:e.Func([e.Vec(he)],[],[]),unset_segment:e.Func([he],[],[]),upload_proposal_asset_chunk:e.Func([ra],[ia],[])})},ro=({IDL:e})=>{let a=e.Record({e8s:e.Nat64}),r=e.Record({mission_control_id:e.Principal,user:e.Principal}),i=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),n=e.Variant({OpenId:i}),o=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),t=e.Variant({GitHub:e.Null,Google:e.Null}),s=e.Record({name:e.Opt(e.Text),locale:e.Opt(e.Text),family_name:e.Opt(e.Text),email:e.Opt(e.Text),picture:e.Opt(e.Text),given_name:e.Opt(e.Text),preferred_username:e.Opt(e.Text)}),c=e.Record({provider:t,data:s}),l=e.Variant({InternetIdentity:e.Null,OpenId:c}),d=e.Record({updated_at:e.Nat64,credits:a,mission_control_id:e.Opt(e.Principal),provider:e.Opt(l),owner:e.Principal,created_at:e.Nat64}),p=e.Record({delegation:o,account:d}),u=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),m=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),y=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),V=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,JwtVerify:m,GetOrFetchJwks:y,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),h=e.Variant({PrepareDelegation:V,RegisterUser:e.Text}),C=e.Variant({Ok:p,Err:h}),U=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),L=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),ae=e.Record({subnet_id:e.Opt(e.Principal)}),re=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),name:e.Opt(e.Text),user:e.Principal}),q=e.Variant({Heap:e.Null,Stable:e.Null}),ie=e.Record({system_memory:e.Opt(q)}),Ae=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),storage:e.Opt(ie),name:e.Opt(e.Text),user:e.Principal}),we=e.Record({controllers:e.Vec(e.Principal)}),ve=e.Record({proposal_ids:e.Vec(e.Nat)}),B=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),ne=e.Record({delegation:e.Opt(B),client_id:e.Text}),oe=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(t,ne))}),te=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),J=e.Record({allowed_callers:e.Vec(e.Principal)}),j=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(oe),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(te),rules:e.Opt(J)}),se=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),T=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),ce=e.Variant({Deny:e.Null,Allow:e.Null}),M=e.Record({status_code:e.Nat16,location:e.Text}),A=e.Record({iframe:e.Opt(se),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(T),raw_access:e.Opt(ce),redirects:e.Opt(e.Vec(e.Tuple(e.Text,M)))}),K=e.Record({authentication:e.Opt(j),storage:A}),G=e.Record({user:e.Principal}),w=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Ie=e.Variant({OpenId:w}),Pe=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),Ee=e.Record({signature:e.Vec(e.Nat8),delegation:Pe}),be=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:m,GetOrFetchJwks:y,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),W=e.Variant({Ok:Ee,Err:be}),v=e.Variant({Orbiter:e.Null,MissionControl:e.Null,Satellite:e.Null}),le=e.Record({e12s:e.Nat64}),Se=e.Record({updated_at:e.Nat64,fee_cycles:le,fee_icp:e.Opt(a)}),de=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),pe=e.Record({clear_existing_assets:e.Opt(e.Bool)}),ue=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),I=e.Variant({AssetsUpgrade:pe,SegmentsDeployment:ue}),P=e.Record({status:de,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:I}),_e=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),De=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),Ce=e.Variant({Heap:e.Null,Stable:e.Null}),H=e.Record({memory:Ce,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),me=e.Variant({Callback:e.Record({token:H,callback:e.Func([],[],[])})}),z=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(me),status_code:e.Nat16}),E=e.Record({token:e.Opt(H),body:e.Vec(e.Nat8)}),b=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),$=e.Record({batch_id:e.Nat}),Ne=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),Te=e.Record({field:Ne,desc:e.Bool}),f=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),ke=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(f),description:e.Opt(e.Text),created_at:e.Opt(f)}),Ue=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),Le=e.Record({order:e.Opt(Te),owner:e.Opt(e.Principal),matcher:e.Opt(ke),paginate:e.Opt(Ue)}),qe=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),Be=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),Je=e.Record({key:qe,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,Be)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),je=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,Je)),items_length:e.Nat64}),Oe=e.Variant({Emulator:e.Null,Automation:e.Null}),ye=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),Me=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(Oe),created_at:e.Nat64,scope:ye,expires_at:e.Opt(e.Nat64)}),ge=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),F=e.Variant({Refunded:e.Null,Acknowledged:e.Null,Completed:e.Null}),S=e.Record({status:F,updated_at:e.Nat64,block_index_payment:e.Nat64,mission_control_id:e.Opt(e.Principal),created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64)}),xe=e.Record({block_index:e.Nat64,ledger_id:e.Principal}),Y=e.Record({owner:e.Principal,subaccount:e.Opt(e.Vec(e.Nat8))}),Ke=e.Record({status:F,updated_at:e.Nat64,created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64),purchaser:Y}),X=e.Record({desc:e.Bool}),Ge=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),We=e.Record({order:e.Opt(X),paginate:e.Opt(Ge)}),He=e.Record({proposal_id:e.Nat}),Q=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(He,P)),items_length:e.Nat64}),O=e.Variant({Orbiter:e.Null,Satellite:e.Null}),ze=e.Record({segment_id:e.Opt(e.Principal),segment_kind:e.Opt(O)}),$e=e.Record({user:e.Principal,segment_id:e.Principal,segment_kind:O}),D=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),segment_id:e.Principal,created_at:e.Nat64}),Ye=e.Record({openid:e.Opt(oe),version:e.Opt(e.Nat64),internet_identity:e.Opt(te),rules:e.Opt(J)}),Xe=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(Oe),scope:ye,expires_at:e.Opt(e.Nat64)}),Qe=e.Record({controller:Xe,controllers:e.Vec(e.Principal)}),Ze=e.Record({fee_cycles:le,fee_icp:e.Opt(a)}),Re=e.Record({metadata:e.Opt(e.Vec(e.Tuple(e.Text,e.Text))),segment_id:e.Principal,segment_kind:O}),ea=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),segment_id:e.Principal,segment_kind:O}),aa=e.Record({iframe:e.Opt(se),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(T),raw_access:e.Opt(ce),redirects:e.Opt(e.Vec(e.Tuple(e.Text,M)))}),he=e.Record({segment_id:e.Principal,segment_kind:O}),ra=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),ia=e.Record({chunk_id:e.Nat});return e.Service({add_credits:e.Func([e.Principal,a],[],[]),add_invitation_code:e.Func([e.Text],[],[]),assert_mission_control_center:e.Func([r],[],[]),authenticate:e.Func([n],[C],[]),commit_proposal:e.Func([U],[e.Null],[]),commit_proposal_asset_upload:e.Func([L],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(L)],[],[]),count_proposals:e.Func([],[e.Nat64],[]),create_mission_control:e.Func([ae],[e.Principal],[]),create_orbiter:e.Func([re],[e.Principal],[]),create_satellite:e.Func([Ae],[e.Principal],[]),del_controllers:e.Func([we],[],[]),del_custom_domain:e.Func([e.Text],[],[]),delete_proposal_assets:e.Func([ve],[],[]),get_account:e.Func([],[e.Opt(d)],[]),get_auth_config:e.Func([],[e.Opt(j)],[]),get_config:e.Func([],[K],[]),get_create_orbiter_fee:e.Func([G],[e.Opt(a)],[]),get_create_satellite_fee:e.Func([G],[e.Opt(a)],[]),get_credits:e.Func([],[a],[]),get_delegation:e.Func([Ie],[W],[]),get_fee:e.Func([v],[Se],[]),get_or_init_account:e.Func([],[d],[]),get_proposal:e.Func([e.Nat],[e.Opt(P)],[]),get_rate_config:e.Func([v],[_e],[]),get_storage_config:e.Func([],[A],[]),http_request:e.Func([De],[z],[]),http_request_streaming_callback:e.Func([H],[E],[]),init_proposal:e.Func([I],[e.Nat,P],[]),init_proposal_asset_upload:e.Func([b,e.Nat],[$],[]),init_proposal_many_assets_upload:e.Func([e.Vec(b),e.Nat],[e.Vec(e.Tuple(e.Text,$))],[]),list_accounts:e.Func([],[e.Vec(e.Tuple(e.Principal,d))],[]),list_assets:e.Func([e.Text,Le],[je],[]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,Me))],[]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,ge))],[]),list_icp_payments:e.Func([],[e.Vec(e.Tuple(e.Nat64,S))],[]),list_icrc_payments:e.Func([],[e.Vec(e.Tuple(xe,Ke))],[]),list_proposals:e.Func([We],[Q],[]),list_segments:e.Func([ze],[e.Vec(e.Tuple($e,D))],[]),reject_proposal:e.Func([U],[e.Null],[]),set_auth_config:e.Func([Ye],[j],[]),set_controllers:e.Func([Qe],[],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_fee:e.Func([v,Ze],[],[]),set_many_segments:e.Func([e.Vec(Re)],[e.Vec(D)],[]),set_rate_config:e.Func([v,_e],[],[]),set_segment:e.Func([Re],[D],[]),set_segment_metadata:e.Func([ea],[D],[]),set_storage_config:e.Func([aa],[A],[]),submit_proposal:e.Func([e.Nat],[e.Nat,P],[]),unset_many_segments:e.Func([e.Vec(he)],[],[]),unset_segment:e.Func([he],[],[]),upload_proposal_asset_chunk:e.Func([ra],[ia],[])})};var oo=async({identity:e,host:a,localActor:r})=>await no.create({identity:e,host:a,retryTimes:10,shouldFetchRootKey:r}),to=async({agent:e,...a})=>e??await so(a),so=async({identity:e,container:a})=>{let r=io(a)&&a!==!1;return await oo({identity:e,host:r?a===!0?"http://127.0.0.1:5987":a:"https://icp-api.io",localActor:r})};var Jr=({satelliteId:e,certified:a=!1,...r})=>Mr({canisterId:e,...r,idlFactory:a?cr:sr});var jr=({consoleId:e,certified:a=!1,...r})=>Mr({canisterId:e,...r,idlFactory:a?ro:ao}),Mr=({canisterId:e,idlFactory:a,...r})=>{if(eo(e))throw new Error("No canister ID provided.");return co({canisterId:e,idlFactory:a,...r})},co=async({canisterId:e,idlFactory:a,config:r,...i})=>{let n=await to(i);return Zn.createActor(a,{agent:n,canisterId:e,...r??{}})};import{assertNonNullish as lo}from"@junobuild/utils";import{nonNullish as lr}from"@junobuild/utils";var Kr=({satelliteId:e,container:a})=>{let{satelliteId:r}=dr({satelliteId:e}),{container:i}=pr({container:a});if(lr(i)&&i!==!1){let{host:n,protocol:o}=new URL(i===!0?sa:i);return`${o}//${r??"unknown"}.${n.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},dr=({satelliteId:e})=>lr(e)?{satelliteId:e}:g.getInstance().get()??{satelliteId:void 0},pr=({container:e})=>lr(e)?{container:e}:g.getInstance().get()??{container:void 0};var N=({satellite:e,options:{certified:a}})=>Wr({idlFactory:a?cr:sr,actorKey:`stock#${a?"update":"query"}`,...e}),Gr=({idlFactory:e,...a})=>Wr({idlFactory:e,actorKey:"extended#query",...a}),Wr=async({satelliteId:e,container:a,...r})=>{let{satelliteId:i}=dr({satelliteId:e});lo(i,"No satellite ID defined. Did you initialize Juno?");let{container:n}=pr({container:a});return await la.getInstance().getActor({satelliteId:i,container:n,...r})};import{Principal as po}from"@icp-sdk/core/principal";import{isNullish as ua,toNullable as k}from"@junobuild/utils";var Va=class extends Error{},fe=class extends Error{},Aa=class extends Error{},wa=class extends Error{},pa=class extends Error{},va=class extends Error{},Ia=class extends Error{},Pa=class extends Error{},Ea=class extends Error{};var Hr=e=>{if(ua(e))return k();switch(e.matcher){case"equal":return k({Equal:e.timestamp});case"greaterThan":return k({GreaterThan:e.timestamp});case"lessThan":return k({LessThan:e.timestamp});case"between":return k({Between:[e.timestamps.start,e.timestamps.end]});default:throw new Ea("Invalid list matcher for timestamp",e)}},Ve=({matcher:e,paginate:a,order:r,owner:i})=>({matcher:ua(e)?[]:[{key:k(e.key),description:k(e.description),created_at:Hr(e.createdAt),updated_at:Hr(e.updatedAt)}],paginate:k(ua(a)?void 0:{start_after:k(a.startAfter),limit:k(ua(a.limit)?void 0:BigInt(a.limit))}),order:k(ua(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:k(ua(i)?void 0:typeof i=="string"?po.fromText(i):i)});import{fromArray as uo}from"@junobuild/utils";var zr=async({data:e})=>{try{return await uo(e)}catch(a){console.error("The data parsing has failed, mapping to undefined as a fallback.",a);return}};import{fromArray as _o,fromNullable as $r,toArray as mo,toNullable as ur}from"@junobuild/utils";var _r=async e=>{let{data:a,version:r,description:i}=e;return{description:ur(i),data:await mo(a),version:ur(r)}},mr=e=>{let{version:a}=e;return{version:ur(a)}},na=async({doc:e,key:a})=>{let{owner:r,version:i,description:n,data:o,...t}=e;return{key:a,description:$r(n),owner:r.toText(),data:await _o(o),version:$r(i),...t}};var Yr=async({collection:e,key:a,...r})=>{let{get_doc:i}=await N(r),n=_a(await i(e,a));if(!No(n))return na({doc:n,key:a})},Xr=async({docs:e,...a})=>{let{get_many_docs:r}=await N(a),i=e.map(({collection:t,key:s})=>[t,s]),n=await r(i),o=[];for(let[t,s]of n){let c=_a(s);o.push(To(c)?await na({key:t,doc:c}):void 0)}return o},Qr=async({collection:e,doc:a,...r})=>{let{set_doc:i}=await N(r),{key:n}=a,o=await _r(a),t=await i(e,n,o);return await na({key:n,doc:t})},Zr=async({docs:e,...a})=>{let{set_many_docs:r}=await N(a),i=[];for(let{collection:t,doc:s}of e){let{key:c}=s;i.push([t,c,await _r(s)])}let n=await r(i),o=[];for(let[t,s]of n)o.push(await na({key:t,doc:s}));return o},ei=async({collection:e,doc:a,...r})=>{let{del_doc:i}=await N(r),{key:n}=a;return i(e,n,mr(a))},ai=async({docs:e,...a})=>{let{del_many_docs:r}=await N(a),i=e.map(({collection:n,doc:o})=>[n,o.key,mr(o)]);await r(i)},ri=async({collection:e,filter:a,...r})=>{let{del_filtered_docs:i}=await N(r);return i(e,Ve(a))},ii=async({collection:e,filter:a,...r})=>{let{list_docs:i}=await N(r),{items:n,items_page:o,items_length:t,matches_length:s,matches_pages:c}=await i(e,Ve(a)),l=[];for(let[d,p]of n){let{data:u,owner:m,description:y,version:V,...h}=p;l.push({key:d,description:_a(y),owner:m.toText(),data:await zr({data:u}),version:_a(V),...h})}return{items:l,items_length:t,items_page:_a(o),matches_length:s,matches_pages:_a(c)}},ni=async({collection:e,filter:a,...r})=>{let{count_docs:i}=await N(r);return i(e,Ve(a))};var ba=async({satellite:e,options:a,...r})=>{let i=_(e?.identity);return await Yr({...r,satellite:{...e,identity:i},options:a??Z})},rl=async({satellite:e,options:a,...r})=>{let i=_(e?.identity);return await Xr({...r,satellite:{...e,identity:i},options:a??Z})},oi=async({satellite:e,...a})=>{let r=_(e?.identity);return await Qr({...a,satellite:{...e,identity:r},options:{certified:!0}})},ti=async({satellite:e,...a})=>{let r=_(e?.identity);return await Zr({...a,satellite:{...e,identity:r},options:{certified:!0}})},il=async({satellite:e,...a})=>{let r=_(e?.identity);return await ei({...a,satellite:{...e,identity:r},options:{certified:!0}})},nl=async({satellite:e,...a})=>{let r=_(e?.identity);return await ai({...a,satellite:{...e,identity:r},options:{certified:!0}})},ol=async({satellite:e,filter:a,...r})=>{let i=_(e?.identity);return await ri({...r,filter:a??{},satellite:{...e,identity:i},options:{certified:!0}})},tl=async({satellite:e,options:a,filter:r,...i})=>{let n=_(e?.identity);return await ii({...i,filter:r??{},satellite:{...e,identity:n},options:a??Z})},sl=async({satellite:e,options:a,filter:r,...i})=>{let n=_(e?.identity);return await ni({...i,filter:r??{},satellite:{...e,identity:n},options:a??Z})};var ci=async({provider:e})=>{let{user:a,userId:r}=await Sa();if(si(a))return a;try{return await yo({userId:r,provider:e})}catch(i){if(tr({error:i,type:Br})){let n=await li({userId:r});if(si(n))return n}throw i}},Sa=async()=>{let e=Fa();if(Oo(e))throw new Pa("No identity to initialize the user. Have you initialized Juno?");let a=e.getPrincipal().toText(),r=await li({userId:a});return{userId:a,user:r}},li=({userId:e})=>ba({collection:"#user",key:e}),yo=({userId:e,...a})=>oi({collection:"#user",doc:{key:e,data:a}});var Da=async({syncTabsOnSuccess:e}={syncTabsOnSuccess:!1})=>{await ha({fn:async()=>{let{user:r}=await Sa();R.getInstance().set(r??null)},syncTabsOnSuccess:e})},di=async()=>{await qr({fn:async({authenticated:a})=>{let i=a?Sa:()=>Promise.resolve({user:null}),{user:n}=await i();R.getInstance().set(n??null)}})},Ca=async({user:e})=>{await ha({fn:async()=>{R.getInstance().set(e)},syncTabsOnSuccess:!0})};var pi=()=>{try{let e=da.getInstance(),a=async()=>{await di(),Ra({message:"junoSignInReload"})};return e.onLoginSuccess(a),()=>{e?.destroy()}}catch(e){console.warn("Auth BroadcastChannel initialization failed",e);return}};var ui=()=>{let e=()=>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"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_SATELLITE_ID??e():e()},_i=()=>{let e=()=>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"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_CONTAINER??e():e()},mi=()=>{let e=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_GOOGLE_CLIENT_ID??import.meta.env?.PUBLIC_GOOGLE_CLIENT_ID:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID??e():e()},Ni=()=>{let e=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_GITHUB_CLIENT_ID??import.meta.env?.PUBLIC_GITHUB_CLIENT_ID:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID??e():e()},ka=()=>{let e=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_JUNO_API_URL??import.meta.env?.PUBLIC_JUNO_API_URL:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_JUNO_API_URL??e():e()};import{isEmptyString as ho,isNullish as fo,nonNullish as Fi}from"@junobuild/utils";var Ti=BigInt(144e11),Oi=!1,yi={width:576,height:576},gi={width:424,height:576},Nr="internetcomputer.org",xi="ic0.app",Ua="id.ai";import{isBrowser as go,isNullish as Ri}from"@junobuild/utils";var hi=({width:e,height:a})=>{if(!go()||Ri(window)||Ri(window.top))return;let{top:{innerWidth:r,innerHeight:i}}=window,n=i/2+screenY-a/2,o=r/2+screenX-e/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${e}, height=${a}, top=${n}, left=${o}`};import{ERROR_USER_INTERRUPT as xo}from"@icp-sdk/auth/client";import{isNullish as Ro}from"@junobuild/utils";var ee=async({fn:e,step:a,onProgress:r})=>{r?.({step:a,state:"in_progress"});try{let i=await e();return r?.({step:a,state:"success"}),i}catch(i){throw r?.({step:a,state:"error"}),i}};var fi=(r=>(r[r.AuthorizingWithProvider=0]="AuthorizingWithProvider",r[r.CreatingOrRetrievingUser=1]="CreatingOrRetrievingUser",r))(fi||{});var La=class{async signIn({options:a,authClient:r,initAuth:i}){await ee({fn:async()=>await this.#e({options:a,authClient:r}),step:0,onProgress:a?.onProgress}),await ee({fn:async()=>await i({provider:this.id}),step:1,onProgress:a?.onProgress})}#e({options:a,authClient:r}){return new Promise(async(i,n)=>{if(Ro(r)){n(new fe("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}await r.login({onSuccess:i,onError:o=>{if(o===xo){n(new Aa(o));return}n(new Va(o))},maxTimeToLive:a?.maxTimeToLiveInNanoseconds??Ti,allowPinAuthentication:a?.allowPin??Oi,...a?.derivationOrigin!==void 0&&{derivationOrigin:a.derivationOrigin},...this.signInOptions({windowed:a?.windowed})})})}};var qa=class extends La{#e;constructor({domain:a}){super(),this.#e=a}get id(){return"internet_identity"}signInOptions({windowed:a}){let i=(()=>{let o=g.getInstance().get()?.container;if(fo(o)||o===!1){let d=[Nr,xi].includes(this.#e??Ua);return ho(this.#e)?`https://${Ua}`:d?`https://identity.${this.#e??Nr}`:`https://${this.#e}`}let t=g.getInstance().get(),s=Fi(t)&&Fi(t?.internetIdentityId)?t.internetIdentityId:br,{host:c,protocol:l}=new URL(o===!0?sa:o);return/apple/i.test(navigator?.vendor)?`${l}//${c}?canisterId=${s}`:`${l}//${s}.${c.replace("127.0.0.1","localhost")}`})();return{...a!==!1&&{windowOpenerFeatures:hi((()=>{try{let{hostname:o}=new URL(i);return o.includes(Ua)}catch{return!1}})()?gi:yi)},identityProvider:i}}};import{arrayBufferToUint8Array as Fo}from"@junobuild/utils";import{uint8ArrayToBase64 as Vo}from"@junobuild/utils";var Tr=e=>Vo(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),Ao=()=>crypto.getRandomValues(new Uint8Array(32)),wo=async({salt:e,caller:a})=>{let r=a.getPrincipal().toUint8Array(),i=new Uint8Array(e.length+r.byteLength);i.set(e),i.set(r,e.length);let n=await crypto.subtle.digest("SHA-256",i);return Tr(Fo(n))},Vi=async({caller:e})=>{let a=Ao();return{nonce:await wo({salt:a,caller:e}),salt:a}};import{Ed25519KeyIdentity as vo}from"@icp-sdk/core/identity";import{isNullish as Io}from"@junobuild/utils";import{Ed25519KeyIdentity as Jo}from"@icp-sdk/core/identity";import{base64ToUint8Array as jo,uint8ArrayToBase64 as Mo}from"@junobuild/utils";import{Delegation as Ho,ECDSAKeyIdentity as zo}from"@icp-sdk/core/identity";import{fromNullable as $o}from"@junobuild/utils";import{DelegationChain as Qo,DelegationIdentity as Zo}from"@icp-sdk/core/identity";import{isEmptyString as it}from"@junobuild/utils";import{isEmptyString as Or}from"@junobuild/utils";import{isNullish as ut,notEmptyString as _t}from"@junobuild/utils";var vi="juno:auth:openid",Ai={authUrl:"https://accounts.google.com/o/oauth2/v2/auth",authScopes:["openid","profile","email"],configUrl:"https://accounts.google.com/gsi/fedcm.json"},Ii={authUrl:"https://github.com/login/oauth/authorize",authScopes:["read:user","user:email"],initUrl:"https://api.juno.build/v1/auth/init/github",finalizeUrl:"https://api.juno.build/v1/auth/finalize/github"},Po=class extends Error{},Eo=class extends Error{},bo=class extends Error{},So=class extends Error{},Do=class extends Error{},Co=class extends Error{},ko=class extends Error{},Pi=class extends Error{},Uo=class extends Error{},Lo=class extends Error{},qo=class extends Error{constructor(e){super("GitHub OAuth initialization failed",e)}},Bo=class extends Error{constructor(e){super("GitHub OAuth finalization failed",e)}},Ei="__caller__",bi="__salt__",Si="__state__",Ko=({caller:e,state:a,salt:r})=>{let i={[Ei]:e.toJSON(),[bi]:Mo(r),[Si]:a};return JSON.stringify(i)},Go=e=>{let{[Ei]:a,[bi]:r,[Si]:i}=JSON.parse(e);return{caller:Jo.fromParsedJson(a),salt:jo(r),state:i}},wi=async({generateState:e})=>{let a=vo.generate(),{nonce:r,salt:i}=await Vi({caller:a}),n=await e({nonce:r}),o=Ko({caller:a,salt:i,state:n});return sessionStorage.setItem(vi,o),{nonce:r,state:n}},Wo=()=>{let e=sessionStorage.getItem(vi);if(Io(e))throw new Eo;return Go(e)},Di=({auth:e,identity:a})=>"satellite"in e?Jr({...e.satellite,identity:a}):jr({...e.console,identity:a}),Yo=async({actorParams:e,args:a})=>{let{authenticate:r}=await Di(e);return await r(a)},Xo=async({actorParams:e,args:a})=>{let{get_delegation:r}=await Di(e);return await r(a)},et=({delegations:e,sessionKey:a})=>{let[r,i]=e,n=Qo.fromDelegations(i,Uint8Array.from(r));return{identity:Zo.fromDelegation(a,n),delegationChain:n,sessionKey:a}},yr=async({jwt:e,context:a,auth:r})=>{let i=await zo.generate({extractable:!1}),n=new Uint8Array(i.getPublicKey().toDer()),{delegations:o,data:t}=await at({jwt:e,publicKey:n,context:a,auth:r});return{identity:et({sessionKey:i,delegations:o}),data:t}},at=async({jwt:e,publicKey:a,context:{caller:r,salt:i},auth:n})=>{let o=await Yo({args:{OpenId:{jwt:e,session_key:a,salt:i}},actorParams:{auth:n,identity:r}});if("Err"in o)throw new Do("Authentication failed",{cause:o});let{delegation:{user_key:t,expiration:s},...c}=o.Ok,l=await rt({jwt:e,context:{caller:r,salt:i},auth:n,publicKey:a,expiration:s}),{delegation:d,signature:p}=l,{pubkey:u,expiration:m,targets:y}=d;return{delegations:[t,[{delegation:new Ho(Uint8Array.from(u),m,$o(y)),signature:Uint8Array.from(p)}]],data:c}},rt=async({jwt:e,publicKey:a,context:{salt:r,caller:i},auth:n,expiration:o,maxRetries:t=5})=>{for(let s=0;s<t;s++){await new Promise(l=>{setInterval(l,1e3*s)});let c=await Xo({args:{OpenId:{jwt:e,session_key:a,salt:r,expiration:o}},actorParams:{auth:n,identity:i}});if("Err"in c){let{Err:l}=c;if("NoSuchDelegation"in l||"GetCachedJwks"in l)continue;throw new Uo("Getting delegation failed",{cause:c})}return c.Ok}throw new Lo},nt=async({url:e})=>{try{let a=await fetch(e,{credentials:"include"});return a.ok?{success:await a.json()}:{error:new Error(`Failed to fetch ${e} (${a.status})`)}}catch(a){return{error:new qo({cause:a})}}},ot=async({url:e,body:a})=>{try{let r=await fetch(e,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});return r.ok?{success:await r.json()}:{error:new Error(`Failed to fetch ${e} (${r.status})`)}}catch(r){return{error:new Bo({cause:r})}}},tt=async({auth:e,context:a,redirect:{finalizeUrl:r}})=>{let{location:{search:i}}=window,n=new URLSearchParams(i),o=n.get("code"),t=n.get("state"),s=await ot({url:r,body:{code:o,state:t}});if("error"in s)throw s.error;let{success:{token:c}}=s;if(it(c))throw new Pi;return await yr({jwt:c,auth:e,context:a})},st=async({auth:e,context:a})=>{let{location:{hash:r}}=window;if(Or(r)||!r.startsWith("#"))throw new Co("No hash found in the current location URL");let i=new URLSearchParams(r.slice(1)),n=i.get("state"),o=i.get("id_token"),{state:t}=a;if(Or(t)||n!==t)throw new ko("The provided state is invalid",{cause:n});if(Or(o))throw new Pi;return await yr({jwt:o,auth:e,context:a})},Ci=async e=>{let a=Wo();if("github"in e){let{github:{redirect:i,auth:n}}=e,{finalizeUrl:o}=Ii;return await tt({redirect:i??{finalizeUrl:o},auth:n,context:a})}let{google:r}=e;if("credentials"in r){let{credentials:{jwt:i},auth:n}=r;return await yr({jwt:i,context:a,auth:n})}return await st({...r,context:a})},gr=({url:e})=>{try{return new URL(e)}catch{throw new Po("Cannot parse authURL",{cause:e})}},ct=({initUrl:e})=>async({nonce:a})=>{let r=gr({url:e});r.searchParams.set("nonce",a);let i=await nt({url:r.toString()});if("error"in i)throw i.error;let{success:{state:n}}=i;return n},lt=({authUrl:e,clientId:a,authScopes:r,state:i,redirectUrl:n})=>{let o=gr({url:e});o.searchParams.set("client_id",a);let{location:{origin:t}}=window;o.searchParams.set("redirect_uri",n??t),o.searchParams.set("scope",r.join(" ")),o.searchParams.set("state",i),window.location.href=o.toString()},dt=()=>Tr(crypto.getRandomValues(new Uint8Array(12))),pt=async e=>dt(),mt=({authUrl:e,clientId:a,nonce:r,loginHint:i,authScopes:n,state:o,redirectUrl:t})=>{let s=gr({url:e});s.searchParams.set("client_id",a);let{location:{origin:c}}=window;s.searchParams.set("redirect_uri",t??c),s.searchParams.set("response_type","code id_token"),s.searchParams.set("scope",n.join(" ")),s.searchParams.set("state",o),s.searchParams.set("nonce",r),_t(i)?s.searchParams.set("login_hint",i):s.searchParams.set("prompt","select_account"),window.location.href=s.toString()},Nt=async({configUrl:e,clientId:a,nonce:r,loginHint:i,domainHint:n})=>{let o=await navigator.credentials.get({identity:{context:"use",providers:[{configURL:e,clientId:a,nonce:r,loginHint:i,domainHint:n}],mode:"active"},mediation:"required"});if(ut(o))throw new bo;let{type:t}=o;if(t!=="identity"||!("token"in o)||typeof o.token!="string")throw new So("Invalid credential received from FedCM API",{cause:o});let{token:s}=o;return{jwt:s}};async function Ba(e){if("github"in e){let{github:t}=e,{redirect:s}=t,{initUrl:c,...l}=s,{authUrl:d,authScopes:p,initUrl:u}=Ii,m=await wi({generateState:ct({initUrl:c??u})});lt({...l,...m,authUrl:d,authScopes:p});return}let a=await wi({generateState:pt}),{google:r}=e;if("credentials"in r){let{credentials:t}=r,{configUrl:s}=Ai;return await Nt({...t,...a,configUrl:s})}let{redirect:i}=r,{authUrl:n,authScopes:o}=Ai;mt({...i,...a,authUrl:n,authScopes:o})}import{isEmptyString as Tt,isNullish as Ot,nonNullish as yt,notEmptyString as gt}from"@junobuild/utils";var Ja=({url:e})=>{try{return new URL(e)}catch{return console.warn(`Cannot parse URL ${e}. Skipping option.`),null}};var xt=async e=>{let{satelliteId:a}=g.getInstance().get()??{satelliteId:void 0};if(Ot(a))throw new fe("Satellite ID not set. Have you initialized the Satellite?");let r=g.getInstance().get()?.container,i={auth:{satellite:{satelliteId:a,container:r}}},o=(()=>{let p="github"in e?e?.github?.options?.finalizeUrl:void 0;if(gt(p))return p;let u=ka();return Tt(u)?null:Ja({url:`${u}/v1/auth/finalize/github`})?.toString()??null})(),{identity:{delegationChain:t,sessionKey:s,identity:c},data:{doc:l}}=await Ci("github"in e?{github:{redirect:yt(o)?{finalizeUrl:o}:null,...i}}:{google:{redirect:null,...i}});await x.getInstance().setAuthClientStorage({delegationChain:t,sessionKey:s});let d=await na({doc:l,key:c.getPrincipal().toText()});await Ca({user:d})};var ki=e=>(e.preventDefault(),e.returnValue="Are you sure you want to exit?"),Rt=()=>{window.addEventListener("beforeunload",ki,{capture:!0})},ht=()=>{window.removeEventListener("beforeunload",ki,{capture:!0})},ja=async({fn:e})=>{try{return Rt(),await e()}finally{ht()}};import{DelegationChain as wt,DelegationIdentity as vt,ECDSAKeyIdentity as It,Ed25519KeyIdentity as Pt}from"@icp-sdk/core/identity";function Ui(e){return new Promise((a,r)=>{e.oncomplete=e.onsuccess=()=>a(e.result),e.onabort=e.onerror=()=>r(e.error)})}function Rr(e,a){let r,i=()=>{if(r)return r;let n=indexedDB.open(e);return n.onupgradeneeded=()=>n.result.createObjectStore(a),r=Ui(n),r.then(o=>{o.onclose=()=>r=void 0},()=>{}),r};return(n,o)=>i().then(t=>o(t.transaction(a,n).objectStore(a)))}var xr;function ft(){return xr||(xr=Rr("keyval-store","keyval")),xr}function Li(e,a,r=ft()){return r("readwrite",i=>new Promise((n,o)=>{i.get(e).onsuccess=function(){try{i.put(a(this.result),e),n(Ui(i.transaction))}catch(t){o(t)}}}))}var Ft=class extends Error{constructor(){super("A dev identity can only be used in browser environments")}},Vt=class extends Error{constructor(){super("A dev identity must only be used on localhost (127.0.0.1 or localhost)")}},At=class extends Error{constructor(e){super(`Identifier must be 32 characters or less, got ${e}`)}},Et=Rr("juno-dev-identifiers","juno-dev-identifiers-store");var qi=async({identifier:e="dev",maxTimeToLiveInMilliseconds:a}={})=>{if(!(typeof window<"u"))throw new Ft;let{location:{hostname:r}}=window;if(!["127.0.0.1","localhost"].includes(r))throw new Vt;let i=()=>{if(e.length>32)throw new At(e.length);return new TextEncoder().encode(e.padEnd(32,"0"))},n=async()=>{let s=i(),c=Pt.generate(s),l=await It.generate({extractable:!1}),d=a??6048e5,p=await wt.create(c,l.getPublicKey(),new Date(Date.now()+d));return{identity:vt.fromDelegation(l,p),sessionKey:l,delegationChain:p}},o=async()=>{await Li(e,s=>{let c=Date.now();return{createdAt:s?.createdAt??c,updatedAt:c}},Et)},t=await n();return await o(),t};var Ma=class{async signIn({options:a,initAuth:r,setStorage:i}){let{sessionKey:n,delegationChain:o}=await qi(a);await i({sessionKey:n,delegationChain:o}),await r({provider:void 0})}};import{isEmptyString as bt,isNullish as St,notEmptyString as Dt}from"@junobuild/utils";var Ka=class{async signIn({options:a={}}){let r=a?.redirect?.clientId??Ni();if(St(r))throw new pa;let{redirect:i}=a;await Ba({github:{redirect:{...i??{},clientId:r,initUrl:(()=>{let o=a?.redirect?.initUrl;if(Dt(o))return o;let t=ka();if(!bt(t))return Ja({url:`${t}/v1/auth/init/github`})?.toString()})()}}})}};import{isNullish as Ct}from"@junobuild/utils";var Ga=class{async signIn({options:a={}}){let r=a?.redirect?.clientId??mi();if(Ct(r))throw new pa;let{redirect:i}=a;await Ba({google:{redirect:{...i??{},clientId:r}}})}};import{IdbStorage as qt,KEY_STORAGE_DELEGATION as Bt,KEY_STORAGE_KEY as Jt}from"@icp-sdk/auth/client";import{AnonymousIdentity as jt}from"@icp-sdk/core/agent";import{DelegationChain as Mt,DelegationIdentity as Kt,DER_COSE_OID as Gt,ECDSAKeyIdentity as Wt,unwrapDER as Ht}from"@icp-sdk/core/identity";import{isNullish as hr,uint8ArrayToBase64 as zt}from"@junobuild/utils";import{nonNullish as kt,uint8ArrayToArrayOfNumber as Ut}from"@junobuild/utils";var Bi=async({delegationIdentity:e,passkeyIdentity:a,satelliteId:r})=>{let i=a.getCredential().getAAGUID(),[n,o]=await ti({docs:[{collection:"#user",doc:{key:e.getPrincipal().toText(),data:{provider:"webauthn",providerData:{webauthn:{...kt(i)&&{aaguid:Ut(i)}}}}}},{collection:"#user-webauthn",doc:{key:a.getCredential().getCredentialIdText(),data:{publicKey:a.getPublicKey().toRaw()}}}],satellite:{identity:e,satelliteId:r}});return n};var Ji=(o=>(o[o.RequestingUserCredential=0]="RequestingUserCredential",o[o.FinalizingCredential=1]="FinalizingCredential",o[o.Signing=2]="Signing",o[o.FinalizingSession=3]="FinalizingSession",o[o.RetrievingUser=4]="RetrievingUser",o))(Ji||{}),ji=(t=>(t[t.CreatingUserCredential=0]="CreatingUserCredential",t[t.ValidatingUserCredential=1]="ValidatingUserCredential",t[t.FinalizingCredential=2]="FinalizingCredential",t[t.Signing=3]="Signing",t[t.FinalizingSession=4]="FinalizingSession",t[t.RegisteringUser=5]="RegisteringUser",t))(ji||{});var ma=class{async signUp({options:{onProgress:a,maxTimeToLiveInMilliseconds:r,passkey:i}={},loadAuthWithUser:n}){let{satelliteId:o}=g.getInstance().get()??{satelliteId:void 0};if(hr(o))throw new fe("Satellite ID not set. Have you initialized the Satellite?");let t=({step:V,state:h})=>{switch(V){case Fe.RequestingUserCredential:a?.({step:1,state:h});break;case Fe.FinalizingCredential:a?.({step:2,state:h});break;case Fe.Signing:a?.({step:3,state:h});break}},c=await ee({fn:async()=>await rr.createWithNewCredential({onProgress:t,passkeyOptions:i}),step:0,onProgress:a}),{delegationIdentity:l,sessionKey:d}=await this.#e({identity:c,maxTimeToLiveInMilliseconds:r}),u=await ee({fn:async()=>await Bi({delegationIdentity:l,passkeyIdentity:c,satelliteId:o}),step:5,onProgress:a});await ee({fn:async()=>await this.#a({delegationIdentity:l,sessionKey:d}),step:4,onProgress:a}),await ee({fn:async()=>await n({user:u}),step:5,onProgress:a})}async signIn({options:{onProgress:a,maxTimeToLiveInMilliseconds:r}={},loadAuth:i}){let{satelliteId:n}=g.getInstance().get()??{satelliteId:void 0};if(hr(n))throw new fe("Satellite ID not set. Have you initialized the Satellite?");let o=async({credentialId:p})=>{let u=await ba({collection:"#user-webauthn",key:zt(p),options:{certified:!0},satellite:{identity:new jt,satelliteId:n}});if(hr(u))throw new va("No public key found for the selected passkey.");let{data:m}=u,{publicKey:y}=m;return Ht(y,Gt)},t=({step:p,state:u})=>{switch(p){case Fe.RequestingUserCredential:a?.({step:0,state:u});break;case Fe.FinalizingCredential:a?.({step:1,state:u});break;case Fe.Signing:a?.({step:2,state:u});break}},s=await rr.createWithExistingCredential({retrievePublicKey:o,onProgress:t}),{delegationIdentity:c,sessionKey:l}=await this.#e({identity:s,maxTimeToLiveInMilliseconds:r});await ee({fn:async()=>await this.#a({delegationIdentity:c,sessionKey:l}),step:3,onProgress:a}),await ee({fn:i,step:4,onProgress:a})}async#e({identity:a,maxTimeToLiveInMilliseconds:r}){let i=await Wt.generate({extractable:!1}),n=r??144e5,o=await Mt.create(a,i.getPublicKey(),new Date(Date.now()+n));return{delegationIdentity:Kt.fromDelegation(i,o),sessionKey:i}}async#a({sessionKey:a,delegationIdentity:r}){let i=new qt;await Promise.all([i.set(Jt,a.getKeyPair()),i.set(Bt,JSON.stringify(r.getDelegation().toJSON()))])}};var Mi=async({provider:e})=>{await ha({fn:async()=>{let r=await ci({provider:e});R.getInstance().set(r)},syncTabsOnSuccess:!0})},$t=async e=>{if("google"in e){let{google:{options:a}}=e;await fa({fn:()=>new Ga().signIn({options:a}),context:{windowGuard:!1}});return}if("github"in e){let{github:{options:a}}=e;await fa({fn:()=>new Ka().signIn({options:a}),context:{windowGuard:!1}});return}if("webauthn"in e){let{webauthn:{options:a,context:r}}=e;await fa({fn:()=>new ma().signIn({options:a,loadAuth:()=>Da({syncTabsOnSuccess:!0})}),context:r});return}if("internet_identity"in e){let{internet_identity:{options:a,context:r}}=e,{domain:i,...n}=a??{};await fa({fn:()=>new qa({domain:i}).signIn({options:n,authClient:x.getInstance().getAuthClient(),initAuth:Mi}),context:r});return}if("dev"in e){let{dev:{options:a}}=e,{setAuthClientStorage:r}=x.getInstance();await fa({fn:()=>new Ma().signIn({options:a,initAuth:Mi,setStorage:r}),context:{windowGuard:!1}});return}throw new wa("An unknown or unsupported provider was provided for sign-in.")},fa=async({fn:e,context:a})=>{if(a?.windowGuard===!1){await e();return}await ja({fn:e})};var Yt=async e=>{let a=async()=>await Xt(e);if(Object.values(e)?.[0].context?.windowGuard===!1){await a();return}await ja({fn:a})},Xt=async e=>{if("webauthn"in e){let{webauthn:{options:a}}=e;await new ma().signUp({options:a,loadAuthWithUser:Ca});return}throw new Ia("An unknown or unsupported provider was provided for sign-up.")};var bp=e=>e?.data?.provider==="webauthn",Sp=e=>e?.data?.provider==="google",Dp=e=>e?.data?.provider==="github";var Lp=async({idlFactory:e,satellite:a})=>{let r=_(a?.identity);return await Gr({idlFactory:e,...a,identity:r})};import{fromNullable as an,nonNullish as rn}from"@junobuild/utils";import{assertNonNullish as Jp,isBrowser as Qt,toNullable as Wa}from"@junobuild/utils";var Ki=async({asset:{data:e,headers:a,...r},actor:i,progress:n})=>{let{init_asset_upload:o,upload_asset_chunk:t,commit_asset_upload:s}=i,{batch_id:c}=await o(Zt(r));n?.onInitiatedBatch();let{chunkIds:l}=await rs({data:e,uploadFn:t,batchId:c});n?.onUploadedFileChunks(r.fullPath),await as({commitFn:s,batchId:c,data:e,headers:a,chunkIds:l}),n?.onCommittedBatch()};var Zt=({filename:e,collection:a,token:r,fullPath:i,encoding:n,description:o})=>({collection:a,full_path:i,name:e,token:Wa(r),encoding_type:Wa(n),description:Wa(o)}),es=({batchId:e,chunkIds:a,headers:r,data:i})=>{let n=r.find(([o,t])=>o.toLowerCase()==="content-type")===void 0&&i.type!==void 0&&i.type!==""?[["Content-Type",i.type]]:void 0;return{batch_id:e,chunk_ids:a.map(({chunk_id:o})=>o),headers:[...r,...n??[]]}},as=async({commitFn:e,...a})=>{let r=es(a);await e(r)},rs=async({data:e,uploadFn:a,batchId:r})=>{let i=[],n=Qt()?new Blob([await e.arrayBuffer()]):e,o=0n;for(let s=0;s<n.size;s+=19e5){let c=n.slice(s,s+19e5);i.push({batchId:r,chunk:c,uploadFn:a,orderId:o}),o++}let t=[];for await(let s of is({uploadChunks:i}))t=[...t,...s];return{chunkIds:t}};async function*is({uploadChunks:e,limit:a=12}){for(let r=0;r<e.length;r=r+a){let i=e.slice(r,r+a);yield await Promise.all(i.map(n=>ns(n)))}}var ns=async({batchId:e,chunk:a,uploadFn:r,orderId:i})=>r({batch_id:e,content:new Uint8Array(await a.arrayBuffer()),order_id:Wa(i)});import{fromNullable as Ha,toNullable as os}from"@junobuild/utils";var Gi=async({asset:e,...a})=>{let r=await N(a);await Ki({actor:r,asset:e})},Wi=async({collection:e,filter:a,...r})=>{let{list_assets:i}=await N(r),{items:n,items_length:o,items_page:t,matches_length:s,matches_pages:c}=await i(e,Ve(a));return{items:n.map(([l,d])=>d),items_length:o,items_page:Ha(t),matches_length:s,matches_pages:Ha(c)}},Hi=async({collection:e,filter:a,...r})=>{let{count_assets:i}=await N(r);return i(e,Ve(a))},zi=async({collection:e,fullPath:a,...r})=>(await N(r)).del_asset(e,a),$i=async({assets:e,satellite:a})=>{let{del_many_assets:r}=await N({satellite:a,options:{certified:!0}}),i=e.map(({collection:n,fullPath:o})=>[n,o]);await r(i)},Yi=async({collection:e,filter:a,...r})=>{let{del_filtered_assets:i}=await N(r);return i(e,Ve(a))},Xi=async({collection:e,fullPath:a,token:r,...i})=>{let{set_asset_token:n}=await N(i);return n(e,a,os(r))},Qi=async({collection:e,fullPath:a,...r})=>{let{get_asset:i}=await N(r);return Ha(await i(e,a))},Zi=async({assets:e,...a})=>{let{get_many_assets:r}=await N(a),i=e.map(({collection:o,fullPath:t})=>[o,t]);return(await r(i)).map(([o,t])=>Ha(t))};var en=e=>btoa([...e].map(a=>String.fromCharCode(a)).join(""));var au=e=>nn(e),ru=e=>nn({filename:e.data.name,...e}),nn=async({filename:e,data:a,collection:r,headers:i=[],fullPath:n,token:o,satellite:t,encoding:s,description:c})=>{let l=_(t?.identity),d=decodeURI(e),p=n??`/${r}/${d}`,u={...t,identity:l};return await Gi({asset:{data:a,filename:d,collection:r,token:o,headers:i,fullPath:p,encoding:s,description:c},satellite:u,options:{certified:!0}}),{downloadUrl:on({satellite:u,assetKey:{fullPath:p,token:o}}),fullPath:p,...rn(o)&&{token:o},name:d}},iu=async({collection:e,filter:a,satellite:r,options:i})=>{let n={...r,identity:_(r?.identity)},{items:o,...t}=await Wi({collection:e,filter:a??{},satellite:n,options:i??Z}),s=o.map(({key:{full_path:c,token:l,name:d,owner:p,description:u},headers:m,encodings:y,created_at:V,updated_at:h})=>{let C=an(l);return{fullPath:c,description:an(u),name:d,downloadUrl:on({satellite:n,assetKey:{fullPath:c,token:C}}),token:C,headers:m,encodings:y.reduce((U,[L,{modified:ae,sha256:re,total_length:q}])=>({...U,[L]:{modified:ae,sha256:en(re),total_length:q}}),{}),owner:p.toText(),created_at:V,updated_at:h}});return{items:s,assets:s,...t}},nu=async({collection:e,filter:a,satellite:r,options:i})=>{let n={...r,identity:_(r?.identity)};return await Hi({collection:e,satellite:n,filter:a??{},options:i??Z})},ou=({collection:e,fullPath:a,satellite:r})=>zi({collection:e,fullPath:a,satellite:{...r,identity:_(r?.identity)},options:{certified:!0}}),tu=({collection:e,fullPath:a,token:r,satellite:i})=>Xi({collection:e,fullPath:a,token:r,satellite:{...i,identity:_(i?.identity)},options:{certified:!0}}),su=({assets:e,satellite:a})=>$i({assets:e,satellite:{...a,identity:_(a?.identity)},options:{certified:!0}}),cu=async({collection:e,satellite:a,filter:r})=>{let i={...a,identity:_(a?.identity)};return await Yi({collection:e,satellite:i,filter:r??{},options:{certified:!0}})},lu=async({satellite:e,options:a,...r})=>{let i=_(e?.identity);return await Qi({...r,satellite:{...e,identity:i},options:a??Z})},du=async({satellite:e,options:a,...r})=>{let i=_(e?.identity);return await Zi({...r,satellite:{...e,identity:i},options:a??Z})},on=({assetKey:{fullPath:e,token:a},satellite:r})=>{let i={...r,identity:_(r?.identity)};return`${Kr(i)}${e}${rn(a)?`?token=${a}`:""}`};var ss=e=>{let a=e?.satelliteId??ui();ts(a,"Satellite ID is not configured. Juno cannot be initialized.");let r=e?.container??_i();return{satelliteId:a,internetIdentityId:e?.internetIdentityId,workers:e?.workers,syncTabs:e?.syncTabs,container:r}},xu=e=>cs(e),cs=async e=>{let a=ss(e);g.getInstance().set(a),await Da();let r=a.workers?.auth!==void 0?Lr(a.workers.auth):void 0,i=a.syncTabs===!1?void 0:pi();return[...tn(r)?[r]:[],...tn(i)?[i]:[]]},ls=e=>R.getInstance().subscribe(e),Ru=ls;export{fi as AuthClientSignInProgressStep,Pa as InitError,qa as InternetIdentityProvider,Ea as ListError,Va as SignInError,fe as SignInInitError,pa as SignInMissingClientIdError,wa as SignInProviderNotSupportedError,Aa as SignInUserInterruptError,Ia as SignUpProviderNotSupportedError,Ji as WebAuthnSignInProgressStep,va as WebAuthnSignInRetrievePublicKeyError,ji as WebAuthnSignUpProgressStep,Ru as authSubscribe,nu as countAssets,sl as countDocs,ou as deleteAsset,il as deleteDoc,cu as deleteFilteredAssets,ol as deleteFilteredDocs,su as deleteManyAssets,nl as deleteManyDocs,on as downloadUrl,lu as getAsset,ba as getDoc,Yn as getIdentityOnce,du as getManyAssets,rl as getManyDocs,Lp as getSatelliteExtendedActor,xt as handleRedirectCallback,xu as initJuno,cs as initSatellite,Dp as isGitHubUser,Sp as isGoogleUser,kn as isWebAuthnAvailable,bp as isWebAuthnUser,iu as listAssets,tl as listDocs,ls as onAuthStateChange,tu as setAssetToken,oi as setDoc,ti as setManyDocs,$t as signIn,or as signOut,Yt as signUp,$n as unsafeIdentity,au as uploadBlob,ru as uploadFile};
|
|
1
|
+
import{uint8ArrayToArrayOfNumber as sn}from"@junobuild/utils";import{DER_COSE_OID as dn,wrapDER as pn}from"@icp-sdk/core/agent";import{uint8ArrayToBase64 as Nn}from"@junobuild/utils";import{Cbor as Fr,SignIdentity as Vn}from"@icp-sdk/core/agent";import{arrayBufferToUint8Array as oa,isNullish as ga,uint8ArraysEqual as An}from"@junobuild/utils";import{nonNullish as Cn}from"@junobuild/utils";var cn=({authData:e})=>{if(e.byteLength<37)return{invalidAuthData:null};if(e.byteLength<53)return{invalidAuthData:null};let a=e.slice(37,53),r=ln({bytes:a});return"aaguid"in r?{aaguidBytes:a,aaguidText:r.aaguid}:{unknownProvider:null}},ln=({bytes:e})=>{if(e.length!==16)return{invalidBytes:null};let a=(e instanceof Uint8Array?sn(e):e).map(r=>r.toString(16).padStart(2,"0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5");return a==="00000000-0000-0000-0000-000000000000"?{unknownProvider:null}:{aaguid:a}};function un(e){let a=new DataView(new ArrayBuffer(2)),r=e.slice(53,55);[...new Uint8Array(r)].forEach((n,o)=>a.setUint8(o,n));let i=a.getUint16(0);return e.slice(55+i)}function _n(e){return pn(e,dn)}var mn=class{constructor(e){this._cose=e,this.#e=_n(e)}#e;toDer(){return this.#e}toRaw(){return new Uint8Array(this.#e)}},vr=class{#e;#a;constructor({rawId:e,cose:a}){this.#e=e,this.#a=new mn(a)}getPublicKey(){return this.#a}getCredentialId(){return this.#e}getCredentialIdText(){return Nn(this.#e)}},Tn=class extends vr{#e;#a;constructor({authData:e,...a}){super(a);let r=cn({authData:e});this.#e="aaguidText"in r?r.aaguidText:void 0,this.#a="aaguidBytes"in r?r.aaguidBytes:void 0}getAAGUID(){return this.#a}getAAGUIDText(){return this.#e}},On=class extends vr{},yn=class extends Error{},gn=class extends Error{},xn=class extends Error{},Rn=class extends Error{},hn=class extends Error{},fn=class extends Error{},Fn=class extends Error{},fr=class extends Error{};var wn={ECDSA_WITH_SHA256:-7,RSA_WITH_SHA256:-257},vn=6e4,Ir=()=>window.crypto.getRandomValues(new Uint8Array(16)),In=()=>Ir(),Pn=()=>Ir(),En=()=>{let{location:{href:e}}=window;try{let{hostname:a}=new URL(e);return a}catch{throw new yn}},Pr=({appId:e})=>e?.id??En(),bn=({appId:e,user:a}={})=>{let{document:{title:r}}=window,i=()=>({rp:{name:e?.name??r,id:Pr({appId:e})}}),n=()=>({user:{id:Pn(),name:a?.name??a?.displayName??r,displayName:a?.displayName??r}});return{attestation:"direct",challenge:In(),...i(),...n(),pubKeyCredParams:Object.values(wn).map(o=>({type:"public-key",alg:o})),excludeCredentials:[],authenticatorSelection:{authenticatorAttachment:"platform",userVerification:"preferred",residentKey:"required",requireResidentKey:!0}}},Sn=(e={})=>({rpId:Pr(e),allowCredentials:[],userVerification:"required"}),ar=async({fn:e,step:a,onProgress:r})=>{r?.({step:a,state:"in_progress"});try{let i=await e();return r?.({step:a,state:"success"}),i}catch(i){throw r?.({step:a,state:"error"}),i}},Fe=(e=>(e[e.RequestingUserCredential=0]="RequestingUserCredential",e[e.FinalizingCredential=1]="FinalizingCredential",e[e.Signing=2]="Signing",e))(Fe||{}),Er=({timeout:e})=>AbortSignal.timeout(e??vn),Dn=async({challenge:e,credentialIds:a,passkeyOptions:r,timeout:i})=>await navigator.credentials.get({publicKey:{...Sn(r),challenge:e.buffer,allowCredentials:(a??[]).map(n=>({id:n.buffer,type:"public-key"}))},signal:Er({timeout:i})}),Vr=e=>{if(e.status!=="initialized")throw new gn},Ar=e=>{if(ga(e))throw new xn},wr=({type:e})=>{if(e!=="public-key")throw new Rn},rr=class xa extends Vn{#e;#a;constructor({onProgress:a,...r}){if(super(),this.#e=a,"retrievePublicKey"in r){let{retrievePublicKey:i}=r;this.#a={status:"pending",retrievePublicKey:i};return}this.#a=xa.#r({credential:new Tn(r)})}static#r({credential:a}){return{status:"initialized",credential:a}}static async createWithNewCredential({passkeyOptions:a,timeout:r,...i}={}){let n=await navigator.credentials.create({publicKey:bn(a),signal:Er({timeout:r})});Ar(n),wr(n);let{response:{attestationObject:o},rawId:t}=n;if(ga(o))throw new hn;let{authData:s}=Fr.decode(oa(o)),c=un(s);return new xa({...i,rawId:oa(t),cose:c,authData:s})}static async createWithExistingCredential(a){return new xa(a)}getPublicKey(){Vr(this.#a);let{credential:a}=this.#a;return a.getPublicKey()}getCredential(){Vr(this.#a);let{credential:a}=this.#a;return a}async sign(a){let r=await ar({fn:async()=>{let i=await Dn({challenge:a,...this.#a.status==="initialized"&&{credentialIds:[this.#a.credential.getCredentialId()]}});return Ar(i),wr(i),i},step:0,onProgress:this.#e});return await ar({fn:async()=>{let{rawId:i}=r;if(this.#a.status==="initialized"){if(!An({a:this.#a.credential.getCredentialId(),b:oa(i)}))throw new fn;return}let{retrievePublicKey:n}=this.#a,o=await n({credentialId:oa(i)});this.#a=xa.#r({credential:new On({rawId:oa(i),cose:o})})},step:1,onProgress:this.#e}),await ar({fn:async()=>{let{response:i}=r,{clientDataJSON:n}=i,{authenticatorData:o,signature:t}="authenticatorData"in i&&"signature"in i?i:{};if(ga(o))throw new fr;if(ga(t))throw new fr;let s=Fr.encode({authenticator_data:o,client_data_json:new TextDecoder().decode(n),signature:oa(t)});if(ga(s))throw new Fn;return Object.assign(s,{__signature__:void 0}),s},step:2,onProgress:this.#e})}},kn=async()=>Cn(window.PublicKeyCredential)&&"isUserVerifyingPlatformAuthenticatorAvailable"in PublicKeyCredential?await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():!1;import{assertNonNullish as ts,nonNullish as tn}from"@junobuild/utils";import{isNullish as jn}from"@junobuild/utils";var ta=class{callbacks=[];populate(a){this.callbacks.forEach(({callback:r})=>r(a))}subscribe(a){let r=Symbol();return this.callbacks.push({id:r,callback:a}),()=>this.callbacks=this.callbacks.filter(({id:i})=>i!==r)}};var R=class e extends ta{static instance;authUser=null;constructor(){super()}static getInstance(){return e.instance||(e.instance=new e),e.instance}set(a){this.authUser=a,this.populate(a)}get(){return this.authUser}subscribe(a){let r=super.subscribe(a);return a(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var Ra=({message:e,detail:a})=>{let r=new CustomEvent(e,{detail:a,bubbles:!0});document.dispatchEvent(r)};import{Actor as Ln}from"@icp-sdk/core/agent";import{isNullish as nr}from"@junobuild/utils";import{isNullish as ir}from"@junobuild/utils";import{HttpAgent as Un}from"@icp-sdk/core/agent";import{nonNullish as Sr}from"@junobuild/utils";var sa="http://127.0.0.1:5987",br="rdmx6-jaaaa-aaaaa-aaadq-cai";var Dr=async({identity:e,container:a})=>{let i=Sr(a)&&a!==!1?a===!0?sa:a:"https://icp-api.io",n=Sr(a);return await Un.create({identity:e,shouldFetchRootKey:n,host:i})};var ca=class e{static instance;#e=void 0;constructor(){}static getInstance(){return ir(e.instance)&&(e.instance=new e),e.instance}async getAgent({identity:a,...r}){let i=a.getPrincipal().toText();if(ir(this.#e)||ir(this.#e[i])){let n=await Dr({identity:a,...r});return this.#e={...this.#e??{},[i]:n},n}return this.#e[i]}reset(){this.#e=null}};var la=class e{static instance;#e=void 0;constructor(){}static getInstance(){return nr(e.instance)&&(e.instance=new e),e.instance}async getActor({satelliteId:a,identity:r,actorKey:i,...n}){let o=`${i}#${r.getPrincipal().toText()}#${a};`;if(nr(this.#e)||nr(this.#e[o])){let t=await this.createActor({satelliteId:a,identity:r,...n});return this.#e={...this.#e??{},[o]:t},t}return this.#e[o]}reset(){this.#e=null}async createActor({idlFactory:a,satelliteId:r,...i}){let n=await ca.getInstance().getAgent(i);return Ln.createActor(a,{agent:n,canisterId:r})}};import{AuthClient as qn,IdbStorage as Cr,KEY_STORAGE_DELEGATION as kr,KEY_STORAGE_KEY as Ur}from"@icp-sdk/auth/client";import{isNullish as Bn}from"@junobuild/utils";var x=class e{static#e;#a;constructor(){}static getInstance(){return Bn(this.#e)&&(this.#e=new e),this.#e}createAuthClient=async()=>(this.#a=await qn.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}}),this.#a);safeCreateAuthClient=async()=>{let a=new Cr;return await Promise.all([a.remove(Ur),a.remove(kr)]),await this.createAuthClient()};getAuthClient=()=>this.#a;logout=async()=>{await this.#a?.logout(),this.#a=null};setAuthClientStorage=async({delegationChain:a,sessionKey:r})=>{let i=new Cr;await Promise.all([i.set(Ur,r.getKeyPair()),i.set(kr,JSON.stringify(a.toJSON()))])}};var or=async e=>{await Jn(),await x.getInstance().createAuthClient(),e?.windowReload!==!1&&window.location.reload()},Jn=async()=>{await x.getInstance().logout(),R.getInstance().reset(),la.getInstance().reset(),ca.getInstance().reset()};var Lr=e=>{let a=e===!0?"./workers/auth.worker.js":e,r=new Worker(a),i=async()=>{Ra({message:"junoSignOutAuthTimer"}),await or()};return r.onmessage=async({data:n})=>{let{msg:o,data:t}=n;switch(o){case"junoSignOutAuthTimer":await i();return;case"junoDelegationRemainingTime":Ra({message:"junoDelegationRemainingTime",detail:t?.authRemainingTime})}},R.getInstance().subscribe(n=>{if(jn(n)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};import{isNullish as Mn,nonNullish as Kn,notEmptyString as Gn}from"@junobuild/utils";var da=class e{static#e;#a;#r;static CHANNEL_NAME="juno_core_auth_channel";static MESSAGE_LOGIN_SUCCESS="authClientLoginSuccess";constructor(){this.#a=new BroadcastChannel(e.CHANNEL_NAME),this.#r=window.crypto.randomUUID()}static getInstance(){return Mn(this.#e)&&(this.#e=new e),this.#e}onLoginSuccess=a=>{let{location:{origin:r}}=window;this.#a.onmessage=async({origin:i,data:n})=>{i===r&&Kn(n)&&n.msg==="authClientLoginSuccess"&&Gn(n.emitterId)&&n.emitterId!==this.#r&&await a()}};destroy=()=>{this.#a.close(),e.#e=null};postLoginSuccess=()=>{let a={emitterId:this.#r,msg:e.MESSAGE_LOGIN_SUCCESS};this.#a.postMessage(a)};get __test__only__emitter_id__(){return this.#r}};var g=class e extends ta{static instance;env;constructor(){super()}static getInstance(){return e.instance||(e.instance=new e),e.instance}set(a){this.env=a,this.populate(a)}get(){return this.env}reset(){this.env=null}subscribe(a){let r=super.subscribe(a);return a(this.env),r}};var ha=async({fn:e,syncTabsOnSuccess:a})=>{let{authenticated:r}=await Wn({fn:e});!r||!a||g.getInstance().get()?.syncTabs===!1||Hn()},qr=async({fn:e})=>{let{createAuthClient:a}=x.getInstance(),i=await(await a()).isAuthenticated();await e({authenticated:i})},Wn=async({fn:e})=>{let{createAuthClient:a,safeCreateAuthClient:r}=x.getInstance();return await(await a()).isAuthenticated()?(await e(),{authenticated:!0}):(await r(),{authenticated:!1})},Hn=()=>{try{da.getInstance().postLoginSuccess()}catch(e){console.warn("Auth BroadcastChannel posting failed",e)}};var tr=({error:e,type:a})=>typeof e=="string"?e.includes(a):e instanceof Error?e.message.includes(a):!1;var Br="juno.datastore.error.user.cannot_update";import{isNullish as Oo,nonNullish as si}from"@junobuild/utils";var Z={certified:!1};import{AnonymousIdentity as Xn}from"@icp-sdk/core/agent";import{nonNullish as Qn}from"@junobuild/utils";import{isNullish as zn}from"@junobuild/utils";var Fa=()=>x.getInstance().getAuthClient()?.getIdentity(),$n=async()=>{let{getAuthClient:e,createAuthClient:a}=x.getInstance();return(e()??await a()).getIdentity()},Yn=async()=>{let e=R.getInstance().get();if(zn(e))return null;let a=x.getInstance().getAuthClient();return await a?.isAuthenticated()??!1?a?.getIdentity()??null:null};var _=e=>Qn(e)?e:Fa()??new Xn;import{fromNullable as _a,isNullish as No,nonNullish as To}from"@junobuild/utils";import{Actor as Zn}from"@icp-sdk/core/agent";import{isNullish as eo}from"@junobuild/utils";import{nonNullish as io}from"@junobuild/utils";import{HttpAgent as no}from"@icp-sdk/core/agent";var sr=({IDL:e})=>{let a=e.Variant({Heap:e.Null,Stable:e.Null}),r=e.Record({system_memory:e.Opt(a)}),i=e.Record({controllers:e.Vec(e.Principal),storage:e.Opt(r)}),n=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),o=e.Variant({OpenId:n}),t=e.Record({updated_at:e.Nat64,owner:e.Principal,data:e.Vec(e.Nat8),description:e.Opt(e.Text),created_at:e.Nat64,version:e.Opt(e.Nat64)}),s=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),c=e.Record({doc:t,delegation:s}),l=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),d=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),p=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),u=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,JwtVerify:d,GetOrFetchJwks:p,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),m=e.Variant({PrepareDelegation:u,RegisterUser:e.Text}),y=e.Variant({Ok:c,Err:m}),V=e.Record({jwt:e.Text,salt:e.Vec(e.Nat8)}),h=e.Variant({OpenId:V}),C=e.Variant({Write:e.Null,Submit:e.Null}),U=e.Record({scope:C,expires_at:e.Nat64}),L=e.Variant({JwtFindProvider:l,InvalidController:e.Text,GetCachedJwks:e.Null,JwtVerify:d,GetOrFetchJwks:p,ControllerAlreadyExists:e.Null,InvalidObservatoryId:e.Text,TooManyControllers:e.Text}),ae=e.Variant({PrepareAutomation:L,RegisterController:e.Text,SaveWorkflowMetadata:e.Text,SaveUniqueJtiToken:e.Text}),re=e.Variant({Ok:e.Tuple(e.Principal,U),Err:ae}),q=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),ie=e.Variant({Heap:e.Record({offset:e.Nat64}),Stable:e.Record({key:e.Opt(q)})}),Ae=e.Variant({Append:e.Null,Clear:e.Null,AppendWithRouting:e.Null}),we=e.Record({cursor:ie,strategy:Ae,chunk_size:e.Opt(e.Nat32)}),ve=e.Record({next_cursor:e.Opt(ie)}),B=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),ne=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),oe=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),te=e.Record({field:oe,desc:e.Bool}),J=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),j=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(J),description:e.Opt(e.Text),created_at:e.Opt(J)}),se=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),T=e.Record({order:e.Opt(te),owner:e.Opt(e.Principal),matcher:e.Opt(j),paginate:e.Opt(se)}),ce=e.Record({controllers:e.Vec(e.Principal)}),M=e.Variant({Emulator:e.Null,Automation:e.Null}),A=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),K=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(M),created_at:e.Nat64,scope:A,expires_at:e.Opt(e.Nat64)}),G=e.Record({version:e.Opt(e.Nat64)}),w=e.Variant({Db:e.Null,Storage:e.Null}),Ie=e.Record({version:e.Opt(e.Nat64)}),Pe=e.Record({proposal_ids:e.Vec(e.Nat)}),Ee=e.Record({cycles:e.Nat,destination_id:e.Principal}),be=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),W=e.Record({key:q,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,be)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),v=e.Variant({GitHub:e.Null,Google:e.Null}),le=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),Se=e.Record({delegation:e.Opt(le),client_id:e.Text}),de=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(v,Se))}),pe=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),ue=e.Record({allowed_callers:e.Vec(e.Principal)}),I=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(de),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(pe),rules:e.Opt(ue)}),P=e.Variant({GitHub:e.Null}),_e=e.Record({scope:e.Opt(C),max_time_to_live:e.Opt(e.Nat64)}),De=e.Record({owner:e.Text,name:e.Text}),Ce=e.Record({refs:e.Opt(e.Vec(e.Text))}),H=e.Record({controller:e.Opt(_e),repositories:e.Vec(e.Tuple(De,Ce))}),me=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(P,H))}),z=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(me),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64)}),E=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),b=e.Record({updated_at:e.Opt(e.Nat64),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E)}),$=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),Ne=e.Variant({Deny:e.Null,Allow:e.Null}),Te=e.Record({status_code:e.Nat16,location:e.Text}),f=e.Record({iframe:e.Opt($),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E),raw_access:e.Opt(Ne),redirects:e.Opt(e.Vec(e.Tuple(e.Text,Te)))}),ke=e.Record({db:e.Opt(b),authentication:e.Opt(I),storage:f,automation:e.Opt(z)}),Ue=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Le=e.Variant({OpenId:Ue}),qe=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),Be=e.Record({signature:e.Vec(e.Nat8),delegation:qe}),Je=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:d,GetOrFetchJwks:p,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),je=e.Variant({Ok:Be,Err:Je}),Oe=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),ye=e.Record({clear_existing_assets:e.Opt(e.Bool)}),Me=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),ge=e.Variant({AssetsUpgrade:ye,SegmentsDeployment:Me}),F=e.Record({status:Oe,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:ge}),S=e.Variant({Controllers:e.Null,Private:e.Null,Public:e.Null,Managed:e.Null}),xe=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),Y=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(a),updated_at:e.Nat64,max_size:e.Opt(e.Nat),read:S,created_at:e.Nat64,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(xe),write:S,max_changes_per_user:e.Opt(e.Nat32)}),Ke=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),X=e.Record({memory:a,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),Ge=e.Variant({Callback:e.Record({token:X,callback:e.Func([],[],["query"])})}),We=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(Ge),status_code:e.Nat16}),He=e.Record({token:e.Opt(X),body:e.Vec(e.Nat8)}),Q=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),O=e.Record({batch_id:e.Nat}),ze=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,W)),items_length:e.Nat64}),$e=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),D=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,t)),items_length:e.Nat64}),Ye=e.Record({desc:e.Bool}),Xe=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),Qe=e.Record({order:e.Opt(Ye),paginate:e.Opt(Xe)}),Ze=e.Record({proposal_id:e.Nat}),Re=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(Ze,F)),items_length:e.Nat64}),ea=e.Record({include_system:e.Bool}),aa=e.Record({matcher:e.Opt(ea)}),he=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(e.Text,Y)),items_length:e.Nat64}),ra=e.Record({stable:e.Nat64,heap:e.Nat64}),ia=e.Record({openid:e.Opt(de),version:e.Opt(e.Nat64),internet_identity:e.Opt(pe),rules:e.Opt(ue)}),za=e.Record({openid:e.Opt(me),version:e.Opt(e.Nat64)}),$a=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(M),scope:A,expires_at:e.Opt(e.Nat64)}),Ya=e.Record({controller:$a,controllers:e.Vec(e.Principal)}),Xa=e.Record({version:e.Opt(e.Nat64),max_memory_size:e.Opt(E)}),Na=e.Record({data:e.Vec(e.Nat8),description:e.Opt(e.Text),version:e.Opt(e.Nat64)}),Qa=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(a),max_size:e.Opt(e.Nat),read:S,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(xe),write:S,max_changes_per_user:e.Opt(e.Nat32)}),Ta=e.Record({iframe:e.Opt($),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E),raw_access:e.Opt(Ne),redirects:e.Opt(e.Vec(e.Tuple(e.Text,Te)))}),Za=e.Record({skip_certification:e.Opt(e.Bool)}),er=e.Record({config:Ta,options:Za}),Oa=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),ya=e.Record({chunk_id:e.Nat});return e.Service({authenticate:e.Func([o],[y],[]),authenticate_automation:e.Func([h],[re],[]),certify_assets_chunk:e.Func([we],[ve],[]),commit_asset_upload:e.Func([B],[],[]),commit_proposal:e.Func([ne],[e.Null],[]),commit_proposal_asset_upload:e.Func([B],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(B)],[],[]),count_assets:e.Func([e.Text,T],[e.Nat64],["query"]),count_collection_assets:e.Func([e.Text],[e.Nat64],["query"]),count_collection_docs:e.Func([e.Text],[e.Nat64],["query"]),count_docs:e.Func([e.Text,T],[e.Nat64],["query"]),count_proposals:e.Func([],[e.Nat64],["query"]),del_asset:e.Func([e.Text,e.Text],[],[]),del_assets:e.Func([e.Text],[],[]),del_controller_self:e.Func([],[],[]),del_controllers:e.Func([ce],[e.Vec(e.Tuple(e.Principal,K))],[]),del_custom_domain:e.Func([e.Text],[],[]),del_doc:e.Func([e.Text,e.Text,G],[],[]),del_docs:e.Func([e.Text],[],[]),del_filtered_assets:e.Func([e.Text,T],[],[]),del_filtered_docs:e.Func([e.Text,T],[],[]),del_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[],[]),del_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,G))],[],[]),del_rule:e.Func([w,e.Text,Ie],[],[]),delete_proposal_assets:e.Func([Pe],[],[]),deposit_cycles:e.Func([Ee],[],[]),get_asset:e.Func([e.Text,e.Text],[e.Opt(W)],["query"]),get_auth_config:e.Func([],[e.Opt(I)],["query"]),get_automation_config:e.Func([],[e.Opt(z)],["query"]),get_config:e.Func([],[ke],[]),get_db_config:e.Func([],[e.Opt(b)],["query"]),get_delegation:e.Func([Le],[je],["query"]),get_doc:e.Func([e.Text,e.Text],[e.Opt(t)],["query"]),get_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(W)))],["query"]),get_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(t)))],["query"]),get_proposal:e.Func([e.Nat],[e.Opt(F)],["query"]),get_rule:e.Func([w,e.Text],[e.Opt(Y)],["query"]),get_storage_config:e.Func([],[f],["query"]),http_request:e.Func([Ke],[We],["query"]),http_request_streaming_callback:e.Func([X],[He],["query"]),init_asset_upload:e.Func([Q],[O],[]),init_proposal:e.Func([ge],[e.Nat,F],[]),init_proposal_asset_upload:e.Func([Q,e.Nat],[O],[]),init_proposal_many_assets_upload:e.Func([e.Vec(Q),e.Nat],[e.Vec(e.Tuple(e.Text,O))],[]),list_assets:e.Func([e.Text,T],[ze],["query"]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,K))],["query"]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,$e))],["query"]),list_docs:e.Func([e.Text,T],[D],["query"]),list_proposals:e.Func([Qe],[Re],["query"]),list_rules:e.Func([w,aa],[he],["query"]),memory_size:e.Func([],[ra],["query"]),reject_proposal:e.Func([ne],[e.Null],[]),set_asset_token:e.Func([e.Text,e.Text,e.Opt(e.Text)],[],[]),set_auth_config:e.Func([ia],[I],[]),set_automation_config:e.Func([za],[z],[]),set_controllers:e.Func([Ya],[e.Vec(e.Tuple(e.Principal,K))],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_db_config:e.Func([Xa],[b],[]),set_doc:e.Func([e.Text,e.Text,Na],[t],[]),set_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,Na))],[e.Vec(e.Tuple(e.Text,t))],[]),set_rule:e.Func([w,e.Text,Qa],[Y],[]),set_storage_config:e.Func([Ta],[f],[]),set_storage_config_with_options:e.Func([er],[f],[]),submit_proposal:e.Func([e.Nat],[e.Nat,F],[]),switch_storage_system_memory:e.Func([],[],[]),upload_asset_chunk:e.Func([Oa],[ya],[]),upload_proposal_asset_chunk:e.Func([Oa],[ya],[])})},cr=({IDL:e})=>{let a=e.Variant({Heap:e.Null,Stable:e.Null}),r=e.Record({system_memory:e.Opt(a)}),i=e.Record({controllers:e.Vec(e.Principal),storage:e.Opt(r)}),n=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),o=e.Variant({OpenId:n}),t=e.Record({updated_at:e.Nat64,owner:e.Principal,data:e.Vec(e.Nat8),description:e.Opt(e.Text),created_at:e.Nat64,version:e.Opt(e.Nat64)}),s=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),c=e.Record({doc:t,delegation:s}),l=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),d=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),p=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),u=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,JwtVerify:d,GetOrFetchJwks:p,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),m=e.Variant({PrepareDelegation:u,RegisterUser:e.Text}),y=e.Variant({Ok:c,Err:m}),V=e.Record({jwt:e.Text,salt:e.Vec(e.Nat8)}),h=e.Variant({OpenId:V}),C=e.Variant({Write:e.Null,Submit:e.Null}),U=e.Record({scope:C,expires_at:e.Nat64}),L=e.Variant({JwtFindProvider:l,InvalidController:e.Text,GetCachedJwks:e.Null,JwtVerify:d,GetOrFetchJwks:p,ControllerAlreadyExists:e.Null,InvalidObservatoryId:e.Text,TooManyControllers:e.Text}),ae=e.Variant({PrepareAutomation:L,RegisterController:e.Text,SaveWorkflowMetadata:e.Text,SaveUniqueJtiToken:e.Text}),re=e.Variant({Ok:e.Tuple(e.Principal,U),Err:ae}),q=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),ie=e.Variant({Heap:e.Record({offset:e.Nat64}),Stable:e.Record({key:e.Opt(q)})}),Ae=e.Variant({Append:e.Null,Clear:e.Null,AppendWithRouting:e.Null}),we=e.Record({cursor:ie,strategy:Ae,chunk_size:e.Opt(e.Nat32)}),ve=e.Record({next_cursor:e.Opt(ie)}),B=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),ne=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),oe=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),te=e.Record({field:oe,desc:e.Bool}),J=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),j=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(J),description:e.Opt(e.Text),created_at:e.Opt(J)}),se=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),T=e.Record({order:e.Opt(te),owner:e.Opt(e.Principal),matcher:e.Opt(j),paginate:e.Opt(se)}),ce=e.Record({controllers:e.Vec(e.Principal)}),M=e.Variant({Emulator:e.Null,Automation:e.Null}),A=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),K=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(M),created_at:e.Nat64,scope:A,expires_at:e.Opt(e.Nat64)}),G=e.Record({version:e.Opt(e.Nat64)}),w=e.Variant({Db:e.Null,Storage:e.Null}),Ie=e.Record({version:e.Opt(e.Nat64)}),Pe=e.Record({proposal_ids:e.Vec(e.Nat)}),Ee=e.Record({cycles:e.Nat,destination_id:e.Principal}),be=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),W=e.Record({key:q,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,be)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),v=e.Variant({GitHub:e.Null,Google:e.Null}),le=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),Se=e.Record({delegation:e.Opt(le),client_id:e.Text}),de=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(v,Se))}),pe=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),ue=e.Record({allowed_callers:e.Vec(e.Principal)}),I=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(de),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(pe),rules:e.Opt(ue)}),P=e.Variant({GitHub:e.Null}),_e=e.Record({scope:e.Opt(C),max_time_to_live:e.Opt(e.Nat64)}),De=e.Record({owner:e.Text,name:e.Text}),Ce=e.Record({refs:e.Opt(e.Vec(e.Text))}),H=e.Record({controller:e.Opt(_e),repositories:e.Vec(e.Tuple(De,Ce))}),me=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(P,H))}),z=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(me),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64)}),E=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),b=e.Record({updated_at:e.Opt(e.Nat64),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E)}),$=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),Ne=e.Variant({Deny:e.Null,Allow:e.Null}),Te=e.Record({status_code:e.Nat16,location:e.Text}),f=e.Record({iframe:e.Opt($),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E),raw_access:e.Opt(Ne),redirects:e.Opt(e.Vec(e.Tuple(e.Text,Te)))}),ke=e.Record({db:e.Opt(b),authentication:e.Opt(I),storage:f,automation:e.Opt(z)}),Ue=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Le=e.Variant({OpenId:Ue}),qe=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),Be=e.Record({signature:e.Vec(e.Nat8),delegation:qe}),Je=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:d,GetOrFetchJwks:p,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),je=e.Variant({Ok:Be,Err:Je}),Oe=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),ye=e.Record({clear_existing_assets:e.Opt(e.Bool)}),Me=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),ge=e.Variant({AssetsUpgrade:ye,SegmentsDeployment:Me}),F=e.Record({status:Oe,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:ge}),S=e.Variant({Controllers:e.Null,Private:e.Null,Public:e.Null,Managed:e.Null}),xe=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),Y=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(a),updated_at:e.Nat64,max_size:e.Opt(e.Nat),read:S,created_at:e.Nat64,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(xe),write:S,max_changes_per_user:e.Opt(e.Nat32)}),Ke=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),X=e.Record({memory:a,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),Ge=e.Variant({Callback:e.Record({token:X,callback:e.Func([],[],[])})}),We=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(Ge),status_code:e.Nat16}),He=e.Record({token:e.Opt(X),body:e.Vec(e.Nat8)}),Q=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),O=e.Record({batch_id:e.Nat}),ze=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,W)),items_length:e.Nat64}),$e=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),D=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,t)),items_length:e.Nat64}),Ye=e.Record({desc:e.Bool}),Xe=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),Qe=e.Record({order:e.Opt(Ye),paginate:e.Opt(Xe)}),Ze=e.Record({proposal_id:e.Nat}),Re=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(Ze,F)),items_length:e.Nat64}),ea=e.Record({include_system:e.Bool}),aa=e.Record({matcher:e.Opt(ea)}),he=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(e.Text,Y)),items_length:e.Nat64}),ra=e.Record({stable:e.Nat64,heap:e.Nat64}),ia=e.Record({openid:e.Opt(de),version:e.Opt(e.Nat64),internet_identity:e.Opt(pe),rules:e.Opt(ue)}),za=e.Record({openid:e.Opt(me),version:e.Opt(e.Nat64)}),$a=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(M),scope:A,expires_at:e.Opt(e.Nat64)}),Ya=e.Record({controller:$a,controllers:e.Vec(e.Principal)}),Xa=e.Record({version:e.Opt(e.Nat64),max_memory_size:e.Opt(E)}),Na=e.Record({data:e.Vec(e.Nat8),description:e.Opt(e.Text),version:e.Opt(e.Nat64)}),Qa=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(a),max_size:e.Opt(e.Nat),read:S,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(xe),write:S,max_changes_per_user:e.Opt(e.Nat32)}),Ta=e.Record({iframe:e.Opt($),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(E),raw_access:e.Opt(Ne),redirects:e.Opt(e.Vec(e.Tuple(e.Text,Te)))}),Za=e.Record({skip_certification:e.Opt(e.Bool)}),er=e.Record({config:Ta,options:Za}),Oa=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),ya=e.Record({chunk_id:e.Nat});return e.Service({authenticate:e.Func([o],[y],[]),authenticate_automation:e.Func([h],[re],[]),certify_assets_chunk:e.Func([we],[ve],[]),commit_asset_upload:e.Func([B],[],[]),commit_proposal:e.Func([ne],[e.Null],[]),commit_proposal_asset_upload:e.Func([B],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(B)],[],[]),count_assets:e.Func([e.Text,T],[e.Nat64],[]),count_collection_assets:e.Func([e.Text],[e.Nat64],[]),count_collection_docs:e.Func([e.Text],[e.Nat64],[]),count_docs:e.Func([e.Text,T],[e.Nat64],[]),count_proposals:e.Func([],[e.Nat64],[]),del_asset:e.Func([e.Text,e.Text],[],[]),del_assets:e.Func([e.Text],[],[]),del_controller_self:e.Func([],[],[]),del_controllers:e.Func([ce],[e.Vec(e.Tuple(e.Principal,K))],[]),del_custom_domain:e.Func([e.Text],[],[]),del_doc:e.Func([e.Text,e.Text,G],[],[]),del_docs:e.Func([e.Text],[],[]),del_filtered_assets:e.Func([e.Text,T],[],[]),del_filtered_docs:e.Func([e.Text,T],[],[]),del_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[],[]),del_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,G))],[],[]),del_rule:e.Func([w,e.Text,Ie],[],[]),delete_proposal_assets:e.Func([Pe],[],[]),deposit_cycles:e.Func([Ee],[],[]),get_asset:e.Func([e.Text,e.Text],[e.Opt(W)],[]),get_auth_config:e.Func([],[e.Opt(I)],[]),get_automation_config:e.Func([],[e.Opt(z)],[]),get_config:e.Func([],[ke],[]),get_db_config:e.Func([],[e.Opt(b)],[]),get_delegation:e.Func([Le],[je],[]),get_doc:e.Func([e.Text,e.Text],[e.Opt(t)],[]),get_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(W)))],[]),get_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(t)))],[]),get_proposal:e.Func([e.Nat],[e.Opt(F)],[]),get_rule:e.Func([w,e.Text],[e.Opt(Y)],[]),get_storage_config:e.Func([],[f],[]),http_request:e.Func([Ke],[We],[]),http_request_streaming_callback:e.Func([X],[He],[]),init_asset_upload:e.Func([Q],[O],[]),init_proposal:e.Func([ge],[e.Nat,F],[]),init_proposal_asset_upload:e.Func([Q,e.Nat],[O],[]),init_proposal_many_assets_upload:e.Func([e.Vec(Q),e.Nat],[e.Vec(e.Tuple(e.Text,O))],[]),list_assets:e.Func([e.Text,T],[ze],[]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,K))],[]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,$e))],[]),list_docs:e.Func([e.Text,T],[D],[]),list_proposals:e.Func([Qe],[Re],[]),list_rules:e.Func([w,aa],[he],[]),memory_size:e.Func([],[ra],[]),reject_proposal:e.Func([ne],[e.Null],[]),set_asset_token:e.Func([e.Text,e.Text,e.Opt(e.Text)],[],[]),set_auth_config:e.Func([ia],[I],[]),set_automation_config:e.Func([za],[z],[]),set_controllers:e.Func([Ya],[e.Vec(e.Tuple(e.Principal,K))],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_db_config:e.Func([Xa],[b],[]),set_doc:e.Func([e.Text,e.Text,Na],[t],[]),set_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,Na))],[e.Vec(e.Tuple(e.Text,t))],[]),set_rule:e.Func([w,e.Text,Qa],[Y],[]),set_storage_config:e.Func([Ta],[f],[]),set_storage_config_with_options:e.Func([er],[f],[]),submit_proposal:e.Func([e.Nat],[e.Nat,F],[]),switch_storage_system_memory:e.Func([],[],[]),upload_asset_chunk:e.Func([Oa],[ya],[]),upload_proposal_asset_chunk:e.Func([Oa],[ya],[])})},ao=({IDL:e})=>{let a=e.Record({e8s:e.Nat64}),r=e.Record({mission_control_id:e.Principal,user:e.Principal}),i=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),n=e.Variant({OpenId:i}),o=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),t=e.Variant({GitHub:e.Null,Google:e.Null}),s=e.Record({name:e.Opt(e.Text),locale:e.Opt(e.Text),family_name:e.Opt(e.Text),email:e.Opt(e.Text),picture:e.Opt(e.Text),given_name:e.Opt(e.Text),preferred_username:e.Opt(e.Text)}),c=e.Record({provider:t,data:s}),l=e.Variant({InternetIdentity:e.Null,OpenId:c}),d=e.Record({updated_at:e.Nat64,credits:a,mission_control_id:e.Opt(e.Principal),provider:e.Opt(l),owner:e.Principal,created_at:e.Nat64}),p=e.Record({delegation:o,account:d}),u=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),m=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),y=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),V=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,JwtVerify:m,GetOrFetchJwks:y,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),h=e.Variant({PrepareDelegation:V,RegisterUser:e.Text}),C=e.Variant({Ok:p,Err:h}),U=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),L=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),ae=e.Record({subnet_id:e.Opt(e.Principal)}),re=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),name:e.Opt(e.Text),user:e.Principal}),q=e.Variant({Heap:e.Null,Stable:e.Null}),ie=e.Record({system_memory:e.Opt(q)}),Ae=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),storage:e.Opt(ie),name:e.Opt(e.Text),user:e.Principal}),we=e.Record({controllers:e.Vec(e.Principal)}),ve=e.Record({proposal_ids:e.Vec(e.Nat)}),B=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),ne=e.Record({delegation:e.Opt(B),client_id:e.Text}),oe=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(t,ne))}),te=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),J=e.Record({allowed_callers:e.Vec(e.Principal)}),j=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(oe),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(te),rules:e.Opt(J)}),se=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),T=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),ce=e.Variant({Deny:e.Null,Allow:e.Null}),M=e.Record({status_code:e.Nat16,location:e.Text}),A=e.Record({iframe:e.Opt(se),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(T),raw_access:e.Opt(ce),redirects:e.Opt(e.Vec(e.Tuple(e.Text,M)))}),K=e.Record({authentication:e.Opt(j),storage:A}),G=e.Record({user:e.Principal}),w=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Ie=e.Variant({OpenId:w}),Pe=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),Ee=e.Record({signature:e.Vec(e.Nat8),delegation:Pe}),be=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:m,GetOrFetchJwks:y,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),W=e.Variant({Ok:Ee,Err:be}),v=e.Variant({Orbiter:e.Null,MissionControl:e.Null,Satellite:e.Null}),le=e.Record({e12s:e.Nat64}),Se=e.Record({updated_at:e.Nat64,fee_cycles:le,fee_icp:e.Opt(a)}),de=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),pe=e.Record({clear_existing_assets:e.Opt(e.Bool)}),ue=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),I=e.Variant({AssetsUpgrade:pe,SegmentsDeployment:ue}),P=e.Record({status:de,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:I}),_e=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),De=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),Ce=e.Variant({Heap:e.Null,Stable:e.Null}),H=e.Record({memory:Ce,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),me=e.Variant({Callback:e.Record({token:H,callback:e.Func([],[],["query"])})}),z=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(me),status_code:e.Nat16}),E=e.Record({token:e.Opt(H),body:e.Vec(e.Nat8)}),b=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),$=e.Record({batch_id:e.Nat}),Ne=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),Te=e.Record({field:Ne,desc:e.Bool}),f=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),ke=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(f),description:e.Opt(e.Text),created_at:e.Opt(f)}),Ue=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),Le=e.Record({order:e.Opt(Te),owner:e.Opt(e.Principal),matcher:e.Opt(ke),paginate:e.Opt(Ue)}),qe=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),Be=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),Je=e.Record({key:qe,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,Be)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),je=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,Je)),items_length:e.Nat64}),Oe=e.Variant({Emulator:e.Null,Automation:e.Null}),ye=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),Me=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(Oe),created_at:e.Nat64,scope:ye,expires_at:e.Opt(e.Nat64)}),ge=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),F=e.Variant({Refunded:e.Null,Acknowledged:e.Null,Completed:e.Null}),S=e.Record({status:F,updated_at:e.Nat64,block_index_payment:e.Nat64,mission_control_id:e.Opt(e.Principal),created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64)}),xe=e.Record({block_index:e.Nat64,ledger_id:e.Principal}),Y=e.Record({owner:e.Principal,subaccount:e.Opt(e.Vec(e.Nat8))}),Ke=e.Record({status:F,updated_at:e.Nat64,created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64),purchaser:Y}),X=e.Record({desc:e.Bool}),Ge=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),We=e.Record({order:e.Opt(X),paginate:e.Opt(Ge)}),He=e.Record({proposal_id:e.Nat}),Q=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(He,P)),items_length:e.Nat64}),O=e.Variant({Orbiter:e.Null,Satellite:e.Null}),ze=e.Record({segment_id:e.Opt(e.Principal),segment_kind:e.Opt(O)}),$e=e.Record({user:e.Principal,segment_id:e.Principal,segment_kind:O}),D=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),segment_id:e.Principal,created_at:e.Nat64}),Ye=e.Record({openid:e.Opt(oe),version:e.Opt(e.Nat64),internet_identity:e.Opt(te),rules:e.Opt(J)}),Xe=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(Oe),scope:ye,expires_at:e.Opt(e.Nat64)}),Qe=e.Record({controller:Xe,controllers:e.Vec(e.Principal)}),Ze=e.Record({fee_cycles:le,fee_icp:e.Opt(a)}),Re=e.Record({metadata:e.Opt(e.Vec(e.Tuple(e.Text,e.Text))),segment_id:e.Principal,segment_kind:O}),ea=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),segment_id:e.Principal,segment_kind:O}),aa=e.Record({iframe:e.Opt(se),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(T),raw_access:e.Opt(ce),redirects:e.Opt(e.Vec(e.Tuple(e.Text,M)))}),he=e.Record({segment_id:e.Principal,segment_kind:O}),ra=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),ia=e.Record({chunk_id:e.Nat});return e.Service({add_credits:e.Func([e.Principal,a],[],[]),add_invitation_code:e.Func([e.Text],[],[]),assert_mission_control_center:e.Func([r],[],["query"]),authenticate:e.Func([n],[C],[]),commit_proposal:e.Func([U],[e.Null],[]),commit_proposal_asset_upload:e.Func([L],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(L)],[],[]),count_proposals:e.Func([],[e.Nat64],["query"]),create_mission_control:e.Func([ae],[e.Principal],[]),create_orbiter:e.Func([re],[e.Principal],[]),create_satellite:e.Func([Ae],[e.Principal],[]),del_controllers:e.Func([we],[],[]),del_custom_domain:e.Func([e.Text],[],[]),delete_proposal_assets:e.Func([ve],[],[]),get_account:e.Func([],[e.Opt(d)],["query"]),get_auth_config:e.Func([],[e.Opt(j)],["query"]),get_config:e.Func([],[K],["query"]),get_create_orbiter_fee:e.Func([G],[e.Opt(a)],["query"]),get_create_satellite_fee:e.Func([G],[e.Opt(a)],["query"]),get_credits:e.Func([],[a],["query"]),get_delegation:e.Func([Ie],[W],["query"]),get_fee:e.Func([v],[Se],["query"]),get_or_init_account:e.Func([],[d],[]),get_proposal:e.Func([e.Nat],[e.Opt(P)],["query"]),get_rate_config:e.Func([v],[_e],["query"]),get_storage_config:e.Func([],[A],["query"]),http_request:e.Func([De],[z],["query"]),http_request_streaming_callback:e.Func([H],[E],["query"]),init_proposal:e.Func([I],[e.Nat,P],[]),init_proposal_asset_upload:e.Func([b,e.Nat],[$],[]),init_proposal_many_assets_upload:e.Func([e.Vec(b),e.Nat],[e.Vec(e.Tuple(e.Text,$))],[]),list_accounts:e.Func([],[e.Vec(e.Tuple(e.Principal,d))],["query"]),list_assets:e.Func([e.Text,Le],[je],["query"]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,Me))],["query"]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,ge))],["query"]),list_icp_payments:e.Func([],[e.Vec(e.Tuple(e.Nat64,S))],["query"]),list_icrc_payments:e.Func([],[e.Vec(e.Tuple(xe,Ke))],["query"]),list_proposals:e.Func([We],[Q],["query"]),list_segments:e.Func([ze],[e.Vec(e.Tuple($e,D))],["query"]),reject_proposal:e.Func([U],[e.Null],[]),set_auth_config:e.Func([Ye],[j],[]),set_controllers:e.Func([Qe],[],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_fee:e.Func([v,Ze],[],[]),set_many_segments:e.Func([e.Vec(Re)],[e.Vec(D)],[]),set_rate_config:e.Func([v,_e],[],[]),set_segment:e.Func([Re],[D],[]),set_segment_metadata:e.Func([ea],[D],[]),set_storage_config:e.Func([aa],[A],[]),submit_proposal:e.Func([e.Nat],[e.Nat,P],[]),unset_many_segments:e.Func([e.Vec(he)],[],[]),unset_segment:e.Func([he],[],[]),upload_proposal_asset_chunk:e.Func([ra],[ia],[])})},ro=({IDL:e})=>{let a=e.Record({e8s:e.Nat64}),r=e.Record({mission_control_id:e.Principal,user:e.Principal}),i=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),n=e.Variant({OpenId:i}),o=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),t=e.Variant({GitHub:e.Null,Google:e.Null}),s=e.Record({name:e.Opt(e.Text),locale:e.Opt(e.Text),family_name:e.Opt(e.Text),email:e.Opt(e.Text),picture:e.Opt(e.Text),given_name:e.Opt(e.Text),preferred_username:e.Opt(e.Text)}),c=e.Record({provider:t,data:s}),l=e.Variant({InternetIdentity:e.Null,OpenId:c}),d=e.Record({updated_at:e.Nat64,credits:a,mission_control_id:e.Opt(e.Principal),provider:e.Opt(l),owner:e.Principal,created_at:e.Nat64}),p=e.Record({delegation:o,account:d}),u=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),m=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),y=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),V=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,JwtVerify:m,GetOrFetchJwks:y,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),h=e.Variant({PrepareDelegation:V,RegisterUser:e.Text}),C=e.Variant({Ok:p,Err:h}),U=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),L=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),ae=e.Record({subnet_id:e.Opt(e.Principal)}),re=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),name:e.Opt(e.Text),user:e.Principal}),q=e.Variant({Heap:e.Null,Stable:e.Null}),ie=e.Record({system_memory:e.Opt(q)}),Ae=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),storage:e.Opt(ie),name:e.Opt(e.Text),user:e.Principal}),we=e.Record({controllers:e.Vec(e.Principal)}),ve=e.Record({proposal_ids:e.Vec(e.Nat)}),B=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),ne=e.Record({delegation:e.Opt(B),client_id:e.Text}),oe=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(t,ne))}),te=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),J=e.Record({allowed_callers:e.Vec(e.Principal)}),j=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(oe),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(te),rules:e.Opt(J)}),se=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),T=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),ce=e.Variant({Deny:e.Null,Allow:e.Null}),M=e.Record({status_code:e.Nat16,location:e.Text}),A=e.Record({iframe:e.Opt(se),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(T),raw_access:e.Opt(ce),redirects:e.Opt(e.Vec(e.Tuple(e.Text,M)))}),K=e.Record({authentication:e.Opt(j),storage:A}),G=e.Record({user:e.Principal}),w=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Ie=e.Variant({OpenId:w}),Pe=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),Ee=e.Record({signature:e.Vec(e.Nat8),delegation:Pe}),be=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:m,GetOrFetchJwks:y,DeriveSeedFailed:e.Text,InvalidObservatoryId:e.Text}),W=e.Variant({Ok:Ee,Err:be}),v=e.Variant({Orbiter:e.Null,MissionControl:e.Null,Satellite:e.Null}),le=e.Record({e12s:e.Nat64}),Se=e.Record({updated_at:e.Nat64,fee_cycles:le,fee_icp:e.Opt(a)}),de=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),pe=e.Record({clear_existing_assets:e.Opt(e.Bool)}),ue=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),I=e.Variant({AssetsUpgrade:pe,SegmentsDeployment:ue}),P=e.Record({status:de,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:I}),_e=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),De=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),Ce=e.Variant({Heap:e.Null,Stable:e.Null}),H=e.Record({memory:Ce,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),me=e.Variant({Callback:e.Record({token:H,callback:e.Func([],[],[])})}),z=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(me),status_code:e.Nat16}),E=e.Record({token:e.Opt(H),body:e.Vec(e.Nat8)}),b=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),$=e.Record({batch_id:e.Nat}),Ne=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),Te=e.Record({field:Ne,desc:e.Bool}),f=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),ke=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(f),description:e.Opt(e.Text),created_at:e.Opt(f)}),Ue=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),Le=e.Record({order:e.Opt(Te),owner:e.Opt(e.Principal),matcher:e.Opt(ke),paginate:e.Opt(Ue)}),qe=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),Be=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),Je=e.Record({key:qe,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,Be)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),je=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,Je)),items_length:e.Nat64}),Oe=e.Variant({Emulator:e.Null,Automation:e.Null}),ye=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),Me=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(Oe),created_at:e.Nat64,scope:ye,expires_at:e.Opt(e.Nat64)}),ge=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),F=e.Variant({Refunded:e.Null,Acknowledged:e.Null,Completed:e.Null}),S=e.Record({status:F,updated_at:e.Nat64,block_index_payment:e.Nat64,mission_control_id:e.Opt(e.Principal),created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64)}),xe=e.Record({block_index:e.Nat64,ledger_id:e.Principal}),Y=e.Record({owner:e.Principal,subaccount:e.Opt(e.Vec(e.Nat8))}),Ke=e.Record({status:F,updated_at:e.Nat64,created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64),purchaser:Y}),X=e.Record({desc:e.Bool}),Ge=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),We=e.Record({order:e.Opt(X),paginate:e.Opt(Ge)}),He=e.Record({proposal_id:e.Nat}),Q=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(He,P)),items_length:e.Nat64}),O=e.Variant({Orbiter:e.Null,Satellite:e.Null}),ze=e.Record({segment_id:e.Opt(e.Principal),segment_kind:e.Opt(O)}),$e=e.Record({user:e.Principal,segment_id:e.Principal,segment_kind:O}),D=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),segment_id:e.Principal,created_at:e.Nat64}),Ye=e.Record({openid:e.Opt(oe),version:e.Opt(e.Nat64),internet_identity:e.Opt(te),rules:e.Opt(J)}),Xe=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),kind:e.Opt(Oe),scope:ye,expires_at:e.Opt(e.Nat64)}),Qe=e.Record({controller:Xe,controllers:e.Vec(e.Principal)}),Ze=e.Record({fee_cycles:le,fee_icp:e.Opt(a)}),Re=e.Record({metadata:e.Opt(e.Vec(e.Tuple(e.Text,e.Text))),segment_id:e.Principal,segment_kind:O}),ea=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),segment_id:e.Principal,segment_kind:O}),aa=e.Record({iframe:e.Opt(se),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(T),raw_access:e.Opt(ce),redirects:e.Opt(e.Vec(e.Tuple(e.Text,M)))}),he=e.Record({segment_id:e.Principal,segment_kind:O}),ra=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),ia=e.Record({chunk_id:e.Nat});return e.Service({add_credits:e.Func([e.Principal,a],[],[]),add_invitation_code:e.Func([e.Text],[],[]),assert_mission_control_center:e.Func([r],[],[]),authenticate:e.Func([n],[C],[]),commit_proposal:e.Func([U],[e.Null],[]),commit_proposal_asset_upload:e.Func([L],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(L)],[],[]),count_proposals:e.Func([],[e.Nat64],[]),create_mission_control:e.Func([ae],[e.Principal],[]),create_orbiter:e.Func([re],[e.Principal],[]),create_satellite:e.Func([Ae],[e.Principal],[]),del_controllers:e.Func([we],[],[]),del_custom_domain:e.Func([e.Text],[],[]),delete_proposal_assets:e.Func([ve],[],[]),get_account:e.Func([],[e.Opt(d)],[]),get_auth_config:e.Func([],[e.Opt(j)],[]),get_config:e.Func([],[K],[]),get_create_orbiter_fee:e.Func([G],[e.Opt(a)],[]),get_create_satellite_fee:e.Func([G],[e.Opt(a)],[]),get_credits:e.Func([],[a],[]),get_delegation:e.Func([Ie],[W],[]),get_fee:e.Func([v],[Se],[]),get_or_init_account:e.Func([],[d],[]),get_proposal:e.Func([e.Nat],[e.Opt(P)],[]),get_rate_config:e.Func([v],[_e],[]),get_storage_config:e.Func([],[A],[]),http_request:e.Func([De],[z],[]),http_request_streaming_callback:e.Func([H],[E],[]),init_proposal:e.Func([I],[e.Nat,P],[]),init_proposal_asset_upload:e.Func([b,e.Nat],[$],[]),init_proposal_many_assets_upload:e.Func([e.Vec(b),e.Nat],[e.Vec(e.Tuple(e.Text,$))],[]),list_accounts:e.Func([],[e.Vec(e.Tuple(e.Principal,d))],[]),list_assets:e.Func([e.Text,Le],[je],[]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,Me))],[]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,ge))],[]),list_icp_payments:e.Func([],[e.Vec(e.Tuple(e.Nat64,S))],[]),list_icrc_payments:e.Func([],[e.Vec(e.Tuple(xe,Ke))],[]),list_proposals:e.Func([We],[Q],[]),list_segments:e.Func([ze],[e.Vec(e.Tuple($e,D))],[]),reject_proposal:e.Func([U],[e.Null],[]),set_auth_config:e.Func([Ye],[j],[]),set_controllers:e.Func([Qe],[],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_fee:e.Func([v,Ze],[],[]),set_many_segments:e.Func([e.Vec(Re)],[e.Vec(D)],[]),set_rate_config:e.Func([v,_e],[],[]),set_segment:e.Func([Re],[D],[]),set_segment_metadata:e.Func([ea],[D],[]),set_storage_config:e.Func([aa],[A],[]),submit_proposal:e.Func([e.Nat],[e.Nat,P],[]),unset_many_segments:e.Func([e.Vec(he)],[],[]),unset_segment:e.Func([he],[],[]),upload_proposal_asset_chunk:e.Func([ra],[ia],[])})};var oo=async({identity:e,host:a,localActor:r})=>await no.create({identity:e,host:a,retryTimes:10,shouldFetchRootKey:r}),to=async({agent:e,...a})=>e??await so(a),so=async({identity:e,container:a})=>{let r=io(a)&&a!==!1;return await oo({identity:e,host:r?a===!0?"http://127.0.0.1:5987":a:"https://icp-api.io",localActor:r})};var Jr=({satelliteId:e,certified:a=!1,...r})=>Mr({canisterId:e,...r,idlFactory:a?cr:sr});var jr=({consoleId:e,certified:a=!1,...r})=>Mr({canisterId:e,...r,idlFactory:a?ro:ao}),Mr=({canisterId:e,idlFactory:a,...r})=>{if(eo(e))throw new Error("No canister ID provided.");return co({canisterId:e,idlFactory:a,...r})},co=async({canisterId:e,idlFactory:a,config:r,...i})=>{let n=await to(i);return Zn.createActor(a,{agent:n,canisterId:e,...r??{}})};import{assertNonNullish as lo}from"@junobuild/utils";import{nonNullish as lr}from"@junobuild/utils";var Kr=({satelliteId:e,container:a})=>{let{satelliteId:r}=dr({satelliteId:e}),{container:i}=pr({container:a});if(lr(i)&&i!==!1){let{host:n,protocol:o}=new URL(i===!0?sa:i);return`${o}//${r??"unknown"}.${n.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},dr=({satelliteId:e})=>lr(e)?{satelliteId:e}:g.getInstance().get()??{satelliteId:void 0},pr=({container:e})=>lr(e)?{container:e}:g.getInstance().get()??{container:void 0};var N=({satellite:e,options:{certified:a}})=>Wr({idlFactory:a?cr:sr,actorKey:`stock#${a?"update":"query"}`,...e}),Gr=({idlFactory:e,...a})=>Wr({idlFactory:e,actorKey:"extended#query",...a}),Wr=async({satelliteId:e,container:a,...r})=>{let{satelliteId:i}=dr({satelliteId:e});lo(i,"No satellite ID defined. Did you initialize Juno?");let{container:n}=pr({container:a});return await la.getInstance().getActor({satelliteId:i,container:n,...r})};import{Principal as po}from"@icp-sdk/core/principal";import{isNullish as ua,toNullable as k}from"@junobuild/utils";var Va=class extends Error{},fe=class extends Error{},Aa=class extends Error{},wa=class extends Error{},pa=class extends Error{},va=class extends Error{},Ia=class extends Error{},Pa=class extends Error{},Ea=class extends Error{};var Hr=e=>{if(ua(e))return k();switch(e.matcher){case"equal":return k({Equal:e.timestamp});case"greaterThan":return k({GreaterThan:e.timestamp});case"lessThan":return k({LessThan:e.timestamp});case"between":return k({Between:[e.timestamps.start,e.timestamps.end]});default:throw new Ea("Invalid list matcher for timestamp",e)}},Ve=({matcher:e,paginate:a,order:r,owner:i})=>({matcher:ua(e)?[]:[{key:k(e.key),description:k(e.description),created_at:Hr(e.createdAt),updated_at:Hr(e.updatedAt)}],paginate:k(ua(a)?void 0:{start_after:k(a.startAfter),limit:k(ua(a.limit)?void 0:BigInt(a.limit))}),order:k(ua(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:k(ua(i)?void 0:typeof i=="string"?po.fromText(i):i)});import{fromArray as uo}from"@junobuild/utils";var zr=async({data:e})=>{try{return await uo(e)}catch(a){console.error("The data parsing has failed, mapping to undefined as a fallback.",a);return}};import{fromArray as _o,fromNullable as $r,toArray as mo,toNullable as ur}from"@junobuild/utils";var _r=async e=>{let{data:a,version:r,description:i}=e;return{description:ur(i),data:await mo(a),version:ur(r)}},mr=e=>{let{version:a}=e;return{version:ur(a)}},na=async({doc:e,key:a})=>{let{owner:r,version:i,description:n,data:o,...t}=e;return{key:a,description:$r(n),owner:r.toText(),data:await _o(o),version:$r(i),...t}};var Yr=async({collection:e,key:a,...r})=>{let{get_doc:i}=await N(r),n=_a(await i(e,a));if(!No(n))return na({doc:n,key:a})},Xr=async({docs:e,...a})=>{let{get_many_docs:r}=await N(a),i=e.map(({collection:t,key:s})=>[t,s]),n=await r(i),o=[];for(let[t,s]of n){let c=_a(s);o.push(To(c)?await na({key:t,doc:c}):void 0)}return o},Qr=async({collection:e,doc:a,...r})=>{let{set_doc:i}=await N(r),{key:n}=a,o=await _r(a),t=await i(e,n,o);return await na({key:n,doc:t})},Zr=async({docs:e,...a})=>{let{set_many_docs:r}=await N(a),i=[];for(let{collection:t,doc:s}of e){let{key:c}=s;i.push([t,c,await _r(s)])}let n=await r(i),o=[];for(let[t,s]of n)o.push(await na({key:t,doc:s}));return o},ei=async({collection:e,doc:a,...r})=>{let{del_doc:i}=await N(r),{key:n}=a;return i(e,n,mr(a))},ai=async({docs:e,...a})=>{let{del_many_docs:r}=await N(a),i=e.map(({collection:n,doc:o})=>[n,o.key,mr(o)]);await r(i)},ri=async({collection:e,filter:a,...r})=>{let{del_filtered_docs:i}=await N(r);return i(e,Ve(a))},ii=async({collection:e,filter:a,...r})=>{let{list_docs:i}=await N(r),{items:n,items_page:o,items_length:t,matches_length:s,matches_pages:c}=await i(e,Ve(a)),l=[];for(let[d,p]of n){let{data:u,owner:m,description:y,version:V,...h}=p;l.push({key:d,description:_a(y),owner:m.toText(),data:await zr({data:u}),version:_a(V),...h})}return{items:l,items_length:t,items_page:_a(o),matches_length:s,matches_pages:_a(c)}},ni=async({collection:e,filter:a,...r})=>{let{count_docs:i}=await N(r);return i(e,Ve(a))};var ba=async({satellite:e,options:a,...r})=>{let i=_(e?.identity);return await Yr({...r,satellite:{...e,identity:i},options:a??Z})},rl=async({satellite:e,options:a,...r})=>{let i=_(e?.identity);return await Xr({...r,satellite:{...e,identity:i},options:a??Z})},oi=async({satellite:e,...a})=>{let r=_(e?.identity);return await Qr({...a,satellite:{...e,identity:r},options:{certified:!0}})},ti=async({satellite:e,...a})=>{let r=_(e?.identity);return await Zr({...a,satellite:{...e,identity:r},options:{certified:!0}})},il=async({satellite:e,...a})=>{let r=_(e?.identity);return await ei({...a,satellite:{...e,identity:r},options:{certified:!0}})},nl=async({satellite:e,...a})=>{let r=_(e?.identity);return await ai({...a,satellite:{...e,identity:r},options:{certified:!0}})},ol=async({satellite:e,filter:a,...r})=>{let i=_(e?.identity);return await ri({...r,filter:a??{},satellite:{...e,identity:i},options:{certified:!0}})},tl=async({satellite:e,options:a,filter:r,...i})=>{let n=_(e?.identity);return await ii({...i,filter:r??{},satellite:{...e,identity:n},options:a??Z})},sl=async({satellite:e,options:a,filter:r,...i})=>{let n=_(e?.identity);return await ni({...i,filter:r??{},satellite:{...e,identity:n},options:a??Z})};var ci=async({provider:e})=>{let{user:a,userId:r}=await Sa();if(si(a))return a;try{return await yo({userId:r,provider:e})}catch(i){if(tr({error:i,type:Br})){let n=await li({userId:r});if(si(n))return n}throw i}},Sa=async()=>{let e=Fa();if(Oo(e))throw new Pa("No identity to initialize the user. Have you initialized Juno?");let a=e.getPrincipal().toText(),r=await li({userId:a});return{userId:a,user:r}},li=({userId:e})=>ba({collection:"#user",key:e}),yo=({userId:e,...a})=>oi({collection:"#user",doc:{key:e,data:a}});var Da=async({syncTabsOnSuccess:e}={syncTabsOnSuccess:!1})=>{await ha({fn:async()=>{let{user:r}=await Sa();R.getInstance().set(r??null)},syncTabsOnSuccess:e})},di=async()=>{await qr({fn:async({authenticated:a})=>{let i=a?Sa:()=>Promise.resolve({user:null}),{user:n}=await i();R.getInstance().set(n??null)}})},Ca=async({user:e})=>{await ha({fn:async()=>{R.getInstance().set(e)},syncTabsOnSuccess:!0})};var pi=()=>{try{let e=da.getInstance(),a=async()=>{await di(),Ra({message:"junoSignInReload"})};return e.onLoginSuccess(a),()=>{e?.destroy()}}catch(e){console.warn("Auth BroadcastChannel initialization failed",e);return}};var ui=()=>{let e=()=>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"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_SATELLITE_ID??e():e()},_i=()=>{let e=()=>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"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_CONTAINER??e():e()},mi=()=>{let e=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_GOOGLE_CLIENT_ID??import.meta.env?.PUBLIC_GOOGLE_CLIENT_ID:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID??e():e()},Ni=()=>{let e=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_GITHUB_CLIENT_ID??import.meta.env?.PUBLIC_GITHUB_CLIENT_ID:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID??e():e()},ka=()=>{let e=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_JUNO_API_URL??import.meta.env?.PUBLIC_JUNO_API_URL:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_JUNO_API_URL??e():e()};import{isEmptyString as ho,isNullish as fo,nonNullish as Fi}from"@junobuild/utils";var Ti=BigInt(144e11),Oi=!1,yi={width:576,height:576},gi={width:424,height:576},Nr="internetcomputer.org",xi="ic0.app",Ua="id.ai";import{isBrowser as go,isNullish as Ri}from"@junobuild/utils";var hi=({width:e,height:a})=>{if(!go()||Ri(window)||Ri(window.top))return;let{top:{innerWidth:r,innerHeight:i}}=window,n=i/2+screenY-a/2,o=r/2+screenX-e/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${e}, height=${a}, top=${n}, left=${o}`};import{ERROR_USER_INTERRUPT as xo}from"@icp-sdk/auth/client";import{isNullish as Ro}from"@junobuild/utils";var ee=async({fn:e,step:a,onProgress:r})=>{r?.({step:a,state:"in_progress"});try{let i=await e();return r?.({step:a,state:"success"}),i}catch(i){throw r?.({step:a,state:"error"}),i}};var fi=(r=>(r[r.AuthorizingWithProvider=0]="AuthorizingWithProvider",r[r.CreatingOrRetrievingUser=1]="CreatingOrRetrievingUser",r))(fi||{});var La=class{async signIn({options:a,authClient:r,initAuth:i}){await ee({fn:async()=>await this.#e({options:a,authClient:r}),step:0,onProgress:a?.onProgress}),await ee({fn:async()=>await i({provider:this.id}),step:1,onProgress:a?.onProgress})}#e({options:a,authClient:r}){return new Promise(async(i,n)=>{if(Ro(r)){n(new fe("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}await r.login({onSuccess:i,onError:o=>{if(o===xo){n(new Aa(o));return}n(new Va(o))},maxTimeToLive:a?.maxTimeToLiveInNanoseconds??Ti,allowPinAuthentication:a?.allowPin??Oi,...a?.derivationOrigin!==void 0&&{derivationOrigin:a.derivationOrigin},...this.signInOptions({windowed:a?.windowed})})})}};var qa=class extends La{#e;constructor({domain:a}){super(),this.#e=a}get id(){return"internet_identity"}signInOptions({windowed:a}){let i=(()=>{let o=g.getInstance().get()?.container;if(fo(o)||o===!1){let d=[Nr,xi].includes(this.#e??Ua);return ho(this.#e)?`https://${Ua}`:d?`https://identity.${this.#e??Nr}`:`https://${this.#e}`}let t=g.getInstance().get(),s=Fi(t)&&Fi(t?.internetIdentityId)?t.internetIdentityId:br,{host:c,protocol:l}=new URL(o===!0?sa:o);return/apple/i.test(navigator?.vendor)?`${l}//${c}?canisterId=${s}`:`${l}//${s}.${c.replace("127.0.0.1","localhost")}`})();return{...a!==!1&&{windowOpenerFeatures:hi((()=>{try{let{hostname:o}=new URL(i);return o.includes(Ua)}catch{return!1}})()?gi:yi)},identityProvider:i}}};import{arrayBufferToUint8Array as Fo}from"@junobuild/utils";import{uint8ArrayToBase64 as Vo}from"@junobuild/utils";var Tr=e=>Vo(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),Ao=()=>crypto.getRandomValues(new Uint8Array(32)),wo=async({salt:e,caller:a})=>{let r=a.getPrincipal().toUint8Array(),i=new Uint8Array(e.length+r.byteLength);i.set(e),i.set(r,e.length);let n=await crypto.subtle.digest("SHA-256",i);return Tr(Fo(n))},Vi=async({caller:e})=>{let a=Ao();return{nonce:await wo({salt:a,caller:e}),salt:a}};import{Ed25519KeyIdentity as vo}from"@icp-sdk/core/identity";import{isNullish as Io}from"@junobuild/utils";import{Ed25519KeyIdentity as Jo}from"@icp-sdk/core/identity";import{base64ToUint8Array as jo,uint8ArrayToBase64 as Mo}from"@junobuild/utils";import{Delegation as Ho,ECDSAKeyIdentity as zo}from"@icp-sdk/core/identity";import{fromNullable as $o}from"@junobuild/utils";import{DelegationChain as Qo,DelegationIdentity as Zo}from"@icp-sdk/core/identity";import{isEmptyString as it}from"@junobuild/utils";import{isEmptyString as Or}from"@junobuild/utils";import{isNullish as ut,notEmptyString as _t}from"@junobuild/utils";var vi="juno:auth:openid",Ai={authUrl:"https://accounts.google.com/o/oauth2/v2/auth",authScopes:["openid","profile","email"],configUrl:"https://accounts.google.com/gsi/fedcm.json"},Ii={authUrl:"https://github.com/login/oauth/authorize",authScopes:["read:user","user:email"],initUrl:"https://api.juno.build/v1/auth/init/github",finalizeUrl:"https://api.juno.build/v1/auth/finalize/github"},Po=class extends Error{},Eo=class extends Error{},bo=class extends Error{},So=class extends Error{},Do=class extends Error{},Co=class extends Error{},ko=class extends Error{},Pi=class extends Error{},Uo=class extends Error{},Lo=class extends Error{},qo=class extends Error{constructor(e){super("GitHub OAuth initialization failed",e)}},Bo=class extends Error{constructor(e){super("GitHub OAuth finalization failed",e)}},Ei="__caller__",bi="__salt__",Si="__state__",Ko=({caller:e,state:a,salt:r})=>{let i={[Ei]:e.toJSON(),[bi]:Mo(r),[Si]:a};return JSON.stringify(i)},Go=e=>{let{[Ei]:a,[bi]:r,[Si]:i}=JSON.parse(e);return{caller:Jo.fromParsedJson(a),salt:jo(r),state:i}},wi=async({generateState:e})=>{let a=vo.generate(),{nonce:r,salt:i}=await Vi({caller:a}),n=await e({nonce:r}),o=Ko({caller:a,salt:i,state:n});return sessionStorage.setItem(vi,o),{nonce:r,state:n}},Wo=()=>{let e=sessionStorage.getItem(vi);if(Io(e))throw new Eo;return Go(e)},Di=({auth:e,identity:a})=>"satellite"in e?Jr({...e.satellite,identity:a}):jr({...e.console,identity:a}),Yo=async({actorParams:e,args:a})=>{let{authenticate:r}=await Di(e);return await r(a)},Xo=async({actorParams:e,args:a})=>{let{get_delegation:r}=await Di(e);return await r(a)},et=({delegations:e,sessionKey:a})=>{let[r,i]=e,n=Qo.fromDelegations(i,Uint8Array.from(r));return{identity:Zo.fromDelegation(a,n),delegationChain:n,sessionKey:a}},yr=async({jwt:e,context:a,auth:r})=>{let i=await zo.generate({extractable:!1}),n=new Uint8Array(i.getPublicKey().toDer()),{delegations:o,data:t}=await at({jwt:e,publicKey:n,context:a,auth:r});return{identity:et({sessionKey:i,delegations:o}),data:t}},at=async({jwt:e,publicKey:a,context:{caller:r,salt:i},auth:n})=>{let o=await Yo({args:{OpenId:{jwt:e,session_key:a,salt:i}},actorParams:{auth:n,identity:r}});if("Err"in o)throw new Do("Authentication failed",{cause:o});let{delegation:{user_key:t,expiration:s},...c}=o.Ok,l=await rt({jwt:e,context:{caller:r,salt:i},auth:n,publicKey:a,expiration:s}),{delegation:d,signature:p}=l,{pubkey:u,expiration:m,targets:y}=d;return{delegations:[t,[{delegation:new Ho(Uint8Array.from(u),m,$o(y)),signature:Uint8Array.from(p)}]],data:c}},rt=async({jwt:e,publicKey:a,context:{salt:r,caller:i},auth:n,expiration:o,maxRetries:t=5})=>{for(let s=0;s<t;s++){await new Promise(l=>{setInterval(l,1e3*s)});let c=await Xo({args:{OpenId:{jwt:e,session_key:a,salt:r,expiration:o}},actorParams:{auth:n,identity:i}});if("Err"in c){let{Err:l}=c;if("NoSuchDelegation"in l||"GetCachedJwks"in l)continue;throw new Uo("Getting delegation failed",{cause:c})}return c.Ok}throw new Lo},nt=async({url:e})=>{try{let a=await fetch(e,{credentials:"include"});return a.ok?{success:await a.json()}:{error:new Error(`Failed to fetch ${e} (${a.status})`)}}catch(a){return{error:new qo({cause:a})}}},ot=async({url:e,body:a})=>{try{let r=await fetch(e,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});return r.ok?{success:await r.json()}:{error:new Error(`Failed to fetch ${e} (${r.status})`)}}catch(r){return{error:new Bo({cause:r})}}},tt=async({auth:e,context:a,redirect:{finalizeUrl:r}})=>{let{location:{search:i}}=window,n=new URLSearchParams(i),o=n.get("code"),t=n.get("state"),s=await ot({url:r,body:{code:o,state:t}});if("error"in s)throw s.error;let{success:{token:c}}=s;if(it(c))throw new Pi;return await yr({jwt:c,auth:e,context:a})},st=async({auth:e,context:a})=>{let{location:{hash:r}}=window;if(Or(r)||!r.startsWith("#"))throw new Co("No hash found in the current location URL");let i=new URLSearchParams(r.slice(1)),n=i.get("state"),o=i.get("id_token"),{state:t}=a;if(Or(t)||n!==t)throw new ko("The provided state is invalid",{cause:n});if(Or(o))throw new Pi;return await yr({jwt:o,auth:e,context:a})},Ci=async e=>{let a=Wo();if("github"in e){let{github:{redirect:i,auth:n}}=e,{finalizeUrl:o}=Ii;return await tt({redirect:i??{finalizeUrl:o},auth:n,context:a})}let{google:r}=e;if("credentials"in r){let{credentials:{jwt:i},auth:n}=r;return await yr({jwt:i,context:a,auth:n})}return await st({...r,context:a})},gr=({url:e})=>{try{return new URL(e)}catch{throw new Po("Cannot parse authURL",{cause:e})}},ct=({initUrl:e})=>async({nonce:a})=>{let r=gr({url:e});r.searchParams.set("nonce",a);let i=await nt({url:r.toString()});if("error"in i)throw i.error;let{success:{state:n}}=i;return n},lt=({authUrl:e,clientId:a,authScopes:r,state:i,redirectUrl:n})=>{let o=gr({url:e});o.searchParams.set("client_id",a);let{location:{origin:t}}=window;o.searchParams.set("redirect_uri",n??t),o.searchParams.set("scope",r.join(" ")),o.searchParams.set("state",i),window.location.href=o.toString()},dt=()=>Tr(crypto.getRandomValues(new Uint8Array(12))),pt=async e=>dt(),mt=({authUrl:e,clientId:a,nonce:r,loginHint:i,authScopes:n,state:o,redirectUrl:t})=>{let s=gr({url:e});s.searchParams.set("client_id",a);let{location:{origin:c}}=window;s.searchParams.set("redirect_uri",t??c),s.searchParams.set("response_type","code id_token"),s.searchParams.set("scope",n.join(" ")),s.searchParams.set("state",o),s.searchParams.set("nonce",r),_t(i)?s.searchParams.set("login_hint",i):s.searchParams.set("prompt","select_account"),window.location.href=s.toString()},Nt=async({configUrl:e,clientId:a,nonce:r,loginHint:i,domainHint:n})=>{let o=await navigator.credentials.get({identity:{context:"use",providers:[{configURL:e,clientId:a,nonce:r,loginHint:i,domainHint:n}],mode:"active"},mediation:"required"});if(ut(o))throw new bo;let{type:t}=o;if(t!=="identity"||!("token"in o)||typeof o.token!="string")throw new So("Invalid credential received from FedCM API",{cause:o});let{token:s}=o;return{jwt:s}};async function Ba(e){if("github"in e){let{github:t}=e,{redirect:s}=t,{initUrl:c,...l}=s,{authUrl:d,authScopes:p,initUrl:u}=Ii,m=await wi({generateState:ct({initUrl:c??u})});lt({...l,...m,authUrl:d,authScopes:p});return}let a=await wi({generateState:pt}),{google:r}=e;if("credentials"in r){let{credentials:t}=r,{configUrl:s}=Ai;return await Nt({...t,...a,configUrl:s})}let{redirect:i}=r,{authUrl:n,authScopes:o}=Ai;mt({...i,...a,authUrl:n,authScopes:o})}import{isEmptyString as Tt,isNullish as Ot,nonNullish as yt,notEmptyString as gt}from"@junobuild/utils";var Ja=({url:e})=>{try{return new URL(e)}catch{return console.warn(`Cannot parse URL ${e}. Skipping option.`),null}};var xt=async e=>{let{satelliteId:a}=g.getInstance().get()??{satelliteId:void 0};if(Ot(a))throw new fe("Satellite ID not set. Have you initialized the Satellite?");let r=g.getInstance().get()?.container,i={auth:{satellite:{satelliteId:a,container:r}}},o=(()=>{let p="github"in e?e?.github?.options?.finalizeUrl:void 0;if(gt(p))return p;let u=ka();return Tt(u)?null:Ja({url:`${u}/v1/auth/finalize/github`})?.toString()??null})(),{identity:{delegationChain:t,sessionKey:s,identity:c},data:{doc:l}}=await Ci("github"in e?{github:{redirect:yt(o)?{finalizeUrl:o}:null,...i}}:{google:{redirect:null,...i}});await x.getInstance().setAuthClientStorage({delegationChain:t,sessionKey:s});let d=await na({doc:l,key:c.getPrincipal().toText()});await Ca({user:d})};var ki=e=>(e.preventDefault(),e.returnValue="Are you sure you want to exit?"),Rt=()=>{window.addEventListener("beforeunload",ki,{capture:!0})},ht=()=>{window.removeEventListener("beforeunload",ki,{capture:!0})},ja=async({fn:e})=>{try{return Rt(),await e()}finally{ht()}};import{DelegationChain as wt,DelegationIdentity as vt,ECDSAKeyIdentity as It,Ed25519KeyIdentity as Pt}from"@icp-sdk/core/identity";function Ui(e){return new Promise((a,r)=>{e.oncomplete=e.onsuccess=()=>a(e.result),e.onabort=e.onerror=()=>r(e.error)})}function Rr(e,a){let r,i=()=>{if(r)return r;let n=indexedDB.open(e);return n.onupgradeneeded=()=>n.result.createObjectStore(a),r=Ui(n),r.then(o=>{o.onclose=()=>r=void 0},()=>{}),r};return(n,o)=>i().then(t=>o(t.transaction(a,n).objectStore(a)))}var xr;function ft(){return xr||(xr=Rr("keyval-store","keyval")),xr}function Li(e,a,r=ft()){return r("readwrite",i=>new Promise((n,o)=>{i.get(e).onsuccess=function(){try{i.put(a(this.result),e),n(Ui(i.transaction))}catch(t){o(t)}}}))}var Ft=class extends Error{constructor(){super("A dev identity can only be used in browser environments")}},Vt=class extends Error{constructor(){super("A dev identity must only be used on localhost (127.0.0.1 or localhost)")}},At=class extends Error{constructor(e){super(`Identifier must be 32 characters or less, got ${e}`)}},Et=Rr("juno-dev-identifiers","juno-dev-identifiers-store");var qi=async({identifier:e="dev",maxTimeToLiveInMilliseconds:a}={})=>{if(!(typeof window<"u"))throw new Ft;let{location:{hostname:r}}=window;if(!["127.0.0.1","localhost"].includes(r))throw new Vt;let i=()=>{if(e.length>32)throw new At(e.length);return new TextEncoder().encode(e.padEnd(32,"0"))},n=async()=>{let s=i(),c=Pt.generate(s),l=await It.generate({extractable:!1}),d=a??6048e5,p=await wt.create(c,l.getPublicKey(),new Date(Date.now()+d));return{identity:vt.fromDelegation(l,p),sessionKey:l,delegationChain:p}},o=async()=>{await Li(e,s=>{let c=Date.now();return{createdAt:s?.createdAt??c,updatedAt:c}},Et)},t=await n();return await o(),t};var Ma=class{async signIn({options:a,initAuth:r,setStorage:i}){let{sessionKey:n,delegationChain:o}=await qi(a);await i({sessionKey:n,delegationChain:o}),await r({provider:void 0})}};import{isEmptyString as bt,isNullish as St,notEmptyString as Dt}from"@junobuild/utils";var Ka=class{async signIn({options:a={}}){let r=a?.redirect?.clientId??Ni();if(St(r))throw new pa;let{redirect:i}=a;await Ba({github:{redirect:{...i??{},clientId:r,initUrl:(()=>{let o=a?.redirect?.initUrl;if(Dt(o))return o;let t=ka();if(!bt(t))return Ja({url:`${t}/v1/auth/init/github`})?.toString()})()}}})}};import{isNullish as Ct}from"@junobuild/utils";var Ga=class{async signIn({options:a={}}){let r=a?.redirect?.clientId??mi();if(Ct(r))throw new pa;let{redirect:i}=a;await Ba({google:{redirect:{...i??{},clientId:r}}})}};import{IdbStorage as qt,KEY_STORAGE_DELEGATION as Bt,KEY_STORAGE_KEY as Jt}from"@icp-sdk/auth/client";import{AnonymousIdentity as jt}from"@icp-sdk/core/agent";import{DelegationChain as Mt,DelegationIdentity as Kt,DER_COSE_OID as Gt,ECDSAKeyIdentity as Wt,unwrapDER as Ht}from"@icp-sdk/core/identity";import{isNullish as hr,uint8ArrayToBase64 as zt}from"@junobuild/utils";import{nonNullish as kt,uint8ArrayToArrayOfNumber as Ut}from"@junobuild/utils";var Bi=async({delegationIdentity:e,passkeyIdentity:a,satelliteId:r})=>{let i=a.getCredential().getAAGUID(),[n,o]=await ti({docs:[{collection:"#user",doc:{key:e.getPrincipal().toText(),data:{provider:"webauthn",providerData:{webauthn:{...kt(i)&&{aaguid:Ut(i)}}}}}},{collection:"#user-webauthn",doc:{key:a.getCredential().getCredentialIdText(),data:{publicKey:a.getPublicKey().toRaw()}}}],satellite:{identity:e,satelliteId:r}});return n};var Ji=(o=>(o[o.RequestingUserCredential=0]="RequestingUserCredential",o[o.FinalizingCredential=1]="FinalizingCredential",o[o.Signing=2]="Signing",o[o.FinalizingSession=3]="FinalizingSession",o[o.RetrievingUser=4]="RetrievingUser",o))(Ji||{}),ji=(t=>(t[t.CreatingUserCredential=0]="CreatingUserCredential",t[t.ValidatingUserCredential=1]="ValidatingUserCredential",t[t.FinalizingCredential=2]="FinalizingCredential",t[t.Signing=3]="Signing",t[t.FinalizingSession=4]="FinalizingSession",t[t.RegisteringUser=5]="RegisteringUser",t))(ji||{});var ma=class{async signUp({options:{onProgress:a,maxTimeToLiveInMilliseconds:r,passkey:i}={},loadAuthWithUser:n}){let{satelliteId:o}=g.getInstance().get()??{satelliteId:void 0};if(hr(o))throw new fe("Satellite ID not set. Have you initialized the Satellite?");let t=({step:V,state:h})=>{switch(V){case Fe.RequestingUserCredential:a?.({step:1,state:h});break;case Fe.FinalizingCredential:a?.({step:2,state:h});break;case Fe.Signing:a?.({step:3,state:h});break}},c=await ee({fn:async()=>await rr.createWithNewCredential({onProgress:t,passkeyOptions:i}),step:0,onProgress:a}),{delegationIdentity:l,sessionKey:d}=await this.#e({identity:c,maxTimeToLiveInMilliseconds:r}),u=await ee({fn:async()=>await Bi({delegationIdentity:l,passkeyIdentity:c,satelliteId:o}),step:5,onProgress:a});await ee({fn:async()=>await this.#a({delegationIdentity:l,sessionKey:d}),step:4,onProgress:a}),await ee({fn:async()=>await n({user:u}),step:5,onProgress:a})}async signIn({options:{onProgress:a,maxTimeToLiveInMilliseconds:r}={},loadAuth:i}){let{satelliteId:n}=g.getInstance().get()??{satelliteId:void 0};if(hr(n))throw new fe("Satellite ID not set. Have you initialized the Satellite?");let o=async({credentialId:p})=>{let u=await ba({collection:"#user-webauthn",key:zt(p),options:{certified:!0},satellite:{identity:new jt,satelliteId:n}});if(hr(u))throw new va("No public key found for the selected passkey.");let{data:m}=u,{publicKey:y}=m;return Ht(y,Gt)},t=({step:p,state:u})=>{switch(p){case Fe.RequestingUserCredential:a?.({step:0,state:u});break;case Fe.FinalizingCredential:a?.({step:1,state:u});break;case Fe.Signing:a?.({step:2,state:u});break}},s=await rr.createWithExistingCredential({retrievePublicKey:o,onProgress:t}),{delegationIdentity:c,sessionKey:l}=await this.#e({identity:s,maxTimeToLiveInMilliseconds:r});await ee({fn:async()=>await this.#a({delegationIdentity:c,sessionKey:l}),step:3,onProgress:a}),await ee({fn:i,step:4,onProgress:a})}async#e({identity:a,maxTimeToLiveInMilliseconds:r}){let i=await Wt.generate({extractable:!1}),n=r??144e5,o=await Mt.create(a,i.getPublicKey(),new Date(Date.now()+n));return{delegationIdentity:Kt.fromDelegation(i,o),sessionKey:i}}async#a({sessionKey:a,delegationIdentity:r}){let i=new qt;await Promise.all([i.set(Jt,a.getKeyPair()),i.set(Bt,JSON.stringify(r.getDelegation().toJSON()))])}};var Mi=async({provider:e})=>{await ha({fn:async()=>{let r=await ci({provider:e});R.getInstance().set(r)},syncTabsOnSuccess:!0})},$t=async e=>{if("google"in e){let{google:{options:a}}=e;await fa({fn:()=>new Ga().signIn({options:a}),context:{windowGuard:!1}});return}if("github"in e){let{github:{options:a}}=e;await fa({fn:()=>new Ka().signIn({options:a}),context:{windowGuard:!1}});return}if("webauthn"in e){let{webauthn:{options:a,context:r}}=e;await fa({fn:()=>new ma().signIn({options:a,loadAuth:()=>Da({syncTabsOnSuccess:!0})}),context:r});return}if("internet_identity"in e){let{internet_identity:{options:a,context:r}}=e,{domain:i,...n}=a??{};await fa({fn:()=>new qa({domain:i}).signIn({options:n,authClient:x.getInstance().getAuthClient(),initAuth:Mi}),context:r});return}if("dev"in e){let{dev:{options:a}}=e,{setAuthClientStorage:r}=x.getInstance();await fa({fn:()=>new Ma().signIn({options:a,initAuth:Mi,setStorage:r}),context:{windowGuard:!1}});return}throw new wa("An unknown or unsupported provider was provided for sign-in.")},fa=async({fn:e,context:a})=>{if(a?.windowGuard===!1){await e();return}await ja({fn:e})};var Yt=async e=>{let a=async()=>await Xt(e);if(Object.values(e)?.[0].context?.windowGuard===!1){await a();return}await ja({fn:a})},Xt=async e=>{if("webauthn"in e){let{webauthn:{options:a}}=e;await new ma().signUp({options:a,loadAuthWithUser:Ca});return}throw new Ia("An unknown or unsupported provider was provided for sign-up.")};var bp=e=>e?.data?.provider==="webauthn",Sp=e=>e?.data?.provider==="google",Dp=e=>e?.data?.provider==="github";var Lp=async({idlFactory:e,satellite:a})=>{let r=_(a?.identity);return await Gr({idlFactory:e,...a,identity:r})};import{fromNullable as an,nonNullish as rn}from"@junobuild/utils";import{assertNonNullish as Jp,isBrowser as Qt,toNullable as Wa}from"@junobuild/utils";var Ki=async({asset:{data:e,headers:a,...r},actor:i,progress:n})=>{let{init_asset_upload:o,upload_asset_chunk:t,commit_asset_upload:s}=i,{batch_id:c}=await o(Zt(r));n?.onInitiatedBatch();let{chunkIds:l}=await rs({data:e,uploadFn:t,batchId:c});n?.onUploadedFileChunks(r.fullPath),await as({commitFn:s,batchId:c,data:e,headers:a,chunkIds:l}),n?.onCommittedBatch()};var Zt=({filename:e,collection:a,token:r,fullPath:i,encoding:n,description:o})=>({collection:a,full_path:i,name:e,token:Wa(r),encoding_type:Wa(n),description:Wa(o)}),es=({batchId:e,chunkIds:a,headers:r,data:i})=>{let n=r.find(([o,t])=>o.toLowerCase()==="content-type")===void 0&&i.type!==void 0&&i.type!==""?[["Content-Type",i.type]]:void 0;return{batch_id:e,chunk_ids:a.map(({chunk_id:o})=>o),headers:[...r,...n??[]]}},as=async({commitFn:e,...a})=>{let r=es(a);await e(r)},rs=async({data:e,uploadFn:a,batchId:r})=>{let i=[],n=Qt()?new Blob([await e.arrayBuffer()]):e,o=0n;for(let s=0;s<n.size;s+=19e5){let c=n.slice(s,s+19e5);i.push({batchId:r,chunk:c,uploadFn:a,orderId:o}),o++}let t=[];for await(let s of is({uploadChunks:i}))t=[...t,...s];return{chunkIds:t}};async function*is({uploadChunks:e,limit:a=12}){for(let r=0;r<e.length;r=r+a){let i=e.slice(r,r+a);yield await Promise.all(i.map(n=>ns(n)))}}var ns=async({batchId:e,chunk:a,uploadFn:r,orderId:i})=>r({batch_id:e,content:new Uint8Array(await a.arrayBuffer()),order_id:Wa(i)});import{fromNullable as Ha,toNullable as os}from"@junobuild/utils";var Gi=async({asset:e,...a})=>{let r=await N(a);await Ki({actor:r,asset:e})},Wi=async({collection:e,filter:a,...r})=>{let{list_assets:i}=await N(r),{items:n,items_length:o,items_page:t,matches_length:s,matches_pages:c}=await i(e,Ve(a));return{items:n.map(([l,d])=>d),items_length:o,items_page:Ha(t),matches_length:s,matches_pages:Ha(c)}},Hi=async({collection:e,filter:a,...r})=>{let{count_assets:i}=await N(r);return i(e,Ve(a))},zi=async({collection:e,fullPath:a,...r})=>(await N(r)).del_asset(e,a),$i=async({assets:e,satellite:a})=>{let{del_many_assets:r}=await N({satellite:a,options:{certified:!0}}),i=e.map(({collection:n,fullPath:o})=>[n,o]);await r(i)},Yi=async({collection:e,filter:a,...r})=>{let{del_filtered_assets:i}=await N(r);return i(e,Ve(a))},Xi=async({collection:e,fullPath:a,token:r,...i})=>{let{set_asset_token:n}=await N(i);return n(e,a,os(r))},Qi=async({collection:e,fullPath:a,...r})=>{let{get_asset:i}=await N(r);return Ha(await i(e,a))},Zi=async({assets:e,...a})=>{let{get_many_assets:r}=await N(a),i=e.map(({collection:o,fullPath:t})=>[o,t]);return(await r(i)).map(([o,t])=>Ha(t))};var en=e=>btoa([...e].map(a=>String.fromCharCode(a)).join(""));var au=e=>nn(e),ru=e=>nn({filename:e.data.name,...e}),nn=async({filename:e,data:a,collection:r,headers:i=[],fullPath:n,token:o,satellite:t,encoding:s,description:c})=>{let l=_(t?.identity),d=decodeURI(e),p=n??`/${r}/${d}`,u={...t,identity:l};return await Gi({asset:{data:a,filename:d,collection:r,token:o,headers:i,fullPath:p,encoding:s,description:c},satellite:u,options:{certified:!0}}),{downloadUrl:on({satellite:u,assetKey:{fullPath:p,token:o}}),fullPath:p,...rn(o)&&{token:o},name:d}},iu=async({collection:e,filter:a,satellite:r,options:i})=>{let n={...r,identity:_(r?.identity)},{items:o,...t}=await Wi({collection:e,filter:a??{},satellite:n,options:i??Z}),s=o.map(({key:{full_path:c,token:l,name:d,owner:p,description:u},headers:m,encodings:y,created_at:V,updated_at:h})=>{let C=an(l);return{fullPath:c,description:an(u),name:d,downloadUrl:on({satellite:n,assetKey:{fullPath:c,token:C}}),token:C,headers:m,encodings:y.reduce((U,[L,{modified:ae,sha256:re,total_length:q}])=>({...U,[L]:{modified:ae,sha256:en(re),total_length:q}}),{}),owner:p.toText(),created_at:V,updated_at:h}});return{items:s,assets:s,...t}},nu=async({collection:e,filter:a,satellite:r,options:i})=>{let n={...r,identity:_(r?.identity)};return await Hi({collection:e,satellite:n,filter:a??{},options:i??Z})},ou=({collection:e,fullPath:a,satellite:r})=>zi({collection:e,fullPath:a,satellite:{...r,identity:_(r?.identity)},options:{certified:!0}}),tu=({collection:e,fullPath:a,token:r,satellite:i})=>Xi({collection:e,fullPath:a,token:r,satellite:{...i,identity:_(i?.identity)},options:{certified:!0}}),su=({assets:e,satellite:a})=>$i({assets:e,satellite:{...a,identity:_(a?.identity)},options:{certified:!0}}),cu=async({collection:e,satellite:a,filter:r})=>{let i={...a,identity:_(a?.identity)};return await Yi({collection:e,satellite:i,filter:r??{},options:{certified:!0}})},lu=async({satellite:e,options:a,...r})=>{let i=_(e?.identity);return await Qi({...r,satellite:{...e,identity:i},options:a??Z})},du=async({satellite:e,options:a,...r})=>{let i=_(e?.identity);return await Zi({...r,satellite:{...e,identity:i},options:a??Z})},on=({assetKey:{fullPath:e,token:a},satellite:r})=>{let i={...r,identity:_(r?.identity)};return`${Kr(i)}${e}${rn(a)?`?token=${a}`:""}`};var ss=e=>{let a=e?.satelliteId??ui();ts(a,"Satellite ID is not configured. Juno cannot be initialized.");let r=e?.container??_i();return{satelliteId:a,internetIdentityId:e?.internetIdentityId,workers:e?.workers,syncTabs:e?.syncTabs,container:r}},xu=e=>cs(e),cs=async e=>{let a=ss(e);g.getInstance().set(a),await Da();let r=a.workers?.auth!==void 0?Lr(a.workers.auth):void 0,i=a.syncTabs===!1?void 0:pi();return[...tn(r)?[r]:[],...tn(i)?[i]:[]]},ls=e=>R.getInstance().subscribe(e),Ru=ls;export{fi as AuthClientSignInProgressStep,Pa as InitError,qa as InternetIdentityProvider,Ea as ListError,Va as SignInError,fe as SignInInitError,pa as SignInMissingClientIdError,wa as SignInProviderNotSupportedError,Aa as SignInUserInterruptError,Ia as SignUpProviderNotSupportedError,Ji as WebAuthnSignInProgressStep,va as WebAuthnSignInRetrievePublicKeyError,ji as WebAuthnSignUpProgressStep,Ru as authSubscribe,nu as countAssets,sl as countDocs,ou as deleteAsset,il as deleteDoc,cu as deleteFilteredAssets,ol as deleteFilteredDocs,su as deleteManyAssets,nl as deleteManyDocs,on as downloadUrl,lu as getAsset,ba as getDoc,Yn as getIdentityOnce,du as getManyAssets,rl as getManyDocs,Lp as getSatelliteExtendedActor,xt as handleRedirectCallback,xu as initJuno,cs as initSatellite,Dp as isGitHubUser,Sp as isGoogleUser,kn as isWebAuthnAvailable,bp as isWebAuthnUser,iu as listAssets,tl as listDocs,ls as onAuthStateChange,tu as setAssetToken,oi as setDoc,ti as setManyDocs,$t as signIn,or as signOut,Yt as signUp,$n as unsafeIdentity,au as uploadBlob,ru as uploadFile};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|