@junobuild/core-peer 0.0.1 → 0.0.3-next-2023-12-08
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 +18 -0
- package/declarations/satellite/satellite.factory.did.js +32 -2
- package/declarations/satellite/satellite.factory.did.mjs +32 -2
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/declarations/satellite/satellite.did.d.ts +18 -0
- package/dist/declarations/satellite/satellite.factory.did.js +32 -2
- package/dist/declarations/satellite/satellite.factory.did.mjs +32 -2
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +4 -4
- package/dist/types/api/doc.api.d.ts +24 -0
- package/dist/types/api/storage.api.d.ts +6 -0
- package/dist/types/services/doc.services.d.ts +24 -0
- package/dist/types/services/storage.services.d.ts +6 -0
- package/dist/types/types/post-message.d.ts +8 -2
- package/dist/types/utils/doc.utils.d.ts +8 -0
- package/dist/workers/auth.worker.js +4 -4
- package/dist/workers/auth.worker.js.map +3 -3
- package/package.json +7 -8
- package/dist/workers/auth.worker.js.gz +0 -0
|
@@ -48,6 +48,10 @@ export interface DelDoc {
|
|
|
48
48
|
export interface DeleteControllersArgs {
|
|
49
49
|
controllers: Array<Principal>;
|
|
50
50
|
}
|
|
51
|
+
export interface DepositCyclesArgs {
|
|
52
|
+
cycles: bigint;
|
|
53
|
+
destination_id: Principal;
|
|
54
|
+
}
|
|
51
55
|
export interface Doc {
|
|
52
56
|
updated_at: bigint;
|
|
53
57
|
owner: Principal;
|
|
@@ -60,6 +64,7 @@ export interface HttpRequest {
|
|
|
60
64
|
method: string;
|
|
61
65
|
body: Uint8Array | number[];
|
|
62
66
|
headers: Array<[string, string]>;
|
|
67
|
+
certificate_version: [] | [number];
|
|
63
68
|
}
|
|
64
69
|
export interface HttpResponse {
|
|
65
70
|
body: Uint8Array | number[];
|
|
@@ -146,8 +151,15 @@ export interface SetRule {
|
|
|
146
151
|
write: Permission;
|
|
147
152
|
}
|
|
148
153
|
export interface StorageConfig {
|
|
154
|
+
iframe: [] | [StorageConfigIFrame];
|
|
149
155
|
rewrites: Array<[string, string]>;
|
|
150
156
|
headers: Array<[string, Array<[string, string]>]>;
|
|
157
|
+
redirects: [] | [Array<[string, StorageConfigRedirect]>];
|
|
158
|
+
}
|
|
159
|
+
export type StorageConfigIFrame = {Deny: null} | {AllowAny: null} | {SameOrigin: null};
|
|
160
|
+
export interface StorageConfigRedirect {
|
|
161
|
+
status_code: number;
|
|
162
|
+
location: string;
|
|
151
163
|
}
|
|
152
164
|
export interface StreamingCallbackHttpResponse {
|
|
153
165
|
token: [] | [StreamingCallbackToken];
|
|
@@ -183,9 +195,14 @@ export interface _SERVICE {
|
|
|
183
195
|
del_controllers: ActorMethod<[DeleteControllersArgs], Array<[Principal, Controller]>>;
|
|
184
196
|
del_custom_domain: ActorMethod<[string], undefined>;
|
|
185
197
|
del_doc: ActorMethod<[string, string, DelDoc], undefined>;
|
|
198
|
+
del_docs: ActorMethod<[string], undefined>;
|
|
199
|
+
del_many_assets: ActorMethod<[Array<[string, string]>], undefined>;
|
|
200
|
+
del_many_docs: ActorMethod<[Array<[string, string, DelDoc]>], undefined>;
|
|
186
201
|
del_rule: ActorMethod<[RulesType, string, DelDoc], undefined>;
|
|
202
|
+
deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
|
|
187
203
|
get_config: ActorMethod<[], Config>;
|
|
188
204
|
get_doc: ActorMethod<[string, string], [] | [Doc]>;
|
|
205
|
+
get_many_docs: ActorMethod<[Array<[string, string]>], Array<[string, [] | [Doc]]>>;
|
|
189
206
|
http_request: ActorMethod<[HttpRequest], HttpResponse>;
|
|
190
207
|
http_request_streaming_callback: ActorMethod<
|
|
191
208
|
[StreamingCallbackToken],
|
|
@@ -201,6 +218,7 @@ export interface _SERVICE {
|
|
|
201
218
|
set_controllers: ActorMethod<[SetControllersArgs], Array<[Principal, Controller]>>;
|
|
202
219
|
set_custom_domain: ActorMethod<[string, [] | [string]], undefined>;
|
|
203
220
|
set_doc: ActorMethod<[string, string, SetDoc], Doc>;
|
|
221
|
+
set_many_docs: ActorMethod<[Array<[string, string, SetDoc]>], Array<[string, Doc]>>;
|
|
204
222
|
set_rule: ActorMethod<[RulesType, string, SetRule], undefined>;
|
|
205
223
|
upload_asset_chunk: ActorMethod<[UploadChunk], UploadChunkResult>;
|
|
206
224
|
version: ActorMethod<[], string>;
|
|
@@ -21,9 +21,24 @@ export const idlFactory = ({IDL}) => {
|
|
|
21
21
|
});
|
|
22
22
|
const DelDoc = IDL.Record({updated_at: IDL.Opt(IDL.Nat64)});
|
|
23
23
|
const RulesType = IDL.Variant({Db: IDL.Null, Storage: IDL.Null});
|
|
24
|
+
const DepositCyclesArgs = IDL.Record({
|
|
25
|
+
cycles: IDL.Nat,
|
|
26
|
+
destination_id: IDL.Principal
|
|
27
|
+
});
|
|
28
|
+
const StorageConfigIFrame = IDL.Variant({
|
|
29
|
+
Deny: IDL.Null,
|
|
30
|
+
AllowAny: IDL.Null,
|
|
31
|
+
SameOrigin: IDL.Null
|
|
32
|
+
});
|
|
33
|
+
const StorageConfigRedirect = IDL.Record({
|
|
34
|
+
status_code: IDL.Nat16,
|
|
35
|
+
location: IDL.Text
|
|
36
|
+
});
|
|
24
37
|
const StorageConfig = IDL.Record({
|
|
38
|
+
iframe: IDL.Opt(StorageConfigIFrame),
|
|
25
39
|
rewrites: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
26
|
-
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))))
|
|
40
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)))),
|
|
41
|
+
redirects: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, StorageConfigRedirect)))
|
|
27
42
|
});
|
|
28
43
|
const Config = IDL.Record({storage: StorageConfig});
|
|
29
44
|
const Doc = IDL.Record({
|
|
@@ -37,7 +52,8 @@ export const idlFactory = ({IDL}) => {
|
|
|
37
52
|
url: IDL.Text,
|
|
38
53
|
method: IDL.Text,
|
|
39
54
|
body: IDL.Vec(IDL.Nat8),
|
|
40
|
-
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))
|
|
55
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
56
|
+
certificate_version: IDL.Opt(IDL.Nat16)
|
|
41
57
|
});
|
|
42
58
|
const Memory = IDL.Variant({Heap: IDL.Null, Stable: IDL.Null});
|
|
43
59
|
const StreamingCallbackToken = IDL.Record({
|
|
@@ -187,9 +203,18 @@ export const idlFactory = ({IDL}) => {
|
|
|
187
203
|
),
|
|
188
204
|
del_custom_domain: IDL.Func([IDL.Text], [], []),
|
|
189
205
|
del_doc: IDL.Func([IDL.Text, IDL.Text, DelDoc], [], []),
|
|
206
|
+
del_docs: IDL.Func([IDL.Text], [], []),
|
|
207
|
+
del_many_assets: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))], [], []),
|
|
208
|
+
del_many_docs: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, DelDoc))], [], []),
|
|
190
209
|
del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
|
|
210
|
+
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
191
211
|
get_config: IDL.Func([], [Config], []),
|
|
192
212
|
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
|
|
213
|
+
get_many_docs: IDL.Func(
|
|
214
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))],
|
|
215
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(Doc)))],
|
|
216
|
+
['query']
|
|
217
|
+
),
|
|
193
218
|
http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
|
|
194
219
|
http_request_streaming_callback: IDL.Func(
|
|
195
220
|
[StreamingCallbackToken],
|
|
@@ -210,6 +235,11 @@ export const idlFactory = ({IDL}) => {
|
|
|
210
235
|
),
|
|
211
236
|
set_custom_domain: IDL.Func([IDL.Text, IDL.Opt(IDL.Text)], [], []),
|
|
212
237
|
set_doc: IDL.Func([IDL.Text, IDL.Text, SetDoc], [Doc], []),
|
|
238
|
+
set_many_docs: IDL.Func(
|
|
239
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, SetDoc))],
|
|
240
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, Doc))],
|
|
241
|
+
[]
|
|
242
|
+
),
|
|
213
243
|
set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [], []),
|
|
214
244
|
upload_asset_chunk: IDL.Func([UploadChunk], [UploadChunkResult], []),
|
|
215
245
|
version: IDL.Func([], [IDL.Text], ['query'])
|
|
@@ -21,9 +21,24 @@ export const idlFactory = ({IDL}) => {
|
|
|
21
21
|
});
|
|
22
22
|
const DelDoc = IDL.Record({updated_at: IDL.Opt(IDL.Nat64)});
|
|
23
23
|
const RulesType = IDL.Variant({Db: IDL.Null, Storage: IDL.Null});
|
|
24
|
+
const DepositCyclesArgs = IDL.Record({
|
|
25
|
+
cycles: IDL.Nat,
|
|
26
|
+
destination_id: IDL.Principal
|
|
27
|
+
});
|
|
28
|
+
const StorageConfigIFrame = IDL.Variant({
|
|
29
|
+
Deny: IDL.Null,
|
|
30
|
+
AllowAny: IDL.Null,
|
|
31
|
+
SameOrigin: IDL.Null
|
|
32
|
+
});
|
|
33
|
+
const StorageConfigRedirect = IDL.Record({
|
|
34
|
+
status_code: IDL.Nat16,
|
|
35
|
+
location: IDL.Text
|
|
36
|
+
});
|
|
24
37
|
const StorageConfig = IDL.Record({
|
|
38
|
+
iframe: IDL.Opt(StorageConfigIFrame),
|
|
25
39
|
rewrites: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
26
|
-
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))))
|
|
40
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)))),
|
|
41
|
+
redirects: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, StorageConfigRedirect)))
|
|
27
42
|
});
|
|
28
43
|
const Config = IDL.Record({storage: StorageConfig});
|
|
29
44
|
const Doc = IDL.Record({
|
|
@@ -37,7 +52,8 @@ export const idlFactory = ({IDL}) => {
|
|
|
37
52
|
url: IDL.Text,
|
|
38
53
|
method: IDL.Text,
|
|
39
54
|
body: IDL.Vec(IDL.Nat8),
|
|
40
|
-
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))
|
|
55
|
+
headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
56
|
+
certificate_version: IDL.Opt(IDL.Nat16)
|
|
41
57
|
});
|
|
42
58
|
const Memory = IDL.Variant({Heap: IDL.Null, Stable: IDL.Null});
|
|
43
59
|
const StreamingCallbackToken = IDL.Record({
|
|
@@ -187,9 +203,18 @@ export const idlFactory = ({IDL}) => {
|
|
|
187
203
|
),
|
|
188
204
|
del_custom_domain: IDL.Func([IDL.Text], [], []),
|
|
189
205
|
del_doc: IDL.Func([IDL.Text, IDL.Text, DelDoc], [], []),
|
|
206
|
+
del_docs: IDL.Func([IDL.Text], [], []),
|
|
207
|
+
del_many_assets: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))], [], []),
|
|
208
|
+
del_many_docs: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, DelDoc))], [], []),
|
|
190
209
|
del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
|
|
210
|
+
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
191
211
|
get_config: IDL.Func([], [Config], []),
|
|
192
212
|
get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
|
|
213
|
+
get_many_docs: IDL.Func(
|
|
214
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))],
|
|
215
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(Doc)))],
|
|
216
|
+
['query']
|
|
217
|
+
),
|
|
193
218
|
http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
|
|
194
219
|
http_request_streaming_callback: IDL.Func(
|
|
195
220
|
[StreamingCallbackToken],
|
|
@@ -210,6 +235,11 @@ export const idlFactory = ({IDL}) => {
|
|
|
210
235
|
),
|
|
211
236
|
set_custom_domain: IDL.Func([IDL.Text, IDL.Opt(IDL.Text)], [], []),
|
|
212
237
|
set_doc: IDL.Func([IDL.Text, IDL.Text, SetDoc], [Doc], []),
|
|
238
|
+
set_many_docs: IDL.Func(
|
|
239
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, SetDoc))],
|
|
240
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, Doc))],
|
|
241
|
+
[]
|
|
242
|
+
),
|
|
213
243
|
set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [], []),
|
|
214
244
|
upload_asset_chunk: IDL.Func([UploadChunk], [UploadChunkResult], []),
|
|
215
245
|
version: IDL.Func([], [IDL.Text], ['query'])
|
package/dist/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var l=t=>t==null,Ot=t=>!l(t);var p=t=>Ot(t)?[t]:[],g=t=>t?.[0],z=async t=>{let e=new Blob([JSON.stringify(t)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},G=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())},k=()=>typeof window<"u";var O=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:i})=>i!==s)}};var w=class t extends O{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 Y=BigInt(144e11),J={width:576,height:576},X={width:505,height:705},Q="internetcomputer.org";var f=class t extends O{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}localIdentity(){return this.get()?.localIdentityCanisterId!==void 0}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var B=({width:t,height:e})=>{if(!k()||l(window)||l(window.top))return;let{top:{innerWidth:s,innerHeight:i}}=window,o=i/2+screenY-e/2,r=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=${o}, left=${r}`};var R=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=f.getInstance().localIdentity()?`http://${f.getInstance().get()?.localIdentityCanisterId}.localhost:8000`:`https://identity.${this.#t??Q}`;return{...e!==!1&&{windowOpenerFeatures:B(J)},identityProvider:s}}},Z=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:B(X)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as vt}from"@dfinity/auth-client";var U=()=>vt.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var $=async({data:t})=>{try{return await G(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};import{Principal as kt}from"@dfinity/principal";var C=({matcher:t,paginate:e,order:s,owner:i})=>({matcher:l(t)?[]:[{key:p(t.key),description:p(t.description)}],paginate:p(l(e)?void 0:{start_after:p(e.startAfter),limit:p(l(e.limit)?void 0:BigInt(e.limit))}),order:p(l(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:p(l(i)?void 0:typeof i=="string"?kt.fromText(i):i)});var I=({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)}),i=t.Variant({Write:t.Null,Admin:t.Null}),o=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:i,expires_at:t.Opt(t.Nat64)}),r=t.Record({updated_at:t.Opt(t.Nat64)}),n=t.Variant({Db:t.Null,Storage:t.Null}),c=t.Record({rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text))))}),d=t.Record({storage:c}),a=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64}),u=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text))}),m=t.Variant({Heap:t.Null,Stable:t.Null}),h=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}),P=t.Variant({Callback:t.Record({token:h,callback:t.Func([],[],["query"])})}),b=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(P),status_code:t.Nat16}),x=t.Record({token:t.Opt(h),body:t.Vec(t.Nat8)}),N=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}),y=t.Record({batch_id:t.Nat}),S=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),F=t.Record({field:S,desc:t.Bool}),V=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),mt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),j=t.Record({order:t.Opt(F),owner:t.Opt(t.Principal),matcher:t.Opt(V),paginate:t.Opt(mt)}),yt=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}),ft=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),gt=t.Record({key:yt,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,ft)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64}),ht=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,gt)),items_length:t.Nat64}),xt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,bn_id:t.Opt(t.Text)}),Tt=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,a)),items_length:t.Nat64}),v=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),At=t.Record({memory:t.Opt(m),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:v,created_at:t.Nat64,mutable_permissions:t.Opt(t.Bool),write:v}),_t=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:i,expires_at:t.Opt(t.Nat64)}),wt=t.Record({controller:_t,controllers:t.Vec(t.Principal)}),Pt=t.Record({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),bt=t.Record({memory:t.Opt(m),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:v,mutable_permissions:t.Opt(t.Bool),write:v}),Nt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),St=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([e],[],[]),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,o))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,r],[],[]),del_rule:t.Func([n,t.Text,r],[],[]),get_config:t.Func([],[d],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(a)],["query"]),http_request:t.Func([u],[b],["query"]),http_request_streaming_callback:t.Func([h],[x],["query"]),init_asset_upload:t.Func([N],[y],[]),list_assets:t.Func([t.Text,j],[ht],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,o))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,xt))],["query"]),list_docs:t.Func([t.Text,j],[Tt],["query"]),list_rules:t.Func([n],[t.Vec(t.Tuple(t.Text,At))],["query"]),set_config:t.Func([d],[],[]),set_controllers:t.Func([wt],[t.Vec(t.Tuple(t.Principal,o))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,Pt],[a],[]),set_rule:t.Func([n,t.Text,bt],[],[]),upload_asset_chunk:t.Func([Nt],[St],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as Rt,HttpAgent as Ut}from"@dfinity/agent";var D=async({satelliteId:t,idlFactory:e,identity:s,fetch:i,env:o="prod"})=>{let r=o==="dev"||f.getInstance().localIdentity(),n=r?"http://127.0.0.1:8000/":"https://icp-api.io",c=new Ut({identity:s,...n&&{host:n},...i&&{fetch:i}});return r&&await c.fetchRootKey(),Rt.createActor(e,{agent:c,canisterId:t})};var T=async({satelliteId:t,...e})=>{let{satelliteId:s}=t!==void 0?{satelliteId:t}:f.getInstance().get()??{satelliteId:void 0};if(!s)throw new Error("No satellite principal defined.");return D({satelliteId:s,idlFactory:I,...e})};var L=async({collection:t,key:e,satellite:s})=>{let i=await T(s),o=g(await i.get_doc(t,e));if(l(o))return;let{data:r,owner:n,description:c,...d}=o,a=await $({data:r});return{key:e,description:g(c),owner:n.toText(),data:a,...d}},tt=async({collection:t,doc:e,satellite:s})=>{let i=await T(s),{key:o,data:r,updated_at:n,description:c}=e,d=await i.set_doc(t,o,{description:p(c),data:await z(r),updated_at:p(n)}),{owner:a,updated_at:u,created_at:m,description:h}=d;return{key:o,description:g(h),owner:a.toText(),data:r,created_at:m,updated_at:u}},et=async({collection:t,doc:e,satellite:s})=>{let i=await T(s),{key:o,updated_at:r}=e;return i.del_doc(t,o,{updated_at:p(r)})},st=async({collection:t,filter:e,satellite:s})=>{let i=await T(s),{items:o,items_page:r,items_length:n,matches_length:c,matches_pages:d}=await i.list_docs(t,C(e)),a=[];for(let[u,m]of o){let{data:h,owner:P,description:b,...x}=m;a.push({key:u,description:g(b),owner:P.toText(),data:await $({data:h}),...x})}return{items:a,items_length:n,items_page:g(r),matches_length:c,matches_pages:g(d)}};import{AnonymousIdentity as Ct}from"@dfinity/agent";var A=t=>t!==void 0?t:E()??new Ct;var it=async({satellite:t,...e})=>{let s=A(t?.identity);return L({...e,satellite:{...t,identity:s}})},ot=async({satellite:t,...e})=>{let s=A(t?.identity);return tt({...e,satellite:{...t,identity:s}})},Pe=async({satellite:t,...e})=>{let s=A(t?.identity);return et({...e,satellite:{...t,identity:s}})},be=async({satellite:t,filter:e,...s})=>{let i=A(t?.identity);return st({...s,filter:e??{},satellite:{...t,identity:i}})};var rt=async t=>{let e=E();if(l(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),i=await it({collection:"#user",key:s});return l(i)?await Et({userId:s,provider:t}):i},Et=async({userId:t,...e})=>ot({collection:"#user",doc:{key:t,data:e}});var _,q=async t=>{if(_=_??await U(),!(await _?.isAuthenticated()??!1))return;let s=await rt(t);w.getInstance().set(s)},Ft=async t=>new Promise(async(e,s)=>{_=_??await U();let i=t?.provider??new R({});await _.login({onSuccess:async()=>{await q(i.id),e()},onError:o=>s(o),maxTimeToLive:t?.maxTimeToLive??Y,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...i.signInOptions({windowed:t?.windowed})})}),M=async()=>{await _?.logout(),_=void 0,w.getInstance().reset()},E=()=>_?.getIdentity(),Vt=async()=>(_??await U()).getIdentity();var nt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),i=async()=>{W({message:"junoSignOutAuthTimer"}),await M()};return s.onmessage=async({data:o})=>{let{msg:r}=o;switch(r){case"junoSignOutAuthTimer":await i();return}},w.getInstance().subscribe(o=>{if(l(o)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var at=async({data:t,filename:e,collection:s,headers:i,token:o,fullPath:r,encoding:n,description:c,satellite:d})=>{let a=await T(d),{batch_id:u}=await a.init_asset_upload({collection:s,full_path:r,name:e,token:p(o),encoding_type:p(n),description:p(c)}),m=19e5,h=[],P=k()?new Blob([await t.arrayBuffer()]):t,b=0n;for(let y=0;y<P.size;y+=m){let S=P.slice(y,y+m);h.push({batchId:u,chunk:S,actor:a,orderId:b}),b++}let x=[];for await(let y of Bt({uploadChunks:h}))x=[...x,...y];let N=i.find(([y,S])=>y.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await a.commit_asset_upload({batch_id:u,chunk_ids:x.map(({chunk_id:y})=>y),headers:[...i,...N||[]]})};async function*Bt({uploadChunks:t,limit:e=12}){for(let s=0;s<t.length;s=s+e){let i=t.slice(s,s+e);yield await Promise.all(i.map(r=>$t(r)))}}var $t=async({batchId:t,chunk:e,actor:s,orderId:i})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:p(i)}),ct=async({collection:t,satellite:e,filter:s})=>{let i=await T(e),{items:o,items_length:r,items_page:n,matches_length:c,matches_pages:d}=await i.list_assets(t,C(s));return{items:o.map(([a,u])=>u),items_length:r,items_page:g(n),matches_length:c,matches_pages:g(d)}},lt=async({collection:t,fullPath:e,satellite:s})=>(await T(s)).del_asset(t,e),pt=async({collection:t,satellite:e})=>(await T(e)).del_assets(t);var dt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var K=()=>{let t=f.getInstance().get()?.satelliteId??"unknown";return f.getInstance().localIdentity()?`http://${t}.localhost:8000`:`https://${t}.icp0.io`};var H=t=>encodeURI(t.toLowerCase().replace(/\s/g,"-"));var es=async t=>ut(t),ss=async t=>ut({filename:t.data.name,...t}),ut=async({filename:t,data:e,collection:s,headers:i=[],fullPath:o,token:r,satellite:n,encoding:c,description:d})=>{let a=A(n?.identity),u=H(t),m=o||`/${s}/${u}`;return await at({data:e,filename:H(u),collection:s,token:r,headers:i,fullPath:m,encoding:c,satellite:{...n,identity:a},description:d}),{downloadUrl:`${K()}${m}${r!==void 0?`?token=${r}`:""}`,fullPath:m,name:u}},is=async({collection:t,satellite:e,filter:s})=>{let{items:i,...o}=await ct({collection:t,satellite:{...e,identity:A(e?.identity)},filter:s??{}}),r=K();return{assets:i.map(({key:{full_path:n,token:c,name:d,owner:a,description:u},headers:m,encodings:h,created_at:P,updated_at:b})=>{let x=g(c);return{fullPath:n,description:g(u),name:d,downloadUrl:`${r}${n}${x!==void 0?`?token=${x}`:""}`,token:x,headers:m,encodings:h.reduce((N,[y,{modified:S,sha256:F,total_length:V}])=>({...N,[y]:{modified:S,sha256:dt(F),total_length:V}}),{}),owner:a.toText(),created_at:P,updated_at:b}}),...o}},os=async({collection:t,fullPath:e,satellite:s})=>lt({collection:t,fullPath:e,satellite:{...s,identity:A(s?.identity)}}),rs=async({collection:t,satellite:e})=>pt({collection:t,satellite:{...e,identity:A(e?.identity)}});var ds=async t=>{f.getInstance().set(t),await q();let e=t.workers?.auth!==void 0?nt(t.workers.auth):void 0;return[...e?[e]:[]]},us=t=>w.getInstance().subscribe(t);export{R as InternetIdentityProvider,Z as NFIDProvider,us as authSubscribe,os as deleteAsset,rs as deleteAssets,Pe as deleteDoc,it as getDoc,ds as initJuno,is as listAssets,be as listDocs,ot as setDoc,Ft as signIn,M as signOut,Vt as unsafeIdentity,es as uploadBlob,ss as uploadFile};
|
|
1
|
+
import{Principal as D}from"@dfinity/principal";var c=t=>t==null,S=t=>!c(t);var j="__bigint__",q="__principal__",K="__uint8array__",zt=(t,e)=>typeof e=="bigint"?{[j]:`${e}`}:S(e)&&e instanceof D?{[q]:e.toText()}:S(e)&&e instanceof Uint8Array?{[K]:Array.from(e)}:e,Gt=(t,e)=>{let s=o=>e[o];return S(e)&&typeof e=="object"&&j in e?BigInt(s(j)):S(e)&&typeof e=="object"&&q in e?D.fromText(s(q)):S(e)&&typeof e=="object"&&K in e?Uint8Array.from(s(K)):e},l=t=>S(t)?[t]:[],f=t=>t?.[0],I=async t=>{let e=new Blob([JSON.stringify(t,zt)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},U=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(),Gt)},C=()=>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 H=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var L=BigInt(144e11),tt={width:576,height:576},et={width:505,height:705},st="internetcomputer.org";var g=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}localIdentity(){return this.get()?.localIdentityCanisterId!==void 0}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var z=({width:t,height:e})=>{if(!C()||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 E=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=g.getInstance().localIdentity()?`http://${g.getInstance().get()?.localIdentityCanisterId}.localhost:8000`:`https://identity.${this.#t??st}`;return{...e!==!1&&{windowOpenerFeatures:z(tt)},identityProvider:s}}},ot=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:z(et)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as Wt}from"@dfinity/auth-client";var F=()=>Wt.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var it=async({data:t})=>{try{return await U(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var G=async t=>{let{data:e,updated_at:s,description:o}=t;return{description:l(o),data:await I(e),updated_at:l(s)}},W=t=>{let{updated_at:e}=t;return{updated_at:l(e)}},k=async({doc:t,key:e})=>{let{owner:s,description:o,data:i,...n}=t;return{key:e,description:f(o),owner:s.toText(),data:await U(i),...n}};import{Principal as Yt}from"@dfinity/principal";var V=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:c(t)?[]:[{key:l(t.key),description:l(t.description)}],paginate:l(c(e)?void 0:{start_after:l(e.startAfter),limit:l(c(e.limit)?void 0:BigInt(e.limit))}),order:l(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:l(c(o)?void 0:typeof o=="string"?Yt.fromText(o):o)});var nt=({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}),p=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),h=t.Record({status_code:t.Nat16,location:t.Text}),m=t.Record({iframe:t.Opt(p),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,h)))}),x=t.Record({storage:m}),T=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64}),b=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)}),A=t.Variant({Heap:t.Null,Stable:t.Null}),_=t.Record({memory:A,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}),N=t.Variant({Callback:t.Record({token:_,callback:t.Func([],[],["query"])})}),y=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(N),status_code:t.Nat16}),O=t.Record({token:t.Opt(_),body:t.Vec(t.Nat8)}),B=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}),$=t.Record({batch_id:t.Nat}),Ot=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),vt=t.Record({field:Ot,desc:t.Bool}),kt=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),Rt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),Q=t.Record({order:t.Opt(vt),owner:t.Opt(t.Principal),matcher:t.Opt(kt),paginate:t.Opt(Rt)}),Ut=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}),Ct=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),Et=t.Record({key:Ut,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,Ct)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64}),Ft=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,Et)),items_length:t.Nat64}),Vt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,bn_id:t.Opt(t.Text)}),Mt=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,T)),items_length:t.Nat64}),R=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Bt=t.Record({memory:t.Opt(A),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:R,created_at:t.Nat64,mutable_permissions:t.Opt(t.Bool),write:R}),$t=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),jt=t.Record({controller:$t,controllers:t.Vec(t.Principal)}),Z=t.Record({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),qt=t.Record({memory:t.Opt(A),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:R,mutable_permissions:t.Opt(t.Bool),write:R}),Kt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Ht=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([e],[],[]),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_config:t.Func([],[x],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(T)],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(T)))],["query"]),http_request:t.Func([b],[y],["query"]),http_request_streaming_callback:t.Func([_],[O],["query"]),init_asset_upload:t.Func([B],[$],[]),list_assets:t.Func([t.Text,Q],[Ft],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Vt))],["query"]),list_docs:t.Func([t.Text,Q],[Mt],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,Bt))],["query"]),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,Z],[T],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,Z))],[t.Vec(t.Tuple(t.Text,T))],[]),set_rule:t.Func([r,t.Text,qt],[],[]),upload_asset_chunk:t.Func([Kt],[Ht],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as Jt,HttpAgent as Xt}from"@dfinity/agent";var rt=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,env:i="prod"})=>{let n=i==="dev"||g.getInstance().localIdentity(),r=n?"http://127.0.0.1:8000/":"https://icp-api.io",a=new Xt({identity:s,...r&&{host:r},...o&&{fetch:o}});return n&&await a.fetchRootKey(),Jt.createActor(e,{agent:a,canisterId:t})};var d=async({satelliteId:t,...e})=>{let{satelliteId:s}=t!==void 0?{satelliteId:t}:g.getInstance().get()??{satelliteId:void 0};if(!s)throw new Error("No satellite principal defined.");return rt({satelliteId:s,idlFactory:nt,...e})};var at=async({collection:t,key:e,satellite:s})=>{let o=await d(s),i=f(await o.get_doc(t,e));if(!c(i))return k({doc:i,key:e})},ct=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await d(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let p=f(a);n.push(S(p)?await k({key:r,doc:p}):void 0)}return n},lt=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await d(s),{key:i}=e,n=await G(e),r=await o(t,i,n);return await k({key:i,doc:r})},pt=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await d(e),o=[];for(let{collection:r,doc:a}of t){let{key:p}=a;o.push([r,p,await G(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await k({key:r,doc:a}));return n},dt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await d(s),{key:i}=e;return o(t,i,W(e))},ut=async({collection:t,satellite:e})=>{let{del_docs:s}=await d(e);return s(t)},mt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await d(e),o=t.map(({collection:i,doc:n})=>[i,n.key,W(n)]);await s(o)},yt=async({collection:t,filter:e,satellite:s})=>{let o=await d(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:p}=await o.list_docs(t,V(e)),h=[];for(let[m,x]of i){let{data:T,owner:b,description:A,..._}=x;h.push({key:m,description:f(A),owner:b.toText(),data:await it({data:T}),..._})}return{items:h,items_length:r,items_page:f(n),matches_length:a,matches_pages:f(p)}};import{AnonymousIdentity as Qt}from"@dfinity/agent";var u=t=>t!==void 0?t:M()??new Qt;var ft=async({satellite:t,...e})=>{let s=u(t?.identity);return at({...e,satellite:{...t,identity:s}})},Ge=async({satellite:t,...e})=>{let s=u(t?.identity);return ct({...e,satellite:{...t,identity:s}})},gt=async({satellite:t,...e})=>{let s=u(t?.identity);return lt({...e,satellite:{...t,identity:s}})},We=async({satellite:t,...e})=>{let s=u(t?.identity);return pt({...e,satellite:{...t,identity:s}})},Ye=async({satellite:t,...e})=>{let s=u(t?.identity);return dt({...e,satellite:{...t,identity:s}})},Je=async({collection:t,satellite:e})=>ut({collection:t,satellite:{...e,identity:u(e?.identity)}}),Xe=async({satellite:t,...e})=>{let s=u(t?.identity);return mt({...e,satellite:{...t,identity:s}})},Qe=async({satellite:t,filter:e,...s})=>{let o=u(t?.identity);return yt({...s,filter:e??{},satellite:{...t,identity:o}})};var ht=async t=>{let e=M();if(c(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await ft({collection:"#user",key:s});return c(o)?await Zt({userId:s,provider:t}):o},Zt=async({userId:t,...e})=>gt({collection:"#user",doc:{key:t,data:e}});var P,Y=async t=>{if(P=P??await F(),!(await P?.isAuthenticated()??!1))return;let s=await ht(t);w.getInstance().set(s)},Dt=async t=>new Promise(async(e,s)=>{P=P??await F();let o=t?.provider??new E({});await P.login({onSuccess:async()=>{await Y(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??L,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),J=async()=>{await P?.logout(),P=void 0,w.getInstance().reset()},M=()=>P?.getIdentity(),It=async()=>(P??await F()).getIdentity();var xt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{H({message:"junoSignOutAuthTimer"}),await J()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":H({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},w.getInstance().subscribe(i=>{if(c(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var _t=async({data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a,satellite:p})=>{let h=await d(p),{batch_id:m}=await h.init_asset_upload({collection:s,full_path:n,name:e,token:l(i),encoding_type:l(r),description:l(a)}),x=19e5,T=[],b=C()?new Blob([await t.arrayBuffer()]):t,A=0n;for(let y=0;y<b.size;y+=x){let O=b.slice(y,y+x);T.push({batchId:m,chunk:O,actor:h,orderId:A}),A++}let _=[];for await(let y of Lt({uploadChunks:T}))_=[..._,...y];let N=o.find(([y,O])=>y.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:_.map(({chunk_id:y})=>y),headers:[...o,...N||[]]})};async function*Lt({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=>te(n)))}}var te=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:l(o)}),Tt=async({collection:t,satellite:e,filter:s})=>{let o=await d(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:p}=await o.list_assets(t,V(s));return{items:i.map(([h,m])=>m),items_length:n,items_page:f(r),matches_length:a,matches_pages:f(p)}},At=async({collection:t,fullPath:e,satellite:s})=>(await d(s)).del_asset(t,e),Pt=async({collection:t,satellite:e})=>(await d(e)).del_assets(t),wt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await d(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)};var bt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var X=()=>{let t=g.getInstance().get()?.satelliteId??"unknown";return g.getInstance().localIdentity()?`http://${t}.localhost:8000`:`https://${t}.icp0.io`};var St=t=>encodeURI(t.toLowerCase().replace(/\s/g,"-"));var Ns=async t=>Nt(t),Os=async t=>Nt({filename:t.data.name,...t}),Nt=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:p})=>{let h=u(r?.identity),m=St(t),x=i??`/${s}/${m}`;return await _t({data:e,filename:m,collection:s,token:n,headers:o,fullPath:x,encoding:a,satellite:{...r,identity:h},description:p}),{downloadUrl:`${X()}${x}${n!==void 0?`?token=${n}`:""}`,fullPath:x,name:m}},vs=async({collection:t,satellite:e,filter:s})=>{let{items:o,...i}=await Tt({collection:t,satellite:{...e,identity:u(e?.identity)},filter:s??{}}),n=X();return{assets:o.map(({key:{full_path:r,token:a,name:p,owner:h,description:m},headers:x,encodings:T,created_at:b,updated_at:A})=>{let _=f(a);return{fullPath:r,description:f(m),name:p,downloadUrl:`${n}${r}${_!==void 0?`?token=${_}`:""}`,token:_,headers:x,encodings:T.reduce((N,[y,{modified:O,sha256:B,total_length:$}])=>({...N,[y]:{modified:O,sha256:bt(B),total_length:$}}),{}),owner:h.toText(),created_at:b,updated_at:A}}),...i}},ks=async({collection:t,fullPath:e,satellite:s})=>At({collection:t,fullPath:e,satellite:{...s,identity:u(s?.identity)}}),Rs=async({collection:t,satellite:e})=>Pt({collection:t,satellite:{...e,identity:u(e?.identity)}}),Us=async({assets:t,satellite:e})=>wt({assets:t,satellite:{...e,identity:u(e?.identity)}});var Bs=async t=>{g.getInstance().set(t),await Y();let e=t.workers?.auth!==void 0?xt(t.workers.auth):void 0;return[...e?[e]:[]]},$s=t=>w.getInstance().subscribe(t);export{E as InternetIdentityProvider,ot as NFIDProvider,$s as authSubscribe,ks as deleteAsset,Rs as deleteAssets,Ye as deleteDoc,Je as deleteDocs,Us as deleteManyAssets,Xe as deleteManyDocs,ft as getDoc,Ge as getManyDocs,Bs as initJuno,vs as listAssets,Qe as listDocs,gt as setDoc,We as setManyDocs,Dt as signIn,J as signOut,It as unsafeIdentity,Ns as uploadBlob,Os as uploadFile};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|