@junobuild/core-peer 0.0.12 → 0.0.13-next-2024-04-28
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/declarations/satellite/satellite.did.d.ts +11 -0
- package/declarations/satellite/satellite.factory.did.js +10 -0
- package/declarations/satellite/satellite.factory.did.mjs +10 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/declarations/satellite/satellite.did.d.ts +11 -0
- package/dist/declarations/satellite/satellite.factory.did.js +10 -0
- package/dist/declarations/satellite/satellite.factory.did.mjs +10 -0
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +3 -3
- package/dist/types/constants/auth.constants.d.ts +1 -0
- package/dist/types/providers/auth.providers.d.ts +10 -20
- package/dist/types/types/auth.types.d.ts +9 -0
- package/dist/workers/auth.worker.js +14 -9
- package/dist/workers/auth.worker.js.map +4 -4
- package/package.json +6 -6
- package/declarations/satellite/index.d.ts +0 -45
- package/declarations/satellite/index.js +0 -37
- package/dist/declarations/satellite/index.d.ts +0 -45
- package/dist/declarations/satellite/index.js +0 -37
|
@@ -22,6 +22,12 @@ export interface AssetNoContent {
|
|
|
22
22
|
headers: Array<[string, string]>;
|
|
23
23
|
created_at: bigint;
|
|
24
24
|
}
|
|
25
|
+
export interface AuthenticationConfig {
|
|
26
|
+
internet_identity: [] | [AuthenticationConfigInternetIdentity];
|
|
27
|
+
}
|
|
28
|
+
export interface AuthenticationConfigInternetIdentity {
|
|
29
|
+
derivation_origin: [] | [string];
|
|
30
|
+
}
|
|
25
31
|
export interface CommitBatch {
|
|
26
32
|
batch_id: bigint;
|
|
27
33
|
headers: Array<[string, string]>;
|
|
@@ -124,6 +130,7 @@ export interface MemorySize {
|
|
|
124
130
|
}
|
|
125
131
|
export type Permission = {Controllers: null} | {Private: null} | {Public: null} | {Managed: null};
|
|
126
132
|
export interface Rule {
|
|
133
|
+
max_capacity: [] | [number];
|
|
127
134
|
memory: [] | [Memory];
|
|
128
135
|
updated_at: bigint;
|
|
129
136
|
max_size: [] | [bigint];
|
|
@@ -148,6 +155,7 @@ export interface SetDoc {
|
|
|
148
155
|
description: [] | [string];
|
|
149
156
|
}
|
|
150
157
|
export interface SetRule {
|
|
158
|
+
max_capacity: [] | [number];
|
|
151
159
|
memory: [] | [Memory];
|
|
152
160
|
updated_at: [] | [bigint];
|
|
153
161
|
max_size: [] | [bigint];
|
|
@@ -209,6 +217,7 @@ export interface _SERVICE {
|
|
|
209
217
|
del_rule: ActorMethod<[RulesType, string, DelDoc], undefined>;
|
|
210
218
|
deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
|
|
211
219
|
get_asset: ActorMethod<[string, string], [] | [AssetNoContent]>;
|
|
220
|
+
get_auth_config: ActorMethod<[], [] | [AuthenticationConfig]>;
|
|
212
221
|
get_config: ActorMethod<[], Config>;
|
|
213
222
|
get_doc: ActorMethod<[string, string], [] | [Doc]>;
|
|
214
223
|
get_many_assets: ActorMethod<[Array<[string, string]>], Array<[string, [] | [AssetNoContent]]>>;
|
|
@@ -225,6 +234,7 @@ export interface _SERVICE {
|
|
|
225
234
|
list_docs: ActorMethod<[string, ListParams], ListResults_1>;
|
|
226
235
|
list_rules: ActorMethod<[RulesType], Array<[string, Rule]>>;
|
|
227
236
|
memory_size: ActorMethod<[], MemorySize>;
|
|
237
|
+
set_auth_config: ActorMethod<[AuthenticationConfig], undefined>;
|
|
228
238
|
set_config: ActorMethod<[Config], undefined>;
|
|
229
239
|
set_controllers: ActorMethod<[SetControllersArgs], Array<[Principal, Controller]>>;
|
|
230
240
|
set_custom_domain: ActorMethod<[string, [] | [string]], undefined>;
|
|
@@ -235,3 +245,4 @@ export interface _SERVICE {
|
|
|
235
245
|
version: ActorMethod<[], string>;
|
|
236
246
|
}
|
|
237
247
|
export declare const idlFactory: IDL.InterfaceFactory;
|
|
248
|
+
export declare const init: (args: {IDL: typeof IDL}) => IDL.Type[];
|
|
@@ -45,6 +45,12 @@ export const idlFactory = ({IDL}) => {
|
|
|
45
45
|
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
46
46
|
created_at: IDL.Nat64
|
|
47
47
|
});
|
|
48
|
+
const AuthenticationConfigInternetIdentity = IDL.Record({
|
|
49
|
+
derivation_origin: IDL.Opt(IDL.Text)
|
|
50
|
+
});
|
|
51
|
+
const AuthenticationConfig = IDL.Record({
|
|
52
|
+
internet_identity: IDL.Opt(AuthenticationConfigInternetIdentity)
|
|
53
|
+
});
|
|
48
54
|
const StorageConfigIFrame = IDL.Variant({
|
|
49
55
|
Deny: IDL.Null,
|
|
50
56
|
AllowAny: IDL.Null,
|
|
@@ -156,6 +162,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
156
162
|
Managed: IDL.Null
|
|
157
163
|
});
|
|
158
164
|
const Rule = IDL.Record({
|
|
165
|
+
max_capacity: IDL.Opt(IDL.Nat32),
|
|
159
166
|
memory: IDL.Opt(Memory),
|
|
160
167
|
updated_at: IDL.Nat64,
|
|
161
168
|
max_size: IDL.Opt(IDL.Nat),
|
|
@@ -180,6 +187,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
180
187
|
description: IDL.Opt(IDL.Text)
|
|
181
188
|
});
|
|
182
189
|
const SetRule = IDL.Record({
|
|
190
|
+
max_capacity: IDL.Opt(IDL.Nat32),
|
|
183
191
|
memory: IDL.Opt(Memory),
|
|
184
192
|
updated_at: IDL.Opt(IDL.Nat64),
|
|
185
193
|
max_size: IDL.Opt(IDL.Nat),
|
|
@@ -213,6 +221,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
213
221
|
del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
|
|
214
222
|
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
215
223
|
get_asset: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(AssetNoContent)], ['query']),
|
|
224
|
+
get_auth_config: IDL.Func([], [IDL.Opt(AuthenticationConfig)], ['query']),
|
|
216
225
|
get_config: IDL.Func([], [Config], []),
|
|
217
226
|
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
|
|
218
227
|
get_many_assets: IDL.Func(
|
|
@@ -238,6 +247,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
238
247
|
list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']),
|
|
239
248
|
list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']),
|
|
240
249
|
memory_size: IDL.Func([], [MemorySize], ['query']),
|
|
250
|
+
set_auth_config: IDL.Func([AuthenticationConfig], [], []),
|
|
241
251
|
set_config: IDL.Func([Config], [], []),
|
|
242
252
|
set_controllers: IDL.Func(
|
|
243
253
|
[SetControllersArgs],
|
|
@@ -45,6 +45,12 @@ export const idlFactory = ({IDL}) => {
|
|
|
45
45
|
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
46
46
|
created_at: IDL.Nat64
|
|
47
47
|
});
|
|
48
|
+
const AuthenticationConfigInternetIdentity = IDL.Record({
|
|
49
|
+
derivation_origin: IDL.Opt(IDL.Text)
|
|
50
|
+
});
|
|
51
|
+
const AuthenticationConfig = IDL.Record({
|
|
52
|
+
internet_identity: IDL.Opt(AuthenticationConfigInternetIdentity)
|
|
53
|
+
});
|
|
48
54
|
const StorageConfigIFrame = IDL.Variant({
|
|
49
55
|
Deny: IDL.Null,
|
|
50
56
|
AllowAny: IDL.Null,
|
|
@@ -156,6 +162,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
156
162
|
Managed: IDL.Null
|
|
157
163
|
});
|
|
158
164
|
const Rule = IDL.Record({
|
|
165
|
+
max_capacity: IDL.Opt(IDL.Nat32),
|
|
159
166
|
memory: IDL.Opt(Memory),
|
|
160
167
|
updated_at: IDL.Nat64,
|
|
161
168
|
max_size: IDL.Opt(IDL.Nat),
|
|
@@ -180,6 +187,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
180
187
|
description: IDL.Opt(IDL.Text)
|
|
181
188
|
});
|
|
182
189
|
const SetRule = IDL.Record({
|
|
190
|
+
max_capacity: IDL.Opt(IDL.Nat32),
|
|
183
191
|
memory: IDL.Opt(Memory),
|
|
184
192
|
updated_at: IDL.Opt(IDL.Nat64),
|
|
185
193
|
max_size: IDL.Opt(IDL.Nat),
|
|
@@ -213,6 +221,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
213
221
|
del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
|
|
214
222
|
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
215
223
|
get_asset: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(AssetNoContent)], ['query']),
|
|
224
|
+
get_auth_config: IDL.Func([], [IDL.Opt(AuthenticationConfig)], ['query']),
|
|
216
225
|
get_config: IDL.Func([], [Config], []),
|
|
217
226
|
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
|
|
218
227
|
get_many_assets: IDL.Func(
|
|
@@ -238,6 +247,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
238
247
|
list_docs: IDL.Func([IDL.Text, ListParams], [ListResults_1], ['query']),
|
|
239
248
|
list_rules: IDL.Func([RulesType], [IDL.Vec(IDL.Tuple(IDL.Text, Rule))], ['query']),
|
|
240
249
|
memory_size: IDL.Func([], [MemorySize], ['query']),
|
|
250
|
+
set_auth_config: IDL.Func([AuthenticationConfig], [], []),
|
|
241
251
|
set_config: IDL.Func([Config], [], []),
|
|
242
252
|
set_controllers: IDL.Func(
|
|
243
253
|
[SetControllersArgs],
|
package/dist/browser/index.js
CHANGED
|
@@ -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},d=t=>p(t)?[t]:[],y=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 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 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 k="http://127.0.0.1:5987",lt="rdmx6-jaaaa-aaaaa-aaadq-cai";var x=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 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=x.getInstance().get()?.container;if(c(o)||o===!1)return`https://identity.${this.#t??ct}`;let i=x.getInstance().get(),n=p(i)&&p(i?.internetIdentityId)?i.internetIdentityId:lt,{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: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,updated_at:s,description:o}=t;return{description:d(o),data:await ot(e),updated_at:d(s)}},J=t=>{let{updated_at:e}=t;return{updated_at:d(e)}},U=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 F(i),...n}};import{Principal as ee}from"@dfinity/principal";var K=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:c(t)?[]:[{key:d(t.key),description:d(t.description)}],paginate:d(c(e)?void 0:{start_after:d(e.startAfter),limit:d(c(e.limit)?void 0:BigInt(e.limit))}),order:d(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:d(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({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}),u=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}),m=t.Record({key:u,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.Record({derivation_origin:t.Opt(t.Text)}),T=t.Record({internet_identity:t.Opt(_)}),O=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),b=t.Record({status_code:t.Nat16,location:t.Text}),P=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)))}),N=t.Record({storage:P}),l=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)}),v=t.Variant({Heap:t.Null,Stable:t.Null}),C=t.Record({memory:v,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,m)),items_length:t.Nat64}),Ht=t.Record({updated_at:t.Nat64,created_at: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(v),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:E,created_at: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({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),Xt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(v),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:E,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(m)],["query"]),get_auth_config:t.Func([],[t.Opt(T)],["query"]),get_config:t.Func([],[N],[]),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(m)))],["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([T],[],[]),set_config:t.Func([N],[],[]),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?k:i:"https://icp-api.io",a=new oe({identity:s,host:r,...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?k: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}:x.getInstance().get()??{satelliteId:void 0},Z=({container:t})=>p(t)?{container:t}:x.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=y(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 u=y(a);n.push(p(u)?await U({key:r,doc:u}):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:u}=a;o.push([r,u,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},_t=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await f(s),{key:i}=e;return o(t,i,J(e))},Tt=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:u}=await o.list_docs(t,K(e)),h=[];for(let[m,_]of i){let{data:T,owner:O,description:b,...P}=_;h.push({key:m,description:y(b),owner:O.toText(),data:await dt({data:T}),...P})}return{items:h,items_length:r,items_page:y(n),matches_length:a,matches_pages:y(u)}};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 _t({...e,satellite:{...t,identity:s}})},us=async({satellite:t,...e})=>{let s=g(t?.identity);return Tt({...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 A,D=async t=>{if(A=A??await $(),!(await A?.isAuthenticated()??!1))return;let s=await Nt(t);w.getInstance().set(s)},re=async t=>new Promise(async(e,s)=>{A=A??await $();let o=t?.provider??new M({});await A.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 A?.logout(),A=void 0,w.getInstance().reset()},q=()=>A?.getIdentity(),ae=async()=>(A??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:u})=>{let h=await f(u),{batch_id:m}=await h.init_asset_upload({collection:s,full_path:n,name:e,token:d(i),encoding_type:d(r),description:d(a)}),_=19e5,T=[],O=V()?new Blob([await t.arrayBuffer()]):t,b=0n;for(let l=0;l<O.size;l+=_){let S=O.slice(l,l+_);T.push({batchId:m,chunk:S,actor:h,orderId:b}),b++}let P=[];for await(let l of ce({uploadChunks:T}))P=[...P,...l];let N=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:m,chunk_ids:P.map(({chunk_id:l})=>l),headers:[...o,...N||[]]})};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:d(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:u}=await o.list_assets(t,K(s));return{items:i.map(([h,m])=>m),items_length:n,items_page:y(r),matches_length:a,matches_pages:y(u)}},St=async({collection:t,fullPath:e,satellite:s})=>(await f(s)).del_asset(t,e),Rt=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)},kt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await f(s);return y(await o(t,e))},vt=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 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:u})=>{let h=g(r?.identity),m=decodeURI(t),_=i??`/${s}/${m}`,T={...r,identity:h};return await Ot({data:e,filename:m,collection:s,token:n,headers:o,fullPath:_,encoding:a,satellite:T,description:u}),{downloadUrl:`${X(T)}${_}${n!==void 0?`?token=${n}`:""}`,fullPath:_,name:m}},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:u,name:h,owner:m,description:_},headers:T,encodings:O,created_at:b,updated_at:P})=>{let N=y(u);return{fullPath:a,description:y(_),name:h,downloadUrl:`${r}${a}${N!==void 0?`?token=${N}`:""}`,token:N,headers:T,encodings:O.reduce((l,[S,{modified:v,sha256:C,total_length:B}])=>({...l,[S]:{modified:v,sha256:Ct(C),total_length:B}}),{}),owner:m.toText(),created_at:b,updated_at:P}}),...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})=>Rt({assets:t,satellite:{...e,identity:g(e?.identity)}}),Gs=async({satellite:t,...e})=>{let s=g(t?.identity);return kt({...e,satellite:{...t,identity:s}})},Ys=async({satellite:t,...e})=>{let s=g(t?.identity);return vt({...e,satellite:{...t,identity:s}})};var Is=async t=>{x.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
|