@junobuild/core-peer 0.0.12 → 0.0.13-next-2024-05-06

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.
@@ -21,6 +21,13 @@ export interface AssetNoContent {
21
21
  encodings: Array<[string, AssetEncodingNoContent]>;
22
22
  headers: Array<[string, string]>;
23
23
  created_at: bigint;
24
+ version: [] | [bigint];
25
+ }
26
+ export interface AuthenticationConfig {
27
+ internet_identity: [] | [AuthenticationConfigInternetIdentity];
28
+ }
29
+ export interface AuthenticationConfigInternetIdentity {
30
+ derivation_origin: [] | [string];
24
31
  }
25
32
  export interface CommitBatch {
26
33
  batch_id: bigint;
@@ -41,10 +48,11 @@ export type ControllerScope = {Write: null} | {Admin: null};
41
48
  export interface CustomDomain {
42
49
  updated_at: bigint;
43
50
  created_at: bigint;
51
+ version: [] | [bigint];
44
52
  bn_id: [] | [string];
45
53
  }
46
54
  export interface DelDoc {
47
- updated_at: [] | [bigint];
55
+ version: [] | [bigint];
48
56
  }
49
57
  export interface DeleteControllersArgs {
50
58
  controllers: Array<Principal>;
@@ -59,6 +67,7 @@ export interface Doc {
59
67
  data: Uint8Array | number[];
60
68
  description: [] | [string];
61
69
  created_at: bigint;
70
+ version: [] | [bigint];
62
71
  }
63
72
  export interface HttpRequest {
64
73
  url: string;
@@ -124,11 +133,13 @@ export interface MemorySize {
124
133
  }
125
134
  export type Permission = {Controllers: null} | {Private: null} | {Public: null} | {Managed: null};
126
135
  export interface Rule {
136
+ max_capacity: [] | [number];
127
137
  memory: [] | [Memory];
128
138
  updated_at: bigint;
129
139
  max_size: [] | [bigint];
130
140
  read: Permission;
131
141
  created_at: bigint;
142
+ version: [] | [bigint];
132
143
  mutable_permissions: [] | [boolean];
133
144
  write: Permission;
134
145
  }
@@ -143,15 +154,16 @@ export interface SetControllersArgs {
143
154
  controllers: Array<Principal>;
144
155
  }
145
156
  export interface SetDoc {
146
- updated_at: [] | [bigint];
147
157
  data: Uint8Array | number[];
148
158
  description: [] | [string];
159
+ version: [] | [bigint];
149
160
  }
150
161
  export interface SetRule {
162
+ max_capacity: [] | [number];
151
163
  memory: [] | [Memory];
152
- updated_at: [] | [bigint];
153
164
  max_size: [] | [bigint];
154
165
  read: Permission;
166
+ version: [] | [bigint];
155
167
  mutable_permissions: [] | [boolean];
156
168
  write: Permission;
157
169
  }
@@ -209,6 +221,7 @@ export interface _SERVICE {
209
221
  del_rule: ActorMethod<[RulesType, string, DelDoc], undefined>;
210
222
  deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
211
223
  get_asset: ActorMethod<[string, string], [] | [AssetNoContent]>;
224
+ get_auth_config: ActorMethod<[], [] | [AuthenticationConfig]>;
212
225
  get_config: ActorMethod<[], Config>;
213
226
  get_doc: ActorMethod<[string, string], [] | [Doc]>;
214
227
  get_many_assets: ActorMethod<[Array<[string, string]>], Array<[string, [] | [AssetNoContent]]>>;
@@ -225,6 +238,7 @@ export interface _SERVICE {
225
238
  list_docs: ActorMethod<[string, ListParams], ListResults_1>;
226
239
  list_rules: ActorMethod<[RulesType], Array<[string, Rule]>>;
227
240
  memory_size: ActorMethod<[], MemorySize>;
241
+ set_auth_config: ActorMethod<[AuthenticationConfig], undefined>;
228
242
  set_config: ActorMethod<[Config], undefined>;
229
243
  set_controllers: ActorMethod<[SetControllersArgs], Array<[Principal, Controller]>>;
230
244
  set_custom_domain: ActorMethod<[string, [] | [string]], undefined>;
@@ -235,3 +249,4 @@ export interface _SERVICE {
235
249
  version: ActorMethod<[], string>;
236
250
  }
237
251
  export declare const idlFactory: IDL.InterfaceFactory;
252
+ export declare const init: (args: {IDL: typeof IDL}) => IDL.Type[];
@@ -19,7 +19,7 @@ export const idlFactory = ({IDL}) => {
19
19
  scope: ControllerScope,
20
20
  expires_at: IDL.Opt(IDL.Nat64)
21
21
  });
22
- const DelDoc = IDL.Record({updated_at: IDL.Opt(IDL.Nat64)});
22
+ const DelDoc = IDL.Record({version: IDL.Opt(IDL.Nat64)});
23
23
  const RulesType = IDL.Variant({Db: IDL.Null, Storage: IDL.Null});
24
24
  const DepositCyclesArgs = IDL.Record({
25
25
  cycles: IDL.Nat,
@@ -43,7 +43,14 @@ export const idlFactory = ({IDL}) => {
43
43
  updated_at: IDL.Nat64,
44
44
  encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),
45
45
  headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
46
- created_at: IDL.Nat64
46
+ created_at: IDL.Nat64,
47
+ version: IDL.Opt(IDL.Nat64)
48
+ });
49
+ const AuthenticationConfigInternetIdentity = IDL.Record({
50
+ derivation_origin: IDL.Opt(IDL.Text)
51
+ });
52
+ const AuthenticationConfig = IDL.Record({
53
+ internet_identity: IDL.Opt(AuthenticationConfigInternetIdentity)
47
54
  });
48
55
  const StorageConfigIFrame = IDL.Variant({
49
56
  Deny: IDL.Null,
@@ -66,7 +73,8 @@ export const idlFactory = ({IDL}) => {
66
73
  owner: IDL.Principal,
67
74
  data: IDL.Vec(IDL.Nat8),
68
75
  description: IDL.Opt(IDL.Text),
69
- created_at: IDL.Nat64
76
+ created_at: IDL.Nat64,
77
+ version: IDL.Opt(IDL.Nat64)
70
78
  });
71
79
  const HttpRequest = IDL.Record({
72
80
  url: IDL.Text,
@@ -140,6 +148,7 @@ export const idlFactory = ({IDL}) => {
140
148
  const CustomDomain = IDL.Record({
141
149
  updated_at: IDL.Nat64,
142
150
  created_at: IDL.Nat64,
151
+ version: IDL.Opt(IDL.Nat64),
143
152
  bn_id: IDL.Opt(IDL.Text)
144
153
  });
145
154
  const ListResults_1 = IDL.Record({
@@ -156,11 +165,13 @@ export const idlFactory = ({IDL}) => {
156
165
  Managed: IDL.Null
157
166
  });
158
167
  const Rule = IDL.Record({
168
+ max_capacity: IDL.Opt(IDL.Nat32),
159
169
  memory: IDL.Opt(Memory),
160
170
  updated_at: IDL.Nat64,
161
171
  max_size: IDL.Opt(IDL.Nat),
162
172
  read: Permission,
163
173
  created_at: IDL.Nat64,
174
+ version: IDL.Opt(IDL.Nat64),
164
175
  mutable_permissions: IDL.Opt(IDL.Bool),
165
176
  write: Permission
166
177
  });
@@ -175,15 +186,16 @@ export const idlFactory = ({IDL}) => {
175
186
  controllers: IDL.Vec(IDL.Principal)
176
187
  });
177
188
  const SetDoc = IDL.Record({
178
- updated_at: IDL.Opt(IDL.Nat64),
179
189
  data: IDL.Vec(IDL.Nat8),
180
- description: IDL.Opt(IDL.Text)
190
+ description: IDL.Opt(IDL.Text),
191
+ version: IDL.Opt(IDL.Nat64)
181
192
  });
182
193
  const SetRule = IDL.Record({
194
+ max_capacity: IDL.Opt(IDL.Nat32),
183
195
  memory: IDL.Opt(Memory),
184
- updated_at: IDL.Opt(IDL.Nat64),
185
196
  max_size: IDL.Opt(IDL.Nat),
186
197
  read: Permission,
198
+ version: IDL.Opt(IDL.Nat64),
187
199
  mutable_permissions: IDL.Opt(IDL.Bool),
188
200
  write: Permission
189
201
  });
@@ -213,6 +225,7 @@ export const idlFactory = ({IDL}) => {
213
225
  del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
214
226
  deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
215
227
  get_asset: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(AssetNoContent)], ['query']),
228
+ get_auth_config: IDL.Func([], [IDL.Opt(AuthenticationConfig)], ['query']),
216
229
  get_config: IDL.Func([], [Config], []),
217
230
  get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
218
231
  get_many_assets: IDL.Func(
@@ -238,6 +251,7 @@ export const idlFactory = ({IDL}) => {
238
251
  list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']),
239
252
  list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']),
240
253
  memory_size: IDL.Func([], [MemorySize], ['query']),
254
+ set_auth_config: IDL.Func([AuthenticationConfig], [], []),
241
255
  set_config: IDL.Func([Config], [], []),
242
256
  set_controllers: IDL.Func(
243
257
  [SetControllersArgs],
@@ -19,7 +19,7 @@ export const idlFactory = ({IDL}) => {
19
19
  scope: ControllerScope,
20
20
  expires_at: IDL.Opt(IDL.Nat64)
21
21
  });
22
- const DelDoc = IDL.Record({updated_at: IDL.Opt(IDL.Nat64)});
22
+ const DelDoc = IDL.Record({version: IDL.Opt(IDL.Nat64)});
23
23
  const RulesType = IDL.Variant({Db: IDL.Null, Storage: IDL.Null});
24
24
  const DepositCyclesArgs = IDL.Record({
25
25
  cycles: IDL.Nat,
@@ -43,7 +43,14 @@ export const idlFactory = ({IDL}) => {
43
43
  updated_at: IDL.Nat64,
44
44
  encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),
45
45
  headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
46
- created_at: IDL.Nat64
46
+ created_at: IDL.Nat64,
47
+ version: IDL.Opt(IDL.Nat64)
48
+ });
49
+ const AuthenticationConfigInternetIdentity = IDL.Record({
50
+ derivation_origin: IDL.Opt(IDL.Text)
51
+ });
52
+ const AuthenticationConfig = IDL.Record({
53
+ internet_identity: IDL.Opt(AuthenticationConfigInternetIdentity)
47
54
  });
48
55
  const StorageConfigIFrame = IDL.Variant({
49
56
  Deny: IDL.Null,
@@ -66,7 +73,8 @@ export const idlFactory = ({IDL}) => {
66
73
  owner: IDL.Principal,
67
74
  data: IDL.Vec(IDL.Nat8),
68
75
  description: IDL.Opt(IDL.Text),
69
- created_at: IDL.Nat64
76
+ created_at: IDL.Nat64,
77
+ version: IDL.Opt(IDL.Nat64)
70
78
  });
71
79
  const HttpRequest = IDL.Record({
72
80
  url: IDL.Text,
@@ -140,6 +148,7 @@ export const idlFactory = ({IDL}) => {
140
148
  const CustomDomain = IDL.Record({
141
149
  updated_at: IDL.Nat64,
142
150
  created_at: IDL.Nat64,
151
+ version: IDL.Opt(IDL.Nat64),
143
152
  bn_id: IDL.Opt(IDL.Text)
144
153
  });
145
154
  const ListResults_1 = IDL.Record({
@@ -156,11 +165,13 @@ export const idlFactory = ({IDL}) => {
156
165
  Managed: IDL.Null
157
166
  });
158
167
  const Rule = IDL.Record({
168
+ max_capacity: IDL.Opt(IDL.Nat32),
159
169
  memory: IDL.Opt(Memory),
160
170
  updated_at: IDL.Nat64,
161
171
  max_size: IDL.Opt(IDL.Nat),
162
172
  read: Permission,
163
173
  created_at: IDL.Nat64,
174
+ version: IDL.Opt(IDL.Nat64),
164
175
  mutable_permissions: IDL.Opt(IDL.Bool),
165
176
  write: Permission
166
177
  });
@@ -175,15 +186,16 @@ export const idlFactory = ({IDL}) => {
175
186
  controllers: IDL.Vec(IDL.Principal)
176
187
  });
177
188
  const SetDoc = IDL.Record({
178
- updated_at: IDL.Opt(IDL.Nat64),
179
189
  data: IDL.Vec(IDL.Nat8),
180
- description: IDL.Opt(IDL.Text)
190
+ description: IDL.Opt(IDL.Text),
191
+ version: IDL.Opt(IDL.Nat64)
181
192
  });
182
193
  const SetRule = IDL.Record({
194
+ max_capacity: IDL.Opt(IDL.Nat32),
183
195
  memory: IDL.Opt(Memory),
184
- updated_at: IDL.Opt(IDL.Nat64),
185
196
  max_size: IDL.Opt(IDL.Nat),
186
197
  read: Permission,
198
+ version: IDL.Opt(IDL.Nat64),
187
199
  mutable_permissions: IDL.Opt(IDL.Bool),
188
200
  write: Permission
189
201
  });
@@ -213,6 +225,7 @@ export const idlFactory = ({IDL}) => {
213
225
  del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
214
226
  deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
215
227
  get_asset: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(AssetNoContent)], ['query']),
228
+ get_auth_config: IDL.Func([], [IDL.Opt(AuthenticationConfig)], ['query']),
216
229
  get_config: IDL.Func([], [Config], []),
217
230
  get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
218
231
  get_many_assets: IDL.Func(
@@ -238,6 +251,7 @@ export const idlFactory = ({IDL}) => {
238
251
  list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']),
239
252
  list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']),
240
253
  memory_size: IDL.Func([], [MemorySize], ['query']),
254
+ set_auth_config: IDL.Func([AuthenticationConfig], [], []),
241
255
  set_config: IDL.Func([Config], [], []),
242
256
  set_controllers: IDL.Func(
243
257
  [SetControllersArgs],
@@ -1,2 +1,2 @@
1
- import{Principal as et}from"@dfinity/principal";var c=t=>t==null,l=t=>!c(t),Xt=class extends Error{},st=(t,e)=>{if(c(t))throw new Xt(e)},j="__bigint__",H="__principal__",z="__uint8array__",Qt=(t,e)=>typeof e=="bigint"?{[j]:`${e}`}:l(e)&&e instanceof et?{[H]:e.toText()}:l(e)&&e instanceof Uint8Array?{[z]:Array.from(e)}:e,Zt=(t,e)=>{let s=o=>e[o];return l(e)&&typeof e=="object"&&j in e?BigInt(s(j)):l(e)&&typeof e=="object"&&H in e?et.fromText(s(H)):l(e)&&typeof e=="object"&&z in e?Uint8Array.from(s(z)):e},p=t=>l(t)?[t]:[],y=t=>t?.[0],ot=async t=>{let e=new Blob([JSON.stringify(t,Qt)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},C=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),Zt)},E=()=>typeof window<"u";var R=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:s})=>s(e))}subscribe(e){let s=Symbol();return this.callbacks.push({id:s,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:o})=>o!==s)}};var w=class t extends R{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let s=super.subscribe(e);return e(this.authUser),s}reset(){this.authUser=null,this.populate(this.authUser)}};var G=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var it=BigInt(144e11),nt={width:576,height:576},rt={width:505,height:705},at="internetcomputer.org";var k="http://127.0.0.1:5987",ct="rdmx6-jaaaa-aaaaa-aaadq-cai";var A=class t extends R{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var W=({width:t,height:e})=>{if(!E()||c(window)||c(window.top))return;let{top:{innerWidth:s,innerHeight:o}}=window,i=o/2+screenY-e/2,n=s/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${n}`};var F=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=A.getInstance().get()?.container;if(c(o)||o===!1)return`https://identity.${this.#t??at}`;let i=A.getInstance().get(),n=l(i)&&l(i?.internetIdentityId)?i.internetIdentityId:ct,{host:r,protocol:a}=new URL(o===!0?k:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:W(nt)},identityProvider:s()}}},lt=class{#t;#e;constructor({appName:e,logoUrl:s}){this.#t=e,this.#e=s}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:W(rt)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as Dt}from"@dfinity/auth-client";var V=()=>Dt.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var pt=async({data:t})=>{try{return await C(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var Y=async t=>{let{data:e,updated_at:s,description:o}=t;return{description:p(o),data:await ot(e),updated_at:p(s)}},J=t=>{let{updated_at:e}=t;return{updated_at:p(e)}},v=async({doc:t,key:e})=>{let{owner:s,description:o,data:i,...n}=t;return{key:e,description:y(o),owner:s.toText(),data:await C(i),...n}};import{Principal as It}from"@dfinity/principal";var M=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:c(t)?[]:[{key:p(t.key),description:p(t.description)}],paginate:p(c(e)?void 0:{start_after:p(e.startAfter),limit:p(c(e.limit)?void 0:BigInt(e.limit))}),order:p(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:p(c(o)?void 0:typeof o=="string"?It.fromText(o):o)});var dt=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),s=t.Record({controllers:t.Vec(t.Principal)}),o=t.Variant({Write:t.Null,Admin:t.Null}),i=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:o,expires_at:t.Opt(t.Nat64)}),n=t.Record({updated_at:t.Opt(t.Nat64)}),r=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({cycles:t.Nat,destination_id:t.Principal}),d=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),h=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),u=t.Record({key:d,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,h)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64}),T=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),x=t.Record({status_code:t.Nat16,location:t.Text}),b=t.Record({iframe:t.Opt(T),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),redirects:t.Opt(t.Vec(t.Tuple(t.Text,x)))}),N=t.Record({storage:b}),_=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64}),S=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),m=t.Variant({Heap:t.Null,Stable:t.Null}),O=t.Record({memory:m,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),K=t.Variant({Callback:t.Record({token:O,callback:t.Func([],[],["query"])})}),q=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(K),status_code:t.Nat16}),B=t.Record({token:t.Opt(O),body:t.Vec(t.Nat8)}),Ct=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),Et=t.Record({batch_id:t.Nat}),Ft=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),Vt=t.Record({field:Ft,desc:t.Bool}),Mt=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),$t=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),L=t.Record({order:t.Opt(Vt),owner:t.Opt(t.Principal),matcher:t.Opt(Mt),paginate:t.Opt($t)}),Kt=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,u)),items_length:t.Nat64}),qt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,bn_id:t.Opt(t.Text)}),Bt=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,_)),items_length:t.Nat64}),U=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),jt=t.Record({memory:t.Opt(m),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:U,created_at:t.Nat64,mutable_permissions:t.Opt(t.Bool),write:U}),Ht=t.Record({stable:t.Nat64,heap:t.Nat64}),zt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),Gt=t.Record({controller:zt,controllers:t.Vec(t.Principal)}),tt=t.Record({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),Wt=t.Record({memory:t.Opt(m),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:U,mutable_permissions:t.Opt(t.Bool),write:U}),Yt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Jt=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([s],[t.Vec(t.Tuple(t.Principal,i))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,n],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,n))],[],[]),del_rule:t.Func([r,t.Text,n],[],[]),deposit_cycles:t.Func([a],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(u)],["query"]),get_config:t.Func([],[N],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(_)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(u)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(_)))],["query"]),http_request:t.Func([S],[q],["query"]),http_request_streaming_callback:t.Func([O],[B],["query"]),init_asset_upload:t.Func([Ct],[Et],[]),list_assets:t.Func([t.Text,L],[Kt],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,qt))],["query"]),list_docs:t.Func([t.Text,L],[Bt],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,jt))],["query"]),memory_size:t.Func([],[Ht],["query"]),set_config:t.Func([N],[],[]),set_controllers:t.Func([Gt],[t.Vec(t.Tuple(t.Principal,i))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,tt],[_],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,tt))],[t.Vec(t.Tuple(t.Text,_))],[]),set_rule:t.Func([r,t.Text,Wt],[],[]),upload_asset_chunk:t.Func([Yt],[Jt],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as Lt,HttpAgent as te}from"@dfinity/agent";var ut=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:i})=>{let r=l(i)&&i!==!1?i===!0?k:i:"https://icp-api.io",a=new te({identity:s,host:r,...o&&{fetch:o}});return l(i)&&await a.fetchRootKey(),Lt.createActor(e,{agent:a,canisterId:t})};var X=({satelliteId:t,container:e})=>{let{satelliteId:s}=Q({satelliteId:t}),{container:o}=Z({container:e});if(l(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?k:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},Q=({satelliteId:t})=>l(t)?{satelliteId:t}:A.getInstance().get()??{satelliteId:void 0},Z=({container:t})=>l(t)?{container:t}:A.getInstance().get()??{container:void 0};var f=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=Q({satelliteId:t});st(o,"No satellite principal defined.");let{container:i}=Z({container:e});return ut({satelliteId:o,container:i,idlFactory:dt,...s})};var mt=async({collection:t,key:e,satellite:s})=>{let o=await f(s),i=y(await o.get_doc(t,e));if(!c(i))return v({doc:i,key:e})},yt=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await f(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let d=y(a);n.push(l(d)?await v({key:r,doc:d}):void 0)}return n},ft=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await f(s),{key:i}=e,n=await Y(e),r=await o(t,i,n);return await v({key:i,doc:r})},gt=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await f(e),o=[];for(let{collection:r,doc:a}of t){let{key:d}=a;o.push([r,d,await Y(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await v({key:r,doc:a}));return n},ht=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await f(s),{key:i}=e;return o(t,i,J(e))},_t=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await f(e),o=t.map(({collection:i,doc:n})=>[i,n.key,J(n)]);await s(o)},Tt=async({collection:t,filter:e,satellite:s})=>{let o=await f(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:d}=await o.list_docs(t,M(e)),h=[];for(let[u,T]of i){let{data:x,owner:b,description:N,..._}=T;h.push({key:u,description:y(N),owner:b.toText(),data:await pt({data:x}),..._})}return{items:h,items_length:r,items_page:y(n),matches_length:a,matches_pages:y(d)}};import{AnonymousIdentity as ee}from"@dfinity/agent";var g=t=>t!==void 0?t:$()??new ee;var xt=async({satellite:t,...e})=>{let s=g(t?.identity);return mt({...e,satellite:{...t,identity:s}})},rs=async({satellite:t,...e})=>{let s=g(t?.identity);return yt({...e,satellite:{...t,identity:s}})},At=async({satellite:t,...e})=>{let s=g(t?.identity);return ft({...e,satellite:{...t,identity:s}})},as=async({satellite:t,...e})=>{let s=g(t?.identity);return gt({...e,satellite:{...t,identity:s}})},cs=async({satellite:t,...e})=>{let s=g(t?.identity);return ht({...e,satellite:{...t,identity:s}})},ls=async({satellite:t,...e})=>{let s=g(t?.identity);return _t({...e,satellite:{...t,identity:s}})},ps=async({satellite:t,filter:e,...s})=>{let o=g(t?.identity);return Tt({...s,filter:e??{},satellite:{...t,identity:o}})};var Pt=async t=>{let e=$();if(c(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await xt({collection:"#user",key:s});return c(o)?await se({userId:s,provider:t}):o},se=async({userId:t,...e})=>At({collection:"#user",doc:{key:t,data:e}});var P,D=async t=>{if(P=P??await V(),!(await P?.isAuthenticated()??!1))return;let s=await Pt(t);w.getInstance().set(s)},oe=async t=>new Promise(async(e,s)=>{P=P??await V();let o=t?.provider??new F({});await P.login({onSuccess:async()=>{await D(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??it,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),I=async()=>{await P?.logout(),P=void 0,w.getInstance().reset()},$=()=>P?.getIdentity(),ie=async()=>(P??await V()).getIdentity();var Nt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{G({message:"junoSignOutAuthTimer"}),await I()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":G({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},w.getInstance().subscribe(i=>{if(c(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var wt=async({data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a,satellite:d})=>{let h=await f(d),{batch_id:u}=await h.init_asset_upload({collection:s,full_path:n,name:e,token:p(i),encoding_type:p(r),description:p(a)}),T=19e5,x=[],b=E()?new Blob([await t.arrayBuffer()]):t,N=0n;for(let m=0;m<b.size;m+=T){let O=b.slice(m,m+T);x.push({batchId:u,chunk:O,actor:h,orderId:N}),N++}let _=[];for await(let m of ne({uploadChunks:x}))_=[..._,...m];let S=o.find(([m,O])=>m.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await h.commit_asset_upload({batch_id:u,chunk_ids:_.map(({chunk_id:m})=>m),headers:[...o,...S||[]]})};async function*ne({uploadChunks:t,limit:e=12}){for(let s=0;s<t.length;s=s+e){let o=t.slice(s,s+e);yield await Promise.all(o.map(n=>re(n)))}}var re=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:p(o)}),bt=async({collection:t,satellite:e,filter:s})=>{let o=await f(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:d}=await o.list_assets(t,M(s));return{items:i.map(([h,u])=>u),items_length:n,items_page:y(r),matches_length:a,matches_pages:y(d)}},St=async({collection:t,fullPath:e,satellite:s})=>(await f(s)).del_asset(t,e),Ot=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await f(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Rt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await f(s);return y(await o(t,e))},kt=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await f(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>y(r))};var vt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var $s=async t=>Ut(t),Ks=async t=>Ut({filename:t.data.name,...t}),Ut=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:d})=>{let h=g(r?.identity),u=decodeURI(t),T=i??`/${s}/${u}`,x={...r,identity:h};return await wt({data:e,filename:u,collection:s,token:n,headers:o,fullPath:T,encoding:a,satellite:x,description:d}),{downloadUrl:`${X(x)}${T}${n!==void 0?`?token=${n}`:""}`,fullPath:T,name:u}},qs=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:g(e?.identity)},{items:i,...n}=await bt({collection:t,satellite:o,filter:s??{}}),r=X(o);return{assets:i.map(({key:{full_path:a,token:d,name:h,owner:u,description:T},headers:x,encodings:b,created_at:N,updated_at:_})=>{let S=y(d);return{fullPath:a,description:y(T),name:h,downloadUrl:`${r}${a}${S!==void 0?`?token=${S}`:""}`,token:S,headers:x,encodings:b.reduce((m,[O,{modified:K,sha256:q,total_length:B}])=>({...m,[O]:{modified:K,sha256:vt(q),total_length:B}}),{}),owner:u.toText(),created_at:N,updated_at:_}}),...n}},Bs=async({collection:t,fullPath:e,satellite:s})=>St({collection:t,fullPath:e,satellite:{...s,identity:g(s?.identity)}}),js=async({assets:t,satellite:e})=>Ot({assets:t,satellite:{...e,identity:g(e?.identity)}}),Hs=async({satellite:t,...e})=>{let s=g(t?.identity);return Rt({...e,satellite:{...t,identity:s}})},zs=async({satellite:t,...e})=>{let s=g(t?.identity);return kt({...e,satellite:{...t,identity:s}})};var Qs=async t=>{A.getInstance().set(t),await D();let e=t.workers?.auth!==void 0?Nt(t.workers.auth):void 0;return[...e?[e]:[]]},Zs=t=>w.getInstance().subscribe(t);export{F as InternetIdentityProvider,lt as NFIDProvider,Zs as authSubscribe,Bs as deleteAsset,cs as deleteDoc,js as deleteManyAssets,ls as deleteManyDocs,Hs as getAsset,xt as getDoc,zs as getManyAssets,rs as getManyDocs,Qs as initJuno,qs as listAssets,ps as listDocs,At as setDoc,as as setManyDocs,oe as signIn,I as signOut,ie as unsafeIdentity,$s as uploadBlob,Ks as uploadFile};
1
+ import{Principal as et}from"@dfinity/principal";var c=t=>t==null,p=t=>!c(t),Dt=class extends Error{},st=(t,e)=>{if(c(t))throw new Dt(e)},j="__bigint__",H="__principal__",z="__uint8array__",It=(t,e)=>typeof e=="bigint"?{[j]:`${e}`}:p(e)&&e instanceof et?{[H]:e.toText()}:p(e)&&e instanceof Uint8Array?{[z]:Array.from(e)}:e,Lt=(t,e)=>{let s=o=>e[o];return p(e)&&typeof e=="object"&&j in e?BigInt(s(j)):p(e)&&typeof e=="object"&&H in e?et.fromText(s(H)):p(e)&&typeof e=="object"&&z in e?Uint8Array.from(s(z)):e},u=t=>p(t)?[t]:[],d=t=>t?.[0],ot=async t=>{let e=new Blob([JSON.stringify(t,It)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},F=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),Lt)},V=()=>typeof window<"u";var v=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:s})=>s(e))}subscribe(e){let s=Symbol();return this.callbacks.push({id:s,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:o})=>o!==s)}};var w=class t extends v{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let s=super.subscribe(e);return e(this.authUser),s}reset(){this.authUser=null,this.populate(this.authUser)}};var W=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var it=BigInt(144e11),nt=!1,rt={width:576,height:576},at={width:505,height:705},ct="internetcomputer.org";var R="http://127.0.0.1:5987",lt="rdmx6-jaaaa-aaaaa-aaadq-cai";var A=class t extends v{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var G=({width:t,height:e})=>{if(!V()||c(window)||c(window.top))return;let{top:{innerWidth:s,innerHeight:o}}=window,i=o/2+screenY-e/2,n=s/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${n}`};var M=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=A.getInstance().get()?.container;if(c(o)||o===!1)return`https://identity.${this.#t??ct}`;let i=A.getInstance().get(),n=p(i)&&p(i?.internetIdentityId)?i.internetIdentityId:lt,{host:r,protocol:a}=new URL(o===!0?R:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:G(rt)},identityProvider:s()}}},pt=class{#t;#e;constructor({appName:e,logoUrl:s}){this.#t=e,this.#e=s}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:G(at)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as te}from"@dfinity/auth-client";var $=()=>te.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var dt=async({data:t})=>{try{return await F(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var Y=async t=>{let{data:e,version:s,description:o}=t;return{description:u(o),data:await ot(e),version:u(s)}},J=t=>{let{version:e}=t;return{version:u(e)}},U=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:d(i),owner:s.toText(),data:await F(n),version:d(o),...r}};import{Principal as ee}from"@dfinity/principal";var K=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:c(t)?[]:[{key:u(t.key),description:u(t.description)}],paginate:u(c(e)?void 0:{start_after:u(e.startAfter),limit:u(c(e.limit)?void 0:BigInt(e.limit))}),order:u(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:u(c(o)?void 0:typeof o=="string"?ee.fromText(o):o)});var ut=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),s=t.Record({controllers:t.Vec(t.Principal)}),o=t.Variant({Write:t.Null,Admin:t.Null}),i=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:o,expires_at:t.Opt(t.Nat64)}),n=t.Record({version:t.Opt(t.Nat64)}),r=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({cycles:t.Nat,destination_id:t.Principal}),m=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),h=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),y=t.Record({key:m,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,h)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),T=t.Record({derivation_origin:t.Opt(t.Text)}),_=t.Record({internet_identity:t.Opt(T)}),O=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),b=t.Record({status_code:t.Nat16,location:t.Text}),N=t.Record({iframe:t.Opt(O),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),redirects:t.Opt(t.Vec(t.Tuple(t.Text,b)))}),x=t.Record({storage:N}),l=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),S=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),k=t.Variant({Heap:t.Null,Stable:t.Null}),C=t.Record({memory:k,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),B=t.Variant({Callback:t.Record({token:C,callback:t.Func([],[],["query"])})}),Et=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(B),status_code:t.Nat16}),Ft=t.Record({token:t.Opt(C),body:t.Vec(t.Nat8)}),Vt=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),Mt=t.Record({batch_id:t.Nat}),$t=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),Kt=t.Record({field:$t,desc:t.Bool}),qt=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),Bt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),L=t.Record({order:t.Opt(Kt),owner:t.Opt(t.Principal),matcher:t.Opt(qt),paginate:t.Opt(Bt)}),jt=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,y)),items_length:t.Nat64}),Ht=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),zt=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,l)),items_length:t.Nat64}),E=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Wt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(k),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:E,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:E}),Gt=t.Record({stable:t.Nat64,heap:t.Nat64}),Yt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),Jt=t.Record({controller:Yt,controllers:t.Vec(t.Principal)}),tt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),Xt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(k),max_size:t.Opt(t.Nat),read:E,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:E}),Qt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Zt=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([s],[t.Vec(t.Tuple(t.Principal,i))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,n],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,n))],[],[]),del_rule:t.Func([r,t.Text,n],[],[]),deposit_cycles:t.Func([a],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(y)],["query"]),get_auth_config:t.Func([],[t.Opt(_)],["query"]),get_config:t.Func([],[x],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(l)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(y)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(l)))],["query"]),http_request:t.Func([S],[Et],["query"]),http_request_streaming_callback:t.Func([C],[Ft],["query"]),init_asset_upload:t.Func([Vt],[Mt],[]),list_assets:t.Func([t.Text,L],[jt],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Ht))],["query"]),list_docs:t.Func([t.Text,L],[zt],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,Wt))],["query"]),memory_size:t.Func([],[Gt],["query"]),set_auth_config:t.Func([_],[],[]),set_config:t.Func([x],[],[]),set_controllers:t.Func([Jt],[t.Vec(t.Tuple(t.Principal,i))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,tt],[l],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,tt))],[t.Vec(t.Tuple(t.Text,l))],[]),set_rule:t.Func([r,t.Text,Xt],[],[]),upload_asset_chunk:t.Func([Qt],[Zt],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as se,HttpAgent as oe}from"@dfinity/agent";var mt=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:i})=>{let r=p(i)&&i!==!1?i===!0?R:i:"https://icp-api.io",a=new oe({identity:s,host:r,retryTimes:10,...o&&{fetch:o}});return p(i)&&await a.fetchRootKey(),se.createActor(e,{agent:a,canisterId:t})};var X=({satelliteId:t,container:e})=>{let{satelliteId:s}=Q({satelliteId:t}),{container:o}=Z({container:e});if(p(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?R:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},Q=({satelliteId:t})=>p(t)?{satelliteId:t}:A.getInstance().get()??{satelliteId:void 0},Z=({container:t})=>p(t)?{container:t}:A.getInstance().get()??{container:void 0};var f=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=Q({satelliteId:t});st(o,"No satellite principal defined.");let{container:i}=Z({container:e});return mt({satelliteId:o,container:i,idlFactory:ut,...s})};var yt=async({collection:t,key:e,satellite:s})=>{let o=await f(s),i=d(await o.get_doc(t,e));if(!c(i))return U({doc:i,key:e})},ft=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await f(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let m=d(a);n.push(p(m)?await U({key:r,doc:m}):void 0)}return n},gt=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await f(s),{key:i}=e,n=await Y(e),r=await o(t,i,n);return await U({key:i,doc:r})},ht=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await f(e),o=[];for(let{collection:r,doc:a}of t){let{key:m}=a;o.push([r,m,await Y(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await U({key:r,doc:a}));return n},Tt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await f(s),{key:i}=e;return o(t,i,J(e))},_t=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await f(e),o=t.map(({collection:i,doc:n})=>[i,n.key,J(n)]);await s(o)},xt=async({collection:t,filter:e,satellite:s})=>{let o=await f(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:m}=await o.list_docs(t,K(e)),h=[];for(let[y,T]of i){let{data:_,owner:O,description:b,version:N,...x}=T;h.push({key:y,description:d(b),owner:O.toText(),data:await dt({data:_}),version:d(N),...x})}return{items:h,items_length:r,items_page:d(n),matches_length:a,matches_pages:d(m)}};import{AnonymousIdentity as ie}from"@dfinity/agent";var g=t=>t!==void 0?t:q()??new ie;var At=async({satellite:t,...e})=>{let s=g(t?.identity);return yt({...e,satellite:{...t,identity:s}})},ls=async({satellite:t,...e})=>{let s=g(t?.identity);return ft({...e,satellite:{...t,identity:s}})},Pt=async({satellite:t,...e})=>{let s=g(t?.identity);return gt({...e,satellite:{...t,identity:s}})},ps=async({satellite:t,...e})=>{let s=g(t?.identity);return ht({...e,satellite:{...t,identity:s}})},ds=async({satellite:t,...e})=>{let s=g(t?.identity);return Tt({...e,satellite:{...t,identity:s}})},us=async({satellite:t,...e})=>{let s=g(t?.identity);return _t({...e,satellite:{...t,identity:s}})},ms=async({satellite:t,filter:e,...s})=>{let o=g(t?.identity);return xt({...s,filter:e??{},satellite:{...t,identity:o}})};var Nt=async t=>{let e=q();if(c(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await At({collection:"#user",key:s});return c(o)?await ne({userId:s,provider:t}):o},ne=async({userId:t,...e})=>Pt({collection:"#user",doc:{key:t,data:e}});var P,D=async t=>{if(P=P??await $(),!(await P?.isAuthenticated()??!1))return;let s=await Nt(t);w.getInstance().set(s)},re=async t=>new Promise(async(e,s)=>{P=P??await $();let o=t?.provider??new M({});await P.login({onSuccess:async()=>{await D(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??it,allowPinAuthentication:t?.allowPin??nt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),I=async()=>{await P?.logout(),P=void 0,w.getInstance().reset()},q=()=>P?.getIdentity(),ae=async()=>(P??await $()).getIdentity();var wt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{W({message:"junoSignOutAuthTimer"}),await I()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":W({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},w.getInstance().subscribe(i=>{if(c(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Ot=async({data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a,satellite:m})=>{let h=await f(m),{batch_id:y}=await h.init_asset_upload({collection:s,full_path:n,name:e,token:u(i),encoding_type:u(r),description:u(a)}),T=19e5,_=[],O=V()?new Blob([await t.arrayBuffer()]):t,b=0n;for(let l=0;l<O.size;l+=T){let S=O.slice(l,l+T);_.push({batchId:y,chunk:S,actor:h,orderId:b}),b++}let N=[];for await(let l of ce({uploadChunks:_}))N=[...N,...l];let x=o.find(([l,S])=>l.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await h.commit_asset_upload({batch_id:y,chunk_ids:N.map(({chunk_id:l})=>l),headers:[...o,...x||[]]})};async function*ce({uploadChunks:t,limit:e=12}){for(let s=0;s<t.length;s=s+e){let o=t.slice(s,s+e);yield await Promise.all(o.map(n=>le(n)))}}var le=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:u(o)}),bt=async({collection:t,satellite:e,filter:s})=>{let o=await f(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:m}=await o.list_assets(t,K(s));return{items:i.map(([h,y])=>y),items_length:n,items_page:d(r),matches_length:a,matches_pages:d(m)}},St=async({collection:t,fullPath:e,satellite:s})=>(await f(s)).del_asset(t,e),vt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await f(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Rt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await f(s);return d(await o(t,e))},kt=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await f(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>d(r))};var Ct=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Bs=async t=>Ut(t),js=async t=>Ut({filename:t.data.name,...t}),Ut=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:m})=>{let h=g(r?.identity),y=decodeURI(t),T=i??`/${s}/${y}`,_={...r,identity:h};return await Ot({data:e,filename:y,collection:s,token:n,headers:o,fullPath:T,encoding:a,satellite:_,description:m}),{downloadUrl:`${X(_)}${T}${n!==void 0?`?token=${n}`:""}`,fullPath:T,name:y}},Hs=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:g(e?.identity)},{items:i,...n}=await bt({collection:t,satellite:o,filter:s??{}}),r=X(o);return{assets:i.map(({key:{full_path:a,token:m,name:h,owner:y,description:T},headers:_,encodings:O,created_at:b,updated_at:N})=>{let x=d(m);return{fullPath:a,description:d(T),name:h,downloadUrl:`${r}${a}${x!==void 0?`?token=${x}`:""}`,token:x,headers:_,encodings:O.reduce((l,[S,{modified:k,sha256:C,total_length:B}])=>({...l,[S]:{modified:k,sha256:Ct(C),total_length:B}}),{}),owner:y.toText(),created_at:b,updated_at:N}}),...n}},zs=async({collection:t,fullPath:e,satellite:s})=>St({collection:t,fullPath:e,satellite:{...s,identity:g(s?.identity)}}),Ws=async({assets:t,satellite:e})=>vt({assets:t,satellite:{...e,identity:g(e?.identity)}}),Gs=async({satellite:t,...e})=>{let s=g(t?.identity);return Rt({...e,satellite:{...t,identity:s}})},Ys=async({satellite:t,...e})=>{let s=g(t?.identity);return kt({...e,satellite:{...t,identity:s}})};var Is=async t=>{A.getInstance().set(t),await D();let e=t.workers?.auth!==void 0?wt(t.workers.auth):void 0;return[...e?[e]:[]]},Ls=t=>w.getInstance().subscribe(t);export{M as InternetIdentityProvider,pt as NFIDProvider,Ls as authSubscribe,zs as deleteAsset,ds as deleteDoc,Ws as deleteManyAssets,us as deleteManyDocs,Gs as getAsset,At as getDoc,Ys as getManyAssets,ls as getManyDocs,Is as initJuno,Hs as listAssets,ms as listDocs,Pt as setDoc,ps as setManyDocs,re as signIn,I as signOut,ae as unsafeIdentity,Bs as uploadBlob,js as uploadFile};
2
2
  //# sourceMappingURL=index.js.map